Jump to content

Setting name variable in create method for uvm_object


Recommended Posts

I face a problem which I believe is not so rare.

I pass the string variable name to member objects (of other class) in new function of my data class. When I use create() method to create the objects of my data, only the default value of name (upper_object) is passed down into the object.

I've realized this is due to the implementation of create_object() method where we call new() without any arguments and then explicitly call set_name() method to set the name variable.

Q. Is there any specific need to call the new method without any argument when we have already access to the name string in create_object method ?

class lower_object;
 rand int data [];
 string name;

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

endclass: my_object

class upper_object extends uvm_object;
 lower_object  lowerO;

 function new(string name="upper_object");
   super.new(name);
   lowerO=new(name);//This always gets the value 'upper_object'
 endfunction: new

endclass: upper_object

module Top;
 upper_object upperO;

 initial begin
   upperO=upper_object::type_id::create("TestStream1"); 
   // what create_object does is: 
   //upperO=new; //No argument passed 
   //upperO.set_name(name);   
 end
endmodule: Top

I would be glad to see a change in implementation coming along this line in the future, but would like to know what is the best way to get this thing going for now. Presently I override the set_name() function of upper_object to assign name field of member lowerO with the updated value.

Thanks,

Malkesh

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

I tried your example, and paste the whole code below which can be compiled.


import uvm_pkg::*;
`include "uvm_macros.svh"
class lower_object;
  rand int data [];
  string name;

  function new(string name="");
    this.name=name;
  endfunction: new
  function void display();
    $display("lower_object's name:%s", name);
  endfunction
endclass: lower_object

class upper_object extends uvm_object;
  lower_object  lowerO;
  `uvm_object_utils(upper_object)

  function new(string name="upper_object");
    super.new(name);
    lowerO=new(name);//This always gets the value 'upper_object'
  endfunction: new

  function void display();
    $display("upper_object's name:%s", get_full_name());
    lowerO.display();
  endfunction:display
endclass:upper_object

module top;
  upper_object upperO;

  initial begin
    upperO = upper_object::type_id::create("TestStream1"); 
    // what create_object does is: 
    //upperO=new; //No argument passed 
    //upperO.set_name(name);   
    upperO.display();
  end
endmodule:top

The answer is

# upper_object's name:TestStream1

# lower_object's name:upper_object

is just what you said.

If upperO indeed is constructed in new(name) constructor, and in new(name) it instantiate lowerO, Then, lowerO should have the same name as uppperO. but the answer is not the case.

maybe create() does not indeed call the new(name) constructor to create upperO and there is something else behind that.

I also want to know the answer.

Edited by wkongzhu
Link to comment
Share on other sites

Yes, the UVM create() method calls new() constructor on the object without any arguments (string name is not passed in there). That means the default value is going to be used in new(). After new'ing , it uses set_name() to assign the appropriate value to the name string. The code is something like this:

function void create(string name);
 ...
 obj = new();
 obj.set_name(name);
 ...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...