Commit ecf047e3 by Zachary Snow

fix declaration order of nested package items

parent b6f4f690
...@@ -49,24 +49,33 @@ convertDescription pis (orig @ Part{}) = ...@@ -49,24 +49,33 @@ convertDescription pis (orig @ Part{}) =
Part attrs extern kw lifetime name ports items' Part attrs extern kw lifetime name ports items'
where where
Part attrs extern kw lifetime name ports items = orig Part attrs extern kw lifetime name ports items = orig
existingPIs = execWriter $ collectModuleItemsM collectPIsM orig items' = addItems pis Set.empty items
runner f = execWriter $ collectModuleItemsM f orig convertDescription _ other = other
usedPIs = Set.unions $ map runner $
-- iteratively inserts missing package items exactly where they are needed
addItems :: PIs -> Idents -> [ModuleItem] -> [ModuleItem]
addItems pis existingPIs (item : items) =
if not $ Set.disjoint existingPIs thisPI then
-- this item was re-imported earlier in the module
addItems pis existingPIs items
else if null itemsToAdd then
-- this item has no additional dependencies
item : addItems pis (Set.union existingPIs thisPI) items
else
-- this item has at least one un-met dependency
addItems pis existingPIs (head itemsToAdd : item : items)
where
thisPI = execWriter $ collectPIsM item
runner f = execWriter $ collectNestedModuleItemsM f item
usedPIs = Set.unions $ map runner
[ collectStmtsM collectSubroutinesM [ collectStmtsM collectSubroutinesM
, collectTypesM $ collectNestedTypesM collectTypenamesM , collectTypesM $ collectNestedTypesM collectTypenamesM
, collectExprsM $ collectNestedExprsM collectIdentsM , collectExprsM $ collectNestedExprsM collectIdentsM
] ]
neededPIs = Set.difference usedPIs existingPIs neededPIs = Set.difference usedPIs existingPIs
newItems = map MIPackageItem $ Map.elems $ itemsToAdd = map MIPackageItem $ Map.elems $
Map.restrictKeys pis neededPIs Map.restrictKeys pis neededPIs
-- place data declarations at the beginning to obey declaration addItems _ _ [] = []
-- ordering; everything else can go at the end
newItemsBefore = filter isDecl newItems
newItemsAfter = filter (not . isDecl) newItems
items' = newItemsBefore ++ items ++ newItemsAfter
isDecl (MIPackageItem (Decl{})) = True
isDecl _ = False
convertDescription _ other = other
-- writes down the names of package items -- writes down the names of package items
collectPIsM :: ModuleItem -> Writer Idents () collectPIsM :: ModuleItem -> Writer Idents ()
......
localparam Z = 1;
localparam Y = 5'(Z);
localparam X = 5'(Y);
module top;
initial begin
$display("%b", X);
$display("%b", Y);
$display("%b", Z);
end
endmodule
module top;
initial begin
$display("%b", 5'b1);
$display("%b", 5'b1);
$display("%b", 32'b1);
end
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