1 |
4 |
vladimirar |
//----------------------------------------------------------------------
|
2 |
|
|
// Copyright 2014-2015 SyoSil ApS
|
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 |
|
|
/// Queue iterator class defining the iterator API used for iterating std queues.
|
20 |
|
|
class cl_syoscb_queue_iterator_std extends cl_syoscb_queue_iterator_base;
|
21 |
|
|
//-------------------------------------
|
22 |
|
|
// UVM Macros
|
23 |
|
|
//-------------------------------------
|
24 |
|
|
`uvm_object_utils(cl_syoscb_queue_iterator_std)
|
25 |
|
|
|
26 |
|
|
function new(string name = "cl_syoscb_queue_iterator_std");
|
27 |
|
|
super.new(name);
|
28 |
|
|
endfunction: new
|
29 |
|
|
|
30 |
|
|
//-------------------------------------
|
31 |
|
|
// Iterator API
|
32 |
|
|
//-------------------------------------
|
33 |
|
|
extern virtual function bit next();
|
34 |
|
|
extern virtual function bit previous();
|
35 |
|
|
extern virtual function bit first();
|
36 |
|
|
extern virtual function bit last();
|
37 |
|
|
extern virtual function int unsigned get_idx();
|
38 |
|
|
extern virtual function cl_syoscb_item get_item();
|
39 |
|
|
extern virtual function bit is_done();
|
40 |
|
|
extern virtual function bit set_queue(cl_syoscb_queue owner);
|
41 |
|
|
endclass: cl_syoscb_queue_iterator_std
|
42 |
|
|
|
43 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
44 |
|
|
function bit cl_syoscb_queue_iterator_std::next();
|
45 |
|
|
cl_syoscb_queue qh = this.get_queue();
|
46 |
|
|
|
47 |
|
|
if(this.position < qh.get_size()) begin
|
48 |
|
|
this.position++;
|
49 |
|
|
return 1;
|
50 |
|
|
end else begin
|
51 |
|
|
// Debug print when unable to advance to the next element (When at the end of the queue)
|
52 |
|
|
`uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Not possible to increment position of queue %s: at end of queue",
|
53 |
|
|
this.cfg.get_scb_name(), qh.get_name()), UVM_DEBUG);
|
54 |
|
|
return 0;
|
55 |
|
|
end
|
56 |
|
|
endfunction: next
|
57 |
|
|
|
58 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
59 |
|
|
function bit cl_syoscb_queue_iterator_std::previous();
|
60 |
|
|
if(this.position != 0) begin
|
61 |
|
|
this.position--;
|
62 |
|
|
return 1;
|
63 |
|
|
end else begin
|
64 |
|
|
cl_syoscb_queue qh = this.get_queue();
|
65 |
|
|
|
66 |
|
|
// Debug print when unable to advance to the previous element (When at the beginning of the queue)
|
67 |
|
|
`uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Not possible to decrement position of queue %s: at end of queue",
|
68 |
|
|
this.cfg.get_scb_name(), qh.get_name()), UVM_DEBUG);
|
69 |
|
|
return 0;
|
70 |
|
|
end
|
71 |
|
|
endfunction: previous
|
72 |
|
|
|
73 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
74 |
|
|
function bit cl_syoscb_queue_iterator_std::first();
|
75 |
|
|
// Std queue uses an SV queue for its items, first item is always 0
|
76 |
|
|
this.position = 0;
|
77 |
|
|
return 1;
|
78 |
|
|
endfunction: first
|
79 |
|
|
|
80 |
|
|
function bit cl_syoscb_queue_iterator_std::last();
|
81 |
|
|
cl_syoscb_queue qh = this.get_queue();
|
82 |
|
|
|
83 |
|
|
this.position = qh.get_size()-1;
|
84 |
|
|
return 1;
|
85 |
|
|
endfunction: last
|
86 |
|
|
|
87 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
88 |
|
|
function int unsigned cl_syoscb_queue_iterator_std::get_idx();
|
89 |
|
|
return this.position;
|
90 |
|
|
endfunction: get_idx
|
91 |
|
|
|
92 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
93 |
|
|
function cl_syoscb_item cl_syoscb_queue_iterator_std::get_item();
|
94 |
|
|
cl_syoscb_queue qh = this.get_queue();
|
95 |
|
|
|
96 |
|
|
return qh.get_item(this.position);
|
97 |
|
|
endfunction: get_item
|
98 |
|
|
|
99 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
100 |
|
|
function bit cl_syoscb_queue_iterator_std::is_done();
|
101 |
|
|
cl_syoscb_queue qh = this.get_queue();
|
102 |
|
|
|
103 |
|
|
if(this.position == qh.get_size()) begin
|
104 |
|
|
return 1;
|
105 |
|
|
end else begin
|
106 |
|
|
return 0;
|
107 |
|
|
end
|
108 |
|
|
endfunction: is_done
|
109 |
|
|
|
110 |
|
|
/// Iterator API: See cl_syoscb_queue_iterator_base for details
|
111 |
|
|
function bit cl_syoscb_queue_iterator_std::set_queue(cl_syoscb_queue owner);
|
112 |
|
|
if(owner == null) begin
|
113 |
|
|
// An iterator should always have an associated queue
|
114 |
|
|
`uvm_error("QUEUE_ERROR", $sformatf("Unable to associate queue with iterator "));
|
115 |
|
|
return 0;
|
116 |
|
|
end else begin
|
117 |
|
|
this.owner = owner;
|
118 |
|
|
this.cfg = owner.get_cfg();
|
119 |
|
|
return 1;
|
120 |
|
|
end
|
121 |
|
|
endfunction: set_queue
|