2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 #include "ir_hierarchical_visitor.h"
27 ir_hierarchical_visitor::ir_hierarchical_visitor()
30 this->callback_enter
= NULL
;
31 this->callback_leave
= NULL
;
32 this->data_enter
= NULL
;
33 this->data_leave
= NULL
;
34 this->in_assignee
= false;
38 ir_hierarchical_visitor::visit(ir_rvalue
*ir
)
40 if (this->callback_enter
!= NULL
)
41 this->callback_enter(ir
, this->data_enter
);
43 return visit_continue
;
47 ir_hierarchical_visitor::visit(ir_variable
*ir
)
49 if (this->callback_enter
!= NULL
)
50 this->callback_enter(ir
, this->data_enter
);
52 return visit_continue
;
56 ir_hierarchical_visitor::visit(ir_constant
*ir
)
58 if (this->callback_enter
!= NULL
)
59 this->callback_enter(ir
, this->data_enter
);
61 return visit_continue
;
65 ir_hierarchical_visitor::visit(ir_loop_jump
*ir
)
67 if (this->callback_enter
!= NULL
)
68 this->callback_enter(ir
, this->data_enter
);
70 return visit_continue
;
74 ir_hierarchical_visitor::visit(ir_dereference_variable
*ir
)
76 if (this->callback_enter
!= NULL
)
77 this->callback_enter(ir
, this->data_enter
);
79 return visit_continue
;
83 ir_hierarchical_visitor::visit_enter(ir_loop
*ir
)
85 if (this->callback_enter
!= NULL
)
86 this->callback_enter(ir
, this->data_enter
);
88 return visit_continue
;
92 ir_hierarchical_visitor::visit_leave(ir_loop
*ir
)
94 if (this->callback_leave
!= NULL
)
95 this->callback_leave(ir
, this->data_leave
);
97 return visit_continue
;
101 ir_hierarchical_visitor::visit_enter(ir_function_signature
*ir
)
103 if (this->callback_enter
!= NULL
)
104 this->callback_enter(ir
, this->data_enter
);
106 return visit_continue
;
110 ir_hierarchical_visitor::visit_leave(ir_function_signature
*ir
)
112 if (this->callback_leave
!= NULL
)
113 this->callback_leave(ir
, this->data_leave
);
115 return visit_continue
;
119 ir_hierarchical_visitor::visit_enter(ir_function
*ir
)
121 if (this->callback_enter
!= NULL
)
122 this->callback_enter(ir
, this->data_enter
);
124 return visit_continue
;
128 ir_hierarchical_visitor::visit_leave(ir_function
*ir
)
130 if (this->callback_leave
!= NULL
)
131 this->callback_leave(ir
, this->data_leave
);
133 return visit_continue
;
137 ir_hierarchical_visitor::visit_enter(ir_expression
*ir
)
139 if (this->callback_enter
!= NULL
)
140 this->callback_enter(ir
, this->data_enter
);
142 return visit_continue
;
146 ir_hierarchical_visitor::visit_leave(ir_expression
*ir
)
148 if (this->callback_leave
!= NULL
)
149 this->callback_leave(ir
, this->data_leave
);
151 return visit_continue
;
155 ir_hierarchical_visitor::visit_enter(ir_texture
*ir
)
157 if (this->callback_enter
!= NULL
)
158 this->callback_enter(ir
, this->data_enter
);
160 return visit_continue
;
164 ir_hierarchical_visitor::visit_leave(ir_texture
*ir
)
166 if (this->callback_leave
!= NULL
)
167 this->callback_leave(ir
, this->data_leave
);
169 return visit_continue
;
173 ir_hierarchical_visitor::visit_enter(ir_swizzle
*ir
)
175 if (this->callback_enter
!= NULL
)
176 this->callback_enter(ir
, this->data_enter
);
178 return visit_continue
;
182 ir_hierarchical_visitor::visit_leave(ir_swizzle
*ir
)
184 if (this->callback_leave
!= NULL
)
185 this->callback_leave(ir
, this->data_leave
);
187 return visit_continue
;
191 ir_hierarchical_visitor::visit_enter(ir_dereference_array
*ir
)
193 if (this->callback_enter
!= NULL
)
194 this->callback_enter(ir
, this->data_enter
);
196 return visit_continue
;
200 ir_hierarchical_visitor::visit_leave(ir_dereference_array
*ir
)
202 if (this->callback_leave
!= NULL
)
203 this->callback_leave(ir
, this->data_leave
);
205 return visit_continue
;
209 ir_hierarchical_visitor::visit_enter(ir_dereference_record
*ir
)
211 if (this->callback_enter
!= NULL
)
212 this->callback_enter(ir
, this->data_enter
);
214 return visit_continue
;
218 ir_hierarchical_visitor::visit_leave(ir_dereference_record
*ir
)
220 if (this->callback_leave
!= NULL
)
221 this->callback_leave(ir
, this->data_leave
);
223 return visit_continue
;
227 ir_hierarchical_visitor::visit_enter(ir_assignment
*ir
)
229 if (this->callback_enter
!= NULL
)
230 this->callback_enter(ir
, this->data_enter
);
232 return visit_continue
;
236 ir_hierarchical_visitor::visit_leave(ir_assignment
*ir
)
238 if (this->callback_leave
!= NULL
)
239 this->callback_leave(ir
, this->data_leave
);
241 return visit_continue
;
245 ir_hierarchical_visitor::visit_enter(ir_call
*ir
)
247 if (this->callback_enter
!= NULL
)
248 this->callback_enter(ir
, this->data_enter
);
250 return visit_continue
;
254 ir_hierarchical_visitor::visit_leave(ir_call
*ir
)
256 if (this->callback_leave
!= NULL
)
257 this->callback_leave(ir
, this->data_leave
);
259 return visit_continue
;
263 ir_hierarchical_visitor::visit_enter(ir_return
*ir
)
265 if (this->callback_enter
!= NULL
)
266 this->callback_enter(ir
, this->data_enter
);
268 return visit_continue
;
272 ir_hierarchical_visitor::visit_leave(ir_return
*ir
)
274 if (this->callback_leave
!= NULL
)
275 this->callback_leave(ir
, this->data_leave
);
277 return visit_continue
;
281 ir_hierarchical_visitor::visit_enter(ir_discard
*ir
)
283 if (this->callback_enter
!= NULL
)
284 this->callback_enter(ir
, this->data_enter
);
286 return visit_continue
;
290 ir_hierarchical_visitor::visit_leave(ir_discard
*ir
)
292 if (this->callback_leave
!= NULL
)
293 this->callback_leave(ir
, this->data_leave
);
295 return visit_continue
;
299 ir_hierarchical_visitor::visit_enter(ir_if
*ir
)
301 if (this->callback_enter
!= NULL
)
302 this->callback_enter(ir
, this->data_enter
);
304 return visit_continue
;
308 ir_hierarchical_visitor::visit_leave(ir_if
*ir
)
310 if (this->callback_leave
!= NULL
)
311 this->callback_leave(ir
, this->data_leave
);
313 return visit_continue
;
317 ir_hierarchical_visitor::visit_enter(ir_emit_vertex
*ir
)
319 if (this->callback_enter
!= NULL
)
320 this->callback_enter(ir
, this->data_enter
);
322 return visit_continue
;
326 ir_hierarchical_visitor::visit_leave(ir_emit_vertex
*ir
)
328 if (this->callback_leave
!= NULL
)
329 this->callback_leave(ir
, this->data_leave
);
331 return visit_continue
;
335 ir_hierarchical_visitor::visit_enter(ir_end_primitive
*ir
)
337 if (this->callback_enter
!= NULL
)
338 this->callback_enter(ir
, this->data_enter
);
340 return visit_continue
;
344 ir_hierarchical_visitor::visit_leave(ir_end_primitive
*ir
)
346 if (this->callback_leave
!= NULL
)
347 this->callback_leave(ir
, this->data_leave
);
349 return visit_continue
;
353 ir_hierarchical_visitor::run(exec_list
*instructions
)
355 visit_list_elements(this, instructions
);
360 visit_tree(ir_instruction
*ir
,
361 void (*callback_enter
)(class ir_instruction
*ir
, void *data
),
363 void (*callback_leave
)(class ir_instruction
*ir
, void *data
),
366 ir_hierarchical_visitor v
;
368 v
.callback_enter
= callback_enter
;
369 v
.callback_leave
= callback_leave
;
370 v
.data_enter
= data_enter
;
371 v
.data_leave
= data_leave
;