From: Kenneth Graunke Date: Thu, 27 May 2010 00:52:44 +0000 (-0700) Subject: ir_reader: Refactor reading of dereferences for later reuse. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c7934bfaae5dff410cddba3ac6696a8911c0c68;p=mesa.git ir_reader: Refactor reading of dereferences for later reuse. --- diff --git a/ir_reader.cpp b/ir_reader.cpp index f4b9967d449..019631f8080 100644 --- a/ir_reader.cpp +++ b/ir_reader.cpp @@ -53,6 +53,9 @@ static ir_expression *read_expression(_mesa_glsl_parse_state *, s_list *); static ir_call *read_call(_mesa_glsl_parse_state *, s_list *); static ir_swizzle *read_swizzle(_mesa_glsl_parse_state *, s_list *); static ir_constant *read_constant(_mesa_glsl_parse_state *, s_list *); + +static ir_dereference *read_dereference(_mesa_glsl_parse_state *, + s_expression *); static ir_dereference *read_var_ref(_mesa_glsl_parse_state *, s_list *); static ir_dereference *read_array_ref(_mesa_glsl_parse_state *, s_list *); static ir_dereference *read_record_ref(_mesa_glsl_parse_state *, s_list *); @@ -528,8 +531,10 @@ read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) return NULL; } - ir_rvalue *rvalue = NULL; - if (strcmp(tag->value(), "swiz") == 0) { + ir_rvalue *rvalue = read_dereference(st, list); + if (rvalue != NULL || st->error) + return rvalue; + else if (strcmp(tag->value(), "swiz") == 0) { rvalue = read_swizzle(st, list); } else if (strcmp(tag->value(), "assign") == 0) { rvalue = read_assignment(st, list); @@ -539,12 +544,6 @@ read_rvalue(_mesa_glsl_parse_state *st, s_expression *expr) rvalue = read_call(st, list); } else if (strcmp(tag->value(), "constant") == 0) { rvalue = read_constant(st, list); - } else if (strcmp(tag->value(), "var_ref") == 0) { - rvalue = read_var_ref(st, list); - } else if (strcmp(tag->value(), "array_ref") == 0) { - rvalue = read_array_ref(st, list); - } else if (strcmp(tag->value(), "record_ref") == 0) { - rvalue = read_record_ref(st, list); } else { ir_read_error(st, expr, "unrecognized rvalue tag: %s", tag->value()); } @@ -817,6 +816,25 @@ read_constant(_mesa_glsl_parse_state *st, s_list *list) return NULL; // should not be reached } +static ir_dereference * +read_dereference(_mesa_glsl_parse_state *st, s_expression *expr) +{ + s_list *list = SX_AS_LIST(expr); + if (list == NULL || list->subexpressions.is_empty()) + return NULL; + + s_symbol *tag = SX_AS_SYMBOL(list->subexpressions.head); + assert(tag != NULL); + + if (strcmp(tag->value(), "var_ref") == 0) + return read_var_ref(st, list); + if (strcmp(tag->value(), "array_ref") == 0) + return read_array_ref(st, list); + if (strcmp(tag->value(), "record_ref") == 0) + return read_record_ref(st, list); + return NULL; +} + static ir_dereference * read_var_ref(_mesa_glsl_parse_state *st, s_list *list) {