History

allow tcc be build from separate objects

If you want that, run: make NOTALLINONE=1

grischka committed 16 years ago

Commit 88a3cca1 parent 7fa712e16 files · +1317 −1040Browse files

Unified · Split

16 files
  1. Makefile +26 −13
  2. arm-gen.c +39 −31
  3. c67-gen.c +50 −45
  4. i386-asm.c +11 −9
  5. i386-gen.c +44 −34
  6. libtcc.c +108 −624
  7. tcc.c +16 −16
  8. tcc.h +406 −28
  9. tccasm.c +10 −8
  10. tcccoff.c +3 −1
  11. tccelf.c +27 −35
  12. tccgen.c +290 −52
  13. tccpe.c +62 −67
  14. tccpp.c +179 −42
  15. tccrun.c +22 −21
  16. x86_64-gen.c +24 −14
Makefile+26−13
@@ -113,11 +113,13 @@ ifdef CONFIG_CROSS · 112 unmodified lines
113113 PROGS+=$(PROGS_CROSS)
114114 endif
115115
116+# NOTALLINONE = 1
117+
116118 all: $(PROGS) $(LIBTCC1) $(BCHECK_O) libtcc.a tcc-doc.html tcc.1 libtcc_test$(EXESUF)
117119
118120 # Host Tiny C Compiler
119−tcc$(EXESUF): $(NATIVE_FILES)
120− $(CC) -o $@ $< $(NATIVE_TARGET) $(CFLAGS) $(LIBS)
121+tcc$(EXESUF): tcc.o libtcc.a
122+ $(CC) -o $@ $^ $(LIBS)
121123
122124 # Cross Tiny C Compilers
123125 i386-tcc$(EXESUF): $(I386_FILES)
@@ -151,10 +153,22 @@ arm-tcc-vfp-eabi$(EXESUF): $(ARM_FILES) · 27 unmodified lines
151153 $(CC) -o $@ $< -DTCC_TARGET_ARM -DTCC_ARM_EABI $(CFLAGS) $(LIBS)
152154
153155 # libtcc generation and test
154−libtcc.o: $(NATIVE_FILES)
155− $(CC) -o $@ -c libtcc.c $(NATIVE_TARGET) $(CFLAGS)
156156
157−libtcc.a: libtcc.o
157+ifdef NOTALLINONE
158+LIBTCC_OBJ = $(filter-out tcc.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
159+LIBTCC_INC = $(filter %.h,$(CORE_FILES)) $(filter-out $(CORE_FILES),$(NATIVE_FILES))
160+$(LIBTCC_OBJ) : DEFINES += -DNOTALLINONE
161+else
162+LIBTCC_OBJ = libtcc.o
163+LIBTCC_INC = $(NATIVE_FILES)
164+endif
165+
166+tcc.o : DEFINES += -DNOTALLINONE
167+
168+$(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
169+ $(CC) -o $@ -c $< $(NATIVE_TARGET) $(CFLAGS) $(DEFINES)
170+
171+libtcc.a: $(LIBTCC_OBJ)
158172 $(AR) rcs $@ $^
159173
160174 libtcc_test$(EXESUF): tests/libtcc_test.c libtcc.a
@@ -260,19 +274,18 @@ tar: · 99 unmodified lines
260274 rm -rf /tmp/$(TCC-VERSION)
261275
262276 # in tests subdir
263−test clean:
277+%est:
264278 $(MAKE) -C tests $@
265279
266−config.mak:
267− @echo Running configure ...
268− @./configure
269−
270−# clean
271−clean: local_clean
272−local_clean:
280+clean:
273281 rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.out libtcc_test$(EXESUF)
282+ $(MAKE) -C tests $@
274283
275284 distclean: clean
276285 rm -vf config.h config.mak config.texi tcc.1
277286
287+config.mak:
288+ @echo Running configure ...
289+ @./configure
290+
278291 endif # ifeq ($(TOP),.)
arm-gen.c+39−31
@@ -20,11 +20,12 @@ · 19 unmodified lines
2020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121 */
2222
23+#ifdef TARGET_DEFS_ONLY
24+
2325 #ifdef TCC_ARM_EABI
2426 #define TCC_ARM_VFP
2527 #endif
2628
27−
2829 /* number of available registers */
2930 #ifdef TCC_ARM_VFP
3031 #define NB_REGS 13
@@ -75,32 +76,6 @@ enum { · 44 unmodified lines
7576 #endif
7677 };
7778
78−const int reg_classes[NB_REGS] = {
79− /* r0 */ RC_INT | RC_R0,
80− /* r1 */ RC_INT | RC_R1,
81− /* r2 */ RC_INT | RC_R2,
82− /* r3 */ RC_INT | RC_R3,
83− /* r12 */ RC_INT | RC_R12,
84− /* f0 */ RC_FLOAT | RC_F0,
85− /* f1 */ RC_FLOAT | RC_F1,
86− /* f2 */ RC_FLOAT | RC_F2,
87− /* f3 */ RC_FLOAT | RC_F3,
88−#ifdef TCC_ARM_VFP
89− /* d4/s8 */ RC_FLOAT | RC_F4,
90−/* d5/s10 */ RC_FLOAT | RC_F5,
91−/* d6/s12 */ RC_FLOAT | RC_F6,
92−/* d7/s14 */ RC_FLOAT | RC_F7,
93−#endif
94−};
95−
96−static int two2mask(int a,int b) {
97− return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT);
98−}
99−
100−static int regmask(int r) {
101− return reg_classes[r]&~(RC_INT|RC_FLOAT);
102−}
103−
10479 #ifdef TCC_ARM_VFP
10580 #define T2CPR(t) (((t) & VT_BTYPE) != VT_FLOAT ? 0x100 : 0)
10681 #endif
@@ -171,10 +146,42 @@ static CType float_type, double_type, func_float_type, func_double_type; · 64 unmodified lines
171146 #define ELF_PAGE_SIZE 0x1000
172147
173148 /******************************************************/
149+#else /* ! TARGET_DEFS_ONLY */
150+/******************************************************/
151+#include "tcc.h"
152+
153+ST_DATA const int reg_classes[NB_REGS] = {
154+ /* r0 */ RC_INT | RC_R0,
155+ /* r1 */ RC_INT | RC_R1,
156+ /* r2 */ RC_INT | RC_R2,
157+ /* r3 */ RC_INT | RC_R3,
158+ /* r12 */ RC_INT | RC_R12,
159+ /* f0 */ RC_FLOAT | RC_F0,
160+ /* f1 */ RC_FLOAT | RC_F1,
161+ /* f2 */ RC_FLOAT | RC_F2,
162+ /* f3 */ RC_FLOAT | RC_F3,
163+#ifdef TCC_ARM_VFP
164+ /* d4/s8 */ RC_FLOAT | RC_F4,
165+/* d5/s10 */ RC_FLOAT | RC_F5,
166+/* d6/s12 */ RC_FLOAT | RC_F6,
167+/* d7/s14 */ RC_FLOAT | RC_F7,
168+#endif
169+};
170+
174171 static unsigned long func_sub_sp_offset,last_itod_magic;
175172 static int leaffunc;
176173
177−void o(unsigned long i)
174+static int two2mask(int a,int b) {
175+ return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT);
176+}
177+
178+static int regmask(int r) {
179+ return reg_classes[r]&~(RC_INT|RC_FLOAT);
180+}
181+
182+/******************************************************/
183+
184+void o(unsigned int i)
178185 {
179186 /* this is a good place to start adding big-endian support*/
180187 int ind1;
@@ -304,7 +311,7 @@ void stuff_const_harder(unsigned long op,unsigned long v) { · 123 unmodified lines
304311 }
305312 }
306313
307−unsigned long encbranch(int pos,int addr,int fail)
314+ST_FUNC unsigned long encbranch(int pos,int addr,int fail)
308315 {
309316 addr-=pos+8;
310317 addr/=4;
@@ -1571,7 +1578,7 @@ void gen_opf(int op) · 1260 unmodified lines
15711578
15721579 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
15731580 and 'long long' cases. */
1574−void gen_cvt_itof1(int t)
1581+ST_FUNC void gen_cvt_itof1(int t)
15751582 {
15761583 int r,r2,bt;
15771584 bt=vtop->type.t & VT_BTYPE;
@@ -1732,4 +1739,5 @@ void ggoto(void) · 154 unmodified lines
17321739
17331740 /* end of ARM code generator */
17341741 /*************************************************************/
1735−
1742+#endif
1743+/*************************************************************/
c67-gen.c+50−45
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#ifdef TARGET_DEFS_ONLY
22+
2123 //#define ASSEMBLY_LISTING_C67
2224
2325 /* number of available registers */
@@ -85,62 +87,18 @@ enum { · 61 unmodified lines
8587 TREG_C67_B13,
8688 };
8789
88−const int reg_classes[NB_REGS] = {
89− /* eax */ RC_INT | RC_FLOAT | RC_EAX,
90− // only allow even regs for floats (allow for doubles)
91− /* ecx */ RC_INT | RC_ECX,
92− /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX,
93− // only allow even regs for floats (allow for doubles)
94− /* st0 */ RC_INT | RC_INT_BSIDE | RC_ST0,
95− /* A4 */ RC_C67_A4,
96− /* A5 */ RC_C67_A5,
97− /* B4 */ RC_C67_B4,
98− /* B5 */ RC_C67_B5,
99− /* A6 */ RC_C67_A6,
100− /* A7 */ RC_C67_A7,
101− /* B6 */ RC_C67_B6,
102− /* B7 */ RC_C67_B7,
103− /* A8 */ RC_C67_A8,
104− /* A9 */ RC_C67_A9,
105− /* B8 */ RC_C67_B8,
106− /* B9 */ RC_C67_B9,
107− /* A10 */ RC_C67_A10,
108− /* A11 */ RC_C67_A11,
109− /* B10 */ RC_C67_B10,
110− /* B11 */ RC_C67_B11,
111− /* A12 */ RC_C67_A10,
112− /* A13 */ RC_C67_A11,
113− /* B12 */ RC_C67_B10,
114− /* B13 */ RC_C67_B11
115−};
116−
11790 /* return registers for function */
11891 #define REG_IRET TREG_C67_A4 /* single word int return register */
11992 #define REG_LRET TREG_C67_A5 /* second word return register (for long long) */
12093 #define REG_FRET TREG_C67_A4 /* float return register */
12194
122−
12395 #define ALWAYS_ASSERT(x) \
12496 do {\
12597 if (!(x))\
12698 error("internal compiler error file at %s:%d", __FILE__, __LINE__);\
12799 } while (0)
128100
129−// although tcc thinks it is passing parameters on the stack,
130−// the C67 really passes up to the first 10 params in special
131−// regs or regs pairs (for 64 bit params). So keep track of
132−// the stack offsets so we can translate to the appropriate
133−// reg (pair)
134−
135−
136−#define NoCallArgsPassedOnStack 10
137−int NoOfCurFuncArgs;
138−int TranslateStackToReg[NoCallArgsPassedOnStack];
139−int ParamLocOnStack[NoCallArgsPassedOnStack];
140−int TotalBytesPushedOnStack;
141−
142101 /* defined if function parameters must be evaluated in reverse order */
143−
144102 //#define INVERT_FUNC_PARAMS
145103
146104 /* defined if structures are passed as pointers. Otherwise structures
@@ -171,7 +129,52 @@ int TotalBytesPushedOnStack; · 24 unmodified lines
171129 #define ELF_PAGE_SIZE 0x1000
172130
173131 /******************************************************/
132+#else /* ! TARGET_DEFS_ONLY */
133+/******************************************************/
134+#include "tcc.h"
135+
136+ST_DATA const int reg_classes[NB_REGS] = {
137+ /* eax */ RC_INT | RC_FLOAT | RC_EAX,
138+ // only allow even regs for floats (allow for doubles)
139+ /* ecx */ RC_INT | RC_ECX,
140+ /* edx */ RC_INT | RC_INT_BSIDE | RC_FLOAT | RC_EDX,
141+ // only allow even regs for floats (allow for doubles)
142+ /* st0 */ RC_INT | RC_INT_BSIDE | RC_ST0,
143+ /* A4 */ RC_C67_A4,
144+ /* A5 */ RC_C67_A5,
145+ /* B4 */ RC_C67_B4,
146+ /* B5 */ RC_C67_B5,
147+ /* A6 */ RC_C67_A6,
148+ /* A7 */ RC_C67_A7,
149+ /* B6 */ RC_C67_B6,
150+ /* B7 */ RC_C67_B7,
151+ /* A8 */ RC_C67_A8,
152+ /* A9 */ RC_C67_A9,
153+ /* B8 */ RC_C67_B8,
154+ /* B9 */ RC_C67_B9,
155+ /* A10 */ RC_C67_A10,
156+ /* A11 */ RC_C67_A11,
157+ /* B10 */ RC_C67_B10,
158+ /* B11 */ RC_C67_B11,
159+ /* A12 */ RC_C67_A10,
160+ /* A13 */ RC_C67_A11,
161+ /* B12 */ RC_C67_B10,
162+ /* B13 */ RC_C67_B11
163+};
164+
165+// although tcc thinks it is passing parameters on the stack,
166+// the C67 really passes up to the first 10 params in special
167+// regs or regs pairs (for 64 bit params). So keep track of
168+// the stack offsets so we can translate to the appropriate
169+// reg (pair)
170+
171+#define NoCallArgsPassedOnStack 10
172+int NoOfCurFuncArgs;
173+int TranslateStackToReg[NoCallArgsPassedOnStack];
174+int ParamLocOnStack[NoCallArgsPassedOnStack];
175+int TotalBytesPushedOnStack;
174176
177+/******************************************************/
175178 static unsigned long func_sub_sp_offset;
176179 static int func_ret_sub;
177180
@@ -2545,5 +2548,7 @@ void ggoto(void) · 2367 unmodified lines
25452548 vtop--;
25462549 }
25472550
2548−/* end of X86 code generator */
2551+/* end of C67 code generator */
2552+/*************************************************************/
2553+#endif
25492554 /*************************************************************/
i386-asm.c+11−9
@@ -19,7 +19,11 @@ · 18 unmodified lines
1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2020 */
2121
22+#include "tcc.h"
23+
24+// #define NB_ASM_REGS 8
2225 #define MAX_OPERANDS 3
26+#define NB_SAVED_REGS 3
2327
2428 #define TOK_ASM_first TOK_ASM_clc
2529 #define TOK_ASM_last TOK_ASM_emms
@@ -398,7 +402,8 @@ static void parse_operand(TCCState *s1, Operand *op) · 372 unmodified lines
398402 op->type |= indir;
399403 }
400404
401−static void gen_expr32(ExprValue *pe)
405+/* XXX: unify with C code output ? */
406+ST_FUNC void gen_expr32(ExprValue *pe)
402407 {
403408 gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
404409 }
@@ -554,7 +559,7 @@ static inline void asm_modrm(int reg, Operand *op) · 149 unmodified lines
554559 }
555560 }
556561
557−static void asm_opcode(TCCState *s1, int opcode)
562+ST_FUNC void asm_opcode(TCCState *s1, int opcode)
558563 {
559564 const ASMInstr *pa;
560565 int i, modrm_index, reg, v, op1, is_short_jmp, seg_prefix;
@@ -966,9 +971,6 @@ static void asm_opcode(TCCState *s1, int opcode) · 405 unmodified lines
966971 #endif
967972 }
968973
969−#define NB_SAVED_REGS 3
970−#define NB_ASM_REGS 8
971−
972974 /* return the constraint priority (we allocate first the lowest
973975 numbered constraints) */
974976 static inline int constraint_priority(const char *str)
@@ -1030,7 +1032,7 @@ static const char *skip_constraint_modifiers(const char *p) · 55 unmodified lines
10301032
10311033 #define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask)
10321034
1033−static void asm_compute_constraints(ASMOperand *operands,
1035+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
10341036 int nb_operands, int nb_outputs,
10351037 const uint8_t *clobber_regs,
10361038 int *pout_reg)
@@ -1262,7 +1264,7 @@ static void asm_compute_constraints(ASMOperand *operands, · 225 unmodified lines
12621264 #endif
12631265 }
12641266
1265−static void subst_asm_operand(CString *add_str,
1267+ST_FUNC void subst_asm_operand(CString *add_str,
12661268 SValue *sv, int modifier)
12671269 {
12681270 int r, reg, size, val;
@@ -1356,7 +1358,7 @@ static void subst_asm_operand(CString *add_str, · 87 unmodified lines
13561358 }
13571359
13581360 /* generate prolog and epilog code for asm statment */
1359−static void asm_gen_code(ASMOperand *operands, int nb_operands,
1361+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
13601362 int nb_outputs, int is_output,
13611363 uint8_t *clobber_regs,
13621364 int out_reg)
@@ -1450,7 +1452,7 @@ static void asm_gen_code(ASMOperand *operands, int nb_operands, · 87 unmodified lines
14501452 }
14511453 }
14521454
1453−static void asm_clobber(uint8_t *clobber_regs, const char *str)
1455+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
14541456 {
14551457 int reg;
14561458 TokenSym *ts;
i386-gen.c+44−34
@@ -18,8 +18,11 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#ifdef TARGET_DEFS_ONLY
22+
2123 /* number of available registers */
22−#define NB_REGS 4
24+#define NB_REGS 4
25+#define NB_ASM_REGS 8
2326
2427 /* a register can belong to several classes. The classes must be
2528 sorted from more general to more precise (see gv2() code which does
@@ -42,13 +45,6 @@ enum { · 16 unmodified lines
4245 TREG_ST0,
4346 };
4447
45−const int reg_classes[NB_REGS] = {
46− /* eax */ RC_INT | RC_EAX,
47− /* ecx */ RC_INT | RC_ECX,
48− /* edx */ RC_INT | RC_EDX,
49− /* st0 */ RC_FLOAT | RC_ST0,
50−};
51−
5248 /* return registers for function */
5349 #define REG_IRET TREG_EAX /* single word int return register */
5450 #define REG_LRET TREG_EDX /* second word return register (for long long) */
@@ -70,6 +66,9 @@ const int reg_classes[NB_REGS] = { · 15 unmodified lines
7066 /* maximum alignment (for aligned attribute support) */
7167 #define MAX_ALIGN 8
7268
69+
70+#define psym oad
71+
7372 /******************************************************/
7473 /* ELF defines */
7574
@@ -85,6 +84,16 @@ const int reg_classes[NB_REGS] = { · 9 unmodified lines
8584 #define ELF_PAGE_SIZE 0x1000
8685
8786 /******************************************************/
87+#else /* ! TARGET_DEFS_ONLY */
88+/******************************************************/
89+#include "tcc.h"
90+
91+ST_DATA const int reg_classes[NB_REGS] = {
92+ /* eax */ RC_INT | RC_EAX,
93+ /* ecx */ RC_INT | RC_ECX,
94+ /* edx */ RC_INT | RC_EDX,
95+ /* st0 */ RC_FLOAT | RC_ST0,
96+};
8897
8998 static unsigned long func_sub_sp_offset;
9099 static int func_ret_sub;
@@ -93,7 +102,7 @@ static unsigned long func_bound_offset; · 2 unmodified lines
93102 #endif
94103
95104 /* XXX: make it faster ? */
96−void g(int c)
105+ST_FUNC void g(int c)
97106 {
98107 int ind1;
99108 ind1 = ind + 1;
@@ -103,7 +112,7 @@ void g(int c) · 3 unmodified lines
103112 ind = ind1;
104113 }
105114
106−void o(unsigned int c)
115+ST_FUNC void o(unsigned int c)
107116 {
108117 while (c) {
109118 g(c);
@@ -111,13 +120,13 @@ void o(unsigned int c) · 1 unmodified line
111120 }
112121 }
113122
114−void gen_le16(int v)
123+ST_FUNC void gen_le16(int v)
115124 {
116125 g(v);
117126 g(v >> 8);
118127 }
119128
120−void gen_le32(int c)
129+ST_FUNC void gen_le32(int c)
121130 {
122131 g(c);
123132 g(c >> 8);
@@ -126,7 +135,7 @@ void gen_le32(int c) · 2 unmodified lines
126135 }
127136
128137 /* output a symbol and patch all calls to it */
129−void gsym_addr(int t, int a)
138+ST_FUNC void gsym_addr(int t, int a)
130139 {
131140 int n, *ptr;
132141 while (t) {
@@ -137,7 +146,7 @@ void gsym_addr(int t, int a) · 4 unmodified lines
137146 }
138147 }
139148
140−void gsym(int t)
149+ST_FUNC void gsym(int t)
141150 {
142151 gsym_addr(t, ind);
143152 }
@@ -147,7 +156,7 @@ void gsym(int t) · 3 unmodified lines
147156 #define psym oad
148157
149158 /* instruction + 4 bytes data. Return the address of the data */
150−static int oad(int c, int s)
159+ST_FUNC int oad(int c, int s)
151160 {
152161 int ind1;
153162
@@ -162,14 +171,14 @@ static int oad(int c, int s) · 8 unmodified lines
162171 }
163172
164173 /* output constant with relocation if 'r & VT_SYM' is true */
165−static void gen_addr32(int r, Sym *sym, int c)
174+ST_FUNC void gen_addr32(int r, Sym *sym, int c)
166175 {
167176 if (r & VT_SYM)
168177 greloc(cur_text_section, sym, ind, R_386_32);
169178 gen_le32(c);
170179 }
171180
172−static void gen_addrpc32(int r, Sym *sym, int c)
181+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
173182 {
174183 if (r & VT_SYM)
175184 greloc(cur_text_section, sym, ind, R_386_PC32);
@@ -200,7 +209,7 @@ static void gen_modrm(int op_reg, int r, Sym *sym, int c) · 24 unmodified lines
200209 }
201210
202211 /* load 'r' from value 'sv' */
203−void load(int r, SValue *sv)
212+ST_FUNC void load(int r, SValue *sv)
204213 {
205214 int v, t, ft, fc, fr;
206215 SValue v1;
@@ -269,7 +278,7 @@ void load(int r, SValue *sv) · 62 unmodified lines
269278 }
270279
271280 /* store register 'r' in lvalue 'v' */
272−void store(int r, SValue *v)
281+ST_FUNC void store(int r, SValue *v)
273282 {
274283 int fr, bt, ft, fc;
275284
@@ -349,7 +358,7 @@ static uint8_t fastcallw_regs[2] = { TREG_ECX, TREG_EDX }; · 73 unmodified lines
349358 /* Generate function call. The function address is pushed first, then
350359 all the parameters in call order. This functions pops all the
351360 parameters and the function address. */
352−void gfunc_call(int nb_args)
361+ST_FUNC void gfunc_call(int nb_args)
353362 {
354363 int size, align, r, args_size, i, func_call;
355364 Sym *func_sym;
@@ -442,7 +451,7 @@ void gfunc_call(int nb_args) · 86 unmodified lines
442451 #endif
443452
444453 /* generate function prolog of type 't' */
445−void gfunc_prolog(CType *func_type)
454+ST_FUNC void gfunc_prolog(CType *func_type)
446455 {
447456 int addr, align, size, func_call, fastcall_nb_regs;
448457 int param_index, param_addr;
@@ -524,7 +533,7 @@ void gfunc_prolog(CType *func_type) · 75 unmodified lines
524533 }
525534
526535 /* generate function epilog */
527−void gfunc_epilog(void)
536+ST_FUNC void gfunc_epilog(void)
528537 {
529538 int v, saved_ind;
530539
@@ -595,13 +604,13 @@ void gfunc_epilog(void) · 64 unmodified lines
595604 }
596605
597606 /* generate a jump to a label */
598−int gjmp(int t)
607+ST_FUNC int gjmp(int t)
599608 {
600609 return psym(0xe9, t);
601610 }
602611
603612 /* generate a jump to a fixed address */
604−void gjmp_addr(int a)
613+ST_FUNC void gjmp_addr(int a)
605614 {
606615 int r;
607616 r = a - ind - 2;
@@ -614,7 +623,7 @@ void gjmp_addr(int a) · 6 unmodified lines
614623 }
615624
616625 /* generate a test. set 'inv' to invert test. Stack entry is popped */
617−int gtst(int inv, int t)
626+ST_FUNC int gtst(int inv, int t)
618627 {
619628 int v, *p;
620629
@@ -659,7 +668,7 @@ int gtst(int inv, int t) · 38 unmodified lines
659668 }
660669
661670 /* generate an integer binary operation */
662−void gen_opi(int op)
671+ST_FUNC void gen_opi(int op)
663672 {
664673 int r, fr, opc, c;
665674
@@ -793,7 +802,7 @@ void gen_opi(int op) · 127 unmodified lines
793802 /* generate a floating point operation 'v = t1 op t2' instruction. The
794803 two operands are guaranted to have the same floating point type */
795804 /* XXX: need to use ST1 too */
796−void gen_opf(int op)
805+ST_FUNC void gen_opf(int op)
797806 {
798807 int a, ft, fc, swapped, r;
799808
@@ -905,7 +914,7 @@ void gen_opf(int op) · 105 unmodified lines
905914
906915 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
907916 and 'long long' cases. */
908−void gen_cvt_itof(int t)
917+ST_FUNC void gen_cvt_itof(int t)
909918 {
910919 save_reg(TREG_ST0);
911920 gv(RC_INT);
@@ -935,7 +944,7 @@ void gen_cvt_itof(int t) · 23 unmodified lines
935944
936945 /* convert fp to int 't' type */
937946 /* XXX: handle long long case */
938−void gen_cvt_ftoi(int t)
947+ST_FUNC void gen_cvt_ftoi(int t)
939948 {
940949 int r, r2, size;
941950 Sym *sym;
@@ -986,14 +995,14 @@ void gen_cvt_ftoi(int t) · 44 unmodified lines
986995 }
987996
988997 /* convert from one floating point type to another */
989−void gen_cvt_ftof(int t)
998+ST_FUNC void gen_cvt_ftof(int t)
990999 {
9911000 /* all we have to do on i386 is to put the float in a register */
9921001 gv(RC_FLOAT);
9931002 }
9941003
9951004 /* computed goto support */
996−void ggoto(void)
1005+ST_FUNC void ggoto(void)
9971006 {
9981007 gcall_or_jmp(1);
9991008 vtop--;
@@ -1003,7 +1012,7 @@ void ggoto(void) · 3 unmodified lines
10031012 #ifdef CONFIG_TCC_BCHECK
10041013
10051014 /* generate a bounded pointer addition */
1006−void gen_bounded_ptr_add(void)
1015+ST_FUNC void gen_bounded_ptr_add(void)
10071016 {
10081017 Sym *sym;
10091018
@@ -1026,7 +1035,7 @@ void gen_bounded_ptr_add(void) · 16 unmodified lines
10261035
10271036 /* patch pointer addition in vtop so that pointer dereferencing is
10281037 also tested */
1029−void gen_bounded_ptr_deref(void)
1038+ST_FUNC void gen_bounded_ptr_deref(void)
10301039 {
10311040 int func;
10321041 int size, align;
@@ -1068,4 +1077,5 @@ void gen_bounded_ptr_deref(void) · 35 unmodified lines
10681077
10691078 /* end of X86 code generator */
10701079 /*************************************************************/
1071−
1080+#endif
1081+/*************************************************************/
libtcc.c+108−624
@@ -23,344 +23,70 @@ · 22 unmodified lines
2323 /********************************************************/
2424 /* global variables */
2525
26−/* display benchmark infos */
27−int total_lines;
28−int total_bytes;
29−
30−/* parser */
31−static struct BufferedFile *file;
32−static int ch, tok;
33−static CValue tokc;
34−static CString tokcstr; /* current parsed string, if any */
35−/* additional informations about token */
36−static int tok_flags;
37−#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
38−#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
39−#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
40−#define TOK_FLAG_EOF 0x0008 /* end of file */
41−
42−static int *macro_ptr, *macro_ptr_allocated;
43−static int *unget_saved_macro_ptr;
44−static int unget_saved_buffer[TOK_MAX_SIZE + 1];
45−static int unget_buffer_enabled;
46−static int parse_flags;
47−#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
48−#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
49−#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
50− token. line feed is also
51− returned at eof */
52−#define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
53−#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
54−
55−static Section *text_section, *data_section, *bss_section; /* predefined sections */
56−static Section *cur_text_section; /* current section where function code is
57− generated */
58−#ifdef CONFIG_TCC_ASM
59−static Section *last_text_section; /* to handle .previous asm directive */
60−#endif
61−
62−#ifdef CONFIG_TCC_BCHECK
63−/* bound check related sections */
64−static Section *bounds_section; /* contains global data bound description */
65−static Section *lbounds_section; /* contains local data bound description */
66−#endif
67−
68−/* symbol sections */
69−static Section *symtab_section, *strtab_section;
70−
71−/* debug sections */
72−static Section *stab_section, *stabstr_section;
73−
74−/* loc : local variable index
75− ind : output code index
76− rsym: return symbol
77− anon_sym: anonymous symbol index
78−*/
79−static int rsym, anon_sym, ind, loc;
80−/* expression generation modifiers */
81−static int const_wanted; /* true if constant wanted */
82−static int nocode_wanted; /* true if no code generation wanted for an expression */
83−static int global_expr; /* true if compound literals must be allocated
84− globally (used during initializers parsing */
85−static CType func_vt; /* current function return type (used by return
86− instruction) */
87−static int func_vc;
88−static int last_line_num, last_ind, func_ind; /* debug last line number and pc */
89−static int tok_ident;
90−static TokenSym **table_ident;
91−static TokenSym *hash_ident[TOK_HASH_SIZE];
92−static char token_buf[STRING_MAX_SIZE + 1];
93−static char *funcname;
94−static Sym *global_stack, *local_stack;
95−static Sym *define_stack;
96−static Sym *global_label_stack, *local_label_stack;
97−/* symbol allocator */
98−#define SYM_POOL_NB (8192 / sizeof(Sym))
99−static Sym *sym_free_first;
100−static void **sym_pools;
101−static int nb_sym_pools;
102−
103−static SValue vstack[VSTACK_SIZE], *vtop;
104−/* some predefined types */
105−static CType char_pointer_type, func_old_type, int_type;
106−
10726 /* use GNU C extensions */
108−static int gnu_ext = 1;
27+ST_DATA int gnu_ext = 1;
10928
110−/* use Tiny C extensions */
111−static int tcc_ext = 1;
112−
113−/* max number of callers shown if error */
114−#ifdef CONFIG_TCC_BACKTRACE
115−int num_callers = 6;
116−void *rt_prog_main;
117−const char **rt_bound_error_msg;
118−#endif
29+/* use TinyCC extensions */
30+ST_DATA int tcc_ext = 1;
11931
12032 /* XXX: get rid of this ASAP */
121−static struct TCCState *tcc_state;
122−
123−/********************************************************/
124−/* function prototypes */
125−
126−/* tccpp.c */
127−static void next(void);
128−char *get_tok_str(int v, CValue *cv);
129−
130−/* tccgen.c */
131−static void parse_expr_type(CType *type);
132−static void expr_type(CType *type);
133−static void unary_type(CType *type);
134−static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
135− int case_reg, int is_expr);
136−static int expr_const(void);
137−static void expr_eq(void);
138−static void gexpr(void);
139−static void gen_inline_functions(void);
140−static void decl(int l);
141−static void decl_initializer(CType *type, Section *sec, unsigned long c,
142− int first, int size_only);
143−static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
144− int has_init, int v, int scope);
145−int gv(int rc);
146−void gv2(int rc1, int rc2);
147−void move_reg(int r, int s);
148−void save_regs(int n);
149−void save_reg(int r);
150−void vpop(void);
151−void vswap(void);
152−void vdup(void);
153−int get_reg(int rc);
154−int get_reg_ex(int rc,int rc2);
155−
156−void gen_op(int op);
157−void force_charshort_cast(int t);
158−static void gen_cast(CType *type);
159−void vstore(void);
160−static Sym *sym_find(int v);
161−static Sym *sym_push(int v, CType *type, int r, int c);
162−
163−/* type handling */
164−static int type_size(CType *type, int *a);
165−static inline CType *pointed_type(CType *type);
166−static int pointed_size(CType *type);
167−static int lvalue_type(int t);
168−static int parse_btype(CType *type, AttributeDef *ad);
169−static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
170−static int compare_types(CType *type1, CType *type2, int unqualified);
171−static int is_compatible_types(CType *type1, CType *type2);
172−static int is_compatible_parameter_types(CType *type1, CType *type2);
173−
174−int ieee_finite(double d);
175−void vpushi(int v);
176−void vpushll(long long v);
177−void vrott(int n);
178−void vnrott(int n);
179−void lexpand_nr(void);
180−static void vpush_global_sym(CType *type, int v);
181−void vset(CType *type, int r, int v);
182−void type_to_str(char *buf, int buf_size,
183− CType *type, const char *varstr);
184−static Sym *get_sym_ref(CType *type, Section *sec,
185− unsigned long offset, unsigned long size);
186−static Sym *external_global_sym(int v, CType *type, int r);
187−
188−/* section generation */
189−static void section_realloc(Section *sec, unsigned long new_size);
190−static void *section_ptr_add(Section *sec, unsigned long size);
191−static void put_extern_sym(Sym *sym, Section *section,
192− unsigned long value, unsigned long size);
193−static void greloc(Section *s, Sym *sym, unsigned long addr, int type);
194−static int put_elf_str(Section *s, const char *sym);
195−static int put_elf_sym(Section *s,
196− unsigned long value, unsigned long size,
197− int info, int other, int shndx, const char *name);
198−static int add_elf_sym(Section *s, uplong value, unsigned long size,
199− int info, int other, int sh_num, const char *name);
200−static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
201− int type, int symbol);
202−static void put_stabs(const char *str, int type, int other, int desc,
203− unsigned long value);
204−static void put_stabs_r(const char *str, int type, int other, int desc,
205− unsigned long value, Section *sec, int sym_index);
206−static void put_stabn(int type, int other, int desc, int value);
207−static void put_stabd(int type, int other, int desc);
208−static int tcc_add_dll(TCCState *s, const char *filename, int flags);
209−
210−#define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
211−#define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
212−#define AFF_PREPROCESS 0x0004 /* preprocess file */
213−static int tcc_add_file_internal(TCCState *s, const char *filename, int flags);
214−
215−/* tcccoff.c */
216−int tcc_output_coff(TCCState *s1, FILE *f);
217−
218−/* tccpe.c */
219−int pe_load_file(struct TCCState *s1, const char *filename, int fd);
220−int pe_output_file(struct TCCState *s1, const char *filename);
221−int pe_dllimport(int r, SValue *sv, void (*fn)(int r, SValue *sv));
222−
223−/* tccasm.c */
224−#ifdef CONFIG_TCC_ASM
225−static void asm_expr(TCCState *s1, ExprValue *pe);
226−static int asm_int_expr(TCCState *s1);
227−static int find_constraint(ASMOperand *operands, int nb_operands,
228− const char *name, const char **pp);
33+ST_DATA struct TCCState *tcc_state;
22934
230−static int tcc_assemble(TCCState *s1, int do_preprocess);
35+#ifdef CONFIG_TCC_BACKTRACE
36+ST_DATA int num_callers = 6;
37+ST_DATA const char **rt_bound_error_msg;
38+ST_DATA void *rt_prog_main;
23139 #endif
23240
233−static void asm_instr(void);
234−static void asm_global_instr(void);
235−
236−/********************************************************/
237−/* libtcc.c */
238−
239−static Sym *__sym_malloc(void);
240−static inline Sym *sym_malloc(void);
241−static inline void sym_free(Sym *sym);
242−Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
243−static void free_section(Section *s);
244−static void section_realloc(Section *sec, unsigned long new_size);
245−static void *section_ptr_add(Section *sec, unsigned long size);
246−Section *find_section(TCCState *s1, const char *name);
247−static void put_extern_sym2(
248− Sym *sym, Section *section,
249− unsigned long value, unsigned long size, int can_add_underscore);
250−static void put_extern_sym(
251− Sym *sym, Section *section,
252− unsigned long value, unsigned long size);
253−static void greloc(Section *s, Sym *sym, unsigned long offset, int type);
254−
255−static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap);
256−static void strcat_printf(char *buf, int buf_size, const char *fmt, ...);
257−
258−/* CString handling */
259−static void cstr_realloc(CString *cstr, int new_size);
260−static inline void cstr_ccat(CString *cstr, int ch);
261−static void cstr_cat(CString *cstr, const char *str);
262−static void cstr_wccat(CString *cstr, int ch);
263−static void cstr_new(CString *cstr);
264−static void cstr_free(CString *cstr);
265−#define cstr_reset(cstr) cstr_free(cstr)
266−static void add_char(CString *cstr, int c);
267−
268−static Sym *sym_push2(Sym **ps, int v, int t, long c);
269−static Sym *sym_find2(Sym *s, int v);
270−static inline Sym *struct_find(int v);
271−static inline Sym *sym_find(int v);
272−static Sym *sym_push(int v, CType *type, int r, int c);
273−static Sym *global_identifier_push(int v, int t, int c);
274−static void sym_pop(Sym **ptop, Sym *b);
275−
276−BufferedFile *tcc_open(TCCState *s1, const char *filename);
277−void tcc_close(BufferedFile *bf);
278−static int tcc_compile(TCCState *s1);
279−
280−void expect(const char *msg);
281−void skip(int c);
282−static void test_lvalue(void);
283−void *resolve_sym(TCCState *s1, const char *sym);
284−
285−static inline int isid(int c)
286−{
287− return (c >= 'a' && c <= 'z')
288− || (c >= 'A' && c <= 'Z')
289− || c == '_';
290−}
291−
292−static inline int isnum(int c)
293−{
294− return c >= '0' && c <= '9';
295−}
296−
297−static inline int isoct(int c)
298−{
299− return c >= '0' && c <= '7';
300−}
301−
302−static inline int toup(int c)
303−{
304− if (c >= 'a' && c <= 'z')
305− return c - 'a' + 'A';
306− else
307− return c;
308−}
309−
31041 /********************************************************/
31142
43+#ifndef NOTALLINONE
44+#include "tccpp.c"
45+#include "tccgen.c"
46+#include "tccelf.c"
47+#include "tccrun.c"
31248 #ifdef TCC_TARGET_I386
31349 #include "i386-gen.c"
31450 #endif
315−
31651 #ifdef TCC_TARGET_ARM
31752 #include "arm-gen.c"
31853 #endif
319−
32054 #ifdef TCC_TARGET_C67
32155 #include "c67-gen.c"
32256 #endif
323−
32457 #ifdef TCC_TARGET_X86_64
32558 #include "x86_64-gen.c"
32659 #endif
327−
328−#include "tccpp.c"
329−#include "tccgen.c"
330−
33160 #ifdef CONFIG_TCC_ASM
332−
61+#include "tccasm.c"
33362 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
33463 #include "i386-asm.c"
33564 #endif
336−
337−#include "tccasm.c"
338−#else
339−static void asm_instr(void)
340−{
341− error("inline asm() not supported");
342−}
343−static void asm_global_instr(void)
344−{
345− error("inline asm() not supported");
346−}
34765 #endif
348−
349−#include "tccelf.c"
350−
35166 #ifdef TCC_TARGET_COFF
35267 #include "tcccoff.c"
35368 #endif
354−
35569 #ifdef TCC_TARGET_PE
35670 #include "tccpe.c"
35771 #endif
72+#endif /* ALL_IN_ONE */
35873
359−#include "tccrun.c"
74+/********************************************************/
75+#ifndef CONFIG_TCC_ASM
76+ST_FUNC void asm_instr(void)
77+{
78+ error("inline asm() not supported");
79+}
80+ST_FUNC void asm_global_instr(void)
81+{
82+ error("inline asm() not supported");
83+}
84+#endif
36085
36186 /********************************************************/
87+
36288 #ifdef _WIN32
363−char *normalize_slashes(char *path)
89+static char *normalize_slashes(char *path)
36490 {
36591 char *p;
36692 for (p = path; *p; ++p)
@@ -369,10 +95,10 @@ char *normalize_slashes(char *path) · 2 unmodified lines
36995 return path;
37096 }
37197
372−HMODULE tcc_module;
98+static HMODULE tcc_module;
37399
374100 /* on win32, we suppose the lib and includes are at the location of 'tcc.exe' */
375−void tcc_set_lib_path_w32(TCCState *s)
101+static void tcc_set_lib_path_w32(TCCState *s)
376102 {
377103 char path[1024], *p;
378104 GetModuleFileNameA(tcc_module, path, sizeof path);
@@ -396,18 +122,8 @@ BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) · 17 unmodified lines
396122 #endif
397123
398124 /********************************************************/
399−
400−/* we use our own 'finite' function to avoid potential problems with
401− non standard math libs */
402−/* XXX: endianness dependent */
403−int ieee_finite(double d)
404−{
405− int *p = (int *)&d;
406− return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
407−}
408−
409125 /* copy a string and truncate it. */
410−char *pstrcpy(char *buf, int buf_size, const char *s)
126+PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s)
411127 {
412128 char *q, *q_end;
413129 int c;
@@ -427,7 +143,7 @@ char *pstrcpy(char *buf, int buf_size, const char *s) · 13 unmodified lines
427143 }
428144
429145 /* strcat and truncate. */
430−char *pstrcat(char *buf, int buf_size, const char *s)
146+PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s)
431147 {
432148 int len;
433149 len = strlen(buf);
@@ -437,7 +153,7 @@ char *pstrcat(char *buf, int buf_size, const char *s) · 3 unmodified lines
437153 }
438154
439155 /* extract the basename of a file */
440−char *tcc_basename(const char *name)
156+PUB_FUNC char *tcc_basename(const char *name)
441157 {
442158 char *p = strchr(name, 0);
443159 while (p > name && !IS_PATHSEP(p[-1]))
@@ -445,21 +161,27 @@ char *tcc_basename(const char *name) · 1 unmodified line
445161 return p;
446162 }
447163
448−char *tcc_fileextension (const char *name)
164+PUB_FUNC char *tcc_fileextension (const char *name)
449165 {
450166 char *b = tcc_basename(name);
451167 char *e = strrchr(b, '.');
452168 return e ? e : strchr(b, 0);
453169 }
454170
171+/********************************************************/
455172 /* memory management */
173+
174+#undef free
175+#undef malloc
176+#undef realloc
177+
456178 #ifdef MEM_DEBUG
457179 int mem_cur_size;
458180 int mem_max_size;
459181 unsigned malloc_usable_size(void*);
460182 #endif
461183
462−void tcc_free(void *ptr)
184+PUB_FUNC void tcc_free(void *ptr)
463185 {
464186 #ifdef MEM_DEBUG
465187 mem_cur_size -= malloc_usable_size(ptr);
@@ -467,7 +189,7 @@ void tcc_free(void *ptr) · 1 unmodified line
467189 free(ptr);
468190 }
469191
470−void *tcc_malloc(unsigned long size)
192+PUB_FUNC void *tcc_malloc(unsigned long size)
471193 {
472194 void *ptr;
473195 ptr = malloc(size);
@@ -481,7 +203,7 @@ void *tcc_malloc(unsigned long size) · 7 unmodified lines
481203 return ptr;
482204 }
483205
484−void *tcc_mallocz(unsigned long size)
206+PUB_FUNC void *tcc_mallocz(unsigned long size)
485207 {
486208 void *ptr;
487209 ptr = tcc_malloc(size);
@@ -489,7 +211,7 @@ void *tcc_mallocz(unsigned long size) · 1 unmodified line
489211 return ptr;
490212 }
491213
492−void *tcc_realloc(void *ptr, unsigned long size)
214+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
493215 {
494216 void *ptr1;
495217 #ifdef MEM_DEBUG
@@ -505,7 +227,7 @@ void *tcc_realloc(void *ptr, unsigned long size) · 9 unmodified lines
505227 return ptr1;
506228 }
507229
508−char *tcc_strdup(const char *str)
230+PUB_FUNC char *tcc_strdup(const char *str)
509231 {
510232 char *ptr;
511233 ptr = tcc_malloc(strlen(str) + 1);
@@ -513,7 +235,7 @@ char *tcc_strdup(const char *str) · 1 unmodified line
513235 return ptr;
514236 }
515237
516−void tcc_memstats(void)
238+PUB_FUNC void tcc_memstats(void)
517239 {
518240 #ifdef MEM_DEBUG
519241 printf("memory in use: %d\n", mem_cur_size);
@@ -524,7 +246,10 @@ void tcc_memstats(void) · 4 unmodified lines
524246 #define malloc(s) use_tcc_malloc(s)
525247 #define realloc(p, s) use_tcc_realloc(p, s)
526248
527−void dynarray_add(void ***ptab, int *nb_ptr, void *data)
249+/********************************************************/
250+/* dynarrays */
251+
252+PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data)
528253 {
529254 int nb, nb_alloc;
530255 void **pp;
@@ -546,7 +271,7 @@ void dynarray_add(void ***ptab, int *nb_ptr, void *data) · 15 unmodified lines
546271 *nb_ptr = nb;
547272 }
548273
549−void dynarray_reset(void *pp, int *n)
274+PUB_FUNC void dynarray_reset(void *pp, int *n)
550275 {
551276 void **p;
552277 for (p = *(void***)pp; *n; ++p, --*n)
@@ -556,43 +281,18 @@ void dynarray_reset(void *pp, int *n) · 3 unmodified lines
556281 *(void**)pp = NULL;
557282 }
558283
559−/* symbol allocator */
560−static Sym *__sym_malloc(void)
561−{
562− Sym *sym_pool, *sym, *last_sym;
563− int i;
564−
565− sym_pool = tcc_malloc(SYM_POOL_NB * sizeof(Sym));
566− dynarray_add(&sym_pools, &nb_sym_pools, sym_pool);
567−
568− last_sym = sym_free_first;
569− sym = sym_pool;
570− for(i = 0; i < SYM_POOL_NB; i++) {
571− sym->next = last_sym;
572− last_sym = sym;
573− sym++;
574− }
575− sym_free_first = last_sym;
576− return last_sym;
577−}
578−
579−static inline Sym *sym_malloc(void)
284+/* we use our own 'finite' function to avoid potential problems with
285+ non standard math libs */
286+/* XXX: endianness dependent */
287+ST_FUNC int ieee_finite(double d)
580288 {
581− Sym *sym;
582− sym = sym_free_first;
583− if (!sym)
584− sym = __sym_malloc();
585− sym_free_first = sym->next;
586− return sym;
289+ int *p = (int *)&d;
290+ return ((unsigned)((p[1] | 0x800fffff) + 1)) >> 31;
587291 }
588292
589−static inline void sym_free(Sym *sym)
590−{
591− sym->next = sym_free_first;
592− sym_free_first = sym;
593−}
293+/********************************************************/
594294
595−Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags)
295+ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags)
596296 {
597297 Section *sec;
598298
@@ -633,7 +333,7 @@ static void free_section(Section *s) · 34 unmodified lines
633333 }
634334
635335 /* realloc section and set its content to zero */
636−static void section_realloc(Section *sec, unsigned long new_size)
336+ST_FUNC void section_realloc(Section *sec, unsigned long new_size)
637337 {
638338 unsigned long size;
639339 unsigned char *data;
@@ -653,7 +353,7 @@ static void section_realloc(Section *sec, unsigned long new_size) · 13 unmodified lines
653353
654354 /* reserve at least 'size' bytes in section 'sec' from
655355 sec->data_offset. */
656−static void *section_ptr_add(Section *sec, unsigned long size)
356+ST_FUNC void *section_ptr_add(Section *sec, unsigned long size)
657357 {
658358 unsigned long offset, offset1;
659359
@@ -667,7 +367,7 @@ static void *section_ptr_add(Section *sec, unsigned long size) · 7 unmodified lines
667367
668368 /* return a reference to a section, and create it if it does not
669369 exists */
670−Section *find_section(TCCState *s1, const char *name)
370+ST_FUNC Section *find_section(TCCState *s1, const char *name)
671371 {
672372 Section *sec;
673373 int i;
@@ -682,7 +382,7 @@ Section *find_section(TCCState *s1, const char *name) · 8 unmodified lines
682382
683383 /* update sym->c so that it points to an external symbol in section
684384 'section' with value 'value' */
685−static void put_extern_sym2(Sym *sym, Section *section,
385+ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
686386 unsigned long value, unsigned long size,
687387 int can_add_underscore)
688388 {
@@ -779,14 +479,14 @@ static void put_extern_sym2(Sym *sym, Section *section, · 90 unmodified lines
779479 }
780480 }
781481
782−static void put_extern_sym(Sym *sym, Section *section,
482+ST_FUNC void put_extern_sym(Sym *sym, Section *section,
783483 unsigned long value, unsigned long size)
784484 {
785485 put_extern_sym2(sym, section, value, size, 1);
786486 }
787487
788488 /* add a new relocation entry to symbol 'sym' in section 's' */
789−static void greloc(Section *s, Sym *sym, unsigned long offset, int type)
489+ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type)
790490 {
791491 int c = 0;
792492 if (sym) {
@@ -798,6 +498,8 @@ static void greloc(Section *s, Sym *sym, unsigned long offset, int type) · 5 unmodified lines
798498 put_elf_reloc(symtab_section, s, offset, type, c);
799499 }
800500
501+/********************************************************/
502+
801503 static void strcat_vprintf(char *buf, int buf_size, const char *fmt, va_list ap)
802504 {
803505 int len;
@@ -813,7 +515,7 @@ static void strcat_printf(char *buf, int buf_size, const char *fmt, ...) · 9 unmodified lines
813515 va_end(ap);
814516 }
815517
816−void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap)
518+static void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap)
817519 {
818520 char buf[2048];
819521 BufferedFile **f;
@@ -850,7 +552,7 @@ void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap) · 30 unmodified lines
850552 s1->nb_errors++;
851553 }
852554
853−void tcc_set_error_func(TCCState *s, void *error_opaque,
555+LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
854556 void (*error_func)(void *opaque, const char *msg))
855557 {
856558 s->error_opaque = error_opaque;
@@ -858,7 +560,7 @@ void tcc_set_error_func(TCCState *s, void *error_opaque, · 1 unmodified line
858560 }
859561
860562 /* error without aborting current compilation */
861−void error_noabort(const char *fmt, ...)
563+PUB_FUNC void error_noabort(const char *fmt, ...)
862564 {
863565 TCCState *s1 = tcc_state;
864566 va_list ap;
@@ -868,7 +570,7 @@ void error_noabort(const char *fmt, ...) · 3 unmodified lines
868570 va_end(ap);
869571 }
870572
871−void error(const char *fmt, ...)
573+PUB_FUNC void error(const char *fmt, ...)
872574 {
873575 TCCState *s1 = tcc_state;
874576 va_list ap;
@@ -885,12 +587,12 @@ void error(const char *fmt, ...) · 10 unmodified lines
885587 }
886588 }
887589
888−void expect(const char *msg)
590+PUB_FUNC void expect(const char *msg)
889591 {
890592 error("%s expected", msg);
891593 }
892594
893−void warning(const char *fmt, ...)
595+PUB_FUNC void warning(const char *fmt, ...)
894596 {
895597 TCCState *s1 = tcc_state;
896598 va_list ap;
@@ -903,233 +605,10 @@ void warning(const char *fmt, ...) · 6 unmodified lines
903605 va_end(ap);
904606 }
905607
906−void skip(int c)
907−{
908− if (tok != c)
909− error("'%c' expected", c);
910− next();
911−}
912−
913−static void test_lvalue(void)
914−{
915− if (!(vtop->r & VT_LVAL))
916− expect("lvalue");
917−}
918−
919−/* CString handling */
920−
921−static void cstr_realloc(CString *cstr, int new_size)
922−{
923− int size;
924− void *data;
925−
926− size = cstr->size_allocated;
927− if (size == 0)
928− size = 8; /* no need to allocate a too small first string */
929− while (size < new_size)
930− size = size * 2;
931− data = tcc_realloc(cstr->data_allocated, size);
932− if (!data)
933− error("memory full");
934− cstr->data_allocated = data;
935− cstr->size_allocated = size;
936− cstr->data = data;
937−}
938−
939−/* add a byte */
940−static inline void cstr_ccat(CString *cstr, int ch)
941−{
942− int size;
943− size = cstr->size + 1;
944− if (size > cstr->size_allocated)
945− cstr_realloc(cstr, size);
946− ((unsigned char *)cstr->data)[size - 1] = ch;
947− cstr->size = size;
948−}
949−
950−static void cstr_cat(CString *cstr, const char *str)
951−{
952− int c;
953− for(;;) {
954− c = *str;
955− if (c == '\0')
956− break;
957− cstr_ccat(cstr, c);
958− str++;
959− }
960−}
961−
962−/* add a wide char */
963−static void cstr_wccat(CString *cstr, int ch)
964−{
965− int size;
966− size = cstr->size + sizeof(nwchar_t);
967− if (size > cstr->size_allocated)
968− cstr_realloc(cstr, size);
969− *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch;
970− cstr->size = size;
971−}
972−
973−static void cstr_new(CString *cstr)
974−{
975− memset(cstr, 0, sizeof(CString));
976−}
977−
978−/* free string and reset it to NULL */
979−static void cstr_free(CString *cstr)
980−{
981− tcc_free(cstr->data_allocated);
982− cstr_new(cstr);
983−}
984−
985−#define cstr_reset(cstr) cstr_free(cstr)
986−
987−/* XXX: unicode ? */
988−static void add_char(CString *cstr, int c)
989−{
990− if (c == '\'' || c == '\"' || c == '\\') {
991− /* XXX: could be more precise if char or string */
992− cstr_ccat(cstr, '\\');
993− }
994− if (c >= 32 && c <= 126) {
995− cstr_ccat(cstr, c);
996− } else {
997− cstr_ccat(cstr, '\\');
998− if (c == '\n') {
999− cstr_ccat(cstr, 'n');
1000− } else {
1001− cstr_ccat(cstr, '0' + ((c >> 6) & 7));
1002− cstr_ccat(cstr, '0' + ((c >> 3) & 7));
1003− cstr_ccat(cstr, '0' + (c & 7));
1004− }
1005− }
1006−}
1007−
1008−/* push, without hashing */
1009−static Sym *sym_push2(Sym **ps, int v, int t, long c)
1010−{
1011− Sym *s;
1012− s = sym_malloc();
1013− s->v = v;
1014− s->type.t = t;
1015− s->type.ref = NULL;
1016−#ifdef _WIN64
1017− s->d = NULL;
1018−#endif
1019− s->c = c;
1020− s->next = NULL;
1021− /* add in stack */
1022− s->prev = *ps;
1023− *ps = s;
1024− return s;
1025−}
1026−
1027−/* find a symbol and return its associated structure. 's' is the top
1028− of the symbol stack */
1029−static Sym *sym_find2(Sym *s, int v)
1030−{
1031− while (s) {
1032− if (s->v == v)
1033− return s;
1034− s = s->prev;
1035− }
1036− return NULL;
1037−}
1038−
1039−/* structure lookup */
1040−static inline Sym *struct_find(int v)
1041−{
1042− v -= TOK_IDENT;
1043− if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
1044− return NULL;
1045− return table_ident[v]->sym_struct;
1046−}
1047−
1048−/* find an identifier */
1049−static inline Sym *sym_find(int v)
1050−{
1051− v -= TOK_IDENT;
1052− if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
1053− return NULL;
1054− return table_ident[v]->sym_identifier;
1055−}
1056−
1057−/* push a given symbol on the symbol stack */
1058−static Sym *sym_push(int v, CType *type, int r, int c)
1059−{
1060− Sym *s, **ps;
1061− TokenSym *ts;
1062−
1063− if (local_stack)
1064− ps = &local_stack;
1065− else
1066− ps = &global_stack;
1067− s = sym_push2(ps, v, type->t, c);
1068− s->type.ref = type->ref;
1069− s->r = r;
1070− /* don't record fields or anonymous symbols */
1071− /* XXX: simplify */
1072− if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
1073− /* record symbol in token array */
1074− ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
1075− if (v & SYM_STRUCT)
1076− ps = &ts->sym_struct;
1077− else
1078− ps = &ts->sym_identifier;
1079− s->prev_tok = *ps;
1080− *ps = s;
1081− }
1082− return s;
1083−}
1084−
1085−/* push a global identifier */
1086−static Sym *global_identifier_push(int v, int t, int c)
1087−{
1088− Sym *s, **ps;
1089− s = sym_push2(&global_stack, v, t, c);
1090− /* don't record anonymous symbol */
1091− if (v < SYM_FIRST_ANOM) {
1092− ps = &table_ident[v - TOK_IDENT]->sym_identifier;
1093− /* modify the top most local identifier, so that
1094− sym_identifier will point to 's' when popped */
1095− while (*ps != NULL)
1096− ps = &(*ps)->prev_tok;
1097− s->prev_tok = NULL;
1098− *ps = s;
1099− }
1100− return s;
1101−}
1102−
1103−/* pop symbols until top reaches 'b' */
1104−static void sym_pop(Sym **ptop, Sym *b)
1105−{
1106− Sym *s, *ss, **ps;
1107− TokenSym *ts;
1108− int v;
1109−
1110− s = *ptop;
1111− while(s != b) {
1112− ss = s->prev;
1113− v = s->v;
1114− /* remove symbol in token array */
1115− /* XXX: simplify */
1116− if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
1117− ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
1118− if (v & SYM_STRUCT)
1119− ps = &ts->sym_struct;
1120− else
1121− ps = &ts->sym_identifier;
1122− *ps = s->prev_tok;
1123− }
1124− sym_free(s);
1125− s = ss;
1126− }
1127− *ptop = b;
1128−}
1129−
608+/********************************************************/
1130609 /* I/O layer */
1131610
1132−BufferedFile *tcc_open(TCCState *s1, const char *filename)
611+ST_FUNC BufferedFile *tcc_open(TCCState *s1, const char *filename)
1133612 {
1134613 int fd;
1135614 BufferedFile *bf;
@@ -1159,7 +638,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 23 unmodified lines
1159638 return bf;
1160639 }
1161640
1162−void tcc_close(BufferedFile *bf)
641+ST_FUNC void tcc_close(BufferedFile *bf)
1163642 {
1164643 total_lines += bf->line_num;
1165644 close(bf->fd);
@@ -1272,7 +751,7 @@ static int tcc_compile(TCCState *s1) · 106 unmodified lines
1272751 return s1->nb_errors != 0 ? -1 : 0;
1273752 }
1274753
1275−int tcc_compile_string(TCCState *s, const char *str)
754+LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
1276755 {
1277756 BufferedFile bf1, *bf = &bf1;
1278757 int ret, len;
@@ -1301,7 +780,7 @@ int tcc_compile_string(TCCState *s, const char *str) · 22 unmodified lines
1301780 }
1302781
1303782 /* define a preprocessor symbol. A value can also be provided with the '=' operator */
1304−void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
783+LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
1305784 {
1306785 BufferedFile bf1, *bf = &bf1;
1307786
@@ -1331,7 +810,7 @@ void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) · 23 unmodified lines
1331810 }
1332811
1333812 /* undefine a preprocessor symbol */
1334−void tcc_undefine_symbol(TCCState *s1, const char *sym)
813+LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym)
1335814 {
1336815 TokenSym *ts;
1337816 Sym *s;
@@ -1369,7 +848,7 @@ static void tcc_cleanup(void) · 31 unmodified lines
1369848 macro_ptr = NULL;
1370849 }
1371850
1372−TCCState *tcc_new(void)
851+LIBTCCAPI TCCState *tcc_new(void)
1373852 {
1374853 TCCState *s;
1375854 char buffer[100];
@@ -1477,6 +956,7 @@ TCCState *tcc_new(void) · 101 unmodified lines
1477956 ".dynstrtab",
1478957 ".dynhashtab", SHF_PRIVATE);
1479958 s->alacarte_link = 1;
959+ s->nocommon = 1;
1480960
1481961 #ifdef CHAR_IS_UNSIGNED
1482962 s->char_is_unsigned = 1;
@@ -1485,17 +965,15 @@ TCCState *tcc_new(void) · 2 unmodified lines
1485965 /* XXX: currently the PE linker is not ready to support that */
1486966 s->leading_underscore = 1;
1487967 #endif
1488−
1489968 if (s->section_align == 0)
1490969 s->section_align = ELF_PAGE_SIZE;
1491−
1492970 #ifdef TCC_TARGET_I386
1493971 s->seg_size = 32;
1494972 #endif
1495973 return s;
1496974 }
1497975
1498−void tcc_delete(TCCState *s1)
976+LIBTCCAPI void tcc_delete(TCCState *s1)
1499977 {
1500978 int i;
1501979
@@ -1533,7 +1011,7 @@ void tcc_delete(TCCState *s1) · 31 unmodified lines
15331011 tcc_free(s1);
15341012 }
15351013
1536−int tcc_add_include_path(TCCState *s1, const char *pathname)
1014+LIBTCCAPI int tcc_add_include_path(TCCState *s1, const char *pathname)
15371015 {
15381016 char *pathname1;
15391017
@@ -1542,7 +1020,7 @@ int tcc_add_include_path(TCCState *s1, const char *pathname) · 2 unmodified lines
15421020 return 0;
15431021 }
15441022
1545−int tcc_add_sysinclude_path(TCCState *s1, const char *pathname)
1023+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s1, const char *pathname)
15461024 {
15471025 char *pathname1;
15481026
@@ -1668,7 +1146,7 @@ the_end: · 119 unmodified lines
16681146 return ret;
16691147 }
16701148
1671−int tcc_add_file(TCCState *s, const char *filename)
1149+LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
16721150 {
16731151 if (s->output_type == TCC_OUTPUT_PREPROCESS)
16741152 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
@@ -1676,7 +1154,7 @@ int tcc_add_file(TCCState *s, const char *filename) · 1 unmodified line
16761154 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR);
16771155 }
16781156
1679−int tcc_add_library_path(TCCState *s, const char *pathname)
1157+LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
16801158 {
16811159 char *pathname1;
16821160
@@ -1687,7 +1165,7 @@ int tcc_add_library_path(TCCState *s, const char *pathname) · 4 unmodified lines
16871165
16881166 /* find and load a dll. Return non zero if not found */
16891167 /* XXX: add '-rpath' option support ? */
1690−static int tcc_add_dll(TCCState *s, const char *filename, int flags)
1168+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
16911169 {
16921170 char buf[1024];
16931171 int i;
@@ -1702,7 +1180,7 @@ static int tcc_add_dll(TCCState *s, const char *filename, int flags) · 8 unmodified lines
17021180 }
17031181
17041182 /* the library name is the same as the argument of the '-l' option */
1705−int tcc_add_library(TCCState *s, const char *libraryname)
1183+LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
17061184 {
17071185 char buf[1024];
17081186 int i;
@@ -1728,7 +1206,7 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 19 unmodified lines
17281206 return -1;
17291207 }
17301208
1731−int tcc_add_symbol(TCCState *s, const char *name, void *val)
1209+LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, void *val)
17321210 {
17331211 add_elf_sym(symtab_section, (uplong)val, 0,
17341212 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
@@ -1736,7 +1214,7 @@ int tcc_add_symbol(TCCState *s, const char *name, void *val) · 1 unmodified line
17361214 return 0;
17371215 }
17381216
1739−int tcc_set_output_type(TCCState *s, int output_type)
1217+LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
17401218 {
17411219 char buf[1024];
17421220
@@ -1825,7 +1303,7 @@ static const FlagDef warning_defs[] = { · 82 unmodified lines
18251303 "implicit-function-declaration" },
18261304 };
18271305
1828−static int set_flag(TCCState *s, const FlagDef *flags, int nb_flags,
1306+ST_FUNC int set_flag(TCCState *s, const FlagDef *flags, int nb_flags,
18291307 const char *name, int value)
18301308 {
18311309 int i;
@@ -1849,9 +1327,8 @@ static int set_flag(TCCState *s, const FlagDef *flags, int nb_flags, · 17 unmodified lines
18491327 return 0;
18501328 }
18511329
1852−
18531330 /* set/reset a warning */
1854−int tcc_set_warning(TCCState *s, const char *warning_name, int value)
1331+LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value)
18551332 {
18561333 int i;
18571334 const FlagDef *p;
@@ -1876,20 +1353,13 @@ static const FlagDef flag_defs[] = { · 18 unmodified lines
18761353 };
18771354
18781355 /* set/reset a flag */
1879−int tcc_set_flag(TCCState *s, const char *flag_name, int value)
1356+PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value)
18801357 {
18811358 return set_flag(s, flag_defs, countof(flag_defs),
18821359 flag_name, value);
18831360 }
18841361
1885−/* set CONFIG_TCCDIR at runtime */
1886−void tcc_set_lib_path(TCCState *s, const char *path)
1887−{
1888− tcc_free(s->tcc_lib_path);
1889− s->tcc_lib_path = tcc_strdup(path);
1890−}
1891−
1892−void tcc_print_stats(TCCState *s, int64_t total_time)
1362+PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
18931363 {
18941364 double tt;
18951365 tt = (double)total_time / 1000000.0;
@@ -1902,3 +1372,17 @@ void tcc_print_stats(TCCState *s, int64_t total_time) · 6 unmodified lines
19021372 tt, (int)(total_lines / tt),
19031373 total_bytes / tt / 1000000.0);
19041374 }
1375+
1376+/* set CONFIG_TCCDIR at runtime */
1377+LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
1378+{
1379+ tcc_free(s->tcc_lib_path);
1380+ s->tcc_lib_path = tcc_strdup(path);
1381+}
1382+
1383+PUB_FUNC void set_num_callers(int n)
1384+{
1385+#ifdef CONFIG_TCC_BACKTRACE
1386+ num_callers = n;
1387+#endif
1388+}
tcc.c+16−16
@@ -18,13 +18,25 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−#ifdef TCC_USE_LIBTCC
21+#if defined NOTALLINONE || defined TCC_USE_LIBTCC
2222 #include "tcc.h"
2323 #else
2424 #include "libtcc.c"
2525 #endif
2626
27−void help(void)
27+static char **files;
28+static int nb_files, nb_libraries;
29+static int multiple_files;
30+static int print_search_dirs;
31+static int output_type;
32+static int reloc_output;
33+static const char *outfile;
34+static int do_bench = 0;
35+
36+#define TCC_OPTION_HAS_ARG 0x0001
37+#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
38+
39+static void help(void)
2840 {
2941 printf("tcc version " TCC_VERSION " - Tiny C Compiler - Copyright (C) 2001-2006 Fabrice Bellard\n"
3042 "usage: tcc [-v] [-c] [-o outfile] [-Bdir] [-bench] [-Idir] [-Dsym[=val]] [-Usym]\n"
@@ -65,18 +77,6 @@ void help(void) · 34 unmodified lines
6577 );
6678 }
6779
68−static char **files;
69−static int nb_files, nb_libraries;
70−static int multiple_files;
71−static int print_search_dirs;
72−static int output_type;
73−static int reloc_output;
74−static const char *outfile;
75−static int do_bench = 0;
76−
77−#define TCC_OPTION_HAS_ARG 0x0001
78−#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
79−
8080 typedef struct TCCOption {
8181 const char *name;
8282 uint16_t index;
@@ -213,7 +213,7 @@ static int expand_args(char ***pargv, const char *str) · 130 unmodified lines
213213 return argc;
214214 }
215215
216−int parse_args(TCCState *s, int argc, char **argv)
216+static int parse_args(TCCState *s, int argc, char **argv)
217217 {
218218 int optind;
219219 const TCCOption *popt;
@@ -304,7 +304,7 @@ int parse_args(TCCState *s, int argc, char **argv) · 84 unmodified lines
304304 break;
305305 #ifdef CONFIG_TCC_BACKTRACE
306306 case TCC_OPTION_bt:
307− num_callers = atoi(optarg);
307+ set_num_callers(atoi(optarg));
308308 break;
309309 #endif
310310 #ifdef CONFIG_TCC_BCHECK
tcc.h+406−28
@@ -18,6 +18,9 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#ifndef _TCC_H
22+#define _TCC_H
23+
2124 #define _GNU_SOURCE
2225 #include "config.h"
2326
@@ -46,6 +49,7 @@ · 22 unmodified lines
4649 #include <direct.h> /* getcwd */
4750 #define inline __inline
4851 #define inp next_inp
52+#define dlclose FreeLibrary
4953 #ifdef _WIN64
5054 #define uplong unsigned long long
5155 #endif
@@ -56,6 +60,7 @@ · 4 unmodified lines
5660 #include <sys/time.h>
5761 #include <sys/ucontext.h>
5862 #include <sys/mman.h>
63+#include <dlfcn.h>
5964 #endif
6065
6166 #endif /* !CONFIG_TCCBOOT */
@@ -766,11 +771,11 @@ enum tcc_token { · 704 unmodified lines
766771 #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) || defined(__DragonFly__) \
767772 || defined(__OpenBSD__)
768773 /* currently incorrect */
769−long double strtold(const char *nptr, char **endptr)
774+static inline long double strtold(const char *nptr, char **endptr)
770775 {
771776 return (long double)strtod(nptr, endptr);
772777 }
773−float strtof(const char *nptr, char **endptr)
778+static inline float strtof(const char *nptr, char **endptr)
774779 {
775780 return (float)strtod(nptr, endptr);
776781 }
@@ -790,38 +795,411 @@ extern long double strtold (const char *__nptr, char **__endptr); · 13 unmodified lines
790795 #define PATHCMP strcmp
791796 #endif
792797
793−void error(const char *fmt, ...);
794−void error_noabort(const char *fmt, ...);
795−void warning(const char *fmt, ...);
796−
797−void tcc_set_lib_path_w32(TCCState *s);
798−int tcc_set_flag(TCCState *s, const char *flag_name, int value);
799−void tcc_print_stats(TCCState *s, int64_t total_time);
798+/* space exlcuding newline */
799+static inline int is_space(int ch)
800+{
801+ return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
802+}
800803
801−void tcc_free(void *ptr);
802−void *tcc_malloc(unsigned long size);
803−void *tcc_mallocz(unsigned long size);
804−void *tcc_realloc(void *ptr, unsigned long size);
805−char *tcc_strdup(const char *str);
804+static inline int isid(int c)
805+{
806+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
807+}
806808
807−char *tcc_basename(const char *name);
808−char *tcc_fileextension (const char *name);
809−char *pstrcpy(char *buf, int buf_size, const char *s);
810−char *pstrcat(char *buf, int buf_size, const char *s);
811−void dynarray_add(void ***ptab, int *nb_ptr, void *data);
812−void dynarray_reset(void *pp, int *n);
809+static inline int isnum(int c)
810+{
811+ return c >= '0' && c <= '9';
812+}
813813
814−/* true if float/double/long double type */
815−static inline int is_float(int t)
814+static inline int isoct(int c)
816815 {
817− int bt;
818− bt = t & VT_BTYPE;
819− return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
816+ return c >= '0' && c <= '7';
820817 }
821818
822−/* space exlcuding newline */
823−static inline int is_space(int ch)
819+static inline int toup(int c)
824820 {
825− return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
821+ return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
826822 }
827823
824+#define PUB_FUNC
825+
826+#ifndef NOTALLINONE
827+#define ST_INLN static inline
828+#define ST_FUNC static
829+#define ST_DATA static
830+#else
831+#define ST_INLN
832+#define ST_FUNC
833+#define ST_DATA extern
834+#endif
835+
836+/* ------------ libtcc.c ------------ */
837+
838+/* use GNU C extensions */
839+ST_DATA int gnu_ext;
840+/* use Tiny C extensions */
841+ST_DATA int tcc_ext;
842+/* XXX: get rid of this ASAP */
843+ST_DATA struct TCCState *tcc_state;
844+
845+#ifdef CONFIG_TCC_BACKTRACE
846+ST_DATA int num_callers;
847+ST_DATA const char **rt_bound_error_msg;
848+ST_DATA void *rt_prog_main;
849+#endif
850+
851+#define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
852+#define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
853+#define AFF_PREPROCESS 0x0004 /* preprocess file */
854+
855+/* public functions currently used by the tcc main function */
856+PUB_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
857+PUB_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
858+PUB_FUNC char *tcc_basename(const char *name);
859+PUB_FUNC char *tcc_fileextension (const char *name);
860+PUB_FUNC void tcc_free(void *ptr);
861+PUB_FUNC void *tcc_malloc(unsigned long size);
862+PUB_FUNC void *tcc_mallocz(unsigned long size);
863+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
864+PUB_FUNC char *tcc_strdup(const char *str);
865+#define free(p) use_tcc_free(p)
866+#define malloc(s) use_tcc_malloc(s)
867+#define realloc(p, s) use_tcc_realloc(p, s)
868+#undef strdup
869+#define strdup(s) use_tcc_strdup(s)
870+PUB_FUNC void tcc_memstats(void);
871+PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data);
872+PUB_FUNC void dynarray_reset(void *pp, int *n);
873+PUB_FUNC void error_noabort(const char *fmt, ...);
874+PUB_FUNC void error(const char *fmt, ...);
875+PUB_FUNC void expect(const char *msg);
876+PUB_FUNC void warning(const char *fmt, ...);
877+
878+/* other utilities */
879+ST_INLN void cstr_ccat(CString *cstr, int ch);
880+ST_FUNC void cstr_cat(CString *cstr, const char *str);
881+ST_FUNC void cstr_wccat(CString *cstr, int ch);
882+ST_FUNC void cstr_new(CString *cstr);
883+ST_FUNC void cstr_free(CString *cstr);
884+ST_FUNC void add_char(CString *cstr, int c);
885+#define cstr_reset(cstr) cstr_free(cstr)
886+
887+ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
888+ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
889+ST_FUNC void *section_ptr_add(Section *sec, unsigned long size);
890+ST_FUNC Section *find_section(TCCState *s1, const char *name);
891+
892+ST_FUNC void put_extern_sym2(Sym *sym, Section *section, unsigned long value, unsigned long size, int can_add_underscore);
893+ST_FUNC void put_extern_sym(Sym *sym, Section *section, unsigned long value, unsigned long size);
894+ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
895+
896+ST_INLN void sym_free(Sym *sym);
897+ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c);
898+ST_FUNC Sym *sym_find2(Sym *s, int v);
899+ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
900+ST_FUNC void sym_pop(Sym **ptop, Sym *b);
901+ST_INLN Sym *struct_find(int v);
902+ST_INLN Sym *sym_find(int v);
903+ST_FUNC Sym *global_identifier_push(int v, int t, int c);
904+
905+ST_FUNC BufferedFile *tcc_open(TCCState *s1, const char *filename);
906+ST_FUNC void tcc_close(BufferedFile *bf);
907+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
908+PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value);
909+PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
910+PUB_FUNC void set_num_callers(int n);
911+
912+ST_FUNC int ieee_finite(double d);
913+
914+/* ------------ tccpp.c ------------ */
915+
916+ST_DATA struct BufferedFile *file;
917+ST_DATA int ch, tok;
918+ST_DATA CValue tokc;
919+ST_DATA int *macro_ptr;
920+ST_DATA int parse_flags;
921+ST_DATA int tok_flags;
922+ST_DATA CString tokcstr; /* current parsed string, if any */
923+
924+/* display benchmark infos */
925+ST_DATA int total_lines;
926+ST_DATA int total_bytes;
927+ST_DATA int tok_ident;
928+ST_DATA TokenSym **table_ident;
929+
930+#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
931+#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
932+#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
933+#define TOK_FLAG_EOF 0x0008 /* end of file */
934+
935+#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
936+#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
937+#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
938+ token. line feed is also
939+ returned at eof */
940+#define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
941+#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
942+
943+ST_FUNC TokenSym *tok_alloc(const char *str, int len);
944+ST_FUNC char *get_tok_str(int v, CValue *cv);
945+ST_FUNC void save_parse_state(ParseState *s);
946+ST_FUNC void restore_parse_state(ParseState *s);
947+ST_INLN void tok_str_new(TokenString *s);
948+ST_FUNC void tok_str_free(int *str);
949+ST_FUNC void tok_str_add(TokenString *s, int t);
950+ST_FUNC void tok_str_add_tok(TokenString *s);
951+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
952+ST_FUNC void define_undef(Sym *s);
953+ST_INLN Sym *define_find(int v);
954+ST_FUNC void free_defines(Sym *b);
955+ST_FUNC Sym *label_find(int v);
956+ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
957+ST_FUNC void label_pop(Sym **ptop, Sym *slast);
958+ST_FUNC void parse_define(void);
959+ST_FUNC void preprocess(int is_bof);
960+ST_FUNC void next_nomacro(void);
961+ST_FUNC void next(void);
962+ST_INLN void unget_tok(int last_tok);
963+ST_FUNC void preprocess_init(TCCState *s1);
964+ST_FUNC void preprocess_new();
965+ST_FUNC int tcc_preprocess(TCCState *s1);
966+ST_FUNC void skip(int c);
967+
968+/* ------------ tccgen.c ------------ */
969+
970+ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
971+ST_DATA Section *cur_text_section; /* current section where function code is generated */
972+#ifdef CONFIG_TCC_ASM
973+ST_DATA Section *last_text_section; /* to handle .previous asm directive */
974+#endif
975+#ifdef CONFIG_TCC_BCHECK
976+/* bound check related sections */
977+ST_DATA Section *bounds_section; /* contains global data bound description */
978+ST_DATA Section *lbounds_section; /* contains local data bound description */
979+#endif
980+/* symbol sections */
981+ST_DATA Section *symtab_section, *strtab_section;
982+/* debug sections */
983+ST_DATA Section *stab_section, *stabstr_section;
984+
985+#define SYM_POOL_NB (8192 / sizeof(Sym))
986+ST_DATA Sym *sym_free_first;
987+ST_DATA void **sym_pools;
988+ST_DATA int nb_sym_pools;
989+
990+ST_DATA Sym *global_stack;
991+ST_DATA Sym *local_stack;
992+ST_DATA Sym *local_label_stack;
993+ST_DATA Sym *global_label_stack;
994+ST_DATA Sym *define_stack;
995+ST_DATA CType char_pointer_type, func_old_type, int_type;
996+ST_DATA SValue vstack[VSTACK_SIZE], *vtop;
997+ST_DATA int rsym, anon_sym, ind, loc;
998+
999+ST_DATA int const_wanted; /* true if constant wanted */
1000+ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1001+ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1002+ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1003+ST_DATA int func_vc;
1004+ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
1005+ST_DATA char *funcname;
1006+
1007+ST_INLN int is_float(int t);
1008+ST_FUNC void test_lvalue(void);
1009+ST_FUNC void swap(int *p, int *q);
1010+ST_FUNC void vpushi(int v);
1011+ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
1012+ST_FUNC void vset(CType *type, int r, int v);
1013+ST_FUNC void vswap(void);
1014+ST_FUNC void save_reg(int r);
1015+ST_FUNC int get_reg(int rc);
1016+ST_FUNC void save_regs(int n);
1017+ST_FUNC int gv(int rc);
1018+ST_FUNC void gv2(int rc1, int rc2);
1019+ST_FUNC void vpop(void);
1020+ST_FUNC void gen_op(int op);
1021+ST_FUNC int type_size(CType *type, int *a);
1022+ST_FUNC void mk_pointer(CType *type);
1023+ST_FUNC void vstore(void);
1024+ST_FUNC void inc(int post, int c);
1025+ST_FUNC int lvalue_type(int t);
1026+ST_FUNC void indir(void);
1027+ST_FUNC void unary(void);
1028+ST_FUNC void expr_prod(void);
1029+ST_FUNC void expr_sum(void);
1030+ST_FUNC void gexpr(void);
1031+ST_FUNC int expr_const(void);
1032+ST_FUNC void gen_inline_functions(void);
1033+ST_FUNC void decl(int l);
1034+#ifdef CONFIG_TCC_BCHECK
1035+ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1036+#endif
1037+
1038+/* ------------ tccelf.c ------------ */
1039+
1040+#define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1041+
1042+typedef struct {
1043+ unsigned int n_strx; /* index into string table of name */
1044+ unsigned char n_type; /* type of symbol */
1045+ unsigned char n_other; /* misc info (usually empty) */
1046+ unsigned short n_desc; /* description field */
1047+ unsigned int n_value; /* value of symbol */
1048+} Stab_Sym;
1049+
1050+ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
1051+
1052+ST_FUNC int put_elf_str(Section *s, const char *sym);
1053+ST_FUNC int put_elf_sym(Section *s, unsigned long value, unsigned long size, int info, int other, int shndx, const char *name);
1054+ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size, int info, int other, int sh_num, const char *name);
1055+ST_FUNC int find_elf_sym(Section *s, const char *name);
1056+ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
1057+
1058+ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
1059+ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1060+ST_FUNC void put_stabn(int type, int other, int desc, int value);
1061+ST_FUNC void put_stabd(int type, int other, int desc);
1062+
1063+ST_FUNC void relocate_common_syms(void);
1064+ST_FUNC void relocate_syms(TCCState *s1, int do_resolve);
1065+ST_FUNC void relocate_section(TCCState *s1, Section *s);
1066+
1067+ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
1068+ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1069+ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
1070+ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1071+ST_FUNC void tcc_add_bcheck(TCCState *s1);
1072+
1073+ST_FUNC void build_got_entries(TCCState *s1);
1074+ST_FUNC void tcc_add_runtime(TCCState *s1);
1075+
1076+#ifndef TCC_TARGET_PE
1077+ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1078+ST_FUNC int tcc_load_ldscript(TCCState *s1);
1079+ST_FUNC uint8_t *parse_comment(uint8_t *p);
1080+ST_FUNC void minp(void);
1081+ST_INLN void inp(void);
1082+ST_FUNC int handle_eob(void);
1083+#endif
1084+
1085+/* ------------ xxx-gen.c ------------ */
1086+
1087+ST_FUNC void gsym_addr(int t, int a);
1088+ST_FUNC void gsym(int t);
1089+ST_FUNC void load(int r, SValue *sv);
1090+ST_FUNC void store(int r, SValue *v);
1091+ST_FUNC void gfunc_call(int nb_args);
1092+ST_FUNC void gfunc_prolog(CType *func_type);
1093+ST_FUNC void gfunc_epilog(void);
1094+ST_FUNC int gjmp(int t);
1095+ST_FUNC void gjmp_addr(int a);
1096+ST_FUNC int gtst(int inv, int t);
1097+ST_FUNC void gen_opi(int op);
1098+ST_FUNC void gen_opf(int op);
1099+ST_FUNC void gen_cvt_ftoi(int t);
1100+ST_FUNC void gen_cvt_ftof(int t);
1101+ST_FUNC void ggoto(void);
1102+#ifndef TCC_TARGET_C67
1103+ST_FUNC void o(unsigned int c);
1104+#endif
1105+#ifndef TCC_TARGET_ARM
1106+ST_FUNC void gen_cvt_itof(int t);
1107+#endif
1108+
1109+/* ------------ i386-gen.c ------------ */
1110+#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1111+ST_FUNC void g(int c);
1112+ST_FUNC int oad(int c, int s);
1113+ST_FUNC void gen_le16(int c);
1114+ST_FUNC void gen_le32(int c);
1115+ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1116+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1117+#endif
1118+
1119+#ifdef CONFIG_TCC_BCHECK
1120+ST_FUNC void gen_bounded_ptr_add(void);
1121+ST_FUNC void gen_bounded_ptr_deref(void);
1122+#endif
1123+
1124+/* ------------ x86_64-gen.c ------------ */
1125+#ifdef TCC_TARGET_X86_64
1126+ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1127+#endif
1128+
1129+/* ------------ arm-gen.c ------------ */
1130+#ifdef TCC_TARGET_ARM
1131+ST_FUNC unsigned long encbranch(int pos,int addr,int fail);
1132+ST_FUNC void gen_cvt_itof1(int t);
1133+#endif
1134+
1135+/* ------------ c67-gen.c ------------ */
1136+#ifdef TCC_TARGET_C67
1137+#endif
1138+
1139+/* ------------ tcccoff.c ------------ */
1140+
1141+#ifdef TCC_TARGET_COFF
1142+ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1143+#endif
1144+
1145+/* ------------ tccasm.c ------------ */
1146+ST_FUNC void asm_instr(void);
1147+ST_FUNC void asm_global_instr(void);
1148+
1149+#ifdef CONFIG_TCC_ASM
1150+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1151+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1152+ST_FUNC int asm_int_expr(TCCState *s1);
1153+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
1154+/* ------------ i386-asm.c ------------ */
1155+ST_FUNC void gen_expr32(ExprValue *pe);
1156+ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1157+ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1158+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1159+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1160+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
1161+#endif
1162+/* ------------ tccpe.c -------------- */
1163+#ifdef TCC_TARGET_PE
1164+ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
1165+ST_FUNC int pe_add_dll(struct TCCState *s, const char *libraryname);
1166+ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1167+ST_FUNC int pe_dllimport(int r, SValue *sv, void (*fn)(int r, SValue *sv));
1168+/* tiny_impdef.c */
1169+ST_FUNC char *get_export_names(FILE *fp);
1170+#endif
1171+
1172+/* ------------ tccrun.c ----------------- */
1173+#if !defined CONFIG_TCC_STATIC && !defined _WIN32
1174+ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
1175+#endif
1176+
1177+/********************************************************/
1178+/* include the target specific definitions */
1179+
1180+#define TARGET_DEFS_ONLY
1181+#ifdef TCC_TARGET_I386
1182+#include "i386-gen.c"
1183+#endif
1184+#ifdef TCC_TARGET_X86_64
1185+#include "x86_64-gen.c"
1186+#endif
1187+#ifdef TCC_TARGET_ARM
1188+#include "arm-gen.c"
1189+#endif
1190+#ifdef TCC_TARGET_C67
1191+#include "c67-gen.c"
1192+#endif
1193+#undef TARGET_DEFS_ONLY
1194+
1195+ST_DATA const int reg_classes[NB_REGS];
1196+
1197+/********************************************************/
1198+#undef ST_DATA
1199+#ifndef NOTALLINONE
1200+#define ST_DATA static
1201+#else
1202+#define ST_DATA
1203+#endif
1204+/********************************************************/
1205+#endif /* _TCC_H */
tccasm.c+10−8
@@ -18,7 +18,9 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−static int asm_get_local_label_name(TCCState *s1, unsigned int n)
21+#include "tcc.h"
22+
23+ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
2224 {
2325 char buf[64];
2426 TokenSym *ts;
@@ -28,7 +30,7 @@ static int asm_get_local_label_name(TCCState *s1, unsigned int n) · 3 unmodified lines
2830 return ts->tok;
2931 }
3032
31−static void asm_expr(TCCState *s1, ExprValue *pe);
33+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
3234
3335 /* We do not use the C expression parser to handle symbols. Maybe the
3436 C expression parser could be tweaked to do so. */
@@ -238,12 +240,12 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) · 203 unmodified lines
238240 }
239241 }
240242
241−static void asm_expr(TCCState *s1, ExprValue *pe)
243+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe)
242244 {
243245 asm_expr_sum(s1, pe);
244246 }
245247
246−static int asm_int_expr(TCCState *s1)
248+ST_FUNC int asm_int_expr(TCCState *s1)
247249 {
248250 ExprValue e;
249251 asm_expr(s1, &e);
@@ -699,7 +701,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) · 449 unmodified lines
699701 }
700702
701703 /* Assemble the current file */
702−static int tcc_assemble(TCCState *s1, int do_preprocess)
704+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
703705 {
704706 Sym *define_start;
705707 int ret;
@@ -765,7 +767,7 @@ static void tcc_assemble_inline(TCCState *s1, char *str, int len) · 59 unmodified lines
765767 /* find a constraint by its number or id (gcc 3 extended
766768 syntax). return -1 if not found. Return in *pp in char after the
767769 constraint */
768−static int find_constraint(ASMOperand *operands, int nb_operands,
770+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands,
769771 const char *name, const char **pp)
770772 {
771773 int index;
@@ -916,7 +918,7 @@ static void parse_asm_str(CString *astr) · 144 unmodified lines
916918 }
917919
918920 /* parse the GCC asm() instruction */
919−static void asm_instr(void)
921+ST_FUNC void asm_instr(void)
920922 {
921923 CString astr, astr1;
922924 ASMOperand operands[MAX_ASM_OPERANDS];
@@ -1017,7 +1019,7 @@ static void asm_instr(void) · 94 unmodified lines
10171019 cstr_free(&astr1);
10181020 }
10191021
1020−static void asm_global_instr(void)
1022+ST_FUNC void asm_global_instr(void)
10211023 {
10221024 CString astr;
10231025
tcccoff.c+3−1
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 * License along with this library; if not, write to the Free Software
1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2020 */
21+
22+#include "tcc.h"
2123 #include "coff.h"
2224
2325 #define MAXNSCNS 255 /* MAXIMUM NUMBER OF SECTIONS */
@@ -73,7 +75,7 @@ typedef struct { · 49 unmodified lines
7375 unsigned short dummy4;
7476 } AUXEF;
7577
76−int tcc_output_coff(TCCState *s1, FILE *f)
78+ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
7779 {
7880 Section *tcc_sect;
7981 SCNHDR *coff_sec;
tccelf.c+27−35
@@ -18,6 +18,8 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#include "tcc.h"
22+
2123 #ifdef TCC_TARGET_X86_64
2224 #define ElfW_Rel ElfW(Rela)
2325 #define SHT_RELX SHT_RELA
@@ -33,7 +35,7 @@ · 9 unmodified lines
3335 /* XXX: DLL with PLT would only work with x86-64 for now */
3436 //#define TCC_OUTPUT_DLL_WITH_PLT
3537
36−static int put_elf_str(Section *s, const char *sym)
38+ST_FUNC int put_elf_str(Section *s, const char *sym)
3739 {
3840 int offset, len;
3941 char *ptr;
@@ -95,7 +97,7 @@ static void rebuild_hash(Section *s, unsigned int nb_buckets) · 55 unmodified lines
9597 }
9698
9799 /* return the symbol number */
98−static int put_elf_sym(Section *s,
100+ST_FUNC int put_elf_sym(Section *s,
99101 unsigned long value, unsigned long size,
100102 int info, int other, int shndx, const char *name)
101103 {
@@ -145,7 +147,7 @@ static int put_elf_sym(Section *s, · 43 unmodified lines
145147
146148 /* find global ELF symbol 'name' and return its index. Return 0 if not
147149 found. */
148−static int find_elf_sym(Section *s, const char *name)
150+ST_FUNC int find_elf_sym(Section *s, const char *name)
149151 {
150152 ElfW(Sym) *sym;
151153 Section *hs;
@@ -185,20 +187,20 @@ static void *get_elf_sym_addr(TCCState *s, const char *name, int err) · 33 unmodified lines
185187 }
186188
187189 /* return elf symbol value */
188−void *tcc_get_symbol(TCCState *s, const char *name)
190+LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name)
189191 {
190192 return get_elf_sym_addr(s, name, 0);
191193 }
192194
193195 /* return elf symbol value or error */
194−void *tcc_get_symbol_err(TCCState *s, const char *name)
196+ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name)
195197 {
196198 return get_elf_sym_addr(s, name, 1);
197199 }
198200
199201 /* add an elf symbol : check if it is already defined and patch
200202 it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
201−static int add_elf_sym(Section *s, uplong value, unsigned long size,
203+ST_FUNC int add_elf_sym(Section *s, uplong value, unsigned long size,
202204 int info, int other, int sh_num, const char *name)
203205 {
204206 ElfW(Sym) *esym;
@@ -272,7 +274,7 @@ static int add_elf_sym(Section *s, uplong value, unsigned long size, · 67 unmodified lines
272274 }
273275
274276 /* put relocation */
275−static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
277+ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
276278 int type, int symbol)
277279 {
278280 char buf[256];
@@ -301,15 +303,7 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 22 unmodified lines
301303
302304 /* put stab debug information */
303305
304−typedef struct {
305− unsigned int n_strx; /* index into string table of name */
306− unsigned char n_type; /* type of symbol */
307− unsigned char n_other; /* misc info (usually empty) */
308− unsigned short n_desc; /* description field */
309− unsigned int n_value; /* value of symbol */
310−} Stab_Sym;
311−
312−static void put_stabs(const char *str, int type, int other, int desc,
306+ST_FUNC void put_stabs(const char *str, int type, int other, int desc,
313307 unsigned long value)
314308 {
315309 Stab_Sym *sym;
@@ -326,7 +320,7 @@ static void put_stabs(const char *str, int type, int other, int desc, · 10 unmodified lines
326320 sym->n_value = value;
327321 }
328322
329−static void put_stabs_r(const char *str, int type, int other, int desc,
323+ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc,
330324 unsigned long value, Section *sec, int sym_index)
331325 {
332326 put_stabs(str, type, other, desc, value);
@@ -335,12 +329,12 @@ static void put_stabs_r(const char *str, int type, int other, int desc, · 2 unmodified lines
335329 R_DATA_32, sym_index);
336330 }
337331
338−static void put_stabn(int type, int other, int desc, int value)
332+ST_FUNC void put_stabn(int type, int other, int desc, int value)
339333 {
340334 put_stabs(NULL, type, other, desc, value);
341335 }
342336
343−static void put_stabd(int type, int other, int desc)
337+ST_FUNC void put_stabd(int type, int other, int desc)
344338 {
345339 put_stabs(NULL, type, other, desc, 0);
346340 }
@@ -410,7 +404,7 @@ static void sort_syms(TCCState *s1, Section *s) · 63 unmodified lines
410404 }
411405
412406 /* relocate common symbols in the .bss section */
413−static void relocate_common_syms(void)
407+ST_FUNC void relocate_common_syms(void)
414408 {
415409 ElfW(Sym) *sym, *sym_end;
416410 unsigned long offset, align;
@@ -434,7 +428,7 @@ static void relocate_common_syms(void) · 17 unmodified lines
434428
435429 /* relocate symbol table, resolve undefined symbols if do_resolve is
436430 true and output error if undefined symbol. */
437−static void relocate_syms(TCCState *s1, int do_resolve)
431+ST_FUNC void relocate_syms(TCCState *s1, int do_resolve)
438432 {
439433 ElfW(Sym) *sym, *esym, *sym_end;
440434 int sym_bind, sh_num, sym_index;
@@ -513,7 +507,7 @@ static unsigned long add_got_table(TCCState *s1, unsigned long val) · 72 unmodified lines
513507 #endif
514508
515509 /* relocate a given section (CPU dependent) */
516−static void relocate_section(TCCState *s1, Section *s)
510+ST_FUNC void relocate_section(TCCState *s1, Section *s)
517511 {
518512 Section *sr;
519513 ElfW_Rel *rel, *rel_end, *qrel;
@@ -1012,7 +1006,7 @@ static void put_got_entry(TCCState *s1, · 492 unmodified lines
10121006 }
10131007
10141008 /* build GOT and PLT entries */
1015−static void build_got_entries(TCCState *s1)
1009+ST_FUNC void build_got_entries(TCCState *s1)
10161010 {
10171011 Section *s, *symtab;
10181012 ElfW_Rel *rel, *rel_end;
@@ -1120,7 +1114,7 @@ static void build_got_entries(TCCState *s1) · 101 unmodified lines
11201114 }
11211115 }
11221116
1123−static Section *new_symtab(TCCState *s1,
1117+ST_FUNC Section *new_symtab(TCCState *s1,
11241118 const char *symtab_name, int sh_type, int sh_flags,
11251119 const char *strtab_name,
11261120 const char *hash_name, int hash_sh_flags)
@@ -1186,7 +1180,7 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 59 unmodified lines
11861180 s->sh_num, sym_end);
11871181 }
11881182
1189−static void tcc_add_bcheck(TCCState *s1)
1183+ST_FUNC void tcc_add_bcheck(TCCState *s1)
11901184 {
11911185 #ifdef CONFIG_TCC_BCHECK
11921186 unsigned long *ptr;
@@ -1227,7 +1221,7 @@ static void tcc_add_bcheck(TCCState *s1) · 34 unmodified lines
12271221 }
12281222
12291223 /* add tcc runtime libraries */
1230−static void tcc_add_runtime(TCCState *s1)
1224+ST_FUNC void tcc_add_runtime(TCCState *s1)
12311225 {
12321226 tcc_add_bcheck(s1);
12331227
@@ -1252,7 +1246,7 @@ static void tcc_add_runtime(TCCState *s1) · 18 unmodified lines
12521246 /* add various standard linker symbols (must be done after the
12531247 sections are filled (for example after allocating common
12541248 symbols)) */
1255−static void tcc_add_linker_symbols(TCCState *s1)
1249+ST_FUNC void tcc_add_linker_symbols(TCCState *s1)
12561250 {
12571251 char buf[1024];
12581252 int i;
@@ -1371,7 +1365,7 @@ void patch_dynsym_undef(TCCState *s1, Section *s) · 112 unmodified lines
13711365
13721366 /* output an ELF file */
13731367 /* XXX: suppress unneeded sections */
1374−int elf_output_file(TCCState *s1, const char *filename)
1368+static int elf_output_file(TCCState *s1, const char *filename)
13751369 {
13761370 ElfW(Ehdr) ehdr;
13771371 FILE *f;
@@ -2110,7 +2104,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 732 unmodified lines
21102104 return ret;
21112105 }
21122106
2113−int tcc_output_file(TCCState *s, const char *filename)
2107+LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename)
21142108 {
21152109 int ret;
21162110 #ifdef TCC_TARGET_PE
@@ -2143,7 +2137,7 @@ typedef struct SectionMergeInfo { · 26 unmodified lines
21432137
21442138 /* load an object file and merge it with current files */
21452139 /* XXX: handle correctly stab (debug) info */
2146−static int tcc_load_object_file(TCCState *s1,
2140+ST_FUNC int tcc_load_object_file(TCCState *s1,
21472141 int fd, unsigned long file_offset)
21482142 {
21492143 ElfW(Ehdr) ehdr;
@@ -2412,8 +2406,6 @@ static int tcc_load_object_file(TCCState *s1, · 262 unmodified lines
24122406 return ret;
24132407 }
24142408
2415−#define ARMAG "!<arch>\012" /* For COFF and a.out archives */
2416−
24172409 typedef struct ArchiveHeader {
24182410 char ar_name[16]; /* name of this member */
24192411 char ar_date[12]; /* file mtime */
@@ -2474,7 +2466,7 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 54 unmodified lines
24742466 }
24752467
24762468 /* load a '.a' file */
2477−static int tcc_load_archive(TCCState *s1, int fd)
2469+ST_FUNC int tcc_load_archive(TCCState *s1, int fd)
24782470 {
24792471 ArchiveHeader hdr;
24802472 char ar_size[11];
@@ -2529,7 +2521,7 @@ static int tcc_load_archive(TCCState *s1, int fd) · 48 unmodified lines
25292521 /* load a DLL and all referenced DLLs. 'level = 0' means that the DLL
25302522 is referenced by the user (so it should be added as DT_NEEDED in
25312523 the generated ELF file) */
2532−static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
2524+ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
25332525 {
25342526 ElfW(Ehdr) ehdr;
25352527 ElfW(Shdr) *shdr, *sh, *sh1;
@@ -2802,7 +2794,7 @@ static int ld_add_file_list(TCCState *s1, int as_needed) · 266 unmodified lines
28022794
28032795 /* interpret a subset of GNU ldscripts to handle the dummy libc.so
28042796 files */
2805−static int tcc_load_ldscript(TCCState *s1)
2797+ST_FUNC int tcc_load_ldscript(TCCState *s1)
28062798 {
28072799 char cmd[64];
28082800 char filename[1024];
tccgen.c+290−52
@@ -18,7 +18,244 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−void swap(int *p, int *q)
21+#include "tcc.h"
22+
23+/********************************************************/
24+/* global variables */
25+
26+/* loc : local variable index
27+ ind : output code index
28+ rsym: return symbol
29+ anon_sym: anonymous symbol index
30+*/
31+ST_DATA int rsym, anon_sym, ind, loc;
32+
33+ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
34+ST_DATA Section *cur_text_section; /* current section where function code is generated */
35+#ifdef CONFIG_TCC_ASM
36+ST_DATA Section *last_text_section; /* to handle .previous asm directive */
37+#endif
38+#ifdef CONFIG_TCC_BCHECK
39+/* bound check related sections */
40+ST_DATA Section *bounds_section; /* contains global data bound description */
41+ST_DATA Section *lbounds_section; /* contains local data bound description */
42+#endif
43+/* symbol sections */
44+ST_DATA Section *symtab_section, *strtab_section;
45+/* debug sections */
46+ST_DATA Section *stab_section, *stabstr_section;
47+ST_DATA Sym *sym_free_first;
48+ST_DATA void **sym_pools;
49+ST_DATA int nb_sym_pools;
50+
51+ST_DATA Sym *global_stack;
52+ST_DATA Sym *local_stack;
53+ST_DATA Sym *define_stack;
54+ST_DATA Sym *global_label_stack;
55+ST_DATA Sym *local_label_stack;
56+
57+ST_DATA SValue vstack[VSTACK_SIZE], *vtop;
58+
59+ST_DATA int const_wanted; /* true if constant wanted */
60+ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
61+ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
62+ST_DATA CType func_vt; /* current function return type (used by return instruction) */
63+ST_DATA int func_vc;
64+ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
65+ST_DATA char *funcname;
66+
67+ST_DATA CType char_pointer_type, func_old_type, int_type;
68+
69+/* ------------------------------------------------------------------------- */
70+static void gen_cast(CType *type);
71+static inline CType *pointed_type(CType *type);
72+static int is_compatible_types(CType *type1, CType *type2);
73+static int parse_btype(CType *type, AttributeDef *ad);
74+static void type_decl(CType *type, AttributeDef *ad, int *v, int td);
75+static void parse_expr_type(CType *type);
76+static void decl_initializer(CType *type, Section *sec, unsigned long c, int first, int size_only);
77+static void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg, int is_expr);
78+static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
79+static void expr_eq(void);
80+static void unary_type(CType *type);
81+static int is_compatible_parameter_types(CType *type1, CType *type2);
82+static void expr_type(CType *type);
83+
84+ST_INLN int is_float(int t)
85+{
86+ int bt;
87+ bt = t & VT_BTYPE;
88+ return bt == VT_LDOUBLE || bt == VT_DOUBLE || bt == VT_FLOAT;
89+}
90+
91+ST_FUNC void test_lvalue(void)
92+{
93+ if (!(vtop->r & VT_LVAL))
94+ expect("lvalue");
95+}
96+
97+/* ------------------------------------------------------------------------- */
98+/* symbol allocator */
99+static Sym *__sym_malloc(void)
100+{
101+ Sym *sym_pool, *sym, *last_sym;
102+ int i;
103+
104+ sym_pool = tcc_malloc(SYM_POOL_NB * sizeof(Sym));
105+ dynarray_add(&sym_pools, &nb_sym_pools, sym_pool);
106+
107+ last_sym = sym_free_first;
108+ sym = sym_pool;
109+ for(i = 0; i < SYM_POOL_NB; i++) {
110+ sym->next = last_sym;
111+ last_sym = sym;
112+ sym++;
113+ }
114+ sym_free_first = last_sym;
115+ return last_sym;
116+}
117+
118+static inline Sym *sym_malloc(void)
119+{
120+ Sym *sym;
121+ sym = sym_free_first;
122+ if (!sym)
123+ sym = __sym_malloc();
124+ sym_free_first = sym->next;
125+ return sym;
126+}
127+
128+ST_INLN void sym_free(Sym *sym)
129+{
130+ sym->next = sym_free_first;
131+ sym_free_first = sym;
132+}
133+
134+/* push, without hashing */
135+ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c)
136+{
137+ Sym *s;
138+ s = sym_malloc();
139+ s->v = v;
140+ s->type.t = t;
141+ s->type.ref = NULL;
142+#ifdef _WIN64
143+ s->d = NULL;
144+#endif
145+ s->c = c;
146+ s->next = NULL;
147+ /* add in stack */
148+ s->prev = *ps;
149+ *ps = s;
150+ return s;
151+}
152+
153+/* find a symbol and return its associated structure. 's' is the top
154+ of the symbol stack */
155+ST_FUNC Sym *sym_find2(Sym *s, int v)
156+{
157+ while (s) {
158+ if (s->v == v)
159+ return s;
160+ s = s->prev;
161+ }
162+ return NULL;
163+}
164+
165+/* structure lookup */
166+ST_INLN Sym *struct_find(int v)
167+{
168+ v -= TOK_IDENT;
169+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
170+ return NULL;
171+ return table_ident[v]->sym_struct;
172+}
173+
174+/* find an identifier */
175+ST_INLN Sym *sym_find(int v)
176+{
177+ v -= TOK_IDENT;
178+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
179+ return NULL;
180+ return table_ident[v]->sym_identifier;
181+}
182+
183+/* push a given symbol on the symbol stack */
184+ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
185+{
186+ Sym *s, **ps;
187+ TokenSym *ts;
188+
189+ if (local_stack)
190+ ps = &local_stack;
191+ else
192+ ps = &global_stack;
193+ s = sym_push2(ps, v, type->t, c);
194+ s->type.ref = type->ref;
195+ s->r = r;
196+ /* don't record fields or anonymous symbols */
197+ /* XXX: simplify */
198+ if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
199+ /* record symbol in token array */
200+ ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
201+ if (v & SYM_STRUCT)
202+ ps = &ts->sym_struct;
203+ else
204+ ps = &ts->sym_identifier;
205+ s->prev_tok = *ps;
206+ *ps = s;
207+ }
208+ return s;
209+}
210+
211+/* push a global identifier */
212+ST_FUNC Sym *global_identifier_push(int v, int t, int c)
213+{
214+ Sym *s, **ps;
215+ s = sym_push2(&global_stack, v, t, c);
216+ /* don't record anonymous symbol */
217+ if (v < SYM_FIRST_ANOM) {
218+ ps = &table_ident[v - TOK_IDENT]->sym_identifier;
219+ /* modify the top most local identifier, so that
220+ sym_identifier will point to 's' when popped */
221+ while (*ps != NULL)
222+ ps = &(*ps)->prev_tok;
223+ s->prev_tok = NULL;
224+ *ps = s;
225+ }
226+ return s;
227+}
228+
229+/* pop symbols until top reaches 'b' */
230+ST_FUNC void sym_pop(Sym **ptop, Sym *b)
231+{
232+ Sym *s, *ss, **ps;
233+ TokenSym *ts;
234+ int v;
235+
236+ s = *ptop;
237+ while(s != b) {
238+ ss = s->prev;
239+ v = s->v;
240+ /* remove symbol in token array */
241+ /* XXX: simplify */
242+ if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
243+ ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
244+ if (v & SYM_STRUCT)
245+ ps = &ts->sym_struct;
246+ else
247+ ps = &ts->sym_identifier;
248+ *ps = s->prev_tok;
249+ }
250+ sym_free(s);
251+ s = ss;
252+ }
253+ *ptop = b;
254+}
255+
256+/* ------------------------------------------------------------------------- */
257+
258+ST_FUNC void swap(int *p, int *q)
22259 {
23260 int t;
24261 t = *p;
@@ -26,7 +263,7 @@ void swap(int *p, int *q) · 1 unmodified line
26263 *q = t;
27264 }
28265
29−void vsetc(CType *type, int r, CValue *vc)
266+static void vsetc(CType *type, int r, CValue *vc)
30267 {
31268 int v;
32269
@@ -48,7 +285,7 @@ void vsetc(CType *type, int r, CValue *vc) · 15 unmodified lines
48285 }
49286
50287 /* push integer constant */
51−void vpushi(int v)
288+ST_FUNC void vpushi(int v)
52289 {
53290 CValue cval;
54291 cval.i = v;
@@ -56,7 +293,7 @@ void vpushi(int v) · 1 unmodified line
56293 }
57294
58295 /* push long long constant */
59−void vpushll(long long v)
296+static void vpushll(long long v)
60297 {
61298 CValue cval;
62299 CType ctype;
@@ -67,8 +304,7 @@ void vpushll(long long v) · 4 unmodified lines
67304 }
68305
69306 /* Return a static symbol pointing to a section */
70−static Sym *get_sym_ref(CType *type, Section *sec,
71− unsigned long offset, unsigned long size)
307+ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
72308 {
73309 int v;
74310 Sym *sym;
@@ -92,7 +328,7 @@ static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned · 17 unmodified lines
92328 }
93329
94330 /* define a new external reference to a symbol 'v' of type 'u' */
95−static Sym *external_global_sym(int v, CType *type, int r)
331+ST_FUNC Sym *external_global_sym(int v, CType *type, int r)
96332 {
97333 Sym *s;
98334
@@ -139,7 +375,7 @@ static void vpush_global_sym(CType *type, int v) · 40 unmodified lines
139375 vtop->sym = sym;
140376 }
141377
142−void vset(CType *type, int r, int v)
378+ST_FUNC void vset(CType *type, int r, int v)
143379 {
144380 CValue cval;
145381
@@ -147,7 +383,7 @@ void vset(CType *type, int r, int v) · 1 unmodified line
147383 vsetc(type, r, &cval);
148384 }
149385
150−void vseti(int r, int v)
386+static void vseti(int r, int v)
151387 {
152388 CType type;
153389 type.t = VT_INT;
@@ -155,7 +391,7 @@ void vseti(int r, int v) · 1 unmodified line
155391 vset(&type, r, v);
156392 }
157393
158−void vswap(void)
394+ST_FUNC void vswap(void)
159395 {
160396 SValue tmp;
161397
@@ -164,7 +400,7 @@ void vswap(void) · 2 unmodified lines
164400 vtop[-1] = tmp;
165401 }
166402
167−void vpushv(SValue *v)
403+static void vpushv(SValue *v)
168404 {
169405 if (vtop >= vstack + (VSTACK_SIZE - 1))
170406 error("memory full");
@@ -172,13 +408,13 @@ void vpushv(SValue *v) · 1 unmodified line
172408 *vtop = *v;
173409 }
174410
175−void vdup(void)
411+static void vdup(void)
176412 {
177413 vpushv(vtop);
178414 }
179415
180416 /* save r to the memory stack, and mark it as being free */
181−void save_reg(int r)
417+ST_FUNC void save_reg(int r)
182418 {
183419 int l, saved, size, align;
184420 SValue *p, sv;
@@ -240,9 +476,10 @@ void save_reg(int r) · 55 unmodified lines
240476 }
241477 }
242478
479+#ifdef TCC_TARGET_ARM
243480 /* find a register of class 'rc2' with at most one reference on stack.
244481 * If none, call get_reg(rc) */
245−int get_reg_ex(int rc, int rc2)
482+ST_FUNC int get_reg_ex(int rc, int rc2)
246483 {
247484 int r;
248485 SValue *p;
@@ -262,9 +499,10 @@ int get_reg_ex(int rc, int rc2) · 13 unmodified lines
262499 }
263500 return get_reg(rc);
264501 }
502+#endif
265503
266504 /* find a free register of class 'rc'. If none, save one register */
267−int get_reg(int rc)
505+ST_FUNC int get_reg(int rc)
268506 {
269507 int r;
270508 SValue *p;
@@ -302,7 +540,7 @@ int get_reg(int rc) · 31 unmodified lines
302540 }
303541
304542 /* save registers up to (vtop - n) stack entry */
305−void save_regs(int n)
543+ST_FUNC void save_regs(int n)
306544 {
307545 int r;
308546 SValue *p, *p1;
@@ -317,7 +555,7 @@ void save_regs(int n) · 8 unmodified lines
317555
318556 /* move register 's' to 'r', and flush previous value of r to memory
319557 if needed */
320−void move_reg(int r, int s)
558+static void move_reg(int r, int s)
321559 {
322560 SValue sv;
323561
@@ -331,7 +569,7 @@ void move_reg(int r, int s) · 7 unmodified lines
331569 }
332570
333571 /* get address of vtop (vtop MUST BE an lvalue) */
334−void gaddrof(void)
572+static void gaddrof(void)
335573 {
336574 vtop->r &= ~VT_LVAL;
337575 /* tricky: if saved lvalue, then we can go back to lvalue */
@@ -341,7 +579,7 @@ void gaddrof(void) · 3 unmodified lines
341579
342580 #ifdef CONFIG_TCC_BCHECK
343581 /* generate lvalue bound code */
344−void gbound(void)
582+static void gbound(void)
345583 {
346584 int lval_type;
347585 CType type1;
@@ -370,7 +608,7 @@ void gbound(void) · 22 unmodified lines
370608 /* store vtop a register belonging to class 'rc'. lvalues are
371609 converted to values. Cannot be used if cannot be converted to
372610 register value (such as structures). */
373−int gv(int rc)
611+ST_FUNC int gv(int rc)
374612 {
375613 int r, rc2, bit_pos, bit_size, size, align, i;
376614
@@ -537,7 +775,7 @@ int gv(int rc) · 160 unmodified lines
537775 }
538776
539777 /* generate vtop[-1] and vtop[0] in resp. classes rc1 and rc2 */
540−void gv2(int rc1, int rc2)
778+ST_FUNC void gv2(int rc1, int rc2)
541779 {
542780 int v;
543781
@@ -569,7 +807,7 @@ void gv2(int rc1, int rc2) · 25 unmodified lines
569807 }
570808
571809 /* wrapper around RC_FRET to return a register by type */
572−int rc_fret(int t)
810+static int rc_fret(int t)
573811 {
574812 #ifdef TCC_TARGET_X86_64
575813 if (t == VT_LDOUBLE) {
@@ -580,7 +818,7 @@ int rc_fret(int t) · 4 unmodified lines
580818 }
581819
582820 /* wrapper around REG_FRET to return a register by type */
583−int reg_fret(int t)
821+static int reg_fret(int t)
584822 {
585823 #ifdef TCC_TARGET_X86_64
586824 if (t == VT_LDOUBLE) {
@@ -591,7 +829,7 @@ int reg_fret(int t) · 4 unmodified lines
591829 }
592830
593831 /* expand long long on stack in two int registers */
594−void lexpand(void)
832+static void lexpand(void)
595833 {
596834 int u;
597835
@@ -607,7 +845,7 @@ void lexpand(void) · 9 unmodified lines
607845
608846 #ifdef TCC_TARGET_ARM
609847 /* expand long long on stack */
610−void lexpand_nr(void)
848+ST_FUNC void lexpand_nr(void)
611849 {
612850 int u,v;
613851
@@ -634,7 +872,7 @@ void lexpand_nr(void) · 20 unmodified lines
634872 #endif
635873
636874 /* build a long long from two ints */
637−void lbuild(int t)
875+static void lbuild(int t)
638876 {
639877 gv2(RC_INT, RC_INT);
640878 vtop[-1].r2 = vtop[0].r;
@@ -645,7 +883,7 @@ void lbuild(int t) · 4 unmodified lines
645883 /* rotate n first stack elements to the bottom
646884 I1 ... In -> I2 ... In I1 [top is right]
647885 */
648−void vrotb(int n)
886+static void vrotb(int n)
649887 {
650888 int i;
651889 SValue tmp;
@@ -659,7 +897,7 @@ void vrotb(int n) · 7 unmodified lines
659897 /* rotate n first stack elements to the top
660898 I1 ... In -> In I1 ... I(n-1) [top is right]
661899 */
662−void vrott(int n)
900+static void vrott(int n)
663901 {
664902 int i;
665903 SValue tmp;
@@ -687,7 +925,7 @@ void vnrott(int n) · 21 unmodified lines
687925 #endif
688926
689927 /* pop stack value */
690−void vpop(void)
928+ST_FUNC void vpop(void)
691929 {
692930 int v;
693931 v = vtop->r & VT_VALMASK;
@@ -706,7 +944,7 @@ void vpop(void) · 12 unmodified lines
706944
707945 /* convert stack entry to register and duplicate its value in another
708946 register */
709−void gv_dup(void)
947+static void gv_dup(void)
710948 {
711949 int rc, t, r, r1;
712950 SValue sv;
@@ -753,7 +991,7 @@ void gv_dup(void) · 40 unmodified lines
753991
754992 #ifndef TCC_TARGET_X86_64
755993 /* generate CPU independent (unsigned) long long operations */
756−void gen_opl(int op)
994+static void gen_opl(int op)
757995 {
758996 int t, a, b, op1, c, i;
759997 int func;
@@ -990,7 +1228,7 @@ void gen_opl(int op) · 230 unmodified lines
9901228
9911229 /* handle integer constant optimizations and various machine
9921230 independent opt */
993−void gen_opic(int op)
1231+static void gen_opic(int op)
9941232 {
9951233 int c1, c2, t1, t2, n;
9961234 SValue *v1, *v2;
@@ -1130,7 +1368,7 @@ void gen_opic(int op) · 133 unmodified lines
11301368 }
11311369
11321370 /* generate a floating point operation with constant propagation */
1133−void gen_opif(int op)
1371+static void gen_opif(int op)
11341372 {
11351373 int c1, c2;
11361374 SValue *v1, *v2;
@@ -1262,7 +1500,7 @@ static void check_comparison_pointer_types(SValue *p1, SValue *p2, int op) · 125 unmodified lines
12621500 }
12631501
12641502 /* generic gen_op: handles types problems */
1265−void gen_op(int op)
1503+ST_FUNC void gen_op(int op)
12661504 {
12671505 int u, t1, t2, bt1, bt2, t;
12681506 CType type1;
@@ -1411,7 +1649,7 @@ void gen_op(int op) · 142 unmodified lines
14111649
14121650 #ifndef TCC_TARGET_ARM
14131651 /* generic itof for unsigned long long case */
1414−void gen_cvt_itof1(int t)
1652+static void gen_cvt_itof1(int t)
14151653 {
14161654 if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
14171655 (VT_LLONG | VT_UNSIGNED)) {
@@ -1435,7 +1673,7 @@ void gen_cvt_itof1(int t) · 17 unmodified lines
14351673 #endif
14361674
14371675 /* generic ftoi for unsigned long long case */
1438−void gen_cvt_ftoi1(int t)
1676+static void gen_cvt_ftoi1(int t)
14391677 {
14401678 int st;
14411679
@@ -1461,7 +1699,7 @@ void gen_cvt_ftoi1(int t) · 19 unmodified lines
14611699 }
14621700
14631701 /* force char or short cast */
1464−void force_charshort_cast(int t)
1702+static void force_charshort_cast(int t)
14651703 {
14661704 int bits, dbt;
14671705 dbt = t & VT_BTYPE;
@@ -1672,7 +1910,7 @@ static void gen_cast(CType *type) · 204 unmodified lines
16721910 }
16731911
16741912 /* return type size. Put alignment at 'a' */
1675−static int type_size(CType *type, int *a)
1913+ST_FUNC int type_size(CType *type, int *a)
16761914 {
16771915 Sym *s;
16781916 int bt;
@@ -1738,7 +1976,7 @@ static inline CType *pointed_type(CType *type) · 59 unmodified lines
17381976 }
17391977
17401978 /* modify type so that its it is a pointer to type. */
1741−static void mk_pointer(CType *type)
1979+ST_FUNC void mk_pointer(CType *type)
17421980 {
17431981 Sym *s;
17441982 s = sym_push(SYM_FIELD, type, 0, -1);
@@ -1829,7 +2067,7 @@ static int is_compatible_parameter_types(CType *type1, CType *type2) · 84 unmodified lines
18292067 printed in the type */
18302068 /* XXX: union */
18312069 /* XXX: add array and function pointers */
1832−void type_to_str(char *buf, int buf_size,
2070+static void type_to_str(char *buf, int buf_size,
18332071 CType *type, const char *varstr)
18342072 {
18352073 int bt, v, t;
@@ -2000,7 +2238,7 @@ static void gen_assign_cast(CType *dt) · 164 unmodified lines
20002238 }
20012239
20022240 /* store vtop in lvalue pushed on stack */
2003−void vstore(void)
2241+ST_FUNC void vstore(void)
20042242 {
20052243 int sbt, dbt, ft, r, t, size, align, bit_size, bit_pos, rc, delayed_cast;
20062244
@@ -2161,7 +2399,7 @@ void vstore(void) · 154 unmodified lines
21612399 }
21622400
21632401 /* post defines POST/PRE add. c is the token ++ or -- */
2164−void inc(int post, int c)
2402+ST_FUNC void inc(int post, int c)
21652403 {
21662404 test_lvalue();
21672405 vdup(); /* save lvalue */
@@ -2879,7 +3117,7 @@ static void type_decl(CType *type, AttributeDef *ad, int *v, int td) · 711 unmodified lines
28793117 }
28803118
28813119 /* compute the lvalue VT_LVAL_xxx needed to match type t. */
2882−static int lvalue_type(int t)
3120+ST_FUNC int lvalue_type(int t)
28833121 {
28843122 int bt, r;
28853123 r = VT_LVAL;
@@ -2896,7 +3134,7 @@ static int lvalue_type(int t) · 10 unmodified lines
28963134 }
28973135
28983136 /* indirection with full error checking and bound check */
2899−static void indir(void)
3137+ST_FUNC void indir(void)
29003138 {
29013139 if ((vtop->type.t & VT_BTYPE) != VT_PTR) {
29023140 if ((vtop->type.t & VT_BTYPE) == VT_FUNC)
@@ -2976,7 +3214,7 @@ static void vpush_tokc(int t) · 73 unmodified lines
29763214 vsetc(&type, VT_CONST, &tokc);
29773215 }
29783216
2979−static void unary(void)
3217+ST_FUNC void unary(void)
29803218 {
29813219 int n, t, align, size, r;
29823220 CType type;
@@ -3444,7 +3682,7 @@ static void uneq(void) · 461 unmodified lines
34443682 }
34453683 }
34463684
3447−static void expr_prod(void)
3685+ST_FUNC void expr_prod(void)
34483686 {
34493687 int t;
34503688
@@ -3457,7 +3695,7 @@ static void expr_prod(void) · 6 unmodified lines
34573695 }
34583696 }
34593697
3460−static void expr_sum(void)
3698+ST_FUNC void expr_sum(void)
34613699 {
34623700 int t;
34633701
@@ -3745,7 +3983,7 @@ static void expr_eq(void) · 281 unmodified lines
37453983 }
37463984 }
37473985
3748−static void gexpr(void)
3986+ST_FUNC void gexpr(void)
37493987 {
37503988 while (1) {
37513989 expr_eq();
@@ -3794,7 +4032,7 @@ static void expr_const1(void) · 42 unmodified lines
37944032 }
37954033
37964034 /* parse an integer constant and return its value. */
3797−static int expr_const(void)
4035+ST_FUNC int expr_const(void)
37984036 {
37994037 int c;
38004038 expr_const1();
@@ -4848,7 +5086,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 1047 unmodified lines
48485086 no_alloc: ;
48495087 }
48505088
4851−void put_func_debug(Sym *sym)
5089+static void put_func_debug(Sym *sym)
48525090 {
48535091 char buf[512];
48545092
@@ -4951,7 +5189,7 @@ static void gen_function(Sym *sym) · 96 unmodified lines
49515189 nocode_wanted = saved_nocode_wanted;
49525190 }
49535191
4954−static void gen_inline_functions(void)
5192+ST_FUNC void gen_inline_functions(void)
49555193 {
49565194 Sym *sym;
49575195 int *str, inline_generated, i;
@@ -4994,7 +5232,7 @@ static void gen_inline_functions(void) · 36 unmodified lines
49945232 }
49955233
49965234 /* 'l' is VT_LOCAL or VT_CONST to define default storage type */
4997−static void decl(int l)
5235+ST_FUNC void decl(int l)
49985236 {
49995237 int v, has_init, r;
50005238 CType type, btype;
tccpe.c+62−67
@@ -18,11 +18,7 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−#ifdef TCC_TARGET_PE
22−
23−#define ST_FN static
24−#define ST_DATA static
25−#define PUB_FN
21+#include "tcc.h"
2622
2723 #ifndef _WIN32
2824 #define stricmp strcasecmp
@@ -300,7 +296,7 @@ enum { · 271 unmodified lines
300296 sec_last
301297 };
302298
303−ST_DATA const DWORD pe_sec_flags[] = {
299+static const DWORD pe_sec_flags[] = {
304300 0x60000020, /* ".text" , */
305301 0xC0000040, /* ".data" , */
306302 0xC0000080, /* ".bss" , */
@@ -366,7 +362,7 @@ struct pe_info { · 59 unmodified lines
366362
367363 /* --------------------------------------------*/
368364
369−ST_FN const char* get_alt_symbol(char *buffer, const char *symbol)
365+static const char* get_alt_symbol(char *buffer, const char *symbol)
370366 {
371367 const char *p;
372368 p = strrchr(symbol, '@');
@@ -384,7 +380,7 @@ ST_FN const char* get_alt_symbol(char *buffer, const char *symbol) · 11 unmodified lines
384380 return buffer;
385381 }
386382
387−ST_FN int pe_find_import(TCCState * s1, const char *symbol)
383+static int pe_find_import(TCCState * s1, const char *symbol)
388384 {
389385 char buffer[200];
390386 const char *s;
@@ -399,7 +395,7 @@ ST_FN int pe_find_import(TCCState * s1, const char *symbol) · 8 unmodified lines
399395
400396 /*----------------------------------------------------------------------------*/
401397
402−ST_FN int dynarray_assoc(void **pp, int n, int key)
398+static int dynarray_assoc(void **pp, int n, int key)
403399 {
404400 int i;
405401 for (i = 0; i < n; ++i, ++pp)
@@ -415,35 +411,35 @@ ST_FN DWORD umin(DWORD a, DWORD b) · 9 unmodified lines
415411 }
416412 #endif
417413
418−ST_FN DWORD umax(DWORD a, DWORD b)
414+static DWORD umax(DWORD a, DWORD b)
419415 {
420416 return a < b ? b : a;
421417 }
422418
423−ST_FN DWORD pe_file_align(struct pe_info *pe, DWORD n)
419+static DWORD pe_file_align(struct pe_info *pe, DWORD n)
424420 {
425421 return (n + (pe->file_align - 1)) & ~(pe->file_align - 1);
426422 }
427423
428−ST_FN DWORD pe_virtual_align(struct pe_info *pe, DWORD n)
424+static DWORD pe_virtual_align(struct pe_info *pe, DWORD n)
429425 {
430426 return (n + (pe->section_align - 1)) & ~(pe->section_align - 1);
431427 }
432428
433−ST_FN void pe_align_section(Section *s, int a)
429+static void pe_align_section(Section *s, int a)
434430 {
435431 int i = s->data_offset & (a-1);
436432 if (i)
437433 section_ptr_add(s, a - i);
438434 }
439435
440−ST_FN void pe_set_datadir(struct pe_header *hdr, int dir, DWORD addr, DWORD size)
436+static void pe_set_datadir(struct pe_header *hdr, int dir, DWORD addr, DWORD size)
441437 {
442438 hdr->opthdr.DataDirectory[dir].VirtualAddress = addr;
443439 hdr->opthdr.DataDirectory[dir].Size = size;
444440 }
445441
446−ST_FN int pe_fwrite(void *data, unsigned len, FILE *fp, DWORD *psum)
442+static int pe_fwrite(void *data, unsigned len, FILE *fp, DWORD *psum)
447443 {
448444 if (psum) {
449445 DWORD sum = *psum;
@@ -458,7 +454,7 @@ ST_FN int pe_fwrite(void *data, unsigned len, FILE *fp, DWORD *psum) · 8 unmodified lines
458454 return len == fwrite(data, 1, len, fp) ? 0 : -1;
459455 }
460456
461−ST_FN void pe_fpad(FILE *fp, DWORD new_pos)
457+static void pe_fpad(FILE *fp, DWORD new_pos)
462458 {
463459 DWORD pos = ftell(fp);
464460 while (++pos <= new_pos)
@@ -466,7 +462,7 @@ ST_FN void pe_fpad(FILE *fp, DWORD new_pos) · 1 unmodified line
466462 }
467463
468464 /*----------------------------------------------------------------------------*/
469−ST_FN int pe_write(struct pe_info *pe)
465+static int pe_write(struct pe_info *pe)
470466 {
471467 static const struct pe_header pe_template = {
472468 {
@@ -745,7 +741,7 @@ ST_FN int pe_write(struct pe_info *pe) · 272 unmodified lines
745741 #endif
746742 /*----------------------------------------------------------------------------*/
747743
748−ST_FN struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
744+static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
749745 {
750746 int i;
751747 int dll_index;
@@ -777,7 +773,7 @@ found_dll: · 25 unmodified lines
777773 }
778774
779775 /*----------------------------------------------------------------------------*/
780−ST_FN void pe_build_imports(struct pe_info *pe)
776+static void pe_build_imports(struct pe_info *pe)
781777 {
782778 int thk_ptr, ent_ptr, dll_ptr, sym_cnt, i;
783779 DWORD rva_base = pe->thunk->sh_addr - pe->imagebase;
@@ -860,14 +856,14 @@ struct pe_sort_sym · 76 unmodified lines
860856 const char *name;
861857 };
862858
863−ST_FN int sym_cmp(const void *va, const void *vb)
859+static int sym_cmp(const void *va, const void *vb)
864860 {
865861 const char *ca = (*(struct pe_sort_sym**)va)->name;
866862 const char *cb = (*(struct pe_sort_sym**)vb)->name;
867863 return strcmp(ca, cb);
868864 }
869865
870−ST_FN void pe_build_exports(struct pe_info *pe)
866+static void pe_build_exports(struct pe_info *pe)
871867 {
872868 ElfW(Sym) *sym;
873869 int sym_index, sym_end;
@@ -967,7 +963,7 @@ ST_FN void pe_build_exports(struct pe_info *pe) · 93 unmodified lines
967963 }
968964
969965 /* ------------------------------------------------------------- */
970−ST_FN void pe_build_reloc (struct pe_info *pe)
966+static void pe_build_reloc (struct pe_info *pe)
971967 {
972968 DWORD offset, block_ptr, addr;
973969 int count, i;
@@ -1023,7 +1019,7 @@ ST_FN void pe_build_reloc (struct pe_info *pe) · 49 unmodified lines
10231019 }
10241020
10251021 /* ------------------------------------------------------------- */
1026−ST_FN int pe_section_class(Section *s)
1022+static int pe_section_class(Section *s)
10271023 {
10281024 int type, flags;
10291025 const char *name;
@@ -1055,7 +1051,7 @@ ST_FN int pe_section_class(Section *s) · 25 unmodified lines
10551051 return -1;
10561052 }
10571053
1058−ST_FN int pe_assign_addresses (struct pe_info *pe)
1054+static int pe_assign_addresses (struct pe_info *pe)
10591055 {
10601056 int i, k, o, c;
10611057 DWORD addr;
@@ -1153,7 +1149,7 @@ ST_FN int pe_assign_addresses (struct pe_info *pe) · 91 unmodified lines
11531149 }
11541150
11551151 /* ------------------------------------------------------------- */
1156−ST_FN void pe_relocate_rva (struct pe_info *pe, Section *s)
1152+static void pe_relocate_rva (struct pe_info *pe, Section *s)
11571153 {
11581154 Section *sr = s->reloc;
11591155 ElfW_Rel *rel, *rel_end;
@@ -1173,6 +1169,7 @@ ST_FN void pe_relocate_rva (struct pe_info *pe, Section *s) · 13 unmodified lines
11731169 }
11741170
11751171 /*----------------------------------------------------------------------------*/
1172+
11761173 static int pe_isafunc(int sym_index)
11771174 {
11781175 Section *sr = text_section->reloc;
@@ -1188,7 +1185,7 @@ static int pe_isafunc(int sym_index) · 9 unmodified lines
11881185 }
11891186
11901187 /*----------------------------------------------------------------------------*/
1191−ST_FN int pe_check_symbols(struct pe_info *pe)
1188+static int pe_check_symbols(struct pe_info *pe)
11921189 {
11931190 ElfW(Sym) *sym;
11941191 int sym_index, sym_end;
@@ -1282,7 +1279,7 @@ ST_FN int pe_check_symbols(struct pe_info *pe) · 87 unmodified lines
12821279
12831280 /*----------------------------------------------------------------------------*/
12841281 #ifdef PE_PRINT_SECTIONS
1285−ST_FN void pe_print_section(FILE * f, Section * s)
1282+static void pe_print_section(FILE * f, Section * s)
12861283 {
12871284 /* just if you'r curious */
12881285 BYTE *p, *e, b;
@@ -1404,7 +1401,7 @@ ST_FN void pe_print_section(FILE * f, Section * s) · 115 unmodified lines
14041401 fprintf(f, "\n\n");
14051402 }
14061403
1407−ST_FN void pe_print_sections(TCCState *s1, const char *fname)
1404+static void pe_print_sections(TCCState *s1, const char *fname)
14081405 {
14091406 Section *s;
14101407 FILE *f;
@@ -1420,34 +1417,8 @@ ST_FN void pe_print_sections(TCCState *s1, const char *fname) · 9 unmodified lines
14201417 #endif
14211418
14221419 /* ------------------------------------------------------------- */
1423−/* helper function for load/store to insert one more indirection */
14241420
1425−int pe_dllimport(int r, SValue *sv, void (*fn)(int r, SValue *sv))
1426−{
1427− int t;
1428− if ((sv->r & (VT_VALMASK|VT_SYM|VT_CONST)) != (VT_SYM|VT_CONST))
1429− return 0;
1430− t = sv->sym->type.t;
1431− if (0 == (t & VT_IMPORT))
1432− return 0;
1433−
1434− sv->sym->type.t = t & ~VT_IMPORT;
1435− //printf("import %x %04x %s\n", t, ind, get_tok_str(sv->sym->v, NULL));
1436−
1437− *++vtop = *sv;
1438− vtop->type.t &= ~(VT_ARRAY|VT_IMPORT);
1439− mk_pointer(&vtop->type);
1440− indir();
1441− fn(r, vtop);
1442− --vtop;
1443−
1444− sv->sym->type.t = t;
1445− return 1;
1446−}
1447−
1448−/* ------------------------------------------------------------- */
1449−
1450−ST_FN int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len)
1421+static int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len)
14511422 {
14521423 fseek(fp, offset, 0);
14531424 return len == fread(buffer, 1, len, fp);
@@ -1458,7 +1429,7 @@ ST_FN int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len) · 4 unmodified lines
14581429 * as generated by 'windres.exe -O coff ...'.
14591430 */
14601431
1461−ST_FN int pe_load_res(TCCState *s1, FILE *fp)
1432+static int pe_load_res(TCCState *s1, FILE *fp)
14621433 {
14631434 struct pe_rsrc_header hdr;
14641435 Section *rsrc_section;
@@ -1498,14 +1469,14 @@ quit: · 33 unmodified lines
14981469 }
14991470
15001471 /* ------------------------------------------------------------- */
1501−ST_FN char *trimfront(char *p)
1472+static char *trimfront(char *p)
15021473 {
15031474 while (*p && (unsigned char)*p <= ' ')
15041475 ++p;
15051476 return p;
15061477 }
15071478
1508−ST_FN char *trimback(char *a, char *e)
1479+static char *trimback(char *a, char *e)
15091480 {
15101481 while (e > a && (unsigned char)e[-1] <= ' ')
15111482 --e;
@@ -1513,7 +1484,7 @@ ST_FN char *trimback(char *a, char *e) · 1 unmodified line
15131484 return a;
15141485 }
15151486
1516−ST_FN char *get_line(char *line, int size, FILE *fp)
1487+static char *get_line(char *line, int size, FILE *fp)
15171488 {
15181489 if (NULL == fgets(line, size, fp))
15191490 return NULL;
@@ -1522,7 +1493,7 @@ ST_FN char *get_line(char *line, int size, FILE *fp) · 2 unmodified lines
15221493 }
15231494
15241495 /* ------------------------------------------------------------- */
1525−ST_FN int pe_load_def(TCCState *s1, FILE *fp)
1496+static int pe_load_def(TCCState *s1, FILE *fp)
15261497 {
15271498 DLLReference *dllref;
15281499 int state = 0, ret = -1;
@@ -1571,7 +1542,7 @@ quit: · 42 unmodified lines
15711542 #define TINY_IMPDEF_GET_EXPORT_NAMES_ONLY
15721543 #include "win32/tools/tiny_impdef.c"
15731544
1574−ST_FN int pe_load_dll(TCCState *s1, const char *dllname, FILE *fp)
1545+static int pe_load_dll(TCCState *s1, const char *dllname, FILE *fp)
15751546 {
15761547 int i = 0;
15771548 char *p, *q;
@@ -1594,7 +1565,7 @@ ST_FN int pe_load_dll(TCCState *s1, const char *dllname, FILE *fp) · 16 unmodified lines
15941565 }
15951566
15961567 /* ------------------------------------------------------------- */
1597−PUB_FN int pe_load_file(struct TCCState *s1, const char *filename, int fd)
1568+ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd)
15981569 {
15991570 FILE *fp = fdopen(dup(fd), "rb");
16001571 int ret = -1;
@@ -1611,7 +1582,7 @@ PUB_FN int pe_load_file(struct TCCState *s1, const char *filename, int fd) · 10 unmodified lines
16111582 return ret;
16121583 }
16131584
1614−int pe_add_dll(struct TCCState *s, const char *libname)
1585+ST_FUNC int pe_add_dll(struct TCCState *s, const char *libname)
16151586 {
16161587 static const char *pat[] = {
16171588 "%s.def", "lib%s.def", "%s.dll", "lib%s.dll", NULL
@@ -1626,6 +1597,32 @@ int pe_add_dll(struct TCCState *s, const char *libname) · 8 unmodified lines
16261597 return -1;
16271598 }
16281599
1600+/* ------------------------------------------------------------- */
1601+/* helper function for load/store to insert one more indirection */
1602+
1603+ST_FUNC int pe_dllimport(int r, SValue *sv, void (*fn)(int r, SValue *sv))
1604+{
1605+ int t;
1606+ if ((sv->r & (VT_VALMASK|VT_SYM|VT_CONST)) != (VT_SYM|VT_CONST))
1607+ return 0;
1608+ t = sv->sym->type.t;
1609+ if (0 == (t & VT_IMPORT))
1610+ return 0;
1611+
1612+ sv->sym->type.t = t & ~VT_IMPORT;
1613+ //printf("import %x %04x %s\n", t, ind, get_tok_str(sv->sym->v, NULL));
1614+
1615+ *++vtop = *sv;
1616+ vtop->type.t &= ~(VT_ARRAY|VT_IMPORT);
1617+ mk_pointer(&vtop->type);
1618+ indir();
1619+ fn(r, vtop);
1620+ --vtop;
1621+
1622+ sv->sym->type.t = t;
1623+ return 1;
1624+}
1625+
16291626 /* ------------------------------------------------------------- */
16301627 #ifdef TCC_TARGET_X86_64
16311628 #define PE_STDSYM(n,s) n
@@ -1633,7 +1630,7 @@ int pe_add_dll(struct TCCState *s, const char *libname) · 1 unmodified line
16331630 #define PE_STDSYM(n,s) "_" n s
16341631 #endif
16351632
1636−ST_FN void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe)
1633+static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe)
16371634 {
16381635 const char *start_symbol;
16391636 unsigned long addr = 0;
@@ -1690,7 +1687,7 @@ ST_FN void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 50 unmodified lines
16901687 pe->start_addr = addr;
16911688 }
16921689
1693−PUB_FN int pe_output_file(TCCState * s1, const char *filename)
1690+ST_FUNC int pe_output_file(TCCState * s1, const char *filename)
16941691 {
16951692 int ret;
16961693 struct pe_info pe;
@@ -1780,5 +1777,3 @@ PUB_FN int pe_output_file(TCCState * s1, const char *filename) · 83 unmodified lines
17801777 }
17811778
17821779 /* ------------------------------------------------------------- */
1783−#endif /* def TCC_TARGET_PE */
1784−/* ------------------------------------------------------------- */
tccpp.c+179−42
@@ -18,6 +18,49 @@ · 17 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21+#include "tcc.h"
22+
23+/********************************************************/
24+/* global variables */
25+
26+ST_DATA int tok_flags;
27+/* additional informations about token */
28+#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
29+#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
30+#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
31+#define TOK_FLAG_EOF 0x0008 /* end of file */
32+
33+ST_DATA int parse_flags;
34+#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
35+#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
36+#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
37+ token. line feed is also
38+ returned at eof */
39+#define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
40+#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
41+
42+ST_DATA struct BufferedFile *file;
43+ST_DATA int ch, tok;
44+ST_DATA CValue tokc;
45+ST_DATA int *macro_ptr;
46+ST_DATA CString tokcstr; /* current parsed string, if any */
47+
48+/* display benchmark infos */
49+ST_DATA int total_lines;
50+ST_DATA int total_bytes;
51+ST_DATA int tok_ident;
52+ST_DATA TokenSym **table_ident;
53+
54+/* ------------------------------------------------------------------------- */
55+
56+static int *macro_ptr_allocated;
57+static int *unget_saved_macro_ptr;
58+static int unget_saved_buffer[TOK_MAX_SIZE + 1];
59+static int unget_buffer_enabled;
60+static TokenSym *hash_ident[TOK_HASH_SIZE];
61+static char token_buf[STRING_MAX_SIZE + 1];
62+/* true if isid(c) || isnum(c) */
63+static unsigned char isidnum_table[256-CH_EOF];
2164
2265 static const char tcc_keywords[] =
2366 #define DEF(id, str) str "\0"
@@ -30,21 +73,115 @@ static const unsigned char tok_two_chars[] = · 6 unmodified lines
3073 "<=\236>=\235!=\225&&\240||\241++\244--\242==\224<<\1>>\2+=\253"
3174 "-=\255*=\252/=\257%=\245&=\246^=\336|=\374->\313..\250##\266";
3275
33−/* true if isid(c) || isnum(c) */
34−static unsigned char isidnum_table[256-CH_EOF];
35−
36−
3776 struct macro_level {
3877 struct macro_level *prev;
3978 int *p;
4079 };
4180
42−static void next_nomacro(void);
81+ST_FUNC void next_nomacro(void);
4382 static void next_nomacro_spc(void);
44−static void macro_subst(TokenString *tok_str, Sym **nested_list,
45− const int *macro_str, struct macro_level **can_read_stream);
83+static void macro_subst(
84+ TokenString *tok_str,
85+ Sym **nested_list,
86+ const int *macro_str,
87+ struct macro_level **can_read_stream
88+ );
89+
90+ST_FUNC void skip(int c)
91+{
92+ if (tok != c)
93+ error("'%c' expected", c);
94+ next();
95+}
4696
97+/* ------------------------------------------------------------------------- */
98+/* CString handling */
99+static void cstr_realloc(CString *cstr, int new_size)
100+{
101+ int size;
102+ void *data;
103+
104+ size = cstr->size_allocated;
105+ if (size == 0)
106+ size = 8; /* no need to allocate a too small first string */
107+ while (size < new_size)
108+ size = size * 2;
109+ data = tcc_realloc(cstr->data_allocated, size);
110+ if (!data)
111+ error("memory full");
112+ cstr->data_allocated = data;
113+ cstr->size_allocated = size;
114+ cstr->data = data;
115+}
116+
117+/* add a byte */
118+ST_INLN void cstr_ccat(CString *cstr, int ch)
119+{
120+ int size;
121+ size = cstr->size + 1;
122+ if (size > cstr->size_allocated)
123+ cstr_realloc(cstr, size);
124+ ((unsigned char *)cstr->data)[size - 1] = ch;
125+ cstr->size = size;
126+}
127+
128+ST_FUNC void cstr_cat(CString *cstr, const char *str)
129+{
130+ int c;
131+ for(;;) {
132+ c = *str;
133+ if (c == '\0')
134+ break;
135+ cstr_ccat(cstr, c);
136+ str++;
137+ }
138+}
47139
140+/* add a wide char */
141+ST_FUNC void cstr_wccat(CString *cstr, int ch)
142+{
143+ int size;
144+ size = cstr->size + sizeof(nwchar_t);
145+ if (size > cstr->size_allocated)
146+ cstr_realloc(cstr, size);
147+ *(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch;
148+ cstr->size = size;
149+}
150+
151+ST_FUNC void cstr_new(CString *cstr)
152+{
153+ memset(cstr, 0, sizeof(CString));
154+}
155+
156+/* free string and reset it to NULL */
157+ST_FUNC void cstr_free(CString *cstr)
158+{
159+ tcc_free(cstr->data_allocated);
160+ cstr_new(cstr);
161+}
162+
163+/* XXX: unicode ? */
164+ST_FUNC void add_char(CString *cstr, int c)
165+{
166+ if (c == '\'' || c == '\"' || c == '\\') {
167+ /* XXX: could be more precise if char or string */
168+ cstr_ccat(cstr, '\\');
169+ }
170+ if (c >= 32 && c <= 126) {
171+ cstr_ccat(cstr, c);
172+ } else {
173+ cstr_ccat(cstr, '\\');
174+ if (c == '\n') {
175+ cstr_ccat(cstr, 'n');
176+ } else {
177+ cstr_ccat(cstr, '0' + ((c >> 6) & 7));
178+ cstr_ccat(cstr, '0' + ((c >> 3) & 7));
179+ cstr_ccat(cstr, '0' + (c & 7));
180+ }
181+ }
182+}
183+
184+/* ------------------------------------------------------------------------- */
48185 /* allocate a new token */
49186 static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
50187 {
@@ -82,7 +219,7 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len) · 31 unmodified lines
82219 #define TOK_HASH_FUNC(h, c) ((h) * 263 + (c))
83220
84221 /* find a token and add it if not found */
85−static TokenSym *tok_alloc(const char *str, int len)
222+ST_FUNC TokenSym *tok_alloc(const char *str, int len)
86223 {
87224 TokenSym *ts, **pts;
88225 int i;
@@ -107,7 +244,7 @@ static TokenSym *tok_alloc(const char *str, int len) · 18 unmodified lines
107244
108245 /* XXX: buffer overflow */
109246 /* XXX: float tokens */
110−char *get_tok_str(int v, CValue *cv)
247+ST_FUNC char *get_tok_str(int v, CValue *cv)
111248 {
112249 static char buf[STRING_MAX_SIZE + 1];
113250 static CString cstr_buf;
@@ -243,13 +380,13 @@ static int tcc_peekc_slow(BufferedFile *bf) · 129 unmodified lines
243380
244381 /* return the current character, handling end of block if necessary
245382 (but not stray) */
246−static int handle_eob(void)
383+ST_FUNC int handle_eob(void)
247384 {
248385 return tcc_peekc_slow(file);
249386 }
250387
251388 /* read next char from current input file and handle end of input buffer */
252−static inline void inp(void)
389+ST_INLN void inp(void)
253390 {
254391 ch = *(++(file->buf_ptr));
255392 /* end of buffer/file handling */
@@ -334,7 +471,7 @@ static int handle_stray1(uint8_t *p) · 78 unmodified lines
334471 /* input with '\[\r]\n' handling. Note that this function cannot
335472 handle other characters after '\', so you cannot call it inside
336473 strings or comments */
337−static void minp(void)
474+ST_FUNC void minp(void)
338475 {
339476 inp();
340477 if (ch == '\\')
@@ -380,7 +517,7 @@ static uint8_t *parse_line_comment(uint8_t *p) · 39 unmodified lines
380517 }
381518
382519 /* C comments */
383−static uint8_t *parse_comment(uint8_t *p)
520+ST_FUNC uint8_t *parse_comment(uint8_t *p)
384521 {
385522 int c;
386523
@@ -537,7 +674,7 @@ static uint8_t *parse_pp_string(uint8_t *p, · 150 unmodified lines
537674
538675 /* skip block of text until #else, #elif or #endif. skip also pairs of
539676 #if/#endif */
540−void preprocess_skip(void)
677+static void preprocess_skip(void)
541678 {
542679 int a, start_of_line, c, in_warn_or_error;
543680 uint8_t *p;
@@ -629,7 +766,7 @@ _default: · 85 unmodified lines
629766 files */
630767
631768 /* save current parse state in 's' */
632−void save_parse_state(ParseState *s)
769+ST_FUNC void save_parse_state(ParseState *s)
633770 {
634771 s->line_num = file->line_num;
635772 s->macro_ptr = macro_ptr;
@@ -638,7 +775,7 @@ void save_parse_state(ParseState *s) · 2 unmodified lines
638775 }
639776
640777 /* restore parse state from 's' */
641−void restore_parse_state(ParseState *s)
778+ST_FUNC void restore_parse_state(ParseState *s)
642779 {
643780 file->line_num = s->line_num;
644781 macro_ptr = s->macro_ptr;
@@ -677,7 +814,7 @@ static inline int tok_ext_size(int t) · 32 unmodified lines
677814
678815 /* token string handling */
679816
680−static inline void tok_str_new(TokenString *s)
817+ST_INLN void tok_str_new(TokenString *s)
681818 {
682819 s->str = NULL;
683820 s->len = 0;
@@ -685,7 +822,7 @@ static inline void tok_str_new(TokenString *s) · 1 unmodified line
685822 s->last_line_num = -1;
686823 }
687824
688−static void tok_str_free(int *str)
825+ST_FUNC void tok_str_free(int *str)
689826 {
690827 tcc_free(str);
691828 }
@@ -707,7 +844,7 @@ static int *tok_str_realloc(TokenString *s) · 15 unmodified lines
707844 return str;
708845 }
709846
710−static void tok_str_add(TokenString *s, int t)
847+ST_FUNC void tok_str_add(TokenString *s, int t)
711848 {
712849 int len, *str;
713850
@@ -790,7 +927,7 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 76 unmodified lines
790927 }
791928
792929 /* add the current parse token in token string 's' */
793−static void tok_str_add_tok(TokenString *s)
930+ST_FUNC void tok_str_add_tok(TokenString *s)
794931 {
795932 CValue cval;
796933
@@ -861,7 +998,7 @@ static void tok_str_add_tok(TokenString *s) · 64 unmodified lines
861998 }
862999
8631000 /* defines handling */
864−static inline void define_push(int v, int macro_type, int *str, Sym *first_arg)
1001+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
8651002 {
8661003 Sym *s;
8671004
@@ -872,7 +1009,7 @@ static inline void define_push(int v, int macro_type, int *str, Sym *first_arg) · 4 unmodified lines
8721009 }
8731010
8741011 /* undefined a define symbol. Its name is just set to zero */
875−static void define_undef(Sym *s)
1012+ST_FUNC void define_undef(Sym *s)
8761013 {
8771014 int v;
8781015 v = s->v;
@@ -881,7 +1018,7 @@ static void define_undef(Sym *s) · 2 unmodified lines
8811018 s->v = 0;
8821019 }
8831020
884−static inline Sym *define_find(int v)
1021+ST_INLN Sym *define_find(int v)
8851022 {
8861023 v -= TOK_IDENT;
8871024 if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
@@ -890,7 +1027,7 @@ static inline Sym *define_find(int v) · 2 unmodified lines
8901027 }
8911028
8921029 /* free define stack until top reaches 'b' */
893−static void free_defines(Sym *b)
1030+ST_FUNC void free_defines(Sym *b)
8941031 {
8951032 Sym *top, *top1;
8961033 int v;
@@ -911,7 +1048,7 @@ static void free_defines(Sym *b) · 14 unmodified lines
9111048 }
9121049
9131050 /* label lookup */
914−static Sym *label_find(int v)
1051+ST_FUNC Sym *label_find(int v)
9151052 {
9161053 v -= TOK_IDENT;
9171054 if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
@@ -919,7 +1056,7 @@ static Sym *label_find(int v) · 1 unmodified line
9191056 return table_ident[v]->sym_label;
9201057 }
9211058
922−static Sym *label_push(Sym **ptop, int v, int flags)
1059+ST_FUNC Sym *label_push(Sym **ptop, int v, int flags)
9231060 {
9241061 Sym *s, **ps;
9251062 s = sym_push2(ptop, v, 0, 0);
@@ -938,7 +1075,7 @@ static Sym *label_push(Sym **ptop, int v, int flags) · 12 unmodified lines
9381075
9391076 /* pop labels until element last is reached. Look if any labels are
9401077 undefined. Define symbols if '&&label' was used. */
941−static void label_pop(Sym **ptop, Sym *slast)
1078+ST_FUNC void label_pop(Sym **ptop, Sym *slast)
9421079 {
9431080 Sym *s, *s1;
9441081 for(s = *ptop; s != slast; s = s1) {
@@ -1017,7 +1154,7 @@ static void tok_print(int *str) · 72 unmodified lines
10171154 #endif
10181155
10191156 /* parse after #define */
1020−static void parse_define(void)
1157+ST_FUNC void parse_define(void)
10211158 {
10221159 Sym *s, *first, **ps;
10231160 int v, t, varg, is_vaargs, spc;
@@ -1193,7 +1330,7 @@ static void pragma_parse(TCCState *s1) · 169 unmodified lines
11931330 }
11941331
11951332 /* is_bof is true if first non space token at beginning of file */
1196−static void preprocess(int is_bof)
1333+ST_FUNC void preprocess(int is_bof)
11971334 {
11981335 TCCState *s1 = tcc_state;
11991336 int i, c, n, saved_parse_flags;
@@ -1350,7 +1487,7 @@ static void preprocess(int is_bof) · 150 unmodified lines
13501487 pstrcpy(f->inc_filename, sizeof(f->inc_filename), buf1);
13511488 file = f;
13521489 /* add include file debug info */
1353− if (tcc_state->do_debug) {
1490+ if (s1->do_debug) {
13541491 put_stabs(file->filename, N_BINCL, 0, 0, 0);
13551492 }
13561493 tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
@@ -1598,7 +1735,7 @@ static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long · 241 unmodified lines
15981735 #define BN_SIZE 2
15991736
16001737 /* bn = (bn << shift) | or_val */
1601−void bn_lshift(unsigned int *bn, int shift, int or_val)
1738+static void bn_lshift(unsigned int *bn, int shift, int or_val)
16021739 {
16031740 int i;
16041741 unsigned int v;
@@ -1609,7 +1746,7 @@ void bn_lshift(unsigned int *bn, int shift, int or_val) · 4 unmodified lines
16091746 }
16101747 }
16111748
1612−void bn_zero(unsigned int *bn)
1749+static void bn_zero(unsigned int *bn)
16131750 {
16141751 int i;
16151752 for(i=0;i<BN_SIZE;i++) {
@@ -1619,7 +1756,7 @@ void bn_zero(unsigned int *bn) · 3 unmodified lines
16191756
16201757 /* parse number in null terminated string 'p' and return it in the
16211758 current token */
1622−void parse_number(const char *p)
1759+static void parse_number(const char *p)
16231760 {
16241761 int b, t, shift, frac_bits, s, exp_val, ch;
16251762 char *q;
@@ -2353,7 +2490,7 @@ static void next_nomacro_spc(void) · 727 unmodified lines
23532490 }
23542491 }
23552492
2356−static void next_nomacro(void)
2493+ST_FUNC void next_nomacro(void)
23572494 {
23582495 do {
23592496 next_nomacro_spc();
@@ -2734,7 +2871,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 374 unmodified lines
27342871 }
27352872
27362873 /* return next token with macro substitution */
2737−static void next(void)
2874+ST_FUNC void next(void)
27382875 {
27392876 Sym *nested_list, *s;
27402877 TokenString str;
@@ -2790,7 +2927,7 @@ static void next(void) · 49 unmodified lines
27902927
27912928 /* push back current token and set current token to 'last_tok'. Only
27922929 identifier case handled for labels. */
2793−static inline void unget_tok(int last_tok)
2930+ST_INLN void unget_tok(int last_tok)
27942931 {
27952932 int i, n;
27962933 int *q;
@@ -2809,7 +2946,7 @@ static inline void unget_tok(int last_tok) · 12 unmodified lines
28092946
28102947 /* better than nothing, but needs extension to handle '-E' option
28112948 correctly too */
2812−static void preprocess_init(TCCState *s1)
2949+ST_FUNC void preprocess_init(TCCState *s1)
28132950 {
28142951 s1->include_stack_ptr = s1->include_stack;
28152952 /* XXX: move that before to avoid having to initialize
@@ -2823,7 +2960,7 @@ static void preprocess_init(TCCState *s1) · 7 unmodified lines
28232960 s1->pack_stack_ptr = s1->pack_stack;
28242961 }
28252962
2826−void preprocess_new()
2963+ST_FUNC void preprocess_new()
28272964 {
28282965 int i, c;
28292966 const char *p, *r;
@@ -2852,9 +2989,10 @@ void preprocess_new() · 22 unmodified lines
28522989 }
28532990
28542991 /* Preprocess the current file */
2855−static int tcc_preprocess(TCCState *s1)
2992+ST_FUNC int tcc_preprocess(TCCState *s1)
28562993 {
28572994 Sym *define_start;
2995+
28582996 BufferedFile *file_ref, **iptr, **iptr_new;
28592997 int token_seen, line_ref, d;
28602998 const char *s;
@@ -2868,8 +3006,8 @@ static int tcc_preprocess(TCCState *s1) · 7 unmodified lines
28683006 token_seen = 0;
28693007 line_ref = 0;
28703008 file_ref = NULL;
2871−
28723009 iptr = s1->include_stack_ptr;
3010+
28733011 for (;;) {
28743012 next();
28753013 if (tok == TOK_EOF) {
@@ -2904,7 +3042,6 @@ print_line: · 28 unmodified lines
29043042 }
29053043 fputs(get_tok_str(tok, &tokc), s1->outfile);
29063044 }
2907− free_defines(define_start);
3045+ free_defines(define_start);
29083046 return 0;
29093047 }
2910−
tccrun.c+22−21
@@ -1,5 +1,5 @@
11 /*
2− * TCC - Tiny C Compiler
2+ * TCC - Tiny C Compiler - Support for -run switch
33 *
44 * Copyright (c) 2001-2004 Fabrice Bellard
55 *
@@ -18,7 +18,7 @@ · 12 unmodified lines
1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1919 */
2020
21−/* tccrun.c - support for tcc -run */
21+#include "tcc.h"
2222
2323 #ifdef _WIN32
2424 #define ucontext_t CONTEXT
@@ -26,7 +26,7 @@ · 1 unmodified line
2626
2727 static void set_pages_executable(void *ptr, unsigned long length);
2828 static void set_exception_handler(void);
29−static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level);
29+static int rt_get_caller_pc(uplong *paddr, ucontext_t *uc, int level);
3030 static void rt_error(ucontext_t *uc, const char *fmt, ...);
3131 static int tcc_relocate_ex(TCCState *s1, void *ptr);
3232
@@ -173,8 +173,8 @@ static void set_pages_executable(void *ptr, unsigned long length) · 140 unmodified lines
173173 VirtualProtect(ptr, length, PAGE_EXECUTE_READWRITE, &old_protect);
174174 #else
175175 unsigned long start, end;
176− start = (unsigned long)ptr & ~(PAGESIZE - 1);
177− end = (unsigned long)ptr + length;
176+ start = (uplong)ptr & ~(PAGESIZE - 1);
177+ end = (uplong)ptr + length;
178178 end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
179179 mprotect((void *)start, end - start, PROT_READ | PROT_WRITE | PROT_EXEC);
180180 #endif
@@ -185,7 +185,7 @@ static void set_pages_executable(void *ptr, unsigned long length) · 4 unmodified lines
185185
186186 /* print the position in the source file of PC value 'pc' by reading
187187 the stabs debug information */
188−static unsigned long rt_printline(unsigned long wanted_pc)
188+static uplong rt_printline(uplong wanted_pc)
189189 {
190190 Stab_Sym *sym, *sym_end;
191191 char func_name[128], last_func_name[128];
@@ -194,7 +194,7 @@ static unsigned long rt_printline(unsigned long wanted_pc) · 2 unmodified lines
194194 int incl_index, len, last_line_num, i;
195195 const char *str, *p;
196196
197− fprintf(stderr, "0x%08lx:", wanted_pc);
197+ fprintf(stderr, "0x%08lx:", (unsigned long)wanted_pc);
198198
199199 func_name[0] = '\0';
200200 func_addr = 0;
@@ -311,7 +311,7 @@ static unsigned long rt_printline(unsigned long wanted_pc) · 110 unmodified lines
311311 static void rt_error(ucontext_t *uc, const char *fmt, ...)
312312 {
313313 va_list ap;
314− unsigned long pc;
314+ uplong pc;
315315 int i;
316316
317317 va_start(ap, fmt);
@@ -327,7 +327,7 @@ static void rt_error(ucontext_t *uc, const char *fmt, ...) · 9 unmodified lines
327327 else
328328 fprintf(stderr, "by ");
329329 pc = rt_printline(pc);
330− if (pc == (unsigned long)rt_prog_main && pc)
330+ if (pc == (uplong)rt_prog_main && pc)
331331 break;
332332 }
333333 exit(255);
@@ -505,11 +505,15 @@ static void set_exception_handler(void) · 171 unmodified lines
505505 SetUnhandledExceptionFilter(cpu_exception_handler);
506506 }
507507
508+#ifdef _WIN64
509+#define Eip Rip
510+#define Ebp Rbp
511+#endif
512+
508513 /* return the PC at frame level 'level'. Return non zero if not found */
509−static int rt_get_caller_pc(unsigned long *paddr,
510− CONTEXT *uc, int level)
514+static int rt_get_caller_pc(uplong *paddr, CONTEXT *uc, int level)
511515 {
512− unsigned long fp;
516+ uplong fp;
513517 int i;
514518
515519 if (level == 0) {
@@ -521,13 +525,16 @@ static int rt_get_caller_pc(unsigned long *paddr, · 5 unmodified lines
521525 /* XXX: check address validity with program info */
522526 if (fp <= 0x1000 || fp >= 0xc0000000)
523527 return -1;
524− fp = ((unsigned long *)fp)[0];
528+ fp = ((uplong*)fp)[0];
525529 }
526− *paddr = ((unsigned long *)fp)[1];
530+ *paddr = ((uplong*)fp)[1];
527531 return 0;
528532 }
529533 }
530534
535+#undef Eip
536+#undef Ebp
537+
531538 #endif /* _WIN32 */
532539 #endif /* CONFIG_TCC_BACKTRACE */
533540 /* ------------------------------------------------------------- */
@@ -584,13 +591,7 @@ void *resolve_sym(TCCState *s1, const char *symbol) · 50 unmodified lines
584591 return NULL;
585592 }
586593
587−#elif defined(_WIN32)
588−
589−#define dlclose FreeLibrary
590−
591−#else
592−
593−#include <dlfcn.h>
594+#elif !defined(_WIN32)
594595
595596 void *resolve_sym(TCCState *s1, const char *sym)
596597 {
x86_64-gen.c+24−14
@@ -20,10 +20,11 @@ · 19 unmodified lines
2020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121 */
2222
23−#include <assert.h>
23+#ifdef TARGET_DEFS_ONLY
2424
2525 /* number of available registers */
26−#define NB_REGS 5
26+#define NB_REGS 5
27+#define NB_ASM_REGS 8
2728
2829 /* a register can belong to several classes. The classes must be
2930 sorted from more general to more precise (see gv2() code which does
@@ -60,14 +61,6 @@ enum { · 30 unmodified lines
6061 #define REX_BASE(reg) (((reg) >> 3) & 1)
6162 #define REG_VALUE(reg) ((reg) & 7)
6263
63−const int reg_classes[NB_REGS] = {
64− /* eax */ RC_INT | RC_RAX,
65− /* ecx */ RC_INT | RC_RCX,
66− /* edx */ RC_INT | RC_RDX,
67− /* xmm0 */ RC_FLOAT | RC_XMM0,
68− /* st0 */ RC_ST0,
69−};
70−
7164 /* return registers for function */
7265 #define REG_IRET TREG_RAX /* single word int return register */
7366 #define REG_LRET TREG_RDX /* second word return register (for long long) */
@@ -85,6 +78,9 @@ const int reg_classes[NB_REGS] = { · 11 unmodified lines
8578 /* maximum alignment (for aligned attribute support) */
8679 #define MAX_ALIGN 8
8780
81+ST_FUNC void gen_opl(int op);
82+ST_FUNC void gen_le64(int64_t c);
83+
8884 /******************************************************/
8985 /* ELF defines */
9086
@@ -100,6 +96,18 @@ const int reg_classes[NB_REGS] = { · 9 unmodified lines
10096 #define ELF_PAGE_SIZE 0x1000
10197
10298 /******************************************************/
99+#else /* ! TARGET_DEFS_ONLY */
100+/******************************************************/
101+#include "tcc.h"
102+#include <assert.h>
103+
104+ST_DATA const int reg_classes[NB_REGS] = {
105+ /* eax */ RC_INT | RC_RAX,
106+ /* ecx */ RC_INT | RC_RCX,
107+ /* edx */ RC_INT | RC_RDX,
108+ /* xmm0 */ RC_FLOAT | RC_XMM0,
109+ /* st0 */ RC_ST0,
110+};
103111
104112 static unsigned long func_sub_sp_offset;
105113 static int func_ret_sub;
@@ -184,7 +192,7 @@ static int is_sse_float(int t) { · 78 unmodified lines
184192 }
185193
186194 /* instruction + 4 bytes data. Return the address of the data */
187−static int oad(int c, int s)
195+ST_FUNC int oad(int c, int s)
188196 {
189197 int ind1;
190198
@@ -198,7 +206,7 @@ static int oad(int c, int s) · 7 unmodified lines
198206 return s;
199207 }
200208
201−static void gen_addr32(int r, Sym *sym, int c)
209+ST_FUNC void gen_addr32(int r, Sym *sym, int c)
202210 {
203211 if (r & VT_SYM)
204212 greloc(cur_text_section, sym, ind, R_X86_64_32);
@@ -206,7 +214,7 @@ static void gen_addr32(int r, Sym *sym, int c) · 1 unmodified line
206214 }
207215
208216 /* output constant with relocation if 'r & VT_SYM' is true */
209−static void gen_addr64(int r, Sym *sym, int64_t c)
217+ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c)
210218 {
211219 if (r & VT_SYM)
212220 greloc(cur_text_section, sym, ind, R_X86_64_64);
@@ -214,7 +222,7 @@ static void gen_addr64(int r, Sym *sym, int64_t c) · 1 unmodified line
214222 }
215223
216224 /* output constant with relocation if 'r & VT_SYM' is true */
217−static void gen_addrpc32(int r, Sym *sym, int c)
225+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
218226 {
219227 if (r & VT_SYM)
220228 greloc(cur_text_section, sym, ind, R_X86_64_PC32);
@@ -1537,3 +1545,5 @@ void ggoto(void) · 1316 unmodified lines
15371545
15381546 /* end of x86-64 code generator */
15391547 /*************************************************************/
1548+#endif /* ! TARGET_DEFS_ONLY */
1549+/******************************************************/

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t