Add ir_dereference constructor for structure field dereferences
[mesa.git] / builtin_function.cpp
index 4243340b3d7b02046bdc0867bf521f704fbb3409..ff731c21625db2919190ba5f0cffb5e78df812e1 100644 (file)
@@ -253,8 +253,6 @@ generate_pow(exec_list *instructions,
 
 void
 generate_function_instance(ir_function *f,
-                          const char *name,
-                          exec_list *instructions,
                           int n_args,
                           void (*generate)(exec_list *instructions,
                                            ir_variable **declarations,
@@ -296,24 +294,20 @@ make_gentype_function(glsl_symbol_table *symtab, exec_list *instructions,
                                       const glsl_type *type))
 {
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec2_type, vec2_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec3_type, vec3_type);
-   generate_function_instance(f, name, instructions, n_args, generate,
-                             vec4_type, vec4_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec2_type, glsl_type::vec2_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec3_type, glsl_type::vec3_type);
+   generate_function_instance(f, n_args, generate,
+                             glsl_type::vec4_type, glsl_type::vec4_type);
 }
 
 static void
@@ -331,6 +325,7 @@ generate_vec_compare(exec_list *instructions,
    return_type = glsl_type::get_instance(GLSL_TYPE_BOOL,
                                         type->vector_elements, 1);
    temp = new ir_variable(return_type, "temp");
+   instructions->push_tail(temp);
 
    for (i = 0; i < type->vector_elements; i++) {
       ir_assignment *assign;
@@ -408,9 +403,6 @@ generate_vec_compare_function(glsl_symbol_table *symtab,
                              bool do_bool)
 {
    ir_function *const f = new ir_function(name);
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
    const glsl_type *ivec2_type = glsl_type::get_instance(GLSL_TYPE_INT, 2, 1);
    const glsl_type *ivec3_type = glsl_type::get_instance(GLSL_TYPE_INT, 3, 1);
    const glsl_type *ivec4_type = glsl_type::get_instance(GLSL_TYPE_INT, 4, 1);
@@ -426,33 +418,33 @@ generate_vec_compare_function(glsl_symbol_table *symtab,
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 2, generate,
-                             bvec2_type, vec2_type);
-   generate_function_instance(f, name, instructions, 2, generate,
-                             bvec3_type, vec3_type);
-   generate_function_instance(f, name, instructions, 2, generate,
-                             bvec4_type, vec4_type);
+   generate_function_instance(f, 2, generate,
+                             bvec2_type, glsl_type::vec2_type);
+   generate_function_instance(f, 2, generate,
+                             bvec3_type, glsl_type::vec3_type);
+   generate_function_instance(f, 2, generate,
+                             bvec4_type, glsl_type::vec4_type);
 
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec2_type, ivec2_type);
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec3_type, ivec3_type);
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec4_type, ivec4_type);
 
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec2_type, uvec2_type);
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec3_type, uvec3_type);
-   generate_function_instance(f, name, instructions, 2, generate,
+   generate_function_instance(f, 2, generate,
                              bvec4_type, uvec4_type);
 
    if (do_bool) {
-      generate_function_instance(f, name, instructions, 2, generate,
+      generate_function_instance(f, 2, generate,
                                 bvec2_type, bvec2_type);
-      generate_function_instance(f, name, instructions, 2, generate,
+      generate_function_instance(f, 2, generate,
                                 bvec3_type, bvec3_type);
-      generate_function_instance(f, name, instructions, 2, generate,
+      generate_function_instance(f, 2, generate,
                                 bvec4_type, bvec4_type);
    }
 }
@@ -481,24 +473,20 @@ generate_length_functions(glsl_symbol_table *symtab, exec_list *instructions)
 {
    const char *name = "length";
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_length,
-                             float_type, vec4_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec2_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec3_type);
+   generate_function_instance(f, 1, generate_length,
+                             glsl_type::float_type, glsl_type::vec4_type);
 }
 
 static void
@@ -523,24 +511,20 @@ generate_dot_functions(glsl_symbol_table *symtab, exec_list *instructions)
 {
    const char *name = "dot";
    ir_function *const f = new ir_function(name);
-   const glsl_type *float_type = glsl_type::float_type;
-   const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
-   const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
-   const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
 
    bool added = symtab->add_function(name, f);
    assert(added);
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 2, generate_dot,
-                             float_type, float_type);
-   generate_function_instance(f, name, instructions, 2, generate_dot,
-                             float_type, vec2_type);
-   generate_function_instance(f, name, instructions, 2, generate_dot,
-                             float_type, vec3_type);
-   generate_function_instance(f, name, instructions, 2, generate_dot,
-                             float_type, vec4_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::float_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec2_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec3_type);
+   generate_function_instance(f, 2, generate_dot,
+                             glsl_type::float_type, glsl_type::vec4_type);
 }
 
 static void
@@ -697,11 +681,11 @@ generate_any_functions(glsl_symbol_table *symtab, exec_list *instructions)
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 1, generate_any_bvec2,
+   generate_function_instance(f, 1, generate_any_bvec2,
                              glsl_type::bool_type, bvec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_any_bvec3,
+   generate_function_instance(f, 1, generate_any_bvec3,
                              glsl_type::bool_type, bvec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_any_bvec4,
+   generate_function_instance(f, 1, generate_any_bvec4,
                              glsl_type::bool_type, bvec4_type);
 }
 
@@ -719,11 +703,11 @@ generate_all_functions(glsl_symbol_table *symtab, exec_list *instructions)
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 1, generate_all_bvec2,
+   generate_function_instance(f, 1, generate_all_bvec2,
                              glsl_type::bool_type, bvec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_all_bvec3,
+   generate_function_instance(f, 1, generate_all_bvec3,
                              glsl_type::bool_type, bvec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_all_bvec4,
+   generate_function_instance(f, 1, generate_all_bvec4,
                              glsl_type::bool_type, bvec4_type);
 }
 
@@ -741,11 +725,11 @@ generate_not_functions(glsl_symbol_table *symtab, exec_list *instructions)
 
    instructions->push_tail(f);
 
-   generate_function_instance(f, name, instructions, 1, generate_not,
+   generate_function_instance(f, 1, generate_not,
                              bvec2_type, bvec2_type);
-   generate_function_instance(f, name, instructions, 1, generate_not,
+   generate_function_instance(f, 1, generate_not,
                              bvec3_type, bvec3_type);
-   generate_function_instance(f, name, instructions, 1, generate_not,
+   generate_function_instance(f, 1, generate_not,
                              bvec4_type, bvec4_type);
 }