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

Subversion Repositories uart2bus_testbench

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//----------------------------------------------------------------------
2
//   Copyright 2011 Cypress Semiconductor
3
//   Copyright 2010 Mentor Graphics Corporation
4
//   All Rights Reserved Worldwide
5
//
6
//   Licensed under the Apache License, Version 2.0 (the
7
//   "License"); you may not use this file except in
8
//   compliance with the License.  You may obtain a copy of
9
//   the License at
10
//
11
//       http://www.apache.org/licenses/LICENSE-2.0
12
//
13
//   Unless required by applicable law or agreed to in
14
//   writing, software distributed under the License is
15
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
16
//   CONDITIONS OF ANY KIND, either express or implied.  See
17
//   the License for the specific language governing
18
//   permissions and limitations under the License.
19
//----------------------------------------------------------------------
20
 
21
//----------------------------------------------------------------------
22
// Title: UVM Resource Database
23
//
24
// Topic: Intro
25
//
26
// The  class provides a convenience interface for
27
// the resources facility.  In many cases basic operations such as
28
// creating and setting a resource or getting a resource could take
29
// multiple lines of code using the interfaces in  or
30
// .  The convenience layer in 
31
// reduces many of those operations to a single line of code.
32
//
33
// If the run-time ~+UVM_RESOURCE_DB_TRACE~ command line option is
34
// specified, all resource DB accesses (read and write) are displayed.
35
//----------------------------------------------------------------------
36
 
37
typedef class uvm_resource_db_options;
38
typedef class uvm_cmdline_processor;
39
 
40
//----------------------------------------------------------------------
41
// class: uvm_resource_db
42
//
43
// All of the functions in uvm_resource_db#(T) are static, so they
44
// must be called using the :: operator.  For example:
45
//
46
//|  uvm_resource_db#(int)::set("A", "*", 17, this);
47
//
48
// The parameter value "int" identifies the resource type as
49
// uvm_resource#(int).  Thus, the type of the object in the resource
50
// container is int. This maintains the type-safety characteristics of
51
// resource operations.
52
//
53
//----------------------------------------------------------------------
54
class uvm_resource_db #(type T=uvm_object);
55
 
56
  typedef uvm_resource #(T) rsrc_t;
57
 
58
  protected function new();
59
  endfunction
60
 
61
  // function: get_by_type
62
  //
63
  // Get a resource by type.  The type is specified in the db
64
  // class parameter so the only argument to this function is the
65
  // ~scope~.
66
 
67
  static function rsrc_t get_by_type(string scope);
68
    return rsrc_t::get_by_type(scope, rsrc_t::get_type());
69
  endfunction
70
 
71
  // function: get_by_name
72
  //
73
  // Imports a resource by ~name~.  The first argument is the current
74
  // ~scope~ of the resource to be retrieved and the second argument is
75
  // the ~name~. The ~rpterr~ flag indicates whether or not to generate
76
  // a warning if no matching resource is found.
77
 
78
  static function rsrc_t get_by_name(string scope,
79
                                     string name,
80
                                     bit rpterr=1);
81
 
82
    return rsrc_t::get_by_name(scope, name, rpterr);
83
  endfunction
84
 
85
  // function: set_default
86
  //
87
  // add a new item into the resources database.  The item will not be
88
  // written to so it will have its default value. The resource is
89
  // created using ~name~ and ~scope~ as the lookup parameters.
90
 
91
  static function rsrc_t set_default(string scope, string name);
92
 
93
    rsrc_t r;
94
 
95
    r = new(name, scope);
96
    r.set();
97
    return r;
98
  endfunction
99
 
100
  // function- show_msg
101
 
102
  // internal helper function to print resource accesses
103
 
104
  protected static function void m_show_msg(
105
          input string id,
106
          input string rtype,
107
          input string action,
108
          input string scope,
109
          input string name,
110
          input uvm_object accessor,
111
          input rsrc_t rsrc);
112
 
113
          T foo;
114
          string msg=`uvm_typename(foo);
115
 
116
          $sformat(msg, "%s '%s%s' (type %s) %s by %s = %s",
117
              rtype,scope, name=="" ? "" : {".",name}, msg,action,
118
              (accessor != null) ? accessor.get_full_name() : "",
119
              rsrc==null?"null (failed lookup)":rsrc.convert2string());
120
 
121
          `uvm_info(id, msg, UVM_LOW)
122
  endfunction
123
 
124
  // function: set
125
  //
126
  // Create a new resource, write a ~val~ to it, and set it into the
127
  // database using ~name~ and ~scope~ as the lookup parameters. The
128
  // ~accessor~ is used for auditing.
129
  static function void set(input string scope, input string name,
130
                           T val, input uvm_object accessor = null);
131
 
132
    rsrc_t rsrc = new(name, scope);
133
    rsrc.write(val, accessor);
134
    rsrc.set();
135
 
