uvm的field automation机制实现的其中一项功能就是sprint功能,该函数通过调用do_print函数实现。在某些情况的,uvm的打印功能不是我们所期望的,比如多维数组的field automation机制就不支持,struct之类的结构体打印结果为大数。因此我们需要对uvm的sprint功能进行扩展,使其打印的log内容符合我们的预期。
do_print函数的定义virtual function void do_print( uvm_printer printer );super.do_print( printer );//print customed variables or structs...
endfunction: do_print
uvm源码中对uvm_sequen_item的打印是通过调用如下函数实现的,因此我们可以通过调用该函数实现打印功能扩展。
virtual function void print_generic (string name, string type_name, int size, string value, byte scope_separator = "."
)
功能描述:Prints a field having the given name, type_name, size, and value.
假如我们在扩展的uvm_transaction中定义了如下的结构体变量:
typedef struct {bit [7:0] x;bit [7:0] y;bit [7:0] z;
} point_spoint_s p;`uvm_field_int(p, UVM_ALL_ON)
...
如果要对uvm_transaction的派生类的实例调用sprint函数进行打印,p打印的结果为整数,而我们期望的结果是打印出p的x,y,z的值。
通过对do_print函数的扩展可以实现上述功能,如下:
virtual function void do_print( uvm_printer printer );super.do_print( printer );//print customed variables or structsprinter.print_generic("p", "struct"$size(p), $sformatf("x='h%0h,y='h%0h,z='h%0h",p.x,p.y,p.z));
endfunction: do_print
上一篇:一朵花昨天开放,一朵花今天开放
下一篇:【考研英语语法】复杂句的逻辑