Commit 57ef23ef by Zachary Snow

fewer conversion phases in main loop

- moved 4 phases to initial set and 3 to final set
- fix synthetic unnamed genblocks preventing name resolution
- asgnop conversion folds in unisub when possible
parent a2b99fa9
......@@ -59,20 +59,18 @@ finalPhases :: Selector -> [Phase]
finalPhases _ =
[ Convert.NamedBlock.convert
, Convert.DuplicateGenvar.convert
, Convert.AsgnOp.convert
, Convert.FuncRet.convert
, Convert.TFBlock.convert
]
mainPhases :: Selector -> [Phase]
mainPhases selectExclude =
[ Convert.AsgnOp.convert
, Convert.BlockDecl.convert
[ Convert.BlockDecl.convert
, selectExclude Job.Logic Convert.Logic.convert
, Convert.FuncRet.convert
, Convert.FuncRoutine.convert
, Convert.EmptyArgs.convert
, Convert.ImplicitNet.convert
, Convert.Inside.convert
, Convert.IntTypes.convert
, Convert.KWArgs.convert
, Convert.MultiplePacked.convert
, Convert.UnbasedUnsized.convert
, Convert.Cast.convert
......@@ -83,13 +81,11 @@ mainPhases selectExclude =
, Convert.Simplify.convert
, Convert.Stream.convert
, Convert.Struct.convert
, Convert.TFBlock.convert
, Convert.Typedef.convert
, Convert.UnpackedArray.convert
, Convert.Unsigned.convert
, Convert.Wildcard.convert
, Convert.Enum.convert
, Convert.ForAsgn.convert
, Convert.StringParam.convert
, selectExclude Job.Interface Convert.Interface.convert
, selectExclude Job.Succinct Convert.RemoveComments.convert
......@@ -97,10 +93,14 @@ mainPhases selectExclude =
initialPhases :: Selector -> [Phase]
initialPhases selectExclude =
[ Convert.Jump.convert
[ Convert.ForAsgn.convert
, Convert.Jump.convert
, Convert.KWArgs.convert
, Convert.Unique.convert
, Convert.LogOp.convert
, Convert.EmptyArgs.convert
, Convert.Foreach.convert
, Convert.FuncRoutine.convert
, selectExclude Job.Assert Convert.Assertion.convert
, selectExclude Job.Always Convert.AlwaysKW.convert
, Convert.Package.convert
......
......@@ -20,7 +20,7 @@ convert =
convertGenItem :: GenItem -> GenItem
convertGenItem (GenFor a b (ident, AsgnOp op, expr) c) =
GenFor a b (ident, AsgnOpEq, BinOp op (Ident ident) expr) c
GenFor a b (ident, AsgnOpEq, elabBinOp op (Ident ident) expr) c
convertGenItem other = other
convertStmt :: Stmt -> Stmt
......@@ -30,8 +30,13 @@ convertStmt (For inits cc asgns stmt) =
asgns' = map convertAsgn asgns
convertAsgn :: (LHS, AsgnOp, Expr) -> (LHS, AsgnOp, Expr)
convertAsgn (lhs, AsgnOp op, expr) =
(lhs, AsgnOpEq, BinOp op (lhsToExpr lhs) expr)
(lhs, AsgnOpEq, elabBinOp op (lhsToExpr lhs) expr)
convertAsgn other = other
convertStmt (Asgn (AsgnOp op) mt lhs expr) =
Asgn AsgnOpEq mt lhs (BinOp op (lhsToExpr lhs) expr)
Asgn AsgnOpEq mt lhs (elabBinOp op (lhsToExpr lhs) expr)
convertStmt other = other
elabBinOp :: BinOp -> Expr -> Expr -> Expr
elabBinOp Add e1 (UniOp UniSub e2) = BinOp Sub e1 e2
elabBinOp Sub e1 (UniOp UniSub e2) = BinOp Add e1 e2
elabBinOp op e1 e2 = BinOp op e1 e2
......@@ -532,7 +532,8 @@ scopeModuleItemT declMapper moduleItemMapper genItemMapper stmtMapper =
injected' <- mapM fullModuleItemMapper injected
genItem'' <- scopeGenItemMapper genItem'
let genItems = map GenModuleItem injected' ++ [genItem'']
return $ GenBlock "" genItems -- flattened during traversal
-- flattened during traversal
return $ GenModuleItem $ Generate genItems
scopeGenItemMapper :: GenItem -> ScoperT a m GenItem
scopeGenItemMapper (GenFor (index, a) b c genItem) = do
genItem' <- scopeGenItemBranchMapper index genItem
......
......@@ -1016,7 +1016,7 @@ traverseNestedGenItems :: Mapper GenItem -> Mapper GenItem
traverseNestedGenItems = unmonad traverseNestedGenItemsM
flattenGenBlocks :: GenItem -> [GenItem]
flattenGenBlocks (GenBlock "" items) = items
flattenGenBlocks (GenModuleItem (Generate items)) = items
flattenGenBlocks (GenFor _ _ _ GenNull) = []
flattenGenBlocks GenNull = []
flattenGenBlocks other = [other]
......@@ -1087,18 +1087,14 @@ traverseNestedModuleItemsM mapper = fullMapper
fullMapper (Initial Null) = return $ Generate []
fullMapper other = mapper other
fullGenItemMapper = traverseNestedGenItemsM genItemMapper
genItemMapper (GenModuleItem moduleItem) = do
moduleItem' <- fullMapper moduleItem
return $ case moduleItem' of
Generate subItems -> GenBlock "" subItems
_ -> GenModuleItem moduleItem'
genItemMapper (GenModuleItem moduleItem) =
fullMapper moduleItem >>= return . GenModuleItem
genItemMapper (GenIf _ GenNull GenNull) = return GenNull
genItemMapper (GenIf (Number n) s1 s2) = do
case numberToInteger n of
Nothing -> return $ GenIf (Number n) s1 s2
Just 0 -> genItemMapper s2
Just _ -> genItemMapper s1
genItemMapper (GenBlock "" [item]) = genItemMapper item
genItemMapper (GenBlock _ []) = return GenNull
genItemMapper other = return other
......
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