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.
24 #include "ir_print_visitor.h"
25 #include "glsl_types.h"
28 print_type(const glsl_type
*t
)
30 if (t
->base_type
== GLSL_TYPE_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) ");
39 printf("%s", t
->name
);
44 void ir_print_visitor::visit(ir_variable
*ir
)
47 printf("(%s)", ir
->name
);
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" };
57 cent
, inv
, mode
[ir
->mode
], interp
[ir
->interpolation
]);
60 printf("(%s)) ", ir
->name
);
65 void ir_print_visitor::visit(ir_function_signature
*ir
)
67 printf("(signature\n (parameters\n");
68 foreach_iter(exec_list_iterator
, iter
, ir
->parameters
) {
69 ir_variable
*const inst
= (ir_variable
*) iter
.get();
76 foreach_iter(exec_list_iterator
, iter
, ir
->body
) {
77 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
86 void ir_print_visitor::visit(ir_function
*ir
)
88 printf("(function %s\n", ir
->name
);
89 foreach_iter(exec_list_iterator
, iter
, *ir
) {
90 ir_function_signature
*const sig
= (ir_function_signature
*) iter
.get();
100 void ir_print_visitor::visit(ir_expression
*ir
)
102 static const char *const operators
[] = {
149 printf("(expression ");
151 print_type(ir
->type
);
153 assert((unsigned int)ir
->operation
<
154 sizeof(operators
) / sizeof(operators
[0]));
156 printf(" %s ", operators
[ir
->operation
]);
160 ir
->operands
[0]->accept(this);
165 ir
->operands
[1]->accept(this);
170 void ir_print_visitor::visit(ir_swizzle
*ir
)
172 const unsigned swiz
[4] = {
180 for (unsigned i
= 0; i
< ir
->mask
.num_components
; i
++) {
181 printf("%c", "xyzw"[swiz
[i
]]);
184 ir
->val
->accept(this);
189 void ir_print_visitor::visit(ir_dereference
*ir
)
194 case ir_dereference::ir_reference_variable
: {
196 ir
->var
->accept(this);
200 case ir_dereference::ir_reference_array
:
201 printf("(array_ref ");
202 ir
->var
->accept(this);
203 ir
->selector
.array_index
->accept(this);
206 case ir_dereference::ir_reference_record
:
207 printf("(record_ref ");
208 ir
->var
->accept(this);
209 printf("(%s)) ", ir
->selector
.field
);
217 void ir_print_visitor::visit(ir_assignment
*ir
)
222 ir
->condition
->accept(this);
228 ir
->lhs
->accept(this);
232 ir
->rhs
->accept(this);
237 void ir_print_visitor::visit(ir_constant
*ir
)
239 const glsl_type
*const base_type
= ir
->type
->get_base_type();
241 printf("(constant ");
242 print_type(ir
->type
);
245 for (unsigned i
= 0; i
< ir
->type
->components(); i
++) {
249 switch (base_type
->base_type
) {
250 case GLSL_TYPE_UINT
: printf("%u", ir
->value
.u
[i
]); break;
251 case GLSL_TYPE_INT
: printf("%d", ir
->value
.i
[i
]); break;
252 case GLSL_TYPE_FLOAT
: printf("%f", ir
->value
.f
[i
]); break;
253 case GLSL_TYPE_BOOL
: printf("%d", ir
->value
.b
[i
]); break;
262 ir_print_visitor::visit(ir_call
*ir
)
264 printf("(call (%s) ", ir
->callee_name());
265 foreach_iter(exec_list_iterator
, iter
, *ir
) {
266 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
274 ir_print_visitor::visit(ir_return
*ir
)
278 ir_rvalue
*const value
= ir
->get_value();
289 ir_print_visitor::visit(ir_if
*ir
)
292 ir
->condition
->accept(this);
295 foreach_iter(exec_list_iterator
, iter
, ir
->then_instructions
) {
296 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
304 foreach_iter(exec_list_iterator
, iter
, ir
->else_instructions
) {
305 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
315 ir_print_visitor::visit(ir_loop
*ir
)
318 if (ir
->counter
!= NULL
)
319 ir
->counter
->accept(this);
321 if (ir
->from
!= NULL
)
322 ir
->from
->accept(this);
325 ir
->to
->accept(this);
327 if (ir
->increment
!= NULL
)
328 ir
->increment
->accept(this);
330 foreach_iter(exec_list_iterator
, iter
, ir
->body_instructions
) {
331 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
341 ir_print_visitor::visit(ir_loop_jump
*ir
)
343 printf("%s", ir
->is_break() ? "break" : "continue");