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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_pool.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-2010 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 for the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
// Title: Pool Classes
24
// This section defines the  class and derivative.
25
 
26
//------------------------------------------------------------------------------
27
//
28
// CLASS: uvm_pool #(KEY,T)
29
//
30
//------------------------------------------------------------------------------
31
// Implements a class-based dynamic associative array. Allows sparse arrays to
32
// be allocated on demand, and passed and stored by reference.
33
//------------------------------------------------------------------------------
34
 
35
class uvm_pool #(type KEY=int, T=uvm_void) extends uvm_object;
36
 
37
  const static string type_name = "uvm_pool";
38
 
39
  typedef uvm_pool #(KEY,T) this_type;
40
 
41
  static protected this_type m_global_pool;
42
  protected T pool[KEY];
43
 
44
 
45
  // Function: new
46
  //
47
  // Creates a new pool with the given ~name~.
48
 
49
  function new (string name="");
50
    super.new(name);
51
  endfunction
52
 
53
 
54
  // Function: get_global_pool
55
  //
56
  // Returns the singleton global pool for the item type, T.
57
  //
58
  // This allows items to be shared amongst components throughout the
59
  // verification environment.
60
 
61
  static function this_type get_global_pool ();
62
    if (m_global_pool==null)
63
      m_global_pool = new("pool");
64
    return m_global_pool;
65
  endfunction
66
 
67
 
68
  // Function: get_global
69
  //
70
  // Returns the specified item instance from the global item pool.
71
 
72
  static function T get_global (KEY key);
73
    this_type gpool;
74
    gpool = get_global_pool();
75
    return gpool.get(key);
76
  endfunction
77
 
78
 
79
  // Function: get
80
  //
81
  // Returns the item with the given ~key~.
82
  //
83
  // If no item exists by that key, a new item is created with that key
84
  // and returned.
85
 
86
  virtual function T get (KEY key);
87
    if (!pool.exists(key)) begin
88
      T default_value;
89
      pool[key] = default_value;
90
    end
91
    return pool[key];
92
  endfunction
93
 
94
 
95
  // Function: add
96
  //
97
  // Adds the given (~key~, ~item~) pair to the pool. If an item already
98
  // exists at the given ~key~ it is overwritten with the new ~item~.
99
 
100
  virtual function void add (KEY key, T item);
101
    pool[key] = item;
102
  endfunction
103
 
104
 
105
  // Function: num
106
  //
107
  // Returns the number of uniquely keyed items stored in the pool.
108
 
109
  virtual function int num ();
110
    return pool.num();
111
  endfunction
112
 
113
 
114
  // Function: delete
115
  //
116
  // Removes the item with the given ~key~ from the pool.
117
 
118
  virtual function void delete (KEY key);
119
    if (!exists(key)) begin
120
      uvm_report_warning("POOLDEL",
121
        $sformatf("delete: pool key doesn't exist. Ignoring delete request"));
122
      return;
123
    end
124
    pool.delete(key);
125
  endfunction
126
 
127
 
128
  // Function: exists
129
  //
130
  // Returns 1 if an item with the given ~key~ exists in the pool,
131
  // 0 otherwise.
132
 
133
  virtual function int exists (KEY key);
134
    return pool.exists(key);
135
  endfunction
136
 
137
 
138
  // Function: first
139
  //
140
  // Returns the key of the first item stored in the pool.
141
  //
142
  // If the pool is empty, then ~key~ is unchanged and 0 is returned.
143
  //
144
  // If the pool is not empty, then ~key~ is key of the first item
145
  // and 1 is returned.
146
 
147
  virtual function int first (ref KEY key);
148
    return pool.first(key);
149
  endfunction
150
 
151
 
152
  // Function: last
153
  //
154
  // Returns the key of the last item stored in the pool.
155
  //
156
  // If the pool is empty, then 0 is returned and ~key~ is unchanged.
157
  //
158
  // If the pool is not empty, then ~key~ is set to the last key in
159
  // the pool and 1 is returned.
160
 
161
  virtual function int last (ref KEY key);
162
    return pool.last(key);
163
  endfunction
164
 
165
 
166
  // Function: next
167
  //
168
  // Returns the key of the next item in the pool.
169
  //
170
  // If the input ~key~ is the last key in the pool, then ~key~ is
171
  // left unchanged and 0 is returned.
172
  //
173
  // If a next key is found, then ~key~ is updated with that key
174
  // and 1 is returned.
175
 
176
  virtual function int next (ref KEY key);
177
    return pool.next(key);
178
  endfunction
179
 
180
 
181
  // Function: prev
182
  //
183
  // Returns the key of the previous item in the pool.
184
  //
185
  // If the input ~key~ is the first key in the pool, then ~key~ is
186
  // left unchanged and 0 is returned.
187
  //
