21 UVM printer

2023-12-31 01:12:48

uvm_printer 类提供了以不同格式打印 uvm_objects 的灵活性。我们已经讨论了使用 `uvm_field_* 宏的 print() 方法,或者如果不使用 utils_begin/ end 宏,则编写 do_print() 方法。

UVM printer提供四种内置printer。

  1. uvm_printer
  2. uvm_table_printer
  3. uvm_tree_printer
  4. uvm_line_printer

1 uvm_printer hierarchy

2 UVM Printer Classes

3 UVM printer knobs

uvm_printer_knobs 类为所有printer类型的printer设置提供了额外的可行性。

uvm_printer_knobs knobs = new

uvm_printer_knobs 类中声明的一些变量。

size:控制是否打印字段的大小。

depth:表示打印对象时的递归深度。

4 UVM printer Methods

?

`include "uvm_macros.svh"
import uvm_pkg::*;

typedef enum{RED, GREEN, BLUE} color_type;

class temp_class extends uvm_object;
  rand bit [7:0] tmp_addr;
  rand bit [7:0] tmp_data;
  
  function new(string name = "temp_class");
    super.new(name);
  endfunction
  
  `uvm_object_utils_begin(temp_class)
    `uvm_field_int(tmp_addr, UVM_ALL_ON)
    `uvm_field_int(tmp_data, UVM_ALL_ON)
  `uvm_object_utils_end
endclass

class my_object extends uvm_object;
  rand int        value;
       string     names;
  rand color_type colors;
  rand byte       data[4];
  rand bit [7:0]  addr;
  rand temp_class tmp;
  
  `uvm_object_utils_begin(my_object)
    `uvm_field_int(value, UVM_ALL_ON)
    `uvm_field_string(names, UVM_ALL_ON)
    `uvm_field_enum(color_type, colors, UVM_ALL_ON)
    `uvm_field_sarray_int(data, UVM_ALL_ON)
    `uvm_field_int(addr, UVM_ALL_ON)
    `uvm_field_object(tmp, UVM_ALL_ON)
  `uvm_object_utils_end
  
  function new(string name = "my_object");
    super.new(name);
    tmp = new();
    this.names = "UVM";
  endfunction
endclass

class my_test extends uvm_test;
  `uvm_component_utils(my_test)
  my_object obj;
  bit packed_data_bits[];
  byte unsigned packed_data_bytes[];
  int unsigned packed_data_ints[];
  
  my_object unpack_obj;
  
  function new(string name = "my_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    obj = my_object::type_id::create("obj", this);
    assert(obj.randomize());
    `uvm_info(get_full_name(), "obj print without any argument", UVM_LOW);
    
    // Knob setting.
    uvm_default_printer.knobs.indent = 5;
    uvm_default_printer.knobs.hex_radix = "0x";
    
    obj.print();
    `uvm_info(get_full_name(), "obj print with uvm_default_table_printer argument", UVM_LOW);
    obj.print(uvm_default_table_printer);
    `uvm_info(get_full_name(), "obj print with uvm_default_tree_printer argument", UVM_LOW);
    obj.print(uvm_default_tree_printer);
    `uvm_info(get_full_name(), "obj print with uvm_default_line_printer argument", UVM_LOW);
    obj.print(uvm_default_line_printer);
  endfunction
endclass

module tb_top;
  initial begin
    run_test("my_test");
  end
endmodule

?output:

UVM_INFO testbench.sv(61) @ 0: uvm_test_top [uvm_test_top] obj print without any argument
--------------------------------------------------
Name                Type          Size  Value     
--------------------------------------------------
obj                 my_object     -     @349      
     value          integral      32    0x1f135537
     names          string        3     UVM       
     colors         color_type    32    GREEN     
     data           sa(integral)  4     -         
          [0]       integral      8     0x9f      
          [1]       integral      8     0x33      
          [2]       integral      8     0x12      
          [3]       integral      8     0x9c      
     addr           integral      8     0x2f      
     tmp            temp_class    -     @350      
          tmp_addr  integral      8     0x39      
          tmp_data  integral      8     0xbd      
--------------------------------------------------
UVM_INFO testbench.sv(68) @ 0: uvm_test_top [uvm_test_top] obj print with uvm_default_table_printer argument
--------------------------------------------------
Name                Type          Size  Value     
--------------------------------------------------
obj                 my_object     -     @349      
     value          integral      32    0x1f135537
     names          string        3     UVM       
     colors         color_type    32    GREEN     
     data           sa(integral)  4     -         
          [0]       integral      8     0x9f      
          [1]       integral      8     0x33      
          [2]       integral      8     0x12      
          [3]       integral      8     0x9c      
     addr           integral      8     0x2f      
     tmp            temp_class    -     @350      
          tmp_addr  integral      8     0x39      
          tmp_data  integral      8     0xbd      
--------------------------------------------------
UVM_INFO testbench.sv(70) @ 0: uvm_test_top [uvm_test_top] obj print with uvm_default_tree_printer argument
obj: (my_object@349) {
  value: 'h1f135537 
  names: UVM 
  colors: GREEN 
  data: {
    [0]: 'h9f 
    [1]: 'h33 
    [2]: 'h12 
    [3]: 'h9c 
  }
  addr: 'h2f 
  tmp: (temp_class@350) {
    tmp_addr: 'h39 
    tmp_data: 'hbd 
  }
}
UVM_INFO testbench.sv(72) @ 0: uvm_test_top [uvm_test_top] obj print with uvm_default_line_printer argument
obj: (my_object@349) { value: 'h1f135537  names: UVM  colors: GREEN  data: { [0]: 'h9f  [1]: 'h33  [2]: 'h12  [3]: 'h9c  } addr: 'h2f  tmp: (temp_class@350) { tmp_addr: 'h39  tmp_data: 'hbd  } } 

5 The print function defined in the uvm_object class

uvm_object 中的 print 函数实际上采用 uvm_printer 类类型作为参数。

function void uvm_object::print(uvm_printer printer=null);
  if (printer==null)
    printer = uvm_default_printer;
  if (printer == null)
    `uvm_error("NULLPRINTER","uvm_default_printer is null")
  $fwrite(printer.knobs.mcd,sprint(printer)); 
endfunction

文章来源:https://blog.csdn.net/Bonnie_89/article/details/135294245
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。