IR print visitor: Print out something for the operator.
authorEric Anholt <eric@anholt.net>
Fri, 26 Mar 2010 18:00:07 +0000 (11:00 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Sat, 27 Mar 2010 00:51:40 +0000 (17:51 -0700)
ir.h
ir_print_visitor.cpp

diff --git a/ir.h b/ir.h
index e6cdf29ebd6ef19fb67a4d55a94f7b838cf53aef..c52efe61781d9583f963907a6cd5e517367d7b0c 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -217,7 +217,7 @@ public:
    ir_rvalue *condition;
 };
 
-
+/* Update ir_print_visitor.cpp when updating this list. */
 enum ir_expression_operation {
    ir_unop_bit_not,
    ir_unop_logic_not,
index 6d0f797807c7caee1b1a90d2590730f3bc5d0a59..f055e8f1d8f2e92dd65fccaf628cd8650ebec1fc 100644 (file)
@@ -86,22 +86,53 @@ void ir_print_visitor::visit(ir_function *ir)
 
 void ir_print_visitor::visit(ir_expression *ir)
 {
-   printf("(expression ");
+   static const char *const operators[] = {
+      "~",
+      "!",
+      "-",
+      "abs",
+      "rcp",
+      "rsq",
+      "exp",
+      "log",
+      "f2i",
+      "i2f",
+      "u2f",
+      "trunc",
+      "ceil",
+      "floor",
+      "+",
+      "-",
+      "*",
+      "/",
+      "%",
+      "<",
+      ">",
+      "<=",
+      ">=",
+      "==",
+      "!=",
+      "<<",
+      ">>",
+      "&",
+      "^",
+      "|",
+      "&&",
+      "^^",
+      "||",
+      "!",
+      "dot",
+      "min",
+      "max",
+   };
 
-   const char *str;
-   char buf[256];
+   printf("(expression ");
 
-   switch (ir->operation) {
-   case ir_unop_f2i: str = "f2i"; break;
-   case ir_unop_i2f: str = "i2f"; break;
-   case ir_unop_u2f: str = "u2f"; break;
-   default:
-      snprintf(buf, sizeof(buf), "operator %u", ir->operation);
-      str = buf;
-      break;
-   }
+   assert((unsigned int)ir->operation <
+         sizeof(operators) / sizeof(operators[0]));
 
-   printf("(%s) (", str);
+   printf("%s", operators[ir->operation]);
+   printf("(");
    if (ir->operands[0])
       ir->operands[0]->accept(this);
    printf(") ");