🖨️ Understanding uvm_object::print()
, sprint()
, sformat()
, sformatf()
, and convert2string()
#
In this section, we explore the print, sprint, sformat, sformatf, and convert2string methods of uvm_object
. These methods are essential for debugging and visualizing object contents in UVM testbenches.
1️⃣ What is print()
?#
✅ The print()
method prints the contents of an object to the simulator’s console or transcript window.
- Uses the UVM printer to generate human-readable output.
- Shows all registered fields of the object.
Example:
txn.print();
2️⃣ What is sprint()
?#
✅ The sprint()
method returns the output as a string instead of printing it directly.
- Useful for appending object data to log files or UVM reports.
Example:
string txt;
txt = txn.sprint();
`uvm_info("TXN_DATA", txt, UVM_LOW)
3️⃣ What is sformat()
?#
✅ The sformat()
method formats object contents in a single-line summary and returns it as a string.
- Provides a concise, quick view for logs.
Example:
string summary;
summary = txn.sformat();
`uvm_info("TXN_SUMMARY", summary, UVM_LOW)
4️⃣ What is sformatf()
?#
✅ The sformatf()
method is a SystemVerilog built-in function that formats strings with embedded variables, similar to printf()
in C.
- Typically used within
convert2string()
to build custom object summaries.
Example:
function string convert2string();
return $sformatf("op_a=%0h, op_b=%0h, opcode=%0h", op_a, op_b, opcode);
endfunction
Usage:
string summary;
summary = txn.convert2string();
`uvm_info("TXN_STRING", summary, UVM_LOW)
5️⃣ What is convert2string()
?#
✅ The convert2string()
method generates a user-defined string representation of the object.
- By default, it returns the result of
sformat()
. - Can be overridden to create custom object summaries.
Example:
function string convert2string();
return $sformatf("op_a=%0h, op_b=%0h, opcode=%0h", op_a, op_b, opcode);
endfunction
Usage:
string summary;
summary = txn.convert2string();
`uvm_info("TXN_STRING", summary, UVM_LOW)
6️⃣ Benefits#
✅ These methods:
- Enable quick and consistent introspection of object contents.
- Reduce the need for manual
$display
statements. - Integrate with UVM reporting.
- Simplify debugging, randomization, and DUT interactions.
📖 Conclusion#
The print()
, sprint()
, sformat()
, sformatf()
, and convert2string()
methods are powerful tools in uvm_object
that make your verification environment easier to debug and maintain.