PageRenderTime 34ms CodeModel.GetById 16ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ovm-2.0.1/src/base/ovm_printer.svh

http://camlet.googlecode.com/
SystemVerilog | 313 lines | 156 code | 48 blank | 109 comment | 0 complexity | c5f4443b5d7a844583f3c27caf8a82b8 MD5 | raw file
Possible License(s): Apache-2.0
  1// $Id: //dvt/vtech/dev/main/ovm/src/base/ovm_printer.svh#8 $
  2//----------------------------------------------------------------------
  3//   Copyright 2007-2008 Mentor Graphics Corporation
  4//   Copyright 2007-2008 Cadence Design Systems, Inc.
  5//   All Rights Reserved Worldwide
  6//
  7//   Licensed under the Apache License, Version 2.0 (the
  8//   "License"); you may not use this file except in
  9//   compliance with the License.  You may obtain a copy of
 10//   the License at
 11//
 12//       http://www.apache.org/licenses/LICENSE-2.0
 13//
 14//   Unless required by applicable law or agreed to in
 15//   writing, software distributed under the License is
 16//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 17//   CONDITIONS OF ANY KIND, either express or implied.  See
 18//   the License for the specific language governing
 19//   permissions and limitations under the License.
 20//----------------------------------------------------------------------
 21
 22//------------------------------------------------------------------------------
 23//
 24// This file provides the declarations for the following printing classes
 25//   ovm_printer_knobs       : controls for controlling print output
 26//   ovm_printer             : default printer object, contains a knob object 
 27//                              and user print methods and override methods.
 28//   ovm_table_printer_knobs : knobs specific to table format, derived from
 29//                             ovm_printer_knobs.
 30//   ovm_table_printer       : printer for tabular format
 31//   ovm_tree_printer_knobs  : knobs specific to tree format
 32//   ovm_tree_printer        : printer for tree format
 33//   ovm_line_printer        : printer for line format
 34//
 35//------------------------------------------------------------------------------
 36`ifndef OVM_PRINTER_SVH
 37`define OVM_PRINTER_SVH
 38
 39// Forward declarations of printer classes
 40typedef class ovm_printer;
 41typedef class ovm_tree_printer;
 42typedef class ovm_table_printer;
 43typedef class ovm_line_printer;
 44
 45`include "base/ovm_object.svh"
 46`include "base/ovm_misc.svh"
 47
 48parameter OVM_STDOUT = 1;  // Writes to standard out and nc logfile
 49
 50//------------------------------------------------------------------------------
 51//
 52// CLASS: ovm_printer_knobs
 53//
 54// Provides standard printer formatting controls.
 55//------------------------------------------------------------------------------
 56
 57class ovm_printer_knobs;
 58  int       column         = 0;      // current column position. This is not a
 59                                     // user level variable.
 60  int       max_width      = 999;    // maximum with of a field. Any field that
 61                                     // requires more characters will be 
 62                                     // truncated.
 63  string    truncation     = "+";    // character to indicate a field has been
 64                                     // truncated.
 65
 66  bit       header         = 1;      // print the header
 67  bit       footer         = 1;      // print the footer
 68  int       global_indent  = 0;      // indentation for any printed line
 69  bit       full_name      = 1;      // the full name when printing id info
 70  bit       identifier     = 1;      // print index identifier information
 71  int       depth          = -1;     // printing depth, -1 is full
 72  bit       reference      = 1;      // print the reference of an object
 73  bit       type_name      = 1;      // print object type (for typed objects)
 74  bit       size           = 1;      // print the size of an object
 75  ovm_radix_enum default_radix = OVM_HEX;    // for data with no radix set
 76  int       begin_elements = 5;      // max front indexs of the array to print
 77                                     // (-1 for no max)
 78  int       end_elements   = 5;      // max back indexs of the array to print
 79  bit       show_radix     = 1;      // prepend value with radix
 80  string    prefix         = "";     // appended to start of each line
 81
 82  bit       print_fields   = 1;      // Used by the tcl printing
 83
 84  //where to print
 85  int       mcd            = OVM_STDOUT; // file descriptor(s) to write to
 86  bit       sprint         = 0;      // if set, write to string instead of mcd
 87
 88  //Radix output control
 89  string    bin_radix      = "'b";
 90  string    oct_radix      = "'o";
 91  string    dec_radix      = "'d";
 92  string    unsigned_radix = "'d";
 93  string    hex_radix      = "'h";
 94
 95  extern function string get_radix_str(ovm_radix_enum radix);
 96endclass
 97
 98
 99//------------------------------------------------------------------------------
