summaryrefslogtreecommitdiff
path: root/frontends/ast
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/ast')
-rw-r--r--frontends/ast/ast.cc3
-rw-r--r--frontends/ast/ast.h1
-rw-r--r--frontends/ast/genrtlil.cc1
-rw-r--r--frontends/ast/simplify.cc20
4 files changed, 22 insertions, 3 deletions
diff --git a/frontends/ast/ast.cc b/frontends/ast/ast.cc
index a14297b6..f7a39cf1 100644
--- a/frontends/ast/ast.cc
+++ b/frontends/ast/ast.cc
@@ -72,6 +72,7 @@ std::string AST::type2str(AstNodeType type)
X(AST_AUTOWIRE)
X(AST_PARAMETER)
X(AST_LOCALPARAM)
+ X(AST_DEFPARAM)
X(AST_PARASET)
X(AST_ARGUMENT)
X(AST_RANGE)
@@ -327,7 +328,7 @@ void AstNode::dumpVlog(FILE *f, std::string indent)
fprintf(f, ");\n");
for (auto child : children)
- if (child->type == AST_PARAMETER || child->type == AST_LOCALPARAM)
+ if (child->type == AST_PARAMETER || child->type == AST_LOCALPARAM || child->type == AST_DEFPARAM)
child->dumpVlog(f, indent + " ");
else
rem_children1.push_back(child);
diff --git a/frontends/ast/ast.h b/frontends/ast/ast.h
index c8de580e..12e9a71b 100644
--- a/frontends/ast/ast.h
+++ b/frontends/ast/ast.h
@@ -50,6 +50,7 @@ namespace AST
AST_AUTOWIRE,
AST_PARAMETER,
AST_LOCALPARAM,
+ AST_DEFPARAM,
AST_PARASET,
AST_ARGUMENT,
AST_RANGE,
diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc
index aa5a98c4..03bb8a43 100644
--- a/frontends/ast/genrtlil.cc
+++ b/frontends/ast/genrtlil.cc
@@ -531,6 +531,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint)
case AST_AUTOWIRE:
case AST_PARAMETER:
case AST_LOCALPARAM:
+ case AST_DEFPARAM:
case AST_GENVAR:
case AST_GENFOR:
case AST_GENBLOCK:
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index bc135b39..cf21c85d 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 || type == AST_PREFIX)
+ if (type == AST_WIRE || type == AST_PARAMETER || type == AST_LOCALPARAM || type == AST_DEFPARAM || 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;
@@ -163,7 +163,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage)
}
wires_are_incompatible:
if (node->type == AST_PARAMETER || node->type == AST_LOCALPARAM || node->type == AST_WIRE || node->type == AST_AUTOWIRE || node->type == AST_GENVAR ||
- node->type == AST_MEMORY || node->type == AST_FUNCTION || node->type == AST_TASK) {
+ node->type == AST_MEMORY || node->type == AST_FUNCTION || node->type == AST_TASK || node->type == AST_CELL) {
backup_scope[node->str] = current_scope[node->str];
current_scope[node->str] = node;
}
@@ -224,6 +224,22 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage)
if (type == AST_MODULE)
current_scope.clear();
+ // convert defparam nodes to cell parameters
+ if (type == AST_DEFPARAM && !str.empty()) {
+ size_t pos = str.rfind('.');
+ if (pos == std::string::npos)
+ log_error("Defparam `%s' does not contain a dot (module/parameter seperator) at %s:%d!\n",
+ RTLIL::id2cstr(str.c_str()), filename.c_str(), linenum);
+ std::string modname = str.substr(0, pos), paraname = "\\" + str.substr(pos+1);
+ if (current_scope.count(modname) == 0 || current_scope.at(modname)->type != AST_CELL)
+ log_error("Can't find cell for defparam `%s . %s` at %s:%d!\n", RTLIL::id2cstr(modname), RTLIL::id2cstr(paraname), filename.c_str(), linenum);
+ AstNode *cell = current_scope.at(modname), *paraset = clone();
+ cell->children.insert(cell->children.begin() + 1, paraset);
+ paraset->type = AST_PARASET;
+ paraset->str = paraname;
+ str.clear();
+ }
+
// resolve constant prefixes
if (type == AST_PREFIX) {
if (children[0]->type != AST_CONSTANT) {