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_variable
*ir
)
38 if (this->callback
!= NULL
)
39 this->callback(ir
, this->data
);
41 return visit_continue
;
45 ir_hierarchical_visitor::visit(ir_constant
*ir
)
47 if (this->callback
!= NULL
)
48 this->callback(ir
, this->data
);
50 return visit_continue
;
54 ir_hierarchical_visitor::visit(ir_loop_jump
*ir
)
56 if (this->callback
!= NULL
)
57 this->callback(ir
, this->data
);
59 return visit_continue
;
63 ir_hierarchical_visitor::visit(ir_dereference_variable
*ir
)
65 if (this->callback
!= NULL
)
66 this->callback(ir
, this->data
);
68 return visit_continue
;
72 ir_hierarchical_visitor::visit_enter(ir_loop
*ir
)
74 if (this->callback
!= NULL
)
75 this->callback(ir
, this->data
);
77 return visit_continue
;
81 ir_hierarchical_visitor::visit_leave(ir_loop
*ir
)
84 return visit_continue
;
88 ir_hierarchical_visitor::visit_enter(ir_function_signature
*ir
)
90 if (this->callback
!= NULL
)
91 this->callback(ir
, this->data
);
93 return visit_continue
;
97 ir_hierarchical_visitor::visit_leave(ir_function_signature
*ir
)
100 return visit_continue
;
104 ir_hierarchical_visitor::visit_enter(ir_function
*ir
)
106 if (this->callback
!= NULL
)
107 this->callback(ir
, this->data
);
109 return visit_continue
;
113 ir_hierarchical_visitor::visit_leave(ir_function
*ir
)
116 return visit_continue
;
120 ir_hierarchical_visitor::visit_enter(ir_expression
*ir
)
122 if (this->callback
!= NULL
)
123 this->callback(ir
, this->data
);
125 return visit_continue
;
129 ir_hierarchical_visitor::visit_leave(ir_expression
*ir
)
132 return visit_continue
;
136 ir_hierarchical_visitor::visit_enter(ir_texture
*ir
)
138 if (this->callback
!= NULL
)
139 this->callback(ir
, this->data
);
141 return visit_continue
;
145 ir_hierarchical_visitor::visit_leave(ir_texture
*ir
)
148 return visit_continue
;
152 ir_hierarchical_visitor::visit_enter(ir_swizzle
*ir
)
154 if (this->callback
!= NULL
)
155 this->callback(ir
, this->data
);
157 return visit_continue
;
161 ir_hierarchical_visitor::visit_leave(ir_swizzle
*ir
)
164 return visit_continue
;
168 ir_hierarchical_visitor::visit_enter(ir_dereference_array
*ir
)
170 if (this->callback
!= NULL
)
171 this->callback(ir
, this->data
);
173 return visit_continue
;
177 ir_hierarchical_visitor::visit_leave(ir_dereference_array
*ir
)
180 return visit_continue
;
184 ir_hierarchical_visitor::visit_enter(ir_dereference_record
*ir
)
186 if (this->callback
!= NULL
)
187 this->callback(ir
, this->data
);
189 return visit_continue
;
193 ir_hierarchical_visitor::visit_leave(ir_dereference_record
*ir
)
196 return visit_continue
;
200 ir_hierarchical_visitor::visit_enter(ir_assignment
*ir
)
202 if (this->callback
!= NULL
)
203 this->callback(ir
, this->data
);
205 return visit_continue
;
209 ir_hierarchical_visitor::visit_leave(ir_assignment
*ir
)
212 return visit_continue
;
216 ir_hierarchical_visitor::visit_enter(ir_call
*ir
)
218 if (this->callback
!= NULL
)
219 this->callback(ir
, this->data
);
221 return visit_continue
;
225 ir_hierarchical_visitor::visit_leave(ir_call
*ir
)
228 return visit_continue
;
232 ir_hierarchical_visitor::visit_enter(ir_return
*ir
)
234 if (this->callback
!= NULL
)
235 this->callback(ir
, this->data
);
237 return visit_continue
;
241 ir_hierarchical_visitor::visit_leave(ir_return
*ir
)
244 return visit_continue
;
248 ir_hierarchical_visitor::visit_enter(ir_discard
*ir
)
250 if (this->callback
!= NULL
)
251 this->callback(ir
, this->data
);
253 return visit_continue
;
257 ir_hierarchical_visitor::visit_leave(ir_discard
*ir
)
260 return visit_continue
;
264 ir_hierarchical_visitor::visit_enter(ir_if
*ir
)
266 if (this->callback
!= NULL
)
267 this->callback(ir
, this->data
);
269 return visit_continue
;
273 ir_hierarchical_visitor::visit_leave(ir_if
*ir
)
276 return visit_continue
;
280 ir_hierarchical_visitor::run(exec_list
*instructions
)
282 visit_list_elements(this, instructions
);
287 visit_tree(ir_instruction
*ir
,
288 void (*callback
)(class ir_instruction
*ir
, void *data
),
291 ir_hierarchical_visitor v
;
293 v
.callback
= callback
;