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