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
|
|
|
|
2017-01-23 20:21:00 +01:00
|
|
|
#include <inttypes.h> /* for PRIx64 macro */
|
2010-03-09 16:23:37 -08:00
|
|
|
#include "ir_print_visitor.h"
|
2016-01-18 11:35:29 +02:00
|
|
|
#include "compiler/glsl_types.h"
|
2010-04-28 13:14:53 -07:00
|
|
|
#include "glsl_parser_extras.h"
|
2013-04-06 19:16:58 -07:00
|
|
|
#include "main/macros.h"
|
2015-08-03 02:15:20 +02:00
|
|
|
#include "util/hash_table.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
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
static void print_type(FILE *f, 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
|
2014-02-20 18:00:23 -08:00
|
|
|
{
|
|
|
|
this->fprint(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_instruction::fprint(FILE *f) 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);
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
ir_print_visitor v(f);
|
2010-06-23 11:37:12 -07:00
|
|
|
deconsted->accept(&v);
|
2010-06-22 12:09:21 -07:00
|
|
|
}
|
|
|
|
|
2013-06-12 16:10:33 -07:00
|
|
|
extern "C" {
|
2010-04-28 13:04:15 -07:00
|
|
|
void
|
2014-02-20 18:00:23 -08:00
|
|
|
_mesa_print_ir(FILE *f, exec_list *instructions,
|
2010-04-28 13:04:15 -07:00
|
|
|
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
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(structure (%s) (%s@%p) (%u) (\n",
|
|
|
|
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++) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\t((");
|
|
|
|
print_type(f, s->fields.structure[j].type);
|
|
|
|
fprintf(f, ")(%s))\n", s->fields.structure[j].name);
|
2010-07-29 15:04:45 -07:00
|
|
|
}
|
2010-04-28 13:14:53 -07:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")\n");
|
2010-07-29 15:04:45 -07:00
|
|
|
}
|
2010-04-28 13:14:53 -07:00
|
|
|
}
|
2010-04-28 13:04:15 -07:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(\n");
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_instruction, ir, instructions) {
|
2014-02-20 18:00:23 -08:00
|
|
|
ir->fprint(f);
|
2010-07-29 14:20:39 -07:00
|
|
|
if (ir->ir_type != ir_type_function)
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-04-28 13:04:15 -07:00
|
|
|
}
|
2015-06-19 16:45:44 -06:00
|
|
|
fprintf(f, ")\n");
|
2010-04-28 13:04:15 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 18:16:22 -07:00
|
|
|
void
|
|
|
|
fprint_ir(FILE *f, const void *instruction)
|
|
|
|
{
|
|
|
|
const ir_instruction *ir = (const ir_instruction *)instruction;
|
|
|
|
ir->fprint(f);
|
|
|
|
}
|
|
|
|
|
2013-06-12 16:10:33 -07:00
|
|
|
} /* extern "C" */
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
ir_print_visitor::ir_print_visitor(FILE *f)
|
|
|
|
: f(f)
|
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
|
|
|
{
|
|
|
|
indentation = 0;
|
|
|
|
printable_names =
|
2015-08-03 02:15:20 +02:00
|
|
|
_mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
|
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
|
|
|
symbols = _mesa_symbol_table_ctor();
|
|
|
|
mem_ctx = ralloc_context(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ir_print_visitor::~ir_print_visitor()
|
|
|
|
{
|
2015-08-03 02:15:20 +02:00
|
|
|
_mesa_hash_table_destroy(printable_names, NULL);
|
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_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++)
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-07-29 14:36:59 -07:00
|
|
|
}
|
|
|
|
|
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? */
|
2015-08-03 02:15:20 +02:00
|
|
|
struct hash_entry * entry =
|
|
|
|
_mesa_hash_table_search(this->printable_names, var);
|
|
|
|
|
|
|
|
if (entry != NULL) {
|
|
|
|
return (const char *) entry->data;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/* If there's no conflict, just use the original name */
|
2015-08-03 02:15:20 +02:00
|
|
|
const char* name = NULL;
|
2016-10-21 16:50:52 +11:00
|
|
|
if (_mesa_symbol_table_find_symbol(this->symbols, var->name) == NULL) {
|
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
|
|
|
name = var->name;
|
|
|
|
} else {
|
|
|
|
static unsigned i = 1;
|
|
|
|
name = ralloc_asprintf(this->mem_ctx, "%s@%u", var->name, ++i);
|
|
|
|
}
|
2015-08-03 02:15:20 +02:00
|
|
|
_mesa_hash_table_insert(this->printable_names, var, (void *) name);
|
2016-10-21 16:50:52 +11:00
|
|
|
_mesa_symbol_table_add_symbol(this->symbols, name, var);
|
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
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2010-03-09 21:44:34 -08:00
|
|
|
static void
|
2014-02-20 18:00:23 -08:00
|
|
|
print_type(FILE *f, const glsl_type *t)
|
2010-03-09 21:44:34 -08:00
|
|
|
{
|
2017-04-21 10:25:42 +02:00
|
|
|
if (t->is_array()) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(array ");
|
|
|
|
print_type(f, t->fields.array);
|
|
|
|
fprintf(f, " %u)", t->length);
|
2017-04-21 10:32:39 +02:00
|
|
|
} else if (t->is_record() && !is_gl_identifier(t->name)) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%s@%p", t->name, (void *) t);
|
2010-03-09 21:44:34 -08:00
|
|
|
} else {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%s", t->name);
|
2010-03-09 21:44:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-27 14:17:53 -07:00
|
|
|
void ir_print_visitor::visit(ir_rvalue *)
|
2011-09-22 15:04:56 -07:00
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "error");
|
2011-09-22 15:04:56 -07:00
|
|
|
}
|
2010-03-09 16:23:37 -08:00
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_variable *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(declare ");
|
2010-03-09 16:23:37 -08:00
|
|
|
|
2016-10-13 15:27:00 +02:00
|
|
|
char binding[32] = {0};
|
|
|
|
if (ir->data.binding)
|
|
|
|
snprintf(binding, sizeof(binding), "binding=%i ", ir->data.binding);
|
|
|
|
|
2016-10-06 23:10:10 +02:00
|
|
|
char loc[32] = {0};
|
2015-03-19 23:28:25 +01:00
|
|
|
if (ir->data.location != -1)
|
|
|
|
snprintf(loc, sizeof(loc), "location=%i ", ir->data.location);
|
|
|
|
|
2016-10-06 23:10:10 +02:00
|
|
|
char component[32] = {0};
|
|
|
|
if (ir->data.explicit_component)
|
|
|
|
snprintf(component, sizeof(component), "component=%i ", ir->data.location_frac);
|
|
|
|
|
2016-11-30 10:38:55 +01:00
|
|
|
char stream[32] = {0};
|
|
|
|
if (ir->data.stream & (1u << 31)) {
|
|
|
|
if (ir->data.stream & ~(1u << 31)) {
|
|
|
|
snprintf(stream, sizeof(stream), "stream(%u,%u,%u,%u) ",
|
|
|
|
ir->data.stream & 3, (ir->data.stream >> 2) & 3,
|
|
|
|
(ir->data.stream >> 4) & 3, (ir->data.stream >> 6) & 3);
|
|
|
|
}
|
|
|
|
} else if (ir->data.stream) {
|
|
|
|
snprintf(stream, sizeof(stream), "stream%u ", ir->data.stream);
|
|
|
|
}
|
|
|
|
|
2017-04-26 18:34:09 +02:00
|
|
|
char image_format[32] = {0};
|
|
|
|
if (ir->data.image_format) {
|
|
|
|
snprintf(image_format, sizeof(image_format), "format=%x ",
|
|
|
|
ir->data.image_format);
|
|
|
|
}
|
|
|
|
|
2013-12-12 12:57:57 +02:00
|
|
|
const char *const cent = (ir->data.centroid) ? "centroid " : "";
|
|
|
|
const char *const samp = (ir->data.sample) ? "sample " : "";
|
2014-03-05 13:43:17 +01:00
|
|
|
const char *const patc = (ir->data.patch) ? "patch " : "";
|
2013-12-12 12:57:57 +02:00
|
|
|
const char *const inv = (ir->data.invariant) ? "invariant " : "";
|
2016-04-03 01:25:03 -07:00
|
|
|
const char *const prec = (ir->data.precise) ? "precise " : "";
|
2017-03-21 13:30:49 +01:00
|
|
|
const char *const bindless = (ir->data.bindless) ? "bindless " : "";
|
|
|
|
const char *const bound = (ir->data.bound) ? "bound " : "";
|
2017-04-26 18:34:09 +02:00
|
|
|
const char *const memory_read_only = (ir->data.memory_read_only) ? "readonly " : "";
|
|
|
|
const char *const memory_write_only = (ir->data.memory_write_only) ? "writeonly " : "";
|
|
|
|
const char *const memory_coherent = (ir->data.memory_coherent) ? "coherent " : "";
|
|
|
|
const char *const memory_volatile = (ir->data.memory_volatile) ? "volatile " : "";
|
|
|
|
const char *const memory_restrict = (ir->data.memory_restrict) ? "restrict " : "";
|
2015-11-08 19:07:43 -08:00
|
|
|
const char *const mode[] = { "", "uniform ", "shader_storage ",
|
2015-07-28 14:56:49 -07:00
|
|
|
"shader_shared ", "shader_in ", "shader_out ",
|
2013-01-11 14:39:32 -08:00
|
|
|
"in ", "out ", "inout ",
|
2011-01-12 15:37:37 -08:00
|
|
|
"const_in ", "sys ", "temporary " };
|
2013-04-09 10:03:11 -07:00
|
|
|
STATIC_ASSERT(ARRAY_SIZE(mode) == ir_var_mode_count);
|
2013-04-06 19:16:58 -07:00
|
|
|
const char *const interp[] = { "", "smooth", "flat", "noperspective" };
|
2016-07-07 02:02:38 -07:00
|
|
|
STATIC_ASSERT(ARRAY_SIZE(interp) == INTERP_MODE_COUNT);
|
2010-03-09 16:23:37 -08:00
|
|
|
|
2017-04-26 18:34:09 +02:00
|
|
|
fprintf(f, "(%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s) ",
|
|
|
|
binding, loc, component, cent, bindless, bound,
|
|
|
|
image_format, memory_read_only, memory_write_only,
|
|
|
|
memory_coherent, memory_volatile, memory_restrict,
|
|
|
|
samp, patc, inv, prec, mode[ir->data.mode],
|
|
|
|
stream,
|
2014-06-10 08:45:44 +02:00
|
|
|
interp[ir->data.interpolation]);
|
2010-03-09 21:44:34 -08:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
print_type(f, ir->type);
|
|
|
|
fprintf(f, " %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);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(signature ");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
print_type(f, ir->return_type);
|
|
|
|
fprintf(f, "\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(parameters\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_variable, inst, &ir->parameters) {
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-07 14:32:53 -07:00
|
|
|
inst->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-04-07 14:32:53 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
|
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
|
|
|
|
indent();
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
2010-04-07 14:32:53 -07:00
|
|
|
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_instruction, inst, &ir->body) {
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-07 13:19:11 -07:00
|
|
|
inst->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-04-07 13:19:11 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "))\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)
|
|
|
|
{
|
2015-04-20 10:22:57 +10:00
|
|
|
fprintf(f, "(%s function %s\n", ir->is_subroutine ? "subroutine" : "", ir->name);
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_function_signature, sig, &ir->signatures) {
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-21 12:30:22 -07:00
|
|
|
sig->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-04-21 12:30:22 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")\n\n");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_expression *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(expression ");
|
2010-03-25 18:25:37 -07:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
print_type(f, ir->type);
|
2010-04-07 16:36:32 -07:00
|
|
|
|
2015-04-15 17:55:32 -07:00
|
|
|
fprintf(f, " %s ", ir_expression_operation_strings[ir->operation]);
|
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
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ") ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-26 15:15:31 -07:00
|
|
|
void ir_print_visitor::visit(ir_texture *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(%s ", ir->opcode_string());
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2015-11-17 16:54:31 -08:00
|
|
|
if (ir->op == ir_samples_identical) {
|
|
|
|
ir->sampler->accept(this);
|
|
|
|
fprintf(f, " ");
|
|
|
|
ir->coordinate->accept(this);
|
|
|
|
fprintf(f, ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
print_type(f, ir->type);
|
|
|
|
fprintf(f, " ");
|
2011-02-25 14:29:36 -08:00
|
|
|
|
2010-05-26 15:15:31 -07:00
|
|
|
ir->sampler->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2015-08-27 23:03:46 -04:00
|
|
|
if (ir->op != ir_txs && ir->op != ir_query_levels &&
|
|
|
|
ir->op != ir_texture_samples) {
|
2011-02-25 14:45:33 -08:00
|
|
|
ir->coordinate->accept(this);
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
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 {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "0");
|
2011-02-25 14:45:33 -08:00
|
|
|
}
|
2011-01-08 23:49:23 -08:00
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2011-02-25 14:45:33 -08:00
|
|
|
}
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2013-09-26 19:37:30 +12:00
|
|
|
if (ir->op != ir_txf && ir->op != ir_txf_ms &&
|
|
|
|
ir->op != ir_txs && ir->op != ir_tg4 &&
|
2015-08-27 23:03:46 -04:00
|
|
|
ir->op != ir_query_levels && ir->op != ir_texture_samples) {
|
2010-05-26 15:15:31 -07:00
|
|
|
if (ir->projector)
|
|
|
|
ir->projector->accept(this);
|
|
|
|
else
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "1");
|
2010-05-26 15:15:31 -07:00
|
|
|
|
2016-12-12 08:32:38 -05:00
|
|
|
if (ir->shadow_comparator) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2016-12-12 08:32:38 -05:00
|
|
|
ir->shadow_comparator->accept(this);
|
2010-05-26 15:15:31 -07:00
|
|
|
} else {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ()");
|
2010-05-26 15:15:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-05-26 15:15:31 -07:00
|
|
|
switch (ir->op)
|
|
|
|
{
|
|
|
|
case ir_tex:
|
2012-09-23 19:50:41 +10:00
|
|
|
case ir_lod:
|
2013-09-26 19:37:30 +12:00
|
|
|
case ir_query_levels:
|
2015-08-27 23:03:46 -04:00
|
|
|
case ir_texture_samples:
|
2010-05-26 15:15:31 -07:00
|
|
|
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;
|
2012-12-21 21:33:37 +13:00
|
|
|
case ir_txf_ms:
|
|
|
|
ir->lod_info.sample_index->accept(this);
|
|
|
|
break;
|
2010-05-26 15:15:31 -07:00
|
|
|
case ir_txd:
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(");
|
2010-05-26 15:15:31 -07:00
|
|
|
ir->lod_info.grad.dPdx->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-05-26 15:15:31 -07:00
|
|
|
ir->lod_info.grad.dPdy->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
2010-05-26 15:15:31 -07:00
|
|
|
break;
|
2013-10-05 18:26:56 +13:00
|
|
|
case ir_tg4:
|
|
|
|
ir->lod_info.component->accept(this);
|
|
|
|
break;
|
2015-11-17 16:54:31 -08:00
|
|
|
case ir_samples_identical:
|
2016-08-30 11:36:01 +01:00
|
|
|
unreachable("ir_samples_identical was already handled");
|
2010-05-26 15:15:31 -07:00
|
|
|
};
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
2010-05-26 15:15:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(swiz ");
|
2010-03-26 01:20:08 -07:00
|
|
|
for (unsigned i = 0; i < ir->mask.num_components; i++) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%c", "xyzw"[swiz[i]]);
|
2010-03-26 01:20:08 -07:00
|
|
|
}
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-03-26 01:20:08 -07:00
|
|
|
ir->val->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
2010-03-26 01:20:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(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)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(array_ref ");
|
2010-05-19 13:52:29 +02:00
|
|
|
ir->array->accept(this);
|
|
|
|
ir->array_index->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ") ");
|
2010-05-19 13:20:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_dereference_record *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(record_ref ");
|
2010-05-19 13:52:29 +02:00
|
|
|
ir->record->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " %s) ", ir->field);
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_assignment *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(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';
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " (%s) ", mask);
|
2010-03-25 18:29:25 -07:00
|
|
|
|
2010-03-09 16:40:45 -08:00
|
|
|
ir->lhs->accept(this);
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-03-25 18:29:25 -07:00
|
|
|
|
2010-03-09 16:40:45 -08:00
|
|
|
ir->rhs->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ") ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ir_print_visitor::visit(ir_constant *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(constant ");
|
|
|
|
print_type(f, ir->type);
|
|
|
|
fprintf(f, " (");
|
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++) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(%s ", ir->type->fields.structure[i].name);
|
2010-12-02 10:11:49 -08:00
|
|
|
value->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
2010-12-02 10:11:49 -08:00
|
|
|
|
|
|
|
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)
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2011-10-25 12:55:54 -07:00
|
|
|
switch (ir->type->base_type) {
|
2014-02-20 18:00:23 -08:00
|
|
|
case GLSL_TYPE_UINT: fprintf(f, "%u", ir->value.u[i]); break;
|
|
|
|
case GLSL_TYPE_INT: fprintf(f, "%d", ir->value.i[i]); break;
|
2013-08-04 14:01:30 -07:00
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
if (ir->value.f[i] == 0.0f)
|
|
|
|
/* 0.0 == -0.0, so print with %f to get the proper sign. */
|
2014-05-27 21:23:02 -04:00
|
|
|
fprintf(f, "%f", ir->value.f[i]);
|
2013-11-25 22:18:28 -08:00
|
|
|
else if (fabs(ir->value.f[i]) < 0.000001f)
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%a", ir->value.f[i]);
|
2013-11-25 22:18:28 -08:00
|
|
|
else if (fabs(ir->value.f[i]) > 1000000.0f)
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%e", ir->value.f[i]);
|
2013-08-04 14:01:30 -07:00
|
|
|
else
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%f", ir->value.f[i]);
|
2013-08-04 14:01:30 -07:00
|
|
|
break;
|
2017-05-25 19:12:12 +02:00
|
|
|
case GLSL_TYPE_SAMPLER:
|
|
|
|
case GLSL_TYPE_IMAGE:
|
|
|
|
case GLSL_TYPE_UINT64:
|
|
|
|
fprintf(f, "%" PRIu64, ir->value.u64[i]);
|
|
|
|
break;
|
2016-09-02 13:17:48 -07:00
|
|
|
case GLSL_TYPE_INT64: fprintf(f, "%" PRIi64, ir->value.i64[i]); break;
|
2014-02-20 18:00:23 -08:00
|
|
|
case GLSL_TYPE_BOOL: fprintf(f, "%d", ir->value.b[i]); break;
|
2015-02-05 12:52:19 +02:00
|
|
|
case GLSL_TYPE_DOUBLE:
|
|
|
|
if (ir->value.d[i] == 0.0)
|
|
|
|
/* 0.0 == -0.0, so print with %f to get the proper sign. */
|
|
|
|
fprintf(f, "%.1f", ir->value.d[i]);
|
|
|
|
else if (fabs(ir->value.d[i]) < 0.000001)
|
|
|
|
fprintf(f, "%a", ir->value.d[i]);
|
|
|
|
else if (fabs(ir->value.d[i]) > 1000000.0)
|
|
|
|
fprintf(f, "%e", ir->value.d[i]);
|
|
|
|
else
|
|
|
|
fprintf(f, "%f", ir->value.d[i]);
|
|
|
|
break;
|
2016-09-02 13:15:24 -07:00
|
|
|
default:
|
|
|
|
unreachable("Invalid constant type");
|
2010-07-20 01:28:09 -07:00
|
|
|
}
|
2010-03-25 18:38:28 -07:00
|
|
|
}
|
|
|
|
}
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")) ");
|
2010-03-09 16:23:37 -08:00
|
|
|
}
|
2010-03-11 14:34:27 -08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_call *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(call %s ", ir->callee_name());
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 15:56:37 -07:00
|
|
|
if (ir->return_deref)
|
|
|
|
ir->return_deref->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " (");
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_rvalue, param, &ir->actual_parameters) {
|
2013-11-23 09:51:52 -08:00
|
|
|
param->accept(this);
|
2010-03-26 17:30:30 -07:00
|
|
|
}
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "))\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)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(return");
|
2010-03-19 16:44:52 -07:00
|
|
|
|
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) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-03-19 16:44:52 -07:00
|
|
|
value->accept(this);
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
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)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(discard ");
|
2010-06-30 10:47:34 -07:00
|
|
|
|
|
|
|
if (ir->condition != NULL) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, " ");
|
2010-06-30 10:47:34 -07:00
|
|
|
ir->condition->accept(this);
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")");
|
2010-06-30 10:47:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-29 14:11:25 -07:00
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_if *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(if ");
|
2010-03-29 14:11:25 -07:00
|
|
|
ir->condition->accept(this);
|
|
|
|
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_instruction, inst, &ir->then_instructions) {
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-03-29 14:11:25 -07:00
|
|
|
inst->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-03-29 14:11:25 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
|
|
|
|
indentation--;
|
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, ")\n");
|
2010-03-29 14:11:25 -07:00
|
|
|
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-08-12 14:55:48 -07:00
|
|
|
if (!ir->else_instructions.is_empty()) {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(\n");
|
2010-08-12 14:55:48 -07:00
|
|
|
indentation++;
|
2010-07-29 14:36:59 -07:00
|
|
|
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_instruction, inst, &ir->else_instructions) {
|
2010-08-12 14:55:48 -07:00
|
|
|
indent();
|
|
|
|
inst->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-08-12 14:55:48 -07:00
|
|
|
}
|
|
|
|
indentation--;
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "))\n");
|
2010-08-12 14:55:48 -07:00
|
|
|
} else {
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "())\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)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "(loop (\n");
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation++;
|
|
|
|
|
2014-06-24 21:34:05 -07:00
|
|
|
foreach_in_list(ir_instruction, inst, &ir->body_instructions) {
|
2010-07-29 14:36:59 -07:00
|
|
|
indent();
|
2010-04-05 16:16:07 -07:00
|
|
|
inst->accept(this);
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "\n");
|
2010-04-05 16:16:07 -07:00
|
|
|
}
|
2010-07-29 14:36:59 -07:00
|
|
|
indentation--;
|
|
|
|
indent();
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "))\n");
|
2010-04-05 16:16:07 -07:00
|
|
|
}
|
2010-04-05 16:28:15 -07:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ir_print_visitor::visit(ir_loop_jump *ir)
|
|
|
|
{
|
2014-02-20 18:00:23 -08:00
|
|
|
fprintf(f, "%s", ir->is_break() ? "break" : "continue");
|
2010-04-05 16:28:15 -07:00
|
|
|
}
|
2013-02-15 09:26:35 -06:00
|
|
|
|
|
|
|
void
|
2014-06-08 13:16:26 +02:00
|
|
|
ir_print_visitor::visit(ir_emit_vertex *ir)
|
2013-02-15 09:26:35 -06:00
|
|
|
{
|
2014-06-08 13:16:26 +02:00
|
|
|
fprintf(f, "(emit-vertex ");
|
|
|
|
ir->stream->accept(this);
|
|
|
|
fprintf(f, ")\n");
|
2013-02-15 09:26:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-08 13:16:26 +02:00
|
|
|
ir_print_visitor::visit(ir_end_primitive *ir)
|
2013-02-15 09:26:35 -06:00
|
|
|
{
|
2014-06-08 13:16:26 +02:00
|
|
|
fprintf(f, "(end-primitive ");
|
|
|
|
ir->stream->accept(this);
|
|
|
|
fprintf(f, ")\n");
|
2014-09-07 19:24:15 +12:00
|
|
|
}
|
2014-06-08 13:16:26 +02:00
|
|
|
|
2014-09-07 19:24:15 +12:00
|
|
|
void
|
2015-08-26 13:38:49 +01:00
|
|
|
ir_print_visitor::visit(ir_barrier *)
|
2014-09-07 19:24:15 +12:00
|
|
|
{
|
|
|
|
fprintf(f, "(barrier)\n");
|
2013-02-15 09:26:35 -06:00
|
|
|
}
|