mirror of
https://github.com/zachjs/sv2v.git
synced 2026-09-07 03:43:04 +02:00
initial generate block scoping support
- significant refactor of struct conversion - significant refactor of typedef conversion - scoping support in multipack conversion - scoping support in typeof conversion
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
module top;
|
||||
logic t;
|
||||
initial $display("A t %0d", $bits(t));
|
||||
initial $display("A top.t %0d", $bits(top.t));
|
||||
generate
|
||||
begin : X
|
||||
logic [1:0] t;
|
||||
initial $display("B t %0d", $bits(t));
|
||||
initial $display("B top.t %0d", $bits(top.t));
|
||||
initial $display("B X.t %0d", $bits(X.t));
|
||||
initial $display("B top.X.t %0d", $bits(top.X.t));
|
||||
begin : Y
|
||||
logic [2:0] t;
|
||||
initial $display("C t %0d", $bits(t));
|
||||
initial $display("C top.t %0d", $bits(top.t));
|
||||
initial $display("C X.t %0d", $bits(X.t));
|
||||
initial $display("C top.X.t %0d", $bits(top.X.t));
|
||||
initial $display("C Y.t %0d", $bits(Y.t));
|
||||
initial $display("C X.Y.t %0d", $bits(X.Y.t));
|
||||
initial $display("C top.X.Y.t %0d", $bits(top.X.Y.t));
|
||||
end
|
||||
end
|
||||
for (genvar i = 0; i < 3; ++i) begin : Z
|
||||
logic [i:0] t;
|
||||
end
|
||||
endgenerate
|
||||
initial $display("A t %0d", $bits(t));
|
||||
initial $display("A top.t %0d", $bits(top.t));
|
||||
initial $display("A X.t %0d", $bits(X.t));
|
||||
initial $display("A top.X.t %0d", $bits(top.X.t));
|
||||
initial $display("A X.Y.t %0d", $bits(X.Y.t));
|
||||
initial $display("A top.X.Y.t %0d", $bits(top.X.Y.t));
|
||||
initial $display("A top.Z[0].t %0d", $bits(top.Z[0].t));
|
||||
initial $display("A Z[0].t %0d", $bits(Z[0].t));
|
||||
initial $display("A Z[1].t %0d", $bits(Z[1].t));
|
||||
initial $display("A Z[2].t %0d", $bits(Z[2].t));
|
||||
|
||||
logic x;
|
||||
initial begin
|
||||
type(x) x [1:0];
|
||||
type(x) y [2:0];
|
||||
$display("size of x = %0d", $bits(x));
|
||||
$display("size of y = %0d", $bits(y));
|
||||
end
|
||||
|
||||
logic [2:0][3:0] arr;
|
||||
generate
|
||||
begin : M
|
||||
logic [3:0][4:0] arr;
|
||||
initial $display("M arr[0] = %b", arr[0]);
|
||||
initial $display("M M.arr[0] = %b", M.arr[0]);
|
||||
initial $display("M top.arr[0] = %b", top.arr[0]);
|
||||
end
|
||||
endgenerate
|
||||
initial $display("arr[0] = %b", arr[0]);
|
||||
initial $display("M.arr[0] = %b", M.arr[0]);
|
||||
initial $display("top.arr[0] = %b", top.arr[0]);
|
||||
|
||||
localparam arr2 [2][3] = '{
|
||||
'{1'b0, 1'b1, 1'b1},
|
||||
'{1'b1, 1'b0, 1'b0}
|
||||
};
|
||||
for (genvar i = 0 ; i < 2 ; ++i) begin
|
||||
for (genvar j = 0 ; j < 3 ; ++j) begin
|
||||
localparam value = arr2[i][j];
|
||||
initial $display("%0d %0d %0d", i, j, value);
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,70 @@
|
||||
module top;
|
||||
wire t;
|
||||
initial $display("A t %0d", 1);
|
||||
initial $display("A top.t %0d", 1);
|
||||
generate
|
||||
begin : X
|
||||
wire [1:0] t;
|
||||
initial $display("B t %0d", 2);
|
||||
initial $display("B top.t %0d", 1);
|
||||
initial $display("B X.t %0d", 2);
|
||||
initial $display("B top.X.t %0d", 2);
|
||||
begin : Y
|
||||
wire [2:0] t;
|
||||
initial $display("C t %0d", 3);
|
||||
initial $display("C top.t %0d", 1);
|
||||
initial $display("C X.t %0d", 2);
|
||||
initial $display("C top.X.t %0d", 2);
|
||||
initial $display("C Y.t %0d", 3);
|
||||
initial $display("C X.Y.t %0d", 3);
|
||||
initial $display("C top.X.Y.t %0d", 3);
|
||||
end
|
||||
end
|
||||
genvar i;
|
||||
for (i = 0; i < 3; i = i + 1) begin : Z
|
||||
wire [i:0] t;
|
||||
end
|
||||
endgenerate
|
||||
initial $display("A t %0d", 1);
|
||||
initial $display("A top.t %0d", 1);
|
||||
initial $display("A X.t %0d", 2);
|
||||
initial $display("A top.X.t %0d", 2);
|
||||
initial $display("A X.Y.t %0d", 3);
|
||||
initial $display("A top.X.Y.t %0d", 3);
|
||||
initial $display("A top.Z[0].t %0d", 1);
|
||||
initial $display("A Z[0].t %0d", 1);
|
||||
initial $display("A Z[1].t %0d", 2);
|
||||
initial $display("A Z[2].t %0d", 3);
|
||||
|
||||
wire x;
|
||||
initial begin : name
|
||||
reg [1:0] x;
|
||||
reg [5:0] y;
|
||||
$display("size of x = %0d", $bits(x));
|
||||
$display("size of y = %0d", $bits(y));
|
||||
end
|
||||
|
||||
wire [11:0] arr;
|
||||
generate
|
||||
begin : M
|
||||
wire [19:0] arr;
|
||||
initial $display("M arr[0] = %b", arr[4:0]);
|
||||
initial $display("M M.arr[0] = %b", M.arr[4:0]);
|
||||
initial $display("M top.arr[0] = %b", top.arr[3:0]);
|
||||
end
|
||||
endgenerate
|
||||
initial $display("arr[0] = %b", arr[3:0]);
|
||||
initial $display("M.arr[0] = %b", M.arr[4:0]);
|
||||
initial $display("top.arr[0] = %b", top.arr[3:0]);
|
||||
|
||||
localparam [0:5] arr2 = 6'b011100;
|
||||
generate
|
||||
genvar j;
|
||||
for (i = 0 ; i < 2 ; i = i + 1) begin
|
||||
for (j = 0 ; j < 3 ; j = j + 1) begin
|
||||
localparam value = arr2[i * 3 + j];
|
||||
initial $display("%0d %0d %0d", i, j, value);
|
||||
end
|
||||
end
|
||||
endgenerate
|
||||
endmodule
|
||||
@@ -0,0 +1,87 @@
|
||||
module top;
|
||||
typedef struct packed {
|
||||
logic x;
|
||||
logic [1:0] y;
|
||||
} A;
|
||||
typedef struct packed {
|
||||
logic [2:0] x;
|
||||
logic [3:0] y;
|
||||
} B;
|
||||
typedef struct packed {
|
||||
logic [4:0] x;
|
||||
logic [5:0] y;
|
||||
B z;
|
||||
} C;
|
||||
|
||||
A a;
|
||||
B b;
|
||||
C c;
|
||||
|
||||
generate
|
||||
begin : foo
|
||||
typedef struct packed {
|
||||
logic [6:0] x;
|
||||
logic [7:0] y;
|
||||
} B;
|
||||
typedef struct packed {
|
||||
logic [8:0] x;
|
||||
logic [9:0] y;
|
||||
B z;
|
||||
} D;
|
||||
|
||||
A a;
|
||||
B b;
|
||||
C c;
|
||||
D d;
|
||||
end
|
||||
endgenerate
|
||||
|
||||
`define INSPECT_SIZE(expr) $display(`"expr -> %0d`", $bits(expr));
|
||||
`define INSPECT_DATA(expr) $display(`"expr -> %b`", expr);
|
||||
initial begin
|
||||
`INSPECT_SIZE(a);
|
||||
`INSPECT_SIZE(a.x);
|
||||
`INSPECT_SIZE(a.y);
|
||||
|
||||
`INSPECT_SIZE(b);
|
||||
`INSPECT_SIZE(b.x);
|
||||
`INSPECT_SIZE(b.y);
|
||||
|
||||
`INSPECT_SIZE(c);
|
||||
`INSPECT_SIZE(c.x);
|
||||
`INSPECT_SIZE(c.y);
|
||||
`INSPECT_SIZE(c.z);
|
||||
`INSPECT_SIZE(c.z.x);
|
||||
`INSPECT_SIZE(c.z.y);
|
||||
|
||||
`INSPECT_SIZE(foo.a);
|
||||
`INSPECT_SIZE(foo.a.x);
|
||||
`INSPECT_SIZE(foo.a.y);
|
||||
|
||||
`INSPECT_SIZE(foo.b);
|
||||
`INSPECT_SIZE(foo.b.x);
|
||||
`INSPECT_SIZE(foo.b.y);
|
||||
|
||||
`INSPECT_SIZE(foo.c);
|
||||
`INSPECT_SIZE(foo.c.x);
|
||||
`INSPECT_SIZE(foo.c.y);
|
||||
`INSPECT_SIZE(foo.c.z);
|
||||
`INSPECT_SIZE(foo.c.z.x);
|
||||
`INSPECT_SIZE(foo.c.z.y);
|
||||
|
||||
`INSPECT_SIZE(foo.d);
|
||||
`INSPECT_SIZE(foo.d.x);
|
||||
`INSPECT_SIZE(foo.d.y);
|
||||
`INSPECT_SIZE(foo.d.z);
|
||||
`INSPECT_SIZE(foo.d.z.x);
|
||||
`INSPECT_SIZE(foo.d.z.y);
|
||||
|
||||
`INSPECT_DATA(a);
|
||||
`INSPECT_DATA(b);
|
||||
`INSPECT_DATA(c);
|
||||
`INSPECT_DATA(foo.a);
|
||||
`INSPECT_DATA(foo.b);
|
||||
`INSPECT_DATA(foo.c);
|
||||
`INSPECT_DATA(foo.d);
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,63 @@
|
||||
module top;
|
||||
wire [2:0] a;
|
||||
wire [6:0] b;
|
||||
wire [17:0] c;
|
||||
|
||||
generate
|
||||
begin : foo
|
||||
wire [2:0] a;
|
||||
wire [14:0] b;
|
||||
wire [17:0] c;
|
||||
wire [33:0] d;
|
||||
end
|
||||
endgenerate
|
||||
|
||||
`define INSPECT_SIZE(expr, size) $display(`"expr -> %0d`", size);
|
||||
`define INSPECT_DATA(expr) $display(`"expr -> %b`", expr);
|
||||
initial begin
|
||||
`INSPECT_SIZE(a, 3);
|
||||
`INSPECT_SIZE(a.x, 1);
|
||||
`INSPECT_SIZE(a.y, 2);
|
||||
|
||||
`INSPECT_SIZE(b, 7);
|
||||
`INSPECT_SIZE(b.x, 3);
|
||||
`INSPECT_SIZE(b.y, 4);
|
||||
|
||||
`INSPECT_SIZE(c, 18);
|
||||
`INSPECT_SIZE(c.x, 5);
|
||||
`INSPECT_SIZE(c.y, 6);
|
||||
`INSPECT_SIZE(c.z, 7);
|
||||
`INSPECT_SIZE(c.z.x, 3);
|
||||
`INSPECT_SIZE(c.z.y, 4);
|
||||
|
||||
`INSPECT_SIZE(foo.a, 3);
|
||||
`INSPECT_SIZE(foo.a.x, 1);
|
||||
`INSPECT_SIZE(foo.a.y, 2);
|
||||
|
||||
`INSPECT_SIZE(foo.b, 15);
|
||||
`INSPECT_SIZE(foo.b.x, 7);
|
||||
`INSPECT_SIZE(foo.b.y, 8);
|
||||
|
||||
`INSPECT_SIZE(foo.c, 18);
|
||||
`INSPECT_SIZE(foo.c.x, 5);
|
||||
`INSPECT_SIZE(foo.c.y, 6);
|
||||
`INSPECT_SIZE(foo.c.z, 7);
|
||||
`INSPECT_SIZE(foo.c.z.x, 3);
|
||||
`INSPECT_SIZE(foo.c.z.y, 4);
|
||||
|
||||
`INSPECT_SIZE(foo.d, 34);
|
||||
`INSPECT_SIZE(foo.d.x, 9);
|
||||
`INSPECT_SIZE(foo.d.y, 10);
|
||||
`INSPECT_SIZE(foo.d.z, 15);
|
||||
`INSPECT_SIZE(foo.d.z.x, 7);
|
||||
`INSPECT_SIZE(foo.d.z.y, 8);
|
||||
|
||||
`INSPECT_DATA(a);
|
||||
`INSPECT_DATA(b);
|
||||
`INSPECT_DATA(c);
|
||||
`INSPECT_DATA(foo.a);
|
||||
`INSPECT_DATA(foo.b);
|
||||
`INSPECT_DATA(foo.c);
|
||||
`INSPECT_DATA(foo.d);
|
||||
end
|
||||
endmodule
|
||||
@@ -134,6 +134,7 @@ module top;
|
||||
input StructA b;
|
||||
input StructB c;
|
||||
input StructC d;
|
||||
integer unused;
|
||||
input StructD e;
|
||||
input StructE f;
|
||||
$display("F: %1d%1d%1d -> ", i,j,k, a,b,c,d,e,f);
|
||||
|
||||
Reference in New Issue
Block a user