mirror of
https://github.com/zachjs/sv2v.git
synced 2026-09-03 08:33:46 +02:00
upgraded size cast conversion
- support casts of generate scoped expressions - support casts to sizes involving genvars
This commit is contained in:
+9
-5
@@ -1,25 +1,29 @@
|
||||
module top;
|
||||
|
||||
parameter WIDTH = 32;
|
||||
generate
|
||||
begin : A
|
||||
int x = -235;
|
||||
end
|
||||
endgenerate
|
||||
initial begin
|
||||
logic [31:0] w = 1234;
|
||||
int x = -235;
|
||||
int y = 1234;
|
||||
logic [4:0] z = y;
|
||||
$display("%0d %0d", w, 5'(w));
|
||||
$display("%0d %0d", x, 5'(x));
|
||||
$display("%0d %0d", A.x, 5'(A.x));
|
||||
$display("%0d %0d", y, 5'(y));
|
||||
$display("%0d %0d", z, 5'(z));
|
||||
$display("%0d %0d", w+1, 5'(w+1));
|
||||
$display("%0d %0d", x+1, 5'(x+1));
|
||||
$display("%0d %0d", A.x+1, 5'(A.x+1));
|
||||
$display("%0d %0d", y+1, 5'(y+1));
|
||||
$display("%0d %0d", z+1, 5'(z+1));
|
||||
$display("%b %b", w, 40'(w));
|
||||
$display("%b %b", x, 40'(x));
|
||||
$display("%b %b", A.x, 40'(A.x));
|
||||
$display("%b %b", y, 40'(y));
|
||||
$display("%b %b", z, 40'(z));
|
||||
$display("%0d %0d", w, ($clog2(WIDTH))'(w));
|
||||
$display("%0d %0d", x, ($clog2(WIDTH))'(x));
|
||||
$display("%0d %0d", A.x, ($clog2(WIDTH))'(A.x));
|
||||
$display("%0d %0d", y, ($clog2(WIDTH))'(y));
|
||||
$display("%0d %0d", z, ($clog2(WIDTH))'(z));
|
||||
$display("%b", 32'(4));
|
||||
|
||||
+10
-6
@@ -1,28 +1,32 @@
|
||||
module top;
|
||||
|
||||
generate
|
||||
begin : A
|
||||
reg signed [31:0] x;
|
||||
end
|
||||
endgenerate
|
||||
initial begin : foo_block
|
||||
reg [31:0] w;
|
||||
reg signed [31:0] x;
|
||||
reg signed [31:0] y;
|
||||
reg [4:0] z;
|
||||
w = 1234;
|
||||
x = -235;
|
||||
A.x = -235;
|
||||
y = 1234;
|
||||
z = y;
|
||||
$display("%0d %0d", w, w[4:0]);
|
||||
$display("%0d %0d", x, $signed(x[4:0]));
|
||||
$display("%0d %0d", A.x, $signed(A.x[4:0]));
|
||||
$display("%0d %0d", y, $signed(y[4:0]));
|
||||
$display("%0d %0d", z, z[4:0]);
|
||||
$display("%0d %0d", w+1, w[4:0]+1);
|
||||
$display("%0d %0d", x+1, $signed(x[4:0])+1);
|
||||
$display("%0d %0d", A.x+1, $signed(A.x[4:0])+1);
|
||||
$display("%0d %0d", y+1, $signed(y[4:0])+1);
|
||||
$display("%0d %0d", z+1, z[4:0]+1);
|
||||
$display("%b %b", w, {8'b0, w});
|
||||
$display("%b %b", x, {8'hFF, x});
|
||||
$display("%b %b", A.x, {8'hFF, A.x});
|
||||
$display("%b %b", y, {8'b0, y});
|
||||
$display("%b %b", z, {35'b0, z});
|
||||
$display("%0d %0d", w, w[4:0]);
|
||||
$display("%0d %0d", x, $signed(x[4:0]));
|
||||
$display("%0d %0d", A.x, $signed(A.x[4:0]));
|
||||
$display("%0d %0d", y, $signed(y[4:0]));
|
||||
$display("%0d %0d", z, z[4:0]);
|
||||
$display("%b", 32'd4);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
module top;
|
||||
generate
|
||||
for (genvar i = 1; i < 5; ++i) begin
|
||||
initial begin
|
||||
integer x, y;
|
||||
x = $unsigned(i'(1'sb1));
|
||||
y = $unsigned((i + 5)'(1'sb1));
|
||||
$display("%0d %b %b", i, x, y);
|
||||
end
|
||||
for (genvar j = 3; j < 6; ++j) begin
|
||||
initial begin
|
||||
integer x;
|
||||
x = $unsigned((i * j)'(1'sb1));
|
||||
$display("%0d %0d %b", i, j, x);
|
||||
end
|
||||
end
|
||||
end
|
||||
endgenerate
|
||||
endmodule
|
||||
@@ -0,0 +1,24 @@
|
||||
module top;
|
||||
generate
|
||||
genvar i, j;
|
||||
for (i = 1; i < 5; i = i + 1) begin
|
||||
initial begin : foo
|
||||
integer x, y;
|
||||
x = $unsigned(cast_i(1'sb1));
|
||||
y = (1 << (i + 5)) - 1;
|
||||
$display("%0d %b %b", i, x, y);
|
||||
end
|
||||
for (j = 3; j < 6; j = j + 1) begin
|
||||
initial begin : bar
|
||||
integer x;
|
||||
x = (1 << (i * j)) - 1;
|
||||
$display("%0d %0d %b", i, j, x);
|
||||
end
|
||||
end
|
||||
function signed [i-1:0] cast_i;
|
||||
input signed [i-1:0] inp;
|
||||
cast_i = inp;
|
||||
endfunction
|
||||
end
|
||||
endgenerate
|
||||
endmodule
|
||||
Reference in New Issue
Block a user