[g3dvl] remove some unneeded Makefiles
[mesa.git] / src / glsl / ir_clone.cpp
index 0a9e25a295a3815f4e270bfef9a5f75bd48cbb8c..069bb85e8ded0978e477359e612bd45fd60a8a23 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <string.h>
+#include "main/compiler.h"
 #include "ir.h"
 #include "glsl_types.h"
 extern "C" {
@@ -51,6 +52,21 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
    var->warn_extension = this->warn_extension;
    var->origin_upper_left = this->origin_upper_left;
    var->pixel_center_integer = this->pixel_center_integer;
+   var->explicit_location = this->explicit_location;
+
+   var->num_state_slots = this->num_state_slots;
+   if (this->state_slots) {
+      /* FINISHME: This really wants to use something like talloc_reference, but
+       * FINISHME: ralloc doesn't have any similar function.
+       */
+      var->state_slots = ralloc_array(var, ir_state_slot,
+                                     this->num_state_slots);
+      memcpy(var->state_slots, this->state_slots,
+            sizeof(this->state_slots[0]) * var->num_state_slots);
+   }
+
+   if (this->explicit_location)
+      var->location = this->location;
 
    if (this->constant_value)
       var->constant_value = this->constant_value->clone(mem_ctx, ht);
@@ -134,12 +150,16 @@ ir_loop::clone(void *mem_ctx, struct hash_table *ht) const
       new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht));
    }
 
+   new_loop->cmp = this->cmp;
    return new_loop;
 }
 
 ir_call *
 ir_call::clone(void *mem_ctx, struct hash_table *ht) const
 {
+   if (this->type == glsl_type::error_type)
+      return ir_call::get_error_instruction(mem_ctx);
+
    exec_list new_parameters;
 
    foreach_iter(exec_list_iterator, iter, this->actual_parameters) {
@@ -153,14 +173,15 @@ ir_call::clone(void *mem_ctx, struct hash_table *ht) const
 ir_expression *
 ir_expression::clone(void *mem_ctx, struct hash_table *ht) const
 {
-   ir_rvalue *op[2] = {NULL, NULL};
+   ir_rvalue *op[Elements(this->operands)] = { NULL, };
    unsigned int i;
 
    for (i = 0; i < get_num_operands(); i++) {
       op[i] = this->operands[i]->clone(mem_ctx, ht);
    }
 
-   return new(mem_ctx) ir_expression(this->operation, this->type, op[0], op[1]);
+   return new(mem_ctx) ir_expression(this->operation, this->type,
+                                    op[0], op[1], op[2], op[3]);
 }
 
 ir_dereference_variable *
@@ -208,8 +229,8 @@ ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
       new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht);
    }
 
-   for (int i = 0; i < 3; i++)
-      new_tex->offsets[i] = this->offsets[i];
+   if (this->offset != NULL)
+      new_tex->offset = this->offset->clone(mem_ctx, ht);
 
    switch (this->op) {
    case ir_tex:
@@ -266,14 +287,33 @@ ir_function::clone(void *mem_ctx, struct hash_table *ht) const
 
 ir_function_signature *
 ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const
+{
+   ir_function_signature *copy = this->clone_prototype(mem_ctx, ht);
+
+   copy->is_defined = this->is_defined;
+
+   /* Clone the instruction list.
+    */
+   foreach_list_const(node, &this->body) {
+      const ir_instruction *const inst = (const ir_instruction *) node;
+
+      ir_instruction *const inst_copy = inst->clone(mem_ctx, ht);
+      copy->body.push_tail(inst_copy);
+   }
+
+   return copy;
+}
+
+ir_function_signature *
+ir_function_signature::clone_prototype(void *mem_ctx, struct hash_table *ht) const
 {
    ir_function_signature *copy =
       new(mem_ctx) ir_function_signature(this->return_type);
 
-   copy->is_defined = this->is_defined;
-   copy->is_built_in = this->is_built_in;
+   copy->is_defined = false;
+   copy->is_builtin = this->is_builtin;
 
-   /* Clone the parameter list.
+   /* Clone the parameter list, but NOT the body.
     */
    foreach_list_const(node, &this->parameters) {
       const ir_variable *const param = (const ir_variable *) node;
@@ -284,15 +324,6 @@ ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const
       copy->parameters.push_tail(param_copy);
    }
 
-   /* Clone the instruction list.
-    */
-   foreach_list_const(node, &this->body) {
-      const ir_instruction *const inst = (const ir_instruction *) node;
-
-      ir_instruction *const inst_copy = inst->clone(mem_ctx, ht);
-      copy->body.push_tail(inst_copy);
-   }
-
    return copy;
 }
 
@@ -327,7 +358,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
       ir_constant *c = new(mem_ctx) ir_constant;
 
       c->type = this->type;
-      c->array_elements = talloc_array(c, ir_constant *, this->type->length);
+      c->array_elements = ralloc_array(c, ir_constant *, this->type->length);
       for (unsigned i = 0; i < this->type->length; i++) {
         c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL);
       }