14 #define GMQCC_VERSION_MAJOR 0
15 #define GMQCC_VERSION_MINOR 3
16 #define GMQCC_VERSION_PATCH 6
17 #define GMQCC_VERSION ((GMQCC_VERSION_MAJOR<<16)|(GMQCC_VERSION_MINOR<<8)|GMQCC_VERSION_PATCH)
19 #ifdef GMQCC_VERSION_TYPE_RELEASE
21 # define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
22 # elif defined(GMQCC_VERSION_TYPE_DEVEL)
23 # define GMQCC_DEV_VERSION_STRING "development build\n"
25 # define GMQCC_DEV_VERSION_STRING
26 # endif /*! GMQCC_GITINGO */
28 # define GMQCC_DEV_VERSION_STRING
31 #define GMQCC_STRINGIFY(x) #x
32 #define GMQCC_IND_STRING(x) GMQCC_STRINGIFY(x)
33 #define GMQCC_FULL_VERSION_STRING \
35 GMQCC_IND_STRING(GMQCC_VERSION_MAJOR) "." \
36 GMQCC_IND_STRING(GMQCC_VERSION_MINOR) "." \
37 GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
38 " Built " __DATE__ " " __TIME__ \
39 "\n" GMQCC_DEV_VERSION_STRING
42 # define false (unsigned char)(0)
43 # define true (unsigned char)(1)
44 typedef unsigned char bool;
47 #if defined(__GNUC__) || defined(__CLANG__)
49 # if (__GNUC__ >= 2) || defined(__CLANG__)
50 # define GMQCC_NORETURN __attribute__((noreturn))
51 # define GMQCC_FORCEINLINE __attribute__((always_inline))
52 # define GMQCC_INLINE __inline
54 # define GMQCC_LIKELY(X) __builtin_expect((X), 1)
55 # define GMQCC_UNLIKELY(X) __builtin_expect((X), 0)
56 # define GMQCC_WARN __attribute__((warn_unused_result))
57 # define GMQCC_USED __attribute__((used))
58 # define GMQCC_RESTRICT __restrict__
61 /* conversion from 'int' to 'float', possible loss of data */
62 # pragma warning(disable : 4244)
64 typedef unsigned __int8 uint8_t;
65 typedef unsigned __int16 uint16_t;
66 typedef unsigned __int32 uint32_t;
67 typedef unsigned __int64 uint64_t;
68 typedef __int16 int16_t;
69 typedef __int32 int32_t;
70 typedef __int64 int64_t;
71 # define GMQCC_NORETURN __declspec(noreturn)
72 # define GMQCC_FORCEINLINE __forceinline
73 # define GMQCC_INLINE __inline
74 # define GMQCC_RESTRICT __restrict
76 # define GMQCC_NORETURN
77 # define GMQCC_FORCEINLINE
79 # define GMQCC_RESTRICT
81 # define GMQCC_LIKELY(X) (X)
82 # define GMQCC_UNLIKELY(X) (X)
87 #define GMQCC_BYTE_ORDER_LITTLE 1234
88 #define GMQCC_BYTE_ORDER_BIG 4321
90 #if defined (__GNUC__) || defined (__GNU_LIBRARY__)
91 # if defined (__FreeBSD__) || defined (__OpenBSD__)
92 # include <sys/endian.h>
93 # elif defined (BSD) && (BSD >= 199103) || defined (__DJGPP__) || defined (__CYGWIN32__)
94 # include <machine/endian.h>
95 # elif defined (__APPLE__)
96 # if defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN)
98 # elif defined (__LITTLE_ENDIAN__) && !defined (LITTLE_ENDIAN)
99 # define LITTLE_ENDIAN
100 # endif /*! defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN) */
101 # elif !defined (__MINGW32__)
103 # if !defined (__BEOS__)
104 # include <byteswap.h>
105 # endif /*! !definde (__BEOS__) */
106 # endif /*! defined (__FreeBSD__) || defined (__OpenBSD__) */
107 #endif /*! defined (__GNUC__) || defined (__GNU_LIBRARY__) */
108 #if !defined(PLATFORM_BYTE_ORDER)
109 # if defined (LITTLE_ENDIAN) || defined (BIG_ENDIAN)
110 # if defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
111 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
112 # elif !defined (LITTLE_ENDIAN) && defined (BIG_ENDIAN)
113 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
114 # elif defined (BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)
115 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
116 # elif defined (BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
117 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
118 # endif /*! defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN) */
119 # elif defined (_LITTLE_ENDIAN) || defined (_BIG_ENDIAN)
120 # if defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
121 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
122 # elif !defined (_LITTLE_ENDIAN) && defined (_BIG_ENDIAN)
123 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
124 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN)
125 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
126 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)
127 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
128 # endif /*! defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) */
129 # elif defined (__LITTLE_ENDIAN__) || defined (__BIG_ENDIAN__)
130 # if defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__)
131 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
132 # elif !defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
133 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
134 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__)
135 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
136 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)
137 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
138 # endif /*! defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__) */
139 # endif /*! defined(LITTLE_ENDIAN) || defined (BIG_ENDIAN) */
140 #endif /*! !defined(PLATFORM_BYTE_ORDER) */
141 #if !defined (PLATFORM_BYTE_ORDER)
142 # if defined (__alpha__) || defined (__alpha) || defined (i386) || \
143 defined (__i386__) || defined (_M_I86) || defined (_M_IX86) || \
144 defined (__OS2__) || defined (sun386) || defined (__TURBOC__) || \
145 defined (vax) || defined (vms) || defined (VMS) || \
146 defined (__VMS) || defined (__x86_64__) || defined (_M_IA64) || \
147 defined (_M_X64) || defined (__i386) || defined (__x86_64)
148 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
149 # elif defined (AMIGA) || defined (applec) || defined (__AS400__) || \
150 defined (_CRAY) || defined (__hppa) || defined (__hp9000) || \
151 defined (ibm370) || defined (mc68000) || defined (m68k) || \
152 defined (__MRC__) || defined (__MVS__) || defined (__MWERKS__) || \
153 defined (sparc) || defined (__sparc) || defined (SYMANTEC_C) || \
154 defined (__TANDEM) || defined (THINK_C) || defined (__VMCMS__) || \
155 defined (__PPC__) || defined (__PPC) || defined (PPC)
156 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
158 # define PLATFORM_BYTE_ORDER -1
162 #define GMQCC_ARRAY_COUNT(X) (sizeof(X) / sizeof((X)[0]))
165 char *stat_mem_strdup(const char *, bool);
167 #define mem_a(SIZE) malloc(SIZE)
168 #define mem_d(PTRN) free((void*)PTRN)
169 #define mem_r(PTRN, SIZE) realloc((void*)PTRN, SIZE)
171 #define util_strdup(SRC) stat_mem_strdup((char*)(SRC), false)
172 #define util_strdupe(SRC) stat_mem_strdup((char*)(SRC), true)
174 #define util_isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
175 #define util_isdigit(a) (((unsigned)(a)-'0') < 10)
176 #define util_islower(a) (((unsigned)(a)-'a') < 26)
177 #define util_isupper(a) (((unsigned)(a)-'A') < 26)
178 #define util_isprint(a) (((unsigned)(a)-0x20) < 0x5F)
179 #define util_isspace(a) (((a) >= 9 && (a) <= 13) || (a) == ' ')
181 bool util_strupper(const char *);
182 bool util_strdigit(const char *);
184 void util_endianswap(void *, size_t, unsigned int);
186 size_t util_strtocmd (const char *, char *, size_t);
187 size_t util_strtononcmd (const char *, char *, size_t);
188 size_t util_optimizationtostr(const char *, char *, size_t);
190 uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
192 void util_seed(uint32_t);
193 uint32_t util_rand(void);
195 int util_asprintf (char **ret, const char *fmt, ...);
196 int util_sscanf (const char *str, const char *format, ...);
197 char *util_strncpy (char *dest, const char *src, size_t n);
198 char *util_strncat (char *dest, const char *src, size_t n);
199 char *util_strcat (char *dest, const char *src);
200 const char *util_strerror(int err);
202 const struct tm *util_localtime(const time_t *timer);
203 const char *util_ctime (const time_t *timer);
205 bool util_isatty(FILE *);
206 size_t hash(const char *key);
209 * A flexible vector implementation: all vector pointers contain some
210 * data about themselfs exactly - sizeof(vector_t) behind the pointer
211 * this data is represented in the structure below. Doing this allows
212 * us to use the array [] to access individual elements from the vector
213 * opposed to using set/get methods.
219 /* can be extended now! whoot */
222 /* hidden interface */
223 void _util_vec_grow(void **a, size_t i, size_t s);
224 void _util_vec_delete(void *vec);
226 #define GMQCC_VEC_WILLGROW(X, Y) ( \
227 ((!(X) || vec_meta(X)->used + Y >= vec_meta(X)->allocated)) ? \
228 (void)_util_vec_grow(((void**)&(X)), (Y), sizeof(*(X))) : \
232 /* exposed interface */
233 #define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
234 #define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = nullptr) : 0))
235 #define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
236 #define vec_size(A) ((A) ? vec_meta(A)->used : 0)
237 #define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
238 #define vec_last(A) ((A)[vec_meta(A)->used - 1])
239 #define vec_pop(A) ((void)(vec_meta(A)->used -= 1))
240 #define vec_shrinkto(A,N) ((void)(vec_meta(A)->used = (N)))
241 #define vec_shrinkby(A,N) ((void)(vec_meta(A)->used -= (N)))
242 #define vec_append(A,N,S) ((void)(memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S)))))
243 #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)))
245 typedef struct hash_table_s {
247 struct hash_node_t **table;
250 hash_table_t *util_htnew (size_t size);
251 void util_htrem(hash_table_t *ht, void (*callback)(void *data));
252 void util_htset(hash_table_t *ht, const char *key, void *value);
253 void util_htdel(hash_table_t *ht);
254 size_t util_hthash(hash_table_t *ht, const char *key);
255 void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
256 void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
257 void util_htrm(hash_table_t *ht, const char *key, void (*cb)(void*));
258 void *util_htget(hash_table_t *ht, const char *key);
259 void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
260 int util_snprintf(char *str, size_t, const char *fmt, ...);
261 int util_getline(char **, size_t *, FILE *);
265 /* Note: if you change the order, fix type_sizeof in ir.c */
281 TYPE_NIL , /* it's its own type / untyped */
282 TYPE_NOEXPR , /* simply invalid in expressions */
287 /* const/var qualifiers */
291 #define CV_WRONG 0x8000 /* magic number to help parsing */
293 extern const char *type_name [TYPE_COUNT];
294 extern const uint16_t type_store_instr [TYPE_COUNT];
295 extern const uint16_t field_store_instr[TYPE_COUNT];
298 * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
299 * but this breaks when TYPE_INTEGER is added, since with the enhanced
300 * instruction set, the old ones are left untouched, thus the _I instructions
301 * are at a seperate place.
303 extern const uint16_t type_storep_instr[TYPE_COUNT];
304 extern const uint16_t type_eq_instr [TYPE_COUNT];
305 extern const uint16_t type_ne_instr [TYPE_COUNT];
306 extern const uint16_t type_not_instr [TYPE_COUNT];
308 struct prog_section_t {
309 uint32_t offset; /* Offset in file of where data begins */
310 uint32_t length; /* Length of section (how many of) */
313 struct prog_header_t {
314 uint32_t version; /* Program version (6) */
318 prog_section_t statements; /* prog_section_statement */
319 prog_section_t defs; /* prog_section_def */
320 prog_section_t fields; /* prog_section_field */
321 prog_section_t functions; /* prog_section_function */
322 prog_section_t strings;
323 prog_section_t globals;
324 uint32_t entfield; /* Number of entity fields */
328 * Each paramater incerements by 3 since vector types hold
329 * 3 components (x,y,z).
333 #define OFS_PARM0 (OFS_RETURN+3)
334 #define OFS_PARM1 (OFS_PARM0 +3)
335 #define OFS_PARM2 (OFS_PARM1 +3)
336 #define OFS_PARM3 (OFS_PARM2 +3)
337 #define OFS_PARM4 (OFS_PARM3 +3)
338 #define OFS_PARM5 (OFS_PARM4 +3)
339 #define OFS_PARM6 (OFS_PARM5 +3)
340 #define OFS_PARM7 (OFS_PARM6 +3)
347 struct prog_section_statement_t {
354 struct prog_section_both_t {
364 * 7 = ev_pointer -- engine only
365 * 8 = ev_bad -- engine only
372 typedef prog_section_both_t prog_section_def_t;
373 typedef prog_section_both_t prog_section_field_t;
375 /* this is ORed to the type */
376 #define DEF_SAVEGLOBAL (1<<15)
377 #define DEF_TYPEMASK ((1<<15)-1)
379 struct prog_section_function_t {
380 int32_t entry; /* in statement table for instructions */
381 uint32_t firstlocal; /* First local in local table */
382 uint32_t locals; /* Total ints of params + locals */
383 uint32_t profile; /* Always zero (engine uses this) */
384 uint32_t name; /* name of function in string table */
385 uint32_t file; /* file of the source file */
386 int32_t nargs; /* number of arguments */
387 uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
392 * These are the external instructions supported by the interperter
393 * this is what things compile to (from the C code).
399 INSTR_MUL_FV, /* NOTE: the float operands must NOT be at the same locations: A != C */
400 INSTR_MUL_VF, /* and here: B != C */
464 * Virtual instructions used by the IR
472 /* A never returning CALL.
473 * Creating this causes IR blocks to be marked as 'final'.
478 /* Emulated instructions. */
479 VINSTR_BITAND_V, /* BITAND_V must be the first emulated bitop */
492 extern const char *util_instr_str[VINSTR_END];
494 void util_swap_header(prog_header_t &code_header);
495 void util_swap_statements(std::vector<prog_section_statement_t> &statements);
496 void util_swap_defs_fields(std::vector<prog_section_both_t> §ion);
497 void util_swap_functions(std::vector<prog_section_function_t> &functions);
498 void util_swap_globals(std::vector<int32_t> &globals);
500 typedef float qcfloat_t;
501 typedef int32_t qcint_t;
502 typedef uint32_t qcuint_t;
505 std::vector<prog_section_statement_t> statements;
506 std::vector<int> linenums;
507 std::vector<int> columnnums;
508 std::vector<prog_section_def_t> defs;
509 std::vector<prog_section_field_t> fields;
510 std::vector<prog_section_function_t> functions;
511 std::vector<int> globals;
512 std::vector<char> chars;
516 qcint_t string_cached_empty;
520 * A shallow copy of a lex_file to remember where which ast node
530 * code_write -- writes out the compiled file
531 * code_init -- prepares the code file
532 * code_genstrin -- generates string for code
533 * code_alloc_field -- allocated a field
534 * code_push_statement -- keeps statements and linenumbers together
535 * code_pop_statement -- keeps statements and linenumbers together
537 bool code_write (code_t *, const char *filename, const char *lno);
539 code_t *code_init (void);
540 void code_cleanup (code_t *);
541 uint32_t code_genstring (code_t *, const char *string);
542 qcint_t code_alloc_field (code_t *, size_t qcsize);
543 void code_push_statement(code_t *, prog_section_statement_t *stmt, lex_ctx_t ctx);
544 void code_pop_statement (code_t *);
566 FILE *con_default_out(void);
567 FILE *con_default_err(void);
569 void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
570 void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...);
571 void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
572 void con_cprintmsg (lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...);
574 void con_close (void);
575 void con_init (void);
576 void con_reset (void);
577 void con_color (int);
578 int con_verr (const char *, va_list);
579 int con_vout (const char *, va_list);
580 int con_err (const char *, ...);
581 int con_out (const char *, ...);
583 /* error/warning interface */
584 extern size_t compile_errors;
585 extern size_t compile_Werrors;
586 extern size_t compile_warnings;
588 void /********/ compile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
589 void /********/ vcompile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
590 bool GMQCC_WARN compile_warning (lex_ctx_t ctx, int warntype, const char *fmt, ...);
591 bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
592 void compile_show_werrors(void);
598 store_local, /* local, assignable for now, should get promoted later */
599 store_param, /* parameters, they are locals with a fixed position */
600 store_value, /* unassignable */
601 store_return /* unassignable, at OFS_RETURN */
612 * Darkplaces has (or will have) a 64 bit prog loader
613 * where the 32 bit qc program is autoconverted on load.
614 * Since we may want to support that as well, let's redefine
615 * float and int here.
627 typedef char qcfloat_t_size_is_correct [sizeof(qcfloat_t) == 4 ?1:-1];
628 typedef char qcint_t_size_is_correct [sizeof(qcint_t) == 4 ?1:-1];
632 VMERR_TEMPSTRING_ALLOC,
636 #define VM_JUMPS_DEFAULT 1000000
639 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
640 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
641 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
644 typedef int (*prog_builtin_t)(qc_program_t *prog);
646 struct qc_exec_stack_t {
649 prog_section_function_t *function;
652 struct qc_program_t {
654 std::vector<prog_section_statement_t> code;
655 std::vector<prog_section_def_t> defs;
656 std::vector<prog_section_def_t> fields;
657 std::vector<prog_section_function_t> functions;
658 std::vector<char> strings;
659 std::vector<qcint_t> globals;
663 const char* *function_stack;
667 size_t tempstring_start;
668 size_t tempstring_at;
674 prog_builtin_t *builtins;
675 size_t builtins_count;
680 bool allowworldwrites;
683 qc_exec_stack_t *stack;
688 int argc; /* current arg count for debugging */
702 bool supports_state; /* is INSTR_STATE supported? */
705 qc_program_t* prog_load (const char *filename, bool ignoreversion);
706 void prog_delete (qc_program_t *prog);
707 bool prog_exec (qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps);
708 const char* prog_getstring (qc_program_t *prog, qcint_t str);
709 prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
710 prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
711 qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
712 qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
717 parser_t *parser_create(void);
718 bool parser_compile_file(parser_t *parser, const char *);
719 bool parser_compile_string(parser_t *parser, const char *, const char *, size_t);
720 bool parser_finish(parser_t *parser, const char *);
721 void parser_cleanup(parser_t *parser);
725 ftepp_t *ftepp_create (void);
726 bool ftepp_preprocess_file (ftepp_t *ftepp, const char *filename);
727 bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str);
728 void ftepp_finish(ftepp_t *ftepp);
729 const char *ftepp_get(ftepp_t *ftepp);
730 void ftepp_flush(ftepp_t *ftepp);
731 void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name);
732 void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value);
737 /* Helpers to allow for a whole lot of flags. Otherwise we'd limit
738 * to 32 or 64 -f options...
741 size_t idx; /* index into an array of 32 bit words */
742 uint8_t bit; /* bit index for the 8 bit group idx points to */
744 #define LONGBIT(bit) { ((bit)/32), ((bit)%32) }
745 #define LONGBIT_SET(B, I) ((B).idx = (I)/32, (B).bit = ((I)%32))
747 typedef uint32_t longbit;
748 #define LONGBIT(bit) (bit)
749 #define LONGBIT_SET(B, I) ((B) = (I))
753 typedef long utf8ch_t;
754 int utf8_from(char *, utf8ch_t);
755 int utf8_to(utf8ch_t *, const unsigned char *, size_t);
758 struct opts_flag_def_t {
763 bool opts_setflag (const char *, bool);
764 bool opts_setwarn (const char *, bool);
765 bool opts_setwerror(const char *, bool);
766 bool opts_setoptim (const char *, bool);
768 void opts_init (const char *, int, size_t);
769 void opts_set (uint32_t *, size_t, bool);
770 void opts_setoptimlevel(unsigned int);
771 void opts_ini_init (const char *);
773 /* Saner flag handling */
774 void opts_backup_non_Wall(void);
775 void opts_restore_non_Wall(void);
776 void opts_backup_non_Werror_all(void);
777 void opts_restore_non_Werror_all(void);
781 # define GMQCC_TYPE_FLAGS
782 # define GMQCC_DEFINE_FLAG(X) X,
788 # define GMQCC_TYPE_WARNS
789 # define GMQCC_DEFINE_FLAG(X) WARN_##X,
795 # define GMQCC_TYPE_OPTIMIZATIONS
796 # define GMQCC_DEFINE_FLAG(NAME, MIN_O) OPTIM_##NAME,
802 # define GMQCC_TYPE_OPTIONS
803 # define GMQCC_DEFINE_FLAG(X) OPTION_##X,
808 extern const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1];
809 extern const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1];
810 extern const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1];
811 extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
812 extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
816 COMPILER_QCC, /* circa QuakeC */
817 COMPILER_FTEQCC, /* fteqcc QuakeC */
818 COMPILER_QCCX, /* qccx QuakeC */
819 COMPILER_GMQCC /* this QuakeC */
836 opt_value_t options [OPTION_COUNT];
837 uint32_t flags [1 + (COUNT_FLAGS / 32)];
838 uint32_t warn [1 + (COUNT_WARNINGS / 32)];
839 uint32_t werror [1 + (COUNT_WARNINGS / 32)];
840 uint32_t warn_backup [1 + (COUNT_WARNINGS / 32)];
841 uint32_t werror_backup[1 + (COUNT_WARNINGS / 32)];
842 uint32_t optimization [1 + (COUNT_OPTIMIZATIONS / 32)];
843 bool optimizeoff; /* True when -O0 */
846 extern opts_cmd_t opts;
848 #define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1U << (unsigned)((i)%32))))
850 #define OPTS_FLAG(i) OPTS_GENERIC(opts.flags, (i))
851 #define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
852 #define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
853 #define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
855 #define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
856 #define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
857 #define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
858 #define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
859 #define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
860 #define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
862 #endif /*! GMQCC_HDR */