mirror of https://github.com/zachjs/sv2v.git
package item nesting perf tweaks
This commit is contained in:
parent
c876c447e6
commit
fcaca6c33a
|
|
@ -7,13 +7,13 @@
|
||||||
module Convert.NestPI (convert) where
|
module Convert.NestPI (convert) where
|
||||||
|
|
||||||
import Control.Monad.Writer
|
import Control.Monad.Writer
|
||||||
import Data.List.Unique (complex)
|
import qualified Data.Map.Strict as Map
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
import Convert.Traverse
|
import Convert.Traverse
|
||||||
import Language.SystemVerilog.AST
|
import Language.SystemVerilog.AST
|
||||||
|
|
||||||
type PIs = [(Identifier, PackageItem)]
|
type PIs = Map.Map Identifier PackageItem
|
||||||
type Idents = Set.Set Identifier
|
type Idents = Set.Set Identifier
|
||||||
|
|
||||||
convert :: [AST] -> [AST]
|
convert :: [AST] -> [AST]
|
||||||
|
|
@ -39,7 +39,7 @@ collectDescriptionM :: Description -> Writer PIs ()
|
||||||
collectDescriptionM (PackageItem item) = do
|
collectDescriptionM (PackageItem item) = do
|
||||||
case piName item of
|
case piName item of
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just ident -> tell [(ident, item)]
|
Just ident -> tell $ Map.singleton ident item
|
||||||
collectDescriptionM _ = return ()
|
collectDescriptionM _ = return ()
|
||||||
|
|
||||||
-- nests packages items missing from modules
|
-- nests packages items missing from modules
|
||||||
|
|
@ -56,10 +56,9 @@ convertDescription pis (orig @ Part{}) =
|
||||||
, collectExprsM $ collectNestedExprsM collectIdentsM
|
, collectExprsM $ collectNestedExprsM collectIdentsM
|
||||||
]
|
]
|
||||||
neededPIs = Set.difference (Set.union usedPIs imports) existingPIs
|
neededPIs = Set.difference (Set.union usedPIs imports) existingPIs
|
||||||
imports = Set.fromList $ map fst $ filter (isImport . snd) pis
|
imports = Map.keysSet $ Map.filter isImport pis
|
||||||
uniq l = l' where (l', _, _) = complex l
|
newItems = map MIPackageItem $ Map.elems $
|
||||||
newItems = uniq $ map MIPackageItem $ map snd $
|
Map.restrictKeys pis neededPIs
|
||||||
filter (\(x, _) -> Set.member x neededPIs) pis
|
|
||||||
-- place data declarations at the beginning to obey declaration
|
-- place data declarations at the beginning to obey declaration
|
||||||
-- ordering; everything else can go at the end
|
-- ordering; everything else can go at the end
|
||||||
newItemsBefore = filter isDecl newItems
|
newItemsBefore = filter isDecl newItems
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue