[qfcc] Create a parser file for GLSL

The syntax is not at all correct at this stage (really, just a copy of
Ruamoko), but the keyword table exists (in the wrong place) and the
additional basic types (bool, bvecN and (d)matNxM) have been added.
Boolean base type is currently just int, and matrices have 0 width while
I think about what to use, but finally some progress after several
months' hiatus.
This commit is contained in:
Bill Currie 2024-04-17 16:25:43 +09:00
parent 65bf3ab459
commit 56f0c3f821
7 changed files with 1888 additions and 2 deletions

View file

@ -19,6 +19,7 @@ EXTRA_DIST += \
tools/qfcc/include/grab.h \ tools/qfcc/include/grab.h \
tools/qfcc/include/idstuff.h \ tools/qfcc/include/idstuff.h \
tools/qfcc/include/linker.h \ tools/qfcc/include/linker.h \
tools/qfcc/include/mat_types.h \
tools/qfcc/include/method.h \ tools/qfcc/include/method.h \
tools/qfcc/include/obj_file.h \ tools/qfcc/include/obj_file.h \
tools/qfcc/include/obj_type.h \ tools/qfcc/include/obj_type.h \

View file

@ -0,0 +1,24 @@
#ifndef MAT_TYPE
#define MAT_TYPE(type_name, base_type, align_as)
#endif
MAT_TYPE(mat2x2, float, vec2)
MAT_TYPE(mat2x3, float, vec3)
MAT_TYPE(mat2x4, float, vec4)
MAT_TYPE(mat3x2, float, vec2)
MAT_TYPE(mat3x3, float, vec3)
MAT_TYPE(mat3x4, float, vec4)
MAT_TYPE(mat4x2, float, vec2)
MAT_TYPE(mat4x3, float, vec3)
MAT_TYPE(mat4x4, float, vec4)
MAT_TYPE(dmat2x2, double, dvec2)
MAT_TYPE(dmat2x3, double, dvec3)
MAT_TYPE(dmat2x4, double, dvec4)
MAT_TYPE(dmat3x2, double, dvec2)
MAT_TYPE(dmat3x3, double, dvec3)
MAT_TYPE(dmat3x4, double, dvec4)
MAT_TYPE(dmat4x2, double, dvec2)
MAT_TYPE(dmat4x3, double, dvec3)
MAT_TYPE(dmat4x4, double, dvec4)
#undef MAT_TYPE

View file

