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

Subversion Repositories uart2bus_testbench

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2007-2010 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
`ifndef UVM_REGISTRY_SVH
24
`define UVM_REGISTRY_SVH
25
 
26
//------------------------------------------------------------------------------
27
// Title: Factory Component and Object Wrappers
28
//
29
// Topic: Intro
30
//
31
// This section defines the proxy component and object classes used by the
32
// factory. To avoid the overhead of creating an instance of every component
33
// and object that get registered, the factory holds lightweight wrappers,
34
// or proxies. When a request for a new object is made, the factory calls upon
35
// the proxy to create the object it represents.
36
//------------------------------------------------------------------------------
37
 
38
//------------------------------------------------------------------------------
39
//
40
// CLASS: uvm_component_registry #(T,Tname)
41
//
42
// The uvm_component_registry serves as a lightweight proxy for a component of
43
// type ~T~ and type name ~Tname~, a string. The proxy enables efficient
44
// registration with the . Without it, registration would
45
// require an instance of the component itself.
46
//
47
// See  section below for information on using uvm_component_registry.
48
//
49
//------------------------------------------------------------------------------
50
 
51
class uvm_component_registry #(type T=uvm_component, string Tname="")
52
                                           extends uvm_object_wrapper;
53
  typedef uvm_component_registry #(T,Tname) this_type;
54
 
55
 
56
  // Function: create_component
57
  //
58
  // Creates a component of type T having the provided ~name~ and ~parent~.
59
  // This is an override of the method in . It is
60
  // called by the factory after determining the type of object to create.
61
  // You should not call this method directly. Call  instead.
62
 
63
  virtual function uvm_component create_component (string name,
64
                                                   uvm_component parent);
65
    T obj;
66
    obj = new(name, parent);
67
    return obj;
68
  endfunction
69
 
70
 
71
  const static string type_name = Tname;
72
 
73
  // Function: get_type_name
74
  //
75
  // Returns the value given by the string parameter, ~Tname~. This method
76
  // overrides the method in .
77
 
78
  virtual function string get_type_name();
79
    return type_name;
80
  endfunction
81
 
82
  local static this_type me = get();
83
 
84
 
85
  // Function: get
86
  //
87
  // Returns the singleton instance of this type. Type-based factory operation
88
  // depends on there being a single proxy instance for each registered type.
89
 
90
  static function this_type get();
91
    if (me == null) begin
92
          uvm_coreservice_t cs = uvm_coreservice_t::get();
93
          uvm_factory factory=cs.get_factory();
94
      me = new;
95
      factory.register(me);
96
    end
97
    return me;
98
  endfunction
99
 
100
 
101
  // Function: create
102
  //
103
  // Returns an instance of the component type, ~T~, represented by this proxy,
104
  // subject to any factory overrides based on the context provided by the
105
  // ~parent~'s full name. The ~contxt~ argument, if supplied, supersedes the
106
  // ~parent~'s context. The new instance will have the given leaf ~name~
107
  // and ~parent~.
108
 
109
  static function T create(string name, uvm_component parent, string contxt="");
110
    uvm_object obj;
111
    uvm_coreservice_t cs = uvm_coreservice_t::get();
112
    uvm_factory factory=cs.get_factory();
113
    if (contxt == "" && parent != null)
114
      contxt = parent.get_full_name();
115
    obj = factory.create_component_by_type(get(),contxt,name,parent);
116
    if (!$cast(create, obj)) begin
117
      string msg;
118
      msg = {"Factory did not return a component of type '",type_name,
119
        "'. A component of type '",obj == null ? "null" : obj.get_type_name(),
120
        "' was returned instead. Name=",name," Parent=",
121
        parent==null?"null":parent.get_type_name()," contxt=",contxt};
122
      uvm_report_fatal("FCTTYP", msg, UVM_NONE);
123
    end
124
  endfunction
125
 
126
 
127
  // Function: set_type_override
128
  //
129
  // Configures the factory to create an object of the type represented by
130
  // ~override_type~ whenever a request is made to create an object of the type,
131
  // ~T~, represented by this proxy, provided no instance override applies. The
132
  // original type, ~T~, is typically a super class of the override type.
133
 
134
  static function void set_type_override (uvm_object_wrapper override_type,
135
                                          bit replace=1);
136
    uvm_coreservice_t cs = uvm_coreservice_t::get();
137
    uvm_factory factory=cs.get_factory();
138
    factory.set_type_override_by_type(get(),override_type,replace);
139
  endfunction
140
 
141
 
142
  // Function: set_inst_override
143
  //
144
  // Configures the factory to create a component of the type represented by
145
  // ~override_type~ whenever a request is made to create an object of the type,
146
  // ~T~, represented by this proxy,  with matching instance paths. The original
147
  // type, ~T~, is typically a super class of the override type.
148
  //
149
  // If ~parent~ is not specified, ~inst_path~ is interpreted as an absolute
150
  // instance path, which enables instance overrides to be set from outside
151
  // component classes. If ~parent~ is specified, ~inst_path~ is interpreted
152
  // as being relative to the ~parent~'s hierarchical instance path, i.e.
153
  // ~{parent.get_full_name(),".",inst_path}~ is the instance path that is
154
  // registered with the override. The ~inst_path~ may contain wildcards for
155
  // matching against multiple contexts.
156
 
157
  static function void set_inst_override(uvm_object_wrapper override_type,
158
                                         string inst_path,
159
                                         uvm_component parent=null);
160
    string full_inst_path;
161
    uvm_coreservice_t cs = uvm_coreservice_t::get();
162
    uvm_factory factory=cs.get_factory();
163
 
164
    if (parent != null) begin
165
      if (inst_path == "")
166
        inst_path = parent.get_full_name();
167
      else
168
        inst_path = {parent.get_full_name(),".",inst_path};
169
    end
170
    factory.set_inst_override_by_type(get(),override_type,inst_path);
171
  endfunction
172
 
173
endclass
174
 
175
 
176
//------------------------------------------------------------------------------
177
//
178
// CLASS: uvm_object_registry #(T,Tname)
179
//
180
// The uvm_object_registry serves as a lightweight proxy for a  of
181
// type ~T~ and type name ~Tname~, a string. The proxy enables efficient
182
// registration with the . Without it, registration would
183
// require an instance of the object itself.
184
//
185
// See  section below for information on using uvm_component_registry.
186
//
187
//------------------------------------------------------------------------------
188
 
189
class uvm_object_registry #(type T=uvm_object, string Tname="")
190
                                        extends uvm_object_wrapper;
191
  typedef uvm_object_registry #(T,Tname) this_type;
192
 
193
  // Function: create_object
194
  //
195
  // Creates an object of type ~T~ and returns it as a handle to a
196
  // . This is an override of the method in .
197
  // It is called by the factory after determining the type of object to create.
198
  // You should not call this method directly. Call  instead.
199
 
200
  virtual function uvm_object create_object(string name="");
201
    T obj;
202
`ifdef UVM_OBJECT_DO_NOT_NEED_CONSTRUCTOR
203
    obj = new();
204
    if (name!="")
205
      obj.set_name(name);
206
`else
207
    if (name=="") obj = new();
208
    else obj = new(name);
209
`endif
210
    return obj;
211
  endfunction
212
 
213
  const static string type_name = Tname;
214
 
215
  // Function: get_type_name
216
  //
217
  // Returns the value given by the string parameter, ~Tname~. This method
218
  // overrides the method in .
219
 
220
  virtual function string get_type_name();
221
    return type_name;
222
  endfunction
223
 
224
  local static this_type me = get();
225
 
226
  // Function: get
227
  //
228
  // Returns the singleton instance of this type. Type-based factory operation
229
  // depends on there being a single proxy instance for each registered type.
230
 
231
  static function this_type get();
232
    if (me == null) begin
233
      uvm_coreservice_t cs = uvm_coreservice_t::get();
234
      uvm_factory factory=cs.get_factory();
235
      me = new;
236
      factory.register(me);
237
    end
238
    return me;
239
  endfunction
240
 
241
 
242
  // Function: create
243
  //
244
  // Returns an instance of the object type, ~T~, represented by this proxy,
245
  // subject to any factory overrides based on the context provided by the
246
  // ~parent~'s full name. The ~contxt~ argument, if supplied, supersedes the
247
  // ~parent~'s context. The new instance will have the given leaf ~name~,
248
  // if provided.
249
 
250
  static function T create (string name="", uvm_component parent=null,
251
                            string contxt="");
252
    uvm_object obj;
253
    uvm_coreservice_t cs = uvm_coreservice_t::get();
254
    uvm_factory factory=cs.get_factory();
255
 
256
    if (contxt == "" && parent != null)
257
      contxt = parent.get_full_name();
258
    obj = factory.create_object_by_type(get(),contxt,name);
259
    if (!$cast(create, obj)) begin
260
      string msg;
261
      msg = {"Factory did not return an object of type '",type_name,
262
        "'. A component of type '",obj == null ? "null" : obj.get_type_name(),
263
        "' was returned instead. Name=",name," Parent=",
264
        parent==null?"null":parent.get_type_name()," contxt=",contxt};
265
      uvm_report_fatal("FCTTYP", msg, UVM_NONE);
266
    end
267
  endfunction
268
 
269
 
270
  // Function: set_type_override
271
  //
272
  // Configures the factory to create an object of the type represented by
273
  // ~override_type~ whenever a request is made to create an object of the type
274
  // represented by this proxy, provided no instance override applies. The
275
  // original type, ~T~, is typically a super class of the override type.
276
 
277
  static function void set_type_override (uvm_object_wrapper override_type,
278
                                          bit replace=1);
279
    uvm_coreservice_t cs = uvm_coreservice_t::get();
280
    uvm_factory factory=cs.get_factory();
281
    factory.set_type_override_by_type(get(),override_type,replace);
282
  endfunction
283
 
284
 
285
  // Function: set_inst_override
286
  //
287
  // Configures the factory to create an object of the type represented by
288
  // ~override_type~ whenever a request is made to create an object of the type
289
  // represented by this proxy, with matching instance paths. The original
290
  // type, ~T~, is typically a super class of the override type.
291
  //
292
  // If ~parent~ is not specified, ~inst_path~ is interpreted as an absolute
293
  // instance path, which enables instance overrides to be set from outside
294
  // component classes. If ~parent~ is specified, ~inst_path~ is interpreted
295
  // as being relative to the ~parent~'s hierarchical instance path, i.e.
296
  // ~{parent.get_full_name(),".",inst_path}~ is the instance path that is
297
  // registered with the override. The ~inst_path~ may contain wildcards for
298
  // matching against multiple contexts.
299
 
300
  static function void set_inst_override(uvm_object_wrapper override_type,
301
                                         string inst_path,
302
                                         uvm_component parent=null);
303
    string full_inst_path;
304
    uvm_coreservice_t cs = uvm_coreservice_t::get();
305
    uvm_factory factory=cs.get_factory();
306
 
307
    if (parent != null) begin
308
      if (inst_path == "")
309
        inst_path = parent.get_full_name();
310
      else
311
        inst_path = {parent.get_full_name(),".",inst_path};
312
    end
313
    factory.set_inst_override_by_type(get(),override_type,inst_path);
314
  endfunction
315
 
316
endclass
317
 
318
 
319
// Group: Usage
320
//
321
// This section describes usage for the uvm_*_registry classes.
322
//
323
// The wrapper classes are used to register lightweight proxies of objects and
324
// components.
325
//
326
// To register a particular component type, you need only typedef a
327
// specialization of its proxy class, which is typically done inside the class.
328
//
329
// For example, to register a UVM component of type ~mycomp~
330
//
331
//|  class mycomp extends uvm_component;
332
//|    typedef uvm_component_registry #(mycomp,"mycomp") type_id;
333
//|  endclass
334
//
335
// However, because of differences between simulators, it is necessary to use a
336
// macro to ensure vendor interoperability with factory registration. To
337
// register a UVM component of type ~mycomp~ in a vendor-independent way, you
338
// would write instead:
339
//
340
//|  class mycomp extends uvm_component;
341
//|    `uvm_component_utils(mycomp);
342
//|    ...
343
//|  endclass
344
//
345
// The <`uvm_component_utils> macro is for non-parameterized classes. In this
346
// example, the typedef underlying the macro specifies the ~Tname~
347
// parameter as "mycomp", and ~mycomp~'s get_type_name() is defined to return
348
// the same. With ~Tname~ defined, you can use the factory's name-based methods to
349
// set overrides and create objects and components of non-parameterized types.
350
//
351
// For parameterized types, the type name changes with each specialization, so
352
// you cannot specify a ~Tname~ inside a parameterized class and get the behavior
353
// you want; the same type name string would be registered for all
354
// specializations of the class! (The factory would produce warnings for each
355
// specialization beyond the first.) To avoid the warnings and simulator
356
// interoperability issues with parameterized classes, you must register
357
// parameterized classes with a different macro.
358
//
359
// For example, to register a UVM component of type driver #(T), you
360
// would write:
361
//
362
//|  class driver #(type T=int) extends uvm_component;
363
//|    `uvm_component_param_utils(driver #(T));
364
//|    ...
365
//|  endclass
366
//
367
// The <`uvm_component_param_utils> and <`uvm_object_param_utils> macros are used
368
// to register parameterized classes with the factory. Unlike the non-param
369
// versions, these macros do not specify the ~Tname~ parameter in the underlying
370
// uvm_component_registry typedef, and they do not define the get_type_name
371
// method for the user class. Consequently, you will not be able to use the
372
// factory's name-based methods for parameterized classes.
373
//
374
// The primary purpose for adding the factory's type-based methods was to
375
// accommodate registration of parameterized types and eliminate the many sources
376
// of errors associated with string-based factory usage. Thus, use of name-based
377
// lookup in  is no longer recommended.
378
 
379
`endif // UVM_REGISTRY_SVH
380
 

powered by: WebSVN 2.1.0

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