Commit 925f11cf by Zachary Snow

expression traversal visits LHS range and bit expressions

parent 04983b0c
...@@ -206,17 +206,16 @@ convertAsgn structs types (lhs, expr) = ...@@ -206,17 +206,16 @@ convertAsgn structs types (lhs, expr) =
convertLHS (LHSBit l e) = convertLHS (LHSBit l e) =
case l' of case l' of
LHSRange lInner NonIndexed (_, loI) -> LHSRange lInner NonIndexed (_, loI) ->
(t', LHSBit lInner (simplify $ BinOp Add loI e')) (t', LHSBit lInner (simplify $ BinOp Add loI e))
LHSRange lInner IndexedPlus (baseI, _) -> LHSRange lInner IndexedPlus (baseI, _) ->
(t', LHSBit lInner (simplify $ BinOp Add baseI e')) (t', LHSBit lInner (simplify $ BinOp Add baseI e))
_ -> (t', LHSBit l' e') _ -> (t', LHSBit l' e)
where where
(t, l') = convertLHS l (t, l') = convertLHS l
t' = case typeRanges t of t' = case typeRanges t of
(_, []) -> Implicit Unspecified [] (_, []) -> Implicit Unspecified []
(tf, rs) -> tf $ tail rs (tf, rs) -> tf $ tail rs
e' = snd $ convertSubExpr e convertLHS (LHSRange lOuter NonIndexed rOuter) =
convertLHS (LHSRange lOuter NonIndexed rOuterOrig) =
case lOuter' of case lOuter' of
LHSRange lInner NonIndexed (_, loI) -> LHSRange lInner NonIndexed (_, loI) ->
(t, LHSRange lInner NonIndexed (simplify hi, simplify lo)) (t, LHSRange lInner NonIndexed (simplify hi, simplify lo))
...@@ -230,16 +229,11 @@ convertAsgn structs types (lhs, expr) = ...@@ -230,16 +229,11 @@ convertAsgn structs types (lhs, expr) =
len = rangeSize rOuter len = rangeSize rOuter
_ -> (t, LHSRange lOuter' NonIndexed rOuter) _ -> (t, LHSRange lOuter' NonIndexed rOuter)
where where
hiO = snd $ convertSubExpr $ fst rOuterOrig (hiO, loO) = rOuter
loO = snd $ convertSubExpr $ snd rOuterOrig
rOuter = (hiO, loO)
(t, lOuter') = convertLHS lOuter (t, lOuter') = convertLHS lOuter
convertLHS (LHSRange l m r) = convertLHS (LHSRange l m r) =
(t', LHSRange l' m r') (t', LHSRange l' m r)
where where
hi = snd $ convertSubExpr $ fst r
lo = snd $ convertSubExpr $ snd r
r' = (hi, lo)
(t, l') = convertLHS l (t, l') = convertLHS l
t' = case typeRanges t of t' = case typeRanges t of
(_, []) -> Implicit Unspecified [] (_, []) -> Implicit Unspecified []
......
...@@ -200,7 +200,7 @@ traverseNestedStmtsM mapper = fullMapper ...@@ -200,7 +200,7 @@ traverseNestedStmtsM mapper = fullMapper
where where
fullMapper stmt = mapper stmt >>= traverseSinglyNestedStmtsM fullMapper fullMapper stmt = mapper stmt >>= traverseSinglyNestedStmtsM fullMapper
-- variant of the above which only traverse one level down -- variant of the above which only traverses one level down
traverseSinglyNestedStmtsM :: Monad m => MapperM m Stmt -> MapperM m Stmt traverseSinglyNestedStmtsM :: Monad m => MapperM m Stmt -> MapperM m Stmt
traverseSinglyNestedStmtsM fullMapper = cs traverseSinglyNestedStmtsM fullMapper = cs
where where
...@@ -447,9 +447,9 @@ traverseNestedExprsM mapper = exprMapper ...@@ -447,9 +447,9 @@ traverseNestedExprsM mapper = exprMapper
return $ Pattern $ zip names exprs return $ Pattern $ zip names exprs
exprMapperHelpers :: Monad m => MapperM m Expr -> exprMapperHelpers :: Monad m => MapperM m Expr ->
(MapperM m Range, MapperM m (Maybe Expr), MapperM m Decl) (MapperM m Range, MapperM m (Maybe Expr), MapperM m Decl, MapperM m LHS)
exprMapperHelpers exprMapper = exprMapperHelpers exprMapper =
(rangeMapper, maybeExprMapper, declMapper) (rangeMapper, maybeExprMapper, declMapper, traverseNestedLHSsM lhsMapper)
where where
rangeMapper (a, b) = do rangeMapper (a, b) = do
...@@ -473,11 +473,17 @@ exprMapperHelpers exprMapper = ...@@ -473,11 +473,17 @@ exprMapperHelpers exprMapper =
me' <- maybeExprMapper me me' <- maybeExprMapper me
return $ Variable d t' x a' me' return $ Variable d t' x a' me'
lhsMapper (LHSRange l m r) =
rangeMapper r >>= return . LHSRange l m
lhsMapper (LHSBit l e) =
exprMapper e >>= return . LHSBit l
lhsMapper other = return other
traverseExprsM' :: Monad m => TFStrategy -> MapperM m Expr -> MapperM m ModuleItem traverseExprsM' :: Monad m => TFStrategy -> MapperM m Expr -> MapperM m ModuleItem
traverseExprsM' strat exprMapper = moduleItemMapper traverseExprsM' strat exprMapper = moduleItemMapper
where where
(rangeMapper, maybeExprMapper, declMapper) (rangeMapper, maybeExprMapper, declMapper, lhsMapper)
= exprMapperHelpers exprMapper = exprMapperHelpers exprMapper
stmtMapper = traverseNestedStmtsM (traverseStmtExprsM exprMapper) stmtMapper = traverseNestedStmtsM (traverseStmtExprsM exprMapper)
...@@ -490,16 +496,19 @@ traverseExprsM' strat exprMapper = moduleItemMapper ...@@ -490,16 +496,19 @@ traverseExprsM' strat exprMapper = moduleItemMapper
return $ MIAttr attr mi return $ MIAttr attr mi
moduleItemMapper (MIDecl decl) = moduleItemMapper (MIDecl decl) =
declMapper decl >>= return . MIDecl declMapper decl >>= return . MIDecl
moduleItemMapper (Defparam lhs expr) = moduleItemMapper (Defparam lhs expr) = do
exprMapper expr >>= return . Defparam lhs lhs' <- lhsMapper lhs
expr' <- exprMapper expr
return $ Defparam lhs' expr'
moduleItemMapper (AlwaysC kw stmt) = moduleItemMapper (AlwaysC kw stmt) =
stmtMapper stmt >>= return . AlwaysC kw stmtMapper stmt >>= return . AlwaysC kw
moduleItemMapper (Initial stmt) = moduleItemMapper (Initial stmt) =
stmtMapper stmt >>= return . Initial stmtMapper stmt >>= return . Initial
moduleItemMapper (Assign delay lhs expr) = do moduleItemMapper (Assign delay lhs expr) = do
delay' <- maybeExprMapper delay delay' <- maybeExprMapper delay
lhs' <- lhsMapper lhs
expr' <- exprMapper expr expr' <- exprMapper expr
return $ Assign delay' lhs expr' return $ Assign delay' lhs' expr'
moduleItemMapper (MIPackageItem (Function lifetime ret f decls stmts)) = do moduleItemMapper (MIPackageItem (Function lifetime ret f decls stmts)) = do
decls' <- decls' <-
if strat == IncludeTFs if strat == IncludeTFs
...@@ -529,9 +538,12 @@ traverseExprsM' strat exprMapper = moduleItemMapper ...@@ -529,9 +538,12 @@ traverseExprsM' strat exprMapper = moduleItemMapper
mapM modportDeclMapper l >>= return . Modport x mapM modportDeclMapper l >>= return . Modport x
moduleItemMapper (NInputGate kw x lhs exprs) = do moduleItemMapper (NInputGate kw x lhs exprs) = do
exprs' <- mapM exprMapper exprs exprs' <- mapM exprMapper exprs
return $ NInputGate kw x lhs exprs' lhs' <- lhsMapper lhs
moduleItemMapper (NOutputGate kw x lhss expr) = return $ NInputGate kw x lhs' exprs'
exprMapper expr >>= return . NOutputGate kw x lhss moduleItemMapper (NOutputGate kw x lhss expr) = do
lhss' <- mapM lhsMapper lhss
expr' <- exprMapper expr
return $ NOutputGate kw x lhss' expr'
moduleItemMapper (Genvar x) = return $ Genvar x moduleItemMapper (Genvar x) = return $ Genvar x
moduleItemMapper (Generate items) = do moduleItemMapper (Generate items) = do
items' <- mapM (traverseNestedGenItemsM genItemMapper) items items' <- mapM (traverseNestedGenItemsM genItemMapper) items
...@@ -581,7 +593,7 @@ traverseStmtExprsM :: Monad m => MapperM m Expr -> MapperM m Stmt ...@@ -581,7 +593,7 @@ traverseStmtExprsM :: Monad m => MapperM m Expr -> MapperM m Stmt
traverseStmtExprsM exprMapper = flatStmtMapper traverseStmtExprsM exprMapper = flatStmtMapper
where where
(_, maybeExprMapper, declMapper) (_, maybeExprMapper, declMapper, lhsMapper)
= exprMapperHelpers exprMapper = exprMapperHelpers exprMapper
caseMapper (exprs, stmt) = do caseMapper (exprs, stmt) = do
...@@ -598,10 +610,14 @@ traverseStmtExprsM exprMapper = flatStmtMapper ...@@ -598,10 +610,14 @@ traverseStmtExprsM exprMapper = flatStmtMapper
e' <- exprMapper e e' <- exprMapper e
cases' <- mapM caseMapper cases cases' <- mapM caseMapper cases
return $ Case u kw e' cases' def return $ Case u kw e' cases' def
flatStmtMapper (AsgnBlk op lhs expr) = flatStmtMapper (AsgnBlk op lhs expr) = do
exprMapper expr >>= return . AsgnBlk op lhs lhs' <- lhsMapper lhs
flatStmtMapper (Asgn mt lhs expr) = expr' <- exprMapper expr
exprMapper expr >>= return . Asgn mt lhs return $ AsgnBlk op lhs' expr'
flatStmtMapper (Asgn mt lhs expr) = do
lhs' <- lhsMapper lhs
expr' <- exprMapper expr
return $ Asgn mt lhs' expr'
flatStmtMapper (For inits cc asgns stmt) = do flatStmtMapper (For inits cc asgns stmt) = do
inits' <- mapM initMapper inits inits' <- mapM initMapper inits
cc' <- maybeExprMapper cc cc' <- maybeExprMapper cc
...@@ -793,7 +809,12 @@ collectGenItemsM = collectify traverseGenItemsM ...@@ -793,7 +809,12 @@ collectGenItemsM = collectify traverseGenItemsM
traverseNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem traverseNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem
traverseNestedGenItemsM mapper = fullMapper traverseNestedGenItemsM mapper = fullMapper
where where
fullMapper genItem = gim genItem >>= mapper fullMapper stmt =
mapper stmt >>= traverseSinglyNestedGenItemsM fullMapper
traverseSinglyNestedGenItemsM :: Monad m => MapperM m GenItem -> MapperM m GenItem
traverseSinglyNestedGenItemsM fullMapper = gim
where
gim (GenBlock x subItems) = do gim (GenBlock x subItems) = do
subItems' <- mapM fullMapper subItems subItems' <- mapM fullMapper subItems
return $ GenBlock x (concatMap flattenBlocks subItems') return $ GenBlock x (concatMap flattenBlocks subItems')
......
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