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