glsl: Refactor out cloning of function prototypes.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 11 Nov 2010 20:21:27 +0000 (12:21 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Tue, 30 Nov 2010 21:48:28 +0000 (13:48 -0800)
This allows us to reuse some code and will be useful later.

src/glsl/ir.h
src/glsl/ir_clone.cpp
src/glsl/ir_import_prototypes.cpp

index 625397a59957b44d2da9e02d83a6d9d25fd213cb..102a68b65516a207d7f7bf29c78a60a0330d00be 100644 (file)
@@ -376,6 +376,8 @@ public:
 
    virtual ir_function_signature *clone(void *mem_ctx,
                                        struct hash_table *ht) const;
+   ir_function_signature *clone_prototype(void *mem_ctx,
+                                         struct hash_table *ht) const;
 
    virtual void accept(ir_visitor *v)
    {
index 325f60661541b37b073169fdf262dd0cb4c256a1..1522af682bb5d46ad0f185eb90d8cb36a214ac65 100644 (file)
@@ -275,14 +275,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_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;
@@ -293,15 +312,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;
 }
 
index 2bdc8d9fd7d21da85182303a241ce1dd7c9f2500..4e0b30aa90e155ee4ee4bf4430bb23c7b69e47eb 100644 (file)
@@ -82,22 +82,7 @@ public:
    {
       assert(this->function != NULL);
 
-      ir_function_signature *copy =
-        new(mem_ctx) ir_function_signature(ir->return_type);
-
-      copy->is_defined = false;
-      copy->is_builtin = ir->is_builtin;
-
-      /* Clone the parameter list, but NOT the body.
-       */
-      foreach_list_const(node, &ir->parameters) {
-        const ir_variable *const param = (const ir_variable *) node;
-
-        assert(const_cast<ir_variable *>(param)->as_variable() != NULL);
-
-        ir_variable *const param_copy = param->clone(mem_ctx, NULL);
-        copy->parameters.push_tail(param_copy);
-      }
+      ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL);
 
       this->function->add_signature(copy);