Merge pull request #1681 from YosysHQ/eddie/fix1663

verilog: instead of modifying localparam size, extend init constant expr
This commit is contained in:
Claire Wolf 2020-03-03 08:34:31 -08:00 committed by GitHub
commit 91892465e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 15 deletions

View File

@ -1324,17 +1324,23 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
if (varbuf->type != AST_CONSTANT) if (varbuf->type != AST_CONSTANT)
log_file_error(filename, linenum, "Right hand side of 1st expression of generate for-loop is not constant!\n"); 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); auto resolved = current_scope.at(init_ast->children[0]->str);
if (resolved->range_valid) { if (resolved->range_valid) {
varbuf->range_left = resolved->range_left; int const_size = varbuf->range_left - varbuf->range_right;
varbuf->range_right = resolved->range_right; int resolved_size = resolved->range_left - resolved->range_right;
varbuf->range_swapped = resolved->range_swapped; if (const_size < resolved_size) {
varbuf->range_valid = resolved->range_valid; 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]; AstNode *backup_scope_varbuf = current_scope[varbuf->str];
current_scope[varbuf->str] = varbuf; current_scope[varbuf->str] = varbuf;
@ -3159,14 +3165,6 @@ void AstNode::expand_genblock(std::string index_var, std::string prefix, std::ma
current_ast_mod->children.push_back(p); current_ast_mod->children.push_back(p);
str = p->str; str = p->str;
id2ast = p; 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;
}
} }
} }