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