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
27 #define CONFIG_TCC_STATIC
44 #include <sys/timeb.h>
46 #define inline __inline
53 #include <sys/ucontext.h>
57 #endif /* !CONFIG_TCCBOOT */
74 /* preprocessor debug */
76 /* include file 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
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 */
101 #if defined(_WIN32) && !defined(TCC_TARGET_PE)
102 #define CONFIG_TCC_STATIC
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
111 /* object format selection */
112 #if defined(TCC_TARGET_C67)
113 #define TCC_TARGET_COFF
116 #if !defined(_WIN32) && !defined(CONFIG_TCCBOOT)
117 #define CONFIG_TCC_BACKTRACE
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 */
153 typedef unsigned short nwchar_t
;
155 typedef int nwchar_t
;
158 typedef struct CString
{
159 int size
; /* size in bytes */
160 void *data
; /* either 'char *' or 'nwchar_t *' */
162 void *data_allocated
; /* if non NULL, data has been malloced */
165 /* type definition */
166 typedef struct CType
{
172 typedef union CValue
{
178 unsigned int ul
; /* address (should be unsigned long on 64 bit cpu) */
180 unsigned long long ull
;
181 struct CString
*cstr
;
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) */
196 /* symbol management */
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 */
207 /* section definition */
208 /* XXX: use directly ELF structure for parameters ? */
209 /* special flag to indicate that the section should not be linked to
211 #define SHF_PRIVATE 0x80000000
213 typedef struct Section
{
214 unsigned long data_offset
; /* current data offset */
215 unsigned char *data
; /* section data */
216 unsigned long data_allocated
; /* used for realloc() handling */
217 int sh_name
; /* elf section name (only used during output) */
218 int sh_num
; /* elf section number */
219 int sh_type
; /* elf section type */
220 int sh_flags
; /* elf section flags */
221 int sh_info
; /* elf section info */
222 int sh_addralign
; /* elf section alignment */
223 int sh_entsize
; /* elf entry size */
224 unsigned long sh_size
; /* section size (only used during output) */
225 unsigned long sh_addr
; /* address at which the section is relocated */
226 unsigned long sh_offset
; /* file offset */
227 int nb_hashed_syms
; /* used to resize the hash table */
228 struct Section
*link
; /* link to another section */
229 struct Section
*reloc
; /* corresponding section for relocation, if any */
230 struct Section
*hash
; /* hash table for symbols */
231 struct Section
*next
;
232 char name
[1]; /* section name */
235 typedef struct DLLReference
{
241 /* GNUC attribute definition */
242 typedef struct AttributeDef
{
246 int func_attr
; /* calling convention, exports, ... */
249 /* -------------------------------------------------- */
250 /* gr: wrappers for casting sym->r for other purposes */
258 #define FUNC_CALL(r) (((func_attr_t*)&(r))->func_call)
259 #define FUNC_EXPORT(r) (((func_attr_t*)&(r))->func_export)
260 #define FUNC_ARGS(r) (((func_attr_t*)&(r))->func_args)
261 #define INLINE_DEF(r) (*(int **)&(r))
262 /* -------------------------------------------------- */
264 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
265 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
266 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
268 /* stored in 'Sym.c' field */
269 #define FUNC_NEW 1 /* ansi function prototype */
270 #define FUNC_OLD 2 /* old function prototype */
271 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
273 /* stored in 'Sym.r' field */
274 #define FUNC_CDECL 0 /* standard c call */
275 #define FUNC_STDCALL 1 /* pascal c call */
276 #define FUNC_FASTCALL1 2 /* first param in %eax */
277 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
278 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
279 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
281 /* field 'Sym.t' for macros */
282 #define MACRO_OBJ 0 /* object like macro */
283 #define MACRO_FUNC 1 /* function like macro */
285 /* field 'Sym.r' for C labels */
286 #define LABEL_DEFINED 0 /* label is defined */
287 #define LABEL_FORWARD 1 /* label is forward defined */
288 #define LABEL_DECLARED 2 /* label is declared but never used */
290 /* type_decl() types */
291 #define TYPE_ABSTRACT 1 /* type without variable */
292 #define TYPE_DIRECT 2 /* type with variable */
294 #define IO_BUF_SIZE 8192
296 typedef struct BufferedFile
{
300 int line_num
; /* current line number - here to simplify code */
301 int ifndef_macro
; /* #ifndef macro / #endif search */
302 int ifndef_macro_saved
; /* saved ifndef_macro */
303 int *ifdef_stack_ptr
; /* ifdef_stack value at the start of the file */
304 char inc_type
; /* type of include */
305 char inc_filename
[512]; /* filename specified by the user */
306 char filename
[1024]; /* current filename - here to simplify code */
307 unsigned char buffer
[IO_BUF_SIZE
+ 1]; /* extra size for CH_EOB char */
310 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
311 #define CH_EOF (-1) /* end of file */
313 /* parsing state (used to save parser state to reparse part of the
314 source several times) */
315 typedef struct ParseState
{
322 /* used to record tokens */
323 typedef struct TokenString
{
330 /* include file cache, used to find files faster and also to eliminate
331 inclusion if the include file is protected by #ifndef ... #endif */
332 typedef struct CachedInclude
{
334 int hash_next
; /* -1 if none */
335 char type
; /* '"' or '>' to give include type */
336 char filename
[1]; /* path specified in #include */
339 #define CACHED_INCLUDES_HASH_SIZE 512
344 BufferedFile
**include_stack_ptr
;
345 int *ifdef_stack_ptr
;
347 /* include file handling */
348 char **include_paths
;
349 int nb_include_paths
;
350 char **sysinclude_paths
;
351 int nb_sysinclude_paths
;
352 CachedInclude
**cached_includes
;
353 int nb_cached_includes
;
355 char **library_paths
;
356 int nb_library_paths
;
358 /* array of all loaded dlls (including those referenced by loaded
360 DLLReference
**loaded_dlls
;
365 int nb_sections
; /* number of sections, including first dummy section */
367 Section
**priv_sections
;
368 int nb_priv_sections
; /* number of private sections */
373 unsigned long *got_offsets
;
375 /* give the correspondance from symtab indexes to dynsym indexes */
376 int *symtab_to_dynsym
;
378 /* temporary dynamic symbol sections (for dll loading) */
379 Section
*dynsymtab_section
;
380 /* exported dynamic symbol section */
383 int nostdinc
; /* if true, no standard headers are added */
384 int nostdlib
; /* if true, no standard libraries are added */
386 int nocommon
; /* if true, do not use common symbols for .bss data */
388 /* if true, static linking is performed */
391 /* soname as specified on the command line (-soname) */
394 /* if true, all symbols are exported */
397 /* if true, only link in referenced objects from archive */
400 /* address of text section */
401 unsigned long text_addr
;
404 /* output format, see TCC_OUTPUT_FORMAT_xxx */
407 /* C language options */
408 int char_is_unsigned
;
409 int leading_underscore
;
411 /* warning switches */
412 int warn_write_strings
;
413 int warn_unsupported
;
416 int warn_implicit_function_declaration
;
420 void (*error_func
)(void *opaque
, const char *msg
);
421 int error_set_jmp_enabled
;
422 jmp_buf error_jmp_buf
;
425 /* tiny assembler state */
428 /* see include_stack_ptr */
429 BufferedFile
*include_stack
[INCLUDE_STACK_SIZE
];
431 /* see ifdef_stack_ptr */
432 int ifdef_stack
[IFDEF_STACK_SIZE
];
434 /* see cached_includes */
435 int cached_includes_hash
[CACHED_INCLUDES_HASH_SIZE
];
438 int pack_stack
[PACK_STACK_SIZE
];
441 /* output file for preprocessing */
444 /* for tcc_relocate */
447 #ifdef TCC_TARGET_X86_64
448 /* write PLT and GOT here */
449 char *runtime_plt_and_got
;
450 unsigned int runtime_plt_and_got_offset
;
454 /* The current value can be: */
455 #define VT_VALMASK 0x00ff
456 #define VT_CONST 0x00f0 /* constant in vc
457 (must be first non register value) */
458 #define VT_LLOCAL 0x00f1 /* lvalue, offset on stack */
459 #define VT_LOCAL 0x00f2 /* offset on stack */
460 #define VT_CMP 0x00f3 /* the value is stored in processor flags (in vc) */
461 #define VT_JMP 0x00f4 /* value is the consequence of jmp true (even) */
462 #define VT_JMPI 0x00f5 /* value is the consequence of jmp false (odd) */
463 #define VT_LVAL 0x0100 /* var is an lvalue */
464 #define VT_SYM 0x0200 /* a symbol value is added */
465 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
466 char/short stored in integer registers) */
467 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
468 dereferencing value */
469 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
470 bounding function call point is in vc */
471 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
472 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
473 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
474 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
477 #define VT_INT 0 /* integer type */
478 #define VT_BYTE 1 /* signed byte type */
479 #define VT_SHORT 2 /* short type */
480 #define VT_VOID 3 /* void type */
481 #define VT_PTR 4 /* pointer */
482 #define VT_ENUM 5 /* enum definition */
483 #define VT_FUNC 6 /* function type */
484 #define VT_STRUCT 7 /* struct/union definition */
485 #define VT_FLOAT 8 /* IEEE float */
486 #define VT_DOUBLE 9 /* IEEE double */
487 #define VT_LDOUBLE 10 /* IEEE long double */
488 #define VT_BOOL 11 /* ISOC99 boolean type */
489 #define VT_LLONG 12 /* 64 bit integer */
490 #define VT_LONG 13 /* long integer (NEVER USED as type, only
492 #define VT_BTYPE 0x000f /* mask for basic type */
493 #define VT_UNSIGNED 0x0010 /* unsigned type */
494 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
495 #define VT_BITFIELD 0x0040 /* bitfield modifier */
496 #define VT_CONSTANT 0x0800 /* const modifier */
497 #define VT_VOLATILE 0x1000 /* volatile modifier */
498 #define VT_SIGNED 0x2000 /* signed type */
501 #define VT_EXTERN 0x00000080 /* extern definition */
502 #define VT_STATIC 0x00000100 /* static variable */
503 #define VT_TYPEDEF 0x00000200 /* typedef definition */
504 #define VT_INLINE 0x00000400 /* inline definition */
506 #define VT_STRUCT_SHIFT 16 /* shift for bitfield shift values */
508 /* type mask (except storage) */
509 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
510 #define VT_TYPE (~(VT_STORAGE))
514 /* warning: the following compare tokens depend on i386 asm code */
521 #define TOK_Nset 0x98
522 #define TOK_Nclear 0x99
528 #define TOK_LAND 0xa0
532 #define TOK_MID 0xa3 /* inc/dec, to void constant */
534 #define TOK_UDIV 0xb0 /* unsigned division */
535 #define TOK_UMOD 0xb1 /* unsigned modulo */
536 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
537 #define TOK_CINT 0xb3 /* number in tokc */
538 #define TOK_CCHAR 0xb4 /* char constant in tokc */
539 #define TOK_STR 0xb5 /* pointer to string in tokc */
540 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
541 #define TOK_LCHAR 0xb7
542 #define TOK_LSTR 0xb8
543 #define TOK_CFLOAT 0xb9 /* float constant */
544 #define TOK_LINENUM 0xba /* line number info */
545 #define TOK_CDOUBLE 0xc0 /* double constant */
546 #define TOK_CLDOUBLE 0xc1 /* long double constant */
547 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
548 #define TOK_ADDC1 0xc3 /* add with carry generation */
549 #define TOK_ADDC2 0xc4 /* add with carry use */
550 #define TOK_SUBC1 0xc5 /* add with carry generation */
551 #define TOK_SUBC2 0xc6 /* add with carry use */
552 #define TOK_CUINT 0xc8 /* unsigned int constant */
553 #define TOK_CLLONG 0xc9 /* long long constant */
554 #define TOK_CULLONG 0xca /* unsigned long long constant */
555 #define TOK_ARROW 0xcb
556 #define TOK_DOTS 0xcc /* three dots */
557 #define TOK_SHR 0xcd /* unsigned shift right */
558 #define TOK_PPNUM 0xce /* preprocessor number */
560 #define TOK_SHL 0x01 /* shift left */
561 #define TOK_SAR 0x02 /* signed shift right */
563 /* assignement operators : normal operator or 0x80 */
564 #define TOK_A_MOD 0xa5
565 #define TOK_A_AND 0xa6
566 #define TOK_A_MUL 0xaa
567 #define TOK_A_ADD 0xab
568 #define TOK_A_SUB 0xad
569 #define TOK_A_DIV 0xaf
570 #define TOK_A_XOR 0xde
571 #define TOK_A_OR 0xfc
572 #define TOK_A_SHL 0x81
573 #define TOK_A_SAR 0x82
576 #define offsetof(type, field) ((size_t) &((type *)0)->field)
580 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
583 /* WARNING: the content of this string encodes token numbers */
584 static char tok_two_chars
[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266";
586 #define TOK_EOF (-1) /* end of file */
587 #define TOK_LINEFEED 10 /* line feed */
589 /* all identificators and strings have token above that */
590 #define TOK_IDENT 256
592 /* only used for i386 asm opcodes definitions */
593 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
596 DEF(TOK_ASM_ ## x ## b, #x "b") \
597 DEF(TOK_ASM_ ## x ## w, #x "w") \
598 DEF(TOK_ASM_ ## x ## l, #x "l") \
599 DEF(TOK_ASM_ ## x, #x)
602 DEF(TOK_ASM_ ## x ## w, #x "w") \
603 DEF(TOK_ASM_ ## x ## l, #x "l") \
604 DEF(TOK_ASM_ ## x, #x)
607 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
608 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
609 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
610 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
613 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
614 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
617 #define DEF_ASMTEST(x) \
649 #define TOK_ASM_int TOK_INT
652 TOK_LAST
= TOK_IDENT
- 1,
653 #define DEF(id, str) id,
658 static const char tcc_keywords
[] =
659 #define DEF(id, str) str "\0"
664 #define TOK_UIDENT TOK_DEFINE
667 #define snprintf _snprintf
668 #define vsnprintf _vsnprintf
670 #define strtold (long double)strtod
671 #define strtof (float)strtod
672 #define strtoll (long long)strtol
674 #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
675 || defined(__OpenBSD__)
676 /* currently incorrect */
677 long double strtold(const char *nptr
, char **endptr
)
679 return (long double)strtod(nptr
, endptr
);
681 float strtof(const char *nptr
, char **endptr
)
683 return (float)strtod(nptr
, endptr
);
686 /* XXX: need to define this to use them in non ISOC99 context */
687 extern float strtof (const char *__nptr
, char **__endptr
);
688 extern long double strtold (const char *__nptr
, char **__endptr
);
691 static char *pstrcpy(char *buf
, int buf_size
, const char *s
);
692 static char *pstrcat(char *buf
, int buf_size
, const char *s
);
693 static char *tcc_basename(const char *name
);
694 static char *tcc_fileextension (const char *p
);
696 static void next(void);
697 static void next_nomacro(void);
698 static void next_nomacro_spc(void);
699 static void parse_expr_type(CType
*type
);
700 static void expr_type(CType
*type
);
701 static void unary_type(CType
*type
);
702 static void block(int *bsym
, int *csym
, int *case_sym
, int *def_sym
,
703 int case_reg
, int is_expr
);
704 static int expr_const(void);
705 static void expr_eq(void);
706 static void gexpr(void);
707 static void gen_inline_functions(void);
708 static void decl(int l
);
709 static void decl_initializer(CType
*type
, Section
*sec
, unsigned long c
,
710 int first
, int size_only
);
711 static void decl_initializer_alloc(CType
*type
, AttributeDef
*ad
, int r
,
712 int has_init
, int v
, int scope
);
714 void gv2(int rc1
, int rc2
);
715 void move_reg(int r
, int s
);
716 void save_regs(int n
);
717 void save_reg(int r
);
722 int get_reg_ex(int rc
,int rc2
);
725 struct macro_level
*prev
;
729 static void macro_subst(TokenString
*tok_str
, Sym
**nested_list
,
730 const int *macro_str
, struct macro_level
**can_read_stream
);
732 void force_charshort_cast(int t
);
733 static void gen_cast(CType
*type
);
735 static Sym
*sym_find(int v
);
736 static Sym
*sym_push(int v
, CType
*type
, int r
, int c
);
739 static int type_size(CType
*type
, int *a
);
740 static inline CType
*pointed_type(CType
*type
);
741 static int pointed_size(CType
*type
);
742 static int lvalue_type(int t
);
743 static int parse_btype(CType
*type
, AttributeDef
*ad
);
744 static void type_decl(CType
*type
, AttributeDef
*ad
, int *v
, int td
);
745 static int compare_types(CType
*type1
, CType
*type2
, int unqualified
);
746 static int is_compatible_types(CType
*type1
, CType
*type2
);
747 static int is_compatible_parameter_types(CType
*type1
, CType
*type2
);
749 int ieee_finite(double d
);
750 void error(const char *fmt
, ...);
752 void vpushll(long long v
);
755 void lexpand_nr(void);
756 static void vpush_global_sym(CType
*type
, int v
);
757 void vset(CType
*type
, int r
, int v
);
758 void type_to_str(char *buf
, int buf_size
,
759 CType
*type
, const char *varstr
);
760 char *get_tok_str(int v
, CValue
*cv
);
761 static Sym
*get_sym_ref(CType
*type
, Section
*sec
,
762 unsigned long offset
, unsigned long size
);
763 static Sym
*external_global_sym(int v
, CType
*type
, int r
);
765 /* section generation */
766 static void section_realloc(Section
*sec
, unsigned long new_size
);
767 static void *section_ptr_add(Section
*sec
, unsigned long size
);
768 static void put_extern_sym(Sym
*sym
, Section
*section
,
769 unsigned long value
, unsigned long size
);
770 static void greloc(Section
*s
, Sym
*sym
, unsigned long addr
, int type
);
771 static int put_elf_str(Section
*s
, const char *sym
);
772 static int put_elf_sym(Section
*s
,
773 unsigned long value
, unsigned long size
,
774 int info
, int other
, int shndx
, const char *name
);
775 static int add_elf_sym(Section
*s
, unsigned long value
, unsigned long size
,
776 int info
, int other
, int sh_num
, const char *name
);
777 static void put_elf_reloc(Section
*symtab
, Section
*s
, unsigned long offset
,
778 int type
, int symbol
);
779 static void put_stabs(const char *str
, int type
, int other
, int desc
,
780 unsigned long value
);
781 static void put_stabs_r(const char *str
, int type
, int other
, int desc
,
782 unsigned long value
, Section
*sec
, int sym_index
);
783 static void put_stabn(int type
, int other
, int desc
, int value
);
784 static void put_stabd(int type
, int other
, int desc
);
785 static int tcc_add_dll(TCCState
*s
, const char *filename
, int flags
);
787 #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
788 #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
789 #define AFF_PREPROCESS 0x0004 /* preprocess file */
790 static int tcc_add_file_internal(TCCState
*s
, const char *filename
, int flags
);
793 int tcc_output_coff(TCCState
*s1
, FILE *f
);
796 void *resolve_sym(TCCState
*s1
, const char *sym
, int type
);
797 int pe_load_def_file(struct TCCState
*s1
, int fd
);
798 int pe_test_res_file(void *v
, int size
);
799 int pe_load_res_file(struct TCCState
*s1
, int fd
);
800 void pe_add_runtime(struct TCCState
*s1
);
801 void pe_guess_outfile(char *objfilename
, int output_type
);
802 int pe_output_file(struct TCCState
*s1
, const char *filename
);
806 #ifdef CONFIG_TCC_ASM
808 typedef struct ExprValue
{
813 #define MAX_ASM_OPERANDS 30
815 typedef struct ASMOperand
{
816 int id
; /* GCC 3 optionnal identifier (0 if number only supported */
818 char asm_str
[16]; /* computed asm string for operand */
819 SValue
*vt
; /* C value of the expression */
820 int ref_index
; /* if >= 0, gives reference to a output constraint */
821 int input_index
; /* if >= 0, gives reference to an input constraint */
822 int priority
; /* priority, used to assign registers */
823 int reg
; /* if >= 0, register number used for this operand */
824 int is_llong
; /* true if double register value */
825 int is_memory
; /* true if memory operand */
826 int is_rw
; /* for '+' modifier */
829 static void asm_expr(TCCState
*s1
, ExprValue
*pe
);
830 static int asm_int_expr(TCCState
*s1
);
831 static int find_constraint(ASMOperand
*operands
, int nb_operands
,
832 const char *name
, const char **pp
);
834 static int tcc_assemble(TCCState
*s1
, int do_preprocess
);
838 static void asm_instr(void);
839 static void asm_global_instr(void);
841 /* true if float/double/long double type */
842 static inline int is_float(int t
)
846 return bt
== VT_LDOUBLE
|| bt
== VT_DOUBLE
|| bt
== VT_FLOAT
;