'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


Solution 1:[1]

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

class my_child extends uvm_component;

to:

class my_child extends my_parent;

When you make this change and run the simulation, it prints the following, as expected:

Hello, UVM!

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1