How to define variable typedef? is it possible or not?


//main transaction class consist common response signals of read and write transactions 
class axi_slave_transaction #(ADDR_WIDTH=32);
  
  typedef enum bit [1:0] {OKAY,EXOKAY,SLVERR,DECERR} response_sig;
  
  //typedef variable declared for response signal 
  rand response_sig w_resp_t;  
  
  //signals which are common in read and write transaction
  bit [ADDR_WIDTH-1:0]ADDR;
  bit [7:0]LEN;
  bit [2:0]SIZE;
  bit [1:0]BURST;
  
endclass:axi_slave_transaction


//read transaction class
class read_transaction extends axi_slave_transaction;
  
  //typedef declartion of queue having variable size depending on SIZE
  typedef  bit [1023:0]r_data_queue_t[$]; // (want to implement) -> typedef bit [((2**SIZE)*8)-1:0] R_DATA_QUEUE_T
  
  //read data from memory and store into queue
  function r_data_queue_t read_data_from_memory(r_data_queue_t r_data_q,input ADDR);
    repeat (LEN)
      begin
        r_data_q.push_back(MEM[ADDR++]);
      end
    return r_data_q;
  endfunction:read_data_from_memory
  
endclass:read_transaction  

I want to use the queue(here R_DATA_QUEUE_T) width equal to the variable “SIZE” width. and I want that queue(here R_DATA_QUEUE_T) to be defined using a typedef construct to be used as a return type of function. but the width should be constant inside the typedef construct.

how can I achieve this requirement?
please help me out!

Thanks & Regards

In reply to jj_bukhari:

typedefs must be created during compilation; they cannot depend on a variable which gets its value during run-time. There are several alternatives to handle this

  • Keep r_data_q declared with the maximum size 1024. Depending in what you need to do, you have to take SIZE into account in your code. For example if you need to pack the data.
  • Make SIZE a parameter, that fixers it to one value. Then you can use your typedef. If you need different values, you can create different class specializations that override the value of the SIZE parameter.
  • Make r_data_q a stream of a single bit queue. Then you’ll have to push 1-bit at a time for every SIZE bit, our use the streaming operator