[Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
V2: Pointed out by Timothy running the CI
   - Fix pp.c reralloc size issue and comment

V3 - Use vprintf instead of printf where we should
   - Fixes failing make-check tests
---
 src/compiler/glsl/glcpp/glcpp-parse.y | 85 ++-
 src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
 src/compiler/glsl/glcpp/pp.c  | 39 +++-
 3 files changed, 64 insertions(+), 68 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
b/src/compiler/glsl/glcpp/glcpp-parse.y
index fe211a0f0b..e84b6fb055 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -209,7 +209,7 @@ line:
 |  SPACE control_line
 |  text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  expanded_line
 ;
@@ -228,20 +228,16 @@ expanded_line:
 |  LINE_EXPANDED integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
-   ralloc_asprintf_rewrite_tail (&parser->output,
- &parser->output_length,
- "#line %" PRIiMAX "\n",
- $2);
+   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
"\n", $2);
}
 |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
parser->has_new_source_number = 1;
parser->new_source_number = $3;
-   ralloc_asprintf_rewrite_tail (&parser->output,
- &parser->output_length,
- "#line %" PRIiMAX " %" PRIiMAX 
"\n",
- $2, $3);
+   _mesa_string_buffer_printf(parser->output,
+  "#line %" PRIiMAX " %" PRIiMAX "\n",
+   $2, $3);
}
 ;
 
@@ -259,7 +255,7 @@ define:
 
 control_line:
control_line_success {
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  control_line_error
 |  HASH_TOKEN LINE pp_tokens NEWLINE {
@@ -432,7 +428,7 @@ control_line_success:
glcpp_parser_resolve_implicit_version(parser);
}
 |  HASH_TOKEN PRAGMA NEWLINE {
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "#%s", $2);
+   _mesa_string_buffer_printf(parser->output, "#%s", $2);
}
 ;
 
@@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
token_list_t *b)
 }
 
 static void
-_token_print(char **out, size_t *len, token_t *token)
+_token_print(struct _mesa_string_buffer *out, token_t *token)
 {
if (token->type < 256) {
-  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+  _mesa_string_buffer_printf(out,"%c", token->type);
   return;
}
 
switch (token->type) {
case INTEGER:
-  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
+  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
   break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
-  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+  _mesa_string_buffer_append(out, token->value.str);
   break;
case SPACE:
-  ralloc_asprintf_rewrite_tail (out, len, " ");
+  _mesa_string_buffer_append(out, " ");
   break;
case LEFT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, "<<");
+  _mesa_string_buffer_append(out, "<<");
   break;
case RIGHT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, ">>");
+  _mesa_string_buffer_append(out, ">>");
   break;
case LESS_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "<=");
+  _mesa_string_buffer_append(out, "<=");
   break;
case GREATER_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, ">=");
+  _mesa_string_buffer_append(out, ">=");
   break;
case EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "==");
+  _mesa_string_buffer_append(out, "==");
   break;
case NOT_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "!=");
+  _mesa_string_buffer_append(out, "!=");
   break;
case AND:
-  ralloc_asprintf_rewrite_tail (out, len, "&&");
+  _mesa_string_buffer_append(out, "&&");
   break;
case OR:
-  ralloc_asprintf_rewrite_tail (out, len, "||");
+  _mesa_string_buffer_append(out, "||");
   break;
