3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 00:55:32 +00:00

Fix generate scoping issues

- expand_genblock defers prefixing of items within named sub-blocks
- Allow partially-qualified references to local scopes
- Handle shadowing within generate blocks
- Resolve generate scope references within tasks and functions
- Apply generate scoping to genvars
- Resolves #2214, resolves #1456
This commit is contained in:
Zachary Snow 2020-07-31 20:13:05 -06:00
parent c39ebe6ae0
commit c3e95eb1ab
3 changed files with 168 additions and 42 deletions

View file

@ -159,3 +159,88 @@ generate
end
endgenerate
endmodule
// ------------------------------------------
module gen_test7;
reg [2:0] out1;
reg [2:0] out2;
wire [2:0] out3;
generate
begin : cond
reg [2:0] sub_out1;
reg [2:0] sub_out2;
wire [2:0] sub_out3;
initial begin : init
reg signed [31:0] x;
x = 2 ** 2;
out1 = x;
sub_out1 = x;
end
always @* begin : proc
reg signed [31:0] x;
x = 2 ** 1;
out2 = x;
sub_out2 = x;
end
genvar x;
for (x = 0; x < 3; x = x + 1) begin
assign out3[x] = 1;
assign sub_out3[x] = 1;
end
end
endgenerate
// `define VERIFY
`ifdef VERIFY
assert property (out1 == 4);
assert property (out2 == 2);
assert property (out3 == 7);
assert property (cond.sub_out1 == 4);
assert property (cond.sub_out2 == 2);
assert property (cond.sub_out3 == 7);
`endif
endmodule
// ------------------------------------------
module gen_test8;
// `define VERIFY
`ifdef VERIFY
`define ASSERT(expr) assert property (expr);
`else
`define ASSERT(expr)
`endif
wire [1:0] x = 2'b11;
generate
begin : A
wire [1:0] x;
begin : B
wire [1:0] x = 2'b00;
`ASSERT(x == 0)
`ASSERT(A.x == 2)
`ASSERT(A.C.x == 1)
`ASSERT(A.B.x == 0)
end
begin : C
wire [1:0] x = 2'b01;
`ASSERT(x == 1)
`ASSERT(A.x == 2)
`ASSERT(A.C.x == 1)
`ASSERT(A.B.x == 0)
end
assign x = B.x ^ 2'b11 ^ C.x;
`ASSERT(x == 2)
`ASSERT(A.x == 2)
`ASSERT(A.C.x == 1)
`ASSERT(A.B.x == 0)
end
endgenerate
`ASSERT(x == 3)
`ASSERT(A.x == 2)
`ASSERT(A.C.x == 1)
`ASSERT(A.B.x == 0)
endmodule