Commit 4c173d86 by Zachary Snow

transition simplify conversion to new scoper

parent a38137b6
...@@ -16,27 +16,25 @@ ...@@ -16,27 +16,25 @@
module Convert.Simplify (convert) where module Convert.Simplify (convert) where
import Control.Monad.State import Control.Monad (when)
import qualified Data.Map.Strict as Map
import Convert.ExprUtils import Convert.ExprUtils
import Convert.Scoper
import Convert.Traverse import Convert.Traverse
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
type Info = Map.Map Identifier Expr
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = map $ traverseDescriptions convertDescription convert = map $ traverseDescriptions convertDescription
convertDescription :: Description -> Description convertDescription :: Description -> Description
convertDescription = convertDescription =
scopedConversion traverseDeclM traverseModuleItemM traverseStmtM Map.empty partScoper traverseDeclM traverseModuleItemM traverseGenItemM traverseStmtM
traverseDeclM :: Decl -> State Info Decl traverseDeclM :: Decl -> Scoper Expr Decl
traverseDeclM decl = do traverseDeclM decl = do
case decl of case decl of
Param Localparam _ x e -> Param Localparam _ x e ->
when (isSimpleExpr e) $ modify $ Map.insert x e when (isSimpleExpr e) $ insertElem x e
_ -> return () _ -> return ()
let mi = MIPackageItem $ Decl decl let mi = MIPackageItem $ Decl decl
mi' <- traverseModuleItemM mi mi' <- traverseModuleItemM mi
...@@ -52,7 +50,7 @@ isSimpleExpr (Bit e _ ) = isSimpleExpr e ...@@ -52,7 +50,7 @@ isSimpleExpr (Bit e _ ) = isSimpleExpr e
isSimpleExpr (Range e _ _) = isSimpleExpr e isSimpleExpr (Range e _ _) = isSimpleExpr e
isSimpleExpr _ = False isSimpleExpr _ = False
traverseModuleItemM :: ModuleItem -> State Info ModuleItem traverseModuleItemM :: ModuleItem -> Scoper Expr ModuleItem
traverseModuleItemM (Instance m p x rs l) = do traverseModuleItemM (Instance m p x rs l) = do
p' <- mapM paramBindingMapper p p' <- mapM paramBindingMapper p
traverseExprsM traverseExprM $ Instance m p' x rs l traverseExprsM traverseExprM $ Instance m p' x rs l
...@@ -63,16 +61,19 @@ traverseModuleItemM (Instance m p x rs l) = do ...@@ -63,16 +61,19 @@ traverseModuleItemM (Instance m p x rs l) = do
paramBindingMapper (param, Right e) = return (param, Right e) paramBindingMapper (param, Right e) = return (param, Right e)
traverseModuleItemM item = traverseExprsM traverseExprM item traverseModuleItemM item = traverseExprsM traverseExprM item
traverseStmtM :: Stmt -> State Info Stmt traverseGenItemM :: GenItem -> Scoper Expr GenItem
traverseGenItemM = traverseGenItemExprsM traverseExprM
traverseStmtM :: Stmt -> Scoper Expr Stmt
traverseStmtM stmt = traverseStmtExprsM traverseExprM stmt traverseStmtM stmt = traverseStmtExprsM traverseExprM stmt
traverseExprM :: Expr -> State Info Expr traverseExprM :: Expr -> Scoper Expr Expr
traverseExprM = stately convertExpr traverseExprM = embedScopes convertExpr
substituteExprM :: Expr -> State Info Expr substituteExprM :: Expr -> Scoper Expr Expr
substituteExprM = stately substitute substituteExprM = embedScopes substitute
convertExpr :: Info -> Expr -> Expr convertExpr :: Scopes Expr -> Expr -> Expr
convertExpr info (Cast (Right c) e) = convertExpr info (Cast (Right c) e) =
Cast (Right c') e' Cast (Right c') e'
where where
...@@ -114,13 +115,13 @@ convertExpr info (Concat exprs) = ...@@ -114,13 +115,13 @@ convertExpr info (Concat exprs) =
convertExpr info expr = convertExpr info expr =
traverseSinglyNestedExprs (convertExpr info) expr traverseSinglyNestedExprs (convertExpr info) expr
substitute :: Info -> Expr -> Expr substitute :: Scopes Expr -> Expr -> Expr
substitute info expr = substitute scopes expr =
traverseNestedExprs substitute' expr traverseNestedExprs substitute' expr
where where
substitute' :: Expr -> Expr substitute' :: Expr -> Expr
substitute' (Ident x) = substitute' (Ident x) =
case Map.lookup x info of case lookupElem scopes x of
Nothing -> Ident x Nothing -> Ident x
Just e -> e Just (_, _, e) -> e
substitute' other = other substitute' other = 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