9 #define GMQCC_VERSION_MAJOR 0
10 #define GMQCC_VERSION_MINOR 3
11 #define GMQCC_VERSION_PATCH 6
12 #define GMQCC_VERSION ((GMQCC_VERSION_MAJOR<<16)|(GMQCC_VERSION_MINOR<<8)|GMQCC_VERSION_PATCH)
14 #ifdef GMQCC_VERSION_TYPE_RELEASE
16 # define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
17 # elif defined(GMQCC_VERSION_TYPE_DEVEL)
18 # define GMQCC_DEV_VERSION_STRING "development build\n"
20 # define GMQCC_DEV_VERSION_STRING
21 # endif /*! GMQCC_GITINGO */
23 # define GMQCC_DEV_VERSION_STRING
26 #define GMQCC_STRINGIFY(x) #x
27 #define GMQCC_IND_STRING(x) GMQCC_STRINGIFY(x)
28 #define GMQCC_FULL_VERSION_STRING \
30 GMQCC_IND_STRING(GMQCC_VERSION_MAJOR) "." \
31 GMQCC_IND_STRING(GMQCC_VERSION_MINOR) "." \
32 GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
33 " Built " __DATE__ " " __TIME__ \
34 "\n" GMQCC_DEV_VERSION_STRING
37 # define false (unsigned char)(0)
38 # define true (unsigned char)(1)
39 typedef unsigned char bool;
42 #if defined(__GNUC__) || defined(__CLANG__)
44 # if (__GNUC__ >= 2) || defined(__CLANG__)
45 # define GMQCC_NORETURN __attribute__((noreturn))
46 # define GMQCC_FORCEINLINE __attribute__((always_inline))
47 # define GMQCC_INLINE __inline
49 # define GMQCC_LIKELY(X) __builtin_expect((X), 1)
50 # define GMQCC_UNLIKELY(X) __builtin_expect((X), 0)
51 # define GMQCC_WARN __attribute__((warn_unused_result))
52 # define GMQCC_USED __attribute__((used))
53 # define GMQCC_RESTRICT __restrict__
56 /* conversion from 'int' to 'float', possible loss of data */
57 # pragma warning(disable : 4244)
59 typedef unsigned __int8 uint8_t;
60 typedef unsigned __int16 uint16_t;
61 typedef unsigned __int32 uint32_t;
62 typedef unsigned __int64 uint64_t;
63 typedef __int16 int16_t;
64 typedef __int32 int32_t;
65 typedef __int64 int64_t;
66 # define GMQCC_NORETURN __declspec(noreturn)
67 # define GMQCC_FORCEINLINE __forceinline
68 # define GMQCC_INLINE __inline
69 # define GMQCC_RESTRICT __restrict
71 # define GMQCC_NORETURN
72 # define GMQCC_FORCEINLINE
74 # define GMQCC_RESTRICT
76 # define GMQCC_LIKELY(X) (X)
77 # define GMQCC_UNLIKELY(X) (X)
82 #define GMQCC_BYTE_ORDER_LITTLE 1234
83 #define GMQCC_BYTE_ORDER_BIG 4321
85 #if defined (__GNUC__) || defined (__GNU_LIBRARY__)
86 # if defined (__FreeBSD__) || defined (__OpenBSD__)
87 # include <sys/endian.h>
88 # elif defined (BSD) && (BSD >= 199103) || defined (__DJGPP__) || defined (__CYGWIN32__)
89 # include <machine/endian.h>
90 # elif defined (__APPLE__)
91 # if defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN)
93 # elif defined (__LITTLE_ENDIAN__) && !defined (LITTLE_ENDIAN)
94 # define LITTLE_ENDIAN
95 # endif /*! defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN) */
96 # elif !defined (__MINGW32__)
98 # if !defined (__BEOS__)
99 # include <byteswap.h>
100 # endif /*! !definde (__BEOS__) */
101 # endif /*! defined (__FreeBSD__) || defined (__OpenBSD__) */
102 #endif /*! defined (__GNUC__) || defined (__GNU_LIBRARY__) */
103 #if !defined(PLATFORM_BYTE_ORDER)
104 # if defined (LITTLE_ENDIAN) || defined (BIG_ENDIAN)
105 # if defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
106 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
107 # elif !defined (LITTLE_ENDIAN) && defined (BIG_ENDIAN)
108 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
109 # elif defined (BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)
110 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
111 # elif defined (BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
112 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
113 # endif /*! defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN) */
114 # elif defined (_LITTLE_ENDIAN) || defined (_BIG_ENDIAN)
115 # if defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
116 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
117 # elif !defined (_LITTLE_ENDIAN) && defined (_BIG_ENDIAN)
118 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
119 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN)
120 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
121 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)
122 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
123 # endif /*! defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) */
124 # elif defined (__LITTLE_ENDIAN__) || defined (__BIG_ENDIAN__)
125 # if defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__)
126 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
127 # elif !defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
128 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
129 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__)
130 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
131 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)
132 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
133 # endif /*! defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__) */
134 # endif /*! defined(LITTLE_ENDIAN) || defined (BIG_ENDIAN) */
135 #endif /*! !defined(PLATFORM_BYTE_ORDER) */
136 #if !defined (PLATFORM_BYTE_ORDER)
137 # if defined (__alpha__) || defined (__alpha) || defined (i386) || \
138 defined (__i386__) || defined (_M_I86) || defined (_M_IX86) || \
139 defined (__OS2__) || defined (sun386) || defined (__TURBOC__) || \
140 defined (vax) || defined (vms) || defined (VMS) || \
141 defined (__VMS) || defined (__x86_64__) || defined (_M_IA64) || \
142 defined (_M_X64) || defined (__i386) || defined (__x86_64)
143 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
144 # elif defined (AMIGA) || defined (applec) || defined (__AS400__) || \
145 defined (_CRAY) || defined (__hppa) || defined (__hp9000) || \
146 defined (ibm370) || defined (mc68000) || defined (m68k) || \
147 defined (__MRC__) || defined (__MVS__) || defined (__MWERKS__) || \
148 defined (sparc) || defined (__sparc) || defined (SYMANTEC_C) || \
149 defined (__TANDEM) || defined (THINK_C) || defined (__VMCMS__) || \
150 defined (__PPC__) || defined (__PPC) || defined (PPC)
151 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
153 # define PLATFORM_BYTE_ORDER -1
157 #define GMQCC_ARRAY_COUNT(X) (sizeof(X) / sizeof((X)[0]))
160 char *stat_mem_strdup(const char *, bool);
162 #define mem_a(SIZE) malloc(SIZE)
163 #define mem_d(PTRN) free((void*)PTRN)
164 #define mem_r(PTRN, SIZE) realloc((void*)PTRN, SIZE)
166 #define util_strdup(SRC) stat_mem_strdup((char*)(SRC), false)
167 #define util_strdupe(SRC) stat_mem_strdup((char*)(SRC), true)
169 #define util_isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
170 #define util_isdigit(a) (((unsigned)(a)-'0') < 10)
171 #define util_islower(a) (((unsigned)(a)-'a') < 26)
172 #define util_isupper(a) (((unsigned)(a)-'A') < 26)
173 #define util_isprint(a) (((unsigned)(a)-0x20) < 0x5F)
174 #define util_isspace(a) (((a) >= 9 && (a) <= 13) || (a) == ' ')
176 bool util_strupper(const char *);
177 bool util_strdigit(const char *);
179 void util_endianswap(void *, size_t, unsigned int);
181 size_t util_strtocmd (const char *, char *, size_t);
182 size_t util_strtononcmd (const char *, char *, size_t);
183 size_t util_optimizationtostr(const char *, char *, size_t);
185 uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
187 void util_seed(uint32_t);
188 uint32_t util_rand(void);
190 int util_asprintf (char **ret, const char *fmt, ...);
191 int util_sscanf (const char *str, const char *format, ...);
192 char *util_strncpy (char *dest, const char *src, size_t n);
193 char *util_strncat (char *dest, const char *src, size_t n);
194 char *util_strcat (char *dest, const char *src);
195 const char *util_strerror(int err);
197 const struct tm *util_localtime(const time_t *timer);
198 const char *util_ctime (const time_t *timer);
200 bool util_isatty(FILE *);
201 size_t hash(const char *key);
204 * A flexible vector implementation: all vector pointers contain some
205 * data about themselfs exactly - sizeof(vector_t) behind the pointer
206 * this data is represented in the structure below. Doing this allows
207 * us to use the array [] to access individual elements from the vector
208 * opposed to using set/get methods.
214 /* can be extended now! whoot */
217 /* hidden interface */
218 void _util_vec_grow(void **a, size_t i, size_t s);
219 void _util_vec_delete(void *vec);
221 #define GMQCC_VEC_WILLGROW(X, Y) ( \
222 ((!(X) || vec_meta(X)->used + Y >= vec_meta(X)->allocated)) ? \
223 (void)_util_vec_grow(((void**)&(X)), (Y), sizeof(*(X))) : \
227 /* exposed interface */
228 #define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
229 #define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = NULL) : 0))
230 #define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
231 #define vec_size(A) ((A) ? vec_meta(A)->used : 0)
232 #define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
233 #define vec_last(A) ((A)[vec_meta(A)->used - 1])
234 #define vec_pop(A) ((void)(vec_meta(A)->used -= 1))
235 #define vec_shrinkto(A,N) ((void)(vec_meta(A)->used = (N)))
236 #define vec_shrinkby(A,N) ((void)(vec_meta(A)->used -= (N)))
237 #define vec_append(A,N,S) ((void)(memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S)))))
238 #define vec_remove(A,I,N) ((void)(memmove((A)+(I),(A)+((I)+(N)),sizeof(*(A))*(vec_meta(A)->used-(I)-(N))),vec_meta(A)->used-=(N)))
240 typedef struct hash_table_s {
242 struct hash_node_t **table;
245 hash_table_t *util_htnew (size_t size);
246 void util_htrem(hash_table_t *ht, void (*callback)(void *data));
247 void util_htset(hash_table_t *ht, const char *key, void *value);
248 void util_htdel(hash_table_t *ht);
249 size_t util_hthash(hash_table_t *ht, const char *key);
250 void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
251 void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
252 void util_htrm(hash_table_t *ht, const char *key, void (*cb)(void*));
253 void *util_htget(hash_table_t *ht, const char *key);
254 void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
255 int util_snprintf(char *str, size_t, const char *fmt, ...);
256 int util_getline(char **, size_t *, FILE *);
260 /* Note: if you change the order, fix type_sizeof in ir.c */
276 TYPE_NIL , /* it's its own type / untyped */
277 TYPE_NOEXPR , /* simply invalid in expressions */
282 /* const/var qualifiers */
286 #define CV_WRONG 0x8000 /* magic number to help parsing */
288 extern const char *type_name [TYPE_COUNT];
289 extern const uint16_t type_store_instr [TYPE_COUNT];
290 extern const uint16_t field_store_instr[TYPE_COUNT];
293 * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
294 * but this breaks when TYPE_INTEGER is added, since with the enhanced
295 * instruction set, the old ones are left untouched, thus the _I instructions
296 * are at a seperate place.
298 extern const uint16_t type_storep_instr[TYPE_COUNT];
299 extern const uint16_t type_eq_instr [TYPE_COUNT];
300 extern const uint16_t type_ne_instr [TYPE_COUNT];
301 extern const uint16_t type_not_instr [TYPE_COUNT];
303 struct prog_section_t {
304 uint32_t offset; /* Offset in file of where data begins */
305 uint32_t length; /* Length of section (how many of) */
308 struct prog_header_t {
309 uint32_t version; /* Program version (6) */
313 prog_section_t statements; /* prog_section_statement */
314 prog_section_t defs; /* prog_section_def */
315 prog_section_t fields; /* prog_section_field */
316 prog_section_t functions; /* prog_section_function */
317 prog_section_t strings;
318 prog_section_t globals;
319 uint32_t entfield; /* Number of entity fields */
323 * Each paramater incerements by 3 since vector types hold
324 * 3 components (x,y,z).
328 #define OFS_PARM0 (OFS_RETURN+3)
329 #define OFS_PARM1 (OFS_PARM0 +3)
330 #define OFS_PARM2 (OFS_PARM1 +3)
331 #define OFS_PARM3 (OFS_PARM2 +3)
332 #define OFS_PARM4 (OFS_PARM3 +3)
333 #define OFS_PARM5 (OFS_PARM4 +3)
334 #define OFS_PARM6 (OFS_PARM5 +3)
335 #define OFS_PARM7 (OFS_PARM6 +3)
342 struct prog_section_statement_t {
349 struct prog_section_both_t {
359 * 7 = ev_pointer -- engine only
360 * 8 = ev_bad -- engine only
367 typedef prog_section_both_t prog_section_def_t;
368 typedef prog_section_both_t prog_section_field_t;
370 /* this is ORed to the type */
371 #define DEF_SAVEGLOBAL (1<<15)
372 #define DEF_TYPEMASK ((1<<15)-1)
374 struct prog_section_function_t {
375 int32_t entry; /* in statement table for instructions */
376 uint32_t firstlocal; /* First local in local table */
377 uint32_t locals; /* Total ints of params + locals */
378 uint32_t profile; /* Always zero (engine uses this) */
379 uint32_t name; /* name of function in string table */
380 uint32_t file; /* file of the source file */
381 int32_t nargs; /* number of arguments */
382 uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
387 * These are the external instructions supported by the interperter
388 * this is what things compile to (from the C code).
394 INSTR_MUL_FV, /* NOTE: the float operands must NOT be at the same locations: A != C */
395 INSTR_MUL_VF, /* and here: B != C */
459 * Virtual instructions used by the IR
467 /* A never returning CALL.
468 * Creating this causes IR blocks to be marked as 'final'.
473 /* Emulated instructions. */
474 VINSTR_BITAND_V, /* BITAND_V must be the first emulated bitop */
487 extern const char *util_instr_str[VINSTR_END];
489 void util_swap_header (prog_header_t *code_header);
490 void util_swap_statements (prog_section_statement_t *statements);
491 void util_swap_defs_fields(prog_section_both_t *section);
492 void util_swap_functions (prog_section_function_t *functions);
493 void util_swap_globals (int32_t *globals);
495 typedef float qcfloat_t;
496 typedef int32_t qcint_t;
497 typedef uint32_t qcuint_t;
500 prog_section_statement_t *statements;
503 prog_section_def_t *defs;
504 prog_section_field_t *fields;
505 prog_section_function_t *functions;
511 qcint_t string_cached_empty;
515 * A shallow copy of a lex_file to remember where which ast node
525 * code_write -- writes out the compiled file
526 * code_init -- prepares the code file
527 * code_genstrin -- generates string for code
528 * code_alloc_field -- allocated a field
529 * code_push_statement -- keeps statements and linenumbers together
530 * code_pop_statement -- keeps statements and linenumbers together
532 bool code_write (code_t *, const char *filename, const char *lno);
534 code_t *code_init (void);
535 void code_cleanup (code_t *);
536 uint32_t code_genstring (code_t *, const char *string);
537 qcint_t code_alloc_field (code_t *, size_t qcsize);
538 void code_push_statement(code_t *, prog_section_statement_t *stmt, lex_ctx_t ctx);
539 void code_pop_statement (code_t *);
561 FILE *con_default_out(void);
562 FILE *con_default_err(void);
564 void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
565 void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...);
566 void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
567 void con_cprintmsg (lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...);
569 void con_close (void);
570 void con_init (void);
571 void con_reset (void);
572 void con_color (int);
573 int con_verr (const char *, va_list);
574 int con_vout (const char *, va_list);
575 int con_err (const char *, ...);
576 int con_out (const char *, ...);
578 /* error/warning interface */
579 extern size_t compile_errors;
580 extern size_t compile_Werrors;
581 extern size_t compile_warnings;
583 void /********/ compile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
584 void /********/ vcompile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
585 bool GMQCC_WARN compile_warning (lex_ctx_t ctx, int warntype, const char *fmt, ...);
586 bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
587 void compile_show_werrors(void);
593 store_local, /* local, assignable for now, should get promoted later */
594 store_param, /* parameters, they are locals with a fixed position */
595 store_value, /* unassignable */
596 store_return /* unassignable, at OFS_RETURN */
607 * Darkplaces has (or will have) a 64 bit prog loader
608 * where the 32 bit qc program is autoconverted on load.
609 * Since we may want to support that as well, let's redefine
610 * float and int here.
622 typedef char qcfloat_t_size_is_correct [sizeof(qcfloat_t) == 4 ?1:-1];
623 typedef char qcint_t_size_is_correct [sizeof(qcint_t) == 4 ?1:-1];
627 VMERR_TEMPSTRING_ALLOC,
631 #define VM_JUMPS_DEFAULT 1000000
634 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
635 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
636 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
639 typedef int (*prog_builtin_t)(qc_program_t *prog);
641 struct qc_exec_stack_t {
644 prog_section_function_t *function;
647 struct qc_program_t {
649 prog_section_statement_t *code;
650 prog_section_def_t *defs;
651 prog_section_def_t *fields;
652 prog_section_function_t *functions;
658 const char* *function_stack;
662 size_t tempstring_start;
663 size_t tempstring_at;
669 prog_builtin_t *builtins;
670 size_t builtins_count;
675 bool allowworldwrites;
678 qc_exec_stack_t *stack;
683 int argc; /* current arg count for debugging */
697 bool supports_state; /* is INSTR_STATE supported? */
700 qc_program_t* prog_load (const char *filename, bool ignoreversion);
701 void prog_delete (qc_program_t *prog);
702 bool prog_exec (qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps);
703 const char* prog_getstring (qc_program_t *prog, qcint_t str);
704 prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
705 prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
706 qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
707 qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
712 parser_t *parser_create(void);
713 bool parser_compile_file(parser_t *parser, const char *);
714 bool parser_compile_string(parser_t *parser, const char *, const char *, size_t);
715 bool parser_finish(parser_t *parser, const char *);
716 void parser_cleanup(parser_t *parser);
720 ftepp_t *ftepp_create (void);
721 bool ftepp_preprocess_file (ftepp_t *ftepp, const char *filename);
722 bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str);
723 void ftepp_finish(ftepp_t *ftepp);
724 const char *ftepp_get(ftepp_t *ftepp);
725 void ftepp_flush(ftepp_t *ftepp);
726 void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name);
727 void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value);
732 /* Helpers to allow for a whole lot of flags. Otherwise we'd limit
733 * to 32 or 64 -f options...
736 size_t idx; /* index into an array of 32 bit words */
737 uint8_t bit; /* bit index for the 8 bit group idx points to */
739 #define LONGBIT(bit) { ((bit)/32), ((bit)%32) }
740 #define LONGBIT_SET(B, I) ((B).idx = (I)/32, (B).bit = ((I)%32))
742 typedef uint32_t longbit;
743 #define LONGBIT(bit) (bit)
744 #define LONGBIT_SET(B, I) ((B) = (I))
748 typedef long utf8ch_t;
749 int utf8_from(char *, utf8ch_t);
750 int utf8_to(utf8ch_t *, const unsigned char *, size_t);
753 struct opts_flag_def_t {
758 bool opts_setflag (const char *, bool);
759 bool opts_setwarn (const char *, bool);
760 bool opts_setwerror(const char *, bool);
761 bool opts_setoptim (const char *, bool);
763 void opts_init (const char *, int, size_t);
764 void opts_set (uint32_t *, size_t, bool);
765 void opts_setoptimlevel(unsigned int);
766 void opts_ini_init (const char *);
768 /* Saner flag handling */
769 void opts_backup_non_Wall(void);
770 void opts_restore_non_Wall(void);
771 void opts_backup_non_Werror_all(void);
772 void opts_restore_non_Werror_all(void);
776 # define GMQCC_TYPE_FLAGS
777 # define GMQCC_DEFINE_FLAG(X) X,
783 # define GMQCC_TYPE_WARNS
784 # define GMQCC_DEFINE_FLAG(X) WARN_##X,
790 # define GMQCC_TYPE_OPTIMIZATIONS
791 # define GMQCC_DEFINE_FLAG(NAME, MIN_O) OPTIM_##NAME,
797 # define GMQCC_TYPE_OPTIONS
798 # define GMQCC_DEFINE_FLAG(X) OPTION_##X,
803 extern const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1];
804 extern const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1];
805 extern const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1];
806 extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
807 extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
811 COMPILER_QCC, /* circa QuakeC */
812 COMPILER_FTEQCC, /* fteqcc QuakeC */
813 COMPILER_QCCX, /* qccx QuakeC */
814 COMPILER_GMQCC /* this QuakeC */
831 opt_value_t options [OPTION_COUNT];
832 uint32_t flags [1 + (COUNT_FLAGS / 32)];
833 uint32_t warn [1 + (COUNT_WARNINGS / 32)];
834 uint32_t werror [1 + (COUNT_WARNINGS / 32)];
835 uint32_t warn_backup [1 + (COUNT_WARNINGS / 32)];
836 uint32_t werror_backup[1 + (COUNT_WARNINGS / 32)];
837 uint32_t optimization [1 + (COUNT_OPTIMIZATIONS / 32)];
838 bool optimizeoff; /* True when -O0 */
841 extern opts_cmd_t opts;
843 #define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1U << (unsigned)((i)%32))))
845 #define OPTS_FLAG(i) OPTS_GENERIC(opts.flags, (i))
846 #define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
847 #define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
848 #define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
850 #define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
851 #define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
852 #define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
853 #define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
854 #define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
855 #define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
857 #endif /*! GMQCC_HDR */