Add regression tests for evaluating expression within assignment patterns
Check that expressions within assignment patterns are evaluated as if they were assigned to a variable with the same type as the base type of the assignment pattern target. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
parent
5b8fb089bf
commit
a3c329ae84
|
|
@ -0,0 +1,51 @@
|
|||
// Check that implicit cast works for expressions in assignment patterns. The
|
||||
// result should be the same as assigning the expression to a variable with the
|
||||
// same type as the base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int dv[];
|
||||
real dr[];
|
||||
|
||||
int tmpv;
|
||||
real tmpr;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check_v(expr) \
|
||||
dv = '{expr}; \
|
||||
tmpv = expr; \
|
||||
if (dv[0] !== tmpv) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", dv[0], tmpv); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
`define check_r(expr) \
|
||||
dr = '{expr}; \
|
||||
tmpr = expr; \
|
||||
if (dr[0] != tmpr) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", dr[0], tmpr); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
real r;
|
||||
int i;
|
||||
|
||||
initial begin
|
||||
r = 4.56;
|
||||
i = -11;
|
||||
|
||||
// Implicit cast from real to vector
|
||||
`check_v(1.234e16)
|
||||
`check_v(r)
|
||||
|
||||
// Implicit cast from vector to real
|
||||
`check_r(32'hfffffff0)
|
||||
`check_r(i)
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// Check that concatenations are evaluated correctly in assignment patterns.
|
||||
// The result should be the same as assigning the expression to a variable with
|
||||
// the same type as the base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
shortint x;
|
||||
byte y;
|
||||
|
||||
initial begin
|
||||
x = -1;
|
||||
y = 10;
|
||||
`check({x,y})
|
||||
`check({3{y}})
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Check that named constants can be accessed in assignment patterns. The
|
||||
// result should be the same as assigning the expression to a variable with the
|
||||
// same type as the base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
parameter A = -1;
|
||||
localparam B = 10;
|
||||
|
||||
typedef enum {
|
||||
X = -1, Y = 0, Z = 1
|
||||
} T;
|
||||
|
||||
initial begin
|
||||
`check(A)
|
||||
`check(B)
|
||||
`check(X)
|
||||
`check(Y)
|
||||
`check(Z)
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
// Check that the width of the element type of the target of an assignment
|
||||
// pattern is considered when evaluating the expression. The result should be
|
||||
// the same as assigning the expression to a variable with the same type as the
|
||||
// base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
shortint x;
|
||||
bit [7:0] y;
|
||||
|
||||
initial begin
|
||||
x = -11;
|
||||
y = 8'h80;
|
||||
|
||||
// Sign extension
|
||||
`check(x)
|
||||
`check(16'sh8000)
|
||||
|
||||
// No sign extension
|
||||
`check(8'hff)
|
||||
`check(y)
|
||||
|
||||
// Gets evaluated in a 32 bit context, the result is 2/-2 not 0
|
||||
`check(1'b1 + 1'b1)
|
||||
`check(1'sb1 + 1'sb1)
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Check that function calls within an assignment pattern are evaluated
|
||||
// correctly. The result should be the same as assigning the expression to a
|
||||
// variable with the same type as the base type of the assignment pattern
|
||||
// target.
|
||||
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
int x, y;
|
||||
|
||||
function int fn(int x);
|
||||
return x*2;
|
||||
endfunction
|
||||
|
||||
initial begin
|
||||
x = -3;
|
||||
y = 10;
|
||||
|
||||
`check(fn(x))
|
||||
`check($clog2(y))
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
// Check that operators in an assignment pattern are evaluated correctly. The
|
||||
// result should be the same as assigning the expression to a variable with the
|
||||
// same type as the base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
int x, y;
|
||||
|
||||
initial begin
|
||||
x = -2;
|
||||
y = 5;
|
||||
|
||||
`check(+x);
|
||||
`check(-x);
|
||||
`check(!x);
|
||||
`check(~x);
|
||||
`check(&x);
|
||||
`check(~&x);
|
||||
`check(|x);
|
||||
`check(~|x);
|
||||
`check(^x);
|
||||
`check(~^x);
|
||||
|
||||
`check(x + y)
|
||||
`check(x - y)
|
||||
`check(x * y)
|
||||
`check(x / y)
|
||||
`check(x % y)
|
||||
`check(x ** y)
|
||||
|
||||
`check(x & y)
|
||||
`check(x | y)
|
||||
`check(x ^ y)
|
||||
`check(x ^~ y)
|
||||
|
||||
`check(x >> y);
|
||||
`check(x << y);
|
||||
`check(x >>> y);
|
||||
`check(x <<< y);
|
||||
|
||||
`check(x == y);
|
||||
`check(x != y);
|
||||
`check(x === y);
|
||||
`check(x !== y);
|
||||
`check(x < y);
|
||||
`check(x <= y);
|
||||
`check(x > y);
|
||||
`check(x >= y);
|
||||
|
||||
`check(x && y);
|
||||
`check(x || y);
|
||||
|
||||
`check(x ? x : y);
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// Check that part selects are evaluated correctly within assignment patterns.
|
||||
// The result should be the same as assigning the expression to a variable with
|
||||
// the same type as the base type of the assignment pattern target.
|
||||
|
||||
module test;
|
||||
|
||||
int d[];
|
||||
int tmp;
|
||||
|
||||
bit failed = 1'b0;
|
||||
|
||||
`define check(expr) \
|
||||
d = '{expr}; \
|
||||
tmp = expr; \
|
||||
if (d[0] !== tmp) begin \
|
||||
$display("FAILED: `%s`, got %0d, expected %0d", `"expr`", d[0], tmp); \
|
||||
failed = 1'b1; \
|
||||
end
|
||||
|
||||
logic [23:0] x;
|
||||
int i = 13;
|
||||
|
||||
initial begin
|
||||
x = 24'ha5a5a5;
|
||||
`check(x[0])
|
||||
`check(x[7:0])
|
||||
`check(x[3+:8])
|
||||
`check(x[23-:5])
|
||||
`check(x[i+:8])
|
||||
`check(x[i-:5])
|
||||
|
||||
if (!failed) begin
|
||||
$display("PASSED");
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
|
@ -455,6 +455,13 @@ struct_packed_write_read2 normal,-g2009 ivltests
|
|||
struct_invalid_member CE,-g2009 ivltests gold=struct_invalid_member.gold
|
||||
struct_signed normal,-g2009 ivltests
|
||||
sv-constants normal,-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
|
||||
sv_assign_pattern_expand normal,-g2005-sv ivltests
|
||||
sv_assign_pattern_func normal,-g2005-sv ivltests
|
||||
sv_assign_pattern_op normal,-g2005-sv ivltests
|
||||
sv_assign_pattern_part normal,-g2005-sv ivltests
|
||||
sv_array_assign_pattern2 normal,-g2009 ivltests
|
||||
sv_cast_integer normal,-g2005-sv ivltests
|
||||
sv_cast_integer2 normal,-g2005-sv ivltests
|
||||
|
|
|
|||
|
|
@ -315,6 +315,13 @@ br_gh383c CE,-g2012,-pallowsigned=1 ivltests
|
|||
br_gh383d CE,-g2012,-pallowsigned=1 ivltests
|
||||
br_gh460 CE,-g2012 ivltests
|
||||
br_ml20191221 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_cast CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_const CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_concat CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_expand CE,-g2005,-sv-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_func CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_op CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_assign_pattern_part CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_array_assign_pattern2 CE,-g2009,-pallowsigned=1 ivltests
|
||||
sv_cast_darray CE,-g2005-sv,-pallowsigned=1 ivltests
|
||||
sv_darray1 CE,-g2009,-pallowsigned=1 ivltests
|
||||
|
|
|
|||
Loading…
Reference in New Issue