Commit 9af38e78 by Zachary Snow

globally imported items are selectively nested

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