[uvm] item域是另外一个item 时, item随机化处理

195 阅读1分钟

静态数组

class my_transaction0  extends uvm_sequence_item;
  rand bit[29:0] data;
  constraint data_cons{
   // data<=1048575;
    data[29:20] <=10'b0;
  }

  `uvm_object_utils_begin(my_transaction0)
    `uvm_field_int(data, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name="my_transaction0");
    super.new(name);
  endfunction

endclass

class my_transaction  extends uvm_sequence_item;
//class my_transaction  extends my_transaction0;
  rand my_transaction0 axc [120];  //item类型  静态数组
  //constraint axc_cons{
   // data<=1048575;
   // data[29:20] <=10'b0;
    //axc.size =120;
 // }

  `uvm_object_utils_begin(my_transaction)
    //`uvm_field_int(data, UVM_ALL_ON)
    `uvm_field_sarray_object(axc, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name="my_transaction");
    super.new(name);
  endfunction

endclass


在sequence中随机化 ,需要逐层new randomize最底层的item

//...
  virtual task body();
    if(starting_phase != null) 
         starting_phase.raise_objection(this);
      #100;
      //repeat(2) begin
         m_trans = new();
       //  m_trans.axc = new[120];
        m_trans.randomize();
     foreach(m_trans.axc[i]) begin
       m_trans.axc[i]  = new();
       m_trans.axc[i].randomize();
     end
  if(starting_phase != null) 
         starting_phase.drop_objection(this);
endtask

//...

动态数组

class my_transaction0  extends uvm_sequence_item;
  rand bit[29:0] data;
  constraint data_cons{
   // data<=1048575;
    data[29:20] <=10'b0;
  }

  `uvm_object_utils_begin(my_transaction0)
    `uvm_field_int(data, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name="my_transaction0");
    super.new(name);
  endfunction

endclass

class my_transaction  extends uvm_sequence_item;
//class my_transaction  extends my_transaction0;
  rand my_transaction0 axc [];
  //constraint axc_cons{
   // data<=1048575;
   // data[29:20] <=10'b0;
    //axc.size =120;
 // }

  `uvm_object_utils_begin(my_transaction)
    //`uvm_field_int(data, UVM_ALL_ON)
    `uvm_field_array_object(axc, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name="my_transaction");
    super.new(name);
  endfunction

endclass
  virtual task body();
      if(starting_phase != null) 
         starting_phase.raise_objection(this);
      #100;
      //repeat(2) begin
         m_trans = new();
         m_trans.axc = new[120];  //动态数组需要new[]
       // m_trans.randomize();
     foreach(m_trans.axc[i]) begin
       m_trans.axc[i]  = new();
       m_trans.axc[i].randomize();
     end

         m_trans.print();
         start_item(m_trans);
         finish_item(m_trans);

      if(starting_phase != null) 
         starting_phase.drop_objection(this);
   endtask