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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [reg/] [uvm_reg_file.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
// -------------------------------------------------------------
3
//    Copyright 2010 Synopsys, Inc.
4
//    Copyright 2010 Mentor Graphics Corporation
5
//    Copyright 2010 Cadence Design Systems, 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 for the specific language governing
20
//    permissions and limitations under the License.
21
// -------------------------------------------------------------
22
//
23
 
24
 
25
//
26
// CLASS: uvm_reg_file
27
// Register file abstraction base class
28
//
29
// A register file is a collection of register files and registers
30
// used to create regular repeated structures.
31
//
32
// Register files are usually instantiated as arrays.
33
//
34
virtual class uvm_reg_file extends uvm_object;
35
 
36
   local uvm_reg_block     parent;
37
   local uvm_reg_file   m_rf;
38
   local string            default_hdl_path = "RTL";
39
   local uvm_object_string_pool #(uvm_queue #(string)) hdl_paths_pool;
40
 
41
 
42
   //----------------------
43
   // Group: Initialization
44
   //----------------------
45
 
46
   //
47
   // Function: new
48
   //
49
   // Create a new instance
50
   //
51
   // Creates an instance of a register file abstraction class
52
   // with the specified name.
53
   //
54
   extern function                  new        (string name="");
55
 
56
   //
57
   // Function: configure
58
   // Configure a register file instance
59
   //
60
   // Specify the parent block and register file of the register file
61
   // instance.
62
   // If the register file is instantiated in a block,
63
   // ~regfile_parent~ is specified as ~null~.
64
   // If the register file is instantiated in a register file,
65
   // ~blk_parent~ must be the block parent of that register file and
66
   // ~regfile_parent~ is specified as that register file.
67
   //
68
   // If the register file corresponds to a hierarchical RTL structure,
69
   // its contribution to the HDL path is specified as the ~hdl_path~.
70
   // Otherwise, the register file does not correspond to a hierarchical RTL
71
   // structure (e.g. it is physically flattened) and does not contribute
72
   // to the hierarchical HDL path of any contained registers.
73
   //
74
   extern function void     configure  (uvm_reg_block blk_parent,
75
                                        uvm_reg_file regfile_parent,
76
                                        string hdl_path = "");
77
 
78
   //---------------------
79
   // Group: Introspection
80
   //---------------------
81
 
82
   //
83
   // Function: get_name
84
   // Get the simple name
85
   //
86
   // Return the simple object name of this register file.
87
   //
88
 
89
   //
90
   // Function: get_full_name
91
   // Get the hierarchical name
92
   //
93
   // Return the hierarchal name of this register file.
94
   // The base of the hierarchical name is the root block.
95
   //
96
   extern virtual function string        get_full_name();
97
 
98
   //
99
   // Function: get_parent
100
   // Get the parent block
101
   //
102
   extern virtual function uvm_reg_block get_parent ();
103
   extern virtual function uvm_reg_block get_block  ();
104
 
105
   //
106
   // Function: get_regfile
107
   // Get the parent register file
108
   //
109
   // Returns ~null~ if this register file is instantiated in a block.
110
   //
111
   extern virtual function uvm_reg_file  get_regfile     ();
112
 
113
 
114
   //----------------
115
   // Group: Backdoor
116
   //----------------
117
 
118
   //
119
   // Function:  clear_hdl_path
120
   // Delete HDL paths
121
   //
122
   // Remove any previously specified HDL path to the register file instance
123
   // for the specified design abstraction.
124
   //
125
   extern function void clear_hdl_path    (string kind = "RTL");
126
 
127
   //
128
   // Function:  add_hdl_path
129
   // Add an HDL path
130
   //
131
   // Add the specified HDL path to the register file instance for the specified
132
   // design abstraction. This method may be called more than once for the
133
   // same design abstraction if the register file is physically duplicated
134
   // in the design abstraction
135
   //
136
   extern function void add_hdl_path      (string path, string kind = "RTL");
137
 
138
   //
139
   // Function:   has_hdl_path
140
   // Check if a HDL path is specified
141
   //
142
   // Returns TRUE if the register file instance has a HDL path defined for the
143
   // specified design abstraction. If no design abstraction is specified,
144
   // uses the default design abstraction specified for the nearest
145
   // enclosing register file or block
146
   //
147
   // If no design abstraction is specified, the default design abstraction
148
   // for this register file is used.
149
   //
150
   extern function bit  has_hdl_path      (string kind = "");
151
 
152
   //
153
   // Function:  get_hdl_path
154
   // Get the incremental HDL path(s)
155
   //
156
   // Returns the HDL path(s) defined for the specified design abstraction
157
   // in the register file instance. If no design abstraction is specified, uses
158
   // the default design abstraction specified for the nearest enclosing
159
   // register file or block.
160
   // Returns only the component of the HDL paths that corresponds to
161
   // the register file, not a full hierarchical path
162
   //
163
   // If no design abstraction is specified, the default design abstraction
164
   // for this register file is used.
165
   //
166
   extern function void get_hdl_path      (ref string paths[$], input string kind = "");
167
 
168
   //
169
   // Function:  get_full_hdl_path
170
   // Get the full hierarchical HDL path(s)
171
   //
172
   // Returns the full hierarchical HDL path(s) defined for the specified
173
   // design abstraction in the register file instance. If no design abstraction
174
   // is specified, uses the default design abstraction specified for the
175
   // nearest enclosing register file or block.
176
   // There may be more than one path returned even
177
   // if only one path was defined for the register file instance, if any of the
178
   // parent components have more than one path defined for the same design
179
   // abstraction
180
   //
181
   // If no design abstraction is specified, the default design abstraction
182
   // for each ancestor register file or block is used to get each
183
   // incremental path.
184
   //
185
   extern function void get_full_hdl_path (ref string paths[$],
186
                                           input string kind = "",
187
                                           input string separator = ".");
188
 
189
   //
190
   // Function:    set_default_hdl_path
191
   // Set the default design abstraction
192
   //
193
   // Set the default design abstraction for this register file instance.
194
   //
195
   extern function void   set_default_hdl_path (string kind);
196
 
197
   //
198
   // Function:  get_default_hdl_path
199
   // Get the default design abstraction
200
   //
201
   // Returns the default design abstraction for this register file instance.
202
   // If a default design abstraction has not been explicitly set for this
203
   // register file instance, returns the default design abstraction for the
204
   // nearest register file or block ancestor.
205
   // Returns "" if no default design abstraction has been specified.
206
   //
207
   extern function string get_default_hdl_path ();
208
 
209
 
210
   extern virtual function void          do_print (uvm_printer printer);
211
   extern virtual function string        convert2string();
212
   extern virtual function uvm_object    clone      ();
213
   extern virtual function void          do_copy    (uvm_object rhs);
214
   extern virtual function bit           do_compare (uvm_object  rhs,
215
                                                     uvm_comparer comparer);
216
   extern virtual function void          do_pack    (uvm_packer packer);
217
   extern virtual function void          do_unpack  (uvm_packer packer);
218
 
219
endclass: uvm_reg_file
220
 
221
 
222
//------------------------------------------------------------------------------
223
// IMPLEMENTATION
224
//------------------------------------------------------------------------------
225
 
226
// new
227
 
228
function uvm_reg_file::new(string name="");
229
   super.new(name);
230
   hdl_paths_pool = new("hdl_paths");
231
endfunction: new
232
 
233
 
234
// configure
235
 
236
function void uvm_reg_file::configure(uvm_reg_block blk_parent, uvm_reg_file regfile_parent, string hdl_path = "");
237
   if (blk_parent == null) begin
238
     `uvm_error("UVM/RFILE/CFG/NOBLK", {"uvm_reg_file::configure() called without a parent block for instance \"", get_name(), "\" of register file type \"", get_type_name(), "\"."})
239
     return;
240
   end
241
 
242
   this.parent = blk_parent;
243
   this.m_rf = regfile_parent;
244
   this.add_hdl_path(hdl_path);
245
endfunction: configure
246
 
247
 
248
// get_block
249
 
250
function uvm_reg_block uvm_reg_file::get_block();
251
   get_block = this.parent;
252
endfunction: get_block
253
 
254
 
255
// get_regfile
256
 
257
function uvm_reg_file uvm_reg_file::get_regfile();
258
   return m_rf;
259
endfunction
260
 
261
 
262
// clear_hdl_path
263
 
264
function void uvm_reg_file::clear_hdl_path(string kind = "RTL");
265
  if (kind == "ALL") begin
266
    hdl_paths_pool = new("hdl_paths");
267
    return;
268
  end
269
 
270
  if (kind == "") begin
271
     if (m_rf != null)
272
        kind = m_rf.get_default_hdl_path();
273
     else
274
        kind = parent.get_default_hdl_path();
275
  end
276
 
277
  if (!hdl_paths_pool.exists(kind)) begin
278
    `uvm_warning("RegModel",{"Unknown HDL Abstraction '",kind,"'"})
279
    return;
280
  end
281
 
282
  hdl_paths_pool.delete(kind);
283
endfunction
284
 
285
 
286
// add_hdl_path
287
 
288
function void uvm_reg_file::add_hdl_path(string path, string kind = "RTL");
289
 
290
  uvm_queue #(string) paths;
291
 
292
  paths = hdl_paths_pool.get(kind);
293
 
294
  paths.push_back(path);
295
 
296
endfunction
297
 
298
 
299
// has_hdl_path
300
 
301
function bit  uvm_reg_file::has_hdl_path(string kind = "");
302
  if (kind == "") begin
303
     if (m_rf != null)
304
        kind = m_rf.get_default_hdl_path();
305
     else
306
        kind = parent.get_default_hdl_path();
307
  end
308
 
309
  return hdl_paths_pool.exists(kind);
310
endfunction
311
 
312
 
313
// get_hdl_path
314
 
315
function void uvm_reg_file::get_hdl_path(ref string paths[$], input string kind = "");
316
 
317
  uvm_queue #(string) hdl_paths;
318
 
319
  if (kind == "") begin
320
     if (m_rf != null)
321
        kind = m_rf.get_default_hdl_path();
322
     else
323
        kind = parent.get_default_hdl_path();
324
  end
325
 
326
  if (!has_hdl_path(kind)) begin
327
    `uvm_error("RegModel",{"Register does not have hdl path defined for abstraction '",kind,"'"})
328
    return;
329
  end
330
 
331
  hdl_paths = hdl_paths_pool.get(kind);
332
 
333
  for (int i=0; i
334
    paths.push_back(hdl_paths.get(i));
335
 
336
endfunction
337
 
338
 
339
// get_full_hdl_path
340
 
341
function void uvm_reg_file::get_full_hdl_path(ref string paths[$],
342
                                              input string kind = "",
343
                                              input string separator = ".");
344
   if (kind == "")
345
      kind = get_default_hdl_path();
346
 
347
   if (!has_hdl_path(kind)) begin
348
      `uvm_error("RegModel",{"Register file does not have hdl path defined for abstraction '",kind,"'"})
349
      return;
350
   end
351
 
352
   paths.delete();
353
 
354
   begin
355
      uvm_queue #(string) hdl_paths = hdl_paths_pool.get(kind);
356
      string parent_paths[$];
357
 
358
      if (m_rf != null)
359
         m_rf.get_full_hdl_path(parent_paths, kind, separator);
360
      else if (parent != null)
361
         parent.get_full_hdl_path(parent_paths, kind, separator);
362
 
363
      for (int i=0; i
364
         string hdl_path = hdl_paths.get(i);
365
 
366
         if (parent_paths.size() == 0) begin
367
            if (hdl_path != "")
368
               paths.push_back(hdl_path);
369
 
370
            continue;
371
         end
372
 
373
         foreach (parent_paths[j])  begin
374
            if (hdl_path == "")
375
               paths.push_back(parent_paths[j]);
376
            else
377
               paths.push_back({ parent_paths[j], separator, hdl_path });
378
         end
379
      end
380
   end
381
 
382
endfunction
383
 
384
 
385
// get_default_hdl_path
386
 
387
function string uvm_reg_file::get_default_hdl_path();
388
  if (default_hdl_path == "") begin
389
     if (m_rf != null)
390
        return m_rf.get_default_hdl_path();
391
     else
392
        return parent.get_default_hdl_path();
393
  end
394
  return default_hdl_path;
395
endfunction
396
 
397
 
398
// set_default_hdl_path
399
 
400
function void uvm_reg_file::set_default_hdl_path(string kind);
401
 
402
  if (kind == "") begin
403
    if (m_rf != null)
404
       kind = m_rf.get_default_hdl_path();
405
    else if (parent == null)
406
       kind = parent.get_default_hdl_path();
407
    else begin
408
      `uvm_error("RegModel",{"Register file has no parent. ",
409
           "Must specify a valid HDL abstraction (kind)"})
410
      return;
411
    end
412
  end
413
 
414
  default_hdl_path = kind;
415
 
416
endfunction
417
 
418
 
419
// get_parent
420
 
421
function uvm_reg_block uvm_reg_file::get_parent();
422
  return get_block();
423
endfunction
424
 
425
 
426
// get_full_name
427
 
428
function string uvm_reg_file::get_full_name();
429
   uvm_reg_block blk;
430
 
431
   get_full_name = this.get_name();
432
 
433
   // Is there a parent register file?
434
   if (m_rf != null)
435
      return {m_rf.get_full_name(), ".", get_full_name};
436
 
437
   // No: then prepend the full name of the parent block (if any)
438
   if (this.parent == null)
439
      return get_full_name;
440
   get_full_name = {this.parent.get_full_name(), ".", get_full_name};
441
endfunction: get_full_name
442
 
443
 
444
//-------------
445
// STANDARD OPS
446
//-------------
447
 
448
// convert2string
449
 
450
function string uvm_reg_file::convert2string();
451
  `uvm_fatal("RegModel","RegModel register files cannot be converted to strings")
452
   return "";
453
endfunction: convert2string
454
 
455
 
456
// do_print
457
 
458
function void uvm_reg_file::do_print (uvm_printer printer);
459
  super.do_print(printer);
460
endfunction
461
 
462
 
463
 
464
// clone
465
 
466
function uvm_object uvm_reg_file::clone();
467
  `uvm_fatal("RegModel","RegModel register files cannot be cloned")
468
  return null;
469
endfunction
470
 
471
// do_copy
472
 
473
function void uvm_reg_file::do_copy(uvm_object rhs);
474
  `uvm_fatal("RegModel","RegModel register files cannot be copied")
475
endfunction
476
 
477
 
478
// do_compare
479
 
480
function bit uvm_reg_file::do_compare (uvm_object  rhs,
481
                                        uvm_comparer comparer);
482
  `uvm_warning("RegModel","RegModel register files cannot be compared")
483
  return 0;
484
endfunction
485
 
486
 
487
// do_pack
488
 
489
function void uvm_reg_file::do_pack (uvm_packer packer);
490
  `uvm_warning("RegModel","RegModel register files cannot be packed")
491
endfunction
492
 
493
 
494
// do_unpack
495
 
496
function void uvm_reg_file::do_unpack (uvm_packer packer);
497
  `uvm_warning("RegModel","RegModel register files cannot be unpacked")
498
endfunction
499
 
500
 

powered by: WebSVN 2.1.0

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