be76945a2178b9b8150db5d6208559946525ecae
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"
26 #include "glsl_parser_extras.h"
31 static void print_type(const glsl_type
*t
);
34 ir_instruction::print(void) const
36 ir_instruction
*deconsted
= const_cast<ir_instruction
*>(this);
39 deconsted
->accept(&v
);
43 _mesa_print_ir(exec_list
*instructions
,
44 struct _mesa_glsl_parse_state
*state
)
47 for (unsigned i
= 0; i
< state
->num_user_structures
; i
++) {
48 const glsl_type
*const s
= state
->user_structures
[i
];
50 printf("(structure (%s) (%s@%p) (%u) (\n",
51 s
->name
, s
->name
, (void *) s
, s
->length
);
53 for (unsigned j
= 0; j
< s
->length
; j
++) {
55 print_type(s
->fields
.structure
[j
].type
);
56 printf(")(%s))\n", s
->fields
.structure
[j
].name
);
64 foreach_iter(exec_list_iterator
, iter
, *instructions
) {
65 ir_instruction
*ir
= (ir_instruction
*)iter
.get();
67 if (ir
->ir_type
!= ir_type_function
)
74 void ir_print_visitor::indent(void)
76 for (int i
= 0; i
< indentation
; i
++)
81 print_type(const glsl_type
*t
)
83 if (t
->base_type
== GLSL_TYPE_ARRAY
) {
85 print_type(t
->fields
.array
);
86 printf(" %u)", t
->length
);
87 } else if ((t
->base_type
== GLSL_TYPE_STRUCT
)
88 && (strncmp("gl_", t
->name
, 3) != 0)) {
89 printf("%s@%p", t
->name
, (void *) t
);
91 printf("%s", t
->name
);
96 void ir_print_visitor::visit(ir_variable
*ir
)
100 const char *const cent
= (ir
->centroid
) ? "centroid " : "";
101 const char *const inv
= (ir
->invariant
) ? "invariant " : "";
102 const char *const mode
[] = { "", "uniform ", "in ", "out ", "inout ",
103 "const_in ", "sys ", "temporary " };
104 const char *const interp
[] = { "", "flat", "noperspective" };
106 printf("(%s%s%s%s) ",
107 cent
, inv
, mode
[ir
->mode
], interp
[ir
->interpolation
]);
109 print_type(ir
->type
);
110 printf(" %s@%p)", ir
->name
, (void *) ir
);
114 void ir_print_visitor::visit(ir_function_signature
*ir
)
116 printf("(signature ");
119 print_type(ir
->return_type
);
123 printf("(parameters\n");
126 foreach_iter(exec_list_iterator
, iter
, ir
->parameters
) {
127 ir_variable
*const inst
= (ir_variable
*) iter
.get();
143 foreach_iter(exec_list_iterator
, iter
, ir
->body
) {
144 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
157 void ir_print_visitor::visit(ir_function
*ir
)
159 printf("(function %s\n", ir
->name
);
161 foreach_iter(exec_list_iterator
, iter
, *ir
) {
162 ir_function_signature
*const sig
= (ir_function_signature
*) iter
.get();
173 void ir_print_visitor::visit(ir_expression
*ir
)
175 printf("(expression ");
177 print_type(ir
->type
);
179 printf(" %s ", ir
->operator_string());
181 for (unsigned i
= 0; i
< ir
->get_num_operands(); i
++) {
182 ir
->operands
[i
]->accept(this);
189 void ir_print_visitor::visit(ir_texture
*ir
)
191 printf("(%s ", ir
->opcode_string());
193 ir
->sampler
->accept(this);
196 ir
->coordinate
->accept(this);
200 if (ir
->offset
!= NULL
) {
201 ir
->offset
->accept(this);
208 if (ir
->op
!= ir_txf
) {
210 ir
->projector
->accept(this);
214 if (ir
->shadow_comparitor
) {
216 ir
->shadow_comparitor
->accept(this);
228 ir
->lod_info
.bias
->accept(this);
232 ir
->lod_info
.lod
->accept(this);
236 ir
->lod_info
.grad
.dPdx
->accept(this);
238 ir
->lod_info
.grad
.dPdy
->accept(this);
246 void ir_print_visitor::visit(ir_swizzle
*ir
)
248 const unsigned swiz
[4] = {
256 for (unsigned i
= 0; i
< ir
->mask
.num_components
; i
++) {
257 printf("%c", "xyzw"[swiz
[i
]]);
260 ir
->val
->accept(this);
265 void ir_print_visitor::visit(ir_dereference_variable
*ir
)
267 ir_variable
*var
= ir
->variable_referenced();
268 printf("(var_ref %s@%p) ", var
->name
, (void *) var
);
272 void ir_print_visitor::visit(ir_dereference_array
*ir
)
274 printf("(array_ref ");
275 ir
->array
->accept(this);
276 ir
->array_index
->accept(this);
281 void ir_print_visitor::visit(ir_dereference_record
*ir
)
283 printf("(record_ref ");
284 ir
->record
->accept(this);
285 printf(" %s) ", ir
->field
);
289 void ir_print_visitor::visit(ir_assignment
*ir
)
294 ir
->condition
->accept(this);
299 for (unsigned i
= 0; i
< 4; i
++) {
300 if ((ir
->write_mask
& (1 << i
)) != 0) {
307 printf(" (%s) ", mask
);
309 ir
->lhs
->accept(this);
313 ir
->rhs
->accept(this);
318 void ir_print_visitor::visit(ir_constant
*ir
)
320 const glsl_type
*const base_type
= ir
->type
->get_base_type();
322 printf("(constant ");
323 print_type(ir
->type
);
326 if (ir
->type
->is_array()) {
327 for (unsigned i
= 0; i
< ir
->type
->length
; i
++)
328 ir
->get_array_element(i
)->accept(this);
329 } else if (ir
->type
->is_record()) {
330 ir_constant
*value
= (ir_constant
*) ir
->components
.get_head();
331 for (unsigned i
= 0; i
< ir
->type
->length
; i
++) {
332 printf("(%s ", ir
->type
->fields
.structure
->name
);
336 value
= (ir_constant
*) value
->next
;
339 for (unsigned i
= 0; i
< ir
->type
->components(); i
++) {
342 switch (base_type
->base_type
) {
343 case GLSL_TYPE_UINT
: printf("%u", ir
->value
.u
[i
]); break;
344 case GLSL_TYPE_INT
: printf("%d", ir
->value
.i
[i
]); break;
345 case GLSL_TYPE_FLOAT
: printf("%f", ir
->value
.f
[i
]); break;
346 case GLSL_TYPE_BOOL
: printf("%d", ir
->value
.b
[i
]); break;
356 ir_print_visitor::visit(ir_call
*ir
)
358 printf("(call %s (", ir
->callee_name());
359 foreach_iter(exec_list_iterator
, iter
, *ir
) {
360 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
369 ir_print_visitor::visit(ir_return
*ir
)
373 ir_rvalue
*const value
= ir
->get_value();
384 ir_print_visitor::visit(ir_discard
*ir
)
388 if (ir
->condition
!= NULL
) {
390 ir
->condition
->accept(this);
398 ir_print_visitor::visit(ir_if
*ir
)
401 ir
->condition
->accept(this);
406 foreach_iter(exec_list_iterator
, iter
, ir
->then_instructions
) {
407 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
419 if (!ir
->else_instructions
.is_empty()) {
423 foreach_iter(exec_list_iterator
, iter
, ir
->else_instructions
) {
424 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
440 ir_print_visitor::visit(ir_loop
*ir
)
443 if (ir
->counter
!= NULL
)
444 ir
->counter
->accept(this);
446 if (ir
->from
!= NULL
)
447 ir
->from
->accept(this);
450 ir
->to
->accept(this);
452 if (ir
->increment
!= NULL
)
453 ir
->increment
->accept(this);
457 foreach_iter(exec_list_iterator
, iter
, ir
->body_instructions
) {
458 ir_instruction
*const inst
= (ir_instruction
*) iter
.get();
471 ir_print_visitor::visit(ir_loop_jump
*ir
)
473 printf("%s", ir
->is_break() ? "break" : "continue");