mirror of https://github.com/zachjs/sv2v.git
split phases into sections
This commit is contained in:
parent
5c2632982e
commit
d847fdfaca
|
|
@ -51,15 +51,19 @@ import qualified Convert.Unsigned
|
|||
import qualified Convert.Wildcard
|
||||
|
||||
type Phase = [AST] -> [AST]
|
||||
type Selector = Job.Exclude -> Phase -> Phase
|
||||
|
||||
phases :: [Job.Exclude] -> [Phase]
|
||||
phases excludes =
|
||||
[ Convert.AsgnOp.convert
|
||||
, Convert.NamedBlock.convert
|
||||
, selectExclude (Job.Assert , Convert.Assertion.convert)
|
||||
, Convert.BlockDecl.convert
|
||||
finalPhases :: Selector -> [Phase]
|
||||
finalPhases _ =
|
||||
[ Convert.NamedBlock.convert
|
||||
, Convert.DuplicateGenvar.convert
|
||||
, selectExclude (Job.Logic , Convert.Logic.convert)
|
||||
]
|
||||
|
||||
mainPhases :: Selector -> [Phase]
|
||||
mainPhases selectExclude =
|
||||
[ Convert.AsgnOp.convert
|
||||
, Convert.BlockDecl.convert
|
||||
, selectExclude Job.Logic Convert.Logic.convert
|
||||
, Convert.FuncRet.convert
|
||||
, Convert.FuncRoutine.convert
|
||||
, Convert.EmptyArgs.convert
|
||||
|
|
@ -67,7 +71,6 @@ phases excludes =
|
|||
, Convert.Inside.convert
|
||||
, Convert.IntTypes.convert
|
||||
, Convert.KWArgs.convert
|
||||
, Convert.LogOp.convert
|
||||
, Convert.MultiplePacked.convert
|
||||
, Convert.UnbasedUnsized.convert
|
||||
, Convert.Cast.convert
|
||||
|
|
@ -79,39 +82,45 @@ phases excludes =
|
|||
, Convert.Struct.convert
|
||||
, Convert.TFBlock.convert
|
||||
, Convert.Typedef.convert
|
||||
, Convert.Unique.convert
|
||||
, Convert.UnpackedArray.convert
|
||||
, Convert.Unsigned.convert
|
||||
, Convert.Wildcard.convert
|
||||
, Convert.Enum.convert
|
||||
, Convert.ForDecl.convert
|
||||
, Convert.Jump.convert
|
||||
, Convert.Foreach.convert
|
||||
, Convert.StringParam.convert
|
||||
, selectExclude (Job.Interface, Convert.Interface.convert)
|
||||
, Convert.StarPort.convert
|
||||
, selectExclude (Job.Always , Convert.AlwaysKW.convert)
|
||||
, selectExclude (Job.Succinct , Convert.RemoveComments.convert)
|
||||
, selectExclude Job.Interface Convert.Interface.convert
|
||||
, selectExclude Job.Succinct Convert.RemoveComments.convert
|
||||
]
|
||||
where
|
||||
selectExclude :: (Job.Exclude, Phase) -> Phase
|
||||
selectExclude (exclude, phase) =
|
||||
if elem exclude excludes
|
||||
then id
|
||||
else phase
|
||||
|
||||
run :: [Job.Exclude] -> Phase
|
||||
run excludes = foldr (.) id $ phases excludes
|
||||
initialPhases :: Selector -> [Phase]
|
||||
initialPhases selectExclude =
|
||||
[ Convert.Jump.convert
|
||||
, Convert.Unique.convert
|
||||
, Convert.LogOp.convert
|
||||
, Convert.Foreach.convert
|
||||
, Convert.StarPort.convert
|
||||
, selectExclude Job.Assert Convert.Assertion.convert
|
||||
, selectExclude Job.Always Convert.AlwaysKW.convert
|
||||
, Convert.Package.convert
|
||||
, Convert.ParamNoDefault.convert
|
||||
]
|
||||
|
||||
convert :: [Job.Exclude] -> Phase
|
||||
convert excludes =
|
||||
convert'
|
||||
. Convert.Package.convert
|
||||
. Convert.ParamNoDefault.convert
|
||||
final . loopMain . initial
|
||||
where
|
||||
convert' :: Phase
|
||||
convert' descriptions =
|
||||
final = combine $ finalPhases selectExclude
|
||||
main = combine $ mainPhases selectExclude
|
||||
initial = combine $ initialPhases selectExclude
|
||||
combine = foldr1 (.)
|
||||
loopMain :: Phase
|
||||
loopMain descriptions =
|
||||
if descriptions == descriptions'
|
||||
then descriptions
|
||||
else convert' descriptions'
|
||||
where descriptions' = run excludes descriptions
|
||||
else loopMain descriptions'
|
||||
where descriptions' = main descriptions
|
||||
selectExclude :: Selector
|
||||
selectExclude exclude phase =
|
||||
if elem exclude excludes
|
||||
then id
|
||||
else phase
|
||||
|
|
|
|||
|
|
@ -139,9 +139,8 @@ convertStmt (Block Par x decls stmts) = do
|
|||
modify $ \s -> s { sJumpAllowed = jumpAllowed, sReturnAllowed = returnAllowed }
|
||||
return $ Block Par x decls stmts'
|
||||
|
||||
convertStmt (Block Seq x decls stmts) = do
|
||||
stmts' <- step stmts
|
||||
return $ Block Seq x decls $ filter (/= Null) stmts'
|
||||
convertStmt (Block Seq x decls stmts) =
|
||||
step stmts >>= return . Block Seq x decls
|
||||
where
|
||||
step :: [Stmt] -> State Info [Stmt]
|
||||
step [] = return []
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ traverseModuleItem ports scopes =
|
|||
Just (_, _, t) -> tell [isRegType t]
|
||||
_ -> tell [False]
|
||||
|
||||
always_comb = AlwaysC Always . Timing (Event SenseStar)
|
||||
|
||||
fixModuleItem :: ModuleItem -> ModuleItem
|
||||
-- rewrite bad continuous assignments to use procedural assignments
|
||||
fixModuleItem (Assign AssignOptionNone lhs expr) =
|
||||
|
|
@ -112,7 +114,7 @@ traverseModuleItem ports scopes =
|
|||
Generate $ map GenModuleItem
|
||||
[ MIPackageItem (Decl (Variable Local t x [] Nil))
|
||||
, Assign AssignOptionNone (LHSIdent x) expr
|
||||
, AlwaysC AlwaysComb $ Asgn AsgnOpEq Nothing lhs (Ident x)
|
||||
, always_comb $ Asgn AsgnOpEq Nothing lhs (Ident x)
|
||||
]
|
||||
where
|
||||
t = Net (NetType TWire) Unspecified
|
||||
|
|
@ -146,7 +148,7 @@ traverseModuleItem ports scopes =
|
|||
[(DimsFn FnBits $ Right expr, RawNum 1)]
|
||||
items =
|
||||
[ MIPackageItem $ Decl $ Variable Local t tmp [] Nil
|
||||
, AlwaysC AlwaysComb $ Asgn AsgnOpEq Nothing lhs tmpExpr]
|
||||
, always_comb $ Asgn AsgnOpEq Nothing lhs tmpExpr]
|
||||
lhs = case exprToLHS expr of
|
||||
Just l -> l
|
||||
Nothing ->
|
||||
|
|
|
|||
|
|
@ -45,8 +45,10 @@ convertPackageItem other = other
|
|||
convertStmt :: Stmt -> Stmt
|
||||
convertStmt (CommentStmt _) = Null
|
||||
convertStmt (Block kw name decls stmts) =
|
||||
Block kw name decls' stmts
|
||||
where decls' = convertDecls decls
|
||||
Block kw name decls' stmts'
|
||||
where
|
||||
decls' = convertDecls decls
|
||||
stmts' = filter (/= Null) stmts
|
||||
convertStmt (For (Left decls) cond incr stmt) =
|
||||
For (Left decls') cond incr stmt
|
||||
where decls' = convertDecls decls
|
||||
|
|
|
|||
Loading…
Reference in New Issue