ir->replace_with(result);
}
- if (all_parameters_are_constant) {
- /* FINISHME: Add support for generating constant arrays. */
- }
+ if (all_parameters_are_constant)
+ return new(ctx) ir_constant(constructor_type, &actual_parameters);
ir_variable *var = new(ctx) ir_variable(constructor_type, "array_ctor",
ir_var_temporary);
this->ir_type = ir_type_constant;
this->type = type;
- /* FINISHME: Support array types. */
assert(type->is_scalar() || type->is_vector() || type->is_matrix()
- || type->is_record());
+ || type->is_record() || type->is_array());
+
+ if (type->is_array()) {
+ this->array_elements = talloc_array(this, ir_constant *, type->length);
+ unsigned i = 0;
+ foreach_list(node, value_list) {
+ ir_constant *value = (ir_constant *) node;
+ assert(value->as_constant() != NULL);
+
+ this->array_elements[i++] = value;
+ }
+ return;
+ }
/* If the constant is a record, the types of each of the entries in
* value_list must be a 1-for-1 match with the structure components. Each
return 0;
}
+ir_constant *
+ir_constant::get_array_element(unsigned i) const
+{
+ assert(this->type->is_array());
+ assert(i < this->type->length);
+
+ return array_elements[i];
+}
ir_constant *
ir_constant::get_record_field(const char *name)
unsigned get_uint_component(unsigned i) const;
/*@}*/
+ ir_constant *get_array_element(unsigned i) const;
+
ir_constant *get_record_field(const char *name);
/**
*/
union ir_constant_data value;
+ /* Array elements */
+ ir_constant **array_elements;
+
+ /* Structure fields */
exec_list components;
private:
return c;
}
+ case GLSL_TYPE_ARRAY: {
+ ir_constant *c = new(ctx) ir_constant;
+
+ c->type = this->type;
+ c->array_elements = talloc_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(NULL);
+ }
+ return c;
+ }
+
default:
assert(!"Should not get here."); break;
return NULL;