Commit 11bb0537 by Zachary Snow

simplify duplicate genvar conversion

parent 99df3264
...@@ -6,47 +6,20 @@ ...@@ -6,47 +6,20 @@
module Convert.DuplicateGenvar (convert) where module Convert.DuplicateGenvar (convert) where
import Control.Monad.State.Strict import Convert.Scoper
import qualified Data.Set as Set
import Convert.Traverse import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
type IdentSet = Set.Set Identifier
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = map $ traverseDescriptions traverseDescription convert = map $ traverseDescriptions traverseDescription
traverseDescription :: Description -> Description traverseDescription :: Description -> Description
traverseDescription (part @ Part{}) = traverseDescription = partScoper return traverseModuleItemM return return
Part attrs extern kw lifetime name ports items'
where
Part attrs extern kw lifetime name ports items = part
-- intentionally only looks at top level module items
items' = evalState (mapM traverseModuleItemM items) Set.empty
traverseDescription other = other
traverseModuleItemM :: ModuleItem -> State IdentSet ModuleItem traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem
traverseModuleItemM (Genvar x) = do traverseModuleItemM (Genvar x) = do
alreadyExists <- gets $ Set.member x details <- lookupElemM x
if alreadyExists if details == Nothing
then return $ Generate [] then insertElem x () >> return (Genvar x)
else do else return $ Generate []
modify $ Set.insert x traverseModuleItemM item = return item
return $ Genvar x
traverseModuleItemM (Generate items) = do
s <- get
items' <- traverseItems items
s' <- get
items'' <- traverseItems items'
let genvarDecls = map (GenModuleItem . Genvar) $
Set.toList $ Set.difference s' s
return $ Generate (genvarDecls ++ items'')
where traverseItems = mapM $ traverseNestedGenItemsM traverseGenItemM
traverseModuleItemM other = return other
traverseGenItemM :: GenItem -> State IdentSet GenItem
traverseGenItemM (GenModuleItem item) = do
item' <- traverseModuleItemM item
return $ GenModuleItem item'
traverseGenItemM other = return other
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