From ef2c38b2450eb366a2e6f6a46d1725aa6c14d74b Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 20 Jul 2010 01:53:07 -0700 Subject: [PATCH] ir_reader: Add support for reading constant arrays. --- src/glsl/ir_reader.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 8b4be4100b0..2248e926d5d 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -753,7 +753,7 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) { void *ctx = st; if (list->length() != 3) { - ir_read_error(st, list, "expected (constant ( ... ))"); + ir_read_error(st, list, "expected (constant (...))"); return NULL; } @@ -764,10 +764,35 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) s_list *values = SX_AS_LIST(type_expr->next); if (values == NULL) { - ir_read_error(st, list, "expected (constant ( ... ))"); + ir_read_error(st, list, "expected (constant (...))"); return NULL; } + if (type->is_array()) { + const unsigned elements_supplied = values->length(); + if (elements_supplied != type->length) { + ir_read_error(st, values, "expected exactly %u array elements, " + "given %u", type->length, elements_supplied); + return NULL; + } + + exec_list elements; + foreach_iter(exec_list_iterator, it, values->subexpressions) { + s_expression *expr = (s_expression *) it.get(); + s_list *elt = SX_AS_LIST(expr); + if (elt == NULL) { + ir_read_error(st, expr, "expected (constant ...) array element"); + return NULL; + } + + ir_constant *ir_elt = read_constant(st, elt); + if (ir_elt == NULL) + return NULL; + elements.push_tail(ir_elt); + } + return new(ctx) ir_constant(type, &elements); + } + const glsl_type *const base_type = type->get_base_type(); ir_constant_data data; -- 2.30.2