Track and print user defined structure types
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 28 Apr 2010 20:14:53 +0000 (13:14 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 29 Apr 2010 01:22:54 +0000 (18:22 -0700)
ast_to_hir.cpp
glsl_parser_extras.h
ir_print_visitor.cpp

index e0913dd972932696897e463fe8e6b7ed871e567a..357683f0c3de5f84c2860a895ab6b4137c2a01c4 100644 (file)
@@ -2375,6 +2375,16 @@ ast_struct_specifier::hir(exec_list *instructions,
       } else {
         t->generate_constructor(state->symbols);
       }
+
+      const glsl_type **s = (const glsl_type **)
+        realloc(state->user_structures,
+                sizeof(state->user_structures[0]) *
+                (state->num_user_structures + 1));
+      if (s != NULL) {
+        s[state->num_user_structures] = t;
+        state->user_structures = s;
+        state->num_user_structures++;
+      }
    }
 
    /* Structure type definitions do not have r-values.
index 55bcc72e9401d28dbad7fbd9b8e836e248dfb86a..125c675a9212c2c6de4171d74cb8adf972f06e0e 100644 (file)
@@ -61,6 +61,10 @@ struct _mesa_glsl_parse_state {
    /** Loop or switch statement containing the current instructions. */
    class ir_instruction *loop_or_switch_nesting;
 
+   /** List of structures defined in user code. */
+   const glsl_type **user_structures;
+   unsigned num_user_structures;
+
    /**
     * \name Enable bits for GLSL extensions
     */
index 272e892a1ec65c50715ac977a7d6bc64c4403488..9edb68038535aaadc7cab4dfaefa8ace56132ff7 100644 (file)
 #include <cstdio>
 #include "ir_print_visitor.h"
 #include "glsl_types.h"
+#include "glsl_parser_extras.h"
+
+static void print_type(const glsl_type *t);
 
 void
 _mesa_print_ir(exec_list *instructions,
               struct _mesa_glsl_parse_state *state)
 {
-   (void) state;
+   for (unsigned i = 0; i < state->num_user_structures; i++) {
+      const glsl_type *const s = state->user_structures[i];
+
+      printf("(structure (%s) (%s@%08x) (%u) (\n",
+            s->name, s->name, (unsigned) s, s->length
+            );
+
+      for (unsigned j = 0; j < s->length; j++) {
+        printf("\t((");
+        print_type(s->fields.structure[j].type);
+        printf(")(%s))\n", s->fields.structure[j].name);
+      }
+
+      printf(")\n");
+   }
 
    printf("(\n");
    foreach_iter(exec_list_iterator, iter, *instructions) {
@@ -47,6 +64,9 @@ print_type(const glsl_type *t)
       printf("(array ");
       print_type(t->fields.array);
       printf(" %u)", t->length);
+   } else if ((t->base_type == GLSL_TYPE_STRUCT)
+             && (strncmp("gl_", t->name, 3) != 0)) {
+      printf("%s@%08x", t->name, (unsigned) t);
    } else {
       printf("%s", t->name);
    }