I just found this strange behavior. The type_id::create() function does not pass my object name to the new function
My code is like this
class my_cfg extends uvm_objects;
//attributes
string m_name;
// register pib_cfg with the factory
`uvm_object_utils_begin(pib_cfg)
`uvm_field_string(m_name, UVM_ALL_ON)
`uvm_object_utils_end
//constructor
function new (string name = "my_cfg");
super.new(name);
endfunction : new
endclass : my_cfg
In my testbench I did this
my_cfg my_cfg_h;
core_id = $sformatf("%m");
$sformat(str, "m_pb_cfg_%s", core_id);
my_cfg_h = my_cfg::type_id::create(str);
In interactive mode, I step into the create() function, find that when it call the new() function, it passes an empty string (“”) to the new function, even though my str has already being customized by the hierarchical path of the module. As the result, all the my_cfg instances are created with the same name “my_cfg” (the defalut).
I don’s see this behavior for other classes that was extended from uvm_component. My customized object name was passed to the new() function correctly.
Anyone has idea why?
Thanks in advance
In reply to Michaelotus:
This code worked for me:
module top;
import uvm_pkg::*;
`include "uvm_macros.svh"
class my_cfg extends uvm_object;
//attributes
string m_name;
// register pib_cfg with the factory
`uvm_object_utils_begin(my_cfg)
`uvm_field_string(m_name, UVM_ALL_ON)
`uvm_object_utils_end
//constructor
function new (string name = "my_cfg");
super.new(name);
endfunction : new
endclass : my_cfg
my_cfg my_cfg_h;
string core_id,str;
initial begin
core_id = $sformatf("%m");
$sformat(str, "m_pb_cfg_%s", core_id);
my_cfg_h = my_cfg::type_id::create(str);
$display(" Object name is: ",my_cfg_h.get_name());
end
endmodule
Note that m_name is an existing member of uvm_object, so there may be some confusion in how you are using it in the code you did not show. Use a different spelling.
Also, we do not recommend using the field automation macros, that could be part of the problem as well.
In reply to dave_59:
In reply to Michaelotus:
This code worked for me:
module top;
import uvm_pkg::*;
`include "uvm_macros.svh"
class my_cfg extends uvm_object;
//attributes
string m_name;
// register pib_cfg with the factory
`uvm_object_utils_begin(my_cfg)
`uvm_field_string(m_name, UVM_ALL_ON)
`uvm_object_utils_end
//constructor
function new (string name = "my_cfg");
super.new(name);
endfunction : new
endclass : my_cfg
my_cfg my_cfg_h;
string core_id,str;
initial begin
core_id = $sformatf("%m");
$sformat(str, "m_pb_cfg_%s", core_id);
my_cfg_h = my_cfg::type_id::create(str);
$display(" Object name is: ",my_cfg_h.get_name());
end
endmodule
Note that m_name is an existing member of uvm_object, so there may be some confusion in how you are using it in the code you did not show. Use a different spelling.
Also, we do not recommend using the field automation macros, that could be part of the problem as well.
Hi Dave,
Thanks for the point. It may be a Cadence simulator issue. I see in my code get_name() method returns the object name I customized. So likely just that the interactive source browser does not display the passed in value correctly at new() function.
Another question - “not recommend using the field automation macros”. Why is that? I recall text books recommend to use it.