X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=gmqcc.h;h=df123c6c42713c733446ee21c1eb8c1773cf4409;hb=52b4c9f0c10267fbba0c81336de56265ed0c6f4d;hp=cc265053d9155a6d13532bf3bafc9ef4532decc1;hpb=e0a7f8a484868ce3c8d9898d5cfb7edc7956019b;p=xonotic%2Fgmqcc.git diff --git a/gmqcc.h b/gmqcc.h index cc26505..df123c6 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -263,6 +263,15 @@ void _util_vec_grow(void **a, size_t i, size_t s); #define vec_shrinkto(A,N) (_vec_end(A) = (N)) #define vec_shrinkby(A,N) (_vec_end(A) -= (N)) +#define vec_upload(X,Y,S) \ + do { \ + size_t E = 0; \ + while (E < S) { \ + vec_push(X, Y[E]); \ + E ++; \ + } \ + } while(0) + typedef struct hash_table_t { size_t size; struct hash_node_t **table; @@ -332,22 +341,24 @@ enum { #define CV_NONE 0 #define CV_CONST 1 #define CV_VAR -1 +/* magic number to help parsing */ +#define CV_WRONG 0x8000 -extern const char *type_name[TYPE_COUNT]; +extern const char *type_name [TYPE_COUNT]; +extern size_t type_sizeof [TYPE_COUNT]; +extern uint16_t type_store_instr [TYPE_COUNT]; +extern uint16_t field_store_instr[TYPE_COUNT]; -extern size_t type_sizeof[TYPE_COUNT]; -extern uint16_t type_store_instr[TYPE_COUNT]; -extern uint16_t field_store_instr[TYPE_COUNT]; -/* could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F +/* + * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F * but this breaks when TYPE_INTEGER is added, since with the enhanced * instruction set, the old ones are left untouched, thus the _I instructions * are at a seperate place. */ extern uint16_t type_storep_instr[TYPE_COUNT]; -/* other useful lists */ -extern uint16_t type_eq_instr[TYPE_COUNT]; -extern uint16_t type_ne_instr[TYPE_COUNT]; -extern uint16_t type_not_instr[TYPE_COUNT]; +extern uint16_t type_eq_instr [TYPE_COUNT]; +extern uint16_t type_ne_instr [TYPE_COUNT]; +extern uint16_t type_not_instr [TYPE_COUNT]; typedef struct { uint32_t offset; /* Offset in file of where data begins */ @@ -356,15 +367,15 @@ typedef struct { typedef struct { uint32_t version; /* Program version (6) */ - uint16_t crc16; /* What is this? */ - uint16_t skip; /* see propsal.txt */ + uint16_t crc16; + uint16_t skip; prog_section statements; /* prog_section_statement */ prog_section defs; /* prog_section_def */ prog_section fields; /* prog_section_field */ prog_section functions; /* prog_section_function */ - prog_section strings; /* What is this? */ - prog_section globals; /* What is this? */ + prog_section strings; + prog_section globals; uint32_t entfield; /* Number of entity fields */ } prog_header; @@ -414,7 +425,8 @@ typedef struct { } prog_section_statement; typedef struct { - /* The types: + /* + * The types: * 0 = ev_void * 1 = ev_string * 2 = ev_float @@ -429,6 +441,7 @@ typedef struct { uint16_t offset; uint32_t name; } prog_section_both; + typedef prog_section_both prog_section_def; typedef prog_section_both prog_section_field; @@ -560,6 +573,7 @@ qcint code_alloc_field (size_t qcsize); /* this function is used to keep statements and linenumbers together */ void code_push_statement(prog_section_statement *stmt, int linenum); +void code_pop_statement(); /* * A shallow copy of a lex_file to remember where which ast node @@ -570,7 +584,6 @@ typedef struct { size_t line; } lex_ctx; - /*===================================================================*/ /*============================ con.c ================================*/ /*===================================================================*/ @@ -592,28 +605,29 @@ enum { LVL_ERROR }; - void con_vprintmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap); void con_printmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, ...); void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap); void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...); -void con_close(); -void con_color(int state); -void con_init (); -void con_reset(); -int con_change(const char *out, const char *err); -int con_verr (const char *fmt, va_list va); -int con_vout (const char *fmt, va_list va); -int con_err (const char *fmt, ...); -int con_out (const char *fmt, ...); +void con_close (); +void con_init (); +void con_reset (); +void con_color (int); +int con_change(const char *, const char *); +int con_verr (const char *, va_list); +int con_vout (const char *, va_list); +int con_err (const char *, ...); +int con_out (const char *, ...); /* error/warning interface */ extern size_t compile_errors; extern size_t compile_warnings; -void compile_error(lex_ctx ctx, const char *msg, ...); -bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...); +void /********/ compile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, ...); +void /********/ vcompile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, va_list ap); +bool GMQCC_WARN compile_warning (lex_ctx ctx, int warntype, const char *fmt, ...); +bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap); /*===================================================================*/ /*========================= assembler.c =============================*/ @@ -717,7 +731,8 @@ vector vec3_mulvf(vector, float); /*============================= exec.c ==============================*/ /*===================================================================*/ -/* darkplaces has (or will have) a 64 bit prog loader +/* + * Darkplaces has (or will have) a 64 bit prog loader * where the 32 bit qc program is autoconverted on load. * Since we may want to support that as well, let's redefine * float and int here. @@ -833,6 +848,7 @@ void ftepp_finish (); const char *ftepp_get (); void ftepp_flush (); void ftepp_add_define (const char *source, const char *name); +void ftepp_add_macro (const char *name, const char *value); /*===================================================================*/ /*======================= main.c commandline ========================*/ @@ -852,14 +868,23 @@ typedef uint32_t longbit; #define LONGBIT(bit) (bit) #endif -/* Used to store the list of flags with names */ +/*===================================================================*/ +/*============================= opts.c ==============================*/ +/*===================================================================*/ typedef struct { const char *name; - longbit bit; + longbit bit; } opts_flag_def; -/*===================================================================*/ -/* list of -f flags, like -fdarkplaces-string-table-bug */ +bool opts_setflag (const char *, bool); +bool opts_setwarn (const char *, bool); +bool opts_setoptim(const char *, bool); + +void opts_init (const char *, int, size_t); +void opts_set (uint32_t *, size_t, bool); +void opts_setoptimlevel(unsigned int); +void opts_ini_init (const char *); + enum { # define GMQCC_TYPE_FLAGS # define GMQCC_DEFINE_FLAG(X) X, @@ -904,34 +929,41 @@ static const unsigned int opts_opt_oflag[] = { # include "opts.def" 0 }; -extern unsigned int optimization_count[COUNT_OPTIMIZATIONS]; +extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS]; /* other options: */ -enum { +typedef enum { COMPILER_QCC, /* circa QuakeC */ COMPILER_FTEQCC, /* fteqcc QuakeC */ COMPILER_QCCX, /* qccx QuakeC */ COMPILER_GMQCC /* this QuakeC */ -}; -extern uint32_t opts_O; /* -Ox */ -extern const char *opts_output; /* -o file */ -extern int opts_standard; -extern bool opts_debug; -extern bool opts_memchk; -extern bool opts_dumpfin; -extern bool opts_dump; -extern bool opts_werror; -extern bool opts_forcecrc; -extern uint16_t opts_forced_crc; -extern bool opts_pp_only; -extern size_t opts_max_array_size; +} opts_std_t; + +typedef struct { + uint32_t O; /* -Ox */ + const char *output; /* -o file */ + bool g; /* -g */ + opts_std_t standard; /* -std= */ + bool debug; /* -debug */ + bool memchk; /* -memchk */ + bool dumpfin; /* -dumpfin */ + bool dump; /* -dump */ + bool werror; /* -Werror */ + bool forcecrc; /* --force-crc= */ + uint16_t forced_crc; /* --force-crc= */ + bool pp_only; /* -E */ + size_t max_array_size; /* --max-array= */ + + uint32_t flags [1 + (COUNT_FLAGS / 32)]; + uint32_t warn [1 + (COUNT_WARNINGS / 32)]; + uint32_t optimization[1 + (COUNT_OPTIMIZATIONS / 32)]; +} opts_cmd_t; + +extern opts_cmd_t opts; /*===================================================================*/ -#define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; -#define OPTS_WARN(i) (!! (opts_warn[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opts_warn[1 + (COUNT_WARNINGS / 32)]; -#define OPTS_OPTIMIZATION(i) (!! (opts_optimization[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opts_optimization[1 + (COUNT_OPTIMIZATIONS / 32)]; +#define OPTS_FLAG(i) (!! (opts.flags [(i)/32] & (1<< ((i)%32)))) +#define OPTS_WARN(i) (!! (opts.warn [(i)/32] & (1<< ((i)%32)))) +#define OPTS_OPTIMIZATION(i) (!! (opts.optimization[(i)/32] & (1<< ((i)%32)))) #endif