Merge pull request #680 from larsclausen/class-static-prop-assign

Handle assignment to static class properties in class methods
This commit is contained in:
Stephen Williams 2022-04-13 22:20:55 -07:00 committed by GitHub
commit 760ecfc44f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 1 deletions

View File

@ -393,6 +393,13 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
if (pidx < 0) if (pidx < 0)
return 0; return 0;
property_qualifier_t qual = class_type->get_prop_qual(pidx);
// Static properties are handled as normal signals. Regular symbol
// search will find it.
if (qual.test_static())
return 0;
NetScope*scope_method = find_method_containing_scope(*this, scope); NetScope*scope_method = find_method_containing_scope(*this, scope);
ivl_assert(*this, scope_method); ivl_assert(*this, scope_method);
@ -428,7 +435,6 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
// Detect assignment to constant properties. Note that the // Detect assignment to constant properties. Note that the
// initializer constructor MAY assign to constant properties, // initializer constructor MAY assign to constant properties,
// as this is how the property gets its value. // as this is how the property gets its value.
property_qualifier_t qual = class_type->get_prop_qual(pidx);
if (qual.test_const()) { if (qual.test_const()) {
if (class_type->get_prop_initialized(pidx)) { if (class_type->get_prop_initialized(pidx)) {
cerr << get_fileline() << ": error: " cerr << get_fileline() << ": error: "

View File

@ -0,0 +1,30 @@
// Check that static class properties can be accessed for read and write in
// class tasks. Check the property is shared across all instances and has the
// same value for all instances.
class C;
static int i;
task t;
int x;
x = i;
i = x + 1;
endtask
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
initial begin
c1.t();
c2.t();
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that static class properties can be accessed for read and write in
// class tasks using `this`. Check the property is shared across all instances
// and has the same value for all instances.
class C;
static int i;
task t;
int x;
x = this.i;
this.i = x + 1;
endtask
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
initial begin
c1.t();
c2.t();
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,31 @@
// Check that static class properties can be accessed for read and write on a
// class object. Check the property is shared across all instances and has the
// same value for all instances.
class C;
static int i;
endclass
module test;
C c1 = new;
C c2 = new;
C c3 = new;
task t(C c);
int x;
x = c.i;
c.i = x + 1;
endtask
initial begin
t(c1);
t(c2);
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -488,6 +488,9 @@ sv_class_extends_scoped normal,-g2009 ivltests
sv_class_localparam normal,-g2009 ivltests sv_class_localparam normal,-g2009 ivltests
sv_class_new_init normal,-g2009 ivltests sv_class_new_init normal,-g2009 ivltests
sv_class_in_module_decl normal,-g2009 ivltests sv_class_in_module_decl normal,-g2009 ivltests
sv_class_static_prop1 normal,-g2009 ivltests
sv_class_static_prop2 normal,-g2009 ivltests
sv_class_static_prop3 normal,-g2009 ivltests
sv_class_super1 normal,-g2009 ivltests sv_class_super1 normal,-g2009 ivltests
sv_class_super2 normal,-g2009 ivltests sv_class_super2 normal,-g2009 ivltests
sv_class_task1 normal,-g2009 ivltests sv_class_task1 normal,-g2009 ivltests

View File

@ -383,6 +383,9 @@ sv_class_extends_scoped CE,-g2009 ivltests
sv_class_localparam CE,-g2009 ivltests sv_class_localparam CE,-g2009 ivltests
sv_class_new_init CE,-g2009 ivltests sv_class_new_init CE,-g2009 ivltests
sv_class_in_module_decl CE,-g2009 ivltests sv_class_in_module_decl CE,-g2009 ivltests
sv_class_static_prop1 CE,-g2009 ivltests
sv_class_static_prop2 CE,-g2009 ivltests
sv_class_static_prop3 CE,-g2009 ivltests
sv_class_super1 CE,-g2009 ivltests sv_class_super1 CE,-g2009 ivltests
sv_class_super2 CE,-g2009 ivltests sv_class_super2 CE,-g2009 ivltests
sv_class_task1 CE,-g2009 ivltests sv_class_task1 CE,-g2009 ivltests