2010-03-09 16:23:37 -08:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2010-06-22 10:38:52 -07:00
|
|
|
|
2010-03-09 16:23:37 -08:00
|
|
|
#include "ir_print_visitor.h"
|
2010-03-09 21:44:34 -08:00
|
|
|
#include "glsl_types.h"
|
2010-04-28 13:14:53 -07:00
|
|
|
#include "glsl_parser_extras.h"
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
#include "program/hash_table.h"
|
|
|
|
|
2010-04-28 13:14:53 -07:00
|
|
|
static void print_type(const glsl_type *t);
|
2010-03-09 21:44:34 -08:00
|
|
|
|
2010-06-22 12:09:21 -07:00
|
|
|
void
|
2010-06-23 11:37:12 -07:00
|
|
|
ir_instruction::print(void) const
|
2010-06-22 12:09:21 -07:00
|
|
|
{
|
2010-06-23 11:37:12 -07:00
|
|
|
ir_instruction *deconsted = const_cast<ir_instruction *>(this);
|
|
|
|
|
2010-06-22 12:09:21 -07:00
|
|
|
ir_print_visitor v;
|
2010-06-23 11:37:12 -07:00
|
|
|
deconsted->accept(&v);
|
2010-06-22 12:09:21 -07:00
|
|
|
}
|
|
|
|
|
2010-04-28 13:04:15 -07:00
|
|
|
void
|
|
|
|
_mesa_print_ir(exec_list *instructions,
|
|
|
|
struct _mesa_glsl_parse_state *state)
|
|
|
|
{
|
2010-07-29 15:04:45 -07:00
|
|
|
if (state) {
|
|
|
|
for (unsigned i = 0; i < state->num_user_structures; i++) {
|
|
|
|
const glsl_type *const s = state->user_structures[i];
|
2010-04-28 13:14:53 -07:00
|
|
|
|
2010-07-29 15:04:45 -07:00
|
|
|
printf("(structure (%s) (%s@%p) (%u) (\n",
|
2010-08-11 14:00:36 -06:00
|
|
|
s->name, s->name, (void *) s, s->length);
|
2010-04-28 13:14:53 -07:00
|
|
|
|
2010-07-29 15:04:45 -07:00
|
|
|
for (unsigned j = 0; j < s->length; j++) {
|
|
|
|
printf("\t((");
|
|
|
|
print_type(s->fields.structure[j].type);
|
|
|
|
printf(")(%s))\n", s->fields.structure[j].name);
|
|
|
|
}
|
2010-04-28 13:14:53 -07:00
|
|
|
|
2010-07-29 15:04:45 -07:00
|
|
|
printf(")\n");
|
|
|
|
}
|
2010-04-28 13:14:53 -07:00
|
|
|
}
|
2010-04-28 13:04:15 -07:00
|
|
|
|
|
|
|
printf("(\n");
|
|
|
|
foreach_iter(exec_list_iterator, iter, *instructions) {
|
2010-07-29 14:20:39 -07:00
|
|
|
ir_instruction *ir = (ir_instruction *)iter.get();
|
|
|
|
ir->print();
|
|
|
|
if (ir->ir_type != ir_type_function)
|
|
|
|
printf("\n");
|
2010-04-28 13:04:15 -07:00
|
|
|
}
|
|
|
|
printf("\n)");
|
|
|
|
}
|
|
|
|
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
ir_print_visitor::ir_print_visitor()
|
|
|
|
{
|
|
|
|
indentation = 0;
|
|
|
|
printable_names =
|
|
|
|
hash_table_ctor(32, hash_table_pointer_hash, hash_table_pointer_compare);
|
|
|
|
symbols = _mesa_symbol_table_ctor();
|
|
|
|
mem_ctx = ralloc_context(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ir_print_visitor::~ir_print_visitor()
|
|
|
|
{
|
|
|
|
hash_table_dtor(printable_names);
|
|
|
|
_mesa_symbol_table_dtor(symbols);
|
|
|
|
ralloc_free(mem_ctx);
|
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
|
|
|
|
void ir_print_visitor::indent(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < indentation; i++)
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
const char *
|
|
|
|
ir_print_visitor::unique_name(ir_variable *var)
|
|
|
|
{
|
2011-06-24 17:30:41 -07:00
|
|
|
/* var->name can be NULL in function prototypes when a type is given for a
|
|
|
|
* parameter but no name is given. In that case, just return an empty
|
|
|
|
* string. Don't worry about tracking the generated name in the printable
|
|
|
|
* names hash because this is the only scope where it can ever appear.
|
|
|
|
*/
|
|
|
|
if (var->name == NULL) {
|
|
|
|
static unsigned arg = 1;
|
|
|
|
return ralloc_asprintf(this->mem_ctx, "parameter@%u", arg++);
|
|
|
|
}
|
|
|
|
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
/* Do we already have a name for this variable? */
|
|
|
|
const char *name = (const char *) hash_table_find(this->printable_names, var);
|
|
|
|
if (name != NULL)
|
|
|
|
return name;
|
|
|
|
|
|
|
|
/* If there's no conflict, just use the original name */
|
|
|
|
if (_mesa_symbol_table_find_symbol(this->symbols, -1, var->name) == NULL) {
|
|
|
|
name = var->name;
|
|
|
|
} else {
|
|
|
|
static unsigned i = 1;
|
|
|
|
name = ralloc_asprintf(this->mem_ctx, "%s@%u", var->name, ++i);
|
|
|
|
}
|
|
|
|
hash_table_insert(this->printable_names, (void *) name, var);
|
|
|
|
_mesa_symbol_table_add_symbol(this->symbols, -1, name, var);
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2010-03-09 21:44:34 -08:00
|
|
|
static void
|
|
|
|
print_type(const glsl_type *t)
|
|
|
|
{
|
|
|
|
if (t->base_type == GLSL_TYPE_ARRAY) {
|
2010-04-07 14:41:13 -07:00
|
|
|
printf("(array ");
|
2010-03-09 21:44:34 -08:00
|
|
|
print_type(t->fields.array);
|
2010-04-09 17:59:51 -07:00
|
|
|
printf(" %u)", t->length);
|
2010-04-28 13:14:53 -07:00
|
|
|
} else if ((t->base_type == GLSL_TYPE_STRUCT)
|
|
|
|
&& (strncmp("gl_", t->name, 3) != 0)) {
|
2010-08-11 14:00:36 -06:00
|
|
|
printf("%s@%p", t->name, (void *) t);
|
2010-03-09 21:44:34 -08:00
|
|
|
} else {
|
|
|
|
printf("%s", t->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-09 16:23:37 -08:00
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_variable *ir)
|
|
|
|
{
|
2010-05-19 13:20:12 +02:00
|
|
|
printf("(declare ");
|
2010-03-09 16:23:37 -08:00
|
|
|
|
2010-05-19 13:20:12 +02:00
|
|
|
const char *const cent = (ir->centroid) ? "centroid " : "";
|
|
|
|
const char *const inv = (ir->invariant) ? "invariant " : "";
|
2010-07-22 16:18:57 -07:00
|
|
|
const char *const mode[] = { "", "uniform ", "in ", "out ", "inout ",
|
2011-01-12 15:37:37 -08:00
|
|
|
"const_in ", "sys ", "temporary " };
|
2010-05-19 13:20:12 +02:00
|
|
|
const char *const interp[] = { "", "flat", "noperspective" };
|
2010-03-09 16:23:37 -08:00
|
|
|
|
2010-05-19 13:20:12 +02:00
|
|
|
printf("(%s%s%s%s) ",
|
|
|
|
cent, inv, mode[ir->mode], interp[ir->interpolation]);
|
2010-03-09 21:44:34 -08:00
|
|
|
|
2010-05-19 13:20:12 +02:00
|
|
|
print_type(ir->type);
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
printf(" %s)", unique_name(ir));
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_function_signature *ir)
|
|
|
|
{
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
_mesa_symbol_table_push_scope(symbols);
|
2010-04-21 17:28:46 -07:00
|
|
|
printf("(signature ");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2010-04-21 17:28:46 -07:00
|
|
|
print_type(ir->return_type);
|
2010-07-29 14:36:59 -07:00
|
|
|
printf("\n");
|
|
|
|
indent();
|
|
|
|
|
|
|
|
printf("(parameters\n");
|
|
|
|
indentation++;
|
|
|
|
|
2010-04-07 14:32:53 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, ir->parameters) {
|
|
|
|
ir_variable *const inst = (ir_variable *) iter.get();
|
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-07 14:32:53 -07:00
|
|
|
inst->accept(this);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
|
|
|
|
indent();
|
|
|
|
printf(")\n");
|
|
|
|
|
|
|
|
indent();
|
|
|
|
|
|
|
|
printf("(\n");
|
|
|
|
indentation++;
|
2010-04-07 14:32:53 -07:00
|
|
|
|
2010-04-07 13:19:11 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, ir->body) {
|
|
|
|
ir_instruction *const inst = (ir_instruction *) iter.get();
|
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-07 13:19:11 -07:00
|
|
|
inst->accept(this);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2010-04-21 12:30:22 -07:00
|
|
|
printf("))\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
_mesa_symbol_table_pop_scope(symbols);
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_function *ir)
|
|
|
|
{
|
|
|
|
printf("(function %s\n", ir->name);
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
2010-04-21 12:30:22 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, *ir) {
|
|
|
|
ir_function_signature *const sig = (ir_function_signature *) iter.get();
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-21 12:30:22 -07:00
|
|
|
sig->accept(this);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2010-07-29 14:20:39 -07:00
|
|
|
printf(")\n\n");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_expression *ir)
|
|
|
|
{
|
2010-03-25 18:25:37 -07:00
|
|
|
printf("(expression ");
|
|
|
|
|
2010-04-07 16:36:32 -07:00
|
|
|
print_type(ir->type);
|
|
|
|
|
2010-04-07 17:18:29 -07:00
|
|
|
printf(" %s ", ir->operator_string());
|
2010-04-07 16:36:32 -07:00
|
|
|
|
2010-11-10 16:33:10 -08:00
|
|
|
for (unsigned i = 0; i < ir->get_num_operands(); i++) {
|
|
|
|
ir->operands[i]->accept(this);
|
|
|
|
}
|
2010-03-25 18:25:37 -07:00
|
|
|
|
2010-04-12 14:52:37 -07:00
|
|
|
printf(") ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-26 15:15:31 -07:00
|
|
|
void ir_print_visitor::visit(ir_texture *ir)
|
|
|
|
{
|
|
|
|
printf("(%s ", ir->opcode_string());
|
|
|
|
|
2011-02-25 14:29:36 -08:00
|
|
|
print_type(ir->type);
|
|
|
|
printf(" ");
|
|
|
|
|
2010-05-26 15:15:31 -07:00
|
|
|
ir->sampler->accept(this);
|
|
|
|
printf(" ");
|
|
|
|
|
2011-02-25 14:45:33 -08:00
|
|
|
if (ir->op != ir_txs) {
|
|
|
|
ir->coordinate->accept(this);
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2011-02-25 14:45:33 -08:00
|
|
|
printf(" ");
|
2011-01-08 23:49:23 -08:00
|
|
|
|
2011-02-25 14:45:33 -08:00
|
|
|
if (ir->offset != NULL) {
|
|
|
|
ir->offset->accept(this);
|
|
|
|
} else {
|
|
|
|
printf("0");
|
|
|
|
}
|
2011-01-08 23:49:23 -08:00
|
|
|
|
2011-02-25 14:45:33 -08:00
|
|
|
printf(" ");
|
|
|
|
}
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2011-02-25 14:45:33 -08:00
|
|
|
if (ir->op != ir_txf && ir->op != ir_txs) {
|
2010-05-26 15:15:31 -07:00
|
|
|
if (ir->projector)
|
|
|
|
ir->projector->accept(this);
|
|
|
|
else
|
|
|
|
printf("1");
|
|
|
|
|
|
|
|
if (ir->shadow_comparitor) {
|
|
|
|
printf(" ");
|
|
|
|
ir->shadow_comparitor->accept(this);
|
|
|
|
} else {
|
|
|
|
printf(" ()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
switch (ir->op)
|
|
|
|
{
|
|
|
|
case ir_tex:
|
|
|
|
break;
|
|
|
|
case ir_txb:
|
|
|
|
ir->lod_info.bias->accept(this);
|
|
|
|
break;
|
|
|
|
case ir_txl:
|
|
|
|
case ir_txf:
|
2011-02-25 14:45:33 -08:00
|
|
|
case ir_txs:
|
2010-05-26 15:15:31 -07:00
|
|
|
ir->lod_info.lod->accept(this);
|
|
|
|
break;
|
|
|
|
case ir_txd:
|
|
|
|
printf("(");
|
|
|
|
ir->lod_info.grad.dPdx->accept(this);
|
|
|
|
printf(" ");
|
|
|
|
ir->lod_info.grad.dPdy->accept(this);
|
|
|
|
printf(")");
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-26 01:20:08 -07:00
|
|
|
void ir_print_visitor::visit(ir_swizzle *ir)
|
|
|
|
{
|
|
|
|
const unsigned swiz[4] = {
|
|
|
|
ir->mask.x,
|
|
|
|
ir->mask.y,
|
|
|
|
ir->mask.z,
|
|
|
|
ir->mask.w,
|
|
|
|
};
|
|
|
|
|
|
|
|
printf("(swiz ");
|
|
|
|
for (unsigned i = 0; i < ir->mask.num_components; i++) {
|
|
|
|
printf("%c", "xyzw"[swiz[i]]);
|
|
|
|
}
|
|
|
|
printf(" ");
|
|
|
|
ir->val->accept(this);
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-19 13:20:12 +02:00
|
|
|
void ir_print_visitor::visit(ir_dereference_variable *ir)
|
2010-03-09 16:23:37 -08:00
|
|
|
{
|
2010-06-24 09:07:38 -07:00
|
|
|
ir_variable *var = ir->variable_referenced();
|
glsl: Generate readable unique names at print time.
Since GLSL IR allows multiple ir_variables to share the same name, we
need to generate unique names when printing the IR. Previously, we
always used %s@%p, appending the ir_variable's memory address.
While this worked, it had two drawbacks:
- When there aren't duplicates, the extra "@0x669a3e88" is useless
and makes the code harder to read.
- Real duplicates were hard to tell apart:
channel_expressions@0x6699e3c8 vs. channel_expressions@0x6699ddd8
We now append @2, @3, @4, and so on, but only where necessary to
distinguish duplicates. Since we only do this at print time, any
performance impact is irrelevant.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <idr@freedesktop.org>
2011-03-25 10:59:46 -07:00
|
|
|
printf("(var_ref %s) ", unique_name(var));
|
2010-05-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
2010-03-25 17:38:13 -07:00
|
|
|
|
2010-05-19 13:20:12 +02:00
|
|
|
void ir_print_visitor::visit(ir_dereference_array *ir)
|
|
|
|
{
|
|
|
|
printf("(array_ref ");
|
2010-05-19 13:52:29 +02:00
|
|
|
ir->array->accept(this);
|
|
|
|
ir->array_index->accept(this);
|
2010-05-19 13:20:12 +02:00
|
|
|
printf(") ");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_dereference_record *ir)
|
|
|
|
{
|
|
|
|
printf("(record_ref ");
|
2010-05-19 13:52:29 +02:00
|
|
|
ir->record->accept(this);
|
2010-05-26 15:20:59 -07:00
|
|
|
printf(" %s) ", ir->field);
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_assignment *ir)
|
|
|
|
{
|
2010-04-09 17:29:47 -07:00
|
|
|
printf("(assign ");
|
2010-03-09 16:40:45 -08:00
|
|
|
|
|
|
|
if (ir->condition)
|
|
|
|
ir->condition->accept(this);
|
2010-08-02 18:48:25 -07:00
|
|
|
|
|
|
|
char mask[5];
|
|
|
|
unsigned j = 0;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 4; i++) {
|
|
|
|
if ((ir->write_mask & (1 << i)) != 0) {
|
|
|
|
mask[j] = "xyzw"[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mask[j] = '\0';
|
|
|
|
|
|
|
|
printf(" (%s) ", mask);
|
2010-03-25 18:29:25 -07:00
|
|
|
|
2010-03-09 16:40:45 -08:00
|
|
|
ir->lhs->accept(this);
|
|
|
|
|
2010-04-09 17:29:47 -07:00
|
|
|
printf(" ");
|
2010-03-25 18:29:25 -07:00
|
|
|
|
2010-03-09 16:40:45 -08:00
|
|
|
ir->rhs->accept(this);
|
2010-03-25 18:29:25 -07:00
|
|
|
printf(") ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_constant *ir)
|
|
|
|
{
|
2010-03-25 18:38:28 -07:00
|
|
|
const glsl_type *const base_type = ir->type->get_base_type();
|
2010-03-09 21:44:34 -08:00
|
|
|
|
2010-04-07 14:41:13 -07:00
|
|
|
printf("(constant ");
|
2010-04-07 14:40:44 -07:00
|
|
|
print_type(ir->type);
|
2010-04-07 14:41:13 -07:00
|
|
|
printf(" (");
|
2010-03-25 18:38:28 -07:00
|
|
|
|
2010-07-20 01:28:09 -07:00
|
|
|
if (ir->type->is_array()) {
|
|
|
|
for (unsigned i = 0; i < ir->type->length; i++)
|
|
|
|
ir->get_array_element(i)->accept(this);
|
2010-12-02 10:11:49 -08:00
|
|
|
} else if (ir->type->is_record()) {
|
|
|
|
ir_constant *value = (ir_constant *) ir->components.get_head();
|
|
|
|
for (unsigned i = 0; i < ir->type->length; i++) {
|
2011-06-03 11:23:31 -07:00
|
|
|
printf("(%s ", ir->type->fields.structure[i].name);
|
2010-12-02 10:11:49 -08:00
|
|
|
value->accept(this);
|
|
|
|
printf(")");
|
|
|
|
|
|
|
|
value = (ir_constant *) value->next;
|
|
|
|
}
|
2010-07-20 01:28:09 -07:00
|
|
|
} else {
|
|
|
|
for (unsigned i = 0; i < ir->type->components(); i++) {
|
|
|
|
if (i != 0)
|
|
|
|
printf(" ");
|
|
|
|
switch (base_type->base_type) {
|
|
|
|
case GLSL_TYPE_UINT: printf("%u", ir->value.u[i]); break;
|
|
|
|
case GLSL_TYPE_INT: printf("%d", ir->value.i[i]); break;
|
|
|
|
case GLSL_TYPE_FLOAT: printf("%f", ir->value.f[i]); break;
|
|
|
|
case GLSL_TYPE_BOOL: printf("%d", ir->value.b[i]); break;
|
|
|
|
default: assert(0);
|
|
|
|
}
|
2010-03-25 18:38:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf(")) ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
2010-03-11 14:34:27 -08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_call *ir)
|
|
|
|
{
|
2010-04-22 00:44:12 -07:00
|
|
|
printf("(call %s (", ir->callee_name());
|
2010-03-26 17:30:30 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, *ir) {
|
|
|
|
ir_instruction *const inst = (ir_instruction *) iter.get();
|
2010-03-11 14:34:27 -08:00
|
|
|
|
2010-03-26 17:30:30 -07:00
|
|
|
inst->accept(this);
|
|
|
|
}
|
2010-04-22 00:44:12 -07:00
|
|
|
printf("))\n");
|
2010-03-11 14:34:27 -08:00
|
|
|
}
|
2010-03-19 16:44:52 -07:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_return *ir)
|
|
|
|
{
|
|
|
|
printf("(return");
|
|
|
|
|
2010-03-26 00:25:36 -07:00
|
|
|
ir_rvalue *const value = ir->get_value();
|
2010-03-19 16:44:52 -07:00
|
|
|
if (value) {
|
|
|
|
printf(" ");
|
|
|
|
value->accept(this);
|
|
|
|
}
|
|
|
|
|
2010-03-25 18:29:25 -07:00
|
|
|
printf(")");
|
2010-03-19 16:44:52 -07:00
|
|
|
}
|
2010-03-29 14:11:25 -07:00
|
|
|
|
|
|
|
|
2010-06-30 10:47:34 -07:00
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_discard *ir)
|
|
|
|
{
|
|
|
|
printf("(discard ");
|
|
|
|
|
|
|
|
if (ir->condition != NULL) {
|
|
|
|
printf(" ");
|
|
|
|
ir->condition->accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-29 14:11:25 -07:00
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_if *ir)
|
|
|
|
{
|
|
|
|
printf("(if ");
|
|
|
|
ir->condition->accept(this);
|
|
|
|
|
|
|
|
printf("(\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2010-03-29 14:11:25 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, ir->then_instructions) {
|
|
|
|
ir_instruction *const inst = (ir_instruction *) iter.get();
|
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-03-29 14:11:25 -07:00
|
|
|
inst->accept(this);
|
2010-04-06 12:13:02 -07:00
|
|
|
printf("\n");
|
2010-03-29 14:11:25 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
|
|
|
|
indentation--;
|
|
|
|
indent();
|
2010-03-29 14:11:25 -07:00
|
|
|
printf(")\n");
|
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-08-12 14:55:48 -07:00
|
|
|
if (!ir->else_instructions.is_empty()) {
|
|
|
|
printf("(\n");
|
|
|
|
indentation++;
|
2010-07-29 14:36:59 -07:00
|
|
|
|
2010-08-12 14:55:48 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, ir->else_instructions) {
|
|
|
|
ir_instruction *const inst = (ir_instruction *) iter.get();
|
2010-03-29 14:11:25 -07:00
|
|
|
|
2010-08-12 14:55:48 -07:00
|
|
|
indent();
|
|
|
|
inst->accept(this);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
indentation--;
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-08-12 14:55:48 -07:00
|
|
|
printf("))\n");
|
|
|
|
} else {
|
|
|
|
printf("())\n");
|
2010-03-29 14:11:25 -07:00
|
|
|
}
|
|
|
|
}
|
2010-04-05 16:16:07 -07:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_loop *ir)
|
|
|
|
{
|
|
|
|
printf("(loop (");
|
|
|
|
if (ir->counter != NULL)
|
|
|
|
ir->counter->accept(this);
|
|
|
|
printf(") (");
|
|
|
|
if (ir->from != NULL)
|
|
|
|
ir->from->accept(this);
|
|
|
|
printf(") (");
|
|
|
|
if (ir->to != NULL)
|
|
|
|
ir->to->accept(this);
|
|
|
|
printf(") (");
|
|
|
|
if (ir->increment != NULL)
|
|
|
|
ir->increment->accept(this);
|
2010-04-05 16:38:20 -07:00
|
|
|
printf(") (\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2010-04-05 16:16:07 -07:00
|
|
|
foreach_iter(exec_list_iterator, iter, ir->body_instructions) {
|
|
|
|
ir_instruction *const inst = (ir_instruction *) iter.get();
|
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-05 16:16:07 -07:00
|
|
|
inst->accept(this);
|
2010-04-05 16:38:20 -07:00
|
|
|
printf("\n");
|
2010-04-05 16:16:07 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2010-04-05 16:16:07 -07:00
|
|
|
printf("))\n");
|
|
|
|
}
|
2010-04-05 16:28:15 -07:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_loop_jump *ir)
|
|
|
|
{
|
|
|
|
printf("%s", ir->is_break() ? "break" : "continue");
|
|
|
|
}
|