Commit 9af38e78 by Zachary Snow

globally imported items are selectively nested

parent 29b51365
......@@ -31,6 +31,7 @@ convert =
(traverseDescriptions . convertDescription)
curr
isPI :: Description -> Bool
isPI (PackageItem Import{}) = False
isPI (PackageItem item) = piName item /= Nothing
isPI _ = False
......@@ -55,8 +56,7 @@ convertDescription pis (orig @ Part{}) =
, collectTypesM $ collectNestedTypesM collectTypenamesM
, collectExprsM $ collectNestedExprsM collectIdentsM
]
neededPIs = Set.difference (Set.union usedPIs imports) existingPIs
imports = Map.keysSet $ Map.filter isImport pis
neededPIs = Set.difference usedPIs existingPIs
newItems = map MIPackageItem $ Map.elems $
Map.restrictKeys pis neededPIs
-- place data declarations at the beginning to obey declaration
......@@ -104,7 +104,3 @@ piName (Decl (CommentDecl _)) = Nothing
piName (Import x y) = Just $ show $ Import x y
piName (Export _) = Nothing
piName (Directive _) = Nothing
isImport :: PackageItem -> Bool
isImport Import{} = True
isImport _ = False
......@@ -53,7 +53,7 @@ convertFile :: Packages -> AST -> AST
convertFile packages ast =
(++) globalItems $
filter (not . isCollected) $
traverseDescriptions (traverseDescription packages) $
concatMap (traverseDescription packages) $
ast
where
globalItems = map PackageItem $
......@@ -127,11 +127,20 @@ collectDescriptionM (Package _ name items) =
isImport _ = False
collectDescriptionM _ = return ()
traverseDescription :: Packages -> Description -> Description
traverseDescription :: Packages -> Description -> [Description]
traverseDescription packages (PackageItem (Import x y)) =
map (\(MIPackageItem item) -> PackageItem item) items
where
orig = Part [] False Module Inherit "DNE" []
[MIPackageItem $ Import x y]
[orig'] = traverseDescription packages orig
Part [] False Module Inherit "DNE" [] items = orig'
traverseDescription packages description =
traverseModuleItems (traverseModuleItem existingItemNames packages)
description
[description']
where
description' = traverseModuleItems
(traverseModuleItem existingItemNames packages)
description
existingItemNames = execWriter $
collectModuleItemsM writePIName description
writePIName :: ModuleItem -> Writer Idents ()
......
package P;
localparam FOO = 1;
localparam BAR = 2;
endpackage
import P::*;
module top;
initial $display(FOO);
endmodule
module top;
localparam FOO = 1;
initial $display(FOO);
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