uvm_pair¶
Title: UVMPair classes
This section defines container classes for handling value pairs.
- class uvm.comps.uvm_pair.UVMClassPair(name='', f=None, s=None)[source]¶
Bases:
UVMObject
Class: UVMClassPair
Container holding handles to two objects whose types are specified by the type parameters, T1 and T2.
- type_name = 'UVMClassPair'¶
- convert2string()[source]¶
This virtual function is a user-definable hook, called directly by the user, that allows users to provide object information in the form of a string. Unlike
sprint
, there is no requirement to use auvm_printer
policy object. As such, the format and content of the output is fully customizable, which may be suitable for applications not requiring the consistent formatting offered by theprint
/sprint
/do_print
API.Fields declared in <Utility Macros> macros (`uvm_field_*), if used, will not automatically appear in calls to convert2string.
An example implementation of convert2string follows.
class Base(UVMObject): field = "foo" def convert2string(self): return "base_field=" + self.field class Obj2(UVMObject): field = "bar" def convert2string() convert2string = "child_field=" + self.field class Obj(Base): addr = 0x123 data = 0x456 write = 1 child = Obj2() def convert2string(self): convert2string = super().convert2string() + sv.sformatf(" write=%0d addr=%8h data=%8h ",write,addr,data) + child.convert2string() Then, to display an object, you could write: .. code-block:: python o = Obj() uvm_report_info("BusMaster", "Sending:
” + o.convert2string())
The output will look similar to:
UVM_INFO @ 0: reporter [BusMaster] Sending: base_field=foo write=1 addr=00000123 data=00000456 child_field=bar
- Returns:
str: Object converted into string.
- create(name='')¶
Group: Creation
The
create
method allocates a new object of the same type as this object and returns it via a base uvm_object handle. Every class deriving from uvm_object, directly or indirectly, must implement the create method.A typical implementation is as follows:
class mytype (UVMObject): ... def create(self, name=""): mytype t = mytype(name) return t
- Parameters
name (str) – Name of the created object.
- Returns
New object.
- Return type
obj
- get_object_type()¶
Function: get_object_type
Returns the type-proxy (wrapper) for this object. The
uvm_factory
’s type-based override and creation methods take arguments ofuvm_object_wrapper
. This method, if implemented, can be used as convenient means of supplying those arguments. This method is the same as the staticget_type
method, but uses an already allocated object to determine the type-proxy to access (instead of using the static object).The default implementation of this method does a factory lookup of the proxy using the return value from
get_type_name
. If the type returned byget_type_name
is not registered with the factory, then aNone
handle is returned.For example:
class cmd (UVMObject): type_id = UVMObjectRegistry() @classmethod def type_id get_type(cls): return type_id.get() def get_object_type(self): return cmd.type_id.get()
This function is implemented by the `uvm_*_utils macros, if employed.
Returns:
- classmethod get_type()¶
Returns the type-proxy (wrapper) for this object. The
UVMFactory
’s type-based override and creation methods take arguments ofuvm_object_wrapper
. This method, if implemented, can be used as convenient means of supplying those arguments.The default implementation of this method produces an error and returns
None
. To enable use of this method, a user’s subtype must implement a version that returns the subtype’s wrapper.For example:
class cmd(UVMObject): type_id = None @classmethod def get_type(cls): return cls.type_id.get()
Then, to use:
factory.set_type_override(cmd.get_type(), subcmd.get_type())
This function is implemented by the uvm_*_utils functions, if employed.
Returns:
- get_type_name()¶
This function returns the type name of the object, which is typically the type identifier enclosed in quotes. It is used for various debugging functions in the library, and it is used by the factory for creating objects.
This function must be defined in every derived class.
A typical implementation is as follows:
class mytype (UVMObject): ... type_name = "mytype" def get_type_name(self): return my_type.type_name
We define the
type_name
static variable to enable access to the type name without need of an object of the class, i.e., to enable access via the scope operator, ~mytype::type_name~.- Returns
Type name of the object.
- Return type
- type_id = <uvm.base.uvm_registry.UVMObjectRegistry object>¶
- class uvm.comps.uvm_pair.UVMBuiltInPair(name='')[source]¶
Bases:
UVMObject
- type_name = 'UVMBuiltInPair'¶
- get_type_name()¶
This function returns the type name of the object, which is typically the type identifier enclosed in quotes. It is used for various debugging functions in the library, and it is used by the factory for creating objects.
This function must be defined in every derived class.
A typical implementation is as follows:
class mytype (UVMObject): ... type_name = "mytype" def get_type_name(self): return my_type.type_name
We define the
type_name
static variable to enable access to the type name without need of an object of the class, i.e., to enable access via the scope operator, ~mytype::type_name~.- Returns
Type name of the object.
- Return type
- convert2string()[source]¶
This virtual function is a user-definable hook, called directly by the user, that allows users to provide object information in the form of a string. Unlike
sprint
, there is no requirement to use auvm_printer
policy object. As such, the format and content of the output is fully customizable, which may be suitable for applications not requiring the consistent formatting offered by theprint
/sprint
/do_print
API.Fields declared in <Utility Macros> macros (`uvm_field_*), if used, will not automatically appear in calls to convert2string.
An example implementation of convert2string follows.
class Base(UVMObject): field = "foo" def convert2string(self): return "base_field=" + self.field class Obj2(UVMObject): field = "bar" def convert2string() convert2string = "child_field=" + self.field class Obj(Base): addr = 0x123 data = 0x456 write = 1 child = Obj2() def convert2string(self): convert2string = super().convert2string() + sv.sformatf(" write=%0d addr=%8h data=%8h ",write,addr,data) + child.convert2string() Then, to display an object, you could write: .. code-block:: python o = Obj() uvm_report_info("BusMaster", "Sending:
” + o.convert2string())
The output will look similar to:
UVM_INFO @ 0: reporter [BusMaster] Sending: base_field=foo write=1 addr=00000123 data=00000456 child_field=bar
- Returns:
str: Object converted into string.
- do_compare(rhs, comparer)[source]¶
The
do_compare
method is the user-definable hook called by thecompare
method. A derived class should override this method to include its fields in a compare operation. It should return 1 if the comparison succeeds, 0 otherwise.A typical implementation is as follows:
class mytype (UVMObject): ... f1 = 0 def do_compare(self, rhs, comparer): do_compare = super.do_compare(rhs,comparer) # Optional type checking do_compare &= comparer.compare_field_int("f1", f1, rhs.f1) return do_compare
A derived class implementation must call
super().do_compare
to ensure its base class’ properties, if any, are included in the comparison. If type matching is required instead of duck-typing, the user can also implemented this checking.The actual comparison should be implemented using the
UVMComparer
object rather than direct field-by-field comparison. This enables users of your class to customize how comparisons are performed and how much miscompare information is collected. SeeUVMComparer
for more details.- Parameters
rhs (UVMObject) –
comparer (UVMComparer) –
- Returns
True if objects match, False otherwise.
- Return type
- create(name='')¶
Group: Creation
The
create
method allocates a new object of the same type as this object and returns it via a base uvm_object handle. Every class deriving from uvm_object, directly or indirectly, must implement the create method.A typical implementation is as follows:
class mytype (UVMObject): ... def create(self, name=""): mytype t = mytype(name) return t
- Parameters
name (str) – Name of the created object.
- Returns
New object.
- Return type
obj
- get_object_type()¶
Function: get_object_type
Returns the type-proxy (wrapper) for this object. The
uvm_factory
’s type-based override and creation methods take arguments ofuvm_object_wrapper
. This method, if implemented, can be used as convenient means of supplying those arguments. This method is the same as the staticget_type
method, but uses an already allocated object to determine the type-proxy to access (instead of using the static object).The default implementation of this method does a factory lookup of the proxy using the return value from
get_type_name
. If the type returned byget_type_name
is not registered with the factory, then aNone
handle is returned.For example:
class cmd (UVMObject): type_id = UVMObjectRegistry() @classmethod def type_id get_type(cls): return type_id.get() def get_object_type(self): return cmd.type_id.get()
This function is implemented by the `uvm_*_utils macros, if employed.
Returns:
- classmethod get_type()¶
Returns the type-proxy (wrapper) for this object. The
UVMFactory
’s type-based override and creation methods take arguments ofuvm_object_wrapper
. This method, if implemented, can be used as convenient means of supplying those arguments.The default implementation of this method produces an error and returns
None
. To enable use of this method, a user’s subtype must implement a version that returns the subtype’s wrapper.For example:
class cmd(UVMObject): type_id = None @classmethod def get_type(cls): return cls.type_id.get()
Then, to use:
factory.set_type_override(cmd.get_type(), subcmd.get_type())
This function is implemented by the uvm_*_utils functions, if employed.
Returns:
- type_id = <uvm.base.uvm_registry.UVMObjectRegistry object>¶