Avoid crash with "Avoid a crash with weak symbols for "make test""
[tinycc.git] / tcc.h
blobbb3eb9f1aee272eea17ea64d6ee737cb02bd43dc
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 #ifndef _TCC_H
22 #define _TCC_H
24 #define _GNU_SOURCE
25 #include "config.h"
27 #ifdef CONFIG_TCCBOOT
29 #include "tccboot.h"
30 #define CONFIG_TCC_STATIC
32 #else
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <math.h>
40 #include <signal.h>
41 #include <fcntl.h>
42 #include <setjmp.h>
43 #include <time.h>
45 #ifdef _WIN32
46 #include <windows.h>
47 #include <sys/timeb.h>
48 #include <io.h> /* open, close etc. */
49 #include <direct.h> /* getcwd */
50 #define inline __inline
51 #define inp next_inp
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 #include <dlfcn.h>
63 #endif
65 #endif /* !CONFIG_TCCBOOT */
67 #ifndef uplong
68 #define uplong unsigned long
69 #endif
71 #ifndef PAGESIZE
72 #define PAGESIZE 4096
73 #endif
75 #include "elf.h"
76 #include "stab.h"
78 #ifndef O_BINARY
79 #define O_BINARY 0
80 #endif
82 #include "libtcc.h"
84 /* parser debug */
85 //#define PARSE_DEBUG
86 /* preprocessor debug */
87 //#define PP_DEBUG
88 /* include file debug */
89 //#define INC_DEBUG
91 //#define MEM_DEBUG
93 /* assembler debug */
94 //#define ASM_DEBUG
96 /* target selection */
97 //#define TCC_TARGET_I386 /* i386 code generator */
98 //#define TCC_TARGET_ARM /* ARMv4 code generator */
99 //#define TCC_TARGET_C67 /* TMS320C67xx code generator */
100 //#define TCC_TARGET_X86_64 /* x86-64 code generator */
102 /* default target is I386 */
103 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
104 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
105 #define TCC_TARGET_I386
106 #endif
108 #if !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
109 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
110 #define CONFIG_TCC_BCHECK /* enable bound checking code */
111 #endif
113 #if defined(_WIN32) && !defined(TCC_TARGET_PE)
114 #define CONFIG_TCC_STATIC
115 #endif
117 /* define it to include assembler support */
118 #if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67)
119 #define CONFIG_TCC_ASM
120 #endif
122 /* object format selection */
123 #if defined(TCC_TARGET_C67)
124 #define TCC_TARGET_COFF
125 #endif
127 #if !defined(CONFIG_TCCBOOT)
128 #define CONFIG_TCC_BACKTRACE
129 #endif
131 #define FALSE 0
132 #define false 0
133 #define TRUE 1
134 #define true 1
135 typedef int BOOL;
137 /* path to find crt1.o, crti.o and crtn.o. Only needed when generating
138 executables or dlls */
139 #if defined(TCC_TARGET_X86_64_CENTOS)
140 # define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib64"
141 #else
142 # define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib"
143 #endif
145 #define INCLUDE_STACK_SIZE 32
146 #define IFDEF_STACK_SIZE 64
147 #define VSTACK_SIZE 256
148 #define STRING_MAX_SIZE 1024
149 #define PACK_STACK_SIZE 8
151 #define TOK_HASH_SIZE 8192 /* must be a power of two */
152 #define TOK_ALLOC_INCR 512 /* must be a power of two */
153 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
155 /* token symbol management */
156 typedef struct TokenSym {
157 struct TokenSym *hash_next;
158 struct Sym *sym_define; /* direct pointer to define */
159 struct Sym *sym_label; /* direct pointer to label */
160 struct Sym *sym_struct; /* direct pointer to structure */
161 struct Sym *sym_identifier; /* direct pointer to identifier */
162 int tok; /* token number */
163 int len;
164 char str[1];
165 } TokenSym;
167 #ifdef TCC_TARGET_PE
168 typedef unsigned short nwchar_t;
169 #else
170 typedef int nwchar_t;
171 #endif
173 typedef struct CString {
174 int size; /* size in bytes */
175 void *data; /* either 'char *' or 'nwchar_t *' */
176 int size_allocated;
177 void *data_allocated; /* if non NULL, data has been malloced */
178 } CString;
180 /* type definition */
181 typedef struct CType {
182 int t;
183 struct Sym *ref;
184 } CType;
186 /* constant value */
187 typedef union CValue {
188 long double ld;
189 double d;
190 float f;
191 int i;
192 unsigned int ui;
193 unsigned int ul; /* address (should be unsigned long on 64 bit cpu) */
194 long long ll;
195 unsigned long long ull;
196 struct CString *cstr;
197 void *ptr;
198 int tab[2];
199 } CValue;
201 /* value on stack */
202 typedef struct SValue {
203 CType type; /* type */
204 unsigned short r; /* register + flags */
205 unsigned short r2; /* second register, used for 'long long'
206 type. If not used, set to VT_CONST */
207 CValue c; /* constant, if VT_CONST */
208 struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */
209 } SValue;
211 /* symbol management */
212 typedef struct Sym {
213 int v; /* symbol token */
214 long r; /* associated register */
215 union {
216 long c; /* associated number */
217 int *d; /* define token stream */
219 CType type; /* associated type */
220 union {
221 struct Sym *next; /* next related symbol */
222 long jnext; /* next jump label */
224 struct Sym *prev; /* prev symbol in stack */
225 struct Sym *prev_tok; /* previous symbol for this token */
226 } Sym;
228 /* section definition */
229 /* XXX: use directly ELF structure for parameters ? */
230 /* special flag to indicate that the section should not be linked to
231 the other ones */
232 #define SHF_PRIVATE 0x80000000
234 /* special flag, too */
235 #define SECTION_ABS ((void *)1)
237 typedef struct Section {
238 unsigned long data_offset; /* current data offset */
239 unsigned char *data; /* section data */
240 unsigned long data_allocated; /* used for realloc() handling */
241 int sh_name; /* elf section name (only used during output) */
242 int sh_num; /* elf section number */
243 int sh_type; /* elf section type */
244 int sh_flags; /* elf section flags */
245 int sh_info; /* elf section info */
246 int sh_addralign; /* elf section alignment */
247 int sh_entsize; /* elf entry size */
248 unsigned long sh_size; /* section size (only used during output) */
249 unsigned long sh_addr; /* address at which the section is relocated */
250 unsigned long sh_offset; /* file offset */
251 int nb_hashed_syms; /* used to resize the hash table */
252 struct Section *link; /* link to another section */
253 struct Section *reloc; /* corresponding section for relocation, if any */
254 struct Section *hash; /* hash table for symbols */
255 struct Section *next;
256 char name[1]; /* section name */
257 } Section;
259 typedef struct DLLReference {
260 int level;
261 void *handle;
262 char name[1];
263 } DLLReference;
265 /* GNUC attribute definition */
266 typedef struct AttributeDef {
267 unsigned
268 func_call : 3, /* calling convention (0..5), see below */
269 aligned : 5, /* alignement (0..16) */
270 packed : 1,
271 func_export : 1,
272 func_import : 1,
273 func_args : 5,
274 mode : 4,
275 weak : 1,
276 fill : 11;
277 struct Section *section;
278 } AttributeDef;
280 /* gr: wrappers for casting sym->r for other purposes */
281 #define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
282 #define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
283 #define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
284 #define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
285 #define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
286 #define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
287 #define FUNC_WEAK(r) (((AttributeDef*)&(r))->weak)
288 #define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
289 #define INT_ATTR(ad) (*(int*)(ad))
291 /* -------------------------------------------------- */
293 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
294 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
295 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
297 /* stored in 'Sym.c' field */
298 #define FUNC_NEW 1 /* ansi function prototype */
299 #define FUNC_OLD 2 /* old function prototype */
300 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
302 /* stored in 'Sym.r' field */
303 #define FUNC_CDECL 0 /* standard c call */
304 #define FUNC_STDCALL 1 /* pascal c call */
305 #define FUNC_FASTCALL1 2 /* first param in %eax */
306 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
307 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
308 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
310 /* field 'Sym.t' for macros */
311 #define MACRO_OBJ 0 /* object like macro */
312 #define MACRO_FUNC 1 /* function like macro */
314 /* field 'Sym.r' for C labels */
315 #define LABEL_DEFINED 0 /* label is defined */
316 #define LABEL_FORWARD 1 /* label is forward defined */
317 #define LABEL_DECLARED 2 /* label is declared but never used */
319 /* type_decl() types */
320 #define TYPE_ABSTRACT 1 /* type without variable */
321 #define TYPE_DIRECT 2 /* type with variable */
323 #define IO_BUF_SIZE 8192
325 typedef struct BufferedFile {
326 uint8_t *buf_ptr;
327 uint8_t *buf_end;
328 int fd;
329 int line_num; /* current line number - here to simplify code */
330 int ifndef_macro; /* #ifndef macro / #endif search */
331 int ifndef_macro_saved; /* saved ifndef_macro */
332 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
333 char inc_type; /* type of include */
334 char inc_filename[512]; /* filename specified by the user */
335 char filename[1024]; /* current filename - here to simplify code */
336 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */
337 } BufferedFile;
339 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
340 #define CH_EOF (-1) /* end of file */
342 /* parsing state (used to save parser state to reparse part of the
343 source several times) */
344 typedef struct ParseState {
345 const int *macro_ptr;
346 int line_num;
347 int tok;
348 CValue tokc;
349 } ParseState;
351 /* used to record tokens */
352 typedef struct TokenString {
353 int *str;
354 int len;
355 int allocated_len;
356 int last_line_num;
357 } TokenString;
359 /* inline functions */
360 typedef struct InlineFunc {
361 int *token_str;
362 Sym *sym;
363 char filename[1];
364 } InlineFunc;
366 /* include file cache, used to find files faster and also to eliminate
367 inclusion if the include file is protected by #ifndef ... #endif */
368 typedef struct CachedInclude {
369 int ifndef_macro;
370 int hash_next; /* -1 if none */
371 char type; /* '"' or '>' to give include type */
372 char filename[1]; /* path specified in #include */
373 } CachedInclude;
375 #define CACHED_INCLUDES_HASH_SIZE 512
377 #ifdef CONFIG_TCC_ASM
378 typedef struct ExprValue {
379 uint32_t v;
380 Sym *sym;
381 } ExprValue;
383 #define MAX_ASM_OPERANDS 30
384 typedef struct ASMOperand {
385 int id; /* GCC 3 optionnal identifier (0 if number only supported */
386 char *constraint;
387 char asm_str[16]; /* computed asm string for operand */
388 SValue *vt; /* C value of the expression */
389 int ref_index; /* if >= 0, gives reference to a output constraint */
390 int input_index; /* if >= 0, gives reference to an input constraint */
391 int priority; /* priority, used to assign registers */
392 int reg; /* if >= 0, register number used for this operand */
393 int is_llong; /* true if double register value */
394 int is_memory; /* true if memory operand */
395 int is_rw; /* for '+' modifier */
396 } ASMOperand;
397 #endif
399 struct TCCState {
400 unsigned output_type : 8;
401 unsigned reloc_output : 1;
403 BufferedFile **include_stack_ptr;
404 int *ifdef_stack_ptr;
406 /* include file handling */
407 char **include_paths;
408 int nb_include_paths;
409 char **sysinclude_paths;
410 int nb_sysinclude_paths;
411 CachedInclude **cached_includes;
412 int nb_cached_includes;
414 char **library_paths;
415 int nb_library_paths;
417 /* array of all loaded dlls (including those referenced by loaded
418 dlls) */
419 DLLReference **loaded_dlls;
420 int nb_loaded_dlls;
422 /* sections */
423 Section **sections;
424 int nb_sections; /* number of sections, including first dummy section */
426 Section **priv_sections;
427 int nb_priv_sections; /* number of private sections */
429 /* got handling */
430 Section *got;
431 Section *plt;
432 unsigned long *got_offsets;
433 int nb_got_offsets;
434 /* give the correspondance from symtab indexes to dynsym indexes */
435 int *symtab_to_dynsym;
437 /* temporary dynamic symbol sections (for dll loading) */
438 Section *dynsymtab_section;
439 /* exported dynamic symbol section */
440 Section *dynsym;
442 int nostdinc; /* if true, no standard headers are added */
443 int nostdlib; /* if true, no standard libraries are added */
444 int nocommon; /* if true, do not use common symbols for .bss data */
446 /* if true, static linking is performed */
447 int static_link;
449 /* soname as specified on the command line (-soname) */
450 const char *soname;
451 /* rpath as specified on the command line (-Wl,-rpath=) */
452 const char *rpath;
454 /* if true, all symbols are exported */
455 int rdynamic;
457 /* if true, resolve symbols in the current module first (-Wl,Bsymbolic) */
458 int symbolic;
460 /* if true, only link in referenced objects from archive */
461 int alacarte_link;
463 /* address of text section */
464 unsigned long text_addr;
465 int has_text_addr;
467 /* symbols to call at load-time / unload-time */
468 const char *init_symbol;
469 const char *fini_symbol;
471 /* output format, see TCC_OUTPUT_FORMAT_xxx */
472 int output_format;
474 /* C language options */
475 int char_is_unsigned;
476 int leading_underscore;
478 /* warning switches */
479 int warn_write_strings;
480 int warn_unsupported;
481 int warn_error;
482 int warn_none;
483 int warn_implicit_function_declaration;
485 /* display some information during compilation */
486 int verbose;
487 /* compile with debug symbol (and use them if error during execution) */
488 int do_debug;
489 #ifdef CONFIG_TCC_BCHECK
490 /* compile with built-in memory and bounds checker */
491 int do_bounds_check;
492 #endif
493 /* give the path of the tcc libraries */
494 char *tcc_lib_path;
496 /* error handling */
497 void *error_opaque;
498 void (*error_func)(void *opaque, const char *msg);
499 int error_set_jmp_enabled;
500 jmp_buf error_jmp_buf;
501 int nb_errors;
503 /* tiny assembler state */
504 Sym *asm_labels;
506 /* see include_stack_ptr */
507 BufferedFile *include_stack[INCLUDE_STACK_SIZE];
509 /* see ifdef_stack_ptr */
510 int ifdef_stack[IFDEF_STACK_SIZE];
512 /* see cached_includes */
513 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
515 /* pack stack */
516 int pack_stack[PACK_STACK_SIZE];
517 int *pack_stack_ptr;
519 /* output file for preprocessing */
520 FILE *outfile;
522 /* input files and libraries for this compilation */
523 char **input_files;
524 int nb_input_files;
525 char **input_libs;
526 int nb_input_libs;
528 /* automatically collected dependencies for this compilation */
529 char **target_deps;
530 int nb_target_deps;
532 /* for tcc_relocate */
533 int runtime_added;
534 void *runtime_mem;
535 #ifdef HAVE_SELINUX
536 void *write_mem;
537 unsigned long mem_size;
538 #endif
540 struct InlineFunc **inline_fns;
541 int nb_inline_fns;
543 #ifdef TCC_TARGET_I386
544 int seg_size;
545 #endif
547 /* section alignment */
548 unsigned long section_align;
550 #ifdef TCC_TARGET_PE
551 /* PE info */
552 int pe_subsystem;
553 unsigned long pe_file_align;
554 struct pe_uw {
555 Section *pdata;
556 int sym_1, sym_2, offs_1;
557 } pe_unwind;
558 #endif
560 #ifndef TCC_TARGET_PE
561 #if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
562 /* write PLT and GOT here */
563 char *runtime_plt_and_got;
564 unsigned int runtime_plt_and_got_offset;
565 #endif
566 #endif
569 /* The current value can be: */
570 #define VT_VALMASK 0x00ff
571 #define VT_CONST 0x00f0 /* constant in vc
572 (must be first non register value) */
573 #define VT_LLOCAL 0x00f1 /* lvalue, offset on stack */
574 #define VT_LOCAL 0x00f2 /* offset on stack */
575 #define VT_CMP 0x00f3 /* the value is stored in processor flags (in vc) */
576 #define VT_JMP 0x00f4 /* value is the consequence of jmp true (even) */
577 #define VT_JMPI 0x00f5 /* value is the consequence of jmp false (odd) */
578 #define VT_LVAL 0x0100 /* var is an lvalue */
579 #define VT_SYM 0x0200 /* a symbol value is added */
580 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
581 char/short stored in integer registers) */
582 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
583 dereferencing value */
584 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
585 bounding function call point is in vc */
586 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
587 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
588 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
589 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
591 /* types */
592 #define VT_INT 0 /* integer type */
593 #define VT_BYTE 1 /* signed byte type */
594 #define VT_SHORT 2 /* short type */
595 #define VT_VOID 3 /* void type */
596 #define VT_PTR 4 /* pointer */
597 #define VT_ENUM 5 /* enum definition */
598 #define VT_FUNC 6 /* function type */
599 #define VT_STRUCT 7 /* struct/union definition */
600 #define VT_FLOAT 8 /* IEEE float */
601 #define VT_DOUBLE 9 /* IEEE double */
602 #define VT_LDOUBLE 10 /* IEEE long double */
603 #define VT_BOOL 11 /* ISOC99 boolean type */
604 #define VT_LLONG 12 /* 64 bit integer */
605 #define VT_LONG 13 /* long integer (NEVER USED as type, only
606 during parsing) */
607 #define VT_BTYPE 0x000f /* mask for basic type */
608 #define VT_UNSIGNED 0x0010 /* unsigned type */
609 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
610 #define VT_BITFIELD 0x0040 /* bitfield modifier */
611 #define VT_CONSTANT 0x0800 /* const modifier */
612 #define VT_VOLATILE 0x1000 /* volatile modifier */
613 #define VT_SIGNED 0x2000 /* signed type */
615 /* storage */
616 #define VT_EXTERN 0x00000080 /* extern definition */
617 #define VT_STATIC 0x00000100 /* static variable */
618 #define VT_TYPEDEF 0x00000200 /* typedef definition */
619 #define VT_INLINE 0x00000400 /* inline definition */
620 #define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */
621 #define VT_EXPORT 0x00008000 /* win32: data exported from dll */
623 #define VT_STRUCT_SHIFT 16 /* shift for bitfield shift values */
625 /* type mask (except storage) */
626 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE | VT_IMPORT | VT_EXPORT)
627 #define VT_TYPE (~(VT_STORAGE))
629 /* token values */
631 /* warning: the following compare tokens depend on i386 asm code */
632 #define TOK_ULT 0x92
633 #define TOK_UGE 0x93
634 #define TOK_EQ 0x94
635 #define TOK_NE 0x95
636 #define TOK_ULE 0x96
637 #define TOK_UGT 0x97
638 #define TOK_Nset 0x98
639 #define TOK_Nclear 0x99
640 #define TOK_LT 0x9c
641 #define TOK_GE 0x9d
642 #define TOK_LE 0x9e
643 #define TOK_GT 0x9f
645 #define TOK_LAND 0xa0
646 #define TOK_LOR 0xa1
648 #define TOK_DEC 0xa2
649 #define TOK_MID 0xa3 /* inc/dec, to void constant */
650 #define TOK_INC 0xa4
651 #define TOK_UDIV 0xb0 /* unsigned division */
652 #define TOK_UMOD 0xb1 /* unsigned modulo */
653 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
654 #define TOK_CINT 0xb3 /* number in tokc */
655 #define TOK_CCHAR 0xb4 /* char constant in tokc */
656 #define TOK_STR 0xb5 /* pointer to string in tokc */
657 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
658 #define TOK_LCHAR 0xb7
659 #define TOK_LSTR 0xb8
660 #define TOK_CFLOAT 0xb9 /* float constant */
661 #define TOK_LINENUM 0xba /* line number info */
662 #define TOK_CDOUBLE 0xc0 /* double constant */
663 #define TOK_CLDOUBLE 0xc1 /* long double constant */
664 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
665 #define TOK_ADDC1 0xc3 /* add with carry generation */
666 #define TOK_ADDC2 0xc4 /* add with carry use */
667 #define TOK_SUBC1 0xc5 /* add with carry generation */
668 #define TOK_SUBC2 0xc6 /* add with carry use */
669 #define TOK_CUINT 0xc8 /* unsigned int constant */
670 #define TOK_CLLONG 0xc9 /* long long constant */
671 #define TOK_CULLONG 0xca /* unsigned long long constant */
672 #define TOK_ARROW 0xcb
673 #define TOK_DOTS 0xcc /* three dots */
674 #define TOK_SHR 0xcd /* unsigned shift right */
675 #define TOK_PPNUM 0xce /* preprocessor number */
677 #define TOK_SHL 0x01 /* shift left */
678 #define TOK_SAR 0x02 /* signed shift right */
680 /* assignement operators : normal operator or 0x80 */
681 #define TOK_A_MOD 0xa5
682 #define TOK_A_AND 0xa6
683 #define TOK_A_MUL 0xaa
684 #define TOK_A_ADD 0xab
685 #define TOK_A_SUB 0xad
686 #define TOK_A_DIV 0xaf
687 #define TOK_A_XOR 0xde
688 #define TOK_A_OR 0xfc
689 #define TOK_A_SHL 0x81
690 #define TOK_A_SAR 0x82
692 #ifndef offsetof
693 #define offsetof(type, field) ((size_t) &((type *)0)->field)
694 #endif
696 #ifndef countof
697 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
698 #endif
700 #define TOK_EOF (-1) /* end of file */
701 #define TOK_LINEFEED 10 /* line feed */
703 /* all identificators and strings have token above that */
704 #define TOK_IDENT 256
706 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
707 #define TOK_ASM_int TOK_INT
709 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
710 /* only used for i386 asm opcodes definitions */
711 #define DEF_BWL(x) \
712 DEF(TOK_ASM_ ## x ## b, #x "b") \
713 DEF(TOK_ASM_ ## x ## w, #x "w") \
714 DEF(TOK_ASM_ ## x ## l, #x "l") \
715 DEF(TOK_ASM_ ## x, #x)
716 #define DEF_WL(x) \
717 DEF(TOK_ASM_ ## x ## w, #x "w") \
718 DEF(TOK_ASM_ ## x ## l, #x "l") \
719 DEF(TOK_ASM_ ## x, #x)
720 #ifdef TCC_TARGET_X86_64
721 # define DEF_BWLQ(x) \
722 DEF(TOK_ASM_ ## x ## b, #x "b") \
723 DEF(TOK_ASM_ ## x ## w, #x "w") \
724 DEF(TOK_ASM_ ## x ## l, #x "l") \
725 DEF(TOK_ASM_ ## x ## q, #x "q") \
726 DEF(TOK_ASM_ ## x, #x)
727 # define DEF_WLQ(x) \
728 DEF(TOK_ASM_ ## x ## w, #x "w") \
729 DEF(TOK_ASM_ ## x ## l, #x "l") \
730 DEF(TOK_ASM_ ## x ## q, #x "q") \
731 DEF(TOK_ASM_ ## x, #x)
732 # define DEF_BWLX DEF_BWLQ
733 # define DEF_WLX DEF_WLQ
734 /* number of sizes + 1 */
735 # define NBWLX 5
736 #else
737 # define DEF_BWLX DEF_BWL
738 # define DEF_WLX DEF_WL
739 /* number of sizes + 1 */
740 # define NBWLX 4
741 #endif
743 #define DEF_FP1(x) \
744 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
745 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
746 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
747 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
749 #define DEF_FP(x) \
750 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
751 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
752 DEF_FP1(x)
754 #define DEF_ASMTEST(x) \
755 DEF_ASM(x ## o) \
756 DEF_ASM(x ## no) \
757 DEF_ASM(x ## b) \
758 DEF_ASM(x ## c) \
759 DEF_ASM(x ## nae) \
760 DEF_ASM(x ## nb) \
761 DEF_ASM(x ## nc) \
762 DEF_ASM(x ## ae) \
763 DEF_ASM(x ## e) \
764 DEF_ASM(x ## z) \
765 DEF_ASM(x ## ne) \
766 DEF_ASM(x ## nz) \
767 DEF_ASM(x ## be) \
768 DEF_ASM(x ## na) \
769 DEF_ASM(x ## nbe) \
770 DEF_ASM(x ## a) \
771 DEF_ASM(x ## s) \
772 DEF_ASM(x ## ns) \
773 DEF_ASM(x ## p) \
774 DEF_ASM(x ## pe) \
775 DEF_ASM(x ## np) \
776 DEF_ASM(x ## po) \
777 DEF_ASM(x ## l) \
778 DEF_ASM(x ## nge) \
779 DEF_ASM(x ## nl) \
780 DEF_ASM(x ## ge) \
781 DEF_ASM(x ## le) \
782 DEF_ASM(x ## ng) \
783 DEF_ASM(x ## nle) \
784 DEF_ASM(x ## g)
786 #endif // defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
788 enum tcc_token {
789 TOK_LAST = TOK_IDENT - 1,
790 #define DEF(id, str) id,
791 #include "tcctok.h"
792 #undef DEF
795 #define TOK_UIDENT TOK_DEFINE
797 #ifdef _WIN32
798 #define snprintf _snprintf
799 #define vsnprintf _vsnprintf
800 #ifndef __GNUC__
801 #define strtold (long double)strtod
802 #define strtof (float)strtod
803 #define strtoll (long long)strtol
804 #endif
805 #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
806 || defined(__OpenBSD__)
807 /* currently incorrect */
808 static inline long double strtold(const char *nptr, char **endptr)
810 return (long double)strtod(nptr, endptr);
812 static inline float strtof(const char *nptr, char **endptr)
814 return (float)strtod(nptr, endptr);
816 #else
817 /* XXX: need to define this to use them in non ISOC99 context */
818 extern float strtof (const char *__nptr, char **__endptr);
819 extern long double strtold (const char *__nptr, char **__endptr);
820 #endif
822 #ifdef _WIN32
823 #define IS_PATHSEP(c) (c == '/' || c == '\\')
824 #define IS_ABSPATH(p) (IS_PATHSEP(p[0]) || (p[0] && p[1] == ':' && IS_PATHSEP(p[2])))
825 #define PATHCMP stricmp
826 #else
827 #define IS_PATHSEP(c) (c == '/')
828 #define IS_ABSPATH(p) IS_PATHSEP(p[0])
829 #define PATHCMP strcmp
830 #endif
832 /* space exlcuding newline */
833 static inline int is_space(int ch)
835 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
838 static inline int isid(int c)
840 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
843 static inline int isnum(int c)
845 return c >= '0' && c <= '9';
848 static inline int isoct(int c)
850 return c >= '0' && c <= '7';
853 static inline int toup(int c)
855 return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
858 #define PUB_FUNC
860 #ifndef NOTALLINONE
861 #define ST_INLN static inline
862 #define ST_FUNC static
863 #define ST_DATA static
864 #else
865 #define ST_INLN
866 #define ST_FUNC
867 #define ST_DATA extern
868 #endif
870 /* ------------ libtcc.c ------------ */
872 /* use GNU C extensions */
873 ST_DATA int gnu_ext;
874 /* use Tiny C extensions */
875 ST_DATA int tcc_ext;
876 /* XXX: get rid of this ASAP */
877 ST_DATA struct TCCState *tcc_state;
879 #ifdef CONFIG_TCC_BACKTRACE
880 ST_DATA int num_callers;
881 ST_DATA const char **rt_bound_error_msg;
882 ST_DATA void *rt_prog_main;
883 #endif
885 #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
886 #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
887 #define AFF_PREPROCESS 0x0004 /* preprocess file */
889 /* public functions currently used by the tcc main function */
890 PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
891 PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
892 PUB_FUNC char *tcc_basename(const char *name);
893 PUB_FUNC char *tcc_fileextension (const char *name);
894 PUB_FUNC void tcc_free(void *ptr);
895 PUB_FUNC void *tcc_malloc(unsigned long size);
896 PUB_FUNC void *tcc_mallocz(unsigned long size);
897 PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
898 PUB_FUNC char *tcc_strdup(const char *str);
899 #define free(p) use_tcc_free(p)
900 #define malloc(s) use_tcc_malloc(s)
901 #define realloc(p, s) use_tcc_realloc(p, s)
902 #undef strdup
903 #define strdup(s) use_tcc_strdup(s)
904 PUB_FUNC void tcc_memstats(void);
905 PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data);
906 PUB_FUNC void dynarray_reset(void *pp, int *n);
907 PUB_FUNC void error_noabort(const char *fmt, ...);
908 PUB_FUNC void error(const char *fmt, ...);
909 PUB_FUNC void expect(const char *msg);
910 PUB_FUNC void warning(const char *fmt, ...);
912 /* other utilities */
913 ST_INLN void cstr_ccat(CString *cstr, int ch);
914 ST_FUNC void cstr_cat(CString *cstr, const char *str);
915 ST_FUNC void cstr_wccat(CString *cstr, int ch);
916 ST_FUNC void cstr_new(CString *cstr);
917 ST_FUNC void cstr_free(CString *cstr);
918 ST_FUNC void add_char(CString *cstr, int c);
919 #define cstr_reset(cstr) cstr_free(cstr)
921 ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
922 ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
923 ST_FUNC void *section_ptr_add(Section *sec, unsigned long size);
924 ST_FUNC void section_reserve(Section *sec, unsigned long size);
925 ST_FUNC Section *find_section(TCCState *s1, const char *name);
927 ST_FUNC void put_extern_sym2(Sym *sym, Section *section, unsigned long value, unsigned long size, int can_add_underscore);
928 ST_FUNC void put_extern_sym(Sym *sym, Section *section, unsigned long value, unsigned long size);
929 ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
931 ST_INLN void sym_free(Sym *sym);
932 ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c);
933 ST_FUNC Sym *sym_find2(Sym *s, int v);
934 ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
935 ST_FUNC void sym_pop(Sym **ptop, Sym *b);
936 ST_INLN Sym *struct_find(int v);
937 ST_INLN Sym *sym_find(int v);
938 ST_FUNC Sym *global_identifier_push(int v, int t, int c);
940 ST_FUNC BufferedFile *tcc_open(TCCState *s1, const char *filename);
941 ST_FUNC void tcc_close(BufferedFile *bf);
942 ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
943 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
944 PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value);
945 PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
946 PUB_FUNC void set_num_callers(int n);
948 ST_FUNC int ieee_finite(double d);
950 /* ------------ tccpp.c ------------ */
952 ST_DATA struct BufferedFile *file;
953 ST_DATA int ch, tok;
954 ST_DATA CValue tokc;
955 ST_DATA const int *macro_ptr;
956 ST_DATA int parse_flags;
957 ST_DATA int tok_flags;
958 ST_DATA CString tokcstr; /* current parsed string, if any */
960 /* display benchmark infos */
961 ST_DATA int total_lines;
962 ST_DATA int total_bytes;
963 ST_DATA int tok_ident;
964 ST_DATA TokenSym **table_ident;
966 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
967 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
968 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
969 #define TOK_FLAG_EOF 0x0008 /* end of file */
971 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
972 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
973 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
974 token. line feed is also
975 returned at eof */
976 #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
977 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
979 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
980 ST_FUNC char *get_tok_str(int v, CValue *cv);
981 ST_FUNC void save_parse_state(ParseState *s);
982 ST_FUNC void restore_parse_state(ParseState *s);
983 ST_INLN void tok_str_new(TokenString *s);
984 ST_FUNC void tok_str_free(int *str);
985 ST_FUNC void tok_str_add(TokenString *s, int t);
986 ST_FUNC void tok_str_add_tok(TokenString *s);
987 ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
988 ST_FUNC void define_undef(Sym *s);
989 ST_INLN Sym *define_find(int v);
990 ST_FUNC void free_defines(Sym *b);
991 ST_FUNC Sym *label_find(int v);
992 ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
993 ST_FUNC void label_pop(Sym **ptop, Sym *slast);
994 ST_FUNC void parse_define(void);
995 ST_FUNC void preprocess(int is_bof);
996 ST_FUNC void next_nomacro(void);
997 ST_FUNC void next(void);
998 ST_INLN void unget_tok(int last_tok);
999 ST_FUNC void preprocess_init(TCCState *s1);
1000 ST_FUNC void preprocess_new();
1001 ST_FUNC int tcc_preprocess(TCCState *s1);
1002 ST_FUNC void skip(int c);
1004 /* ------------ tccgen.c ------------ */
1006 ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
1007 ST_DATA Section *cur_text_section; /* current section where function code is generated */
1008 #ifdef CONFIG_TCC_ASM
1009 ST_DATA Section *last_text_section; /* to handle .previous asm directive */
1010 #endif
1011 #ifdef CONFIG_TCC_BCHECK
1012 /* bound check related sections */
1013 ST_DATA Section *bounds_section; /* contains global data bound description */
1014 ST_DATA Section *lbounds_section; /* contains local data bound description */
1015 #endif
1016 /* symbol sections */
1017 ST_DATA Section *symtab_section, *strtab_section;
1018 /* debug sections */
1019 ST_DATA Section *stab_section, *stabstr_section;
1021 #define SYM_POOL_NB (8192 / sizeof(Sym))
1022 ST_DATA Sym *sym_free_first;
1023 ST_DATA void **sym_pools;
1024 ST_DATA int nb_sym_pools;
1026 ST_DATA Sym *global_stack;
1027 ST_DATA Sym *local_stack;
1028 ST_DATA Sym *local_label_stack;
1029 ST_DATA Sym *global_label_stack;
1030 ST_DATA Sym *define_stack;
1031 ST_DATA CType char_pointer_type, func_old_type, int_type;
1032 ST_DATA SValue vstack[VSTACK_SIZE], *vtop;
1033 ST_DATA int rsym, anon_sym, ind, loc;
1035 ST_DATA int const_wanted; /* true if constant wanted */
1036 ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1037 ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1038 ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1039 ST_DATA int func_vc;
1040 ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
1041 ST_DATA char *funcname;
1043 ST_INLN int is_float(int t);
1044 ST_FUNC void test_lvalue(void);
1045 ST_FUNC void swap(int *p, int *q);
1046 ST_FUNC void vpushi(int v);
1047 ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
1048 ST_FUNC void vset(CType *type, int r, int v);
1049 ST_FUNC void vswap(void);
1050 ST_FUNC void vpush_global_sym(CType *type, int v);
1051 ST_FUNC void vrott(int n);
1052 #ifdef TCC_TARGET_ARM
1053 ST_FUNC int get_reg_ex(int rc, int rc2);
1054 ST_FUNC void vnrott(int n);
1055 ST_FUNC void lexpand_nr(void);
1056 #endif
1057 ST_FUNC void vpushv(SValue *v);
1058 ST_FUNC void save_reg(int r);
1059 ST_FUNC int get_reg(int rc);
1060 ST_FUNC void save_regs(int n);
1061 ST_FUNC int gv(int rc);
1062 ST_FUNC void gv2(int rc1, int rc2);
1063 ST_FUNC void vpop(void);
1064 ST_FUNC void gen_op(int op);
1065 ST_FUNC int type_size(CType *type, int *a);
1066 ST_FUNC void mk_pointer(CType *type);
1067 ST_FUNC void vstore(void);
1068 ST_FUNC void inc(int post, int c);
1069 ST_FUNC int lvalue_type(int t);
1070 ST_FUNC void indir(void);
1071 ST_FUNC void unary(void);
1072 ST_FUNC void expr_prod(void);
1073 ST_FUNC void expr_sum(void);
1074 ST_FUNC void gexpr(void);
1075 ST_FUNC int expr_const(void);
1076 ST_FUNC void gen_inline_functions(void);
1077 ST_FUNC void decl(int l);
1078 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1079 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1080 #endif
1082 /* ------------ tccelf.c ------------ */
1084 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1086 typedef struct {
1087 unsigned int n_strx; /* index into string table of name */
1088 unsigned char n_type; /* type of symbol */
1089 unsigned char n_other; /* misc info (usually empty) */
1090 unsigned short n_desc; /* description field */
1091 unsigned int n_value; /* value of symbol */
1092 } Stab_Sym;
1094 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);
1096 ST_FUNC int put_elf_str(Section *s, const char *sym);
1097 ST_FUNC int put_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int shndx, const char *name);
1098 ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int sh_num, const char *name);
1099 ST_FUNC int find_elf_sym(Section *s, const char *name);
1100 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
1102 ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
1103 ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1104 ST_FUNC void put_stabn(int type, int other, int desc, int value);
1105 ST_FUNC void put_stabd(int type, int other, int desc);
1107 ST_FUNC void relocate_common_syms(void);
1108 ST_FUNC void relocate_syms(TCCState *s1, int do_resolve);
1109 ST_FUNC void relocate_section(TCCState *s1, Section *s);
1111 ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
1112 ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1113 ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
1114 ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1115 ST_FUNC void tcc_add_bcheck(TCCState *s1);
1117 ST_FUNC void build_got_entries(TCCState *s1);
1118 ST_FUNC void tcc_add_runtime(TCCState *s1);
1120 #ifndef TCC_TARGET_PE
1121 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1122 ST_FUNC int tcc_load_ldscript(TCCState *s1);
1123 ST_FUNC uint8_t *parse_comment(uint8_t *p);
1124 ST_FUNC void minp(void);
1125 ST_INLN void inp(void);
1126 ST_FUNC int handle_eob(void);
1127 #endif
1129 /* ------------ xxx-gen.c ------------ */
1131 ST_FUNC void gsym_addr(int t, int a);
1132 ST_FUNC void gsym(int t);
1133 ST_FUNC void load(int r, SValue *sv);
1134 ST_FUNC void store(int r, SValue *v);
1135 ST_FUNC void gfunc_call(int nb_args);
1136 ST_FUNC void gfunc_prolog(CType *func_type);
1137 ST_FUNC void gfunc_epilog(void);
1138 ST_FUNC int gjmp(int t);
1139 ST_FUNC void gjmp_addr(int a);
1140 ST_FUNC int gtst(int inv, int t);
1141 ST_FUNC void gen_opi(int op);
1142 ST_FUNC void gen_opf(int op);
1143 ST_FUNC void gen_cvt_ftoi(int t);
1144 ST_FUNC void gen_cvt_ftof(int t);
1145 ST_FUNC void ggoto(void);
1146 #ifndef TCC_TARGET_C67
1147 ST_FUNC void o(unsigned int c);
1148 #endif
1149 #ifndef TCC_TARGET_ARM
1150 ST_FUNC void gen_cvt_itof(int t);
1151 #endif
1153 /* ------------ i386-gen.c ------------ */
1154 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1155 ST_FUNC void g(int c);
1156 ST_FUNC int oad(int c, int s);
1157 ST_FUNC void gen_le16(int c);
1158 ST_FUNC void gen_le32(int c);
1159 ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1160 ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1161 #endif
1163 #ifdef CONFIG_TCC_BCHECK
1164 ST_FUNC void gen_bounded_ptr_add(void);
1165 ST_FUNC void gen_bounded_ptr_deref(void);
1166 #endif
1168 /* ------------ x86_64-gen.c ------------ */
1169 #ifdef TCC_TARGET_X86_64
1170 ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1171 #endif
1173 /* ------------ arm-gen.c ------------ */
1174 #ifdef TCC_TARGET_ARM
1175 ST_FUNC uint32_t encbranch(int pos, int addr, int fail);
1176 ST_FUNC void gen_cvt_itof1(int t);
1177 #endif
1179 /* ------------ c67-gen.c ------------ */
1180 #ifdef TCC_TARGET_C67
1181 #endif
1183 /* ------------ tcccoff.c ------------ */
1185 #ifdef TCC_TARGET_COFF
1186 ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1187 ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
1188 #endif
1190 /* ------------ tccasm.c ------------ */
1191 ST_FUNC void asm_instr(void);
1192 ST_FUNC void asm_global_instr(void);
1194 #ifdef CONFIG_TCC_ASM
1195 ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1196 ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1197 ST_FUNC int asm_int_expr(TCCState *s1);
1198 ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
1199 /* ------------ i386-asm.c ------------ */
1200 ST_FUNC void gen_expr32(ExprValue *pe);
1201 ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1202 ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1203 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1204 ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1205 ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
1206 #endif
1207 /* ------------ tccpe.c -------------- */
1208 #ifdef TCC_TARGET_PE
1209 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
1210 ST_FUNC int pe_add_dll(struct TCCState *s, const char *libraryname);
1211 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1212 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const void *value);
1213 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
1214 /* tiny_impdef.c */
1215 ST_FUNC char *get_export_names(FILE *fp);
1216 #ifdef TCC_TARGET_X86_64
1217 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
1218 #endif
1219 #endif
1221 /* ------------ tccrun.c ----------------- */
1222 #ifdef CONFIG_TCC_STATIC
1223 #define RTLD_LAZY 0x001
1224 #define RTLD_NOW 0x002
1225 #define RTLD_GLOBAL 0x100
1226 #define RTLD_DEFAULT NULL
1227 /* dummy function for profiling */
1228 ST_FUNC void *dlopen(const char *filename, int flag);
1229 ST_FUNC void dlclose(void *p);
1230 //ST_FUNC const char *dlerror(void);
1231 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
1232 #elif !defined TCC_TARGET_PE || !defined _WIN32
1233 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
1234 #endif
1235 /********************************************************/
1236 /* include the target specific definitions */
1238 #define TARGET_DEFS_ONLY
1239 #ifdef TCC_TARGET_I386
1240 #include "i386-gen.c"
1241 #endif
1242 #ifdef TCC_TARGET_X86_64
1243 #include "x86_64-gen.c"
1244 #endif
1245 #ifdef TCC_TARGET_ARM
1246 #include "arm-gen.c"
1247 #endif
1248 #ifdef TCC_TARGET_C67
1249 #include "coff.h"
1250 #include "c67-gen.c"
1251 #endif
1252 #undef TARGET_DEFS_ONLY
1254 ST_DATA const int reg_classes[NB_REGS];
1256 /********************************************************/
1257 #undef ST_DATA
1258 #ifndef NOTALLINONE
1259 #define ST_DATA static
1260 #else
1261 #define ST_DATA
1262 #endif
1263 /********************************************************/
1264 #endif /* _TCC_H */