@ -98,6 +98,13 @@ typedef struct type_s {
#define VEC_TYPE(type_name, base_type) extern type_t type_##type_name; #define VEC_TYPE(type_name, base_type) extern type_t type_##type_name;
#include "tools/qfcc/include/vec_types.h" #include "tools/qfcc/include/vec_types.h"
#define MAT_TYPE(type_name, base_type, align_as) extern type_t type_##type_name;
#include "tools/qfcc/include/mat_types.h"
extern type_t type_bool;
extern type_t type_bvec2;
extern type_t type_bvec3;
extern type_t type_bvec4;
extern type_t type_auto; extern type_t type_auto;
extern type_t type_invalid; extern type_t type_invalid;
extern type_t type_floatfield; extern type_t type_floatfield;

View file

@ -39,6 +39,7 @@ qfcc_SOURCES = \
tools/qfcc/source/evaluate.c \ tools/qfcc/source/evaluate.c \
tools/qfcc/source/flow.c \ tools/qfcc/source/flow.c \
tools/qfcc/source/function.c \ tools/qfcc/source/function.c \
tools/qfcc/source/glsl-parse.y \
tools/qfcc/source/grab.c \ tools/qfcc/source/grab.c \
tools/qfcc/source/idstuff.c \ tools/qfcc/source/idstuff.c \
tools/qfcc/source/linker.c \ tools/qfcc/source/linker.c \
@ -82,6 +83,8 @@ qfprogs_LDADD= $(QFCC_LIBS)
qfprogs_DEPENDENCIES= $(QFCC_DEPS) qfprogs_DEPENDENCIES= $(QFCC_DEPS)
BUILT_SOURCES += \ BUILT_SOURCES += \
tools/qfcc/source/glsl-parse.c \
tools/qfcc/source/glsl-parse.h \
tools/qfcc/source/pre-parse.c \ tools/qfcc/source/pre-parse.c \
tools/qfcc/source/pre-parse.h \ tools/qfcc/source/pre-parse.h \
tools/qfcc/source/qc-parse.c \ tools/qfcc/source/qc-parse.c \
@ -91,6 +94,8 @@ BUILT_SOURCES += \
tools/qfcc/source/qp-parse.h \ tools/qfcc/source/qp-parse.h \
tools/qfcc/source/qp-lex.c tools/qfcc/source/qp-lex.c
tools/qfcc/source/glsl-parse.c: tools/qfcc/source/glsl-parse.y
$(AM_V_YACC)$(YACCCOMPILE) $< -o $@
tools/qfcc/source/pre-parse.c: tools/qfcc/source/pre-parse.y tools/qfcc/source/pre-parse.c: tools/qfcc/source/pre-parse.y
$(AM_V_YACC)$(YACCCOMPILE) $< -o $@ $(AM_V_YACC)$(YACCCOMPILE) $< -o $@
tools/qfcc/source/qc-parse.c: tools/qfcc/source/qc-parse.y tools/qfcc/source/qc-parse.c: tools/qfcc/source/qc-parse.y

File diff suppressed because it is too large Load diff

View file

@ -371,13 +371,13 @@ pp_vnumber '({s}*{m}?{pp_number}){2,4}{s}*'{ULFD}?
#define ARRCOUNT(_k) (sizeof (_k) / sizeof (_k[0])) #define ARRCOUNT(_k) (sizeof (_k) / sizeof (_k[0]))
typedef struct { typedef struct keyword_s {
const char *name; const char *name;
int value; int value;
specifier_t spec; specifier_t spec;
} keyword_t; } keyword_t;
typedef struct { typedef struct directive_s {
const char *name; const char *name;
int value; int value;
} directive_t; } directive_t;

View file

@ -95,11 +95,51 @@ type_t type_auto = {
}; };
#include "tools/qfcc/include/vec_types.h" #include "tools/qfcc/include/vec_types.h"
#define MAT_TYPE(type_name, base_type, align_as) \
type_t type_##type_name = { \
.type = ev_##base_type, \
.name = #type_name, \
.alignment = PR_ALIGNOF(align_as), \
.width = 0, /*FIXME what width? */ \
.meta = ty_basic, \
};
#include "tools/qfcc/include/mat_types.h"
#define VEC_TYPE(type_name, base_type) &type_##type_name, #define VEC_TYPE(type_name, base_type) &type_##type_name,
static type_t *vec_types[] = { static type_t *vec_types[] = {
#include "tools/qfcc/include/vec_types.h" #include "tools/qfcc/include/vec_types.h"
0 0
}; };
type_t type_bool = {
.type = ev_int, //FIXME create bool type?
.name = "bool",
.alignment = PR_ALIGNOF(int),
.width = PR_SIZEOF(int) / PR_SIZEOF (int),
.meta = ty_basic,
};
type_t type_bvec2 = {
.type = ev_int, //FIXME create bool type?
.name = "bvec2",
.alignment = PR_ALIGNOF(ivec2),
.width = PR_SIZEOF(ivec2) / PR_SIZEOF (int),
.meta = ty_basic,
};
type_t type_bvec3 = {
.type = ev_int, //FIXME create bool type?
.name = "bvec3",
.alignment = PR_ALIGNOF(ivec3),
.width = PR_SIZEOF(ivec3) / PR_SIZEOF (int),
.meta = ty_basic,
};
type_t type_bvec4 = {
.type = ev_int, //FIXME create bool type?
.name = "bvec4",
.alignment = PR_ALIGNOF(ivec4),
.width = PR_SIZEOF(ivec4) / PR_SIZEOF (int),
.meta = ty_basic,
};
type_t *type_nil; type_t *type_nil;
type_t *type_default; type_t *type_default;
type_t *type_long_int; type_t *type_long_int;