Hi There,
I recently started learning UVM when I have small doubts reagrding the constructor and cretate methods. can anyone explain what is the difference between the two constructors and create methods. Is it legal to give null to constructor and create method, if it is legal in what situations I need to use null and this.
``` verilog
1. function new(string name, uvm_component parent = null);
super.new(name, parent);
endfunction
2. function new(string name, uvm_component parent = this);
super.new(name, parent);
endfunction
1. e = env::type_id::create("e", this);
2. e = env::type_id::create("e", null);
In reply to marathuteja:
The UVM component’s constructor does not need a default for either argument. Just use:
function new(string name, uvm_component parent);
Next, don’t create components with a null parent. If you do that, the component’s phase methods won’t be called, so your environment won’t execute.
Why do you throw null into this and break your code?
In reply to chrisspear:
When I am executing the hello world program by doulos academy
interface dut_if;
endinterface
module dut(dut_if dif);
endmodule
`include "uvm_macros.svh"
package my_pkg;
import uvm_pkg::*;
class my_env extends uvm_env;
`uvm_component_utils(my_env)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
endclass: my_env
class my_test extends uvm_test;
`uvm_component_utils(my_test)
my_env m_env;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
m_env = my_env::type_id::create("m_env", this);
endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
#10;
`uvm_info("TEST", "Hello Teja", UVM_MEDIUM)
phase.drop_objection(this);
endtask
endclass: my_test
endpackage: my_pkg
module top;
import uvm_pkg::*;
import my_pkg::*;
dut_if dut_if1 ();
dut dut1 ( .dif(dut_if1) );
initial
begin
run_test();
end
endmodule: top
class driverB #(type T=uvm_object) extends uvm_driver;
// parameterized classes must use the _param_utils version
`uvm_component_param_utils(driverB #(T))
// our packet type; this can be overridden via the factory
T pkt;
// standard component constructor
function new(string name, uvm_component parent=null);
super.new(name,parent);
endfunction
// get_type_name not implemented by macro for parameterized classes
const static string type_name = {"driverB #(",T::type_name,")"};
virtual function string get_type_name();
return type_name;
endfunction
// using the factory allows pkt overrides from outside the class
virtual function void build_phase(uvm_phase phase);
pkt = packet::type_id::create("pkt",this);
endfunction
// print the packet so we can confirm its type when printing
virtual function void do_print(uvm_printer printer);
printer.print_object("pkt",pkt);
endfunction
endclass
If you will see above two programs in one program(constructor) is not using anything and one program(constructor) is using null. If you come to create method I just want to know what will happen if we use null and this.
In reply to marathuteja:
In my opinion, this parameterized driver is a poor example. There is no need for a default value for the parent argument, and using null causes a subtle bug. It is not a // standard component constructor. Just say no to bad code. But heck, what do I know?