0
votes

I wanted to print out a structure used in a ovm_sequence_item. Since the structure is long, I plan to override table printer knobs by using tbl_printer.knobs.value_width = 100;

Here is the code snipper

   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

I am getting this casting error. Error-[DCF] Dynamic cast failed *.sv, 58 Casting of source class type 'SIP_SHARED_LIB.ovm_pkg.ovm_tree_printer' to destination class type 'SIP_SHARED_LIB.ovm_pkg.ovm_table_printer' failed due to type mismatch. Please ensure matching types for dynamic cast

Can someone help me what I am doing wrong? How is it getting ovm_tree_printer when I am trying to use ovm_printer?

1
probably because your 'printer' is not an instance of the 'ovm_table_pribnter'. You can only cast to a base class. - Serge

1 Answers

0
votes

ovm_printer is just the base class that declares the API for printers. What gets passed around are concrete classes, like ovm_table_printer or ovm_tree_printer. Both of these can be stored in a variable of type ovm_printer.

You're probably passing a tree printer in the print(...) call on your object. If you don't specify any printer, the default printer is used. Per default, this is the table printer, but it could be that this was changed. Look for ovm_default_printer in the package scope.

If someone explicitly wants you to do a tree print, then you can't magically change that to a table print. Best you can do is check if you're doing a table print and if so then change the knobs:

 if (!$cast(tbl_printer, printer))
   return;
 tbl_printer.knobs.value_width = 100;