/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

  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. // This file provides the declarations for the following printing classes
  24. // ovm_printer_knobs : controls for controlling print output
  25. // ovm_printer : default printer object, contains a knob object
  26. // and user print methods and override methods.
  27. // ovm_table_printer_knobs : knobs specific to table format, derived from
  28. // ovm_printer_knobs.
  29. // ovm_table_printer : printer for tabular format
  30. // ovm_tree_printer_knobs : knobs specific to tree format
  31. // ovm_tree_printer : printer for tree format
  32. // ovm_line_printer : printer for line format
  33. //
  34. //------------------------------------------------------------------------------
  35. `ifndef OVM_PRINTER_SVH
  36. `define OVM_PRINTER_SVH
  37. // Forward declarations of printer classes
  38. typedef class ovm_printer;
  39. typedef class ovm_tree_printer;
  40. typedef class ovm_table_printer;
  41. typedef class ovm_line_printer;
  42. `include "base/ovm_object.svh"
  43. `include "base/ovm_misc.svh"
  44. parameter OVM_STDOUT = 1; // Writes to standard out and nc logfile
  45. //------------------------------------------------------------------------------
  46. //
  47. // CLASS: ovm_printer_knobs
  48. //
  49. // Provides standard printer formatting controls.
  50. //------------------------------------------------------------------------------
  51. class ovm_printer_knobs;
  52. int column = 0; // current column position. This is not a
  53. // user level variable.
  54. int max_width = 999; // maximum with of a field. Any field that
  55. // requires more characters will be
  56. // truncated.
  57. string truncation = "+"; // character to indicate a field has been
  58. // truncated.
  59. bit header = 1; // print the header
  60. bit footer = 1; // print the footer
  61. int global_indent = 0; // indentation for any printed line
  62. bit full_name = 1; // the full name when printing id info
  63. bit identifier = 1; // print index identifier information
  64. int depth = -1; // printing depth, -1 is full
  65. bit reference = 1; // print the reference of an object
  66. bit type_name = 1; // print object type (for typed objects)
  67. bit size = 1; // print the size of an object
  68. ovm_radix_enum default_radix = OVM_HEX; // for data with no radix set
  69. int begin_elements = 5; // max front indexs of the array to print
  70. // (-1 for no max)
  71. int end_elements = 5; // max back indexs of the array to print
  72. bit show_radix = 1; // prepend value with radix
  73. string prefix = ""; // appended to start of each line
  74. bit print_fields = 1; // Used by the tcl printing
  75. //where to print
  76. int mcd = OVM_STDOUT; // file descriptor(s) to write to
  77. bit sprint = 0; // if set, write to string instead of mcd
  78. //Radix output control
  79. string bin_radix = "'b";
  80. string oct_radix = "'o";
  81. string dec_radix = "'d";
  82. string unsigned_radix = "'d";
  83. string hex_radix = "'h";
  84. extern function string get_radix_str(ovm_radix_enum radix);
  85. endclass
  86. //------------------------------------------------------------------------------
  87. //
  88. // CLASS: ovm_printer
  89. //
  90. // Provides a generic printer. No formatting is done, the information is
  91. // just printed in a raw form.
  92. //------------------------------------------------------------------------------
  93. class ovm_printer;
  94. protected bit m_array_stack[$];
  95. ovm_scope_stack m_scope = new; //for internal use
  96. string m_string = ""; //for internal use
  97. ovm_printer_knobs knobs = new;
  98. // Primary derived class overrides. Use these methods to create a new
  99. // printer type. Functions needed for array printing are not protected
  100. // since array printing must be done in macros.
  101. extern virtual function void print_header ();
  102. extern virtual function void print_footer ();
  103. extern virtual protected function void print_id (string id,
  104. byte scope_separator=".");
  105. extern virtual protected function void print_type_name (string name, bit is_object=0);
  106. extern virtual protected function void print_size (int size=-1);
  107. extern virtual protected function void print_newline (bit do_global_indent=1);
  108. extern virtual protected function void print_value (ovm_bitstream_t value,
  109. int size,
  110. ovm_radix_enum radix=OVM_NORADIX);
  111. extern virtual protected function void print_value_object (ovm_object value);
  112. extern virtual protected function void print_value_string (string value);
  113. extern virtual function void print_value_array (string value="",
  114. int size=0);
  115. extern virtual function void print_array_header ( string name,
  116. int size,
  117. string arraytype="array",
  118. byte scope_separator=".");
  119. extern virtual function void print_array_range (int min,
  120. int max);
  121. extern virtual function void print_array_footer (int size=0);
  122. // Utility methods, may be overridden.
  123. extern virtual protected function void indent (int depth,
  124. string indent_str=" ");
  125. // Primary user level functions. These functions are called from
  126. // ovm_object::print() methods, or are called directly on any data to
  127. // get formatted printing.
  128. extern virtual function void print_field ( string name,
  129. ovm_bitstream_t value,
  130. int size,
  131. ovm_radix_enum radix=OVM_NORADIX,
  132. byte scope_separator=".",
  133. string type_name="");
  134. extern virtual function void print_object_header ( string name,
  135. ovm_object value,
  136. byte scope_separator=".");
  137. extern virtual function void print_object (string name,
  138. ovm_object value,
  139. byte scope_separator=".");
  140. extern virtual function void print_string (string name,
  141. string value,
  142. byte scope_separator=".");
  143. extern virtual function void print_time ( string name,
  144. time value,
  145. byte scope_separator=".");
  146. extern virtual function void print_generic (string name,
  147. string type_name,
  148. int size,
  149. string value,
  150. byte scope_separator=".");
  151. // Utility methods
  152. extern function bit istop ();
  153. extern function int index (string name);
  154. extern function string index_string (int index,
  155. string name="");
  156. extern protected function void write_stream (string str);
  157. endclass
  158. //------------------------------------------------------------------------------
  159. //
  160. // CLASS: ovm_hier_printer_knobs
  161. //
  162. // Knobs for hierarchical printing. These are knobs which are common to any
  163. // hierarchy printing control.
  164. //------------------------------------------------------------------------------
  165. class ovm_hier_printer_knobs extends ovm_printer_knobs;
  166. // Add an indentation string for indenting hierarchy instead of
  167. // printing full names.
  168. string indent_str = " "; // string to use for indentation
  169. bit show_root = 0; // show full name of the very first object
  170. extern function new();
  171. endclass
  172. //------------------------------------------------------------------------------
  173. //
  174. // CLASS: ovm_table_printer_knobs
  175. //
  176. // Table printing knobs. Specifies the length of the columns.
  177. //------------------------------------------------------------------------------
  178. class ovm_table_printer_knobs extends ovm_hier_printer_knobs;
  179. int name_width = 25; // characters in the name column
  180. int type_width = 20; // characters in the type column
  181. int size_width = 5; // characters in the size column
  182. int value_width = 20; // characters in the value column
  183. endclass
  184. //------------------------------------------------------------------------------
  185. //
  186. // CLASS: ovm_table_printer
  187. //
  188. // Table printer prints output in a tabular format.
  189. //------------------------------------------------------------------------------
  190. class ovm_table_printer extends ovm_printer;
  191. extern function new();
  192. // Adds column headers
  193. extern virtual function void print_header ();
  194. extern virtual function void print_footer ();
  195. // Puts information in column format
  196. extern virtual function void print_id (string id,
  197. byte scope_separator=".");
  198. extern virtual function void print_size (int size=-1);
  199. extern virtual function void print_type_name (string name, bit is_object=0);
  200. extern virtual function void print_value (ovm_bitstream_t value,
  201. int size,
  202. ovm_radix_enum radix=OVM_NORADIX);
  203. extern virtual function void print_value_object (ovm_object value);
  204. extern virtual function void print_value_string (string value);
  205. extern virtual function void print_value_array (string value="",
  206. int size=0);
  207. //override the knobs variable to allow direct access
  208. ovm_table_printer_knobs knobs = new;
  209. endclass
  210. //------------------------------------------------------------------------------
  211. //
  212. // CLASS: ovm_tree_printer_knobs
  213. //
  214. // Tree printing knobs. Specifies the hierarchy separator.
  215. //------------------------------------------------------------------------------
  216. class ovm_tree_printer_knobs extends ovm_hier_printer_knobs;
  217. string separator = "{}"; // the separator for composites
  218. endclass
  219. //------------------------------------------------------------------------------
  220. //
  221. // CLASS: ovm_tree_printer
  222. //
  223. // Tree printer prints output in a tree format.
  224. //------------------------------------------------------------------------------
  225. class ovm_tree_printer extends ovm_printer;
  226. // Information to print at the opening/closing of a scope
  227. extern virtual function void print_scope_open ();
  228. extern virtual function void print_scope_close ();
  229. // Puts information in tree format
  230. extern virtual function void print_id (string id,
  231. byte scope_separator=".");
  232. extern virtual function void print_type_name (string name, bit is_object=0);
  233. extern virtual function void print_object_header(string name,
  234. ovm_object value,
  235. byte scope_separator=".");
  236. extern virtual function void print_object (string name,
  237. ovm_object value,
  238. byte scope_separator=".");
  239. extern virtual function void print_string ( string name,
  240. string value,
  241. byte scope_separator=".");
  242. extern virtual function void print_value_object (ovm_object value);
  243. extern virtual function void print_value_array (string value="",
  244. int size=0);
  245. extern virtual function void print_array_footer (int size=0);
  246. extern function new();
  247. //override the knobs variable to allow direct access
  248. ovm_tree_printer_knobs knobs = new;
  249. endclass
  250. //------------------------------------------------------------------------------
  251. //
  252. // CLASS: ovm_line_printer
  253. //
  254. // Tree printer prints output in a line format.
  255. //------------------------------------------------------------------------------
  256. class ovm_line_printer extends ovm_tree_printer;
  257. extern virtual function void print_newline (bit do_global_indent=1);
  258. extern function new();
  259. endclass
  260. // Package global printer objects
  261. ovm_table_printer ovm_default_table_printer = new();
  262. ovm_tree_printer ovm_default_tree_printer = new();
  263. ovm_line_printer ovm_default_line_printer = new();
  264. ovm_printer ovm_default_printer = ovm_default_table_printer;
  265. `endif