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