Uvm_component_utils with parameters

When you are dealing with parameterized classes in UVM, you need to use the “param” version of the factory registration macros to register with the factory. You can then set the parameters when you create an object. Example code would look something like this:

class my_param_class #(int paramA = 5, string paramB = "hello") extends uvm_component;
   `uvm_component_param_utils(my_param_class#(paramA, paramB))

   //The rest of the class

endclass : my_param_class

class another_class extends uvm_component;
   `uvm_component_utils(another_class)

   my_param_class #(10, "goodbye")  my_class_h;

   //Constructor, etc.

   function void build_phase(uvm_phase phase);
      super.build_phase(phase);
    
      my_class_h = my_param_class #(10, "goodbye")::type_id::create("my_class_h", this);

   endfunction : build_phase

endclass : another_class
3 Likes