simplify shadowing notes non-trivial localparams too

This commit is contained in:
Zachary Snow 2023-08-08 22:30:36 -04:00
parent 5b035613ee
commit b09fdaf76a
3 changed files with 16 additions and 6 deletions

View File

@ -12,6 +12,7 @@
### Bug Fixes
* Fixed an issue that prevented parsing tasks and functions with `inout` ports
* Fixed errant constant folding of shadowed non-trivial localparams
* Fixed certain non-ANSI style port declarations being incorrectly reported as
incompatible

View File

@ -17,8 +17,6 @@
module Convert.Simplify (convert) where
import Control.Monad (when)
import Convert.ExprUtils
import Convert.Scoper
import Convert.Traverse
@ -53,13 +51,14 @@ pattern SimpleVector sg l r <- IntegerVector _ sg [(RawNum l, RawNum r)]
insertExpr :: Identifier -> Expr -> Scoper Expr ()
insertExpr ident expr = do
expr' <- substituteExprM expr
case expr' of
insertElem ident $ case expr' of
Cast (Left (SimpleVector sg l r)) (Number n) ->
insertElem ident $ Number $ numberCast signed size n
Number $ numberCast signed size n
where
signed = sg == Signed
size = fromIntegral $ abs $ l - r + 1
_ -> when (isSimpleExpr expr') $ insertElem ident expr'
_ | isSimpleExpr expr' -> expr'
_ -> Nil
isSimpleExpr :: Expr -> Bool
isSimpleExpr Number{} = True
@ -84,7 +83,7 @@ traverseGenItemM :: GenItem -> Scoper Expr GenItem
traverseGenItemM = traverseGenItemExprsM traverseExprM
traverseStmtM :: Stmt -> Scoper Expr Stmt
traverseStmtM stmt = traverseStmtExprsM traverseExprM stmt
traverseStmtM = traverseStmtExprsM traverseExprM
traverseExprM :: Expr -> Scoper Expr Expr
traverseExprM = embedScopes convertExpr

View File

@ -0,0 +1,10 @@
module top;
localparam i = 1234;
if (1) begin
genvar j;
for (j = 0; j < 10; j = j + 1) begin
localparam i = j;
initial $display(i > 5 ? i + 100 : i - 100);
end
end
endmodule