Skip to content
Snippets Groups Projects
Commit 9c0b233c authored by Ian Romanick's avatar Ian Romanick
Browse files

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.
parent 364aa728
No related branches found
No related tags found
No related merge requests found
......@@ -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=$@ $<
......
......@@ -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);
......
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment