Just 2 more macros to make UVM life easier :-) or harder :-<

While creating any new component or object in UVM we first register it with the factory,

We usually use the macros `uvm_component_utis and `uvm_object_utils followed by function new().


? `uvm_object_utils(my_sequence)

? function new(string name="my_sequence");
? ? super.new(name);
? endfunction?        

Most of the time I write nothing inside the function new and need to type those 3 lines of code.

If there is already a macro `uvm_component_utils I wonder WHY the UVM didn't have a macro for these lines

Here is the solution,

Add the following lines in you tb_top and reduce the rework.


`define uvm_component_function_new(NAME,PARENT) 
function new(string name=`"NAME`",uvm_component parent=`"PARENT`"); \
? super.new(name,parent); \
endfunction
`define uvm_object_function_new(NAME) \
function new(string name=`"NAME`"); \
? super.new(name); \
endfunction\        

Here is how the new code would like


class my_sequencer extends uvm_sequencer#(my_seq_item);
? `uvm_component_utils(my_sequencer)
??
? `uvm_component_function_new(name,parent)


class i_seq_item extends uvm_sequence_item
? `uvm_object_utils(i_seq_item)
?
? `uvm_object_function_new(i_seq_item);
endclass        

Now WHY should we use 2 different macros if we know we are not doing inside it

Here is the solution

`define uvm_register_component(NAME,PARENT) 
`uvm_component_utils(NAME) \
`uvm_component_function_new(NAME,PARENT)


`define uvm_register_object(NAME) \
`uvm_object_utils(NAME) \
`uvm_object_function_new(NAME)\        

Here is the reduced code

class my_sequencer extends uvm_sequencer#(my_seq_item)
//? `uvm_component_utils(my_sequencer)
??
//? `uvm_component_function_new(name,parent)
??
? `uvm_register_component(my_sequencer,parent);        


Here is the how the code looks like for uvm_seq_item


class i_seq_item extends uvm_sequence_item
? //`uvm_object_utils(i_seq_item)
?
? //`uvm_object_function_new(i_seq_item)
??
? `uvm_register_object(i_seq_item);        

The remaining code you need to write. So to conclude create macros if you know what you are doing and the task is repetitive.


Following are links to my previous articles


要查看或添加评论,请登录

社区洞察

其他会员也浏览了