I am writing a class that contains some abstracted logic. Specifically, it has some arbitration methods that could be redefined in an extension. Objects of this type will be used by sequences. This class will also need to be able to get information from the config_db using hierarchical paths, and plain old uvm_objects don't have hierarchy.
Because this will be created during the run_phase it can't extend uvm_component, and it wouldn't make sense for this class to have phases anyways. It could extend uvm_sequence_item, however it doesn't make sense for this object to be started on a sequencer.
It seems like UVM is missing something like a vanilla uvm_hierarchical_object. I am making do using the follow pattern highly leveraged from looking at the UVM source code:
class MyClass extends uvm_object;
`uvm_object_utils(MyClass)
protected uvm_object m_parent;
protected string m_name;
function new(string name = "MyClass");
super.new(name);
endfunction // new
virtual function void set_name(string name);
super.set_name(name);
m_set_full_name();
endfunction
virtual function void set_parent(uvm_object parent);
if (parent == this) begin
`uvm_fatal("THISPARENT", "cannot set the parent of an object to itself")
end
m_parent = parent;
m_set_full_name();
endfunction
virtual function uvm_object get_parent();
return m_parent;
endfunction
protected virtual function void m_set_full_name();
if (m_parent == null)
m_name = get_name();
else
m_name = {m_parent.get_full_name(),".",get_name()};
endfunction
virtual function string get_full_name();
if (m_name == "")
return get_name();
else
return m_name;
endfunction
endclass
Unfortunately, I can't use the uvm_component_utils macros because they assume uvm_component type. And the uvm_object_utils macros assume there is no parent. So I need to still make my own utils macro, but for the moment I'm getting by, by manually calling set_parent() after I create the object.
Anyone else already solve this? Will something like this make its way into official UVM code?
Thanks,
Ryan