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