如何使用factory機制中的override
[導讀]UVM?factory允許一個類在構造時被派生類替換。這對于更改testbench的行為很有用,它將一個類替換為另一個類,而無需編輯或重新編譯testbench代碼。為了使factoryoverride發(fā)揮作用,需要遵循許多編碼約定的先決條件。主要存在component(實例替換...
UVM?factory 允許一個類在構造時被派生類替換。這對于更改testbench的行為很有用,它將一個類替換為另一個類,而無需編輯或重新編譯testbench 代碼。
為了使factory override發(fā)揮作用,需要遵循許多編碼約定的先決條件。主要存在component (實例替換、類替換)和object(實例替換、類替換)?Component Type Overrides類型覆蓋適用于該組件類型的所有實例:
一個特定的組件實例可以通過指定其在uvm組件層次結構中的路徑來被覆蓋。同樣,這種方法可以用于參數(shù)化的類,只要注意匹配覆蓋中涉及的兩個類的參數(shù):
為了使factory override發(fā)揮作用,需要遵循許多編碼約定的先決條件。主要存在component (實例替換、類替換)和object(實例替換、類替換)?Component Type Overrides類型覆蓋適用于該組件類型的所有實例:
class colour extends uvm_component;`uvm_component_utils(colour)// etcendclass: colour // Red child classclass red extends colour;`uvm_component_utils(red)//etcendclass: red // ::type_id::set_type_override(::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 colourpixel = colour::type_id::create("pixel", this);參數(shù)化的組件類也可以override,但必須注意確保覆蓋類具有相同的參數(shù)值,否則它們不被認為是相關類型:class bus_driver #(int BUS_WIDTH = 32) extends uvm_component;`uvm_component_param_utils(bus_driver #(BUS_WIDTH))// etcendclass: bus_driver class bus_conductor #(int BUS_WIDTH = 32) extends bus_driver #(BUS_WIDTH);`uvm_component_param_utils(bus_conductor #(BUS_WIDTH))// etcendclass: bus_conductor // The parameterised type override needs to keep the parameterisation consistentbus_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 typebus_driver #(64)::type_id::set_type_override(bus_conductor #(32)::get_type(), 1); // Returns bus_driver #(64)Component Instance Overrides一個特定的組件實例可以通過指定其在uvm組件層次結構中的路徑來被覆蓋。同樣,這種方法可以用于參數(shù)化的類,只要注意匹配覆蓋中涉及的兩個類的參數(shù):
// Using red --> colour example from type override example// ::type_id::set_inst_override(::get_type(), ); colour::type_id::set_inst_override(red::get_type(), "top.env.raster.spot");// And again for a parameterised type, the parameter values must matchbus_driver #(64)::type_id::set_inst_override(bus_conductor #(64)::get_type(), "top.env.bus_agent.m_driver");Objects 或sequence 相關的對象通常只與類型覆蓋一起使用,因為uvm_object與uvm_component不同,其不具有組件層次結構路徑。對象覆蓋的代碼與組件覆蓋的形式相同。? 




