summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-10-05 11:22:34 -0700
committerIan Romanick <ian.d.romanick@intel.com>2011-04-14 11:57:59 -0700
commit9c0b233c44106391b543c882c72ac35c23560585 (patch)
treebe65bae1d7d5a65a170c12b7f79596819262a4df
parent364aa72824c57d6f67bdfb89c187af56d8183c72 (diff)
ARB prog parser: Compile parser as C++
This is in anticipation of generating GLSL IR from the parser. The C++ rules for enums vs. ints are just plain broken.
-rw-r--r--src/mesa/Makefile4
-rw-r--r--src/mesa/program/program_parse.y35
-rw-r--r--src/mesa/program/program_parser.h15
-rw-r--r--src/mesa/sources.mak2
4 files changed, 32 insertions, 24 deletions
diff --git a/src/mesa/Makefile b/src/mesa/Makefile
index 03962e9c194..6059058d0d7 100644
--- a/src/mesa/Makefile
+++ b/src/mesa/Makefile
@@ -74,8 +74,8 @@ main/api_exec_es1.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py m
main/api_exec_es2.c: main/APIspec.xml main/es_generator.py main/APIspecutil.py main/APIspec.py
$(PYTHON2) $(PYTHON_FLAGS) main/es_generator.py -S main/APIspec.xml -V GLES2.0 > $@
-program/program_parse.tab.c program/program_parse.tab.h: program/program_parse.y
- bison -v -d --output=program/program_parse.tab.c $<
+program/program_parse.cpp program/program_parse.tab.h: program/program_parse.y
+ bison -v -o program/program_parse.cpp --defines=program/program_parse.tab.h $<
program/lex.yy.c: program/program_lexer.l
flex --never-interactive --outfile=$@ $<
diff --git a/src/mesa/program/program_parse.y b/src/mesa/program/program_parse.y
index 19aa8ccdb53..0c70307f013 100644
--- a/src/mesa/program/program_parse.y
+++ b/src/mesa/program/program_parse.y
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
+extern "C" {
#include "main/mtypes.h"
#include "main/imports.h"
#include "program/program.h"
@@ -38,6 +39,8 @@
extern void *yy_scan_string(char *);
extern void yy_delete_buffer(void *);
+extern int yylex(union YYSTYPE*, struct YYLTYPE*, void*);
+};
static struct asm_symbol *declare_variable(struct asm_parser_state *state,
char *name, enum asm_type t, struct YYLTYPE *locp);
@@ -46,10 +49,10 @@ static int add_state_reference(struct gl_program_parameter_list *param_list,
const gl_state_index tokens[STATE_LENGTH]);
static int initialize_symbol_from_state(struct gl_program *prog,
- struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
+ struct asm_symbol *param_var, const unsigned tokens[STATE_LENGTH]);
static int initialize_symbol_from_param(struct gl_program *prog,
- struct asm_symbol *param_var, const gl_state_index tokens[STATE_LENGTH]);
+ struct asm_symbol *param_var, const unsigned tokens[STATE_LENGTH]);
static int initialize_symbol_from_const(struct gl_program *prog,
struct asm_symbol *param_var, const struct asm_vector *vec,
@@ -136,7 +139,7 @@ static struct asm_instruction *asm_instruction_copy_ctor(
unsigned attrib;
int integer;
float real;
- gl_state_index state[STATE_LENGTH];
+ unsigned state[STATE_LENGTH];
int negate;
struct asm_vector vector;
gl_inst_opcode opcode;
@@ -1973,14 +1976,14 @@ ADDRESS_statement: ADDRESS { $<integer>$ = $1; } varNameList
varNameList: varNameList ',' IDENTIFIER
{
- if (!declare_variable(state, $3, $<integer>0, & @3)) {
+ if (!declare_variable(state, $3, (asm_type) $<integer>0, & @3)) {
free($3);
YYERROR;
}
}
| IDENTIFIER
{
- if (!declare_variable(state, $1, $<integer>0, & @1)) {
+ if (!declare_variable(state, $1, (asm_type) $<integer>0, & @1)) {
free($1);
YYERROR;
}
@@ -2061,8 +2064,8 @@ resultColBinding: COLOR optResultFaceType optResultColorType
optResultFaceType:
{
$$ = (state->mode == ARB_vertex)
- ? VERT_RESULT_COL0
- : FRAG_RESULT_COLOR;
+ ? (int) VERT_RESULT_COL0
+ : (int) FRAG_RESULT_COLOR;
}
| FRONT
{
@@ -2389,7 +2392,7 @@ declare_variable(struct asm_parser_state *state, char *name, enum asm_type t,
if (exist != NULL) {
yyerror(locp, state, "redeclared identifier");
} else {
- s = calloc(1, sizeof(struct asm_symbol));
+ s = (struct asm_symbol *) calloc(1, sizeof(struct asm_symbol));
s->name = name;
s->type = t;
@@ -2452,7 +2455,7 @@ int add_state_reference(struct gl_program_parameter_list *param_list,
int
initialize_symbol_from_state(struct gl_program *prog,
struct asm_symbol *param_var,
- const gl_state_index tokens[STATE_LENGTH])
+ const unsigned tokens[STATE_LENGTH])
{
int idx = -1;
gl_state_index state_tokens[STATE_LENGTH];
@@ -2477,7 +2480,7 @@ initialize_symbol_from_state(struct gl_program *prog,
const int last_row = state_tokens[3];
for (row = first_row; row <= last_row; row++) {
- state_tokens[2] = state_tokens[3] = row;
+ state_tokens[2] = state_tokens[3] = (gl_state_index) row;
idx = add_state_reference(prog->Parameters, state_tokens);
if (param_var->param_binding_begin == ~0U) {
@@ -2504,7 +2507,7 @@ initialize_symbol_from_state(struct gl_program *prog,
int
initialize_symbol_from_param(struct gl_program *prog,
struct asm_symbol *param_var,
- const gl_state_index tokens[STATE_LENGTH])
+ const unsigned tokens[STATE_LENGTH])
{
int idx = -1;
gl_state_index state_tokens[STATE_LENGTH];
@@ -2533,7 +2536,7 @@ initialize_symbol_from_param(struct gl_program *prog,
const int last_row = state_tokens[3];
for (row = first_row; row <= last_row; row++) {
- state_tokens[2] = state_tokens[3] = row;
+ state_tokens[2] = state_tokens[3] = (gl_state_index) row;
idx = add_state_reference(prog->Parameters, state_tokens);
if (param_var->param_binding_begin == ~0U) {
@@ -2609,7 +2612,7 @@ make_error_string(const char *fmt, ...)
length = 1 + vsnprintf(NULL, 0, fmt, args);
va_end(args);
- str = malloc(length);
+ str = (char *) malloc(length);
if (str) {
va_start(args, fmt);
vsnprintf(str, length, fmt, args);
@@ -2745,7 +2748,9 @@ _mesa_parse_arb_program(struct gl_context *ctx, GLenum target, const GLubyte *st
result = GL_TRUE;
error:
- for (inst = state->inst_head; inst != NULL; inst = temp) {
+ for (inst = state->inst_head;
+ inst != NULL;
+ inst = (struct asm_instruction *) temp) {
temp = inst->next;
free(inst);
}
@@ -2753,7 +2758,7 @@ error:
state->inst_head = NULL;
state->inst_tail = NULL;
- for (sym = state->sym; sym != NULL; sym = temp) {
+ for (sym = state->sym; sym != NULL; sym = (struct asm_symbol *) temp) {
temp = sym->next;
free((void *) sym->name);
diff --git a/src/mesa/program/program_parser.h b/src/mesa/program/program_parser.h
index d689eef7958..31871f3253c 100644
--- a/src/mesa/program/program_parser.h
+++ b/src/mesa/program/program_parser.h
@@ -23,6 +23,7 @@
#pragma once
#include "main/config.h"
+#include "main/mtypes.h"
struct gl_context;
@@ -45,7 +46,7 @@ struct asm_symbol {
/**
* One of PROGRAM_STATE_VAR, PROGRAM_LOCAL_PARAM, or PROGRAM_ENV_PARAM.
*/
- unsigned param_binding_type;
+ gl_register_file param_binding_type;
/**
* Offset into the program_parameter_list where the tokens representing our
@@ -127,6 +128,12 @@ struct asm_instruction {
};
+enum asm_program_target {
+ invalid_mode = 0,
+ ARB_vertex,
+ ARB_fragment
+};
+
struct asm_parser_state {
struct gl_context *ctx;
struct gl_program *prog;
@@ -191,11 +198,7 @@ struct asm_parser_state {
*/
unsigned InputsBound;
- enum {
- invalid_mode = 0,
- ARB_vertex,
- ARB_fragment
- } mode;
+ enum asm_program_target mode;
struct {
unsigned PositionInvariant:1;
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index 9b2cb1a3c14..7b2f812459b 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -244,7 +244,6 @@ PROGRAM_SOURCES = \
program/nvfragparse.c \
program/nvvertparse.c \
program/program.c \
- program/program_parse.tab.c \
program/program_parse_extra.c \
program/prog_cache.c \
program/prog_execute.c \
@@ -262,6 +261,7 @@ PROGRAM_SOURCES = \
SHADER_CXX_SOURCES = \
+ program/program_parse.cpp \
program/ir_to_mesa.cpp \
program/sampler.cpp