sv2v/src/Convert/NamedBlock.hs

40 lines
1.2 KiB
Haskell
Raw Normal View History

{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for unnamed blocks with contain data declarations
2019-04-23 06:23:32 +02:00
-
- SystemVerilog allows data declarations to appear in all blocks, but Verilog
2019-05-15 15:55:15 +02:00
- allows them to appear only in blocks that are named. This conversion gives
2019-04-23 06:23:32 +02:00
- such blocks a unique name to placate strict Verilog frontends.
-}
module Convert.NamedBlock (convert) where
2020-08-12 01:14:18 +02:00
import Control.Monad.State.Strict
import Convert.Traverse
import Language.SystemVerilog.AST
convert :: [AST] -> [AST]
convert = map $ traverseDescriptions convertDescription
convertDescription :: Description -> Description
convertDescription description =
evalState (traverseModuleItemsM traverseModuleItem description) 1
where
traverseModuleItem = traverseStmtsM $ traverseNestedStmtsM traverseStmtM
traverseStmtM :: Stmt -> State Int Stmt
traverseStmtM (Block kw "" [] stmts) =
return $ Block kw "" [] stmts
traverseStmtM (Block kw "" decls stmts) = do
x <- uniqueBlockName
return $ Block kw x decls stmts
traverseStmtM other = return other
uniqueBlockName :: State Int String
uniqueBlockName = do
cnt <- get
put $ cnt + 1
return $ "sv2v_autoblock_" ++ show cnt