Add tracking for extension based warnings
[mesa.git] / ir_print_visitor.cpp
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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.
14 *
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.
22 */
23 #include <cstdio>
24 #include "ir_print_visitor.h"
25 #include "glsl_types.h"
26
27 static void
28 print_type(const glsl_type *t)
29 {
30 if (t->base_type == GLSL_TYPE_ARRAY) {
31 printf("array (");
32 print_type(t->fields.array);
33 printf(") (%u))", t->length);
34 } else if (t->base_type == GLSL_TYPE_STRUCT) {
35 printf("struct (%s %u ", t->name ? t->name : "@", t->length);
36 printf("(FINISHME: structure fields go here) ");
37 printf(")");
38 } else {
39 printf("%s", t->name);
40 }
41 }
42
43
44 void ir_print_visitor::visit(ir_variable *ir)
45 {
46 if (deref_depth) {
47 printf("(%s)", ir->name);
48 } else {
49 printf("(declare ");
50
51 const char *const cent = (ir->centroid) ? "centroid " : "";
52 const char *const inv = (ir->invariant) ? "invariant " : "";
53 const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " };
54 const char *const interp[] = { "", "flat", "noperspective" };
55
56 printf("(%s%s%s%s) ",
57 cent, inv, mode[ir->mode], interp[ir->interpolation]);
58
59 printf("(");
60 print_type(ir->type);
61 printf(") ");
62 printf("(%s)) ", ir->name);
63 }
64 }
65
66
67 void ir_print_visitor::visit(ir_label *ir)
68 {
69 printf("\n(label %s)", ir->label);
70 }
71
72
73 void ir_print_visitor::visit(ir_function_signature *ir)
74 {
75 printf("%s:%d:\n", __func__, __LINE__);
76 (void) ir;
77 }
78
79
80 void ir_print_visitor::visit(ir_function *ir)
81 {
82 printf("(function %s\n", ir->name);
83 printf(")\n");
84 }
85
86
87 void ir_print_visitor::visit(ir_expression *ir)
88 {
89 static const char *const operators[] = {
90 "~",
91 "!",
92 "-",
93 "abs",
94 "rcp",
95 "rsq",
96 "sqrt",
97 "exp",
98 "log",
99 "exp2",
100 "log2",
101 "f2i",
102 "i2f",
103 "f2b",
104 "b2f",
105 "i2b",
106 "b2i",
107 "u2f",
108 "trunc",
109 "ceil",
110 "floor",
111 "+",
112 "-",
113 "*",
114 "/",
115 "%",
116 "<",
117 ">",
118 "<=",
119 ">=",
120 "==",
121 "!=",
122 "<<",
123 ">>",
124 "&",
125 "^",
126 "|",
127 "&&",
128 "^^",
129 "||",
130 "dot",
131 "min",
132 "max",
133 "pow",
134 };
135
136 printf("(expression ");
137
138 assert((unsigned int)ir->operation <
139 sizeof(operators) / sizeof(operators[0]));
140
141 printf("%s", operators[ir->operation]);
142 printf("(");
143 if (ir->operands[0])
144 ir->operands[0]->accept(this);
145 printf(") ");
146
147 printf("(");
148 if (ir->operands[1])
149 ir->operands[1]->accept(this);
150 printf(")) ");
151 }
152
153
154 void ir_print_visitor::visit(ir_swizzle *ir)
155 {
156 const unsigned swiz[4] = {
157 ir->mask.x,
158 ir->mask.y,
159 ir->mask.z,
160 ir->mask.w,
161 };
162
163 printf("(swiz ");
164 for (unsigned i = 0; i < ir->mask.num_components; i++) {
165 printf("%c", "xyzw"[swiz[i]]);
166 }
167 printf(" ");
168 ir->val->accept(this);
169 printf(")");
170 }
171
172
173 void ir_print_visitor::visit(ir_dereference *ir)
174 {
175 deref_depth++;
176
177 switch (ir->mode) {
178 case ir_dereference::ir_reference_variable: {
179 printf("(var_ref ");
180 ir->var->accept(this);
181 printf(") ");
182 break;
183 }
184 case ir_dereference::ir_reference_array:
185 printf("(array_ref ");
186 ir->var->accept(this);
187 ir->selector.array_index->accept(this);
188 printf(") ");
189 break;
190 case ir_dereference::ir_reference_record:
191 printf("(record_ref ");
192 ir->var->accept(this);
193 printf("(%s)) ", ir->selector.field);
194 break;
195 }
196
197 deref_depth--;
198 }
199
200
201 void ir_print_visitor::visit(ir_assignment *ir)
202 {
203 printf("(assign (");
204
205 if (ir->condition)
206 ir->condition->accept(this);
207 else
208 printf("true");
209
210 printf(") (");
211
212 ir->lhs->accept(this);
213
214 printf(") (");
215
216 ir->rhs->accept(this);
217 printf(") ");
218 }
219
220
221 void ir_print_visitor::visit(ir_constant *ir)
222 {
223 const glsl_type *const base_type = ir->type->get_base_type();
224
225 printf("(constant (");
226 print_type(base_type);
227 printf(") ");
228
229 printf("(%d) (", ir->type->components());
230 for (unsigned i = 0; i < ir->type->components(); i++) {
231 if (i != 0)
232 printf(", ");
233
234 switch (base_type->base_type) {
235 case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break;
236 case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break;
237 case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
238 case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break;
239 default: assert(0);
240 }
241 }
242 printf(")) ");
243 }
244
245
246 void
247 ir_print_visitor::visit(ir_call *ir)
248 {
249 printf("(call (%s) ", ir->callee_name());
250 foreach_iter(exec_list_iterator, iter, *ir) {
251 ir_instruction *const inst = (ir_instruction *) iter.get();
252
253 inst->accept(this);
254 }
255 }
256
257
258 void
259 ir_print_visitor::visit(ir_return *ir)
260 {
261 printf("(return");
262
263 ir_rvalue *const value = ir->get_value();
264 if (value) {
265 printf(" ");
266 value->accept(this);
267 }
268
269 printf(")");
270 }
271
272
273 void
274 ir_print_visitor::visit(ir_if *ir)
275 {
276 printf("(if ");
277 ir->condition->accept(this);
278
279 printf("(\n");
280 foreach_iter(exec_list_iterator, iter, ir->then_instructions) {
281 ir_instruction *const inst = (ir_instruction *) iter.get();
282
283 inst->accept(this);
284 printf("\n");
285 }
286 printf(")\n");
287
288 printf("(\n");
289 foreach_iter(exec_list_iterator, iter, ir->else_instructions) {
290 ir_instruction *const inst = (ir_instruction *) iter.get();
291
292 inst->accept(this);
293 printf("\n");
294 }
295 printf("))\n");
296 }
297
298
299 void
300 ir_print_visitor::visit(ir_loop *ir)
301 {
302 printf("(loop (");
303 if (ir->counter != NULL)
304 ir->counter->accept(this);
305 printf(") (");
306 if (ir->from != NULL)
307 ir->from->accept(this);
308 printf(") (");
309 if (ir->to != NULL)
310 ir->to->accept(this);
311 printf(") (");
312 if (ir->increment != NULL)
313 ir->increment->accept(this);
314 printf(") (\n");
315 foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
316 ir_instruction *const inst = (ir_instruction *) iter.get();
317
318 inst->accept(this);
319 printf("\n");
320 }
321 printf("))\n");
322 }
323
324
325 void
326 ir_print_visitor::visit(ir_loop_jump *ir)
327 {
328 printf("%s", ir->is_break() ? "break" : "continue");
329 }