tcc -dt -run ... : simpler is better
[tinycc.git] / tcc.h
blob4b272f551ea4396cab80d684043aedf1a086524d
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 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <math.h>
33 #include <fcntl.h>
34 #include <setjmp.h>
35 #include <time.h>
37 #ifndef _WIN32
38 # include <unistd.h>
39 # include <sys/time.h>
40 # ifndef CONFIG_TCC_STATIC
41 # include <dlfcn.h>
42 # endif
43 /* XXX: need to define this to use them in non ISOC99 context */
44 extern float strtof (const char *__nptr, char **__endptr);
45 extern long double strtold (const char *__nptr, char **__endptr);
46 #endif
48 #ifdef _WIN32
49 # include <windows.h>
50 # include <io.h> /* open, close etc. */
51 # include <direct.h> /* getcwd */
52 # ifdef __GNUC__
53 # include <stdint.h>
54 # endif
55 # define inline __inline
56 # define snprintf _snprintf
57 # define vsnprintf _vsnprintf
58 # ifndef __GNUC__
59 # define strtold (long double)strtod
60 # define strtof (float)strtod
61 # define strtoll _strtoi64
62 # define strtoull _strtoui64
63 # endif
64 # ifdef LIBTCC_AS_DLL
65 # define LIBTCCAPI __declspec(dllexport)
66 # define PUB_FUNC LIBTCCAPI
67 # endif
68 # define inp next_inp /* inp is an intrinsic on msvc/mingw */
69 # ifdef _MSC_VER
70 # pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
71 # pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
72 # pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
73 # pragma warning (disable : 4018) // signed/unsigned mismatch
74 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
75 # define ssize_t intptr_t
76 # endif
77 # undef CONFIG_TCC_STATIC
78 #endif
80 #ifndef O_BINARY
81 # define O_BINARY 0
82 #endif
84 #ifdef _MSC_VER
85 # define NORETURN __declspec(noreturn)
86 # define ALIGNED(x) __declspec(align(x))
87 #else
88 # define NORETURN __attribute__((noreturn))
89 # define ALIGNED(x) __attribute__((aligned(x)))
90 #endif
92 #ifdef _WIN32
93 # define IS_DIRSEP(c) (c == '/' || c == '\\')
94 # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
95 # define PATHCMP stricmp
96 #else
97 # define IS_DIRSEP(c) (c == '/')
98 # define IS_ABSPATH(p) IS_DIRSEP(p[0])
99 # define PATHCMP strcmp
100 #endif
102 #ifdef TCC_TARGET_PE
103 #define PATHSEP ';'
104 #else
105 #define PATHSEP ':'
106 #endif
108 /* -------------------------------------------- */
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_X86_64 *//* x86-64 code generator */
124 /* #define TCC_TARGET_ARM *//* ARMv4 code generator */
125 /* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */
126 /* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */
128 /* default target is I386 */
129 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
130 !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
131 !defined(TCC_TARGET_X86_64)
132 #define TCC_TARGET_I386
133 #endif
135 /* object format selection */
136 #if defined(TCC_TARGET_C67)
137 #define TCC_TARGET_COFF
138 #endif
140 /* only native compiler supports -run */
141 #if defined _WIN32 == defined TCC_TARGET_PE
142 # if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386
143 # define TCC_IS_NATIVE
144 # elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64
145 # define TCC_IS_NATIVE
146 # elif defined __arm__ && defined TCC_TARGET_ARM
147 # define TCC_IS_NATIVE
148 # elif defined __aarch64__ && defined TCC_TARGET_ARM64
149 # define TCC_IS_NATIVE
150 # endif
151 #endif
153 #if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
154 # define CONFIG_TCC_BACKTRACE
155 # if (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64) \
156 && !defined TCC_UCLIBC && !defined TCC_MUSL
157 # define CONFIG_TCC_BCHECK /* enable bound checking code */
158 # endif
159 #endif
161 /* ------------ path configuration ------------ */
163 #ifndef CONFIG_SYSROOT
164 # define CONFIG_SYSROOT ""
165 #endif
166 #ifndef CONFIG_TCCDIR
167 # define CONFIG_TCCDIR "."
168 #endif
169 #ifndef CONFIG_LDDIR
170 # define CONFIG_LDDIR "lib"
171 #endif
172 #ifdef CONFIG_TRIPLET
173 # define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
174 # define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
175 #else
176 # define USE_TRIPLET(s) s
177 # define ALSO_TRIPLET(s) s
178 #endif
180 /* path to find crt1.o, crti.o and crtn.o */
181 #ifndef CONFIG_TCC_CRTPREFIX
182 # define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
183 #endif
185 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
187 /* system include paths */
188 #ifndef CONFIG_TCC_SYSINCLUDEPATHS
189 # ifdef TCC_TARGET_PE
190 # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
191 # else
192 # define CONFIG_TCC_SYSINCLUDEPATHS \
193 "{B}/include" \
194 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
195 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
196 # endif
197 #endif
199 /* library search paths */
200 #ifndef CONFIG_TCC_LIBPATHS
201 # ifdef TCC_TARGET_PE
202 # define CONFIG_TCC_LIBPATHS "{B}/lib"
203 # else
204 # define CONFIG_TCC_LIBPATHS \
205 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
206 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
207 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
208 # endif
209 #endif
211 /* name of ELF interpreter */
212 #ifndef CONFIG_TCC_ELFINTERP
213 # if defined __FreeBSD__
214 # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
215 # elif defined __FreeBSD_kernel__
216 # if defined(TCC_TARGET_X86_64)
217 # define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
218 # else
219 # define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
220 # endif
221 # elif defined __DragonFly__
222 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
223 # elif defined __NetBSD__
224 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
225 # elif defined __GNU__
226 # define CONFIG_TCC_ELFINTERP "/lib/ld.so"
227 # elif defined(TCC_TARGET_PE)
228 # define CONFIG_TCC_ELFINTERP "-"
229 # elif defined(TCC_UCLIBC)
230 # define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
231 # elif defined TCC_TARGET_ARM64
232 # if defined(TCC_MUSL)
233 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
234 # else
235 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
236 # endif
237 # elif defined(TCC_TARGET_X86_64)
238 # if defined(TCC_MUSL)
239 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
240 # else
241 # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
242 # endif
243 # elif !defined(TCC_ARM_EABI)
244 # if defined(TCC_MUSL)
245 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
246 # else
247 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
248 # endif
249 # endif
250 #endif
252 /* var elf_interp dans *-gen.c */
253 #ifdef CONFIG_TCC_ELFINTERP
254 # define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
255 #else
256 # define DEFAULT_ELFINTERP(s) default_elfinterp(s)
257 #endif
259 /* (target specific) libtcc1.a */
260 #ifndef TCC_LIBTCC1
261 # define TCC_LIBTCC1 "libtcc1.a"
262 #endif
264 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
265 #if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
266 #define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
267 #endif
269 /* -------------------------------------------- */
271 #include "libtcc.h"
272 #include "elf.h"
273 #include "stab.h"
275 /* -------------------------------------------- */
277 #ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
278 # define PUB_FUNC
279 #endif
281 #ifdef ONE_SOURCE
282 #define ST_INLN static inline
283 #define ST_FUNC static
284 #define ST_DATA static
285 #else
286 #define ST_INLN
287 #define ST_FUNC
288 #define ST_DATA extern
289 #endif
291 #ifdef TCC_PROFILE /* profile all functions */
292 # define static
293 #endif
295 /* -------------------------------------------- */
296 /* include the target specific definitions */
298 #define TARGET_DEFS_ONLY
299 #ifdef TCC_TARGET_I386
300 # include "i386-gen.c"
301 # include "i386-link.c"
302 #endif
303 #ifdef TCC_TARGET_X86_64
304 # include "x86_64-gen.c"
305 # include "x86_64-link.c"
306 #endif
307 #ifdef TCC_TARGET_ARM
308 # include "arm-gen.c"
309 # include "arm-link.c"
310 # include "arm-asm.c"
311 #endif
312 #ifdef TCC_TARGET_ARM64
313 # include "arm64-gen.c"
314 # include "arm64-link.c"
315 #endif
316 #ifdef TCC_TARGET_C67
317 # include "coff.h"
318 # include "c67-gen.c"
319 # include "c67-link.c"
320 #endif
321 #undef TARGET_DEFS_ONLY
323 /* -------------------------------------------- */
325 #if PTR_SIZE == 8
326 # define ELFCLASSW ELFCLASS64
327 # define ElfW(type) Elf##64##_##type
328 # define ELFW(type) ELF##64##_##type
329 # define ElfW_Rel ElfW(Rela)
330 # define SHT_RELX SHT_RELA
331 # define REL_SECTION_FMT ".rela%s"
332 #else
333 # define ELFCLASSW ELFCLASS32
334 # define ElfW(type) Elf##32##_##type
335 # define ELFW(type) ELF##32##_##type
336 # define ElfW_Rel ElfW(Rel)
337 # define SHT_RELX SHT_REL
338 # define REL_SECTION_FMT ".rel%s"
339 #endif
340 /* target address type */
341 #define addr_t ElfW(Addr)
343 /* -------------------------------------------- */
345 #define INCLUDE_STACK_SIZE 32
346 #define IFDEF_STACK_SIZE 64
347 #define VSTACK_SIZE 256
348 #define STRING_MAX_SIZE 1024
349 #define TOKSTR_MAX_SIZE 256
350 #define PACK_STACK_SIZE 8
352 #define TOK_HASH_SIZE 16384 /* must be a power of two */
353 #define TOK_ALLOC_INCR 512 /* must be a power of two */
354 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
356 /* token symbol management */
357 typedef struct TokenSym {
358 struct TokenSym *hash_next;
359 struct Sym *sym_define; /* direct pointer to define */
360 struct Sym *sym_label; /* direct pointer to label */
361 struct Sym *sym_struct; /* direct pointer to structure */
362 struct Sym *sym_identifier; /* direct pointer to identifier */
363 int tok; /* token number */
364 int len;
365 char str[1];
366 } TokenSym;
368 #ifdef TCC_TARGET_PE
369 typedef unsigned short nwchar_t;
370 #else
371 typedef int nwchar_t;
372 #endif
374 typedef struct CString {
375 int size; /* size in bytes */
376 void *data; /* either 'char *' or 'nwchar_t *' */
377 int size_allocated;
378 } CString;
380 /* type definition */
381 typedef struct CType {
382 int t;
383 struct Sym *ref;
384 } CType;
386 /* constant value */
387 typedef union CValue {
388 long double ld;
389 double d;
390 float f;
391 uint64_t i;
392 struct {
393 int size;
394 const void *data;
395 } str;
396 int tab[LDOUBLE_SIZE/4];
397 } CValue;
399 /* value on stack */
400 typedef struct SValue {
401 CType type; /* type */
402 unsigned short r; /* register + flags */
403 unsigned short r2; /* second register, used for 'long long'
404 type. If not used, set to VT_CONST */
405 CValue c; /* constant, if VT_CONST */
406 struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if
407 result of unary() for an identifier. */
408 } SValue;
410 /* symbol attributes */
411 struct SymAttr {
412 unsigned short
413 aligned : 5, /* alignment as log2+1 (0 == unspecified) */
414 packed : 1,
415 weak : 1,
416 visibility : 2,
417 dllexport : 1,
418 dllimport : 1,
419 unused : 5;
422 /* function attributes or temporary attributes for parsing */
423 struct FuncAttr {
424 unsigned
425 func_call : 3, /* calling convention (0..5), see below */
426 func_type : 2, /* FUNC_OLD/NEW/ELLIPSIS */
427 func_body : 1, /* body was defined */
428 func_args : 8; /* PE __stdcall args */
431 /* GNUC attribute definition */
432 typedef struct AttributeDef {
433 struct SymAttr a;
434 struct FuncAttr f;
435 struct Section *section;
436 int alias_target; /* token */
437 int asm_label; /* associated asm label */
438 char attr_mode; /* __attribute__((__mode__(...))) */
439 } AttributeDef;
441 /* symbol management */
442 typedef struct Sym {
443 int v; /* symbol token */
444 unsigned short r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
445 struct SymAttr a; /* symbol attributes */
446 union {
447 struct {
448 int c; /* associated number or Elf symbol index */
449 union {
450 int sym_scope; /* scope level for locals */
451 int jnext; /* next jump label */
452 struct FuncAttr f; /* function attributes */
453 int auxtype; /* bitfield access type */
456 long long enum_val; /* enum constant if IS_ENUM_VAL */
457 int *d; /* define token stream */
459 CType type; /* associated type */
460 union {
461 struct Sym *next; /* next related symbol (for fields and anoms) */
462 int asm_label; /* associated asm label */
464 struct Sym *prev; /* prev symbol in stack */
465 struct Sym *prev_tok; /* previous symbol for this token */
466 } Sym;
468 /* section definition */
469 /* XXX: use directly ELF structure for parameters ? */
470 /* special flag to indicate that the section should not be linked to
471 the other ones */
472 #define SHF_PRIVATE 0x80000000
474 /* special flag, too */
475 #define SECTION_ABS ((void *)1)
477 typedef struct Section {
478 unsigned long data_offset; /* current data offset */
479 unsigned char *data; /* section data */
480 unsigned long data_allocated; /* used for realloc() handling */
481 int sh_name; /* elf section name (only used during output) */
482 int sh_num; /* elf section number */
483 int sh_type; /* elf section type */
484 int sh_flags; /* elf section flags */
485 int sh_info; /* elf section info */
486 int sh_addralign; /* elf section alignment */
487 int sh_entsize; /* elf entry size */
488 unsigned long sh_size; /* section size (only used during output) */
489 addr_t sh_addr; /* address at which the section is relocated */
490 unsigned long sh_offset; /* file offset */
491 int nb_hashed_syms; /* used to resize the hash table */
492 struct Section *link; /* link to another section */
493 struct Section *reloc; /* corresponding section for relocation, if any */
494 struct Section *hash; /* hash table for symbols */
495 struct Section *prev; /* previous section on section stack */
496 char name[1]; /* section name */
497 } Section;
499 typedef struct DLLReference {
500 int level;
501 void *handle;
502 char name[1];
503 } DLLReference;
505 /* -------------------------------------------------- */
507 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
508 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
509 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
511 /* stored in 'Sym->f.func_type' field */
512 #define FUNC_NEW 1 /* ansi function prototype */
513 #define FUNC_OLD 2 /* old function prototype */
514 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
516 /* stored in 'Sym->f.func_call' field */
517 #define FUNC_CDECL 0 /* standard c call */
518 #define FUNC_STDCALL 1 /* pascal c call */
519 #define FUNC_FASTCALL1 2 /* first param in %eax */
520 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
521 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
522 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
524 /* field 'Sym.t' for macros */
525 #define MACRO_OBJ 0 /* object like macro */
526 #define MACRO_FUNC 1 /* function like macro */
528 /* field 'Sym.r' for C labels */
529 #define LABEL_DEFINED 0 /* label is defined */
530 #define LABEL_FORWARD 1 /* label is forward defined */
531 #define LABEL_DECLARED 2 /* label is declared but never used */
533 /* type_decl() types */
534 #define TYPE_ABSTRACT 1 /* type without variable */
535 #define TYPE_DIRECT 2 /* type with variable */
537 #define IO_BUF_SIZE 8192
539 typedef struct BufferedFile {
540 uint8_t *buf_ptr;
541 uint8_t *buf_end;
542 int fd;
543 struct BufferedFile *prev;
544 int line_num; /* current line number - here to simplify code */
545 int line_ref; /* tcc -E: last printed line */
546 int ifndef_macro; /* #ifndef macro / #endif search */
547 int ifndef_macro_saved; /* saved ifndef_macro */
548 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
549 int include_next_index; /* next search path */
550 char filename[1024]; /* filename */
551 char *true_filename; /* filename not modified by # line directive */
552 unsigned char unget[4];
553 unsigned char buffer[1]; /* extra size for CH_EOB char */
554 } BufferedFile;
556 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
557 #define CH_EOF (-1) /* end of file */
559 /* used to record tokens */
560 typedef struct TokenString {
561 int *str;
562 int len;
563 int lastlen;
564 int allocated_len;
565 int last_line_num;
566 int save_line_num;
567 /* used to chain token-strings with begin/end_macro() */
568 struct TokenString *prev;
569 const int *prev_ptr;
570 char alloc;
571 } TokenString;
573 /* inline functions */
574 typedef struct InlineFunc {
575 TokenString *func_str;
576 Sym *sym;
577 char filename[1];
578 } InlineFunc;
580 /* include file cache, used to find files faster and also to eliminate
581 inclusion if the include file is protected by #ifndef ... #endif */
582 typedef struct CachedInclude {
583 int ifndef_macro;
584 int once;
585 int hash_next; /* -1 if none */
586 char filename[1]; /* path specified in #include */
587 } CachedInclude;
589 #define CACHED_INCLUDES_HASH_SIZE 32
591 #ifdef CONFIG_TCC_ASM
592 typedef struct ExprValue {
593 uint64_t v;
594 Sym *sym;
595 int pcrel;
596 } ExprValue;
598 #define MAX_ASM_OPERANDS 30
599 typedef struct ASMOperand {
600 int id; /* GCC 3 optional identifier (0 if number only supported */
601 char *constraint;
602 char asm_str[16]; /* computed asm string for operand */
603 SValue *vt; /* C value of the expression */
604 int ref_index; /* if >= 0, gives reference to a output constraint */
605 int input_index; /* if >= 0, gives reference to an input constraint */
606 int priority; /* priority, used to assign registers */
607 int reg; /* if >= 0, register number used for this operand */
608 int is_llong; /* true if double register value */
609 int is_memory; /* true if memory operand */
610 int is_rw; /* for '+' modifier */
611 } ASMOperand;
612 #endif
614 /* extra symbol attributes (not in symbol table) */
615 struct sym_attr {
616 unsigned got_offset;
617 unsigned plt_offset;
618 int plt_sym;
619 int dyn_index;
620 #ifdef TCC_TARGET_ARM
621 unsigned char plt_thumb_stub:1;
622 #endif
625 struct TCCState {
627 int verbose; /* if true, display some information during compilation */
628 int nostdinc; /* if true, no standard headers are added */
629 int nostdlib; /* if true, no standard libraries are added */
630 int nocommon; /* if true, do not use common symbols for .bss data */
631 int static_link; /* if true, static linking is performed */
632 int rdynamic; /* if true, all symbols are exported */
633 int symbolic; /* if true, resolve symbols in the current module first */
634 int alacarte_link; /* if true, only link in referenced objects from archive */
636 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
637 char *soname; /* as specified on the command line (-soname) */
638 char *rpath; /* as specified on the command line (-Wl,-rpath=) */
639 int enable_new_dtags; /* ditto, (-Wl,--enable-new-dtags) */
641 /* output type, see TCC_OUTPUT_XXX */
642 int output_type;
643 /* output format, see TCC_OUTPUT_FORMAT_xxx */
644 int output_format;
646 /* C language options */
647 int char_is_unsigned;
648 int leading_underscore;
649 int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
650 int dollars_in_identifiers; /* allows '$' char in identifiers */
651 int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
653 /* warning switches */
654 int warn_write_strings;
655 int warn_unsupported;
656 int warn_error;
657 int warn_none;
658 int warn_implicit_function_declaration;
659 int warn_gcc_compat;
661 /* compile with debug symbol (and use them if error during execution) */
662 int do_debug;
663 #ifdef CONFIG_TCC_BCHECK
664 /* compile with built-in memory and bounds checker */
665 int do_bounds_check;
666 #endif
667 #ifdef TCC_TARGET_ARM
668 enum float_abi float_abi; /* float ABI of the generated code*/
669 #endif
670 int run_test; /* nth test to run with -dt -run */
672 addr_t text_addr; /* address of text section */
673 int has_text_addr;
675 unsigned section_align; /* section alignment */
677 char *init_symbol; /* symbols to call at load-time (not used currently) */
678 char *fini_symbol; /* symbols to call at unload-time (not used currently) */
680 #ifdef TCC_TARGET_I386
681 int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */
682 #endif
683 #ifdef TCC_TARGET_X86_64
684 int nosse; /* For -mno-sse support. */
685 #endif
687 /* array of all loaded dlls (including those referenced by loaded dlls) */
688 DLLReference **loaded_dlls;
689 int nb_loaded_dlls;
691 /* include paths */
692 char **include_paths;
693 int nb_include_paths;
695 char **sysinclude_paths;
696 int nb_sysinclude_paths;
698 /* library paths */
699 char **library_paths;
700 int nb_library_paths;
702 /* crt?.o object path */
703 char **crt_paths;
704 int nb_crt_paths;
706 /* -include files */
707 char **cmd_include_files;
708 int nb_cmd_include_files;
710 /* error handling */
711 void *error_opaque;
712 void (*error_func)(void *opaque, const char *msg);
713 int error_set_jmp_enabled;
714 jmp_buf error_jmp_buf;
715 int nb_errors;
717 /* output file for preprocessing (-E) */
718 FILE *ppfp;
719 enum {
720 LINE_MACRO_OUTPUT_FORMAT_GCC,
721 LINE_MACRO_OUTPUT_FORMAT_NONE,
722 LINE_MACRO_OUTPUT_FORMAT_STD,
723 LINE_MACRO_OUTPUT_FORMAT_P10 = 11
724 } Pflag; /* -P switch */
725 char dflag; /* -dX value */
727 /* for -MD/-MF: collected dependencies for this compilation */
728 char **target_deps;
729 int nb_target_deps;
731 /* compilation */
732 BufferedFile *include_stack[INCLUDE_STACK_SIZE];
733 BufferedFile **include_stack_ptr;
735 int ifdef_stack[IFDEF_STACK_SIZE];
736 int *ifdef_stack_ptr;
738 /* included files enclosed with #ifndef MACRO */
739 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
740 CachedInclude **cached_includes;
741 int nb_cached_includes;
743 /* #pragma pack stack */
744 int pack_stack[PACK_STACK_SIZE];
745 int *pack_stack_ptr;
746 char **pragma_libs;
747 int nb_pragma_libs;
749 /* inline functions are stored as token lists and compiled last
750 only if referenced */
751 struct InlineFunc **inline_fns;
752 int nb_inline_fns;
754 /* sections */
755 Section **sections;
756 int nb_sections; /* number of sections, including first dummy section */
758 Section **priv_sections;
759 int nb_priv_sections; /* number of private sections */
761 /* got & plt handling */
762 Section *got;
763 Section *plt;
765 /* temporary dynamic symbol sections (for dll loading) */
766 Section *dynsymtab_section;
767 /* exported dynamic symbol section */
768 Section *dynsym;
769 /* copy of the global symtab_section variable */
770 Section *symtab;
771 /* extra attributes (eg. GOT/PLT value) for symtab symbols */
772 struct sym_attr *sym_attrs;
773 int nb_sym_attrs;
774 /* tiny assembler state */
775 Sym *asm_labels;
777 #ifdef TCC_TARGET_PE
778 /* PE info */
779 int pe_subsystem;
780 unsigned pe_characteristics;
781 unsigned pe_file_align;
782 unsigned pe_stack_size;
783 # ifdef TCC_TARGET_X86_64
784 Section *uw_pdata;
785 int uw_sym;
786 unsigned uw_offs;
787 # endif
788 #endif
790 #ifdef TCC_IS_NATIVE
791 const char *runtime_main;
792 void **runtime_mem;
793 int nb_runtime_mem;
794 #endif
796 /* used by main and tcc_parse_args only */
797 struct filespec **files; /* files seen on command line */
798 int nb_files; /* number thereof */
799 int nb_libraries; /* number of libs thereof */
800 int filetype;
801 char *outfile; /* output filename */
802 int option_r; /* option -r */
803 int do_bench; /* option -bench */
804 int gen_deps; /* option -MD */
805 char *deps_outfile; /* option -MF */
806 int option_pthread; /* -pthread option */
807 int argc;
808 char **argv;
811 struct filespec {
812 char type;
813 char alacarte;
814 char name[1];
817 /* The current value can be: */
818 #define VT_VALMASK 0x003f /* mask for value location, register or: */
819 #define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
820 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
821 #define VT_LOCAL 0x0032 /* offset on stack */
822 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
823 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
824 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
825 #define VT_LVAL 0x0100 /* var is an lvalue */
826 #define VT_SYM 0x0200 /* a symbol value is added */
827 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
828 char/short stored in integer registers) */
829 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
830 dereferencing value */
831 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
832 bounding function call point is in vc */
833 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
834 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
835 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
836 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
838 /* types */
839 #define VT_BTYPE 0x000f /* mask for basic type */
840 #define VT_VOID 0 /* void type */
841 #define VT_BYTE 1 /* signed byte type */
842 #define VT_SHORT 2 /* short type */
843 #define VT_INT 3 /* integer type */
844 #define VT_LLONG 4 /* 64 bit integer */
845 #define VT_PTR 5 /* pointer */
846 #define VT_FUNC 6 /* function type */
847 #define VT_STRUCT 7 /* struct/union definition */
848 #define VT_FLOAT 8 /* IEEE float */
849 #define VT_DOUBLE 9 /* IEEE double */
850 #define VT_LDOUBLE 10 /* IEEE long double */
851 #define VT_BOOL 11 /* ISOC99 boolean type */
852 #define VT_LONG 12 /* long integer (NEVER USED as type, only during parsing) */
853 #define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */
854 #define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */
856 #define VT_UNSIGNED 0x0010 /* unsigned type */
857 #define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */
858 #define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */
859 #define VT_BITFIELD 0x0080 /* bitfield modifier */
860 #define VT_CONSTANT 0x0100 /* const modifier */
861 #define VT_VOLATILE 0x0200 /* volatile modifier */
862 #define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
864 /* storage */
865 #define VT_EXTERN 0x00001000 /* extern definition */
866 #define VT_STATIC 0x00002000 /* static variable */
867 #define VT_TYPEDEF 0x00004000 /* typedef definition */
868 #define VT_INLINE 0x00008000 /* inline definition */
869 /* currently unused: 0x0800, 0x000[1248]0000 */
871 #define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
872 #define VT_STRUCT_MASK (((1 << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)
873 #define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f)
874 #define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f)
876 #define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
877 #define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
878 #define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
880 #define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
881 #define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
882 #define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION)
884 /* type mask (except storage) */
885 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
886 #define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
889 /* token values */
891 /* warning: the following compare tokens depend on i386 asm code */
892 #define TOK_ULT 0x92
893 #define TOK_UGE 0x93
894 #define TOK_EQ 0x94
895 #define TOK_NE 0x95
896 #define TOK_ULE 0x96
897 #define TOK_UGT 0x97
898 #define TOK_Nset 0x98
899 #define TOK_Nclear 0x99
900 #define TOK_LT 0x9c
901 #define TOK_GE 0x9d
902 #define TOK_LE 0x9e
903 #define TOK_GT 0x9f
905 #define TOK_LAND 0xa0
906 #define TOK_LOR 0xa1
907 #define TOK_DEC 0xa2
908 #define TOK_MID 0xa3 /* inc/dec, to void constant */
909 #define TOK_INC 0xa4
910 #define TOK_UDIV 0xb0 /* unsigned division */
911 #define TOK_UMOD 0xb1 /* unsigned modulo */
912 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
914 /* tokens that carry values (in additional token string space / tokc) --> */
915 #define TOK_CCHAR 0xb3 /* char constant in tokc */
916 #define TOK_LCHAR 0xb4
917 #define TOK_CINT 0xb5 /* number in tokc */
918 #define TOK_CUINT 0xb6 /* unsigned int constant */
919 #define TOK_CLLONG 0xb7 /* long long constant */
920 #define TOK_CULLONG 0xb8 /* unsigned long long constant */
921 #define TOK_STR 0xb9 /* pointer to string in tokc */
922 #define TOK_LSTR 0xba
923 #define TOK_CFLOAT 0xbb /* float constant */
924 #define TOK_CDOUBLE 0xbc /* double constant */
925 #define TOK_CLDOUBLE 0xbd /* long double constant */
926 #define TOK_PPNUM 0xbe /* preprocessor number */
927 #define TOK_PPSTR 0xbf /* preprocessor string */
928 #define TOK_LINENUM 0xc0 /* line number info */
929 /* <-- */
931 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
932 #define TOK_ADDC1 0xc3 /* add with carry generation */
933 #define TOK_ADDC2 0xc4 /* add with carry use */
934 #define TOK_SUBC1 0xc5 /* add with carry generation */
935 #define TOK_SUBC2 0xc6 /* add with carry use */
936 #define TOK_ARROW 0xc7
937 #define TOK_DOTS 0xc8 /* three dots */
938 #define TOK_SHR 0xc9 /* unsigned shift right */
939 #define TOK_TWOSHARPS 0xca /* ## preprocessing token */
940 #define TOK_PLCHLDR 0xcb /* placeholder token as defined in C99 */
941 #define TOK_NOSUBST 0xcc /* means following token has already been pp'd */
942 #define TOK_PPJOIN 0xce /* A '##' in the right position to mean pasting */
944 #define TOK_SHL 0x01 /* shift left */
945 #define TOK_SAR 0x02 /* signed shift right */
947 /* assignment operators : normal operator or 0x80 */
948 #define TOK_A_MOD 0xa5
949 #define TOK_A_AND 0xa6
950 #define TOK_A_MUL 0xaa
951 #define TOK_A_ADD 0xab
952 #define TOK_A_SUB 0xad
953 #define TOK_A_DIV 0xaf
954 #define TOK_A_XOR 0xde
955 #define TOK_A_OR 0xfc
956 #define TOK_A_SHL 0x81
957 #define TOK_A_SAR 0x82
959 #ifndef offsetof
960 #define offsetof(type, field) ((size_t) &((type *)0)->field)
961 #endif
963 #ifndef countof
964 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
965 #endif
967 #define TOK_EOF (-1) /* end of file */
968 #define TOK_LINEFEED 10 /* line feed */
970 /* all identifiers and strings have token above that */
971 #define TOK_IDENT 256
973 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
974 #define TOK_ASM_int TOK_INT
975 #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
976 #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
977 #define TOK_ASMDIR_LAST TOK_ASMDIR_section
979 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
980 /* only used for i386 asm opcodes definitions */
981 #define DEF_BWL(x) \
982 DEF(TOK_ASM_ ## x ## b, #x "b") \
983 DEF(TOK_ASM_ ## x ## w, #x "w") \
984 DEF(TOK_ASM_ ## x ## l, #x "l") \
985 DEF(TOK_ASM_ ## x, #x)
986 #define DEF_WL(x) \
987 DEF(TOK_ASM_ ## x ## w, #x "w") \
988 DEF(TOK_ASM_ ## x ## l, #x "l") \
989 DEF(TOK_ASM_ ## x, #x)
990 #ifdef TCC_TARGET_X86_64
991 # define DEF_BWLQ(x) \
992 DEF(TOK_ASM_ ## x ## b, #x "b") \
993 DEF(TOK_ASM_ ## x ## w, #x "w") \
994 DEF(TOK_ASM_ ## x ## l, #x "l") \
995 DEF(TOK_ASM_ ## x ## q, #x "q") \
996 DEF(TOK_ASM_ ## x, #x)
997 # define DEF_WLQ(x) \
998 DEF(TOK_ASM_ ## x ## w, #x "w") \
999 DEF(TOK_ASM_ ## x ## l, #x "l") \
1000 DEF(TOK_ASM_ ## x ## q, #x "q") \
1001 DEF(TOK_ASM_ ## x, #x)
1002 # define DEF_BWLX DEF_BWLQ
1003 # define DEF_WLX DEF_WLQ
1004 /* number of sizes + 1 */
1005 # define NBWLX 5
1006 #else
1007 # define DEF_BWLX DEF_BWL
1008 # define DEF_WLX DEF_WL
1009 /* number of sizes + 1 */
1010 # define NBWLX 4
1011 #endif
1013 #define DEF_FP1(x) \
1014 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
1015 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
1016 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
1017 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
1019 #define DEF_FP(x) \
1020 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
1021 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
1022 DEF_FP1(x)
1024 #define DEF_ASMTEST(x,suffix) \
1025 DEF_ASM(x ## o ## suffix) \
1026 DEF_ASM(x ## no ## suffix) \
1027 DEF_ASM(x ## b ## suffix) \
1028 DEF_ASM(x ## c ## suffix) \
1029 DEF_ASM(x ## nae ## suffix) \
1030 DEF_ASM(x ## nb ## suffix) \
1031 DEF_ASM(x ## nc ## suffix) \
1032 DEF_ASM(x ## ae ## suffix) \
1033 DEF_ASM(x ## e ## suffix) \
1034 DEF_ASM(x ## z ## suffix) \
1035 DEF_ASM(x ## ne ## suffix) \
1036 DEF_ASM(x ## nz ## suffix) \
1037 DEF_ASM(x ## be ## suffix) \
1038 DEF_ASM(x ## na ## suffix) \
1039 DEF_ASM(x ## nbe ## suffix) \
1040 DEF_ASM(x ## a ## suffix) \
1041 DEF_ASM(x ## s ## suffix) \
1042 DEF_ASM(x ## ns ## suffix) \
1043 DEF_ASM(x ## p ## suffix) \
1044 DEF_ASM(x ## pe ## suffix) \
1045 DEF_ASM(x ## np ## suffix) \
1046 DEF_ASM(x ## po ## suffix) \
1047 DEF_ASM(x ## l ## suffix) \
1048 DEF_ASM(x ## nge ## suffix) \
1049 DEF_ASM(x ## nl ## suffix) \
1050 DEF_ASM(x ## ge ## suffix) \
1051 DEF_ASM(x ## le ## suffix) \
1052 DEF_ASM(x ## ng ## suffix) \
1053 DEF_ASM(x ## nle ## suffix) \
1054 DEF_ASM(x ## g ## suffix)
1056 #endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */
1058 enum tcc_token {
1059 TOK_LAST = TOK_IDENT - 1
1060 #define DEF(id, str) ,id
1061 #include "tcctok.h"
1062 #undef DEF
1065 /* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
1066 #define TOK_UIDENT TOK_DEFINE
1068 /* ------------ libtcc.c ------------ */
1070 /* use GNU C extensions */
1071 ST_DATA int gnu_ext;
1072 /* use Tiny C extensions */
1073 ST_DATA int tcc_ext;
1074 /* XXX: get rid of this ASAP */
1075 ST_DATA struct TCCState *tcc_state;
1077 /* public functions currently used by the tcc main function */
1078 ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
1079 ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
1080 ST_FUNC char *pstrncpy(char *out, const char *in, size_t num);
1081 PUB_FUNC char *tcc_basename(const char *name);
1082 PUB_FUNC char *tcc_fileextension (const char *name);
1084 #ifndef MEM_DEBUG
1085 PUB_FUNC void tcc_free(void *ptr);
1086 PUB_FUNC void *tcc_malloc(unsigned long size);
1087 PUB_FUNC void *tcc_mallocz(unsigned long size);
1088 PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
1089 PUB_FUNC char *tcc_strdup(const char *str);
1090 #else
1091 #define tcc_free(ptr) tcc_free_debug(ptr)
1092 #define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
1093 #define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
1094 #define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
1095 #define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
1096 PUB_FUNC void tcc_free_debug(void *ptr);
1097 PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
1098 PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
1099 PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
1100 PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
1101 #endif
1103 #define free(p) use_tcc_free(p)
1104 #define malloc(s) use_tcc_malloc(s)
1105 #define realloc(p, s) use_tcc_realloc(p, s)
1106 #undef strdup
1107 #define strdup(s) use_tcc_strdup(s)
1108 PUB_FUNC void tcc_memcheck(void);
1109 PUB_FUNC void tcc_error_noabort(const char *fmt, ...);
1110 PUB_FUNC NORETURN void tcc_error(const char *fmt, ...);
1111 PUB_FUNC void tcc_warning(const char *fmt, ...);
1113 /* other utilities */
1114 ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
1115 ST_FUNC void dynarray_reset(void *pp, int *n);
1116 ST_INLN void cstr_ccat(CString *cstr, int ch);
1117 ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
1118 ST_FUNC void cstr_wccat(CString *cstr, int ch);
1119 ST_FUNC void cstr_new(CString *cstr);
1120 ST_FUNC void cstr_free(CString *cstr);
1121 ST_FUNC void cstr_reset(CString *cstr);
1123 ST_INLN void sym_free(Sym *sym);
1124 ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
1125 ST_FUNC Sym *sym_find2(Sym *s, int v);
1126 ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
1127 ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
1128 ST_INLN Sym *struct_find(int v);
1129 ST_INLN Sym *sym_find(int v);
1130 ST_FUNC Sym *global_identifier_push(int v, int t, int c);
1132 ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
1133 ST_FUNC int tcc_open(TCCState *s1, const char *filename);
1134 ST_FUNC void tcc_close(void);
1136 ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
1137 /* flags: */
1138 #define AFF_PRINT_ERROR 0x10 /* print error if file not found */
1139 #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
1140 #define AFF_TYPE_BIN 0x40 /* file to add is binary */
1141 /* s->filetype: */
1142 #define AFF_TYPE_NONE 0
1143 #define AFF_TYPE_C 1
1144 #define AFF_TYPE_ASM 2
1145 #define AFF_TYPE_ASMPP 3
1146 #define AFF_TYPE_LIB 4
1147 /* values from tcc_object_type(...) */
1148 #define AFF_BINTYPE_REL 1
1149 #define AFF_BINTYPE_DYN 2
1150 #define AFF_BINTYPE_AR 3
1151 #define AFF_BINTYPE_C67 4
1154 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
1155 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1156 ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
1157 PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
1158 PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
1159 PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
1160 #ifdef _WIN32
1161 ST_FUNC char *normalize_slashes(char *path);
1162 #endif
1164 /* tcc_parse_args return codes: */
1165 #define OPT_HELP 1
1166 #define OPT_HELP2 2
1167 #define OPT_V 3
1168 #define OPT_PRINT_DIRS 4
1169 #define OPT_AR 5
1170 #define OPT_IMPDEF 6
1171 #define OPT_M32 32
1172 #define OPT_M64 64
1174 /* ------------ tccpp.c ------------ */
1176 ST_DATA struct BufferedFile *file;
1177 ST_DATA int ch, tok;
1178 ST_DATA CValue tokc;
1179 ST_DATA const int *macro_ptr;
1180 ST_DATA int parse_flags;
1181 ST_DATA int tok_flags;
1182 ST_DATA CString tokcstr; /* current parsed string, if any */
1184 /* display benchmark infos */
1185 ST_DATA int total_lines;
1186 ST_DATA int total_bytes;
1187 ST_DATA int tok_ident;
1188 ST_DATA TokenSym **table_ident;
1190 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1191 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1192 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1193 #define TOK_FLAG_EOF 0x0008 /* end of file */
1195 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1196 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1197 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1198 token. line feed is also
1199 returned at eof */
1200 #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
1201 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1202 #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
1203 #define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
1205 /* isidnum_table flags: */
1206 #define IS_SPC 1
1207 #define IS_ID 2
1208 #define IS_NUM 4
1210 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
1211 ST_FUNC const char *get_tok_str(int v, CValue *cv);
1212 ST_FUNC void begin_macro(TokenString *str, int alloc);
1213 ST_FUNC void end_macro(void);
1214 ST_FUNC int set_idnum(int c, int val);
1215 ST_INLN void tok_str_new(TokenString *s);
1216 ST_FUNC TokenString *tok_str_alloc(void);
1217 ST_FUNC void tok_str_free(TokenString *s);
1218 ST_FUNC void tok_str_free_str(int *str);
1219 ST_FUNC void tok_str_add(TokenString *s, int t);
1220 ST_FUNC void tok_str_add_tok(TokenString *s);
1221 ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
1222 ST_FUNC void define_undef(Sym *s);
1223 ST_INLN Sym *define_find(int v);
1224 ST_FUNC void free_defines(Sym *b);
1225 ST_FUNC Sym *label_find(int v);
1226 ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
1227 ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep);
1228 ST_FUNC void parse_define(void);
1229 ST_FUNC void preprocess(int is_bof);
1230 ST_FUNC void next_nomacro(void);
1231 ST_FUNC void next(void);
1232 ST_INLN void unget_tok(int last_tok);
1233 ST_FUNC void preprocess_start(TCCState *s1, int is_asm);
1234 ST_FUNC void preprocess_end(TCCState *s1);
1235 ST_FUNC void tccpp_new(TCCState *s);
1236 ST_FUNC void tccpp_delete(TCCState *s);
1237 ST_FUNC int tcc_preprocess(TCCState *s1);
1238 ST_FUNC void skip(int c);
1239 ST_FUNC NORETURN void expect(const char *msg);
1241 /* space excluding newline */
1242 static inline int is_space(int ch) {
1243 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
1245 static inline int isid(int c) {
1246 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
1248 static inline int isnum(int c) {
1249 return c >= '0' && c <= '9';
1251 static inline int isoct(int c) {
1252 return c >= '0' && c <= '7';
1254 static inline int toup(int c) {
1255 return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
1258 /* ------------ tccgen.c ------------ */
1260 #define SYM_POOL_NB (8192 / sizeof(Sym))
1261 ST_DATA Sym *sym_free_first;
1262 ST_DATA void **sym_pools;
1263 ST_DATA int nb_sym_pools;
1265 ST_DATA Sym *global_stack;
1266 ST_DATA Sym *local_stack;
1267 ST_DATA Sym *local_label_stack;
1268 ST_DATA Sym *global_label_stack;
1269 ST_DATA Sym *define_stack;
1270 ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;
1271 ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop, *pvtop;
1272 #define vstack (__vstack + 1)
1273 ST_DATA int rsym, anon_sym, ind, loc;
1275 ST_DATA int const_wanted; /* true if constant wanted */
1276 ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1277 ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1278 ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1279 ST_DATA int func_var; /* true if current function is variadic */
1280 ST_DATA int func_vc;
1281 ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
1282 ST_DATA const char *funcname;
1283 ST_DATA int g_debug;
1285 ST_FUNC void tcc_debug_start(TCCState *s1);
1286 ST_FUNC void tcc_debug_end(TCCState *s1);
1287 ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
1288 ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
1289 ST_FUNC void tcc_debug_line(TCCState *s1);
1291 ST_FUNC int tccgen_compile(TCCState *s1);
1292 ST_FUNC void free_inline_functions(TCCState *s);
1293 ST_FUNC void check_vstack(void);
1295 ST_INLN int is_float(int t);
1296 ST_FUNC int ieee_finite(double d);
1297 ST_FUNC void test_lvalue(void);
1298 ST_FUNC void vpushi(int v);
1299 ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
1300 ST_FUNC void vset(CType *type, int r, int v);
1301 ST_FUNC void vswap(void);
1302 ST_FUNC void vpush_global_sym(CType *type, int v);
1303 ST_FUNC void vrote(SValue *e, int n);
1304 ST_FUNC void vrott(int n);
1305 ST_FUNC void vrotb(int n);
1306 #ifdef TCC_TARGET_ARM
1307 ST_FUNC int get_reg_ex(int rc, int rc2);
1308 ST_FUNC void lexpand_nr(void);
1309 #endif
1310 ST_FUNC void vpushv(SValue *v);
1311 ST_FUNC void save_reg(int r);
1312 ST_FUNC void save_reg_upstack(int r, int n);
1313 ST_FUNC int get_reg(int rc);
1314 ST_FUNC void save_regs(int n);
1315 ST_FUNC void gaddrof(void);
1316 ST_FUNC int gv(int rc);
1317 ST_FUNC void gv2(int rc1, int rc2);
1318 ST_FUNC void vpop(void);
1319 ST_FUNC void gen_op(int op);
1320 ST_FUNC int type_size(CType *type, int *a);
1321 ST_FUNC void mk_pointer(CType *type);
1322 ST_FUNC void vstore(void);
1323 ST_FUNC void inc(int post, int c);
1324 ST_FUNC void parse_mult_str (CString *astr, const char *msg);
1325 ST_FUNC void parse_asm_str(CString *astr);
1326 ST_FUNC int lvalue_type(int t);
1327 ST_FUNC void indir(void);
1328 ST_FUNC void unary(void);
1329 ST_FUNC void expr_prod(void);
1330 ST_FUNC void expr_sum(void);
1331 ST_FUNC void gexpr(void);
1332 ST_FUNC int expr_const(void);
1333 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1334 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1335 #endif
1336 #if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
1337 ST_FUNC int classify_x86_64_va_arg(CType *ty);
1338 #endif
1340 /* ------------ tccelf.c ------------ */
1342 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
1343 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
1344 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
1346 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1348 typedef struct {
1349 unsigned int n_strx; /* index into string table of name */
1350 unsigned char n_type; /* type of symbol */
1351 unsigned char n_other; /* misc info (usually empty) */
1352 unsigned short n_desc; /* description field */
1353 unsigned int n_value; /* value of symbol */
1354 } Stab_Sym;
1356 ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
1357 ST_DATA Section *common_section;
1358 ST_DATA Section *cur_text_section; /* current section where function code is generated */
1359 #ifdef CONFIG_TCC_ASM
1360 ST_DATA Section *last_text_section; /* to handle .previous asm directive */
1361 #endif
1362 #ifdef CONFIG_TCC_BCHECK
1363 /* bound check related sections */
1364 ST_DATA Section *bounds_section; /* contains global data bound description */
1365 ST_DATA Section *lbounds_section; /* contains local data bound description */
1366 ST_FUNC void tccelf_bounds_new(TCCState *s);
1367 #endif
1368 /* symbol sections */
1369 ST_DATA Section *symtab_section, *strtab_section;
1370 /* debug sections */
1371 ST_DATA Section *stab_section, *stabstr_section;
1373 ST_FUNC void tccelf_new(TCCState *s);
1374 ST_FUNC void tccelf_delete(TCCState *s);
1375 ST_FUNC void tccelf_stab_new(TCCState *s);
1377 ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
1378 ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
1379 ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
1380 ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
1381 ST_FUNC void section_reserve(Section *sec, unsigned long size);
1382 ST_FUNC Section *find_section(TCCState *s1, const char *name);
1383 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);
1385 ST_FUNC void put_extern_sym2(Sym *sym, Section *section, addr_t value, unsigned long size, int can_add_underscore);
1386 ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
1387 #if PTR_SIZE == 4
1388 ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
1389 #endif
1390 ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
1392 ST_FUNC int put_elf_str(Section *s, const char *sym);
1393 ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1394 ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1395 ST_FUNC int find_elf_sym(Section *s, const char *name);
1396 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
1397 ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
1399 ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
1400 ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1401 ST_FUNC void put_stabn(int type, int other, int desc, int value);
1402 ST_FUNC void put_stabd(int type, int other, int desc);
1404 ST_FUNC void relocate_common_syms(void);
1405 ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
1406 ST_FUNC void relocate_section(TCCState *s1, Section *s);
1408 ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
1409 ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
1410 ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1411 ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
1412 ST_FUNC void tcc_add_bcheck(TCCState *s1);
1413 ST_FUNC void tcc_add_runtime(TCCState *s1);
1415 ST_FUNC void build_got_entries(TCCState *s1);
1416 ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
1417 ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
1419 ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
1420 #if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
1421 ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1422 #endif
1424 #ifndef TCC_TARGET_PE
1425 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1426 ST_FUNC int tcc_load_ldscript(TCCState *s1);
1427 ST_FUNC uint8_t *parse_comment(uint8_t *p);
1428 ST_FUNC void minp(void);
1429 ST_INLN void inp(void);
1430 ST_FUNC int handle_eob(void);
1431 #endif
1433 /* ------------ xxx-link.c ------------ */
1435 /* Wether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
1436 that unknown relocation don't create a GOT or PLT entry */
1437 enum gotplt_entry {
1438 NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
1439 BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */
1440 AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
1441 ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
1444 ST_FUNC int code_reloc (int reloc_type);
1445 ST_FUNC int gotplt_entry_type (int reloc_type);
1446 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1447 ST_FUNC void relocate_init(Section *sr);
1448 ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1449 ST_FUNC void relocate_plt(TCCState *s1);
1451 /* ------------ xxx-gen.c ------------ */
1453 ST_DATA const int reg_classes[NB_REGS];
1455 ST_FUNC void gsym_addr(int t, int a);
1456 ST_FUNC void gsym(int t);
1457 ST_FUNC void load(int r, SValue *sv);
1458 ST_FUNC void store(int r, SValue *v);
1459 ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
1460 ST_FUNC void gfunc_call(int nb_args);
1461 ST_FUNC void gfunc_prolog(CType *func_type);
1462 ST_FUNC void gfunc_epilog(void);
1463 ST_FUNC int gjmp(int t);
1464 ST_FUNC void gjmp_addr(int a);
1465 ST_FUNC int gtst(int inv, int t);
1466 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1467 ST_FUNC void gtst_addr(int inv, int a);
1468 #else
1469 #define gtst_addr(inv, a) gsym_addr(gtst(inv, 0), a)
1470 #endif
1471 ST_FUNC void gen_opi(int op);
1472 ST_FUNC void gen_opf(int op);
1473 ST_FUNC void gen_cvt_ftoi(int t);
1474 ST_FUNC void gen_cvt_ftof(int t);
1475 ST_FUNC void ggoto(void);
1476 #ifndef TCC_TARGET_C67
1477 ST_FUNC void o(unsigned int c);
1478 #endif
1479 #ifndef TCC_TARGET_ARM
1480 ST_FUNC void gen_cvt_itof(int t);
1481 #endif
1482 ST_FUNC void gen_vla_sp_save(int addr);
1483 ST_FUNC void gen_vla_sp_restore(int addr);
1484 ST_FUNC void gen_vla_alloc(CType *type, int align);
1486 static inline uint16_t read16le(unsigned char *p) {
1487 return p[0] | (uint16_t)p[1] << 8;
1489 static inline void write16le(unsigned char *p, uint16_t x) {
1490 p[0] = x & 255, p[1] = x >> 8 & 255;
1492 static inline uint32_t read32le(unsigned char *p) {
1493 return read16le(p) | (uint32_t)read16le(p + 2) << 16;
1495 static inline void write32le(unsigned char *p, uint32_t x) {
1496 write16le(p, x), write16le(p + 2, x >> 16);
1498 static inline void add32le(unsigned char *p, int32_t x) {
1499 write32le(p, read32le(p) + x);
1501 static inline uint64_t read64le(unsigned char *p) {
1502 return read32le(p) | (uint64_t)read32le(p + 4) << 32;
1504 static inline void write64le(unsigned char *p, uint64_t x) {
1505 write32le(p, x), write32le(p + 4, x >> 32);
1507 static inline void add64le(unsigned char *p, int64_t x) {
1508 write64le(p, read64le(p) + x);
1511 /* ------------ i386-gen.c ------------ */
1512 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1513 ST_FUNC void g(int c);
1514 ST_FUNC void gen_le16(int c);
1515 ST_FUNC void gen_le32(int c);
1516 ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1517 ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1518 #endif
1520 #ifdef CONFIG_TCC_BCHECK
1521 ST_FUNC void gen_bounded_ptr_add(void);
1522 ST_FUNC void gen_bounded_ptr_deref(void);
1523 #endif
1525 /* ------------ x86_64-gen.c ------------ */
1526 #ifdef TCC_TARGET_X86_64
1527 ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1528 ST_FUNC void gen_opl(int op);
1529 #endif
1531 /* ------------ arm-gen.c ------------ */
1532 #ifdef TCC_TARGET_ARM
1533 #if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
1534 PUB_FUNC const char *default_elfinterp(struct TCCState *s);
1535 #endif
1536 ST_FUNC void arm_init(struct TCCState *s);
1537 ST_FUNC void gen_cvt_itof1(int t);
1538 #endif
1540 /* ------------ arm64-gen.c ------------ */
1541 #ifdef TCC_TARGET_ARM64
1542 ST_FUNC void gen_cvt_sxtw(void);
1543 ST_FUNC void gen_opl(int op);
1544 ST_FUNC void gfunc_return(CType *func_type);
1545 ST_FUNC void gen_va_start(void);
1546 ST_FUNC void gen_va_arg(CType *t);
1547 ST_FUNC void gen_clear_cache(void);
1548 #endif
1550 /* ------------ c67-gen.c ------------ */
1551 #ifdef TCC_TARGET_C67
1552 #endif
1554 /* ------------ tcccoff.c ------------ */
1556 #ifdef TCC_TARGET_COFF
1557 ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1558 ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
1559 #endif
1561 /* ------------ tccasm.c ------------ */
1562 ST_FUNC void asm_instr(void);
1563 ST_FUNC void asm_global_instr(void);
1564 #ifdef CONFIG_TCC_ASM
1565 ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1566 ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
1567 ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1568 ST_FUNC int asm_int_expr(TCCState *s1);
1569 ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
1570 /* ------------ i386-asm.c ------------ */
1571 ST_FUNC void gen_expr32(ExprValue *pe);
1572 #ifdef TCC_TARGET_X86_64
1573 ST_FUNC void gen_expr64(ExprValue *pe);
1574 #endif
1575 ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1576 ST_FUNC int asm_parse_regvar(int t);
1577 ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1578 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1579 ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1580 ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
1581 #endif
1583 /* ------------ tccpe.c -------------- */
1584 #ifdef TCC_TARGET_PE
1585 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
1586 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1587 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
1588 #ifndef TCC_TARGET_ARM
1589 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
1590 #endif
1591 #ifdef TCC_TARGET_X86_64
1592 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
1593 #endif
1594 PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
1595 /* symbol properties stored in Elf32_Sym->st_other */
1596 # define ST_PE_EXPORT 0x10
1597 # define ST_PE_IMPORT 0x20
1598 # define ST_PE_STDCALL 0x40
1599 #endif
1601 /* ------------ tccrun.c ----------------- */
1602 #ifdef TCC_IS_NATIVE
1603 #ifdef CONFIG_TCC_STATIC
1604 #define RTLD_LAZY 0x001
1605 #define RTLD_NOW 0x002
1606 #define RTLD_GLOBAL 0x100
1607 #define RTLD_DEFAULT NULL
1608 /* dummy function for profiling */
1609 ST_FUNC void *dlopen(const char *filename, int flag);
1610 ST_FUNC void dlclose(void *p);
1611 ST_FUNC const char *dlerror(void);
1612 ST_FUNC void *dlsym(void *handle, const char *symbol);
1613 #endif
1614 #ifdef CONFIG_TCC_BACKTRACE
1615 ST_DATA int rt_num_callers;
1616 ST_DATA const char **rt_bound_error_msg;
1617 ST_DATA void *rt_prog_main;
1618 ST_FUNC void tcc_set_num_callers(int n);
1619 #endif
1620 ST_FUNC void tcc_run_free(TCCState *s1);
1621 #endif
1623 /* ------------ tcctools.c ----------------- */
1624 #if 0 /* included in tcc.c */
1625 ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
1626 #ifdef TCC_TARGET_PE
1627 ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
1628 #endif
1629 ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
1630 ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
1631 #endif
1633 /********************************************************/
1634 #undef ST_DATA
1635 #ifdef ONE_SOURCE
1636 #define ST_DATA static
1637 #else
1638 #define ST_DATA
1639 #endif
1640 /********************************************************/
1641 #endif /* _TCC_H */