[Mesa-dev] [PATCH 09/15] glsl: use the linear allocator for ast_node and derived classes
Marek Olšák
maraeo at gmail.com
Sat Oct 8 10:58:33 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/compiler/glsl/ast.h | 4 +-
src/compiler/glsl/ast_type.cpp | 13 +-
src/compiler/glsl/glsl_parser.yy | 202 +++++++++++++++----------------
src/compiler/glsl/glsl_parser_extras.cpp | 4 +-
src/compiler/glsl/glsl_symbol_table.cpp | 3 +-
src/compiler/glsl/glsl_symbol_table.h | 1 +
6 files changed, 114 insertions(+), 113 deletions(-)
diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
index 0713582..2195141 100644
--- a/src/compiler/glsl/ast.h
+++ b/src/compiler/glsl/ast.h
@@ -42,21 +42,21 @@ struct YYLTYPE;
* syntactic checking is done. Symantic checking is performed by a later
* stage that converts the AST to a more generic intermediate representation.
*
*@{
*/
/**
* Base class of all abstract syntax tree nodes
*/
class ast_node {
public:
- DECLARE_RZALLOC_CXX_OPERATORS(ast_node);
+ DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ast_node);
/**
* Print an AST node in something approximating the original GLSL code
*/
virtual void print(void) const;
/**
* Convert the AST node to the high-level intermediate representation
*/
virtual ir_rvalue *hir(exec_list *instructions,
@@ -763,21 +763,21 @@ struct ast_type_qualifier {
const ast_type_qualifier &allowed_flags,
const char *message, const char *name);
ast_subroutine_list *subroutine_list;
};
class ast_declarator_list;
class ast_struct_specifier : public ast_node {
public:
- ast_struct_specifier(const char *identifier,
+ ast_struct_specifier(void *lin_ctx, const char *identifier,
ast_declarator_list *declarator_list);
virtual void print(void) const;
virtual ir_rvalue *hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state);
const char *name;
ast_type_qualifier *layout;
/* List of ast_declarator_list * */
exec_list declarations;
diff --git a/src/compiler/glsl/ast_type.cpp b/src/compiler/glsl/ast_type.cpp
index b586f94..e4cbc84 100644
--- a/src/compiler/glsl/ast_type.cpp
+++ b/src/compiler/glsl/ast_type.cpp
@@ -257,24 +257,24 @@ ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
/* Set xfb_stride flag to 0 to avoid adding duplicates every time
* there is a merge.
*/
this->flags.q.xfb_stride = 0;
unsigned buff_idx;
if (process_qualifier_constant(state, loc, "xfb_buffer",
this->xfb_buffer, &buff_idx)) {
if (state->out_qualifier->out_xfb_stride[buff_idx]) {
state->out_qualifier->out_xfb_stride[buff_idx]->merge_qualifier(
- new(state) ast_layout_expression(*loc, this->xfb_stride));
+ new(state->linalloc) ast_layout_expression(*loc, this->xfb_stride));
} else {
state->out_qualifier->out_xfb_stride[buff_idx] =
- new(state) ast_layout_expression(*loc, this->xfb_stride);
+ new(state->linalloc) ast_layout_expression(*loc, this->xfb_stride);
}
}
}
}
if (q.flags.q.vertices) {
if (this->vertices) {
this->vertices->merge_qualifier(q.vertices);
} else {
this->vertices = q.vertices;
@@ -356,21 +356,20 @@ ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
return true;
}
bool
ast_type_qualifier::merge_out_qualifier(YYLTYPE *loc,
_mesa_glsl_parse_state *state,
const ast_type_qualifier &q,
ast_node* &node, bool create_node)
{
- void *mem_ctx = state;
const bool r = this->merge_qualifier(loc, state, q, false);
ast_type_qualifier valid_out_mask;
valid_out_mask.flags.i = 0;
if (state->stage == MESA_SHADER_GEOMETRY) {
if (q.flags.q.prim_type) {
/* Make sure this is a valid output primitive type. */
switch (q.prim_type) {
case GL_POINTS:
case GL_LINE_STRIP:
@@ -389,21 +388,21 @@ ast_type_qualifier::merge_out_qualifier(YYLTYPE *loc,
valid_out_mask.flags.q.stream = 1;
valid_out_mask.flags.q.explicit_stream = 1;
valid_out_mask.flags.q.explicit_xfb_buffer = 1;
valid_out_mask.flags.q.xfb_buffer = 1;
valid_out_mask.flags.q.explicit_xfb_stride = 1;
valid_out_mask.flags.q.xfb_stride = 1;
valid_out_mask.flags.q.max_vertices = 1;
valid_out_mask.flags.q.prim_type = 1;
} else if (state->stage == MESA_SHADER_TESS_CTRL) {
if (create_node) {
- node = new(mem_ctx) ast_tcs_output_layout(*loc);
+ node = new(state->linalloc) ast_tcs_output_layout(*loc);
}
valid_out_mask.flags.q.vertices = 1;
valid_out_mask.flags.q.explicit_xfb_buffer = 1;
valid_out_mask.flags.q.xfb_buffer = 1;
valid_out_mask.flags.q.explicit_xfb_stride = 1;
valid_out_mask.flags.q.xfb_stride = 1;
} else if (state->stage == MESA_SHADER_TESS_EVAL ||
state->stage == MESA_SHADER_VERTEX) {
valid_out_mask.flags.q.explicit_xfb_buffer = 1;
valid_out_mask.flags.q.xfb_buffer = 1;
@@ -429,21 +428,21 @@ ast_type_qualifier::merge_out_qualifier(YYLTYPE *loc,
return r;
}
bool
ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
_mesa_glsl_parse_state *state,
const ast_type_qualifier &q,
ast_node* &node, bool create_node)
{
- void *mem_ctx = state;
+ void *lin_ctx = state->linalloc;
bool create_gs_ast = false;
bool create_cs_ast = false;
ast_type_qualifier valid_in_mask;
valid_in_mask.flags.i = 0;
switch (state->stage) {
case MESA_SHADER_TESS_EVAL:
if (q.flags.q.prim_type) {
/* Make sure this is a valid input primitive type. */
switch (q.prim_type) {
@@ -568,23 +567,23 @@ ast_type_qualifier::merge_in_qualifier(YYLTYPE *loc,
_mesa_glsl_error(loc, state,
"conflicting point mode specified");
}
} else if (q.flags.q.point_mode) {
this->flags.q.point_mode = 1;
this->point_mode = q.point_mode;
}
if (create_node) {
if (create_gs_ast) {
- node = new(mem_ctx) ast_gs_input_layout(*loc, q.prim_type);
+ node = new(lin_ctx) ast_gs_input_layout(*loc, q.prim_type);
} else if (create_cs_ast) {
- node = new(mem_ctx) ast_cs_input_layout(*loc, q.local_size);
+ node = new(lin_ctx) ast_cs_input_layout(*loc, q.local_size);
}
}
return true;
}
/**
* Check if the current type qualifier has any illegal flags.
*
* If so, print an error message, followed by a list of illegal flags.
diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy
index 9e1fd9e..175bffd 100644
--- a/src/compiler/glsl/glsl_parser.yy
+++ b/src/compiler/glsl/glsl_parser.yy
@@ -425,94 +425,94 @@ external_declaration_list:
;
variable_identifier:
IDENTIFIER
| NEW_IDENTIFIER
;
primary_expression:
variable_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_identifier, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.identifier = $1;
}
| INTCONSTANT
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_int_constant, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.int_constant = $1;
}
| UINTCONSTANT
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_uint_constant, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.uint_constant = $1;
}
| FLOATCONSTANT
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_float_constant, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.float_constant = $1;
}
| DOUBLECONSTANT
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_double_constant, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.double_constant = $1;
}
| BOOLCONSTANT
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_bool_constant, NULL, NULL, NULL);
$$->set_location(@1);
$$->primary_expression.bool_constant = $1;
}
| '(' expression ')'
{
$$ = $2;
}
;
postfix_expression:
primary_expression
| postfix_expression '[' integer_expression ']'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_array_index, $1, $3, NULL);
$$->set_location_range(@1, @4);
}
| function_call
{
$$ = $1;
}
| postfix_expression DOT_TOK FIELD_SELECTION
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_field_selection, $1, NULL, NULL);
$$->set_location_range(@1, @3);
$$->primary_expression.identifier = $3;
}
| postfix_expression INC_OP
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_post_inc, $1, NULL, NULL);
$$->set_location_range(@1, @2);
}
| postfix_expression DEC_OP
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_post_dec, $1, NULL, NULL);
$$->set_location_range(@1, @2);
}
;
integer_expression:
expression
;
function_call:
@@ -551,240 +551,240 @@ function_call_header_with_parameters:
// Grammar Note: Constructors look like functions, but lexical
// analysis recognized most of them as keywords. They are now
// recognized through "type_specifier".
function_call_header:
function_identifier '('
;
function_identifier:
type_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_function_expression($1);
$$->set_location(@1);
}
| postfix_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_function_expression($1);
$$->set_location(@1);
}
;
// Grammar Note: Constructors look like methods, but lexical
// analysis recognized most of them as keywords. They are now
// recognized through "type_specifier".
// Grammar Note: No traditional style type casts.
unary_expression:
postfix_expression
| INC_OP unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_pre_inc, $2, NULL, NULL);
$$->set_location(@1);
}
| DEC_OP unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_pre_dec, $2, NULL, NULL);
$$->set_location(@1);
}
| unary_operator unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression($1, $2, NULL, NULL);
$$->set_location_range(@1, @2);
}
;
// Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
unary_operator:
'+' { $$ = ast_plus; }
| '-' { $$ = ast_neg; }
| '!' { $$ = ast_logic_not; }
| '~' { $$ = ast_bit_not; }
;
multiplicative_expression:
unary_expression
| multiplicative_expression '*' unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_mul, $1, $3);
$$->set_location_range(@1, @3);
}
| multiplicative_expression '/' unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_div, $1, $3);
$$->set_location_range(@1, @3);
}
| multiplicative_expression '%' unary_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_mod, $1, $3);
$$->set_location_range(@1, @3);
}
;
additive_expression:
multiplicative_expression
| additive_expression '+' multiplicative_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_add, $1, $3);
$$->set_location_range(@1, @3);
}
| additive_expression '-' multiplicative_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_sub, $1, $3);
$$->set_location_range(@1, @3);
}
;
shift_expression:
additive_expression
| shift_expression LEFT_OP additive_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_lshift, $1, $3);
$$->set_location_range(@1, @3);
}
| shift_expression RIGHT_OP additive_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_rshift, $1, $3);
$$->set_location_range(@1, @3);
}
;
relational_expression:
shift_expression
| relational_expression '<' shift_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_less, $1, $3);
$$->set_location_range(@1, @3);
}
| relational_expression '>' shift_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_greater, $1, $3);
$$->set_location_range(@1, @3);
}
| relational_expression LE_OP shift_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_lequal, $1, $3);
$$->set_location_range(@1, @3);
}
| relational_expression GE_OP shift_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_gequal, $1, $3);
$$->set_location_range(@1, @3);
}
;
equality_expression:
relational_expression
| equality_expression EQ_OP relational_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_equal, $1, $3);
$$->set_location_range(@1, @3);
}
| equality_expression NE_OP relational_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_nequal, $1, $3);
$$->set_location_range(@1, @3);
}
;
and_expression:
equality_expression
| and_expression '&' equality_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_bit_and, $1, $3);
$$->set_location_range(@1, @3);
}
;
exclusive_or_expression:
and_expression
| exclusive_or_expression '^' and_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_bit_xor, $1, $3);
$$->set_location_range(@1, @3);
}
;
inclusive_or_expression:
exclusive_or_expression
| inclusive_or_expression '|' exclusive_or_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_bit_or, $1, $3);
$$->set_location_range(@1, @3);
}
;
logical_and_expression:
inclusive_or_expression
| logical_and_expression AND_OP inclusive_or_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_logic_and, $1, $3);
$$->set_location_range(@1, @3);
}
;
logical_xor_expression:
logical_and_expression
| logical_xor_expression XOR_OP logical_and_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_logic_xor, $1, $3);
$$->set_location_range(@1, @3);
}
;
logical_or_expression:
logical_xor_expression
| logical_or_expression OR_OP logical_xor_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_bin(ast_logic_or, $1, $3);
$$->set_location_range(@1, @3);
}
;
conditional_expression:
logical_or_expression
| logical_or_expression '?' expression ':' assignment_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression(ast_conditional, $1, $3, $5);
$$->set_location_range(@1, @5);
}
;
assignment_expression:
conditional_expression
| unary_expression assignment_operator assignment_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression($2, $1, $3, NULL);
$$->set_location_range(@1, @3);
}
;
assignment_operator:
'=' { $$ = ast_assign; }
| MUL_ASSIGN { $$ = ast_mul_assign; }
| DIV_ASSIGN { $$ = ast_div_assign; }
| MOD_ASSIGN { $$ = ast_mod_assign; }
@@ -797,21 +797,21 @@ assignment_operator:
| OR_ASSIGN { $$ = ast_or_assign; }
;
expression:
assignment_expression
{
$$ = $1;
}
| expression ',' assignment_expression
{
- void *ctx = state;
+ void *ctx = state->linalloc;
if ($1->oper != ast_sequence) {
$$ = new(ctx) ast_expression(ast_sequence, NULL, NULL, NULL);
$$->set_location_range(@1, @3);
$$->expressions.push_tail(& $1->link);
} else {
$$ = $1;
}
$$->expressions.push_tail(& $3->link);
}
@@ -860,70 +860,70 @@ function_header_with_parameters:
| function_header_with_parameters ',' parameter_declaration
{
$$ = $1;
$$->parameters.push_tail(& $3->link);
}
;
function_header:
fully_specified_type variable_identifier '('
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_function();
$$->set_location(@2);
$$->return_type = $1;
$$->identifier = $2;
if ($1->qualifier.flags.q.subroutine) {
/* add type for IDENTIFIER search */
state->symbols->add_type($2, glsl_type::get_subroutine_instance($2));
} else
state->symbols->add_function(new(state) ir_function($2));
state->symbols->push_scope();
}
;
parameter_declarator:
type_specifier any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_parameter_declarator();
$$->set_location_range(@1, @2);
$$->type = new(ctx) ast_fully_specified_type();
$$->type->set_location(@1);
$$->type->specifier = $1;
$$->identifier = $2;
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
| type_specifier any_identifier array_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_parameter_declarator();
$$->set_location_range(@1, @3);
$$->type = new(ctx) ast_fully_specified_type();
$$->type->set_location(@1);
$$->type->specifier = $1;
$$->identifier = $2;
$$->array_specifier = $3;
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
;
parameter_declaration:
parameter_qualifier parameter_declarator
{
$$ = $2;
$$->type->qualifier = $1;
}
| parameter_qualifier parameter_type_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_parameter_declarator();
$$->set_location(@2);
$$->type = new(ctx) ast_fully_specified_type();
$$->type->set_location_range(@1, @2);
$$->type->qualifier = $1;
$$->type->specifier = $2;
}
;
parameter_qualifier:
@@ -997,150 +997,150 @@ parameter_direction_qualifier:
;
parameter_type_specifier:
type_specifier
;
init_declarator_list:
single_declaration
| init_declarator_list ',' any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
decl->set_location(@3);
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
| init_declarator_list ',' any_identifier array_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($3, $4, NULL);
decl->set_location_range(@3, @4);
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
| init_declarator_list ',' any_identifier array_specifier '=' initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($3, $4, $6);
decl->set_location_range(@3, @4);
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
| init_declarator_list ',' any_identifier '=' initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($3, NULL, $5);
decl->set_location(@3);
$$ = $1;
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $3, ir_var_auto));
}
;
// Grammar Note: No 'enum', or 'typedef'.
single_declaration:
fully_specified_type
{
- void *ctx = state;
+ void *ctx = state->linalloc;
/* Empty declaration list is valid. */
$$ = new(ctx) ast_declarator_list($1);
$$->set_location(@1);
}
| fully_specified_type any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
decl->set_location(@2);
$$ = new(ctx) ast_declarator_list($1);
$$->set_location_range(@1, @2);
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
| fully_specified_type any_identifier array_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, $3, NULL);
decl->set_location_range(@2, @3);
$$ = new(ctx) ast_declarator_list($1);
$$->set_location_range(@1, @3);
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
| fully_specified_type any_identifier array_specifier '=' initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, $3, $5);
decl->set_location_range(@2, @3);
$$ = new(ctx) ast_declarator_list($1);
$$->set_location_range(@1, @3);
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
| fully_specified_type any_identifier '=' initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
decl->set_location(@2);
$$ = new(ctx) ast_declarator_list($1);
$$->set_location_range(@1, @2);
$$->declarations.push_tail(&decl->link);
state->symbols->add_variable(new(state) ir_variable(NULL, $2, ir_var_auto));
}
| INVARIANT variable_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
decl->set_location(@2);
$$ = new(ctx) ast_declarator_list(NULL);
$$->set_location_range(@1, @2);
$$->invariant = true;
$$->declarations.push_tail(&decl->link);
}
| PRECISE variable_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, NULL);
decl->set_location(@2);
$$ = new(ctx) ast_declarator_list(NULL);
$$->set_location_range(@1, @2);
$$->precise = true;
$$->declarations.push_tail(&decl->link);
}
;
fully_specified_type:
type_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_fully_specified_type();
$$->set_location(@1);
$$->specifier = $1;
}
| type_qualifier type_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_fully_specified_type();
$$->set_location_range(@1, @2);
$$->qualifier = $1;
$$->specifier = $2;
if ($$->specifier->structure != NULL &&
$$->specifier->structure->is_declaration) {
$$->specifier->structure->layout = &$$->qualifier;
}
}
;
@@ -1493,21 +1493,21 @@ layout_qualifier_id:
if (!$$.flags.i) {
_mesa_glsl_error(& @1, state, "unrecognized layout identifier "
"`%s'", $1);
YYERROR;
}
}
| any_identifier '=' constant_expression
{
memset(& $$, 0, sizeof($$));
- void *ctx = state;
+ void *ctx = state->linalloc;
if ($3->oper != ast_int_constant &&
$3->oper != ast_uint_constant &&
!state->has_enhanced_layouts()) {
_mesa_glsl_error(& @1, state,
"compile-time constant expressions require "
"GLSL 4.40 or ARB_enhanced_layouts");
}
if (match_layout_qualifier("align", $1, state) == 0) {
@@ -1715,30 +1715,30 @@ subroutine_qualifier:
{
memset(& $$, 0, sizeof($$));
$$.flags.q.subroutine_def = 1;
$$.subroutine_list = $3;
}
;
subroutine_type_list:
any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($1, NULL, NULL);
decl->set_location(@1);
$$ = new(ctx) ast_subroutine_list();
$$->declarations.push_tail(&decl->link);
}
| subroutine_type_list ',' any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($3, NULL, NULL);
decl->set_location(@3);
$$ = $1;
$$->declarations.push_tail(&decl->link);
}
;
interpolation_qualifier:
SMOOTH
@@ -2045,35 +2045,35 @@ memory_qualifier:
| WRITEONLY
{
memset(& $$, 0, sizeof($$));
$$.flags.q.write_only = 1;
}
;
array_specifier:
'[' ']'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_array_specifier(@1, new(ctx) ast_expression(
ast_unsized_array_dim, NULL,
NULL, NULL));
$$->set_location_range(@1, @2);
}
| '[' constant_expression ']'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_array_specifier(@1, $2);
$$->set_location_range(@1, @3);
}
| array_specifier '[' ']'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = $1;
if (state->check_arrays_of_arrays_allowed(& @1)) {
$$->add_dimension(new(ctx) ast_expression(ast_unsized_array_dim, NULL,
NULL, NULL));
}
}
| array_specifier '[' constant_expression ']'
{
$$ = $1;
@@ -2089,33 +2089,33 @@ type_specifier:
| type_specifier_nonarray array_specifier
{
$$ = $1;
$$->array_specifier = $2;
}
;
type_specifier_nonarray:
basic_type_specifier_nonarray
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_type_specifier($1);
$$->set_location(@1);
}
| struct_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_type_specifier($1);
$$->set_location(@1);
}
| TYPE_IDENTIFIER
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_type_specifier($1);
$$->set_location(@1);
}
;
basic_type_specifier_nonarray:
VOID_TOK { $$ = "void"; }
| FLOAT_TOK { $$ = "float"; }
| DOUBLE_TOK { $$ = "double"; }
| INT_TOK { $$ = "int"; }
@@ -2245,50 +2245,50 @@ precision_qualifier:
| LOWP
{
state->check_precision_qualifiers_allowed(&@1);
$$ = ast_precision_low;
}
;
struct_specifier:
STRUCT any_identifier '{' struct_declaration_list '}'
{
- void *ctx = state;
- $$ = new(ctx) ast_struct_specifier($2, $4);
+ void *ctx = state->linalloc;
+ $$ = new(ctx) ast_struct_specifier(ctx, $2, $4);
$$->set_location_range(@2, @5);
state->symbols->add_type($2, glsl_type::void_type);
}
| STRUCT '{' struct_declaration_list '}'
{
- void *ctx = state;
- $$ = new(ctx) ast_struct_specifier(NULL, $3);
+ void *ctx = state->linalloc;
+ $$ = new(ctx) ast_struct_specifier(ctx, NULL, $3);
$$->set_location_range(@2, @4);
}
;
struct_declaration_list:
struct_declaration
{
$$ = $1;
$1->link.self_link();
}
| struct_declaration_list struct_declaration
{
$$ = $1;
$$->link.insert_before(& $2->link);
}
;
struct_declaration:
fully_specified_type struct_declarator_list ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_fully_specified_type *const type = $1;
type->set_location(@1);
if (type->qualifier.flags.i != 0)
_mesa_glsl_error(&@1, state,
"only precision qualifiers may be applied to "
"structure members");
$$ = new(ctx) ast_declarator_list(type);
$$->set_location(@2);
@@ -2306,48 +2306,48 @@ struct_declarator_list:
| struct_declarator_list ',' struct_declarator
{
$$ = $1;
$$->link.insert_before(& $3->link);
}
;
struct_declarator:
any_identifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_declaration($1, NULL, NULL);
$$->set_location(@1);
}
| any_identifier array_specifier
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_declaration($1, $2, NULL);
$$->set_location_range(@1, @2);
}
;
initializer:
assignment_expression
| '{' initializer_list '}'
{
$$ = $2;
}
| '{' initializer_list ',' '}'
{
$$ = $2;
}
;
initializer_list:
initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_aggregate_initializer();
$$->set_location(@1);
$$->expressions.push_tail(& $1->link);
}
| initializer_list ',' initializer
{
$1->expressions.push_tail(& $3->link);
}
;
@@ -2367,52 +2367,52 @@ simple_statement:
| expression_statement
| selection_statement
| switch_statement
| iteration_statement
| jump_statement
;
compound_statement:
'{' '}'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_compound_statement(true, NULL);
$$->set_location_range(@1, @2);
}
| '{'
{
state->symbols->push_scope();
}
statement_list '}'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_compound_statement(true, $3);
$$->set_location_range(@1, @4);
state->symbols->pop_scope();
}
;
statement_no_new_scope:
compound_statement_no_new_scope { $$ = (ast_node *) $1; }
| simple_statement
;
compound_statement_no_new_scope:
'{' '}'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_compound_statement(false, NULL);
$$->set_location_range(@1, @2);
}
| '{' statement_list '}'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_compound_statement(false, $2);
$$->set_location_range(@1, @3);
}
;
statement_list:
statement
{
if ($1 == NULL) {
_mesa_glsl_error(& @1, state, "<nil> statement");
@@ -2429,37 +2429,37 @@ statement_list:
assert($2 != NULL);
}
$$ = $1;
$$->link.insert_before(& $2->link);
}
;
expression_statement:
';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_statement(NULL);
$$->set_location(@1);
}
| expression ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_expression_statement($1);
$$->set_location(@1);
}
;
selection_statement:
IF '(' expression ')' selection_rest_statement
{
- $$ = new(state) ast_selection_statement($3, $5.then_statement,
- $5.else_statement);
+ $$ = new(state->linalloc) ast_selection_statement($3, $5.then_statement,
+ $5.else_statement);
$$->set_location_range(@1, @5);
}
;
selection_rest_statement:
statement ELSE statement
{
$$.then_statement = $1;
$$.else_statement = $3;
}
@@ -2470,135 +2470,135 @@ selection_rest_statement:
}
;
condition:
expression
{
$$ = (ast_node *) $1;
}
| fully_specified_type any_identifier '=' initializer
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_declaration *decl = new(ctx) ast_declaration($2, NULL, $4);
ast_declarator_list *declarator = new(ctx) ast_declarator_list($1);
decl->set_location_range(@2, @4);
declarator->set_location(@1);
declarator->declarations.push_tail(&decl->link);
$$ = declarator;
}
;
/*
* switch_statement grammar is based on the syntax described in the body
* of the GLSL spec, not in it's appendix!!!
*/
switch_statement:
SWITCH '(' expression ')' switch_body
{
- $$ = new(state) ast_switch_statement($3, $5);
+ $$ = new(state->linalloc) ast_switch_statement($3, $5);
$$->set_location_range(@1, @5);
}
;
switch_body:
'{' '}'
{
- $$ = new(state) ast_switch_body(NULL);
+ $$ = new(state->linalloc) ast_switch_body(NULL);
$$->set_location_range(@1, @2);
}
| '{' case_statement_list '}'
{
- $$ = new(state) ast_switch_body($2);
+ $$ = new(state->linalloc) ast_switch_body($2);
$$->set_location_range(@1, @3);
}
;
case_label:
CASE expression ':'
{
- $$ = new(state) ast_case_label($2);
+ $$ = new(state->linalloc) ast_case_label($2);
$$->set_location(@2);
}
| DEFAULT ':'
{
- $$ = new(state) ast_case_label(NULL);
+ $$ = new(state->linalloc) ast_case_label(NULL);
$$->set_location(@2);
}
;
case_label_list:
case_label
{
- ast_case_label_list *labels = new(state) ast_case_label_list();
+ ast_case_label_list *labels = new(state->linalloc) ast_case_label_list();
labels->labels.push_tail(& $1->link);
$$ = labels;
$$->set_location(@1);
}
| case_label_list case_label
{
$$ = $1;
$$->labels.push_tail(& $2->link);
}
;
case_statement:
case_label_list statement
{
- ast_case_statement *stmts = new(state) ast_case_statement($1);
+ ast_case_statement *stmts = new(state->linalloc) ast_case_statement($1);
stmts->set_location(@2);
stmts->stmts.push_tail(& $2->link);
$$ = stmts;
}
| case_statement statement
{
$$ = $1;
$$->stmts.push_tail(& $2->link);
}
;
case_statement_list:
case_statement
{
- ast_case_statement_list *cases= new(state) ast_case_statement_list();
+ ast_case_statement_list *cases= new(state->linalloc) ast_case_statement_list();
cases->set_location(@1);
cases->cases.push_tail(& $1->link);
$$ = cases;
}
| case_statement_list case_statement
{
$$ = $1;
$$->cases.push_tail(& $2->link);
}
;
iteration_statement:
WHILE '(' condition ')' statement_no_new_scope
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_while,
NULL, $3, NULL, $5);
$$->set_location_range(@1, @4);
}
| DO statement WHILE '(' expression ')' ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_do_while,
NULL, $5, NULL, $2);
$$->set_location_range(@1, @6);
}
| FOR '(' for_init_statement for_rest_statement ')' statement_no_new_scope
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_iteration_statement(ast_iteration_statement::ast_for,
$3, $4.cond, $4.rest, $6);
$$->set_location_range(@1, @6);
}
;
for_init_statement:
expression_statement
| declaration_statement
;
@@ -2621,61 +2621,61 @@ for_rest_statement:
{
$$.cond = $1;
$$.rest = $3;
}
;
// Grammar Note: No 'goto'. Gotos are not supported.
jump_statement:
CONTINUE ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_continue, NULL);
$$->set_location(@1);
}
| BREAK ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_break, NULL);
$$->set_location(@1);
}
| RETURN ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, NULL);
$$->set_location(@1);
}
| RETURN expression ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_return, $2);
$$->set_location_range(@1, @2);
}
| DISCARD ';' // Fragment shader only.
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_jump_statement(ast_jump_statement::ast_discard, NULL);
$$->set_location(@1);
}
;
external_declaration:
function_definition { $$ = $1; }
| declaration { $$ = $1; }
| pragma_statement { $$ = NULL; }
| layout_defaults { $$ = $1; }
;
function_definition:
function_prototype compound_statement_no_new_scope
{
- void *ctx = state;
+ void *ctx = state->linalloc;
$$ = new(ctx) ast_function_definition();
$$->set_location_range(@1, @2);
$$->prototype = $1;
$$->body = $2;
state->symbols->pop_scope();
}
;
/* layout_qualifieropt is packed into this rule */
@@ -2767,51 +2767,51 @@ interface_qualifier:
_mesa_glsl_error(&@1, state, "duplicate patch qualifier");
}
$$ = $2;
$$.flags.q.patch = 1;
}
;
instance_name_opt:
/* empty */
{
- $$ = new(state) ast_interface_block(NULL, NULL);
+ $$ = new(state->linalloc) ast_interface_block(NULL, NULL);
}
| NEW_IDENTIFIER
{
- $$ = new(state) ast_interface_block($1, NULL);
+ $$ = new(state->linalloc) ast_interface_block($1, NULL);
$$->set_location(@1);
}
| NEW_IDENTIFIER array_specifier
{
- $$ = new(state) ast_interface_block($1, $2);
+ $$ = new(state->linalloc) ast_interface_block($1, $2);
$$->set_location_range(@1, @2);
}
;
member_list:
member_declaration
{
$$ = $1;
$1->link.self_link();
}
| member_declaration member_list
{
$$ = $1;
$2->link.insert_before(& $$->link);
}
;
member_declaration:
fully_specified_type struct_declarator_list ';'
{
- void *ctx = state;
+ void *ctx = state->linalloc;
ast_fully_specified_type *type = $1;
type->set_location(@1);
if (type->qualifier.flags.q.attribute) {
_mesa_glsl_error(& @1, state,
"keyword 'attribute' cannot be used with "
"interface block member");
} else if (type->qualifier.flags.q.varying) {
_mesa_glsl_error(& @1, state,
"keyword 'varying' cannot be used with "
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index d649695..74dd8d3 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1625,33 +1625,33 @@ void
ast_struct_specifier::print(void) const
{
printf("struct %s { ", name);
foreach_list_typed(ast_node, ast, link, &this->declarations) {
ast->print();
}
printf("} ");
}
-ast_struct_specifier::ast_struct_specifier(const char *identifier,
+ast_struct_specifier::ast_struct_specifier(void *lin_ctx, const char *identifier,
ast_declarator_list *declarator_list)
{
if (identifier == NULL) {
static mtx_t mutex = _MTX_INITIALIZER_NP;
static unsigned anon_count = 1;
unsigned count;
mtx_lock(&mutex);
count = anon_count++;
mtx_unlock(&mutex);
- identifier = ralloc_asprintf(this, "#anon_struct_%04x", count);
+ identifier = linear_asprintf(lin_ctx, "#anon_struct_%04x", count);
}
name = identifier;
this->declarations.push_degenerate_list_at_head(&declarator_list->link);
is_declaration = true;
layout = NULL;
}
void ast_subroutine_list::print(void) const
{
foreach_list_typed (ast_node, ast, link, & this->declarations) {
diff --git a/src/compiler/glsl/glsl_symbol_table.cpp b/src/compiler/glsl/glsl_symbol_table.cpp
index 6d7baad..0b21faa 100644
--- a/src/compiler/glsl/glsl_symbol_table.cpp
+++ b/src/compiler/glsl/glsl_symbol_table.cpp
@@ -99,20 +99,21 @@ public:
const glsl_type *ibi;
const glsl_type *ibo;
const class ast_type_specifier *a;
};
glsl_symbol_table::glsl_symbol_table()
{
this->separate_function_namespace = false;
this->table = _mesa_symbol_table_ctor();
this->mem_ctx = ralloc_context(NULL);
+ this->linalloc = linear_alloc_parent(this->mem_ctx, 0);
}
glsl_symbol_table::~glsl_symbol_table()
{
_mesa_symbol_table_dtor(table);
ralloc_free(mem_ctx);
}
void glsl_symbol_table::push_scope()
{
@@ -200,21 +201,21 @@ bool glsl_symbol_table::add_function(ir_function *f)
}
symbol_table_entry *entry = new(mem_ctx) symbol_table_entry(f);
return _mesa_symbol_table_add_symbol(table, -1, f->name, entry) == 0;
}
bool glsl_symbol_table::add_default_precision_qualifier(const char *type_name,
int precision)
{
char *name = ralloc_asprintf(mem_ctx, "#default_precision_%s", type_name);
- ast_type_specifier *default_specifier = new(mem_ctx) ast_type_specifier(name);
+ ast_type_specifier *default_specifier = new(linalloc) ast_type_specifier(name);
default_specifier->default_precision = precision;
symbol_table_entry *entry =
new(mem_ctx) symbol_table_entry(default_specifier);
return _mesa_symbol_table_add_symbol(table, -1, name, entry) == 0;
}
void glsl_symbol_table::add_global_function(ir_function *f)
{
diff --git a/src/compiler/glsl/glsl_symbol_table.h b/src/compiler/glsl/glsl_symbol_table.h
index 2f94d4c..087cc71 100644
--- a/src/compiler/glsl/glsl_symbol_table.h
+++ b/src/compiler/glsl/glsl_symbol_table.h
@@ -103,13 +103,14 @@ struct glsl_symbol_table {
/**
* Replaces the variable in the entry by the new variable.
*/
void replace_variable(const char *name, ir_variable *v);
private:
symbol_table_entry *get_entry(const char *name);
struct _mesa_symbol_table *table;
void *mem_ctx;
+ void *linalloc;
};
#endif /* GLSL_SYMBOL_TABLE */
--
2.7.4
More information about the mesa-dev
mailing list