🛠️ UVM Utility Field Macros#
🚀 Introduction#
UVM Utility Field Macros are powerful tools that automatically generate essential object methods like copy
, compare
, print
, and pack/unpack
. Instead of manually implementing each method, you can simply declare your fields and gain full object functionality effortlessly.
🗂️ Basic Macro Usage#
Using Object Utils with Multiple Field Types#
Below is a single, comprehensive example that combines different data types—integers, strings, dynamic arrays, queues, and enums—demonstrating how to use UVM Utility Field Macros efficiently:
typedef enum {IDLE, ACTIVE, ERROR} state_e;
class all_fields_example extends uvm_object;
// Scalar fields
int timeout;
bit [7:0] data;
// String fields
string name;
string description;
// Dynamic array
bit [15:0] payload[];
// Queue
int values[$];
// Enum
state_e current_state;
`uvm_object_utils_begin(all_fields_example)
// 🔹 Integer fields
`uvm_field_int(timeout, UVM_ALL_ON | UVM_DEC)
`uvm_field_int(data, UVM_ALL_ON | UVM_HEX)
// 🔹 String fields
`uvm_field_string(name, UVM_ALL_ON)
`uvm_field_string(description, UVM_ALL_ON | UVM_NOCOMPARE)
// 🔹 Dynamic array field
`uvm_field_array_int(payload, UVM_ALL_ON | UVM_HEX)
// 🔹 Queue field
`uvm_field_queue_int(values, UVM_ALL_ON | UVM_DEC)
// 🔹 Enum field
`uvm_field_enum(state_e, current_state, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "all_fields_example");
super.new(name);
current_state = IDLE;
endfunction
endclass
🏷️ Field Automation Flags#
Key Flag Categories#
Flag | Description |
---|---|
UVM_ALL_ON | Enables all operations (copy, compare, print, pack, record) |
UVM_COPY | Includes in the copy() method |
UVM_COMPARE | Includes in the compare() method |
UVM_PRINT | Includes in the print() method |
UVM_PACK | Includes in the pack() and unpack() methods |
UVM_RECORD | Includes in the record() method |
UVM_NOCOPY | Excludes from copy() |
UVM_NOCOMPARE | Excludes from compare() |
UVM_NOPRINT | Excludes from print() |
UVM_HEX | Prints in hexadecimal format |
UVM_BIN | Prints in binary format |
UVM_NORAND | Excludes from randomization |
🚀 Summary#
Feature | Utility Macro | Field Macro |
---|---|---|
Purpose | Adds basic UVM functions to a class. | Registers class variables for UVM automation. |
Usage | uvm_object_utils , uvm_component_utils | uvm_field_int , uvm_field_string |
Functions | Adds methods like print() , copy() , compare() . | Defines how these methods process specific fields. |
Performance | Faster (only adds basic functions). | Slower (processes fields at runtime). |
uvm_component_utils
for component class and its child classesuvm_object_utils
for object class and its child classes
🔹 Using UVM Field Macros:
✅ Rapid object development
✅ One-line automation for methods (copy, compare, print, pack)
✅ Less manual code
✅ Fewer errors