Merge branch 'master' into i915-superioctl
[mesa.git] / src / mesa / shader / prog_print.c
index 0d21912a0eed03da01fc91c645aad69f0b5ca242..e92837f739ef4030fbd58769806a66ec3184a80f 100644 (file)
@@ -361,8 +361,8 @@ writemask_string(GLuint writeMask)
 }
 
 
-static const char *
-condcode_string(GLuint condcode)
+const char *
+_mesa_condcode_string(GLuint condcode)
 {
    switch (condcode) {
    case COND_GT:  return "GT";
@@ -388,6 +388,12 @@ print_dst_reg(const struct prog_dst_register *dstReg, gl_prog_print_mode mode,
                            dstReg->Index, mode, prog),
                 writemask_string(dstReg->WriteMask));
 
+   if (dstReg->CondMask != COND_TR) {
+      _mesa_printf(" (%s.%s)",
+                   _mesa_condcode_string(dstReg->CondMask),
+                   _mesa_swizzle_string(dstReg->CondSwizzle, GL_FALSE, GL_FALSE));
+   }
+
 #if 0
    _mesa_printf("%s[%d]%s",
                 file_string((enum register_file) dstReg->File, mode),
@@ -426,7 +432,7 @@ print_comment(const struct prog_instruction *inst)
 
 static void
 print_alu_instruction(const struct prog_instruction *inst,
-                      const char *opcode_string,  GLuint numRegs,
+                      const char *opcode_string, GLuint numRegs,
                       gl_prog_print_mode mode,
                       const struct gl_program *prog)
 {
@@ -461,6 +467,14 @@ print_alu_instruction(const struct prog_instruction *inst,
 }
 
 
+void
+_mesa_print_alu_instruction(const struct prog_instruction *inst,
+                            const char *opcode_string, GLuint numRegs)
+{
+   print_alu_instruction(inst, opcode_string, numRegs, PROG_PRINT_DEBUG, NULL);
+}
+
+
 void
 _mesa_print_instruction(const struct prog_instruction *inst)
 {
@@ -547,21 +561,27 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
       print_comment(inst);
       break;
    case OPCODE_BRA:
-      _mesa_printf("BRA %u (%s%s)",
+      _mesa_printf("BRA %d (%s%s)",
                    inst->BranchTarget,
-                   condcode_string(inst->DstReg.CondMask),
+                   _mesa_condcode_string(inst->DstReg.CondMask),
                    _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
       print_comment(inst);
       break;
-   case OPCODE_CAL:
-      _mesa_printf("CAL %u", inst->BranchTarget);
-      print_comment(inst);
-      break;
    case OPCODE_IF:
-      _mesa_printf("IF (%s%s); # (if false, goto %d)",
-                   condcode_string(inst->DstReg.CondMask),
-                   _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
-                   inst->BranchTarget);
+      if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) {
+         /* Use ordinary register */
+         _mesa_printf("IF ");
+         print_src_reg(&inst->SrcReg[0], mode, prog);
+         _mesa_printf("; ");
+      }
+      else {
+         /* Use cond codes */
+         _mesa_printf("IF (%s%s);",
+                      _mesa_condcode_string(inst->DstReg.CondMask),
+                      _mesa_swizzle_string(inst->DstReg.CondSwizzle,
+                                           0, GL_FALSE));
+      }
+      _mesa_printf(" # (if false, goto %d)", inst->BranchTarget);
       print_comment(inst);
       return indent + 3;
    case OPCODE_ELSE:
@@ -577,27 +597,47 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst, GLint indent,
       _mesa_printf("ENDLOOP; # (goto %d)\n", inst->BranchTarget);
       break;
    case OPCODE_BRK:
-      _mesa_printf("BRK (%s%s); #(goto %d)",
-                   condcode_string(inst->DstReg.CondMask),
-                   _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
-                   inst->BranchTarget);
-      print_comment(inst);
-      break;
    case OPCODE_CONT:
-      _mesa_printf("CONT (%s%s); #(goto %d)",
-                   condcode_string(inst->DstReg.CondMask),
+      _mesa_printf("%s (%s%s); # (goto %d)",
+                   _mesa_opcode_string(inst->Opcode),
+                   _mesa_condcode_string(inst->DstReg.CondMask),
                    _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE),
                    inst->BranchTarget);
       print_comment(inst);
       break;
+
    case OPCODE_BGNSUB:
-      _mesa_printf("SUB");
-      print_comment(inst);
-      return indent + 3;
+      if (mode == PROG_PRINT_NV) {
+         _mesa_printf("%s:\n", inst->Comment); /* comment is label */
+         return indent;
+      }
+      else {
+         _mesa_printf("BGNSUB");
+         print_comment(inst);
+         return indent + 3;
+      }
    case OPCODE_ENDSUB:
-      _mesa_printf("ENDSUB");
+      if (mode == PROG_PRINT_DEBUG) {
+         _mesa_printf("ENDSUB");
+         print_comment(inst);
+      }
+      break;
+   case OPCODE_CAL:
+      if (mode == PROG_PRINT_NV) {
+         _mesa_printf("CAL %s;  # (goto %d)\n", inst->Comment, inst->BranchTarget);
+      }
+      else {
+         _mesa_printf("CAL %u", inst->BranchTarget);
+         print_comment(inst);
+      }
+      break;
+   case OPCODE_RET:
+      _mesa_printf("RET (%s%s)",
+                   _mesa_condcode_string(inst->DstReg.CondMask),
+                   _mesa_swizzle_string(inst->DstReg.CondSwizzle, 0, GL_FALSE));
       print_comment(inst);
       break;
+
    case OPCODE_END:
       _mesa_printf("END\n");
       break;