Construct an ir_constant from a list of ir_constant values
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 4 Jun 2010 23:34:38 +0000 (16:34 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 20:51:09 +0000 (13:51 -0700)
ir.cpp
ir.h

diff --git a/ir.cpp b/ir.cpp
index 7e5873b646c8867cf1fcfeac4d33c3f198e2a612..759bf9f804a29bc4df098f37c628acd027c116d0 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -240,6 +240,51 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i)
    }
 }
 
+ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
+{
+   this->type = type;
+
+   /* FINISHME: Support structure and array types. */
+   assert(type->is_scalar() || type->is_vector() || type->is_matrix());
+
+   ir_constant *value = (ir_constant *) (value_list->head);
+
+   /* Use each component from each entry in the value_list to initialize one
+    * component of the constant being constructed.
+    */
+   for (unsigned i = 0; i < type->components(); /* empty */) {
+      assert(value->as_constant() != NULL);
+      assert(!value->is_tail_sentinal());
+
+      for (unsigned j = 0; j < value->type->components(); j++) {
+        switch (type->base_type) {
+        case GLSL_TYPE_UINT:
+           this->value.u[i] = value->get_uint_component(j);
+           break;
+        case GLSL_TYPE_INT:
+           this->value.i[i] = value->get_int_component(j);
+           break;
+        case GLSL_TYPE_FLOAT:
+           this->value.f[i] = value->get_float_component(j);
+           break;
+        case GLSL_TYPE_BOOL:
+           this->value.b[i] = value->get_bool_component(j);
+           break;
+        default:
+           /* FINISHME: What to do?  Exceptions are not the answer.
+            */
+           break;
+        }
+
+        i++;
+        if (i >= type->components())
+           break;
+      }
+
+      value = (ir_constant *) value->next;
+   }
+}
+
 bool
 ir_constant::get_bool_component(unsigned i) const
 {
diff --git a/ir.h b/ir.h
index 033d6f2261e9a470a45b077ccd2ae48d1b6130ce..60164a5ab1c388ed98cb285325f4f1edea37d2d4 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -1026,6 +1026,11 @@ public:
    ir_constant(int i);
    ir_constant(float f);
 
+   /**
+    * Construct an ir_constant from a list of ir_constant values
+    */
+   ir_constant(const struct glsl_type *type, exec_list *values);
+
    /**
     * Construct an ir_constant from a scalar component of another ir_constant
     *