Merge pull request #659 from larsclausen/typedef-overwrite

Support typedef overwrites with unpacked dimensions and in classes
This commit is contained in:
Stephen Williams 2022-03-27 15:49:55 -07:00 committed by GitHub
commit d480c4d7d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 9 deletions

View File

@ -0,0 +1,24 @@
// Check that it is possible to overwrite a type identifier declared in a higher
// level scope. Check that this works if the new type is an array type.
typedef logic [3:0] T;
T x;
module test;
typedef logic [7:0] T[1:0];
T y;
initial begin
y[0] = 8'hff;
y[1] = 8'hfe;
if ($bits(T) == 16 && $size(x) == 4 && $size(y) == 2 &&
y[0] == 8'hff && y[1] == 8'hfe) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that it is possible to overwrite a type identifier declared in a higher
// level scope. Check that this works when the new type is declared in a class.
typedef logic [3:0] T;
T x;
module test;
class C;
typedef logic [7:0] T;
T y;
task t;
y = 8'hff;
if ($bits(x) == 4 && $bits(y) == 8 && y == 8'hff) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
endclass
C c;
initial begin
c = new;
c.t();
end
endmodule

View File

@ -589,7 +589,9 @@ sv_timeunit_prec_fail2 CE,-g2009,-u,\
./ivltests/sv_timeunit_prec_fail2a.v,\
./ivltests/sv_timeunit_prec_fail2b.v,\
./ivltests/sv_timeunit_prec_fail2c.v, ivltests gold=sv_timeunit_prec_fail2.gold
sv_typedef_scope normal,-g2009 ivltests
sv_typedef_scope1 normal,-g2009 ivltests
sv_typedef_scope2 normal,-g2009 ivltests
sv_typedef_scope3 normal,-g2009 ivltests
sv_union1 normal,-g2009 ivltests
sv_union1b normal,-g2009 ivltests
sv_union2 normal,-g2009 ivltests

View File

@ -392,6 +392,7 @@ sv_port_default7 CE,-g2009,-pallowsigned=1 ivltests
sv_port_default8 CE,-g2009,-pallowsigned=1 ivltests
sv_port_default9 CE,-g2009 ivltests
sv_root_class CE,-g2009 ivltests
sv_typedef_scope3 CE,-g2009 ivltests
sv_unit2b CE,-g2009 ivltests
sv_unit3b CE,-g2009 ivltests
sv_unit4b CE,-g2009 ivltests

13
parse.y
View File

@ -915,11 +915,8 @@ class_item /* IEEE1800-2005: A.1.8 */
/* IEEEE1800-2017: A.1.9 Class items: class_item ::= { property_qualifier} data_declaration */
| property_qualifier_opt K_typedef data_type IDENTIFIER dimensions_opt ';'
{ perm_string name = lex_strings.make($4);
delete[]$4;
pform_set_typedef(name, $3, $5);
}
/* TODO: Restrict the access based on the property qualifier. */
| property_qualifier_opt type_declaration
/* IEEE1800-1017: A.1.9 Class items: Class methods... */
@ -2690,13 +2687,13 @@ type_declaration
/* If the IDENTIFIER already is a typedef, it is possible for this
code to override the definition, but only if the typedef is
inherited from a different scope. */
| K_typedef data_type TYPE_IDENTIFIER ';'
| K_typedef data_type TYPE_IDENTIFIER dimensions_opt ';'
{ perm_string name = lex_strings.make($3.text);
if (pform_test_type_identifier_local(name)) {
yyerror(@3, "error: Typedef identifier \"%s\" is already a type name.", $3.text);
delete $4;
} else {
pform_set_typedef(name, $2, NULL);
pform_set_typedef(name, $2, $4);
}
delete[]$3.text;
}