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