From 756a3fac4fbbc6b3785715db745f8d58a14baeb9 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 4 Jun 2010 16:34:38 -0700 Subject: [PATCH] Construct an ir_constant from a list of ir_constant values --- ir.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ ir.h | 5 +++++ 2 files changed, 50 insertions(+) diff --git a/ir.cpp b/ir.cpp index 7e5873b646c..759bf9f804a 100644 --- 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 033d6f2261e..60164a5ab1c 100644 --- 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 * -- 2.30.2