Commit a803284b by Zachary Snow

support for instantiations with a range

parent ed816ac5
...@@ -54,7 +54,7 @@ convertDescription interfaces (Part Module name ports items) = ...@@ -54,7 +54,7 @@ convertDescription interfaces (Part Module name ports items) =
tell (Map.empty, Map.singleton ident modportDecls) tell (Map.empty, Map.singleton ident modportDecls)
where modportDecls = lookupModport Nothing interfaceName modportName where modportDecls = lookupModport Nothing interfaceName modportName
_ -> return () _ -> return ()
collectInterface (Instance part _ ident _) = collectInterface (Instance part _ ident Nothing _) =
if Map.member part interfaces if Map.member part interfaces
then tell (Map.singleton ident part, Map.empty) then tell (Map.singleton ident part, Map.empty)
else return () else return ()
...@@ -73,12 +73,12 @@ convertDescription interfaces (Part Module name ports items) = ...@@ -73,12 +73,12 @@ convertDescription interfaces (Part Module name ports items) =
mapper = \(dir, port, Just expr) -> mapper = \(dir, port, Just expr) ->
Variable dir (lookupType interfaceItems expr) Variable dir (lookupType interfaceItems expr)
(ident ++ "_" ++ port) [] Nothing (ident ++ "_" ++ port) [] Nothing
mapInterface (Instance part params ident instancePorts) = mapInterface (Instance part params ident Nothing instancePorts) =
case Map.lookup part interfaces of case Map.lookup part interfaces of
Just interface -> Just interface ->
Generate $ map GenModuleItem $ Generate $ map GenModuleItem $
inlineInterface interface (ident, expandedPorts) inlineInterface interface (ident, expandedPorts)
Nothing -> Instance part params ident expandedPorts Nothing -> Instance part params ident Nothing expandedPorts
where expandedPorts = concatMap expandPortBinding instancePorts where expandedPorts = concatMap expandPortBinding instancePorts
mapInterface other = other mapInterface other = other
......
...@@ -22,8 +22,8 @@ convert descriptions = ...@@ -22,8 +22,8 @@ convert descriptions =
getPorts _ = return () getPorts _ = return ()
mapInstance :: ModuleItem -> ModuleItem mapInstance :: ModuleItem -> ModuleItem
mapInstance (Instance m p x bindings) = mapInstance (Instance m p x r bindings) =
Instance m p x $ concatMap expandBinding bindings Instance m p x r $ concatMap expandBinding bindings
where where
alreadyBound :: [Identifier] alreadyBound :: [Identifier]
alreadyBound = map fst bindings alreadyBound = map fst bindings
......
...@@ -315,9 +315,10 @@ traverseExprsM mapper = moduleItemMapper ...@@ -315,9 +315,10 @@ traverseExprsM mapper = moduleItemMapper
decls' <- mapM declMapper decls decls' <- mapM declMapper decls
stmts' <- mapM stmtMapper stmts stmts' <- mapM stmtMapper stmts
return $ MIPackageItem $ Task lifetime f decls' stmts' return $ MIPackageItem $ Task lifetime f decls' stmts'
moduleItemMapper (Instance m params x l) = do moduleItemMapper (Instance m params x r l) = do
l' <- mapM portBindingMapper l l' <- mapM portBindingMapper l
return $ Instance m params x l' r' <- mapM rangeMapper r
return $ Instance m params x r' l'
moduleItemMapper (Modport x l) = moduleItemMapper (Modport x l) =
mapM modportDeclMapper l >>= return . Modport x mapM modportDeclMapper l >>= return . Modport x
moduleItemMapper (NInputGate kw x lhs exprs) = do moduleItemMapper (NInputGate kw x lhs exprs) = do
......
...@@ -113,7 +113,7 @@ data ModuleItem ...@@ -113,7 +113,7 @@ data ModuleItem
| AlwaysC AlwaysKW Stmt | AlwaysC AlwaysKW Stmt
| Assign LHS Expr | Assign LHS Expr
| Defparam LHS Expr | Defparam LHS Expr
| Instance Identifier [PortBinding] Identifier [PortBinding] | Instance Identifier [PortBinding] Identifier (Maybe Range) [PortBinding]
| Genvar Identifier | Genvar Identifier
| Generate [GenItem] | Generate [GenItem]
| Modport Identifier [ModportDecl] | Modport Identifier [ModportDecl]
...@@ -145,9 +145,10 @@ instance Show ModuleItem where ...@@ -145,9 +145,10 @@ instance Show ModuleItem where
AlwaysC k b -> printf "%s %s" (show k) (show b) AlwaysC k b -> printf "%s %s" (show k) (show b)
Assign a b -> printf "assign %s = %s;" (show a) (show b) Assign a b -> printf "assign %s = %s;" (show a) (show b)
Defparam a b -> printf "defparam %s = %s;" (show a) (show b) Defparam a b -> printf "defparam %s = %s;" (show a) (show b)
Instance m params i ports Instance m params i r ports
| null params -> printf "%s %s%s;" m i (showPorts ports) | null params -> printf "%s %s%s%s;" m i rStr (showPorts ports)
| otherwise -> printf "%s #%s %s%s;" m (showPorts params) i (showPorts ports) | otherwise -> printf "%s #%s %s%s%s;" m (showPorts params) i rStr (showPorts ports)
where rStr = maybe "" (\a -> showRanges [a] ++ " ") r
Genvar x -> printf "genvar %s;" x Genvar x -> printf "genvar %s;" x
Generate b -> printf "generate\n%s\nendgenerate" (indent $ unlines' $ map show b) Generate b -> printf "generate\n%s\nendgenerate" (indent $ unlines' $ map show b)
Modport x l -> printf "modport %s(\n%s\n);" x (indent $ intercalate ",\n" $ map showModportDecl l) Modport x l -> printf "modport %s(\n%s\n);" x (indent $ intercalate ",\n" $ map showModportDecl l)
......
...@@ -460,8 +460,8 @@ Lifetime :: { Lifetime } ...@@ -460,8 +460,8 @@ Lifetime :: { Lifetime }
: "static" { Static } : "static" { Static }
| "automatic" { Automatic } | "automatic" { Automatic }
ModuleInstantiation :: { (Identifier, [PortBinding]) } ModuleInstantiation :: { [PortBinding] }
: Identifier "(" Bindings ")" { ($1, $3) } : "(" Bindings ")" { $2 }
TFItems :: { [Decl] } TFItems :: { [Decl] }
: "(" DeclTokens(")") ";" { parseDTsAsDecls $2 } : "(" DeclTokens(")") ";" { parseDTsAsDecls $2 }
......
...@@ -53,7 +53,7 @@ data DeclToken ...@@ -53,7 +53,7 @@ data DeclToken
| DTDir Direction | DTDir Direction
| DTType (Signing -> [Range] -> Type) | DTType (Signing -> [Range] -> Type)
| DTParams [PortBinding] | DTParams [PortBinding]
| DTInstance (Identifier, [PortBinding]) | DTInstance [PortBinding]
| DTBit Expr | DTBit Expr
| DTConcat [LHS] | DTConcat [LHS]
| DTDot Identifier | DTDot Identifier
...@@ -125,21 +125,31 @@ parseDTsAsModuleItems tokens = ...@@ -125,21 +125,31 @@ parseDTsAsModuleItems tokens =
-- internal; parser for module instantiations -- internal; parser for module instantiations
parseDTsAsIntantiations :: [DeclToken] -> [ModuleItem] parseDTsAsIntantiations :: [DeclToken] -> [ModuleItem]
parseDTsAsIntantiations (DTIdent name : tokens) = parseDTsAsIntantiations (DTIdent name : tokens) =
if not (all isInstanceOrComma rest) if not (all isInstanceToken rest)
then error $ "instantiations mixed with other items: " ++ (show rest) then error $ "instantiations mixed with other items: " ++ (show rest)
else map (uncurry $ Instance name params) instances else step rest
where where
step :: [DeclToken] -> [ModuleItem]
step [] = error $ "unexpected end of instantiation list: " ++ (show tokens)
step toks =
Instance name params x mr p : follow
where
(inst, toks') = span (DTComma /=) toks
(x, mr, p) = case inst of
[DTIdent a, DTRange s, DTInstance b] -> (a, Just s , b)
[DTIdent a, DTInstance b] -> (a, Nothing, b)
_ -> error $ "unrecognized instantiation: " ++ show inst
follow = x `seq` if null toks' then [] else step (tail toks')
(params, rest) = (params, rest) =
case head tokens of case head tokens of
DTParams ps -> (ps, tail tokens) DTParams ps -> (ps, tail tokens)
_ -> ([], tokens) _ -> ([], tokens)
instances = isInstanceToken :: DeclToken -> Bool
map (\(DTInstance inst) -> inst) $ isInstanceToken (DTInstance _) = True
filter (DTComma /=) $ rest isInstanceToken (DTRange _) = True
isInstanceOrComma :: DeclToken -> Bool isInstanceToken (DTIdent _) = True
isInstanceOrComma (DTInstance _) = True isInstanceToken DTComma = True
isInstanceOrComma DTComma = True isInstanceToken _ = False
isInstanceOrComma _ = False
parseDTsAsIntantiations tokens = parseDTsAsIntantiations tokens =
error $ error $
"DeclTokens contain instantiations, but start with non-ident: " "DeclTokens contain instantiations, but start with non-ident: "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment