diff options
-rw-r--r-- | frontends/ast/simplify.cc | 12 | ||||
-rw-r--r-- | tests/various/const_func_block_var.v | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index bf375aa1b..0ba2ab6ac 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -4507,6 +4507,18 @@ AstNode *AstNode::eval_const_function(AstNode *fcall) log_assert(variables.count(str) != 0); + if (stmt->type == AST_LOCALPARAM) + { + while (stmt->simplify(true, false, false, 1, -1, false, true)) { } + + if (!backup_scope.count(stmt->str)) + backup_scope[stmt->str] = current_scope[stmt->str]; + current_scope[stmt->str] = stmt; + + block->children.erase(block->children.begin()); + continue; + } + if (stmt->type == AST_ASSIGN_EQ) { if (stmt->children.at(0)->type == AST_IDENTIFIER && stmt->children.at(0)->children.size() != 0 && diff --git a/tests/various/const_func_block_var.v b/tests/various/const_func_block_var.v index 98e83aa5b..cb60844ab 100644 --- a/tests/various/const_func_block_var.v +++ b/tests/various/const_func_block_var.v @@ -1,15 +1,18 @@ module top(out); function integer operation; input integer num; + localparam incr = 1; + localparam mult = 1; begin operation = 0; begin : op_i integer i; - for (i = 0; i < 2; i = i + 1) + for (i = 0; i * mult < 2; i = i + incr) begin : op_j integer j; - for (j = i; j < i * 2; j = j + 1) - num = num + 1; + localparam other_mult = 2; + for (j = i; j < i * other_mult; j = j + incr) + num = num + incr; end num = num * 2; end |