summaryrefslogtreecommitdiff
path: root/frontends/ast/simplify.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-02-26 13:18:22 +0100
committerClifford Wolf <clifford@clifford.at>2013-02-26 13:18:22 +0100
commit4f0c2862a0d7e1ca247e0a4d54301c7f8cc92fd8 (patch)
treeb1ecbcf2ff95ba1613b5aed85b7883d736c1c9fc /frontends/ast/simplify.cc
parent26a192b8c7ae959a38d58e971e78064c6f028ad1 (diff)
Added support for verilog genblock[index].member syntax
Diffstat (limited to 'frontends/ast/simplify.cc')
-rw-r--r--frontends/ast/simplify.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index cb8b1043..33776d65 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -103,7 +103,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage)
}
// activate const folding if this is anything that must be evaluated statically (ranges, parameters, attributes, etc.)
- if (type == AST_WIRE || type == AST_PARAMETER || type == AST_LOCALPARAM || type == AST_PARASET || type == AST_RANGE)
+ if (type == AST_WIRE || type == AST_PARAMETER || type == AST_LOCALPARAM || type == AST_PARASET || type == AST_RANGE || type == AST_PREFIX)
const_fold = true;
if (type == AST_IDENTIFIER && current_scope.count(str) > 0 && (current_scope[str]->type == AST_PARAMETER || current_scope[str]->type == AST_LOCALPARAM))
const_fold = true;
@@ -179,6 +179,8 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage)
break;
if (type == AST_GENIF && i >= 1)
break;
+ if (type == AST_PREFIX && i >= 1)
+ break;
while (did_something_here && i < children.size()) {
bool const_fold_here = const_fold, in_lvalue_here = in_lvalue;
if (i == 0 && type == AST_REPLICATE)
@@ -217,6 +219,18 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage)
if (type == AST_MODULE)
current_scope.clear();
+ // resolve constant prefixes
+ if (type == AST_PREFIX) {
+ if (children[0]->type != AST_CONSTANT) {
+ dumpAst(NULL, "> ", NULL);
+ log_error("Index in generate block prefix syntax at %s:%d is not constant!\n", filename.c_str(), linenum);
+ }
+ assert(children[1]->type == AST_IDENTIFIER);
+ newNode = children[1]->clone();
+ newNode->str = stringf("%s[%d].%s", str.c_str(), children[0]->integer, children[1]->str.c_str());
+ goto apply_newNode;
+ }
+
// annotate constant ranges
if (type == AST_RANGE) {
bool old_range_valid = range_valid;