OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_printer.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2007-2011 Mentor Graphics Corporation
4
//   Copyright 2007-2011 Cadence Design Systems, Inc.
5
//   Copyright 2010 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License or the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
 
24
typedef class uvm_printer_knobs;
25
 
26
parameter UVM_STDOUT = 1;  // Writes to standard out and logfile
27
 
28
typedef struct {
29
  int    level;
30
  string name;
31
  string type_name;
32
  string size;
33
  string val;
34
} uvm_printer_row_info;
35
 
36
 
37
//------------------------------------------------------------------------------
38
//
39
// Class: uvm_printer
40
//
41
// The uvm_printer class provides an interface for printing  in
42
// various formats. Subtypes of uvm_printer implement different print formats,
43
// or policies.
44
//
45
// A user-defined printer format can be created, or one of the following four
46
// built-in printers can be used:
47
//
48
// -  - provides base printer functionality; must be overridden.
49
//
50
// -  - prints the object in a tabular form.
51
//
52
// -  - prints the object in a tree form.
53
//
54
// -  - prints the information on a single line, but uses the
55
//   same object separators as the tree printer.
56
//
57
// Printers have knobs that you use to control what and how information is printed.
58
// These knobs are contained in a separate knob class:
59
//
60
// -  - common printer settings
61
//
62
// For convenience, global instances of each printer type are available for
63
// direct reference in your testbenches.
64
//
65
//  -  
66
//  -  
67
//  -  
68
//  -   (set to default_table_printer by default)
69
//
70
// When  and  are called without
71
// specifying a printer, the  is used.
72
//
73
//------------------------------------------------------------------------------
74
virtual class uvm_printer;
75
 
76
  // Variable: knobs
77
  //
78
  // The knob object provides access to the variety of knobs associated with a
79
  // specific printer instance.
80
  //
81
  uvm_printer_knobs knobs = new;
82
 
83
 
84
  // Group: Methods for printer usage
85
 
86
  // These functions are called from , or they are called
87
  // directly on any data to get formatted printing.
88
 
89
  // Function: print_field
90
  //
91
  // Prints an integral field (up to 4096 bits).
92
  //
93
  // name  - The name of the field.
94
  // value - The value of the field.
95
  // size  - The number of bits of the field (maximum is 4096).
96
  // radix - The radix to use for printing. The printer knob for radix is used
97
  //           if no radix is specified.
98
  // scope_separator - is used to find the leaf name since many printers only
99
  //           print the leaf name of a field.  Typical values for the separator
100
  //           are . (dot) or [ (open bracket).
101
 
102
  extern virtual function void print_field (string          name,
103
                                            uvm_bitstream_t value,
104
                                            int    size,
105
                                            uvm_radix_enum radix=UVM_NORADIX,
106
                                            byte   scope_separator=".",
107
                                            string type_name="");
108
 
109
  // backward compatibility
110
  virtual function void print_int (string          name,
111
                                   uvm_bitstream_t value,
112
                                   int    size,
113
                                   uvm_radix_enum radix=UVM_NORADIX,
114
                                   byte   scope_separator=".",
115
                                   string type_name="");
116
    print_field (name, value, size, radix, scope_separator, type_name);
117
  endfunction
118
 
119
  // Function: print_field_int
120
  //
121
  // Prints an integral field (up to 64 bits).
122
  //
123
  // name  - The name of the field.
124
  // value - The value of the field.
125
  // size  - The number of bits of the field (maximum is 64).
126
  // radix - The radix to use for printing. The printer knob for radix is used
127
  //           if no radix is specified.
128
  // scope_separator - is used to find the leaf name since many printers only
129
  //           print the leaf name of a field.  Typical values for the separator
130
  //           are . (dot) or [ (open bracket).
131
  extern virtual function void print_field_int (string name,
132
                                                uvm_integral_t value,
133
                                                int    size,
134
                                                uvm_radix_enum radix=UVM_NORADIX,
135
                                                byte   scope_separator=".",
136
                                                string type_name="");
137
 
138
  // Function: print_object
139
  //
140
  // Prints an object. Whether the object is recursed depends on a variety of
141
  // knobs, such as the depth knob; if the current depth is at or below the
142
  // depth setting, then the object is not recursed.
143
  //
144
  // By default, the children of  are printed. To turn this
145
  // behavior off, you must set the  bit to 0 for
146
  // the specific children you do not want automatically printed.
147
 
148
  extern virtual function void print_object (string     name,
149
                                             uvm_object value,
150
                                             byte       scope_separator=".");
151
 
152
 
