aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/ast
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2020-12-26 08:39:57 -0700
committerZachary Snow <zach@zachjs.com>2020-12-26 08:48:01 -0700
commit1419c8761cc7594f56855546a633f8bdf0e3ebca (patch)
treec002566f1988d5f5a6bea7fc11bcc9edb64d656e /frontends/ast
parent449154803737f45406f711d965113536bc8ae818 (diff)
downloadyosys-1419c8761cc7594f56855546a633f8bdf0e3ebca.tar.gz
yosys-1419c8761cc7594f56855546a633f8bdf0e3ebca.tar.bz2
yosys-1419c8761cc7594f56855546a633f8bdf0e3ebca.zip
Fix constants bound to redeclared function args
The changes in #2476 ensured that function inputs like `input x;` retained their single-bit size when instantiated with a constant argument and turned into a localparam. That change did not handle the possibility for an input to be redeclared later on with an explicit width, such as `integer x;`.
Diffstat (limited to 'frontends/ast')
-rw-r--r--frontends/ast/simplify.cc21
1 files changed, 16 insertions, 5 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index 5fa4ac83b..c6d63f247 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -3344,11 +3344,22 @@ skip_dynamic_range_lvalue_expansion:;
wire->children.insert(wire->children.begin(), arg->clone());
// args without a range implicitly have width 1
if (wire->children.back()->type != AST_RANGE) {
- AstNode* range = new AstNode();
- range->type = AST_RANGE;
- wire->children.push_back(range);
- range->children.push_back(mkconst_int(0, true));
- range->children.push_back(mkconst_int(0, true));
+ // check if this wire is redeclared with an explicit size
+ bool uses_explicit_size = false;
+ for (const AstNode *other_child : decl->children)
+ if (other_child->type == AST_WIRE && child->str == other_child->str
+ && !other_child->children.empty()
+ && other_child->children.back()->type == AST_RANGE) {
+ uses_explicit_size = true;
+ break;
+ }
+ if (!uses_explicit_size) {
+ AstNode* range = new AstNode();
+ range->type = AST_RANGE;
+ wire->children.push_back(range);
+ range->children.push_back(mkconst_int(0, true));
+ range->children.push_back(mkconst_int(0, true));
+ }
}
continue;
}