Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / mesa / src / glsl / ir_hv_accept.cpp
blob4a607dc87499b800df7a6fff5c09b09fb49822be
1 /*
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
13 * Software.
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.
24 #include "ir.h"
26 /**
27 * \file ir_hv_accept.cpp
28 * Implementations of all hierarchical visitor accept methods for IR
29 * instructions.
32 /**
33 * Process a list of nodes using a hierarchical vistor
35 * \warning
36 * This function will operate correctly if a node being processed is removed
37 * from the list. However, if nodes are added to the list after the node being
38 * processed, some of the added nodes may not be processed.
40 ir_visitor_status
41 visit_list_elements(ir_hierarchical_visitor *v, exec_list *l)
43 ir_instruction *prev_base_ir = v->base_ir;
45 foreach_list_safe(n, l) {
46 ir_instruction *const ir = (ir_instruction *) n;
47 v->base_ir = ir;
48 ir_visitor_status s = ir->accept(v);
50 if (s != visit_continue)
51 return s;
53 v->base_ir = prev_base_ir;
55 return visit_continue;
59 ir_visitor_status
60 ir_variable::accept(ir_hierarchical_visitor *v)
62 return v->visit(this);
66 ir_visitor_status
67 ir_loop::accept(ir_hierarchical_visitor *v)
69 ir_visitor_status s = v->visit_enter(this);
71 if (s != visit_continue)
72 return (s == visit_continue_with_parent) ? visit_continue : s;
74 s = visit_list_elements(v, &this->body_instructions);
75 if (s == visit_stop)
76 return s;
78 if (s != visit_continue_with_parent) {
79 if (this->from) {
80 s = this->from->accept(v);
81 if (s != visit_continue)
82 return (s == visit_continue_with_parent) ? visit_continue : s;
85 if (this->to) {
86 s = this->to->accept(v);
87 if (s != visit_continue)
88 return (s == visit_continue_with_parent) ? visit_continue : s;
91 if (this->increment) {
92 s = this->increment->accept(v);
93 if (s != visit_continue)
94 return (s == visit_continue_with_parent) ? visit_continue : s;
98 return v->visit_leave(this);
102 ir_visitor_status
103 ir_loop_jump::accept(ir_hierarchical_visitor *v)
105 return v->visit(this);
109 ir_visitor_status
110 ir_function_signature::accept(ir_hierarchical_visitor *v)
112 ir_visitor_status s = v->visit_enter(this);
113 if (s != visit_continue)
114 return (s == visit_continue_with_parent) ? visit_continue : s;
116 s = visit_list_elements(v, &this->parameters);
117 if (s == visit_stop)
118 return s;
120 s = visit_list_elements(v, &this->body);
121 return (s == visit_stop) ? s : v->visit_leave(this);
125 ir_visitor_status
126 ir_function::accept(ir_hierarchical_visitor *v)
128 ir_visitor_status s = v->visit_enter(this);
129 if (s != visit_continue)
130 return (s == visit_continue_with_parent) ? visit_continue : s;
132 s = visit_list_elements(v, &this->signatures);
133 return (s == visit_stop) ? s : v->visit_leave(this);
137 ir_visitor_status
138 ir_expression::accept(ir_hierarchical_visitor *v)
140 ir_visitor_status s = v->visit_enter(this);
142 if (s != visit_continue)
143 return (s == visit_continue_with_parent) ? visit_continue : s;
145 for (unsigned i = 0; i < this->get_num_operands(); i++) {
146 switch (this->operands[i]->accept(v)) {
147 case visit_continue:
148 break;
150 case visit_continue_with_parent:
151 // I wish for Java's labeled break-statement here.
152 goto done;
154 case visit_stop:
155 return s;
159 done:
160 return v->visit_leave(this);
163 ir_visitor_status
164 ir_texture::accept(ir_hierarchical_visitor *v)
166 ir_visitor_status s = v->visit_enter(this);
167 if (s != visit_continue)
168 return (s == visit_continue_with_parent) ? visit_continue : s;
170 s = this->sampler->accept(v);
171 if (s != visit_continue)
172 return (s == visit_continue_with_parent) ? visit_continue : s;
174 s = this->coordinate->accept(v);
175 if (s != visit_continue)
176 return (s == visit_continue_with_parent) ? visit_continue : s;
178 if (this->projector) {
179 s = this->projector->accept(v);
180 if (s != visit_continue)
181 return (s == visit_continue_with_parent) ? visit_continue : s;
184 if (this->shadow_comparitor) {
185 s = this->shadow_comparitor->accept(v);
186 if (s != visit_continue)
187 return (s == visit_continue_with_parent) ? visit_continue : s;
190 if (this->offset) {
191 s = this->offset->accept(v);
192 if (s != visit_continue)
193 return (s == visit_continue_with_parent) ? visit_continue : s;
196 switch (this->op) {
197 case ir_tex:
198 break;
199 case ir_txb:
200 s = this->lod_info.bias->accept(v);
201 if (s != visit_continue)
202 return (s == visit_continue_with_parent) ? visit_continue : s;
203 break;
204 case ir_txl:
205 case ir_txf:
206 s = this->lod_info.lod->accept(v);
207 if (s != visit_continue)
208 return (s == visit_continue_with_parent) ? visit_continue : s;
209 break;
210 case ir_txd:
211 s = this->lod_info.grad.dPdx->accept(v);
212 if (s != visit_continue)
213 return (s == visit_continue_with_parent) ? visit_continue : s;
215 s = this->lod_info.grad.dPdy->accept(v);
216 if (s != visit_continue)
217 return (s == visit_continue_with_parent) ? visit_continue : s;
218 break;
221 return (s == visit_stop) ? s : v->visit_leave(this);
225 ir_visitor_status
226 ir_swizzle::accept(ir_hierarchical_visitor *v)
228 ir_visitor_status s = v->visit_enter(this);
229 if (s != visit_continue)
230 return (s == visit_continue_with_parent) ? visit_continue : s;
232 s = this->val->accept(v);
233 return (s == visit_stop) ? s : v->visit_leave(this);
237 ir_visitor_status
238 ir_dereference_variable::accept(ir_hierarchical_visitor *v)
240 return v->visit(this);
244 ir_visitor_status
245 ir_dereference_array::accept(ir_hierarchical_visitor *v)
247 ir_visitor_status s = v->visit_enter(this);
248 if (s != visit_continue)
249 return (s == visit_continue_with_parent) ? visit_continue : s;
251 /* The array index is not the target of the assignment, so clear the
252 * 'in_assignee' flag. Restore it after returning from the array index.
254 const bool was_in_assignee = v->in_assignee;
255 v->in_assignee = false;
256 s = this->array_index->accept(v);
257 v->in_assignee = was_in_assignee;
259 if (s != visit_continue)
260 return (s == visit_continue_with_parent) ? visit_continue : s;
262 s = this->array->accept(v);
263 return (s == visit_stop) ? s : v->visit_leave(this);
267 ir_visitor_status
268 ir_dereference_record::accept(ir_hierarchical_visitor *v)
270 ir_visitor_status s = v->visit_enter(this);
271 if (s != visit_continue)
272 return (s == visit_continue_with_parent) ? visit_continue : s;
274 s = this->record->accept(v);
275 return (s == visit_stop) ? s : v->visit_leave(this);
279 ir_visitor_status
280 ir_assignment::accept(ir_hierarchical_visitor *v)
282 ir_visitor_status s = v->visit_enter(this);
283 if (s != visit_continue)
284 return (s == visit_continue_with_parent) ? visit_continue : s;
286 v->in_assignee = true;
287 s = this->lhs->accept(v);
288 v->in_assignee = false;
289 if (s != visit_continue)
290 return (s == visit_continue_with_parent) ? visit_continue : s;
292 s = this->rhs->accept(v);
293 if (s != visit_continue)
294 return (s == visit_continue_with_parent) ? visit_continue : s;
296 if (this->condition)
297 s = this->condition->accept(v);
299 return (s == visit_stop) ? s : v->visit_leave(this);
303 ir_visitor_status
304 ir_constant::accept(ir_hierarchical_visitor *v)
306 return v->visit(this);
310 ir_visitor_status
311 ir_call::accept(ir_hierarchical_visitor *v)
313 ir_visitor_status s = v->visit_enter(this);
314 if (s != visit_continue)
315 return (s == visit_continue_with_parent) ? visit_continue : s;
317 s = visit_list_elements(v, &this->actual_parameters);
318 if (s == visit_stop)
319 return s;
321 return v->visit_leave(this);
325 ir_visitor_status
326 ir_return::accept(ir_hierarchical_visitor *v)
328 ir_visitor_status s = v->visit_enter(this);
329 if (s != visit_continue)
330 return (s == visit_continue_with_parent) ? visit_continue : s;
332 ir_rvalue *val = this->get_value();
333 if (val) {
334 s = val->accept(v);
335 if (s != visit_continue)
336 return (s == visit_continue_with_parent) ? visit_continue : s;
339 return v->visit_leave(this);
343 ir_visitor_status
344 ir_discard::accept(ir_hierarchical_visitor *v)
346 ir_visitor_status s = v->visit_enter(this);
347 if (s != visit_continue)
348 return (s == visit_continue_with_parent) ? visit_continue : s;
350 if (this->condition != NULL) {
351 s = this->condition->accept(v);
352 if (s != visit_continue)
353 return (s == visit_continue_with_parent) ? visit_continue : s;
356 return v->visit_leave(this);
360 ir_visitor_status
361 ir_if::accept(ir_hierarchical_visitor *v)
363 ir_visitor_status s = v->visit_enter(this);
364 if (s != visit_continue)
365 return (s == visit_continue_with_parent) ? visit_continue : s;
367 s = this->condition->accept(v);
368 if (s != visit_continue)
369 return (s == visit_continue_with_parent) ? visit_continue : s;
371 if (s != visit_continue_with_parent) {
372 s = visit_list_elements(v, &this->then_instructions);
373 if (s == visit_stop)
374 return s;
377 if (s != visit_continue_with_parent) {
378 s = visit_list_elements(v, &this->else_instructions);
379 if (s == visit_stop)
380 return s;
383 return v->visit_leave(this);