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