100//
101// CLASS: ovm_printer
102//
103// Provides a generic printer. No formatting is done, the information is 
104// just printed in a raw form.
105//------------------------------------------------------------------------------
106
107class ovm_printer;
108  protected bit m_array_stack[$];
109  ovm_scope_stack    m_scope  = new;  //for internal use
110  string             m_string = "";   //for internal use
111
112  ovm_printer_knobs  knobs = new;
113
114  // Primary derived class overrides. Use these methods to create a new 
115  // printer type. Functions needed for array printing are not protected
116  // since array printing must be done in macros.
117  extern virtual  function void print_header       ();
118  extern virtual  function void print_footer       ();
119  extern virtual protected function void print_id           (string      id, 
120                                         byte        scope_separator=".");
121  extern virtual protected function void print_type_name    (string      name, bit is_object=0);
122  extern virtual protected function void print_size         (int         size=-1);
123  extern virtual protected function void print_newline      (bit         do_global_indent=1);
124  extern virtual protected function void print_value        (ovm_bitstream_t value, 
125                                         int         size, 
126                                         ovm_radix_enum  radix=OVM_NORADIX);
127  extern virtual protected function void print_value_object (ovm_object  value);
128  extern virtual protected function void print_value_string (string      value);
129
130  extern virtual  function void print_value_array  (string      value="", 
131                                         int         size=0);
132  extern virtual  function void print_array_header ( string      name,
133                                         int         size,     
134                                         string      arraytype="array",
135                                         byte        scope_separator=".");
136  extern virtual  function void print_array_range  (int         min,      
137                                         int         max);
138  extern virtual  function void print_array_footer (int         size=0);
139
140  // Utility methods, may be overridden.
141  extern virtual protected function void indent             (int         depth, 
142                                         string      indent_str="  ");
143
144  // Primary user level functions. These functions are called from 
145  // ovm_object::print() methods, or are called directly on any data to
146  // get formatted printing.
147  extern virtual function void print_field         ( string      name, 
148                                         ovm_bitstream_t value, 
149                                         int         size, 
150                                         ovm_radix_enum  radix=OVM_NORADIX,
151                                         byte        scope_separator=".",
152                                         string      type_name="");
153  extern virtual function void print_object_header ( string      name,
154                                         ovm_object  value, 
155                                         byte        scope_separator=".");
156  extern virtual function void print_object        (string      name,
157                                         ovm_object  value, 
158                                         byte        scope_separator=".");
159  extern virtual function void print_string        (string      name,
160                                         string      value, 
161                                         byte        scope_separator=".");
162  extern virtual function void print_time          ( string      name,
163                                         time        value, 
164                                         byte        scope_separator=".");
165  extern virtual function void print_generic       (string      name, 
166                                         string      type_name, 
167                                         int         size, 
168                                         string      value,
169                                         byte        scope_separator=".");
170
171  // Utility methods
172  extern  function bit    istop             ();
173  extern  function int    index             (string name);
174  extern  function string index_string      (int index, 
175                                         string      name="");
176  extern protected function void   write_stream      (string str);
177endclass
178
179
180//------------------------------------------------------------------------------
181//
182// CLASS: ovm_hier_printer_knobs
183//
184// Knobs for hierarchical printing. These are knobs which are common to any
185// hierarchy printing control.
186//------------------------------------------------------------------------------
187class ovm_hier_printer_knobs extends ovm_printer_knobs;
188  // Add an indentation string for indenting hierarchy instead of 
189  // printing full names.
190  string   indent_str    = "  ";    // string to use for indentation
191  bit      show_root      = 0;      // show full name of the very first object
192
193  extern function new(); 
194endclass
195
196
197//------------------------------------------------------------------------------
198//
199// CLASS: ovm_table_printer_knobs
200//
201// Table printing knobs. Specifies the length of the columns.
202//------------------------------------------------------------------------------
203
204class ovm_table_printer_knobs extends ovm_hier_printer_knobs;
205  int            name_width  = 25;      // characters in the name column
206  int            type_width  = 20;      // characters in the type column
207  int            size_width  = 5;       // characters in the size column
208  int            value_width = 20;      // characters in the value column
209endclass
210
211//------------------------------------------------------------------------------
212//
213// CLASS: ovm_table_printer
214//
215// Table printer prints output in a tabular format.
216//------------------------------------------------------------------------------
217
218class ovm_table_printer extends ovm_printer;
219  extern  function new(); 
220
221  // Adds column headers
222  extern virtual function void print_header       ();
223  extern virtual function void print_footer       ();
224
225  // Puts information in column format
226  extern virtual function void print_id           (string      id,
227                                        byte        scope_separator=".");
228  extern virtual function void print_size         (int         size=-1);
229  extern virtual function void print_type_name    (string      name, bit is_object=0);
230  extern virtual function void print_value        (ovm_bitstream_t value, 
231                                        int         size, 
232                                        ovm_radix_enum  radix=OVM_NORADIX);
233  extern virtual function void print_value_object (ovm_object  value);
234  extern virtual function void print_value_string (string      value);
235  extern virtual function void print_value_array  (string      value="", 
236                                        int         size=0);
237
238  //override the knobs variable to allow direct access
239  ovm_table_printer_knobs knobs = new;
240endclass
241
242
243//------------------------------------------------------------------------------
244//
245// CLASS: ovm_tree_printer_knobs
246//
247// Tree printing knobs. Specifies the hierarchy separator.
248//------------------------------------------------------------------------------
249
250class ovm_tree_printer_knobs extends ovm_hier_printer_knobs;
251  string            separator     = "{}";    // the separator for composites
252endclass
253
254
255//------------------------------------------------------------------------------
256//
257// CLASS: ovm_tree_printer
258//
259// Tree printer prints output in a tree format.
260//------------------------------------------------------------------------------
261
262class ovm_tree_printer extends ovm_printer;
263  // Information to print at the opening/closing of a scope
264  extern virtual function void print_scope_open   ();
265  extern virtual function void print_scope_close  ();
266
267  // Puts information in tree format
268  extern virtual function void print_id           (string id,
269                                        byte   scope_separator=".");
270  extern virtual function void print_type_name    (string name, bit is_object=0);
271  extern virtual function void print_object_header(string      name,
272                                        ovm_object  value, 
273                                        byte        scope_separator=".");
274  extern virtual function void print_object       (string      name,
275                                        ovm_object  value, 
276                                        byte        scope_separator=".");
277  extern virtual function void print_string       ( string      name,
278                                        string      value, 
279                                        byte        scope_separator=".");
280  extern virtual function void print_value_object (ovm_object value);
281  extern virtual function void print_value_array  (string      value="", 
282                                        int         size=0);
283  extern virtual function void print_array_footer (int         size=0);
284
285  extern function new(); 
286
287  //override the knobs variable to allow direct access
288  ovm_tree_printer_knobs knobs = new;
289endclass
290
291
292//------------------------------------------------------------------------------
293//
294// CLASS: ovm_line_printer
295//
296// Tree printer prints output in a line format.
297//------------------------------------------------------------------------------
298
299class ovm_line_printer extends ovm_tree_printer;
300  extern virtual function void print_newline      (bit do_global_indent=1);
301  extern  function new(); 
302endclass
303
304
305// Package global printer objects
306ovm_table_printer ovm_default_table_printer = new();
307ovm_tree_printer  ovm_default_tree_printer  = new();
308ovm_line_printer  ovm_default_line_printer  = new();
309
310ovm_printer       ovm_default_printer = ovm_default_table_printer;
311
312
313`endif