| |
The UVM Factory
UVM factory的目的是允许将一种类型的对象替换为派生类型的对象,而无需更改测试平台的结构或编辑测试平台代码。使用的机制被称为重载,重载可以是by instance or type。此功能对于更改sequence功能或将组件的一个版本更改为另一个版本非常有用。要交换的任何组件必须是多态兼容的。这包括具有所有相同的TLM接口句柄,并且必须由新的替换组件创建TLM对象。另外,为了利用factory,需要遵循某些编码约定。
Factory Coding Convention 1: Registration
组件或对象必须包含factory注册代码,该代码包含以下元素:
例如:
class my_component extends uvm_component;
// Wrapper class around the component class that is used within the factory
typedef uvm_component_registry #(my_component, "my_component") type_id;
// Used to get the type_id wrapper
static function type_id get_type();
return type_id::get();
endfunction
// Used to get the type_name as a string
function string get_type_name();
return "my_component";
endfunction
...
endclass: my_component
注册代码具有常规模式,可以使用一组四个factory注册宏中的一个安全地生成:
// For a component
class my_component extends uvm_component;
// Component factory registration macro
`uvm_component_utils(my_component)
// For a parameterised component
class my_param_component #(int ADD_WIDTH=20, int DATA_WIDTH=23) extends uvm_component;
typedef my_param_component #(ADD_WIDTH, DATA_WIDTH) this_t;
// Parameterised component factory registration macro
`uvm_component_param_utils(this_t)
// For a class derived from an object (uvm_object, uvm_transaction, uvm_sequence_item, uvm_sequence etc)
class my_item extends uvm_sequence_item;
`uvm_object_utils(my_item)
// For a parameterised object class
class my_item #(int ADD_WIDTH=20, int DATA_WIDHT=20) extends uvm_sequence_item;
typedef my_item #(ADD_WIDTH, DATA_WIDTH) this_t
`uvm_object_param_utils(this_t)