Commit a0c3112b by Zachary Snow

flatten tf blocks with decls

parent 9e7768b6
...@@ -38,9 +38,9 @@ import qualified Convert.SignCast ...@@ -38,9 +38,9 @@ import qualified Convert.SignCast
import qualified Convert.Simplify import qualified Convert.Simplify
import qualified Convert.SizeCast import qualified Convert.SizeCast
import qualified Convert.StarPort import qualified Convert.StarPort
import qualified Convert.StmtBlock
import qualified Convert.Stream import qualified Convert.Stream
import qualified Convert.Struct import qualified Convert.Struct
import qualified Convert.TFBlock
import qualified Convert.Typedef import qualified Convert.Typedef
import qualified Convert.TypeOf import qualified Convert.TypeOf
import qualified Convert.UnbasedUnsized import qualified Convert.UnbasedUnsized
...@@ -73,9 +73,9 @@ phases excludes = ...@@ -73,9 +73,9 @@ phases excludes =
, Convert.SizeCast.convert , Convert.SizeCast.convert
, Convert.Simplify.convert , Convert.Simplify.convert
, Convert.StarPort.convert , Convert.StarPort.convert
, Convert.StmtBlock.convert
, Convert.Stream.convert , Convert.Stream.convert
, Convert.Struct.convert , Convert.Struct.convert
, Convert.TFBlock.convert
, Convert.Typedef.convert , Convert.Typedef.convert
, Convert.UnbasedUnsized.convert , Convert.UnbasedUnsized.convert
, Convert.Unique.convert , Convert.Unique.convert
......
{- sv2v {- sv2v
- Author: Zachary Snow <zach@zachjs.com> - Author: Zachary Snow <zach@zachjs.com>
- -
- Conversion for tasks and functions to use only one statement, as required in - Conversion for tasks and functions to contain only one top-level statement,
- Verilog-2005. - as required in Verilog-2005. This conversion also hoists data declarations to
- the task or function level for greater portability.
-} -}
module Convert.StmtBlock (convert) where module Convert.TFBlock (convert) where
import Data.List (isPrefixOf)
import Convert.Traverse import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
...@@ -20,11 +23,33 @@ convertModuleItem other = other ...@@ -20,11 +23,33 @@ convertModuleItem other = other
convertPackageItem :: PackageItem -> PackageItem convertPackageItem :: PackageItem -> PackageItem
convertPackageItem (Function ml t f decls stmts) = convertPackageItem (Function ml t f decls stmts) =
Function ml t f decls [stmtsToStmt stmts] Function ml t f decls' stmts'
where (decls', stmts') = convertTFBlock decls stmts
convertPackageItem (Task ml f decls stmts) = convertPackageItem (Task ml f decls stmts) =
Task ml f decls [stmtsToStmt stmts] Task ml f decls' stmts'
where (decls', stmts') = convertTFBlock decls stmts
convertPackageItem other = other convertPackageItem other = other
convertTFBlock :: [Decl] -> [Stmt] -> ([Decl], [Stmt])
convertTFBlock decls stmts =
(decls', [stmtsToStmt stmts'])
where (decls', stmts') = flattenOuterBlocks $ Block Seq "" decls stmts
stmtsToStmt :: [Stmt] -> Stmt stmtsToStmt :: [Stmt] -> Stmt
stmtsToStmt [stmt] = stmt stmtsToStmt [stmt] = stmt
stmtsToStmt stmts = Block Seq "" [] stmts stmtsToStmt stmts = Block Seq "" [] stmts
flattenOuterBlocks :: Stmt -> ([Decl], [Stmt])
flattenOuterBlocks (Block Seq "" declsA [stmt]) =
(declsA ++ declsB, stmtsB)
where (declsB, stmtsB) = flattenOuterBlocks stmt
flattenOuterBlocks (Block Seq "" declsA (Block Seq name declsB stmtsA : stmtsB)) =
flattenOuterBlocks $ Block Seq name (declsA ++ declsB) (stmtsA ++ stmtsB)
flattenOuterBlocks (Block Seq name decls stmts)
| notscope name = (decls, stmts)
| otherwise = ([], [Block Seq name decls stmts])
flattenOuterBlocks stmt = ([], [stmt])
notscope :: Identifier -> Bool
notscope "" = True
notscope name = "sv2v_autoblock_" `isPrefixOf` name
...@@ -86,9 +86,9 @@ executable sv2v ...@@ -86,9 +86,9 @@ executable sv2v
Convert.Simplify Convert.Simplify
Convert.SizeCast Convert.SizeCast
Convert.StarPort Convert.StarPort
Convert.StmtBlock
Convert.Stream Convert.Stream
Convert.Struct Convert.Struct
Convert.TFBlock
Convert.Traverse Convert.Traverse
Convert.Typedef Convert.Typedef
Convert.TypeOf Convert.TypeOf
......
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