What is the way of finding the name of parent object/component from a child object/component?
For instance, I’d like to find the name of the ovm_env component that ‘has a’ monitor component inside an agent component and print it. The get_full_name() method gives full name. Is there a way to get only the name of the ovm_env.
From the xbus example in the downloaded ovm folder shows similar code for retrieving the name of the agent housing the monitor.
trans_collected.slave = m_parent.get_name();
What is the code for finding the name of ovm_env or other component instantiations up the hierarchy?
get_parent() returns the handle to parent of component. I browsed through the ovm_component class and m_parent is doing the same.
Also to know the name of env or a class up the hierarchy, the get_parent needs to be issued again and again. For example, in xbus example, to know the env, the code has to be
Hi Kal,
You can pass the name of the parent object to the child in the parent class build phase, so that you can access that passed string variable in the child class wherever it is required. Example:
class agent extends ovm_agent;
proj_monitor monitor;
function void build() monitor.parent_obj_name = get_name();
endfunction : build
endclass : agent
class proj_monitor extends ovm_monitor;
string parent_obj_name;
//use the above string variable to get the name of the parent object.
endclass : proj_monitor