case PASTE:
-  ralloc_asprintf_rewrite_tail (out, len

Re: [Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
2017-05-28 15:19 GMT+02:00 Thomas Helland :
> V2: Failure found by Timothy running it through CI
>- Fix pp.c reralloc size issue and comment

There is still something here that doesn't work as intended.
Some tests are failing  I'll report once I find the cause.

> ---
>  src/compiler/glsl/glcpp/glcpp-parse.y | 85 
> ++-
>  src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
>  src/compiler/glsl/glcpp/pp.c  | 39 +++-
>  3 files changed, 64 insertions(+), 68 deletions(-)
>
> diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
> b/src/compiler/glsl/glcpp/glcpp-parse.y
> index fe211a0f0b..e84b6fb055 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -209,7 +209,7 @@ line:
>  |  SPACE control_line
>  |  text_line {
> _glcpp_parser_print_expanded_token_list (parser, $1);
> -   ralloc_asprintf_rewrite_tail (&parser->output, 
> &parser->output_length, "\n");
> +   _mesa_string_buffer_append_char(parser->output, '\n');
> }
>  |  expanded_line
>  ;
> @@ -228,20 +228,16 @@ expanded_line:
>  |  LINE_EXPANDED integer_constant NEWLINE {
> parser->has_new_line_number = 1;
> parser->new_line_number = $2;
> -   ralloc_asprintf_rewrite_tail (&parser->output,
> - &parser->output_length,
> - "#line %" PRIiMAX "\n",
> - $2);
> +   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
> "\n", $2);
> }
>  |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
> parser->has_new_line_number = 1;
> parser->new_line_number = $2;
> parser->has_new_source_number = 1;
> parser->new_source_number = $3;
> -   ralloc_asprintf_rewrite_tail (&parser->output,
> - &parser->output_length,
> - "#line %" PRIiMAX " %" PRIiMAX 
> "\n",
> - $2, $3);
> +   _mesa_string_buffer_printf(parser->output,
> +  "#line %" PRIiMAX " %" PRIiMAX 
> "\n",
> +   $2, $3);
> }
>  ;
>
> @@ -259,7 +255,7 @@ define:
>
>  control_line:
> control_line_success {
> -   ralloc_asprintf_rewrite_tail (&parser->output, 
> &parser->output_length, "\n");
> +   _mesa_string_buffer_append_char(parser->output, '\n');
> }
>  |  control_line_error
>  |  HASH_TOKEN LINE pp_tokens NEWLINE {
> @@ -432,7 +428,7 @@ control_line_success:
> glcpp_parser_resolve_implicit_version(parser);
> }
>  |  HASH_TOKEN PRAGMA NEWLINE {
> -   ralloc_asprintf_rewrite_tail (&parser->output, 
> &parser->output_length, "#%s", $2);
> +   _mesa_string_buffer_printf(parser->output, "#%s", $2);
> }
>  ;
>
> @@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
> token_list_t *b)
>  }
>
>  static void
> -_token_print(char **out, size_t *len, token_t *token)
> +_token_print(struct _mesa_string_buffer *out, token_t *token)
>  {
> if (token->type < 256) {
> -  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
> +  _mesa_string_buffer_printf(out,"%c", token->type);
>return;
> }
>
> switch (token->type) {
> case INTEGER:
> -  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, 
> token->value.ival);
> +  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
>break;
> case IDENTIFIER:
> case INTEGER_STRING:
> case OTHER:
> -  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
> +  _mesa_string_buffer_append(out, token->value.str);
>break;
> case SPACE:
> -  ralloc_asprintf_rewrite_tail (out, len, " ");
> +  _mesa_string_buffer_append(out, " ");
>break;
> case LEFT_SHIFT:
> -  ralloc_asprintf_rewrite_tail (out, len, "<<");
> +  _mesa_string_buffer_append(out, "<<");
>break;
> case RIGHT_SHIFT:
> -  ralloc_asprintf_rewrite_tail (out, len, ">>");
> +  _mesa_string_buffer_append(out, ">>");
>break;
> case LESS_OR_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "<=");
> +  _mesa_string_buffer_append(out, "<=");
>break;
> case GREATER_OR_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, ">=");
> +  _mesa_string_buffer_append(out, ">=");
>break;
> case EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "==");
> +  _mesa_string_buffer_append(out, "==");
>break;
> case NOT_EQUAL:
> -  ralloc_asprintf_rewrite_tail (out, len, "!=");
> +  _mesa_string_buffer_append(out, "!=");
>

[Mesa-dev] [PATCH] glsl: Change the parser to use the string buffer

2017-05-28 Thread Thomas Helland
V2: Failure found by Timothy running it through CI
   - Fix pp.c reralloc size issue and comment
---
 src/compiler/glsl/glcpp/glcpp-parse.y | 85 ++-
 src/compiler/glsl/glcpp/glcpp.h   |  8 ++--
 src/compiler/glsl/glcpp/pp.c  | 39 +++-
 3 files changed, 64 insertions(+), 68 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y 
