2 * TCC - Tiny C Compiler
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
30 #define CONFIG_TCC_STATIC
47 # include <sys/time.h>
48 # include <sys/ucontext.h>
49 # include <sys/mman.h>
50 # ifndef CONFIG_TCC_STATIC
55 # include <sys/timeb.h>
56 # include <io.h> /* open, close etc. */
57 # include <direct.h> /* getcwd */
61 typedef UINT_PTR
uintptr_t;
63 # define inline __inline
66 # define LIBTCCAPI __declspec(dllexport)
67 # define PUB_FUNC LIBTCCAPI
71 #endif /* !CONFIG_TCCBOOT */
82 #define SA_SIGINFO 0x00000004u
86 #ifdef TCC_TARGET_X86_64
87 # define ELFCLASSW ELFCLASS64
88 # define ElfW(type) Elf##64##_##type
89 # define ELFW(type) ELF##64##_##type
90 # define ElfW_Rel ElfW(Rela)
91 # define SHT_RELX SHT_RELA
92 # define REL_SECTION_FMT ".rela%s"
93 /* XXX: DLL with PLT would only work with x86-64 for now */
94 # define TCC_OUTPUT_DLL_WITH_PLT
96 # define ELFCLASSW ELFCLASS32
97 # define ElfW(type) Elf##32##_##type
98 # define ELFW(type) ELF##32##_##type
99 # define ElfW_Rel ElfW(Rel)
100 # define SHT_RELX SHT_REL
101 # define REL_SECTION_FMT ".rel%s"
104 /* target address type */
105 #define addr_t ElfW(Addr)
111 //#define PARSE_DEBUG
112 /* preprocessor debug */
114 /* include file debug */
119 /* assembler debug */
122 /* target selection */
123 //#define TCC_TARGET_I386 /* i386 code generator */
124 //#define TCC_TARGET_ARM /* ARMv4 code generator */
125 //#define TCC_TARGET_C67 /* TMS320C67xx code generator */
126 //#define TCC_TARGET_X86_64 /* x86-64 code generator */
128 /* default target is I386 */
129 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
130 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
131 #define TCC_TARGET_I386
134 #if !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
135 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
136 #define CONFIG_TCC_BCHECK /* enable bound checking code */
139 /* define it to include assembler support */
140 #if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67)
141 #define CONFIG_TCC_ASM
144 /* object format selection */
145 #if defined(TCC_TARGET_C67)
146 #define TCC_TARGET_COFF
149 /* only native compiler supports -run */
150 #if defined _WIN32 == defined TCC_TARGET_PE
151 # if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386
152 # define TCC_IS_NATIVE
153 # elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64
154 # define TCC_IS_NATIVE
155 # elif defined __arm__ && defined TCC_TARGET_ARM
156 # define TCC_IS_NATIVE
160 #if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
161 # define CONFIG_TCC_BACKTRACE
164 /* ------------ path configuration ------------ */
166 #ifndef CONFIG_SYSROOT
167 # define CONFIG_SYSROOT ""
171 # ifdef CONFIG_MULTIARCHDIR
172 # define CONFIG_LDDIR "lib/" CONFIG_MULTIARCHDIR
174 # define CONFIG_LDDIR "lib"
178 /* path to find crt1.o, crti.o and crtn.o */
179 #ifndef CONFIG_TCC_CRTPREFIX
180 # define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR
183 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
185 /* system include paths */
186 #ifndef CONFIG_TCC_SYSINCLUDEPATHS
187 # ifdef TCC_TARGET_PE
188 # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
189 # elif defined CONFIG_MULTIARCHDIR
190 # define CONFIG_TCC_SYSINCLUDEPATHS \
191 CONFIG_SYSROOT "/usr/local/include" \
192 ":" CONFIG_SYSROOT "/usr/local/include/" CONFIG_MULTIARCHDIR \
193 ":" CONFIG_SYSROOT "/usr/include" \
194 ":" CONFIG_SYSROOT "/usr/include/" CONFIG_MULTIARCHDIR \
197 # define CONFIG_TCC_SYSINCLUDEPATHS \
198 CONFIG_SYSROOT "/usr/local/include" \
199 ":" CONFIG_SYSROOT "/usr/include" \
204 /* library search paths */
205 #ifndef CONFIG_TCC_LIBPATHS
206 # ifdef TCC_TARGET_PE
207 # define CONFIG_TCC_LIBPATHS "{B}/lib"
209 # define CONFIG_TCC_LIBPATHS \
210 CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \
211 ":" CONFIG_SYSROOT "/" CONFIG_LDDIR \
212 ":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR
216 /* name of ELF interpreter */
217 #ifndef CONFIG_TCC_ELFINTERP
218 # if defined __FreeBSD__
219 # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
220 # elif defined __FreeBSD_kernel__
221 # define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
222 # elif defined TCC_ARM_HARDFLOAT
223 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-armhf.so.3"
224 # elif defined TCC_ARM_EABI
225 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.3"
226 # elif defined(TCC_TARGET_X86_64)
227 # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
228 # elif defined(TCC_UCLIBC)
229 # define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0"
231 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
235 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
236 #define TCC_LIBGCC CONFIG_SYSROOT "/" CONFIG_LDDIR "/libgcc_s.so.1"
238 /* -------------------------------------------- */
240 #define INCLUDE_STACK_SIZE 32
241 #define IFDEF_STACK_SIZE 64
242 #define VSTACK_SIZE 256
243 #define STRING_MAX_SIZE 1024
244 #define PACK_STACK_SIZE 8
246 #define TOK_HASH_SIZE 8192 /* must be a power of two */
247 #define TOK_ALLOC_INCR 512 /* must be a power of two */
248 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
250 /* token symbol management */
251 typedef struct TokenSym
{
252 struct TokenSym
*hash_next
;
253 struct Sym
*sym_define
; /* direct pointer to define */
254 struct Sym
*sym_label
; /* direct pointer to label */
255 struct Sym
*sym_struct
; /* direct pointer to structure */
256 struct Sym
*sym_identifier
; /* direct pointer to identifier */
257 int tok
; /* token number */
263 typedef unsigned short nwchar_t
;
265 typedef int nwchar_t
;
268 typedef struct CString
{
269 int size
; /* size in bytes */
270 void *data
; /* either 'char *' or 'nwchar_t *' */
272 void *data_allocated
; /* if non NULL, data has been malloced */
275 /* type definition */
276 typedef struct CType
{
282 typedef union CValue
{
288 unsigned int ul
; /* address (should be unsigned long on 64 bit cpu) */
290 unsigned long long ull
;
291 struct CString
*cstr
;
297 typedef struct SValue
{
298 CType type
; /* type */
299 unsigned short r
; /* register + flags */
300 unsigned short r2
; /* second register, used for 'long long'
301 type. If not used, set to VT_CONST */
302 CValue c
; /* constant, if VT_CONST */
303 struct Sym
*sym
; /* symbol, if (VT_SYM | VT_CONST) */
306 /* symbol management */
308 int v
; /* symbol token */
309 char *asm_label
; /* associated asm label */
310 long r
; /* associated register */
312 long c
; /* associated number */
313 int *d
; /* define token stream */
315 CType type
; /* associated type */
317 struct Sym
*next
; /* next related symbol */
318 long jnext
; /* next jump label */
320 struct Sym
*prev
; /* prev symbol in stack */
321 struct Sym
*prev_tok
; /* previous symbol for this token */
324 /* section definition */
325 /* XXX: use directly ELF structure for parameters ? */
326 /* special flag to indicate that the section should not be linked to
328 #define SHF_PRIVATE 0x80000000
330 /* special flag, too */
331 #define SECTION_ABS ((void *)1)
333 typedef struct Section
{
334 unsigned long data_offset
; /* current data offset */
335 unsigned char *data
; /* section data */
336 unsigned long data_allocated
; /* used for realloc() handling */
337 int sh_name
; /* elf section name (only used during output) */
338 int sh_num
; /* elf section number */
339 int sh_type
; /* elf section type */
340 int sh_flags
; /* elf section flags */
341 int sh_info
; /* elf section info */
342 int sh_addralign
; /* elf section alignment */
343 int sh_entsize
; /* elf entry size */
344 unsigned long sh_size
; /* section size (only used during output) */
345 addr_t sh_addr
; /* address at which the section is relocated */
346 unsigned long sh_offset
; /* file offset */
347 int nb_hashed_syms
; /* used to resize the hash table */
348 struct Section
*link
; /* link to another section */
349 struct Section
*reloc
; /* corresponding section for relocation, if any */
350 struct Section
*hash
; /* hash table for symbols */
351 struct Section
*next
;
352 char name
[1]; /* section name */
355 typedef struct DLLReference
{
361 /* GNUC attribute definition */
362 typedef struct AttributeDef
{
364 func_call
: 3, /* calling convention (0..5), see below */
365 aligned
: 5, /* alignement (0..16) */
373 struct Section
*section
;
374 int alias_target
; /* token */
377 /* gr: wrappers for casting sym->r for other purposes */
378 #define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
379 #define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
380 #define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
381 #define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
382 #define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
383 #define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
384 #define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
385 #define INT_ATTR(ad) (*(int*)(ad))
387 /* -------------------------------------------------- */
389 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
390 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
391 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
393 /* stored in 'Sym.c' field */
394 #define FUNC_NEW 1 /* ansi function prototype */
395 #define FUNC_OLD 2 /* old function prototype */
396 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
398 /* stored in 'Sym.r' field */
399 #define FUNC_CDECL 0 /* standard c call */
400 #define FUNC_STDCALL 1 /* pascal c call */
401 #define FUNC_FASTCALL1 2 /* first param in %eax */
402 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
403 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
404 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
406 /* field 'Sym.t' for macros */
407 #define MACRO_OBJ 0 /* object like macro */
408 #define MACRO_FUNC 1 /* function like macro */
410 /* field 'Sym.r' for C labels */
411 #define LABEL_DEFINED 0 /* label is defined */
412 #define LABEL_FORWARD 1 /* label is forward defined */
413 #define LABEL_DECLARED 2 /* label is declared but never used */
415 /* type_decl() types */
416 #define TYPE_ABSTRACT 1 /* type without variable */
417 #define TYPE_DIRECT 2 /* type with variable */
419 #define IO_BUF_SIZE 8192
421 typedef struct BufferedFile
{
425 struct BufferedFile
*prev
;
426 int line_num
; /* current line number - here to simplify code */
427 int ifndef_macro
; /* #ifndef macro / #endif search */
428 int ifndef_macro_saved
; /* saved ifndef_macro */
429 int *ifdef_stack_ptr
; /* ifdef_stack value at the start of the file */
430 char filename
[1024]; /* filename */
431 unsigned char buffer
[IO_BUF_SIZE
+ 1]; /* extra size for CH_EOB char */
434 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
435 #define CH_EOF (-1) /* end of file */
437 /* parsing state (used to save parser state to reparse part of the
438 source several times) */
439 typedef struct ParseState
{
440 const int *macro_ptr
;
446 /* used to record tokens */
447 typedef struct TokenString
{
454 /* inline functions */
455 typedef struct InlineFunc
{
461 /* include file cache, used to find files faster and also to eliminate
462 inclusion if the include file is protected by #ifndef ... #endif */
463 typedef struct CachedInclude
{
465 int hash_next
; /* -1 if none */
466 char filename
[1]; /* path specified in #include */
469 #define CACHED_INCLUDES_HASH_SIZE 512
471 #ifdef CONFIG_TCC_ASM
472 typedef struct ExprValue
{
477 #define MAX_ASM_OPERANDS 30
478 typedef struct ASMOperand
{
479 int id
; /* GCC 3 optionnal identifier (0 if number only supported */
481 char asm_str
[16]; /* computed asm string for operand */
482 SValue
*vt
; /* C value of the expression */
483 int ref_index
; /* if >= 0, gives reference to a output constraint */
484 int input_index
; /* if >= 0, gives reference to an input constraint */
485 int priority
; /* priority, used to assign registers */
486 int reg
; /* if >= 0, register number used for this operand */
487 int is_llong
; /* true if double register value */
488 int is_memory
; /* true if memory operand */
489 int is_rw
; /* for '+' modifier */
494 unsigned long got_offset
;
495 #ifdef TCC_TARGET_ARM
496 unsigned char plt_thumb_stub
:1;
501 unsigned output_type
: 8;
502 unsigned reloc_output
: 1;
504 BufferedFile
**include_stack_ptr
;
505 int *ifdef_stack_ptr
;
507 /* include file handling */
508 char **include_paths
;
509 int nb_include_paths
;
510 char **sysinclude_paths
;
511 int nb_sysinclude_paths
;
512 CachedInclude
**cached_includes
;
513 int nb_cached_includes
;
515 char **library_paths
;
516 int nb_library_paths
;
520 /* array of all loaded dlls (including those referenced by loaded
522 DLLReference
**loaded_dlls
;
527 int nb_sections
; /* number of sections, including first dummy section */
529 Section
**priv_sections
;
530 int nb_priv_sections
; /* number of private sections */
532 /* got & plt handling */
535 struct sym_attr
*sym_attrs
;
537 /* give the correspondance from symtab indexes to dynsym indexes */
538 int *symtab_to_dynsym
;
540 /* temporary dynamic symbol sections (for dll loading) */
541 Section
*dynsymtab_section
;
542 /* exported dynamic symbol section */
545 /* copy of the gobal symtab_section variable */
548 int nostdinc
; /* if true, no standard headers are added */
549 int nostdlib
; /* if true, no standard libraries are added */
550 int nocommon
; /* if true, do not use common symbols for .bss data */
552 /* if true, static linking is performed */
555 /* soname as specified on the command line (-soname) */
557 /* rpath as specified on the command line (-Wl,-rpath=) */
560 /* if true, all symbols are exported */
563 /* if true, resolve symbols in the current module first (-Wl,Bsymbolic) */
566 /* if true, only link in referenced objects from archive */
569 /* address of text section */
573 /* symbols to call at load-time / unload-time */
574 const char *init_symbol
;
575 const char *fini_symbol
;
577 /* output format, see TCC_OUTPUT_FORMAT_xxx */
580 /* C language options */
581 int char_is_unsigned
;
582 int leading_underscore
;
584 /* warning switches */
585 int warn_write_strings
;
586 int warn_unsupported
;
589 int warn_implicit_function_declaration
;
591 /* display some information during compilation */
593 /* compile with debug symbol (and use them if error during execution) */
595 #ifdef CONFIG_TCC_BCHECK
596 /* compile with built-in memory and bounds checker */
599 /* give the path of the tcc libraries */
604 void (*error_func
)(void *opaque
, const char *msg
);
605 int error_set_jmp_enabled
;
606 jmp_buf error_jmp_buf
;
609 /* tiny assembler state */
612 /* see include_stack_ptr */
613 BufferedFile
*include_stack
[INCLUDE_STACK_SIZE
];
615 /* see ifdef_stack_ptr */
616 int ifdef_stack
[IFDEF_STACK_SIZE
];
618 /* see cached_includes */
619 int cached_includes_hash
[CACHED_INCLUDES_HASH_SIZE
];
622 int pack_stack
[PACK_STACK_SIZE
];
625 /* output file for preprocessing */
628 /* automatically collected dependencies for this compilation */
632 /* for tcc_relocate */
637 unsigned long mem_size
;
640 struct InlineFunc
**inline_fns
;
643 #ifdef TCC_TARGET_I386
647 /* section alignment */
648 unsigned long section_align
;
653 unsigned long pe_file_align
;
654 unsigned long pe_stack_size
;
655 #ifdef TCC_TARGET_X86_64
662 #if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE \
663 && (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM)
664 /* write PLT and GOT here */
665 char *runtime_plt_and_got
;
666 unsigned int runtime_plt_and_got_offset
;
667 # define TCC_HAS_RUNTIME_PLTGOT
671 /* The current value can be: */
672 #define VT_VALMASK 0x003f
673 #define VT_CONST 0x0030 /* constant in vc
674 (must be first non register value) */
675 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
676 #define VT_LOCAL 0x0032 /* offset on stack */
677 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
678 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
679 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
680 #define VT_REF 0x0040 /* value is pointer to structure rather than address */
681 #define VT_LVAL 0x0100 /* var is an lvalue */
682 #define VT_SYM 0x0200 /* a symbol value is added */
683 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
684 char/short stored in integer registers) */
685 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
686 dereferencing value */
687 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
688 bounding function call point is in vc */
689 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
690 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
691 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
692 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
695 #define VT_INT 0 /* integer type */
696 #define VT_BYTE 1 /* signed byte type */
697 #define VT_SHORT 2 /* short type */
698 #define VT_VOID 3 /* void type */
699 #define VT_PTR 4 /* pointer */
700 #define VT_ENUM 5 /* enum definition */
701 #define VT_FUNC 6 /* function type */
702 #define VT_STRUCT 7 /* struct/union definition */
703 #define VT_FLOAT 8 /* IEEE float */
704 #define VT_DOUBLE 9 /* IEEE double */
705 #define VT_LDOUBLE 10 /* IEEE long double */
706 #define VT_BOOL 11 /* ISOC99 boolean type */
707 #define VT_LLONG 12 /* 64 bit integer */
708 #define VT_LONG 13 /* long integer (NEVER USED as type, only
710 #define VT_BTYPE 0x000f /* mask for basic type */
711 #define VT_UNSIGNED 0x0010 /* unsigned type */
712 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
713 #define VT_VLA 0x20000 /* VLA type (also has VT_PTR and VT_ARRAY) */
714 #define VT_BITFIELD 0x0040 /* bitfield modifier */
715 #define VT_CONSTANT 0x0800 /* const modifier */
716 #define VT_VOLATILE 0x1000 /* volatile modifier */
717 #define VT_SIGNED 0x2000 /* signed type */
720 #define VT_EXTERN 0x00000080 /* extern definition */
721 #define VT_STATIC 0x00000100 /* static variable */
722 #define VT_TYPEDEF 0x00000200 /* typedef definition */
723 #define VT_INLINE 0x00000400 /* inline definition */
724 #define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */
725 #define VT_EXPORT 0x00008000 /* win32: data exported from dll */
726 #define VT_WEAK 0x00010000 /* win32: data exported from dll */
728 #define VT_STRUCT_SHIFT 18 /* shift for bitfield shift values */
730 /* type mask (except storage) */
731 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE | VT_IMPORT | VT_EXPORT | VT_WEAK)
732 #define VT_TYPE (~(VT_STORAGE))
736 /* warning: the following compare tokens depend on i386 asm code */
743 #define TOK_Nset 0x98
744 #define TOK_Nclear 0x99
750 #define TOK_LAND 0xa0
754 #define TOK_MID 0xa3 /* inc/dec, to void constant */
756 #define TOK_UDIV 0xb0 /* unsigned division */
757 #define TOK_UMOD 0xb1 /* unsigned modulo */
758 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
759 #define TOK_CINT 0xb3 /* number in tokc */
760 #define TOK_CCHAR 0xb4 /* char constant in tokc */
761 #define TOK_STR 0xb5 /* pointer to string in tokc */
762 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
763 #define TOK_LCHAR 0xb7
764 #define TOK_LSTR 0xb8
765 #define TOK_CFLOAT 0xb9 /* float constant */
766 #define TOK_LINENUM 0xba /* line number info */
767 #define TOK_CDOUBLE 0xc0 /* double constant */
768 #define TOK_CLDOUBLE 0xc1 /* long double constant */
769 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
770 #define TOK_ADDC1 0xc3 /* add with carry generation */
771 #define TOK_ADDC2 0xc4 /* add with carry use */
772 #define TOK_SUBC1 0xc5 /* add with carry generation */
773 #define TOK_SUBC2 0xc6 /* add with carry use */
774 #define TOK_CUINT 0xc8 /* unsigned int constant */
775 #define TOK_CLLONG 0xc9 /* long long constant */
776 #define TOK_CULLONG 0xca /* unsigned long long constant */
777 #define TOK_ARROW 0xcb
778 #define TOK_DOTS 0xcc /* three dots */
779 #define TOK_SHR 0xcd /* unsigned shift right */
780 #define TOK_PPNUM 0xce /* preprocessor number */
781 #define TOK_NOSUBST 0xcf /* means following token has already been pp'd */
783 #define TOK_SHL 0x01 /* shift left */
784 #define TOK_SAR 0x02 /* signed shift right */
786 /* assignement operators : normal operator or 0x80 */
787 #define TOK_A_MOD 0xa5
788 #define TOK_A_AND 0xa6
789 #define TOK_A_MUL 0xaa
790 #define TOK_A_ADD 0xab
791 #define TOK_A_SUB 0xad
792 #define TOK_A_DIV 0xaf
793 #define TOK_A_XOR 0xde
794 #define TOK_A_OR 0xfc
795 #define TOK_A_SHL 0x81
796 #define TOK_A_SAR 0x82
799 #define offsetof(type, field) ((size_t) &((type *)0)->field)
803 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
806 #define TOK_EOF (-1) /* end of file */
807 #define TOK_LINEFEED 10 /* line feed */
809 /* all identificators and strings have token above that */
810 #define TOK_IDENT 256
812 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
813 #define TOK_ASM_int TOK_INT
814 #define TOK_ASM_weak TOK_WEAK1
816 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
817 /* only used for i386 asm opcodes definitions */
819 DEF(TOK_ASM_ ## x ## b, #x "b") \
820 DEF(TOK_ASM_ ## x ## w, #x "w") \
821 DEF(TOK_ASM_ ## x ## l, #x "l") \
822 DEF(TOK_ASM_ ## x, #x)
824 DEF(TOK_ASM_ ## x ## w, #x "w") \
825 DEF(TOK_ASM_ ## x ## l, #x "l") \
826 DEF(TOK_ASM_ ## x, #x)
827 #ifdef TCC_TARGET_X86_64
828 # define DEF_BWLQ(x) \
829 DEF(TOK_ASM_ ## x ## b, #x "b") \
830 DEF(TOK_ASM_ ## x ## w, #x "w") \
831 DEF(TOK_ASM_ ## x ## l, #x "l") \
832 DEF(TOK_ASM_ ## x ## q, #x "q") \
833 DEF(TOK_ASM_ ## x, #x)
834 # define DEF_WLQ(x) \
835 DEF(TOK_ASM_ ## x ## w, #x "w") \
836 DEF(TOK_ASM_ ## x ## l, #x "l") \
837 DEF(TOK_ASM_ ## x ## q, #x "q") \
838 DEF(TOK_ASM_ ## x, #x)
839 # define DEF_BWLX DEF_BWLQ
840 # define DEF_WLX DEF_WLQ
841 /* number of sizes + 1 */
844 # define DEF_BWLX DEF_BWL
845 # define DEF_WLX DEF_WL
846 /* number of sizes + 1 */
851 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
852 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
853 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
854 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
857 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
858 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
861 #define DEF_ASMTEST(x) \
893 #endif // defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
896 TOK_LAST
= TOK_IDENT
- 1,
897 #define DEF(id, str) id,
902 #define TOK_UIDENT TOK_DEFINE
905 #define snprintf _snprintf
906 #define vsnprintf _vsnprintf
908 #define strtold (long double)strtod
909 #define strtof (float)strtod
910 #define strtoll _strtoi64
911 #define strtoull _strtoui64
914 /* XXX: need to define this to use them in non ISOC99 context */
915 extern float strtof (const char *__nptr
, char **__endptr
);
916 extern long double strtold (const char *__nptr
, char **__endptr
);
920 #define IS_DIRSEP(c) (c == '/' || c == '\\')
921 #define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
922 #define PATHCMP stricmp
924 #define IS_DIRSEP(c) (c == '/')
925 #define IS_ABSPATH(p) IS_DIRSEP(p[0])
926 #define PATHCMP strcmp
935 /* space exlcuding newline */
936 static inline int is_space(int ch
)
938 return ch
== ' ' || ch
== '\t' || ch
== '\v' || ch
== '\f' || ch
== '\r';
941 static inline int isid(int c
)
943 return (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z') || c
== '_';
946 static inline int isnum(int c
)
948 return c
>= '0' && c
<= '9';
951 static inline int isoct(int c
)
953 return c
>= '0' && c
<= '7';
956 static inline int toup(int c
)
958 return (c
>= 'a' && c
<= 'z') ? c
- 'a' + 'A' : c
;
966 #define ST_INLN static inline
967 #define ST_FUNC static
968 #define ST_DATA static
972 #define ST_DATA extern
975 /* ------------ libtcc.c ------------ */
977 /* use GNU C extensions */
979 /* use Tiny C extensions */
981 /* XXX: get rid of this ASAP */
982 ST_DATA
struct TCCState
*tcc_state
;
984 #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
985 #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
986 #define AFF_PREPROCESS 0x0004 /* preprocess file */
988 /* public functions currently used by the tcc main function */
989 PUB_FUNC
char *pstrcpy(char *buf
, int buf_size
, const char *s
);
990 PUB_FUNC
char *pstrcat(char *buf
, int buf_size
, const char *s
);
991 PUB_FUNC
char *pstrncpy(char *out
, const char *in
, size_t num
);
992 PUB_FUNC
char *tcc_basename(const char *name
);
993 PUB_FUNC
char *tcc_fileextension (const char *name
);
994 PUB_FUNC
void tcc_free(void *ptr
);
995 PUB_FUNC
void *tcc_malloc(unsigned long size
);
996 PUB_FUNC
void *tcc_mallocz(unsigned long size
);
997 PUB_FUNC
void *tcc_realloc(void *ptr
, unsigned long size
);
998 PUB_FUNC
char *tcc_strdup(const char *str
);
999 #define free(p) use_tcc_free(p)
1000 #define malloc(s) use_tcc_malloc(s)
1001 #define realloc(p, s) use_tcc_realloc(p, s)
1003 #define strdup(s) use_tcc_strdup(s)
1004 PUB_FUNC
void tcc_memstats(void);
1005 PUB_FUNC
void dynarray_add(void ***ptab
, int *nb_ptr
, void *data
);
1006 PUB_FUNC
void dynarray_reset(void *pp
, int *n
);
1007 PUB_FUNC
void tcc_error_noabort(const char *fmt
, ...);
1008 PUB_FUNC
void tcc_error(const char *fmt
, ...);
1009 PUB_FUNC
void tcc_warning(const char *fmt
, ...);
1011 /* other utilities */
1012 PUB_FUNC
void cstr_ccat(CString
*cstr
, int ch
);
1013 PUB_FUNC
void cstr_cat(CString
*cstr
, const char *str
);
1014 PUB_FUNC
void cstr_wccat(CString
*cstr
, int ch
);
1015 PUB_FUNC
void cstr_new(CString
*cstr
);
1016 PUB_FUNC
void cstr_free(CString
*cstr
);
1017 PUB_FUNC
void cstr_reset(CString
*cstr
);
1019 ST_FUNC Section
*new_section(TCCState
*s1
, const char *name
, int sh_type
, int sh_flags
);
1020 ST_FUNC
void section_realloc(Section
*sec
, unsigned long new_size
);
1021 ST_FUNC
void *section_ptr_add(Section
*sec
, unsigned long size
);
1022 ST_FUNC
void section_reserve(Section
*sec
, unsigned long size
);
1023 ST_FUNC Section
*find_section(TCCState
*s1
, const char *name
);
1025 ST_FUNC
void put_extern_sym2(Sym
*sym
, Section
*section
, addr_t value
, unsigned long size
, int can_add_underscore
);
1026 ST_FUNC
void put_extern_sym(Sym
*sym
, Section
*section
, addr_t value
, unsigned long size
);
1027 ST_FUNC
void greloc(Section
*s
, Sym
*sym
, unsigned long offset
, int type
);
1029 ST_INLN
void sym_free(Sym
*sym
);
1030 ST_FUNC Sym
*sym_push2(Sym
**ps
, int v
, int t
, long c
);
1031 ST_FUNC Sym
*sym_find2(Sym
*s
, int v
);
1032 ST_FUNC Sym
*sym_push(int v
, CType
*type
, int r
, int c
);
1033 ST_FUNC
void sym_pop(Sym
**ptop
, Sym
*b
);
1034 ST_INLN Sym
*struct_find(int v
);
1035 ST_INLN Sym
*sym_find(int v
);
1036 ST_FUNC Sym
*global_identifier_push(int v
, int t
, int c
);
1038 ST_FUNC
void tcc_open_bf(TCCState
*s1
, const char *filename
, int initlen
);
1039 ST_FUNC
int tcc_open(TCCState
*s1
, const char *filename
);
1040 ST_FUNC
void tcc_close(void);
1042 ST_FUNC
int tcc_add_file_internal(TCCState
*s1
, const char *filename
, int flags
);
1043 ST_FUNC
int tcc_add_crt(TCCState
*s
, const char *filename
);
1044 #ifndef TCC_TARGET_PE
1045 ST_FUNC
int tcc_add_dll(TCCState
*s
, const char *filename
, int flags
);
1048 PUB_FUNC
int tcc_set_flag(TCCState
*s
, const char *flag_name
, int value
);
1049 PUB_FUNC
void tcc_print_stats(TCCState
*s
, int64_t total_time
);
1050 PUB_FUNC
char *tcc_default_target(TCCState
*s
, const char *default_file
);
1051 PUB_FUNC
void tcc_gen_makedeps(TCCState
*s
, const char *target
, const char *filename
);
1053 /* ------------ tccpp.c ------------ */
1055 ST_DATA
struct BufferedFile
*file
;
1056 ST_DATA
int ch
, tok
;
1057 ST_DATA CValue tokc
;
1058 ST_DATA
const int *macro_ptr
;
1059 ST_DATA
int parse_flags
;
1060 ST_DATA
int tok_flags
;
1061 ST_DATA CString tokcstr
; /* current parsed string, if any */
1063 /* display benchmark infos */
1064 ST_DATA
int total_lines
;
1065 ST_DATA
int total_bytes
;
1066 ST_DATA
int tok_ident
;
1067 ST_DATA TokenSym
**table_ident
;
1069 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1070 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1071 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1072 #define TOK_FLAG_EOF 0x0008 /* end of file */
1074 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1075 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1076 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1077 token. line feed is also
1079 #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
1080 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1082 ST_FUNC TokenSym
*tok_alloc(const char *str
, int len
);
1083 ST_FUNC
char *get_tok_str(int v
, CValue
*cv
);
1084 ST_FUNC
void save_parse_state(ParseState
*s
);
1085 ST_FUNC
void restore_parse_state(ParseState
*s
);
1086 ST_INLN
void tok_str_new(TokenString
*s
);
1087 ST_FUNC
void tok_str_free(int *str
);
1088 ST_FUNC
void tok_str_add(TokenString
*s
, int t
);
1089 ST_FUNC
void tok_str_add_tok(TokenString
*s
);
1090 ST_INLN
void define_push(int v
, int macro_type
, int *str
, Sym
*first_arg
);
1091 ST_FUNC
void define_undef(Sym
*s
);
1092 ST_INLN Sym
*define_find(int v
);
1093 ST_FUNC
void free_defines(Sym
*b
);
1094 ST_FUNC Sym
*label_find(int v
);
1095 ST_FUNC Sym
*label_push(Sym
**ptop
, int v
, int flags
);
1096 ST_FUNC
void label_pop(Sym
**ptop
, Sym
*slast
);
1097 ST_FUNC
void parse_define(void);
1098 ST_FUNC
void preprocess(int is_bof
);
1099 ST_FUNC
void next_nomacro(void);
1100 ST_FUNC
void next(void);
1101 ST_INLN
void unget_tok(int last_tok
);
1102 ST_FUNC
void preprocess_init(TCCState
*s1
);
1103 ST_FUNC
void preprocess_new();
1104 ST_FUNC
int tcc_preprocess(TCCState
*s1
);
1105 ST_FUNC
void skip(int c
);
1106 ST_FUNC
void expect(const char *msg
);
1108 /* ------------ tccgen.c ------------ */
1110 ST_DATA Section
*text_section
, *data_section
, *bss_section
; /* predefined sections */
1111 ST_DATA Section
*cur_text_section
; /* current section where function code is generated */
1112 #ifdef CONFIG_TCC_ASM
1113 ST_DATA Section
*last_text_section
; /* to handle .previous asm directive */
1115 #ifdef CONFIG_TCC_BCHECK
1116 /* bound check related sections */
1117 ST_DATA Section
*bounds_section
; /* contains global data bound description */
1118 ST_DATA Section
*lbounds_section
; /* contains local data bound description */
1120 /* symbol sections */
1121 ST_DATA Section
*symtab_section
, *strtab_section
;
1122 /* debug sections */
1123 ST_DATA Section
*stab_section
, *stabstr_section
;
1125 #define SYM_POOL_NB (8192 / sizeof(Sym))
1126 ST_DATA Sym
*sym_free_first
;
1127 ST_DATA
void **sym_pools
;
1128 ST_DATA
int nb_sym_pools
;
1130 ST_DATA Sym
*global_stack
;
1131 ST_DATA Sym
*local_stack
;
1132 ST_DATA Sym
*local_label_stack
;
1133 ST_DATA Sym
*global_label_stack
;
1134 ST_DATA Sym
*define_stack
;
1135 ST_DATA CType char_pointer_type
, func_old_type
, int_type
, size_type
;
1136 ST_DATA SValue __vstack
[1+/*to make bcheck happy*/ VSTACK_SIZE
], *vtop
;
1137 #define vstack (__vstack + 1)
1138 ST_DATA
int rsym
, anon_sym
, ind
, loc
;
1140 ST_DATA
int const_wanted
; /* true if constant wanted */
1141 ST_DATA
int nocode_wanted
; /* true if no code generation wanted for an expression */
1142 ST_DATA
int global_expr
; /* true if compound literals must be allocated globally (used during initializers parsing */
1143 ST_DATA CType func_vt
; /* current function return type (used by return instruction) */
1144 ST_DATA
int func_vc
;
1145 ST_DATA
int last_line_num
, last_ind
, func_ind
; /* debug last line number and pc */
1146 ST_DATA
char *funcname
;
1148 ST_INLN
int is_float(int t
);
1149 ST_FUNC
int ieee_finite(double d
);
1150 ST_FUNC
void test_lvalue(void);
1151 ST_FUNC
void swap(int *p
, int *q
);
1152 ST_FUNC
void vpushi(int v
);
1153 ST_FUNC Sym
*external_global_sym(int v
, CType
*type
, int r
);
1154 ST_FUNC
void vset(CType
*type
, int r
, int v
);
1155 ST_FUNC
void vswap(void);
1156 ST_FUNC
void vpush_global_sym(CType
*type
, int v
);
1157 ST_FUNC
void vrote(SValue
*e
, int n
);
1158 ST_FUNC
void vrott(int n
);
1159 ST_FUNC
void vrotb(int n
);
1160 #ifdef TCC_TARGET_ARM
1161 ST_FUNC
int get_reg_ex(int rc
, int rc2
);
1162 ST_FUNC
void lexpand_nr(void);
1164 ST_FUNC
void vpushv(SValue
*v
);
1165 ST_FUNC
void save_reg(int r
);
1166 ST_FUNC
int get_reg(int rc
);
1167 ST_FUNC
void save_regs(int n
);
1168 ST_FUNC
int gv(int rc
);
1169 ST_FUNC
void gv2(int rc1
, int rc2
);
1170 ST_FUNC
void vpop(void);
1171 ST_FUNC
void gen_op(int op
);
1172 ST_FUNC
int type_size(CType
*type
, int *a
);
1173 ST_FUNC
void mk_pointer(CType
*type
);
1174 ST_FUNC
void vstore(void);
1175 ST_FUNC
void inc(int post
, int c
);
1176 ST_FUNC
void parse_asm_str(CString
*astr
);
1177 ST_FUNC
int lvalue_type(int t
);
1178 ST_FUNC
void indir(void);
1179 ST_FUNC
void unary(void);
1180 ST_FUNC
void expr_prod(void);
1181 ST_FUNC
void expr_sum(void);
1182 ST_FUNC
void gexpr(void);
1183 ST_FUNC
int expr_const(void);
1184 ST_FUNC
void gen_inline_functions(void);
1185 ST_FUNC
void decl(int l
);
1186 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1187 ST_FUNC Sym
*get_sym_ref(CType
*type
, Section
*sec
, unsigned long offset
, unsigned long size
);
1190 /* ------------ tccelf.c ------------ */
1192 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1195 unsigned int n_strx
; /* index into string table of name */
1196 unsigned char n_type
; /* type of symbol */
1197 unsigned char n_other
; /* misc info (usually empty) */
1198 unsigned short n_desc
; /* description field */
1199 unsigned int n_value
; /* value of symbol */
1202 ST_FUNC Section
*new_symtab(TCCState
*s1
, const char *symtab_name
, int sh_type
, int sh_flags
, const char *strtab_name
, const char *hash_name
, int hash_sh_flags
);
1204 ST_FUNC
int put_elf_str(Section
*s
, const char *sym
);
1205 ST_FUNC
int put_elf_sym(Section
*s
, addr_t value
, unsigned long size
, int info
, int other
, int shndx
, const char *name
);
1206 ST_FUNC
int add_elf_sym(Section
*s
, addr_t value
, unsigned long size
, int info
, int other
, int sh_num
, const char *name
);
1207 ST_FUNC
int find_elf_sym(Section
*s
, const char *name
);
1208 ST_FUNC
void put_elf_reloc(Section
*symtab
, Section
*s
, unsigned long offset
, int type
, int symbol
);
1210 ST_FUNC
void put_stabs(const char *str
, int type
, int other
, int desc
, unsigned long value
);
1211 ST_FUNC
void put_stabs_r(const char *str
, int type
, int other
, int desc
, unsigned long value
, Section
*sec
, int sym_index
);
1212 ST_FUNC
void put_stabn(int type
, int other
, int desc
, int value
);
1213 ST_FUNC
void put_stabd(int type
, int other
, int desc
);
1215 ST_FUNC
void relocate_common_syms(void);
1216 ST_FUNC
void relocate_syms(TCCState
*s1
, int do_resolve
);
1217 ST_FUNC
void relocate_section(TCCState
*s1
, Section
*s
);
1219 ST_FUNC
void tcc_add_linker_symbols(TCCState
*s1
);
1220 ST_FUNC
int tcc_load_object_file(TCCState
*s1
, int fd
, unsigned long file_offset
);
1221 ST_FUNC
int tcc_load_archive(TCCState
*s1
, int fd
);
1222 ST_FUNC
void tcc_add_bcheck(TCCState
*s1
);
1224 ST_FUNC
void build_got_entries(TCCState
*s1
);
1225 ST_FUNC
void tcc_add_runtime(TCCState
*s1
);
1227 ST_FUNC addr_t
get_elf_sym_addr(TCCState
*s
, const char *name
, int err
);
1228 #ifdef TCC_IS_NATIVE
1229 ST_FUNC
void *tcc_get_symbol_err(TCCState
*s
, const char *name
);
1232 #ifndef TCC_TARGET_PE
1233 ST_FUNC
int tcc_load_dll(TCCState
*s1
, int fd
, const char *filename
, int level
);
1234 ST_FUNC
int tcc_load_ldscript(TCCState
*s1
);
1235 ST_FUNC
uint8_t *parse_comment(uint8_t *p
);
1236 ST_FUNC
void minp(void);
1237 ST_INLN
void inp(void);
1238 ST_FUNC
int handle_eob(void);
1241 /* ------------ xxx-gen.c ------------ */
1243 ST_FUNC
void gsym_addr(int t
, int a
);
1244 ST_FUNC
void gsym(int t
);
1245 ST_FUNC
void load(int r
, SValue
*sv
);
1246 ST_FUNC
void store(int r
, SValue
*v
);
1247 ST_FUNC
void gfunc_call(int nb_args
);
1248 ST_FUNC
void gfunc_prolog(CType
*func_type
);
1249 ST_FUNC
void gfunc_epilog(void);
1250 ST_FUNC
int gjmp(int t
);
1251 ST_FUNC
void gjmp_addr(int a
);
1252 ST_FUNC
int gtst(int inv
, int t
);
1253 ST_FUNC
void gen_opi(int op
);
1254 ST_FUNC
void gen_opf(int op
);
1255 ST_FUNC
void gen_cvt_ftoi(int t
);
1256 ST_FUNC
void gen_cvt_ftof(int t
);
1257 ST_FUNC
void ggoto(void);
1258 #ifndef TCC_TARGET_C67
1259 ST_FUNC
void o(unsigned int c
);
1261 #ifndef TCC_TARGET_ARM
1262 ST_FUNC
void gen_cvt_itof(int t
);
1265 /* ------------ i386-gen.c ------------ */
1266 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1267 ST_FUNC
void g(int c
);
1268 ST_FUNC
int oad(int c
, int s
);
1269 ST_FUNC
void gen_le16(int c
);
1270 ST_FUNC
void gen_le32(int c
);
1271 ST_FUNC
void gen_addr32(int r
, Sym
*sym
, int c
);
1272 ST_FUNC
void gen_addrpc32(int r
, Sym
*sym
, int c
);
1275 #ifdef CONFIG_TCC_BCHECK
1276 ST_FUNC
void gen_bounded_ptr_add(void);
1277 ST_FUNC
void gen_bounded_ptr_deref(void);
1280 /* ------------ x86_64-gen.c ------------ */
1281 #ifdef TCC_TARGET_X86_64
1282 ST_FUNC
void gen_addr64(int r
, Sym
*sym
, int64_t c
);
1285 /* ------------ arm-gen.c ------------ */
1286 #ifdef TCC_TARGET_ARM
1287 ST_FUNC
uint32_t encbranch(int pos
, int addr
, int fail
);
1288 ST_FUNC
void gen_cvt_itof1(int t
);
1291 /* ------------ c67-gen.c ------------ */
1292 #ifdef TCC_TARGET_C67
1295 /* ------------ tcccoff.c ------------ */
1297 #ifdef TCC_TARGET_COFF
1298 ST_FUNC
int tcc_output_coff(TCCState
*s1
, FILE *f
);
1299 ST_FUNC
int tcc_load_coff(TCCState
* s1
, int fd
);
1302 /* ------------ tccasm.c ------------ */
1303 ST_FUNC
void asm_instr(void);
1304 ST_FUNC
void asm_global_instr(void);
1306 #ifdef CONFIG_TCC_ASM
1307 ST_FUNC
int find_constraint(ASMOperand
*operands
, int nb_operands
, const char *name
, const char **pp
);
1308 ST_FUNC
void asm_expr(TCCState
*s1
, ExprValue
*pe
);
1309 ST_FUNC
int asm_int_expr(TCCState
*s1
);
1310 ST_FUNC
int tcc_assemble(TCCState
*s1
, int do_preprocess
);
1311 /* ------------ i386-asm.c ------------ */
1312 ST_FUNC
void gen_expr32(ExprValue
*pe
);
1313 ST_FUNC
void asm_opcode(TCCState
*s1
, int opcode
);
1314 ST_FUNC
void asm_compute_constraints(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, const uint8_t *clobber_regs
, int *pout_reg
);
1315 ST_FUNC
void subst_asm_operand(CString
*add_str
, SValue
*sv
, int modifier
);
1316 ST_FUNC
void asm_gen_code(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, int is_output
, uint8_t *clobber_regs
, int out_reg
);
1317 ST_FUNC
void asm_clobber(uint8_t *clobber_regs
, const char *str
);
1319 /* ------------ tccpe.c -------------- */
1320 #ifdef TCC_TARGET_PE
1321 ST_FUNC
int pe_load_file(struct TCCState
*s1
, const char *filename
, int fd
);
1322 ST_FUNC
int pe_output_file(TCCState
* s1
, const char *filename
);
1323 ST_FUNC
int pe_putimport(TCCState
*s1
, int dllindex
, const char *name
, addr_t value
);
1324 ST_FUNC SValue
*pe_getimport(SValue
*sv
, SValue
*v2
);
1326 ST_FUNC
char *get_export_names(FILE *fp
);
1327 #ifdef TCC_TARGET_X86_64
1328 ST_FUNC
void pe_add_unwind_data(unsigned start
, unsigned end
, unsigned stack
);
1332 /* ------------ tccrun.c ----------------- */
1333 #ifdef TCC_IS_NATIVE
1334 #ifdef CONFIG_TCC_STATIC
1335 #define RTLD_LAZY 0x001
1336 #define RTLD_NOW 0x002
1337 #define RTLD_GLOBAL 0x100
1338 #define RTLD_DEFAULT NULL
1339 /* dummy function for profiling */
1340 ST_FUNC
void *dlopen(const char *filename
, int flag
);
1341 ST_FUNC
void dlclose(void *p
);
1342 //ST_FUNC const char *dlerror(void);
1343 ST_FUNC
void *resolve_sym(TCCState
*s1
, const char *symbol
);
1344 #elif !defined _WIN32
1345 ST_FUNC
void *resolve_sym(TCCState
*s1
, const char *symbol
);
1348 #ifdef CONFIG_TCC_BACKTRACE
1349 ST_DATA
int rt_num_callers
;
1350 ST_DATA
const char **rt_bound_error_msg
;
1351 ST_DATA
void *rt_prog_main
;
1352 PUB_FUNC
void tcc_set_num_callers(int n
);
1356 /********************************************************/
1357 /* include the target specific definitions */
1359 #define TARGET_DEFS_ONLY
1360 #ifdef TCC_TARGET_I386
1361 #include "i386-gen.c"
1363 #ifdef TCC_TARGET_X86_64
1364 #include "x86_64-gen.c"
1366 #ifdef TCC_TARGET_ARM
1367 #include "arm-gen.c"
1369 #ifdef TCC_TARGET_C67
1371 #include "c67-gen.c"
1373 #undef TARGET_DEFS_ONLY
1375 ST_DATA
const int reg_classes
[];
1377 /********************************************************/
1380 #define ST_DATA static
1384 /********************************************************/