Start trying to fill in a few bits of ir_constant_expression.cpp
[mesa.git] / ir_print_visitor.cpp
index 8941d3c7b9fa694842d97217368de14e2304eeab..e6b24d2d5bce9456d43dc20a7d3b564428fd18e9 100644 (file)
@@ -86,10 +86,56 @@ void ir_print_visitor::visit(ir_function *ir)
 
 void ir_print_visitor::visit(ir_expression *ir)
 {
+   static const char *const operators[] = {
+      "~",
+      "!",
+      "-",
+      "abs",
+      "rcp",
+      "rsq",
+      "sqrt",
+      "exp",
+      "log",
+      "exp2",
+      "log2",
+      "f2i",
+      "i2f",
+      "u2f",
+      "trunc",
+      "ceil",
+      "floor",
+      "+",
+      "-",
+      "*",
+      "/",
+      "%",
+      "<",
+      ">",
+      "<=",
+      ">=",
+      "==",
+      "!=",
+      "<<",
+      ">>",
+      "&",
+      "^",
+      "|",
+      "&&",
+      "^^",
+      "||",
+      "!",
+      "dot",
+      "min",
+      "max",
+      "pow",
+   };
+
    printf("(expression ");
 
-   printf("(FINISHME: operator) ");
+   assert((unsigned int)ir->operation <
+         sizeof(operators) / sizeof(operators[0]));
 
+   printf("%s", operators[ir->operation]);
    printf("(");
    if (ir->operands[0])
       ir->operands[0]->accept(this);
@@ -102,26 +148,34 @@ void ir_print_visitor::visit(ir_expression *ir)
 }
 
 
+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(")");
+}
+
+
 void ir_print_visitor::visit(ir_dereference *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(")) ");
+      printf(") ");
       break;
    }
    case ir_dereference::ir_reference_array:
@@ -169,12 +223,8 @@ void ir_print_visitor::visit(ir_constant *ir)
    print_type(base_type);
    printf(") ");
 
-   const unsigned num_values = 1
-      * ((ir->type->vector_elements > 0) ? ir->type->vector_elements : 1)
-      * ((ir->type->matrix_columns > 0) ? ir->type->matrix_columns : 1);
-
-   printf("(%d) (", num_values);
-   for (unsigned i = 0; i < num_values; i++) {
+   printf("(%d) (", ir->type->components());
+   for (unsigned i = 0; i < ir->type->components(); i++) {
       if (i != 0)
         printf(", ");
 
@@ -193,10 +243,12 @@ void ir_print_visitor::visit(ir_constant *ir)
 void
 ir_print_visitor::visit(ir_call *ir)
 {
-   (void) ir;
+   printf("(call (%s) ", ir->callee_name());
+   foreach_iter(exec_list_iterator, iter, *ir) {
+      ir_instruction *const inst = (ir_instruction *) iter.get();
 
-   printf("(call FINISHME: function name here\n");
-   printf("    (FINISHME: function paramaters here))\n");
+      inst->accept(this);
+   }
 }
 
 
@@ -213,3 +265,27 @@ ir_print_visitor::visit(ir_return *ir)
 
    printf(")");
 }
+
+
+void
+ir_print_visitor::visit(ir_if *ir)
+{
+   printf("(if ");
+   ir->condition->accept(this);
+
+   printf("(\n");
+   foreach_iter(exec_list_iterator, iter, ir->then_instructions) {
+      ir_instruction *const inst = (ir_instruction *) iter.get();
+
+      inst->accept(this);
+   }
+   printf(")\n");
+
+   printf("(\n");
+   foreach_iter(exec_list_iterator, iter, ir->else_instructions) {
+      ir_instruction *const inst = (ir_instruction *) iter.get();
+
+      inst->accept(this);
+   }
+   printf("))\n");
+}