b/src/compiler/glsl/glcpp/glcpp-parse.y
index fe211a0f0b..e84b6fb055 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -209,7 +209,7 @@ line:
 |  SPACE control_line
 |  text_line {
_glcpp_parser_print_expanded_token_list (parser, $1);
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  expanded_line
 ;
@@ -228,20 +228,16 @@ expanded_line:
 |  LINE_EXPANDED integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
-   ralloc_asprintf_rewrite_tail (&parser->output,
- &parser->output_length,
- "#line %" PRIiMAX "\n",
- $2);
+   _mesa_string_buffer_printf(parser->output, "#line %" PRIiMAX 
"\n", $2);
}
 |  LINE_EXPANDED integer_constant integer_constant NEWLINE {
parser->has_new_line_number = 1;
parser->new_line_number = $2;
parser->has_new_source_number = 1;
parser->new_source_number = $3;
-   ralloc_asprintf_rewrite_tail (&parser->output,
- &parser->output_length,
- "#line %" PRIiMAX " %" PRIiMAX 
"\n",
- $2, $3);
+   _mesa_string_buffer_printf(parser->output,
+  "#line %" PRIiMAX " %" PRIiMAX "\n",
+   $2, $3);
}
 ;
 
@@ -259,7 +255,7 @@ define:
 
 control_line:
control_line_success {
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "\n");
+   _mesa_string_buffer_append_char(parser->output, '\n');
}
 |  control_line_error
 |  HASH_TOKEN LINE pp_tokens NEWLINE {
@@ -432,7 +428,7 @@ control_line_success:
glcpp_parser_resolve_implicit_version(parser);
}
 |  HASH_TOKEN PRAGMA NEWLINE {
-   ralloc_asprintf_rewrite_tail (&parser->output, 
&parser->output_length, "#%s", $2);
+   _mesa_string_buffer_printf(parser->output, "#%s", $2);
}
 ;
 
@@ -1110,60 +1106,60 @@ _token_list_equal_ignoring_space(token_list_t *a, 
token_list_t *b)
 }
 
 static void
-_token_print(char **out, size_t *len, token_t *token)
+_token_print(struct _mesa_string_buffer *out, token_t *token)
 {
if (token->type < 256) {
-  ralloc_asprintf_rewrite_tail (out, len, "%c", token->type);
+  _mesa_string_buffer_printf(out,"%c", token->type);
   return;
}
 
switch (token->type) {
case INTEGER:
-  ralloc_asprintf_rewrite_tail (out, len, "%" PRIiMAX, token->value.ival);
+  _mesa_string_buffer_printf(out, "%" PRIiMAX, token->value.ival);
   break;
case IDENTIFIER:
case INTEGER_STRING:
case OTHER:
-  ralloc_asprintf_rewrite_tail (out, len, "%s", token->value.str);
+  _mesa_string_buffer_append(out, token->value.str);
   break;
case SPACE:
-  ralloc_asprintf_rewrite_tail (out, len, " ");
+  _mesa_string_buffer_append(out, " ");
   break;
case LEFT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, "<<");
+  _mesa_string_buffer_append(out, "<<");
   break;
case RIGHT_SHIFT:
-  ralloc_asprintf_rewrite_tail (out, len, ">>");
+  _mesa_string_buffer_append(out, ">>");
   break;
case LESS_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "<=");
+  _mesa_string_buffer_append(out, "<=");
   break;
case GREATER_OR_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, ">=");
+  _mesa_string_buffer_append(out, ">=");
   break;
case EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "==");
+  _mesa_string_buffer_append(out, "==");
   break;
case NOT_EQUAL:
-  ralloc_asprintf_rewrite_tail (out, len, "!=");
+  _mesa_string_buffer_append(out, "!=");
   break;
case AND:
-  ralloc_asprintf_rewrite_tail (out, len, "&&");
+  _mesa_string_buffer_append(out, "&&");
   break;
case OR:
-  ralloc_asprintf_rewrite_tail (out, len, "||");
+  _mesa_string_buffer_append(out, "||");
   break;
case PASTE:
-  ralloc_asprintf_rewrite_tail (out, len, "##");
+  _mesa_string_buffer_append(out, "##");
   break;
case P