【UVM】parameterized classes

  1. SystemVerilog uses a “#” sign to list the Parameter names in a Class Header to define a Generic Class.
  2. When we specify a default Parameter in a Class Header, we don’t have to provide an Overrides for that Parameter when referencing that Class.
  3. Generic Class & actual Parameter values is called a Specialization.
  4. Static Class Properties do not get allocated unless their Class is Specialized
  5. Every Specialization has unique set of Static Properties

 

以sequence為例(new_sequence override packet_sequence):

class packet_sequence #(CC_NUM = 3) extends uvm_sequence #(packet);

  int item_cnt = 10;

  `uvm_object_param_utils_begin(packet_sequence#(CC_NUM))
     `uvm_field_int(item_cnt,UVM_ALL_ON)
  `uvm_object_utils_end

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

class new_sequence#(CC_NUM = 3)extends packet_sequence;
  `uvm_object_param_utils(new_sequence#(CC_NUM))
  
   function new(string name = "new_sequence");
     super.new(name);
   endfunction
   .....
endclass

 

class base_test extends uvm_test;

  virtual function void build_phase(uvm_phase phase);
    ....
    set_type_override_by_type(packet_sequence#(5)::get_type(),new_sequence#(5)::get_type());

    uvm_config_db #(uvm_object_wrapper)::set(this,"env.i_agent.seqr.main_phase","default_sequence",packet_sequence#(5)::get_type());
   
  endfunction
endclass

如果packet_sequence在test_base new的話:

seq= packet_sequence#(CC_NUM)::type_id::create("seq");

 

parameterized class 有以下幾點需要注意:

  • 要用`uvm_object_param_utils聲明;
  • 任何使用parameterized class的地方均要加上#(parameter);

下面舉個sv的例子:

/ Parameterized Class Declaration
class transaction #(type T = int, type A = bit, int R = 3);
  /// CRC Declaration
  T crc;
  /// Source Address
  bit [R:0] SA;
  /// Dynamic Array Declaration
  T dynam [];

  /// Constructor
  function new (A a);
    SA = a;
  endfunction: new

  /// Calculate CRC Task
  task CalCrc (T t);
    this.crc = t;
  endtask: CalCrc

  /// Print Function
   function void print;
     $display("Value of R = %0d, Source Address = %b, No. of DyArr entries = %0d, CRC = %b, Dynamic Element[3] = %b ", this.R, this.SA, this.dynam.size(), this.crc, dynam[3]);
   endfunction: print

 endclass: transaction

//======================================================================================

/ Extended Class with Non-default Specialization
class my_transaction extends transaction #(bit [3:0], int, 9);
  ///  Newly Added Property
  int errBit;
  /// Constructor
  function new (A b);
    super.new(b);
  endfunction: new
 
endclass: my_transaction

//======================================================================================

/ Top Module
module top;
 initial begin
   fork
     begin
      transaction #(bit [7:0], bit [3:0]) txn;
      txn = new(4);
      txn.dynam = new[5];
      foreach (txn.dynam[i])
        txn.dynam[i] = i;
      txn.CalCrc(6);
      txn.print;
     end
     begin
      my_transaction mtxn;
      mtxn = new(5);
      mtxn.dynam = new[5];
      foreach (mtxn.dynam[i])
        mtxn.dynam[i] = i;
      mtxn.CalCrc(7);
      mtxn.print;
    end 
  join
 end
endmodule: top

the Extended Class without any customized Parameters, default Parameters types will be applied to the Extended Class.

 

你可能感兴趣的:(UVM)