153
  extern virtual function void print_object_header (string name,
154
                                                    uvm_object value,
155
                                                    byte scope_separator=".");
156
 
157
 
158
  // Function: print_string
159
  //
160
  // Prints a string field.
161
 
162
  extern virtual function void print_string (string name,
163
                                             string value,
164
                                             byte   scope_separator=".");
165
 
166
 
167
  // Function: print_time
168
  //
169
  // Prints a time value. name is the name of the field, and value is the
170
  // value to print.
171
  //
172
  // The print is subject to the ~$timeformat~ system task for formatting time
173
  // values.
174
 
175
  extern virtual function void print_time (string name,
176
                                           time   value,
177
                                           byte   scope_separator=".");
178
 
179
 
180
  // Function: print_real
181
  //
182
  // Prints a real field.
183
 
184
  extern virtual function void print_real (string  name,
185
                                           real    value,
186
                                           byte    scope_separator=".");
187
 
188
  // Function: print_generic
189
  //
190
  // Prints a field having the given ~name~, ~type_name~, ~size~, and ~value~.
191
 
192
  extern virtual function void print_generic (string  name,
193
                                              string  type_name,
194
                                              int     size,
195
                                              string  value,
196
                                              byte    scope_separator=".");
197
 
198
  // Group: Methods for printer subtyping
199
 
200
  // Function: emit
201
  //
202
  // Emits a string representing the contents of an object
203
  // in a format defined by an extension of this object.
204
  //
205
  extern virtual function string emit ();
206
 
207
 
208
  // Function: format_row
209
  //
210
  // Hook for producing custom output of a single field (row).
211
  //
212
  extern virtual function string format_row (uvm_printer_row_info row);
213
 
214
 
215
  // Function: format_header
216
  //
217
  // Hook to override base header with a custom header.
218
  virtual function string format_header();
219
    return "";
220
  endfunction
221
 
222
 
223
  // Function: format_footer
224
  //
225
  // Hook to override base footer with a custom footer.
226
  virtual function string format_footer();
227
    return "";
228
  endfunction
229
 
230
 
231
  // Function: adjust_name
232
  //
233
  // Prints a field's name, or ~id~, which is the full instance name.
234
  //
235
  // The intent of the separator is to mark where the leaf name starts if the
236
  // printer if configured to print only the leaf name of the identifier.
237
 
238
  extern virtual protected function string adjust_name (string id,
239
                                                   byte scope_separator=".");
240
 
241
  // Function: print_array_header
242
  //
243
  // Prints the header of an array. This function is called before each
244
  // individual element is printed.  is called to mark the
245
  // completion of array printing.
246
 
247
  extern virtual  function void print_array_header(string name,
248
                                                   int    size,
249
                                                   string arraytype="array",
250
                                                   byte   scope_separator=".");
251
 
252
  // Function: print_array_range
253
  //
254
  // Prints a range using ellipses for values. This method is used when honoring
255
  // the array knobs for partial printing of large arrays,
256
  //  and .
257
  //
258
  // This function should be called after begin_elements have been printed
259
  // and before end_elements have been printed.
260
 
261
  extern virtual function void print_array_range (int min, int max);
262
 
263
 
264
  // Function: print_array_footer
265
  //
266
  // Prints the header of a footer. This function marks the end of an array
267
  // print. Generally, there is no output associated with the array footer, but
268
  // this method let's the printer know that the array printing is complete.
269
 
270
  extern virtual  function void print_array_footer (int size = 0);
271
 
272
 
273
 
274
  // Utility methods
275
  extern  function bit istop ();
276
  extern  function string index_string (int index, string name="");
277
 
278
  protected bit m_array_stack[$];
279
  uvm_scope_stack m_scope = new;
280
  string m_string;
281
 
282
  // holds each cell entry
283
  protected uvm_printer_row_info m_rows[$];
284
 
285
endclass
286
 
287
 
288
//------------------------------------------------------------------------------
289
//
290
// Class: uvm_table_printer
291
//
292
// The table printer prints output in a tabular format.
293
//
294
// The following shows sample output from the table printer.
295
//
296
//|  ---------------------------------------------------
297
//|  Name        Type            Size        Value
298
//|  ---------------------------------------------------
299
//|  c1          container       -           @1013
300
//|  d1          mydata          -           @1022
301
//|  v1          integral        32          'hcb8f1c97
302
//|  e1          enum            32          THREE
303
//|  str         string          2           hi
304
//|  value       integral        12          'h2d
305
//|  ---------------------------------------------------
306
//
307
//------------------------------------------------------------------------------
308
 
309
class uvm_table_printer extends uvm_printer;
310
 
311
  // Variable: new
312
  //
313
  // Creates a new instance of ~uvm_table_printer~.
314
  //
315
  extern function new();
316
 
317
  // Function: emit
318
  //
319
  // Formats the collected information from prior calls to ~print_*~
320
  // into table format.
321
  //
322
  extern virtual function string emit();
323
 
324
  // Variables- m_max_*
325
  //
326
  // holds max size of each column, so table columns can be resized dynamically
327
 
328
  protected int m_max_name;
329
  protected int m_max_type;
330
  protected int m_max_size;
331
  protected int m_max_value;
332
 
333
  extern function void calculate_max_widths();
334
 
335
endclass
336
 
337
 
338
//------------------------------------------------------------------------------
339
//
340
// Class: uvm_tree_printer
341
//
342
// By overriding various methods of the  super class,
343
// the tree printer prints output in a tree format.
344
//
345
// The following shows sample output from the tree printer.
346
//
347
//|  c1: (container@1013) {
348
//|    d1: (mydata@1022) {
349
//|         v1: 'hcb8f1c97
350
//|         e1: THREE
351
//|         str: hi
352
//|    }
353
//|    value: 'h2d
354
//|  }
355
//
356
//------------------------------------------------------------------------------
357
 
358
class uvm_tree_printer extends uvm_printer;
359
 
360
  string newline = "\n";
361
 
362
  // Variable: new
363
  //
364
  // Creates a new instance of ~uvm_tree_printer~.
365
 
366
  extern function new();
367
 
368
  // Function: emit
369
  //
370
  // Formats the collected information from prior calls to ~print_*~
371
  // into hierarchical tree format.
372
  //
373
  extern virtual function string emit();
374
 
375
endclass
376
 
377
 
378
 
379
//------------------------------------------------------------------------------
380
//
381
// Class: uvm_line_printer
382
//
383
// The line printer prints output in a line format.
384
//
385
// The following shows sample output from the line printer.
386
//
387
//| c1: (container@1013) { d1: (mydata@1022) { v1: 'hcb8f1c97 e1: THREE str: hi } value: 'h2d }
388
//------------------------------------------------------------------------------
389
 
390
class uvm_line_printer extends uvm_tree_printer;
391
 
392
  // Variable: new
393
  //
394
  // Creates a new instance of ~uvm_line_printer~. It differs from the
395
  //  only in that the output contains no line-feeds
396
  // and indentation.
397
 
398
  function new();
399
    newline = " ";
400
    knobs.indent = 0;
401
  endfunction
402
 
403
endclass
404
 
405
 
406
 
407
//------------------------------------------------------------------------------
408
//
409
// Class: uvm_printer_knobs
410
//
411
// The ~uvm_printer_knobs~ class defines the printer settings available to all
412
// printer subtypes.
413
//
414
//------------------------------------------------------------------------------
415
 
416
class uvm_printer_knobs;
417
 
418
  // Variable: header
419
  //
420
  // Indicates whether the  function should be called when
421
  // printing an object.
422
 
423
  bit header = 1;
424
 
425
 
426
  // Variable: footer
427
  //
428
  // Indicates whether the  function should be called when
429
  // printing an object.
430
 
431
  bit footer = 1;
432
 
433
 
434
  // Variable: full_name
435
  //
436
  // Indicates whether  should print the full name of an identifier
437
  // or just the leaf name.
438
 
439
  bit full_name = 0;
440
 
441
 
442
  // Variable: identifier
443
  //
444
  // Indicates whether  should print the identifier. This is useful
445
  // in cases where you just want the values of an object, but no identifiers.
446
 
447
  bit identifier = 1;
448
 
449
 
450
  // Variable: type_name
451
  //
452
  // Controls whether to print a field's type name.
453
 
454
  bit type_name = 1;
455
 
456
 
457
  // Variable: size
458
  //
459
  // Controls whether to print a field's size.
460
 
461
  bit size = 1;
462
 
463
 
464
  // Variable: depth
465
  //
466
  // Indicates how deep to recurse when printing objects.
467
  // A depth of -1 means to print everything.
468
 
469
  int depth = -1;
470
 
471
 
472
  // Variable: reference
473
  //
474
  // Controls whether to print a unique reference ID for object handles.
475
  // The behavior of this knob is simulator-dependent.
476
 
477
  bit reference = 1;
478
 
479
 
480
  // Variable: begin_elements
481
  //
482
  // Defines the number of elements at the head of a list to print.
483
  // Use -1 for no max.
484
 
485
  int begin_elements = 5;
486
 
487
 
488
  // Variable: end_elements
489
  //
490
  // This defines the number of elements at the end of a list that
491
  // should be printed.
492
 
493
  int end_elements = 5;
494
 
495
 
496
  // Variable: prefix
497
  //
498
  // Specifies the string prepended to each output line
499
 
500
  string prefix = "";
501
 
502
 
503
  // Variable: indent
504
  //
505
  // This knob specifies the number of spaces to use for level indentation.
506
  // The default level indentation is two spaces.
507
 
508
  int indent = 2;
509
 
510
 
511
  // Variable: show_root
512
  //
513
  // This setting indicates whether or not the initial object that is printed
514
  // (when current depth is 0) prints the full path name. By default, the first
515
  // object is treated like all other objects and only the leaf name is printed.
516
 
517
  bit show_root = 0;
518
 
519
 
520
  // Variable: mcd
521
  //
522
  // This is a file descriptor, or multi-channel descriptor, that specifies
523
  // where the print output should be directed.
524
  //
525
  // By default, the output goes to the standard output of the simulator.
526
 
527
  int mcd = UVM_STDOUT;
528
 
529
 
530
  // Variable: separator
531
  //
532
  // For tree printers only, determines the opening and closing
533
  // separators used for nested objects.
534
 
535
  string separator = "{}";
536
 
537
 
538
  // Variable: show_radix
539
  //
540
  // Indicates whether the radix string ('h, and so on) should be prepended to
541
  // an integral value when one is printed.
542
 
543
  bit show_radix = 1;
544
 
545
 
546
  // Variable: default_radix
547
  //
548
  // This knob sets the default radix to use for integral values when no radix
549
  // enum is explicitly supplied to the  or
550
  //  methods.
551
 
552
  uvm_radix_enum default_radix = UVM_HEX;
553
 
554
 
555
  // Variable: dec_radix
556
  //
557
  // This string should be prepended to the value of an integral type when a
558
  // radix of  is used for the radix of the integral object.
559
  //
560
  // When a negative number is printed, the radix is not printed since only
561
  // signed decimal values can print as negative.
562
 
563
  string dec_radix = "'d";
564
 
565
 
566
  // Variable: bin_radix
567
  //
568
  // This string should be prepended to the value of an integral type when a
569
  // radix of  is used for the radix of the integral object.
570
 
571
  string bin_radix = "'b";
572
 
573
 
574
  // Variable: oct_radix
575
  //
576
  // This string should be prepended to the value of an integral type when a
577
  // radix of  is used for the radix of the integral object.
578
 
579
  string oct_radix = "'o";
580
 
581
 
582
  // Variable: unsigned_radix
583
  //
584
  // This is the string which should be prepended to the value of an integral
585
  // type when a radix of  is used for the radix of the integral
586
  // object.
587
 
588
  string unsigned_radix = "'d";
589
 
590
 
591
  // Variable: hex_radix
592
  //
593
  // This string should be prepended to the value of an integral type when a
594
  // radix of  is used for the radix of the integral object.
595
 
596
  string hex_radix = "'h";
597
 
598
 
599
  // Function: get_radix_str
600
  //
601
  // Converts the radix from an enumerated to a printable radix according to
602
  // the radix printing knobs (bin_radix, and so on).
603
 
604
  function string get_radix_str(uvm_radix_enum radix);
605
    if(show_radix == 0)
606
      return "";
607
    if(radix == UVM_NORADIX)
608
      radix = default_radix;
609
    case(radix)
610
      UVM_BIN: return bin_radix;
611
      UVM_OCT: return oct_radix;
612
      UVM_DEC: return dec_radix;
613
      UVM_HEX: return hex_radix;
614
      UVM_UNSIGNED: return unsigned_radix;
615
      default: return "";
616
    endcase
617
  endfunction
618
 
619
  // Deprecated knobs, hereafter ignored
620
  int max_width = 999;
621
  string truncation = "+";
622
  int name_width = -1;
623
  int type_width = -1;
624
  int size_width = -1;
625
  int value_width = -1;
626
  bit sprint = 1;
627
 
628
endclass
629
 
630
 
631
typedef uvm_printer_knobs uvm_table_printer_knobs;
632
typedef uvm_printer_knobs uvm_tree_printer_knobs;
633
 
634
 
635
//------------------------------------------------------------------------------
636
// IMPLEMENTATION
637
//------------------------------------------------------------------------------
638
 
639
// emit
640
// ----
641
 
