From 8c70a621939e55a81a363f04dee3333772339cbe Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 25 Mar 2010 17:38:13 -0700 Subject: [PATCH] IR print visitor: print ir_dereference instructions Also make a slight change to ir_variable. The ir_dereference tracks the number of nested dereferences. If an ir_variable is visited and the count is non-zero, just print the name of the variable. --- ir_print_visitor.cpp | 63 ++++++++++++++++++++++++++++++++++---------- ir_print_visitor.h | 4 +++ 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp index 8fe35bfa6e9..9e4c4412ae3 100644 --- a/ir_print_visitor.cpp +++ b/ir_print_visitor.cpp @@ -47,21 +47,24 @@ print_type(const glsl_type *t) void ir_print_visitor::visit(ir_variable *ir) { - printf("(declare "); - - const char *const cent = (ir->centroid) ? "centroid " : ""; - const char *const inv = (ir->invariant) ? "invariant " : ""; - const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " }; - const char *const interp[] = { "", "flat", "noperspective" }; + if (deref_depth) { + printf("(%s)", ir->name); + } else { + printf("(declare "); - printf("(%s%s%s%s) ", - cent, inv, mode[ir->mode], interp[ir->interpolation]); + const char *const cent = (ir->centroid) ? "centroid " : ""; + const char *const inv = (ir->invariant) ? "invariant " : ""; + const char *const mode[] = { "", "uniform ", "in ", "out ", "inout " }; + const char *const interp[] = { "", "flat", "noperspective" }; - printf("("); - print_type(ir->type); - printf(") "); + printf("(%s%s%s%s) ", + cent, inv, mode[ir->mode], interp[ir->interpolation]); - printf("(%s))\n", ir->name); + printf("("); + print_type(ir->type); + printf(") "); + printf("(%s))\n", ir->name); + } } @@ -94,8 +97,40 @@ void ir_print_visitor::visit(ir_expression *ir) void ir_print_visitor::visit(ir_dereference *ir) { - printf("%s:%d:\n", __func__, __LINE__); - (void) ir; + deref_depth++; + + switch (ir->mode) { + case ir_dereference::ir_reference_variable: { + const unsigned swiz[4] = { + ir->selector.swizzle.x, + ir->selector.swizzle.y, + ir->selector.swizzle.z, + ir->selector.swizzle.w, + }; + + printf("(var_ref "); + ir->var->accept(this); + printf("("); + for (unsigned i = 0; i < ir->selector.swizzle.num_components; i++) { + printf("%c", "xyzw"[swiz[i]]); + } + printf("))\n"); + break; + } + case ir_dereference::ir_reference_array: + printf("(array_ref "); + ir->var->accept(this); + ir->selector.array_index->accept(this); + printf(")\n"); + break; + case ir_dereference::ir_reference_record: + printf("(record_ref "); + ir->var->accept(this); + printf("(%s))\n", ir->selector.field); + break; + } + + deref_depth--; } diff --git a/ir_print_visitor.h b/ir_print_visitor.h index 121b7e8bb68..a4309c4f2a4 100644 --- a/ir_print_visitor.h +++ b/ir_print_visitor.h @@ -35,6 +35,7 @@ class ir_print_visitor : public ir_visitor { public: ir_print_visitor() + : deref_depth(0) { /* empty */ } @@ -63,6 +64,9 @@ public: virtual void visit(ir_call *); virtual void visit(ir_return *); /*@}*/ + +private: + int deref_depth; }; #endif /* IR_PRINT_VISITOR_H */ -- 2.30.2