enums: Accept GNU extension
[tinycc.git] / tcc.h
blob47c3c5fe8a88804e84b0f0827de74bcfe5fab2a8
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 /* parsing state (used to save parser state to reparse part of the
560 source several times) */
561 typedef struct ParseState {
562 const int *macro_ptr;
563 int line_num;
564 int tok;
565 CValue tokc;
566 } ParseState;
568 /* used to record tokens */
569 typedef struct TokenString {
570 int *str;
571 int len;
572 int lastlen;
573 int allocated_len;
574 int last_line_num;
575 /* used to chain token-strings with begin/end_macro() */
576 struct TokenString *prev;
577 const int *prev_ptr;
578 char alloc;
579 } TokenString;
581 /* inline functions */
582 typedef struct InlineFunc {
583 TokenString *func_str;
584 Sym *sym;
585 char filename[1];
586 } InlineFunc;
588 /* include file cache, used to find files faster and also to eliminate
589 inclusion if the include file is protected by #ifndef ... #endif */
590 typedef struct CachedInclude {
591 int ifndef_macro;
592 int once;
593 int hash_next; /* -1 if none */
594 char filename[1]; /* path specified in #include */
595 } CachedInclude;
597 #define CACHED_INCLUDES_HASH_SIZE 32
599 #ifdef CONFIG_TCC_ASM
600 typedef struct ExprValue {
601 uint64_t v;
602 Sym *sym;
603 int pcrel;
604 } ExprValue;
606 #define MAX_ASM_OPERANDS 30
607 typedef struct ASMOperand {
608 int id; /* GCC 3 optional identifier (0 if number only supported */
609 char *constraint;
610 char asm_str[16]; /* computed asm string for operand */
611 SValue *vt; /* C value of the expression */
612 int ref_index; /* if >= 0, gives reference to a output constraint */
613 int input_index; /* if >= 0, gives reference to an input constraint */
614 int priority; /* priority, used to assign registers */
615 int reg; /* if >= 0, register number used for this operand */
616 int is_llong; /* true if double register value */
617 int is_memory; /* true if memory operand */
618 int is_rw; /* for '+' modifier */
619 } ASMOperand;
620 #endif
622 /* extra symbol attributes (not in symbol table) */
623 struct sym_attr {
624 unsigned got_offset;
625 unsigned plt_offset;
626 int plt_sym;
627 int dyn_index;
628 #ifdef TCC_TARGET_ARM
629 unsigned char plt_thumb_stub:1;
630 #endif
633 struct TCCState {
635 int verbose; /* if true, display some information during compilation */
636 int nostdinc; /* if true, no standard headers are added */
637 int nostdlib; /* if true, no standard libraries are added */
638 int nocommon; /* if true, do not use common symbols for .bss data */
639 int static_link; /* if true, static linking is performed */
640 int rdynamic; /* if true, all symbols are exported */
641 int symbolic; /* if true, resolve symbols in the current module first */
642 int alacarte_link; /* if true, only link in referenced objects from archive */
644 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
645 char *soname; /* as specified on the command line (-soname) */
646 char *rpath; /* as specified on the command line (-Wl,-rpath=) */
647 int enable_new_dtags; /* ditto, (-Wl,--enable-new-dtags) */
649 /* output type, see TCC_OUTPUT_XXX */
650 int output_type;
651 /* output format, see TCC_OUTPUT_FORMAT_xxx */
652 int output_format;
654 /* C language options */
655 int char_is_unsigned;
656 int leading_underscore;
657 int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
658 int dollars_in_identifiers; /* allows '$' char in identifiers */
659 int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
661 /* warning switches */
662 int warn_write_strings;
663 int warn_unsupported;
664 int warn_error;
665 int warn_none;
666 int warn_implicit_function_declaration;
667 int warn_gcc_compat;
669 /* compile with debug symbol (and use them if error during execution) */
670 int do_debug;
671 #ifdef CONFIG_TCC_BCHECK
672 /* compile with built-in memory and bounds checker */
673 int do_bounds_check;
674 #endif
675 #ifdef TCC_TARGET_ARM
676 enum float_abi float_abi; /* float ABI of the generated code*/
677 #endif
679 addr_t text_addr; /* address of text section */
680 int has_text_addr;
682 unsigned section_align; /* section alignment */
684 char *init_symbol; /* symbols to call at load-time (not used currently) */
685 char *fini_symbol; /* symbols to call at unload-time (not used currently) */
687 #ifdef TCC_TARGET_I386
688 int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */
689 #endif
690 #ifdef TCC_TARGET_X86_64
691 int nosse; /* For -mno-sse support. */
692 #endif
694 /* array of all loaded dlls (including those referenced by loaded dlls) */
695 DLLReference **loaded_dlls;
696 int nb_loaded_dlls;
698 /* include paths */
699 char **include_paths;
700 int nb_include_paths;
702 char **sysinclude_paths;
703 int nb_sysinclude_paths;
705 /* library paths */
706 char **library_paths;
707 int nb_library_paths;
709 /* crt?.o object path */
710 char **crt_paths;
711 int nb_crt_paths;
713 /* -include files */
714 char **cmd_include_files;
715 int nb_cmd_include_files;
717 /* error handling */
718 void *error_opaque;
719 void (*error_func)(void *opaque, const char *msg);
720 int error_set_jmp_enabled;
721 jmp_buf error_jmp_buf;
722 int nb_errors;
724 /* output file for preprocessing (-E) */
725 FILE *ppfp;
726 enum {
727 LINE_MACRO_OUTPUT_FORMAT_GCC,
728 LINE_MACRO_OUTPUT_FORMAT_NONE,
729 LINE_MACRO_OUTPUT_FORMAT_STD,
730 LINE_MACRO_OUTPUT_FORMAT_P10 = 11
731 } Pflag; /* -P switch */
732 char dflag; /* -dX value */
734 /* for -MD/-MF: collected dependencies for this compilation */
735 char **target_deps;
736 int nb_target_deps;
738 /* compilation */
739 BufferedFile *include_stack[INCLUDE_STACK_SIZE];
740 BufferedFile **include_stack_ptr;
742 int ifdef_stack[IFDEF_STACK_SIZE];
743 int *ifdef_stack_ptr;
745 /* included files enclosed with #ifndef MACRO */
746 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
747 CachedInclude **cached_includes;
748 int nb_cached_includes;
750 /* #pragma pack stack */
751 int pack_stack[PACK_STACK_SIZE];
752 int *pack_stack_ptr;
753 char **pragma_libs;
754 int nb_pragma_libs;
756 /* inline functions are stored as token lists and compiled last
757 only if referenced */
758 struct InlineFunc **inline_fns;
759 int nb_inline_fns;
761 /* sections */
762 Section **sections;
763 int nb_sections; /* number of sections, including first dummy section */
765 Section **priv_sections;
766 int nb_priv_sections; /* number of private sections */
768 /* got & plt handling */
769 Section *got;
770 Section *plt;
772 /* temporary dynamic symbol sections (for dll loading) */
773 Section *dynsymtab_section;
774 /* exported dynamic symbol section */
775 Section *dynsym;
776 /* copy of the global symtab_section variable */
777 Section *symtab;
778 /* extra attributes (eg. GOT/PLT value) for symtab symbols */
779 struct sym_attr *sym_attrs;
780 int nb_sym_attrs;
781 /* tiny assembler state */
782 Sym *asm_labels;
784 #ifdef TCC_TARGET_PE
785 /* PE info */
786 int pe_subsystem;
787 unsigned pe_characteristics;
788 unsigned pe_file_align;
789 unsigned pe_stack_size;
790 # ifdef TCC_TARGET_X86_64
791 Section *uw_pdata;
792 int uw_sym;
793 unsigned uw_offs;
794 # endif
795 #endif
797 #ifdef TCC_IS_NATIVE
798 const char *runtime_main;
799 void **runtime_mem;
800 int nb_runtime_mem;
801 #endif
803 /* used by main and tcc_parse_args only */
804 struct filespec **files; /* files seen on command line */
805 int nb_files; /* number thereof */
806 int nb_libraries; /* number of libs thereof */
807 int filetype;
808 char *outfile; /* output filename */
809 int option_r; /* option -r */
810 int do_bench; /* option -bench */
811 int gen_deps; /* option -MD */
812 char *deps_outfile; /* option -MF */
813 int option_pthread; /* -pthread option */
814 int argc;
815 char **argv;
818 struct filespec {
819 char type;
820 char alacarte;
821 char name[1];
824 /* The current value can be: */
825 #define VT_VALMASK 0x003f /* mask for value location, register or: */
826 #define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
827 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
828 #define VT_LOCAL 0x0032 /* offset on stack */
829 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
830 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
831 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
832 #define VT_LVAL 0x0100 /* var is an lvalue */
833 #define VT_SYM 0x0200 /* a symbol value is added */
834 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
835 char/short stored in integer registers) */
836 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
837 dereferencing value */
838 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
839 bounding function call point is in vc */
840 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
841 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
842 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
843 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
845 /* types */
846 #define VT_BTYPE 0x000f /* mask for basic type */
847 #define VT_VOID 0 /* void type */
848 #define VT_BYTE 1 /* signed byte type */
849 #define VT_SHORT 2 /* short type */
850 #define VT_INT 3 /* integer type */
851 #define VT_LLONG 4 /* 64 bit integer */
852 #define VT_PTR 5 /* pointer */
853 #define VT_FUNC 6 /* function type */
854 #define VT_STRUCT 7 /* struct/union definition */
855 #define VT_FLOAT 8 /* IEEE float */
856 #define VT_DOUBLE 9 /* IEEE double */
857 #define VT_LDOUBLE 10 /* IEEE long double */
858 #define VT_BOOL 11 /* ISOC99 boolean type */
859 #define VT_LONG 12 /* long integer (NEVER USED as type, only during parsing) */
860 #define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */
861 #define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */
863 #define VT_UNSIGNED 0x0010 /* unsigned type */
864 #define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */
865 #define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */
866 #define VT_BITFIELD 0x0080 /* bitfield modifier */
867 #define VT_CONSTANT 0x0100 /* const modifier */
868 #define VT_VOLATILE 0x0200 /* volatile modifier */
869 #define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
871 /* storage */
872 #define VT_EXTERN 0x00001000 /* extern definition */
873 #define VT_STATIC 0x00002000 /* static variable */
874 #define VT_TYPEDEF 0x00004000 /* typedef definition */
875 #define VT_INLINE 0x00008000 /* inline definition */
876 /* currently unused: 0x0800, 0x000[1248]0000 */
878 #define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
879 #define VT_STRUCT_MASK (((1 << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)
880 #define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f)
881 #define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f)
883 #define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
884 #define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
885 #define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
887 #define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
888 #define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
889 #define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION)
891 /* type mask (except storage) */
892 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
893 #define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
896 /* token values */
898 /* warning: the following compare tokens depend on i386 asm code */
899 #define TOK_ULT 0x92
900 #define TOK_UGE 0x93
901 #define TOK_EQ 0x94
902 #define TOK_NE 0x95
903 #define TOK_ULE 0x96
904 #define TOK_UGT 0x97
905 #define TOK_Nset 0x98
906 #define TOK_Nclear 0x99
907 #define TOK_LT 0x9c
908 #define TOK_GE 0x9d
909 #define TOK_LE 0x9e
910 #define TOK_GT 0x9f
912 #define TOK_LAND 0xa0
913 #define TOK_LOR 0xa1
914 #define TOK_DEC 0xa2
915 #define TOK_MID 0xa3 /* inc/dec, to void constant */
916 #define TOK_INC 0xa4
917 #define TOK_UDIV 0xb0 /* unsigned division */
918 #define TOK_UMOD 0xb1 /* unsigned modulo */
919 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
921 /* tokens that carry values (in additional token string space / tokc) --> */
922 #define TOK_CCHAR 0xb3 /* char constant in tokc */
923 #define TOK_LCHAR 0xb4
924 #define TOK_CINT 0xb5 /* number in tokc */
925 #define TOK_CUINT 0xb6 /* unsigned int constant */
926 #define TOK_CLLONG 0xb7 /* long long constant */
927 #define TOK_CULLONG 0xb8 /* unsigned long long constant */
928 #define TOK_STR 0xb9 /* pointer to string in tokc */
929 #define TOK_LSTR 0xba
930 #define TOK_CFLOAT 0xbb /* float constant */
931 #define TOK_CDOUBLE 0xbc /* double constant */
932 #define TOK_CLDOUBLE 0xbd /* long double constant */
933 #define TOK_PPNUM 0xbe /* preprocessor number */
934 #define TOK_PPSTR 0xbf /* preprocessor string */
935 #define TOK_LINENUM 0xc0 /* line number info */
936 /* <-- */
938 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
939 #define TOK_ADDC1 0xc3 /* add with carry generation */
940 #define TOK_ADDC2 0xc4 /* add with carry use */
941 #define TOK_SUBC1 0xc5 /* add with carry generation */
942 #define TOK_SUBC2 0xc6 /* add with carry use */
943 #define TOK_ARROW 0xc7
944 #define TOK_DOTS 0xc8 /* three dots */
945 #define TOK_SHR 0xc9 /* unsigned shift right */
946 #define TOK_TWOSHARPS 0xca /* ## preprocessing token */
947 #define TOK_PLCHLDR 0xcb /* placeholder token as defined in C99 */
948 #define TOK_NOSUBST 0xcc /* means following token has already been pp'd */
949 #define TOK_PPJOIN 0xce /* A '##' in the right position to mean pasting */
951 #define TOK_SHL 0x01 /* shift left */
952 #define TOK_SAR 0x02 /* signed shift right */
954 /* assignment operators : normal operator or 0x80 */
955 #define TOK_A_MOD 0xa5
956 #define TOK_A_AND 0xa6
957 #define TOK_A_MUL 0xaa
958 #define TOK_A_ADD 0xab
959 #define TOK_A_SUB 0xad
960 #define TOK_A_DIV 0xaf
961 #define TOK_A_XOR 0xde
962 #define TOK_A_OR 0xfc
963 #define TOK_A_SHL 0x81
964 #define TOK_A_SAR 0x82
966 #ifndef offsetof
967 #define offsetof(type, field) ((size_t) &((type *)0)->field)
968 #endif
970 #ifndef countof
971 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
972 #endif
974 #define TOK_EOF (-1) /* end of file */
975 #define TOK_LINEFEED 10 /* line feed */
977 /* all identifiers and strings have token above that */
978 #define TOK_IDENT 256
980 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
981 #define TOK_ASM_int TOK_INT
982 #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
983 #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
984 #define TOK_ASMDIR_LAST TOK_ASMDIR_section
986 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
987 /* only used for i386 asm opcodes definitions */
988 #define DEF_BWL(x) \
989 DEF(TOK_ASM_ ## x ## b, #x "b") \
990 DEF(TOK_ASM_ ## x ## w, #x "w") \
991 DEF(TOK_ASM_ ## x ## l, #x "l") \
992 DEF(TOK_ASM_ ## x, #x)
993 #define DEF_WL(x) \
994 DEF(TOK_ASM_ ## x ## w, #x "w") \
995 DEF(TOK_ASM_ ## x ## l, #x "l") \
996 DEF(TOK_ASM_ ## x, #x)
997 #ifdef TCC_TARGET_X86_64
998 # define DEF_BWLQ(x) \
999 DEF(TOK_ASM_ ## x ## b, #x "b") \
1000 DEF(TOK_ASM_ ## x ## w, #x "w") \
1001 DEF(TOK_ASM_ ## x ## l, #x "l") \
1002 DEF(TOK_ASM_ ## x ## q, #x "q") \
1003 DEF(TOK_ASM_ ## x, #x)
1004 # define DEF_WLQ(x) \
1005 DEF(TOK_ASM_ ## x ## w, #x "w") \
1006 DEF(TOK_ASM_ ## x ## l, #x "l") \
1007 DEF(TOK_ASM_ ## x ## q, #x "q") \
1008 DEF(TOK_ASM_ ## x, #x)
1009 # define DEF_BWLX DEF_BWLQ
1010 # define DEF_WLX DEF_WLQ
1011 /* number of sizes + 1 */
1012 # define NBWLX 5
1013 #else
1014 # define DEF_BWLX DEF_BWL
1015 # define DEF_WLX DEF_WL
1016 /* number of sizes + 1 */
1017 # define NBWLX 4
1018 #endif
1020 #define DEF_FP1(x) \
1021 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
1022 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
1023 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
1024 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
1026 #define DEF_FP(x) \
1027 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
1028 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
1029 DEF_FP1(x)
1031 #define DEF_ASMTEST(x,suffix) \
1032 DEF_ASM(x ## o ## suffix) \
1033 DEF_ASM(x ## no ## suffix) \
1034 DEF_ASM(x ## b ## suffix) \
1035 DEF_ASM(x ## c ## suffix) \
1036 DEF_ASM(x ## nae ## suffix) \
1037 DEF_ASM(x ## nb ## suffix) \
1038 DEF_ASM(x ## nc ## suffix) \
1039 DEF_ASM(x ## ae ## suffix) \
1040 DEF_ASM(x ## e ## suffix) \
1041 DEF_ASM(x ## z ## suffix) \
1042 DEF_ASM(x ## ne ## suffix) \
1043 DEF_ASM(x ## nz ## suffix) \
1044 DEF_ASM(x ## be ## suffix) \
1045 DEF_ASM(x ## na ## suffix) \
1046 DEF_ASM(x ## nbe ## suffix) \
1047 DEF_ASM(x ## a ## suffix) \
1048 DEF_ASM(x ## s ## suffix) \
1049 DEF_ASM(x ## ns ## suffix) \
1050 DEF_ASM(x ## p ## suffix) \
1051 DEF_ASM(x ## pe ## suffix) \
1052 DEF_ASM(x ## np ## suffix) \
1053 DEF_ASM(x ## po ## suffix) \
1054 DEF_ASM(x ## l ## suffix) \
1055 DEF_ASM(x ## nge ## suffix) \
1056 DEF_ASM(x ## nl ## suffix) \
1057 DEF_ASM(x ## ge ## suffix) \
1058 DEF_ASM(x ## le ## suffix) \
1059 DEF_ASM(x ## ng ## suffix) \
1060 DEF_ASM(x ## nle ## suffix) \
1061 DEF_ASM(x ## g ## suffix)
1063 #endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */
1065 enum tcc_token {
1066 TOK_LAST = TOK_IDENT - 1
1067 #define DEF(id, str) ,id
1068 #include "tcctok.h"
1069 #undef DEF
1072 /* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
1073 #define TOK_UIDENT TOK_DEFINE
1075 /* ------------ libtcc.c ------------ */
1077 /* use GNU C extensions */
1078 ST_DATA int gnu_ext;
1079 /* use Tiny C extensions */
1080 ST_DATA int tcc_ext;
1081 /* XXX: get rid of this ASAP */
1082 ST_DATA struct TCCState *tcc_state;
1084 /* public functions currently used by the tcc main function */
1085 ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
1086 ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
1087 ST_FUNC char *pstrncpy(char *out, const char *in, size_t num);
1088 PUB_FUNC char *tcc_basename(const char *name);
1089 PUB_FUNC char *tcc_fileextension (const char *name);
1091 #ifndef MEM_DEBUG
1092 PUB_FUNC void tcc_free(void *ptr);
1093 PUB_FUNC void *tcc_malloc(unsigned long size);
1094 PUB_FUNC void *tcc_mallocz(unsigned long size);
1095 PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
1096 PUB_FUNC char *tcc_strdup(const char *str);
1097 #else
1098 #define tcc_free(ptr) tcc_free_debug(ptr)
1099 #define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
1100 #define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
1101 #define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
1102 #define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
1103 PUB_FUNC void tcc_free_debug(void *ptr);
1104 PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
1105 PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
1106 PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
1107 PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
1108 #endif
1110 #define free(p) use_tcc_free(p)
1111 #define malloc(s) use_tcc_malloc(s)
1112 #define realloc(p, s) use_tcc_realloc(p, s)
1113 #undef strdup
1114 #define strdup(s) use_tcc_strdup(s)
1115 PUB_FUNC void tcc_memcheck(void);
1116 PUB_FUNC void tcc_error_noabort(const char *fmt, ...);
1117 PUB_FUNC NORETURN void tcc_error(const char *fmt, ...);
1118 PUB_FUNC void tcc_warning(const char *fmt, ...);
1120 /* other utilities */
1121 ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
1122 ST_FUNC void dynarray_reset(void *pp, int *n);
1123 ST_INLN void cstr_ccat(CString *cstr, int ch);
1124 ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
1125 ST_FUNC void cstr_wccat(CString *cstr, int ch);
1126 ST_FUNC void cstr_new(CString *cstr);
1127 ST_FUNC void cstr_free(CString *cstr);
1128 ST_FUNC void cstr_reset(CString *cstr);
1130 ST_INLN void sym_free(Sym *sym);
1131 ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
1132 ST_FUNC Sym *sym_find2(Sym *s, int v);
1133 ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
1134 ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
1135 ST_INLN Sym *struct_find(int v);
1136 ST_INLN Sym *sym_find(int v);
1137 ST_FUNC Sym *global_identifier_push(int v, int t, int c);
1139 ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
1140 ST_FUNC int tcc_open(TCCState *s1, const char *filename);
1141 ST_FUNC void tcc_close(void);
1143 ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
1144 /* flags: */
1145 #define AFF_PRINT_ERROR 0x10 /* print error if file not found */
1146 #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
1147 #define AFF_PREPROCESS 0x40 /* preprocess file */
1148 /* combined with: */
1149 #define AFF_TYPE_NONE 0
1150 #define AFF_TYPE_C 1
1151 #define AFF_TYPE_ASM 2
1152 #define AFF_TYPE_ASMPP 3
1153 #define AFF_TYPE_BIN 4
1154 #define AFF_TYPE_LIB 5
1155 /* values from tcc_object_type(...) */
1156 #define AFF_BINTYPE_REL 1
1157 #define AFF_BINTYPE_DYN 2
1158 #define AFF_BINTYPE_AR 3
1159 #define AFF_BINTYPE_C67 4
1162 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
1163 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1164 ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
1165 PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
1166 PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
1167 PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
1168 #ifdef _WIN32
1169 ST_FUNC char *normalize_slashes(char *path);
1170 #endif
1172 /* tcc_parse_args return codes: */
1173 #define OPT_HELP 1
1174 #define OPT_HELP2 2
1175 #define OPT_V 3
1176 #define OPT_PRINT_DIRS 4
1177 #define OPT_AR 5
1178 #define OPT_IMPDEF 6
1179 #define OPT_M32 32
1180 #define OPT_M64 64
1182 /* ------------ tccpp.c ------------ */
1184 ST_DATA struct BufferedFile *file;
1185 ST_DATA int ch, tok;
1186 ST_DATA CValue tokc;
1187 ST_DATA const int *macro_ptr;
1188 ST_DATA int parse_flags;
1189 ST_DATA int tok_flags;
1190 ST_DATA CString tokcstr; /* current parsed string, if any */
1192 /* display benchmark infos */
1193 ST_DATA int total_lines;
1194 ST_DATA int total_bytes;
1195 ST_DATA int tok_ident;
1196 ST_DATA TokenSym **table_ident;
1198 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1199 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1200 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1201 #define TOK_FLAG_EOF 0x0008 /* end of file */
1203 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1204 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1205 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1206 token. line feed is also
1207 returned at eof */
1208 #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
1209 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1210 #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
1211 #define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
1213 /* isidnum_table flags: */
1214 #define IS_SPC 1
1215 #define IS_ID 2
1216 #define IS_NUM 4
1218 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
1219 ST_FUNC const char *get_tok_str(int v, CValue *cv);
1220 ST_FUNC void begin_macro(TokenString *str, int alloc);
1221 ST_FUNC void end_macro(void);
1222 ST_FUNC void set_idnum(int c, int val);
1223 ST_FUNC void save_parse_state(ParseState *s);
1224 ST_FUNC void restore_parse_state(ParseState *s);
1225 ST_INLN void tok_str_new(TokenString *s);
1226 ST_FUNC TokenString *tok_str_alloc(void);
1227 ST_FUNC void tok_str_free(TokenString *s);
1228 ST_FUNC void tok_str_free_str(int *str);
1229 ST_FUNC void tok_str_add(TokenString *s, int t);
1230 ST_FUNC void tok_str_add_tok(TokenString *s);
1231 ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
1232 ST_FUNC void define_undef(Sym *s);
1233 ST_INLN Sym *define_find(int v);
1234 ST_FUNC void free_defines(Sym *b);
1235 ST_FUNC Sym *label_find(int v);
1236 ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
1237 ST_FUNC void label_pop(Sym **ptop, Sym *slast);
1238 ST_FUNC void parse_define(void);
1239 ST_FUNC void preprocess(int is_bof);
1240 ST_FUNC void next_nomacro(void);
1241 ST_FUNC void next(void);
1242 ST_INLN void unget_tok(int last_tok);
1243 ST_FUNC void preprocess_start(TCCState *s1);
1244 ST_FUNC void tccpp_new(TCCState *s);
1245 ST_FUNC void tccpp_delete(TCCState *s);
1246 ST_FUNC int tcc_preprocess(TCCState *s1);
1247 ST_FUNC void skip(int c);
1248 ST_FUNC NORETURN void expect(const char *msg);
1250 /* space excluding newline */
1251 static inline int is_space(int ch) {
1252 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
1254 static inline int isid(int c) {
1255 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
1257 static inline int isnum(int c) {
1258 return c >= '0' && c <= '9';
1260 static inline int isoct(int c) {
1261 return c >= '0' && c <= '7';
1263 static inline int toup(int c) {
1264 return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
1267 /* ------------ tccgen.c ------------ */
1269 #define SYM_POOL_NB (8192 / sizeof(Sym))
1270 ST_DATA Sym *sym_free_first;
1271 ST_DATA void **sym_pools;
1272 ST_DATA int nb_sym_pools;
1274 ST_DATA Sym *global_stack;
1275 ST_DATA Sym *local_stack;
1276 ST_DATA Sym *local_label_stack;
1277 ST_DATA Sym *global_label_stack;
1278 ST_DATA Sym *define_stack;
1279 ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;
1280 ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop, *pvtop;
1281 #define vstack (__vstack + 1)
1282 ST_DATA int rsym, anon_sym, ind, loc;
1284 ST_DATA int const_wanted; /* true if constant wanted */
1285 ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1286 ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1287 ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1288 ST_DATA int func_var; /* true if current function is variadic */
1289 ST_DATA int func_vc;
1290 ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
1291 ST_DATA const char *funcname;
1293 ST_FUNC void tcc_debug_start(TCCState *s1);
1294 ST_FUNC void tcc_debug_end(TCCState *s1);
1295 ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
1296 ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
1297 ST_FUNC void tcc_debug_line(TCCState *s1);
1299 ST_FUNC void tccgen_start(TCCState *s1);
1300 ST_FUNC void tccgen_end(TCCState *s1);
1302 ST_FUNC void free_inline_functions(TCCState *s);
1303 ST_FUNC void check_vstack(void);
1305 ST_INLN int is_float(int t);
1306 ST_FUNC int ieee_finite(double d);
1307 ST_FUNC void test_lvalue(void);
1308 ST_FUNC void vpushi(int v);
1309 ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
1310 ST_FUNC void vset(CType *type, int r, int v);
1311 ST_FUNC void vswap(void);
1312 ST_FUNC void vpush_global_sym(CType *type, int v);
1313 ST_FUNC void vrote(SValue *e, int n);
1314 ST_FUNC void vrott(int n);
1315 ST_FUNC void vrotb(int n);
1316 #ifdef TCC_TARGET_ARM
1317 ST_FUNC int get_reg_ex(int rc, int rc2);
1318 ST_FUNC void lexpand_nr(void);
1319 #endif
1320 ST_FUNC void vpushv(SValue *v);
1321 ST_FUNC void save_reg(int r);
1322 ST_FUNC void save_reg_upstack(int r, int n);
1323 ST_FUNC int get_reg(int rc);
1324 ST_FUNC void save_regs(int n);
1325 ST_FUNC void gaddrof(void);
1326 ST_FUNC int gv(int rc);
1327 ST_FUNC void gv2(int rc1, int rc2);
1328 ST_FUNC void vpop(void);
1329 ST_FUNC void gen_op(int op);
1330 ST_FUNC int type_size(CType *type, int *a);
1331 ST_FUNC void mk_pointer(CType *type);
1332 ST_FUNC void vstore(void);
1333 ST_FUNC void inc(int post, int c);
1334 ST_FUNC void parse_mult_str (CString *astr, const char *msg);
1335 ST_FUNC void parse_asm_str(CString *astr);
1336 ST_FUNC int lvalue_type(int t);
1337 ST_FUNC void indir(void);
1338 ST_FUNC void unary(void);
1339 ST_FUNC void expr_prod(void);
1340 ST_FUNC void expr_sum(void);
1341 ST_FUNC void gexpr(void);
1342 ST_FUNC int expr_const(void);
1343 ST_FUNC void decl(int l);
1344 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1345 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1346 #endif
1347 #if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
1348 ST_FUNC int classify_x86_64_va_arg(CType *ty);
1349 #endif
1351 /* ------------ tccelf.c ------------ */
1353 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
1354 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
1355 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
1357 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1359 typedef struct {
1360 unsigned int n_strx; /* index into string table of name */
1361 unsigned char n_type; /* type of symbol */
1362 unsigned char n_other; /* misc info (usually empty) */
1363 unsigned short n_desc; /* description field */
1364 unsigned int n_value; /* value of symbol */
1365 } Stab_Sym;
1367 ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
1368 ST_DATA Section *common_section;
1369 ST_DATA Section *cur_text_section; /* current section where function code is generated */
1370 #ifdef CONFIG_TCC_ASM
1371 ST_DATA Section *last_text_section; /* to handle .previous asm directive */
1372 #endif
1373 #ifdef CONFIG_TCC_BCHECK
1374 /* bound check related sections */
1375 ST_DATA Section *bounds_section; /* contains global data bound description */
1376 ST_DATA Section *lbounds_section; /* contains local data bound description */
1377 ST_FUNC void tccelf_bounds_new(TCCState *s);
1378 #endif
1379 /* symbol sections */
1380 ST_DATA Section *symtab_section, *strtab_section;
1381 /* debug sections */
1382 ST_DATA Section *stab_section, *stabstr_section;
1384 ST_FUNC void tccelf_new(TCCState *s);
1385 ST_FUNC void tccelf_delete(TCCState *s);
1386 ST_FUNC void tccelf_stab_new(TCCState *s);
1388 ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
1389 ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
1390 ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
1391 ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
1392 ST_FUNC void section_reserve(Section *sec, unsigned long size);
1393 ST_FUNC Section *find_section(TCCState *s1, const char *name);
1394 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);
1396 ST_FUNC void put_extern_sym2(Sym *sym, Section *section, addr_t value, unsigned long size, int can_add_underscore);
1397 ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
1398 #if PTR_SIZE == 4
1399 ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
1400 #endif
1401 ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
1403 ST_FUNC int put_elf_str(Section *s, const char *sym);
1404 ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1405 ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1406 ST_FUNC int find_elf_sym(Section *s, const char *name);
1407 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
1408 ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
1410 ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
1411 ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1412 ST_FUNC void put_stabn(int type, int other, int desc, int value);
1413 ST_FUNC void put_stabd(int type, int other, int desc);
1415 ST_FUNC void relocate_common_syms(void);
1416 ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
1417 ST_FUNC void relocate_section(TCCState *s1, Section *s);
1419 ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
1420 ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
1421 ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1422 ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
1423 ST_FUNC void tcc_add_bcheck(TCCState *s1);
1424 ST_FUNC void tcc_add_runtime(TCCState *s1);
1426 ST_FUNC void build_got_entries(TCCState *s1);
1427 ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
1428 ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
1430 ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
1431 #if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
1432 ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1433 #endif
1435 #ifndef TCC_TARGET_PE
1436 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1437 ST_FUNC int tcc_load_ldscript(TCCState *s1);
1438 ST_FUNC uint8_t *parse_comment(uint8_t *p);
1439 ST_FUNC void minp(void);
1440 ST_INLN void inp(void);
1441 ST_FUNC int handle_eob(void);
1442 #endif
1444 /* ------------ xxx-link.c ------------ */
1446 /* Wether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
1447 that unknown relocation don't create a GOT or PLT entry */
1448 enum gotplt_entry {
1449 NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
1450 BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */
1451 AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
1452 ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
1455 ST_FUNC int code_reloc (int reloc_type);
1456 ST_FUNC int gotplt_entry_type (int reloc_type);
1457 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1458 ST_FUNC void relocate_init(Section *sr);
1459 ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1460 ST_FUNC void relocate_plt(TCCState *s1);
1462 /* ------------ xxx-gen.c ------------ */
1464 ST_DATA const int reg_classes[NB_REGS];
1466 ST_FUNC void gsym_addr(int t, int a);
1467 ST_FUNC void gsym(int t);
1468 ST_FUNC void load(int r, SValue *sv);
1469 ST_FUNC void store(int r, SValue *v);
1470 ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
1471 ST_FUNC void gfunc_call(int nb_args);
1472 ST_FUNC void gfunc_prolog(CType *func_type);
1473 ST_FUNC void gfunc_epilog(void);
1474 ST_FUNC int gjmp(int t);
1475 ST_FUNC void gjmp_addr(int a);
1476 ST_FUNC int gtst(int inv, int t);
1477 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1478 ST_FUNC void gtst_addr(int inv, int a);
1479 #else
1480 #define gtst_addr(inv, a) gsym_addr(gtst(inv, 0), a)
1481 #endif
1482 ST_FUNC void gen_opi(int op);
1483 ST_FUNC void gen_opf(int op);
1484 ST_FUNC void gen_cvt_ftoi(int t);
1485 ST_FUNC void gen_cvt_ftof(int t);
1486 ST_FUNC void ggoto(void);
1487 #ifndef TCC_TARGET_C67
1488 ST_FUNC void o(unsigned int c);
1489 #endif
1490 #ifndef TCC_TARGET_ARM
1491 ST_FUNC void gen_cvt_itof(int t);
1492 #endif
1493 ST_FUNC void gen_vla_sp_save(int addr);
1494 ST_FUNC void gen_vla_sp_restore(int addr);
1495 ST_FUNC void gen_vla_alloc(CType *type, int align);
1497 static inline uint16_t read16le(unsigned char *p) {
1498 return p[0] | (uint16_t)p[1] << 8;
1500 static inline void write16le(unsigned char *p, uint16_t x) {
1501 p[0] = x & 255, p[1] = x >> 8 & 255;
1503 static inline uint32_t read32le(unsigned char *p) {
1504 return read16le(p) | (uint32_t)read16le(p + 2) << 16;
1506 static inline void write32le(unsigned char *p, uint32_t x) {
1507 write16le(p, x), write16le(p + 2, x >> 16);
1509 static inline void add32le(unsigned char *p, int32_t x) {
1510 write32le(p, read32le(p) + x);
1512 static inline uint64_t read64le(unsigned char *p) {
1513 return read32le(p) | (uint64_t)read32le(p + 4) << 32;
1515 static inline void write64le(unsigned char *p, uint64_t x) {
1516 write32le(p, x), write32le(p + 4, x >> 32);
1518 static inline void add64le(unsigned char *p, int64_t x) {
1519 write64le(p, read64le(p) + x);
1522 /* ------------ i386-gen.c ------------ */
1523 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1524 ST_FUNC void g(int c);
1525 ST_FUNC void gen_le16(int c);
1526 ST_FUNC void gen_le32(int c);
1527 ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1528 ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1529 #endif
1531 #ifdef CONFIG_TCC_BCHECK
1532 ST_FUNC void gen_bounded_ptr_add(void);
1533 ST_FUNC void gen_bounded_ptr_deref(void);
1534 #endif
1536 /* ------------ x86_64-gen.c ------------ */
1537 #ifdef TCC_TARGET_X86_64
1538 ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1539 ST_FUNC void gen_opl(int op);
1540 #endif
1542 /* ------------ arm-gen.c ------------ */
1543 #ifdef TCC_TARGET_ARM
1544 #if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
1545 PUB_FUNC const char *default_elfinterp(struct TCCState *s);
1546 #endif
1547 ST_FUNC void arm_init(struct TCCState *s);
1548 ST_FUNC void gen_cvt_itof1(int t);
1549 #endif
1551 /* ------------ arm64-gen.c ------------ */
1552 #ifdef TCC_TARGET_ARM64
1553 ST_FUNC void gen_cvt_sxtw(void);
1554 ST_FUNC void gen_opl(int op);
1555 ST_FUNC void gfunc_return(CType *func_type);
1556 ST_FUNC void gen_va_start(void);
1557 ST_FUNC void gen_va_arg(CType *t);
1558 ST_FUNC void gen_clear_cache(void);
1559 #endif
1561 /* ------------ c67-gen.c ------------ */
1562 #ifdef TCC_TARGET_C67
1563 #endif
1565 /* ------------ tcccoff.c ------------ */
1567 #ifdef TCC_TARGET_COFF
1568 ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1569 ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
1570 #endif
1572 /* ------------ tccasm.c ------------ */
1573 ST_FUNC void asm_instr(void);
1574 ST_FUNC void asm_global_instr(void);
1575 #ifdef CONFIG_TCC_ASM
1576 ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1577 ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
1578 ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1579 ST_FUNC int asm_int_expr(TCCState *s1);
1580 ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
1581 /* ------------ i386-asm.c ------------ */
1582 ST_FUNC void gen_expr32(ExprValue *pe);
1583 #ifdef TCC_TARGET_X86_64
1584 ST_FUNC void gen_expr64(ExprValue *pe);
1585 #endif
1586 ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1587 ST_FUNC int asm_parse_regvar(int t);
1588 ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1589 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1590 ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1591 ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
1592 #endif
1594 /* ------------ tccpe.c -------------- */
1595 #ifdef TCC_TARGET_PE
1596 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
1597 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1598 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
1599 #ifndef TCC_TARGET_ARM
1600 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
1601 #endif
1602 #ifdef TCC_TARGET_X86_64
1603 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
1604 #endif
1605 PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
1606 /* symbol properties stored in Elf32_Sym->st_other */
1607 # define ST_PE_EXPORT 0x10
1608 # define ST_PE_IMPORT 0x20
1609 # define ST_PE_STDCALL 0x40
1610 #endif
1612 /* ------------ tccrun.c ----------------- */
1613 #ifdef TCC_IS_NATIVE
1614 #ifdef CONFIG_TCC_STATIC
1615 #define RTLD_LAZY 0x001
1616 #define RTLD_NOW 0x002
1617 #define RTLD_GLOBAL 0x100
1618 #define RTLD_DEFAULT NULL
1619 /* dummy function for profiling */
1620 ST_FUNC void *dlopen(const char *filename, int flag);
1621 ST_FUNC void dlclose(void *p);
1622 ST_FUNC const char *dlerror(void);
1623 ST_FUNC void *dlsym(void *handle, const char *symbol);
1624 #endif
1625 #ifdef CONFIG_TCC_BACKTRACE
1626 ST_DATA int rt_num_callers;
1627 ST_DATA const char **rt_bound_error_msg;
1628 ST_DATA void *rt_prog_main;
1629 ST_FUNC void tcc_set_num_callers(int n);
1630 #endif
1631 ST_FUNC void tcc_run_free(TCCState *s1);
1632 #endif
1634 /* ------------ tcctools.c ----------------- */
1635 #if 0 /* included in tcc.c */
1636 ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
1637 #ifdef TCC_TARGET_PE
1638 ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
1639 #endif
1640 ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
1641 ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
1642 #endif
1644 /********************************************************/
1645 #undef ST_DATA
1646 #ifdef ONE_SOURCE
1647 #define ST_DATA static
1648 #else
1649 #define ST_DATA
1650 #endif
1651 /********************************************************/
1652 #endif /* _TCC_H */