# Parent parameter for new function in agent class

**URL:** <https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292>\
**Category:** UVM\
**Tags:** UVM, new\
**Created:** [April 3, 2018, 2:23pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292 "2018-04-03T14:23:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![verif\_learner1](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@verif\_learner1](https://verificationacademy.com/forums/u/verif_learner1)\
**Post date:** [April 3, 2018, 2:23pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/1 "2018-04-03T14:23:29Z")

</div>

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

```verilog
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?

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 3, 2018, 2:35pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/2 "2018-04-03T14:35:56Z")

</div>

_In reply to [verif\_learner](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292):_

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.

---

<div class="post-metadata">

**Author:** ![verif\_learner1](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@verif\_learner1](https://verificationacademy.com/forums/u/verif_learner1)\
**Post date:** [April 3, 2018, 4:48pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/3 "2018-04-03T16:48:58Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/2):_

> _In reply to [verif\_learner](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/2):_  
> 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?

---

<div class="post-metadata">

**Author:** ![mayurkubavat](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@mayurkubavat](https://verificationacademy.com/forums/u/mayurkubavat)\
**Post date:** [April 4, 2018, 6:33am UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/4 "2018-04-04T06:33:43Z")

</div>

_In reply to [verif\_learner](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/3):_

Consider below function:

```verilog
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.

```verilog
class Env;

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

```

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [April 4, 2018, 6:54am UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/5 "2018-04-04T06:54:18Z")

</div>

_In reply to [MayurKubavat](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/4):_

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 “”’.

---

<div class="post-metadata">

**Author:** ![nikhilsingla4u](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/2bfe46/32.png) [@nikhilsingla4u](https://verificationacademy.com/forums/u/nikhilsingla4u)\
**Post date:** [April 4, 2018, 8:31am UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/6 "2018-04-04T08:31:59Z")

</div>

_In reply to [verif\_learner](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/5):_

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 .

---

<div class="post-metadata">

**Author:** ![verif\_learner1](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/7993a0/32.png) [@verif\_learner1](https://verificationacademy.com/forums/u/verif_learner1)\
**Post date:** [April 4, 2018, 4:29pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/7 "2018-04-04T16:29:53Z")

</div>

_In reply to [nikhilverif](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/6):_

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

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 4, 2018, 4:38pm UTC](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/8 "2018-04-04T16:38:12Z")

</div>

_In reply to [verif\_learner](https://verificationacademy.com/forums/t/parent-parameter-for-new-function-in-agent-class/34292/7):_

_THis_ was not your original question.

```verilog
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.
