Re: [Mesa-dev] [PATCH 07/15] glcpp: use the linear allocator for most objects

2016-10-12 Thread Marek Olšák
On Wed, Oct 12, 2016 at 3:11 PM, Nicolai Hähnle  wrote:
> 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

2016-10-12 Thread Nicolai Hähnle

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