| |
UVM factory允许在构造时将类替换为派生类型的另一个类。这对于通过将一个类替换为另一个类而无需编辑或重新编译测试平台代码来更改测试平台的行为来说是非常有用的。为了使factory重载过程起作用,需要遵循许多编码约定先决条件,这些在UVM factory的文章中进行了解释。
UVM factory可以被认为是查找表。当使用<type> :: type_id :: create(“<name>”,<parent>)方法(approach)进行“普通”组件构造时,会发生的是type_id用于为类选择factory组件包装器, 构造其内容并再次传回结果句柄。factory重载更改了查找的发生方式,因此查找原始的type_id会导致使用不同的type_id。因此,返回不同类型的构造对象的句柄。此技术依赖于多态性,即能够使用基本类型句柄引用派生类型的能力。实际上,只有当父类被类扩展层次结构中的一个子类重载时,重载才会起作用。
Component Overrides
UVM中有两种类型的组件重载 - type overrides 和 instance overrides。
Component Type Overrides
type override意味着每次在测试平台层次结构中创建组件类type时,都会在其位置创建替换type。这适用于该组件类型的所有实例。以下代码片段中说明了此类重载的方法调用:
//
// Component type override example
// ---------------------------------------------
// Colour parent class
class colour extends uvm_component;
`uvm_component_utils(colour)
//etc
endclass: colour
// Red child class
class red extends colour;
`uvm_component_utils(red)
//etc
endclass: red
//
// Factory type override syntax is:
//
// <original_type>
//
// Where replace is a bit which when ==1 enables the override of an existing override, otherwise
// the existing override is honoured.
colour::type_id::set_type_override(red::get_type(), 1);
pixel = colour::type_id::create("pixel", this);
// Type overrides for parameterised classes:
// ----------------------------------------------------------
class bus_driver #(int BUS_WIDTH = 32) extends uvm_component;
// etc
class bus_conductor #(int BUS_WIDTH = 32) extends bus_driver #(BUS_WIDTH);
// etc
// the matching type override is not found:
Component Instance Overrides
可以通过在uvm组件层次结构中指定其位置来重载特定组件实例。同样,这种方法可以与参数化类一起使用,只要注意匹配重载中涉及的两个类类型的参数:
//
// Component Instance Factory Override example
// --------------------------------------------
// Using red --> colour example from type override example
//
// Syntax for the instance override:
//
// <original_type>
//
Objects or sequence 相关 objects通常仅与type重载一起使用,因为instance重载方法涉及UVM测试平台组件层次结构中哪些objects不参与的位置。然而,有一个编码技巧可用于重载object的特定“instances”,这在overriding sequences的文章中有解释。
object 重载的代码遵循与组件重载相同的形式。