aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r--mesalib/src/glsl/ast_type.cpp10
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-lex.l33
-rw-r--r--mesalib/src/glsl/glcpp/glcpp-parse.y189
-rw-r--r--mesalib/src/glsl/glcpp/glcpp.h9
-rw-r--r--mesalib/src/glsl/list.h6
5 files changed, 187 insertions, 60 deletions
diff --git a/mesalib/src/glsl/ast_type.cpp b/mesalib/src/glsl/ast_type.cpp
index de4c1a410..b596cd59e 100644
--- a/mesalib/src/glsl/ast_type.cpp
+++ b/mesalib/src/glsl/ast_type.cpp
@@ -168,6 +168,16 @@ ast_type_qualifier::merge_qualifier(YYLTYPE *loc,
this->max_vertices = q.max_vertices;
}
+ if (q.flags.q.invocations) {
+ if (this->flags.q.invocations && this->invocations != q.invocations) {
+ _mesa_glsl_error(loc, state,
+ "geometry shader set conflicting invocations "
+ "(%d and %d)", this->invocations, q.invocations);
+ return false;
+ }
+ this->invocations = q.invocations;
+ }
+
if (state->stage == MESA_SHADER_GEOMETRY &&
state->has_explicit_attrib_stream()) {
if (q.flags.q.stream && q.stream >= state->ctx->Const.MaxVertexStreams) {
diff --git a/mesalib/src/glsl/glcpp/glcpp-lex.l b/mesalib/src/glsl/glcpp/glcpp-lex.l
index 188e45466..a1a8e76af 100644
--- a/mesalib/src/glsl/glcpp/glcpp-lex.l
+++ b/mesalib/src/glsl/glcpp/glcpp-lex.l
@@ -76,6 +76,7 @@ NEWLINE [\n]
HSPACE [ \t]
HASH ^{HSPACE}*#{HSPACE}*
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
+PP_NUMBER [.]?[0-9]([._a-zA-Z0-9]|[eEpP][-+])*
PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
/* The OTHER class is simply a catch-all for things that the CPP
@@ -137,14 +138,15 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
* 2. The skip_stack is NULL meaning that we've reached
* the last #endif.
*
- * 3. The lexing_if bit is set. This indicates that we
- * are lexing the expression following an "#if" of
- * "#elif". Even inside an "#if 0" we need to lex this
- * expression so the parser can correctly update the
- * skip_stack state.
+ * 3. The lexing_directive bit is set. This indicates that we are
+ * lexing a pre-processor directive, (such as #if, #elif, or
+ * #else). For the #if and #elif directives we always need to
+ * parse the conditions, (even if otherwise within an #if
+ * 0). And for #else, we want to be able to generate an error
+ * if any garbage follows #else.
*/
if (YY_START == INITIAL || YY_START == SKIP) {
- if (parser->lexing_if ||
+ if (parser->lexing_directive ||
parser->skip_stack == NULL ||
parser->skip_stack->type == SKIP_NO_SKIP)
{
@@ -178,7 +180,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
/* glcpp doesn't handle #extension, #version, or #pragma directives.
* Simply pass them through to the main compiler's lexer/parser. */
-{HASH}(extension|pragma)[^\n]+ {
+{HASH}(extension|pragma)[^\n]* {
if (parser->commented_newlines)
BEGIN NEWLINE_CATCHUP;
yylval->str = ralloc_strdup (yyextra, yytext);
@@ -193,25 +195,25 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
<SKIP,INITIAL>{
{HASH}ifdef {
- yyextra->lexing_if = 1;
+ yyextra->lexing_directive = 1;
yyextra->space_tokens = 0;
return HASH_IFDEF;
}
{HASH}ifndef {
- yyextra->lexing_if = 1;
+ yyextra->lexing_directive = 1;
yyextra->space_tokens = 0;
return HASH_IFNDEF;
}
{HASH}if/[^_a-zA-Z0-9] {
- yyextra->lexing_if = 1;
+ yyextra->lexing_directive = 1;
yyextra->space_tokens = 0;
return HASH_IF;
}
{HASH}elif/[^_a-zA-Z0-9] {
- yyextra->lexing_if = 1;
+ yyextra->lexing_directive = 1;
yyextra->space_tokens = 0;
return HASH_ELIF;
}
@@ -329,6 +331,11 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
return IDENTIFIER;
}
+{PP_NUMBER} {
+ yylval->str = ralloc_strdup (yyextra, yytext);
+ return OTHER;
+}
+
{PUNCTUATION} {
return yytext[0];
}
@@ -348,7 +355,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
if (parser->commented_newlines) {
BEGIN NEWLINE_CATCHUP;
}
- yyextra->lexing_if = 0;
+ yyextra->lexing_directive = 0;
yylineno++;
yycolumn = 0;
return NEWLINE;
@@ -357,7 +364,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
/* Handle missing newline at EOF. */
<INITIAL><<EOF>> {
BEGIN DONE; /* Don't keep matching this rule forever. */
- yyextra->lexing_if = 0;
+ yyextra->lexing_directive = 0;
return NEWLINE;
}
diff --git a/mesalib/src/glsl/glcpp/glcpp-parse.y b/mesalib/src/glsl/glcpp/glcpp-parse.y
index ccf810559..084078eb0 100644
--- a/mesalib/src/glsl/glcpp/glcpp-parse.y
+++ b/mesalib/src/glsl/glcpp/glcpp-parse.y
@@ -166,7 +166,8 @@ add_builtin_define(glcpp_parser_t *parser, const char *name, int value);
%expect 0
%token COMMA_FINAL DEFINED ELIF_EXPANDED HASH HASH_DEFINE FUNC_IDENTIFIER OBJ_IDENTIFIER HASH_ELIF HASH_ELSE HASH_ENDIF HASH_IF HASH_IFDEF HASH_IFNDEF HASH_LINE HASH_UNDEF HASH_VERSION IDENTIFIER IF_EXPANDED INTEGER INTEGER_STRING LINE_EXPANDED NEWLINE OTHER PLACEHOLDER SPACE
%token PASTE
-%type <ival> expression INTEGER operator SPACE integer_constant
+%type <ival> INTEGER operator SPACE integer_constant
+%type <expression_value> expression
%type <str> IDENTIFIER FUNC_IDENTIFIER OBJ_IDENTIFIER INTEGER_STRING OTHER
%type <string_list> identifier_list
%type <token> preprocessing_token conditional_token
@@ -216,10 +217,14 @@ line:
expanded_line:
IF_EXPANDED expression NEWLINE {
- _glcpp_parser_skip_stack_push_if (parser, & @1, $2);
+ 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);
}
| ELIF_EXPANDED expression NEWLINE {
- _glcpp_parser_skip_stack_change_if (parser, & @1, "elif", $2);
+ 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_change_if (parser, & @1, "elif", $2.value);
}
| LINE_EXPANDED integer_constant NEWLINE {
parser->has_new_line_number = 1;
@@ -260,7 +265,14 @@ control_line:
| HASH_UNDEF {
glcpp_parser_resolve_implicit_version(parser);
} IDENTIFIER NEWLINE {
- macro_t *macro = hash_table_find (parser->defines, $3);
+ macro_t *macro;
+ if (strcmp("__LINE__", $3) == 0
+ || strcmp("__FILE__", $3) == 0
+ || strcmp("__VERSION__", $3) == 0)
+ glcpp_error(& @1, parser, "Built-in (pre-defined)"
+ " macro names can not be undefined.");
+
+ macro = hash_table_find (parser->defines, $3);
if (macro) {
hash_table_remove (parser->defines, $3);
ralloc_free (macro);
@@ -358,7 +370,7 @@ control_line:
glcpp_warning(& @1, parser, "ignoring illegal #elif without expression");
}
}
-| HASH_ELSE {
+| HASH_ELSE { parser->lexing_directive = 1; } NEWLINE {
if (parser->skip_stack &&
parser->skip_stack->has_else)
{
@@ -370,7 +382,7 @@ control_line:
if (parser->skip_stack)
parser->skip_stack->has_else = true;
}
- } NEWLINE
+ }
| HASH_ENDIF {
_glcpp_parser_skip_stack_pop (parser, & @1);
} NEWLINE
@@ -406,87 +418,176 @@ integer_constant:
}
expression:
- integer_constant
+ integer_constant {
+ $$.value = $1;
+ $$.undefined_macro = NULL;
+ }
| IDENTIFIER {
+ $$.value = 0;
if (parser->is_gles)
- glcpp_error(& @1, parser, "undefined macro %s in expression (illegal in GLES)", $1);
- $$ = 0;
+ $$.undefined_macro = ralloc_strdup (parser, $1);
+ else
+ $$.undefined_macro = NULL;
}
| expression OR expression {
- $$ = $1 || $3;
+ $$.value = $1.value || $3.value;
+
+ /* Short-circuit: Only flag undefined from right side
+ * if left side evaluates to false.
+ */
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else if (! $1.value)
+ $$.undefined_macro = $3.undefined_macro;
}
| expression AND expression {
- $$ = $1 && $3;
+ $$.value = $1.value && $3.value;
+
+ /* Short-circuit: Only flag undefined from right-side
+ * if left side evaluates to true.
+ */
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else if ($1.value)
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '|' expression {
- $$ = $1 | $3;
+ $$.value = $1.value | $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '^' expression {
- $$ = $1 ^ $3;
+ $$.value = $1.value ^ $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '&' expression {
- $$ = $1 & $3;
+ $$.value = $1.value & $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression NOT_EQUAL expression {
- $$ = $1 != $3;
+ $$.value = $1.value != $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression EQUAL expression {
- $$ = $1 == $3;
+ $$.value = $1.value == $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression GREATER_OR_EQUAL expression {
- $$ = $1 >= $3;
+ $$.value = $1.value >= $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression LESS_OR_EQUAL expression {
- $$ = $1 <= $3;
+ $$.value = $1.value <= $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '>' expression {
- $$ = $1 > $3;
+ $$.value = $1.value > $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '<' expression {
- $$ = $1 < $3;
+ $$.value = $1.value < $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression RIGHT_SHIFT expression {
- $$ = $1 >> $3;
+ $$.value = $1.value >> $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression LEFT_SHIFT expression {
- $$ = $1 << $3;
+ $$.value = $1.value << $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '-' expression {
- $$ = $1 - $3;
+ $$.value = $1.value - $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '+' expression {
- $$ = $1 + $3;
+ $$.value = $1.value + $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '%' expression {
- if ($3 == 0) {
+ if ($3.value == 0) {
yyerror (& @1, parser,
"zero modulus in preprocessor directive");
} else {
- $$ = $1 % $3;
+ $$.value = $1.value % $3.value;
}
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '/' expression {
- if ($3 == 0) {
+ if ($3.value == 0) {
yyerror (& @1, parser,
"division by 0 in preprocessor directive");
} else {
- $$ = $1 / $3;
+ $$.value = $1.value / $3.value;
}
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| expression '*' expression {
- $$ = $1 * $3;
+ $$.value = $1.value * $3.value;
+ if ($1.undefined_macro)
+ $$.undefined_macro = $1.undefined_macro;
+ else
+ $$.undefined_macro = $3.undefined_macro;
}
| '!' expression %prec UNARY {
- $$ = ! $2;
+ $$.value = ! $2.value;
+ $$.undefined_macro = $2.undefined_macro;
}
| '~' expression %prec UNARY {
- $$ = ~ $2;
+ $$.value = ~ $2.value;
+ $$.undefined_macro = $2.undefined_macro;
}
| '-' expression %prec UNARY {
- $$ = - $2;
+ $$.value = - $2.value;
+ $$.undefined_macro = $2.undefined_macro;
}
| '+' expression %prec UNARY {
- $$ = + $2;
+ $$.value = + $2.value;
+ $$.undefined_macro = $2.undefined_macro;
}
| '(' expression ')' {
$$ = $2;
@@ -525,7 +626,7 @@ replacement_list:
junk:
/* empty */
| pp_tokens {
- glcpp_warning(&@1, parser, "extra tokens at end of directive");
+ glcpp_error(&@1, parser, "extra tokens at end of directive");
}
;
@@ -933,14 +1034,16 @@ _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
if (node_a == NULL || node_b == NULL)
return 0;
-
- if (node_a->token->type == SPACE) {
- node_a = node_a->next;
- continue;
- }
-
- if (node_b->token->type == SPACE) {
- node_b = node_b->next;
+ /* Make sure whitespace appears in the same places in both.
+ * It need not be exactly the same amount of whitespace,
+ * though.
+ */
+ if (node_a->token->type == SPACE
+ && node_b->token->type == SPACE) {
+ while (node_a->token->type == SPACE)
+ node_a = node_a->next;
+ while (node_b->token->type == SPACE)
+ node_b = node_b->next;
continue;
}
@@ -1203,7 +1306,7 @@ glcpp_parser_create (const struct gl_extensions *extensions, gl_api api)
parser->defines = hash_table_ctor (32, hash_table_string_hash,
hash_table_string_compare);
parser->active = NULL;
- parser->lexing_if = 0;
+ parser->lexing_directive = 0;
parser->space_tokens = 1;
parser->newline_as_space = 0;
parser->in_control_line = 0;
diff --git a/mesalib/src/glsl/glcpp/glcpp.h b/mesalib/src/glsl/glcpp/glcpp.h
index 79ccb234f..64b487202 100644
--- a/mesalib/src/glsl/glcpp/glcpp.h
+++ b/mesalib/src/glsl/glcpp/glcpp.h
@@ -37,6 +37,12 @@
/* Some data types used for parser values. */
+typedef struct expression_value {
+ intmax_t value;
+ char *undefined_macro;
+} expression_value_t;
+
+
typedef struct string_node {
const char *str;
struct string_node *next;
@@ -53,6 +59,7 @@ typedef struct token_list token_list_t;
typedef union YYSTYPE
{
intmax_t ival;
+ expression_value_t expression_value;
char *str;
string_list_t *string_list;
token_t *token;
@@ -168,7 +175,7 @@ struct glcpp_parser {
yyscan_t scanner;
struct hash_table *defines;
active_list_t *active;
- int lexing_if;
+ int lexing_directive;
int space_tokens;
int newline_as_space;
int in_control_line;
diff --git a/mesalib/src/glsl/list.h b/mesalib/src/glsl/list.h
index 922bd68ab..a4444bda9 100644
--- a/mesalib/src/glsl/list.h
+++ b/mesalib/src/glsl/list.h
@@ -565,9 +565,9 @@ inline void exec_node::insert_before(exec_list *before)
!(__inst)->is_tail_sentinel(); \
(__inst) = (__type *)(__inst)->next)
-#define foreach_in_list_reverse(__type, __inst, __list) \
- for (__type *(__inst) = (__type *)(__list)->head; \
- !(__inst)->is_head_sentinel(); \
+#define foreach_in_list_reverse(__type, __inst, __list) \
+ for (__type *(__inst) = (__type *)(__list)->tail_pred; \
+ !(__inst)->is_head_sentinel(); \
(__inst) = (__type *)(__inst)->prev)
/**