Mercurial > hg > tinycc
annotate tcc.h @ 589:49d3fc246344
Small fix for building on a 64 bit host.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 06 Apr 2008 16:10:01 -0500 |
parents | 8e32c8615b39 |
children |
rev | line source |
---|---|
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * TCC - Tiny C Compiler |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * Copyright (c) 2001-2004 Fabrice Bellard |
499
2b451d2e68ea
Exercise LGPL clause 3 and convert more notices from LGPL to GPLv2. (If you
Rob Landley <rob@landley.net>
parents:
490
diff
changeset
|
5 * Copyright (C) 2006-2007 Rob Landley |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 * |
499
2b451d2e68ea
Exercise LGPL clause 3 and convert more notices from LGPL to GPLv2. (If you
Rob Landley <rob@landley.net>
parents:
490
diff
changeset
|
7 * Licensed under GPLv2, see file LICENSE in this tarball. |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
9 // #define _GNU_SOURCE |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 #ifdef CONFIG_TCCBOOT |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 #include "tccboot.h" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 #define CONFIG_TCC_STATIC |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 #else |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 #include <stdlib.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 #include <stdio.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 #include <stdarg.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 #include <string.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 #include <errno.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 #include <math.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 #include <unistd.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 #include <signal.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 #include <fcntl.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 #include <setjmp.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 #include <time.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 #ifdef WIN32 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 #include <sys/timeb.h> |
429
67c767fc07c8
Timovj Lahde says this tweak fixes building on windows. (I wouldn't know.)
Rob Landley <rob@landley.net>
parents:
426
diff
changeset
|
31 #else |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 #include <sys/time.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 #include <sys/mman.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 #endif /* !CONFIG_TCCBOOT */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 #ifndef PAGESIZE |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 #define PAGESIZE 4096 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 #include "elf.h" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 #include "stab.h" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 #ifndef O_BINARY |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 #define O_BINARY 0 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 |
519
ff406be3015d
The old build system doesn't apply to the current source anymore, remove it.
Rob Landley <rob@landley.net>
parents:
511
diff
changeset
|
49 #include "libtinycc.h" |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 /* parser debug */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 //#define PARSE_DEBUG |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 /* preprocessor debug */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 //#define PP_DEBUG |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 /* include file debug */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 //#define INC_DEBUG |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 /* assembler debug */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 //#define ASM_DEBUG |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 /* target selection */ |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
62 //#define TINYCC_TARGET_I386 /* i386 code generator */ |
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
63 //#define TINYCC_TARGET_ARM /* ARMv4 code generator */ |
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
64 //#define TINYCC_TARGET_C67 /* TMS320C67xx code generator */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 /* default target is I386 */ |
563 | 67 //#if !defined(TINYCC_TARGET_I386) && !defined(TINYCC_TARGET_ARM) && !defined(TINYCC_TARGET_C67) |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
68 //#define TINYCC_TARGET_I386 |
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
69 //#endif |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
71 #if !defined(WIN32) && !defined(TCC_UCLIBC) && !defined(TINYCC_TARGET_ARM) && \ |
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
72 !defined(TINYCC_TARGET_C67) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 #define CONFIG_TCC_BCHECK /* enable bound checking code */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
76 #if defined(WIN32) && !defined(TINYCC_TARGET_PE) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 #define CONFIG_TCC_STATIC |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 /* define it to include assembler support */ |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
81 #if !defined(TINYCC_TARGET_ARM) && !defined(TINYCC_TARGET_C67) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 #define CONFIG_TCC_ASM |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 /* object format selection */ |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
86 #if defined(TINYCC_TARGET_C67) |
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
87 #define TINYCC_TARGET_COFF |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 #define FALSE 0 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 #define false 0 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 #define TRUE 1 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 #define true 1 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 typedef int BOOL; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 #define INCLUDE_STACK_SIZE 32 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 #define IFDEF_STACK_SIZE 64 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 #define VSTACK_SIZE 256 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 #define STRING_MAX_SIZE 1024 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 #define PACK_STACK_SIZE 8 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 #define TOK_HASH_SIZE 8192 /* must be a power of two */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 #define TOK_ALLOC_INCR 512 /* must be a power of two */ |
453
a70ac19d704b
Stringize patch from Harald van Dijk:
Rob Landley <rob@landley.net>
parents:
447
diff
changeset
|
104 #define TOK_MAX_SIZE 5 /* token max size in int unit when stored in string */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 /* token symbol management */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 typedef struct TokenSym { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 struct TokenSym *hash_next; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 struct Sym *sym_define; /* direct pointer to define */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 struct Sym *sym_label; /* direct pointer to label */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 struct Sym *sym_struct; /* direct pointer to structure */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 struct Sym *sym_identifier; /* direct pointer to identifier */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 int tok; /* token number */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 int len; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 char str[1]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 } TokenSym; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 |
555
646f1f0972b6
Update TCC_TARGET_* to TINYCC_TARGET_* (which is what new build sets).
Rob Landley <rob@landley.net>
parents:
554
diff
changeset
|
118 #ifdef TINYCC_TARGET_PE |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 typedef unsigned short nwchar_t; |
510
f304c7e3de8d
Teach tcc.c to handle colon separated paths (semicolon separated on a win32
Rob Landley <rob@landley.net>
parents:
503
diff
changeset
|
120 #define LIB_PATH_SEPCHAR ';' |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 #else |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 typedef int nwchar_t; |
510
f304c7e3de8d
Teach tcc.c to handle colon separated paths (semicolon separated on a win32
Rob Landley <rob@landley.net>
parents:
503
diff
changeset
|
123 #define LIB_PATH_SEPCHAR ':' |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 typedef struct CString { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 int size; /* size in bytes */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 void *data; /* either 'char *' or 'nwchar_t *' */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 int size_allocated; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 void *data_allocated; /* if non NULL, data has been malloced */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 } CString; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 /* type definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 typedef struct CType { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 int t; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 struct Sym *ref; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 } CType; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 /* constant value */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 typedef union CValue { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 long double ld; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 double d; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 float f; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 int i; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 unsigned int ui; |
490
082f4509bce5
First bit of dynamic arrays. Doesn't work yet, but gives a specific error
Rob Landley <rob@landley.net>
parents:
481
diff
changeset
|
146 unsigned long ul; /* address (should be unsigned long on 64 bit cpu) */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 long long ll; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 unsigned long long ull; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 struct CString *cstr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 void *ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
151 int tab[1]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 } CValue; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 /* value on stack */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 typedef struct SValue { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 CType type; /* type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 unsigned short r; /* register + flags */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 unsigned short r2; /* second register, used for 'long long' |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 type. If not used, set to VT_CONST */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 CValue c; /* constant, if VT_CONST */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 } SValue; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 /* symbol management */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 typedef struct Sym { |
551
d8b3fa09ca5d
One of the members of "struct Sym" is a token. Rename it from "v" to "token", and change local variables
Rob Landley <rob@landley.net>
parents:
550
diff
changeset
|
166 int token; /* symbol token */ |
589
49d3fc246344
Small fix for building on a 64 bit host.
Rob Landley <rob@landley.net>
parents:
563
diff
changeset
|
167 long r; /* associated register */ |
550
cfb21030b240
Minor tweaks for building on a 64-bit host, and remove an unnecessary local variable.
Rob Landley <rob@landley.net>
parents:
545
diff
changeset
|
168 long c; /* associated number */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 CType type; /* associated type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 struct Sym *next; /* next related symbol */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 struct Sym *prev; /* prev symbol in stack */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 struct Sym *prev_tok; /* previous symbol for this token */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 } Sym; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 /* section definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 /* XXX: use directly ELF structure for parameters ? */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 /* special flag to indicate that the section should not be linked to |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 the other ones */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
179 #define SHF_PRIVATE 0x80000000 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 typedef struct Section { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 unsigned long data_offset; /* current data offset */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 unsigned char *data; /* section data */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 unsigned long data_allocated; /* used for realloc() handling */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 int sh_name; /* elf section name (only used during output) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 int sh_num; /* elf section number */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 int sh_type; /* elf section type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 int sh_flags; /* elf section flags */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 int sh_info; /* elf section info */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 int sh_addralign; /* elf section alignment */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
191 int sh_entsize; /* elf entry size */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 unsigned long sh_size; /* section size (only used during output) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 unsigned long sh_addr; /* address at which the section is relocated */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 unsigned long sh_offset; /* file offset */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 int nb_hashed_syms; /* used to resize the hash table */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
196 struct Section *link; /* link to another section */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
197 struct Section *reloc; /* corresponding section for relocation, if any */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 struct Section *hash; /* hash table for symbols */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 struct Section *next; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
200 char name[1]; /* section name */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 } Section; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
203 typedef struct DLLReference { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 int level; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 char name[1]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 } DLLReference; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
207 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
208 /* GNUC attribute definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 typedef struct AttributeDef { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
210 int aligned; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 int packed; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 Section *section; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
213 unsigned char func_call; /* FUNC_CDECL, FUNC_STDCALL, FUNC_FASTCALLx */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 unsigned char dllexport; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 } AttributeDef; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
220 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 /* stored in 'Sym.c' field */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 #define FUNC_NEW 1 /* ansi function prototype */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 #define FUNC_OLD 2 /* old function prototype */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
224 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 /* stored in 'Sym.r' field */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 #define FUNC_CDECL 0 /* standard c call */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
228 #define FUNC_STDCALL 1 /* pascal c call */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
229 #define FUNC_FASTCALL1 2 /* first param in %eax */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
230 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
231 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
232 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 /* field 'Sym.t' for macros */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 #define MACRO_OBJ 0 /* object like macro */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 #define MACRO_FUNC 1 /* function like macro */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
238 /* field 'Sym.r' for C labels */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
239 #define LABEL_DEFINED 0 /* label is defined */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
240 #define LABEL_FORWARD 1 /* label is forward defined */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
241 #define LABEL_DECLARED 2 /* label is declared but never used */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
242 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
243 /* type_decl() types */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
244 #define TYPE_ABSTRACT 1 /* type without variable */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
245 #define TYPE_DIRECT 2 /* type with variable */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
246 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
247 #define IO_BUF_SIZE 8192 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
248 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
249 typedef struct BufferedFile { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
250 uint8_t *buf_ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
251 uint8_t *buf_end; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
252 int fd; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
253 int line_num; /* current line number - here to simplify code */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
254 int ifndef_macro; /* #ifndef macro / #endif search */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
255 int ifndef_macro_saved; /* saved ifndef_macro */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
256 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
257 char inc_type; /* type of include */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
258 char inc_filename[512]; /* filename specified by the user */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
259 char filename[1024]; /* current filename - here to simplify code */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
260 unsigned char buffer[IO_BUF_SIZE + 1]; /* extra size for CH_EOB char */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
261 } BufferedFile; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
262 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
263 #define CH_EOB '\\' /* end of buffer or '\0' char in file */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
264 #define CH_EOF (-1) /* end of file */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
265 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
266 /* parsing state (used to save parser state to reparse part of the |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
267 source several times) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
268 typedef struct ParseState { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
269 int *macro_ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
270 int line_num; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
271 int tok; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
272 CValue tokc; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
273 } ParseState; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
274 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
275 /* used to record tokens */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
276 typedef struct TokenString { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
277 int *str; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
278 int len; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
279 int allocated_len; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
280 int last_line_num; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
281 } TokenString; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
282 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
283 /* include file cache, used to find files faster and also to eliminate |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
284 inclusion if the include file is protected by #ifndef ... #endif */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
285 typedef struct CachedInclude { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
286 int ifndef_macro; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
287 int hash_next; /* -1 if none */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
288 char type; /* '"' or '>' to give include type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
289 char filename[1]; /* path specified in #include */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
290 } CachedInclude; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
291 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
292 #define CACHED_INCLUDES_HASH_SIZE 512 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
293 |
430
b331c8f04d55
More shuffling stuff around to facilitate breaking it up into multiple
Rob Landley <rob@landley.net>
parents:
429
diff
changeset
|
294 /* additional information about token */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
295 //#define TOK_FLAG_BOW 0x0001 /* beginning of word before */ |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
296 //#define TOK_FLAG_BOL 0x0002 /* beginning of line before */ |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
297 //#define TOK_FLAG_BOF 0x0004 /* beginning of file before */ |
453
a70ac19d704b
Stringize patch from Harald van Dijk:
Rob Landley <rob@landley.net>
parents:
447
diff
changeset
|
298 #define TOK_FLAG_ENDIF 0x0008 /* a endif was found matching starting #ifdef */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
299 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
300 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
301 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
302 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
303 token. line feed is also |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
304 returned at eof */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
305 #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
306 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
307 #define SYM_POOL_NB (8192 / sizeof(Sym)) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
308 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
309 //struct dynarray { |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
310 // char **data; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
311 // int len; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
312 //}; |
520
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
313 |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
314 struct TCCState { |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
315 //int output_type; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
316 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
317 BufferedFile **include_stack_ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
318 int *ifdef_stack_ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
319 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
320 /* include file handling */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
321 // struct dynarray include_paths; |
521
22b60bb22c83
Convert more paths to add_dynarray_path().
Rob Landley <rob@landley.net>
parents:
520
diff
changeset
|
322 struct dynarray sysinclude_paths; |
520
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
323 |
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
324 //struct dynarray cached_includes; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
325 CachedInclude **cached_includes; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
326 int nb_cached_includes; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
327 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
328 // struct dynarray library_paths; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
329 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
330 /* array of all loaded dlls (including those referenced by loaded |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
331 dlls) */ |
520
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
332 //struct dynarray loaded_dlls; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
333 DLLReference **loaded_dlls; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
334 int nb_loaded_dlls; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
335 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
336 /* sections */ |
520
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
337 //struct dynarray sections; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
338 Section **sections; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
339 int nb_sections; /* number of sections, including first dummy section */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
340 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
341 /* got handling */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
342 Section *got; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
343 Section *plt; |
520
647f1a3feb8b
Add "struct dynarray" to group some dynamic array logic. Make the colon
Rob Landley <rob@landley.net>
parents:
519
diff
changeset
|
344 //struct dynarray got_offsets; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
345 unsigned long *got_offsets; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
346 int nb_got_offsets; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
347 /* give the correspondance from symtab indexes to dynsym indexes */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
348 int *symtab_to_dynsym; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
349 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
350 /* temporary dynamic symbol sections (for dll loading) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
351 Section *dynsymtab_section; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
352 /* exported dynamic symbol section */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
353 Section *dynsym; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
354 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
355 // int nostdinc; /* if true, no standard headers are added */ |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
356 // int nostdlib; /* if true, no standard libraries are added */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
357 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
358 //int nocommon; /* if true, do not use common symbols for .bss data */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
359 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
360 /* if true, static linking is performed */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
361 // int static_link; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
362 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
363 /* if true, all symbols are exported */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
364 // int rdynamic; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
365 |
523
d72f42753974
Add -v option (and -v -v, and -v -v -v).
Rob Landley <rob@landley.net>
parents:
521
diff
changeset
|
366 /* if true, describe each room as you enter it, unless it contains a grue */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
367 // int verbose; |
523
d72f42753974
Add -v option (and -v -v, and -v -v -v).
Rob Landley <rob@landley.net>
parents:
521
diff
changeset
|
368 |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
369 /* if true, only link in referenced objects from archive */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
370 int alacarte_link; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
371 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
372 /* address of text section */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
373 // unsigned long text_addr; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
374 // int has_text_addr; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
375 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
376 /* output format, see TCC_OUTPUT_FORMAT_xxx */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
377 // int output_format; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
378 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
379 /* C language options */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
380 //int char_is_unsigned; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
381 //int leading_underscore; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
382 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
383 /* warning switches */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
384 //int warn_write_strings; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
385 //int warn_unsupported; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
386 //int warn_error; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
387 //int warn_none; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
388 //int warn_implicit_function_declaration; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
389 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
390 /* error handling */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
391 void *error_opaque; |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
392 void (*error_func)(void *opaque, char *msg); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
393 int error_set_jmp_enabled; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
394 jmp_buf error_jmp_buf; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
395 int nb_errors; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
396 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
397 /* tiny assembler state */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
398 Sym *asm_labels; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
399 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
400 /* see include_stack_ptr */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
401 BufferedFile *include_stack[INCLUDE_STACK_SIZE]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
402 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
403 /* see ifdef_stack_ptr */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
404 int ifdef_stack[IFDEF_STACK_SIZE]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
405 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
406 /* see cached_includes */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
407 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
408 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
409 /* pack stack */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
410 int pack_stack[PACK_STACK_SIZE]; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
411 int *pack_stack_ptr; |
447
4aa3f7aa86f0
Switch from the earlier -E patch to the one Fabrice checked into CVS last year.
Rob Landley <rob@landley.net>
parents:
430
diff
changeset
|
412 |
4aa3f7aa86f0
Switch from the earlier -E patch to the one Fabrice checked into CVS last year.
Rob Landley <rob@landley.net>
parents:
430
diff
changeset
|
413 /* output file for preprocessing */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
414 // FILE *outfile; |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
415 }; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
416 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
417 /* The current value can be: */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
418 #define VT_VALMASK 0x00ff |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
419 #define VT_CONST 0x00f0 /* constant in vc |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
420 (must be first non register value) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
421 #define VT_LLOCAL 0x00f1 /* lvalue, offset on stack */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
422 #define VT_LOCAL 0x00f2 /* offset on stack */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
423 #define VT_CMP 0x00f3 /* the value is stored in processor flags (in vc) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
424 #define VT_JMP 0x00f4 /* value is the consequence of jmp true (even) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
425 #define VT_JMPI 0x00f5 /* value is the consequence of jmp false (odd) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
426 #define VT_LVAL 0x0100 /* var is an lvalue */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
427 #define VT_SYM 0x0200 /* a symbol value is added */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
428 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
429 char/short stored in integer registers) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
430 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
431 dereferencing value */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
432 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
433 bounding function call point is in vc */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
434 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
435 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
436 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
437 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
438 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
439 /* types */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
440 #define VT_INT 0 /* integer type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
441 #define VT_BYTE 1 /* signed byte type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
442 #define VT_SHORT 2 /* short type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
443 #define VT_VOID 3 /* void type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
444 #define VT_PTR 4 /* pointer */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
445 #define VT_ENUM 5 /* enum definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
446 #define VT_FUNC 6 /* function type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
447 #define VT_STRUCT 7 /* struct/union definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
448 #define VT_FLOAT 8 /* IEEE float */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
449 #define VT_DOUBLE 9 /* IEEE double */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
450 #define VT_LDOUBLE 10 /* IEEE long double */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
451 #define VT_BOOL 11 /* ISOC99 boolean type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
452 #define VT_LLONG 12 /* 64 bit integer */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
453 #define VT_LONG 13 /* long integer (NEVER USED as type, only |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
454 during parsing) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
455 #define VT_BTYPE 0x000f /* mask for basic type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
456 #define VT_UNSIGNED 0x0010 /* unsigned type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
457 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
458 #define VT_BITFIELD 0x0040 /* bitfield modifier */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
459 #define VT_CONSTANT 0x0800 /* const modifier */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
460 #define VT_VOLATILE 0x1000 /* volatile modifier */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
461 #define VT_SIGNED 0x2000 /* signed type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
462 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
463 /* storage */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
464 #define VT_EXTERN 0x00000080 /* extern definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
465 #define VT_STATIC 0x00000100 /* static variable */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
466 #define VT_TYPEDEF 0x00000200 /* typedef definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
467 #define VT_INLINE 0x00000400 /* inline definition */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
468 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
469 #define VT_STRUCT_SHIFT 16 /* shift for bitfield shift values */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
470 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
471 /* type mask (except storage) */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
472 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
473 #define VT_TYPE (~(VT_STORAGE)) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
474 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
475 /* token values */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
476 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
477 /* warning: the following compare tokens depend on i386 asm code */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
478 #define TOK_ULT 0x92 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
479 #define TOK_UGE 0x93 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
480 #define TOK_EQ 0x94 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
481 #define TOK_NE 0x95 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
482 #define TOK_ULE 0x96 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
483 #define TOK_UGT 0x97 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
484 #define TOK_Nset 0x98 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
485 #define TOK_Nclear 0x99 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
486 #define TOK_LT 0x9c |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
487 #define TOK_GE 0x9d |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
488 #define TOK_LE 0x9e |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
489 #define TOK_GT 0x9f |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
490 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
491 #define TOK_LAND 0xa0 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
492 #define TOK_LOR 0xa1 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
493 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
494 #define TOK_DEC 0xa2 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
495 #define TOK_MID 0xa3 /* inc/dec, to void constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
496 #define TOK_INC 0xa4 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
497 #define TOK_UDIV 0xb0 /* unsigned division */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
498 #define TOK_UMOD 0xb1 /* unsigned modulo */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
499 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
500 #define TOK_CINT 0xb3 /* number in tokc */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
501 #define TOK_CCHAR 0xb4 /* char constant in tokc */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
502 #define TOK_STR 0xb5 /* pointer to string in tokc */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
503 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
504 #define TOK_LCHAR 0xb7 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
505 #define TOK_LSTR 0xb8 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
506 #define TOK_CFLOAT 0xb9 /* float constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
507 #define TOK_LINENUM 0xba /* line number info */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
508 #define TOK_CDOUBLE 0xc0 /* double constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
509 #define TOK_CLDOUBLE 0xc1 /* long double constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
510 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
511 #define TOK_ADDC1 0xc3 /* add with carry generation */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
512 #define TOK_ADDC2 0xc4 /* add with carry use */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
513 #define TOK_SUBC1 0xc5 /* add with carry generation */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
514 #define TOK_SUBC2 0xc6 /* add with carry use */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
515 #define TOK_CUINT 0xc8 /* unsigned int constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
516 #define TOK_CLLONG 0xc9 /* long long constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
517 #define TOK_CULLONG 0xca /* unsigned long long constant */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
518 #define TOK_ARROW 0xcb |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
519 #define TOK_DOTS 0xcc /* three dots */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
520 #define TOK_SHR 0xcd /* unsigned shift right */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
521 #define TOK_PPNUM 0xce /* preprocessor number */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
522 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
523 #define TOK_SHL 0x01 /* shift left */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
524 #define TOK_SAR 0x02 /* signed shift right */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
525 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
526 /* assignement operators : normal operator or 0x80 */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
527 #define TOK_A_MOD 0xa5 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
528 #define TOK_A_AND 0xa6 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
529 #define TOK_A_MUL 0xaa |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
530 #define TOK_A_ADD 0xab |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
531 #define TOK_A_SUB 0xad |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
532 #define TOK_A_DIV 0xaf |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
533 #define TOK_A_XOR 0xde |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
534 #define TOK_A_OR 0xfc |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
535 #define TOK_A_SHL 0x81 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
536 #define TOK_A_SAR 0x82 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
537 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
538 //#ifndef offsetof |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
539 //#define offsetof(type, field) ((size_t) &((type *)0)->field) |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
540 //#endif |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
541 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
542 //#ifndef countof |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
543 //#define countof(tab) (sizeof(tab) / sizeof((tab)[0])) |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
544 //#endif |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
545 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
546 /* WARNING: the content of this string encodes token numbers */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
547 static unsigned char tok_two_chars[] = "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266"; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
548 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
549 #define TOK_EOF (-1) /* end of file */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
550 #define TOK_LINEFEED 10 /* line feed */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
551 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
552 /* all identificators and strings have token above that */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
553 //#define TOK_IDENT 256 |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
554 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
555 /* only used for i386 asm opcodes definitions */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
556 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
557 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
558 #define DEF_BWL(x) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
559 DEF(TOK_ASM_ ## x ## b, #x "b") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
560 DEF(TOK_ASM_ ## x ## w, #x "w") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
561 DEF(TOK_ASM_ ## x ## l, #x "l") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
562 DEF(TOK_ASM_ ## x, #x) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
563 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
564 #define DEF_WL(x) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
565 DEF(TOK_ASM_ ## x ## w, #x "w") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
566 DEF(TOK_ASM_ ## x ## l, #x "l") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
567 DEF(TOK_ASM_ ## x, #x) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
568 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
569 #define DEF_FP1(x) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
570 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
571 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
572 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
573 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s") |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
574 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
575 #define DEF_FP(x) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
576 DEF(TOK_ASM_ ## f ## x, "f" #x ) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
577 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
578 DEF_FP1(x) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
579 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
580 #define DEF_ASMTEST(x) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
581 DEF_ASM(x ## o) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
582 DEF_ASM(x ## no) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
583 DEF_ASM(x ## b) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
584 DEF_ASM(x ## c) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
585 DEF_ASM(x ## nae) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
586 DEF_ASM(x ## nb) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
587 DEF_ASM(x ## nc) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
588 DEF_ASM(x ## ae) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
589 DEF_ASM(x ## e) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
590 DEF_ASM(x ## z) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
591 DEF_ASM(x ## ne) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
592 DEF_ASM(x ## nz) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
593 DEF_ASM(x ## be) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
594 DEF_ASM(x ## na) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
595 DEF_ASM(x ## nbe) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
596 DEF_ASM(x ## a) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
597 DEF_ASM(x ## s) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
598 DEF_ASM(x ## ns) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
599 DEF_ASM(x ## p) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
600 DEF_ASM(x ## pe) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
601 DEF_ASM(x ## np) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
602 DEF_ASM(x ## po) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
603 DEF_ASM(x ## l) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
604 DEF_ASM(x ## nge) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
605 DEF_ASM(x ## nl) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
606 DEF_ASM(x ## ge) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
607 DEF_ASM(x ## le) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
608 DEF_ASM(x ## ng) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
609 DEF_ASM(x ## nle) \ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
610 DEF_ASM(x ## g) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
611 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
612 #define TOK_ASM_int TOK_INT |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
613 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
614 enum tcc_token { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
615 TOK_LAST = TOK_IDENT - 1, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
616 #define DEF(id, str) id, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
617 #include "tcctok.h" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
618 #undef DEF |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
619 }; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
620 |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
621 static char tcc_keywords[] = |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
622 #define DEF(id, str) str "\0" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
623 #include "tcctok.h" |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
624 #undef DEF |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
625 ; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
626 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
627 #define TOK_UIDENT TOK_DEFINE |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
628 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
629 #ifdef WIN32 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
630 int __stdcall GetModuleFileNameA(void *, char *, int); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
631 void *__stdcall GetProcAddress(void *, const char *); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
632 void *__stdcall GetModuleHandleA(const char *); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
633 void *__stdcall LoadLibraryA(const char *); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
634 int __stdcall FreeConsole(void); |
429
67c767fc07c8
Timovj Lahde says this tweak fixes building on windows. (I wouldn't know.)
Rob Landley <rob@landley.net>
parents:
426
diff
changeset
|
635 int __stdcall VirtualProtect(void*,int,int,int*); |
67c767fc07c8
Timovj Lahde says this tweak fixes building on windows. (I wouldn't know.)
Rob Landley <rob@landley.net>
parents:
426
diff
changeset
|
636 #define PAGE_EXECUTE_READWRITE 0x40 |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
637 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
638 #define snprintf _snprintf |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
639 #define vsnprintf _vsnprintf |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
640 #ifndef __GNUC__ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
641 #define strtold (long double)strtod |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
642 #define strtof (float)strtod |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
643 #define strtoll (long long)strtol |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
644 #endif |
467
b8971268a804
minor changes to enable compilation on OpenBSD
Gregg Reynolds <gar@kbui.org>
parents:
461
diff
changeset
|
645 #elif (defined(TCC_UCLIBC) || \ |
b8971268a804
minor changes to enable compilation on OpenBSD
Gregg Reynolds <gar@kbui.org>
parents:
461
diff
changeset
|
646 defined(__FreeBSD__) || \ |
b8971268a804
minor changes to enable compilation on OpenBSD
Gregg Reynolds <gar@kbui.org>
parents:
461
diff
changeset
|
647 defined(__DragonFly__) || \ |
b8971268a804
minor changes to enable compilation on OpenBSD
Gregg Reynolds <gar@kbui.org>
parents:
461
diff
changeset
|
648 defined(__OpenBSD__)) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
649 /* currently incorrect */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
650 static inline long double strtold(const char *nptr, char **endptr) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
651 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
652 return (long double)strtod(nptr, endptr); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
653 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
654 static inline float strtof(const char *nptr, char **endptr) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
655 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
656 return (float)strtod(nptr, endptr); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
657 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
658 #else |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
659 /* XXX: need to define this to use them in non ISOC99 context */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
660 extern float strtof (const char *__nptr, char **__endptr); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
661 extern long double strtold (const char *__nptr, char **__endptr); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
662 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
663 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
664 //char *pstrcpy(char *buf, int buf_size, char *s); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
665 static char *pstrcat(char *buf, int buf_size, char *s); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
666 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
667 static void next(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
668 static void next_nomacro(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
669 static void parse_expr_type(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
670 static void expr_type(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
671 static void unary_type(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
672 static void block(int *bsym, int *csym, int *case_sym, int *def_sym, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
673 int case_reg, int is_expr); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
674 static int expr_const(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
675 static void expr_eq(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
676 static void gexpr(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
677 static void gen_inline_functions(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
678 static void decl(int l); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
679 static void decl_initializer(CType *type, Section *sec, unsigned long c, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
680 int first, int size_only); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
681 static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
682 int has_init, int v, int scope); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
683 int gv(int rc); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
684 void gv2(int rc1, int rc2); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
685 void move_reg(int r, int s); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
686 void save_regs(int n); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
687 void save_reg(int r); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
688 void vpop(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
689 void vswap(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
690 void vdup(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
691 int get_reg(int rc); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
692 int get_reg_ex(int rc,int rc2); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
693 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
694 struct macro_level { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
695 struct macro_level *prev; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
696 int *p; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
697 }; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
698 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
699 static void macro_subst(TokenString *tok_str, Sym **nested_list, |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
700 int *macro_str, struct macro_level **can_read_stream); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
701 void gen_op(int op); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
702 void force_charshort_cast(int t); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
703 static void gen_cast(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
704 void vstore(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
705 static Sym *sym_find(int v); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
706 static Sym *sym_push(int v, CType *type, int r, int c); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
707 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
708 /* type handling */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
709 static int type_size(CType *type, int *a); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
710 static inline CType *pointed_type(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
711 static int pointed_size(CType *type); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
712 static int lvalue_type(int t); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
713 static int parse_btype(CType *type, AttributeDef *ad); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
714 static void type_decl(CType *type, AttributeDef *ad, int *v, int td); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
715 static int is_compatible_types(CType *type1, CType *type2); |
490
082f4509bce5
First bit of dynamic arrays. Doesn't work yet, but gives a specific error
Rob Landley <rob@landley.net>
parents:
481
diff
changeset
|
716 static void expr_const1(void); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
717 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
718 int ieee_finite(double d); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
719 void error(char *fmt, ...); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
720 void vpushi(int v); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
721 void vrott(int n); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
722 void vnrott(int n); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
723 void lexpand_nr(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
724 static void vpush_global_sym(CType *type, int v); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
725 void vset(CType *type, int r, int v); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
726 void type_to_str(char *buf, int buf_size, |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
727 CType *type, char *varstr); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
728 char *get_tok_str(int v, CValue *cv); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
729 static Sym *get_sym_ref(CType *type, Section *sec, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
730 unsigned long offset, unsigned long size); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
731 static Sym *external_global_sym(int v, CType *type, int r); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
732 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
733 /* section generation */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
734 static void section_realloc(Section *sec, unsigned long new_size); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
735 static void *section_ptr_add(Section *sec, unsigned long size); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
736 static void put_extern_sym(Sym *sym, Section *section, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
737 unsigned long value, unsigned long size); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
738 static void greloc(Section *s, Sym *sym, unsigned long addr, int type); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
739 static int put_elf_str(Section *s, char *sym); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
740 static int put_elf_sym(Section *s, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
741 unsigned long value, unsigned long size, |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
742 int info, int other, int shndx, char *name); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
743 static int add_elf_sym(Section *s, unsigned long value, unsigned long size, |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
744 int info, int other, int sh_num, char *name); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
745 static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
746 int type, int symbol); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
747 static void put_stabs(char *str, int type, int other, int desc, |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
748 unsigned long value); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
749 static void put_stabs_r(char *str, int type, int other, int desc, |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
750 unsigned long value, Section *sec, int sym_index); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
751 static void put_stabn(int type, int other, int desc, int value); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
752 static void put_stabd(int type, int other, int desc); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
753 static int tcc_add_dll(TCCState *s, char *filename, int flags); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
754 |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
755 //#define AFF_PRINT_ERROR 0x0001 /* print error if file not found */ |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
756 #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
757 //#define AFF_PREPROCESS 0x0004 /* preprocess file */ |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
758 //int tcc_add_file_internal(TCCState *s, char *filename, int flags); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
759 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
760 /* tcccoff.c */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
761 int tcc_output_coff(TCCState *s1, FILE *f); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
762 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
763 /* tccpe.c */ |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
764 static void *resolve_sym(TCCState *s1, char *sym, int type); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
765 int pe_load_def_file(struct TCCState *s1, FILE *fp); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
766 void pe_setup_paths(struct TCCState *s1, int *p_output_type, char **p_outfile, char *first_file); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
767 unsigned long pe_add_runtime(struct TCCState *s1); |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
768 int tcc_output_pe(struct TCCState *s1, char *filename); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
769 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
770 /* tccasm.c */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
771 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
772 #ifdef CONFIG_TCC_ASM |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
773 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
774 typedef struct ExprValue { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
775 uint32_t v; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
776 Sym *sym; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
777 } ExprValue; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
778 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
779 #define MAX_ASM_OPERANDS 30 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
780 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
781 typedef struct ASMOperand { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
782 int id; /* GCC 3 optionnal identifier (0 if number only supported */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
783 char *constraint; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
784 char asm_str[16]; /* computed asm string for operand */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
785 SValue *vt; /* C value of the expression */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
786 int ref_index; /* if >= 0, gives reference to a output constraint */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
787 int input_index; /* if >= 0, gives reference to an input constraint */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
788 int priority; /* priority, used to assign registers */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
789 int reg; /* if >= 0, register number used for this operand */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
790 int is_llong; /* true if double register value */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
791 int is_memory; /* true if memory operand */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
792 int is_rw; /* for '+' modifier */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
793 } ASMOperand; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
794 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
795 static void asm_expr(TCCState *s1, ExprValue *pe); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
796 static int asm_int_expr(TCCState *s1); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
797 static int find_constraint(ASMOperand *operands, int nb_operands, |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
798 char *name, char **pp); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
799 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
800 static int tcc_assemble(TCCState *s1, int do_preprocess); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
801 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
802 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
803 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
804 static void asm_instr(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
805 static void asm_global_instr(void); |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
806 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
807 /* true if float/double/long double type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
808 static inline int is_float(int t) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
809 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
810 int bt; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
811 bt = t & VT_BTYPE; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
812 return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
813 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
814 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
815 /* true if long long type */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
816 static inline int is_llong(int t) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
817 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
818 int bt; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
819 bt = t & VT_BTYPE; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
820 return bt == VT_LLONG; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
821 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
822 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
823 #ifdef CONFIG_TCC_STATIC |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
824 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
825 #define RTLD_LAZY 0x001 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
826 #define RTLD_NOW 0x002 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
827 #define RTLD_GLOBAL 0x100 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
828 #define RTLD_DEFAULT NULL |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
829 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
830 typedef struct TCCSyms { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
831 char *str; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
832 void *ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
833 } TCCSyms; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
834 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
835 #define TCCSYM(a) { #a, &a, }, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
836 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
837 /* add the symbol you want here if no dynamic linking is done */ |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
838 static TCCSyms tcc_syms[] = { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
839 #if !defined(CONFIG_TCCBOOT) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
840 TCCSYM(printf) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
841 TCCSYM(fprintf) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
842 TCCSYM(fopen) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
843 TCCSYM(fclose) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
844 #endif |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
845 { NULL, NULL }, |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
846 }; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
847 |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
848 static void *resolve_sym(TCCState *s1, char *symbol, int type) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
849 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
850 TCCSyms *p; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
851 p = tcc_syms; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
852 while (p->str != NULL) { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
853 if (!strcmp(p->str, symbol)) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
854 return p->ptr; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
855 p++; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
856 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
857 return NULL; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
858 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
859 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
860 /* dummy function for profiling */ |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
861 void *dlopen(char *filename, int flag) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
862 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
863 return NULL; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
864 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
865 |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
866 char *dlerror(void) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
867 { |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
868 return "error"; |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
869 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
870 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
871 #elif !defined(WIN32) |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
872 |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
873 #include <dlfcn.h> |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
874 |
553
4533aa54ffcf
More simplification and attacking warnings.
Rob Landley <rob@landley.net>
parents:
551
diff
changeset
|
875 static inline void *resolve_sym(TCCState *s1, char *sym, int type) |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
876 { |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
877 return dlsym(0, sym); |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
878 } |
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
879 |
545
11d95002dfe1
Split option parsing logic into a separate source file.
Rob Landley <rob@landley.net>
parents:
529
diff
changeset
|
880 /* space excluding newline */ |
554
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
881 //static inline int is_space(int ch) |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
882 //{ |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
883 // return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; |
8c020de0af57
Fix earlier options.c break-up by migrating some stuff from tcc.h to tinycc.h.
Rob Landley <rob@landley.net>
parents:
553
diff
changeset
|
884 //} |
545
11d95002dfe1
Split option parsing logic into a separate source file.
Rob Landley <rob@landley.net>
parents:
529
diff
changeset
|
885 |
11d95002dfe1
Split option parsing logic into a separate source file.
Rob Landley <rob@landley.net>
parents:
529
diff
changeset
|
886 |
426
ac0ea0043e55
Start breaking up tcc.c, starting with tcc.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
887 #endif |