Hi All,
How can I prints all elements of struct data types using do_print method?
Thanks
In reply to Mukund Sojitra:
I think there is no automatic way to print a struct not even with the field macros(which are the devil according to some EDA vendors ;-), kidding they can add a lot of overhead and complexity to debug) as described in this link
You need to manually print each member something like this, maybe you need to play around with scope separator of the print_int method
or maybe use print_string along with $sformatf(ā%pā, my_struct);
`include "uvm_macros.svh"
import uvm_pkg::*;
class item extends uvm_object;
`uvm_object_utils(item)
typedef enum bit {FALSE, TRUE} bool_t;
typedef struct packed {
bit x;
int y;
} m_struct_t;
rand int x;
rand bool_t my_bool;
rand m_struct_t my_struct;
function new(string name = "item");
super.new(name);
endfunction
virtual function void do_print(uvm_printer printer);
super.do_print(printer);
printer.print_generic("my_bool ", "bool_t", $bits(this.my_bool), my_bool.name());
printer.print_int("my_struct.x", my_struct.x, $bits(my_struct.x), UVM_HEX, ""); //scope separator left empty, the default argument is "."
printer.print_int("my_struct.y", my_struct.y, $bits(my_struct.y), UVM_DEC, "");
printer.print_int("x", x, $bits(x), UVM_DEC);
printer.print_string("my_struct", $sformatf("%p", my_struct));
endfunction
endclass
class base_test extends uvm_test;
`uvm_component_utils(base_test)
item my_item;
function new(string name = "base_test", uvm_component parent=null);
super.new(name, parent);
endfunction
function void build_phase(uvm_phase phase);
my_item = item::type_id::create("my_item", this);
if(!my_item.randomize()) begin
`uvm_fatal(get_full_name(), "Randomize failed")
end
my_item.print();
endfunction
endclass
module tb;
initial run_test("base_test");
endmodule
//Which gives the following output
# KERNEL: --------------------------------------------------
# KERNEL: Name Type Size Value
# KERNEL: --------------------------------------------------
# KERNEL: my_item item - @348
# KERNEL: my_bool bool_t 1 TRUE
# KERNEL: my_item.my_struct.x integral 1 'h0
# KERNEL: my_item.my_struct.y integral 32 -1231346002
# KERNEL: x integral 32 -83677571
# KERNEL: my_struct string 21 '{x:0, y:-1231346002}
# KERNEL: -------------------------------------------------
HTH,
-R