r300/compiler: Clear empty registers after constant folding
[mesa.git] / src / glsl / glsl_types.cpp
index 9b1bef6cb8566e07130bc98e037ea59b00087687..82eb470605689761b387e8c4f1a18963a7e5875f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <cstdio>
 #include <stdlib.h>
+#include "main/core.h" /* for Elements */
 #include "glsl_symbol_table.h"
 #include "glsl_parser_extras.h"
 #include "glsl_types.h"
@@ -39,7 +40,7 @@ void
 glsl_type::init_talloc_type_ctx(void)
 {
    if (glsl_type::mem_ctx == NULL) {
-      glsl_type::mem_ctx = talloc_init("glsl_type");
+      glsl_type::mem_ctx = talloc_autofree_context();
       assert(glsl_type::mem_ctx != NULL);
    }
 }
@@ -110,9 +111,8 @@ add_types_to_symbol_table(glsl_symbol_table *symtab,
    }
 }
 
-
 void
-glsl_type::generate_110_types(glsl_symbol_table *symtab)
+glsl_type::generate_100ES_types(glsl_symbol_table *symtab)
 {
    add_types_to_symbol_table(symtab, builtin_core_types,
                             Elements(builtin_core_types),
@@ -120,10 +120,20 @@ glsl_type::generate_110_types(glsl_symbol_table *symtab)
    add_types_to_symbol_table(symtab, builtin_structure_types,
                             Elements(builtin_structure_types),
                             false);
+   add_types_to_symbol_table(symtab, &void_type, 1, false);
+}
+
+void
+glsl_type::generate_110_types(glsl_symbol_table *symtab)
+{
+   generate_100ES_types(symtab);
+
+   add_types_to_symbol_table(symtab, builtin_110_types,
+                            Elements(builtin_110_types),
+                            false);
    add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
                             Elements(builtin_110_deprecated_structure_types),
                             false);
-   add_types_to_symbol_table(symtab, & void_type, 1, false);
 }
 
 
@@ -172,6 +182,10 @@ void
 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
 {
    switch (state->language_version) {
+   case 100:
+      assert(state->es_shader);
+      glsl_type::generate_100ES_types(state->symbols);
+      break;
    case 110:
       glsl_type::generate_110_types(state->symbols);
       break;
@@ -228,72 +242,6 @@ _mesa_glsl_release_types(void)
       hash_table_dtor(glsl_type::record_types);
       glsl_type::record_types = NULL;
    }
-
-   if (glsl_type::mem_ctx != NULL) {
-      talloc_free(glsl_type::mem_ctx);
-      glsl_type::mem_ctx = NULL;
-   }
-}
-
-
-ir_function *
-glsl_type::generate_constructor(glsl_symbol_table *symtab) const
-{
-   void *ctx = symtab;
-
-   /* Generate the function name and add it to the symbol table.
-    */
-   ir_function *const f = new(ctx) ir_function(name);
-
-   bool added = symtab->add_function(name, f);
-   assert(added);
-
-   ir_function_signature *const sig = new(ctx) ir_function_signature(this);
-   f->add_signature(sig);
-
-   ir_variable **declarations =
-      (ir_variable **) malloc(sizeof(ir_variable *) * this->length);
-   for (unsigned i = 0; i < length; i++) {
-      char *const param_name = (char *) malloc(10);
-
-      snprintf(param_name, 10, "p%08X", i);
-
-      ir_variable *var = (this->base_type == GLSL_TYPE_ARRAY)
-        ? new(ctx) ir_variable(fields.array, param_name, ir_var_in)
-        : new(ctx) ir_variable(fields.structure[i].type, param_name, ir_var_in);
-
-      declarations[i] = var;
-      sig->parameters.push_tail(var);
-   }
-
-   /* Generate the body of the constructor.  The body assigns each of the
-    * parameters to a portion of a local variable called _ret_val that has
-    * the same type as the constructor.  After initializing _ret_val,
-    * _ret_val is returned.
-    */
-   ir_variable *retval = new(ctx) ir_variable(this, "_ret_val", ir_var_auto);
-   sig->body.push_tail(retval);
-
-   for (unsigned i = 0; i < length; i++) {
-      ir_dereference *const lhs = (this->base_type == GLSL_TYPE_ARRAY)
-        ? (ir_dereference *) new(ctx) ir_dereference_array(retval,
-                                                           new(ctx) ir_constant(i))
-        : (ir_dereference *) new(ctx) ir_dereference_record(retval,
-                                                            fields.structure[i].name);
-
-      ir_dereference *const rhs = new(ctx) ir_dereference_variable(declarations[i]);
-      ir_instruction *const assign = new(ctx) ir_assignment(lhs, rhs, NULL);
-
-      sig->body.push_tail(assign);
-   }
-
-   free(declarations);
-
-   ir_dereference *const retref = new(ctx) ir_dereference_variable(retval);
-   ir_instruction *const inst = new(ctx) ir_return(retref);
-   sig->body.push_tail(inst);
-
-   return f;
 }
 
 
@@ -400,7 +348,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
     * named 'foo'.
     */
    char key[128];
-   snprintf(key, sizeof(key), "%p[%u]", base, array_size);
+   snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size);
 
    const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
    if (t == NULL) {
@@ -458,7 +406,7 @@ glsl_type::record_key_hash(const void *a)
         break;
 
       size += snprintf(& hash_key[size], sizeof(hash_key) - size,
-                      "%p", key->fields.structure[i].type);
+                      "%p", (void *) key->fields.structure[i].type);
    }
 
    return hash_table_string_hash(& hash_key);