support for localparam type

This commit is contained in:
Zachary Snow 2020-07-08 19:34:49 -06:00
parent 9aa8d5a5d3
commit 4b5e3232b9
4 changed files with 33 additions and 11 deletions

View File

@ -147,22 +147,15 @@ convert files =
where where
Part attrs extern kw ml m p items = part Part attrs extern kw ml m p items = part
m' = moduleInstanceName m typeMap m' = moduleInstanceName m typeMap
items' = map rewriteDecl items items' = map (traverseDecls rewriteDecl) items
rewriteDecl :: ModuleItem -> ModuleItem rewriteDecl :: Decl -> Decl
rewriteDecl (MIPackageItem (Decl (ParamType Parameter x _))) = rewriteDecl (ParamType Parameter x _) =
MIPackageItem $ Typedef (typeMap' Map.! x) x ParamType Localparam x (Just $ typeMap' Map.! x)
rewriteDecl other = other rewriteDecl other = other
explodedTypeMap = Map.mapWithKey prepareTypeIdents typeMap explodedTypeMap = Map.mapWithKey prepareTypeIdents typeMap
typeMap' = Map.map fst explodedTypeMap typeMap' = Map.map fst explodedTypeMap
additionalParamItems = concatMap makeAddedParams $ additionalParamItems = concatMap makeAddedParams $
Map.toList $ Map.map snd explodedTypeMap Map.toList $ Map.map snd explodedTypeMap
-- TODO FIXME: Typedef conversion must be made to handle
-- ParamTypes!
-----items' = map (traverseDecls rewriteDecl) items
-----rewriteDecl :: Decl -> Decl
-----rewriteDecl (ParamType Parameter x _) =
----- ParamType Localparam x (Just $ typeMap Map.! x)
-----rewriteDecl other = other
makeAddedParams :: (Identifier, IdentSet) -> [ModuleItem] makeAddedParams :: (Identifier, IdentSet) -> [ModuleItem]
makeAddedParams (paramName, identSet) = makeAddedParams (paramName, identSet) =

View File

@ -70,6 +70,10 @@ traverseDeclM decl = do
case decl' of case decl' of
Variable{} -> return decl' Variable{} -> return decl'
Param{} -> return decl' Param{} -> return decl'
ParamType Localparam x (Just t) -> do
t' <- traverseNestedTypesM traverseTypeM t
insertElem x t'
return $ CommentDecl $ "removed localparam type " ++ x
ParamType{} -> return decl' ParamType{} -> return decl'
CommentDecl{} -> return decl' CommentDecl{} -> return decl'

View File

@ -0,0 +1,16 @@
module top;
localparam type T = logic;
initial begin
$display("A %0d", $bits(T));
begin
localparam type T = logic [1:0];
$display("B %0d", $bits(T));
begin
localparam type T = T [1:0];
$display("C %0d", $bits(T));
end
$display("B %0d", $bits(T));
end
$display("A %0d", $bits(T));
end
endmodule

View File

@ -0,0 +1,9 @@
module top;
initial begin
$display("A %0d", 1);
$display("B %0d", 2);
$display("C %0d", 4);
$display("B %0d", 2);
$display("A %0d", 1);
end
endmodule