Commit a2b99fa9 by Zachary Snow

module item statement traversals only visit the top level

parent 2eee536f
...@@ -14,7 +14,7 @@ import Language.SystemVerilog.AST ...@@ -14,7 +14,7 @@ import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert =
map $ traverseDescriptions $ traverseModuleItems $ map $ traverseDescriptions $ traverseModuleItems $
( traverseStmts convertStmt ( traverseStmts (traverseNestedStmts convertStmt)
. traverseGenItems (traverseNestedGenItems convertGenItem) . traverseGenItems (traverseNestedGenItems convertGenItem)
) )
......
...@@ -18,7 +18,8 @@ convertModuleItem (AssertionItem item) = ...@@ -18,7 +18,8 @@ convertModuleItem (AssertionItem item) =
map (GenModuleItem . MIPackageItem . Decl . CommentDecl) $ map (GenModuleItem . MIPackageItem . Decl . CommentDecl) $
"removed an assertion item" : "removed an assertion item" :
(lines $ show $ AssertionItem item) (lines $ show $ AssertionItem item)
convertModuleItem other = traverseStmts convertStmt other convertModuleItem other =
traverseStmts (traverseNestedStmts convertStmt) other
convertStmt :: Stmt -> Stmt convertStmt :: Stmt -> Stmt
convertStmt (Assertion _) = Null convertStmt (Assertion _) = Null
......
...@@ -16,7 +16,7 @@ import Language.SystemVerilog.AST ...@@ -16,7 +16,7 @@ import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert =
map $ traverseDescriptions $ traverseModuleItems map $ traverseDescriptions $ traverseModuleItems
(convertModuleItem . traverseStmts convertStmt) (convertModuleItem . traverseStmts (traverseNestedStmts convertStmt))
convertModuleItem :: ModuleItem -> ModuleItem convertModuleItem :: ModuleItem -> ModuleItem
convertModuleItem (MIPackageItem (Function ml t f decls stmts)) = convertModuleItem (MIPackageItem (Function ml t f decls stmts)) =
......
...@@ -17,7 +17,7 @@ import Language.SystemVerilog.AST ...@@ -17,7 +17,7 @@ import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert =
map $ traverseDescriptions $ traverseModuleItems $ map $ traverseDescriptions $ traverseModuleItems $
traverseStmts convertStmt traverseStmts $ traverseNestedStmts convertStmt
convertStmt :: Stmt -> Stmt convertStmt :: Stmt -> Stmt
......
...@@ -16,7 +16,7 @@ import Language.SystemVerilog.AST ...@@ -16,7 +16,7 @@ import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert =
map $ traverseDescriptions $ traverseModuleItems $ map $ traverseDescriptions $ traverseModuleItems $
traverseStmts convertStmt traverseStmts $ traverseNestedStmts convertStmt
convertStmt :: Stmt -> Stmt convertStmt :: Stmt -> Stmt
convertStmt (Foreach x idxs stmt) = convertStmt (Foreach x idxs stmt) =
......
...@@ -23,8 +23,11 @@ convert = map $ traverseDescriptions convertDescription ...@@ -23,8 +23,11 @@ convert = map $ traverseDescriptions convertDescription
convertDescription :: Description -> Description convertDescription :: Description -> Description
convertDescription (description @ Part{}) = convertDescription (description @ Part{}) =
traverseModuleItems (traverseStmts $ convertStmt functions) description traverseModuleItems traverseModuleItem description
where functions = execWriter $ where
traverseModuleItem =
traverseStmts $ traverseNestedStmts $ convertStmt functions
functions = execWriter $
collectModuleItemsM collectFunctionsM description collectModuleItemsM collectFunctionsM description
convertDescription other = other convertDescription other = other
......
...@@ -28,7 +28,7 @@ convert = map $ traverseDescriptions $ traverseModuleItems convertModuleItem ...@@ -28,7 +28,7 @@ convert = map $ traverseDescriptions $ traverseModuleItems convertModuleItem
convertModuleItem :: ModuleItem -> ModuleItem convertModuleItem :: ModuleItem -> ModuleItem
convertModuleItem item = convertModuleItem item =
traverseExprs (traverseNestedExprs convertExpr) $ traverseExprs (traverseNestedExprs convertExpr) $
traverseStmts convertStmt $ traverseStmts (traverseNestedStmts convertStmt) $
item item
convertExpr :: Expr -> Expr convertExpr :: Expr -> Expr
......
...@@ -29,7 +29,7 @@ convertDescription description = ...@@ -29,7 +29,7 @@ convertDescription description =
convertModuleItem :: TFs -> ModuleItem -> ModuleItem convertModuleItem :: TFs -> ModuleItem -> ModuleItem
convertModuleItem tfs = convertModuleItem tfs =
(traverseExprs $ traverseNestedExprs $ convertExpr tfs) . (traverseExprs $ traverseNestedExprs $ convertExpr tfs) .
(traverseStmts $ convertStmt tfs) (traverseStmts $ traverseNestedStmts $ convertStmt tfs)
collectTF :: ModuleItem -> Writer TFs () collectTF :: ModuleItem -> Writer TFs ()
collectTF (MIPackageItem (Function _ _ f decls _)) = collectTFDecls f decls collectTF (MIPackageItem (Function _ _ f decls _)) = collectTFDecls f decls
......
...@@ -23,7 +23,8 @@ convert asts = ...@@ -23,7 +23,8 @@ convert asts =
-- we collect all the existing blocks in the first pass to make sure we -- we collect all the existing blocks in the first pass to make sure we
-- don't generate conflicting names on repeated passes of this conversion -- don't generate conflicting names on repeated passes of this conversion
evalState (runner collectStmtM asts >>= runner traverseStmtM) Set.empty evalState (runner collectStmtM asts >>= runner traverseStmtM) Set.empty
where runner = mapM . traverseDescriptionsM . traverseModuleItemsM . traverseStmtsM where runner = mapM . traverseDescriptionsM . traverseModuleItemsM .
traverseStmtsM . traverseNestedStmtsM
collectStmtM :: Stmt -> State Idents Stmt collectStmtM :: Stmt -> State Idents Stmt
collectStmtM (Block kw x decls stmts) = do collectStmtM (Block kw x decls stmts) = do
......
...@@ -185,19 +185,18 @@ traverseStmtsM :: Monad m => MapperM m Stmt -> MapperM m ModuleItem ...@@ -185,19 +185,18 @@ traverseStmtsM :: Monad m => MapperM m Stmt -> MapperM m ModuleItem
traverseStmtsM mapper = moduleItemMapper traverseStmtsM mapper = moduleItemMapper
where where
moduleItemMapper (AlwaysC kw stmt) = moduleItemMapper (AlwaysC kw stmt) =
fullMapper stmt >>= return . AlwaysC kw mapper stmt >>= return . AlwaysC kw
moduleItemMapper (MIPackageItem (Function lifetime ret name decls stmts)) = do moduleItemMapper (MIPackageItem (Function lifetime ret name decls stmts)) = do
stmts' <- mapM fullMapper stmts stmts' <- mapM mapper stmts
return $ MIPackageItem $ Function lifetime ret name decls stmts' return $ MIPackageItem $ Function lifetime ret name decls stmts'
moduleItemMapper (MIPackageItem (Task lifetime name decls stmts)) = do moduleItemMapper (MIPackageItem (Task lifetime name decls stmts)) = do
stmts' <- mapM fullMapper stmts stmts' <- mapM mapper stmts
return $ MIPackageItem $ Task lifetime name decls stmts' return $ MIPackageItem $ Task lifetime name decls stmts'
moduleItemMapper (Initial stmt) = moduleItemMapper (Initial stmt) =
fullMapper stmt >>= return . Initial mapper stmt >>= return . Initial
moduleItemMapper (Final stmt) = moduleItemMapper (Final stmt) =
fullMapper stmt >>= return . Final mapper stmt >>= return . Final
moduleItemMapper other = return $ other moduleItemMapper other = return $ other
fullMapper = traverseNestedStmtsM mapper
traverseStmts :: Mapper Stmt -> Mapper ModuleItem traverseStmts :: Mapper Stmt -> Mapper ModuleItem
traverseStmts = unmonad traverseStmtsM traverseStmts = unmonad traverseStmtsM
...@@ -719,7 +718,8 @@ collectStmtExprsM = collectify traverseStmtExprsM ...@@ -719,7 +718,8 @@ collectStmtExprsM = collectify traverseStmtExprsM
traverseLHSsM :: Monad m => MapperM m LHS -> MapperM m ModuleItem traverseLHSsM :: Monad m => MapperM m LHS -> MapperM m ModuleItem
traverseLHSsM mapper = traverseLHSsM mapper =
traverseStmtsM (traverseStmtLHSsM mapper) >=> traverseModuleItemLHSsM traverseStmtsM (traverseNestedStmtsM $ traverseStmtLHSsM mapper)
>=> traverseModuleItemLHSsM
where where
traverseModuleItemLHSsM (Assign delay lhs expr) = do traverseModuleItemLHSsM (Assign delay lhs expr) = do
lhs' <- mapper lhs lhs' <- mapper lhs
...@@ -1055,7 +1055,7 @@ traverseAsgnsM mapper = moduleItemMapper ...@@ -1055,7 +1055,7 @@ traverseAsgnsM mapper = moduleItemMapper
return $ Defparam lhs' expr' return $ Defparam lhs' expr'
miMapperA other = return other miMapperA other = return other
miMapperB = traverseStmtsM stmtMapper miMapperB = traverseStmtsM $ traverseNestedStmtsM stmtMapper
stmtMapper = traverseStmtAsgnsM mapper stmtMapper = traverseStmtAsgnsM mapper
traverseAsgns :: Mapper (LHS, Expr) -> Mapper ModuleItem traverseAsgns :: Mapper (LHS, Expr) -> Mapper ModuleItem
......
...@@ -15,7 +15,8 @@ import Language.SystemVerilog.AST ...@@ -15,7 +15,8 @@ import Language.SystemVerilog.AST
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert =
map $ traverseDescriptions $ traverseModuleItems $ traverseStmts convertStmt map $ traverseDescriptions $ traverseModuleItems $ traverseStmts $
traverseNestedStmts convertStmt
convertStmt :: Stmt -> Stmt convertStmt :: Stmt -> Stmt
convertStmt (If _ cc s1 s2) = convertStmt (If _ cc s1 s2) =
......
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