glsl: add SYSTEM_VALUE_VERTEX_CNT
[mesa.git] / src / glsl / ir_import_prototypes.cpp
index 20aa8a6ae238b6718f4737081fbe984d7ceb1b99..b0429fbc3afc90ba3a40de9339c1dff3be972da0 100644 (file)
  *
  * \author Ian Romanick
  */
-#include <cstdio>
 #include "ir.h"
 #include "glsl_symbol_table.h"
 
+namespace {
+
 /**
  * Visitor used to import function prototypes
  *
@@ -55,7 +56,17 @@ public:
    virtual ir_visitor_status visit_enter(ir_function *ir)
    {
       assert(this->function == NULL);
-      this->function = new(this->mem_ctx) ir_function(ir->name);
+
+      this->function = this->symbols->get_function(ir->name);
+      if (!this->function) {
+        this->function = new(this->mem_ctx) ir_function(ir->name);
+
+        list->push_tail(this->function);
+
+        /* Add the new function to the symbol table.
+         */
+        this->symbols->add_function(this->function);
+      }
       return visit_continue;
    }
 
@@ -64,15 +75,6 @@ public:
       (void) ir;
       assert(this->function != NULL);
 
-      /* Add the new function (and all its signatures) to the end of the
-       * instruction stream.
-       */
-      list->push_tail(this->function);
-
-      /* Add the new function to the symbol table.
-       */
-      this->symbols->add_function(this->function->name, this->function);
-
       this->function = NULL;
       return visit_continue;
    }
@@ -81,22 +83,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_built_in = ir->is_built_in;
-
-      /* 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(NULL);
-        copy->parameters.push_tail(param_copy);
-      }
+      ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL);
 
       this->function->add_signature(copy);
 
@@ -114,6 +101,7 @@ private:
    void *mem_ctx;
 };
 
+} /* anonymous namespace */
 
 /**
  * Import function prototypes from one IR tree into another
@@ -123,7 +111,7 @@ private:
  * \param dest     Destination instruction stream where new \c ir_function and
  *                 \c ir_function_signature nodes will be stored
  * \param symbols  Symbol table where new functions will be stored
- * \param mem_ctx  talloc memory context used for new allocations
+ * \param mem_ctx  ralloc memory context used for new allocations
  */
 void
 import_prototypes(const exec_list *source, exec_list *dest,