Add regression tests for enum base type

Check that the behavior for all sorts of base types for enums is correctly
implemented. Both for valid as well as invalid base types.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-03-19 19:11:00 +01:00
parent 4bf0d62cd1
commit 315bc1908a
22 changed files with 381 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Check that it is possible to declare an enum type with an atom2 type as the
// base type.
module test;
enum byte {
A
} e1;
enum shortint {
B
} e2;
enum int {
C
} e3;
enum longint {
D
} e4;
initial begin
if ($bits(e1) == 8 && $bits(e2) == 16 &&
$bits(e3) == 32 && $bits(e4) == 64) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using an array type as the base type for an enum results in an
// error.
module test;
typedef logic T[1:0];
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that using a class type as the base type for an enum results in an
// error.
class C;
endclass
module test;
enum C {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using a dynamic array type as the base type for an enum results in
// an error.
module test;
typedef logic T[];
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that using an enum type as the base type for an enum results in an
// error.
module test;
typedef enum {
X
} T;
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using a queue type as the base type for an enum results in an
// error
module test;
typedef logic T[$];
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that using a type identifier that resolves to a type with a packed
// dimensions together with another packed dimensions as the base type for an
// enum results in an error.
module test;
typedef int T;
enum T [1:0] {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using a type identifier that resolves to a type with multiple
// packed dimensions as the base type for an enum results in an error.
module test;
typedef bit [1:0][1:0] T;
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that specifying a vector type with multiple packed dimensions as the
// base type for an enum results in an error.
module test;
enum logic [1:0][1:0] {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that using a real type as the base type for an enum results in an
// error.
module test;
enum real {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using a real type as the base type for an enum results in an
// error.
module test;
typedef real T;
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that using a string type as the base type for an enum results in an
// error.
module test;
enum string {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that using a string type as the base type for an enum results in an
// error.
module test;
typedef string T;
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that using a struct type as the base type for an enum results in an
// error.
module test;
typedef struct packed {
int x;
} T;
enum T {
A
} e;
initial begin
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that it is possible to declare an enum type with the integer type as
// the base type.
module test;
enum integer {
A
} E;
initial begin
if ($bits(E) == $bits(integer)) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that it is possible to declare an enum type without an explicit base
// type. In this case the base type should default to `int`.
module test;
enum {
A
} E;
initial begin
if ($bits(E) == 32) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,26 @@
// Check that it is possible to declare an enum type with a scalar vector type
// as the base type.
module test;
enum reg {
A
} e1;
enum logic {
B
} e2;
enum bit {
C
} e3;
initial begin
if ($bits(e1) == 1 && $bits(e2) == 1 && $bits(e3) == 1) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that it is possible to declare an enum type with the time type as the
// base type.
module test;
enum time {
A
} E;
initial begin
if ($bits(E) == 64) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,20 @@
// Check that it is possible to declare an enum type with a type identifier that
// resolves to an integer type as the base type.
module test;
typedef integer T;
enum T {
A
} E;
initial begin
if ($bits(E) == $bits(integer)) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,20 @@
// Check that it is possible to declare an enum type with a type identifier plus
// packed dimensions as the the base type.
module test;
typedef bit T;
enum T [31:0] {
A
} E;
initial begin
if ($bits(E) == 32) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -231,7 +231,27 @@ clkgen_reg normal,-g2009 ivltests
disable_fork_cmd normal,-g2009 ivltests
display_bug normal,-g2009 ivltests gold=display_bug.gold
edge normal,-g2009 ivltests
enum_base_atom2 normal,-g2005-sv ivltests
enum_base_fail_array CE,-g2005-sv ivltests
enum_base_fail_darray CE,-g2005-sv ivltests
enum_base_fail_darray CE,-g2005-sv ivltests
enum_base_fail_enum CE,-g2005-sv ivltests
enum_base_fail_queue CE,-g2005-sv ivltests
enum_base_fail_range1 CE,-g2005-sv ivltests
enum_base_fail_range2 CE,-g2005-sv ivltests
enum_base_fail_range3 CE,-g2005-sv ivltests
enum_base_fail_real1 CE,-g2005-sv ivltests
enum_base_fail_real2 CE,-g2005-sv ivltests
enum_base_fail_string1 CE,-g2005-sv ivltests
enum_base_fail_string2 CE,-g2005-sv ivltests
enum_base_fail_struct CE,-g2005-sv ivltests
enum_base_integer normal,-g2005-sv ivltests
enum_base_none normal,-g2005-sv ivltests
enum_base_range normal,-g2005-sv ivltests
enum_base_scalar normal,-g2005-sv ivltests
enum_base_time normal,-g2005-sv ivltests
enum_base_typename1 normal,-g2005-sv ivltests
enum_base_typename2 normal,-g2005-sv ivltests
enum_compatibility1 normal,-g2005-sv ivltests
enum_compatibility2 normal,-g2005-sv ivltests
enum_compatibility3 normal,-g2005-sv ivltests

View File

@ -776,6 +776,8 @@ constfunc6_ams normal,-pallowsigned=1 ivltests
constfunc7 normal,-pallowsigned=1 ivltests
constfunc13 normal,-pallowsigned=1 ivltests
constfunc14 normal,-pallowsigned=1 ivltests
enum_base_atom2 normal,-g2005-sv,-pallowsigned=1 ivltests
enum_base_none normal,-g2005-sv,-pallowsigned=1 ivltests
enum_elem_ranges normal,-g2009,-pallowsigned=1 ivltests
enum_value_expr normal,-g2009,-pallowsigned=1 ivltests
enum_values normal,-g2009,-pallowsigned=1 ivltests