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