UVMfactory 允许一个类在构造时被派生类替换。这对于更改testbench的行为很有用,它将一个类替换为另一个类,而无需编辑或重新编译testbench 代码。
为了使factory override发挥作用,需要遵循许多编码约定的先决条件。主要存在component (实例替换、类替换)和object(实例替换、类替换)
Component Type Overrides
类型覆盖适用于该组件类型的所有实例:
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
// <original_type>::type_id::set_type_override(<substitute_type>::get_type(), replace);
// Where replace is a bit which when ==1 enables the override of an existing override, otherwise
// the existing override is honoured.
// To override all instances of colour with red:
colour::type_id::set_type_override(red::get_type(), 1);
// This means that the following creation line returns a red, rather than a colour
pixel = colour::type_id::create("pixel", this);
参数化的组件类也可以override,但必须注意确保覆盖类具有相同的参数值,否则它们不被认为是相关类型:
class bus_driver #(int BUS_WIDTH = 32) extends uvm_component;
`uvm_component_param_utils(bus_driver #(BUS_WIDTH))
// etc
endclass: bus_driver
class bus_conductor #(int BUS_WIDTH = 32) extends bus_driver #(BUS_WIDTH);
`uvm_component_param_utils(bus_conductor #(BUS_WIDTH))
// etc
endclass: bus_conductor
// The parameterised type override needs to keep the parameterisation consistent
bus_driver #(64)::type_id::set_type_override(bus_conductor #(64)::get_type(), 1); // This will succeed
// Creation of a #(64) bus_driver results in a #(64) bus_conductor handle being returned:
bus_person = bus_driver#(64)::type_id::create("bus_person", this);
// Whereas creating a #(16) bus_driver results in a #(16) bus_driver handle being returned because
// the matching type override is not found:
bus_person = bus_driver#(16)::type_id::create("bus_person", this);
// Similarly if a type override has non-matching parameters, then it will fail and return the original type
bus_driver #(64)::type_id::set_type_override(bus_conductor #(32)::get_type(), 1); // Returns bus_driver #(64)
Component Instance Overrides
一个特定的组件实例可以通过指定其在uvm组件层次结构中的路径来被覆盖。同样,这种方法可以用于参数化的类,只要注意匹配覆盖中涉及的两个类的参数:
// Using red --> colour example from type override example
// <original_type>::type_id::set_inst_override(<substitute_type>::get_type(), <path_string>);
colour::type_id::set_inst_override(red::get_type(), "top.env.raster.spot");
// And again for a parameterised type, the parameter values must match
bus_driver #(64)::type_id::set_inst_override(bus_conductor #(64)::get_type(), "top.env.bus_agent.m_driver");
Objects 或sequence 相关的对象通常只与类型覆盖一起使用,因为uvm_object与uvm_component不同,其不具有组件层次结构路径。对象覆盖的代码与组件覆盖的形式相同。
作者:验证哥布林
原文链接:https://mp.weixin.qq.com/s/RNmMn_nceNTeH3veHFYUGQ
微信公众号:
推荐阅读
更多IC设计技术干货请关注IC设计技术专栏