mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
sv: Fix typedefs in packages
Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
parent
c962951612
commit
e70e4afb60
|
@ -796,14 +796,17 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
||||||
log_assert(children.size() == 1);
|
log_assert(children.size() == 1);
|
||||||
log_assert(children[0]->type == AST_WIRETYPE);
|
log_assert(children[0]->type == AST_WIRETYPE);
|
||||||
if (!current_scope.count(children[0]->str))
|
if (!current_scope.count(children[0]->str))
|
||||||
log_file_error(filename, linenum, "Unknown identifier `%s' used as type name", children[0]->str.c_str());
|
log_file_error(filename, linenum, "Unknown identifier `%s' used as type name\n", children[0]->str.c_str());
|
||||||
AstNode *resolved_type = current_scope.at(children[0]->str);
|
AstNode *resolved_type = current_scope.at(children[0]->str);
|
||||||
if (resolved_type->type != AST_TYPEDEF)
|
if (resolved_type->type != AST_TYPEDEF)
|
||||||
log_file_error(filename, linenum, "`%s' does not name a type", children[0]->str.c_str());
|
log_file_error(filename, linenum, "`%s' does not name a type\n", children[0]->str.c_str());
|
||||||
log_assert(resolved_type->children.size() == 1);
|
log_assert(resolved_type->children.size() == 1);
|
||||||
AstNode *templ = resolved_type->children[0];
|
AstNode *templ = resolved_type->children[0];
|
||||||
delete_children(); // type reference no longer needed
|
delete_children(); // type reference no longer needed
|
||||||
|
|
||||||
|
// Ensure typedef itself is fully simplified
|
||||||
|
while(templ->simplify(const_fold, at_zero, in_lvalue, stage, width_hint, sign_hint, in_param)) {};
|
||||||
|
|
||||||
is_reg = templ->is_reg;
|
is_reg = templ->is_reg;
|
||||||
is_logic = templ->is_logic;
|
is_logic = templ->is_logic;
|
||||||
is_signed = templ->is_signed;
|
is_signed = templ->is_signed;
|
||||||
|
@ -826,15 +829,18 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
||||||
log_assert(children.size() == 2);
|
log_assert(children.size() == 2);
|
||||||
log_assert(children[1]->type == AST_WIRETYPE);
|
log_assert(children[1]->type == AST_WIRETYPE);
|
||||||
if (!current_scope.count(children[1]->str))
|
if (!current_scope.count(children[1]->str))
|
||||||
log_file_error(filename, linenum, "Unknown identifier `%s' used as type name", children[1]->str.c_str());
|
log_file_error(filename, linenum, "Unknown identifier `%s' used as type name\n", children[1]->str.c_str());
|
||||||
AstNode *resolved_type = current_scope.at(children[1]->str);
|
AstNode *resolved_type = current_scope.at(children[1]->str);
|
||||||
if (resolved_type->type != AST_TYPEDEF)
|
if (resolved_type->type != AST_TYPEDEF)
|
||||||
log_file_error(filename, linenum, "`%s' does not name a type", children[1]->str.c_str());
|
log_file_error(filename, linenum, "`%s' does not name a type\n", children[1]->str.c_str());
|
||||||
log_assert(resolved_type->children.size() == 1);
|
log_assert(resolved_type->children.size() == 1);
|
||||||
AstNode *templ = resolved_type->children[0];
|
AstNode *templ = resolved_type->children[0];
|
||||||
delete children[1];
|
delete children[1];
|
||||||
children.pop_back();
|
children.pop_back();
|
||||||
|
|
||||||
|
// Ensure typedef itself is fully simplified
|
||||||
|
while(templ->simplify(const_fold, at_zero, in_lvalue, stage, width_hint, sign_hint, in_param)) {};
|
||||||
|
|
||||||
is_signed = templ->is_signed;
|
is_signed = templ->is_signed;
|
||||||
is_string = templ->is_string;
|
is_string = templ->is_string;
|
||||||
is_custom_type = templ->is_custom_type;
|
is_custom_type = templ->is_custom_type;
|
||||||
|
|
11
tests/svtypes/typedef_package.sv
Normal file
11
tests/svtypes/typedef_package.sv
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package pkg;
|
||||||
|
typedef logic [7:0] uint8_t;
|
||||||
|
endpackage
|
||||||
|
|
||||||
|
module top;
|
||||||
|
|
||||||
|
(* keep *) pkg::uint8_t a = 8'hAA;
|
||||||
|
|
||||||
|
always @* assert(a == 8'hAA);
|
||||||
|
|
||||||
|
endmodule
|
Loading…
Reference in a new issue