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()
29 this->callback
= NULL
;
34 ir_hierarchical_visitor::visit(ir_variable
*ir
)
36 if (this->callback
!= NULL
)
37 this->callback(ir
, this->data
);
39 return visit_continue
;
43 ir_hierarchical_visitor::visit(ir_constant
*ir
)
45 if (this->callback
!= NULL
)
46 this->callback(ir
, this->data
);
48 return visit_continue
;
52 ir_hierarchical_visitor::visit(ir_loop_jump
*ir
)
54 if (this->callback
!= NULL
)
55 this->callback(ir
, this->data
);
57 return visit_continue
;
61 ir_hierarchical_visitor::visit(ir_dereference_variable
*ir
)
63 if (this->callback
!= NULL
)
64 this->callback(ir
, this->data
);
66 return visit_continue
;
70 ir_hierarchical_visitor::visit_enter(ir_loop
*ir
)
72 if (this->callback
!= NULL
)
73 this->callback(ir
, this->data
);
75 return visit_continue
;
79 ir_hierarchical_visitor::visit_leave(ir_loop
*ir
)
82 return visit_continue
;
86 ir_hierarchical_visitor::visit_enter(ir_function_signature
*ir
)
88 if (this->callback
!= NULL
)
89 this->callback(ir
, this->data
);
91 return visit_continue
;
95 ir_hierarchical_visitor::visit_leave(ir_function_signature
*ir
)
98 return visit_continue
;
102 ir_hierarchical_visitor::visit_enter(ir_function
*ir
)
104 if (this->callback
!= NULL
)
105 this->callback(ir
, this->data
);
107 return visit_continue
;
111 ir_hierarchical_visitor::visit_leave(ir_function
*ir
)
114 return visit_continue
;
118 ir_hierarchical_visitor::visit_enter(ir_expression
*ir
)
120 if (this->callback
!= NULL
)
121 this->callback(ir
, this->data
);
123 return visit_continue
;
127 ir_hierarchical_visitor::visit_leave(ir_expression
*ir
)
130 return visit_continue
;
134 ir_hierarchical_visitor::visit_enter(ir_texture
*ir
)
136 if (this->callback
!= NULL
)
137 this->callback(ir
, this->data
);
139 return visit_continue
;
143 ir_hierarchical_visitor::visit_leave(ir_texture
*ir
)
146 return visit_continue
;
150 ir_hierarchical_visitor::visit_enter(ir_swizzle
*ir
)
152 if (this->callback
!= NULL
)
153 this->callback(ir
, this->data
);
155 return visit_continue
;
159 ir_hierarchical_visitor::visit_leave(ir_swizzle
*ir
)
162 return visit_continue
;
166 ir_hierarchical_visitor::visit_enter(ir_dereference_array
*ir
)
168 if (this->callback
!= NULL
)
169 this->callback(ir
, this->data
);
171 return visit_continue
;
175 ir_hierarchical_visitor::visit_leave(ir_dereference_array
*ir
)
178 return visit_continue
;
182 ir_hierarchical_visitor::visit_enter(ir_dereference_record
*ir
)
184 if (this->callback
!= NULL
)
185 this->callback(ir
, this->data
);
187 return visit_continue
;
191 ir_hierarchical_visitor::visit_leave(ir_dereference_record
*ir
)
194 return visit_continue
;
198 ir_hierarchical_visitor::visit_enter(ir_assignment
*ir
)
200 if (this->callback
!= NULL
)
201 this->callback(ir
, this->data
);
203 return visit_continue
;
207 ir_hierarchical_visitor::visit_leave(ir_assignment
*ir
)
210 return visit_continue
;
214 ir_hierarchical_visitor::visit_enter(ir_call
*ir
)
216 if (this->callback
!= NULL
)
217 this->callback(ir
, this->data
);
219 return visit_continue
;
223 ir_hierarchical_visitor::visit_leave(ir_call
*ir
)
226 return visit_continue
;
230 ir_hierarchical_visitor::visit_enter(ir_return
*ir
)
232 if (this->callback
!= NULL
)
233 this->callback(ir
, this->data
);
235 return visit_continue
;
239 ir_hierarchical_visitor::visit_leave(ir_return
*ir
)
242 return visit_continue
;
246 ir_hierarchical_visitor::visit_enter(ir_if
*ir
)
248 if (this->callback
!= NULL
)
249 this->callback(ir
, this->data
);
251 return visit_continue
;
255 ir_hierarchical_visitor::visit_leave(ir_if
*ir
)
258 return visit_continue
;
262 ir_hierarchical_visitor::run(exec_list
*instructions
)
264 foreach_list(n
, instructions
) {
265 ir_instruction
*ir
= (ir_instruction
*) n
;
267 if (ir
->accept(this) != visit_continue
)