Parameterized Class when the parameter is a virtual class

Hi,

I have a Parameterized Class :

class my_class#(type in_class_v= base_class_c#()) extends base_class_c;  

   rand in_class cntrl;
   
   `uvm_object_param_utils_begin(my_class#(.in_class_v(in_class_v)))
      `uvm_field_object(cntrl,UVM_ALL_ON)
   `uvm_object_utils_end
	
   function new(string name = "my_class");
      super.new(name);
      cntrl= in_class_v::type_id::create("cntrl"); //NOT COMPILING !!!
   endfunction   
endclass : my_class

while in_class_v is a virtual class :

virtual class base_class_c#(int WIDTH = -1) extends uvm_object;

    logic [WIDTH-1:0] ds_packed;

    pure virtual function void ds_pack();
    pure virtual function void ds_unpack();

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

endclass // base_class_c

and i have a not virtual class that is derived from the virtual class

class dev_class_c#(int BUS_WIDTH = CTRL_WIDTH) extendsbase_class_c#(WIDTH);

      rand bit [0:0] error;

      `uvm_object_utils_begin(dev_class_c)

            `uvm_field_int(error, UVM_ALL_ON)

      `uvm_object_utils_end

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

      // Pack all fields into bus
      virtual function void ds_pack();

      endfunction

      // Unpack bus to fields 
      virtual function void ds_unpack();
       endfunction

endclass
  • At my verification environment i use my_class with the parameter of dev_class_c

  • the problem is that the whole thing is not even compiling (fails at elaboration phase)

i get this error :


cntrl= in_class_v::type_id::create("cntrl");
                           |
xmelab: *E,CUVSCE  Scoped name component 'type_id' lookup failed at 'base_class_c'.

What is the problem ???

thanks !

In reply to snognog:

Do you have a typo? base_class_c vs. in_class_v?

In reply to dave_59:

Hi Dave,

well, if we look in the virtual class code :

class my_class#(type in_class_v= base_class_c#()) extends base_class_c;

rand in_class cntrl;

uvm_object_param_utils_begin(my_class#(.in_class_v(in_class_v))) uvm_field_object(cntrl,UVM_ALL_ON)
`uvm_object_utils_end

function new(string name = “my_class”);
super.new(name);
cntrl= in_class_v::type_id::create(“cntrl”); //NOT COMPILING !!!
endfunction
endclass : my_class

this is my typo from my code to the question here… it should be of course

cntrl= in_class::type_id::create(“cntrl”); //NOT COMPILING !!!

i’ve read in some sites and it seems that there may be a problem that this base_class_c is a virtual class, and that cause the elaboration problem (even though when creating instance of the my_class, i use a non virtual class that was derived from base_class_c)

still in elaboration it fails.

Thanks

In reply to snognog:

That is a typo as well, as there is no in_class with the you have provided.

Assuming you meant

cntrl= base_class_c::type_id::create("cntrl"); //NOT COMPILING !!!

There are two issues here.

In UVM 1.1d and 1.2, the factory does not work when the base class is a virtual class. This has been addressed in 1800.2, but until that is widely available, do not make your base class virtual, or create an intermediary class that is not virtual.

The other issue is with the parameterization of the base class. Its value has to be paired with the value used in the override. You gave WIDTH the default value of -1. The override has to pass -1 as well, which is probably not what you wanted to do. It would help if did not specify a default for the parameter WIDTH. The you would be forced to provide one every time you referenced base_class_c.

In reply to dave_59:

Thanks !

you are right
the problem is indeed the base class as a virtual class, and the problem with the factory not working with that base class.