From d847fdfacab53ccb8526ca7a3642f1516b44795e Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Mon, 8 Feb 2021 12:42:34 -0500 Subject: [PATCH] split phases into sections --- src/Convert.hs | 69 ++++++++++++++++++++--------------- src/Convert/Jump.hs | 5 +-- src/Convert/Logic.hs | 6 ++- src/Convert/RemoveComments.hs | 6 ++- 4 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/Convert.hs b/src/Convert.hs index 1cf2fcd..41d59ee 100644 --- a/src/Convert.hs +++ b/src/Convert.hs @@ -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 diff --git a/src/Convert/Jump.hs b/src/Convert/Jump.hs index 67dfb4c..cf83ee3 100644 --- a/src/Convert/Jump.hs +++ b/src/Convert/Jump.hs @@ -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 [] diff --git a/src/Convert/Logic.hs b/src/Convert/Logic.hs index 925964f..02c6688 100644 --- a/src/Convert/Logic.hs +++ b/src/Convert/Logic.hs @@ -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 -> diff --git a/src/Convert/RemoveComments.hs b/src/Convert/RemoveComments.hs index f8ce19f..86856c0 100644 --- a/src/Convert/RemoveComments.hs +++ b/src/Convert/RemoveComments.hs @@ -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