Skip to content

Commit 760ecfc

Browse files
authored
Merge pull request #680 from larsclausen/class-static-prop-assign
Handle assignment to static class properties in class methods
2 parents 083671c + ea55421 commit 760ecfc

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

elab_lval.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
393393
if (pidx < 0)
394394
return 0;
395395

396+
property_qualifier_t qual = class_type->get_prop_qual(pidx);
397+
398+
// Static properties are handled as normal signals. Regular symbol
399+
// search will find it.
400+
if (qual.test_static())
401+
return 0;
402+
396403
NetScope*scope_method = find_method_containing_scope(*this, scope);
397404
ivl_assert(*this, scope_method);
398405

@@ -428,7 +435,6 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
428435
// Detect assignment to constant properties. Note that the
429436
// initializer constructor MAY assign to constant properties,
430437
// as this is how the property gets its value.
431-
property_qualifier_t qual = class_type->get_prop_qual(pidx);
432438
if (qual.test_const()) {
433439
if (class_type->get_prop_initialized(pidx)) {
434440
cerr << get_fileline() << ": error: "
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Check that static class properties can be accessed for read and write in
2+
// class tasks. Check the property is shared across all instances and has the
3+
// same value for all instances.
4+
5+
class C;
6+
static int i;
7+
task t;
8+
int x;
9+
x = i;
10+
i = x + 1;
11+
endtask
12+
endclass
13+
14+
module test;
15+
16+
C c1 = new;
17+
C c2 = new;
18+
C c3 = new;
19+
20+
initial begin
21+
c1.t();
22+
c2.t();
23+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
24+
$display("PASSED");
25+
end else begin
26+
$display("FAILED");
27+
end
28+
end
29+
30+
endmodule
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Check that static class properties can be accessed for read and write in
2+
// class tasks using `this`. Check the property is shared across all instances
3+
// and has the same value for all instances.
4+
5+
class C;
6+
static int i;
7+
task t;
8+
int x;
9+
x = this.i;
10+
this.i = x + 1;
11+
endtask
12+
endclass
13+
14+
module test;
15+
16+
C c1 = new;
17+
C c2 = new;
18+
C c3 = new;
19+
20+
initial begin
21+
c1.t();
22+
c2.t();
23+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
24+
$display("PASSED");
25+
end else begin
26+
$display("FAILED");
27+
end
28+
end
29+
30+
endmodule
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Check that static class properties can be accessed for read and write on a
2+
// class object. Check the property is shared across all instances and has the
3+
// same value for all instances.
4+
5+
class C;
6+
static int i;
7+
endclass
8+
9+
module test;
10+
11+
C c1 = new;
12+
C c2 = new;
13+
C c3 = new;
14+
15+
task t(C c);
16+
int x;
17+
x = c.i;
18+
c.i = x + 1;
19+
endtask
20+
21+
initial begin
22+
t(c1);
23+
t(c2);
24+
if (c1.i == 2 && c2.i == 2 && c3.i == 2) begin
25+
$display("PASSED");
26+
end else begin
27+
$display("FAILED");
28+
end
29+
end
30+
31+
endmodule

ivtest/regress-sv.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ sv_class_extends_scoped normal,-g2009 ivltests
488488
sv_class_localparam normal,-g2009 ivltests
489489
sv_class_new_init normal,-g2009 ivltests
490490
sv_class_in_module_decl normal,-g2009 ivltests
491+
sv_class_static_prop1 normal,-g2009 ivltests
492+
sv_class_static_prop2 normal,-g2009 ivltests
493+
sv_class_static_prop3 normal,-g2009 ivltests
491494
sv_class_super1 normal,-g2009 ivltests
492495
sv_class_super2 normal,-g2009 ivltests
493496
sv_class_task1 normal,-g2009 ivltests

ivtest/regress-vlog95.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ sv_class_extends_scoped CE,-g2009 ivltests
383383
sv_class_localparam CE,-g2009 ivltests
384384
sv_class_new_init CE,-g2009 ivltests
385385
sv_class_in_module_decl CE,-g2009 ivltests
386+
sv_class_static_prop1 CE,-g2009 ivltests
387+
sv_class_static_prop2 CE,-g2009 ivltests
388+
sv_class_static_prop3 CE,-g2009 ivltests
386389
sv_class_super1 CE,-g2009 ivltests
387390
sv_class_super2 CE,-g2009 ivltests
388391
sv_class_task1 CE,-g2009 ivltests

0 commit comments

Comments
 (0)