Wuuu
Wuuu

Reputation: 21

Complex DataType in system verilog(hash of queues)

Suppose I declared a queue: axi4_req_txn_t wr_req_queue[$]; Now I want to have a hash of queue, key is the address and data is the pointer to the queue; Is it possible in systemverilog ?

when I write code like this: typedef wr_req_queue waw_hash[*]; the compiler reports that wr_req_queue is not a valid type.

Upvotes: 0

Views: 1163

Answers (1)

Serge
Serge

Reputation: 12354

A rule of thumb is to express any complicated struct as a typedef if you want to use in another typedef. So, here is a simple example of array of queues:

package pkg;
   typedef int mytype_t; // whatever the type of queue elements 
   typedef mytype_t queue_type_t[$];  // queue of mytype_t
   typedef queue_type_t array_type_t[int]; // associative  array of queues
endpackage // pkg

// test the above
module tb;
   import pkg::*;
   
   array_type_t arr;

   initial begin
      arr[0] = {0};
      arr[1] = {1};
      arr[3] = {arr[0], arr[1]};

      $display(arr);
   end
endmodule // tb

Or vice versa, queue of arrays:

package pkg;
   typedef int/*your type*/ mytype_t;
   typedef mytype_t array_type_t[int];
   typedef array_type_t queue_type_t[$];
endpackage // pkg

module tb;
   import pkg::*;
   
   array_type_t arr;

   initial begin
      array_type_t arr1, arr2;
      queue_type_t que;

      arr1[0] = 0;
      arr2[0] = 1;
      arr2[1] = 2;

      que = {arr1};
      que = {que,arr2};

      $display(que);
   end
endmodule // tb

Upvotes: 1

Related Questions