136
    if(uvm_resource_db_options::is_tracing())
137
      m_show_msg("RSRCDB/SET", "Resource","set", scope, name, accessor, rsrc);
138
  endfunction
139
 
140
  // function: set_anonymous
141
  //
142
  // Create a new resource, write a ~val~ to it, and set it into the
143
  // database.  The resource has no name and therefore will not be
144
  // entered into the name map. But is does have a ~scope~ for lookup
145
  // purposes. The ~accessor~ is used for auditing.
146
  static function void set_anonymous(input string scope,
147
                                     T val, input uvm_object accessor = null);
148
 
149
    rsrc_t rsrc = new("", scope);
150
    rsrc.write(val, accessor);
151
    rsrc.set();
152
 
153
    if(uvm_resource_db_options::is_tracing())
154
      m_show_msg("RSRCDB/SETANON","Resource", "set", scope, "", accessor, rsrc);
155
  endfunction
156
 
157
  // function set_override
158
  //
159
  // Create a new resource, write ~val~ to it, and set it into the
160
  // database.  Set it at the beginning of the queue in the type map and
161
  // the name map so that it will be (currently) the highest priority
162
  // resource with the specified name and type.
163
 
164
  static function void set_override(input string scope, input string name,
165
                                    T val, uvm_object accessor = null);
166
    rsrc_t rsrc = new(name, scope);
167
    rsrc.write(val, accessor);
168
    rsrc.set_override();
169
 
170
    if(uvm_resource_db_options::is_tracing())
171
      m_show_msg("RSRCDB/SETOVRD", "Resource","set", scope, name, accessor, rsrc);
172
  endfunction
173
 
174
 
175
 
176
  // function set_override_type
177
  //
178
  // Create a new resource, write ~val~ to it, and set it into the
179
  // database.  Set it at the beginning of the queue in the type map so
180
  // that it will be (currently) the highest priority resource with the
181
  // specified type. It will be normal priority (i.e. at the end of the
182
  // queue) in the name map.
183
 
184
  static function void set_override_type(input string scope, input string name,
185
                                         T val, uvm_object accessor = null);
186
    rsrc_t rsrc = new(name, scope);
187
    rsrc.write(val, accessor);
188
    rsrc.set_override(uvm_resource_types::TYPE_OVERRIDE);
189
 
190
    if(uvm_resource_db_options::is_tracing())
191
      m_show_msg("RSRCDB/SETOVRDTYP","Resource", "set", scope, name, accessor, rsrc);
192
  endfunction
193
 
194
  // function set_override_name
195
  //
196
  // Create a new resource, write ~val~ to it, and set it into the
197
  // database.  Set it at the beginning of the queue in the name map so
198
  // that it will be (currently) the highest priority resource with the
199
  // specified name. It will be normal priority (i.e. at the end of the
200
  // queue) in the type map.
201
 
202
  static function void set_override_name(input string scope, input string name,
203
                                  T val, uvm_object accessor = null);
204
    rsrc_t rsrc = new(name, scope);
205
    rsrc.write(val, accessor);
206
    rsrc.set_override(uvm_resource_types::NAME_OVERRIDE);
207
 
208
    if(uvm_resource_db_options::is_tracing())
209
      m_show_msg("RSRCDB/SETOVRDNAM","Resource", "set", scope, name, accessor, rsrc);
210
  endfunction
211
 
212
  // function: read_by_name
213
  //
214
  // locate a resource by ~name~ and ~scope~ and read its value. The value
215
  // is returned through the output argument ~val~.  The return value is a bit
216
  // that indicates whether or not the read was successful. The ~accessor~
217
  // is used for auditing.
218
  static function bit read_by_name(input string scope,
219
                                   input string name,
220
                                   inout T val, input uvm_object accessor = null);
221
 
222
    rsrc_t rsrc = get_by_name(scope, name);
223
 
224
    if(uvm_resource_db_options::is_tracing())
225
      m_show_msg("RSRCDB/RDBYNAM","Resource", "read", scope, name, accessor, rsrc);
226
 
227
    if(rsrc == null)
228
      return 0;
229
 
230
    val = rsrc.read(accessor);
231
 
232
    return 1;
233
 
234
  endfunction
235
 
236
  // function: read_by_type
237
  //
238
  // Read a value by type.  The value is returned through the output
239
  // argument ~val~.  The ~scope~ is used for the lookup. The return
240
  // value is a bit that indicates whether or not the read is successful.
241
  // The ~accessor~ is used for auditing.
242
  static function bit read_by_type(input string scope,
243
                                   inout T val,
244
                                   input uvm_object accessor = null);
245
 
246
    rsrc_t rsrc = get_by_type(scope);
247
 
248
    if(uvm_resource_db_options::is_tracing())
249
      m_show_msg("RSRCDB/RDBYTYP", "Resource","read", scope, "", accessor, rsrc);
250
 
251
    if(rsrc == null)
252
      return 0;
253
 
254
    val = rsrc.read(accessor);
255
 
256
    return 1;
257
 
258
  endfunction
259
 
260
  // function: write_by_name
261
  //
262
  // write a ~val~ into the resources database.  First, look up the
263
  // resource by ~name~ and ~scope~.  If it is not located then add a new
264
  // resource to the database and then write its value.
265
  //
266
  // Because the ~scope~ is matched to a resource which may be a
267
  // regular expression, and consequently may target other scopes beyond
268
  // the ~scope~ argument. Care must be taken with this function. If
269
  // a  match is found for ~name~ and ~scope~ then ~val~
270
  // will be written to that matching resource and thus may impact
271
  // other scopes which also match the resource.
272
  static function bit write_by_name(input string scope, input string name,
273
                                    input T val, input uvm_object accessor = null);
274
 
275
    rsrc_t rsrc = get_by_name(scope, name);
276
 
277
    if(uvm_resource_db_options::is_tracing())
278
      m_show_msg("RSRCDB/WR","Resource", "written", scope, name, accessor, rsrc);
279
 
280
    if(rsrc == null)
281
      return 0;
282
 
283
    rsrc.write(val, accessor);
284
 
285
    return 1;
286
 
287
  endfunction
288
 
289
  // function: write_by_type
290
  //
291
  // write a ~val~ into the resources database.  First, look up the
292
  // resource by type.  If it is not located then add a new resource to
293
  // the database and then write its value.
294
  //
295
  // Because the ~scope~ is matched to a resource which may be a
296
  // regular expression, and consequently may target other scopes beyond
297
  // the ~scope~ argument. Care must be taken with this function. If
298
  // a  match is found for ~name~ and ~scope~ then ~val~
299
  // will be written to that matching resource and thus may impact
300
  // other scopes which also match the resource.
301
  static function bit write_by_type(input string scope,
302
                                    input T val, input uvm_object accessor = null);
303
 
304
    rsrc_t rsrc = get_by_type(scope);
305
 
306
    if(uvm_resource_db_options::is_tracing())
307
      m_show_msg("RSRCDB/WRTYP", "Resource","written", scope, "", accessor, rsrc);
308
 
309
    if(rsrc == null)
310
      return 0;
311
 
312
    rsrc.write(val, accessor);
313
 
314
    return 1;
315
  endfunction
316
 
317
  // function: dump
318
  //
319
  // Dump all the resources in the resource pool. This is useful for
320
  // debugging purposes.  This function does not use the parameter T, so
321
  // it will dump the same thing -- the entire database -- no matter the
322
  // value of the parameter.
323
 
324
  static function void dump();
325
    uvm_resource_pool rp = uvm_resource_pool::get();
326
    rp.dump();
327
  endfunction
328
 
329
endclass
330
 
331
 
332
//----------------------------------------------------------------------
333
// Class: uvm_resource_db_options
334
//
335
// Provides a namespace for managing options for the
336
// resources DB facility.  The only thing allowed in this class is static
337
// local data members and static functions for manipulating and
338
// retrieving the value of the data members.  The static local data
339
// members represent options and settings that control the behavior of
340
// the resources DB facility.
341
 
342
// Options include:
343
//
344
//  * tracing:  on/off
345
//
346
//    The default for tracing is off.
347
//
348
//----------------------------------------------------------------------
349
class uvm_resource_db_options;
350
 
351
  static local bit ready;
352
  static local bit tracing;
353
 
354
  // Function: turn_on_tracing
355
  //
356
  // Turn tracing on for the resource database. This causes all
357
  // reads and writes to the database to display information about
358
  // the accesses. Tracing is off by default.
359
  //
360
  // This method is implicitly called by the ~+UVM_RESOURCE_DB_TRACE~.
361
 
362
  static function void turn_on_tracing();
363
     if (!ready) init();
364
    tracing = 1;
365
  endfunction
366
 
367
  // Function: turn_off_tracing
368
  //
369
  // Turn tracing off for the resource database.
370
 
371
  static function void turn_off_tracing();
372
     if (!ready) init();
373
    tracing = 0;
374
  endfunction
375
 
376
  // Function: is_tracing
377
  //
378
  // Returns 1 if the tracing facility is on and 0 if it is off.
379
 
380
  static function bit is_tracing();
381
    if (!ready) init();
382
    return tracing;
383
  endfunction
384
 
385
 
386
  static local function void init();
387
     uvm_cmdline_processor clp;
388
     string trace_args[$];
389
 
390
     clp = uvm_cmdline_processor::get_inst();
391
 
392
     if (clp.get_arg_matches("+UVM_RESOURCE_DB_TRACE", trace_args)) begin
393
        tracing = 1;
394
     end
395
 
396
     ready = 1;
397
  endfunction
398
 
399
endclass

powered by: WebSVN 2.1.0

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