Convert ast_node use of simple_node to exec_list and exec_node
This commit is contained in:
19
ast.h
19
ast.h
@@ -26,7 +26,6 @@
|
|||||||
#ifndef AST_H
|
#ifndef AST_H
|
||||||
#define AST_H
|
#define AST_H
|
||||||
|
|
||||||
#include "main/simple_list.h"
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "glsl_parser_extras.h"
|
#include "glsl_parser_extras.h"
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ struct _mesa_glsl_parse_state;
|
|||||||
|
|
||||||
struct YYLTYPE;
|
struct YYLTYPE;
|
||||||
|
|
||||||
class ast_node : public simple_node {
|
class ast_node {
|
||||||
public:
|
public:
|
||||||
virtual ~ast_node();
|
virtual ~ast_node();
|
||||||
virtual void print(void) const;
|
virtual void print(void) const;
|
||||||
@@ -81,6 +80,8 @@ public:
|
|||||||
unsigned column;
|
unsigned column;
|
||||||
} location;
|
} location;
|
||||||
|
|
||||||
|
exec_node link;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ast_node(void);
|
ast_node(void);
|
||||||
};
|
};
|
||||||
@@ -181,7 +182,7 @@ public:
|
|||||||
* List of expressions for an \c ast_sequence or parameters for an
|
* List of expressions for an \c ast_sequence or parameters for an
|
||||||
* \c ast_function_call
|
* \c ast_function_call
|
||||||
*/
|
*/
|
||||||
struct simple_node expressions;
|
exec_list expressions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ast_expression_bin : public ast_expression {
|
class ast_expression_bin : public ast_expression {
|
||||||
@@ -247,7 +248,7 @@ public:
|
|||||||
struct _mesa_glsl_parse_state *state);
|
struct _mesa_glsl_parse_state *state);
|
||||||
|
|
||||||
int new_scope;
|
int new_scope;
|
||||||
struct simple_node statements;
|
exec_list statements;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ast_declaration : public ast_node {
|
class ast_declaration : public ast_node {
|
||||||
@@ -294,7 +295,7 @@ public:
|
|||||||
struct _mesa_glsl_parse_state *state);
|
struct _mesa_glsl_parse_state *state);
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
struct simple_node declarations;
|
exec_list declarations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -414,7 +415,7 @@ public:
|
|||||||
struct _mesa_glsl_parse_state *state);
|
struct _mesa_glsl_parse_state *state);
|
||||||
|
|
||||||
ast_fully_specified_type *type;
|
ast_fully_specified_type *type;
|
||||||
struct simple_node declarations;
|
exec_list declarations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special flag for vertex shader "invariant" declarations.
|
* Special flag for vertex shader "invariant" declarations.
|
||||||
@@ -439,7 +440,7 @@ public:
|
|||||||
int is_array;
|
int is_array;
|
||||||
ast_expression *array_size;
|
ast_expression *array_size;
|
||||||
|
|
||||||
static void parameters_to_hir(simple_node *ast_parameters,
|
static void parameters_to_hir(exec_list *ast_parameters,
|
||||||
bool formal, exec_list *ir_parameters,
|
bool formal, exec_list *ir_parameters,
|
||||||
struct _mesa_glsl_parse_state *state);
|
struct _mesa_glsl_parse_state *state);
|
||||||
|
|
||||||
@@ -468,7 +469,7 @@ public:
|
|||||||
ast_fully_specified_type *return_type;
|
ast_fully_specified_type *return_type;
|
||||||
char *identifier;
|
char *identifier;
|
||||||
|
|
||||||
struct simple_node parameters;
|
exec_list parameters;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@@ -554,7 +555,7 @@ public:
|
|||||||
class ast_switch_statement : public ast_node {
|
class ast_switch_statement : public ast_node {
|
||||||
public:
|
public:
|
||||||
ast_expression *expression;
|
ast_expression *expression;
|
||||||
struct simple_node statements;
|
exec_list statements;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ast_iteration_statement : public ast_node {
|
class ast_iteration_statement : public ast_node {
|
||||||
|
@@ -29,15 +29,14 @@
|
|||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
process_parameters(exec_list *instructions, exec_list *actual_parameters,
|
process_parameters(exec_list *instructions, exec_list *actual_parameters,
|
||||||
simple_node *parameters,
|
exec_list *parameters,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
simple_node *ptr;
|
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
|
||||||
foreach (ptr, parameters) {
|
foreach_list (n, parameters) {
|
||||||
ir_rvalue *const result =
|
ast_node *const ast = exec_node_data(ast_node, n, link);
|
||||||
((ast_node *) ptr)->hir(instructions, state);
|
ir_rvalue *const result = ast->hir(instructions, state);
|
||||||
|
|
||||||
actual_parameters->push_tail(result);
|
actual_parameters->push_tail(result);
|
||||||
count++;
|
count++;
|
||||||
@@ -107,7 +106,7 @@ process_call(exec_list *instructions, ir_function *f,
|
|||||||
|
|
||||||
static ir_rvalue *
|
static ir_rvalue *
|
||||||
match_function_by_name(exec_list *instructions, const char *name,
|
match_function_by_name(exec_list *instructions, const char *name,
|
||||||
YYLTYPE *loc, simple_node *parameters,
|
YYLTYPE *loc, exec_list *parameters,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
ir_function *f = state->symbols->get_function(name);
|
ir_function *f = state->symbols->get_function(name);
|
||||||
@@ -216,7 +215,7 @@ dereference_component(ir_rvalue *src, unsigned component)
|
|||||||
static ir_rvalue *
|
static ir_rvalue *
|
||||||
process_array_constructor(exec_list *instructions,
|
process_array_constructor(exec_list *instructions,
|
||||||
const glsl_type *constructor_type,
|
const glsl_type *constructor_type,
|
||||||
YYLTYPE *loc, simple_node *parameters,
|
YYLTYPE *loc, exec_list *parameters,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
/* Array constructors come in two forms: sized and unsized. Sized array
|
/* Array constructors come in two forms: sized and unsized. Sized array
|
||||||
@@ -358,12 +357,12 @@ ast_function_expression::hir(exec_list *instructions,
|
|||||||
unsigned nonmatrix_parameters = 0;
|
unsigned nonmatrix_parameters = 0;
|
||||||
exec_list actual_parameters;
|
exec_list actual_parameters;
|
||||||
|
|
||||||
assert(!is_empty_list(&this->expressions));
|
assert(!this->expressions.is_empty());
|
||||||
|
|
||||||
simple_node *ptr;
|
foreach_list (n, &this->expressions) {
|
||||||
foreach (ptr, &this->expressions) {
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
ir_rvalue *const result =
|
ir_rvalue *const result =
|
||||||
((ast_node *) ptr)->hir(instructions, state)->as_rvalue();
|
ast->hir(instructions, state)->as_rvalue();
|
||||||
|
|
||||||
/* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
|
/* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec:
|
||||||
*
|
*
|
||||||
|
@@ -59,16 +59,15 @@
|
|||||||
void
|
void
|
||||||
_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
|
_mesa_ast_to_hir(exec_list *instructions, struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
_mesa_glsl_initialize_variables(instructions, state);
|
_mesa_glsl_initialize_variables(instructions, state);
|
||||||
_mesa_glsl_initialize_constructors(instructions, state);
|
_mesa_glsl_initialize_constructors(instructions, state);
|
||||||
_mesa_glsl_initialize_functions(instructions, state);
|
_mesa_glsl_initialize_functions(instructions, state);
|
||||||
|
|
||||||
state->current_function = NULL;
|
state->current_function = NULL;
|
||||||
|
|
||||||
foreach (ptr, & state->translation_unit) {
|
foreach_list (n, & state->translation_unit) {
|
||||||
((ast_node *)ptr)->hir(instructions, state);
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->hir(instructions, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -622,13 +621,11 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
};
|
};
|
||||||
ir_rvalue *result = NULL;
|
ir_rvalue *result = NULL;
|
||||||
ir_rvalue *op[2];
|
ir_rvalue *op[2];
|
||||||
struct simple_node op_list;
|
|
||||||
const struct glsl_type *type = glsl_type::error_type;
|
const struct glsl_type *type = glsl_type::error_type;
|
||||||
bool error_emitted = false;
|
bool error_emitted = false;
|
||||||
YYLTYPE loc;
|
YYLTYPE loc;
|
||||||
|
|
||||||
loc = this->get_location();
|
loc = this->get_location();
|
||||||
make_empty_list(& op_list);
|
|
||||||
|
|
||||||
switch (this->oper) {
|
switch (this->oper) {
|
||||||
case ast_assign: {
|
case ast_assign: {
|
||||||
@@ -1257,20 +1254,20 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ast_sequence: {
|
case ast_sequence: {
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
/* It should not be possible to generate a sequence in the AST without
|
/* It should not be possible to generate a sequence in the AST without
|
||||||
* any expressions in it.
|
* any expressions in it.
|
||||||
*/
|
*/
|
||||||
assert(!is_empty_list(&this->expressions));
|
assert(!this->expressions.is_empty());
|
||||||
|
|
||||||
/* The r-value of a sequence is the last expression in the sequence. If
|
/* The r-value of a sequence is the last expression in the sequence. If
|
||||||
* the other expressions in the sequence do not have side-effects (and
|
* the other expressions in the sequence do not have side-effects (and
|
||||||
* therefore add instructions to the instruction list), they get dropped
|
* therefore add instructions to the instruction list), they get dropped
|
||||||
* on the floor.
|
* on the floor.
|
||||||
*/
|
*/
|
||||||
foreach (ptr, &this->expressions)
|
foreach_list (n, &this->expressions) {
|
||||||
result = ((ast_node *)ptr)->hir(instructions, state);
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
result = ast->hir(instructions, state);
|
||||||
|
}
|
||||||
|
|
||||||
type = result->type;
|
type = result->type;
|
||||||
|
|
||||||
@@ -1314,14 +1311,13 @@ ir_rvalue *
|
|||||||
ast_compound_statement::hir(exec_list *instructions,
|
ast_compound_statement::hir(exec_list *instructions,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
|
|
||||||
if (new_scope)
|
if (new_scope)
|
||||||
state->symbols->push_scope();
|
state->symbols->push_scope();
|
||||||
|
|
||||||
foreach (ptr, &statements)
|
foreach_list (n, &this->statements) {
|
||||||
((ast_node *)ptr)->hir(instructions, state);
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->hir(instructions, state);
|
||||||
|
}
|
||||||
|
|
||||||
if (new_scope)
|
if (new_scope)
|
||||||
state->symbols->pop_scope();
|
state->symbols->pop_scope();
|
||||||
@@ -1472,7 +1468,6 @@ ir_rvalue *
|
|||||||
ast_declarator_list::hir(exec_list *instructions,
|
ast_declarator_list::hir(exec_list *instructions,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
const struct glsl_type *decl_type;
|
const struct glsl_type *decl_type;
|
||||||
const char *type_name = NULL;
|
const char *type_name = NULL;
|
||||||
ir_rvalue *result = NULL;
|
ir_rvalue *result = NULL;
|
||||||
@@ -1489,7 +1484,7 @@ ast_declarator_list::hir(exec_list *instructions,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
decl_type = this->type->specifier->glsl_type(& type_name, state);
|
decl_type = this->type->specifier->glsl_type(& type_name, state);
|
||||||
if (is_empty_list(&this->declarations)) {
|
if (this->declarations.is_empty()) {
|
||||||
/* There are only two valid cases where the declaration list can be
|
/* There are only two valid cases where the declaration list can be
|
||||||
* empty.
|
* empty.
|
||||||
*
|
*
|
||||||
@@ -1506,8 +1501,8 @@ ast_declarator_list::hir(exec_list *instructions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ptr, &this->declarations) {
|
foreach_list (n, &this->declarations) {
|
||||||
struct ast_declaration *const decl = (struct ast_declaration * )ptr;
|
ast_declaration *const decl = exec_node_data(ast_declaration, n, link);
|
||||||
const struct glsl_type *var_type;
|
const struct glsl_type *var_type;
|
||||||
struct ir_variable *var;
|
struct ir_variable *var;
|
||||||
|
|
||||||
@@ -1875,17 +1870,17 @@ ast_parameter_declarator::hir(exec_list *instructions,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ast_parameter_declarator::parameters_to_hir(struct simple_node *ast_parameters,
|
ast_parameter_declarator::parameters_to_hir(exec_list *ast_parameters,
|
||||||
bool formal,
|
bool formal,
|
||||||
exec_list *ir_parameters,
|
exec_list *ir_parameters,
|
||||||
_mesa_glsl_parse_state *state)
|
_mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
ast_parameter_declarator *void_param = NULL;
|
ast_parameter_declarator *void_param = NULL;
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
|
||||||
foreach (ptr, ast_parameters) {
|
foreach_list (n, ast_parameters) {
|
||||||
ast_parameter_declarator *param = (ast_parameter_declarator *)ptr;
|
ast_parameter_declarator *param =
|
||||||
|
exec_node_data(ast_parameter_declarator, n, link);
|
||||||
param->formal_parameter = formal;
|
param->formal_parameter = formal;
|
||||||
param->hir(ir_parameters, state);
|
param->hir(ir_parameters, state);
|
||||||
|
|
||||||
@@ -2279,7 +2274,6 @@ ir_rvalue *
|
|||||||
ast_struct_specifier::hir(exec_list *instructions,
|
ast_struct_specifier::hir(exec_list *instructions,
|
||||||
struct _mesa_glsl_parse_state *state)
|
struct _mesa_glsl_parse_state *state)
|
||||||
{
|
{
|
||||||
simple_node *ptr;
|
|
||||||
unsigned decl_count = 0;
|
unsigned decl_count = 0;
|
||||||
|
|
||||||
/* Make an initial pass over the list of structure fields to determine how
|
/* Make an initial pass over the list of structure fields to determine how
|
||||||
@@ -2287,11 +2281,11 @@ ast_struct_specifier::hir(exec_list *instructions,
|
|||||||
* This means that we actually need to count the number of elements in the
|
* This means that we actually need to count the number of elements in the
|
||||||
* 'declarations' list in each of the elements.
|
* 'declarations' list in each of the elements.
|
||||||
*/
|
*/
|
||||||
foreach (ptr, & this->declarations) {
|
foreach_list (n, & this->declarations) {
|
||||||
ast_declarator_list *decl_list = (ast_declarator_list *) ptr;
|
ast_declarator_list *decl_list =
|
||||||
simple_node *decl_ptr;
|
exec_node_data(ast_declarator_list, n, link);
|
||||||
|
|
||||||
foreach (decl_ptr, & decl_list->declarations) {
|
foreach_list_const (decl_ptr, & decl_list->declarations) {
|
||||||
decl_count++;
|
decl_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2306,9 +2300,9 @@ ast_struct_specifier::hir(exec_list *instructions,
|
|||||||
malloc(sizeof(*fields) * decl_count);
|
malloc(sizeof(*fields) * decl_count);
|
||||||
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
foreach (ptr, & this->declarations) {
|
foreach_list (n, & this->declarations) {
|
||||||
ast_declarator_list *decl_list = (ast_declarator_list *) ptr;
|
ast_declarator_list *decl_list =
|
||||||
simple_node *decl_ptr;
|
exec_node_data(ast_declarator_list, n, link);
|
||||||
const char *type_name;
|
const char *type_name;
|
||||||
|
|
||||||
decl_list->type->specifier->hir(instructions, state);
|
decl_list->type->specifier->hir(instructions, state);
|
||||||
@@ -2316,8 +2310,9 @@ ast_struct_specifier::hir(exec_list *instructions,
|
|||||||
const glsl_type *decl_type =
|
const glsl_type *decl_type =
|
||||||
decl_list->type->specifier->glsl_type(& type_name, state);
|
decl_list->type->specifier->glsl_type(& type_name, state);
|
||||||
|
|
||||||
foreach (decl_ptr, & decl_list->declarations) {
|
foreach_list (decl_node, & decl_list->declarations) {
|
||||||
ast_declaration *const decl = (ast_declaration *) decl_ptr;
|
ast_declaration *const decl =
|
||||||
|
exec_node_data(ast_declaration, decl_node, link);
|
||||||
const struct glsl_type *const field_type =
|
const struct glsl_type *const field_type =
|
||||||
(decl->is_array)
|
(decl->is_array)
|
||||||
? process_array_type(decl_type, decl->array_size, state)
|
? process_array_type(decl_type, decl->array_size, state)
|
||||||
|
@@ -234,13 +234,11 @@ extension_statement:
|
|||||||
external_declaration_list:
|
external_declaration_list:
|
||||||
external_declaration
|
external_declaration
|
||||||
{
|
{
|
||||||
insert_at_tail(& state->translation_unit,
|
state->translation_unit.push_tail(& $1->link);
|
||||||
(struct simple_node *) $1);
|
|
||||||
}
|
}
|
||||||
| external_declaration_list external_declaration
|
| external_declaration_list external_declaration
|
||||||
{
|
{
|
||||||
insert_at_tail(& state->translation_unit,
|
state->translation_unit.push_tail(& $2->link);
|
||||||
(struct simple_node *) $2);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -352,13 +350,13 @@ function_call_header_with_parameters:
|
|||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->expressions, (struct simple_node *) $2);
|
$$->expressions.push_tail(& $2->link);
|
||||||
}
|
}
|
||||||
| function_call_header_with_parameters ',' assignment_expression
|
| function_call_header_with_parameters ',' assignment_expression
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->expressions, (struct simple_node *) $3);
|
$$->expressions.push_tail(& $3->link);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -598,12 +596,12 @@ expression:
|
|||||||
if ($1->oper != ast_sequence) {
|
if ($1->oper != ast_sequence) {
|
||||||
$$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
|
$$ = new ast_expression(ast_sequence, NULL, NULL, NULL);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->expressions, $1);
|
$$->expressions.push_tail(& $1->link);
|
||||||
} else {
|
} else {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_at_tail(& $$->expressions, $3);
|
$$->expressions.push_tail(& $3->link);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -639,14 +637,12 @@ function_header_with_parameters:
|
|||||||
function_header parameter_declaration
|
function_header parameter_declaration
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->parameters,
|
$$->parameters.push_tail(& $2->link);
|
||||||
(struct simple_node *) $2);
|
|
||||||
}
|
}
|
||||||
| function_header_with_parameters ',' parameter_declaration
|
| function_header_with_parameters ',' parameter_declaration
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->parameters,
|
$$->parameters.push_tail(& $3->link);
|
||||||
(struct simple_node *) $3);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -735,8 +731,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| init_declarator_list ',' IDENTIFIER '[' ']'
|
| init_declarator_list ',' IDENTIFIER '[' ']'
|
||||||
{
|
{
|
||||||
@@ -744,8 +739,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
|
| init_declarator_list ',' IDENTIFIER '[' constant_expression ']'
|
||||||
{
|
{
|
||||||
@@ -753,8 +747,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
|
| init_declarator_list ',' IDENTIFIER '[' ']' '=' initializer
|
||||||
{
|
{
|
||||||
@@ -762,8 +755,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
|
| init_declarator_list ',' IDENTIFIER '[' constant_expression ']' '=' initializer
|
||||||
{
|
{
|
||||||
@@ -771,8 +763,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| init_declarator_list ',' IDENTIFIER '=' initializer
|
| init_declarator_list ',' IDENTIFIER '=' initializer
|
||||||
{
|
{
|
||||||
@@ -780,8 +771,7 @@ init_declarator_list:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -798,8 +788,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| fully_specified_type IDENTIFIER '[' ']'
|
| fully_specified_type IDENTIFIER '[' ']'
|
||||||
{
|
{
|
||||||
@@ -807,8 +796,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| fully_specified_type IDENTIFIER '[' constant_expression ']'
|
| fully_specified_type IDENTIFIER '[' constant_expression ']'
|
||||||
{
|
{
|
||||||
@@ -816,8 +804,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| fully_specified_type IDENTIFIER '[' ']' '=' initializer
|
| fully_specified_type IDENTIFIER '[' ']' '=' initializer
|
||||||
{
|
{
|
||||||
@@ -825,8 +812,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
|
| fully_specified_type IDENTIFIER '[' constant_expression ']' '=' initializer
|
||||||
{
|
{
|
||||||
@@ -834,8 +820,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| fully_specified_type IDENTIFIER '=' initializer
|
| fully_specified_type IDENTIFIER '=' initializer
|
||||||
{
|
{
|
||||||
@@ -843,8 +828,7 @@ single_declaration:
|
|||||||
|
|
||||||
$$ = new ast_declarator_list($1);
|
$$ = new ast_declarator_list($1);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
| INVARIANT IDENTIFIER // Vertex only.
|
| INVARIANT IDENTIFIER // Vertex only.
|
||||||
{
|
{
|
||||||
@@ -854,8 +838,7 @@ single_declaration:
|
|||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
$$->invariant = true;
|
$$->invariant = true;
|
||||||
|
|
||||||
insert_at_tail(& $$->declarations,
|
$$->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1033,12 +1016,12 @@ struct_declaration_list:
|
|||||||
struct_declaration
|
struct_declaration
|
||||||
{
|
{
|
||||||
$$ = (struct ast_node *) $1;
|
$$ = (struct ast_node *) $1;
|
||||||
|
$1->link.self_link();
|
||||||
}
|
}
|
||||||
| struct_declaration_list struct_declaration
|
| struct_declaration_list struct_declaration
|
||||||
{
|
{
|
||||||
$$ = (struct ast_node *) $1;
|
$$ = (struct ast_node *) $1;
|
||||||
insert_at_tail((struct simple_node *) $$,
|
$$->link.insert_before(& $2->link);
|
||||||
(struct simple_node *) $2);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1052,18 +1035,20 @@ struct_declaration:
|
|||||||
$$ = new ast_declarator_list(type);
|
$$ = new ast_declarator_list(type);
|
||||||
$$->set_location(yylloc);
|
$$->set_location(yylloc);
|
||||||
|
|
||||||
insert_at_tail((struct simple_node *) $2,
|
$$->declarations.push_degenerate_list_at_head(& $2->link);
|
||||||
& $$->declarations);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
struct_declarator_list:
|
struct_declarator_list:
|
||||||
struct_declarator
|
struct_declarator
|
||||||
|
{
|
||||||
|
$$ = $1;
|
||||||
|
$1->link.self_link();
|
||||||
|
}
|
||||||
| struct_declarator_list ',' struct_declarator
|
| struct_declarator_list ',' struct_declarator
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail((struct simple_node *) $$,
|
$$->link.insert_before(& $3->link);
|
||||||
(struct simple_node *) $3);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1154,7 +1139,7 @@ statement_list:
|
|||||||
}
|
}
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
make_empty_list((struct simple_node *) $$);
|
$$->link.self_link();
|
||||||
}
|
}
|
||||||
| statement_list statement
|
| statement_list statement
|
||||||
{
|
{
|
||||||
@@ -1163,8 +1148,7 @@ statement_list:
|
|||||||
assert($2 != NULL);
|
assert($2 != NULL);
|
||||||
}
|
}
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
insert_at_tail((struct simple_node *) $$,
|
$$->link.insert_before(& $2->link);
|
||||||
(struct simple_node *) $2);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1219,9 +1203,7 @@ condition:
|
|||||||
decl->set_location(yylloc);
|
decl->set_location(yylloc);
|
||||||
declarator->set_location(yylloc);
|
declarator->set_location(yylloc);
|
||||||
|
|
||||||
insert_at_tail(& declarator->declarations,
|
declarator->declarations.push_tail(&decl->link);
|
||||||
(struct simple_node *) decl);
|
|
||||||
|
|
||||||
$$ = declarator;
|
$$ = declarator;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@@ -222,7 +222,7 @@ ast_node::print(void) const
|
|||||||
|
|
||||||
ast_node::ast_node(void)
|
ast_node::ast_node(void)
|
||||||
{
|
{
|
||||||
make_empty_list(this);
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,12 +243,11 @@ ast_opt_array_size_print(bool is_array, const ast_expression *array_size)
|
|||||||
void
|
void
|
||||||
ast_compound_statement::print(void) const
|
ast_compound_statement::print(void) const
|
||||||
{
|
{
|
||||||
const struct simple_node *ptr;
|
|
||||||
|
|
||||||
printf("{\n");
|
printf("{\n");
|
||||||
|
|
||||||
foreach(ptr, & statements) {
|
foreach_list_const(n, &this->statements) {
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
@@ -259,16 +258,9 @@ ast_compound_statement::ast_compound_statement(int new_scope,
|
|||||||
ast_node *statements)
|
ast_node *statements)
|
||||||
{
|
{
|
||||||
this->new_scope = new_scope;
|
this->new_scope = new_scope;
|
||||||
make_empty_list(& this->statements);
|
|
||||||
|
|
||||||
if (statements != NULL) {
|
if (statements != NULL) {
|
||||||
/* This seems odd, but it works. The simple_list is,
|
this->statements.push_degenerate_list_at_head(&statements->link);
|
||||||
* basically, a circular list. insert_at_tail adds
|
|
||||||
* the specified node to the list before the current
|
|
||||||
* head.
|
|
||||||
*/
|
|
||||||
insert_at_tail((struct simple_node *) statements,
|
|
||||||
& this->statements);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,10 +325,11 @@ ast_expression::print(void) const
|
|||||||
subexpressions[0]->print();
|
subexpressions[0]->print();
|
||||||
printf("( ");
|
printf("( ");
|
||||||
|
|
||||||
struct simple_node *ptr;
|
foreach_list_const (n, &this->expressions) {
|
||||||
foreach (ptr, &this->expressions) {
|
|
||||||
printf(", ");
|
printf(", ");
|
||||||
((ast_node *)ptr)->print();
|
|
||||||
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(") ");
|
printf(") ");
|
||||||
@@ -366,15 +359,13 @@ ast_expression::print(void) const
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ast_sequence: {
|
case ast_sequence: {
|
||||||
struct simple_node *ptr;
|
|
||||||
struct simple_node *const head = first_elem(& expressions);
|
|
||||||
|
|
||||||
printf("( ");
|
printf("( ");
|
||||||
foreach (ptr, & expressions) {
|
foreach_list_const(n, & this->expressions) {
|
||||||
if (ptr != head)
|
if (n != this->expressions.get_head())
|
||||||
printf(", ");
|
printf(", ");
|
||||||
|
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
printf(") ");
|
printf(") ");
|
||||||
break;
|
break;
|
||||||
@@ -395,7 +386,6 @@ ast_expression::ast_expression(int oper,
|
|||||||
this->subexpressions[0] = ex0;
|
this->subexpressions[0] = ex0;
|
||||||
this->subexpressions[1] = ex1;
|
this->subexpressions[1] = ex1;
|
||||||
this->subexpressions[2] = ex2;
|
this->subexpressions[2] = ex2;
|
||||||
make_empty_list(& expressions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -419,13 +409,12 @@ ast_expression_statement::ast_expression_statement(ast_expression *ex) :
|
|||||||
void
|
void
|
||||||
ast_function::print(void) const
|
ast_function::print(void) const
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
return_type->print();
|
return_type->print();
|
||||||
printf(" %s (", identifier);
|
printf(" %s (", identifier);
|
||||||
|
|
||||||
foreach(ptr, & parameters) {
|
foreach_list_const(n, & this->parameters) {
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(")");
|
printf(")");
|
||||||
@@ -435,7 +424,7 @@ ast_function::print(void) const
|
|||||||
ast_function::ast_function(void)
|
ast_function::ast_function(void)
|
||||||
: is_definition(false), signature(NULL)
|
: is_definition(false), signature(NULL)
|
||||||
{
|
{
|
||||||
make_empty_list(& parameters);
|
/* empty */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -492,9 +481,6 @@ ast_declaration::ast_declaration(char *identifier, int is_array,
|
|||||||
void
|
void
|
||||||
ast_declarator_list::print(void) const
|
ast_declarator_list::print(void) const
|
||||||
{
|
{
|
||||||
struct simple_node *head;
|
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
assert(type || invariant);
|
assert(type || invariant);
|
||||||
|
|
||||||
if (type)
|
if (type)
|
||||||
@@ -502,12 +488,12 @@ ast_declarator_list::print(void) const
|
|||||||
else
|
else
|
||||||
printf("invariant ");
|
printf("invariant ");
|
||||||
|
|
||||||
head = first_elem(& declarations);
|
foreach_list_const (ptr, & this->declarations) {
|
||||||
foreach (ptr, & declarations) {
|
if (ptr != this->declarations.get_head())
|
||||||
if (ptr != head)
|
|
||||||
printf(", ");
|
printf(", ");
|
||||||
|
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, ptr, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("; ");
|
printf("; ");
|
||||||
@@ -517,7 +503,6 @@ ast_declarator_list::print(void) const
|
|||||||
ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
|
ast_declarator_list::ast_declarator_list(ast_fully_specified_type *type)
|
||||||
{
|
{
|
||||||
this->type = type;
|
this->type = type;
|
||||||
make_empty_list(& this->declarations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -638,11 +623,10 @@ ast_iteration_statement::ast_iteration_statement(int mode,
|
|||||||
void
|
void
|
||||||
ast_struct_specifier::print(void) const
|
ast_struct_specifier::print(void) const
|
||||||
{
|
{
|
||||||
struct simple_node *ptr;
|
|
||||||
|
|
||||||
printf("struct %s { ", name);
|
printf("struct %s { ", name);
|
||||||
foreach (ptr, & declarations) {
|
foreach_list_const(n, &this->declarations) {
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
printf("} ");
|
printf("} ");
|
||||||
}
|
}
|
||||||
@@ -652,14 +636,7 @@ ast_struct_specifier::ast_struct_specifier(char *identifier,
|
|||||||
ast_node *declarator_list)
|
ast_node *declarator_list)
|
||||||
{
|
{
|
||||||
name = identifier;
|
name = identifier;
|
||||||
|
this->declarations.push_degenerate_list_at_head(&declarator_list->link);
|
||||||
/* This seems odd, but it works. The simple_list is,
|
|
||||||
* basically, a circular list. insert_at_tail adds
|
|
||||||
* the specified node to the list before the current
|
|
||||||
* head.
|
|
||||||
*/
|
|
||||||
insert_at_tail((struct simple_node *) declarator_list,
|
|
||||||
& declarations);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -712,7 +689,6 @@ main(int argc, char **argv)
|
|||||||
struct _mesa_glsl_parse_state state;
|
struct _mesa_glsl_parse_state state;
|
||||||
char *shader;
|
char *shader;
|
||||||
size_t shader_len;
|
size_t shader_len;
|
||||||
struct simple_node *ptr;
|
|
||||||
exec_list instructions;
|
exec_list instructions;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
@@ -743,7 +719,7 @@ main(int argc, char **argv)
|
|||||||
shader = load_text_file(argv[2], & shader_len);
|
shader = load_text_file(argv[2], & shader_len);
|
||||||
|
|
||||||
state.scanner = NULL;
|
state.scanner = NULL;
|
||||||
make_empty_list(& state.translation_unit);
|
state.translation_unit.make_empty();
|
||||||
state.symbols = new glsl_symbol_table;
|
state.symbols = new glsl_symbol_table;
|
||||||
state.error = false;
|
state.error = false;
|
||||||
state.temp_index = 0;
|
state.temp_index = 0;
|
||||||
@@ -755,8 +731,9 @@ main(int argc, char **argv)
|
|||||||
_mesa_glsl_parse(& state);
|
_mesa_glsl_parse(& state);
|
||||||
_mesa_glsl_lexer_dtor(& state);
|
_mesa_glsl_lexer_dtor(& state);
|
||||||
|
|
||||||
foreach (ptr, & state.translation_unit) {
|
foreach_list_const(n, &state.translation_unit) {
|
||||||
((ast_node *)ptr)->print();
|
ast_node *ast = exec_node_data(ast_node, n, link);
|
||||||
|
ast->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
_mesa_ast_to_hir(&instructions, &state);
|
_mesa_ast_to_hir(&instructions, &state);
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#define GLSL_PARSER_EXTRAS_H
|
#define GLSL_PARSER_EXTRAS_H
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "main/simple_list.h"
|
|
||||||
#include "glsl_symbol_table.h"
|
#include "glsl_symbol_table.h"
|
||||||
|
|
||||||
enum _mesa_glsl_parser_targets {
|
enum _mesa_glsl_parser_targets {
|
||||||
@@ -38,7 +37,7 @@ enum _mesa_glsl_parser_targets {
|
|||||||
|
|
||||||
struct _mesa_glsl_parse_state {
|
struct _mesa_glsl_parse_state {
|
||||||
void *scanner;
|
void *scanner;
|
||||||
struct simple_node translation_unit;
|
exec_list translation_unit;
|
||||||
glsl_symbol_table *symbols;
|
glsl_symbol_table *symbols;
|
||||||
|
|
||||||
unsigned language_version;
|
unsigned language_version;
|
||||||
|
Reference in New Issue
Block a user