factory機制最偉大的地方在于其具有重載功能。重載并不是factory機制的發明,前面已經介紹過的所有面向對象的語言都支持函數/任務重載,另外,SystemVerilog還額外支持對約束的重載。只是factory機制的重載與這些重載都不一樣。
一 問題引出
以8.1.1節的代碼清單8-1和代碼清單8-2為例,定義好bird與parrot,并在測試用例中調用print_hungry函數。只是與8.1.1節代碼不同的地方在于,其將代碼清單8-2的build_phase中改為如下語句:
`ifndef MY_CASE0__SV
`define MY_CASE0__SV
class case0_sequence extends uvm_sequence #(my_transaction);my_transaction m_trans;function new(string name= "case0_sequence");super.new(name);endfunction virtual task body();if(starting_phase != null) starting_phase.raise_objection(this);repeat (10) begin`uvm_do(m_trans)end#100;if(starting_phase != null)