Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The parent argument in the uvm_component constructor

I expected my_child to inherit the say_hello function from my_parent in the following code, but it did not.

Can someone explain to me what exactly parent argument does?

class my_parent extends uvm_component;
  `uvm_component_utils(my_parent);
  
  function new(string name = "my_parent", uvm_component parent);
    super.new(name, parent);
  endfunction: new
  
  function void say_hello;
    $display("Hello, UVM!");
  endfunction: say_hello
endclass: my_parent
/*========================================*/

class my_child extends uvm_component;
  `uvm_component_utils(my_child);
  
  function new(string name = "my_child", uvm_component parent);
    super.new(name, parent);
  endfunction: new
endclass: my_child
/*========================================*/

module top;
  my_parent p;
  my_child c;
  
  initial begin
    p = my_parent::type_id::create("p", null);
    c = my_child::type_id::create("c", p);
    c.say_hello;
  end 
endmodule: top

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should extend the child class from the parent class instead of uvm_component when you want to inherit from the parent class. Change:

class my_child extends uvm_component;

to:

class my_child extends my_parent;

The parent variable is explained in the UVM Class Reference document under uvm_component.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading