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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_recorder.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
//   Copyright 2013 NVIDIA Corporation
7
//   All Rights Reserved Worldwide
8
//
9
//   Licensed under the Apache License, Version 2.0 (the
10
//   "License"); you may not use this file except in
11
//   compliance with the License.  You may obtain a copy of
12
//   the License at
13
//
14
//       http://www.apache.org/licenses/LICENSE-2.0
15
//
16
//   Unless required by applicable law or agreed to in
17
//   writing, software distributed under the License is
18
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
19
//   CONDITIONS OF ANY KIND, either express or implied.  See
20
//   the License for the specific language governing
21
//   permissions and limitations under the License.
22
//-----------------------------------------------------------------------------
23
 
24
typedef class uvm_report_message;
25
 
26
// File: UVM Recorders
27
//
28
// The uvm_recorder class serves two purposes:
29
//  - Firstly, it is an abstract representation of a record within a
30
//    .
31
//  - Secondly, it is a policy object for recording fields ~into~ that
32
//    record within the ~stream~.
33
//
34
 
35
//------------------------------------------------------------------------------
36
//
37
// CLASS: uvm_recorder
38
//
39
// Abstract class which defines the ~recorder~ API.
40
//
41
//------------------------------------------------------------------------------
42
 
43
virtual class uvm_recorder extends uvm_object;
44
 
45
  // Variable- m_stream_dap
46
  // Data access protected reference to the stream
47
  local uvm_set_before_get_dap#(uvm_tr_stream) m_stream_dap;
48
 
49
  // Variable- m_warn_null_stream
50
  // Used to limit the number of warnings
51
  local bit m_warn_null_stream;
52
 
53
  // Variable- m_is_opened
54
  // Used to indicate recorder is open
55
  local bit m_is_opened;
56
 
57
  // Variable- m_is_closed
58
  // Used to indicate recorder is closed
59
  local bit m_is_closed;
60
 
61
  // !m_is_opened && !m_is_closed == m_is_freed
62
 
63
  // Variable- m_open_time
64
  // Used to store the open_time
65
  local time m_open_time;
66
 
67
  // Variable- m_close_time
68
  // Used to store the close_time
69
  local time m_close_time;
70
 
71
  // Variable- recording_depth
72
  int recording_depth;
73
 
74
  // Variable: default_radix
75
  //
76
  // This is the default radix setting if  is called without
77
  // a radix.
78
 
79
  uvm_radix_enum default_radix = UVM_HEX;
80
 
81
  // Variable: physical
82
  //
83
  // This bit provides a filtering mechanism for fields.
84
  //
85
  // The  and physical settings allow an object to distinguish between
86
  // two different classes of fields.
87
  //
88
  // It is up to you, in the  method, to test the
89
  // setting of this field if you want to use the physical trait as a filter.
90
 
91
  bit physical = 1;
92
 
93
 
94
  // Variable: abstract
95
  //
96
  // This bit provides a filtering mechanism for fields.
97
  //
98
  // The abstract and physical settings allow an object to distinguish between
99
  // two different classes of fields.
100
  //
101
  // It is up to you, in the  method, to test the
102
  // setting of this field if you want to use the abstract trait as a filter.
103
 
104
  bit abstract = 1;
105
 
106
 
107
  // Variable: identifier
108
  //
109
  // This bit is used to specify whether or not an object's reference should be
110
  // recorded when the object is recorded.
111
 
112
  bit identifier = 1;
113
 
114
 
115
  // Variable: recursion_policy
116
  //
117
  // Sets the recursion policy for recording objects.
118
  //
119
  // The default policy is deep (which means to recurse an object).
120
 
121
  uvm_recursion_policy_enum policy = UVM_DEFAULT_POLICY;
122
 
123
   // Variable- m_ids_by_recorder
124
   // An associative array of integers, indexed by uvm_recorders.  This
125
   // provides a unique 'id' or 'handle' for each recorder, which can be
126
   // used to identify the recorder.
127
   //
128
   // By default, neither ~m_ids_by_recorder~ or ~m_recorders_by_id~ are
129
   // used.  Recorders are only placed in the arrays when the user
130
   // attempts to determine the id for a recorder.
131
   local static integer m_ids_by_recorder[uvm_recorder];
132
 
133
 
134
  function new(string name = "uvm_recorder");
135
     super.new(name);
136
     m_stream_dap = new("stream_dap");
137
     m_warn_null_stream = 1;
138
  endfunction
139
 
140
   // Group: Configuration API
141
 
142
   // Function: get_stream
143
   // Returns a reference to the stream which created
144
   // this record.
145
   //
146
   // A warning will be asserted if get_stream is called prior
147
   // to the record being initialized via .
148
   //
149
   function uvm_tr_stream get_stream();
150
      if (!m_stream_dap.try_get(get_stream)) begin
151
         if (m_warn_null_stream == 1)
152
           `uvm_warning("UVM/REC/NO_CFG",
153
                        $sformatf("attempt to retrieve STREAM from '%s' before it was set!",
154
                                  get_name()))
155
         m_warn_null_stream = 0;
156
      end
157
   endfunction : get_stream
158
 
159
   // Group: Transaction Recorder API
160
   //
161
   // Once a recorder has been opened via , the user
162
   // can ~close~ the recorder.
163
   //
164
   // Due to the fact that many database implementations will require crossing
165
   // a language boundary, an additional step of ~freeing~ the recorder is required.
166
   //
167
   // A ~link~ can be established within the database any time between ~open~ and
168
   // ~free~, however it is illegal to establish a link after ~freeing~ the recorder.
169
   //
170
 
171
   // Function: close
172
   // Closes this recorder.
173
   //
174
   // Closing a recorder marks the end of the transaction in the stream.
175
   //
176
   // Parameters:
177
   // close_time - Optional time to record as the closing time of this transaction.
178
   //
179
   // This method will trigger a  call.
180
   function void close(time close_time = 0);
181
      if (close_time == 0)
182
        close_time = $realtime;
183
 
184
      if (!is_open())
185
        return;
186
 
187
      do_close(close_time);
188
 
189
      m_is_opened = 0;
190
      m_is_closed = 1;
191
      m_close_time = close_time;
192
   endfunction : close
193
 
194
   // Function: free
195
   // Frees this recorder
196
   //
197
   // Freeing a recorder indicates that the stream and database can release
198
   // any references to the recorder.
199
   //
200
   // Parameters:
201
   // close_time - Optional time to record as the closing time of this transaction.
202
   //
203
   // If a recorder has not yet been closed (via a call to ), then
204
   //  will automatically be called, and passed the ~close_time~.  If the recorder
205
   // has already been closed, then the ~close_time~ will be ignored.
206
   //
207
   // This method will trigger a  call.
208
   function void free(time close_time = 0);
209
           process p=process::self();
210
           string s;
211
 
212
       uvm_tr_stream stream;
213
 
214
      if (!is_open() && !is_closed())
215
        return;
216
 
217
      if (is_open()) begin
218
         close(close_time);
219
      end
220
 
221
      do_free();
222
 
223
      // Clear out internal state
224
      stream = get_stream();
225
 
226
      m_is_closed = 0;
227
      if(p != null)
228
        s=p.get_randstate();
229
      m_stream_dap = new("stream_dap");
230
      if(p != null)
231
        p.set_randstate(s);
232
      m_warn_null_stream = 1;
233
      if (m_ids_by_recorder.exists(this))
234
        m_free_id(m_ids_by_recorder[this]);
235
 
236
      // Clear out stream state
237
      if (stream != null)
238
        stream.m_free_recorder(this);
239
   endfunction : free
240
 
241
   // Function: is_open
242
   // Returns true if this ~uvm_recorder~ was opened on its stream,
243
   // but has not yet been closed.
244
   //
245
   function bit is_open();
246
      return m_is_opened;
247
   endfunction : is_open
248
 
249
   // Function: get_open_time
250
   // Returns the ~open_time~
251
   //
252
   function time get_open_time();
253
      return m_open_time;
254
   endfunction : get_open_time
255
 
256
   // Function: is_closed
257
   // Returns true if this ~uvm_recorder~ was closed on its stream,
258
   // but has not yet been freed.
259
   //
260
   function bit is_closed();
261
      return m_is_closed;
262
   endfunction : is_closed
263
 
264
   // Function: get_close_time
265
   // Returns the ~close_time~
266
   //
267
   function time get_close_time();
268
      return m_close_time;
269
   endfunction : get_close_time
270
 
271
  // Function- m_do_open
272
  // Initializes the internal state of the recorder.
273
  //
274
  // Parameters:
275
  // stream - The stream which spawned this recorder
276
  //
277
  // This method will trigger a  call.
278
  //
279
  // An error will be asserted if:
280
  // - ~m_do_open~ is called more than once without the
281
  //  recorder being ~freed~ in between.
282
  // - ~stream~ is ~null~
283
  function void m_do_open(uvm_tr_stream stream, time open_time, string type_name);
284
     uvm_tr_stream m_stream;
285
     if (stream == null) begin
286
        `uvm_error("UVM/REC/NULL_STREAM",
287
                   $sformatf("Illegal attempt to set STREAM for '%s' to ''",
288
                             this.get_name()))
289
        return;
290
     end
291
 
292
     if (m_stream_dap.try_get(m_stream)) begin
293
        `uvm_error("UVM/REC/RE_INIT",
294
                   $sformatf("Illegal attempt to re-initialize '%s'",
295
                             this.get_name()))
296
        return;
297
     end
298
 
299
     m_stream_dap.set(stream);
300
     m_open_time = open_time;
301
     m_is_opened = 1;
302
 
303
     do_open(stream, open_time, type_name);
304
  endfunction : m_do_open
305
 
306
   // Group: Handles
307
 
308
 
309
   // Variable- m_recorders_by_id
310
   // A corollary to ~m_ids_by_recorder~, this indexes the recorders by their
311
   // unique ids.
312
   local static uvm_recorder m_recorders_by_id[integer];
313
 
314
   // Variable- m_id
315
   // Static int marking the last assigned id.
316
   local static integer m_id;
317
 
318
   // Function- m_free_id
319
   // Frees the id/recorder link (memory cleanup)
320
   //
321
   static function void m_free_id(integer id);
322
      uvm_recorder recorder;
323
      if ((!$isunknown(id)) && (m_recorders_by_id.exists(id)))
324
        recorder = m_recorders_by_id[id];
325
 
326
      if (recorder != null) begin
327
         m_recorders_by_id.delete(id);
328
         m_ids_by_recorder.delete(recorder);
329
      end
330
   endfunction : m_free_id
331
 
332
   // Function: get_handle
333
   // Returns a unique ID for this recorder.
334
   //
335
   // A value of ~0~ indicates that the recorder has been ~freed~,
336
   // and no longer has a valid ID.
337
   //
338
   function integer get_handle();
339
      if (!is_open() && !is_closed()) begin
340
         return 0;
341
      end
342
      else begin
343
         integer handle = get_inst_id();
344
 
345
         // Check for the weird case where our handle changed.
346
         if (m_ids_by_recorder.exists(this) && m_ids_by_recorder[this] != handle)
347
           m_recorders_by_id.delete(m_ids_by_recorder[this]);
348
 
349
         m_recorders_by_id[handle] = this;
350
         m_ids_by_recorder[this] = handle;
351
 
352
         return handle;
353
      end
354
   endfunction : get_handle
355
 
356
   // Function: get_recorder_from_handle
357
   // Static accessor, returns a recorder reference for a given unique id.
358
   //
359
   // If no recorder exists with the given ~id~, or if the
360
   // recorder with that ~id~ has been freed, then ~null~ is
361
   // returned.
362
   //
363
   // This method can be used to access the recorder associated with a
364
   // call to  or .
365
   //
366
   // | integer handle = tr.begin_tr();
367
   // | uvm_recorder recorder = uvm_recorder::get_recorder_from_handle(handle);
368
   // | if (recorder != null) begin
369
   // |   recorder.record_string("begin_msg", "Started recording transaction!");
370
   // | end
371
   //
372
   static function uvm_recorder get_recorder_from_handle(integer id);
373
      if (id == 0)
374
        return null;
375
 
376
      if (($isunknown(id)) || (!m_recorders_by_id.exists(id)))
377
        return null;
378
 
379
      return m_recorders_by_id[id];
380
   endfunction : get_recorder_from_handle
381
 
382
   // Group: Attribute Recording
383
 
384
   // Function: record_field
385
   // Records an integral field (less than or equal to 4096 bits).
386
   //
387
   // Parameters:
388
   // name - Name of the field
389
   // value - Value of the field to record.
390
   // size - Number of bits of the field which apply (Usually obtained via $bits).
391
   // radix - The  to use.
392
   //
393
   // This method will trigger a  call.
394
   function void record_field(string name,
395
                              uvm_bitstream_t value,
396
                              int size,
397
                              uvm_radix_enum radix=UVM_NORADIX);
398
      if (get_stream() == null) begin
399
         return;
400
      end
401
      do_record_field(name, value, size, radix);
402
   endfunction : record_field
403
 
404
   // Function: record_field_int
405
   // Records an integral field (less than or equal to 64 bits).
406
   //
407
   // This optimized version of  is useful for sizes up
408
   // to 64 bits.
409
   //
410
   // Parameters:
411
   // name - Name of the field
412
   // value - Value of the field to record
413
   // size - Number of bits of the wfield which apply (Usually obtained via $bits).
414
   // radix - The  to use.
415
   //
416
   // This method will trigger a  call.
417
   function void record_field_int(string name,
418
                                  uvm_integral_t value,
419
                                  int size,
420
                                  uvm_radix_enum radix=UVM_NORADIX);
421
        if (get_stream() == null) begin
422
         return;
423
      end
424
      do_record_field_int(name, value, size, radix);
425
   endfunction : record_field_int
426
 
427
   // Function: record_field_real
428
   // Records a real field.
429
   //
430
   // Parameters:
431
   // name - Name of the field
432
   // value - Value of the field to record
433
   //
434
   // This method will trigger a  call.
435
   function void record_field_real(string name,
436
                                   real value);
437
      if (get_stream() == null) begin
438
         return;
439
      end
440
      do_record_field_real(name, value);
441
   endfunction : record_field_real
442
 
443
   // Function: record_object
444
   // Records an object field.
445
   //
446
   // Parameters:
447
   // name - Name of the field
448
   // value - Object to record
449
   //
450
   // The implementation must use the  and  to
451
   // determine exactly what should be recorded.
452
   function void record_object(string name,
453
                               uvm_object value);
454
      if (get_stream() == null) begin
455
         return;
456
      end
457
 
458
      do_record_object(name, value);
459
   endfunction : record_object
460
 
461
   // Function: record_string
462
   // Records a string field.
463
   //
464
   // Parameters:
465
   // name - Name of the field
466
   // value - Value of the field
467
   //
468
   function void record_string(string name,
469
                               string value);
470
      if (get_stream() == null) begin
471
         return;
472
      end
473
 
474
      do_record_string(name, value);
475
   endfunction : record_string
476
 
477
   // Function: record_time
478
   // Records a time field.
479
   //
480
   // Parameters:
481
   // name - Name of the field
482
   // value - Value of the field
483
   //
484
   function void record_time(string name,
485
                             time value);
486
      if (get_stream() == null) begin
487
         return;
488
      end
489
 
490
      do_record_time(name, value);
491
   endfunction : record_time
492
 
493
   // Function: record_generic
494
   // Records a name/value pair, where ~value~ has been converted to a string.
495
   //
496
   // For example:
497
   //| recorder.record_generic("myvar","var_type", $sformatf("%0d",myvar), 32);
498
   //
499
   // Parameters:
500
   // name - Name of the field
501
   // value - Value of the field
502
   // type_name - ~optional~ Type name of the field
503
   function void record_generic(string name,
504
                                string value,
505
                                string type_name="");
506
      if (get_stream() == null) begin
507
         return;
508
      end
509
 
510
      do_record_generic(name, value, type_name);
511
   endfunction : record_generic
512
 
513
  // Function: use_record_attribute
514
  //
515
  // Indicates that this recorder does (or does not) support usage of
516
  // the <`uvm_record_attribute> macro.
517
  //
518
  // The default return value is ~0~ (not supported), developers can
519
  // optionally extend ~uvm_recorder~ and set the value to ~1~ if they
520
  // support the <`uvm_record_attribute> macro.
521
  virtual function bit use_record_attribute();
522
     return 0;
523
  endfunction : use_record_attribute
524
 
525
   // Function: get_record_attribute_handle
526
   // Provides a tool-specific handle which is compatible with <`uvm_record_attribute>.
527
   //
528
   // By default, this method will return the same value as ,
529
   // however tool vendors can override this method to provide tool-specific handles
530
   // which will be passed to the <`uvm_record_attribute> macro.
531
   //
532
   virtual function integer get_record_attribute_handle();
533
      return get_handle();
534
   endfunction : get_record_attribute_handle
535
 
536
   // Group: Implementation Agnostic API
537
 
538
   // Function: do_open
539
   // Callback triggered via .
540
   //
541
   // The ~do_open~ callback can be used to initialize any internal
542
   // state within the recorder, as well as providing a location to
543
   // record any initial information.
544
   protected virtual function void do_open(uvm_tr_stream stream,
545
                                             time open_time,
546
                                             string type_name);
547
   endfunction : do_open
548
 
549
   // Function: do_close
550
   // Callback triggered via .
551
   //
552
   // The ~do_close~ callback can be used to set internal state
553
   // within the recorder, as well as providing a location to
554
   // record any closing information.
555
   protected virtual function void do_close(time close_time);
556
   endfunction : do_close
557
 
558
   // Function: do_free
559
   // Callback triggered via .
560
   //
561
   // The ~do_free~ callback can be used to release the internal
562
   // state within the recorder, as well as providing a location
563
   // to record any "freeing" information.
564
   protected virtual function void do_free();
565
   endfunction : do_free
566
 
567
   // Function: do_record_field
