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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [deprecated/] [uvm_resource_converter.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
//   Copyright 2011 Cadence Design Systems, Inc.
4
//   Copyright 2011 Synopsys, Inc.
5
//   All Rights Reserved Worldwide
6
//
7
//   Licensed under the Apache License, Version 2.0 (the
8
//   "License"); you may not use this file except in
9
//   compliance with the License.  You may obtain a copy of
10
//   the License at
11
//
12
//       http://www.apache.org/licenses/LICENSE-2.0
13
//
14
//   Unless required by applicable law or agreed to in
15
//   writing, software distributed under the License is
16
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17
//   CONDITIONS OF ANY KIND, either express or implied.  See
18
//   the License for the specific language governing
19
//   permissions and limitations under the License.
20
//----------------------------------------------------------------------
21
 
22
 
23
//------------------------------------------------------------------------------
24
//
25
// CLASS- uvm_resource_converter#(T)
26
//
27
// The uvm_resource_converter class provides a policy object for doing
28
// convertion from resource value to string.
29
//
30
//------------------------------------------------------------------------------
31
class m_uvm_resource_converter #(type T=int);
32
 
33
   // Function- convert2string
34
   // Convert a value of type ~T~ to a string that can be displayed.
35
   //
36
   // By default, returns the name of the type
37
   //
38
   virtual function string convert2string(T val);
39
        return {"(", `uvm_typename(val), ") ?"};
40
   endfunction
41
endclass
42
 
43
//----------------------------------------------------------------------
44
//
45
// CLASS- uvm_resource_default_converter
46
// Define a default resource value converter using '%p'.
47
//
48
// May be used for almost all types, except virtual interfaces.
49
// Default resource converters are already defined for the
50
// built-in singular types using the 
51
// class.
52
//
53
//----------------------------------------------------------------------
54
 
55
class m_uvm_resource_default_converter#(type T=int) extends m_uvm_resource_converter#(T);
56
   local static m_uvm_resource_default_converter#(T) m_singleton;
57
   local string m_name;
58
 
59
   virtual function string convert2string(T val);
60
      return $sformatf("(%s) %0p", (m_name=="")? `uvm_typename(val):m_name, val);
61
   endfunction
62
 
63
   local function new();
64
   endfunction
65
 
66
   // Function- register
67
   // Register this policy class as the resource value conversion function
68
   // for this resource type.
69
   //
70
   //| uvm_resource_default_converter#(bit[7:0])::register();
71
   //
72
   // If a ~typename~ is specified, it will be used as the name of the type
73
   // instead of the name returned by the  method.
74
   //
75
 
76
   static function bit register(string typename = "");
77
      if (m_singleton == null) begin
78
         m_singleton = new();
79
         m_singleton.m_name = typename;
80
      end
81
      uvm_resource#(T)::m_set_converter(m_singleton);
82
      return 1;
83
   endfunction
84
endclass
85
 
86
 
87
//----------------------------------------------------------------------
88
//
89
// CLASS- uvm_resource_convert2string_converter
90
// Define a default resource value converter using convert2string() method
91
//
92
// May be used for all class types that contain a ~convert2string()~ method,
93
// such as .
94
//
95
//----------------------------------------------------------------------
96
 
97
class m_uvm_resource_convert2string_converter#(type T=int) extends m_uvm_resource_converter#(T);
98
   local static m_uvm_resource_convert2string_converter #(T) m_singleton;
99
 
100
   virtual function string convert2string(T val);
101
      return $sformatf("(%s) %0s", `uvm_typename(val),
102
                       (val == null) ? "(null)" : val.convert2string());
103
   endfunction
104
 
105
   local function new();
106
   endfunction
107
 
108
   // Function- register
109
   // Register this policy class as the resource value conversion function
110
   // for this resource type.
111
   //
112
   //| uvm_resource_convert2string_converter#(my_obj)::register();
113
   //
114
   static function bit register();
115
      if (m_singleton == null) m_singleton = new();
116
      uvm_resource#(T)::m_set_converter(m_singleton);
117
      return 1;
118
   endfunction
119
endclass
120
 
121
//----------------------------------------------------------------------
122
//
123
// CLASS- uvm_resource_sprint_converter
124
// Define a default resource value converter using sprint() method
125
//
126
// May be used for all class types that contain a ~sprint()~ method,
127
// such as .
128
//
129
//----------------------------------------------------------------------
130
 
131
class m_uvm_resource_sprint_converter#(type T=int) extends m_uvm_resource_converter#(T);
132
   local static m_uvm_resource_sprint_converter #(T) m_singleton;
133
 
134
   virtual function string convert2string(T val);
135
      return $sformatf("(%s) %0s", `uvm_typename(val),
136
                       (val == null) ? "(null)" : {"\n",val.sprint()});
137
   endfunction
138
 
139
   local function new();
140
   endfunction
141
 
142
   // Function- register
143
   // Register this policy class as the resource value conversion function
144
   // for this resource type.
145
   //
146
   //| void'(uvm_resource_sprint_converter#(my_obj)::register());
147
   //
148
   static function bit register();
149
      if (m_singleton == null) m_singleton = new();
150
      uvm_resource#(T)::m_set_converter(m_singleton);
151
      return 1;
152
   endfunction
153
endclass
154
 
155
 
156
//
157
// CLASS- m_uvm_resource_default_converters
158
// Singleton used to register default resource value converters
159
// for the built-in singular types.
160
//
161
class m_uvm_resource_default_converters;
162
 
163
   local static bit m_singleton = register();
164
   local function new();
165
   endfunction
166
 
167
   // Function- register
168
   // Explicitly initialize the singleton to eliminate race conditions
169
   //
170
   static function bit register();
171
      if (!m_singleton) begin
172
 
173
         `define __built_in(T) void'(m_uvm_resource_default_converter#(T)::register(`"T`"))
174
 
175
         `__built_in(shortint);
176
         `__built_in(int);
177
         `__built_in(longint);
178
         `__built_in(byte);
179
         `__built_in(bit);
180
         `__built_in(logic);
181
         `__built_in(reg);
182
         `__built_in(integer);
183
         `__built_in(time);
184
         `__built_in(real);
185
         `__built_in(realtime);
186
         `__built_in(string);
187
         `__built_in(uvm_bitstream_t);
188
         `__built_in(bit[7:0]);
189
         `__built_in(bit[15:0]);
190
         `__built_in(bit[31:0]);
191
 
192
         `undef __built_in
193
 
194
         m_singleton = 1;
195
      end
196
      return 1;
197
   endfunction
198
endclass
199
 

powered by: WebSVN 2.1.0

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