diff --git a/ivtest/ivltests/sv_chained_constructor1.v b/ivtest/ivltests/sv_chained_constructor1.v new file mode 100644 index 000000000..7041dfccd --- /dev/null +++ b/ivtest/ivltests/sv_chained_constructor1.v @@ -0,0 +1,40 @@ +// Check that the constructor of a base class gets called exactly once when +// mixing implicit and explicit constructors. + +module test; + + bit failed = 1'b0; + + `define check(val, exp) do begin \ + if ((val) !== (exp)) begin \ + $display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \ + `"val`", (exp), (val)); \ + failed = 1'b1; \ + end \ + end while (0) + + int c_new_calls = 0; + + class C; + function new; + c_new_calls++; + endfunction + endclass + + class D extends C; + int x = 10; + endclass + + initial begin + D d; + d = new; + + `check(c_new_calls, 1); + `check(d.x, 10); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_chained_constructor2.v b/ivtest/ivltests/sv_chained_constructor2.v new file mode 100644 index 000000000..e7748ed12 --- /dev/null +++ b/ivtest/ivltests/sv_chained_constructor2.v @@ -0,0 +1,48 @@ +// Check that the constructor of a base class gets called exactly once when +// mixing implicit and explicit constructors. + +module test; + + bit failed = 1'b0; + + `define check(val, exp) do begin \ + if ((val) !== (exp)) begin \ + $display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \ + `"val`", (exp), (val)); \ + failed = 1'b1; \ + end \ + end while (0) + + int d_new_calls = 0; + + class C; + int x = 10; + endclass + + class D extends C; + function new; + d_new_calls++; + endfunction + endclass + + class E extends D; + int y; + function new; + y = 20; + endfunction + endclass + + initial begin + E e; + e = new; + + `check(d_new_calls, 1); + `check(e.x, 10); + `check(e.y, 20); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_chained_constructor3.v b/ivtest/ivltests/sv_chained_constructor3.v new file mode 100644 index 000000000..45cdfa0e4 --- /dev/null +++ b/ivtest/ivltests/sv_chained_constructor3.v @@ -0,0 +1,22 @@ +// Check that forwarding base class constructor arguments through the `extends` +// works when the derived class has no constructor. + +module test; + + class C; + function new(int a); + if (a == 10) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + endfunction + endclass + + // D has no constructor + class D extends C(10); + endclass + + D d = new; + +endmodule diff --git a/ivtest/ivltests/sv_chained_constructor4.v b/ivtest/ivltests/sv_chained_constructor4.v new file mode 100644 index 000000000..8f0e3f701 --- /dev/null +++ b/ivtest/ivltests/sv_chained_constructor4.v @@ -0,0 +1,23 @@ +// Check that forwarding base class constructor arguments through the `extends` +// works when the derived class has an implicit constructor. + +module test; + + class C; + function new(int a); + if (a == 10) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + endfunction + endclass + + // D has an implicit constructor + class D extends C(10); + int y; + endclass + + D d = new; + +endmodule diff --git a/ivtest/ivltests/sv_chained_constructor5.v b/ivtest/ivltests/sv_chained_constructor5.v new file mode 100644 index 000000000..190a04ab1 --- /dev/null +++ b/ivtest/ivltests/sv_chained_constructor5.v @@ -0,0 +1,26 @@ +// Check that forwarding base class constructor arguments through the `extends` +// works when the derived class has an explicit constructor. + +module test; + + class C; + function new(int a); + if (a == 10) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + endfunction + endclass + + // D has an explicit constructor + class D extends C(10); + int x; + function new; + x = 10; + endfunction + endclass + + D d = new; + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 5fa756256..b18194e48 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -61,6 +61,11 @@ sv_array_assign_fail2 vvp_tests/sv_array_assign_fail2.json sv_array_cassign6 vvp_tests/sv_array_cassign6.json sv_array_cassign7 vvp_tests/sv_array_cassign7.json sv_automatic_2state vvp_tests/sv_automatic_2state.json +sv_chained_constructor1 vvp_tests/sv_chained_constructor1.json +sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json +sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json +sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json +sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json sv_const1 vvp_tests/sv_const1.json sv_const2 vvp_tests/sv_const2.json sv_const3 vvp_tests/sv_const3.json diff --git a/ivtest/vvp_tests/sv_chained_constructor1.json b/ivtest/vvp_tests/sv_chained_constructor1.json new file mode 100644 index 000000000..214751b72 --- /dev/null +++ b/ivtest/vvp_tests/sv_chained_constructor1.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_chained_constructor1.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_chained_constructor2.json b/ivtest/vvp_tests/sv_chained_constructor2.json new file mode 100644 index 000000000..a70bcc038 --- /dev/null +++ b/ivtest/vvp_tests/sv_chained_constructor2.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_chained_constructor2.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_chained_constructor3.json b/ivtest/vvp_tests/sv_chained_constructor3.json new file mode 100644 index 000000000..e4bf14197 --- /dev/null +++ b/ivtest/vvp_tests/sv_chained_constructor3.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_chained_constructor3.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_chained_constructor4.json b/ivtest/vvp_tests/sv_chained_constructor4.json new file mode 100644 index 000000000..7c3ed45cc --- /dev/null +++ b/ivtest/vvp_tests/sv_chained_constructor4.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_chained_constructor4.v", + "iverilog-args" : [ "-g2005-sv" ] +} diff --git a/ivtest/vvp_tests/sv_chained_constructor5.json b/ivtest/vvp_tests/sv_chained_constructor5.json new file mode 100644 index 000000000..494ff049f --- /dev/null +++ b/ivtest/vvp_tests/sv_chained_constructor5.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_chained_constructor5.v", + "iverilog-args" : [ "-g2005-sv" ] +}