tccpe: build IAT vector with with -run too
[tinycc/kirr.git] / tcc.h
blob60da4fae69ddaa8139573a68d0b92e348cb50cc6
1 /*
2 * TCC - Tiny C Compiler
3 *
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define _GNU_SOURCE
22 #include "config.h"
24 #ifdef CONFIG_TCCBOOT
26 #include "tccboot.h"
27 #define CONFIG_TCC_STATIC
29 #else
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <math.h>
37 #include <signal.h>
38 #include <fcntl.h>
39 #include <setjmp.h>
40 #include <time.h>
42 #ifdef _WIN32
43 #include <windows.h>
44 #include <sys/timeb.h>
45 #include <io.h> /* open, close etc. */
46 #include <direct.h> /* getcwd */
47 #define inline __inline
48 #define inp next_inp
49 #define dlclose FreeLibrary
50 #endif
52 #ifndef _WIN32
53 #include <unistd.h>
54 #include <sys/time.h>
55 #include <sys/ucontext.h>
56 #include <sys/mman.h>
57 #endif
59 #endif /* !CONFIG_TCCBOOT */
61 #ifndef PAGESIZE
62 #define PAGESIZE 4096
63 #endif
65 #include "elf.h"
66 #include "stab.h"
68 #ifndef O_BINARY
69 #define O_BINARY 0
70 #endif
72 #include "libtcc.h"
74 /* parser debug */
75 //#define PARSE_DEBUG
76 /* preprocessor debug */
77 //#define PP_DEBUG
78 /* include file debug */
79 //#define INC_DEBUG
81 //#define MEM_DEBUG
83 /* assembler debug */
84 //#define ASM_DEBUG
86 /* target selection */
87 //#define TCC_TARGET_I386 /* i386 code generator */
88 //#define TCC_TARGET_ARM /* ARMv4 code generator */
89 //#define TCC_TARGET_C67 /* TMS320C67xx code generator */
90 //#define TCC_TARGET_X86_64 /* x86-64 code generator */
92 /* default target is I386 */
93 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
94 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
95 #define TCC_TARGET_I386
96 #endif
98 #if !defined(_WIN32) && !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
99 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
100 #define CONFIG_TCC_BCHECK /* enable bound checking code */
101 #endif
103 #if defined(_WIN32) && !defined(TCC_TARGET_PE)
104 #define CONFIG_TCC_STATIC
105 #endif
107 /* define it to include assembler support */
108 #if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67) && \
109 !defined(TCC_TARGET_X86_64)
110 #define CONFIG_TCC_ASM
111 #endif
113 /* object format selection */
114 #if defined(TCC_TARGET_C67)
115 #define TCC_TARGET_COFF
116 #endif
118 #if !defined(_WIN32) && !defined(CONFIG_TCCBOOT)
119 #define CONFIG_TCC_BACKTRACE
120 #endif
122 #define FALSE 0
123 #define false 0
124 #define TRUE 1
125 #define true 1
126 typedef int BOOL;
128 /* path to find crt1.o, crti.o and crtn.o. Only needed when generating
129 executables or dlls */
130 #define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib"
132 #define INCLUDE_STACK_SIZE 32
133 #define IFDEF_STACK_SIZE 64
134 #define VSTACK_SIZE 256
135 #define STRING_MAX_SIZE 1024
136 #define PACK_STACK_SIZE 8
138 #define TOK_HASH_SIZE 8192 /* must be a power of two */
139 #define TOK_ALLOC_INCR 512 /* must be a power of two */
140 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
142 /* token symbol management */
143 typedef struct TokenSym {
144 struct TokenSym *hash_next;
145 struct Sym *sym_define; /* direct pointer to define */
146 struct Sym *sym_label; /* direct pointer to label */
147 struct Sym *sym_struct; /* direct pointer to structure */
148 struct Sym *sym_identifier; /* direct pointer to identifier */
149 int tok; /* token number */
150 int len;
151 char str[1];
152 } TokenSym;
154 #ifdef TCC_TARGET_PE
155 typedef unsigned short nwchar_t;
156 #else
157 typedef int nwchar_t;
158 #endif
160 typedef struct CString {
161 int size; /* size in bytes */
162 void *data; /* either 'char *' or 'nwchar_t *' */
163 int size_allocated;
164 void *data_allocated; /* if non NULL, data has been malloced */
165 } CString;
167 /* type definition */
168 typedef struct CType {
169 int t;
170 struct Sym *ref;
171 } CType;
173 /* constant value */
174 typedef union CValue {
175 long double ld;
176 double d;
177 float f;
178 int i;
179 unsigned int ui;
180 unsigned int ul; /* address (should be unsigned long on 64 bit cpu) */
181 long long ll;
182 unsigned long long ull;
183 struct CString *cstr;
184 void *ptr;
185 int tab[1];
186 } CValue;
188 /* value on stack */
189 typedef struct SValue {
190 CType type; /* type */
191 unsigned short r; /* register + flags */
192 unsigned short r2; /* second register, used for 'long long'
193 type. If not used, set to VT_CONST */
194 CValue c; /* constant, if VT_CONST */
195 struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */
196 } SValue;
198 /* symbol management */
199 typedef struct Sym {
200 int v; /* symbol token */
201 long r; /* associated register */
202 union {
203 long c; /* associated number */
204 int *d; /* define token stream */
206 CType type; /* associated type */
207 struct Sym *next; /* next related symbol */
208 struct Sym *prev; /* prev symbol in stack */
209 struct Sym *prev_tok; /* previous symbol for this token */
210 } Sym;
212 /* section definition */
213 /* XXX: use directly ELF structure for parameters ? */
214 /* special flag to indicate that the section should not be linked to
215 the other ones */
216 #define SHF_PRIVATE 0x80000000
218 /* special flag, too */
219 #define SECTION_ABS ((void *)1)
221 typedef struct Section {
222 unsigned long data_offset; /* current data offset */
223 unsigned char *data; /* section data */
224 unsigned long data_allocated; /* used for realloc() handling */
225 int sh_name; /* elf section name (only used during output) */
226 int sh_num; /* elf section number */
227 int sh_type; /* elf section type */
228 int sh_flags; /* elf section flags */
229 int sh_info; /* elf section info */
230 int sh_addralign; /* elf section alignment */
231 int sh_entsize; /* elf entry size */
232 unsigned long sh_size; /* section size (only used during output) */
233 unsigned long sh_addr; /* address at which the section is relocated */
234 unsigned long sh_offset; /* file offset */
235 int nb_hashed_syms; /* used to resize the hash table */
236 struct Section *link; /* link to another section */
237 struct Section *reloc; /* corresponding section for relocation, if any */
238 struct Section *hash; /* hash table for symbols */
239 struct Section *next;
240 char name[1]; /* section name */
241 } Section;
243 typedef struct DLLReference {
244 int level;
245 void *handle;
246 char name[1];
247 } DLLReference;
249 /* GNUC attribute definition */
250 typedef struct AttributeDef {
251 int aligned;
252 int packed;
253 Section *section;
254 int func_attr; /* calling convention, exports, ... */
255 } AttributeDef;
257 /* -------------------------------------------------- */
258 /* gr: wrappers for casting sym->r for other purposes */
259 typedef struct {
260 unsigned
261 func_call : 8,
262 func_args : 8,
263 func_export : 1;
264 } func_attr_t;
266 #define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
267 #define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
268 #define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
269 /* -------------------------------------------------- */
271 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
272 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
273 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
275 /* stored in 'Sym.c' field */
276 #define FUNC_NEW 1 /* ansi function prototype */
277 #define FUNC_OLD 2 /* old function prototype */
278 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
280 /* stored in 'Sym.r' field */
281 #define FUNC_CDECL 0 /* standard c call */
282 #define FUNC_STDCALL 1 /* pascal c call */
283 #define FUNC_FASTCALL1 2 /* first param in %eax */
284 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
285 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
286 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
288 /* field 'Sym.t' for macros */
289 #define MACRO_OBJ 0 /* object like macro */
290 #define MACRO_FUNC 1 /* function like macro */
292 /* field 'Sym.r' for C labels */
293 #define LABEL_DEFINED 0 /* label is defined */
294 #define LABEL_FORWARD 1 /* label is forward defined */
295 #define LABEL_DECLARED 2 /* label is declared but never used */
297 /* type_decl() types */
298 #define TYPE_ABSTRACT 1 /* type without variable */
299 #define TYPE_DIRECT 2 /* type with variable */
301 #define IO_BUF_SIZE 8192
303 typedef struct BufferedFile {
304 uint8_t *buf_ptr;
305 uint8_t *buf_end;
306 int fd;
307 int line_num; /* current line number - here to simplify code */
308 int ifndef_macro; /* #ifndef macro / #endif search */
309 int ifndef_macro_saved; /* saved ifndef_macro */
310 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
311 char inc_type; /* type of include */
312 char inc_filename[512]; /* filename specified by the user */
313 char filename[1024]; /* current filename - here to simplify code */
314 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
315 } BufferedFile;
317 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
318 #define CH_EOF (-1) /* end of file */
320 /* parsing state (used to save parser state to reparse part of the
321 source several times) */
322 typedef struct ParseState {
323 int *macro_ptr;
324 int line_num;
325 int tok;
326 CValue tokc;
327 } ParseState;
329 /* used to record tokens */
330 typedef struct TokenString {
331 int *str;
332 int len;
333 int allocated_len;
334 int last_line_num;
335 } TokenString;
337 /* inline functions */
338 typedef struct InlineFunc {
339 int *token_str;
340 Sym *sym;
341 char filename[1];
342 } InlineFunc;
344 /* include file cache, used to find files faster and also to eliminate
345 inclusion if the include file is protected by #ifndef ... #endif */
346 typedef struct CachedInclude {
347 int ifndef_macro;
348 int hash_next; /* -1 if none */
349 char type; /* '"' or '>' to give include type */
350 char filename[1]; /* path specified in #include */
351 } CachedInclude;
353 #define CACHED_INCLUDES_HASH_SIZE 512
355 #ifdef CONFIG_TCC_ASM
356 typedef struct ExprValue {
357 uint32_t v;
358 Sym *sym;
359 } ExprValue;
361 #define MAX_ASM_OPERANDS 30
362 typedef struct ASMOperand {
363 int id; /* GCC 3 optionnal identifier (0 if number only supported */
364 char *constraint;
365 char asm_str[16]; /* computed asm string for operand */
366 SValue *vt; /* C value of the expression */
367 int ref_index; /* if >= 0, gives reference to a output constraint */
368 int input_index; /* if >= 0, gives reference to an input constraint */
369 int priority; /* priority, used to assign registers */
370 int reg; /* if >= 0, register number used for this operand */
371 int is_llong; /* true if double register value */
372 int is_memory; /* true if memory operand */
373 int is_rw; /* for '+' modifier */
374 } ASMOperand;
375 #endif
377 struct TCCState {
378 int output_type;
380 BufferedFile **include_stack_ptr;
381 int *ifdef_stack_ptr;
383 /* include file handling */
384 char **include_paths;
385 int nb_include_paths;
386 char **sysinclude_paths;
387 int nb_sysinclude_paths;
388 CachedInclude **cached_includes;
389 int nb_cached_includes;
391 char **library_paths;
392 int nb_library_paths;
394 /* array of all loaded dlls (including those referenced by loaded
395 dlls) */
396 DLLReference **loaded_dlls;
397 int nb_loaded_dlls;
399 /* sections */
400 Section **sections;
401 int nb_sections; /* number of sections, including first dummy section */
403 Section **priv_sections;
404 int nb_priv_sections; /* number of private sections */
406 /* got handling */
407 Section *got;
408 Section *plt;
409 unsigned long *got_offsets;
410 int nb_got_offsets;
411 /* give the correspondance from symtab indexes to dynsym indexes */
412 int *symtab_to_dynsym;
414 /* temporary dynamic symbol sections (for dll loading) */
415 Section *dynsymtab_section;
416 /* exported dynamic symbol section */
417 Section *dynsym;
419 int nostdinc; /* if true, no standard headers are added */
420 int nostdlib; /* if true, no standard libraries are added */
421 int nocommon; /* if true, do not use common symbols for .bss data */
423 /* if true, static linking is performed */
424 int static_link;
426 /* soname as specified on the command line (-soname) */
427 const char *soname;
429 /* if true, all symbols are exported */
430 int rdynamic;
432 /* if true, only link in referenced objects from archive */
433 int alacarte_link;
435 /* address of text section */
436 unsigned long text_addr;
437 int has_text_addr;
439 /* output format, see TCC_OUTPUT_FORMAT_xxx */
440 int output_format;
442 /* C language options */
443 int char_is_unsigned;
444 int leading_underscore;
446 /* warning switches */
447 int warn_write_strings;
448 int warn_unsupported;
449 int warn_error;
450 int warn_none;
451 int warn_implicit_function_declaration;
453 /* display some information during compilation */
454 int verbose;
455 /* compile with debug symbol (and use them if error during execution) */
456 int do_debug;
457 /* compile with built-in memory and bounds checker */
458 int do_bounds_check;
459 /* give the path of the tcc libraries */
460 const char *tcc_lib_path;
462 /* error handling */
463 void *error_opaque;
464 void (*error_func)(void *opaque, const char *msg);
465 int error_set_jmp_enabled;
466 jmp_buf error_jmp_buf;
467 int nb_errors;
469 /* tiny assembler state */
470 Sym *asm_labels;
472 /* see include_stack_ptr */
473 BufferedFile *include_stack[INCLUDE_STACK_SIZE];
475 /* see ifdef_stack_ptr */
476 int ifdef_stack[IFDEF_STACK_SIZE];
478 /* see cached_includes */
479 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
481 /* pack stack */
482 int pack_stack[PACK_STACK_SIZE];
483 int *pack_stack_ptr;
485 /* output file for preprocessing */
486 FILE *outfile;
488 /* for tcc_relocate */
489 int runtime_added;
491 struct InlineFunc **inline_fns;
492 int nb_inline_fns;
494 #ifdef TCC_TARGET_X86_64
495 /* write PLT and GOT here */
496 char *runtime_plt_and_got;
497 unsigned int runtime_plt_and_got_offset;
498 #endif
501 /* The current value can be: */
502 #define VT_VALMASK 0x00ff
503 #define VT_CONST 0x00f0 /* constant in vc
504 (must be first non register value) */
505 #define VT_LLOCAL 0x00f1 /* lvalue, offset on stack */
506 #define VT_LOCAL 0x00f2 /* offset on stack */
507 #define VT_CMP 0x00f3 /* the value is stored in processor flags (in vc) */
508 #define VT_JMP 0x00f4 /* value is the consequence of jmp true (even) */
509 #define VT_JMPI 0x00f5 /* value is the consequence of jmp false (odd) */
510 #define VT_LVAL 0x0100 /* var is an lvalue */
511 #define VT_SYM 0x0200 /* a symbol value is added */
512 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
513 char/short stored in integer registers) */
514 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
515 dereferencing value */
516 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
517 bounding function call point is in vc */
518 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
519 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
520 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
521 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
523 /* types */
524 #define VT_INT 0 /* integer type */
525 #define VT_BYTE 1 /* signed byte type */
526 #define VT_SHORT 2 /* short type */
527 #define VT_VOID 3 /* void type */
528 #define VT_PTR 4 /* pointer */
529 #define VT_ENUM 5 /* enum definition */
530 #define VT_FUNC 6 /* function type */
531 #define VT_STRUCT 7 /* struct/union definition */
532 #define VT_FLOAT 8 /* IEEE float */
533 #define VT_DOUBLE 9 /* IEEE double */
534 #define VT_LDOUBLE 10 /* IEEE long double */
535 #define VT_BOOL 11 /* ISOC99 boolean type */
536 #define VT_LLONG 12 /* 64 bit integer */
537 #define VT_LONG 13 /* long integer (NEVER USED as type, only
538 during parsing) */
539 #define VT_BTYPE 0x000f /* mask for basic type */
540 #define VT_UNSIGNED 0x0010 /* unsigned type */
541 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
542 #define VT_BITFIELD 0x0040 /* bitfield modifier */
543 #define VT_CONSTANT 0x0800 /* const modifier */
544 #define VT_VOLATILE 0x1000 /* volatile modifier */
545 #define VT_SIGNED 0x2000 /* signed type */
547 /* storage */
548 #define VT_EXTERN 0x00000080 /* extern definition */
549 #define VT_STATIC 0x00000100 /* static variable */
550 #define VT_TYPEDEF 0x00000200 /* typedef definition */
551 #define VT_INLINE 0x00000400 /* inline definition */
553 #define VT_STRUCT_SHIFT 16 /* shift for bitfield shift values */
555 /* type mask (except storage) */
556 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
557 #define VT_TYPE (~(VT_STORAGE))
559 /* token values */
561 /* warning: the following compare tokens depend on i386 asm code */
562 #define TOK_ULT 0x92
563 #define TOK_UGE 0x93
564 #define TOK_EQ 0x94
565 #define TOK_NE 0x95
566 #define TOK_ULE 0x96
567 #define TOK_UGT 0x97
568 #define TOK_Nset 0x98
569 #define TOK_Nclear 0x99
570 #define TOK_LT 0x9c
571 #define TOK_GE 0x9d
572 #define TOK_LE 0x9e
573 #define TOK_GT 0x9f
575 #define TOK_LAND 0xa0
576 #define TOK_LOR 0xa1
578 #define TOK_DEC 0xa2
579 #define TOK_MID 0xa3 /* inc/dec, to void constant */
580 #define TOK_INC 0xa4
581 #define TOK_UDIV 0xb0 /* unsigned division */
582 #define TOK_UMOD 0xb1 /* unsigned modulo */
583 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
584 #define TOK_CINT 0xb3 /* number in tokc */
585 #define TOK_CCHAR 0xb4 /* char constant in tokc */
586 #define TOK_STR 0xb5 /* pointer to string in tokc */
587 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
588 #define TOK_LCHAR 0xb7
589 #define TOK_LSTR 0xb8
590 #define TOK_CFLOAT 0xb9 /* float constant */
591 #define TOK_LINENUM 0xba /* line number info */
592 #define TOK_CDOUBLE 0xc0 /* double constant */
593 #define TOK_CLDOUBLE 0xc1 /* long double constant */
594 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
595 #define TOK_ADDC1 0xc3 /* add with carry generation */
596 #define TOK_ADDC2 0xc4 /* add with carry use */
597 #define TOK_SUBC1 0xc5 /* add with carry generation */
598 #define TOK_SUBC2 0xc6 /* add with carry use */
599 #define TOK_CUINT 0xc8 /* unsigned int constant */
600 #define TOK_CLLONG 0xc9 /* long long constant */
601 #define TOK_CULLONG 0xca /* unsigned long long constant */
602 #define TOK_ARROW 0xcb
603 #define TOK_DOTS 0xcc /* three dots */
604 #define TOK_SHR 0xcd /* unsigned shift right */
605 #define TOK_PPNUM 0xce /* preprocessor number */
607 #define TOK_SHL 0x01 /* shift left */
608 #define TOK_SAR 0x02 /* signed shift right */
610 /* assignement operators : normal operator or 0x80 */
611 #define TOK_A_MOD 0xa5
612 #define TOK_A_AND 0xa6
613 #define TOK_A_MUL 0xaa
614 #define TOK_A_ADD 0xab
615 #define TOK_A_SUB 0xad
616 #define TOK_A_DIV 0xaf
617 #define TOK_A_XOR 0xde
618 #define TOK_A_OR 0xfc
619 #define TOK_A_SHL 0x81
620 #define TOK_A_SAR 0x82
622 #ifndef offsetof
623 #define offsetof(type, field) ((size_t) &((type *)0)->field)
624 #endif
626 #ifndef countof
627 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
628 #endif
630 #define TOK_EOF (-1) /* end of file */
631 #define TOK_LINEFEED 10 /* line feed */
633 /* all identificators and strings have token above that */
634 #define TOK_IDENT 256
636 /* only used for i386 asm opcodes definitions */
637 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
639 #define DEF_BWL(x) \
640 DEF(TOK_ASM_ ## x ## b, #x "b") \
641 DEF(TOK_ASM_ ## x ## w, #x "w") \
642 DEF(TOK_ASM_ ## x ## l, #x "l") \
643 DEF(TOK_ASM_ ## x, #x)
645 #define DEF_WL(x) \
646 DEF(TOK_ASM_ ## x ## w, #x "w") \
647 DEF(TOK_ASM_ ## x ## l, #x "l") \
648 DEF(TOK_ASM_ ## x, #x)
650 #define DEF_FP1(x) \
651 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
652 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
653 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
654 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
656 #define DEF_FP(x) \
657 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
658 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
659 DEF_FP1(x)
661 #define DEF_ASMTEST(x) \
662 DEF_ASM(x ## o) \
663 DEF_ASM(x ## no) \
664 DEF_ASM(x ## b) \
665 DEF_ASM(x ## c) \
666 DEF_ASM(x ## nae) \
667 DEF_ASM(x ## nb) \
668 DEF_ASM(x ## nc) \
669 DEF_ASM(x ## ae) \
670 DEF_ASM(x ## e) \
671 DEF_ASM(x ## z) \
672 DEF_ASM(x ## ne) \
673 DEF_ASM(x ## nz) \
674 DEF_ASM(x ## be) \
675 DEF_ASM(x ## na) \
676 DEF_ASM(x ## nbe) \
677 DEF_ASM(x ## a) \
678 DEF_ASM(x ## s) \
679 DEF_ASM(x ## ns) \
680 DEF_ASM(x ## p) \
681 DEF_ASM(x ## pe) \
682 DEF_ASM(x ## np) \
683 DEF_ASM(x ## po) \
684 DEF_ASM(x ## l) \
685 DEF_ASM(x ## nge) \
686 DEF_ASM(x ## nl) \
687 DEF_ASM(x ## ge) \
688 DEF_ASM(x ## le) \
689 DEF_ASM(x ## ng) \
690 DEF_ASM(x ## nle) \
691 DEF_ASM(x ## g)
693 #define TOK_ASM_int TOK_INT
695 enum tcc_token {
696 TOK_LAST = TOK_IDENT - 1,
697 #define DEF(id, str) id,
698 #include "tcctok.h"
699 #undef DEF
702 #define TOK_UIDENT TOK_DEFINE
704 #ifdef _WIN32
705 #define snprintf _snprintf
706 #define vsnprintf _vsnprintf
707 #ifndef __GNUC__
708 #define strtold (long double)strtod
709 #define strtof (float)strtod
710 #define strtoll (long long)strtol
711 #endif
712 #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
713 || defined(__OpenBSD__)
714 /* currently incorrect */
715 long double strtold(const char *nptr, char **endptr)
717 return (long double)strtod(nptr, endptr);
719 float strtof(const char *nptr, char **endptr)
721 return (float)strtod(nptr, endptr);
723 #else
724 /* XXX: need to define this to use them in non ISOC99 context */
725 extern float strtof (const char *__nptr, char **__endptr);
726 extern long double strtold (const char *__nptr, char **__endptr);
727 #endif
729 #ifdef _WIN32
730 #define IS_PATHSEP(c) (c == '/' || c == '\\')
731 #define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2])))
732 #define PATHCMP stricmp
733 #else
734 #define IS_PATHSEP(c) (c == '/')
735 #define IS_ABSPATH(p) IS_PATHSEP(p[0])
736 #define PATHCMP strcmp
737 #endif
739 void error(const char *fmt, ...);
740 void error_noabort(const char *fmt, ...);
741 void warning(const char *fmt, ...);
743 void tcc_set_lib_path_w32(TCCState *s);
744 int tcc_set_flag(TCCState *s, const char *flag_name, int value);
745 void tcc_print_stats(TCCState *s, int64_t total_time);
747 void tcc_free(void *ptr);
748 void *tcc_malloc(unsigned long size);
749 void *tcc_mallocz(unsigned long size);
750 void *tcc_realloc(void *ptr, unsigned long size);
751 char *tcc_strdup(const char *str);
753 char *tcc_basename(const char *name);
754 char *tcc_fileextension (const char *name);
755 char *pstrcpy(char *buf, int buf_size, const char *s);
756 char *pstrcat(char *buf, int buf_size, const char *s);
757 void dynarray_add(void ***ptab, int *nb_ptr, void *data);
758 void dynarray_reset(void *pp, int *n);
760 #ifdef CONFIG_TCC_BACKTRACE
761 extern int num_callers;
762 extern const char **rt_bound_error_msg;
763 #endif
765 /* true if float/double/long double type */
766 static inline int is_float(int t)
768 int bt;
769 bt = t & VT_BTYPE;
770 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
773 /* space exlcuding newline */
774 static inline int is_space(int ch)
776 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';