aboutsummaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-09-19 21:07:20 +0100
committerDavid Shah <dave@ds0.me>2019-10-03 09:54:14 +0100
commitc9629516120930aedaf52d72fec5d7fabe51d496 (patch)
tree4219cf0483c9ee44938eb7432492d840a57ab970 /frontends
parentf6b5e47e40b4a2bda6e5d928480ea218a6a911c2 (diff)
downloadyosys-c9629516120930aedaf52d72fec5d7fabe51d496.tar.gz
yosys-c9629516120930aedaf52d72fec5d7fabe51d496.tar.bz2
yosys-c9629516120930aedaf52d72fec5d7fabe51d496.zip
sv: Fix typedef parameters
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'frontends')
-rw-r--r--frontends/ast/simplify.cc33
-rw-r--r--frontends/verilog/verilog_parser.y21
2 files changed, 48 insertions, 6 deletions
diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc
index b94662bcd..9abd2916d 100644
--- a/frontends/ast/simplify.cc
+++ b/frontends/ast/simplify.cc
@@ -790,8 +790,8 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
log_assert(!children[0]->is_custom_type);
}
- // resolve types of wires and parameters
- if (type == AST_WIRE || type == AST_LOCALPARAM || type == AST_PARAMETER) {
+ // resolve types of wires
+ if (type == AST_WIRE) {
if (is_custom_type) {
log_assert(children.size() == 1);
log_assert(children[0]->type == AST_WIRETYPE);
@@ -820,6 +820,35 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
log_assert(!is_custom_type);
}
+ // resolve types of parameters
+ if (type == AST_LOCALPARAM || type == AST_PARAMETER) {
+ if (is_custom_type) {
+ log_assert(children.size() == 2);
+ log_assert(children[1]->type == AST_WIRETYPE);
+ if (!current_scope.count(children[1]->str))
+ log_file_error(filename, linenum, "Unknown identifier `%s' used as type name", children[1]->str.c_str());
+ AstNode *resolved_type = current_scope.at(children[1]->str);
+ if (resolved_type->type != AST_TYPEDEF)
+ log_file_error(filename, linenum, "`%s' does not name a type", children[1]->str.c_str());
+ log_assert(resolved_type->children.size() == 1);
+ AstNode *templ = resolved_type->children[0];
+ delete children[1];
+ children.pop_back();
+
+ is_signed = templ->is_signed;
+ is_string = templ->is_string;
+ is_custom_type = templ->is_custom_type;
+
+ range_valid = templ->range_valid;
+ range_swapped = templ->range_swapped;
+ range_left = templ->range_left;
+ range_right = templ->range_right;
+ for (auto template_child : templ->children)
+ children.push_back(template_child->clone());
+ }
+ log_assert(!is_custom_type);
+ }
+
// resolve constant prefixes
if (type == AST_PREFIX) {
if (children[0]->type != AST_CONSTANT) {
diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y
index eb091bea6..8cc084fe0 100644
--- a/frontends/verilog/verilog_parser.y
+++ b/frontends/verilog/verilog_parser.y
@@ -327,13 +327,13 @@ single_module_para:
astbuf1 = new AstNode(AST_PARAMETER);
astbuf1->children.push_back(AstNode::mkconst_int(0, true));
append_attr(astbuf1, $1);
- } param_signed param_integer param_range single_param_decl |
+ } int_param_type single_param_decl |
attr TOK_LOCALPARAM {
if (astbuf1) delete astbuf1;
astbuf1 = new AstNode(AST_LOCALPARAM);
astbuf1->children.push_back(AstNode::mkconst_int(0, true));
append_attr(astbuf1, $1);
- } param_signed param_integer param_range single_param_decl |
+ } int_param_type single_param_decl |
single_param_decl;
module_args_opt:
@@ -1158,12 +1158,25 @@ param_range:
}
};
+custom_param_type:
+ hierarchical_id {
+ astbuf1->is_custom_type = true;
+ astbuf1->children.push_back(new AstNode(AST_WIRETYPE));
+ astbuf1->children.back()->str = *$1;
+ };
+
+param_type:
+ param_signed param_integer param_real param_range | custom_param_type;
+
+int_param_type:
+ param_signed param_integer param_range | custom_param_type;
+
param_decl:
attr TOK_PARAMETER {
astbuf1 = new AstNode(AST_PARAMETER);
astbuf1->children.push_back(AstNode::mkconst_int(0, true));
append_attr(astbuf1, $1);
- } param_signed param_integer param_real param_range param_decl_list ';' {
+ } param_type param_decl_list ';' {
delete astbuf1;
};
@@ -1172,7 +1185,7 @@ localparam_decl:
astbuf1 = new AstNode(AST_LOCALPARAM);
astbuf1->children.push_back(AstNode::mkconst_int(0, true));
append_attr(astbuf1, $1);
- } param_signed param_integer param_real param_range param_decl_list ';' {
+ } param_type param_decl_list ';' {
delete astbuf1;
};