module test; typedef struct packed { bit [9:-1][2:0] a; ///REQ-EXT-10001, REQ-EXT-10004 bit [3:0] b; } ST1; typedef struct { ST1 st1; ST1 st2[3:0]; } ST2; typedef struct { ST2 st3; ST2 st3 = '{ '{ {9{1'b0}}, 4'h5, {{10{3'b0}}, 3'b1, 12'hABC, 3'b0}}}; }ST3; logic clk; always @ (posedge clk) begin ST2 st2 = '{ {10{1'b1}}, '{3'b1, 3'b0, 12'hFFF,3'b1}}; $display("st2 before:%0d '%h", st2.st2[0].b, st2.st2[0].a); st3.st2[0].b=st3.st2[0].b+1; end endmodule when compiled by vcs, it reports Error-[XMRE] Cross-Module reference resolution error sc_assignment_pattern_058.sv, 35 Error found while trying to resolve cross-module reference. token 'st3'. Originating module 'test'. Sournce info: st3.st2[0].b= (st3.st2[0].b+1); how should I fix this error?
时间: 2024-03-20 16:42:21 浏览: 56
The error is caused by trying to access a variable declared in a nested structure from outside the structure. To fix this error, you can declare the ST3 structure outside the module scope, and then instantiate it inside the module. Here is an example code snippet that fixes the error:
```
typedef struct packed {
bit [9:-1][2:0] a; ///REQ-EXT-10001, REQ-EXT-10004
bit [3:0] b;
} ST1;
typedef struct {
ST1 st1;
ST1 st2[3:0];
} ST2;
typedef struct {
ST2 st3;
ST2 st3_init = '{ '{ {9{1'b0}}, 4'h5, {{10{3'b0}}, 3'b1, 12'hABC, 3'b0}}};
}ST3;
module test;
logic clk;
ST3 st3_inst;
always @ (posedge clk) begin
ST2 st2 = '{ {10{1'b1}}, '{3'b1, 3'b0, 12'hFFF,3'b1}};
$display("st2 before:%0d '%h", st2.st2[0].b, st2.st2[0].a);
st3_inst.st3.st2[0].b = st3_inst.st3.st2[0].b + 1;
end
endmodule
```
In this code, the ST3 structure is declared outside the module scope, and then an instance of it is created inside the module using the name `st3_inst`. This allows the `st3_inst` variable to be accessed from inside the module, including in the `always` block.
阅读全文