I defined following data structures:
typedef int profile_lru_q_t[PROFILE_NUM];
typedef profile_lru_q_t vc_lru_queue[$];
vc_lru_queue vc_lru_queue_inst;
It's a queue of queue. I want to initialize it with the following code but failed. Can anyone help me with it?
for (int i=0; i<PROFILE_NUM; i++) begin
for (int j=SDP_VC_NUM-1; j>=0; j--) begin
vc_lru_queue_inst[i].push_back = j;
end
end
One problem is that you do not have a queue of queues. You have a queue of fixed-sized arrays because this line declares a fixed-sized array, not a queue:
typedef int profile_lru_q_t[PROFILE_NUM];
If you want to initialize the structure you have, here is a way to do it:
module tb;
parameter PROFILE_NUM = 4;
parameter SDP_VC_NUM = 4;
typedef int profile_lru_q_t [PROFILE_NUM]; // array, not a queue
typedef profile_lru_q_t vc_lru_queue [$]; // queue
vc_lru_queue vc_lru_queue_inst;
initial begin
for (int i=0; i<PROFILE_NUM; i++) begin
profile_lru_q_t inner;
for (int j=SDP_VC_NUM-1; j>=0; j--) begin
inner[j] = j;
end
vc_lru_queue_inst.push_back(inner);
end
$display("%p", vc_lru_queue_inst);
end
endmodule
This prints:
'{'{0, 1, 2, 3}, '{0, 1, 2, 3}, '{0, 1, 2, 3}, '{0, 1, 2, 3}}
Although, since you declared the array of a fixed size using PROFILE_NUM
, it does not make much sense to iterate over SDP_VC_NUM
.
Another problem is that push_back = j
is incorrect syntax. push_back.(j)
is legal.
Refer to IEEE Std 1800-2023 section 7.10 Queues.