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