#define GMQCC_IS_STDERR(X) ((X) == stderr)
#define GMQCC_IS_DEFINE(X) (GMQCC_IS_STDERR(X) || GMQCC_IS_STDOUT(X))
-typedef struct {
+struct con_t {
FILE *handle_err;
FILE *handle_out;
int color_err;
int color_out;
-} con_t;
+};
static con_t console;
"noexpr"
};
-typedef struct {
+struct qcvm_parameter {
int vtype;
const char *value;
-} qcvm_parameter;
+};
static qcvm_parameter *main_params = NULL;
*/
typedef uint32_t sfloat_t;
-typedef union {
+union sfloat_cast_t {
qcfloat_t f;
sfloat_t s;
-} sfloat_cast_t;
+};
/* Exception flags */
-typedef enum {
+enum sfloat_exceptionflags_t {
SFLOAT_NOEXCEPT = 0,
SFLOAT_INVALID = 1,
SFLOAT_DIVBYZERO = 4,
SFLOAT_OVERFLOW = 8,
SFLOAT_UNDERFLOW = 16,
SFLOAT_INEXACT = 32
-} sfloat_exceptionflags_t;
+};
/* Rounding modes */
typedef enum {
#define HT_MACROS 1024
-typedef struct {
+struct ppcondition {
bool on;
bool was_on;
bool had_else;
-} ppcondition;
+};
-typedef struct {
- int token;
+struct pptoken {
+ int token;
char *value;
/* a copy from the lexer */
union {
vec3_t v;
- int i;
+ int i;
double f;
- int t; /* type */
+ int t; /* type */
} constval;
-} pptoken;
+};
-typedef struct {
+struct ppmacro {
lex_ctx_t ctx;
-
- char *name;
- char **params;
+ char *name;
+ char **params;
/* yes we need an extra flag since `#define FOO x` is not the same as `#define FOO() x` */
- bool has_params;
- bool variadic;
-
+ bool has_params;
+ bool variadic;
pptoken **output;
-} ppmacro;
+};
-typedef struct ftepp_s {
- lex_file *lex;
- int token;
+struct ftepp_t {
+ lex_file *lex;
+ int token;
unsigned int errors;
-
- bool output_on;
+ bool output_on;
ppcondition *conditions;
- /*ppmacro **macros;*/
- ht macros; /* hashtable<string, ppmacro*> */
- char *output_string;
-
- char *itemname;
- char *includename;
- bool in_macro;
-
+ ht macros; /* hashtable<string, ppmacro*> */
+ char *output_string;
+ char *itemname;
+ char *includename;
+ bool in_macro;
uint32_t predef_countval;
uint32_t predef_randval;
-} ftepp_t;
+};
/* __DATE__ */
static char *ftepp_predef_date(ftepp_t *context) {
typedef int32_t qcint_t;
typedef uint32_t qcuint_t;
-typedef struct {
+struct code_t {
prog_section_statement_t *statements;
int *linenums;
int *columnnums;
uint32_t entfields;
ht string_cache;
qcint_t string_cached_empty;
-} code_t;
+};
/*
* A shallow copy of a lex_file to remember where which ast node
* came from.
*/
-typedef struct {
+struct lex_ctx_t {
const char *file;
size_t line;
size_t column;
-} lex_ctx_t;
+};
/*
* code_write -- writes out the compiled file
prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
-qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
+qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
/* parser.c */
-struct parser_s;
-struct parser_s *parser_create (void);
-bool parser_compile_file (struct parser_s *parser, const char *);
-bool parser_compile_string(struct parser_s *parser, const char *, const char *, size_t);
-bool parser_finish (struct parser_s *parser, const char *);
-void parser_cleanup (struct parser_s *parser);
+struct parser_t;
+parser_t *parser_create(void);
+bool parser_compile_file(parser_t *parser, const char *);
+bool parser_compile_string(parser_t *parser, const char *, const char *, size_t);
+bool parser_finish(parser_t *parser, const char *);
+void parser_cleanup(parser_t *parser);
/* ftepp.c */
-struct ftepp_s;
-struct ftepp_s *ftepp_create (void);
-bool ftepp_preprocess_file (struct ftepp_s *ftepp, const char *filename);
-bool ftepp_preprocess_string(struct ftepp_s *ftepp, const char *name, const char *str);
-void ftepp_finish (struct ftepp_s *ftepp);
-const char *ftepp_get (struct ftepp_s *ftepp);
-void ftepp_flush (struct ftepp_s *ftepp);
-void ftepp_add_define (struct ftepp_s *ftepp, const char *source, const char *name);
-void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, const char *value);
+struct ftepp_t;
+ftepp_t *ftepp_create (void);
+bool ftepp_preprocess_file (ftepp_t *ftepp, const char *filename);
+bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str);
+void ftepp_finish(ftepp_t *ftepp);
+const char *ftepp_get(ftepp_t *ftepp);
+void ftepp_flush(ftepp_t *ftepp);
+void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name);
+void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value);
/* main.c */
static bool ir_builder_set_name(ir_builder *self, const char *name);
-static ir_function* ir_function_new(struct ir_builder_s *owner, int returntype);
+static ir_function* ir_function_new(ir_builder *owner, int returntype);
static bool ir_function_set_name(ir_function*, const char *name);
static void ir_function_delete(ir_function*);
static void ir_function_dump(ir_function*, char *ind, int (*oprintf)(const char*,...));
static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t, const char *label,
int op, ir_value *a, ir_value *b, int outype);
static void ir_block_delete(ir_block*);
-static ir_block* ir_block_new(struct ir_function_s *owner, const char *label);
+static ir_block* ir_block_new(ir_function *owner, const char *label);
static bool GMQCC_WARN ir_block_create_store(ir_block*, lex_ctx_t, ir_value *target, ir_value *what);
static bool ir_block_set_label(ir_block*, const char *label);
static void ir_block_dump(ir_block*, char *ind, int (*oprintf)(const char*,...));
*/
typedef uint8_t ir_flag_t;
-typedef struct ir_value_s ir_value;
-typedef struct ir_instr_s ir_instr;
-typedef struct ir_block_s ir_block;
-typedef struct ir_function_s ir_function;
-typedef struct ir_builder_s ir_builder;
+struct ir_value;
+struct ir_instr;
+struct ir_block;
+struct ir_function;
+struct ir_builder;
typedef struct {
/* both inclusive */
IR_FLAG_MASK_NO_LOCAL_TEMPS = (IR_FLAG_HAS_ARRAYS | IR_FLAG_HAS_UNINITIALIZED)
};
-struct ir_value_s {
+struct ir_value {
char *name;
int vtype;
int store;
void ir_value_dump_life(const ir_value *self, int (*oprintf)(const char*,...));
/* PHI data */
-typedef struct ir_phi_entry_s {
+struct ir_phi_entry_t {
ir_value *value;
ir_block *from;
-} ir_phi_entry_t;
+};
/* instruction */
-struct ir_instr_s {
- int opcode;
- lex_ctx_t context;
- ir_value* (_ops[3]);
- ir_block* (bops[2]);
+struct ir_instr {
+ int opcode;
+ lex_ctx_t context;
+ ir_value *(_ops[3]);
+ ir_block *(bops[2]);
ir_phi_entry_t *phi;
- ir_value **params;
+ ir_value **params;
/* For the temp-allocation */
size_t eid;
/* For IFs */
- bool likely;
+ bool likely;
ir_block *owner;
};
/* block */
-struct ir_block_s {
+struct ir_block {
char *label;
lex_ctx_t context;
bool final; /* once a jump is added we're done */
bool GMQCC_WARN ir_block_create_goto(ir_block*, lex_ctx_t, ir_block *to);
/* function */
-struct ir_function_s {
+struct ir_function {
char *name;
int outtype;
int *params;
#define IR_HT_SIZE 1024
#define IR_MAX_VINSTR_TEMPS 1
-struct ir_builder_s {
+struct ir_builder {
char *name;
ir_function **functions;
ir_value **globals;
#define GMQCC_LEXER_HDR
#include "gmqcc.h"
-typedef struct token_s token;
-
-struct token_s {
+struct token {
int ttype;
-
char *value;
-
union {
- vec3_t v;
- int i;
+ vec3_t v;
+ int i;
qcfloat_t f;
- int t; /* type */
+ int t; /* type */
} constval;
-
lex_ctx_t ctx;
};
TOKEN_FATAL /* internal error, eg out of memory */
};
-typedef struct {
+struct frame_macro {
char *name;
- int value;
-} frame_macro;
+ int value;
+};
-typedef struct lex_file_s {
+struct lex_file {
FILE *file;
const char *open_string;
size_t open_string_length;
char *modelname;
size_t push_line;
-} lex_file;
+};
lex_file* lex_open (const char *file);
lex_file* lex_open_string(const char *str, size_t len, const char *name);
#define OP_SUFFIX 1
#define OP_PREFIX 2
-typedef struct {
+struct oper_info {
const char *op;
unsigned int operands;
unsigned int id;
signed int prec;
unsigned int flags;
bool folds;
-} oper_info;
+};
/*
* Explicit uint8_t casts since the left operand of shift operator cannot
bool operators_free = false;
bool progs_src = false;
FILE *outfile = NULL;
- struct parser_s *parser = NULL;
- struct ftepp_s *ftepp = NULL;
+ parser_t *parser = NULL;
+ ftepp_t *ftepp = NULL;
app_name = argv[0];
con_init ();
#include "lexer.h"
#include "ast.h"
-typedef struct intrin_s intrin_t;
-typedef struct parser_s parser_t;
-
-typedef struct {
- struct parser_s *parser;
- ast_value **imm_float; /* vector<ast_value*> */
- ast_value **imm_vector; /* vector<ast_value*> */
- ast_value **imm_string; /* vector<ast_value*> */
- hash_table_t *imm_string_untranslate; /* map<string, ast_value*> */
- hash_table_t *imm_string_dotranslate; /* map<string, ast_value*> */
-} fold_t;
-
-typedef struct {
+struct parser_t;
+struct intrin_t;
+
+struct fold_t {
+ parser_t *parser;
+ ast_value **imm_float; /* vector<ast_value*> */
+ ast_value **imm_vector; /* vector<ast_value*> */
+ ast_value **imm_string; /* vector<ast_value*> */
+ hash_table_t *imm_string_untranslate; /* map<string, ast_value*> */
+ hash_table_t *imm_string_dotranslate; /* map<string, ast_value*> */
+};
+
+struct intrin_func_t {
ast_expression *(*intrin)(intrin_t *);
- const char *name;
- const char *alias;
- size_t args;
-} intrin_func_t;
+ const char *name;
+ const char *alias;
+ size_t args;
+};
-struct intrin_s {
+struct intrin_t {
intrin_func_t *intrinsics; /* vector<intrin_func_t> */
ast_expression **generated; /* vector<ast_expression*> */
parser_t *parser;
#define parser_ctx(p) ((p)->lex->tok.ctx)
-struct parser_s {
+struct parser_t {
lex_file *lex;
int tok;