🧩 UVM Object#
🚀 Introduction#
uvm_object
is the foundation class in the UVM library, serving as the base class for all UVM objects. This includes data objects, transactions, sequences, and configuration objects. It provides essential object-oriented features such as naming, identification, cloning, comparison, serialization, and conversion to string—key features for building reusable and flexible verification environments.
🏗️ Class Definition#
Below is a simplified example of the uvm_object
class showing its key methods and properties:
virtual class uvm_object extends uvm_void;
// 🔹 Constructor: creates a new object with an optional name
extern function new(string name = "");
// 🔹 Returns the object's local name
extern virtual function string get_name();
// 🔹 Returns the object's full hierarchical name
extern virtual function string get_full_name();
// 🔹 Returns the object's type wrapper (note: static)
extern static function uvm_object_wrapper get_type();
// 🔹 Creates a new object dynamically via the factory
virtual function uvm_object create(string name="");
return null;
endfunction
// 🔹 Clones (deep copies) the object
extern virtual function uvm_object clone();
// 🔹 Copies values from another object of the same type
extern function void copy(uvm_object rhs);
// 🔹 Compares this object to another object
extern function bit compare(uvm_object rhs, uvm_comparer comparer=null);
// 🔹 Prints the object's contents
extern function void print(uvm_printer printer=null);
// 🔹 Converts the object to a string representation
extern virtual function string convert2string();
// 🔹 Packs the object's contents into a bitstream
extern function int pack(ref bit bitstream[], input uvm_packer packer=null);
// 🔹 Unpacks the object's contents from a bitstream
extern function int unpack(ref bit bitstream[], input uvm_packer packer=null);
// 🔹 Returns the object's unique, numeric instance identifier
// (Bu method orijinal UVM'de genelde bulunmaz veya implementation-specific olabilir. Eklenmek isteniyorsa virtual yazılabilir.)
// virtual function int get_inst_id(); // Eğer dosyada varsa eklenebilir.
endclass
🔎 Key Features#
🆔 Object Identity#
Each uvm_object
instance has a unique ID assigned automatically and can optionally be named. This is useful for debugging, logging, and testbench introspection.
Instance ID & Name Management#
Assigning names and IDs to objects simplifies debugging and improves test readability.
class my_data extends uvm_object;
function new(string name = "my_data");
super.new(name);
`uvm_info("CREATE", $sformatf("Created %s with ID %0d",
get_name(), get_inst_id()), UVM_LOW)
endfunction
endclass
// Usage
my_data data1 = new("packet_data");
my_data data2 = new("config_data");
// Each object has a unique ID
⚙️ Core Object Methods#
These methods provide object management capabilities essential for verification.
🗂️ clone(), copy(), compare(), print(), convert2string(), pack(), and unpack() Methods#
Below is an example that integrates these key methods into a single uvm_object
-derived class:
class my_packet extends uvm_object;
rand bit [7:0] data;
rand bit [31:0] addr;
`uvm_object_utils_begin(my_packet)
`uvm_field_int(data, UVM_ALL_ON)
`uvm_field_int(addr, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "my_packet");
super.new(name);
endfunction
// 🔹 clone(): Creates a deep copy of the object and returns it.
function uvm_object clone();
my_packet cloned_obj;
cloned_obj = my_packet::type_id::create(get_name());
cloned_obj.copy(this);
return cloned_obj;
endfunction
// 🔹 copy(): Copies values from another object of the same type.
function void copy(uvm_object rhs);
my_packet rhs_obj;
if (!$cast(rhs_obj, rhs)) begin
`uvm_error("COPY", "Type mismatch during copy!")
return;
end
this.data = rhs_obj.data;
this.addr = rhs_obj.addr;
endfunction
// 🔹 compare(): Compares this object with another object.
function bit compare(uvm_object rhs, uvm_comparer comparer = null);
my_packet rhs_obj;
if (!$cast(rhs_obj, rhs)) return 0;
if (this.data != rhs_obj.data) return 0;
if (this.addr != rhs_obj.addr) return 0;
return 1;
endfunction
// 🔹 print(): Prints the object's contents.
function void print(uvm_printer printer = null);
if (printer == null)
printer = uvm_default_table_printer;
super.print(printer);
endfunction
// 🔹 convert2string(): Converts object data to a single-line string.
function string convert2string();
return $sformatf("Packet[data=0x%0h, addr=0x%0h]", data, addr);
endfunction
// 🔹 pack(): Serializes the object's contents into a bitstream.
function int pack(ref bit bitstream[], input uvm_packer packer = null);
int num_bits = 0;
num_bits += uvm_pack_int(data, bitstream, packer);
num_bits += uvm_pack_int(addr, bitstream, packer);
return num_bits;
endfunction
// 🔹 unpack(): Deserializes the object's contents from a bitstream.
function int unpack(ref bit bitstream[], input uvm_packer packer = null);
int num_bits = 0;
num_bits += uvm_unpack_int(data, bitstream, packer);
num_bits += uvm_unpack_int(addr, bitstream, packer);
return num_bits;
endfunction
endclass
📝 Summary#
With these core methods integrated:
✅ You can easily copy, compare, print, and convert to string.
✅ You can serialize and deserialize object data for communication or storage.
✅ You avoid writing repetitive code, making your testbench more efficient and maintainable.