如何使用uvm_printer而不是默认的十六进制格式以十进制格式打印整数值

时间:2018-09-04 09:06:29

标签: uvm

class dpcfg extends uvm_object;
  rand int num_lanes;

  function new(string name="");
    super.new(name);
  endfunction

  function void do_print(uvm_printer printer);
    printer.print_string("dpcfg", "dpcfg");
    printer.print_field("num_lanes", num_lanes, $bits(num_lanes));
  endfunction

endclass

//Instantiating the above class
dpcfg cfg;
cfg = new("cfg");
cfg.print();

我得到的打印输出如下

 ----------------------------------------------
 Name                Type      Size  Value     
 ----------------------------------------------
 cfg                 dpcfg     -     @2579     
   dpcfg             string    5     dpcfg     
   num_lanes         integral  32    'hA 
 ----------------------------------------------

我需要如下打印输出

 ----------------------------------------------
 Name                Type      Size  Value     
 ----------------------------------------------
 cfg                 dpcfg     -     @2579     
   dpcfg             string    5     dpcfg     
   num_lanes         integral  32    'd10 
 ----------------------------------------------

2 个答案:

答案 0 :(得分:0)

怎么样:

printer.print_field("num_lanes", num_lanes, $bits(num_lanes), UVM_DEC);

print_field的原型为:

  // Function: print_field
  //
  // Prints an integral field (up to 4096 bits).
  //
  // name  - The name of the field. 
  // value - The value of the field.
  // size  - The number of bits of the field (maximum is 4096). 
  // radix - The radix to use for printing. The printer knob for radix is used
  //           if no radix is specified. 
  // scope_separator - is used to find the leaf name since many printers only
  //           print the leaf name of a field.  Typical values for the separator
  //           are . (dot) or [ (open bracket).

  extern virtual function void print_field (string          name, 
                                            uvm_bitstream_t value, 
                                            int    size, 
                                            uvm_radix_enum radix=UVM_NORADIX,
                                            byte   scope_separator=".",
                                            string type_name="");

我怎么知道这个?来自UVM随附的HTML文档。它确实非常好,如果有疑问,您可以单击进入UVM代码本身。

答案 1 :(得分:0)

添加UVM_DEC解决了该问题

function void do_print(uvm_printer printer);
  printer.print_string("dpcfg", "dpcfg");
  printer.print_field("num_lanes", num_lanes, $bits(num_lanes), UVM_DEC);
endfunction