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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_queue.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
 
24
`ifndef UVM_QUEUE_SVH
25
`define UVM_QUEUE_SVH
26
 
27
//------------------------------------------------------------------------------
28
//
29
// CLASS: uvm_queue #(T)
30
//
31
//------------------------------------------------------------------------------
32
// Implements a class-based dynamic queue. Allows queues to be allocated on
33
// demand, and passed and stored by reference.
34
//------------------------------------------------------------------------------
35
 
36
class uvm_queue #(type T=int) extends uvm_object;
37
 
38
  const static string type_name = "uvm_queue";
39
 
40
  typedef uvm_queue #(T) this_type;
41
 
42
  static local this_type m_global_queue;
43
  protected T queue[$];
44
 
45
  // Function: new
46
  //
47
  // Creates a new queue with the given ~name~.
48
 
49
  function new (string name="");
50
    super.new(name);
51
  endfunction
52
 
53
 
54
  // Function: get_global_queue
55
  //
56
  // Returns the singleton global queue 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_queue ();
62
    if (m_global_queue==null)
63
      m_global_queue = new("global_queue");
64
    return m_global_queue;
65
  endfunction
66
 
67
 
68
  // Function: get_global
69
  //
70
  // Returns the specified item instance from the global item queue.
71
 
72
  static function T get_global (int index);
73
    this_type gqueue;
74
    gqueue = get_global_queue();
75
    return gqueue.get(index);
76
  endfunction
77
 
78
 
79
  // Function: get
80
  //
81
  // Returns the item at the given ~index~.
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 (int index);
87
    T default_value;
88
    if (index >= size() || index < 0) begin
89
      uvm_report_warning("QUEUEGET",
90
        $sformatf("get: given index out of range for queue of size %0d. Ignoring get request",size()));
91
      return default_value;
92
    end
93
    return queue[index];
94
  endfunction
95
 
96
 
97
  // Function: size
98
  //
99
  // Returns the number of items stored in the queue.
100
 
101
  virtual function int size ();
102
    return queue.size();
103
  endfunction
104
 
105
 
106
  // Function: insert
107
  //
108
  // Inserts the item at the given ~index~ in the queue.
109
 
110
  virtual function void insert (int index, T item);
111
    if (index >= size() || index < 0) begin
112
      uvm_report_warning("QUEUEINS",
113
        $sformatf("insert: given index out of range for queue of size %0d. Ignoring insert request",size()));
114
      return;
115
    end
116
    queue.insert(index,item);
117
  endfunction
118
 
119
 
120
  // Function: delete
121
  //
122
  // Removes the item at the given ~index~ from the queue; if ~index~ is
123
  // not provided, the entire contents of the queue are deleted.
124
 
125
  virtual function void delete (int index=-1);
126
    if (index >= size() || index < -1) begin
127
      uvm_report_warning("QUEUEDEL",
128
        $sformatf("delete: given index out of range for queue of size %0d. Ignoring delete request",size()));
129
      return;
130
    end
131
    if (index == -1)
132
      queue.delete();
133
    else
134
      queue.delete(index);
135
  endfunction
136
 
137
 
138
  // Function: pop_front
139
  //
140
  // Returns the first element in the queue (index=0),
141
  // or ~null~ if the queue is empty.
142
 
143
  virtual function T pop_front();
144
    return queue.pop_front();
145
  endfunction
146
 
147
 
148
  // Function: pop_back
149
  //
150
  // Returns the last element in the queue (index=size()-1),
151
  // or ~null~ if the queue is empty.
152
 
153
  virtual function T pop_back();
154
    return queue.pop_back();
155
  endfunction
156
 
157
 
158
  // Function: push_front
159
  //
160
  // Inserts the given ~item~ at the front of the queue.
161
 
162
  virtual function void push_front(T item);
163
    queue.push_front(item);
164
  endfunction
165
 
166
 
167
  // Function: push_back
168
  //
169
  // Inserts the given ~item~ at the back of the queue.
170
 
171
  virtual function void push_back(T item);
172
    queue.push_back(item);
173
  endfunction
174
 
175
 
176
  virtual function uvm_object create (string name="");
177
    this_type v;
178
    v=new(name);
179
    return v;
180
  endfunction
181
 
182
  virtual function string get_type_name ();
183
    return type_name;
184
  endfunction
185
 
186
  virtual function void do_copy (uvm_object rhs);
187
    this_type p;
188
    super.do_copy(rhs);
189
    if (rhs == null || !$cast(p, rhs))
190
      return;
191
    queue = p.queue;
192
  endfunction
193
 
194
  virtual function string convert2string();
195
      return $sformatf("%p",queue);
196
  endfunction
197
 
198
 
199
endclass
200
 
201
 
202
`endif // UVM_QUEUE_SVH
203
 

powered by: WebSVN 2.1.0

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