Jump to content

Question for array of class

Recommended Posts


I have a question of `uvm_do() macro usage.

The following is an example code.

class my_transfer extends uvm_object;

rand string direction;

rand bit [31:0] addr;

rand bit [31:0] wdata;


class my_transaction extends uvm_sequence_item;

rand int delay_before_transaction;

rand int transfer_size;

constraint const_c { transfer_size < 1000; }

rand my_transfer transfers[];

constraint transfer_c {transfers.size() == transfer_size; }

rand int delay_to_req_end;


In my sequence class, I want to execute like below code. But randomization is failed. Becuase there is no allocation of "transfers" array.

virtual task body();


// or

`uvm_do_with(req, {req.transfer_size == 7; req.transfers[0].direction == READ; })


If above sequence works, how should I modify my code? Is there any simple example?

(I want that each transfer within transaction has constrained-random value for each field and I want to control this constraint in test senario or sequence.)

Thanks & Regards,


Edited by yyn
Link to comment
Share on other sites


There are several ways to do what you ask.

one way is:

You could upfront `uvm_create the object and then do

for(int i =0; i<transfer_size; i++); req.transfers=new;


lets assume all my_transfer array assignments happen after my_transaction variables are set.

add to class my_transaction

      function void post_randomize();
 foreach (transfers[i])  transfers[i]= new();

then lets assume you need to update req with the relevant data before it is send to the driver.

add to sequence, perform aray assignment:

  virtual task body();
     `uvm_do_with(req, {transfer_size==7;})      
  function  void mid_do (uvm_sequence_item this_item);

There are other ways to achieve this, so it really depends on what you want to do.

Also, have a look at the send_request() and sequence API in the class-ref.

FYI, you probably dont want "rand string direction".

instead try:

typedef enum {READ,WRITE} direction_t;
class my_transfer extends uvm_sequence_item;
  rand direction_t direction;



Link to comment
Share on other sites


another option is to avoid the rand-array-allocation issue at all is to generate the elements on the fly and NOT the full array upfront. if you do have dependencies between the transactions you can add inline constraints using the uvm_do_*_with class of macros and refer to send items.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...