[Mesa-dev] [PATCH 02/11] glsl: Make ir_reader able to read plain (return) statements.

Kenneth Graunke kenneth at whitecape.org
Thu Jul 7 01:20:33 PDT 2011


On 07/05/2011 03:07 PM, Paul Berry wrote:
> Previously ir_reader was only able to handle return of non-void.
>
> This patch is necessary in order to allow optimization passes to be
> tested in isolation.
> ---
>   src/glsl/ir_reader.cpp |   24 +++++++++++++-----------
>   1 files changed, 13 insertions(+), 11 deletions(-)

I wasn't sure if we wanted "(return)" or just "return", but this seems 
entirely reasonable [(return) and (return foo) are nice and symmetric]. 
  Plus it matches what the printer already does.

Thanks for catching this.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
> index 30df257..f3a6217 100644
> --- a/src/glsl/ir_reader.cpp
> +++ b/src/glsl/ir_reader.cpp
> @@ -482,19 +482,21 @@ ir_reader::read_return(s_expression *expr)
>   {
>      s_expression *s_retval;
>
> -   s_pattern pat[] = { "return", s_retval};
> -   if (!MATCH(expr, pat)) {
> -      ir_read_error(expr, "expected (return<rvalue>)");
> -      return NULL;
> -   }
> -
> -   ir_rvalue *retval = read_rvalue(s_retval);
> -   if (retval == NULL) {
> -      ir_read_error(NULL, "when reading return value");
> +   s_pattern return_value_pat[] = { "return", s_retval};
> +   s_pattern return_void_pat[] = { "return" };
> +   if (MATCH(expr, return_value_pat)) {
> +      ir_rvalue *retval = read_rvalue(s_retval);
> +      if (retval == NULL) {
> +         ir_read_error(NULL, "when reading return value");
> +         return NULL;
> +      }
> +      return new(mem_ctx) ir_return(retval);
> +   } else if (MATCH(expr, return_void_pat)) {
> +      return new(mem_ctx) ir_return;
> +   } else {
> +      ir_read_error(expr, "expected (return<rvalue>) or (return)");
>         return NULL;
>      }
> -
> -   return new(mem_ctx) ir_return(retval);
>   }
>
>



More information about the mesa-dev mailing list