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 /* TODO: rename to mem variations */
167 #define util_strdup(SRC) stat_mem_strdup((char*)(SRC), false)
168 #define util_strdupe(SRC) stat_mem_strdup((char*)(SRC), true)
173 * Microsoft implements against the spec versions of ctype.h. Which
174 * means what ever the current set locale is will render the actual
175 * results of say isalpha('A') wrong for what ever retarded locale
176 * is used. Simalerly these are also implemented inefficently on
177 * some toolchains and end up becoming actual library calls. Perhaps
178 * this is why tools like yacc provide their own? Regardless implementing
179 * these as functions is equally as silly, the call overhead is not
180 * justified when this could happen on every character from an input
181 * stream. We provide our own as macros for absolute inlinability.
183 #define util_isalpha(a) ((((unsigned)(a)|32)-'a') < 26)
184 #define util_isdigit(a) (((unsigned)(a)-'0') < 10)
185 #define util_islower(a) (((unsigned)(a)-'a') < 26)
186 #define util_isupper(a) (((unsigned)(a)-'A') < 26)
187 #define util_isprint(a) (((unsigned)(a)-0x20) < 0x5F)
188 #define util_isspace(a) (((a) >= 9 && (a) <= 13) || (a) == ' ')
190 bool util_strupper(const char *);
191 bool util_strdigit(const char *);
193 void util_endianswap(void *, size_t, unsigned int);
195 size_t util_strtocmd (const char *, char *, size_t);
196 size_t util_strtononcmd (const char *, char *, size_t);
197 size_t util_optimizationtostr(const char *, char *, size_t);
199 uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
201 void util_seed(uint32_t);
202 uint32_t util_rand(void);
204 int util_asprintf (char **ret, const char *fmt, ...);
205 int util_sscanf (const char *str, const char *format, ...);
206 char *util_strncpy (char *dest, const char *src, size_t n);
207 char *util_strncat (char *dest, const char *src, size_t n);
208 char *util_strcat (char *dest, const char *src);
209 const char *util_strerror(int err);
211 const struct tm *util_localtime(const time_t *timer);
212 const char *util_ctime (const time_t *timer);
214 bool util_isatty(FILE *);
215 size_t hash(const char *key);
218 * A flexible vector implementation: all vector pointers contain some
219 * data about themselfs exactly - sizeof(vector_t) behind the pointer
220 * this data is represented in the structure below. Doing this allows
221 * us to use the array [] to access individual elements from the vector
222 * opposed to using set/get methods.
228 /* can be extended now! whoot */
231 /* hidden interface */
232 void _util_vec_grow(void **a, size_t i, size_t s);
233 void _util_vec_delete(void *vec);
235 #define GMQCC_VEC_WILLGROW(X, Y) ( \
236 ((!(X) || vec_meta(X)->used + Y >= vec_meta(X)->allocated)) ? \
237 (void)_util_vec_grow(((void**)&(X)), (Y), sizeof(*(X))) : \
241 /* exposed interface */
242 #define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
243 #define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = NULL) : 0))
244 #define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
245 #define vec_size(A) ((A) ? vec_meta(A)->used : 0)
246 #define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
247 #define vec_last(A) ((A)[vec_meta(A)->used - 1])
248 #define vec_pop(A) ((void)(vec_meta(A)->used -= 1))
249 #define vec_shrinkto(A,N) ((void)(vec_meta(A)->used = (N)))
250 #define vec_shrinkby(A,N) ((void)(vec_meta(A)->used -= (N)))
251 #define vec_append(A,N,S) ((void)(memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S)))))
252 #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)))
254 typedef struct hash_table_s {
256 struct hash_node_t **table;
260 * hashtable implementation:
263 * This was designed for pointers: you manage the life of the object yourself
264 * if you do use this for non-pointers please be warned that the object may not
265 * be valid if the duration of it exceeds (i.e on stack). So you need to allocate
266 * yourself, or put those in global scope to ensure duration is for the whole
269 * util_htnew(size) -- to make a new hashtable
270 * util_htset(table, key, value, sizeof(value)) -- to set something in the table
271 * util_htget(table, key) -- to get something from the table
272 * util_htdel(table) -- to delete the table
276 * ht foo = util_htnew(1024);
278 * char *test = "hello world\n";
279 * util_htset(foo, "foo", (void*)&data);
280 * util_gtset(foo, "bar", (void*)test);
282 * printf("foo: %d, bar %s",
283 * *((int *)util_htget(foo, "foo")),
284 * ((char*)util_htget(foo, "bar"))
289 hash_table_t *util_htnew (size_t size);
290 void util_htrem(hash_table_t *ht, void (*callback)(void *data));
291 void util_htset(hash_table_t *ht, const char *key, void *value);
292 void util_htdel(hash_table_t *ht);
293 size_t util_hthash(hash_table_t *ht, const char *key);
294 void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
295 void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
296 void util_htrm(hash_table_t *ht, const char *key, void (*cb)(void*));
297 void *util_htget(hash_table_t *ht, const char *key);
298 void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
299 int util_snprintf(char *str, size_t, const char *fmt, ...);
300 int util_getline(char **, size_t *, FILE *);
304 /* Note: if you change the order, fix type_sizeof in ir.c */
320 TYPE_NIL , /* it's its own type / untyped */
321 TYPE_NOEXPR , /* simply invalid in expressions */
326 /* const/var qualifiers */
330 #define CV_WRONG 0x8000 /* magic number to help parsing */
332 extern const char *type_name [TYPE_COUNT];
333 extern const uint16_t type_store_instr [TYPE_COUNT];
334 extern const uint16_t field_store_instr[TYPE_COUNT];
337 * could use type_store_instr + INSTR_STOREP_F - INSTR_STORE_F
338 * but this breaks when TYPE_INTEGER is added, since with the enhanced
339 * instruction set, the old ones are left untouched, thus the _I instructions
340 * are at a seperate place.
342 extern const uint16_t type_storep_instr[TYPE_COUNT];
343 extern const uint16_t type_eq_instr [TYPE_COUNT];
344 extern const uint16_t type_ne_instr [TYPE_COUNT];
345 extern const uint16_t type_not_instr [TYPE_COUNT];
348 uint32_t offset; /* Offset in file of where data begins */
349 uint32_t length; /* Length of section (how many of) */
353 uint32_t version; /* Program version (6) */
357 prog_section_t statements; /* prog_section_statement */
358 prog_section_t defs; /* prog_section_def */
359 prog_section_t fields; /* prog_section_field */
360 prog_section_t functions; /* prog_section_function */
361 prog_section_t strings;
362 prog_section_t globals;
363 uint32_t entfield; /* Number of entity fields */
367 * Each paramater incerements by 3 since vector types hold
368 * 3 components (x,y,z).
372 #define OFS_PARM0 (OFS_RETURN+3)
373 #define OFS_PARM1 (OFS_PARM0 +3)
374 #define OFS_PARM2 (OFS_PARM1 +3)
375 #define OFS_PARM3 (OFS_PARM2 +3)
376 #define OFS_PARM4 (OFS_PARM3 +3)
377 #define OFS_PARM5 (OFS_PARM4 +3)
378 #define OFS_PARM6 (OFS_PARM5 +3)
379 #define OFS_PARM7 (OFS_PARM6 +3)
386 int16_t s1; /* signed */
387 uint16_t u1; /* unsigned */
391 int16_t s1; /* signed */
392 uint16_t u1; /* unsigned */
396 int16_t s1; /* signed */
397 uint16_t u1; /* unsigned */
401 * This is the same as the structure in darkplaces
406 * But this one is more sane to work with, and the
407 * type sizes are guranteed.
409 } prog_section_statement_t;
421 * 7 = ev_pointer -- engine only
422 * 8 = ev_bad -- engine only
427 } prog_section_both_t;
429 typedef prog_section_both_t prog_section_def_t;
430 typedef prog_section_both_t prog_section_field_t;
432 /* this is ORed to the type */
433 #define DEF_SAVEGLOBAL (1<<15)
434 #define DEF_TYPEMASK ((1<<15)-1)
437 int32_t entry; /* in statement table for instructions */
438 uint32_t firstlocal; /* First local in local table */
439 uint32_t locals; /* Total ints of params + locals */
440 uint32_t profile; /* Always zero (engine uses this) */
441 uint32_t name; /* name of function in string table */
442 uint32_t file; /* file of the source file */
443 int32_t nargs; /* number of arguments */
444 uint8_t argsize[8]; /* size of arguments (keep 8 always?) */
445 } prog_section_function_t;
449 * These are the external instructions supported by the interperter
450 * this is what things compile to (from the C code).
456 INSTR_MUL_FV, /* NOTE: the float operands must NOT be at the same locations: A != C */
457 INSTR_MUL_VF, /* and here: B != C */
521 * Virtual instructions used by the IR
529 /* A never returning CALL.
530 * Creating this causes IR blocks to be marked as 'final'.
535 /* Emulated instructions. */
536 VINSTR_BITAND_V, /* BITAND_V must be the first emulated bitop */
549 extern const char *util_instr_str[VINSTR_END];
551 void util_swap_header (prog_header_t *code_header);
552 void util_swap_statements (prog_section_statement_t *statements);
553 void util_swap_defs_fields(prog_section_both_t *section);
554 void util_swap_functions (prog_section_function_t *functions);
555 void util_swap_globals (int32_t *globals);
557 typedef float qcfloat_t;
558 typedef int32_t qcint_t;
559 typedef uint32_t qcuint_t;
562 prog_section_statement_t *statements;
565 prog_section_def_t *defs;
566 prog_section_field_t *fields;
567 prog_section_function_t *functions;
573 qcint_t string_cached_empty;
577 * A shallow copy of a lex_file to remember where which ast node
587 * code_write -- writes out the compiled file
588 * code_init -- prepares the code file
589 * code_genstrin -- generates string for code
590 * code_alloc_field -- allocated a field
591 * code_push_statement -- keeps statements and linenumbers together
592 * code_pop_statement -- keeps statements and linenumbers together
594 bool code_write (code_t *, const char *filename, const char *lno);
596 code_t *code_init (void);
597 void code_cleanup (code_t *);
598 uint32_t code_genstring (code_t *, const char *string);
599 qcint_t code_alloc_field (code_t *, size_t qcsize);
600 void code_push_statement(code_t *, prog_section_statement_t *stmt, lex_ctx_t ctx);
601 void code_pop_statement (code_t *);
623 FILE *con_default_out(void);
624 FILE *con_default_err(void);
626 void con_vprintmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap);
627 void con_printmsg (int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...);
628 void con_cvprintmsg(lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
629 void con_cprintmsg (lex_ctx_t ctx, int lvl, const char *msgtype, const char *msg, ...);
631 void con_close (void);
632 void con_init (void);
633 void con_reset (void);
634 void con_color (int);
635 int con_verr (const char *, va_list);
636 int con_vout (const char *, va_list);
637 int con_err (const char *, ...);
638 int con_out (const char *, ...);
640 /* error/warning interface */
641 extern size_t compile_errors;
642 extern size_t compile_Werrors;
643 extern size_t compile_warnings;
645 void /********/ compile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
646 void /********/ vcompile_error (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
647 bool GMQCC_WARN compile_warning (lex_ctx_t ctx, int warntype, const char *fmt, ...);
648 bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
649 void compile_show_werrors(void);
655 store_local, /* local, assignable for now, should get promoted later */
656 store_param, /* parameters, they are locals with a fixed position */
657 store_value, /* unassignable */
658 store_return /* unassignable, at OFS_RETURN */
669 * Darkplaces has (or will have) a 64 bit prog loader
670 * where the 32 bit qc program is autoconverted on load.
671 * Since we may want to support that as well, let's redefine
672 * float and int here.
684 typedef char qcfloat_t_size_is_correct [sizeof(qcfloat_t) == 4 ?1:-1];
685 typedef char qcint_t_size_is_correct [sizeof(qcint_t) == 4 ?1:-1];
689 VMERR_TEMPSTRING_ALLOC,
693 #define VM_JUMPS_DEFAULT 1000000
696 #define VMXF_DEFAULT 0x0000 /* default flags - nothing */
697 #define VMXF_TRACE 0x0001 /* trace: print statements before executing */
698 #define VMXF_PROFILE 0x0002 /* profile: increment the profile counters */
701 typedef int (*prog_builtin_t)(struct qc_program_s *prog);
706 prog_section_function_t *function;
709 typedef struct qc_program_s {
711 prog_section_statement_t *code;
712 prog_section_def_t *defs;
713 prog_section_def_t *fields;
714 prog_section_function_t *functions;
720 const char* *function_stack;
724 size_t tempstring_start;
725 size_t tempstring_at;
731 prog_builtin_t *builtins;
732 size_t builtins_count;
737 bool allowworldwrites;
740 qc_exec_stack_t *stack;
745 int argc; /* current arg count for debugging */
759 bool supports_state; /* is INSTR_STATE supported? */
762 qc_program_t* prog_load (const char *filename, bool ignoreversion);
763 void prog_delete (qc_program_t *prog);
764 bool prog_exec (qc_program_t *prog, prog_section_function_t *func, size_t flags, long maxjumps);
765 const char* prog_getstring (qc_program_t *prog, qcint_t str);
766 prog_section_def_t* prog_entfield (qc_program_t *prog, qcint_t off);
767 prog_section_def_t* prog_getdef (qc_program_t *prog, qcint_t off);
768 qcany_t* prog_getedict (qc_program_t *prog, qcint_t e);
769 qcint_t prog_tempstring(qc_program_t *prog, const char *_str);
774 struct parser_s *parser_create (void);
775 bool parser_compile_file (struct parser_s *parser, const char *);
776 bool parser_compile_string(struct parser_s *parser, const char *, const char *, size_t);
777 bool parser_finish (struct parser_s *parser, const char *);
778 void parser_cleanup (struct parser_s *parser);
782 struct ftepp_s *ftepp_create (void);
783 bool ftepp_preprocess_file (struct ftepp_s *ftepp, const char *filename);
784 bool ftepp_preprocess_string(struct ftepp_s *ftepp, const char *name, const char *str);
785 void ftepp_finish (struct ftepp_s *ftepp);
786 const char *ftepp_get (struct ftepp_s *ftepp);
787 void ftepp_flush (struct ftepp_s *ftepp);
788 void ftepp_add_define (struct ftepp_s *ftepp, const char *source, const char *name);
789 void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, const char *value);
794 /* Helpers to allow for a whole lot of flags. Otherwise we'd limit
795 * to 32 or 64 -f options...
798 size_t idx; /* index into an array of 32 bit words */
799 uint8_t bit; /* bit index for the 8 bit group idx points to */
801 #define LONGBIT(bit) { ((bit)/32), ((bit)%32) }
802 #define LONGBIT_SET(B, I) ((B).idx = (I)/32, (B).bit = ((I)%32))
804 typedef uint32_t longbit;
805 #define LONGBIT(bit) (bit)
806 #define LONGBIT_SET(B, I) ((B) = (I))
810 typedef long utf8ch_t;
811 int utf8_from(char *, utf8ch_t);
812 int utf8_to(utf8ch_t *, const unsigned char *, size_t);
820 bool opts_setflag (const char *, bool);
821 bool opts_setwarn (const char *, bool);
822 bool opts_setwerror(const char *, bool);
823 bool opts_setoptim (const char *, bool);
825 void opts_init (const char *, int, size_t);
826 void opts_set (uint32_t *, size_t, bool);
827 void opts_setoptimlevel(unsigned int);
828 void opts_ini_init (const char *);
830 /* Saner flag handling */
831 void opts_backup_non_Wall(void);
832 void opts_restore_non_Wall(void);
833 void opts_backup_non_Werror_all(void);
834 void opts_restore_non_Werror_all(void);
838 # define GMQCC_TYPE_FLAGS
839 # define GMQCC_DEFINE_FLAG(X) X,
845 # define GMQCC_TYPE_WARNS
846 # define GMQCC_DEFINE_FLAG(X) WARN_##X,
852 # define GMQCC_TYPE_OPTIMIZATIONS
853 # define GMQCC_DEFINE_FLAG(NAME, MIN_O) OPTIM_##NAME,
859 # define GMQCC_TYPE_OPTIONS
860 # define GMQCC_DEFINE_FLAG(X) OPTION_##X,
865 extern const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1];
866 extern const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1];
867 extern const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1];
868 extern const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1];
869 extern unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
873 COMPILER_QCC, /* circa QuakeC */
874 COMPILER_FTEQCC, /* fteqcc QuakeC */
875 COMPILER_QCCX, /* qccx QuakeC */
876 COMPILER_GMQCC /* this QuakeC */
896 opt_value_t options [OPTION_COUNT];
897 uint32_t flags [1 + (COUNT_FLAGS / 32)];
898 uint32_t warn [1 + (COUNT_WARNINGS / 32)];
899 uint32_t werror [1 + (COUNT_WARNINGS / 32)];
900 uint32_t warn_backup [1 + (COUNT_WARNINGS / 32)];
901 uint32_t werror_backup[1 + (COUNT_WARNINGS / 32)];
902 uint32_t optimization [1 + (COUNT_OPTIMIZATIONS / 32)];
903 bool optimizeoff; /* True when -O0 */
906 extern opts_cmd_t opts;
908 #define OPTS_GENERIC(f,i) (!! (((f)[(i)/32]) & (1U << (unsigned)((i)%32))))
910 #define OPTS_FLAG(i) OPTS_GENERIC(opts.flags, (i))
911 #define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
912 #define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
913 #define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
915 #define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
916 #define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
917 #define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
918 #define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
919 #define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
920 #define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
922 #endif /*! GMQCC_HDR */