uvm_printer及使用

1.uvm_printer使用示例

(1) 在调用uvm_top.print_topology()函数时,可以不指定uvm_printer参数;

(2) 在不指定uvm_printer参数的情况下,会使用uvm_default_table_printer;

(3) 如果有需要指定uvm_printer参数,可以指定为其他参数,如uvm_default_tree_printer, uvm_default_line_printer或其他用户自定义的printer;

 1 // Variable: uvm_default_table_printer
 2 //
 3 // The table printer is a global object that can be used with
 4 // <uvm_object::do_print> to get tabular style printing.
 5 
 6 uvm_table_printer uvm_default_table_printer = new();
 7 
 8 
 9 // Variable: uvm_default_tree_printer
10 //
11 // The tree printer is a global object that can be used with
12 // <uvm_object::do_print> to get multi-line tree style printing.
13 
14 uvm_tree_printer uvm_default_tree_printer  = new();
15 
16 
17 // Variable: uvm_default_line_printer
18 //
19 // The line printer is a global object that can be used with
20 // <uvm_object::do_print> to get single-line style printing.
21 
22 uvm_line_printer uvm_default_line_printer  = new();
23 
24 
25 // Variable: uvm_default_printer
26 //
27 // The default printer policy. Used when calls to <uvm_object::print>
28 // or <uvm_object::sprint> do not specify a printer policy.
29 //
30 // The default printer may be set to any legal <uvm_printer> derived type,
31 // including the global line, tree, and table printers described above.
32 
33 uvm_printer uvm_default_printer = uvm_default_table_printer;
 1 function void uvm_root::print_topology(uvm_printer printer=null);
 2 
 3   string s;
 4 
 5   if (m_children.num()==0) begin
 6     uvm_report_warning("EMTCOMP", "print_topology - No UVM components to print.", UVM_NONE);
 7     return;
 8   end
 9 
10   if (printer==null)
11     printer = uvm_default_printer;
12 
13   foreach (m_children[c]) begin
14     if(m_children[c].print_enabled) begin
15       printer.print_object("", m_children[c]);  
16     end
17   end
18   `uvm_info("UVMTOP",{"UVM testbench topology:\n",printer.emit()},UVM_NONE)
19 
20 endfunction

2.uvm_printer

 1 //------------------------------------------------------------------------------
 2 //
 3 // Class: uvm_printer
 4 //
 5 // The uvm_printer class provides an interface for printing <uvm_objects> in
 6 // various formats. Subtypes of uvm_printer implement different print formats,
 7 // or policies.
 8 //
 9 // A user-defined printer format can be created, or one of the following four
10 // built-in printers can be used:
11 //
12 // - <uvm_printer> - provides base printer functionality; must be overridden.
13 //
14 // - <uvm_table_printer> - prints the object in a tabular form. 
15 //
16 // - <uvm_tree_printer> - prints the object in a tree form. 
17 //
18 // - <uvm_line_printer> - prints the information on a single line, but uses the
19 //   same object separators as the tree printer.
20 //
21 // Printers have knobs that you use to control what and how information is printed.
22 // These knobs are contained in a separate knob class:
23 //
24 // - <uvm_printer_knobs> - common printer settings
25 //
26 // For convenience, global instances of each printer type are available for
27 // direct reference in your testbenches.
28 //
29 //  -  <uvm_default_tree_printer>
30 //  -  <uvm_default_line_printer>
31 //  -  <uvm_default_table_printer>
32 //  -  <uvm_default_printer> (set to default_table_printer by default)
33 //
34 // When <uvm_object::print> and <uvm_object::sprint> are called without 
35 // specifying a printer, the <uvm_default_printer> is used.
36 //
37 //------------------------------------------------------------------------------
38 virtual class uvm_printer;
39    
40   ...
41   extern virtual function void print_object (string     name,
42                                              uvm_object value, 
43                                              byte       scope_separator=".");
44   ...
45 endclass

3.uvm_printer派生类

3.1 uvm_table_printer

 1 //------------------------------------------------------------------------------
 2 //
 3 // Class: uvm_table_printer
 4 //
 5 // The table printer prints output in a tabular format.
 6 //
 7 // The following shows sample output from the table printer.
 8 //
 9 //|  ---------------------------------------------------
10 //|  Name        Type            Size        Value
11 //|  ---------------------------------------------------
12 //|  c1          container       -           @1013
13 //|  d1          mydata          -           @1022
14 //|  v1          integral        32          'hcb8f1c97
15 //|  e1          enum            32          THREE
16 //|  str         string          2           hi
17 //|  value       integral        12          'h2d
18 //|  ---------------------------------------------------
19 //
20 //------------------------------------------------------------------------------
class uvm_table_printer extends uvm_printer;

  // Variable: new
  //
  // Creates a new instance of ~uvm_table_printer~.
  //
  extern function new(); 

  // Function: emit
  //
  // Formats the collected information from prior calls to ~print_*~
  // into table format.
  //
  extern virtual function string emit();

  // Variables- m_max_*
  //
  // holds max size of each column, so table columns can be resized dynamically

  protected int m_max_name;
  protected int m_max_type;
  protected int m_max_size;
  protected int m_max_value;

  extern function void calculate_max_widths();

endclass

3.2 uvm_tree_printer

 1 //------------------------------------------------------------------------------
 2 //
 3 // Class: uvm_tree_printer
 4 //
 5 // By overriding various methods of the <uvm_printer> super class,
 6 // the tree printer prints output in a tree format.
 7 //
 8 // The following shows sample output from the tree printer.
 9 //
10 //|  c1: (container@1013) {
11 //|    d1: (mydata@1022) {
12 //|         v1: 'hcb8f1c97
13 //|         e1: THREE
14 //|         str: hi
15 //|    }  
16 //|    value: 'h2d
17 //|  }
18 //
19 //------------------------------------------------------------------------------
 1 class uvm_tree_printer extends uvm_printer;
 2 
 3   string newline = "\n";
 4 
 5   // Variable: new
 6   //
 7   // Creates a new instance of ~uvm_tree_printer~.
 8 
 9   extern function new();
10 
11   // Function: emit
12   //
13   // Formats the collected information from prior calls to ~print_*~
14   // into hierarchical tree format.
15   //
16   extern virtual function string emit();
17 
18 endclass

3.3 uvm_line_printer

 1 //------------------------------------------------------------------------------
 2 //
 3 // Class: uvm_line_printer
 4 //
 5 // The line printer prints output in a line format.
 6 //
 7 // The following shows sample output from the line printer.
 8 //
 9 //| c1: (container@1013) { d1: (mydata@1022) { v1: 'hcb8f1c97 e1: THREE str: hi } value: 'h2d } 
10 //------------------------------------------------------------------------------
 1 class uvm_line_printer extends uvm_tree_printer;
 2 
 3   // Variable: new
 4   //
 5   // Creates a new instance of ~uvm_line_printer~. It differs from the
 6   // <uvm_tree_printer> only in that the output contains no line-feeds
 7   // and indentation.
 8 
 9   function new(); 
10     newline = " ";
11     knobs.indent = 0;
12   endfunction
13 
14 endclass

 

posted on 2022-04-29 14:36  知北游。。  阅读(1679)  评论(0编辑  收藏  举报

导航