188
  // If a previous key is found, then ~key~ is updated with that key
189
  // and 1 is returned.
190
 
191
  virtual function int prev (ref KEY key);
192
    return pool.prev(key);
193
  endfunction
194
 
195
 
196
  virtual function uvm_object create (string name="");
197
    this_type v;
198
    v=new(name);
199
    return v;
200
  endfunction
201
 
202
  virtual function string get_type_name ();
203
    return type_name;
204
  endfunction
205
 
206
  virtual function void do_copy (uvm_object rhs);
207
    this_type p;
208
    KEY key;
209
    super.do_copy(rhs);
210
    if (rhs==null || !$cast(p, rhs))
211
      return;
212
    pool = p.pool;
213
  endfunction
214
 
215
  virtual function void do_print (uvm_printer printer);
216
    string v;
217
    int cnt;
218
    string item;
219
    KEY key;
220
    printer.print_array_header("pool",pool.num(),"aa_object_string");
221
    if (pool.first(key))
222
      do begin
223
        item.itoa(cnt);
224
        item = {"[-key",item,"--]"};
225
        $swrite(v,pool[key]);
226
        printer.print_generic(item,"",-1,v,"[");
227
      end
228
      while (pool.next(key));
229
    printer.print_array_footer();
230
  endfunction
231
 
232
endclass
233
 
234
 
235
//------------------------------------------------------------------------------
236
//
237
// CLASS: uvm_object_string_pool #(T)
238
//
239
//------------------------------------------------------------------------------
240
// This provides a specialization of the generic  class for
241
// an associative array of -based objects indexed by string.
242
// Specializations of this class include the ~uvm_event_pool~ (a
243
// uvm_object_string_pool storing ~uvm_event#(uvm_object)~) and
244
// ~uvm_barrier_pool~ (a uvm_obejct_string_pool storing ).
245
//------------------------------------------------------------------------------
246
 
247
class uvm_object_string_pool #(type T=uvm_object) extends uvm_pool #(string,T);
248
 
249
  typedef uvm_object_string_pool #(T) this_type;
250
  static protected this_type m_global_pool;
251
 
252
 
253
  // Function: new
254
  //
255
  // Creates a new pool with the given ~name~.
256
 
257
  function new (string name="");
258
    super.new(name);
259
  endfunction
260
 
261
 
262
  const static string type_name = {"uvm_obj_str_pool"};
263
 
264
  // Function: get_type_name
265
  //
266
  // Returns the type name of this object.
267
 
268
  virtual function string get_type_name();
269
    return type_name;
270
  endfunction
271
 
272
 
273
  // Function: get_global_pool
274
  //
275
  // Returns the singleton global pool for the item type, T.
276
  //
277
  // This allows items to be shared amongst components throughout the
278
  // verification environment.
279
 
280
  static function this_type get_global_pool ();
281
    if (m_global_pool==null)
282
      m_global_pool = new("global_pool");
283
    return m_global_pool;
284
  endfunction
285
 
286
 
287
  // Function: get_global
288
  //
289
  // Returns the specified item instance from the global item pool.
290
 
291
  static function T get_global (string key);
292
    this_type gpool;
293
    gpool = get_global_pool();
294
    return gpool.get(key);
295
  endfunction
296
 
297
 
298
  // Function: get
299
  //
300
  // Returns the object item at the given string ~key~.
301
  //
302
  // If no item exists by the given ~key~, a new item is created for that key
303
  // and returned.
304
 
305
  virtual function T get (string key);
306
    if (!pool.exists(key))
307
      pool[key] = new (key);
308
    return pool[key];
309
  endfunction
310
 
311
 
312
  // Function: delete
313
  //
314
  // Removes the item with the given string ~key~ from the pool.
315
 
316
  virtual function void delete (string key);
317
    if (!exists(key)) begin
318
      uvm_report_warning("POOLDEL",
319
        $sformatf("delete: key '%s' doesn't exist", key));
320
      return;
321
    end
322
    pool.delete(key);
323
  endfunction
324
 
325
 
326
  // Function- do_print
327
 
328
  virtual function void do_print (uvm_printer printer);
329
    string key;
330
    printer.print_array_header("pool",pool.num(),"aa_object_string");
331
    if (pool.first(key))
332
      do
333
        printer.print_object({"[",key,"]"}, pool[key],"[");
334
      while (pool.next(key));
335
    printer.print_array_footer();
336
  endfunction
337
 
338
endclass
339
 
340
 
341
typedef class uvm_barrier;
342
typedef class uvm_event;
343
 
344
typedef uvm_object_string_pool #(uvm_barrier) uvm_barrier_pool;
345
typedef uvm_object_string_pool #(uvm_event#(uvm_object)) uvm_event_pool;
346
 
347
 

powered by: WebSVN 2.1.0

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