概述UVM Factory機(jī)制
[導(dǎo)讀]UVM?factory的目的是允許將一種類型的對(duì)象替換為派生類型的對(duì)象,而不需要更改testbench的結(jié)構(gòu)或代碼(實(shí)例替換或者類替換),此功能對(duì)于更改sequence或組件非常有用。任何要替換的組件都必須具有多態(tài)兼容性,這包括具有所有相同的TLM接口句柄并且TLM對(duì)象必須由新的...
UVM?factory 的目的是允許將一種類型的對(duì)象替換為派生類型的對(duì)象,而不需要更改testbench 的結(jié)構(gòu)或代碼(實(shí)例替換或者類替換),此功能對(duì)于更改sequence或組件非常有用。
任何要替換的組件都必須具有多態(tài)兼容性,這包括具有所有相同的TLM接口句柄并且TLM對(duì)象必須由新的替換組件創(chuàng)建。此外,為了利用UVM Factory機(jī)制,需要遵循某些編碼約定。?1、注冊(cè)??組件或?qū)ο舐暶鞔a中包括:1、一個(gè)uvm_component_registry?wrapper,被宏定義為type_id2、一個(gè)用來獲取type_id的靜態(tài)函數(shù)3、一個(gè)用來獲取類型名稱的函數(shù)
uvm_component和uvm_object構(gòu)造函數(shù)是虛擬方法,這意味著用戶必須遵循它們的原型模板。
任何要替換的組件都必須具有多態(tài)兼容性,這包括具有所有相同的TLM接口句柄并且TLM對(duì)象必須由新的替換組件創(chuàng)建。此外,為了利用UVM Factory機(jī)制,需要遵循某些編碼約定。?1、注冊(cè)??組件或?qū)ο舐暶鞔a中包括:1、一個(gè)uvm_component_registry?wrapper,被宏定義為type_id2、一個(gè)用來獲取type_id的靜態(tài)函數(shù)3、一個(gè)用來獲取類型名稱的函數(shù)
class my_component extends uvm_component;typedef uvm_component_registry #(my_component, "my_component") type_id;static function type_id get_type();return type_id::get();endfunction function string get_type_name();return "my_component";endfunction...endclass: my_component組件或?qū)ο?/span>注冊(cè)代碼可以使用四個(gè)factory 注冊(cè)宏生成:// For a componentclass my_component extends uvm_component;`uvm_component_utils(my_component)
// For a parameterised componentclass my_param_component #(int ADD_WIDTH=20, int DATA_WIDTH=23) extends uvm_component;typedef my_param_component #(ADD_WIDTH, DATA_WIDTH) this_t;`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 classclass 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)2、默認(rèn)構(gòu)造函數(shù)uvm_component和uvm_object構(gòu)造函數(shù)是虛擬方法,這意味著用戶必須遵循它們的原型模板。
// For a component:class my_component extends uvm_component;function new(string name = "my_component", uvm_component parent = null);super.new(name, parent);endfunction// For an objectclass my_item extends uvm_sequence_item;function new(string name = "my_item");super.new(name);endfunction3、組件和對(duì)象的創(chuàng)建Testbench在build phase使用uvm_component_registry中的create方法創(chuàng)建組件。首先構(gòu)造class,然后將類的指針賦值到Testbench 中的聲明句柄。class env extends uvm_env;my_component m_my_component;my_param_component?#(.ADDR_WIDTH(32),?.DATA_WIDTH(32))?m_my_p_component;function void build_phase( uvm_phase phase );m_my_component = my_component::type_id::create("m_my_component", this);m_my_p_component = my_param_component #(32, 32)::type_id::create("m_my_p_component", this);endfunction: build task run_phase( uvm_phase phase );my_seq test_seq;my_param_seq #(.ADDR_WIDTH(32), .DATA_WIDTH(32)) p_test_seq;test_seq = my_seq::type_id::create("test_seq");p_test_seq = my_param_seq #(32,32)::type_id::create("p_test_seq");// ....endtask: run 




