mirror of https://github.com/zachjs/sv2v.git
globally imported items are selectively nested
This commit is contained in:
parent
29b5136503
commit
9af38e7870
|
|
@ -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 =
|
||||
traverseModuleItems (traverseModuleItem existingItemNames packages)
|
||||
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 =
|
||||
[description']
|
||||
where
|
||||
description' = traverseModuleItems
|
||||
(traverseModuleItem existingItemNames packages)
|
||||
description
|
||||
existingItemNames = execWriter $
|
||||
collectModuleItemsM writePIName description
|
||||
writePIName :: ModuleItem -> Writer Idents ()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package P;
|
||||
localparam FOO = 1;
|
||||
localparam BAR = 2;
|
||||
endpackage
|
||||
import P::*;
|
||||
module top;
|
||||
initial $display(FOO);
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module top;
|
||||
localparam FOO = 1;
|
||||
initial $display(FOO);
|
||||
endmodule
|
||||
Loading…
Reference in New Issue