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