2019-04-20 01:08:52 +02:00
|
|
|
{- 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.
|
2019-04-20 01:08:52 +02:00
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Convert.NamedBlock (convert) where
|
|
|
|
|
|
2020-08-12 01:14:18 +02:00
|
|
|
import Control.Monad.State.Strict
|
2019-04-20 01:08:52 +02:00
|
|
|
|
|
|
|
|
import Convert.Traverse
|
|
|
|
|
import Language.SystemVerilog.AST
|
|
|
|
|
|
2019-04-24 00:44:45 +02:00
|
|
|
convert :: [AST] -> [AST]
|
2021-07-16 15:19:38 +02:00
|
|
|
convert = map $ traverseDescriptions convertDescription
|
2019-04-20 01:08:52 +02:00
|
|
|
|
2021-07-16 15:19:38 +02:00
|
|
|
convertDescription :: Description -> Description
|
|
|
|
|
convertDescription description =
|
|
|
|
|
evalState (traverseModuleItemsM traverseModuleItem description) 1
|
|
|
|
|
where
|
|
|
|
|
traverseModuleItem = traverseStmtsM $ traverseNestedStmtsM traverseStmtM
|
2019-04-20 01:08:52 +02:00
|
|
|
|
2021-07-16 15:19:38 +02:00
|
|
|
traverseStmtM :: Stmt -> State Int Stmt
|
2019-10-01 05:03:55 +02:00
|
|
|
traverseStmtM (Block kw "" [] stmts) =
|
|
|
|
|
return $ Block kw "" [] stmts
|
|
|
|
|
traverseStmtM (Block kw "" decls stmts) = do
|
2021-07-16 15:19:38 +02:00
|
|
|
x <- uniqueBlockName
|
2019-10-01 05:03:55 +02:00
|
|
|
return $ Block kw x decls stmts
|
2019-04-20 01:08:52 +02:00
|
|
|
traverseStmtM other = return other
|
|
|
|
|
|
2021-07-16 15:19:38 +02:00
|
|
|
uniqueBlockName :: State Int String
|
|
|
|
|
uniqueBlockName = do
|
|
|
|
|
cnt <- get
|
|
|
|
|
put $ cnt + 1
|
|
|
|
|
return $ "sv2v_autoblock_" ++ show cnt
|