642
function string uvm_printer::emit ();
643
  `uvm_error("NO_OVERRIDE","emit() method not overridden in printer subtype")
644
  return "";
645
endfunction
646
 
647
 
648
// format_row
649
// ----------
650
 
651
function string uvm_printer::format_row (uvm_printer_row_info row);
652
  return "";
653
endfunction
654
 
655
 
656
// print_array_header
657
// ------------------
658
 
659
function void uvm_printer::print_array_header (string name,
660
                                               int size,
661
                                               string arraytype="array",
662
                                               byte scope_separator=".");
663
  uvm_printer_row_info row_info;
664
 
665
  if(name != "")
666
    m_scope.set_arg(name);
667
 
668
  row_info.level = m_scope.depth();
669
  row_info.name = adjust_name(m_scope.get(),scope_separator);
670
  row_info.type_name = arraytype;
671
  row_info.size = $sformatf("%0d",size);
672
  row_info.val = "-";
673
 
674
  m_rows.push_back(row_info);
675
 
676
  m_scope.down(name);
677
  m_array_stack.push_back(1);
678
endfunction
679
 
680
 
681
// print_array_footer
682
// ------------------
683
 
684
function void  uvm_printer::print_array_footer (int size=0);
685
  if(m_array_stack.size()) begin
686
    m_scope.up();
687
    void'(m_array_stack.pop_front());
688
  end
689
endfunction
690
 
691
 
692
// print_array_range
693
// -----------------
694
 
695
function void uvm_printer::print_array_range(int min, int max);
696
  string tmpstr;
697
  if(min == -1 && max == -1)
698
     return;
699
  if(min == -1)
700
     min = max;
701
  if(max == -1)
702
     max = min;
703
  if(max < min)
704
     return;
705
  print_generic("...", "...", -2, "...");
706
endfunction
707
 
708
 
709
// print_object_header
710
// -------------------
711
 
712
function void uvm_printer::print_object_header (string name,
713
                                                uvm_object value,
714
                                                byte scope_separator=".");
715
  uvm_printer_row_info row_info;
716
  uvm_component comp;
717
 
718
  if(name == "") begin
719
    if(value!=null) begin
720
      if((m_scope.depth()==0) && $cast(comp, value)) begin
721
        name = comp.get_full_name();
722
      end
723
      else begin
724
        name=value.get_name();
725
      end
726
    end
727
  end
728
 
729
  if(name == "")
730
    name = "";
731
 
732
  m_scope.set_arg(name);
733
 
734
  row_info.level = m_scope.depth();
735
 
736
  if(row_info.level == 0 && knobs.show_root==1)
737
        row_info.name = value.get_full_name();
738
  else
739
        row_info.name = adjust_name(m_scope.get(),scope_separator);
740
 
741
  row_info.type_name = (value != null) ?  value.get_type_name() : "object";
742
  row_info.size = "-";
743
  row_info.val = knobs.reference ? uvm_object_value_str(value) : "-";
744
 
745
  m_rows.push_back(row_info);
746
 
747
endfunction
748
 
749
 
750
// print_object
751
// ------------
752
 
753
function void uvm_printer::print_object (string name, uvm_object value,
754
                                         byte scope_separator=".");
755
  uvm_component comp, child_comp;
756
 
757
  print_object_header(name,value,scope_separator);
758
 
759
  if(value != null)  begin
760
    if((knobs.depth == -1 || (knobs.depth > m_scope.depth())) &&
761
          !value.__m_uvm_status_container.cycle_check.exists(value)) begin
762
 
763
      value.__m_uvm_status_container.cycle_check[value] = 1;
764
      if(name=="" && value!=null)
765
        m_scope.down(value.get_name());
766
      else
767
        m_scope.down(name);
768
 
769
      //Handle children of the comp
770
      if($cast(comp, value)) begin
771
        string name;
772
        if (comp.get_first_child(name))
773
          do begin
774
            child_comp = comp.get_child(name);
775
            if(child_comp.print_enabled)
776
              this.print_object("",child_comp);
777
          end while (comp.get_next_child(name));
778
      end
779
 
780
      // print members of object
781
      void'(value.sprint(this));
782
 
783
      if(name != "" && name[0] == "[")
784
        m_scope.up("[");
785
      else
786
        m_scope.up(".");
787
      value.__m_uvm_status_container.cycle_check.delete(value);
788
    end
789
  end
790
 
791
endfunction
792
 
793
 
794
// istop
795
// -----
796
 
797
function bit uvm_printer::istop ();
798
  return (m_scope.depth() == 0);
799
endfunction
800
 
801
 
802
// adjust_name
803
// -----------
804
 
805
function string uvm_printer::adjust_name(string id, byte scope_separator=".");
806
  if (knobs.show_root && m_scope.depth()==0 || knobs.full_name || id == "...")
807
    return id;
808
  return uvm_leaf_scope(id, scope_separator);
809
endfunction
810
 
811
 
812
// print_generic
813
// -------------
814
 
815
function void uvm_printer::print_generic (string name,
816
                                          string type_name,
817
                                          int size,
818
                                          string value,
819
                                          byte scope_separator=".");
820
 
821
  uvm_printer_row_info row_info;
822
 
823
  if (name != "" && name != "...") begin
824
    m_scope.set_arg(name);
825
    name = m_scope.get();
826
  end
827
 
828
  row_info.level = m_scope.depth();
829
  row_info.name = adjust_name(name,scope_separator);
830
  row_info.type_name = type_name;
831
  row_info.size = (size == -2 ? "..." : $sformatf("%0d",size));
832
  row_info.val = (value == "" ? "\"\"" : value);
833
 
834
  m_rows.push_back(row_info);
835
 
836
endfunction
837
 
838
 
839
// print_field
840
// ---------
841
 
842
function void uvm_printer::print_field (string name,
843
                                      uvm_bitstream_t value,
844
                                      int size,
845
                                      uvm_radix_enum radix=UVM_NORADIX,
846
                                      byte scope_separator=".",
847
                                      string type_name="");
848
 
849
  uvm_printer_row_info row_info;
850
  string sz_str, val_str;
851
 
852
  if(name != "") begin
853
    m_scope.set_arg(name);
854
    name = m_scope.get();
855
  end
856
 
857
  if(type_name == "") begin
858
    if(radix == UVM_TIME)
859
      type_name ="time";
860
    else if(radix == UVM_STRING)
861
      type_name ="string";
862
    else
863
      type_name ="integral";
864
  end
865
 
866
  sz_str.itoa(size);
867
 
868
  if(radix == UVM_NORADIX)
869
    radix = knobs.default_radix;
870
 
871
  val_str = uvm_bitstream_to_string (value, size, radix,
872
                                     knobs.get_radix_str(radix));
873
 
874
  row_info.level = m_scope.depth();
875
  row_info.name = adjust_name(name,scope_separator);
876
  row_info.type_name = type_name;
877
  row_info.size = sz_str;
878
  row_info.val = val_str;
879
 
880
  m_rows.push_back(row_info);
881
 
882
endfunction
883
 
884
// print_field_int
885
// ---------
886
 
887
function void uvm_printer::print_field_int (string name,
888
                                            uvm_integral_t value,
889
                                            int          size,
890
                                            uvm_radix_enum radix=UVM_NORADIX,
891
                                            byte         scope_separator=".",
892
                                            string       type_name="");
893
 
894
  uvm_printer_row_info row_info;
895
  string sz_str, val_str;
896
 
897
  if(name != "") begin
898
    m_scope.set_arg(name);
899
    name = m_scope.get();
900
  end
901
 
902
  if(type_name == "") begin
903
    if(radix == UVM_TIME)
904
      type_name ="time";
905
    else if(radix == UVM_STRING)
906
      type_name ="string";
907
    else
908
      type_name ="integral";
909
  end
910
 
911
  sz_str.itoa(size);
912
 
913
  if(radix == UVM_NORADIX)
914
    radix = knobs.default_radix;
915
 
916
  val_str = uvm_integral_to_string (value, size, radix,
917
                                    knobs.get_radix_str(radix));
918
 
919
  row_info.level = m_scope.depth();
920
  row_info.name = adjust_name(name,scope_separator);
921
  row_info.type_name = type_name;
922
  row_info.size = sz_str;
923
  row_info.val = val_str;
924
 
925
  m_rows.push_back(row_info);
926
 
927
endfunction
928
 
929
 
930
// print_time
931
// ----------
932
 
933
function void uvm_printer::print_time (string name,
934
                                       time value,
935
                                       byte scope_separator=".");
936
  print_field_int(name, value, 64, UVM_TIME, scope_separator);
937
endfunction
938
 
939
 
940
// print_string
941
// ------------
942
 
943
function void uvm_printer::print_string (string name,
944
                                         string value,
945
                                         byte scope_separator=".");
946
 
947
  uvm_printer_row_info row_info;
948
 
949
  if(name != "")
950
    m_scope.set_arg(name);
951
 
952
  row_info.level = m_scope.depth();
953
  row_info.name = adjust_name(m_scope.get(),scope_separator);
954
  row_info.type_name = "string";
955
  row_info.size = $sformatf("%0d",value.len());
956
  row_info.val = (value == "" ? "\"\"" : value);
957
 
958
  m_rows.push_back(row_info);
959
 
960
endfunction
961
 
962
 
963
// print_real
964
// ----------
965
 
966
function void uvm_printer::print_real (string name,
967
                                       real value,
968
                                       byte scope_separator=".");
969
 
970
  uvm_printer_row_info row_info;
971
 
972
  if (name != "" && name != "...") begin
973
    m_scope.set_arg(name);
974
    name = m_scope.get();
975
  end
976
 
977
  row_info.level = m_scope.depth();
978
  row_info.name = adjust_name(m_scope.get(),scope_separator);
979
  row_info.type_name = "real";
980
  row_info.size = "64";
981
  row_info.val = $sformatf("%f",value);
982
 
983
  m_rows.push_back(row_info);
984
 
985
endfunction
986
 
987
 
988
// index_string
989
// ------------
990
 
991
function string uvm_printer::index_string(int index, string name="");
992
  index_string.itoa(index);
993
  index_string = { name, "[", index_string, "]" };
994
endfunction
995
 
996
 
997
 
998
//------------------------------------------------------------------------------
999
// Class- uvm_table_printer
1000
//------------------------------------------------------------------------------
1001
 
1002
// new
1003
// ---
1004
 
1005
function uvm_table_printer::new();
1006
  super.new();
1007
endfunction
1008
 
1009
 
1010
// calculate_max_widths
1011
// --------------------
1012
 
1013
function void uvm_table_printer::calculate_max_widths();
1014
   m_max_name=4;
1015
   m_max_type=4;
1016
   m_max_size = 4;
1017
   m_max_value= 5;
1018
   foreach(m_rows[j]) begin
1019
      int name_len;
1020
      uvm_printer_row_info row = m_rows[j];
1021
      name_len = knobs.indent*row.level + row.name.len();
1022
      if (name_len > m_max_name)
1023
        m_max_name = name_len;
1024
      if (row.type_name.len() > m_max_type)
1025
        m_max_type = row.type_name.len();
1026
      if (row.size.len() > m_max_size)
1027
        m_max_size = row.size.len();
1028
      if (row.val.len() > m_max_value)
1029
        m_max_value = row.val.len();
1030
   end
1031
endfunction
1032
 
1033
// emit
1034
// ----
1035
 
1036
function string uvm_table_printer::emit();
1037
 
1038
  string s;
1039
  string user_format;
1040
  static string dash; // = "---------------------------------------------------------------------------------------------------";
1041
  static string space; //= "                                                                                                   ";
1042
  string dashes;
1043
 
1044
  string linefeed = {"\n", knobs.prefix};
1045
 
1046
  calculate_max_widths();
1047
 
1048
   begin
1049
      int q[5];
1050
      int m;
1051
      int qq[$];
1052
 
1053
      q = '{m_max_name,m_max_type,m_max_size,m_max_value,100};
1054
      qq = q.max;
1055
      m = qq[0];
1056
        if(dash.len()
1057
                dash = {m{"-"}};
1058
                space = {m{" "}};
1059
        end
1060
  end
1061
 
1062
  if (knobs.header) begin
1063
    string header;
1064
    user_format = format_header();
1065
    if (user_format == "") begin
1066
      string dash_id, dash_typ, dash_sz;
1067
      string head_id, head_typ, head_sz;
1068
      if (knobs.identifier) begin
1069
        dashes = {dash.substr(1,m_max_name+2)};
1070
        header = {"Name",space.substr(1,m_max_name-2)};
1071
      end
1072
      if (knobs.type_name) begin
1073
        dashes = {dashes, dash.substr(1,m_max_type+2)};
1074
        header = {header, "Type",space.substr(1,m_max_type-2)};
1075
      end
1076
      if (knobs.size) begin
1077
        dashes = {dashes, dash.substr(1,m_max_size+2)};
1078
        header = {header, "Size",space.substr(1,m_max_size-2)};
1079
      end
1080
      dashes = {dashes, dash.substr(1,m_max_value), linefeed};
1081
      header = {header, "Value", space.substr(1,m_max_value-5), linefeed};
1082
 
1083
      s = {s, dashes, header, dashes};
1084
    end
1085
    else begin
1086
      s = {s, user_format, linefeed};
1087
    end
1088
  end
1089
 
1090
  foreach (m_rows[i]) begin
1091
    uvm_printer_row_info row = m_rows[i];
1092
    user_format = format_row(row);
1093
    if (user_format == "") begin
1094
      string row_str;
1095
      if (knobs.identifier)
1096
        row_str = {space.substr(1,row.level * knobs.indent), row.name,
1097
                   space.substr(1,m_max_name-row.name.len()-(row.level*knobs.indent)+2)};
1098
      if (knobs.type_name)
1099
        row_str = {row_str, row.type_name, space.substr(1,m_max_type-row.type_name.len()+2)};
1100
      if (knobs.size)
1101
        row_str = {row_str, row.size, space.substr(1,m_max_size-row.size.len()+2)};
1102
      s = {s, row_str, row.val, space.substr(1,m_max_value-row.val.len()), linefeed};
1103
    end
1104
    else
1105
      s = {s, user_format, linefeed};
1106
  end
1107
 
1108
  if (knobs.footer) begin
1109
    user_format = format_footer();
1110
    if (user_format == "")
1111
      s = {s, dashes};
1112
    else
1113
      s = {s, user_format, linefeed};
1114
  end
1115
 
1116
  emit = {knobs.prefix, s};
1117
  m_rows.delete();
1118
endfunction
1119
 
1120
 
1121
 
1122
//------------------------------------------------------------------------------
1123
// Class- uvm_tree_printer
1124
//------------------------------------------------------------------------------
1125
 
1126
 
1127
// new
1128
// ---
1129
 
1130
function uvm_tree_printer::new();
1131
  super.new();
1132
  knobs.size = 0;
1133
  knobs.type_name = 0;
1134
  knobs.header = 0;
1135
  knobs.footer = 0;
1136
endfunction
1137
 
1138
 
1139
// emit
1140
// ----
1141
 
1142
function string uvm_tree_printer::emit();
1143
 
1144
  string s = knobs.prefix;
1145
  string space= "                                                                                                   ";
1146
  string user_format;
1147
 
1148
  string linefeed = newline == "" || newline == " " ? newline : {newline, knobs.prefix};
1149
 
1150
  // Header
1151
  if (knobs.header) begin
1152
    user_format = format_header();
1153
    if (user_format != "")
1154
      s = {s, user_format, linefeed};
1155
  end
1156
 
1157
  foreach (m_rows[i]) begin
1158
    uvm_printer_row_info row = m_rows[i];
1159
    user_format = format_row(row);
1160
    if (user_format == "") begin
1161
      string indent_str;
1162
      indent_str = space.substr(1,row.level * knobs.indent);
1163
 
1164
      // Name (id)
1165
      if (knobs.identifier) begin
1166
        s = {s,indent_str, row.name};
1167
        if (row.name != "" && row.name != "...")
1168
          s = {s, ": "};
1169
      end
1170
 
1171
      // Type Name
1172
      if (row.val[0] == "@") // is an object w/ knobs.reference on
1173
        s = {s,"(",row.type_name,row.val,") "};
1174
      else
1175
        if (knobs.type_name &&
1176
             (row.type_name != "" ||
1177
              row.type_name != "-" ||
1178
              row.type_name != "..."))
1179
          s = {s,"(",row.type_name,") "};
1180
 
1181
      // Size
1182
      if (knobs.size) begin
1183
        if (row.size != "" || row.size != "-")
1184
            s = {s,"(",row.size,") "};
1185
      end
1186
 
1187
      if (i < m_rows.size()-1) begin
1188
        if (m_rows[i+1].level > row.level) begin
1189
          s = {s, string'(knobs.separator[0]), linefeed};
1190
          continue;
1191
        end
1192
      end
1193
 
1194
      // Value (unconditional)
1195
      s = {s, row.val, " ", linefeed};
1196
 
1197
      // Scope handling...
1198
      if (i <= m_rows.size()-1) begin
1199
        int end_level;
1200
        if (i == m_rows.size()-1)
1201
          end_level = 0;
1202
        else
1203
          end_level = m_rows[i+1].level;
1204
        if (end_level < row.level) begin
1205
          string indent_str;
1206
          for (int l=row.level-1; l >= end_level; l--) begin
1207
            indent_str = space.substr(1,l * knobs.indent);
1208
            s = {s, indent_str, string'(knobs.separator[1]), linefeed};
1209
          end
1210
        end
1211
      end
1212
 
1213
    end
1214
    else
1215
      s = {s, user_format};
1216
  end
1217
 
1218
  // Footer
1219
  if (knobs.footer) begin
1220
    user_format = format_footer();
1221
    if (user_format != "")
1222
      s = {s, user_format, linefeed};
1223
  end
1224
 
1225
  if (newline == "" || newline == " ")
1226
    s = {s, "\n"};
1227
 
1228
  emit = s;
1229
  m_rows.delete();
1230
endfunction
1231
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.