15 #define GMQCC_VERSION_MAJOR 0
16 #define GMQCC_VERSION_MINOR 3
17 #define GMQCC_VERSION_PATCH 6
18 #define GMQCC_VERSION ((GMQCC_VERSION_MAJOR<<16)|(GMQCC_VERSION_MINOR<<8)|GMQCC_VERSION_PATCH)
20 #ifdef GMQCC_VERSION_TYPE_RELEASE
22 # define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
23 # elif defined(GMQCC_VERSION_TYPE_DEVEL)
24 # define GMQCC_DEV_VERSION_STRING "development build\n"
26 # define GMQCC_DEV_VERSION_STRING
27 # endif /*! GMQCC_GITINGO */
29 # define GMQCC_DEV_VERSION_STRING
32 #define GMQCC_STRINGIFY(x) #x
33 #define GMQCC_IND_STRING(x) GMQCC_STRINGIFY(x)
34 #define GMQCC_FULL_VERSION_STRING \
36 GMQCC_IND_STRING(GMQCC_VERSION_MAJOR) "." \
37 GMQCC_IND_STRING(GMQCC_VERSION_MINOR) "." \
38 GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
39 " Built " __DATE__ " " __TIME__ \
40 "\n" GMQCC_DEV_VERSION_STRING
43 # define false (unsigned char)(0)
44 # define true (unsigned char)(1)
45 typedef unsigned char bool;
48 #if defined(__GNUC__) || defined(__CLANG__)
50 # if (__GNUC__ >= 2) || defined(__CLANG__)
51 # define GMQCC_NORETURN __attribute__((noreturn))
52 # define GMQCC_FORCEINLINE __attribute__((always_inline))
53 # define GMQCC_INLINE __inline
55 # define GMQCC_LIKELY(X) __builtin_expect((X), 1)
56 # define GMQCC_UNLIKELY(X) __builtin_expect((X), 0)
57 # define GMQCC_WARN __attribute__((warn_unused_result))
58 # define GMQCC_USED __attribute__((used))
59 # define GMQCC_RESTRICT __restrict__
62 /* conversion from 'int' to 'float', possible loss of data */
63 # pragma warning(disable : 4244)
65 typedef unsigned __int8 uint8_t;
66 typedef unsigned __int16 uint16_t;
67 typedef unsigned __int32 uint32_t;
68 typedef unsigned __int64 uint64_t;
69 typedef __int16 int16_t;
70 typedef __int32 int32_t;
71 typedef __int64 int64_t;
72 # define GMQCC_NORETURN __declspec(noreturn)
73 # define GMQCC_FORCEINLINE __forceinline
74 # define GMQCC_INLINE __inline
75 # define GMQCC_RESTRICT __restrict
77 # define GMQCC_NORETURN
78 # define GMQCC_FORCEINLINE
80 # define GMQCC_RESTRICT
82 # define GMQCC_LIKELY(X) (X)
83 # define GMQCC_UNLIKELY(X) (X)
88 #define GMQCC_BYTE_ORDER_LITTLE 1234
89 #define GMQCC_BYTE_ORDER_BIG 4321
91 #if defined (__GNUC__) || defined (__GNU_LIBRARY__)
92 # if defined (__FreeBSD__) || defined (__OpenBSD__)
93 # include <sys/endian.h>
94 # elif defined (BSD) && (BSD >= 199103) || defined (__DJGPP__) || defined (__CYGWIN32__)
95 # include <machine/endian.h>
96 # elif defined (__APPLE__)
97 # if defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN)
99 # elif defined (__LITTLE_ENDIAN__) && !defined (LITTLE_ENDIAN)
100 # define LITTLE_ENDIAN
101 # endif /*! defined (__BIG_ENDIAN__) && !defined(BIG_ENDIAN) */
102 # elif !defined (__MINGW32__)
104 # if !defined (__BEOS__)
105 # include <byteswap.h>
106 # endif /*! !definde (__BEOS__) */
107 # endif /*! defined (__FreeBSD__) || defined (__OpenBSD__) */
108 #endif /*! defined (__GNUC__) || defined (__GNU_LIBRARY__) */
109 #if !defined(PLATFORM_BYTE_ORDER)
110 # if defined (LITTLE_ENDIAN) || defined (BIG_ENDIAN)
111 # if defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
112 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
113 # elif !defined (LITTLE_ENDIAN) && defined (BIG_ENDIAN)
114 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
115 # elif defined (BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)
116 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
117 # elif defined (BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
118 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
119 # endif /*! defined (LITTLE_ENDIAN) && !defined(BIG_ENDIAN) */
120 # elif defined (_LITTLE_ENDIAN) || defined (_BIG_ENDIAN)
121 # if defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
122 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
123 # elif !defined (_LITTLE_ENDIAN) && defined (_BIG_ENDIAN)
124 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
125 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN)
126 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
127 # elif defined (_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)
128 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
129 # endif /*! defined (_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) */
130 # elif defined (__LITTLE_ENDIAN__) || defined (__BIG_ENDIAN__)
131 # if defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__)
132 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
133 # elif !defined (__LITTLE_ENDIAN__) && defined (__BIG_ENDIAN__)
134 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
135 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__)
136 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
137 # elif defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)
138 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
139 # endif /*! defined (__LITTLE_ENDIAN__) && !defined (__BIG_ENDIAN__) */
140 # endif /*! defined(LITTLE_ENDIAN) || defined (BIG_ENDIAN) */
141 #endif /*! !defined(PLATFORM_BYTE_ORDER) */
142 #if !defined (PLATFORM_BYTE_ORDER)
143 # if defined (__alpha__) || defined (__alpha) || defined (i386) || \
144 defined (__i386__) || defined (_M_I86) || defined (_M_IX86) || \
145 defined (__OS2__) || defined (sun386) || defined (__TURBOC__) || \
146 defined (vax) || defined (vms) || defined (VMS) || \
147 defined (__VMS) || defined (__x86_64__) || defined (_M_IA64) || \
148 defined (_M_X64) || defined (__i386) || defined (__x86_64)
149 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_LITTLE
150 # elif defined (AMIGA) || defined (applec) || defined (__AS400__) || \
151 defined (_CRAY) || defined (__hppa) || defined (__hp9000) || \
152 defined (ibm370) || defined (mc68000) || defined (m68k) || \
153 defined (__MRC__) || defined (__MVS__) || defined (__MWERKS__) || \
154 defined (sparc) || defined (__sparc) || defined (SYMANTEC_C) || \
155 defined (__TANDEM) || defined (THINK_C) || defined (__VMCMS__) || \
156 defined (__PPC__) || defined (__PPC) || defined (PPC)
157 # define PLATFORM_BYTE_ORDER GMQCC_BYTE_ORDER_BIG
159 # define PLATFORM_BYTE_ORDER -1
163 #define GMQCC_ARRAY_COUNT(X) (sizeof(X) / sizeof((X)[0]))
166 char *stat_mem_strdup(const char *, bool);
168 #define mem_a(SIZE) malloc(SIZE)
169 #define mem_d(PTRN) free((void*)PTRN)
170 #define mem_r(PTRN, SIZE) realloc((void*)PTRN, SIZE)
172 #define util_strdup(SRC) stat_mem_strdup((char*)(SRC), false)
173 #define util_strdupe(SRC) stat_mem_strdup((char*)(SRC), true)
175 #define util_isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
176 #define util_isdigit(a) (((unsigned)(a)-'0') < 10)
177 #define util_islower(a) (((unsigned)(a)-'a') < 26)
178 #define util_isupper(a) (((unsigned)(a)-'A') < 26)
179 #define util_isprint(a) (((unsigned)(a)-0x20) < 0x5F)
180 #define util_isspace(a) (((a) >= 9 && (a) <= 13) || (a) == ' ')
182 bool util_strupper(const char *);
183 bool util_strdigit(const char *);
185 void util_endianswap(void *, size_t, unsigned int);
187 size_t util_strtocmd (const char *, char *, size_t);
188 size_t util_strtononcmd (const char *, char *, size_t);
189 size_t util_optimizationtostr(const char *, char *, size_t);
191 uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
193 void util_seed(uint32_t);
194 uint32_t util_rand(void);
196 int util_asprintf (char **ret, const char *fmt, ...);
197 int util_sscanf (const char *str, const char *format, ...);
198 char *util_strncpy (char *dest, const char *src, size_t n);
199 char *util_strncat (char *dest, const char *src, size_t n);
200 char *util_strcat (char *dest, const char *src);
201 const char *util_strerror(int err);
203 const struct tm *util_localtime(const time_t *timer);
204 const char *util_ctime (const time_t *timer);
206 bool util_isatty(FILE *);
207 size_t hash(const char *key);
210 * A flexible vector implementation: all vector pointers contain some
211 * data about themselfs exactly - sizeof(vector_t) behind the pointer
212 * this data is represented in the structure below. Doing this allows
213 * us to use the array [] to access individual elements from the vector
214 * opposed to using set/get methods.
220 /* can be extended now! whoot */
223 /* hidden interface */
224 void _util_vec_grow(void **a, size_t i, size_t s);
225 void _util_vec_delete(void *vec);
227 #define GMQCC_VEC_WILLGROW(X, Y) ( \
228 ((!(X) || vec_meta(X)->used + Y >= vec_meta(X)->allocated)) ? \
229 (void)_util_vec_grow(((void**)&(X)), (Y), sizeof(*(X))) : \
233 /* exposed interface */
234 #define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
235 #define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = nullptr) : 0))
236 #define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
237 #define vec_size(A) ((A) ? vec_meta(A)->used : 0)
238 #define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
239 #define vec_last(A) ((A)[vec_meta(A)->used - 1])
240 #define vec_pop(A) ((void)(vec_meta(A)->used -= 1))
241 #define vec_shrinkto(A,N) ((void)(vec_meta(A)->used = (N)))
242 #define vec_shrinkby(A,N) ((void)(vec_meta(A)->used -= (N)))
243 #define vec_append(A,N,S) ((void)(memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S)))))
244 #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)))
246 typedef struct hash_table_s {
248 struct hash_node_t **table;
251 hash_table_t *util_htnew (size_t size);
252 void util_htrem(hash_table_t *ht, void (*callback)(void *data));
253 void util_htset(hash_table_t *ht, const char *key, void *value);
254 void util_htdel(hash_table_t *ht);
255 size_t util_hthash(hash_table_t *ht, const char *key);
256 void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
257 void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
258 void util_htrm(hash_table_t *ht, const char *key, void (*cb)(void*));
259 void *util_htget(hash_table_t *ht, const char *key);
260 void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
261 int util_snprintf(char *str, size_t, const char *fmt, ...);
262 int util_getline(char **, size_t *, FILE *);
266 /* Note: if you change the order, fix type_sizeof in ir.c */
282 TYPE_NIL , /* it's its own type / untyped */
283 TYPE_NOEXPR , /* simply invalid in expressions */
288 /* const/var qualifiers */
292 #define CV_WRONG 0x8000 /* magic number to help parsing */
294 extern const char *type_name [TYPE_COUNT];
295 extern const uint16_t type_store_instr [TYPE_COUNT];
296 extern const uint16_t field_store_instr[TYPE_COUNT];
299 * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
300 * but this breaks when TYPE_INTEGER is added, since with the enhanced
301 * instruction set, the old ones are left untouched, thus the _I instructions
302 * are at a seperate place.
304 extern const uint16_t type_storep_instr[TYPE_COUNT];
305 extern const uint16_t type_eq_instr [TYPE_COUNT];
306 extern const uint16_t type_ne_instr [TYPE_COUNT];
307 extern const uint16_t type_not_instr [TYPE_COUNT];
309 struct prog_section_t {
310 uint32_t offset; /* Offset in file of where data begins */
311 uint32_t length; /* Length of section (how many of) */
314 struct prog_header_t {
315 uint32_t version; /* Program version (6) */
319 prog_section_t statements; /* prog_section_statement */
320 prog_section_t defs; /* prog_section_def */
321 prog_section_t fields; /* prog_section_field */
322 prog_section_t functions; /* prog_section_function */
323 prog_section_t strings;
324 prog_section_t globals;
325 uint32_t entfield; /* Number of entity fields */
329 * Each paramater incerements by 3 since vector types hold
330 * 3 components (x,y,z).
334 #define OFS_PARM0 (OFS_RETURN+3)
335 #define OFS_PARM1 (OFS_PARM0 +3)
336 #define OFS_PARM2 (OFS_PARM1 +3)
337 #define OFS_PARM3 (OFS_PARM2 +3)
338 #define OFS_PARM4 (OFS_PARM3 +3)
339 #define OFS_PARM5 (OFS_PARM4 +3)
340 #define OFS_PARM6 (OFS_PARM5 +3)
341 #define OFS_PARM7 (OFS_PARM6 +3)
348 struct prog_section_statement_t {
355 struct prog_section_both_t {
365 * 7 = ev_pointer -- engine only
366 * 8 = ev_bad -- engine only
373 typedef prog_section_both_t prog_section_def_t;
374 typedef prog_section_both_t prog_section_field_t;
376 /* this is ORed to the type */
377 #define DEF_SAVEGLOBAL (1<<15)
378 #define DEF_TYPEMASK ((1<<15)-1)
380 struct prog_section_function_t {
381 int32_t entry; /* in statement table for instructions */
382 uint32_t firstlocal; /* First local in local table */
383 uint32_t locals; /* Total ints of params + locals */
384 uint32_t profile; /* Always zero (engine uses this) */
385 uint32_t name; /* name of function in string table */
386 uint32_t file; /* file of the source file */
387 int32_t nargs; /* number of arguments */
388 uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
393 * These are the external instructions supported by the interperter
394 * this is what things compile to (from the C code).
400 INSTR_MUL_FV, /* NOTE: the float operands must NOT be at the same locations: A != C */
401 INSTR_MUL_VF, /* and here: B != C */
465 * Virtual instructions used by the IR
473 /* A never returning CALL.
474 * Creating this causes IR blocks to be marked as 'final'.
479 /* Emulated instructions. */
480 VINSTR_BITAND_V, /* BITAND_V must be the first emulated bitop */
493 extern const char *util_instr_str[VINSTR_END];
495 void util_swap_header(prog_header_t &code_header);
496 void util_swap_statements(std::vector<prog_section_statement_t> &statements);
497 void util_swap_defs_fields(std::vector<prog_section_both_t> §ion);
498 void util_swap_functions(std::vector<prog_section_function_t> &functions);
499 void util_swap_globals(std::vector<int32_t> &globals);
501 typedef float qcfloat_t;
502 typedef int32_t qcint_t;
503 typedef uint32_t qcuint_t;
506 void* operator new(std::size_t);
507 void operator delete(void*);
510 std::vector<prog_section_statement_t> statements;
511 std::vector<int> linenums;
512 std::vector<int> columnnums;
513 std::vector<prog_section_def_t> defs;
514 std::vector<prog_section_field_t> fields;
515 std::vector<prog_section_function_t> functions;
516 std::vector<int> globals;
517 std::vector<char> chars;
519 uint32_t entfields = 0;
521 qcint_t string_cached_empty = 0;
525 * A shallow copy of a lex_file to remember where which ast node
535 * code_write -- writes out the compiled file
536 * code_init -- prepares the code file
537 * code_genstrin -- generates string for code
538 * code_alloc_field -- allocated a field
539 * code_push_statement -- keeps statements and linenumbers together
540 * code_pop_statement -- keeps statements and linenumbers together
542 bool code_write (code_t *, const char *filename, const char *lno);
544 code_t *code_init (void);
545 void code_cleanup (code_t *);
546 uint32_t code_genstring (code_t *, const char *string);
547 qcint_t code_alloc_field (code_t *, size_t qcsize);
548 void code_push_statement(code_t *, prog_section_statement_t *stmt, lex_ctx_t ctx);
549 void code_pop_statement (code_t *);
571 FILE *con_default_out(void);
572 FILE *con_default_err(void);
574 void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
575 void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...);
576 void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
577 void con_cprintmsg (lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...);
579 void con_close (void);
580 void con_init (void);
581 void con_reset (void);
582 void con_color (int);
583 int con_verr (const char *, va_list);
584 int con_vout (const char *, va_list);
585 int con_err (const char *, ...);
586 int con_out (const char *, ...);
588 /* error/warning interface */
589 extern size_t compile_errors;
590 extern size_t compile_Werrors;
591 extern size_t compile_warnings;
593 void /********/ compile_error_ (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
594 void /********/ vcompile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
595 bool GMQCC_WARN compile_warning_(lex_ctx_t ctx, int warntype, const char *fmt, ...);
596 bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
597 void compile_show_werrors(void);
599 template <typename T>
600 inline constexpr const T formatNormalize(const T argument) { return argument; }
602 inline const char *formatNormalize(const std::string &argument) {
603 return argument.c_str();
606 template<typename... Ts>
607 inline bool GMQCC_WARN compile_warning(lex_ctx_t ctx, int warntype, const char *fmt, const Ts&... ts) {
608 return compile_warning_(ctx, warntype, fmt, formatNormalize(ts)...);
610 template<typename... Ts>
611 inline void /********/ compile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, const Ts&... ts) {
612 return compile_error_(ctx, msg, formatNormalize(ts)...);
619 store_local, /* local, assignable for now, should get promoted later */
620 store_param, /* parameters, they are locals with a fixed position */
621 store_value, /* unassignable */
622 store_return /* unassignable, at OFS_RETURN */
633 * Darkplaces has (or will have) a 64 bit prog loader
634 * where the 32 bit qc program is autoconverted on load.
635 * Since we may want to support that as well, let's redefine
636 * float and int here.
648 typedef char qcfloat_t_size_is_correct [sizeof(qcfloat_t) == 4 ?1:-1];
649 typedef char qcint_t_size_is_correct [sizeof(qcint_t) == 4 ?1:-1];
653 VMERR_TEMPSTRING_ALLOC,
657 #define VM_JUMPS_DEFAULT 1000000
660 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
661 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
662 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
664 typedef struct qc_program qc_program_t;
665 typedef int (*prog_builtin_t)(qc_program_t *prog);
667 struct qc_exec_stack_t {
670 prog_section_function_t *function;
674 qc_program() = delete;
675 qc_program(const char *name, uint16_t crc, size_t entfields);
677 std::string filename;
678 std::vector<prog_section_statement_t> code;
679 std::vector<prog_section_def_t> defs;
680 std::vector<prog_section_def_t> fields;
681 std::vector<prog_section_function_t> functions;
682 std::vector<char> strings;
683 std::vector<qcint_t> globals;
684 std::vector<qcint_t> entitydata;
685 std::vector<bool> entitypool;
687 std::vector<const char*> function_stack;
691 size_t tempstring_start;
692 size_t tempstring_at;
696 std::vector<size_t> profile;
698 prog_builtin_t *builtins;
699 size_t builtins_count;
704 bool allowworldwrites;
706 std::vector<qcint_t> localstack;
707 std::vector<qc_exec_stack_t> stack;
712 int argc; /* current arg count for debugging */
726 bool supports_state; /* is INSTR_STATE supported? */
729 qc_program_t* prog_load (const char *filename, bool ignoreversion);
730 void prog_delete (qc_program_t *prog);
731 bool prog_exec (qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps);
732 const char* prog_getstring (qc_program_t *prog, qcint_t str);
733 prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
734 prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
735 qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
736 qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
741 parser_t *parser_create(void);
742 bool parser_compile_file(parser_t *parser, const char *);
743 bool parser_compile_string(parser_t *parser, const char *, const char *, size_t);
744 bool parser_finish(parser_t *parser, const char *);
748 ftepp_t *ftepp_create (void);
749 bool ftepp_preprocess_file (ftepp_t *ftepp, const char *filename);
750 bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str);
751 void ftepp_finish(ftepp_t *ftepp);
752 const char *ftepp_get(ftepp_t *ftepp);
753 void ftepp_flush(ftepp_t *ftepp);
754 void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name);
755 void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value);
760 /* Helpers to allow for a whole lot of flags. Otherwise we'd limit
761 * to 32 or 64 -f options...
764 size_t idx; /* index into an array of 32 bit words */
765 uint8_t bit; /* bit index for the 8 bit group idx points to */
767 #define LONGBIT(bit) { ((bit)/32), ((bit)%32) }
768 #define LONGBIT_SET(B, I) ((B).idx = (I)/32, (B).bit = ((I)%32))
770 typedef uint32_t longbit;
771 #define LONGBIT(bit) (bit)
772 #define LONGBIT_SET(B, I) ((B) = (I))
776 typedef long utf8ch_t;
777 int utf8_from(char *, utf8ch_t);
778 int utf8_to(utf8ch_t *, const unsigned char *, size_t);
781 struct opts_flag_def_t {
786 bool opts_setflag (const char *, bool);
787 bool opts_setwarn (const char *, bool);
788 bool opts_setwerror(const char *, bool);
789 bool opts_setoptim (const char *, bool);
791 void opts_init (const char *, int, size_t);
792 void opts_set (uint32_t *, size_t, bool);
793 void opts_setoptimlevel(unsigned int);
794 void opts_ini_init (const char *);
796 /* Saner flag handling */
797 void opts_backup_non_Wall(void);
798 void opts_restore_non_Wall(void);
799 void opts_backup_non_Werror_all(void);
800 void opts_restore_non_Werror_all(void);
804 # define GMQCC_TYPE_FLAGS
805 # define GMQCC_DEFINE_FLAG(X) X,
811 # define GMQCC_TYPE_WARNS
812 # define GMQCC_DEFINE_FLAG(X) WARN_##X,
818 # define GMQCC_TYPE_OPTIMIZATIONS
819 # define GMQCC_DEFINE_FLAG(NAME, MIN_O) OPTIM_##NAME,
825 # define GMQCC_TYPE_OPTIONS
826 # define GMQCC_DEFINE_FLAG(X) OPTION_##X,
831 extern const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1];
832 extern const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1];
833 extern const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1];
834 extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
835 extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
839 COMPILER_QCC, /* circa QuakeC */
840 COMPILER_FTEQCC, /* fteqcc QuakeC */
841 COMPILER_QCCX, /* qccx QuakeC */
842 COMPILER_GMQCC /* this QuakeC */
859 opt_value_t options [OPTION_COUNT];
860 uint32_t flags [1 + (COUNT_FLAGS / 32)];
861 uint32_t warn [1 + (COUNT_WARNINGS / 32)];
862 uint32_t werror [1 + (COUNT_WARNINGS / 32)];
863 uint32_t warn_backup [1 + (COUNT_WARNINGS / 32)];
864 uint32_t werror_backup[1 + (COUNT_WARNINGS / 32)];
865 uint32_t optimization [1 + (COUNT_OPTIMIZATIONS / 32)];
866 bool optimizeoff; /* True when -O0 */
869 extern opts_cmd_t opts;
871 #define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1U << (unsigned)((i)%32))))
873 #define OPTS_FLAG(i) OPTS_GENERIC(opts.flags, (i))
874 #define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
875 #define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
876 #define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
878 #define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
879 #define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
880 #define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
881 #define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
882 #define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
883 #define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
885 #endif /*! GMQCC_HDR */