summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-03-25 17:38:13 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-03-25 18:40:36 -0700
commit8c70a621939e55a81a363f04dee3333772339cbe (patch)
tree0e54585385d44cbbb9b00c271e13af47d6eac61e
parent6e7c278e243e506dd10cc7e0ca5768c187c33b27 (diff)
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.
-rw-r--r--ir_print_visitor.cpp63
-rw-r--r--ir_print_visitor.h4
2 files changed, 53 insertions, 14 deletions
diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp
index 8fe35bfa6e..9e4c4412ae 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 121b7e8bb6..a4309c4f2a 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 */