in sv we use new to create object so what is the use of build phase in uvm it provide any extra benefit?
The UVM build phase provides more advantages over new by enabling factory based object creation, centralized configuration, hierarchical construction, and phase synchronization. These features make testbenches more flexible, reusable, and scalable, which is critical for verifying complex designs in UVM based environments.
In SystemVerilog, you can only append to the constructor new() when extending a class. However, using the build_phase() method of a component instead of placing everything within the new() constructor enables you to prepend, append, or completely override the method with modified behavior when extending the class.
Thank you @dave_59 @Surya_prakash.Kapireddy
Hello,
Can you please give me an example of what prepend and append mean? I have tried many things using the build phase and new. Whatever we do in the build phase can also be done using new. Please can you give me an example of something that is possible only using the build phase and not using new?
The first statement in any SystemVerilog extended class constructor must be a call to super.new()
(implicit or explicitly).
class my_component extends uvm_component;
function new(string name, uvm_component parent);
super.new(name,parent);
$display("in my_component constructor");
endfunction
function void build_phase(uvm_phase phase);
$display("in my_component build_phase");
endfunction
//...
endclass
class my_extended_component extends my_component;
function new(string name, uvm_component parent);
super.new(name,parent);
$display("in my_extended_component constructor");
endfunction
function void build_phase(uvm_phase phase);
$display("in my_extended_component build_phase");
endfunction
There is no way to override the constructor to prevent it from displaying “in my_component constructor”, whereas I can prevent displaying “in my_component build_phase” by not calling super.build_phase()
. You have the option of calling super.build_phase()
as well as adding code before (prepend), or after(append) the call.
function void build_phase(uvm_phase phase);
$display("prepend to my_extended_component build_phase");
super.build_phase(phase);
$display("append to my_extended_component build_phase");
endfunction
Now instead of simple $display
statement, we have code that constructs other components. If we put that code in the base constructor, there is no way to stop that from happening from an override of the constructor.
thanks for explanation