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

Subversion Repositories uart2bus_testbench

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//----------------------------------------------------------------------
2
//   Copyright 2010 Mentor Graphics Corporation
3
//   All Rights Reserved Worldwide
4
//
5
//   Licensed under the Apache License, Version 2.0 (the
6
//   "License"); you may not use this file except in
7
//   compliance with the License.  You may obtain a copy of
8
//   the License at
9
//
10
//       http://www.apache.org/licenses/LICENSE-2.0
11
//
12
//   Unless required by applicable law or agreed to in
13
//   writing, software distributed under the License is
14
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
15
//   CONDITIONS OF ANY KIND, either express or implied.  See
16
//   the License for the specific language governing
17
//   permissions and limitations under the License.
18
//----------------------------------------------------------------------
19
 
20
// macro - UVM_RESOURCE_GET_FCNS
21
 
22
// When specicializing resources the get_by_name and get_by_type
23
// functions must be redefined.  The reason is that the version of these
24
// functions in the base class (uvm_resource#(T)) returns an object of
25
// type uvm_resource#(T).  In the specializations we must return an
26
// object of the type of the specialization.  So, we call the base_class
27
// implementation of these functions and then downcast to the subtype.
28
//
29
// This macro is invokved once in each where a resource specialization
30
// is a class defined as:
31
//
32
//|  class  extends uvm_resource#(T)
33
//
34
// where  is the name of the derived class.
35
// The argument to this macro is T, the type of the uvm_resource#(T)
36
// specialization.  The class in which the macro is defined must supply
37
// a typedef of the specialized class of the form:
38
//
39
//|  typedef  this_subtype;
40
//
41
// where  is the same as above.  The macro
42
// generates the get_by_name() and get_by_type() functions for the
43
// specialized resource (i.e. resource subtype).
44
 
45
`define UVM_RESOURCE_GET_FCNS(base_type)                                               \
46
  static function this_subtype get_by_name(string scope, string name, bit rpterr = 1); \
47
    this_subtype t;                                                                    \
48
    uvm_resource_base b = uvm_resource#(base_type)::get_by_name(scope, name, rpterr);  \
49
    if(!$cast(t, b))                                                                   \
50
      `uvm_fatal("BADCAST", "cannot cast resource to resource subtype");               \
51
    return t;                                                                          \
52
  endfunction                                                                          \
53
                                                                                       \
54
  static function this_subtype get_by_type(string scope = "",                          \
55
                                           uvm_resource_base type_handle);             \
56
    this_subtype t;                                                                    \
57
    uvm_resource_base b = uvm_resource#(base_type)::get_by_type(scope, type_handle);   \
58
    if(!$cast(t, b))                                                                   \
59
      `uvm_fatal("BADCAST", "cannot cast resource to resource subtype");               \
60
    return t;                                                                          \
61
  endfunction
62
 
63
 
64
//----------------------------------------------------------------------
65
// uvm_int_rsrc
66
//
67
// specialization of uvm_resource #(T) for T = int
68
//----------------------------------------------------------------------
69
class uvm_int_rsrc extends uvm_resource #(int);
70
 
71
  typedef uvm_int_rsrc this_subtype;
72
 
73
  function new(string name, string s = "*");
74
    super.new(name, s);
75
  endfunction
76
 
77
  function string convert2string();
78
    string s;
79
    $sformat(s, "%0d", read());
80
    return s;
81
  endfunction
82
 
83
  `UVM_RESOURCE_GET_FCNS(int)
84
 
85
endclass
86
 
87
//----------------------------------------------------------------------
88
// uvm_string_rsrc
89
//
90
// specialization of uvm_resource #(T) for T = string
91
//----------------------------------------------------------------------
92
class uvm_string_rsrc extends uvm_resource #(string);
93
 
94
  typedef uvm_string_rsrc this_subtype;
95
 
96
  function new(string name, string s = "*");
97
    super.new(name, s);
98
  endfunction
99
 
100
  function string convert2string();
101
    return read();
102
  endfunction
103
 
104
  `UVM_RESOURCE_GET_FCNS(string)
105
 
106
endclass
107
 
108
//----------------------------------------------------------------------
109
// uvm_obj_rsrc
110
//
111
// specialization of uvm_resource #(T) for T = uvm_object
112
//----------------------------------------------------------------------
113
class uvm_obj_rsrc extends uvm_resource #(uvm_object);
114
 
115
  typedef uvm_obj_rsrc this_subtype;
116
 
117
  function new(string name, string s = "*");
118
    super.new(name, s);
119
  endfunction
120
 
121
  `UVM_RESOURCE_GET_FCNS(uvm_object)
122
 
123
endclass
124
 
125
//----------------------------------------------------------------------
126
// uvm_bit_rsrc
127
//
128
// specialization of uvm_resource #(T) for T = vector of bits
129
//----------------------------------------------------------------------
130
class uvm_bit_rsrc #(int unsigned N=1) extends uvm_resource #(bit[N-1:0]);
131
 
132
  typedef uvm_bit_rsrc#(N) this_subtype;
133
 
134
  function new(string name, string s = "*");
135
    super.new(name, s);
136
  endfunction
137
 
138
  function string convert2string();
139
    string s;
140
    $sformat(s, "%0b", read());
141
    return s;
142
  endfunction
143
 
144
  `UVM_RESOURCE_GET_FCNS(bit[N-1:0])
145
 
146
endclass
147
 
148
//----------------------------------------------------------------------
149
// uvm_byte_rsrc
150
//
151
// specialization of uvm_resource #T() for T = vector of bytes
152
//----------------------------------------------------------------------
153
class uvm_byte_rsrc #(int unsigned N=1) extends uvm_resource #(bit[7:0][N-1:0]);
154
 
155
  typedef uvm_byte_rsrc#(N) this_subtype;
156
 
157
  function new(string name, string s = "*");
158
    super.new(name, s);
159
  endfunction
160
 
161
  function string convert2string();
162
    string s;
163
    $sformat(s, "%0x", read());
164
    return s;
165
  endfunction
166
 
167
  `UVM_RESOURCE_GET_FCNS(bit[7:0][N-1:0])
168
 
169
endclass
170
 

powered by: WebSVN 2.1.0

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