Commit c876c447 by Zachary Snow

fix interface inlining renaming

parent df4244d8
...@@ -57,7 +57,6 @@ phases excludes = ...@@ -57,7 +57,6 @@ phases excludes =
, Convert.Assertion.convert , Convert.Assertion.convert
, Convert.BlockDecl.convert , Convert.BlockDecl.convert
, selectExclude (Job.Logic , Convert.Logic.convert) , selectExclude (Job.Logic , Convert.Logic.convert)
, Convert.ForDecl.convert
, Convert.FuncRet.convert , Convert.FuncRet.convert
, Convert.FuncRoutine.convert , Convert.FuncRoutine.convert
, Convert.EmptyArgs.convert , Convert.EmptyArgs.convert
...@@ -88,6 +87,7 @@ phases excludes = ...@@ -88,6 +87,7 @@ phases excludes =
, Convert.Jump.convert , Convert.Jump.convert
, Convert.Foreach.convert , Convert.Foreach.convert
, selectExclude (Job.Interface, Convert.Interface.convert) , selectExclude (Job.Interface, Convert.Interface.convert)
, Convert.ForDecl.convert
, selectExclude (Job.Always , Convert.AlwaysKW.convert) , selectExclude (Job.Always , Convert.AlwaysKW.convert)
, selectExclude (Job.Succinct , Convert.RemoveComments.convert) , selectExclude (Job.Succinct , Convert.RemoveComments.convert)
] ]
......
...@@ -199,39 +199,52 @@ convertDescription _ _ other = other ...@@ -199,39 +199,52 @@ convertDescription _ _ other = other
-- add a prefix to all standard identifiers in a module item -- add a prefix to all standard identifiers in a module item
prefixModuleItems :: Identifier -> ModuleItem -> ModuleItem prefixModuleItems :: (Identifier -> Identifier) -> ModuleItem -> ModuleItem
prefixModuleItems prefix = prefixModuleItems prefix =
prefixMIPackageItem . prefixOtherItem .
traverseDecls prefixDecl . traverseDecls prefixDecl .
traverseExprs (traverseNestedExprs prefixExpr) . traverseExprs (traverseNestedExprs prefixExpr) .
traverseLHSs (traverseNestedLHSs prefixLHS ) traverseLHSs (traverseNestedLHSs prefixLHS )
where where
prefixDecl :: Decl -> Decl prefixDecl :: Decl -> Decl
prefixDecl (Variable d t x a me) = Variable d t (prefix ++ x) a me prefixDecl (Variable d t x a me) = Variable d t (prefix x) a me
prefixDecl (Param s t x e) = Param s t (prefix ++ x) e prefixDecl (Param s t x e) = Param s t (prefix x) e
prefixDecl (ParamType s x mt) = ParamType s (prefix ++ x) mt prefixDecl (ParamType s x mt) = ParamType s (prefix x) mt
prefixDecl (CommentDecl c) = CommentDecl c prefixDecl (CommentDecl c) = CommentDecl c
prefixExpr :: Expr -> Expr prefixExpr :: Expr -> Expr
prefixExpr (Ident ('$' : x)) = Ident $ '$' : x prefixExpr (Ident x) = Ident (prefix x)
prefixExpr (Ident x) = Ident (prefix ++ x)
prefixExpr other = other prefixExpr other = other
prefixLHS :: LHS -> LHS prefixLHS :: LHS -> LHS
prefixLHS (LHSIdent x) = LHSIdent (prefix ++ x) prefixLHS (LHSIdent x) = LHSIdent (prefix x)
prefixLHS other = other prefixLHS other = other
prefixMIPackageItem (MIPackageItem item) = prefixOtherItem (MIPackageItem item) =
MIPackageItem $ prefixPackageItem prefix item MIPackageItem $ prefixPackageItem prefix item
prefixMIPackageItem other = other prefixOtherItem (Genvar x) = Genvar $ prefix x
prefixOtherItem other = other
-- add a prefix to all standard identifiers in a package item -- add a prefix to all standard identifiers in a package item
prefixPackageItem :: Identifier -> PackageItem -> PackageItem prefixPackageItem :: (Identifier -> Identifier) -> PackageItem -> PackageItem
prefixPackageItem prefix (Function lifetime t x decls stmts) = prefixPackageItem prefix (Function lifetime t x decls stmts) =
Function lifetime t x' decls stmts Function lifetime t x' decls stmts
where x' = prefix ++ x where x' = prefix x
prefixPackageItem prefix (Task lifetime x decls stmts) = prefixPackageItem prefix (Task lifetime x decls stmts) =
Task lifetime x' decls stmts Task lifetime x' decls stmts
where x' = prefix ++ x where x' = prefix x
prefixPackageItem _ other = other prefixPackageItem _ other = other
-- collect all identifiers defined within a module item
collectIdentsM :: ModuleItem -> Writer (Set.Set Identifier) ()
collectIdentsM (MIPackageItem (Function _ _ x _ _)) = tell $ Set.singleton x
collectIdentsM (MIPackageItem (Task _ x _ _)) = tell $ Set.singleton x
collectIdentsM (Genvar x) = tell $ Set.singleton x
collectIdentsM item = collectDeclsM collectDecl item
where
collectDecl :: Decl -> Writer (Set.Set Identifier) ()
collectDecl (Variable _ _ x _ _) = tell $ Set.singleton x
collectDecl (Param _ _ x _) = tell $ Set.singleton x
collectDecl (ParamType _ x _) = tell $ Set.singleton x
collectDecl (CommentDecl _) = return ()
lookupType :: [ModuleItem] -> Expr -> (Type, [Range]) lookupType :: [ModuleItem] -> Expr -> (Type, [Range])
lookupType items (Ident ident) = lookupType items (Ident ident) =
case mapMaybe findType items of case mapMaybe findType items of
...@@ -258,10 +271,16 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) = ...@@ -258,10 +271,16 @@ inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
where where
comment = MIPackageItem $ Decl $ CommentDecl $ comment = MIPackageItem $ Decl $ CommentDecl $
"expanded instance: " ++ instanceName "expanded instance: " ++ instanceName
prefix = instanceName ++ "_" prefix = instanceName ++ "_"
idents = execWriter $
mapM (collectNestedModuleItemsM collectIdentsM) items
prefixIfNecessary :: Identifier -> Identifier
prefixIfNecessary x =
if Set.member x idents
then prefix ++ x
else x
itemsPrefixed = itemsPrefixed =
map (prefixModuleItems prefix) $ map (traverseNestedModuleItems $ prefixModuleItems prefixIfNecessary) $
map (traverseDecls overrideParam) $ map (traverseDecls overrideParam) $
items items
origInstancePortNames = map fst instancePorts origInstancePortNames = map fst instancePorts
......
localparam SOME_VAL = 3;
interface Interface; interface Interface;
logic x; logic x;
modport Modport( modport Modport(
input x input x
); );
initial $display("Interface", x); initial $display("Interface %d %d", x, SOME_VAL);
generate
for (genvar g = 10; g < 15; ++g) begin
initial $display(g);
end
endgenerate
endinterface endinterface
module Module(Interface.Modport foo); module Module(Interface.Modport foo);
initial $display("Module", foo.x); initial $display("Module %d", foo.x);
endmodule endmodule
module top; module top;
generate
for (genvar g = 0; g < 5; ++g) begin
initial $display(g);
end
endgenerate
Interface i(); Interface i();
Module m(i); Module m(i);
endmodule endmodule
module Module(input wire x); module Module(input wire x);
initial $display("Module", x); initial $display("Module %d", x);
endmodule endmodule
module top; module top;
wire i_x; wire i_x;
initial $display("Interface", i_x); localparam SOME_VAL = 3;
initial $display("Interface %d %d", i_x, SOME_VAL);
Module m(.x(i_x)); Module m(.x(i_x));
generate
genvar g;
for (g = 0; g < 5; g = g + 1) begin
initial $display(g);
end
for (g = 10; g < 15; g = g + 1) begin
initial $display(g);
end
endgenerate
endmodule endmodule
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