568
   // Records an integral field (less than or equal to 4096 bits).
569
   //
570
   // ~Mandatory~ Backend implementation of 
571
   pure virtual protected function void do_record_field(string name,
572
                                                        uvm_bitstream_t value,
573
                                                        int size,
574
                                                        uvm_radix_enum radix);
575
 
576
   // Function: do_record_field_int
577
   // Records an integral field (less than or equal to 64 bits).
578
   //
579
   // ~Mandatory~ Backend implementation of 
580
   pure virtual protected function void do_record_field_int(string name,
581
                                                            uvm_integral_t value,
582
                                                            int          size,
583
                                                            uvm_radix_enum radix);
584
 
585
   // Function: do_record_field_real
586
   // Records a real field.
587
   //
588
   // ~Mandatory~ Backend implementation of 
589
   pure virtual protected function void do_record_field_real(string name,
590
                                                             real value);
591
 
592
   // Function: do_record_object
593
   // Records an object field.
594
   //
595
   // ~Mandatory~ Backend implementation of 
596
   pure virtual protected function void do_record_object(string name,
597
                                                         uvm_object value);
598
 
599
   // Function: do_record_string
600
   // Records a string field.
601
   //
602
   // ~Mandatory~ Backend implementation of 
603
   pure virtual protected function void do_record_string(string name,
604
                                                         string value);
605
 
606
   // Function: do_record_time
607
   // Records a time field.
608
   //
609
   // ~Mandatory~ Backend implementation of 
610
   pure virtual protected function void do_record_time(string name,
611
                                                       time value);
612
 
613
   // Function: do_record_generic
614
   // Records a name/value pair, where ~value~ has been converted to a string.
615
   //
616
   // ~Mandatory~ Backend implementation of 
617
   pure virtual protected function void do_record_generic(string name,
618
                                                          string value,
619
                                                          string type_name);
620
 
621
 
622
   // The following code is primarily for backwards compat. purposes.  "Transaction
623
   // Handles" are useful when connecting to a backend, but when passing the information
624
   // back and forth within simulation, it is safer to user the ~recorder~ itself
625
   // as a reference to the transaction within the database.
626
 
627
   //------------------------------
628
   // Group- Vendor-Independent API
629
   //------------------------------
630
 
631
 
632
  // UVM provides only a text-based default implementation.
633
  // Vendors provide subtype implementations and overwrite the
634
  //  handle.
635
 
636
 
637
  // Function- open_file
638
  //
639
  // Opens the file in the  property and assigns to the
640
  // file descriptor .
641
  //
642
  virtual function bit open_file();
643
     return 0;
644
  endfunction
645
 
646
  // Function- create_stream
647
  //
648
  //
649
  virtual function integer create_stream (string name,
650
                                          string t,
651
                                          string scope);
652
     return -1;
653
  endfunction
654
 
655
 
656
  // Function- m_set_attribute
657
  //
658
  //
659
  virtual function void m_set_attribute (integer txh,
660
                                 string nm,
661
                                 string value);
662
  endfunction
663
 
664
 
665
  // Function- set_attribute
666
  //
667
  virtual function void set_attribute (integer txh,
668
                               string nm,
669
                               logic [1023:0] value,
670
                               uvm_radix_enum radix,
671
                               integer numbits=1024);
672
  endfunction
673
 
674
 
675
  // Function- check_handle_kind
676
  //
677
  //
678
  virtual function integer check_handle_kind (string htype, integer handle);
679
     return 0;
680
  endfunction
681
 
682
 
683
  // Function- begin_tr
684
  //
685
  //
686
  virtual function integer begin_tr(string txtype,
687
                                     integer stream,
688
                                     string nm,
689
                                     string label="",
690
                                     string desc="",
691
                                     time begin_time=0);
692
    return -1;
693
  endfunction
694
 
695
 
696
  // Function- end_tr
697
  //
698
  //
699
  virtual function void end_tr (integer handle, time end_time=0);
700
  endfunction
701
 
702
 
703
  // Function- link_tr
704
  //
705
  //
706
  virtual function void link_tr(integer h1,
707
                                 integer h2,
708
                                 string relation="");
709
  endfunction
710
 
711
 
712
 
713
  // Function- free_tr
714
  //
715
  //
716
  virtual function void free_tr(integer handle);
717
  endfunction
718
 
719
endclass // uvm_recorder
720
 
721
//------------------------------------------------------------------------------
722
//
723
// CLASS: uvm_text_recorder
724
//
725
// The ~uvm_text_recorder~ is the default recorder implementation for the
726
// .
727
//
728
 
