aboutsummaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorEddie Hung <eddie@fpgeh.com>2020-02-05 17:19:42 -0800
committerEddie Hung <eddie@fpgeh.com>2020-02-05 17:19:42 -0800
commitfc33287bc1db3014ad0a0dbe554aeb8fca95ec86 (patch)
tree79d9fb41e49a52d13ce10aa0a0e2edd995ae8240 /frontends
parent505557e93e0263b7714bd37b274923a6369278f5 (diff)
downloadyosys-fc33287bc1db3014ad0a0dbe554aeb8fca95ec86.tar.gz
yosys-fc33287bc1db3014ad0a0dbe554aeb8fca95ec86.tar.bz2
yosys-fc33287bc1db3014ad0a0dbe554aeb8fca95ec86.zip
verilog: instead of modifying localparam size, extend init constant expr
Diffstat (limited to 'frontends')
-rw-r--r--frontends/ast/simplify.cc28
1 files changed, 13 insertions, 15 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index 8855d9954..36ae831b8 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -1200,17 +1200,23 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
if (varbuf->type != AST_CONSTANT)
log_file_error(filename, linenum, "Right hand side of 1st expression of generate for-loop is not constant!\n");
- varbuf = new AstNode(AST_LOCALPARAM, varbuf);
- varbuf->str = init_ast->children[0]->str;
-
auto resolved = current_scope.at(init_ast->children[0]->str);
if (resolved->range_valid) {
- varbuf->range_left = resolved->range_left;
- varbuf->range_right = resolved->range_right;
- varbuf->range_swapped = resolved->range_swapped;
- varbuf->range_valid = resolved->range_valid;
+ int const_size = varbuf->range_left - varbuf->range_right;
+ int resolved_size = resolved->range_left - resolved->range_right;
+ if (const_size < resolved_size) {
+ for (int i = const_size; i < resolved_size; i++)
+ varbuf->bits.push_back(resolved->is_signed ? varbuf->bits.back() : State::S0);
+ varbuf->range_left = resolved->range_left;
+ varbuf->range_right = resolved->range_right;
+ varbuf->range_swapped = resolved->range_swapped;
+ varbuf->range_valid = resolved->range_valid;
+ }
}
+ varbuf = new AstNode(AST_LOCALPARAM, varbuf);
+ varbuf->str = init_ast->children[0]->str;
+
AstNode *backup_scope_varbuf = current_scope[varbuf->str];
current_scope[varbuf->str] = varbuf;
@@ -3022,14 +3028,6 @@ void AstNode::expand_genblock(std::string index_var, std::string prefix, std::ma
current_ast_mod->children.push_back(p);
str = p->str;
id2ast = p;
-
- auto resolved = current_scope.at(index_var);
- if (resolved->range_valid) {
- p->range_left = resolved->range_left;
- p->range_right = resolved->range_right;
- p->range_swapped = resolved->range_swapped;
- p->range_valid = resolved->range_valid;
- }
}
}