2

I'm wondering why some new constructor has been implemented with argument and some new constructor has been implemented with no argument in UVM as the below example.

class mem_monitor extends uvm_monitor;
 
  uvm_analysis_port #(mem_seq_item) item_collected_port;
 
  // Placeholder to capture transaction information.
  mem_seq_item trans_collected;
 
  `uvm_component_utils(mem_monitor)
 
  // new - constructor
  function new (string name, uvm_component parent);
    super.new(name, parent);
    trans_collected = new();
    item_collected_port = new("item_collected_port", this);
  endfunction : new

As you can see in the above, trans_collected = new(); has been implemented with no argument, and item_collected_port = new("item_collected_port", this); has arguments.

Is there any special rule for implementing new constructor?

toolic
  • 5,637
  • 5
  • 20
  • 33
Carter
  • 581
  • 2
  • 6
  • 23

1 Answers1

3

The number (and type) of arguments passed to the new constructor depend on how the class was declared. You need to refer to the IEEE 1800.2 UVM documentation.


trans_collected is of type mem_seq_item. Since you did not show the class declaration of mem_seq_item, let's assume it was extended from uvm_sequence_item. From this online UVM document, we see that the constructor method for uvm_sequence_item is:

function new (string name = "uvm_sequence_item")

This shows that there is one argument which has a default value defined. This means that it is not necessary to pass an argument to new.

Note that it is a good practice to construct a sequence item using create instead of new. Refer to the documentation.


item_collected_port is declared as a uvm_analysis_port, and from the documentation, we see:

  uvm_analysis_port#(trans) ap;
     ap = new("ap", this);

We can infer that the 1st argument is a name string and the 2nd is a class handle (similar to uvm_component).

toolic
  • 5,637
  • 5
  • 20
  • 33