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 = NULL;
32 this->in_assignee = false;
36 ir_hierarchical_visitor::visit(ir_rvalue *ir)
38 if (this->callback != NULL)
39 this->callback(ir, this->data);
41 return visit_continue;
45 ir_hierarchical_visitor::visit(ir_variable *ir)
47 if (this->callback != NULL)
48 this->callback(ir, this->data);
50 return visit_continue;
54 ir_hierarchical_visitor::visit(ir_constant *ir)
56 if (this->callback != NULL)
57 this->callback(ir, this->data);
59 return visit_continue;
63 ir_hierarchical_visitor::visit(ir_loop_jump *ir)
65 if (this->callback != NULL)
66 this->callback(ir, this->data);
68 return visit_continue;
72 ir_hierarchical_visitor::visit(ir_dereference_variable *ir)
74 if (this->callback != NULL)
75 this->callback(ir, this->data);
77 return visit_continue;
81 ir_hierarchical_visitor::visit_enter(ir_loop *ir)
83 if (this->callback != NULL)
84 this->callback(ir, this->data);
86 return visit_continue;
90 ir_hierarchical_visitor::visit_leave(ir_loop *ir)
93 return visit_continue;
97 ir_hierarchical_visitor::visit_enter(ir_function_signature *ir)
99 if (this->callback != NULL)
100 this->callback(ir, this->data);
102 return visit_continue;
106 ir_hierarchical_visitor::visit_leave(ir_function_signature *ir)
109 return visit_continue;
113 ir_hierarchical_visitor::visit_enter(ir_function *ir)
115 if (this->callback != NULL)
116 this->callback(ir, this->data);
118 return visit_continue;
122 ir_hierarchical_visitor::visit_leave(ir_function *ir)
125 return visit_continue;
129 ir_hierarchical_visitor::visit_enter(ir_expression *ir)
131 if (this->callback != NULL)
132 this->callback(ir, this->data);
134 return visit_continue;
138 ir_hierarchical_visitor::visit_leave(ir_expression *ir)
141 return visit_continue;
145 ir_hierarchical_visitor::visit_enter(ir_texture *ir)
147 if (this->callback != NULL)
148 this->callback(ir, this->data);
150 return visit_continue;
154 ir_hierarchical_visitor::visit_leave(ir_texture *ir)
157 return visit_continue;
161 ir_hierarchical_visitor::visit_enter(ir_swizzle *ir)
163 if (this->callback != NULL)
164 this->callback(ir, this->data);
166 return visit_continue;
170 ir_hierarchical_visitor::visit_leave(ir_swizzle *ir)
173 return visit_continue;
177 ir_hierarchical_visitor::visit_enter(ir_dereference_array *ir)
179 if (this->callback != NULL)
180 this->callback(ir, this->data);
182 return visit_continue;
186 ir_hierarchical_visitor::visit_leave(ir_dereference_array *ir)
189 return visit_continue;
193 ir_hierarchical_visitor::visit_enter(ir_dereference_record *ir)
195 if (this->callback != NULL)
196 this->callback(ir, this->data);
198 return visit_continue;
202 ir_hierarchical_visitor::visit_leave(ir_dereference_record *ir)
205 return visit_continue;
209 ir_hierarchical_visitor::visit_enter(ir_assignment *ir)
211 if (this->callback != NULL)
212 this->callback(ir, this->data);
214 return visit_continue;
218 ir_hierarchical_visitor::visit_leave(ir_assignment *ir)
221 return visit_continue;
225 ir_hierarchical_visitor::visit_enter(ir_call *ir)
227 if (this->callback != NULL)
228 this->callback(ir, this->data);
230 return visit_continue;
234 ir_hierarchical_visitor::visit_leave(ir_call *ir)
237 return visit_continue;
241 ir_hierarchical_visitor::visit_enter(ir_return *ir)
243 if (this->callback != NULL)
244 this->callback(ir, this->data);
246 return visit_continue;
250 ir_hierarchical_visitor::visit_leave(ir_return *ir)
253 return visit_continue;
257 ir_hierarchical_visitor::visit_enter(ir_discard *ir)
259 if (this->callback != NULL)
260 this->callback(ir, this->data);
262 return visit_continue;
266 ir_hierarchical_visitor::visit_leave(ir_discard *ir)
269 return visit_continue;
273 ir_hierarchical_visitor::visit_enter(ir_if *ir)
275 if (this->callback != NULL)
276 this->callback(ir, this->data);
278 return visit_continue;
282 ir_hierarchical_visitor::visit_leave(ir_if *ir)
285 return visit_continue;
289 ir_hierarchical_visitor::run(exec_list *instructions)
291 visit_list_elements(this, instructions);
296 visit_tree(ir_instruction *ir,
297 void (*callback)(class ir_instruction *ir, void *data),
300 ir_hierarchical_visitor v;
302 v.callback = callback;