mirror of https://github.com/zachjs/sv2v.git
simplify shadowing notes non-trivial localparams too
This commit is contained in:
parent
5b035613ee
commit
b09fdaf76a
|
|
@ -12,6 +12,7 @@
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
* Fixed an issue that prevented parsing tasks and functions with `inout` ports
|
* 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
|
* Fixed certain non-ANSI style port declarations being incorrectly reported as
|
||||||
incompatible
|
incompatible
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
module Convert.Simplify (convert) where
|
module Convert.Simplify (convert) where
|
||||||
|
|
||||||
import Control.Monad (when)
|
|
||||||
|
|
||||||
import Convert.ExprUtils
|
import Convert.ExprUtils
|
||||||
import Convert.Scoper
|
import Convert.Scoper
|
||||||
import Convert.Traverse
|
import Convert.Traverse
|
||||||
|
|
@ -53,13 +51,14 @@ pattern SimpleVector sg l r <- IntegerVector _ sg [(RawNum l, RawNum r)]
|
||||||
insertExpr :: Identifier -> Expr -> Scoper Expr ()
|
insertExpr :: Identifier -> Expr -> Scoper Expr ()
|
||||||
insertExpr ident expr = do
|
insertExpr ident expr = do
|
||||||
expr' <- substituteExprM expr
|
expr' <- substituteExprM expr
|
||||||
case expr' of
|
insertElem ident $ case expr' of
|
||||||
Cast (Left (SimpleVector sg l r)) (Number n) ->
|
Cast (Left (SimpleVector sg l r)) (Number n) ->
|
||||||
insertElem ident $ Number $ numberCast signed size n
|
Number $ numberCast signed size n
|
||||||
where
|
where
|
||||||
signed = sg == Signed
|
signed = sg == Signed
|
||||||
size = fromIntegral $ abs $ l - r + 1
|
size = fromIntegral $ abs $ l - r + 1
|
||||||
_ -> when (isSimpleExpr expr') $ insertElem ident expr'
|
_ | isSimpleExpr expr' -> expr'
|
||||||
|
_ -> Nil
|
||||||
|
|
||||||
isSimpleExpr :: Expr -> Bool
|
isSimpleExpr :: Expr -> Bool
|
||||||
isSimpleExpr Number{} = True
|
isSimpleExpr Number{} = True
|
||||||
|
|
@ -84,7 +83,7 @@ traverseGenItemM :: GenItem -> Scoper Expr GenItem
|
||||||
traverseGenItemM = traverseGenItemExprsM traverseExprM
|
traverseGenItemM = traverseGenItemExprsM traverseExprM
|
||||||
|
|
||||||
traverseStmtM :: Stmt -> Scoper Expr Stmt
|
traverseStmtM :: Stmt -> Scoper Expr Stmt
|
||||||
traverseStmtM stmt = traverseStmtExprsM traverseExprM stmt
|
traverseStmtM = traverseStmtExprsM traverseExprM
|
||||||
|
|
||||||
traverseExprM :: Expr -> Scoper Expr Expr
|
traverseExprM :: Expr -> Scoper Expr Expr
|
||||||
traverseExprM = embedScopes convertExpr
|
traverseExprM = embedScopes convertExpr
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue