1 |
16 |
HanySalah |
//----------------------------------------------------------------------
|
2 |
|
|
// Copyright 2013 Cadence Design Systems, Inc.
|
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 |
|
|
//------------------------------------------------------------------------------
|
21 |
|
|
//
|
22 |
|
|
// CLASS: uvm_visitor #(NODE)
|
23 |
|
|
//
|
24 |
|
|
// The uvm_visitor class provides an abstract base class for a visitor. The visitor
|
25 |
|
|
// visits instances of type NODE. For general information regarding the visitor pattern
|
26 |
|
|
// see http://en.wikipedia.org/wiki/Visitor_pattern
|
27 |
|
|
//
|
28 |
|
|
//------------------------------------------------------------------------------
|
29 |
|
|
|
30 |
|
|
virtual class uvm_visitor#(type NODE=uvm_component) extends uvm_object;
|
31 |
|
|
function new (string name = "");
|
32 |
|
|
super.new(name);
|
33 |
|
|
endfunction
|
34 |
|
|
// Function: begin_v
|
35 |
|
|
//
|
36 |
|
|
// This method will be invoked by the visitor before the first NODE is visited
|
37 |
|
|
|
38 |
|
|
virtual function void begin_v(); endfunction
|
39 |
|
|
|
40 |
|
|
// Function: end_v
|
41 |
|
|
//
|
42 |
|
|
// This method will be invoked by the visitor after the last NODE is visited
|
43 |
|
|
|
44 |
|
|
virtual function void end_v(); endfunction
|
45 |
|
|
|
46 |
|
|
// Function: visit
|
47 |
|
|
//
|
48 |
|
|
// This method will be invoked by the visitor for every visited ~node~ of the provided structure.
|
49 |
|
|
// The user is expected to provide the own functionality in this function.
|
50 |
|
|
//
|
51 |
|
|
//| class count_nodes_visitor#(type T=uvm_component) extends uvm_visitor#(T);
|
52 |
|
|
//| function new (string name = "");
|
53 |
|
|
//| super.new(name);
|
54 |
|
|
//| endfunction
|
55 |
|
|
//| local int cnt;
|
56 |
|
|
//| virtual function void begin_v(); cnt = 0; endfunction
|
57 |
|
|
//| virtual function void end_v(); `uvm_info("TEXT",$sformatf("%d elements",cnt),UVM_NONE) endfunction
|
58 |
|
|
//| virtual function void visit(T node); cnt++; endfunction
|
59 |
|
|
//| endclass
|
60 |
|
|
pure virtual function void visit(NODE node);
|
61 |
|
|
endclass
|
62 |
|
|
|
63 |
|
|
//------------------------------------------------------------------------------
|
64 |
|
|
//
|
65 |
|
|
// CLASS: uvm_structure_proxy #(STRUCTURE)
|
66 |
|
|
//
|
67 |
|
|
// The uvm_structure_proxy is a wrapper and provides a set of elements
|
68 |
|
|
// of the STRUCTURE to the caller on demand. This is to decouple the retrieval of
|
69 |
|
|
// the STRUCTUREs subelements from the actual function being invoked on STRUCTURE
|
70 |
|
|
//
|
71 |
|
|
//------------------------------------------------------------------------------
|
72 |
|
|
|
73 |
|
|
virtual class uvm_structure_proxy#(type STRUCTURE=uvm_component) extends uvm_object;
|
74 |
|
|
function new (string name = "");
|
75 |
|
|
super.new(name);
|
76 |
|
|
endfunction
|
77 |
|
|
// Function: get_immediate_children
|
78 |
|
|
//
|
79 |
|
|
// This method will be return in ~children~ a set of the direct subelements of ~s~
|
80 |
|
|
|
81 |
|
|
pure virtual function void get_immediate_children(STRUCTURE s, ref STRUCTURE children[$]);
|
82 |
|
|
endclass
|
83 |
|
|
|
84 |
|
|
//------------------------------------------------------------------------------
|
85 |
|
|
//
|
86 |
|
|
// CLASS: uvm_visitor_adapter #(STRUCTURE,uvm_visitor#(STRUCTURE))
|
87 |
|
|
//
|
88 |
|
|
// The visitor adaptor traverses all nodes of the STRUCTURE and will invoke visitor.visit() on every node.
|
89 |
|
|
//
|
90 |
|
|
//------------------------------------------------------------------------------
|
91 |
|
|
|
92 |
|
|
virtual class uvm_visitor_adapter#(type STRUCTURE=uvm_component,VISITOR=uvm_visitor#(STRUCTURE)) extends uvm_object;
|
93 |
|
|
// Function: accept()
|
94 |
|
|
//
|
95 |
|
|
// Calling this function will traverse through ~s~ (and every subnode of ~s~). For each node found
|
96 |
|
|
// ~v~.visit(node) will be invoked. The children of ~s~ are recursively determined
|
97 |
|
|
// by invoking ~p~.get_immediate_children().~invoke_begin_end~ determines whether the visitors begin/end functions
|
98 |
|
|
// should be invoked prior to traversal.
|
99 |
|
|
|
100 |
|
|
pure virtual function void accept(STRUCTURE s, VISITOR v,uvm_structure_proxy#(STRUCTURE) p, bit invoke_begin_end=1);
|
101 |
|
|
function new (string name = "");
|
102 |
|
|
super.new(name);
|
103 |
|
|
endfunction
|
104 |
|
|
endclass
|
105 |
|
|
|
106 |
|
|
//------------------------------------------------------------------------------
|
107 |
|
|
//
|
108 |
|
|
// CLASS: uvm_top_down_visitor_adapter
|
109 |
|
|
//
|
110 |
|
|
// This uvm_top_down_visitor_adapter traverses the STRUCTURE ~s~ (and will invoke the visitor) in a hierarchical fashion.
|
111 |
|
|
// During traversal ~s~ will be visited before all subnodes of ~s~ will be visited.
|
112 |
|
|
//
|
113 |
|
|
//------------------------------------------------------------------------------
|
114 |
|
|
|
115 |
|
|
class uvm_top_down_visitor_adapter#(type STRUCTURE=uvm_component,VISITOR=uvm_visitor#(STRUCTURE)) extends
|
116 |
|
|
uvm_visitor_adapter#(STRUCTURE,VISITOR);
|
117 |
|
|
function new (string name = "");
|
118 |
|
|
super.new(name);
|
119 |
|
|
endfunction
|
120 |
|
|
virtual function void accept(STRUCTURE s, VISITOR v,uvm_structure_proxy#(STRUCTURE) p, bit invoke_begin_end=1);
|
121 |
|
|
STRUCTURE c[$];
|
122 |
|
|
|
123 |
|
|
if(invoke_begin_end)
|
124 |
|
|
v.begin_v();
|
125 |
|
|
|
126 |
|
|
v.visit(s);
|
127 |
|
|
p.get_immediate_children(s, c);
|
128 |
|
|
|
129 |
|
|
foreach(c[idx])
|
130 |
|
|
accept(c[idx],v,p,0);
|
131 |
|
|
|
132 |
|
|
if(invoke_begin_end)
|
133 |
|
|
v.end_v();
|
134 |
|
|
|
135 |
|
|
endfunction
|
136 |
|
|
endclass
|
137 |
|
|
|
138 |
|
|
//------------------------------------------------------------------------------
|
139 |
|
|
//
|
140 |
|
|
// CLASS: uvm_bottom_up_visitor_adapter
|
141 |
|
|
//
|
142 |
|
|
// This uvm_bottom_up_visitor_adapter traverses the STRUCTURE ~s~ (and will invoke the visitor) in a hierarchical fashion.
|
143 |
|
|
// During traversal all children of node ~s~ will be visited ~s~ will be visited.
|
144 |
|
|
//
|
145 |
|
|
//------------------------------------------------------------------------------
|
146 |
|
|
|
147 |
|
|
class uvm_bottom_up_visitor_adapter#(type STRUCTURE=uvm_component,VISITOR=uvm_visitor#(STRUCTURE)) extends
|
148 |
|
|
uvm_visitor_adapter#(STRUCTURE,VISITOR);
|
149 |
|
|
function new (string name = "");
|
150 |
|
|
super.new(name);
|
151 |
|
|
endfunction
|
152 |
|
|
virtual function void accept(STRUCTURE s, VISITOR v,uvm_structure_proxy#(STRUCTURE) p, bit invoke_begin_end=1);
|
153 |
|
|
STRUCTURE c[$];
|
154 |
|
|
|
155 |
|
|
if(invoke_begin_end)
|
156 |
|
|
v.begin_v();
|
157 |
|
|
|
158 |
|
|
p.get_immediate_children(s, c);
|
159 |
|
|
foreach(c[idx])
|
160 |
|
|
accept(c[idx],v,p,0);
|
161 |
|
|
|
162 |
|
|
v.visit(s);
|
163 |
|
|
|
164 |
|
|
if(invoke_begin_end)
|
165 |
|
|
v.end_v();
|
166 |
|
|
|
167 |
|
|
endfunction
|
168 |
|
|
endclass
|
169 |
|
|
|
170 |
|
|
//------------------------------------------------------------------------------
|
171 |
|
|
//
|
172 |
|
|
// CLASS: uvm_by_level_visitor_adapter
|
173 |
|
|
//
|
174 |
|
|
// This uvm_by_level_visitor_adapter traverses the STRUCTURE ~s~ (and will invoke the visitor) in a hierarchical fashion.
|
175 |
|
|
// During traversal will visit all direct children of ~s~ before all grand-children are visited.
|
176 |
|
|
//------------------------------------------------------------------------------
|
177 |
|
|
|
178 |
|
|
class uvm_by_level_visitor_adapter#(type STRUCTURE=uvm_component,VISITOR=uvm_visitor#(STRUCTURE)) extends
|
179 |
|
|
uvm_visitor_adapter#(STRUCTURE,VISITOR);
|
180 |
|
|
function new (string name = "");
|
181 |
|
|
super.new(name);
|
182 |
|
|
endfunction
|
183 |
|
|
virtual function void accept(STRUCTURE s, VISITOR v,uvm_structure_proxy#(STRUCTURE) p, bit invoke_begin_end=1);
|
184 |
|
|
STRUCTURE c[$];
|
185 |
|
|
c.push_back(s);
|
186 |
|
|
|
187 |
|
|
if(invoke_begin_end)
|
188 |
|
|
v.begin_v();
|
189 |
|
|
|
190 |
|
|
while(c.size() > 0) begin
|
191 |
|
|
STRUCTURE q[$];
|
192 |
|
|
foreach(c[idx]) begin
|
193 |
|
|
STRUCTURE t[$];
|
194 |
|
|
|
195 |
|
|
v.visit(c[idx]);
|
196 |
|
|
p.get_immediate_children(c[idx], t);
|
197 |
|
|
q = {q,t};
|
198 |
|
|
end
|
199 |
|
|
c=q;
|
200 |
|
|
end
|
201 |
|
|
|
202 |
|
|
if(invoke_begin_end)
|
203 |
|
|
v.end_v();
|
204 |
|
|
endfunction
|
205 |
|
|
endclass
|
206 |
|
|
|
207 |
|
|
//------------------------------------------------------------------------------
|
208 |
|
|
//
|
209 |
|
|
// CLASS: uvm_component_proxy
|
210 |
|
|
//
|
211 |
|
|
// The class is providing the proxy to extract the direct subcomponents of ~s~
|
212 |
|
|
//------------------------------------------------------------------------------
|
213 |
|
|
|
214 |
|
|
class uvm_component_proxy extends uvm_structure_proxy#(uvm_component);
|
215 |
|
|
virtual function void get_immediate_children(STRUCTURE s, ref STRUCTURE children[$]);
|
216 |
|
|
s.get_children(children);
|
217 |
|
|
endfunction
|
218 |
|
|
|
219 |
|
|
function new (string name = "");
|
220 |
|
|
super.new(name);
|
221 |
|
|
endfunction
|
222 |
|
|
endclass
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
//------------------------------------------------------------------------------
|
226 |
|
|
//
|
227 |
|
|
// CLASS: uvm_component_name_check_visitor
|
228 |
|
|
//
|
229 |
|
|
// This specialized visitor analyze the naming of the current component. The established rule set
|
230 |
|
|
// ensures that a component.get_full_name() is parsable, unique, printable to order to avoid any ambiguities
|
231 |
|
|
// when messages are being emitted.
|
232 |
|
|
//
|
233 |
|
|
// ruleset a legal name is composed of
|
234 |
|
|
// - allowed charset "A-z:_0-9[](){}-: "
|
235 |
|
|
// - whitespace-as-is, no-balancing delimiter semantic, no escape sequences
|
236 |
|
|
// - path delimiter not allowed anywhere in the name
|
237 |
|
|
//
|
238 |
|
|
// the check is coded here as a function to complete it in a single function call
|
239 |
|
|
// otherwise save/restore issues with the used dpi could occur
|
240 |
|
|
//------------------------------------------------------------------------------
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
class uvm_component_name_check_visitor extends uvm_visitor#(uvm_component);
|
244 |
|
|
local uvm_root _root;
|
245 |
|
|
|
246 |
|
|
// Function: get_name_constraint
|
247 |
|
|
//
|
248 |
|
|
// This method should return a regex for what is being considered a valid/good component name.
|
249 |
|
|
// The visitor will check all component names using this regex and report failing names
|
250 |
|
|
|
251 |
|
|
virtual function string get_name_constraint();
|
252 |
|
|
return "^[][[:alnum:](){}_:-]([][[:alnum:](){} _:-]*[][[:alnum:](){}_:-])?$";
|
253 |
|
|
endfunction
|
254 |
|
|
|
255 |
|
|
virtual function void visit(NODE node);
|
256 |
|
|
`ifndef UVM_NO_DPI
|
257 |
|
|
static chandle compiled_regex;
|
258 |
|
|
|
259 |
|
|
if(compiled_regex==null)
|
260 |
|
|
compiled_regex=uvm_dpi_regcomp(get_name_constraint());
|
261 |
|
|
|
262 |
|
|
assert(compiled_regex!=null);
|
263 |
|
|
|
264 |
|
|
// dont check the root component
|
265 |
|
|
if(_root != node)
|
266 |
|
|
if(uvm_dpi_regexec(compiled_regex, node.get_name()))
|
267 |
|
|
`uvm_warning("UVM/COMP/NAME",$sformatf("the name \"%s\" of the component \"%s\" violates the uvm component name constraints",node.get_name(),node.get_full_name()))
|
268 |
|
|
`endif
|
269 |
|
|
endfunction
|
270 |
|
|
function new (string name = "");
|
271 |
|
|
super.new(name);
|
272 |
|
|
endfunction
|
273 |
|
|
|
274 |
|
|
virtual function void begin_v();
|
275 |
|
|
uvm_coreservice_t cs = uvm_coreservice_t::get();
|
276 |
|
|
|
277 |
|
|
_root = cs.get_root();
|
278 |
|
|
`ifdef UVM_NO_DPI
|
279 |
|
|
`uvm_info("UVM/COMP/NAMECHECK","This implementation of the component name checks requires DPI to be enabled",UVM_NONE)
|
280 |
|
|
`endif
|
281 |
|
|
endfunction
|
282 |
|
|
virtual function void end_v();
|
283 |
|
|
`ifndef UVM_NO_DPI
|
284 |
|
|
uvm_dpi_regfree(visit.compiled_regex);
|
285 |
|
|
visit.compiled_regex=null;
|
286 |
|
|
`endif
|
287 |
|
|
endfunction
|
288 |
|
|
endclass
|