1 |
16 |
HanySalah |
//
|
2 |
|
|
//-----------------------------------------------------------------------------
|
3 |
|
|
// Copyright 2007-2011 Mentor Graphics Corporation
|
4 |
|
|
// Copyright 2007-2011 Cadence Design Systems, Inc.
|
5 |
|
|
// Copyright 2010 Synopsys, Inc.
|
6 |
|
|
// Copyright 2013 NVIDIA Corporation
|
7 |
|
|
// All Rights Reserved Worldwide
|
8 |
|
|
//
|
9 |
|
|
// Licensed under the Apache License, Version 2.0 (the
|
10 |
|
|
// "License"); you may not use this file except in
|
11 |
|
|
// compliance with the License. You may obtain a copy of
|
12 |
|
|
// the License at
|
13 |
|
|
//
|
14 |
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
15 |
|
|
//
|
16 |
|
|
// Unless required by applicable law or agreed to in
|
17 |
|
|
// writing, software distributed under the License is
|
18 |
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
19 |
|
|
// CONDITIONS OF ANY KIND, either express or implied. See
|
20 |
|
|
// the License for the specific language governing
|
21 |
|
|
// permissions and limitations under the License.
|
22 |
|
|
//-----------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
//------------------------------------------------------------------------------
|
25 |
|
|
// File: Transaction Recording Databases
|
26 |
|
|
//
|
27 |
|
|
// The UVM "Transaction Recording Database" classes are an abstract representation
|
28 |
|
|
// of the backend tool which is recording information for the user. Usually this
|
29 |
|
|
// tool would be dumping information such that it can be viewed with the ~waves~
|
30 |
|
|
// of the DUT.
|
31 |
|
|
//
|
32 |
|
|
|
33 |
|
|
typedef class uvm_recorder;
|
34 |
|
|
typedef class uvm_tr_stream;
|
35 |
|
|
typedef class uvm_link_base;
|
36 |
|
|
typedef class uvm_simple_lock_dap;
|
37 |
|
|
typedef class uvm_text_tr_stream;
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
//------------------------------------------------------------------------------
|
41 |
|
|
//
|
42 |
|
|
// CLASS: uvm_tr_database
|
43 |
|
|
//
|
44 |
|
|
// The ~uvm_tr_database~ class is intended to hide the underlying database implementation
|
45 |
|
|
// from the end user, as these details are often vendor or tool-specific.
|
46 |
|
|
//
|
47 |
|
|
// The ~uvm_tr_database~ class is pure virtual, and must be extended with an
|
48 |
|
|
// implementation. A default text-based implementation is provided via the
|
49 |
|
|
// class.
|
50 |
|
|
//
|
51 |
|
|
|
52 |
|
|
virtual class uvm_tr_database extends uvm_object;
|
53 |
|
|
|
54 |
|
|
// Variable- m_is_opened
|
55 |
|
|
// Tracks the opened state of the database
|
56 |
|
|
local bit m_is_opened;
|
57 |
|
|
|
58 |
|
|
// Variable- m_streams
|
59 |
|
|
// Used for tracking streams which are between the open and closed states
|
60 |
|
|
local bit m_streams[uvm_tr_stream];
|
61 |
|
|
|
62 |
|
|
// Function: new
|
63 |
|
|
// Constructor
|
64 |
|
|
//
|
65 |
|
|
// Parameters:
|
66 |
|
|
// name - Instance name
|
67 |
|
|
function new(string name="unnamed-uvm_tr_database");
|
68 |
|
|
super.new(name);
|
69 |
|
|
endfunction : new
|
70 |
|
|
|
71 |
|
|
// Group: Database API
|
72 |
|
|
|
73 |
|
|
// Function: open_db
|
74 |
|
|
// Open the backend connection to the database.
|
75 |
|
|
//
|
76 |
|
|
// If the database is already open, then this
|
77 |
|
|
// method will return 1.
|
78 |
|
|
//
|
79 |
|
|
// Otherwise, the method will call ,
|
80 |
|
|
// and return the result.
|
81 |
|
|
function bit open_db();
|
82 |
|
|
if (!m_is_opened)
|
83 |
|
|
m_is_opened = do_open_db();
|
84 |
|
|
return m_is_opened;
|
85 |
|
|
endfunction : open_db
|
86 |
|
|
|
87 |
|
|
// Function: close_db
|
88 |
|
|
// Closes the backend connection to the database.
|
89 |
|
|
//
|
90 |
|
|
// Closing a database implicitly closes and
|
91 |
|
|
// frees all within the database.
|
92 |
|
|
//
|
93 |
|
|
// If the database is already closed, then this
|
94 |
|
|
// method will return 1.
|
95 |
|
|
//
|
96 |
|
|
// Otherwise, this method will trigger a
|
97 |
|
|
// call, and return the result.
|
98 |
|
|
function bit close_db();
|
99 |
|
|
if (m_is_opened) begin
|
100 |
|
|
if (do_close_db())
|
101 |
|
|
m_is_opened = 0;
|
102 |
|
|
end
|
103 |
|
|
return (m_is_opened == 0);
|
104 |
|
|
endfunction : close_db
|
105 |
|
|
|
106 |
|
|
// Function: is_open
|
107 |
|
|
// Returns the open/closed status of the database.
|
108 |
|
|
//
|
109 |
|
|
// This method returns 1 if the database has been
|
110 |
|
|
// successfully opened, but not yet closed.
|
111 |
|
|
//
|
112 |
|
|
function bit is_open();
|
113 |
|
|
return m_is_opened;
|
114 |
|
|
endfunction : is_open
|
115 |
|
|
|
116 |
|
|
// Group: Stream API
|
117 |
|
|
|
118 |
|
|
// Function: open_stream
|
119 |
|
|
// Provides a reference to a ~stream~ within the
|
120 |
|
|
// database.
|
121 |
|
|
//
|
122 |
|
|
// Parameters:
|
123 |
|
|
// name - A string name for the stream. This is the name associated
|
124 |
|
|
// with the stream in the database.
|
125 |
|
|
// scope - An optional scope for the stream.
|
126 |
|
|
// type_name - An optional name describing the type of records which
|
127 |
|
|
// will be created in this stream.
|
128 |
|
|
//
|
129 |
|
|
// The method returns a reference to a
|
130 |
|
|
// object if successful, ~null~ otherwise.
|
131 |
|
|
//
|
132 |
|
|
// This method will trigger a call, and if a
|
133 |
|
|
// non ~null~ stream is returned, then
|
134 |
|
|
// will be called.
|
135 |
|
|
//
|
136 |
|
|
// Streams can only be opened if the database is
|
137 |
|
|
// open (per ). Otherwise the request will
|
138 |
|
|
// be ignored, and ~null~ will be returned.
|
139 |
|
|
function uvm_tr_stream open_stream(string name,
|
140 |
|
|
string scope="",
|
141 |
|
|
string type_name="");
|
142 |
|
|
if (!open_db()) begin
|
143 |
|
|
return null;
|
144 |
|
|
end
|
145 |
|
|
else begin
|
146 |
|
|
process p = process::self();
|
147 |
|
|
string s;
|
148 |
|
|
|
149 |
|
|
if (p != null)
|
150 |
|
|
s = p.get_randstate();
|
151 |
|
|
|
152 |
|
|
open_stream = do_open_stream(name, scope, type_name);
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
if (open_stream != null) begin
|
156 |
|
|
m_streams[open_stream] = 1;
|
157 |
|
|
open_stream.m_do_open(this, scope, type_name);
|
158 |
|
|
end
|
159 |
|
|
|
160 |
|
|
if (p != null)
|
161 |
|
|
p.set_randstate(s);
|
162 |
|
|
|
163 |
|
|
end
|
164 |
|
|
endfunction : open_stream
|
165 |
|
|
|
166 |
|
|
// Function- m_free_stream
|
167 |
|
|
// Removes stream from the internal array
|
168 |
|
|
function void m_free_stream(uvm_tr_stream stream);
|
169 |
|
|
if (m_streams.exists(stream))
|
170 |
|
|
m_streams.delete(stream);
|
171 |
|
|
endfunction : m_free_stream
|
172 |
|
|
|
173 |
|
|
// Function: get_streams
|
174 |
|
|
// Provides a queue of all streams within the database.
|
175 |
|
|
//
|
176 |
|
|
// Parameters:
|
177 |
|
|
// q - A reference to a queue of s
|
178 |
|
|
//
|
179 |
|
|
// The ~get_streams~ method returns the size of the queue,
|
180 |
|
|
// such that the user can conditionally process the elements.
|
181 |
|
|
//
|
182 |
|
|
// | uvm_tr_stream stream_q[$];
|
183 |
|
|
// | if (my_db.get_streams(stream_q)) begin
|
184 |
|
|
// | // Process the queue...
|
185 |
|
|
// | end
|
186 |
|
|
function unsigned get_streams(ref uvm_tr_stream q[$]);
|
187 |
|
|
// Clear out the queue first...
|
188 |
|
|
q.delete();
|
189 |
|
|
// Then fill in the values
|
190 |
|
|
foreach (m_streams[idx])
|
191 |
|
|
q.push_back(idx);
|
192 |
|
|
// Finally, return the size of the queue
|
193 |
|
|
return q.size();
|
194 |
|
|
endfunction : get_streams
|
195 |
|
|
|
196 |
|
|
// Group: Link API
|
197 |
|
|
|
198 |
|
|
// Function: establish_link
|
199 |
|
|
// Establishes a ~link~ between two elements in the database
|
200 |
|
|
//
|
201 |
|
|
// Links are only supported between ~streams~ and ~records~
|
202 |
|
|
// within a single database.
|
203 |
|
|
//
|
204 |
|
|
// This method will trigger a call.
|
205 |
|
|
function void establish_link(uvm_link_base link);
|
206 |
|
|
uvm_tr_stream s_lhs, s_rhs;
|
207 |
|
|
uvm_recorder r_lhs, r_rhs;
|
208 |
|
|
uvm_object lhs = link.get_lhs();
|
209 |
|
|
uvm_object rhs = link.get_rhs();
|
210 |
|
|
uvm_tr_database db;
|
211 |
|
|
|
212 |
|
|
if (lhs == null) begin
|
213 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
214 |
|
|
"left hand side '' is not supported in links for 'uvm_tr_database'")
|
215 |
|
|
return;
|
216 |
|
|
end
|
217 |
|
|
if (rhs == null) begin
|
218 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
219 |
|
|
"right hand side '' is not supported in links for 'uvm_tr_database'")
|
220 |
|
|
return;
|
221 |
|
|
end
|
222 |
|
|
|
223 |
|
|
if (!$cast(s_lhs, lhs) &&
|
224 |
|
|
!$cast(r_lhs, lhs)) begin
|
225 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
226 |
|
|
$sformatf("left hand side of type '%s' not supported in links for 'uvm_tr_database'",
|
227 |
|
|
lhs.get_type_name()))
|
228 |
|
|
return;
|
229 |
|
|
end
|
230 |
|
|
if (!$cast(s_rhs, rhs) &&
|
231 |
|
|
!$cast(r_rhs, rhs)) begin
|
232 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
233 |
|
|
$sformatf("right hand side of type '%s' not supported in links for 'uvm_record_datbasae'",
|
234 |
|
|
rhs.get_type_name()))
|
235 |
|
|
return;
|
236 |
|
|
end
|
237 |
|
|
|
238 |
|
|
if (r_lhs != null) begin
|
239 |
|
|
s_lhs = r_lhs.get_stream();
|
240 |
|
|
end
|
241 |
|
|
if (r_rhs != null) begin
|
242 |
|
|
s_rhs = r_rhs.get_stream();
|
243 |
|
|
end
|
244 |
|
|
|
245 |
|
|
if ((s_lhs != null) && (s_lhs.get_db() != this)) begin
|
246 |
|
|
db = s_lhs.get_db();
|
247 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
248 |
|
|
$sformatf("attempt to link stream from '%s' into '%s'",
|
249 |
|
|
db.get_name(), this.get_name()))
|
250 |
|
|
return;
|
251 |
|
|
end
|
252 |
|
|
if ((s_rhs != null) && (s_rhs.get_db() != this)) begin
|
253 |
|
|
db = s_rhs.get_db();
|
254 |
|
|
`uvm_warning("UVM/TR_DB/BAD_LINK",
|
255 |
|
|
$sformatf("attempt to link stream from '%s' into '%s'",
|
256 |
|
|
db.get_name(), this.get_name()))
|
257 |
|
|
return;
|
258 |
|
|
end
|
259 |
|
|
|
260 |
|
|
do_establish_link(link);
|
261 |
|
|
endfunction : establish_link
|
262 |
|
|
|
263 |
|
|
// Group: Implementation Agnostic API
|
264 |
|
|
//
|
265 |
|
|
|
266 |
|
|
// Function: do_open_db
|
267 |
|
|
// Backend implementation of
|
268 |
|
|
pure virtual protected function bit do_open_db();
|
269 |
|
|
|
270 |
|
|
// Function: do_close_db
|
271 |
|
|
// Backend implementation of
|
272 |
|
|
pure virtual protected function bit do_close_db();
|
273 |
|
|
|
274 |
|
|
// Function: do_open_stream
|
275 |
|
|
// Backend implementation of
|
276 |
|
|
pure virtual protected function uvm_tr_stream do_open_stream(string name,
|
277 |
|
|
string scope,
|
278 |
|
|
string type_name);
|
279 |
|
|
|
280 |
|
|
// Function: do_establish_link
|
281 |
|
|
// Backend implementation of
|
282 |
|
|
pure virtual protected function void do_establish_link(uvm_link_base link);
|
283 |
|
|
|
284 |
|
|
endclass : uvm_tr_database
|
285 |
|
|
|
286 |
|
|
//------------------------------------------------------------------------------
|
287 |
|
|
//
|
288 |
|
|
// CLASS: uvm_text_tr_database
|
289 |
|
|
//
|
290 |
|
|
// The ~uvm_text_tr_database~ is the default implementation for the
|
291 |
|
|
// . It provides the ability to store recording information
|
292 |
|
|
// into a textual log file.
|
293 |
|
|
//
|
294 |
|
|
//
|
295 |
|
|
|
296 |
|
|
class uvm_text_tr_database extends uvm_tr_database;
|
297 |
|
|
|
298 |
|
|
// Variable- m_filename_dap
|
299 |
|
|
// Data Access Protected Filename
|
300 |
|
|
local uvm_simple_lock_dap#(string) m_filename_dap;
|
301 |
|
|
|
302 |
|
|
// Variable- m_file
|
303 |
|
|
UVM_FILE m_file;
|
304 |
|
|
|
305 |
|
|
`uvm_object_utils_begin(uvm_text_tr_database)
|
306 |
|
|
`uvm_object_utils_end
|
307 |
|
|
|
308 |
|
|
// Function: new
|
309 |
|
|
// Constructor
|
310 |
|
|
//
|
311 |
|
|
// Parameters:
|
312 |
|
|
// name - Instance name
|
313 |
|
|
function new(string name="unnamed-uvm_text_tr_database");
|
314 |
|
|
super.new(name);
|
315 |
|
|
|
316 |
|
|
m_filename_dap = new("filename_dap");
|
317 |
|
|
m_filename_dap.set("tr_db.log");
|
318 |
|
|
endfunction : new
|
319 |
|
|
|
320 |
|
|
// Group: Implementation Agnostic API
|
321 |
|
|
|
322 |
|
|
// Function: do_open_db
|
323 |
|
|
// Open the backend connection to the database.
|
324 |
|
|
//
|
325 |
|
|
// Text-Backend implementation of .
|
326 |
|
|
//
|
327 |
|
|
// The text-backend will open a text file to dump all records in to. The name
|
328 |
|
|
// of this text file is controlled via .
|
329 |
|
|
//
|
330 |
|
|
// This will also lock the ~file_name~, so that it cannot be
|
331 |
|
|
// modified while the connection is open.
|
332 |
|
|
protected virtual function bit do_open_db();
|
333 |
|
|
if (m_file == 0) begin
|
334 |
|
|
m_file = $fopen(m_filename_dap.get(), "a+");
|
335 |
|
|
if (m_file != 0)
|
336 |
|
|
m_filename_dap.lock();
|
337 |
|
|
end
|
338 |
|
|
return (m_file != 0);
|
339 |
|
|
endfunction : do_open_db
|
340 |
|
|
|
341 |
|
|
// Function: do_close_db
|
342 |
|
|
// Close the backend connection to the database.
|
343 |
|
|
//
|
344 |
|
|
// Text-Backend implementation of .
|
345 |
|
|
//
|
346 |
|
|
// The text-backend will close the text file used to dump all records in to,
|
347 |
|
|
// if it is currently opened.
|
348 |
|
|
//
|
349 |
|
|
// This unlocks the ~file_name~, allowing it to be modified again.
|
350 |
|
|
protected virtual function bit do_close_db();
|
351 |
|
|
if (m_file != 0) begin
|
352 |
|
|
fork // Needed because $fclose is a task
|
353 |
|
|
$fclose(m_file);
|
354 |
|
|
join_none
|
355 |
|
|
m_filename_dap.unlock();
|
356 |
|
|
end
|
357 |
|
|
return 1;
|
358 |
|
|
endfunction : do_close_db
|
359 |
|
|
|
360 |
|
|
// Function: do_open_stream
|
361 |
|
|
// Provides a reference to a ~stream~ within the
|
362 |
|
|
// database.
|
363 |
|
|
//
|
364 |
|
|
// Text-Backend implementation of
|
365 |
|
|
protected virtual function uvm_tr_stream do_open_stream(string name,
|
366 |
|
|
string scope,
|
367 |
|
|
string type_name);
|
368 |
|
|
uvm_text_tr_stream m_stream = uvm_text_tr_stream::type_id::create(name);
|
369 |
|
|
return m_stream;
|
370 |
|
|
endfunction : do_open_stream
|
371 |
|
|
|
372 |
|
|
// Function: do_establish_link
|
373 |
|
|
// Establishes a ~link~ between two elements in the database
|
374 |
|
|
//
|
375 |
|
|
// Text-Backend implementation of .
|
376 |
|
|
protected virtual function void do_establish_link(uvm_link_base link);
|
377 |
|
|
uvm_recorder r_lhs, r_rhs;
|
378 |
|
|
uvm_object lhs = link.get_lhs();
|
379 |
|
|
uvm_object rhs = link.get_rhs();
|
380 |
|
|
|
381 |
|
|
void'($cast(r_lhs, lhs));
|
382 |
|
|
void'($cast(r_rhs, rhs));
|
383 |
|
|
|
384 |
|
|
if ((r_lhs == null) ||
|
385 |
|
|
(r_rhs == null))
|
386 |
|
|
return;
|
387 |
|
|
else begin
|
388 |
|
|
uvm_parent_child_link pc_link;
|
389 |
|
|
uvm_related_link re_link;
|
390 |
|
|
if ($cast(pc_link, link)) begin
|
391 |
|
|
$fdisplay(m_file," LINK @%0t {TXH1:%0d TXH2:%0d RELATION=%0s}",
|
392 |
|
|
$time,
|
393 |
|
|
r_lhs.get_handle(),
|
394 |
|
|
r_rhs.get_handle(),
|
395 |
|
|
"child");
|
396 |
|
|
|
397 |
|
|
end
|
398 |
|
|
else if ($cast(re_link, link)) begin
|
399 |
|
|
$fdisplay(m_file," LINK @%0t {TXH1:%0d TXH2:%0d RELATION=%0s}",
|
400 |
|
|
$time,
|
401 |
|
|
r_lhs.get_handle(),
|
402 |
|
|
r_rhs.get_handle(),
|
403 |
|
|
"");
|
404 |
|
|
|
405 |
|
|
end
|
406 |
|
|
end
|
407 |
|
|
endfunction : do_establish_link
|
408 |
|
|
|
409 |
|
|
// Group: Implementation Specific API
|
410 |
|
|
|
411 |
|
|
// Function: set_file_name
|
412 |
|
|
// Sets the file name which will be used for output.
|
413 |
|
|
//
|
414 |
|
|
// The ~set_file_name~ method can only be called prior to ~open_db~.
|
415 |
|
|
//
|
416 |
|
|
// By default, the database will use a file named "tr_db.log".
|
417 |
|
|
function void set_file_name(string filename);
|
418 |
|
|
if (filename == "") begin
|
419 |
|
|
`uvm_warning("UVM/TXT_DB/EMPTY_NAME",
|
420 |
|
|
"Ignoring attempt to set file name to ''!")
|
421 |
|
|
return;
|
422 |
|
|
end
|
423 |
|
|
|
424 |
|
|
if (!m_filename_dap.try_set(filename)) begin
|
425 |
|
|
`uvm_warning("UVM/TXT_DB/SET_AFTER_OPEN",
|
426 |
|
|
"Ignoring attempt to change file name after opening the db!")
|
427 |
|
|
return;
|
428 |
|
|
end
|
429 |
|
|
endfunction : set_file_name
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
endclass : uvm_text_tr_database
|