Full credit goes to this forum post: http://forums.accellera.org/topic/1002-uvm-print-with-array-objects/
The UVM print()
accepts an uvm_printer
argument. Create a new uvm_table_printer
object (child of uvm_printer
), change it knobs values, and pass it to the print()
method.
uvm_table_printer printer;
my_uvm_object m;
// ...
printer = new();
m = my_uvm_object::type_id::create("my_uvm_object");
printer.knobs.begin_elements = -1; // this indicates to print all
m.print(printer);
//Optionally you can specify numbers for begin/end
printer.knobs.begin_elements = 10; // prints the first 10; default: 5
printer.knobs.end_elements = 2; // also print the last 2; default: 5
m.print(printer);
This is useful when you want to affect the with in a particular uvm_object
can can be made scalable by overriding the do_print()
method.
Alternatively, if the change is intended to be global, there is a default printer that automatically created at root called uvm_default_printer
. Changing the knob values of this printer will alter the printing behavior of all prints using default.
uvm_default_printer.knobs.begin_elements=-1; // this indicates to print all
m.print(); // will print all elements
//Optionally you can specify numbers for begin/end
uvm_default_printer.knobs.begin_elements = 2; // prints the first 2; default: 5
uvm_default_printer.knobs.end_elements = 3; // also print the last 3; default: 5
m.print(); // will print the first 2 and last 3 elements
working example: http://www.edaplayground.com/x/Ze