but if I remove the keyword packed as you suggested, vcs reports 2 errors: Error-[IBC] Invalid bounds count sc_assignment_pattern_030.sv,29 The following access has an invalid number of indices.st4.st2.push_back Error-[XMRE] Cross Module reference resolution error sc_assignment_pattern_030.sv, 29 Error found while trying to resolve cross-module reference. token 'st2'. Originating module 'test'. Source Info:st4.st2.push_back((i+1)); then how should I fix these 2 errors?
时间: 2024-03-12 14:49:04 浏览: 159
mipi_CSI-2_specification_v1_mipi_CSI2资料_mipicsi2_mipi_MIPIcsi_mi
5星 · 资源好评率100%
I apologize for the mistake in my previous answer. The use of an unpacked array in the struct declaration requires an explicit size. To fix the syntax error and the cross-module reference error, you can modify the declaration of `st2` to include a size for the unpacked array.
Here is the corrected code:
```
module test;
typedef struct packed {
logic [9:-1][2:0] a;
} ST1;
typedef struct {
ST1 st1;
ST1 st2[$];
logic [7:0] b;
} ST4;
initial begin
ST4 st4;
st4.st1.a[0][0] = 1;
for (int i = 0; i < 5; i++) begin
st4.st2.push_back(ST1'(i + 1));
end
st4.b = 8'hAA;
$display("%s", st4.st2); //CHECK-001:'{a:'h1}, st2:'{'a:'h1}, {'a:'h2},{'a:'h3},{'a:'h4},{'a:'h5}}}
end
endmodule
```
In this code, the declaration of `st2` now includes the size `[$]` to indicate that it is an unpacked array with a dynamic size. The `$` size specifier allows the size of the array to be determined at runtime, based on the number of elements that are pushed onto the array using the `push_back` method.
With this modification, the code should now compile without any syntax errors or cross-module reference errors.
阅读全文