729
class uvm_text_recorder extends uvm_recorder;
730
 
731
   `uvm_object_utils(uvm_text_recorder)
732
 
733
   // Variable- m_text_db
734
   //
735
   // Reference to the text database backend
736
   uvm_text_tr_database m_text_db;
737
 
738
   // Variable- scope
739
   // Imeplementation detail
740
   uvm_scope_stack scope = new;
741
 
742
   // Function: new
743
   // Constructor
744
   //
745
   // Parameters:
746
   // name - Instance name
747
   function new(string name="unnamed-uvm_text_recorder");
748
      super.new(name);
749
   endfunction : new
750
 
751
   // Group: Implementation Agnostic API
752
 
753
   // Function: do_open
754
   // Callback triggered via .
755
   //
756
   // Text-backend specific implementation.
757
   protected virtual function void do_open(uvm_tr_stream stream,
758
                                             time open_time,
759
                                             string type_name);
760
      $cast(m_text_db, stream.get_db());
761
      if (m_text_db.open_db())
762
        $fdisplay(m_text_db.m_file,
763
                  "    OPEN_RECORDER @%0t {TXH:%0d STREAM:%0d NAME:%s TIME:%0t TYPE=\"%0s\"}",
764
                  $realtime,
765
                  this.get_handle(),
766
                  stream.get_handle(),
767
                  this.get_name(),
768
                  open_time,
769
                  type_name);
770
   endfunction : do_open
771
 
772
   // Function: do_close
773
   // Callback triggered via .
774
   //
775
   // Text-backend specific implementation.
776
   protected virtual function void do_close(time close_time);
777
      if (m_text_db.open_db()) begin
778
         $fdisplay(m_text_db.m_file,
779
                   "    CLOSE_RECORDER @%0t {TXH:%0d TIME=%0t}",
780
                   $realtime,
781
                   this.get_handle(),
782
                   close_time);
783
 
784
      end
785
   endfunction : do_close
786
 
787
   // Function: do_free
788
   // Callback triggered via .
789
   //
790
   // Text-backend specific implementation.
791
   protected virtual function void do_free();
792
      if (m_text_db.open_db()) begin
793
         $fdisplay(m_text_db.m_file,
794
                   "    FREE_RECORDER @%0t {TXH:%0d}",
795
                   $realtime,
796
                   this.get_handle());
797
      end
798
      m_text_db = null;
799
   endfunction : do_free
800
 
801
   // Function: do_record_field
802
   // Records an integral field (less than or equal to 4096 bits).
803
   //
804
   // Text-backend specific implementation.
805
   protected virtual function void do_record_field(string name,
806
                                                   uvm_bitstream_t value,
807
                                                   int size,
808
                                                   uvm_radix_enum radix);
809
      scope.set_arg(name);
810
      if (!radix)
811
        radix = default_radix;
812
 
813
      write_attribute(scope.get(),
814
                      value,
815
                      radix,
816
                      size);
817
 
818
   endfunction : do_record_field
819
 
820
 
821
   // Function: do_record_field_int
822
   // Records an integral field (less than or equal to 64 bits).
823
   //
824
   // Text-backend specific implementation.
825
   protected virtual function void do_record_field_int(string name,
826
                                                       uvm_integral_t value,
827
                                                       int          size,
828
                                                       uvm_radix_enum radix);
829
      scope.set_arg(name);
830
      if (!radix)
831
        radix = default_radix;
832
 
833
      write_attribute_int(scope.get(),
834
                          value,
835
                          radix,
836
                          size);
837
 
838
   endfunction : do_record_field_int
839
 
840
 
841
   // Function: do_record_field_real
842
   // Record a real field.
843
   //
844
   // Text-backened specific implementation.
845
   protected virtual function void do_record_field_real(string name,
846
                                                        real value);
847
      bit [63:0] ival = $realtobits(value);
848
      scope.set_arg(name);
849
 
850
      write_attribute_int(scope.get(),
851
                          ival,
852
                          UVM_REAL,
853
                          64);
854
   endfunction : do_record_field_real
855
 
856
   // Function: do_record_object
857
   // Record an object field.
858
   //
859
   // Text-backend specific implementation.
860
   //
861
   // The method uses ~identifier~ to determine whether or not to
862
   // record the object instance id, and ~recursion_policy~ to
863
   // determine whether or not to recurse into the object.
864
   protected virtual function void do_record_object(string name,
865
                                                    uvm_object value);
866
      int            v;
867
      string         str;
868
 
869
      if(identifier) begin
870
         if(value != null) begin
871
            $swrite(str, "%0d", value.get_inst_id());
872
            v = str.atoi();
873
         end
874
         scope.set_arg(name);
875
         write_attribute_int(scope.get(),
876
                             v,
877
                             UVM_DEC,
878
                             32);
879
      end
880
 
881
      if(policy != UVM_REFERENCE) begin
882
         if(value!=null) begin
883
            if(value.__m_uvm_status_container.cycle_check.exists(value)) return;
884
            value.__m_uvm_status_container.cycle_check[value] = 1;
885
            scope.down(name);
886
            value.record(this);
887
            scope.up();
888
            value.__m_uvm_status_container.cycle_check.delete(value);
889
         end
890
      end
891
   endfunction : do_record_object
892
 
893
   // Function: do_record_string
894
   // Records a string field.
895
   //
896
   // Text-backend specific implementation.
897
   protected virtual function void do_record_string(string name,
898
                                                    string value);
899
      scope.set_arg(name);
900
      if (m_text_db.open_db()) begin
901
         $fdisplay(m_text_db.m_file,
902
                   "      SET_ATTR @%0t {TXH:%0d NAME:%s VALUE:%s   RADIX:%s BITS=%0d}",
903
                   $realtime,
904
                   this.get_handle(),
905
                   scope.get(),
906
                   value,
907
                   "UVM_STRING",
908
                   8+value.len());
909
      end
910
   endfunction : do_record_string
911
 
912
   // Function: do_record_time
913
   // Records a time field.
914
   //
915
   // Text-backend specific implementation.
916
   protected virtual function void do_record_time(string name,
917
                                                    time value);
918
      scope.set_arg(name);
919
      write_attribute_int(scope.get(),
920
                          value,
921
                          UVM_TIME,
922
                          64);
923
   endfunction : do_record_time
924
 
925
   // Function: do_record_generic
926
   // Records a name/value pair, where ~value~ has been converted to a string.
927
   //
928
   // Text-backend specific implementation.
929
   protected virtual function void do_record_generic(string name,
930
                                                     string value,
931
                                                     string type_name);
932
      scope.set_arg(name);
933
      write_attribute(scope.get(),
934
                      uvm_string_to_bits(value),
935
                      UVM_STRING,
936
                      8+value.len());
937
   endfunction : do_record_generic
938
 
939
   // Group: Implementation Specific API
940
 
941
   // Function: write_attribute
942
   // Outputs an integral attribute to the textual log
943
   //
944
   // Parameters:
945
   // nm - Name of the attribute
946
   // value - Value
947
   // radix - Radix of the output
948
   // numbits - number of valid bits
949
   function void write_attribute(string nm,
950
                                 uvm_bitstream_t value,
951
                                 uvm_radix_enum radix,
952
                                 integer numbits=$bits(uvm_bitstream_t));
953
      if (m_text_db.open_db()) begin
954
         $fdisplay(m_text_db.m_file,
955
                   "      SET_ATTR @%0t {TXH:%0d NAME:%s VALUE:%s   RADIX:%s BITS=%0d}",
956
                   $realtime,
957
                   this.get_handle(),
958
                   nm,
959
                   uvm_bitstream_to_string(value, numbits, radix),
960
                    radix.name(),
961
                   numbits);
962
      end
963
   endfunction : write_attribute
964
 
965
   // Function: write_attribute_int
966
   // Outputs an integral attribute to the textual log
967
   //
968
   // Parameters:
969
   // nm - Name of the attribute
970
   // value - Value
971
   // radix - Radix of the output
972
   // numbits - number of valid bits
973
   function void write_attribute_int(string  nm,
974
                                     uvm_integral_t value,
975
                                     uvm_radix_enum radix,
976
                                     integer numbits=$bits(uvm_bitstream_t));
977
      if (m_text_db.open_db()) begin
978
         $fdisplay(m_text_db.m_file,
979
                   "      SET_ATTR @%0t {TXH:%0d NAME:%s VALUE:%s   RADIX:%s BITS=%0d}",
980
                   $realtime,
981
                   this.get_handle(),
982
                   nm,
983
                   uvm_integral_to_string(value, numbits, radix),
984
                   radix.name(),
985
                   numbits);
986
      end
987
   endfunction : write_attribute_int
988
 
989
   /// LEFT FOR BACKWARDS COMPAT ONLY!!!!!!!!
990
 
991
   //------------------------------
992
   // Group- Vendor-Independent API
993
   //------------------------------
994
 
995
 
996
  // UVM provides only a text-based default implementation.
997
  // Vendors provide subtype implementations and overwrite the
998
  //  handle.
999
 
1000
   string                                                   filename;
1001
   bit                                                      filename_set;
1002
 
1003
  // Function- open_file
1004
  //
1005
  // Opens the file in the  property and assigns to the
1006
  // file descriptor .
1007
  //
1008
  virtual function bit open_file();
1009
     if (!filename_set) begin
1010
        m_text_db.set_file_name(filename);
1011
     end
1012
     return m_text_db.open_db();
1013
  endfunction
1014
 
1015
 
1016
  // Function- create_stream
1017
  //
1018
  //
1019
  virtual function integer create_stream (string name,
1020
                                          string t,
1021
                                          string scope);
1022
     uvm_text_tr_stream stream;
1023
     if (open_file()) begin
1024
        $cast(stream,m_text_db.open_stream(name, scope, t));
1025
        return stream.get_handle();
1026
     end
1027
     return 0;
1028
  endfunction
1029
 
1030
 
1031
  // Function- m_set_attribute
1032
  //
1033
  //
1034
  virtual function void m_set_attribute (integer txh,
1035
                                 string nm,
1036
                                 string value);
1037
     if (open_file()) begin
1038
        UVM_FILE file = m_text_db.m_file;
1039
        $fdisplay(file,"      SET_ATTR @%0t {TXH:%0d NAME:%s VALUE:%s}", $realtime,txh,nm,value);
1040
     end
1041
  endfunction
1042
 
1043
 
1044
  // Function- set_attribute
1045
  //
1046
  //
1047
  virtual function void set_attribute (integer txh,
1048
                               string nm,
1049
                               logic [1023:0] value,
1050
                               uvm_radix_enum radix,
1051
                               integer numbits=1024);
1052
     if (open_file()) begin
1053
        UVM_FILE file = m_text_db.m_file;
1054
         $fdisplay(file,
1055
                   "      SET_ATTR @%0t {TXH:%0d NAME:%s VALUE:%s   RADIX:%s BITS=%0d}",
1056
                   $realtime,
1057
                   txh,
1058
                   nm,
1059
                   uvm_bitstream_to_string(value, numbits, radix),
1060
                   radix.name(),
1061
                   numbits);
1062
 
1063
     end
1064
  endfunction
1065
 
1066
 
1067
  // Function- check_handle_kind
1068
  //
1069
  //
1070
  virtual function integer check_handle_kind (string htype, integer handle);
1071
     return ((uvm_recorder::get_recorder_from_handle(handle) != null) ||
1072
             (uvm_tr_stream::get_stream_from_handle(handle) != null));
1073
  endfunction
1074
 
1075
 
1076
  // Function- begin_tr
1077
  //
1078
  //
1079
  virtual function integer begin_tr(string txtype,
1080
                                     integer stream,
1081
                                     string nm,
1082
                                     string label="",
1083
                                     string desc="",
1084
                                     time begin_time=0);
1085
     if (open_file()) begin
1086
        uvm_tr_stream stream_obj = uvm_tr_stream::get_stream_from_handle(stream);
1087
        uvm_recorder recorder;
1088
 
1089
        if (stream_obj == null)
1090
          return -1;
1091
 
1092
        recorder = stream_obj.open_recorder(nm, begin_time, txtype);
1093
 
1094
        return recorder.get_handle();
1095
     end
1096
     return -1;
1097
  endfunction
1098
 
1099
 
1100
  // Function- end_tr
1101
  //
1102
  //
1103
  virtual function void end_tr (integer handle, time end_time=0);
1104
     if (open_file()) begin
1105
        uvm_recorder record = uvm_recorder::get_recorder_from_handle(handle);
1106
        if (record != null) begin
1107
           record.close(end_time);
1108
        end
1109
     end
1110
  endfunction
1111
 
1112
 
1113
  // Function- link_tr
1114
  //
1115
  //
1116
  virtual function void link_tr(integer h1,
1117
                                 integer h2,
1118
                                 string relation="");
1119
    if (open_file())
1120
      $fdisplay(m_text_db.m_file,"  LINK @%0t {TXH1:%0d TXH2:%0d RELATION=%0s}", $realtime,h1,h2,relation);
1121
  endfunction
1122
 
1123
 
1124
 
1125
  // Function- free_tr
1126
  //
1127
  //
1128
  virtual function void free_tr(integer handle);
1129
     if (open_file()) begin
1130
        uvm_recorder record = uvm_recorder::get_recorder_from_handle(handle);
1131
        if (record != null) begin
1132
           record.free();
1133
        end
1134
     end
1135
  endfunction // free_tr
1136
 
1137
endclass : uvm_text_recorder
1138
 
1139
 
1140
 

powered by: WebSVN 2.1.0

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