[Mesa-dev] [PATCH 07/15] glcpp: use the linear allocator for most objects
From: Marek Olšákv2: cosmetic changes Tested-by: Edmondo Tommasina (v1) Reviewed-by: Nicolai Hähnle (v1) --- src/compiler/glsl/glcpp/glcpp-lex.l | 2 +- src/compiler/glsl/glcpp/glcpp-parse.y | 205 +++--- src/compiler/glsl/glcpp/glcpp.h | 1 + 3 files changed, 92 insertions(+), 116 deletions(-) diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l index d09441a..f4a6876 100644 --- a/src/compiler/glsl/glcpp/glcpp-lex.l +++ b/src/compiler/glsl/glcpp/glcpp-lex.l @@ -94,21 +94,21 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner); #define RETURN_TOKEN(token)\ do {\ if (! parser->skipping) { \ RETURN_TOKEN_NEVER_SKIP(token); \ } \ } while(0) #define RETURN_STRING_TOKEN(token) \ do {\ if (! parser->skipping) { \ - yylval->str = ralloc_strdup (yyextra, yytext); \ + yylval->str = linear_strdup(yyextra->linalloc, yytext); \ RETURN_TOKEN_NEVER_SKIP (token);\ } \ } while(0) /* Update all state necessary for each token being returned. * * Here we'll be tracking newlines and spaces so that the lexer can * alter its behavior as necessary, (for example, '#' has special * significance if it is the first non-whitespace, non-comment token diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index 4fd1448..84c8ee5 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -42,61 +42,62 @@ _define_object_macro(glcpp_parser_t *parser, token_list_t *replacements); static void _define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc, const char *macro, string_list_t *parameters, token_list_t *replacements); static string_list_t * -_string_list_create(void *ctx); +_string_list_create(glcpp_parser_t *parser); static void -_string_list_append_item(string_list_t *list, const char *str); +_string_list_append_item(glcpp_parser_t *parser, string_list_t *list, + const char *str); static int _string_list_contains(string_list_t *list, const char *member, int *index); static const char * _string_list_has_duplicate(string_list_t *list); static int _string_list_length(string_list_t *list); static int _string_list_equal(string_list_t *a, string_list_t *b); static argument_list_t * -_argument_list_create(void *ctx); +_argument_list_create(glcpp_parser_t *parser); static void -_argument_list_append(argument_list_t *list, token_list_t *argument); +_argument_list_append(glcpp_parser_t *parser, argument_list_t *list, + token_list_t *argument); static int _argument_list_length(argument_list_t *list); static token_list_t * _argument_list_member_at(argument_list_t *list, int index); -/* Note: This function ralloc_steal()s the str pointer. */ static token_t * -_token_create_str(void *ctx, int type, char *str); +_token_create_str(glcpp_parser_t *parser, int type, char *str); static token_t * -_token_create_ival(void *ctx, int type, int ival); +_token_create_ival(glcpp_parser_t *parser, int type, int ival); static token_list_t * -_token_list_create(void *ctx); +_token_list_create(glcpp_parser_t *parser); static void -_token_list_append(token_list_t *list, token_t *token); +_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token); static void _token_list_append_list(token_list_t *list, token_list_t *tail); static int _token_list_equal_ignoring_space(token_list_t *a, token_list_t *b); static void _parser_active_list_push(glcpp_parser_t *parser, const char *identifier, token_node_t *marker); @@ -202,21 +203,20 @@ input: /* empty */ | input line ; line: control_line | SPACE control_line | text_line { _glcpp_parser_print_expanded_token_list (parser, $1); ralloc_asprintf_rewrite_tail (>output, >output_length, "\n"); - ralloc_free ($1); } | expanded_line ; expanded_line: IF_EXPANDED expression NEWLINE { if (parser->is_gles && $2.undefined_macro) glcpp_error(& @1, parser, "undefined macro %s in
Re: [Mesa-dev] [PATCH 07/15] glcpp: use the linear allocator for most objects
On Wed, Oct 12, 2016 at 3:11 PM, Nicolai Hähnlewrote: > On 08.10.2016 12:58, Marek Olšák wrote: >> >> From: Marek Olšák >> >> --- >> src/compiler/glsl/glcpp/glcpp-lex.l | 2 +- >> src/compiler/glsl/glcpp/glcpp-parse.y | 203 >> +++--- >> src/compiler/glsl/glcpp/glcpp.h | 1 + >> 3 files changed, 94 insertions(+), 112 deletions(-) >> >> diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l >> b/src/compiler/glsl/glcpp/glcpp-lex.l >> index d09441a..f4a6876 100644 >> --- a/src/compiler/glsl/glcpp/glcpp-lex.l >> +++ b/src/compiler/glsl/glcpp/glcpp-lex.l > > [snip] > >> @@ -1002,51 +994,50 @@ _token_list_append_list(token_list_t *list, >> token_list_t *tail) >>list->head = tail->head; >> } else { >>list->tail->next = tail->head; >> } >> >> list->tail = tail->tail; >> list->non_space_tail = tail->non_space_tail; >> } >> >> static token_list_t * >> -_token_list_copy(void *ctx, token_list_t *other) >> +_token_list_copy(glcpp_parser_t *parser, token_list_t *other) >> { >> token_list_t *copy; >> token_node_t *node; >> >> if (other == NULL) >>return NULL; >> >> - copy = _token_list_create (ctx); >> + copy = _token_list_create (parser); >> for (node = other->head; node; node = node->next) { >> - token_t *new_token = ralloc (copy, token_t); >> + token_t *new_token = linear_alloc_child(parser->linalloc, >> sizeof(token_t)); >>*new_token = *node->token; >> - _token_list_append (copy, new_token); >> + _token_list_append (parser, copy, new_token); >> } >> >> return copy; >> } >> >> static void >> _token_list_trim_trailing_space(token_list_t *list) >> { >> token_node_t *tail, *next; >> >> if (list->non_space_tail) { >>tail = list->non_space_tail->next; >>list->non_space_tail->next = NULL; >>list->tail = list->non_space_tail; >> >>while (tail) { >> next = tail->next; >> - ralloc_free (tail); >> tail = next; >>} > > > This whole loop can be dropped now. > > >> } >> } >> >> static int >> _token_list_is_empty_ignoring_space(token_list_t *l) >> { >> token_node_t *n; >> >> @@ -1177,69 +1168,70 @@ _token_print(char **out, size_t *len, token_t >> *token) >> case PLACEHOLDER: >>/* Nothing to print. */ >>break; >> default: >>assert(!"Error: Don't know how to print token."); >> >>break; >> } >> } >> >> -/* Return a new token (ralloc()ed off of 'token') formed by pasting >> - * 'token' and 'other'. Note that this function may return 'token' or >> - * 'other' directly rather than allocating anything new. >> +/* Return a new token formed by pasting 'token' and 'other'. Note that >> this >> + * function may return 'token' or 'other' directly rather than allocating >> + * anything new. >> * >> * Caution: Only very cursory error-checking is performed to see if >> * the final result is a valid single token. */ >> static token_t * >> -_token_paste(glcpp_parser_t *parser, token_t *token, token_t *other) >> +_token_paste(glcpp_parser_t *parser, token_list_t *list, token_t *token, >> + token_t *other) > > > I seem to be blind... where is list used? It's probably a leftover from my initial work where each list was a linear parent, but then I reworked it to use only one linear parent per parser instance. Marek ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 07/15] glcpp: use the linear allocator for most objects
On 08.10.2016 12:58, Marek Olšák wrote: From: Marek Olšák--- src/compiler/glsl/glcpp/glcpp-lex.l | 2 +- src/compiler/glsl/glcpp/glcpp-parse.y | 203 +++--- src/compiler/glsl/glcpp/glcpp.h | 1 + 3 files changed, 94 insertions(+), 112 deletions(-) diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l index d09441a..f4a6876 100644 --- a/src/compiler/glsl/glcpp/glcpp-lex.l +++ b/src/compiler/glsl/glcpp/glcpp-lex.l [snip] @@ -1002,51 +994,50 @@ _token_list_append_list(token_list_t *list, token_list_t *tail) list->head = tail->head; } else { list->tail->next = tail->head; } list->tail = tail->tail; list->non_space_tail = tail->non_space_tail; } static token_list_t * -_token_list_copy(void *ctx, token_list_t *other) +_token_list_copy(glcpp_parser_t *parser, token_list_t *other) { token_list_t *copy; token_node_t *node; if (other == NULL) return NULL; - copy = _token_list_create (ctx); + copy = _token_list_create (parser); for (node = other->head; node; node = node->next) { - token_t *new_token = ralloc (copy, token_t); + token_t *new_token = linear_alloc_child(parser->linalloc, sizeof(token_t)); *new_token = *node->token; - _token_list_append (copy, new_token); + _token_list_append (parser, copy, new_token); } return copy; } static void _token_list_trim_trailing_space(token_list_t *list) { token_node_t *tail, *next; if (list->non_space_tail) { tail = list->non_space_tail->next; list->non_space_tail->next = NULL; list->tail = list->non_space_tail; while (tail) { next = tail->next; - ralloc_free (tail); tail = next; } This whole loop can be dropped now. } } static int _token_list_is_empty_ignoring_space(token_list_t *l) { token_node_t *n; @@ -1177,69 +1168,70 @@ _token_print(char **out, size_t *len, token_t *token) case PLACEHOLDER: /* Nothing to print. */ break; default: assert(!"Error: Don't know how to print token."); break; } } -/* Return a new token (ralloc()ed off of 'token') formed by pasting - * 'token' and 'other'. Note that this function may return 'token' or - * 'other' directly rather than allocating anything new. +/* Return a new token formed by pasting 'token' and 'other'. Note that this + * function may return 'token' or 'other' directly rather than allocating + * anything new. * * Caution: Only very cursory error-checking is performed to see if * the final result is a valid single token. */ static token_t * -_token_paste(glcpp_parser_t *parser, token_t *token, token_t *other) +_token_paste(glcpp_parser_t *parser, token_list_t *list, token_t *token, + token_t *other) I seem to be blind... where is list used? Nicolai { token_t *combined = NULL; /* Pasting a placeholder onto anything makes no change. */ if (other->type == PLACEHOLDER) return token; /* When 'token' is a placeholder, just return 'other'. */ if (token->type == PLACEHOLDER) return other; /* A very few single-character punctuators can be combined * with another to form a multi-character punctuator. */ switch (token->type) { case '<': if (other->type == '<') - combined = _token_create_ival (token, LEFT_SHIFT, LEFT_SHIFT); + combined = _token_create_ival (parser, LEFT_SHIFT, LEFT_SHIFT); else if (other->type == '=') - combined = _token_create_ival (token, LESS_OR_EQUAL, LESS_OR_EQUAL); + combined = _token_create_ival (parser, LESS_OR_EQUAL, LESS_OR_EQUAL); break; case '>': if (other->type == '>') - combined = _token_create_ival (token, RIGHT_SHIFT, RIGHT_SHIFT); + combined = _token_create_ival (parser, RIGHT_SHIFT, RIGHT_SHIFT); else if (other->type == '=') - combined = _token_create_ival (token, GREATER_OR_EQUAL, GREATER_OR_EQUAL); + combined = _token_create_ival (parser, GREATER_OR_EQUAL, GREATER_OR_EQUAL); break; case '=': if (other->type == '=') - combined = _token_create_ival (token, EQUAL, EQUAL); + combined = _token_create_ival (parser, EQUAL, EQUAL); break; case '!': if (other->type == '=') - combined = _token_create_ival (token, NOT_EQUAL, NOT_EQUAL); + combined = _token_create_ival (parser, NOT_EQUAL, NOT_EQUAL); break; case '&': if (other->type == '&') - combined = _token_create_ival (token, AND, AND); + combined = _token_create_ival (parser, AND, AND); break; case '|': if (other->type == '|') - combined = _token_create_ival (token, OR, OR); + combined = _token_create_ival (parser, OR, OR); break; } if (combined != NULL) { /* Inherit the location from
[Mesa-dev] [PATCH 07/15] glcpp: use the linear allocator for most objects
From: Marek Olšák--- src/compiler/glsl/glcpp/glcpp-lex.l | 2 +- src/compiler/glsl/glcpp/glcpp-parse.y | 203 +++--- src/compiler/glsl/glcpp/glcpp.h | 1 + 3 files changed, 94 insertions(+), 112 deletions(-) diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l index d09441a..f4a6876 100644 --- a/src/compiler/glsl/glcpp/glcpp-lex.l +++ b/src/compiler/glsl/glcpp/glcpp-lex.l @@ -94,21 +94,21 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner); #define RETURN_TOKEN(token)\ do {\ if (! parser->skipping) { \ RETURN_TOKEN_NEVER_SKIP(token); \ } \ } while(0) #define RETURN_STRING_TOKEN(token) \ do {\ if (! parser->skipping) { \ - yylval->str = ralloc_strdup (yyextra, yytext); \ + yylval->str = linear_strdup(yyextra->linalloc, yytext); \ RETURN_TOKEN_NEVER_SKIP (token);\ } \ } while(0) /* Update all state necessary for each token being returned. * * Here we'll be tracking newlines and spaces so that the lexer can * alter its behavior as necessary, (for example, '#' has special * significance if it is the first non-whitespace, non-comment token diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index 4fd1448..d2081b3 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -42,61 +42,62 @@ _define_object_macro(glcpp_parser_t *parser, token_list_t *replacements); static void _define_function_macro(glcpp_parser_t *parser, YYLTYPE *loc, const char *macro, string_list_t *parameters, token_list_t *replacements); static string_list_t * -_string_list_create(void *ctx); +_string_list_create(glcpp_parser_t *parser); static void -_string_list_append_item(string_list_t *list, const char *str); +_string_list_append_item(glcpp_parser_t *parser, string_list_t *list, + const char *str); static int _string_list_contains(string_list_t *list, const char *member, int *index); static const char * _string_list_has_duplicate(string_list_t *list); static int _string_list_length(string_list_t *list); static int _string_list_equal(string_list_t *a, string_list_t *b); static argument_list_t * -_argument_list_create(void *ctx); +_argument_list_create(glcpp_parser_t *parser); static void -_argument_list_append(argument_list_t *list, token_list_t *argument); +_argument_list_append(glcpp_parser_t *parser, argument_list_t *list, + token_list_t *argument); static int _argument_list_length(argument_list_t *list); static token_list_t * _argument_list_member_at(argument_list_t *list, int index); -/* Note: This function ralloc_steal()s the str pointer. */ static token_t * -_token_create_str(void *ctx, int type, char *str); +_token_create_str(glcpp_parser_t *parser, int type, char *str); static token_t * -_token_create_ival(void *ctx, int type, int ival); +_token_create_ival(glcpp_parser_t *parser, int type, int ival); static token_list_t * -_token_list_create(void *ctx); +_token_list_create(glcpp_parser_t *parser); static void -_token_list_append(token_list_t *list, token_t *token); +_token_list_append(glcpp_parser_t *parser, token_list_t *list, token_t *token); static void _token_list_append_list(token_list_t *list, token_list_t *tail); static int _token_list_equal_ignoring_space(token_list_t *a, token_list_t *b); static void _parser_active_list_push(glcpp_parser_t *parser, const char *identifier, token_node_t *marker); @@ -202,21 +203,20 @@ input: /* empty */ | input line ; line: control_line | SPACE control_line | text_line { _glcpp_parser_print_expanded_token_list (parser, $1); ralloc_asprintf_rewrite_tail (>output, >output_length, "\n"); - ralloc_free ($1); } | expanded_line ; expanded_line: IF_EXPANDED expression NEWLINE { if (parser->is_gles && $2.undefined_macro) glcpp_error(& @1, parser, "undefined macro %s in expression (illegal in GLES)", $2.undefined_macro); _glcpp_parser_skip_stack_push_if (parser, & @1, $2.value); } @@ -270,21