我想打印出ovm_sequence_item中使用的结构。由于结构很长,我计划使用tbl_printer.knobs.value_width = 100覆盖表打印机旋钮;
这是代码片段
virtual function void do_print(ovm_printer printer);
ovm_table_printer tbl_printer;
super.do_print(printer); //print all other fields
$cast(tbl_printer, printer);
tbl_printer.knobs.value_width = 100;
tbl_printer.print_generic("ppid","CppPpid_t",$bits(CppPpid_t),
$psprintf("A=%0b,B=%0b,C=%0d,D=%0d,E=%0d,F=%0x",
struct.A,
struct.B,
struct.C,
struct.D,
struct.E,
struct.F)
);
endfunction: do_print
我得到这个投射错误。错误 - [DCF]动态强制转换失败* .sv,58由于类型不匹配,将源类类型“SIP_SHARED_LIB.ovm_pkg.ovm_tree_printer”强制转换为目标类类型“SIP_SHARED_LIB.ovm_pkg.ovm_table_printer”失败。请确保动态演员的匹配类型
有人可以帮助我,我做错了吗?当我尝试使用ovm_printer时,它是如何获得ovm_tree_printer的?
ovm_printer
只是为打印机声明API的基类。传递的是具体的类,如ovm_table_printer
或ovm_tree_printer
。这两个都可以存储在ovm_printer
类型的变量中。
您可能正在通过print(...)
调用中的树打印机传递对象。如果未指定任何打印机,则使用默认打印机。默认情况下,这是表打印机,但可能会更改。在包范围内查找ovm_default_printer
。
如果某人明确要求您进行树形打印,那么您无法将其神奇地更改为表格打印。你能做的最好的事情就是检查你是否正在打印桌面,如果是,那么更换旋钮:
if (!$cast(tbl_printer, printer))
return;
tbl_printer.knobs.value_width = 100;