Parent parameter for new function in agent class

,

This is the new function in agent class. This is a reference code I am using for my project.

function spi_agent::new(string name = "spi_agent", uvm_component parent = null);
  super.new(name, parent);
endfunction

As this is an agent class, shouldn’t the parent parameter be the environment class rather than null?

In reply to verif_learner:

The env class object gets passed as an argument when calling the new() constructor. But no class derived from uvm_component is required to have a parent.

In reply to dave_59:

In reply to verif_learner:
The env class object gets passed as an argument when calling the new() constructor. But no class derived from uvm_component is required to have a parent.

The following is what I see in UVM reference guide.

Creates a new component with the given leaf instance name and handle to its parent. If
the component is a top-level component (i.e. it is created in a static module or
interface), parent should be null.
The component will be inserted as a child of the parent object, if any. If parent already
has a child by the given name, an error is produced.
If parent is null, then the component will become a child of the implicit top-level
component, uvm_top.

If I am new’ing agent class then it looks like i need to pass env class as the parent.
Maybe there is no major issue if I keep it null but are there any implications.
For example, if I use get_parent or get_full_name for this class then I assume, I get a wrong answer. Any thoughts?

In reply to verif_learner:

Consider below function:

module test;
  function void message(string msg = "");
    $display("%s", msg);
  endfunction

  initial
  begin
    message("Started Simulation..");
    #10 $finish;
  end
endmodule

Here function message default argument is null. But when calling the function, we do provide an argument. So, when you want Agent instance to be part of Env, you need to provide parent argument when calling the function. By the way, call create() method which calls new().

E.g.

class Env;

  //build_phase()
  ..
  myAgent = Agent::type_id::create("myAgent", this); //Here parent is this component (Env)
  ..
endclass

In reply to MayurKubavat:

I do not believe this is a good example, because in your message definition the argument is not null. ‘null’ is only used for object-type arguments, but your argument is simply a string and the default value is the ‘empty string “”’.

In reply to verif_learner:

Yes , parent should be passed while creating the agent , else it will come under the scope of UVM_TOP . I am attaching 1 code snippet and output .

env_code :
abc h_dummy;
abc h_dummy1;
build_phase()
h_dummy = abc::type_id::create(“config_h_dummy”,null); // with null parent
h_dummy1 = abc::type_id::create(“config_h_dummy1”,this); // with parent as env

Output topology :

Name-----------------------------------Type----------------------------------Size----Value

h_dummy--------------------------------abc-------------------------------------#-----@2207
uvm_test_top---------------------------base_test-------------------------------#-----@833
–env---------------------------------------env-------------------------------------#-----@874
—h_dummy1----------------------------abc-------------------------------------#-----@2216

From functionality point of view , it won’t make any noticable difference unless you are using any handle hierarchically , but its always better to maintain the TB hierarchy the way data flows .

In reply to nikhilverif:

THis is exactly what I was getting at but I don’t have an example to explain. Definitely, uvm guide is clear about it.

In reply to verif_learner:

THis was not your original question.

function spi_agent::new(string name = "spi_agent", uvm_component parent = null);
  super.new(name, parent);
endfunction

You asked why there was a null in the declaration of the argument
uvm_component parent = null
. That is not the same as the object that gets passed to that argument(arg2) through the
create( arg1, arg2)
method.