Add regression tests for struct assignment patterns

Check that struct assignment patterns with only positional arguments are
supported. Also check that invalid assignment patterns for structs report
an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-11 19:57:43 -08:00
parent 4fca564614
commit 6ae085812d
5 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,28 @@
// Check that positional assigment patterns are supported for structs.
module test;
typedef struct packed {
int x;
shortint y;
byte z;
} T;
T x = '{1'b1, 2.0, 2 + 1};
// Check nested assignment patterns
struct packed {
T x;
bit [2:0][3:0] y;
} y = '{'{1'b1, 2.0, 2 + 1}, '{4, 5, 6}};
initial begin
if (x === 56'h00000001000203 &&
y === 68'h00000001000203456) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,22 @@
// Check that positional assigment patterns are supported for structs are
// supported for parameters.
module test;
typedef struct packed {
int x;
shortint y;
byte z;
} T;
localparam T x = '{1'b1, 2.0, 2 + 1};
initial begin
if (x === 56'h00000001000203) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that it is an error to provide less elements in a struct assignment
// pattern than there are members in the struct.
module test;
struct packed {
int x;
shortint y;
byte z;
} x = '{1, 2}; // This should fail. Less elements than required.
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that it is an error to provide more elements in a struct assignment
// pattern than there are members in the struct.
module test;
struct packed {
int x;
shortint y;
byte z;
} x = '{1, 2, 3, 4}; // This should fail. More elements than required.
initial begin
$display("FAILED");
end
endmodule

View File

@ -525,6 +525,10 @@ sv_ap_parray2 normal,-g2005-sv ivltests
sv_ap_parray_fail1 CE,-g2005-sv ivltests
sv_ap_parray_fail2 CE,-g2005-sv ivltests
sv_ap_parray_fail3 CE,-g2005-sv ivltests
sv_ap_struct1 normal,-g2005-sv ivltests
sv_ap_struct2 normal,-g2005-sv ivltests
sv_ap_struct_fail1 CE,-g2005-sv ivltests
sv_ap_struct_fail2 CE,-g2005-sv ivltests
sv_assign_pattern_cast normal,-g2005-sv ivltests
sv_assign_pattern_const normal,-g2005-sv ivltests
sv_assign_pattern_concat normal,-g2005-sv ivltests