History

Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"

This reverts commit af686a796bda94dc92fc3ad140ef438dafa08950.

mingodad committed 5 years ago

Commit 16456161 parent 2ce2dbc30 files · +10750 −11217Browse files

Unified · Split

30 files
  1. arm-asm.c +556 −556
  2. arm-gen.c +570 −563
  3. arm-link.c +32 −32
  4. arm64-asm.c +13 −13
  5. arm64-gen.c +647 −641
  6. arm64-link.c +32 −32
  7. c67-gen.c +758 −758
  8. c67-link.c +7 −7
  9. i386-asm.c +187 −187
  10. i386-gen.c +368 −365
  11. i386-link.c +34 −34
  12. libtcc.c +393 −470
  13. libtcc.h +21 −72
  14. riscv64-asm.c +187 −187
  15. riscv64-gen.c +457 −451
  16. riscv64-link.c +30 −30
  17. tcc.c +70 −168
  18. tcc.h +299 −458
  19. tccasm.c +420 −418
  20. tcccoff.c +58 −58
  21. tccelf.c +675 −672
  22. tccgen.c +2728 −2636
  23. tccmacho.c +113 −112
  24. tccpe.c +178 −177
  25. tccpp.c +1108 −1063
  26. tccqsort.c +0 −261
  27. tccrun.c +64 −64
  28. tcctools.c +27 −27
  29. x86_64-gen.c +680 −667
  30. x86_64-link.c +38 −38
arm-asm.c+556−556
@@ -24,9 +24,9 @@ · 23 unmodified lines
2424 #define CONFIG_TCC_ASM
2525 #define NB_ASM_REGS 16
2626
27−ST_FUNC void g(TCCState* S, int c);
28−ST_FUNC void gen_le16(TCCState* S, int c);
29−ST_FUNC void gen_le32(TCCState* S, int c);
27+ST_FUNC void g(int c);
28+ST_FUNC void gen_le16(int c);
29+ST_FUNC void gen_le32(int c);
3030
3131 /*************************************************************/
3232 #else
@@ -92,7 +92,7 @@ static int asm_parse_vfp_status_regvar(int t) · 59 unmodified lines
9292 }
9393
9494 /* Parse a text containing operand and store the result in OP */
95−static void parse_operand(TCCState *S, Operand *op)
95+static void parse_operand(TCCState *s1, Operand *op)
9696 {
9797 ExprValue e;
9898 int8_t reg;
@@ -100,54 +100,54 @@ static void parse_operand(TCCState *S, Operand *op) · 1 unmodified line
100100
101101 op->type = 0;
102102
103− if (S->tccpp_tok == '{') { // regset literal
104− next(S); // skip '{'
105− while (S->tccpp_tok != '}' && S->tccpp_tok != TOK_EOF) {
106− reg = asm_parse_regvar(S, S->tccpp_tok);
103+ if (tok == '{') { // regset literal
104+ next(); // skip '{'
105+ while (tok != '}' && tok != TOK_EOF) {
106+ reg = asm_parse_regvar(tok);
107107 if (reg == -1) {
108− expect(S, "register");
108+ expect("register");
109109 return;
110110 } else
111− next(S); // skip register name
111+ next(); // skip register name
112112
113113 if ((1 << reg) < regset)
114− tcc_warning(S, "registers will be processed in ascending order by hardware--but are not specified in ascending order here");
114+ tcc_warning("registers will be processed in ascending order by hardware--but are not specified in ascending order here");
115115 regset |= 1 << reg;
116− if (S->tccpp_tok != ',')
116+ if (tok != ',')
117117 break;
118− next(S); // skip ','
118+ next(); // skip ','
119119 }
120− if (S->tccpp_tok != '}')
121− expect(S, "'}'");
122− next(S); // skip '}'
120+ if (tok != '}')
121+ expect("'}'");
122+ next(); // skip '}'
123123 if (regset == 0) {
124124 // ARM instructions don't support empty regset.
125− tcc_error(S, "empty register list is not supported");
125+ tcc_error("empty register list is not supported");
126126 } else {
127127 op->type = OP_REGSET32;
128128 op->regset = regset;
129129 }
130130 return;
131− } else if ((reg = asm_parse_regvar(S, S->tccpp_tok)) != -1) {
132− next(S); // skip register name
131+ } else if ((reg = asm_parse_regvar(tok)) != -1) {
132+ next(); // skip register name
133133 op->type = OP_REG32;
134134 op->reg = (uint8_t) reg;
135135 return;
136− } else if ((reg = asm_parse_vfp_regvar(S->tccpp_tok, 0)) != -1) {
137− next(S); // skip register name
136+ } else if ((reg = asm_parse_vfp_regvar(tok, 0)) != -1) {
137+ next(); // skip register name
138138 op->type = OP_VREG32;
139139 op->reg = (uint8_t) reg;
140140 return;
141− } else if ((reg = asm_parse_vfp_regvar(S->tccpp_tok, 1)) != -1) {
142− next(S); // skip register name
141+ } else if ((reg = asm_parse_vfp_regvar(tok, 1)) != -1) {
142+ next(); // skip register name
143143 op->type = OP_VREG64;
144144 op->reg = (uint8_t) reg;
145145 return;
146− } else if (S->tccpp_tok == '#' || S->tccpp_tok == '$') {
146+ } else if (tok == '#' || tok == '$') {
147147 /* constant value */
148− next(S); // skip '#' or '$'
148+ next(); // skip '#' or '$'
149149 }
150− asm_expr(S, &e);
150+ asm_expr(s1, &e);
151151 op->type = OP_IM32;
152152 op->e = e;
153153 if (!op->e.sym) {
@@ -156,64 +156,64 @@ static void parse_operand(TCCState *S, Operand *op) · 2 unmodified lines
156156 else if (op->e.v == (uint8_t)op->e.v)
157157 op->type = OP_IM8;
158158 } else
159− expect(S, "operand");
159+ expect("operand");
160160 }
161161
162162 /* XXX: make it faster ? */
163−ST_FUNC void g(TCCState* S, int c)
163+ST_FUNC void g(int c)
164164 {
165165 int ind1;
166− if (S->tccgen_nocode_wanted)
166+ if (nocode_wanted)
167167 return;
168− ind1 = S->tccgen_ind + 1;
168+ ind1 = ind + 1;
169169 if (ind1 > cur_text_section->data_allocated)
170− section_realloc(S, cur_text_section, ind1);
171− cur_text_section->data[S->tccgen_ind] = c;
172− S->tccgen_ind = ind1;
170+ section_realloc(cur_text_section, ind1);
171+ cur_text_section->data[ind] = c;
172+ ind = ind1;
173173 }
174174
175−ST_FUNC void gen_le16 (TCCState* S, int i)
175+ST_FUNC void gen_le16 (int i)
176176 {
177− g(S, i);
178− g(S, i>>8);
177+ g(i);
178+ g(i>>8);
179179 }
180180
181−ST_FUNC void gen_le32 (TCCState* S, int i)
181+ST_FUNC void gen_le32 (int i)
182182 {
183183 int ind1;
184− if (S->tccgen_nocode_wanted)
184+ if (nocode_wanted)
185185 return;
186− ind1 = S->tccgen_ind + 4;
186+ ind1 = ind + 4;
187187 if (ind1 > cur_text_section->data_allocated)
188− section_realloc(S, cur_text_section, ind1);
189− cur_text_section->data[S->tccgen_ind++] = i & 0xFF;
190− cur_text_section->data[S->tccgen_ind++] = (i >> 8) & 0xFF;
191− cur_text_section->data[S->tccgen_ind++] = (i >> 16) & 0xFF;
192− cur_text_section->data[S->tccgen_ind++] = (i >> 24) & 0xFF;
188+ section_realloc(cur_text_section, ind1);
189+ cur_text_section->data[ind++] = i & 0xFF;
190+ cur_text_section->data[ind++] = (i >> 8) & 0xFF;
191+ cur_text_section->data[ind++] = (i >> 16) & 0xFF;
192+ cur_text_section->data[ind++] = (i >> 24) & 0xFF;
193193 }
194194
195−ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
195+ST_FUNC void gen_expr32(ExprValue *pe)
196196 {
197− gen_le32(S, pe->v);
197+ gen_le32(pe->v);
198198 }
199199
200−static uint32_t condition_code_of_token(TCCState* S, int token) {
200+static uint32_t condition_code_of_token(int token) {
201201 if (token < TOK_ASM_nopeq) {
202− expect(S, "condition-enabled instruction");
202+ expect("condition-enabled instruction");
203203 return 0;
204204 } else
205205 return (token - TOK_ASM_nopeq) & 15;
206206 }
207207
208−static void asm_emit_opcode(TCCState* S, int token, uint32_t opcode) {
209− gen_le32(S, (condition_code_of_token(S, token) << 28) | opcode);
208+static void asm_emit_opcode(int token, uint32_t opcode) {
209+ gen_le32((condition_code_of_token(token) << 28) | opcode);
210210 }
211211
212−static void asm_emit_unconditional_opcode(TCCState* S, uint32_t opcode) {
213− gen_le32(S, opcode);
212+static void asm_emit_unconditional_opcode(uint32_t opcode) {
213+ gen_le32(opcode);
214214 }
215215
216−static void asm_emit_coprocessor_opcode(TCCState* S, uint32_t high_nibble, uint8_t cp_number, uint8_t cp_opcode, uint8_t cp_destination_register, uint8_t cp_n_operand_register, uint8_t cp_m_operand_register, uint8_t cp_opcode2, int inter_processor_transfer)
216+static void asm_emit_coprocessor_opcode(uint32_t high_nibble, uint8_t cp_number, uint8_t cp_opcode, uint8_t cp_destination_register, uint8_t cp_n_operand_register, uint8_t cp_m_operand_register, uint8_t cp_opcode2, int inter_processor_transfer)
217217 {
218218 uint32_t opcode = 0xe000000;
219219 if (inter_processor_transfer)
@@ -230,69 +230,69 @@ static void asm_emit_coprocessor_opcode(TCCState* S, uint32_t high_nibble, uint8 · 10 unmodified lines
230230 opcode |= cp_opcode2 << 5;
231231 //assert(cp_m_operand_register < 16);
232232 opcode |= cp_m_operand_register;
233− asm_emit_unconditional_opcode(S, (high_nibble << 28) | opcode);
233+ asm_emit_unconditional_opcode((high_nibble << 28) | opcode);
234234 }
235235
236−static void asm_nullary_opcode(TCCState* S, int token)
236+static void asm_nullary_opcode(int token)
237237 {
238238 switch (ARM_INSTRUCTION_GROUP(token)) {
239239 case TOK_ASM_nopeq:
240− asm_emit_opcode(S, token, 0xd << 21); // mov r0, r0
240+ asm_emit_opcode(token, 0xd << 21); // mov r0, r0
241241 break;
242242 case TOK_ASM_wfeeq:
243− asm_emit_opcode(S, token, 0x320f002);
243+ asm_emit_opcode(token, 0x320f002);
244244 case TOK_ASM_wfieq:
245− asm_emit_opcode(S, token, 0x320f003);
245+ asm_emit_opcode(token, 0x320f003);
246246 break;
247247 default:
248− expect(S, "nullary instruction");
248+ expect("nullary instruction");
249249 }
250250 }
251251
252−static void asm_unary_opcode(TCCState *S, int token)
252+static void asm_unary_opcode(TCCState *s1, int token)
253253 {
254254 Operand op;
255− parse_operand(S, &op);
255+ parse_operand(s1, &op);
256256
257257 switch (ARM_INSTRUCTION_GROUP(token)) {
258258 case TOK_ASM_swieq:
259259 case TOK_ASM_svceq:
260260 if (op.type != OP_IM8)
261− expect(S, "immediate 8-bit unsigned integer");
261+ expect("immediate 8-bit unsigned integer");
262262 else {
263263 /* Note: Dummy operand (ignored by processor): ARM ref documented 0...255, ARM instruction set documented 24 bit */
264− asm_emit_opcode(S, token, (0xf << 24) | op.e.v);
264+ asm_emit_opcode(token, (0xf << 24) | op.e.v);
265265 }
266266 break;
267267 default:
268− expect(S, "unary instruction");
268+ expect("unary instruction");
269269 }
270270 }
271271
272−static void asm_binary_opcode(TCCState *S, int token)
272+static void asm_binary_opcode(TCCState *s1, int token)
273273 {
274274 Operand ops[2];
275275 Operand rotation;
276276 uint32_t encoded_rotation = 0;
277277 uint64_t amount;
278− parse_operand(S, &ops[0]);
279− if (S->tccpp_tok == ',')
280− next(S);
278+ parse_operand(s1, &ops[0]);
279+ if (tok == ',')
280+ next();
281281 else
282− expect(S, "','");
283− parse_operand(S, &ops[1]);
282+ expect("','");
283+ parse_operand(s1, &ops[1]);
284284 if (ops[0].type != OP_REG32) {
285− expect(S, "(destination operand) register");
285+ expect("(destination operand) register");
286286 return;
287287 }
288288
289289 if (ops[0].reg == 15) {
290− tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
290+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
291291 return;
292292 }
293293
294294 if (ops[0].reg == 13)
295− tcc_warning(S, "Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(S, token, NULL));
295+ tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL));
296296
297297 if (ops[1].type != OP_REG32) {
298298 switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -303,38 +303,38 @@ static void asm_binary_opcode(TCCState *S, int token) · 4 unmodified lines
303303 uint16_t immediate_value = ops[1].e.v;
304304 switch (ARM_INSTRUCTION_GROUP(token)) {
305305 case TOK_ASM_movteq:
306− asm_emit_opcode(S, token, 0x3400000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
306+ asm_emit_opcode(token, 0x3400000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
307307 break;
308308 case TOK_ASM_movweq:
309− asm_emit_opcode(S, token, 0x3000000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
309+ asm_emit_opcode(token, 0x3000000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
310310 break;
311311 }
312312 } else
313− expect(S, "(source operand) immediate 16 bit value");
313+ expect("(source operand) immediate 16 bit value");
314314 } else
315− expect(S, "(source operand) immediate");
315+ expect("(source operand) immediate");
316316 break;
317317 default:
318− expect(S, "(source operand) register");
318+ expect("(source operand) register");
319319 }
320320 return;
321321 }
322322
323323 if (ops[1].reg == 15) {
324− tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
324+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
325325 return;
326326 }
327327
328328 if (ops[1].reg == 13)
329− tcc_warning(S, "Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(S, token, NULL));
329+ tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL));
330330
331− if (S->tccpp_tok == ',') {
332− next(S); // skip ','
333− if (S->tccpp_tok == TOK_ASM_ror) {
334− next(S); // skip 'ror'
335− parse_operand(S, &rotation);
331+ if (tok == ',') {
332+ next(); // skip ','
333+ if (tok == TOK_ASM_ror) {
334+ next(); // skip 'ror'
335+ parse_operand(s1, &rotation);
336336 if (rotation.type != OP_IM8) {
337− expect(S, "immediate value for rotation");
337+ expect("immediate value for rotation");
338338 return;
339339 } else {
340340 amount = rotation.e.v;
@@ -349,7 +349,7 @@ static void asm_binary_opcode(TCCState *S, int token) · 8 unmodified lines
349349 encoded_rotation = 3 << 10;
350350 break;
351351 default:
352− expect(S, "'8' or '16' or '24'");
352+ expect("'8' or '16' or '24'");
353353 return;
354354 }
355355 }
@@ -358,27 +358,27 @@ static void asm_binary_opcode(TCCState *S, int token) · 2 unmodified lines
358358 switch (ARM_INSTRUCTION_GROUP(token)) {
359359 case TOK_ASM_clzeq:
360360 if (encoded_rotation)
361− tcc_error(S, "clz does not support rotation");
362− asm_emit_opcode(S, token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg);
361+ tcc_error("clz does not support rotation");
362+ asm_emit_opcode(token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg);
363363 break;
364364 case TOK_ASM_sxtbeq:
365− asm_emit_opcode(S, token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
365+ asm_emit_opcode(token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
366366 break;
367367 case TOK_ASM_sxtheq:
368− asm_emit_opcode(S, token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
368+ asm_emit_opcode(token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
369369 break;
370370 case TOK_ASM_uxtbeq:
371− asm_emit_opcode(S, token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
371+ asm_emit_opcode(token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
372372 break;
373373 case TOK_ASM_uxtheq:
374− asm_emit_opcode(S, token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
374+ asm_emit_opcode(token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
375375 break;
376376 default:
377− expect(S, "binary instruction");
377+ expect("binary instruction");
378378 }
379379 }
380380
381−static void asm_coprocessor_opcode(TCCState *S, int token) {
381+static void asm_coprocessor_opcode(TCCState *s1, int token) {
382382 uint8_t coprocessor;
383383 Operand opcode1;
384384 Operand opcode2;
@@ -387,70 +387,70 @@ static void asm_coprocessor_opcode(TCCState *S, int token) { · 2 unmodified lines
387387 uint8_t high_nibble;
388388 uint8_t mrc = 0;
389389
390− if (S->tccpp_tok >= TOK_ASM_p0 && S->tccpp_tok <= TOK_ASM_p15) {
391− coprocessor = S->tccpp_tok - TOK_ASM_p0;
392− next(S);
390+ if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) {
391+ coprocessor = tok - TOK_ASM_p0;
392+ next();
393393 } else {
394− expect(S, "'p<number>'");
394+ expect("'p<number>'");
395395 return;
396396 }
397397
398− if (S->tccpp_tok == ',')
399− next(S);
398+ if (tok == ',')
399+ next();
400400 else
401− expect(S, "','");
401+ expect("','");
402402
403− parse_operand(S, &opcode1);
403+ parse_operand(s1, &opcode1);
404404 if (opcode1.type != OP_IM8 || opcode1.e.v > 15) {
405− tcc_error(S, "opcode1 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(S, token, NULL));
405+ tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL));
406406 return;
407407 }
408408
409409 for (i = 0; i < 3; ++i) {
410− if (S->tccpp_tok == ',')
411− next(S);
410+ if (tok == ',')
411+ next();
412412 else
413− expect(S, "','");
413+ expect("','");
414414 if (i == 0 && token != TOK_ASM_cdp2 && (ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mrceq || ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mcreq)) {
415− if (S->tccpp_tok >= TOK_ASM_r0 && S->tccpp_tok <= TOK_ASM_r15) {
416− registers[i] = S->tccpp_tok - TOK_ASM_r0;
417− next(S);
415+ if (tok >= TOK_ASM_r0 && tok <= TOK_ASM_r15) {
416+ registers[i] = tok - TOK_ASM_r0;
417+ next();
418418 } else {
419− expect(S, "'r<number>'");
419+ expect("'r<number>'");
420420 return;
421421 }
422422 } else {
423− if (S->tccpp_tok >= TOK_ASM_c0 && S->tccpp_tok <= TOK_ASM_c15) {
424− registers[i] = S->tccpp_tok - TOK_ASM_c0;
425− next(S);
423+ if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) {
424+ registers[i] = tok - TOK_ASM_c0;
425+ next();
426426 } else {
427− expect(S, "'c<number>'");
427+ expect("'c<number>'");
428428 return;
429429 }
430430 }
431431 }
432− if (S->tccpp_tok == ',') {
433− next(S);
434− parse_operand(S, &opcode2);
432+ if (tok == ',') {
433+ next();
434+ parse_operand(s1, &opcode2);
435435 } else {
436436 opcode2.type = OP_IM8;
437437 opcode2.e.v = 0;
438438 }
439439 if (opcode2.type != OP_IM8 || opcode2.e.v > 15) {
440− tcc_error(S, "opcode2 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(S, token, NULL));
440+ tcc_error("opcode2 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL));
441441 return;
442442 }
443443
444444 if (token == TOK_ASM_cdp2) {
445445 high_nibble = 0xF;
446− asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
446+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
447447 return;
448448 } else
449− high_nibble = condition_code_of_token(S, token);
449+ high_nibble = condition_code_of_token(token);
450450
451451 switch (ARM_INSTRUCTION_GROUP(token)) {
452452 case TOK_ASM_cdpeq:
453− asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
453+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
454454 break;
455455 case TOK_ASM_mrceq:
456456 // opcode1 encoding changes! highest and lowest bit gone.
@@ -459,13 +459,13 @@ static void asm_coprocessor_opcode(TCCState *S, int token) { · 2 unmodified lines
459459 case TOK_ASM_mcreq:
460460 // opcode1 encoding changes! highest and lowest bit gone.
461461 if (opcode1.e.v > 7) {
462− tcc_error(S, "opcode1 of instruction '%s' must be an immediate value between 0 and 7", get_tok_str(S, token, NULL));
462+ tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 7", get_tok_str(token, NULL));
463463 return;
464464 }
465− asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, (opcode1.e.v << 1) | mrc, registers[0], registers[1], registers[2], opcode2.e.v, 1);
465+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, (opcode1.e.v << 1) | mrc, registers[0], registers[1], registers[2], opcode2.e.v, 1);
466466 break;
467467 default:
468− expect(S, "known instruction");
468+ expect("known instruction");
469469 }
470470 }
471471
@@ -486,27 +486,27 @@ static void asm_coprocessor_opcode(TCCState *S, int token) { · 14 unmodified lines
486486 #define ENCODE_BARREL_SHIFTER_REGISTER(register_index) ((register_index) << 8)
487487 #define ENCODE_BARREL_SHIFTER_IMMEDIATE(value) ((value) << 7)
488488
489−static void asm_block_data_transfer_opcode(TCCState *S, int token)
489+static void asm_block_data_transfer_opcode(TCCState *s1, int token)
490490 {
491491 uint32_t opcode;
492492 int op0_exclam = 0;
493493 Operand ops[2];
494494 int nb_ops = 1;
495− parse_operand(S, &ops[0]);
496− if (S->tccpp_tok == '!') {
495+ parse_operand(s1, &ops[0]);
496+ if (tok == '!') {
497497 op0_exclam = 1;
498− next(S); // skip '!'
498+ next(); // skip '!'
499499 }
500− if (S->tccpp_tok == ',') {
501− next(S); // skip comma
502− parse_operand(S, &ops[1]);
500+ if (tok == ',') {
501+ next(); // skip comma
502+ parse_operand(s1, &ops[1]);
503503 ++nb_ops;
504504 }
505505 if (nb_ops < 1) {
506− expect(S, "at least one operand");
506+ expect("at least one operand");
507507 return;
508508 } else if (ops[nb_ops - 1].type != OP_REGSET32) {
509− expect(S, "(last operand) register list");
509+ expect("(last operand) register list");
510510 return;
511511 }
512512
@@ -522,9 +522,9 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token) · 9 unmodified lines
522522 // Rn: base register
523523 // Register List: bits 15...0
524524 if (nb_ops != 1)
525− expect(S, "exactly one operand");
525+ expect("exactly one operand");
526526 else
527− asm_emit_opcode(S, token, (0x92d << 16) | ops[0].regset); // TODO: base register ?
527+ asm_emit_opcode(token, (0x92d << 16) | ops[0].regset); // TODO: base register ?
528528 break;
529529 case TOK_ASM_popeq: // TODO: Optimize 1-register case to: ldr ?, [sp], #4
530530 // Instruction: 1 I=0 P=0 U=1 S=0 W=0 L=1 << 20, op 1101
@@ -532,9 +532,9 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token) · 1 unmodified line
532532 // Rn: base register
533533 // Register List: bits 15...0
534534 if (nb_ops != 1)
535− expect(S, "exactly one operand");
535+ expect("exactly one operand");
536536 else
537− asm_emit_opcode(S, token, (0x8bd << 16) | ops[0].regset); // TODO: base register ?
537+ asm_emit_opcode(token, (0x8bd << 16) | ops[0].regset); // TODO: base register ?
538538 break;
539539 case TOK_ASM_stmdaeq:
540540 case TOK_ASM_ldmdaeq:
@@ -574,23 +574,23 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token) · 33 unmodified lines
574574 opcode = 0x99 << 20;
575575 break;
576576 default:
577− tcc_error(S, "internal error: This place should not be reached (fallback in asm_block_data_transfer_opcode)");
577+ tcc_error("internal error: This place should not be reached (fallback in asm_block_data_transfer_opcode)");
578578 }
579579 // operands:
580580 // Rn: first operand
581581 // Register List: lower bits
582582 if (nb_ops != 2)
583− expect(S, "exactly two operands");
583+ expect("exactly two operands");
584584 else if (ops[0].type != OP_REG32)
585− expect(S, "(first operand) register");
585+ expect("(first operand) register");
586586 else {
587587 if (op0_exclam)
588588 opcode |= 1 << 21; // writeback
589− asm_emit_opcode(S, token, opcode | ENCODE_RN(ops[0].reg) | ops[1].regset);
589+ asm_emit_opcode(token, opcode | ENCODE_RN(ops[0].reg) | ops[1].regset);
590590 }
591591 break;
592592 default:
593− expect(S, "block data transfer instruction");
593+ expect("block data transfer instruction");
594594 }
595595 }
596596
@@ -600,17 +600,17 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token) · 3 unmodified lines
600600
601601 NB_SHIFT: will be set to 1 iff SHIFT is filled. Note that for rrx, there's no need to fill SHIFT.
602602 SHIFT: will be filled in with the shift operand to use, if any. */
603−static uint32_t asm_parse_optional_shift(TCCState* S, int* nb_shift, Operand* shift)
603+static uint32_t asm_parse_optional_shift(TCCState* s1, int* nb_shift, Operand* shift)
604604 {
605605 uint32_t opcode = 0;
606606 *nb_shift = 0;
607− switch (S->tccpp_tok) {
607+ switch (tok) {
608608 case TOK_ASM_asl:
609609 case TOK_ASM_lsl:
610610 case TOK_ASM_asr:
611611 case TOK_ASM_lsr:
612612 case TOK_ASM_ror:
613− switch (S->tccpp_tok) {
613+ switch (tok) {
614614 case TOK_ASM_asl:
615615 /* fallthrough */
616616 case TOK_ASM_lsl:
@@ -626,26 +626,26 @@ static uint32_t asm_parse_optional_shift(TCCState* S, int* nb_shift, Operand* sh · 9 unmodified lines
626626 opcode = ENCODE_BARREL_SHIFTER_MODE_ROR;
627627 break;
628628 }
629− next(S);
630− parse_operand(S, shift);
629+ next();
630+ parse_operand(s1, shift);
631631 *nb_shift = 1;
632632 break;
633633 case TOK_ASM_rrx:
634− next(S);
634+ next();
635635 opcode = ENCODE_BARREL_SHIFTER_MODE_ROR;
636636 break;
637637 }
638638 return opcode;
639639 }
640640
641−static uint32_t asm_encode_shift(TCCState *S, Operand* shift)
641+static uint32_t asm_encode_shift(Operand* shift)
642642 {
643643 uint64_t amount;
644644 uint32_t operands = 0;
645645 switch (shift->type) {
646646 case OP_REG32:
647647 if (shift->reg == 15)
648− tcc_error(S, "r15 cannot be used as a shift count");
648+ tcc_error("r15 cannot be used as a shift count");
649649 else {
650650 operands = ENCODE_BARREL_SHIFTER_SHIFT_BY_REGISTER;
651651 operands |= ENCODE_BARREL_SHIFTER_REGISTER(shift->reg);
@@ -656,15 +656,15 @@ static uint32_t asm_encode_shift(TCCState *S, Operand* shift) · 4 unmodified lines
656656 if (amount > 0 && amount < 32)
657657 operands = ENCODE_BARREL_SHIFTER_IMMEDIATE(amount);
658658 else
659− tcc_error(S, "shift count out of range");
659+ tcc_error("shift count out of range");
660660 break;
661661 default:
662− tcc_error(S, "unknown shift amount");
662+ tcc_error("unknown shift amount");
663663 }
664664 return operands;
665665 }
666666
667−static void asm_data_processing_opcode(TCCState *S, int token)
667+static void asm_data_processing_opcode(TCCState *s1, int token)
668668 {
669669 Operand ops[3];
670670 int nb_ops;
@@ -677,31 +677,31 @@ static void asm_data_processing_opcode(TCCState *S, int token) · 6 unmodified lines
677677 uint32_t opcode_nos = opcode_idx >> 1; // without "s"; "OpCode" in ARM docs
678678
679679 for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ) {
680− if (S->tccpp_tok == TOK_ASM_asl || S->tccpp_tok == TOK_ASM_lsl || S->tccpp_tok == TOK_ASM_lsr || S->tccpp_tok == TOK_ASM_asr || S->tccpp_tok == TOK_ASM_ror || S->tccpp_tok == TOK_ASM_rrx)
680+ if (tok == TOK_ASM_asl || tok == TOK_ASM_lsl || tok == TOK_ASM_lsr || tok == TOK_ASM_asr || tok == TOK_ASM_ror || tok == TOK_ASM_rrx)
681681 break;
682− parse_operand(S, &ops[nb_ops]);
682+ parse_operand(s1, &ops[nb_ops]);
683683 ++nb_ops;
684− if (S->tccpp_tok != ',')
684+ if (tok != ',')
685685 break;
686− next(S); // skip ','
686+ next(); // skip ','
687687 }
688− if (S->tccpp_tok == ',')
689− next(S);
690− operands |= asm_parse_optional_shift(S, &nb_shift, &shift);
688+ if (tok == ',')
689+ next();
690+ operands |= asm_parse_optional_shift(s1, &nb_shift, &shift);
691691 if (nb_ops < 2)
692− expect(S, "at least two operands");
692+ expect("at least two operands");
693693 else if (nb_ops == 2) {
694694 memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2]
695695 memcpy(&ops[1], &ops[0], sizeof(ops[0])); // ops[1] was implicit
696696 nb_ops = 3;
697697 } else if (nb_ops == 3) {
698698 if (opcode_nos == 0xd || opcode_nos == 0xf || opcode_nos == 0xa || opcode_nos == 0xb || opcode_nos == 0x8 || opcode_nos == 0x9) { // mov, mvn, cmp, cmn, tst, teq
699− tcc_error(S, "'%s' cannot be used with three operands", get_tok_str(S, token, NULL));
699+ tcc_error("'%s' cannot be used with three operands", get_tok_str(token, NULL));
700700 return;
701701 }
702702 }
703703 if (nb_ops != 3) {
704− expect(S, "two or three operands");
704+ expect("two or three operands");
705705 return;
706706 } else {
707707 uint32_t opcode = 0;
@@ -710,7 +710,7 @@ static void asm_data_processing_opcode(TCCState *S, int token) · 2 unmodified lines
710710 if (nb_shift && shift.type == OP_REG32) {
711711 if ((ops[0].type == OP_REG32 && ops[0].reg == 15) ||
712712 (ops[1].type == OP_REG32 && ops[1].reg == 15)) {
713− tcc_error(S, "Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
713+ tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
714714 return;
715715 }
716716 }
@@ -726,13 +726,13 @@ static void asm_data_processing_opcode(TCCState *S, int token) · 9 unmodified lines
726726 /* operations in the token list are ordered by opcode */
727727 opcode = opcode_nos << 21; // drop "s"
728728 if (ops[0].type != OP_REG32)
729− expect(S, "(destination operand) register");
729+ expect("(destination operand) register");
730730 else if (opcode_nos == 0xa || opcode_nos == 0xb || opcode_nos == 0x8 || opcode_nos == 0x9) // cmp, cmn, tst, teq
731731 operands |= ENCODE_SET_CONDITION_CODES; // force S set, otherwise it's a completely different instruction.
732732 else
733733 operands |= ENCODE_RD(ops[0].reg);
734734 if (ops[1].type != OP_REG32)
735− expect(S, "(first source operand) register");
735+ expect("(first source operand) register");
736736 else if (!(opcode_nos == 0xd || opcode_nos == 0xf)) // not: mov, mvn (those have only one source operand)
737737 operands |= ENCODE_RN(ops[1].reg);
738738 switch (ops[2].type) {
@@ -809,7 +809,7 @@ static void asm_data_processing_opcode(TCCState *S, int token) · 70 unmodified lines
809809 immediate_value = ~immediate_value;
810810 break;
811811 default:
812− tcc_error(S, "cannot use '%s' with a negative immediate value", get_tok_str(S, token, NULL));
812+ tcc_error("cannot use '%s' with a negative immediate value", get_tok_str(token, NULL));
813813 }
814814 for (half_immediate_rotation = 0; half_immediate_rotation < 16; ++half_immediate_rotation) {
815815 if (immediate_value >= 0x00 && immediate_value < 0x100)
@@ -819,30 +819,30 @@ static void asm_data_processing_opcode(TCCState *S, int token) · 3 unmodified lines
819819 }
820820 if (half_immediate_rotation >= 16) {
821821 immediate_value = ops[2].e.v;
822− tcc_error(S, "immediate value 0x%X cannot be encoded into ARM immediate", (unsigned) immediate_value);
822+ tcc_error("immediate value 0x%X cannot be encoded into ARM immediate", (unsigned) immediate_value);
823823 return;
824824 }
825825 operands |= immediate_value;
826826 operands |= half_immediate_rotation << 8;
827827 break;
828828 default:
829− expect(S, "(second source operand) register or immediate value");
829+ expect("(second source operand) register or immediate value");
830830 }
831831
832832 if (nb_shift) {
833833 if (operands & ENCODE_IMMEDIATE_FLAG)
834− tcc_error(S, "immediate rotation not implemented");
834+ tcc_error("immediate rotation not implemented");
835835 else
836− operands |= asm_encode_shift(S, &shift);
836+ operands |= asm_encode_shift(&shift);
837837 }
838838
839839 /* S=0 and S=1 entries alternate one after another, in that order */
840840 opcode |= (opcode_idx & 1) ? ENCODE_SET_CONDITION_CODES : 0;
841− asm_emit_opcode(S, token, opcode | operands);
841+ asm_emit_opcode(token, opcode | operands);
842842 }
843843 }
844844
845−static void asm_shift_opcode(TCCState *S, int token)
845+static void asm_shift_opcode(TCCState *s1, int token)
846846 {
847847 Operand ops[3];
848848 int nb_ops;
@@ -851,20 +851,20 @@ static void asm_shift_opcode(TCCState *S, int token) · 2 unmodified lines
851851 uint32_t operands = 0;
852852
853853 for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
854− parse_operand(S, &ops[nb_ops]);
855− if (S->tccpp_tok != ',') {
854+ parse_operand(s1, &ops[nb_ops]);
855+ if (tok != ',') {
856856 ++nb_ops;
857857 break;
858858 }
859− next(S); // skip ','
859+ next(); // skip ','
860860 }
861861 if (nb_ops < 2) {
862− expect(S, "at least two operands");
862+ expect("at least two operands");
863863 return;
864864 }
865865
866866 if (ops[0].type != OP_REG32) {
867− expect(S, "(destination operand) register");
867+ expect("(destination operand) register");
868868 return;
869869 } else
870870 operands |= ENCODE_RD(ops[0].reg);
@@ -878,9 +878,9 @@ static void asm_shift_opcode(TCCState *S, int token) · 7 unmodified lines
878878 if (ops[1].type == OP_REG32) {
879879 operands |= ops[1].reg;
880880 operands |= ENCODE_BARREL_SHIFTER_MODE_ROR;
881− asm_emit_opcode(S, token, opcode | operands);
881+ asm_emit_opcode(token, opcode | operands);
882882 } else
883− tcc_error(S, "(first source operand) register");
883+ tcc_error("(first source operand) register");
884884 return;
885885 default:
886886 memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2]
@@ -889,7 +889,7 @@ static void asm_shift_opcode(TCCState *S, int token) · 2 unmodified lines
889889 }
890890 }
891891 if (nb_ops != 3) {
892− expect(S, "two or three operands");
892+ expect("two or three operands");
893893 return;
894894 }
895895
@@ -909,7 +909,7 @@ static void asm_shift_opcode(TCCState *S, int token) · 13 unmodified lines
909909 case OP_IM8:
910910 operands |= ENCODE_IMMEDIATE_FLAG;
911911 operands |= ops[1].e.v;
912− tcc_error(S, "Using an immediate value as the source operand is not possible with '%s' instruction on ARM", get_tok_str(S, token, NULL));
912+ tcc_error("Using an immediate value as the source operand is not possible with '%s' instruction on ARM", get_tok_str(token, NULL));
913913 return;
914914 }
915915
@@ -917,13 +917,13 @@ static void asm_shift_opcode(TCCState *S, int token) · 1 unmodified line
917917 case OP_REG32:
918918 if ((ops[0].type == OP_REG32 && ops[0].reg == 15) ||
919919 (ops[1].type == OP_REG32 && ops[1].reg == 15)) {
920− tcc_error(S, "Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
920+ tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
921921 }
922− operands |= asm_encode_shift(S, &ops[2]);
922+ operands |= asm_encode_shift(&ops[2]);
923923 break;
924924 case OP_IM8:
925925 if (ops[2].e.v)
926− operands |= asm_encode_shift(S, &ops[2]);
926+ operands |= asm_encode_shift(&ops[2]);
927927 else
928928 definitely_neutral = 1;
929929 break;
@@ -947,28 +947,28 @@ static void asm_shift_opcode(TCCState *S, int token) · 17 unmodified lines
947947 operands |= ENCODE_BARREL_SHIFTER_MODE_ROR;
948948 break;
949949 default:
950− expect(S, "shift instruction");
950+ expect("shift instruction");
951951 return;
952952 }
953− asm_emit_opcode(S, token, opcode | operands);
953+ asm_emit_opcode(token, opcode | operands);
954954 }
955955
956−static void asm_multiplication_opcode(TCCState *S, int token)
956+static void asm_multiplication_opcode(TCCState *s1, int token)
957957 {
958958 Operand ops[4];
959959 int nb_ops = 0;
960960 uint32_t opcode = 0x90;
961961
962962 for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
963− parse_operand(S, &ops[nb_ops]);
964− if (S->tccpp_tok != ',') {
963+ parse_operand(s1, &ops[nb_ops]);
964+ if (tok != ',') {
965965 ++nb_ops;
966966 break;
967967 }
968− next(S); // skip ','
968+ next(); // skip ','
969969 }
970970 if (nb_ops < 2)
971− expect(S, "at least two operands");
971+ expect("at least two operands");
972972 else if (nb_ops == 2) {
973973 switch (ARM_INSTRUCTION_GROUP(token)) {
974974 case TOK_ASM_mulseq:
@@ -976,7 +976,7 @@ static void asm_multiplication_opcode(TCCState *S, int token) · 1 unmodified line
976976 memcpy(&ops[2], &ops[0], sizeof(ops[1])); // ARM is actually like this!
977977 break;
978978 default:
979− expect(S, "at least three operands");
979+ expect("at least three operands");
980980 return;
981981 }
982982 nb_ops = 3;
@@ -992,20 +992,20 @@ static void asm_multiplication_opcode(TCCState *S, int token) · 9 unmodified lines
992992 if (ops[0].type == OP_REG32)
993993 opcode |= ops[0].reg << 16;
994994 else
995− expect(S, "(destination operand) register");
995+ expect("(destination operand) register");
996996 if (ops[1].type == OP_REG32)
997997 opcode |= ops[1].reg;
998998 else
999− expect(S, "(first source operand) register");
999+ expect("(first source operand) register");
10001000 if (ops[2].type == OP_REG32)
10011001 opcode |= ops[2].reg << 8;
10021002 else
1003− expect(S, "(second source operand) register");
1003+ expect("(second source operand) register");
10041004 if (nb_ops > 3) {
10051005 if (ops[3].type == OP_REG32)
10061006 opcode |= ops[3].reg << 12;
10071007 else
1008− expect(S, "(third source operand) register");
1008+ expect("(third source operand) register");
10091009 }
10101010
10111011 switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1014,9 +1014,9 @@ static void asm_multiplication_opcode(TCCState *S, int token) · 2 unmodified lines
10141014 /* fallthrough */
10151015 case TOK_ASM_muleq:
10161016 if (nb_ops != 3)
1017− expect(S, "three operands");
1017+ expect("three operands");
10181018 else {
1019− asm_emit_opcode(S, token, opcode);
1019+ asm_emit_opcode(token, opcode);
10201020 }
10211021 break;
10221022 case TOK_ASM_mlaseq:
@@ -1024,33 +1024,33 @@ static void asm_multiplication_opcode(TCCState *S, int token) · 1 unmodified line
10241024 /* fallthrough */
10251025 case TOK_ASM_mlaeq:
10261026 if (nb_ops != 4)
1027− expect(S, "four operands");
1027+ expect("four operands");
10281028 else {
10291029 opcode |= 1 << 21; // Accumulate
1030− asm_emit_opcode(S, token, opcode);
1030+ asm_emit_opcode(token, opcode);
10311031 }
10321032 break;
10331033 default:
1034− expect(S, "known multiplication instruction");
1034+ expect("known multiplication instruction");
10351035 }
10361036 }
10371037
1038−static void asm_long_multiplication_opcode(TCCState *S, int token)
1038+static void asm_long_multiplication_opcode(TCCState *s1, int token)
10391039 {
10401040 Operand ops[4];
10411041 int nb_ops = 0;
10421042 uint32_t opcode = 0x90 | (1 << 23);
10431043
10441044 for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
1045− parse_operand(S, &ops[nb_ops]);
1046− if (S->tccpp_tok != ',') {
1045+ parse_operand(s1, &ops[nb_ops]);
1046+ if (tok != ',') {
10471047 ++nb_ops;
10481048 break;
10491049 }
1050− next(S); // skip ','
1050+ next(); // skip ','
10511051 }
10521052 if (nb_ops != 4) {
1053− expect(S, "four operands");
1053+ expect("four operands");
10541054 return;
10551055 }
10561056
@@ -1064,19 +1064,19 @@ static void asm_long_multiplication_opcode(TCCState *S, int token) · 7 unmodified lines
10641064 if (ops[0].type == OP_REG32)
10651065 opcode |= ops[0].reg << 12;
10661066 else
1067− expect(S, "(destination lo accumulator) register");
1067+ expect("(destination lo accumulator) register");
10681068 if (ops[1].type == OP_REG32)
10691069 opcode |= ops[1].reg << 16;
10701070 else
1071− expect(S, "(destination hi accumulator) register");
1071+ expect("(destination hi accumulator) register");
10721072 if (ops[2].type == OP_REG32)
10731073 opcode |= ops[2].reg;
10741074 else
1075− expect(S, "(first source operand) register");
1075+ expect("(first source operand) register");
10761076 if (ops[3].type == OP_REG32)
10771077 opcode |= ops[3].reg << 8;
10781078 else
1079− expect(S, "(second source operand) register");
1079+ expect("(second source operand) register");
10801080
10811081 switch (ARM_INSTRUCTION_GROUP(token)) {
10821082 case TOK_ASM_smullseq:
@@ -1084,13 +1084,13 @@ static void asm_long_multiplication_opcode(TCCState *S, int token) · 1 unmodified line
10841084 /* fallthrough */
10851085 case TOK_ASM_smulleq:
10861086 opcode |= 1 << 22; // signed
1087− asm_emit_opcode(S, token, opcode);
1087+ asm_emit_opcode(token, opcode);
10881088 break;
10891089 case TOK_ASM_umullseq:
10901090 opcode |= 1 << 20; // Status
10911091 /* fallthrough */
10921092 case TOK_ASM_umulleq:
1093− asm_emit_opcode(S, token, opcode);
1093+ asm_emit_opcode(token, opcode);
10941094 break;
10951095 case TOK_ASM_smlalseq:
10961096 opcode |= 1 << 20; // Status
@@ -1098,21 +1098,21 @@ static void asm_long_multiplication_opcode(TCCState *S, int token) · 1 unmodified line
10981098 case TOK_ASM_smlaleq:
10991099 opcode |= 1 << 22; // signed
11001100 opcode |= 1 << 21; // Accumulate
1101− asm_emit_opcode(S, token, opcode);
1101+ asm_emit_opcode(token, opcode);
11021102 break;
11031103 case TOK_ASM_umlalseq:
11041104 opcode |= 1 << 20; // Status
11051105 /* fallthrough */
11061106 case TOK_ASM_umlaleq:
11071107 opcode |= 1 << 21; // Accumulate
1108− asm_emit_opcode(S, token, opcode);
1108+ asm_emit_opcode(token, opcode);
11091109 break;
11101110 default:
1111− expect(S, "known long multiplication instruction");
1111+ expect("known long multiplication instruction");
11121112 }
11131113 }
11141114
1115−static void asm_single_data_transfer_opcode(TCCState *S, int token)
1115+static void asm_single_data_transfer_opcode(TCCState *s1, int token)
11161116 {
11171117 Operand ops[3];
11181118 Operand strex_operand;
@@ -1126,67 +1126,67 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 7 unmodified lines
11261126 // Note: ldr r0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
11271127 // Note: ldr r0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
11281128
1129− parse_operand(S, &ops[0]);
1129+ parse_operand(s1, &ops[0]);
11301130 if (ops[0].type == OP_REG32)
11311131 opcode |= ENCODE_RD(ops[0].reg);
11321132 else {
1133− expect(S, "(destination operand) register");
1133+ expect("(destination operand) register");
11341134 return;
11351135 }
1136− if (S->tccpp_tok != ',')
1137− expect(S, "at least two arguments");
1136+ if (tok != ',')
1137+ expect("at least two arguments");
11381138 else
1139− next(S); // skip ','
1139+ next(); // skip ','
11401140
11411141 switch (ARM_INSTRUCTION_GROUP(token)) {
11421142 case TOK_ASM_strexbeq:
11431143 case TOK_ASM_strexeq:
1144− parse_operand(S, &strex_operand);
1144+ parse_operand(s1, &strex_operand);
11451145 if (strex_operand.type != OP_REG32) {
1146− expect(S, "register");
1146+ expect("register");
11471147 return;
11481148 }
1149− if (S->tccpp_tok != ',')
1150− expect(S, "at least three arguments");
1149+ if (tok != ',')
1150+ expect("at least three arguments");
11511151 else
1152− next(S); // skip ','
1152+ next(); // skip ','
11531153 break;
11541154 }
11551155
1156− if (S->tccpp_tok != '[')
1157− expect(S, "'['");
1156+ if (tok != '[')
1157+ expect("'['");
11581158 else
1159− next(S); // skip '['
1159+ next(); // skip '['
11601160
1161− parse_operand(S, &ops[1]);
1161+ parse_operand(s1, &ops[1]);
11621162 if (ops[1].type == OP_REG32)
11631163 opcode |= ENCODE_RN(ops[1].reg);
11641164 else {
1165− expect(S, "(first source operand) register");
1165+ expect("(first source operand) register");
11661166 return;
11671167 }
1168− if (S->tccpp_tok == ']') {
1169− next(S);
1168+ if (tok == ']') {
1169+ next();
11701170 closed_bracket = 1;
11711171 // exclam = 1; // implicit in hardware; don't do it in software
11721172 }
1173− if (S->tccpp_tok == ',') {
1174− next(S); // skip ','
1175− if (S->tccpp_tok == '-') {
1173+ if (tok == ',') {
1174+ next(); // skip ','
1175+ if (tok == '-') {
11761176 op2_minus = 1;
1177− next(S);
1177+ next();
11781178 }
1179− parse_operand(S, &ops[2]);
1179+ parse_operand(s1, &ops[2]);
11801180 if (ops[2].type == OP_REG32) {
11811181 if (ops[2].reg == 15) {
1182− tcc_error(S, "Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(S, token, NULL));
1182+ tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL));
11831183 return;
11841184 }
1185− if (S->tccpp_tok == ',') {
1186− next(S);
1187− opcode |= asm_parse_optional_shift(S, &nb_shift, &shift);
1185+ if (tok == ',') {
1186+ next();
1187+ opcode |= asm_parse_optional_shift(s1, &nb_shift, &shift);
11881188 if (opcode == 0)
1189− expect(S, "shift directive, or no comma");
1189+ expect("shift directive, or no comma");
11901190 }
11911191 }
11921192 } else {
@@ -1196,14 +1196,14 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 3 unmodified lines
11961196 opcode |= 1 << 24; // add offset before transfer
11971197 }
11981198 if (!closed_bracket) {
1199− if (S->tccpp_tok != ']')
1200− expect(S, "']'");
1199+ if (tok != ']')
1200+ expect("']'");
12011201 else
1202− next(S); // skip ']'
1202+ next(); // skip ']'
12031203 opcode |= 1 << 24; // add offset before transfer
1204− if (S->tccpp_tok == '!') {
1204+ if (tok == '!') {
12051205 exclam = 1;
1206− next(S); // skip '!'
1206+ next(); // skip '!'
12071207 }
12081208 }
12091209
@@ -1224,16 +1224,16 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 14 unmodified lines
12241224 if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) {
12251225 int v = ops[2].e.v;
12261226 if (op2_minus)
1227− tcc_error(S, "minus before '#' not supported for immediate values");
1227+ tcc_error("minus before '#' not supported for immediate values");
12281228 if (v >= 0) {
12291229 opcode |= 1 << 23; // up
12301230 if (v >= 0x1000)
1231− tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
1231+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
12321232 else
12331233 opcode |= v;
12341234 } else { // down
12351235 if (v <= -0x1000)
1236− tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
1236+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
12371237 else
12381238 opcode |= -v;
12391239 }
@@ -1243,7 +1243,7 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 3 unmodified lines
12431243 opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */
12441244 opcode |= ops[2].reg;
12451245 } else
1246− expect(S, "register");
1246+ expect("register");
12471247
12481248 switch (ARM_INSTRUCTION_GROUP(token)) {
12491249 case TOK_ASM_strbeq:
@@ -1252,8 +1252,8 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 2 unmodified lines
12521252 case TOK_ASM_streq:
12531253 opcode |= 1 << 26; // Load/Store
12541254 if (nb_shift)
1255− opcode |= asm_encode_shift(S, &shift);
1256− asm_emit_opcode(S, token, opcode);
1255+ opcode |= asm_encode_shift(&shift);
1256+ asm_emit_opcode(token, opcode);
12571257 break;
12581258 case TOK_ASM_ldrbeq:
12591259 opcode |= 1 << 22; // B
@@ -1262,56 +1262,56 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token) · 2 unmodified lines
12621262 opcode |= 1 << 20; // L
12631263 opcode |= 1 << 26; // Load/Store
12641264 if (nb_shift)
1265− opcode |= asm_encode_shift(S, &shift);
1266− asm_emit_opcode(S, token, opcode);
1265+ opcode |= asm_encode_shift(&shift);
1266+ asm_emit_opcode(token, opcode);
12671267 break;
12681268 case TOK_ASM_strexbeq:
12691269 opcode |= 1 << 22; // B
12701270 /* fallthrough */
12711271 case TOK_ASM_strexeq:
12721272 if ((opcode & 0xFFF) || nb_shift) {
1273− tcc_error(S, "neither offset nor shift allowed with 'strex'");
1273+ tcc_error("neither offset nor shift allowed with 'strex'");
12741274 return;
12751275 } else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate
1276− tcc_error(S, "offset not allowed with 'strex'");
1276+ tcc_error("offset not allowed with 'strex'");
12771277 return;
12781278 }
12791279 if ((opcode & (1 << 24)) == 0) { // add offset after transfer
1280− tcc_error(S, "adding offset after transfer not allowed with 'strex'");
1280+ tcc_error("adding offset after transfer not allowed with 'strex'");
12811281 return;
12821282 }
12831283
12841284 opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL
12851285 opcode |= strex_operand.reg;
1286− asm_emit_opcode(S, token, opcode);
1286+ asm_emit_opcode(token, opcode);
12871287 break;
12881288 case TOK_ASM_ldrexbeq:
12891289 opcode |= 1 << 22; // B
12901290 /* fallthrough */
12911291 case TOK_ASM_ldrexeq:
12921292 if ((opcode & 0xFFF) || nb_shift) {
1293− tcc_error(S, "neither offset nor shift allowed with 'ldrex'");
1293+ tcc_error("neither offset nor shift allowed with 'ldrex'");
12941294 return;
12951295 } else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate
1296− tcc_error(S, "offset not allowed with 'ldrex'");
1296+ tcc_error("offset not allowed with 'ldrex'");
12971297 return;
12981298 }
12991299 if ((opcode & (1 << 24)) == 0) { // add offset after transfer
1300− tcc_error(S, "adding offset after transfer not allowed with 'ldrex'");
1300+ tcc_error("adding offset after transfer not allowed with 'ldrex'");
13011301 return;
13021302 }
13031303 opcode |= 1 << 20; // L
13041304 opcode |= 0x00f;
13051305 opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL
1306− asm_emit_opcode(S, token, opcode);
1306+ asm_emit_opcode(token, opcode);
13071307 break;
13081308 default:
1309− expect(S, "data transfer instruction");
1309+ expect("data transfer instruction");
13101310 }
13111311 }
13121312
13131313 // Note: Only call this using a VFP register if you know exactly what you are doing (i.e. cp_number is 10 or 11 and you are doing a vmov)
1314−static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble, uint8_t cp_number, uint8_t CRd, const Operand* Rn, const Operand* offset, int offset_minus, int preincrement, int writeback, int long_transfer, int load) {
1314+static void asm_emit_coprocessor_data_transfer(uint32_t high_nibble, uint8_t cp_number, uint8_t CRd, const Operand* Rn, const Operand* offset, int offset_minus, int preincrement, int writeback, int long_transfer, int load) {
13151315 uint32_t opcode = 0x0;
13161316 opcode |= 1 << 26; // Load/Store
13171317 opcode |= 1 << 27; // coprocessor
@@ -1328,7 +1328,7 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble · 10 unmodified lines
13281328 opcode |= ENCODE_RD(CRd);
13291329
13301330 if (Rn->type != OP_REG32) {
1331− expect(S, "register");
1331+ expect("register");
13321332 return;
13331333 }
13341334 //assert(Rn->reg < 16);
@@ -1342,18 +1342,18 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble · 7 unmodified lines
13421342 if (offset->type == OP_IM8 || offset->type == OP_IM8N || offset->type == OP_IM32) {
13431343 int v = offset->e.v;
13441344 if (offset_minus)
1345− tcc_error(S, "minus before '#' not supported for immediate values");
1345+ tcc_error("minus before '#' not supported for immediate values");
13461346 if (offset->type == OP_IM8N || v < 0)
13471347 v = -v;
13481348 else
13491349 opcode |= 1 << 23; // up
13501350 if (v & 3) {
1351− tcc_error(S, "immediate offset must be a multiple of 4");
1351+ tcc_error("immediate offset must be a multiple of 4");
13521352 return;
13531353 }
13541354 v >>= 2;
13551355 if (v > 255) {
1356− tcc_error(S, "immediate offset must be between -1020 and 1020");
1356+ tcc_error("immediate offset must be between -1020 and 1020");
13571357 return;
13581358 }
13591359 opcode |= v;
@@ -1362,20 +1362,20 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble · 2 unmodified lines
13621362 opcode |= 1 << 23; // up
13631363 opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */
13641364 opcode |= offset->reg;
1365− tcc_error(S, "Using register offset to register address is not possible here");
1365+ tcc_error("Using register offset to register address is not possible here");
13661366 return;
13671367 } else if (offset->type == OP_VREG64) {
13681368 opcode |= 16;
13691369 opcode |= offset->reg;
13701370 } else
1371− expect(S, "immediate or register");
1371+ expect("immediate or register");
13721372
1373− asm_emit_unconditional_opcode(S, (high_nibble << 28) | opcode);
1373+ asm_emit_unconditional_opcode((high_nibble << 28) | opcode);
13741374 }
13751375
13761376 // Almost exactly the same as asm_single_data_transfer_opcode.
13771377 // Difference: Offsets are smaller and multiples of 4; no shifts, no STREX, ENCODE_IMMEDIATE_FLAG is inverted again.
1378−static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
1378+static void asm_coprocessor_data_transfer_opcode(TCCState *s1, int token)
13791379 {
13801380 Operand ops[3];
13811381 uint8_t coprocessor;
@@ -1389,61 +1389,61 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token) · 7 unmodified lines
13891389 // Note: ldc p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
13901390 // Note: ldc p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
13911391
1392− if (S->tccpp_tok >= TOK_ASM_p0 && S->tccpp_tok <= TOK_ASM_p15) {
1393− coprocessor = S->tccpp_tok - TOK_ASM_p0;
1394− next(S);
1392+ if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) {
1393+ coprocessor = tok - TOK_ASM_p0;
1394+ next();
13951395 } else {
1396− expect(S, "'c<number>'");
1396+ expect("'c<number>'");
13971397 return;
13981398 }
13991399
1400− if (S->tccpp_tok == ',')
1401− next(S);
1400+ if (tok == ',')
1401+ next();
14021402 else
1403− expect(S, "','");
1403+ expect("','");
14041404
1405− if (S->tccpp_tok >= TOK_ASM_c0 && S->tccpp_tok <= TOK_ASM_c15) {
1406− coprocessor_destination_register = S->tccpp_tok - TOK_ASM_c0;
1407− next(S);
1405+ if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) {
1406+ coprocessor_destination_register = tok - TOK_ASM_c0;
1407+ next();
14081408 } else {
1409− expect(S, "'c<number>'");
1409+ expect("'c<number>'");
14101410 return;
14111411 }
14121412
1413− if (S->tccpp_tok == ',')
1414− next(S);
1413+ if (tok == ',')
1414+ next();
14151415 else
1416− expect(S, "','");
1416+ expect("','");
14171417
1418− if (S->tccpp_tok != '[')
1419− expect(S, "'['");
1418+ if (tok != '[')
1419+ expect("'['");
14201420 else
1421− next(S); // skip '['
1421+ next(); // skip '['
14221422
1423− parse_operand(S, &ops[1]);
1423+ parse_operand(s1, &ops[1]);
14241424 if (ops[1].type != OP_REG32) {
1425− expect(S, "(first source operand) register");
1425+ expect("(first source operand) register");
14261426 return;
14271427 }
1428− if (S->tccpp_tok == ']') {
1429− next(S);
1428+ if (tok == ']') {
1429+ next();
14301430 closed_bracket = 1;
14311431 // exclam = 1; // implicit in hardware; don't do it in software
14321432 }
1433− if (S->tccpp_tok == ',') {
1434− next(S); // skip ','
1435− if (S->tccpp_tok == '-') {
1433+ if (tok == ',') {
1434+ next(); // skip ','
1435+ if (tok == '-') {
14361436 op2_minus = 1;
1437− next(S);
1437+ next();
14381438 }
1439− parse_operand(S, &ops[2]);
1439+ parse_operand(s1, &ops[2]);
14401440 if (ops[2].type == OP_REG32) {
14411441 if (ops[2].reg == 15) {
1442− tcc_error(S, "Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(S, token, NULL));
1442+ tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL));
14431443 return;
14441444 }
14451445 } else if (ops[2].type == OP_VREG64) {
1446− tcc_error(S, "'%s' does not support VFP register operand", get_tok_str(S, token, NULL));
1446+ tcc_error("'%s' does not support VFP register operand", get_tok_str(token, NULL));
14471447 return;
14481448 }
14491449 } else {
@@ -1453,14 +1453,14 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token) · 3 unmodified lines
14531453 preincrement = 1; // add offset before transfer
14541454 }
14551455 if (!closed_bracket) {
1456− if (S->tccpp_tok != ']')
1457− expect(S, "']'");
1456+ if (tok != ']')
1457+ expect("']'");
14581458 else
1459− next(S); // skip ']'
1459+ next(); // skip ']'
14601460 preincrement = 1; // add offset before transfer
1461− if (S->tccpp_tok == '!') {
1461+ if (tok == '!') {
14621462 exclam = 1;
1463− next(S); // skip '!'
1463+ next(); // skip '!'
14641464 }
14651465 }
14661466
@@ -1472,13 +1472,13 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token) · 5 unmodified lines
14721472 long_transfer = 1; // long transfer
14731473 /* fallthrough */
14741474 case TOK_ASM_ldc2:
1475− asm_emit_coprocessor_data_transfer(S, 0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
1475+ asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
14761476 break;
14771477 case TOK_ASM_stc2l:
14781478 long_transfer = 1; // long transfer
14791479 /* fallthrough */
14801480 case TOK_ASM_stc2:
1481− asm_emit_coprocessor_data_transfer(S, 0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
1481+ asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
14821482 break;
14831483 }
14841484 } else switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1486,16 +1486,16 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token) · 1 unmodified line
14861486 long_transfer = 1;
14871487 /* fallthrough */
14881488 case TOK_ASM_stceq:
1489− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
1489+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
14901490 break;
14911491 case TOK_ASM_ldcleq:
14921492 long_transfer = 1;
14931493 /* fallthrough */
14941494 case TOK_ASM_ldceq:
1495− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
1495+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
14961496 break;
14971497 default:
1498− expect(S, "coprocessor data transfer instruction");
1498+ expect("coprocessor data transfer instruction");
14991499 }
15001500 }
15011501
@@ -1503,7 +1503,7 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token) · 1 unmodified line
15031503 #define CP_SINGLE_PRECISION_FLOAT 10
15041504 #define CP_DOUBLE_PRECISION_FLOAT 11
15051505
1506−static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int token)
1506+static void asm_floating_point_single_data_transfer_opcode(TCCState *s1, int token)
15071507 {
15081508 Operand ops[3];
15091509 uint8_t coprocessor = 0;
@@ -1513,7 +1513,7 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke · 3 unmodified lines
15131513 // Note: Not allowed: vldr p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
15141514 // Note: Not allowed: vldr p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
15151515
1516− parse_operand(S, &ops[0]);
1516+ parse_operand(s1, &ops[0]);
15171517 if (ops[0].type == OP_VREG32) {
15181518 coprocessor = CP_SINGLE_PRECISION_FLOAT;
15191519 coprocessor_destination_register = ops[0].reg;
@@ -1522,32 +1522,32 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke · 2 unmodified lines
15221522 } else if (ops[0].type == OP_VREG64) {
15231523 coprocessor = CP_DOUBLE_PRECISION_FLOAT;
15241524 coprocessor_destination_register = ops[0].reg;
1525− next(S);
1525+ next();
15261526 } else {
1527− expect(S, "floating point register");
1527+ expect("floating point register");
15281528 return;
15291529 }
15301530
1531− if (S->tccpp_tok == ',')
1532− next(S);
1531+ if (tok == ',')
1532+ next();
15331533 else
1534− expect(S, "','");
1534+ expect("','");
15351535
1536− if (S->tccpp_tok != '[')
1537− expect(S, "'['");
1536+ if (tok != '[')
1537+ expect("'['");
15381538 else
1539− next(S); // skip '['
1539+ next(); // skip '['
15401540
1541− parse_operand(S, &ops[1]);
1541+ parse_operand(s1, &ops[1]);
15421542 if (ops[1].type != OP_REG32) {
1543− expect(S, "(first source operand) register");
1543+ expect("(first source operand) register");
15441544 return;
15451545 }
1546− if (S->tccpp_tok == ',') {
1547− next(S); // skip ','
1548− parse_operand(S, &ops[2]);
1546+ if (tok == ',') {
1547+ next(); // skip ','
1548+ parse_operand(s1, &ops[2]);
15491549 if (ops[2].type != OP_IM8 && ops[2].type != OP_IM8N) {
1550− expect(S, "immediate offset");
1550+ expect("immediate offset");
15511551 return;
15521552 }
15531553 } else {
@@ -1555,24 +1555,24 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke · 1 unmodified line
15551555 ops[2].type = OP_IM8;
15561556 ops[2].e.v = 0;
15571557 }
1558− if (S->tccpp_tok != ']')
1559− expect(S, "']'");
1558+ if (tok != ']')
1559+ expect("']'");
15601560 else
1561− next(S); // skip ']'
1561+ next(); // skip ']'
15621562
15631563 switch (ARM_INSTRUCTION_GROUP(token)) {
15641564 case TOK_ASM_vldreq:
1565− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 1);
1565+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 1);
15661566 break;
15671567 case TOK_ASM_vstreq:
1568− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 0);
1568+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 0);
15691569 break;
15701570 default:
1571− expect(S, "floating point data transfer instruction");
1571+ expect("floating point data transfer instruction");
15721572 }
15731573 }
15741574
1575−static void asm_floating_point_block_data_transfer_opcode(TCCState *S, int token)
1575+static void asm_floating_point_block_data_transfer_opcode(TCCState *s1, int token)
15761576 {
15771577 uint8_t coprocessor = 0;
15781578 int first_regset_register;
@@ -1592,56 +1592,56 @@ static void asm_floating_point_block_data_transfer_opcode(TCCState *S, int token · 13 unmodified lines
15921592 op0_exclam = 1;
15931593 break;
15941594 default:
1595− parse_operand(S, &ops[0]);
1596− if (S->tccpp_tok == '!') {
1595+ parse_operand(s1, &ops[0]);
1596+ if (tok == '!') {
15971597 op0_exclam = 1;
1598− next(S); // skip '!'
1598+ next(); // skip '!'
15991599 }
1600− if (S->tccpp_tok == ',')
1601− next(S); // skip comma
1600+ if (tok == ',')
1601+ next(); // skip comma
16021602 else {
1603− expect(S, "','");
1603+ expect("','");
16041604 return;
16051605 }
16061606 }
16071607
1608− if (S->tccpp_tok != '{') {
1609− expect(S, "'{'");
1608+ if (tok != '{') {
1609+ expect("'{'");
16101610 return;
16111611 }
1612− next(S); // skip '{'
1613− first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 1);
1614− if ((first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 1)) != -1) {
1612+ next(); // skip '{'
1613+ first_regset_register = asm_parse_vfp_regvar(tok, 1);
1614+ if ((first_regset_register = asm_parse_vfp_regvar(tok, 1)) != -1) {
16151615 coprocessor = CP_DOUBLE_PRECISION_FLOAT;
1616− next(S);
1617− } else if ((first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 0)) != -1) {
1616+ next();
1617+ } else if ((first_regset_register = asm_parse_vfp_regvar(tok, 0)) != -1) {
16181618 coprocessor = CP_SINGLE_PRECISION_FLOAT;
1619− next(S);
1619+ next();
16201620 } else {
1621− expect(S, "floating-point register");
1621+ expect("floating-point register");
16221622 return;
16231623 }
16241624
1625− if (S->tccpp_tok == '-') {
1626− next(S);
1627− if ((last_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, coprocessor == CP_DOUBLE_PRECISION_FLOAT)) != -1)
1628− next(S);
1625+ if (tok == '-') {
1626+ next();
1627+ if ((last_regset_register = asm_parse_vfp_regvar(tok, coprocessor == CP_DOUBLE_PRECISION_FLOAT)) != -1)
1628+ next();
16291629 else {
1630− expect(S, "floating-point register");
1630+ expect("floating-point register");
16311631 return;
16321632 }
16331633 } else
16341634 last_regset_register = first_regset_register;
16351635
16361636 if (last_regset_register < first_regset_register) {
1637− tcc_error(S, "registers will be processed in ascending order by hardware--but are not specified in ascending order here");
1637+ tcc_error("registers will be processed in ascending order by hardware--but are not specified in ascending order here");
16381638 return;
16391639 }
1640− if (S->tccpp_tok != '}') {
1641− expect(S, "'}'");
1640+ if (tok != '}') {
1641+ expect("'}'");
16421642 return;
16431643 }
1644− next(S); // skip '}'
1644+ next(); // skip '}'
16451645
16461646 // Note: 0 (one down) is not implemented by us regardless.
16471647 regset_item_count = last_regset_register - first_regset_register + 1;
@@ -1672,23 +1672,23 @@ static void asm_floating_point_block_data_transfer_opcode(TCCState *S, int token · 24 unmodified lines
16721672 preincrement = 1;
16731673 break;
16741674 default:
1675− expect(S, "floating point block data transfer instruction");
1675+ expect("floating point block data transfer instruction");
16761676 return;
16771677 }
16781678 if (ops[0].type != OP_REG32)
1679− expect(S, "(first operand) register");
1679+ expect("(first operand) register");
16801680 else if (ops[0].reg == 15)
1681− tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
1681+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
16821682 else if (!op0_exclam && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vldmeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vldmiaeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vstmeq && ARM_INSTRUCTION_GROUP(token) != TOK_ASM_vstmiaeq)
1683− tcc_error(S, "first operand of '%s' should have an exclamation mark", get_tok_str(S, token, NULL));
1683+ tcc_error("first operand of '%s' should have an exclamation mark", get_tok_str(token, NULL));
16841684 else
1685− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, first_regset_register, &ops[0], &offset, 0, preincrement, op0_exclam, extra_register_bit, load);
1685+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, first_regset_register, &ops[0], &offset, 0, preincrement, op0_exclam, extra_register_bit, load);
16861686 }
16871687
16881688 #define VMOV_FRACTIONAL_DIGITS 7
16891689 #define VMOV_ONE 10000000 /* pow(10, VMOV_FRACTIONAL_DIGITS) */
16901690
1691−static uint32_t vmov_parse_fractional_part(TCCState* S, const char* s)
1691+static uint32_t vmov_parse_fractional_part(const char* s)
16921692 {
16931693 uint32_t result = 0;
16941694 int i;
@@ -1701,7 +1701,7 @@ static uint32_t vmov_parse_fractional_part(TCCState* S, const char* s) · 6 unmodified lines
17011701 }
17021702 }
17031703 if (*s)
1704− expect(S, "decimal numeral");
1704+ expect("decimal numeral");
17051705 return result;
17061706 }
17071707
@@ -1720,34 +1720,34 @@ static int vmov_linear_approx_index(uint32_t beginning, uint32_t end, uint32_t v · 12 unmodified lines
17201720 return -1;
17211721 }
17221722
1723−static uint32_t vmov_parse_immediate_value(TCCState* S) {
1723+static uint32_t vmov_parse_immediate_value() {
17241724 uint32_t value;
17251725 unsigned long integral_value;
17261726 const char *p;
17271727
1728− if (S->tccpp_tok != TOK_PPNUM) {
1729− expect(S, "immediate value");
1728+ if (tok != TOK_PPNUM) {
1729+ expect("immediate value");
17301730 return 0;
17311731 }
1732− p = S->tccpp_tokc.str.data;
1732+ p = tokc.str.data;
17331733 errno = 0;
17341734 integral_value = strtoul(p, (char **)&p, 0);
17351735
17361736 if (errno || integral_value >= 32) {
1737− tcc_error(S, "invalid floating-point immediate value");
1737+ tcc_error("invalid floating-point immediate value");
17381738 return 0;
17391739 }
17401740
17411741 value = (uint32_t) integral_value * VMOV_ONE;
17421742 if (*p == '.') {
17431743 ++p;
1744− value += vmov_parse_fractional_part(S, p);
1744+ value += vmov_parse_fractional_part(p);
17451745 }
1746− next(S);
1746+ next();
17471747 return value;
17481748 }
17491749
1750−static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value)
1750+static uint8_t vmov_encode_immediate_value(uint32_t value)
17511751 {
17521752 uint32_t limit;
17531753 uint32_t end = 0;
@@ -1767,7 +1767,7 @@ static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value) · 13 unmodified lines
17671767 limit >>= 1;
17681768 }
17691769 if (r == -1 || value < beginning || value > end) {
1770− tcc_error(S, "invalid decimal number for vmov: %d", value);
1770+ tcc_error("invalid decimal number for vmov: %d", value);
17711771 return 0;
17721772 }
17731773 n = vmov_linear_approx_index(beginning, end, value);
@@ -1775,7 +1775,7 @@ static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value) · 1 unmodified line
17751775 }
17761776
17771777 // Not standalone.
1778−static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S, int token, uint8_t coprocessor, uint8_t CRd) {
1778+static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *s1, int token, uint8_t coprocessor, uint8_t CRd) {
17791779 uint8_t opcode1 = 0;
17801780 uint8_t opcode2 = 0;
17811781 uint8_t operands[3] = {0, 0, 0};
@@ -1785,14 +1785,14 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S · 3 unmodified lines
17851785
17861786 operands[0] = CRd;
17871787
1788− if (S->tccpp_tok == '#' || S->tccpp_tok == '$') {
1789− next(S);
1788+ if (tok == '#' || tok == '$') {
1789+ next();
17901790 }
1791− if (S->tccpp_tok == '-') {
1791+ if (tok == '-') {
17921792 op_minus = 1;
1793− next(S);
1793+ next();
17941794 }
1795− immediate_value = vmov_parse_immediate_value(S);
1795+ immediate_value = vmov_parse_immediate_value();
17961796
17971797 opcode1 = 11; // "Other" instruction
17981798 switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1801,7 +1801,7 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S · 2 unmodified lines
18011801 opcode2 = 2;
18021802 operands[1] = 5;
18031803 if (immediate_value) {
1804− expect(S, "Immediate value 0");
1804+ expect("Immediate value 0");
18051805 return;
18061806 }
18071807 break;
@@ -1810,7 +1810,7 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S · 2 unmodified lines
18101810 opcode2 = 6;
18111811 operands[1] = 5;
18121812 if (immediate_value) {
1813− expect(S, "Immediate value 0");
1813+ expect("Immediate value 0");
18141814 return;
18151815 }
18161816 break;
@@ -1821,12 +1821,12 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S · 4 unmodified lines
18211821 operands[1] = 0x8;
18221822 else
18231823 operands[1] = 0x0;
1824− code = vmov_encode_immediate_value(S, immediate_value);
1824+ code = vmov_encode_immediate_value(immediate_value);
18251825 operands[1] |= code >> 4;
18261826 operands[2] = code & 0xF;
18271827 break;
18281828 default:
1829− expect(S, "known floating point with immediate instruction");
1829+ expect("known floating point with immediate instruction");
18301830 return;
18311831 }
18321832
@@ -1836,17 +1836,17 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S · 3 unmodified lines
18361836 operands[0] >>= 1;
18371837 }
18381838
1839− asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode1, operands[0], operands[1], operands[2], opcode2, 0);
1839+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, operands[0], operands[1], operands[2], opcode2, 0);
18401840 }
18411841
1842−static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *S, int token, int coprocessor, int nb_arm_regs, int nb_ops, Operand ops[3]) {
1842+static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *s1, int token, int coprocessor, int nb_arm_regs, int nb_ops, Operand ops[3]) {
18431843 uint8_t opcode1 = 0;
18441844 uint8_t opcode2 = 0;
18451845 switch (coprocessor) {
18461846 case CP_SINGLE_PRECISION_FLOAT:
18471847 // "vmov.f32 r2, s3" or "vmov.f32 s3, r2"
18481848 if (nb_ops != 2 || nb_arm_regs != 1) {
1849− tcc_error(S, "vmov.f32 only implemented for one VFP register operand and one ARM register operands");
1849+ tcc_error("vmov.f32 only implemented for one VFP register operand and one ARM register operands");
18501850 return;
18511851 }
18521852 if (ops[0].type != OP_REG32) { // determine mode: load or store
@@ -1869,11 +1869,11 @@ static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *S, int · 16 unmodified lines
18691869 ops[0].reg >>= 1;
18701870 }
18711871
1872− asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, 0x10, opcode2, 0);
1872+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, 0x10, opcode2, 0);
18731873 break;
18741874 case CP_DOUBLE_PRECISION_FLOAT:
18751875 if (nb_ops != 3 || nb_arm_regs != 2) {
1876− tcc_error(S, "vmov.f32 only implemented for one VFP register operand and two ARM register operands");
1876+ tcc_error("vmov.f32 only implemented for one VFP register operand and two ARM register operands");
18771877 return;
18781878 }
18791879 // Determine whether it's a store into a VFP register (vmov "d1, r2, r3") rather than "vmov r2, r3, d1"
@@ -1886,23 +1886,23 @@ static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *S, int · 6 unmodified lines
18861886 memcpy(&ops[1], &ops[2], sizeof(ops[1]));
18871887 memcpy(&ops[2], &temp, sizeof(ops[2]));
18881888 } else {
1889− tcc_error(S, "vmov.f64 only implemented for one VFP register operand and two ARM register operands");
1889+ tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands");
18901890 return;
18911891 }
18921892 } else if (ops[0].type != OP_REG32 || ops[1].type != OP_REG32 || ops[2].type != OP_VREG64) {
1893− tcc_error(S, "vmov.f64 only implemented for one VFP register operand and two ARM register operands");
1893+ tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands");
18941894 return;
18951895 } else {
18961896 opcode1 |= 1;
18971897 }
1898− asm_emit_coprocessor_data_transfer(S, condition_code_of_token(S, token), coprocessor, ops[0].reg, &ops[1], &ops[2], 0, 0, 0, 1, opcode1);
1898+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, ops[0].reg, &ops[1], &ops[2], 0, 0, 0, 1, opcode1);
18991899 break;
19001900 default:
1901− tcc_internal_error(S, "unknown coprocessor");
1901+ tcc_internal_error("unknown coprocessor");
19021902 }
19031903 }
19041904
1905−static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int token) {
1905+static void asm_floating_point_vcvt_data_processing_opcode(TCCState *s1, int token) {
19061906 uint8_t coprocessor = 0;
19071907 Operand ops[3];
19081908 uint8_t opcode1 = 11;
@@ -1928,11 +1928,11 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke · 19 unmodified lines
19281928 coprocessor = CP_SINGLE_PRECISION_FLOAT;
19291929 break;
19301930 default:
1931− tcc_error(S, "Unknown coprocessor for instruction '%s'", get_tok_str(S, token, NULL));
1931+ tcc_error("Unknown coprocessor for instruction '%s'", get_tok_str(token, NULL));
19321932 return;
19331933 }
19341934
1935− parse_operand(S, &ops[0]);
1935+ parse_operand(s1, &ops[0]);
19361936 ops[1].type = OP_IM8;
19371937 ops[1].e.v = 8;
19381938 /* floating-point -> integer */
@@ -1956,11 +1956,11 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke · 17 unmodified lines
19561956 break;
19571957 }
19581958
1959− if (S->tccpp_tok == ',')
1960− next(S);
1959+ if (tok == ',')
1960+ next();
19611961 else
1962− expect(S, "','");
1963− parse_operand(S, &ops[2]);
1962+ expect("','");
1963+ parse_operand(s1, &ops[2]);
19641964
19651965 switch (ARM_INSTRUCTION_GROUP(token)) {
19661966 /* floating-point -> integer */
@@ -1990,7 +1990,7 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke · 23 unmodified lines
19901990 case TOK_ASM_vcvteq_f64_f32:
19911991 if (ops[0].type == OP_VREG64 && ops[2].type == OP_VREG32) {
19921992 } else {
1993− expect(S, "d<number>, s<number>");
1993+ expect("d<number>, s<number>");
19941994 return;
19951995 }
19961996 break;
@@ -1998,13 +1998,13 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke · 1 unmodified line
19981998 if (coprocessor == CP_SINGLE_PRECISION_FLOAT) {
19991999 if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG32) {
20002000 } else {
2001− expect(S, "s<number>, s<number>");
2001+ expect("s<number>, s<number>");
20022002 return;
20032003 }
20042004 } else if (coprocessor == CP_DOUBLE_PRECISION_FLOAT) {
20052005 if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG64) {
20062006 } else {
2007− expect(S, "s<number>, d<number>");
2007+ expect("s<number>, d<number>");
20082008 return;
20092009 }
20102010 }
@@ -2020,10 +2020,10 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke · 9 unmodified lines
20202020 opcode1 |= 4;
20212021 ops[0].reg >>= 1;
20222022 }
2023− asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
2023+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
20242024 }
20252025
2026−static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
2026+static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {
20272027 uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
20282028 uint8_t opcode1 = 0;
20292029 uint8_t opcode2 = 0; // (0 || 2) | register selection
@@ -2078,30 +2078,30 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) { · 48 unmodified lines
20782078
20792079 for (nb_ops = 0; nb_ops < 3; ) {
20802080 // Note: Necessary because parse_operand can't parse decimal numerals.
2081− if (nb_ops == 1 && (S->tccpp_tok == '#' || S->tccpp_tok == '$' || S->tccpp_tok == TOK_PPNUM || S->tccpp_tok == '-')) {
2082− asm_floating_point_immediate_data_processing_opcode_tail(S, token, coprocessor, ops[0].reg);
2081+ if (nb_ops == 1 && (tok == '#' || tok == '$' || tok == TOK_PPNUM || tok == '-')) {
2082+ asm_floating_point_immediate_data_processing_opcode_tail(s1, token, coprocessor, ops[0].reg);
20832083 return;
20842084 }
2085− parse_operand(S, &ops[nb_ops]);
2085+ parse_operand(s1, &ops[nb_ops]);
20862086 if (vmov && ops[nb_ops].type == OP_REG32) {
20872087 ++nb_arm_regs;
20882088 } else if (ops[nb_ops].type == OP_VREG32) {
20892089 if (coprocessor != CP_SINGLE_PRECISION_FLOAT) {
2090− expect(S, "'s<number>'");
2090+ expect("'s<number>'");
20912091 return;
20922092 }
20932093 } else if (ops[nb_ops].type == OP_VREG64) {
20942094 if (coprocessor != CP_DOUBLE_PRECISION_FLOAT) {
2095− expect(S, "'d<number>'");
2095+ expect("'d<number>'");
20962096 return;
20972097 }
20982098 } else {
2099− expect(S, "floating point register");
2099+ expect("floating point register");
21002100 return;
21012101 }
21022102 ++nb_ops;
2103− if (S->tccpp_tok == ',')
2104− next(S);
2103+ if (tok == ',')
2104+ next();
21052105 else
21062106 break;
21072107 }
@@ -2113,7 +2113,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) { · 5 unmodified lines
21132113 nb_ops = 3;
21142114 }
21152115 if (nb_ops < 3) {
2116− tcc_error(S, "Not enough operands for '%s' (%u)", get_tok_str(S, token, NULL), nb_ops);
2116+ tcc_error("Not enough operands for '%s' (%u)", get_tok_str(token, NULL), nb_ops);
21172117 return;
21182118 }
21192119 }
@@ -2202,7 +2202,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) { · 82 unmodified lines
22022202 case TOK_ASM_vmoveq_f32:
22032203 case TOK_ASM_vmoveq_f64:
22042204 if (nb_arm_regs > 0) { // vmov.f32 r2, s3 or similar
2205− asm_floating_point_reg_arm_reg_transfer_opcode_tail(S, token, coprocessor, nb_arm_regs, nb_ops, ops);
2205+ asm_floating_point_reg_arm_reg_transfer_opcode_tail(s1, token, coprocessor, nb_arm_regs, nb_ops, ops);
22062206 return;
22072207 } else {
22082208 opcode1 = 11; // "Other" instruction
@@ -2212,7 +2212,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) { · 3 unmodified lines
22122212 }
22132213 break;
22142214 default:
2215− expect(S, "known floating point instruction");
2215+ expect("known floating point instruction");
22162216 return;
22172217 }
22182218
@@ -2236,10 +2236,10 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) { · 17 unmodified lines
22362236 }
22372237 }
22382238
2239− asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
2239+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
22402240 }
22412241
2242−static void asm_floating_point_status_register_opcode(TCCState* S, int token)
2242+static void asm_floating_point_status_register_opcode(TCCState* s1, int token)
22432243 {
22442244 uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
22452245 uint8_t opcode;
@@ -2248,61 +2248,61 @@ static void asm_floating_point_status_register_opcode(TCCState* S, int token) · 2 unmodified lines
22482248 switch (ARM_INSTRUCTION_GROUP(token)) {
22492249 case TOK_ASM_vmrseq:
22502250 opcode = 0xf;
2251− if (S->tccpp_tok == TOK_ASM_apsr_nzcv) {
2251+ if (tok == TOK_ASM_apsr_nzcv) {
22522252 arm_operand.type = OP_REG32;
22532253 arm_operand.reg = 15; // not PC
2254− next(S); // skip apsr_nzcv
2254+ next(); // skip apsr_nzcv
22552255 } else {
2256− parse_operand(S, &arm_operand);
2256+ parse_operand(s1, &arm_operand);
22572257 if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) {
2258− tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
2258+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
22592259 return;
22602260 }
22612261 }
22622262
2263− if (S->tccpp_tok != ',')
2264− expect(S, "','");
2263+ if (tok != ',')
2264+ expect("','");
22652265 else
2266− next(S); // skip ','
2267− vfp_sys_reg = asm_parse_vfp_status_regvar(S->tccpp_tok);
2268− next(S); // skip vfp sys reg
2266+ next(); // skip ','
2267+ vfp_sys_reg = asm_parse_vfp_status_regvar(tok);
2268+ next(); // skip vfp sys reg
22692269 if (arm_operand.type == OP_REG32 && arm_operand.reg == 15 && vfp_sys_reg != 1) {
2270− tcc_error(S, "'%s' only supports the variant 'vmrs apsr_nzcv, fpscr' here", get_tok_str(S, token, NULL));
2270+ tcc_error("'%s' only supports the variant 'vmrs apsr_nzcv, fpscr' here", get_tok_str(token, NULL));
22712271 return;
22722272 }
22732273 break;
22742274 case TOK_ASM_vmsreq:
22752275 opcode = 0xe;
2276− vfp_sys_reg = asm_parse_vfp_status_regvar(S->tccpp_tok);
2277− next(S); // skip vfp sys reg
2278− if (S->tccpp_tok != ',')
2279− expect(S, "','");
2276+ vfp_sys_reg = asm_parse_vfp_status_regvar(tok);
2277+ next(); // skip vfp sys reg
2278+ if (tok != ',')
2279+ expect("','");
22802280 else
2281− next(S); // skip ','
2282− parse_operand(S, &arm_operand);
2281+ next(); // skip ','
2282+ parse_operand(s1, &arm_operand);
22832283 if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) {
2284− tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
2284+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
22852285 return;
22862286 }
22872287 break;
22882288 default:
2289− expect(S, "floating point status register instruction");
2289+ expect("floating point status register instruction");
22902290 return;
22912291 }
22922292 if (vfp_sys_reg == -1) {
2293− expect(S, "VFP system register");
2293+ expect("VFP system register");
22942294 return;
22952295 }
22962296 if (arm_operand.type != OP_REG32) {
2297− expect(S, "ARM register");
2297+ expect("ARM register");
22982298 return;
22992299 }
2300− asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode, arm_operand.reg, vfp_sys_reg, 0x10, 0, 0);
2300+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode, arm_operand.reg, vfp_sys_reg, 0x10, 0, 0);
23012301 }
23022302
23032303 #endif
23042304
2305−static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
2305+static void asm_misc_single_data_transfer_opcode(TCCState *s1, int token)
23062306 {
23072307 Operand ops[3];
23082308 int exclam = 0;
@@ -2322,42 +2322,42 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 13 unmodified lines
23222322 // Here: 0 0 0 P U I W L << 20
23232323 // [compare single data transfer: 0 1 I P U B W L << 20]
23242324
2325− parse_operand(S, &ops[0]);
2325+ parse_operand(s1, &ops[0]);
23262326 if (ops[0].type == OP_REG32)
23272327 opcode |= ENCODE_RD(ops[0].reg);
23282328 else {
2329− expect(S, "(destination operand) register");
2329+ expect("(destination operand) register");
23302330 return;
23312331 }
2332− if (S->tccpp_tok != ',')
2333− expect(S, "at least two arguments");
2332+ if (tok != ',')
2333+ expect("at least two arguments");
23342334 else
2335− next(S); // skip ','
2335+ next(); // skip ','
23362336
2337− if (S->tccpp_tok != '[')
2338− expect(S, "'['");
2337+ if (tok != '[')
2338+ expect("'['");
23392339 else
2340− next(S); // skip '['
2340+ next(); // skip '['
23412341
2342− parse_operand(S, &ops[1]);
2342+ parse_operand(s1, &ops[1]);
23432343 if (ops[1].type == OP_REG32)
23442344 opcode |= ENCODE_RN(ops[1].reg);
23452345 else {
2346− expect(S, "(first source operand) register");
2346+ expect("(first source operand) register");
23472347 return;
23482348 }
2349− if (S->tccpp_tok == ']') {
2350− next(S);
2349+ if (tok == ']') {
2350+ next();
23512351 closed_bracket = 1;
23522352 // exclam = 1; // implicit in hardware; don't do it in software
23532353 }
2354− if (S->tccpp_tok == ',') {
2355− next(S); // skip ','
2356− if (S->tccpp_tok == '-') {
2354+ if (tok == ',') {
2355+ next(); // skip ','
2356+ if (tok == '-') {
23572357 op2_minus = 1;
2358− next(S);
2358+ next();
23592359 }
2360− parse_operand(S, &ops[2]);
2360+ parse_operand(s1, &ops[2]);
23612361 } else {
23622362 // end of input expression in brackets--assume 0 offset
23632363 ops[2].type = OP_IM8;
@@ -2365,20 +2365,20 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 1 unmodified line
23652365 opcode |= 1 << 24; // add offset before transfer
23662366 }
23672367 if (!closed_bracket) {
2368− if (S->tccpp_tok != ']')
2369− expect(S, "']'");
2368+ if (tok != ']')
2369+ expect("']'");
23702370 else
2371− next(S); // skip ']'
2371+ next(); // skip ']'
23722372 opcode |= 1 << 24; // add offset before transfer
2373− if (S->tccpp_tok == '!') {
2373+ if (tok == '!') {
23742374 exclam = 1;
2375− next(S); // skip '!'
2375+ next(); // skip '!'
23762376 }
23772377 }
23782378
23792379 if (exclam) {
23802380 if ((opcode & (1 << 24)) == 0) {
2381− tcc_error(S, "result of '%s' would be unpredictable here", get_tok_str(S, token, NULL));
2381+ tcc_error("result of '%s' would be unpredictable here", get_tok_str(token, NULL));
23822382 return;
23832383 }
23842384 opcode |= 1 << 21; // write offset back into register
@@ -2387,11 +2387,11 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 2 unmodified lines
23872387 if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) {
23882388 int v = ops[2].e.v;
23892389 if (op2_minus)
2390− tcc_error(S, "minus before '#' not supported for immediate values");
2390+ tcc_error("minus before '#' not supported for immediate values");
23912391 if (v >= 0) {
23922392 opcode |= 1 << 23; // up
23932393 if (v >= 0x100)
2394− tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
2394+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
23952395 else {
23962396 // bits 11...8: immediate hi nibble
23972397 // bits 3...0: immediate lo nibble
@@ -2400,7 +2400,7 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 2 unmodified lines
24002400 }
24012401 } else { // down
24022402 if (v <= -0x100)
2403− tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
2403+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
24042404 else {
24052405 v = -v;
24062406 // bits 11...8: immediate hi nibble
@@ -2415,7 +2415,7 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 8 unmodified lines
24152415 opcode |= 1 << 23; // up
24162416 opcode |= ops[2].reg;
24172417 } else
2418− expect(S, "register");
2418+ expect("register");
24192419
24202420 switch (ARM_INSTRUCTION_GROUP(token)) {
24212421 case TOK_ASM_ldrsheq:
@@ -2424,34 +2424,34 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token) · 2 unmodified lines
24242424 case TOK_ASM_ldrsbeq:
24252425 opcode |= 1 << 6; // sign extend
24262426 opcode |= 1 << 20; // L
2427− asm_emit_opcode(S, token, opcode);
2427+ asm_emit_opcode(token, opcode);
24282428 break;
24292429 case TOK_ASM_ldrheq:
24302430 opcode |= 1 << 5; // halfword, not byte
24312431 opcode |= 1 << 20; // L
2432− asm_emit_opcode(S, token, opcode);
2432+ asm_emit_opcode(token, opcode);
24332433 break;
24342434 case TOK_ASM_strheq:
24352435 opcode |= 1 << 5; // halfword, not byte
2436− asm_emit_opcode(S, token, opcode);
2436+ asm_emit_opcode(token, opcode);
24372437 break;
24382438 }
24392439 }
24402440
24412441 /* Note: almost dupe of encbranch in arm-gen.c */
2442−static uint32_t encbranchoffset(TCCState* S, int pos, int addr, int fail)
2442+static uint32_t encbranchoffset(int pos, int addr, int fail)
24432443 {
24442444 addr-=pos+8;
24452445 addr/=4;
24462446 if(addr>=0x7fffff || addr<-0x800000) {
24472447 if(fail)
2448− tcc_error(S, "branch offset is too far");
2448+ tcc_error("branch offset is too far");
24492449 return 0;
24502450 }
24512451 return /*not 0x0A000000|*/(addr&0xffffff);
24522452 }
24532453
2454−static void asm_branch_opcode(TCCState *S, int token)
2454+static void asm_branch_opcode(TCCState *s1, int token)
24552455 {
24562456 int jmp_disp = 0;
24572457 Operand op;
@@ -2461,63 +2461,63 @@ static void asm_branch_opcode(TCCState *S, int token) · 3 unmodified lines
24612461 switch (ARM_INSTRUCTION_GROUP(token)) {
24622462 case TOK_ASM_beq:
24632463 case TOK_ASM_bleq:
2464− asm_expr(S, &e);
2465− esym = elfsym(S, e.sym);
2464+ asm_expr(s1, &e);
2465+ esym = elfsym(e.sym);
24662466 if (!esym || esym->st_shndx != cur_text_section->sh_num) {
2467− tcc_error(S, "invalid branch target");
2467+ tcc_error("invalid branch target");
24682468 return;
24692469 }
2470− jmp_disp = encbranchoffset(S, S->tccgen_ind, e.v + esym->st_value, 1);
2470+ jmp_disp = encbranchoffset(ind, e.v + esym->st_value, 1);
24712471 break;
24722472 default:
2473− parse_operand(S, &op);
2473+ parse_operand(s1, &op);
24742474 break;
24752475 }
24762476 switch (ARM_INSTRUCTION_GROUP(token)) {
24772477 case TOK_ASM_beq:
2478− asm_emit_opcode(S, token, (0xa << 24) | (jmp_disp & 0xffffff));
2478+ asm_emit_opcode(token, (0xa << 24) | (jmp_disp & 0xffffff));
24792479 break;
24802480 case TOK_ASM_bleq:
2481− asm_emit_opcode(S, token, (0xb << 24) | (jmp_disp & 0xffffff));
2481+ asm_emit_opcode(token, (0xb << 24) | (jmp_disp & 0xffffff));
24822482 break;
24832483 case TOK_ASM_bxeq:
24842484 if (op.type != OP_REG32)
2485− expect(S, "register");
2485+ expect("register");
24862486 else
2487− asm_emit_opcode(S, token, (0x12fff1 << 4) | op.reg);
2487+ asm_emit_opcode(token, (0x12fff1 << 4) | op.reg);
24882488 break;
24892489 case TOK_ASM_blxeq:
24902490 if (op.type != OP_REG32)
2491− expect(S, "register");
2491+ expect("register");
24922492 else
2493− asm_emit_opcode(S, token, (0x12fff3 << 4) | op.reg);
2493+ asm_emit_opcode(token, (0x12fff3 << 4) | op.reg);
24942494 break;
24952495 default:
2496− expect(S, "branch instruction");
2496+ expect("branch instruction");
24972497 }
24982498 }
24992499
2500−ST_FUNC void asm_opcode(TCCState *S, int token)
2500+ST_FUNC void asm_opcode(TCCState *s1, int token)
25012501 {
25022502 while (token == TOK_LINEFEED) {
2503− next(S);
2504− token = S->tccpp_tok;
2503+ next();
2504+ token = tok;
25052505 }
25062506 if (token == TOK_EOF)
25072507 return;
25082508 if (token < TOK_ASM_nopeq) { // no condition code
25092509 switch (token) {
25102510 case TOK_ASM_cdp2:
2511− asm_coprocessor_opcode(S, token);
2511+ asm_coprocessor_opcode(s1, token);
25122512 return;
25132513 case TOK_ASM_ldc2:
25142514 case TOK_ASM_ldc2l:
25152515 case TOK_ASM_stc2:
25162516 case TOK_ASM_stc2l:
2517− asm_coprocessor_data_transfer_opcode(S, token);
2517+ asm_coprocessor_data_transfer_opcode(s1, token);
25182518 return;
25192519 default:
2520− expect(S, "instruction");
2520+ expect("instruction");
25212521 return;
25222522 }
25232523 }
@@ -2535,22 +2535,22 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 11 unmodified lines
25352535 case TOK_ASM_ldmdbeq:
25362536 case TOK_ASM_stmibeq:
25372537 case TOK_ASM_ldmibeq:
2538− asm_block_data_transfer_opcode(S, token);
2538+ asm_block_data_transfer_opcode(s1, token);
25392539 return;
25402540 case TOK_ASM_nopeq:
25412541 case TOK_ASM_wfeeq:
25422542 case TOK_ASM_wfieq:
2543− asm_nullary_opcode(S, token);
2543+ asm_nullary_opcode(token);
25442544 return;
25452545 case TOK_ASM_swieq:
25462546 case TOK_ASM_svceq:
2547− asm_unary_opcode(S, token);
2547+ asm_unary_opcode(s1, token);
25482548 return;
25492549 case TOK_ASM_beq:
25502550 case TOK_ASM_bleq:
25512551 case TOK_ASM_bxeq:
25522552 case TOK_ASM_blxeq:
2553− asm_branch_opcode(S, token);
2553+ asm_branch_opcode(s1, token);
25542554 return;
25552555 case TOK_ASM_clzeq:
25562556 case TOK_ASM_sxtbeq:
@@ -2559,7 +2559,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 2 unmodified lines
25592559 case TOK_ASM_uxtheq:
25602560 case TOK_ASM_movteq:
25612561 case TOK_ASM_movweq:
2562− asm_binary_opcode(S, token);
2562+ asm_binary_opcode(s1, token);
25632563 return;
25642564
25652565 case TOK_ASM_ldreq:
@@ -2570,14 +2570,14 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 4 unmodified lines
25702570 case TOK_ASM_ldrexbeq:
25712571 case TOK_ASM_strexeq:
25722572 case TOK_ASM_strexbeq:
2573− asm_single_data_transfer_opcode(S, token);
2573+ asm_single_data_transfer_opcode(s1, token);
25742574 return;
25752575
25762576 case TOK_ASM_ldrheq:
25772577 case TOK_ASM_ldrsheq:
25782578 case TOK_ASM_ldrsbeq:
25792579 case TOK_ASM_strheq:
2580− asm_misc_single_data_transfer_opcode(S, token);
2580+ asm_misc_single_data_transfer_opcode(s1, token);
25812581 return;
25822582
25832583 case TOK_ASM_andeq:
@@ -2612,7 +2612,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 28 unmodified lines
26122612 case TOK_ASM_movseq:
26132613 case TOK_ASM_bicseq:
26142614 case TOK_ASM_mvnseq:
2615− asm_data_processing_opcode(S, token);
2615+ asm_data_processing_opcode(s1, token);
26162616 return;
26172617
26182618 case TOK_ASM_lsleq:
@@ -2625,14 +2625,14 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 6 unmodified lines
26252625 case TOK_ASM_rorseq:
26262626 case TOK_ASM_rrxseq:
26272627 case TOK_ASM_rrxeq:
2628− asm_shift_opcode(S, token);
2628+ asm_shift_opcode(s1, token);
26292629 return;
26302630
26312631 case TOK_ASM_muleq:
26322632 case TOK_ASM_mulseq:
26332633 case TOK_ASM_mlaeq:
26342634 case TOK_ASM_mlaseq:
2635− asm_multiplication_opcode(S, token);
2635+ asm_multiplication_opcode(s1, token);
26362636 return;
26372637
26382638 case TOK_ASM_smulleq:
@@ -2643,26 +2643,26 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 4 unmodified lines
26432643 case TOK_ASM_smlalseq:
26442644 case TOK_ASM_umlaleq:
26452645 case TOK_ASM_umlalseq:
2646− asm_long_multiplication_opcode(S, token);
2646+ asm_long_multiplication_opcode(s1, token);
26472647 return;
26482648
26492649 case TOK_ASM_cdpeq:
26502650 case TOK_ASM_mcreq:
26512651 case TOK_ASM_mrceq:
2652− asm_coprocessor_opcode(S, token);
2652+ asm_coprocessor_opcode(s1, token);
26532653 return;
26542654
26552655 case TOK_ASM_ldceq:
26562656 case TOK_ASM_ldcleq:
26572657 case TOK_ASM_stceq:
26582658 case TOK_ASM_stcleq:
2659− asm_coprocessor_data_transfer_opcode(S, token);
2659+ asm_coprocessor_data_transfer_opcode(s1, token);
26602660 return;
26612661
26622662 #if defined(TCC_ARM_VFP)
26632663 case TOK_ASM_vldreq:
26642664 case TOK_ASM_vstreq:
2665− asm_floating_point_single_data_transfer_opcode(S, token);
2665+ asm_floating_point_single_data_transfer_opcode(s1, token);
26662666 return;
26672667
26682668 case TOK_ASM_vmlaeq_f32:
@@ -2695,7 +2695,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 26 unmodified lines
26952695 case TOK_ASM_vcmpeq_f64:
26962696 case TOK_ASM_vcmpeeq_f64:
26972697 case TOK_ASM_vmoveq_f64:
2698− asm_floating_point_data_processing_opcode(S, token);
2698+ asm_floating_point_data_processing_opcode(s1, token);
26992699 return;
27002700
27012701 case TOK_ASM_vcvtreq_s32_f32:
@@ -2712,7 +2712,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 10 unmodified lines
27122712 case TOK_ASM_vcvteq_f32_u32:
27132713 case TOK_ASM_vcvteq_f64_f32:
27142714 case TOK_ASM_vcvteq_f32_f64:
2715− asm_floating_point_vcvt_data_processing_opcode(S, token);
2715+ asm_floating_point_vcvt_data_processing_opcode(s1, token);
27162716 return;
27172717
27182718 case TOK_ASM_vpusheq:
@@ -2723,21 +2723,21 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 4 unmodified lines
27232723 case TOK_ASM_vstmeq:
27242724 case TOK_ASM_vstmiaeq:
27252725 case TOK_ASM_vstmdbeq:
2726− asm_floating_point_block_data_transfer_opcode(S, token);
2726+ asm_floating_point_block_data_transfer_opcode(s1, token);
27272727 return;
27282728
27292729 case TOK_ASM_vmsreq:
27302730 case TOK_ASM_vmrseq:
2731− asm_floating_point_status_register_opcode(S, token);
2731+ asm_floating_point_status_register_opcode(s1, token);
27322732 return;
27332733 #endif
27342734
27352735 default:
2736− expect(S, "known instruction");
2736+ expect("known instruction");
27372737 }
27382738 }
27392739
2740−ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int modifier)
2740+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
27412741 {
27422742 int r, reg, size, val;
27432743 char buf[64];
@@ -2746,45 +2746,45 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int mo · 2 unmodified lines
27462746 if ((r & VT_VALMASK) == VT_CONST) {
27472747 if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' &&
27482748 modifier != 'P')
2749− cstr_ccat(S, add_str, '#');
2749+ cstr_ccat(add_str, '#');
27502750 if (r & VT_SYM) {
2751− const char *name = get_tok_str(S, sv->sym->v, NULL);
2751+ const char *name = get_tok_str(sv->sym->v, NULL);
27522752 if (sv->sym->v >= SYM_FIRST_ANOM) {
27532753 /* In case of anonymous symbols ("L.42", used
27542754 for static data labels) we can't find them
27552755 in the C symbol table when later looking up
27562756 this name. So enter them now into the asm label
27572757 list when we still know the symbol. */
2758− get_asm_sym(S, tok_alloc(S, name, strlen(name))->tok, sv->sym);
2758+ get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym);
27592759 }
2760− if (S->leading_underscore)
2761− cstr_ccat(S, add_str, '_');
2762− cstr_cat(S, add_str, name, -1);
2760+ if (tcc_state->leading_underscore)
2761+ cstr_ccat(add_str, '_');
2762+ cstr_cat(add_str, name, -1);
27632763 if ((uint32_t) sv->c.i == 0)
27642764 goto no_offset;
2765− cstr_ccat(S, add_str, '+');
2765+ cstr_ccat(add_str, '+');
27662766 }
27672767 val = sv->c.i;
27682768 if (modifier == 'n')
27692769 val = -val;
27702770 snprintf(buf, sizeof(buf), "%d", (int) sv->c.i);
2771− cstr_cat(S, add_str, buf, -1);
2771+ cstr_cat(add_str, buf, -1);
27722772 no_offset:;
27732773 } else if ((r & VT_VALMASK) == VT_LOCAL) {
27742774 snprintf(buf, sizeof(buf), "[fp,#%d]", (int) sv->c.i);
2775− cstr_cat(S, add_str, buf, -1);
2775+ cstr_cat(add_str, buf, -1);
27762776 } else if (r & VT_LVAL) {
27772777 reg = r & VT_VALMASK;
27782778 if (reg >= VT_CONST)
2779− tcc_internal_error(S, "");
2779+ tcc_internal_error("");
27802780 snprintf(buf, sizeof(buf), "[%s]",
2781− get_tok_str(S, TOK_ASM_r0 + reg, NULL));
2782− cstr_cat(S, add_str, buf, -1);
2781+ get_tok_str(TOK_ASM_r0 + reg, NULL));
2782+ cstr_cat(add_str, buf, -1);
27832783 } else {
27842784 /* register case */
27852785 reg = r & VT_VALMASK;
27862786 if (reg >= VT_CONST)
2787− tcc_internal_error(S, "");
2787+ tcc_internal_error("");
27882788
27892789 /* choose register operand size */
27902790 if ((sv->type.t & VT_BTYPE) == VT_BYTE ||
@@ -2808,13 +2808,13 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int mo · 17 unmodified lines
28082808 reg = TOK_ASM_r0 + reg;
28092809 break;
28102810 }
2811− snprintf(buf, sizeof(buf), "%s", get_tok_str(S, reg, NULL));
2812− cstr_cat(S, add_str, buf, -1);
2811+ snprintf(buf, sizeof(buf), "%s", get_tok_str(reg, NULL));
2812+ cstr_cat(add_str, buf, -1);
28132813 }
28142814 }
28152815
28162816 /* generate prolog and epilog code for asm statement */
2817−ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
2817+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
28182818 int nb_outputs, int is_output,
28192819 uint8_t *clobber_regs,
28202820 int out_reg)
@@ -2844,7 +2844,7 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 23 unmodified lines
28442844 if (!is_output) { // prolog
28452845 /* generate reg save code */
28462846 if (saved_regset)
2847− gen_le32(S, 0xe92d0000 | saved_regset); // push {...}
2847+ gen_le32(0xe92d0000 | saved_regset); // push {...}
28482848
28492849 /* generate load code */
28502850 for(i = 0; i < nb_operands; i++) {
@@ -2858,12 +2858,12 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 7 unmodified lines
28582858 sv = *op->vt;
28592859 sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
28602860 sv.type.t = VT_PTR;
2861− load(S, op->reg, &sv);
2861+ load(op->reg, &sv);
28622862 } else if (i >= nb_outputs || op->is_rw) { // not write-only
28632863 /* load value in register */
2864− load(S, op->reg, op->vt);
2864+ load(op->reg, op->vt);
28652865 if (op->is_llong)
2866− tcc_error(S, "long long not implemented");
2866+ tcc_error("long long not implemented");
28672867 }
28682868 }
28692869 }
@@ -2878,29 +2878,29 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 8 unmodified lines
28782878 sv = *op->vt;
28792879 sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL;
28802880 sv.type.t = VT_PTR;
2881− load(S, out_reg, &sv);
2881+ load(out_reg, &sv);
28822882
28832883 sv = *op->vt;
28842884 sv.r = (sv.r & ~VT_VALMASK) | out_reg;
2885− store(S, op->reg, &sv);
2885+ store(op->reg, &sv);
28862886 }
28872887 } else {
2888− store(S, op->reg, op->vt);
2888+ store(op->reg, op->vt);
28892889 if (op->is_llong)
2890− tcc_error(S, "long long not implemented");
2890+ tcc_error("long long not implemented");
28912891 }
28922892 }
28932893 }
28942894
28952895 /* generate reg restore code */
28962896 if (saved_regset)
2897− gen_le32(S, 0xe8bd0000 | saved_regset); // pop {...}
2897+ gen_le32(0xe8bd0000 | saved_regset); // pop {...}
28982898 }
28992899 }
29002900
29012901 /* return the constraint priority (we allocate first the lowest
29022902 numbered constraints) */
2903−static inline int constraint_priority(TCCState* S, const char *str)
2903+static inline int constraint_priority(const char *str)
29042904 {
29052905 int priority, c, pr;
29062906
@@ -2927,7 +2927,7 @@ static inline int constraint_priority(TCCState* S, const char *str) · 20 unmodified lines
29272927 pr = 4;
29282928 break;
29292929 default:
2930− tcc_error(S, "unknown constraint '%c'", c);
2930+ tcc_error("unknown constraint '%c'", c);
29312931 pr = 0;
29322932 }
29332933 if (pr > priority)
@@ -2956,7 +2956,7 @@ static const char *skip_constraint_modifiers(const char *p) · 22 unmodified lines
29562956
29572957 #define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask)
29582958
2959−ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
2959+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
29602960 int nb_operands, int nb_outputs,
29612961 const uint8_t *clobber_regs,
29622962 int *pout_reg)
@@ -3009,13 +3009,13 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 46 unmodified lines
30093009 str = skip_constraint_modifiers(str);
30103010 if (isnum(*str) || *str == '[') {
30113011 /* this is a reference to another constraint */
3012− k = find_constraint(S, operands, nb_operands, str, NULL);
3012+ k = find_constraint(operands, nb_operands, str, NULL);
30133013 if ((unsigned) k >= i || i < nb_outputs)
3014− tcc_error(S, "invalid reference in constraint %d ('%s')",
3014+ tcc_error("invalid reference in constraint %d ('%s')",
30153015 i, str);
30163016 op->ref_index = k;
30173017 if (operands[k].input_index >= 0)
3018− tcc_error(S, "cannot reference twice the same operand");
3018+ tcc_error("cannot reference twice the same operand");
30193019 operands[k].input_index = i;
30203020 op->priority = 5;
30213021 } else if ((op->vt->r & VT_VALMASK) == VT_LOCAL
@@ -3024,7 +3024,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 2 unmodified lines
30243024 op->priority = 1;
30253025 op->reg = reg;
30263026 } else {
3027− op->priority = constraint_priority(S, str);
3027+ op->priority = constraint_priority(str);
30283028 }
30293029 }
30303030
@@ -3073,7 +3073,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 42 unmodified lines
30733073 if (op->reg >= 0) {
30743074 if (is_reg_allocated(op->reg))
30753075 tcc_error
3076− (S, "asm regvar requests register that's taken already");
3076+ ("asm regvar requests register that's taken already");
30773077 reg = op->reg;
30783078 goto reg_found;
30793079 }
@@ -3087,7 +3087,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 7 unmodified lines
30873087 /* FALL THRU */
30883088 case '&': // Operand is clobbered before the instruction is done using the input operands
30893089 if (j >= nb_outputs)
3090− tcc_error(S, "'%c' modifier can only be applied to outputs",
3090+ tcc_error("'%c' modifier can only be applied to outputs",
30913091 c);
30923092 reg_mask = REG_IN_MASK | REG_OUT_MASK;
30933093 goto try_next;
@@ -3147,7 +3147,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 53 unmodified lines
31473147 }
31483148 break;
31493149 default:
3150− tcc_error(S, "asm constraint %d ('%s') could not be satisfied",
3150+ tcc_error("asm constraint %d ('%s') could not be satisfied",
31513151 j, op->constraint);
31523152 break;
31533153 }
@@ -3169,7 +3169,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 15 unmodified lines
31693169 if (!(regs_allocated[reg] & REG_OUT_MASK))
31703170 goto reg_found2;
31713171 }
3172− tcc_error(S, "could not find free output register for reloading");
3172+ tcc_error("could not find free output register for reloading");
31733173 reg_found2:
31743174 *pout_reg = reg;
31753175 break;
@@ -3183,7 +3183,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 7 unmodified lines
31833183 op = &operands[j];
31843184 printf("%%%d [%s]: \"%s\" r=0x%04x reg=%d\n",
31853185 j,
3186− op->id ? get_tok_str(S, op->id, NULL) : "",
3186+ op->id ? get_tok_str(op->id, NULL) : "",
31873187 op->constraint, op->vt->r, op->reg);
31883188 }
31893189 if (*pout_reg >= 0)
@@ -3191,7 +3191,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 1 unmodified line
31913191 #endif
31923192 }
31933193
3194−ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
3194+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
31953195 {
31963196 int reg;
31973197 TokenSym *ts;
@@ -3200,17 +3200,17 @@ ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str) · 2 unmodified lines
32003200 !strcmp(str, "cc") ||
32013201 !strcmp(str, "flags"))
32023202 return;
3203− ts = tok_alloc(S, str, strlen(str));
3204− reg = asm_parse_regvar(S, ts->tok);
3203+ ts = tok_alloc(str, strlen(str));
3204+ reg = asm_parse_regvar(ts->tok);
32053205 if (reg == -1) {
3206− tcc_error(S, "invalid clobber register '%s'", str);
3206+ tcc_error("invalid clobber register '%s'", str);
32073207 }
32083208 clobber_regs[reg] = 1;
32093209 }
32103210
32113211 /* If T refers to a register then return the register number and type.
32123212 Otherwise return -1. */
3213−ST_FUNC int asm_parse_regvar (TCCState *S, int t)
3213+ST_FUNC int asm_parse_regvar (int t)
32143214 {
32153215 if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */
32163216 switch (t) {
arm-gen.c+570−563
@@ -179,17 +179,24 @@ ST_DATA const int reg_classes[NB_REGS] = { · 178 unmodified lines
179179 static int func_sub_sp_offset, last_itod_magic;
180180 static int leaffunc;
181181
182+#if defined(CONFIG_TCC_BCHECK)
183+static addr_t func_bound_offset;
184+static unsigned long func_bound_ind;
185+ST_DATA int func_bound_add_epilog;
186+#endif
187+
182188 #if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
183−ST_FUNC void arm_init(TCCState *S)
189+static CType float_type, double_type, func_float_type, func_double_type;
190+ST_FUNC void arm_init(struct TCCState *s)
184191 {
185− S->armgen_float_type.t = VT_FLOAT;
186− S->armgen_double_type.t = VT_DOUBLE;
187− S->armgen_func_float_type.t = VT_FUNC;
188− S->armgen_func_float_type.ref = sym_push(S, SYM_FIELD, &S->armgen_float_type, FUNC_CDECL, FUNC_OLD);
189− S->armgen_func_double_type.t = VT_FUNC;
190− S->armgen_func_double_type.ref = sym_push(S, SYM_FIELD, &S->armgen_double_type, FUNC_CDECL, FUNC_OLD);
191−
192− float_abi = S->float_abi;
192+ float_type.t = VT_FLOAT;
193+ double_type.t = VT_DOUBLE;
194+ func_float_type.t = VT_FUNC;
195+ func_float_type.ref = sym_push(SYM_FIELD, &float_type, FUNC_CDECL, FUNC_OLD);
196+ func_double_type.t = VT_FUNC;
197+ func_double_type.ref = sym_push(SYM_FIELD, &double_type, FUNC_CDECL, FUNC_OLD);
198+
199+ float_abi = s->float_abi;
193200 #ifndef TCC_ARM_HARDFLOAT
194201 // XXX: Works on OpenBSD
195202 // # warning "soft float ABI currently not supported: default to softfp"
@@ -216,15 +223,15 @@ ST_FUNC void arm_init(struct TCCState *s) · 20 unmodified lines
216223
217224 #define CHECK_R(r) ((r) >= TREG_R0 && (r) <= TREG_LR)
218225
219−static int two2mask(TCCState* S, int a,int b) {
226+static int two2mask(int a,int b) {
220227 if (!CHECK_R(a) || !CHECK_R(b))
221− tcc_error(S, "compiler error! registers %i,%i is not valid",a,b);
228+ tcc_error("compiler error! registers %i,%i is not valid",a,b);
222229 return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT);
223230 }
224231
225−static int regmask(TCCState* S, int r) {
232+static int regmask(int r) {
226233 if (!CHECK_R(r))
227− tcc_error(S, "compiler error! register %i is not valid",r);
234+ tcc_error("compiler error! register %i is not valid",r);
228235 return reg_classes[r]&~(RC_INT|RC_FLOAT);
229236 }
230237
@@ -240,25 +247,25 @@ const char *default_elfinterp(struct TCCState *s) · 9 unmodified lines
240247 }
241248 #endif
242249
243−void o(TCCState* S, uint32_t i)
250+void o(uint32_t i)
244251 {
245252 /* this is a good place to start adding big-endian support*/
246253 int ind1;
247− if (S->tccgen_nocode_wanted)
254+ if (nocode_wanted)
248255 return;
249− ind1 = S->tccgen_ind + 4;
256+ ind1 = ind + 4;
250257 if (!cur_text_section)
251− tcc_error(S, "compiler error! This happens f.ex. if the compiler\n"
258+ tcc_error("compiler error! This happens f.ex. if the compiler\n"
252259 "can't evaluate constant expressions outside of a function.");
253260 if (ind1 > cur_text_section->data_allocated)
254− section_realloc(S, cur_text_section, ind1);
255− cur_text_section->data[S->tccgen_ind++] = i&255;
261+ section_realloc(cur_text_section, ind1);
262+ cur_text_section->data[ind++] = i&255;
256263 i>>=8;
257− cur_text_section->data[S->tccgen_ind++] = i&255;
264+ cur_text_section->data[ind++] = i&255;
258265 i>>=8;
259− cur_text_section->data[S->tccgen_ind++] = i&255;
266+ cur_text_section->data[ind++] = i&255;
260267 i>>=8;
261− cur_text_section->data[S->tccgen_ind++] = i;
268+ cur_text_section->data[ind++] = i;
262269 }
263270
264271 static uint32_t stuff_const(uint32_t op, uint32_t c)
@@ -315,11 +322,11 @@ static uint32_t stuff_const(uint32_t op, uint32_t c) · 50 unmodified lines
315322
316323
317324 //only add,sub
318−void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) {
325+void stuff_const_harder(uint32_t op, uint32_t v) {
319326 uint32_t x;
320327 x=stuff_const(op,v);
321328 if(x)
322− o(S, x);
329+ o(x);
323330 else {
324331 uint32_t a[16], nv, no, o2, n2;
325332 int i,j,k;
@@ -330,8 +337,8 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) { · 4 unmodified lines
330337 for(i=0;i<12;i++)
331338 for(j=i<4?i+12:15;j>=i+4;j--)
332339 if((v&(a[i]|a[j]))==v) {
333− o(S, stuff_const(op,v&a[i]));
334− o(S, stuff_const(o2,v&a[j]));
340+ o(stuff_const(op,v&a[i]));
341+ o(stuff_const(o2,v&a[j]));
335342 return;
336343 }
337344 no=op^0xC00000;
@@ -340,17 +347,17 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) { · 2 unmodified lines
340347 for(i=0;i<12;i++)
341348 for(j=i<4?i+12:15;j>=i+4;j--)
342349 if((nv&(a[i]|a[j]))==nv) {
343− o(S, stuff_const(no,nv&a[i]));
344− o(S, stuff_const(n2,nv&a[j]));
350+ o(stuff_const(no,nv&a[i]));
351+ o(stuff_const(n2,nv&a[j]));
345352 return;
346353 }
347354 for(i=0;i<8;i++)
348355 for(j=i+4;j<12;j++)
349356 for(k=i<4?i+12:15;k>=j+4;k--)
350357 if((v&(a[i]|a[j]|a[k]))==v) {
351− o(S, stuff_const(op,v&a[i]));
352− o(S, stuff_const(o2,v&a[j]));
353− o(S, stuff_const(o2,v&a[k]));
358+ o(stuff_const(op,v&a[i]));
359+ o(stuff_const(o2,v&a[j]));
360+ o(stuff_const(o2,v&a[k]));
354361 return;
355362 }
356363 no=op^0xC00000;
@@ -359,31 +366,31 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) { · 2 unmodified lines
359366 for(j=i+4;j<12;j++)
360367 for(k=i<4?i+12:15;k>=j+4;k--)
361368 if((nv&(a[i]|a[j]|a[k]))==nv) {
362− o(S, stuff_const(no,nv&a[i]));
363− o(S, stuff_const(n2,nv&a[j]));
364− o(S, stuff_const(n2,nv&a[k]));
369+ o(stuff_const(no,nv&a[i]));
370+ o(stuff_const(n2,nv&a[j]));
371+ o(stuff_const(n2,nv&a[k]));
365372 return;
366373 }
367− o(S, stuff_const(op,v&a[0]));
368− o(S, stuff_const(o2,v&a[4]));
369− o(S, stuff_const(o2,v&a[8]));
370− o(S, stuff_const(o2,v&a[12]));
374+ o(stuff_const(op,v&a[0]));
375+ o(stuff_const(o2,v&a[4]));
376+ o(stuff_const(o2,v&a[8]));
377+ o(stuff_const(o2,v&a[12]));
371378 }
372379 }
373380
374−uint32_t encbranch(TCCState* S, int pos, int addr, int fail)
381+uint32_t encbranch(int pos, int addr, int fail)
375382 {
376383 addr-=pos+8;
377384 addr/=4;
378385 if(addr>=0x1000000 || addr<-0x1000000) {
379386 if(fail)
380− tcc_error(S, "FIXME: function bigger than 32MB");
387+ tcc_error("FIXME: function bigger than 32MB");
381388 return 0;
382389 }
383390 return 0x0A000000|(addr&0xffffff);
384391 }
385392
386−int decbranch(TCCState* S, int pos)
393+int decbranch(int pos)
387394 {
388395 int x;
389396 x=*(uint32_t *)(cur_text_section->data + pos);
@@ -394,50 +401,50 @@ int decbranch(TCCState* S, int pos) · 4 unmodified lines
394401 }
395402
396403 /* output a symbol and patch all calls to it */
397−void gsym_addr(TCCState* S, int t, int a)
404+void gsym_addr(int t, int a)
398405 {
399406 uint32_t *x;
400407 int lt;
401408 while(t) {
402409 x=(uint32_t *)(cur_text_section->data + t);
403− t=decbranch(S, lt=t);
410+ t=decbranch(lt=t);
404411 if(a==lt+4)
405412 *x=0xE1A00000; // nop
406413 else {
407414 *x &= 0xff000000;
408− *x |= encbranch(S, lt,a,1);
415+ *x |= encbranch(lt,a,1);
409416 }
410417 }
411418 }
412419
413420 #ifdef TCC_ARM_VFP
414−static uint32_t vfpr(TCCState* S, int r)
421+static uint32_t vfpr(int r)
415422 {
416423 if(r<TREG_F0 || r>TREG_F7)
417− tcc_error(S, "compiler error! register %i is no vfp register",r);
424+ tcc_error("compiler error! register %i is no vfp register",r);
418425 return r - TREG_F0;
419426 }
420427 #else
421−static uint32_t fpr(TCCState* S, int r)
428+static uint32_t fpr(int r)
422429 {
423430 if(r<TREG_F0 || r>TREG_F3)
424− tcc_error(S, "compiler error! register %i is no fpa register",r);
431+ tcc_error("compiler error! register %i is no fpa register",r);
425432 return r - TREG_F0;
426433 }
427434 #endif
428435
429−static uint32_t intr(TCCState* S, int r)
436+static uint32_t intr(int r)
430437 {
431438 if(r == TREG_R12)
432439 return 12;
433440 if(r >= TREG_R0 && r <= TREG_R3)
434441 return r - TREG_R0;
435442 if (!(r >= TREG_SP && r <= TREG_LR))
436− tcc_error(S, "compiler error! register %i is no int register",r);
443+ tcc_error("compiler error! register %i is no int register",r);
437444 return r + (13 - TREG_SP);
438445 }
439446
440−static void calcaddr(TCCState* S, uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift)
447+static void calcaddr(uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift)
441448 {
442449 if(*off>maxoff || *off&((1<<shift)-1)) {
443450 uint32_t x, y;
@@ -448,23 +455,23 @@ static void calcaddr(TCCState* S, uint32_t *base, int *off, int *sgn, int maxoff · 4 unmodified lines
448455 *base=14; // lr
449456 y=stuff_const(x,*off&~maxoff);
450457 if(y) {
451− o(S, y);
458+ o(y);
452459 *off&=maxoff;
453460 return;
454461 }
455462 y=stuff_const(x,(*off+maxoff)&~maxoff);
456463 if(y) {
457− o(S, y);
464+ o(y);
458465 *sgn=!*sgn;
459466 *off=((*off+maxoff)&~maxoff)-*off;
460467 return;
461468 }
462− stuff_const_harder(S, x,*off&~maxoff);
469+ stuff_const_harder(x,*off&~maxoff);
463470 *off&=maxoff;
464471 }
465472 }
466473
467−static uint32_t mapcc(TCCState* S, int cc)
474+static uint32_t mapcc(int cc)
468475 {
469476 switch(cc)
470477 {
@@ -493,11 +500,11 @@ static uint32_t mapcc(TCCState* S, int cc) · 22 unmodified lines
493500 case TOK_GT:
494501 return 0xC0000000; /* GT */
495502 }
496− tcc_error(S, "unexpected condition code");
503+ tcc_error("unexpected condition code");
497504 return 0xE0000000; /* AL */
498505 }
499506
500−static int negcc(TCCState* S, int cc)
507+static int negcc(int cc)
501508 {
502509 switch(cc)
503510 {
@@ -526,44 +533,44 @@ static int negcc(TCCState* S, int cc) · 22 unmodified lines
526533 case TOK_GT:
527534 return TOK_LE;
528535 }
529− tcc_error(S, "unexpected condition code");
536+ tcc_error("unexpected condition code");
530537 return TOK_NE;
531538 }
532539
533540 /* Load value into register r.
534541 Use relative/got addressing to avoid setting DT_TEXTREL */
535−static void load_value(TCCState* S, SValue *sv, int r)
542+static void load_value(SValue *sv, int r)
536543 {
537− o(S, 0xE59F0000|(intr(S, r)<<12)); /* ldr r, [pc] */
538− o(S, 0xEA000000); /* b $+4 */
544+ o(0xE59F0000|(intr(r)<<12)); /* ldr r, [pc] */
545+ o(0xEA000000); /* b $+4 */
539546 #ifndef CONFIG_TCC_PIE
540547 if(sv->r & VT_SYM)
541− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_ARM_ABS32);
542− o(S, sv->c.i);
548+ greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32);
549+ o(sv->c.i);
543550 #else
544551 if(sv->r & VT_SYM) {
545552 if (sv->sym->type.t & VT_STATIC) {
546553 greloc(cur_text_section, sv->sym, ind, R_ARM_REL32);
547− o(S, sv->c.i - 12);
548− o(S, 0xe080000f | (intr(S, r)<<12) | (intr(S, r)<<16)); // add rx,rx,pc
554+ o(sv->c.i - 12);
555+ o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc
549556 }
550557 else {
551558 greloc(cur_text_section, sv->sym, ind, R_ARM_GOT_PREL);
552− o(S, -12);
553− o(S, 0xe080000f | (intr(S, r)<<12) | (intr(S, r)<<16)); // add rx,rx,pc
554− o(S, 0xe5900000 | (intr(S, r)<<12) | (intr(S, r)<<16)); // ldr rx,[rx]
559+ o(-12);
560+ o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc
561+ o(0xe5900000 | (intr(r)<<12) | (intr(r)<<16)); // ldr rx,[rx]
555562 if (sv->c.i)
556− stuff_const_harder(S, 0xe2800000 | (intr(S, r)<<12) | (intr(S, r)<<16),
563+ stuff_const_harder(0xe2800000 | (intr(r)<<12) | (intr(r)<<16),
557564 sv->c.i);
558565 }
559566 }
560567 else
561− o(S, sv->c.i);
568+ o(sv->c.i);
562569 #endif
563570 }
564571
565572 /* load 'r' from value 'sv' */
566−void load(TCCState* S, int r, SValue *sv)
573+void load(int r, SValue *sv)
567574 {
568575 int v, ft, fc, fr, sign;
569576 uint32_t op;
@@ -587,7 +594,7 @@ void load(TCCState* S, int r, SValue *sv) · 17 unmodified lines
587594 v1.type.t = VT_PTR;
588595 v1.r = VT_LOCAL | VT_LVAL;
589596 v1.c.i = sv->c.i;
590− load(S, TREG_LR, &v1);
597+ load(TREG_LR, &v1);
591598 base = 14; /* lr */
592599 fc=sign=0;
593600 v=VT_LOCAL;
@@ -596,25 +603,25 @@ void load(TCCState* S, int r, SValue *sv) · 2 unmodified lines
596603 v1.r = fr&~VT_LVAL;
597604 v1.c.i = sv->c.i;
598605 v1.sym=sv->sym;
599− load(S, TREG_LR, &v1);
606+ load(TREG_LR, &v1);
600607 base = 14; /* lr */
601608 fc=sign=0;
602609 v=VT_LOCAL;
603610 } else if(v < VT_CONST) {
604− base=intr(S, v);
611+ base=intr(v);
605612 fc=sign=0;
606613 v=VT_LOCAL;
607614 }
608615 if(v == VT_LOCAL) {
609616 if(is_float(ft)) {
610− calcaddr(S, &base,&fc,&sign,1020,2);
617+ calcaddr(&base,&fc,&sign,1020,2);
611618 #ifdef TCC_ARM_VFP
612619 op=0xED100A00; /* flds */
613620 if(!sign)
614621 op|=0x800000;
615622 if ((ft & VT_BTYPE) != VT_FLOAT)
616623 op|=0x100; /* flds -> fldd */
617− o(S, op|(vfpr(S, r)<<12)|(fc>>2)|(base<<16));
624+ o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16));
618625 #else
619626 op=0xED100100;
620627 if(!sign)
@@ -628,11 +635,11 @@ void load(TCCState* S, int r, SValue *sv) · 7 unmodified lines
628635 else if ((ft & VT_BTYPE) == VT_LDOUBLE)
629636 op|=0x400000;
630637 #endif
631− o(S, op|(fpr(S, r)<<12)|(fc>>2)|(base<<16));
638+ o(op|(fpr(r)<<12)|(fc>>2)|(base<<16));
632639 #endif
633640 } else if((ft & (VT_BTYPE|VT_UNSIGNED)) == VT_BYTE
634641 || (ft & VT_BTYPE) == VT_SHORT) {
635− calcaddr(S, &base,&fc,&sign,255,0);
642+ calcaddr(&base,&fc,&sign,255,0);
636643 op=0xE1500090;
637644 if ((ft & VT_BTYPE) == VT_SHORT)
638645 op|=0x20;
@@ -640,63 +647,63 @@ void load(TCCState* S, int r, SValue *sv) · 1 unmodified line
640647 op|=0x40;
641648 if(!sign)
642649 op|=0x800000;
643− o(S, op|(intr(S, r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
650+ o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
644651 } else {
645− calcaddr(S, &base,&fc,&sign,4095,0);
652+ calcaddr(&base,&fc,&sign,4095,0);
646653 op=0xE5100000;
647654 if(!sign)
648655 op|=0x800000;
649656 if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL)
650657 op|=0x400000;
651− o(S, op|(intr(S, r)<<12)|fc|(base<<16));
658+ o(op|(intr(r)<<12)|fc|(base<<16));
652659 }
653660 return;
654661 }
655662 } else {
656663 if (v == VT_CONST) {
657− op=stuff_const(0xE3A00000|(intr(S, r)<<12),sv->c.i);
664+ op=stuff_const(0xE3A00000|(intr(r)<<12),sv->c.i);
658665 if (fr & VT_SYM || !op)
659− load_value(S, sv, r);
666+ load_value(sv, r);
660667 else
661− o(S, op);
668+ o(op);
662669 return;
663670 } else if (v == VT_LOCAL) {
664− op=stuff_const(0xE28B0000|(intr(S, r)<<12),sv->c.i);
671+ op=stuff_const(0xE28B0000|(intr(r)<<12),sv->c.i);
665672 if (fr & VT_SYM || !op) {
666− load_value(S, sv, r);
667− o(S, 0xE08B0000|(intr(S, r)<<12)|intr(S, r));
673+ load_value(sv, r);
674+ o(0xE08B0000|(intr(r)<<12)|intr(r));
668675 } else
669− o(S, op);
676+ o(op);
670677 return;
671678 } else if(v == VT_CMP) {
672− o(S, mapcc(S, sv->c.i)|0x3A00001|(intr(S, r)<<12));
673− o(S, mapcc(S, negcc(S, sv->c.i))|0x3A00000|(intr(S, r)<<12));
679+ o(mapcc(sv->c.i)|0x3A00001|(intr(r)<<12));
680+ o(mapcc(negcc(sv->c.i))|0x3A00000|(intr(r)<<12));
674681 return;
675682 } else if (v == VT_JMP || v == VT_JMPI) {
676683 int t;
677684 t = v & 1;
678− o(S, 0xE3A00000|(intr(S, r)<<12)|t);
679− o(S, 0xEA000000);
680− gsym(S, sv->c.i);
681− o(S, 0xE3A00000|(intr(S, r)<<12)|(t^1));
685+ o(0xE3A00000|(intr(r)<<12)|t);
686+ o(0xEA000000);
687+ gsym(sv->c.i);
688+ o(0xE3A00000|(intr(r)<<12)|(t^1));
682689 return;
683690 } else if (v < VT_CONST) {
684691 if(is_float(ft))
685692 #ifdef TCC_ARM_VFP
686− o(S, 0xEEB00A40|(vfpr(S, r)<<12)|vfpr(S, v)|T2CPR(ft)); /* fcpyX */
693+ o(0xEEB00A40|(vfpr(r)<<12)|vfpr(v)|T2CPR(ft)); /* fcpyX */
687694 #else
688− o(S, 0xEE008180|(fpr(S, r)<<12)|fpr(S, v));
695+ o(0xEE008180|(fpr(r)<<12)|fpr(v));
689696 #endif
690697 else
691− o(S, 0xE1A00000|(intr(S, r)<<12)|intr(S, v));
698+ o(0xE1A00000|(intr(r)<<12)|intr(v));
692699 return;
693700 }
694701 }
695− tcc_error(S, "load unimplemented!");
702+ tcc_error("load unimplemented!");
696703 }
697704
698705 /* store register 'r' in lvalue 'v' */
699−void store(TCCState* S, int r, SValue *sv)
706+void store(int r, SValue *sv)
700707 {
701708 SValue v1;
702709 int v, ft, fc, fr, sign;
@@ -717,7 +724,7 @@ void store(TCCState* S, int r, SValue *sv) · 14 unmodified lines
717724 if (fr & VT_LVAL || fr == VT_LOCAL) {
718725 uint32_t base = 0xb; /* fp */
719726 if(v < VT_CONST) {
720− base=intr(S, v);
727+ base=intr(v);
721728 v=VT_LOCAL;
722729 fc=sign=0;
723730 } else if(v == VT_CONST) {
@@ -725,21 +732,21 @@ void store(TCCState* S, int r, SValue *sv) · 1 unmodified line
725732 v1.r = fr&~VT_LVAL;
726733 v1.c.i = sv->c.i;
727734 v1.sym=sv->sym;
728− load(S, TREG_LR, &v1);
735+ load(TREG_LR, &v1);
729736 base = 14; /* lr */
730737 fc=sign=0;
731738 v=VT_LOCAL;
732739 }
733740 if(v == VT_LOCAL) {
734741 if(is_float(ft)) {
735− calcaddr(S, &base,&fc,&sign,1020,2);
742+ calcaddr(&base,&fc,&sign,1020,2);
736743 #ifdef TCC_ARM_VFP
737744 op=0xED000A00; /* fsts */
738745 if(!sign)
739746 op|=0x800000;
740747 if ((ft & VT_BTYPE) != VT_FLOAT)
741748 op|=0x100; /* fsts -> fstd */
742− o(S, op|(vfpr(S, r)<<12)|(fc>>2)|(base<<16));
749+ o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16));
743750 #else
744751 op=0xED000100;
745752 if(!sign)
@@ -753,138 +760,138 @@ void store(TCCState* S, int r, SValue *sv) · 7 unmodified lines
753760 if ((ft & VT_BTYPE) == VT_LDOUBLE)
754761 op|=0x400000;
755762 #endif
756− o(S, op|(fpr(S, r)<<12)|(fc>>2)|(base<<16));
763+ o(op|(fpr(r)<<12)|(fc>>2)|(base<<16));
757764 #endif
758765 return;
759766 } else if((ft & VT_BTYPE) == VT_SHORT) {
760− calcaddr(S, &base,&fc,&sign,255,0);
767+ calcaddr(&base,&fc,&sign,255,0);
761768 op=0xE14000B0;
762769 if(!sign)
763770 op|=0x800000;
764− o(S, op|(intr(S, r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
771+ o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
765772 } else {
766− calcaddr(S, &base,&fc,&sign,4095,0);
773+ calcaddr(&base,&fc,&sign,4095,0);
767774 op=0xE5000000;
768775 if(!sign)
769776 op|=0x800000;
770777 if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL)
771778 op|=0x400000;
772− o(S, op|(intr(S, r)<<12)|fc|(base<<16));
779+ o(op|(intr(r)<<12)|fc|(base<<16));
773780 }
774781 return;
775782 }
776783 }
777− tcc_error(S, "store unimplemented");
784+ tcc_error("store unimplemented");
778785 }
779786
780−static void gadd_sp(TCCState* S, int val)
787+static void gadd_sp(int val)
781788 {
782− stuff_const_harder(S, 0xE28DD000,val);
789+ stuff_const_harder(0xE28DD000,val);
783790 }
784791
785792 /* 'is_jmp' is '1' if it is a jump */
786−static void gcall_or_jmp(TCCState* S, int is_jmp)
793+static void gcall_or_jmp(int is_jmp)
787794 {
788795 int r;
789796 uint32_t x;
790− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
797+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
791798 /* constant case */
792− if(S->tccgen_vtop->r & VT_SYM){
793− x=encbranch(S, S->tccgen_ind, S->tccgen_ind+S->tccgen_vtop->c.i,0);
799+ if(vtop->r & VT_SYM){
800+ x=encbranch(ind,ind+vtop->c.i,0);
794801 if(x) {
795802 /* relocation case */
796− greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind, R_ARM_PC24);
797− o(S, x|(is_jmp?0xE0000000:0xE1000000));
803+ greloc(cur_text_section, vtop->sym, ind, R_ARM_PC24);
804+ o(x|(is_jmp?0xE0000000:0xE1000000));
798805 } else {
799806 r = TREG_LR;
800− load_value(S, S->tccgen_vtop, r);
807+ load_value(vtop, r);
801808 if(is_jmp)
802− o(S, 0xE1A0F000 | intr(S, r)); // mov pc, r
809+ o(0xE1A0F000 | intr(r)); // mov pc, r
803810 else
804− o(S, 0xe12fff30 | intr(S, r)); // blx r
811+ o(0xe12fff30 | intr(r)); // blx r
805812 }
806813 }else{
807814 if(!is_jmp)
808− o(S, 0xE28FE004); // add lr,pc,#4
809− o(S, 0xE51FF004); // ldr pc,[pc,#-4]
810− o(S, S->tccgen_vtop->c.i);
815+ o(0xE28FE004); // add lr,pc,#4
816+ o(0xE51FF004); // ldr pc,[pc,#-4]
817+ o(vtop->c.i);
811818 }
812819 } else {
813820 /* otherwise, indirect call */
814821 #ifdef CONFIG_TCC_BCHECK
815− S->tccgen_vtop->r &= ~VT_MUSTBOUND;
822+ vtop->r &= ~VT_MUSTBOUND;
816823 #endif
817− r = gv(S, RC_INT);
824+ r = gv(RC_INT);
818825 if(!is_jmp)
819− o(S, 0xE1A0E00F); // mov lr,pc
820− o(S, 0xE1A0F000|intr(S, r)); // mov pc,r
826+ o(0xE1A0E00F); // mov lr,pc
827+ o(0xE1A0F000|intr(r)); // mov pc,r
821828 }
822829 }
823830
824831 #if defined(CONFIG_TCC_BCHECK)
825832
826−static void gen_bounds_call(TCCState* S, int v)
833+static void gen_bounds_call(int v)
827834 {
828− Sym *sym = external_helper_sym(S, v);
835+ Sym *sym = external_helper_sym(v);
829836
830− greloc(S, cur_text_section, sym, S->tccgen_ind, R_ARM_PC24);
831− o(S, 0xebfffffe);
837+ greloc(cur_text_section, sym, ind, R_ARM_PC24);
838+ o(0xebfffffe);
832839 }
833840
834−static void gen_bounds_prolog(TCCState* S)
841+static void gen_bounds_prolog(void)
835842 {
836843 /* leave some room for bound checking code */
837− S->func_bound_offset = lbounds_section->data_offset;
838− S->func_bound_ind = S->tccgen_ind;
839− S->func_bound_add_epilog = 0;
840− o(S, 0xe1a00000); /* ld r0,lbounds_section->data_offset */
841− o(S, 0xe1a00000);
842− o(S, 0xe1a00000);
843− o(S, 0xe1a00000);
844− o(S, 0xe1a00000); /* call __bound_local_new */
844+ func_bound_offset = lbounds_section->data_offset;
845+ func_bound_ind = ind;
846+ func_bound_add_epilog = 0;
847+ o(0xe1a00000); /* ld r0,lbounds_section->data_offset */
848+ o(0xe1a00000);
849+ o(0xe1a00000);
850+ o(0xe1a00000);
851+ o(0xe1a00000); /* call __bound_local_new */
845852 }
846853
847−static void gen_bounds_epilog(TCCState* S)
854+static void gen_bounds_epilog(void)
848855 {
849856 addr_t saved_ind;
850857 addr_t *bounds_ptr;
851858 Sym *sym_data;
852− int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
859+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
853860
854− if (!offset_modified && !S->func_bound_add_epilog)
861+ if (!offset_modified && !func_bound_add_epilog)
855862 return;
856863
857864 /* add end of table info */
858− bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
865+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
859866 *bounds_ptr = 0;
860867
861− sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
862− S->func_bound_offset, lbounds_section->data_offset);
868+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
869+ func_bound_offset, lbounds_section->data_offset);
863870
864871 /* generate bound local allocation */
865872 if (offset_modified) {
866− saved_ind = S->tccgen_ind;
867− S->tccgen_ind = S->func_bound_ind;
868− o(S, 0xe59f0000); /* ldr r0, [pc] */
869− o(S, 0xea000000); /* b $+4 */
870− greloc(S, cur_text_section, sym_data, S->tccgen_ind, R_ARM_REL32);
871− o(S, -12); /* lbounds_section->data_offset */
872− o(S, 0xe080000f); /* add r0,r0,pc */
873− gen_bounds_call(S, TOK___bound_local_new);
874− S->tccgen_ind = saved_ind;
873+ saved_ind = ind;
874+ ind = func_bound_ind;
875+ o(0xe59f0000); /* ldr r0, [pc] */
876+ o(0xea000000); /* b $+4 */
877+ greloc(cur_text_section, sym_data, ind, R_ARM_REL32);
878+ o(-12); /* lbounds_section->data_offset */
879+ o(0xe080000f); /* add r0,r0,pc */
880+ gen_bounds_call(TOK___bound_local_new);
881+ ind = saved_ind;
875882 }
876883
877884 /* generate bound check local freeing */
878− o(S, 0xe92d0003); /* push {r0,r1} */
879− o(S, 0xed2d0b02); /* vpush {d0} */
880− o(S, 0xe59f0000); /* ldr r0, [pc] */
881− o(S, 0xea000000); /* b $+4 */
882− greloc(S, cur_text_section, sym_data, S->tccgen_ind, R_ARM_REL32);
883− o(S, -12); /* lbounds_section->data_offset */
884− o(S, 0xe080000f); /* add r0,r0,pc */
885− gen_bounds_call(S, TOK___bound_local_delete);
886− o(S, 0xecbd0b02); /* vpop {d0} */
887− o(S, 0xe8bd0003); /* pop {r0,r1} */
885+ o(0xe92d0003); /* push {r0,r1} */
886+ o(0xed2d0b02); /* vpush {d0} */
887+ o(0xe59f0000); /* ldr r0, [pc] */
888+ o(0xea000000); /* b $+4 */
889+ greloc(cur_text_section, sym_data, ind, R_ARM_REL32);
890+ o(-12); /* lbounds_section->data_offset */
891+ o(0xe080000f); /* add r0,r0,pc */
892+ gen_bounds_call(TOK___bound_local_delete);
893+ o(0xecbd0b02); /* vpop {d0} */
894+ o(0xe8bd0003); /* pop {r0,r1} */
888895 }
889896 #endif
890897
@@ -1070,7 +1077,7 @@ static void add_param_plan(struct plan* plan, int cls, int start, int end, SValu · 179 unmodified lines
10701077 Note: this function allocated an array in plan->pplans with tcc_malloc. It
10711078 is the responsibility of the caller to free this array once used (ie not
10721079 before copy_params). */
1073−static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *plan, int *todo)
1080+static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
10741081 {
10751082 int i, size, align;
10761083 int ncrn /* next core register number */, nsaa /* next stacked argument address*/;
@@ -1081,12 +1088,12 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla · 4 unmodified lines
10811088
10821089 for(i = nb_args; i-- ;) {
10831090 int j, start_vfpreg = 0;
1084− CType type = S->tccgen_vtop[-i].type;
1091+ CType type = vtop[-i].type;
10851092 type.t &= ~VT_ARRAY;
10861093 size = type_size(&type, &align);
10871094 size = (size + 3) & ~3;
10881095 align = (align + 3) & ~3;
1089− switch(S->tccgen_vtop[-i].type.t & VT_BTYPE) {
1096+ switch(vtop[-i].type.t & VT_BTYPE) {
10901097 case VT_STRUCT:
10911098 case VT_FLOAT:
10921099 case VT_DOUBLE:
@@ -1094,15 +1101,15 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla · 1 unmodified line
10941101 if (float_abi == ARM_HARD_FLOAT) {
10951102 int is_hfa = 0; /* Homogeneous float aggregate */
10961103
1097− if (is_float(S->tccgen_vtop[-i].type.t)
1098− || (is_hfa = is_hgen_float_aggr(&S->tccgen_vtop[-i].type))) {
1104+ if (is_float(vtop[-i].type.t)
1105+ || (is_hfa = is_hgen_float_aggr(&vtop[-i].type))) {
10991106 int end_vfpreg;
11001107
11011108 start_vfpreg = assign_vfpreg(&avregs, align, size);
11021109 end_vfpreg = start_vfpreg + ((size - 1) >> 2);
11031110 if (start_vfpreg >= 0) {
11041111 add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS,
1105− start_vfpreg, end_vfpreg, &S->tccgen_vtop[-i]);
1112+ start_vfpreg, end_vfpreg, &vtop[-i]);
11061113 continue;
11071114 } else
11081115 break;
@@ -1115,7 +1122,7 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla · 6 unmodified lines
11151122 * CORE_STRUCT_CLASS or the first of STACK_CLASS. */
11161123 for (j = ncrn; j < 4 && j < ncrn + size / 4; j++)
11171124 *todo|=(1<<j);
1118− add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &S->tccgen_vtop[-i]);
1125+ add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &vtop[-i]);
11191126 ncrn += size/4;
11201127 if (ncrn > 4)
11211128 nsaa = (ncrn - 4) * 4;
@@ -1126,20 +1133,20 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla · 4 unmodified lines
11261133 continue;
11271134 default:
11281135 if (ncrn < 4) {
1129− int is_long = (S->tccgen_vtop[-i].type.t & VT_BTYPE) == VT_LLONG;
1136+ int is_long = (vtop[-i].type.t & VT_BTYPE) == VT_LLONG;
11301137
11311138 if (is_long) {
11321139 ncrn = (ncrn + 1) & -2;
11331140 if (ncrn == 4)
11341141 break;
11351142 }
1136− add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &S->tccgen_vtop[-i]);
1143+ add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]);
11371144 ncrn += 1 + is_long;
11381145 continue;
11391146 }
11401147 }
11411148 nsaa = (nsaa + (align - 1)) & ~(align - 1);
1142− add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &S->tccgen_vtop[-i]);
1149+ add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]);
11431150 nsaa += size; /* size already rounded up before */
11441151 }
11451152 return nsaa;
@@ -1153,7 +1160,7 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla · 7 unmodified lines
11531160 todo: a bitmap indicating what core reg will hold a parameter
11541161
11551162 Returns the number of SValue added by this function on the value stack */
1156−static int copy_params(TCCState* S, int nb_args, struct plan *plan, int todo)
1163+static int copy_params(int nb_args, struct plan *plan, int todo)
11571164 {
11581165 int size, align, r, i, nb_extra_sval = 0;
11591166 struct param_plan *pplan;
@@ -1182,7 +1189,7 @@ again: · 22 unmodified lines
11821189 && (i != CORE_CLASS || pplan->sval->r < VT_CONST))
11831190 continue;
11841191
1185− vpushv(S, pplan->sval);
1192+ vpushv(pplan->sval);
11861193 pplan->sval->r = pplan->sval->r2 = VT_CONST; /* disable entry */
11871194 switch(i) {
11881195 case STACK_CLASS:
@@ -1197,16 +1204,16 @@ again: · 8 unmodified lines
11971204 padding = pplan->start - pplan->prev->end;
11981205 size += padding; /* Add padding if any */
11991206 /* allocate the necessary size on stack */
1200− gadd_sp(S, -size);
1207+ gadd_sp(-size);
12011208 /* generate structure store */
1202− r = get_reg(S, RC_INT);
1203− o(S, 0xE28D0000|(intr(S, r)<<12)|padding); /* add r, sp, padding */
1204− vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
1205− vswap(S);
1209+ r = get_reg(RC_INT);
1210+ o(0xE28D0000|(intr(r)<<12)|padding); /* add r, sp, padding */
1211+ vset(&vtop->type, r | VT_LVAL, 0);
1212+ vswap();
12061213 /* XXX: optimize. Save all register because memcpy can use them */
1207− o(S, 0xED2D0A00|(0&1)<<22|(0>>1)<<12|16); /* vpush {s0-s15} */
1208− vstore(S); /* memcpy to current sp + potential padding */
1209− o(S, 0xECBD0A00|(0&1)<<22|(0>>1)<<12|16); /* vpop {s0-s15} */
1214+ o(0xED2D0A00|(0&1)<<22|(0>>1)<<12|16); /* vpush {s0-s15} */
1215+ vstore(); /* memcpy to current sp + potential padding */
1216+ o(0xECBD0A00|(0&1)<<22|(0>>1)<<12|16); /* vpop {s0-s15} */
12101217
12111218 /* Homogeneous float aggregate are loaded to VFP registers
12121219 immediately since there is no way of loading data in multiple
@@ -1215,23 +1222,23 @@ again: · 2 unmodified lines
12151222 if (i == VFP_STRUCT_CLASS) {
12161223 int first = pplan->start, nb = pplan->end - first + 1;
12171224 /* vpop.32 {pplan->start, ..., pplan->end} */
1218− o(S, 0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb);
1225+ o(0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb);
12191226 /* No need to write the register used to a SValue since VFP regs
12201227 cannot be used for gcall_or_jmp */
12211228 }
12221229 } else {
12231230 if (is_float(pplan->sval->type.t)) {
12241231 #ifdef TCC_ARM_VFP
1225− r = vfpr(S, gv(S, RC_FLOAT)) << 12;
1232+ r = vfpr(gv(RC_FLOAT)) << 12;
12261233 if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT)
12271234 size = 4;
12281235 else {
12291236 size = 8;
12301237 r |= 0x101; /* vpush.32 -> vpush.64 */
12311238 }
1232− o(S, 0xED2D0A01 + r); /* vpush */
1239+ o(0xED2D0A01 + r); /* vpush */
12331240 #else
1234− r = fpr(S, gv(S, RC_FLOAT)) << 12;
1241+ r = fpr(gv(RC_FLOAT)) << 12;
12351242 if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT)
12361243 size = 4;
12371244 else if ((pplan->sval->type.t & VT_BTYPE) == VT_DOUBLE)
@@ -1244,49 +1251,49 @@ again: · 6 unmodified lines
12441251 else if(size == 8)
12451252 r|=0x8000;
12461253
1247− o(S, 0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */
1254+ o(0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */
12481255 #endif
12491256 } else {
12501257 /* simple type (currently always same size) */
12511258 /* XXX: implicit cast ? */
12521259 size=4;
12531260 if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) {
1254− lexpand(S);
1261+ lexpand();
12551262 size = 8;
1256− r = gv(S, RC_INT);
1257− o(S, 0xE52D0004|(intr(S, r)<<12)); /* push r */
1258− S->tccgen_vtop--;
1263+ r = gv(RC_INT);
1264+ o(0xE52D0004|(intr(r)<<12)); /* push r */
1265+ vtop--;
12591266 }
1260− r = gv(S, RC_INT);
1261− o(S, 0xE52D0004|(intr(S, r)<<12)); /* push r */
1267+ r = gv(RC_INT);
1268+ o(0xE52D0004|(intr(r)<<12)); /* push r */
12621269 }
12631270 if (i == STACK_CLASS && pplan->prev)
1264− gadd_sp(S, pplan->prev->end - pplan->start); /* Add padding if any */
1271+ gadd_sp(pplan->prev->end - pplan->start); /* Add padding if any */
12651272 }
12661273 break;
12671274
12681275 case VFP_CLASS:
1269− gv(S, regmask(S, TREG_F0 + (pplan->start >> 1)));
1276+ gv(regmask(TREG_F0 + (pplan->start >> 1)));
12701277 if (pplan->start & 1) { /* Must be in upper part of double register */
1271− o(S, 0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */
1272− S->tccgen_vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */
1278+ o(0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */
1279+ vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */
12731280 }
12741281 break;
12751282
12761283 case CORE_CLASS:
12771284 if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) {
1278− lexpand(S);
1279− gv(S, regmask(S, pplan->end));
1280− pplan->sval->r2 = S->tccgen_vtop->r;
1281− S->tccgen_vtop--;
1285+ lexpand();
1286+ gv(regmask(pplan->end));
1287+ pplan->sval->r2 = vtop->r;
1288+ vtop--;
12821289 }
1283− gv(S, regmask(S, pplan->start));
1290+ gv(regmask(pplan->start));
12841291 /* Mark register as used so that gcall_or_jmp use another one
12851292 (regs >=4 are free as never used to pass parameters) */
1286− pplan->sval->r = S->tccgen_vtop->r;
1293+ pplan->sval->r = vtop->r;
12871294 break;
12881295 }
1289− S->tccgen_vtop--;
1296+ vtop--;
12901297 }
12911298 }
12921299
@@ -1297,10 +1304,10 @@ again: · 4 unmodified lines
12971304
12981305 /* Manually free remaining registers since next parameters are loaded
12991306 * manually, without the help of gv(int). */
1300− save_regs(S, nb_args);
1307+ save_regs(nb_args);
13011308
13021309 if(todo) {
1303− o(S, 0xE8BD0000|todo); /* pop {todo} */
1310+ o(0xE8BD0000|todo); /* pop {todo} */
13041311 for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) {
13051312 int r;
13061313 pplan->sval->r = pplan->start;
@@ -1311,8 +1318,8 @@ again: · 4 unmodified lines
13111318 for (r = pplan->start + 1; r <= pplan->end; r++) {
13121319 if (todo & (1 << r)) {
13131320 nb_extra_sval++;
1314− vpushi(S, 0);
1315− S->tccgen_vtop->r = r;
1321+ vpushi(0);
1322+ vtop->r = r;
13161323 }
13171324 }
13181325 }
@@ -1323,7 +1330,7 @@ again: · 4 unmodified lines
13231330 /* Generate function call. The function address is pushed first, then
13241331 all the parameters in call order. This functions pops all the
13251332 parameters and the function address. */
1326−void gfunc_call(TCCState* S, int nb_args)
1333+void gfunc_call(int nb_args)
13271334 {
13281335 int r, args_size;
13291336 int def_float_abi = float_abi;
@@ -1334,62 +1341,62 @@ void gfunc_call(TCCState* S, int nb_args) · 4 unmodified lines
13341341 #endif
13351342
13361343 #ifdef CONFIG_TCC_BCHECK
1337− if (S->do_bounds_check)
1338− gbound_args(S, nb_args);
1344+ if (tcc_state->do_bounds_check)
1345+ gbound_args(nb_args);
13391346 #endif
13401347
13411348 #ifdef TCC_ARM_EABI
13421349 if (float_abi == ARM_HARD_FLOAT) {
1343− variadic = (S->tccgen_vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS);
1344− if (variadic || floats_in_core_regs(&S->tccgen_vtop[-nb_args]))
1350+ variadic = (vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS);
1351+ if (variadic || floats_in_core_regs(&vtop[-nb_args]))
13451352 float_abi = ARM_SOFTFP_FLOAT;
13461353 }
13471354 #endif
13481355 /* cannot let cpu flags if other instruction are generated. Also avoid leaving
13491356 VT_JMP anywhere except on the top of the stack because it would complicate
13501357 the code generator. */
1351− r = S->tccgen_vtop->r & VT_VALMASK;
1358+ r = vtop->r & VT_VALMASK;
13521359 if (r == VT_CMP || (r & ~1) == VT_JMP)
1353− gv(S, RC_INT);
1360+ gv(RC_INT);
13541361
13551362 memset(&plan, 0, sizeof plan);
13561363 if (nb_args)
1357− plan.pplans = tcc_malloc(S, nb_args * sizeof(*plan.pplans));
1364+ plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans));
13581365
1359− args_size = assign_regs(S, nb_args, float_abi, &plan, &todo);
1366+ args_size = assign_regs(nb_args, float_abi, &plan, &todo);
13601367
13611368 #ifdef TCC_ARM_EABI
13621369 if (args_size & 7) { /* Stack must be 8 byte aligned at fct call for EABI */
13631370 args_size = (args_size + 7) & ~7;
1364− o(S, 0xE24DD004); /* sub sp, sp, #4 */
1371+ o(0xE24DD004); /* sub sp, sp, #4 */
13651372 }
13661373 #endif
13671374
1368− nb_args += copy_params(S, nb_args, &plan, todo);
1369− tcc_free(S, plan.pplans);
1375+ nb_args += copy_params(nb_args, &plan, todo);
1376+ tcc_free(plan.pplans);
13701377
13711378 /* Move fct SValue on top as required by gcall_or_jmp */
1372− vrotb(S, nb_args + 1);
1373− gcall_or_jmp(S, 0);
1379+ vrotb(nb_args + 1);
1380+ gcall_or_jmp(0);
13741381 if (args_size)
1375− gadd_sp(S, args_size); /* pop all parameters passed on the stack */
1382+ gadd_sp(args_size); /* pop all parameters passed on the stack */
13761383 #if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
1377− if(float_abi == ARM_SOFTFP_FLOAT && is_float(S->tccgen_vtop->type.ref->type.t)) {
1378− if((S->tccgen_vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) {
1379− o(S, 0xEE000A10); /*vmov s0, r0 */
1384+ if(float_abi == ARM_SOFTFP_FLOAT && is_float(vtop->type.ref->type.t)) {
1385+ if((vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) {
1386+ o(0xEE000A10); /*vmov s0, r0 */
13801387 } else {
1381− o(S, 0xEE000B10); /* vmov.32 d0[0], r0 */
1382− o(S, 0xEE201B10); /* vmov.32 d0[1], r1 */
1388+ o(0xEE000B10); /* vmov.32 d0[0], r0 */
1389+ o(0xEE201B10); /* vmov.32 d0[1], r1 */
13831390 }
13841391 }
13851392 #endif
1386− S->tccgen_vtop -= nb_args + 1; /* Pop all params and fct address from value stack */
1393+ vtop -= nb_args + 1; /* Pop all params and fct address from value stack */
13871394 leaffunc = 0; /* we are calling a function, so we aren't in a leaf function */
13881395 float_abi = def_float_abi;
13891396 }
13901397
13911398 /* generate function prolog of type 't' */
1392−void gfunc_prolog(TCCState* S, Sym *func_sym)
1399+void gfunc_prolog(Sym *func_sym)
13931400 {
13941401 CType *func_type = &func_sym->type;
13951402 Sym *sym,*sym2;
@@ -1404,17 +1411,17 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 8 unmodified lines
14041411 sym = func_type->ref;
14051412
14061413 n = nf = 0;
1407− if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT &&
1408− !gfunc_sret(&S->tccgen_func_vt, S->tccgen_func_var, &ret_type, &align, &rs))
1414+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT &&
1415+ !gfunc_sret(&func_vt, func_var, &ret_type, &align, &rs))
14091416 {
14101417 n++;
14111418 struct_ret = 1;
1412− S->tccgen_func_vc = 12; /* Offset from fp of the place to store the result */
1419+ func_vc = 12; /* Offset from fp of the place to store the result */
14131420 }
14141421 for(sym2 = sym->next; sym2 && (n < 4 || nf < 16); sym2 = sym2->next) {
14151422 size = type_size(&sym2->type, &align);
14161423 #ifdef TCC_ARM_EABI
1417− if (float_abi == ARM_HARD_FLOAT && !S->tccgen_func_var &&
1424+ if (float_abi == ARM_HARD_FLOAT && !func_var &&
14181425 (is_float(sym2->type.t) || is_hgen_float_aggr(&sym2->type))) {
14191426 int tmpnf = assign_vfpreg(&avregs, align, size);
14201427 tmpnf += (size + 3) / 4;
@@ -1424,8 +1431,8 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 3 unmodified lines
14241431 if (n < 4)
14251432 n += (size + 3) / 4;
14261433 }
1427− o(S, 0xE1A0C00D); /* mov ip,sp */
1428− if (S->tccgen_func_var)
1434+ o(0xE1A0C00D); /* mov ip,sp */
1435+ if (func_var)
14291436 n=4;
14301437 if (n) {
14311438 if(n>4)
@@ -1433,22 +1440,22 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 1 unmodified line
14331440 #ifdef TCC_ARM_EABI
14341441 n=(n+1)&-2;
14351442 #endif
1436− o(S, 0xE92D0000|((1<<n)-1)); /* save r0-r4 on stack if needed */
1443+ o(0xE92D0000|((1<<n)-1)); /* save r0-r4 on stack if needed */
14371444 }
14381445 if (nf) {
14391446 if (nf>16)
14401447 nf=16;
14411448 nf=(nf+1)&-2; /* nf => HARDFLOAT => EABI */
1442− o(S, 0xED2D0A00|nf); /* save s0-s15 on stack if needed */
1449+ o(0xED2D0A00|nf); /* save s0-s15 on stack if needed */
14431450 }
1444− o(S, 0xE92D5800); /* save fp, ip, lr */
1445− o(S, 0xE1A0B00D); /* mov fp, sp */
1446− func_sub_sp_offset = S->tccgen_ind;
1447− o(S, 0xE1A00000); /* nop, leave space for stack adjustment in epilog */
1451+ o(0xE92D5800); /* save fp, ip, lr */
1452+ o(0xE1A0B00D); /* mov fp, sp */
1453+ func_sub_sp_offset = ind;
1454+ o(0xE1A00000); /* nop, leave space for stack adjustment in epilog */
14481455
14491456 #ifdef TCC_ARM_EABI
14501457 if (float_abi == ARM_HARD_FLOAT) {
1451− S->tccgen_func_vc += nf * 4;
1458+ func_vc += nf * 4;
14521459 memset(&avregs, 0, sizeof avregs);
14531460 }
14541461 #endif
@@ -1460,7 +1467,7 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 5 unmodified lines
14601467 size = (size + 3) >> 2;
14611468 align = (align + 3) & ~3;
14621469 #ifdef TCC_ARM_EABI
1463− if (float_abi == ARM_HARD_FLOAT && !S->tccgen_func_var && (is_float(sym->type.t)
1470+ if (float_abi == ARM_HARD_FLOAT && !func_var && (is_float(sym->type.t)
14641471 || is_hgen_float_aggr(&sym->type))) {
14651472 int fpn = assign_vfpreg(&avregs, align, size << 2);
14661473 if (fpn >= 0)
@@ -1485,42 +1492,42 @@ from_stack: · 18 unmodified lines
14851492 addr = (n + nf + sn) * 4;
14861493 sn += size;
14871494 }
1488− sym_push(S, sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL,
1495+ sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL,
14891496 addr + 12);
14901497 }
14911498 last_itod_magic=0;
14921499 leaffunc = 1;
1493− S->tccgen_loc = 0;
1500+ loc = 0;
14941501 #ifdef CONFIG_TCC_BCHECK
1495− if (S->do_bounds_check)
1496− gen_bounds_prolog(S);
1502+ if (tcc_state->do_bounds_check)
1503+ gen_bounds_prolog();
14971504 #endif
14981505 }
14991506
15001507 /* generate function epilog */
1501−void gfunc_epilog(TCCState* S)
1508+void gfunc_epilog(void)
15021509 {
15031510 uint32_t x;
15041511 int diff;
15051512
15061513 #ifdef CONFIG_TCC_BCHECK
1507− if (S->do_bounds_check)
1508− gen_bounds_epilog(S);
1514+ if (tcc_state->do_bounds_check)
1515+ gen_bounds_epilog();
15091516 #endif
15101517 /* Copy float return value to core register if base standard is used and
15111518 float computation is made with VFP */
15121519 #if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
1513− if ((float_abi == ARM_SOFTFP_FLOAT || S->tccgen_func_var) && is_float(S->tccgen_func_vt.t)) {
1514− if((S->tccgen_func_vt.t & VT_BTYPE) == VT_FLOAT)
1515− o(S, 0xEE100A10); /* fmrs r0, s0 */
1520+ if ((float_abi == ARM_SOFTFP_FLOAT || func_var) && is_float(func_vt.t)) {
1521+ if((func_vt.t & VT_BTYPE) == VT_FLOAT)
1522+ o(0xEE100A10); /* fmrs r0, s0 */
15161523 else {
1517− o(S, 0xEE100B10); /* fmrdl r0, d0 */
1518− o(S, 0xEE301B10); /* fmrdh r1, d0 */
1524+ o(0xEE100B10); /* fmrdl r0, d0 */
1525+ o(0xEE301B10); /* fmrdh r1, d0 */
15191526 }
15201527 }
15211528 #endif
1522− o(S, 0xE89BA800); /* restore fp, sp, pc */
1523− diff = (-S->tccgen_loc + 3) & -4;
1529+ o(0xE89BA800); /* restore fp, sp, pc */
1530+ diff = (-loc + 3) & -4;
15241531 #ifdef TCC_ARM_EABI
15251532 if(!leaffunc)
15261533 diff = ((diff + 11) & -8) - 4;
@@ -1531,74 +1538,74 @@ void gfunc_epilog(TCCState* S) · 4 unmodified lines
15311538 *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = x;
15321539 else {
15331540 int addr;
1534− addr=S->tccgen_ind;
1535− o(S, 0xE59FC004); /* ldr ip,[pc+4] */
1536− o(S, 0xE04BD00C); /* sub sp,fp,ip */
1537− o(S, 0xE1A0F00E); /* mov pc,lr */
1538− o(S, diff);
1539− *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(S, func_sub_sp_offset,addr,1);
1541+ addr=ind;
1542+ o(0xE59FC004); /* ldr ip,[pc+4] */
1543+ o(0xE04BD00C); /* sub sp,fp,ip */
1544+ o(0xE1A0F00E); /* mov pc,lr */
1545+ o(diff);
1546+ *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(func_sub_sp_offset,addr,1);
15401547 }
15411548 }
15421549 }
15431550
1544−ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
1551+ST_FUNC void gen_fill_nops(int bytes)
15451552 {
15461553 if ((bytes & 3))
1547− tcc_error(S, "alignment of code section not multiple of 4");
1554+ tcc_error("alignment of code section not multiple of 4");
15481555 while (bytes > 0) {
1549− o(S, 0xE1A00000);
1556+ o(0xE1A00000);
15501557 bytes -= 4;
15511558 }
15521559 }
15531560
15541561 /* generate a jump to a label */
1555−ST_FUNC int gjmp(TCCState* S, int t)
1562+ST_FUNC int gjmp(int t)
15561563 {
15571564 int r;
1558− if (S->tccgen_nocode_wanted)
1565+ if (nocode_wanted)
15591566 return t;
1560− r=S->tccgen_ind;
1561− o(S, 0xE0000000|encbranch(S, r,t,1));
1567+ r=ind;
1568+ o(0xE0000000|encbranch(r,t,1));
15621569 return r;
15631570 }
15641571
15651572 /* generate a jump to a fixed address */
1566−ST_FUNC void gjmp_addr(TCCState* S, int a)
1573+ST_FUNC void gjmp_addr(int a)
15671574 {
1568− gjmp(S, a);
1575+ gjmp(a);
15691576 }
15701577
1571−ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
1578+ST_FUNC int gjmp_cond(int op, int t)
15721579 {
15731580 int r;
1574− if (S->tccgen_nocode_wanted)
1581+ if (nocode_wanted)
15751582 return t;
1576− r=S->tccgen_ind;
1577− op=mapcc(S, op);
1578− op|=encbranch(S, r,t,1);
1579− o(S, op);
1583+ r=ind;
1584+ op=mapcc(op);
1585+ op|=encbranch(r,t,1);
1586+ o(op);
15801587 return r;
15811588 }
15821589
1583−ST_FUNC int gjmp_append(TCCState* S, int n, int t)
1590+ST_FUNC int gjmp_append(int n, int t)
15841591 {
15851592 uint32_t *x;
15861593 int p,lp;
15871594 if(n) {
15881595 p = n;
15891596 do {
1590− p = decbranch(S, lp=p);
1597+ p = decbranch(lp=p);
15911598 } while(p);
15921599 x = (uint32_t *)(cur_text_section->data + lp);
15931600 *x &= 0xff000000;
1594− *x |= encbranch(S, lp,t,1);
1601+ *x |= encbranch(lp,t,1);
15951602 t = n;
15961603 }
15971604 return t;
15981605 }
15991606
16001607 /* generate an integer binary operation */
1601−void gen_opi(TCCState* S, int op)
1608+void gen_opi(int op)
16021609 {
16031610 int c, func = 0;
16041611 uint32_t opc = 0, r, fr;
@@ -1643,11 +1650,11 @@ void gen_opi(TCCState* S, int op) · 38 unmodified lines
16431650 c=1;
16441651 break;
16451652 case '*':
1646− gv2(S, RC_INT, RC_INT);
1647− r = S->tccgen_vtop[-1].r;
1648− fr = S->tccgen_vtop[0].r;
1649− S->tccgen_vtop--;
1650− o(S, 0xE0000090|(intr(S, r)<<16)|(intr(S, r)<<8)|intr(S, fr));
1653+ gv2(RC_INT, RC_INT);
1654+ r = vtop[-1].r;
1655+ fr = vtop[0].r;
1656+ vtop--;
1657+ o(0xE0000090|(intr(r)<<16)|(intr(r)<<8)|intr(fr));
16511658 return;
16521659 case TOK_SHL:
16531660 opc = 0;
@@ -1689,12 +1696,12 @@ void gen_opi(TCCState* S, int op) · 35 unmodified lines
16891696 c=3;
16901697 break;
16911698 case TOK_UMULL:
1692− gv2(S, RC_INT, RC_INT);
1693− r=intr(S, S->tccgen_vtop[-1].r2=get_reg(S, RC_INT));
1694− c=S->tccgen_vtop[-1].r;
1695− S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, c));
1696− S->tccgen_vtop--;
1697− o(S, 0xE0800090|(r<<16)|(intr(S, S->tccgen_vtop->r)<<12)|(intr(S, c)<<8)|intr(S, S->tccgen_vtop[1].r));
1699+ gv2(RC_INT, RC_INT);
1700+ r=intr(vtop[-1].r2=get_reg(RC_INT));
1701+ c=vtop[-1].r;
1702+ vtop[-1].r=get_reg_ex(RC_INT,regmask(c));
1703+ vtop--;
1704+ o(0xE0800090|(r<<16)|(intr(vtop->r)<<12)|(intr(c)<<8)|intr(vtop[1].r));
16981705 return;
16991706 default:
17001707 opc = 0x15;
@@ -1703,128 +1710,128 @@ void gen_opi(TCCState* S, int op) · 2 unmodified lines
17031710 }
17041711 switch(c) {
17051712 case 1:
1706− if((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1713+ if((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
17071714 if(opc == 4 || opc == 5 || opc == 0xc) {
1708− vswap(S);
1715+ vswap();
17091716 opc|=2; // sub -> rsb
17101717 }
17111718 }
1712− if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP ||
1713− (S->tccgen_vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
1714− gv(S, RC_INT);
1715− vswap(S);
1716− c=intr(S, gv(S, RC_INT));
1717− vswap(S);
1719+ if ((vtop->r & VT_VALMASK) == VT_CMP ||
1720+ (vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
1721+ gv(RC_INT);
1722+ vswap();
1723+ c=intr(gv(RC_INT));
1724+ vswap();
17181725 opc=0xE0000000|(opc<<20);
1719− if((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1726+ if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
17201727 uint32_t x;
1721− x=stuff_const(opc|0x2000000|(c<<16),S->tccgen_vtop->c.i);
1728+ x=stuff_const(opc|0x2000000|(c<<16),vtop->c.i);
17221729 if(x) {
17231730 if ((x & 0xfff00000) == 0xe3500000) // cmp rx,#c
1724− o(S, x);
1731+ o(x);
17251732 else {
1726− r=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, S->tccgen_vtop[-1].r)));
1727− o(S, x|(r<<12));
1733+ r=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r)));
1734+ o(x|(r<<12));
17281735 }
17291736 goto done;
17301737 }
17311738 }
1732− fr=intr(S, gv(S, RC_INT));
1739+ fr=intr(gv(RC_INT));
17331740 #ifdef CONFIG_TCC_BCHECK
1734− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1735− vswap(S);
1736− c=intr(S, gv(S, RC_INT));
1737− vswap(S);
1741+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1742+ vswap();
1743+ c=intr(gv(RC_INT));
1744+ vswap();
17381745 }
17391746 #endif
17401747 if ((opc & 0xfff00000) == 0xe1500000) // cmp rx,ry
1741− o(S, opc|(c<<16)|fr);
1748+ o(opc|(c<<16)|fr);
17421749 else {
1743− r=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,two2mask(S, S->tccgen_vtop->r,S->tccgen_vtop[-1].r)));
1744− o(S, opc|(c<<16)|(r<<12)|fr);
1750+ r=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r)));
1751+ o(opc|(c<<16)|(r<<12)|fr);
17451752 }
17461753 done:
1747− S->tccgen_vtop--;
1754+ vtop--;
17481755 if (op >= TOK_ULT && op <= TOK_GT)
1749− vset_VT_CMP(S, op);
1756+ vset_VT_CMP(op);
17501757 break;
17511758 case 2:
17521759 opc=0xE1A00000|(opc<<5);
1753− if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP ||
1754− (S->tccgen_vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
1755− gv(S, RC_INT);
1756− vswap(S);
1757− r=intr(S, gv(S, RC_INT));
1758− vswap(S);
1759− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1760− fr=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, S->tccgen_vtop[-1].r)));
1761− c = S->tccgen_vtop->c.i & 0x1f;
1762− o(S, opc|r|(c<<7)|(fr<<12));
1760+ if ((vtop->r & VT_VALMASK) == VT_CMP ||
1761+ (vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
1762+ gv(RC_INT);
1763+ vswap();
1764+ r=intr(gv(RC_INT));
1765+ vswap();
1766+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1767+ fr=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r)));
1768+ c = vtop->c.i & 0x1f;
1769+ o(opc|r|(c<<7)|(fr<<12));
17631770 } else {
1764− fr=intr(S, gv(S, RC_INT));
1771+ fr=intr(gv(RC_INT));
17651772 #ifdef CONFIG_TCC_BCHECK
1766− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1767− vswap(S);
1768− r=intr(S, gv(S, RC_INT));
1769− vswap(S);
1773+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1774+ vswap();
1775+ r=intr(gv(RC_INT));
1776+ vswap();
17701777 }
17711778 #endif
1772− c=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,two2mask(S, S->tccgen_vtop->r,S->tccgen_vtop[-1].r)));
1773− o(S, opc|r|(c<<12)|(fr<<8)|0x10);
1779+ c=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r)));
1780+ o(opc|r|(c<<12)|(fr<<8)|0x10);
17741781 }
1775− S->tccgen_vtop--;
1782+ vtop--;
17761783 break;
17771784 case 3:
1778− vpush_helper_func(S, func);
1779− vrott(S, 3);
1780− gfunc_call(S, 2);
1781− vpushi(S, 0);
1782− S->tccgen_vtop->r = retreg;
1785+ vpush_helper_func(func);
1786+ vrott(3);
1787+ gfunc_call(2);
1788+ vpushi(0);
1789+ vtop->r = retreg;
17831790 break;
17841791 default:
1785− tcc_error(S, "gen_opi %i unimplemented!",op);
1792+ tcc_error("gen_opi %i unimplemented!",op);
17861793 }
17871794 }
17881795
17891796 #ifdef TCC_ARM_VFP
1790−static int is_zero(TCCState* S, int i)
1797+static int is_zero(int i)
17911798 {
1792− if((S->tccgen_vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
1799+ if((vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
17931800 return 0;
1794− if (S->tccgen_vtop[i].type.t == VT_FLOAT)
1795− return (S->tccgen_vtop[i].c.f == 0.f);
1796− else if (S->tccgen_vtop[i].type.t == VT_DOUBLE)
1797− return (S->tccgen_vtop[i].c.d == 0.0);
1798− return (S->tccgen_vtop[i].c.ld == 0.l);
1801+ if (vtop[i].type.t == VT_FLOAT)
1802+ return (vtop[i].c.f == 0.f);
1803+ else if (vtop[i].type.t == VT_DOUBLE)
1804+ return (vtop[i].c.d == 0.0);
1805+ return (vtop[i].c.ld == 0.l);
17991806 }
18001807
18011808 /* generate a floating point operation 'v = t1 op t2' instruction. The
18021809 * two operands are guaranteed to have the same floating point type */
1803−void gen_opf(TCCState* S, int op)
1810+void gen_opf(int op)
18041811 {
18051812 uint32_t x;
18061813 int fneg=0,r;
1807− x=0xEE000A00|T2CPR(S->tccgen_vtop->type.t);
1814+ x=0xEE000A00|T2CPR(vtop->type.t);
18081815 switch(op) {
18091816 case '+':
1810− if(is_zero(S, -1))
1811− vswap(S);
1812− if(is_zero(S, 0)) {
1813− S->tccgen_vtop--;
1817+ if(is_zero(-1))
1818+ vswap();
1819+ if(is_zero(0)) {
1820+ vtop--;
18141821 return;
18151822 }
18161823 x|=0x300000;
18171824 break;
18181825 case '-':
18191826 x|=0x300040;
1820− if(is_zero(S, 0)) {
1821− S->tccgen_vtop--;
1827+ if(is_zero(0)) {
1828+ vtop--;
18221829 return;
18231830 }
1824− if(is_zero(S, -1)) {
1831+ if(is_zero(-1)) {
18251832 x|=0x810000; /* fsubX -> fnegX */
1826− vswap(S);
1827− S->tccgen_vtop--;
1833+ vswap();
1834+ vtop--;
18281835 fneg=1;
18291836 }
18301837 break;
@@ -1836,11 +1843,11 @@ void gen_opf(TCCState* S, int op) · 5 unmodified lines
18361843 break;
18371844 default:
18381845 if(op < TOK_ULT || op > TOK_GT) {
1839− tcc_error(S, "unknown fp op %x!",op);
1846+ tcc_error("unknown fp op %x!",op);
18401847 return;
18411848 }
1842− if(is_zero(S, -1)) {
1843− vswap(S);
1849+ if(is_zero(-1)) {
1850+ vswap();
18441851 switch(op) {
18451852 case TOK_LT: op=TOK_GT; break;
18461853 case TOK_GE: op=TOK_ULE; break;
@@ -1851,16 +1858,16 @@ void gen_opf(TCCState* S, int op) · 4 unmodified lines
18511858 x|=0xB40040; /* fcmpX */
18521859 if(op!=TOK_EQ && op!=TOK_NE)
18531860 x|=0x80; /* fcmpX -> fcmpeX */
1854− if(is_zero(S, 0)) {
1855− S->tccgen_vtop--;
1856− o(S, x|0x10000|(vfpr(S, gv(S, RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */
1861+ if(is_zero(0)) {
1862+ vtop--;
1863+ o(x|0x10000|(vfpr(gv(RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */
18571864 } else {
1858− gv2(S, RC_FLOAT,RC_FLOAT);
1859− x|=vfpr(S, S->tccgen_vtop[0].r);
1860− o(S, x|(vfpr(S, S->tccgen_vtop[-1].r) << 12));
1861− S->tccgen_vtop--;
1865+ gv2(RC_FLOAT,RC_FLOAT);
1866+ x|=vfpr(vtop[0].r);
1867+ o(x|(vfpr(vtop[-1].r) << 12));
1868+ vtop--;
18621869 }
1863− o(S, 0xEEF1FA10); /* fmstat */
1870+ o(0xEEF1FA10); /* fmstat */
18641871
18651872 switch(op) {
18661873 case TOK_LE: op=TOK_ULE; break;
@@ -1868,46 +1875,46 @@ void gen_opf(TCCState* S, int op) · 1 unmodified line
18681875 case TOK_UGE: op=TOK_GE; break;
18691876 case TOK_UGT: op=TOK_GT; break;
18701877 }
1871− vset_VT_CMP(S, op);
1878+ vset_VT_CMP(op);
18721879 return;
18731880 }
1874− r=gv(S, RC_FLOAT);
1875− x|=vfpr(S, r);
1876− r=regmask(S, r);
1881+ r=gv(RC_FLOAT);
1882+ x|=vfpr(r);
1883+ r=regmask(r);
18771884 if(!fneg) {
18781885 int r2;
1879− vswap(S);
1880− r2=gv(S, RC_FLOAT);
1881− x|=vfpr(S, r2)<<16;
1882− r|=regmask(S, r2);
1886+ vswap();
1887+ r2=gv(RC_FLOAT);
1888+ x|=vfpr(r2)<<16;
1889+ r|=regmask(r2);
18831890 #ifdef CONFIG_TCC_BCHECK
1884− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1885− vswap(S);
1886− r=gv(S, RC_FLOAT);
1887− vswap(S);
1888− x=(x&~0xf)|vfpr(S, r);
1891+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1892+ vswap();
1893+ r=gv(RC_FLOAT);
1894+ vswap();
1895+ x=(x&~0xf)|vfpr(r);
18891896 }
18901897 #endif
18911898 }
1892− S->tccgen_vtop->r=get_reg_ex(S, RC_FLOAT,r);
1899+ vtop->r=get_reg_ex(RC_FLOAT,r);
18931900 if(!fneg)
1894− S->tccgen_vtop--;
1895− o(S, x|(vfpr(S, S->tccgen_vtop->r)<<12));
1901+ vtop--;
1902+ o(x|(vfpr(vtop->r)<<12));
18961903 }
18971904
18981905 #else
1899−static uint32_t is_fconst(TCCState* S)
1906+static uint32_t is_fconst()
19001907 {
19011908 long double f;
19021909 uint32_t r;
1903− if((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
1910+ if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
19041911 return 0;
1905− if (S->tccgen_vtop->type.t == VT_FLOAT)
1906− f = S->tccgen_vtop->c.f;
1907− else if (S->tccgen_vtop->type.t == VT_DOUBLE)
1908− f = S->tccgen_vtop->c.d;
1912+ if (vtop->type.t == VT_FLOAT)
1913+ f = vtop->c.f;
1914+ else if (vtop->type.t == VT_DOUBLE)
1915+ f = vtop->c.d;
19091916 else
1910− f = S->tccgen_vtop->c.ld;
1917+ f = vtop->c.ld;
19111918 if(!ieee_finite(f))
19121919 return 0;
19131920 r=0x8;
@@ -1936,45 +1943,45 @@ static uint32_t is_fconst(TCCState* S) · 22 unmodified lines
19361943
19371944 /* generate a floating point operation 'v = t1 op t2' instruction. The
19381945 two operands are guaranteed to have the same floating point type */
1939−void gen_opf(TCCState* S, int op)
1946+void gen_opf(int op)
19401947 {
19411948 uint32_t x, r, r2, c1, c2;
19421949 //fputs("gen_opf\n",stderr);
1943− vswap(S);
1944− c1 = is_fconst(S);
1945− vswap(S);
1946− c2 = is_fconst(S);
1950+ vswap();
1951+ c1 = is_fconst();
1952+ vswap();
1953+ c2 = is_fconst();
19471954 x=0xEE000100;
19481955 #if LDOUBLE_SIZE == 8
1949− if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FLOAT)
1956+ if ((vtop->type.t & VT_BTYPE) != VT_FLOAT)
19501957 x|=0x80;
19511958 #else
1952− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE)
1959+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
19531960 x|=0x80;
1954− else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE)
1961+ else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE)
19551962 x|=0x80000;
19561963 #endif
19571964 switch(op)
19581965 {
19591966 case '+':
19601967 if(!c2) {
1961− vswap(S);
1968+ vswap();
19621969 c2=c1;
19631970 }
1964− vswap(S);
1965− r=fpr(S, gv(S, RC_FLOAT));
1966− vswap(S);
1971+ vswap();
1972+ r=fpr(gv(RC_FLOAT));
1973+ vswap();
19671974 if(c2) {
19681975 if(c2>0xf)
19691976 x|=0x200000; // suf
19701977 r2=c2&0xf;
19711978 } else {
1972− r2=fpr(S, gv(S, RC_FLOAT));
1979+ r2=fpr(gv(RC_FLOAT));
19731980 #ifdef CONFIG_TCC_BCHECK
1974− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1975− vswap(S);
1976− r=fpr(S, gv(S, RC_FLOAT));
1977− vswap(S);
1981+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
1982+ vswap();
1983+ r=fpr(gv(RC_FLOAT));
1984+ vswap();
19781985 }
19791986 #endif
19801987 }
@@ -1984,46 +1991,46 @@ void gen_opf(TCCState* S, int op) · 3 unmodified lines
19841991 if(c2<=0xf)
19851992 x|=0x200000; // suf
19861993 r2=c2&0xf;
1987− vswap(S);
1988− r=fpr(S, gv(S, RC_FLOAT));
1989− vswap(S);
1994+ vswap();
1995+ r=fpr(gv(RC_FLOAT));
1996+ vswap();
19901997 } else if(c1 && c1<=0xf) {
19911998 x|=0x300000; // rsf
19921999 r2=c1;
1993− r=fpr(S, gv(S, RC_FLOAT));
1994− vswap(S);
2000+ r=fpr(gv(RC_FLOAT));
2001+ vswap();
19952002 } else {
19962003 x|=0x200000; // suf
1997− vswap(S);
1998− r=fpr(S, gv(S, RC_FLOAT));
1999− vswap(S);
2000− r2=fpr(S, gv(S, RC_FLOAT));
2004+ vswap();
2005+ r=fpr(gv(RC_FLOAT));
2006+ vswap();
2007+ r2=fpr(gv(RC_FLOAT));
20012008 #ifdef CONFIG_TCC_BCHECK
2002− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2003− vswap(S);
2004− r=fpr(S, gv(S, RC_FLOAT));
2005− vswap(S);
2009+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2010+ vswap();
2011+ r=fpr(gv(RC_FLOAT));
2012+ vswap();
20062013 }
20072014 #endif
20082015 }
20092016 break;
20102017 case '*':
20112018 if(!c2 || c2>0xf) {
2012− vswap(S);
2019+ vswap();
20132020 c2=c1;
20142021 }
2015− vswap(S);
2016− r=fpr(S, gv(S, RC_FLOAT));
2017− vswap(S);
2022+ vswap();
2023+ r=fpr(gv(RC_FLOAT));
2024+ vswap();
20182025 if(c2 && c2<=0xf)
20192026 r2=c2;
20202027 else {
2021− r2=fpr(S, gv(S, RC_FLOAT));
2028+ r2=fpr(gv(RC_FLOAT));
20222029 #ifdef CONFIG_TCC_BCHECK
2023− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2024− vswap(S);
2025− r=fpr(S, gv(S, RC_FLOAT));
2026− vswap(S);
2030+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2031+ vswap();
2032+ r=fpr(gv(RC_FLOAT));
2033+ vswap();
20272034 }
20282035 #endif
20292036 }
@@ -2033,25 +2040,25 @@ void gen_opf(TCCState* S, int op) · 3 unmodified lines
20332040 if(c2 && c2<=0xf) {
20342041 x|=0x400000; // dvf
20352042 r2=c2;
2036− vswap(S);
2037− r=fpr(S, gv(S, RC_FLOAT));
2038− vswap(S);
2043+ vswap();
2044+ r=fpr(gv(RC_FLOAT));
2045+ vswap();
20392046 } else if(c1 && c1<=0xf) {
20402047 x|=0x500000; // rdf
20412048 r2=c1;
2042− r=fpr(S, gv(S, RC_FLOAT));
2043− vswap(S);
2049+ r=fpr(gv(RC_FLOAT));
2050+ vswap();
20442051 } else {
20452052 x|=0x400000; // dvf
2046− vswap(S);
2047− r=fpr(S, gv(S, RC_FLOAT));
2048− vswap(S);
2049− r2=fpr(S, gv(S, RC_FLOAT));
2053+ vswap();
2054+ r=fpr(gv(RC_FLOAT));
2055+ vswap();
2056+ r2=fpr(gv(RC_FLOAT));
20502057 #ifdef CONFIG_TCC_BCHECK
2051− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2052− vswap(S);
2053− r=fpr(S, gv(S, RC_FLOAT));
2054− vswap(S);
2058+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2059+ vswap();
2060+ r=fpr(gv(RC_FLOAT));
2061+ vswap();
20552062 }
20562063 #endif
20572064 }
@@ -2066,7 +2073,7 @@ void gen_opf(TCCState* S, int op) · 8 unmodified lines
20662073 case TOK_UGE:
20672074 case TOK_ULE:
20682075 case TOK_UGT:
2069− tcc_error(S, "unsigned comparison on floats?");
2076+ tcc_error("unsigned comparison on floats?");
20702077 break;
20712078 case TOK_LT:
20722079 op=TOK_Nset;
@@ -2081,7 +2088,7 @@ void gen_opf(TCCState* S, int op) · 8 unmodified lines
20812088 }
20822089 if(c1 && !c2) {
20832090 c2=c1;
2084− vswap(S);
2091+ vswap();
20852092 switch(op) {
20862093 case TOK_Nset:
20872094 op=TOK_GT;
@@ -2097,86 +2104,86 @@ void gen_opf(TCCState* S, int op) · 9 unmodified lines
20972104 break;
20982105 }
20992106 }
2100− vswap(S);
2101− r=fpr(S, gv(S, RC_FLOAT));
2102− vswap(S);
2107+ vswap();
2108+ r=fpr(gv(RC_FLOAT));
2109+ vswap();
21032110 if(c2) {
21042111 if(c2>0xf)
21052112 x|=0x200000;
21062113 r2=c2&0xf;
21072114 } else {
2108− r2=fpr(S, gv(S, RC_FLOAT));
2115+ r2=fpr(gv(RC_FLOAT));
21092116 #ifdef CONFIG_TCC_BCHECK
2110− if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2111− vswap(S);
2112− r=fpr(S, gv(S, RC_FLOAT));
2113− vswap(S);
2117+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
2118+ vswap();
2119+ r=fpr(gv(RC_FLOAT));
2120+ vswap();
21142121 }
21152122 #endif
21162123 }
2117− --S->tccgen_vtop;
2118− vset_VT_CMP(S, op);
2119− ++S->tccgen_vtop;
2124+ --vtop;
2125+ vset_VT_CMP(op);
2126+ ++vtop;
21202127 } else {
2121− tcc_error(S, "unknown fp op %x!",op);
2128+ tcc_error("unknown fp op %x!",op);
21222129 return;
21232130 }
21242131 }
2125− if(S->tccgen_vtop[-1].r == VT_CMP)
2132+ if(vtop[-1].r == VT_CMP)
21262133 c1=15;
21272134 else {
2128− c1=S->tccgen_vtop->r;
2135+ c1=vtop->r;
21292136 if(r2&0x8)
2130− c1=S->tccgen_vtop[-1].r;
2131− S->tccgen_vtop[-1].r=get_reg_ex(S, RC_FLOAT,two2mask(S, S->tccgen_vtop[-1].r,c1));
2132− c1=fpr(S, S->tccgen_vtop[-1].r);
2137+ c1=vtop[-1].r;
2138+ vtop[-1].r=get_reg_ex(RC_FLOAT,two2mask(vtop[-1].r,c1));
2139+ c1=fpr(vtop[-1].r);
21332140 }
2134− S->tccgen_vtop--;
2135− o(S, x|(r<<16)|(c1<<12)|r2);
2141+ vtop--;
2142+ o(x|(r<<16)|(c1<<12)|r2);
21362143 }
21372144 #endif
21382145
21392146 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
21402147 and 'long long' cases. */
2141−ST_FUNC void gen_cvt_itof(TCCState* S, int t)
2148+ST_FUNC void gen_cvt_itof(int t)
21422149 {
21432150 uint32_t r, r2;
21442151 int bt;
2145− bt=S->tccgen_vtop->type.t & VT_BTYPE;
2152+ bt=vtop->type.t & VT_BTYPE;
21462153 if(bt == VT_INT || bt == VT_SHORT || bt == VT_BYTE) {
21472154 #ifndef TCC_ARM_VFP
21482155 uint32_t dsize = 0;
21492156 #endif
2150− r=intr(S, gv(S, RC_INT));
2157+ r=intr(gv(RC_INT));
21512158 #ifdef TCC_ARM_VFP
2152− r2=vfpr(S, S->tccgen_vtop->r=get_reg(S, RC_FLOAT));
2153− o(S, 0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */
2159+ r2=vfpr(vtop->r=get_reg(RC_FLOAT));
2160+ o(0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */
21542161 r2|=r2<<12;
2155− if(!(S->tccgen_vtop->type.t & VT_UNSIGNED))
2162+ if(!(vtop->type.t & VT_UNSIGNED))
21562163 r2|=0x80; /* fuitoX -> fsituX */
2157− o(S, 0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/
2164+ o(0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/
21582165 #else
2159− r2=fpr(S, S->tccgen_vtop->r=get_reg(S, RC_FLOAT));
2166+ r2=fpr(vtop->r=get_reg(RC_FLOAT));
21602167 if((t & VT_BTYPE) != VT_FLOAT)
21612168 dsize=0x80; /* flts -> fltd */
2162− o(S, 0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */
2163− if((S->tccgen_vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) {
2169+ o(0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */
2170+ if((vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) {
21642171 uint32_t off = 0;
2165− o(S, 0xE3500000|(r<<12)); /* cmp */
2166− r=fpr(S, get_reg(S, RC_FLOAT));
2172+ o(0xE3500000|(r<<12)); /* cmp */
2173+ r=fpr(get_reg(RC_FLOAT));
21672174 if(last_itod_magic) {
2168− off=S->tccgen_ind+8-last_itod_magic;
2175+ off=ind+8-last_itod_magic;
21692176 off/=4;
21702177 if(off>255)
21712178 off=0;
21722179 }
2173− o(S, 0xBD1F0100|(r<<12)|off); /* ldflts */
2180+ o(0xBD1F0100|(r<<12)|off); /* ldflts */
21742181 if(!off) {
2175− o(S, 0xEA000000); /* b */
2176− last_itod_magic=S->tccgen_ind;
2177− o(S, 0x4F800000); /* 4294967296.0f */
2182+ o(0xEA000000); /* b */
2183+ last_itod_magic=ind;
2184+ o(0x4F800000); /* 4294967296.0f */
21782185 }
2179− o(S, 0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */
2186+ o(0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */
21802187 }
21812188 #endif
21822189 return;
@@ -2184,15 +2191,15 @@ ST_FUNC void gen_cvt_itof(TCCState* S, int t) · 1 unmodified line
21842191 int func;
21852192 CType *func_type = 0;
21862193 if((t & VT_BTYPE) == VT_FLOAT) {
2187− func_type = &S->armgen_func_float_type;
2188− if(S->tccgen_vtop->type.t & VT_UNSIGNED)
2194+ func_type = &func_float_type;
2195+ if(vtop->type.t & VT_UNSIGNED)
21892196 func=TOK___floatundisf;
21902197 else
21912198 func=TOK___floatdisf;
21922199 #if LDOUBLE_SIZE != 8
21932200 } else if((t & VT_BTYPE) == VT_LDOUBLE) {
2194− func_type = &S->armgen_func_ldouble_type;
2195− if(S->tccgen_vtop->type.t & VT_UNSIGNED)
2201+ func_type = &func_ldouble_type;
2202+ if(vtop->type.t & VT_UNSIGNED)
21962203 func=TOK___floatundixf;
21972204 else
21982205 func=TOK___floatdixf;
@@ -2200,39 +2207,39 @@ ST_FUNC void gen_cvt_itof(TCCState* S, int t) · 1 unmodified line
22002207 #else
22012208 } else if((t & VT_BTYPE) == VT_DOUBLE || (t & VT_BTYPE) == VT_LDOUBLE) {
22022209 #endif
2203− func_type = &S->armgen_func_double_type;
2204− if(S->tccgen_vtop->type.t & VT_UNSIGNED)
2210+ func_type = &func_double_type;
2211+ if(vtop->type.t & VT_UNSIGNED)
22052212 func=TOK___floatundidf;
22062213 else
22072214 func=TOK___floatdidf;
22082215 }
22092216 if(func_type) {
2210− vpushsym(S, func_type, external_helper_sym(S, func));
2211− vswap(S);
2212− gfunc_call(S, 1);
2213− vpushi(S, 0);
2214− S->tccgen_vtop->r=TREG_F0;
2217+ vpushsym(func_type, external_helper_sym(func));
2218+ vswap();
2219+ gfunc_call(1);
2220+ vpushi(0);
2221+ vtop->r=TREG_F0;
22152222 return;
22162223 }
22172224 }
2218− tcc_error(S, "unimplemented gen_cvt_itof %x!",S->tccgen_vtop->type.t);
2225+ tcc_error("unimplemented gen_cvt_itof %x!",vtop->type.t);
22192226 }
22202227
22212228 /* convert fp to int 't' type */
2222−void gen_cvt_ftoi(TCCState* S, int t)
2229+void gen_cvt_ftoi(int t)
22232230 {
22242231 uint32_t r, r2;
22252232 int u, func = 0;
22262233 u=t&VT_UNSIGNED;
22272234 t&=VT_BTYPE;
2228− r2=S->tccgen_vtop->type.t & VT_BTYPE;
2235+ r2=vtop->type.t & VT_BTYPE;
22292236 if(t==VT_INT) {
22302237 #ifdef TCC_ARM_VFP
2231− r=vfpr(S, gv(S, RC_FLOAT));
2238+ r=vfpr(gv(RC_FLOAT));
22322239 u=u?0:0x10000;
2233− o(S, 0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */
2234− r2=intr(S, S->tccgen_vtop->r=get_reg(S, RC_INT));
2235− o(S, 0xEE100A10|(r<<16)|(r2<<12));
2240+ o(0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */
2241+ r2=intr(vtop->r=get_reg(RC_INT));
2242+ o(0xEE100A10|(r<<16)|(r2<<12));
22362243 return;
22372244 #else
22382245 if(u) {
@@ -2247,9 +2254,9 @@ void gen_cvt_ftoi(TCCState* S, int t) · 8 unmodified lines
22472254 #endif
22482255 func=TOK___fixunsdfsi;
22492256 } else {
2250− r=fpr(S, gv(S, RC_FLOAT));
2251− r2=intr(S, S->tccgen_vtop->r=get_reg(S, RC_INT));
2252− o(S, 0xEE100170|(r2<<12)|r);
2257+ r=fpr(gv(RC_FLOAT));
2258+ r2=intr(vtop->r=get_reg(RC_INT));
2259+ o(0xEE100170|(r2<<12)|r);
22532260 return;
22542261 }
22552262 #endif
@@ -2266,93 +2273,93 @@ void gen_cvt_ftoi(TCCState* S, int t) · 10 unmodified lines
22662273 func=TOK___fixdfdi;
22672274 }
22682275 if(func) {
2269− vpush_helper_func(S, func);
2270− vswap(S);
2271− gfunc_call(S, 1);
2272− vpushi(S, 0);
2276+ vpush_helper_func(func);
2277+ vswap();
2278+ gfunc_call(1);
2279+ vpushi(0);
22732280 if(t == VT_LLONG)
2274− S->tccgen_vtop->r2 = REG_IRE2;
2275− S->tccgen_vtop->r = REG_IRET;
2281+ vtop->r2 = REG_IRE2;
2282+ vtop->r = REG_IRET;
22762283 return;
22772284 }
2278− tcc_error(S, "unimplemented gen_cvt_ftoi!");
2285+ tcc_error("unimplemented gen_cvt_ftoi!");
22792286 }
22802287
22812288 /* convert from one floating point type to another */
2282−void gen_cvt_ftof(TCCState* S, int t)
2289+void gen_cvt_ftof(int t)
22832290 {
22842291 #ifdef TCC_ARM_VFP
2285− if(((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) {
2286− uint32_t r = vfpr(S, gv(S, RC_FLOAT));
2287− o(S, 0xEEB70AC0|(r<<12)|r|T2CPR(S->tccgen_vtop->type.t));
2292+ if(((vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) {
2293+ uint32_t r = vfpr(gv(RC_FLOAT));
2294+ o(0xEEB70AC0|(r<<12)|r|T2CPR(vtop->type.t));
22882295 }
22892296 #else
22902297 /* all we have to do on i386 and FPA ARM is to put the float in a register */
2291− gv(S, RC_FLOAT);
2298+ gv(RC_FLOAT);
22922299 #endif
22932300 }
22942301
22952302 /* increment tcov counter */
2296−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
2303+ST_FUNC void gen_increment_tcov (SValue *sv)
22972304 {
22982305 int r1, r2;
22992306
2300− vpushv(S, sv);
2301− S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
2302− r2 = get_reg(S, RC_INT);
2303− o(S, 0xE59F0000 | (intr(S, r1)<<12)); // ldr r1,[pc]
2304− o(S, 0xEA000000); // b $+4
2305− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_ARM_REL32);
2306− o(S, -12);
2307− o(S, 0xe080000f | (intr(S, r1)<<16) | (intr(S, r1)<<12)); // add r1,r1,pc
2308− o(S, 0xe5900000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // ldr r2, [r1]
2309− o(S, 0xe2900001 | (intr(S, r2)<<16) | (intr(S, r2)<<12)); // adds r2, r2, #1
2310− o(S, 0xe5800000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // str r2, [r1]
2311− o(S, 0xe2800004 | (intr(S, r1)<<16) | (intr(S, r1)<<12)); // add r1, r1, #4
2312− o(S, 0xe5900000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // ldr r2, [r1]
2313− o(S, 0xe2a00000 | (intr(S, r2)<<16) | (intr(S, r2)<<12)); // adc r2, r2, #0
2314− o(S, 0xe5800000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // str r2, [r1]
2315− vpop(S);
2307+ vpushv(sv);
2308+ vtop->r = r1 = get_reg(RC_INT);
2309+ r2 = get_reg(RC_INT);
2310+ o(0xE59F0000 | (intr(r1)<<12)); // ldr r1,[pc]
2311+ o(0xEA000000); // b $+4
2312+ greloc(cur_text_section, sv->sym, ind, R_ARM_REL32);
2313+ o(-12);
2314+ o(0xe080000f | (intr(r1)<<16) | (intr(r1)<<12)); // add r1,r1,pc
2315+ o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1]
2316+ o(0xe2900001 | (intr(r2)<<16) | (intr(r2)<<12)); // adds r2, r2, #1
2317+ o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1]
2318+ o(0xe2800004 | (intr(r1)<<16) | (intr(r1)<<12)); // add r1, r1, #4
2319+ o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1]
2320+ o(0xe2a00000 | (intr(r2)<<16) | (intr(r2)<<12)); // adc r2, r2, #0
2321+ o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1]
2322+ vpop();
23162323 }
23172324
23182325 /* computed goto support */
2319−void ggoto(TCCState* S)
2326+void ggoto(void)
23202327 {
2321− gcall_or_jmp(S, 1);
2322− S->tccgen_vtop--;
2328+ gcall_or_jmp(1);
2329+ vtop--;
23232330 }
23242331
23252332 /* Save the stack pointer onto the stack and return the location of its address */
2326−ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
2333+ST_FUNC void gen_vla_sp_save(int addr) {
23272334 SValue v;
23282335 v.type.t = VT_PTR;
23292336 v.r = VT_LOCAL | VT_LVAL;
23302337 v.c.i = addr;
2331− store(S, TREG_SP, &v);
2338+ store(TREG_SP, &v);
23322339 }
23332340
23342341 /* Restore the SP from a location on the stack */
2335−ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
2342+ST_FUNC void gen_vla_sp_restore(int addr) {
23362343 SValue v;
23372344 v.type.t = VT_PTR;
23382345 v.r = VT_LOCAL | VT_LVAL;
23392346 v.c.i = addr;
2340− load(S, TREG_SP, &v);
2347+ load(TREG_SP, &v);
23412348 }
23422349
23432350 /* Subtract from the stack pointer, and push the resulting value onto the stack */
2344−ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
2351+ST_FUNC void gen_vla_alloc(CType *type, int align) {
23452352 int r;
23462353 #if defined(CONFIG_TCC_BCHECK)
2347− if (S->do_bounds_check)
2348− vpushv(S, S->tccgen_vtop);
2354+ if (tcc_state->do_bounds_check)
2355+ vpushv(vtop);
23492356 #endif
2350− r = intr(S, gv(S, RC_INT));
2357+ r = intr(gv(RC_INT));
23512358 #if defined(CONFIG_TCC_BCHECK)
2352− if (S->do_bounds_check)
2353− o(S, 0xe2800001 | (r<<16)|(r<<12)); /* add r,r,#1 */
2359+ if (tcc_state->do_bounds_check)
2360+ o(0xe2800001 | (r<<16)|(r<<12)); /* add r,r,#1 */
23542361 #endif
2355− o(S, 0xE04D0000|(r<<12)|r); /* sub r, sp, r */
2362+ o(0xE04D0000|(r<<12)|r); /* sub r, sp, r */
23562363 #ifdef TCC_ARM_EABI
23572364 if (align < 8)
23582365 align = 8;
@@ -2361,19 +2368,19 @@ ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) { · 2 unmodified lines
23612368 align = 4;
23622369 #endif
23632370 if (align & (align - 1))
2364− tcc_error(S, "alignment is not a power of 2: %i", align);
2365− o(S, stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */
2366− vpop(S);
2371+ tcc_error("alignment is not a power of 2: %i", align);
2372+ o(stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */
2373+ vpop();
23672374 #if defined(CONFIG_TCC_BCHECK)
2368− if (S->do_bounds_check) {
2369− vpushi(S, 0);
2370− S->tccgen_vtop->r = TREG_R0;
2371− o(S, 0xe1a0000d | (S->tccgen_vtop->r << 12)); // mov r0,sp
2372− vswap(S);
2373− vpush_helper_func(S, TOK___bound_new_region);
2374− vrott(S, 3);
2375− gfunc_call(S, 2);
2376− S->func_bound_add_epilog = 1;
2375+ if (tcc_state->do_bounds_check) {
2376+ vpushi(0);
2377+ vtop->r = TREG_R0;
2378+ o(0xe1a0000d | (vtop->r << 12)); // mov r0,sp
2379+ vswap();
2380+ vpush_helper_func(TOK___bound_new_region);
2381+ vrott(3);
2382+ gfunc_call(2);
2383+ func_bound_add_epilog = 1;
23772384 }
23782385 #endif
23792386 }
arm-link.c+32−32
@@ -107,9 +107,9 @@ int gotplt_entry_type (int reloc_type) · 106 unmodified lines
107107 }
108108
109109 #ifndef TCC_TARGET_PE
110−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
110+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
111111 {
112− Section *plt = S->plt;
112+ Section *plt = s1->plt;
113113 uint8_t *p;
114114 unsigned plt_offset;
115115
@@ -119,7 +119,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 3 unmodified lines
119119 /* empty PLT: create PLT0 entry that push address of call site and
120120 jump to ld.so resolution routine (GOT + 8) */
121121 if (plt->data_offset == 0) {
122− p = section_ptr_add(S, plt, 20);
122+ p = section_ptr_add(plt, 20);
123123 write32le(p, 0xe52de004); /* push {lr} */
124124 write32le(p+4, 0xe59fe004); /* ldr lr, [pc, #4] */
125125 write32le(p+8, 0xe08fe00e); /* add lr, pc, lr */
@@ -129,11 +129,11 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 3 unmodified lines
129129 plt_offset = plt->data_offset;
130130
131131 if (attr->plt_thumb_stub) {
132− p = section_ptr_add(S, plt, 4);
132+ p = section_ptr_add(plt, 4);
133133 write32le(p, 0x4778); /* bx pc */
134134 write32le(p+2, 0x46c0); /* nop */
135135 }
136− p = section_ptr_add(S, plt, 16);
136+ p = section_ptr_add(plt, 16);
137137 /* save GOT offset for relocate_plt */
138138 write32le(p + 4, got_offset);
139139 return plt_offset;
@@ -141,22 +141,22 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 1 unmodified line
141141
142142 /* relocate the PLT: compute addresses and offsets in the PLT now that final
143143 address for PLT and GOT are known (see fill_program_header) */
144−ST_FUNC void relocate_plt(TCCState *S)
144+ST_FUNC void relocate_plt(TCCState *s1)
145145 {
146146 uint8_t *p, *p_end;
147147
148− if (!S->plt)
148+ if (!s1->plt)
149149 return;
150150
151− p = S->plt->data;
152− p_end = p + S->plt->data_offset;
151+ p = s1->plt->data;
152+ p_end = p + s1->plt->data_offset;
153153
154154 if (p < p_end) {
155− int x = S->got->sh_addr - S->plt->sh_addr - 12;
156− write32le(S->plt->data + 16, x - 4);
155+ int x = s1->got->sh_addr - s1->plt->sh_addr - 12;
156+ write32le(s1->plt->data + 16, x - 4);
157157 p += 20;
158158 while (p < p_end) {
159− unsigned off = x + read32le(p + 4) + (S->plt->data - p) + 4;
159+ unsigned off = x + read32le(p + 4) + (s1->plt->data - p) + 4;
160160 if (read32le(p) == 0x46c04778) /* PLT Thumb stub present */
161161 p += 4;
162162 write32le(p, 0xe28fc200 | ((off >> 28) & 0xf)); // add ip, pc, #0xN0000000
@@ -167,17 +167,17 @@ ST_FUNC void relocate_plt(TCCState *S) · 4 unmodified lines
167167 }
168168 }
169169
170− if (S->plt->reloc) {
170+ if (s1->plt->reloc) {
171171 ElfW_Rel *rel;
172− p = S->got->data;
173− for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
174− write32le(p + rel->r_offset, S->plt->sh_addr);
172+ p = s1->got->data;
173+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
174+ write32le(p + rel->r_offset, s1->plt->sh_addr);
175175 }
176176 }
177177 }
178178 #endif
179179
180−void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
180+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
181181 {
182182 ElfW(Sym) *sym;
183183 int sym_index, esym_index;
@@ -212,7 +212,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 28 unmodified lines
212212 h = x & 2;
213213 th_ko = (x & 3) && (!blx_avail || !is_call);
214214 if (th_ko || x >= 0x2000000 || x < -0x2000000)
215− tcc_error(S, "can't relocate value at %x,%d",addr, type);
215+ tcc_error("can't relocate value at %x,%d",addr, type);
216216 x >>= 2;
217217 x &= 0xffffff;
218218 /* Only reached if blx is avail and it is a call */
@@ -255,7 +255,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 36 unmodified lines
255255
256256 /* Relocation infos */
257257 to_thumb = val & 1;
258− plt = S->plt;
258+ plt = s1->plt;
259259 to_plt = (val >= plt->sh_addr) &&
260260 (val < plt->sh_addr + plt->data_offset);
261261 is_call = (type == R_ARM_THM_PC22);
@@ -267,10 +267,10 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 5 unmodified lines
267267 Section *text;
268268
269269 name = (char *) symtab_section->link->data + sym->st_name;
270− text = S->sections[sym->st_shndx];
270+ text = s1->sections[sym->st_shndx];
271271 /* Modify reloc to target a thumb stub to switch to ARM */
272272 snprintf(buf, sizeof(buf), "%s_from_thumb", name);
273− index = put_elf_sym(S, symtab_section,
273+ index = put_elf_sym(symtab_section,
274274 text->data_offset + 1,
275275 sym->st_size, sym->st_info, 0,
276276 sym->st_shndx, buf);
@@ -281,7 +281,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 4 unmodified lines
281281 put_elf_reloc(symtab_section, text,
282282 text->data_offset + 4, R_ARM_JUMP24,
283283 sym_index);
284− p = section_ptr_add(S, text, 8);
284+ p = section_ptr_add(text, 8);
285285 write32le(p, 0x4778); /* bx pc */
286286 write32le(p+2, 0x46c0); /* nop */
287287 write32le(p+4, 0xeafffffe); /* b $sym */
@@ -301,7 +301,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 13 unmodified lines
301301 - instruction must be a call (bl) or a jump to PLT */
302302 if (!to_thumb || x >= 0x1000000 || x < -0x1000000)
303303 if (to_thumb || (val & 2) || (!is_call && !to_plt))
304− tcc_error(S, "can't relocate value at %x,%d",addr, type);
304+ tcc_error("can't relocate value at %x,%d",addr, type);
305305
306306 /* Compute and store final offset */
307307 s = (x >> 24) & 1;
@@ -372,14 +372,14 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 64 unmodified lines
372372 x = (x * 2) / 2;
373373 x += val - addr;
374374 if((x^(x>>1))&0x40000000)
375− tcc_error(S, "can't relocate value at %x,%d",addr, type);
375+ tcc_error("can't relocate value at %x,%d",addr, type);
376376 (*(int *)ptr) |= x & 0x7fffffff;
377377 }
378378 return;
379379 case R_ARM_ABS32:
380380 case R_ARM_TARGET1:
381− if (S->output_type == TCC_OUTPUT_DLL) {
382− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
381+ if (s1->output_type == TCC_OUTPUT_DLL) {
382+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
383383 qrel->r_offset = rel->r_offset;
384384 if (esym_index) {
385385 qrel->r_info = ELFW(R_INFO)(esym_index, R_ARM_ABS32);
@@ -396,19 +396,19 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 10 unmodified lines
396396 *(int *)ptr += val - addr;
397397 return;
398398 case R_ARM_GOTPC:
399− *(int *)ptr += S->got->sh_addr - addr;
399+ *(int *)ptr += s1->got->sh_addr - addr;
400400 return;
401401 case R_ARM_GOTOFF:
402− *(int *)ptr += val - S->got->sh_addr;
402+ *(int *)ptr += val - s1->got->sh_addr;
403403 return;
404404 case R_ARM_GOT32:
405405 /* we load the got offset */
406− *(int *)ptr += get_sym_attr(S, sym_index, 0)->got_offset;
406+ *(int *)ptr += get_sym_attr(s1, sym_index, 0)->got_offset;
407407 return;
408408 case R_ARM_GOT_PREL:
409409 /* we load the pc relative got offset */
410− *(int *)ptr += S->got->sh_addr +
411− get_sym_attr(S, sym_index, 0)->got_offset -
410+ *(int *)ptr += s1->got->sh_addr +
411+ get_sym_attr(s1, sym_index, 0)->got_offset -
412412 addr;
413413 return;
414414 case R_ARM_COPY:
@@ -428,7 +428,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 13 unmodified lines
428428 return;
429429 case R_ARM_RELATIVE:
430430 #ifdef TCC_TARGET_PE
431− add32le(ptr, val - S->pe_imagebase);
431+ add32le(ptr, val - s1->pe_imagebase);
432432 #endif
433433 /* do nothing */
434434 return;
arm64-asm.c+13−13
@@ -9,9 +9,9 @@ · 8 unmodified lines
99 #define CONFIG_TCC_ASM
1010 #define NB_ASM_REGS 16
1111
12−ST_FUNC void g(TCCState* S, int c);
13−ST_FUNC void gen_le16(TCCState* S, int c);
14−ST_FUNC void gen_le32(TCCState* S, int c);
12+ST_FUNC void g(int c);
13+ST_FUNC void gen_le16(int c);
14+ST_FUNC void gen_le32(int c);
1515
1616 /*************************************************************/
1717 #else
@@ -25,7 +25,7 @@ static void asm_error(void) · 7 unmodified lines
2525 }
2626
2727 /* XXX: make it faster ? */
28−ST_FUNC void g(TCCState* S, int c)
28+ST_FUNC void g(int c)
2929 {
3030 int ind1;
3131 if (nocode_wanted)
@@ -37,24 +37,24 @@ ST_FUNC void g(TCCState* S, int c) · 5 unmodified lines
3737 ind = ind1;
3838 }
3939
40−ST_FUNC void gen_le16 (TCCState* S, int i)
40+ST_FUNC void gen_le16 (int i)
4141 {
42− g(S, i);
43− g(S, i>>8);
42+ g(i);
43+ g(i>>8);
4444 }
4545
46−ST_FUNC void gen_le32 (TCCState* S, int i)
46+ST_FUNC void gen_le32 (int i)
4747 {
48− gen_le16(S, i);
49− gen_le16(S, i>>16);
48+ gen_le16(i);
49+ gen_le16(i>>16);
5050 }
5151
52−ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
52+ST_FUNC void gen_expr32(ExprValue *pe)
5353 {
54− gen_le32(S, pe->v);
54+ gen_le32(pe->v);
5555 }
5656
57−ST_FUNC void asm_opcode(TCCState *S, int opcode)
57+ST_FUNC void asm_opcode(TCCState *s1, int opcode)
5858 {
5959 asm_error();
6060 }
arm64-gen.c+647−641
@@ -90,9 +90,15 @@ ST_DATA const int reg_classes[NB_REGS] = { · 89 unmodified lines
9090 RC_FLOAT | RC_F(7)
9191 };
9292
93+#if defined(CONFIG_TCC_BCHECK)
94+static addr_t func_bound_offset;
95+static unsigned long func_bound_ind;
96+ST_DATA int func_bound_add_epilog;
97+#endif
98+
9399 #define IS_FREG(x) ((x) >= TREG_F(0))
94100
95−static uint32_t intr(TCCState *S, int r)
101+static uint32_t intr(int r)
96102 {
97103 assert(TREG_R(0) <= r && r <= TREG_R30);
98104 return r < TREG_R30 ? r : 30;
@@ -105,15 +111,15 @@ static uint32_t fltr(int r) · 6 unmodified lines
105111 }
106112
107113 // Add an instruction to text section:
108−ST_FUNC void o(TCCState *S, unsigned int c)
114+ST_FUNC void o(unsigned int c)
109115 {
110− int ind1 = S->tccgen_ind + 4;
111− if (S->tccgen_nocode_wanted)
116+ int ind1 = ind + 4;
117+ if (nocode_wanted)
112118 return;
113119 if (ind1 > cur_text_section->data_allocated)
114− section_realloc(S, cur_text_section, ind1);
115− write32le(cur_text_section->data + S->tccgen_ind, c);
116− S->tccgen_ind = ind1;
120+ section_realloc(cur_text_section, ind1);
121+ write32le(cur_text_section->data + ind, c);
122+ ind = ind1;
117123 }
118124
119125 static int arm64_encode_bimm64(uint64_t x)
@@ -202,11 +208,11 @@ static uint32_t arm64_movi(int r, uint64_t x) · 82 unmodified lines
202208 return 0;
203209 }
204210
205−static void arm64_movimm(TCCState *S, int r, uint64_t x)
211+static void arm64_movimm(int r, uint64_t x)
206212 {
207213 uint32_t i;
208214 if ((i = arm64_movi(r, x)))
209− o(S, i); // a single MOV
215+ o(i); // a single MOV
210216 else {
211217 // MOVZ/MOVN and 1-3 MOVKs
212218 int z = 0, m = 0;
@@ -222,19 +228,19 @@ static void arm64_movimm(TCCState *S, int r, uint64_t x) · 9 unmodified lines
222228 }
223229 for (i = 0; i < 64; i += 16)
224230 if (x1 >> i & 0xffff) {
225− o(S, mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17);
231+ o(mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17);
226232 // movz/movn x(r),#(*),lsl #(i)
227233 break;
228234 }
229235 for (i += 16; i < 64; i += 16)
230236 if (x1 >> i & 0xffff)
231− o(S, 0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17);
237+ o(0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17);
232238 // movk x(r),#(*),lsl #(i)
233239 }
234240 }
235241
236242 // Patch all branches in list pointed to by t to branch to a:
237−ST_FUNC void gsym_addr(TCCState *S, int t_, int a_)
243+ST_FUNC void gsym_addr(int t_, int a_)
238244 {
239245 uint32_t t = t_;
240246 uint32_t a = a_;
@@ -242,7 +248,7 @@ ST_FUNC void gsym_addr(TCCState *S, int t_, int a_) · 1 unmodified line
242248 unsigned char *ptr = cur_text_section->data + t;
243249 uint32_t next = read32le(ptr);
244250 if (a - t + 0x8000000 >= 0x10000000)
245− tcc_error(S, "branch out of range");
251+ tcc_error("branch out of range");
246252 write32le(ptr, (a - t == 4 ? 0xd503201f : // nop
247253 0x14000000 | ((a - t) >> 2 & 0x3ffffff))); // b
248254 t = next;
@@ -272,17 +278,17 @@ static int arm64_type_size(int t) · 23 unmodified lines
272278 return 0;
273279 }
274280
275−static void arm64_spoff(TCCState *S, int reg, uint64_t off)
281+static void arm64_spoff(int reg, uint64_t off)
276282 {
277283 uint32_t sub = off >> 63;
278284 if (sub)
279285 off = -off;
280286 if (off < 4096)
281− o(S, 0x910003e0 | sub << 30 | reg | off << 10);
287+ o(0x910003e0 | sub << 30 | reg | off << 10);
282288 // (add|sub) x(reg),sp,#(off)
283289 else {
284− arm64_movimm(S, 30, off); // use x30 for offset
285− o(S, 0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30
290+ arm64_movimm(30, off); // use x30 for offset
291+ o(0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30
286292 }
287293 }
288294
@@ -303,41 +309,41 @@ static uint64_t arm64_check_offset(int invert, int sz_, uint64_t off) · 14 unmodified lines
303309 return invert ? 0ul : off;
304310 }
305311
306−static void arm64_ldrx(TCCState *S, int sg, int sz_, int dst, int bas, uint64_t off)
312+static void arm64_ldrx(int sg, int sz_, int dst, int bas, uint64_t off)
307313 {
308314 uint32_t sz = sz_;
309315 if (sz >= 2)
310316 sg = 0;
311317 if (!(off & ~((uint32_t)0xfff << sz)))
312− o(S, 0x39400000 | dst | bas << 5 | off << (10 - sz) |
318+ o(0x39400000 | dst | bas << 5 | off << (10 - sz) |
313319 (uint32_t)!!sg << 23 | sz << 30); // ldr(*) x(dst),[x(bas),#(off)]
314320 else if (off < 256 || -off <= 256)
315− o(S, 0x38400000 | dst | bas << 5 | (off & 511) << 12 |
321+ o(0x38400000 | dst | bas << 5 | (off & 511) << 12 |
316322 (uint32_t)!!sg << 23 | sz << 30); // ldur(*) x(dst),[x(bas),#(off)]
317323 else {
318− arm64_movimm(S, 30, off); // use x30 for offset
319− o(S, 0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 |
324+ arm64_movimm(30, off); // use x30 for offset
325+ o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 |
320326 (uint32_t)(!!sg + 1) << 22 | sz << 30); // ldr(*) x(dst),[x(bas),x30]
321327 }
322328 }
323329
324−static void arm64_ldrv(TCCState *S, int sz_, int dst, int bas, uint64_t off)
330+static void arm64_ldrv(int sz_, int dst, int bas, uint64_t off)
325331 {
326332 uint32_t sz = sz_;
327333 if (!(off & ~((uint32_t)0xfff << sz)))
328− o(S, 0x3d400000 | dst | bas << 5 | off << (10 - sz) |
334+ o(0x3d400000 | dst | bas << 5 | off << (10 - sz) |
329335 (sz & 4) << 21 | (sz & 3) << 30); // ldr (s|d|q)(dst),[x(bas),#(off)]
330336 else if (off < 256 || -off <= 256)
331− o(S, 0x3c400000 | dst | bas << 5 | (off & 511) << 12 |
337+ o(0x3c400000 | dst | bas << 5 | (off & 511) << 12 |
332338 (sz & 4) << 21 | (sz & 3) << 30); // ldur (s|d|q)(dst),[x(bas),#(off)]
333339 else {
334− arm64_movimm(S, 30, off); // use x30 for offset
335− o(S, 0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 |
340+ arm64_movimm(30, off); // use x30 for offset
341+ o(0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 |
336342 sz << 30 | (sz & 4) << 21); // ldr (s|d|q)(dst),[x(bas),x30]
337343 }
338344 }
339345
340−static void arm64_ldrs(TCCState *S, int reg_, int size)
346+static void arm64_ldrs(int reg_, int size)
341347 {
342348 uint32_t reg = reg_;
343349 // Use x30 for intermediate value in some cases.
@@ -347,138 +353,138 @@ static void arm64_ldrs(TCCState *S, int reg_, int size) · 3 unmodified lines
347353 /* Can happen with zero size structs */
348354 break;
349355 case 1:
350− arm64_ldrx(S, 0, 0, reg, reg, 0);
356+ arm64_ldrx(0, 0, reg, reg, 0);
351357 break;
352358 case 2:
353− arm64_ldrx(S, 0, 1, reg, reg, 0);
359+ arm64_ldrx(0, 1, reg, reg, 0);
354360 break;
355361 case 3:
356− arm64_ldrx(S, 0, 1, 30, reg, 0);
357− arm64_ldrx(S, 0, 0, reg, reg, 2);
358− o(S, 0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16
362+ arm64_ldrx(0, 1, 30, reg, 0);
363+ arm64_ldrx(0, 0, reg, reg, 2);
364+ o(0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16
359365 break;
360366 case 4:
361− arm64_ldrx(S, 0, 2, reg, reg, 0);
367+ arm64_ldrx(0, 2, reg, reg, 0);
362368 break;
363369 case 5:
364− arm64_ldrx(S, 0, 2, 30, reg, 0);
365− arm64_ldrx(S, 0, 0, reg, reg, 4);
366− o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
370+ arm64_ldrx(0, 2, 30, reg, 0);
371+ arm64_ldrx(0, 0, reg, reg, 4);
372+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
367373 break;
368374 case 6:
369− arm64_ldrx(S, 0, 2, 30, reg, 0);
370− arm64_ldrx(S, 0, 1, reg, reg, 4);
371− o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
375+ arm64_ldrx(0, 2, 30, reg, 0);
376+ arm64_ldrx(0, 1, reg, reg, 4);
377+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
372378 break;
373379 case 7:
374− arm64_ldrx(S, 0, 2, 30, reg, 0);
375− arm64_ldrx(S, 0, 2, reg, reg, 3);
376− o(S, 0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8
377− o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
380+ arm64_ldrx(0, 2, 30, reg, 0);
381+ arm64_ldrx(0, 2, reg, reg, 3);
382+ o(0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8
383+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
378384 break;
379385 case 8:
380− arm64_ldrx(S, 0, 3, reg, reg, 0);
386+ arm64_ldrx(0, 3, reg, reg, 0);
381387 break;
382388 case 9:
383− arm64_ldrx(S, 0, 0, reg + 1, reg, 8);
384− arm64_ldrx(S, 0, 3, reg, reg, 0);
389+ arm64_ldrx(0, 0, reg + 1, reg, 8);
390+ arm64_ldrx(0, 3, reg, reg, 0);
385391 break;
386392 case 10:
387− arm64_ldrx(S, 0, 1, reg + 1, reg, 8);
388− arm64_ldrx(S, 0, 3, reg, reg, 0);
393+ arm64_ldrx(0, 1, reg + 1, reg, 8);
394+ arm64_ldrx(0, 3, reg, reg, 0);
389395 break;
390396 case 11:
391− arm64_ldrx(S, 0, 2, reg + 1, reg, 7);
392− o(S, 0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8
393− arm64_ldrx(S, 0, 3, reg, reg, 0);
397+ arm64_ldrx(0, 2, reg + 1, reg, 7);
398+ o(0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8
399+ arm64_ldrx(0, 3, reg, reg, 0);
394400 break;
395401 case 12:
396− arm64_ldrx(S, 0, 2, reg + 1, reg, 8);
397− arm64_ldrx(S, 0, 3, reg, reg, 0);
402+ arm64_ldrx(0, 2, reg + 1, reg, 8);
403+ arm64_ldrx(0, 3, reg, reg, 0);
398404 break;
399405 case 13:
400− arm64_ldrx(S, 0, 3, reg + 1, reg, 5);
401− o(S, 0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24
402− arm64_ldrx(S, 0, 3, reg, reg, 0);
406+ arm64_ldrx(0, 3, reg + 1, reg, 5);
407+ o(0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24
408+ arm64_ldrx(0, 3, reg, reg, 0);
403409 break;
404410 case 14:
405− arm64_ldrx(S, 0, 3, reg + 1, reg, 6);
406− o(S, 0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16
407− arm64_ldrx(S, 0, 3, reg, reg, 0);
411+ arm64_ldrx(0, 3, reg + 1, reg, 6);
412+ o(0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16
413+ arm64_ldrx(0, 3, reg, reg, 0);
408414 break;
409415 case 15:
410− arm64_ldrx(S, 0, 3, reg + 1, reg, 7);
411− o(S, 0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8
412− arm64_ldrx(S, 0, 3, reg, reg, 0);
416+ arm64_ldrx(0, 3, reg + 1, reg, 7);
417+ o(0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8
418+ arm64_ldrx(0, 3, reg, reg, 0);
413419 break;
414420 case 16:
415− o(S, 0xa9400000 | reg | (reg+1) << 10 | reg << 5);
421+ o(0xa9400000 | reg | (reg+1) << 10 | reg << 5);
416422 // ldp x(reg),x(reg+1),[x(reg)]
417423 break;
418424 }
419425 }
420426
421−static void arm64_strx(TCCState *S, int sz_, int dst, int bas, uint64_t off)
427+static void arm64_strx(int sz_, int dst, int bas, uint64_t off)
422428 {
423429 uint32_t sz = sz_;
424430 if (!(off & ~((uint32_t)0xfff << sz)))
425− o(S, 0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30);
431+ o(0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30);
426432 // str(*) x(dst),[x(bas],#(off)]
427433 else if (off < 256 || -off <= 256)
428− o(S, 0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30);
434+ o(0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30);
429435 // stur(*) x(dst),[x(bas],#(off)]
430436 else {
431− arm64_movimm(S, 30, off); // use x30 for offset
432− o(S, 0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30);
437+ arm64_movimm(30, off); // use x30 for offset
438+ o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30);
433439 // str(*) x(dst),[x(bas),x30]
434440 }
435441 }
436442
437−static void arm64_strv(TCCState *S, int sz_, int dst, int bas, uint64_t off)
443+static void arm64_strv(int sz_, int dst, int bas, uint64_t off)
438444 {
439445 uint32_t sz = sz_;
440446 if (!(off & ~((uint32_t)0xfff << sz)))
441− o(S, 0x3d000000 | dst | bas << 5 | off << (10 - sz) |
447+ o(0x3d000000 | dst | bas << 5 | off << (10 - sz) |
442448 (sz & 4) << 21 | (sz & 3) << 30); // str (s|d|q)(dst),[x(bas),#(off)]
443449 else if (off < 256 || -off <= 256)
444− o(S, 0x3c000000 | dst | bas << 5 | (off & 511) << 12 |
450+ o(0x3c000000 | dst | bas << 5 | (off & 511) << 12 |
445451 (sz & 4) << 21 | (sz & 3) << 30); // stur (s|d|q)(dst),[x(bas),#(off)]
446452 else {
447− arm64_movimm(S, 30, off); // use x30 for offset
448− o(S, 0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 |
453+ arm64_movimm(30, off); // use x30 for offset
454+ o(0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 |
449455 sz << 30 | (sz & 4) << 21); // str (s|d|q)(dst),[x(bas),x30]
450456 }
451457 }
452458
453−static void arm64_sym(TCCState *S, int r, Sym *sym, unsigned long addend)
459+static void arm64_sym(int r, Sym *sym, unsigned long addend)
454460 {
455− greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
456− o(S, 0x90000000 | r); // adrp xr, #sym
457− greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
458− o(S, 0xf9400000 | r | (r << 5)); // ld xr,[xr, #sym]
461+ greloca(cur_text_section, sym, ind, R_AARCH64_ADR_GOT_PAGE, 0);
462+ o(0x90000000 | r); // adrp xr, #sym
463+ greloca(cur_text_section, sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
464+ o(0xf9400000 | r | (r << 5)); // ld xr,[xr, #sym]
459465 if (addend) {
460466 // add xr, xr, #addend
461467 if (addend & 0xffful)
462− o(S, 0x91000000 | r | r << 5 | (addend & 0xfff) << 10);
468+ o(0x91000000 | r | r << 5 | (addend & 0xfff) << 10);
463469 if (addend > 0xffful) {
464470 // add xr, xr, #addend, lsl #12
465471 if (addend & 0xfff000ul)
466− o(S, 0x91400000 | r | r << 5 | ((addend >> 12) & 0xfff) << 10);
472+ o(0x91400000 | r | r << 5 | ((addend >> 12) & 0xfff) << 10);
467473 if (addend > 0xfffffful) {
468474 /* very unlikely */
469475 int t = r ? 0 : 1;
470− o(S, 0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
471− arm64_movimm(S, t, addend & ~0xfffffful); // use xt for addent
472− o(S, 0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
473− o(S, 0xf84107e0 | t); /* ldr xt, [sp], #16 */
476+ o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
477+ arm64_movimm(t, addend & ~0xfffffful); // use xt for addent
478+ o(0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
479+ o(0xf84107e0 | t); /* ldr xt, [sp], #16 */
474480 }
475481 }
476482 }
477483 }
478484
479−static void arm64_load_cmp(TCCState *S, int r, SValue *sv);
485+static void arm64_load_cmp(int r, SValue *sv);
480486
481−ST_FUNC void load(TCCState *S, int r, SValue *sv)
487+ST_FUNC void load(int r, SValue *sv)
482488 {
483489 int svtt = sv->type.t;
484490 int svr = sv->r & ~VT_BOUNDED;
@@ -488,24 +494,24 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv) · 3 unmodified lines
488494
489495 if (svr == (VT_LOCAL | VT_LVAL)) {
490496 if (IS_FREG(r))
491− arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 29, svcul);
497+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 29, svcul);
492498 else
493− arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
494− intr(S, r), 29, svcul);
499+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
500+ intr(r), 29, svcul);
495501 return;
496502 }
497503
498504 if (svr == (VT_CONST | VT_LVAL)) {
499505 if (sv->sym)
500− arm64_sym(S, 30, sv->sym, // use x30 for address
506+ arm64_sym(30, sv->sym, // use x30 for address
501507 arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
502508 else
503− arm64_movimm (S, 30, sv->c.i);
509+ arm64_movimm (30, sv->c.i);
504510 if (IS_FREG(r))
505− arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30,
511+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30,
506512 arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
507513 else
508− arm64_ldrx(S, !(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(S, r), 30,
514+ arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30,
509515 arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
510516 return;
511517 }
@@ -513,34 +519,34 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv) · 1 unmodified line
513519 if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) {
514520 if ((svtt & VT_BTYPE) != VT_VOID) {
515521 if (IS_FREG(r))
516− arm64_ldrv(S, arm64_type_size(svtt), fltr(r), intr(S, svrv), 0);
522+ arm64_ldrv(arm64_type_size(svtt), fltr(r), intr(svrv), 0);
517523 else
518− arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
519− intr(S, r), intr(S, svrv), 0);
524+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
525+ intr(r), intr(svrv), 0);
520526 }
521527 return;
522528 }
523529
524530 if (svr == (VT_CONST | VT_LVAL | VT_SYM)) {
525− arm64_sym(S, 30, sv->sym, // use x30 for address
531+ arm64_sym(30, sv->sym, // use x30 for address
526532 arm64_check_offset(0, arm64_type_size(svtt), svcul));
527533 if (IS_FREG(r))
528− arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30,
534+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30,
529535 arm64_check_offset(1, arm64_type_size(svtt), svcul));
530536 else
531− arm64_ldrx(S, !(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(S, r), 30,
537+ arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30,
532538 arm64_check_offset(1, arm64_type_size(svtt), svcul));
533539 return;
534540 }
535541
536542 if (svr == (VT_CONST | VT_SYM)) {
537− arm64_sym(S, intr(S, r), sv->sym, svcul);
543+ arm64_sym(intr(r), sv->sym, svcul);
538544 return;
539545 }
540546
541547 if (svr == VT_CONST) {
542548 if ((svtt & VT_BTYPE) != VT_VOID)
543− arm64_movimm(S, intr(S, r), arm64_type_size(svtt) == 3 ?
549+ arm64_movimm(intr(r), arm64_type_size(svtt) == 3 ?
544550 sv->c.i : (uint32_t)svcul);
545551 return;
546552 }
@@ -548,12 +554,12 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv) · 1 unmodified line
548554 if (svr < VT_CONST) {
549555 if (IS_FREG(r) && IS_FREG(svr))
550556 if (svtt == VT_LDOUBLE)
551− o(S, 0x4ea01c00 | fltr(r) | fltr(svr) << 5);
557+ o(0x4ea01c00 | fltr(r) | fltr(svr) << 5);
552558 // mov v(r).16b,v(svr).16b
553559 else
554− o(S, 0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr)
560+ o(0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr)
555561 else if (!IS_FREG(r) && !IS_FREG(svr))
556− o(S, 0xaa0003e0 | intr(S, r) | intr(S, svr) << 16); // mov x(r),x(svr)
562+ o(0xaa0003e0 | intr(r) | intr(svr) << 16); // mov x(r),x(svr)
557563 else
558564 assert(0);
559565 return;
@@ -561,35 +567,35 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv) · 1 unmodified line
561567
562568 if (svr == VT_LOCAL) {
563569 if (-svcul < 0x1000)
564− o(S, 0xd10003a0 | intr(S, r) | -svcul << 10); // sub x(r),x29,#...
570+ o(0xd10003a0 | intr(r) | -svcul << 10); // sub x(r),x29,#...
565571 else {
566− arm64_movimm(S, 30, -svcul); // use x30 for offset
567− o(S, 0xcb0003a0 | intr(S, r) | (uint32_t)30 << 16); // sub x(r),x29,x30
572+ arm64_movimm(30, -svcul); // use x30 for offset
573+ o(0xcb0003a0 | intr(r) | (uint32_t)30 << 16); // sub x(r),x29,x30
568574 }
569575 return;
570576 }
571577
572578 if (svr == VT_JMP || svr == VT_JMPI) {
573579 int t = (svr == VT_JMPI);
574− arm64_movimm(S, intr(S, r), t);
575− o(S, 0x14000002); // b .+8
576− gsym(S, svcul);
577− arm64_movimm(S, intr(S, r), t ^ 1);
580+ arm64_movimm(intr(r), t);
581+ o(0x14000002); // b .+8
582+ gsym(svcul);
583+ arm64_movimm(intr(r), t ^ 1);
578584 return;
579585 }
580586
581587 if (svr == (VT_LLOCAL | VT_LVAL)) {
582− arm64_ldrx(S, 0, 3, 30, 29, svcul); // use x30 for offset
588+ arm64_ldrx(0, 3, 30, 29, svcul); // use x30 for offset
583589 if (IS_FREG(r))
584− arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30, 0);
590+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, 0);
585591 else
586− arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
587− intr(S, r), 30, 0);
592+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
593+ intr(r), 30, 0);
588594 return;
589595 }
590596
591597 if (svr == VT_CMP) {
592− arm64_load_cmp(S, r, sv);
598+ arm64_load_cmp(r, sv);
593599 return;
594600 }
595601
@@ -597,7 +603,7 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv) · 1 unmodified line
597603 assert(0);
598604 }
599605
600−ST_FUNC void store(TCCState *S, int r, SValue *sv)
606+ST_FUNC void store(int r, SValue *sv)
601607 {
602608 int svtt = sv->type.t;
603609 int svr = sv->r & ~VT_BOUNDED;
@@ -607,43 +613,43 @@ ST_FUNC void store(TCCState *S, int r, SValue *sv) · 3 unmodified lines
607613
608614 if (svr == (VT_LOCAL | VT_LVAL)) {
609615 if (IS_FREG(r))
610− arm64_strv(S, arm64_type_size(svtt), fltr(r), 29, svcul);
616+ arm64_strv(arm64_type_size(svtt), fltr(r), 29, svcul);
611617 else
612− arm64_strx(S, arm64_type_size(svtt), intr(S, r), 29, svcul);
618+ arm64_strx(arm64_type_size(svtt), intr(r), 29, svcul);
613619 return;
614620 }
615621
616622 if (svr == (VT_CONST | VT_LVAL)) {
617623 if (sv->sym)
618− arm64_sym(S, 30, sv->sym, // use x30 for address
624+ arm64_sym(30, sv->sym, // use x30 for address
619625 arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
620626 else
621− arm64_movimm(S, 30, sv->c.i);
627+ arm64_movimm (30, sv->c.i);
622628 if (IS_FREG(r))
623− arm64_strv(S, arm64_type_size(svtt), fltr(r), 30,
629+ arm64_strv(arm64_type_size(svtt), fltr(r), 30,
624630 arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
625631 else
626− arm64_strx(S, arm64_type_size(svtt), intr(S, r), 30,
632+ arm64_strx(arm64_type_size(svtt), intr(r), 30,
627633 arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
628634 return;
629635 }
630636
631637 if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) {
632638 if (IS_FREG(r))
633− arm64_strv(S, arm64_type_size(svtt), fltr(r), intr(S, svrv), 0);
639+ arm64_strv(arm64_type_size(svtt), fltr(r), intr(svrv), 0);
634640 else
635− arm64_strx(S, arm64_type_size(svtt), intr(S, r), intr(S, svrv), 0);
641+ arm64_strx(arm64_type_size(svtt), intr(r), intr(svrv), 0);
636642 return;
637643 }
638644
639645 if (svr == (VT_CONST | VT_LVAL | VT_SYM)) {
640− arm64_sym(S, 30, sv->sym, // use x30 for address
646+ arm64_sym(30, sv->sym, // use x30 for address
641647 arm64_check_offset(0, arm64_type_size(svtt), svcul));
642648 if (IS_FREG(r))
643− arm64_strv(S, arm64_type_size(svtt), fltr(r), 30,
649+ arm64_strv(arm64_type_size(svtt), fltr(r), 30,
644650 arm64_check_offset(1, arm64_type_size(svtt), svcul));
645651 else
646− arm64_strx(S, arm64_type_size(svtt), intr(S, r), 30,
652+ arm64_strx(arm64_type_size(svtt), intr(r), 30,
647653 arm64_check_offset(1, arm64_type_size(svtt), svcul));
648654 return;
649655 }
@@ -652,82 +658,82 @@ ST_FUNC void store(TCCState *S, int r, SValue *sv) · 2 unmodified lines
652658 assert(0);
653659 }
654660
655−static void arm64_gen_bl_or_b(TCCState *S, int b)
661+static void arm64_gen_bl_or_b(int b)
656662 {
657− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (S->tccgen_vtop->r & VT_SYM)) {
658− greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind,
663+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) {
664+ greloca(cur_text_section, vtop->sym, ind,
659665 b ? R_AARCH64_JUMP26 : R_AARCH64_CALL26, 0);
660− o(S, 0x14000000 | (uint32_t)!b << 31); // b/bl .
666+ o(0x14000000 | (uint32_t)!b << 31); // b/bl .
661667 }
662668 else {
663669 #ifdef CONFIG_TCC_BCHECK
664− S->tccgen_vtop->r &= ~VT_MUSTBOUND;
670+ vtop->r &= ~VT_MUSTBOUND;
665671 #endif
666− o(S, 0xd61f0000 | (uint32_t)!b << 21 | intr(S, gv(S, RC_R30)) << 5); // br/blr
672+ o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr
667673 }
668674 }
669675
670676 #if defined(CONFIG_TCC_BCHECK)
671677
672−static void gen_bounds_call(TCCState *S, int v)
678+static void gen_bounds_call(int v)
673679 {
674− Sym *sym = external_helper_sym(S, v);
680+ Sym *sym = external_helper_sym(v);
675681
676− greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_CALL26, 0);
677− o(S, 0x94000000); // bl
682+ greloca(cur_text_section, sym, ind, R_AARCH64_CALL26, 0);
683+ o(0x94000000); // bl
678684 }
679685
680−static void gen_bounds_prolog(TCCState *S)
686+static void gen_bounds_prolog(void)
681687 {
682688 /* leave some room for bound checking code */
683− S->func_bound_offset = lbounds_section->data_offset;
684− S->func_bound_ind = S->tccgen_ind;
685− S->func_bound_add_epilog = 0;
686− o(S, 0xd503201f); /* nop -> mov x0, lbound section pointer */
687− o(S, 0xd503201f);
688− o(S, 0xd503201f);
689− o(S, 0xd503201f); /* nop -> call __bound_local_new */
689+ func_bound_offset = lbounds_section->data_offset;
690+ func_bound_ind = ind;
691+ func_bound_add_epilog = 0;
692+ o(0xd503201f); /* nop -> mov x0, lbound section pointer */
693+ o(0xd503201f);
694+ o(0xd503201f);
695+ o(0xd503201f); /* nop -> call __bound_local_new */
690696 }
691697
692−static void gen_bounds_epilog(TCCState *S)
698+static void gen_bounds_epilog(void)
693699 {
694700 addr_t saved_ind;
695701 addr_t *bounds_ptr;
696702 Sym *sym_data;
697− int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
703+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
698704
699− if (!offset_modified && !S->func_bound_add_epilog)
705+ if (!offset_modified && !func_bound_add_epilog)
700706 return;
701707
702708 /* add end of table info */
703− bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
709+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
704710 *bounds_ptr = 0;
705711
706− sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
707− S->func_bound_offset, lbounds_section->data_offset);
712+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
713+ func_bound_offset, lbounds_section->data_offset);
708714
709715 /* generate bound local allocation */
710716 if (offset_modified) {
711− saved_ind = S->tccgen_ind;
712− S->tccgen_ind = S->func_bound_ind;
713− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
714− o(S, 0x90000000 | 0); // adrp x0, #sym_data
715− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
716− o(S, 0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
717− gen_bounds_call(S, TOK___bound_local_new);
718− S->tccgen_ind = saved_ind;
717+ saved_ind = ind;
718+ ind = func_bound_ind;
719+ greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0);
720+ o(0x90000000 | 0); // adrp x0, #sym_data
721+ greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
722+ o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
723+ gen_bounds_call(TOK___bound_local_new);
724+ ind = saved_ind;
719725 }
720726
721727 /* generate bound check local freeing */
722− o(S, 0xf81f0fe0); /* str x0, [sp, #-16]! */
723− o(S, 0x3c9f0fe0); /* str q0, [sp, #-16]! */
724− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
725− o(S, 0x90000000 | 0); // adrp x0, #sym_data
726− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
727− o(S, 0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
728− gen_bounds_call(S, TOK___bound_local_delete);
729− o(S, 0x3cc107e0); /* ldr q0, [sp], #16 */
730− o(S, 0xf84107e0); /* ldr x0, [sp], #16 */
728+ o(0xf81f0fe0); /* str x0, [sp, #-16]! */
729+ o(0x3c9f0fe0); /* str q0, [sp, #-16]! */
730+ greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0);
731+ o(0x90000000 | 0); // adrp x0, #sym_data
732+ greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
733+ o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
734+ gen_bounds_call(TOK___bound_local_delete);
735+ o(0x3cc107e0); /* ldr q0, [sp], #16 */
736+ o(0xf84107e0); /* ldr x0, [sp], #16 */
731737 }
732738 #endif
733739
@@ -964,7 +970,7 @@ static unsigned long arm64_pcs(int n, CType **type, unsigned long *a) · 230 unmodified lines
964970 return stack;
965971 }
966972
967−ST_FUNC void gfunc_call(TCCState *S, int nb_args)
973+ST_FUNC void gfunc_call(int nb_args)
968974 {
969975 CType *return_type;
970976 CType **t;
@@ -973,28 +979,28 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args) · 2 unmodified lines
973979 int i;
974980
975981 #ifdef CONFIG_TCC_BCHECK
976− if (S->do_bounds_check)
977− gbound_args(S, nb_args);
982+ if (tcc_state->do_bounds_check)
983+ gbound_args(nb_args);
978984 #endif
979985
980− return_type = &S->tccgen_vtop[-nb_args].type.ref->type;
986+ return_type = &vtop[-nb_args].type.ref->type;
981987 if ((return_type->t & VT_BTYPE) == VT_STRUCT)
982988 --nb_args;
983989
984− t = tcc_malloc(S, (nb_args + 1) * sizeof(*t));
985− a = tcc_malloc(S, (nb_args + 1) * sizeof(*a));
986− a1 = tcc_malloc(S, (nb_args + 1) * sizeof(*a1));
990+ t = tcc_malloc((nb_args + 1) * sizeof(*t));
991+ a = tcc_malloc((nb_args + 1) * sizeof(*a));
992+ a1 = tcc_malloc((nb_args + 1) * sizeof(*a1));
987993
988994 t[0] = return_type;
989995 for (i = 0; i < nb_args; i++)
990− t[nb_args - i] = &S->tccgen_vtop[-i].type;
996+ t[nb_args - i] = &vtop[-i].type;
991997
992998 stack = arm64_pcs(nb_args, t, a);
993999
9941000 // Allocate space for structs replaced by pointer:
9951001 for (i = nb_args; i; i--)
9961002 if (a[i] & 1) {
997− SValue *arg = &S->tccgen_vtop[i - nb_args];
1003+ SValue *arg = &vtop[i - nb_args];
9981004 int align, size = type_size(&arg->type, &align);
9991005 assert((arg->type.t & VT_BTYPE) == VT_STRUCT);
10001006 stack = (stack + align - 1) & -align;
@@ -1005,134 +1011,134 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args) · 4 unmodified lines
10051011 stack = (stack + 15) >> 4 << 4;
10061012
10071013 /* fetch cpu flag before generating any code */
1008− if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP)
1009− gv(S, RC_INT);
1014+ if ((vtop->r & VT_VALMASK) == VT_CMP)
1015+ gv(RC_INT);
10101016
10111017 if (stack >= 0x1000000) // 16Mb
1012− tcc_error(S, "stack size too big %lu", stack);
1018+ tcc_error("stack size too big %lu", stack);
10131019 if (stack & 0xfff)
1014− o(S, 0xd10003ff | (stack & 0xfff) << 10); // sub sp,sp,#(n)
1020+ o(0xd10003ff | (stack & 0xfff) << 10); // sub sp,sp,#(n)
10151021 if (stack >> 12)
1016− o(S, 0xd14003ff | (stack >> 12) << 10);
1022+ o(0xd14003ff | (stack >> 12) << 10);
10171023
10181024 // First pass: set all values on stack
10191025 for (i = nb_args; i; i--) {
1020− vpushv(S, S->tccgen_vtop - nb_args + i);
1026+ vpushv(vtop - nb_args + i);
10211027
10221028 if (a[i] & 1) {
10231029 // struct replaced by pointer
1024− int r = get_reg(S, RC_INT);
1025− arm64_spoff(S, intr(S, r), a1[i]);
1026− vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
1027− vswap(S);
1028− vstore(S);
1030+ int r = get_reg(RC_INT);
1031+ arm64_spoff(intr(r), a1[i]);
1032+ vset(&vtop->type, r | VT_LVAL, 0);
1033+ vswap();
1034+ vstore();
10291035 if (a[i] >= 32) {
10301036 // pointer on stack
1031− r = get_reg(S, RC_INT);
1032− arm64_spoff(S, intr(S, r), a1[i]);
1033− arm64_strx(S, 3, intr(S, r), 31, (a[i] - 32) >> 1 << 1);
1037+ r = get_reg(RC_INT);
1038+ arm64_spoff(intr(r), a1[i]);
1039+ arm64_strx(3, intr(r), 31, (a[i] - 32) >> 1 << 1);
10341040 }
10351041 }
10361042 else if (a[i] >= 32) {
10371043 // value on stack
1038− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1039− int r = get_reg(S, RC_INT);
1040− arm64_spoff(S, intr(S, r), a[i] - 32);
1041− vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
1042− vswap(S);
1043− vstore(S);
1044+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1045+ int r = get_reg(RC_INT);
1046+ arm64_spoff(intr(r), a[i] - 32);
1047+ vset(&vtop->type, r | VT_LVAL, 0);
1048+ vswap();
1049+ vstore();
10441050 }
1045− else if (is_float(S->tccgen_vtop->type.t)) {
1046− gv(S, RC_FLOAT);
1047− arm64_strv(S, arm64_type_size(S->tccgen_vtop[0].type.t),
1048− fltr(S->tccgen_vtop[0].r), 31, a[i] - 32);
1051+ else if (is_float(vtop->type.t)) {
1052+ gv(RC_FLOAT);
1053+ arm64_strv(arm64_type_size(vtop[0].type.t),
1054+ fltr(vtop[0].r), 31, a[i] - 32);
10491055 }
10501056 else {
1051− gv(S, RC_INT);
1052− arm64_strx(S, arm64_type_size(S->tccgen_vtop[0].type.t),
1053− intr(S, S->tccgen_vtop[0].r), 31, a[i] - 32);
1057+ gv(RC_INT);
1058+ arm64_strx(arm64_type_size(vtop[0].type.t),
1059+ intr(vtop[0].r), 31, a[i] - 32);
10541060 }
10551061 }
10561062
1057− --S->tccgen_vtop;
1063+ --vtop;
10581064 }
10591065
10601066 // Second pass: assign values to registers
1061− for (i = nb_args; i; i--, S->tccgen_vtop--) {
1067+ for (i = nb_args; i; i--, vtop--) {
10621068 if (a[i] < 16 && !(a[i] & 1)) {
10631069 // value in general-purpose registers
1064− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1065− int align, size = type_size(&S->tccgen_vtop->type, &align);
1070+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1071+ int align, size = type_size(&vtop->type, &align);
10661072 if (size) {
1067− S->tccgen_vtop->type.t = VT_PTR;
1068− gaddrof(S);
1069− gv(S, RC_R(a[i] / 2));
1070− arm64_ldrs(S, a[i] / 2, size);
1073+ vtop->type.t = VT_PTR;
1074+ gaddrof();
1075+ gv(RC_R(a[i] / 2));
1076+ arm64_ldrs(a[i] / 2, size);
10711077 }
10721078 }
10731079 else
1074− gv(S, RC_R(a[i] / 2));
1080+ gv(RC_R(a[i] / 2));
10751081 }
10761082 else if (a[i] < 16)
10771083 // struct replaced by pointer in register
1078− arm64_spoff(S, a[i] / 2, a1[i]);
1084+ arm64_spoff(a[i] / 2, a1[i]);
10791085 else if (a[i] < 32) {
10801086 // value in floating-point registers
1081− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1082− uint32_t j, sz, n = arm64_hfa(&S->tccgen_vtop->type, &sz);
1083− S->tccgen_vtop->type.t = VT_PTR;
1084− gaddrof(S);
1085− gv(S, RC_R30);
1087+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1088+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
1089+ vtop->type.t = VT_PTR;
1090+ gaddrof();
1091+ gv(RC_R30);
10861092 for (j = 0; j < n; j++)
1087− o(S, 0x3d4003c0 |
1093+ o(0x3d4003c0 |
10881094 (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
10891095 (a[i] / 2 - 8 + j) |
10901096 j << 10); // ldr ([sdq])(*),[x30,#(j * sz)]
10911097 }
10921098 else
1093− gv(S, RC_F(a[i] / 2 - 8));
1099+ gv(RC_F(a[i] / 2 - 8));
10941100 }
10951101 }
10961102
10971103 if ((return_type->t & VT_BTYPE) == VT_STRUCT) {
10981104 if (a[0] == 1) {
10991105 // indirect return: set x8 and discard the stack value
1100− gv(S, RC_R(8));
1101− --S->tccgen_vtop;
1106+ gv(RC_R(8));
1107+ --vtop;
11021108 }
11031109 else
11041110 // return in registers: keep the address for after the call
1105− vswap(S);
1111+ vswap();
11061112 }
11071113
1108− save_regs(S, 0);
1109− arm64_gen_bl_or_b(S, 0);
1110− --S->tccgen_vtop;
1114+ save_regs(0);
1115+ arm64_gen_bl_or_b(0);
1116+ --vtop;
11111117 if (stack & 0xfff)
1112− o(S, 0x910003ff | (stack & 0xfff) << 10); // add sp,sp,#(n)
1118+ o(0x910003ff | (stack & 0xfff) << 10); // add sp,sp,#(n)
11131119 if (stack >> 12)
1114− o(S, 0x914003ff | (stack >> 12) << 10);
1120+ o(0x914003ff | (stack >> 12) << 10);
11151121
11161122 {
11171123 int rt = return_type->t;
11181124 int bt = rt & VT_BTYPE;
11191125 if (bt == VT_STRUCT && !(a[0] & 1)) {
11201126 // A struct was returned in registers, so write it out:
1121− gv(S, RC_R(8));
1122− --S->tccgen_vtop;
1127+ gv(RC_R(8));
1128+ --vtop;
11231129 if (a[0] == 0) {
11241130 int align, size = type_size(return_type, &align);
11251131 assert(size <= 16);
11261132 if (size > 8)
1127− o(S, 0xa9000500); // stp x0,x1,[x8]
1133+ o(0xa9000500); // stp x0,x1,[x8]
11281134 else if (size)
1129− arm64_strx(S, size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0);
1135+ arm64_strx(size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0);
11301136
11311137 }
11321138 else if (a[0] == 16) {
11331139 uint32_t j, sz, n = arm64_hfa(return_type, &sz);
11341140 for (j = 0; j < n; j++)
1135− o(S, 0x3d000100 |
1141+ o(0x3d000100 |
11361142 (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
11371143 (a[i] / 2 - 8 + j) |
11381144 j << 10); // str ([sdq])(*),[x8,#(j * sz)]
@@ -1140,9 +1146,9 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args) · 1 unmodified line
11401146 }
11411147 }
11421148
1143− tcc_free(S, a1);
1144− tcc_free(S, a);
1145− tcc_free(S, t);
1149+ tcc_free(a1);
1150+ tcc_free(a);
1151+ tcc_free(t);
11461152 }
11471153
11481154 static unsigned long arm64_func_va_list_stack;
@@ -1150,7 +1156,7 @@ static int arm64_func_va_list_gr_offs; · 1 unmodified line
11501156 static int arm64_func_va_list_vr_offs;
11511157 static int arm64_func_sub_sp_offset;
11521158
1153−ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym)
1159+ST_FUNC void gfunc_prolog(Sym *func_sym)
11541160 {
11551161 CType *func_type = &func_sym->type;
11561162 int n = 0;
@@ -1159,28 +1165,28 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym) · 2 unmodified lines
11591165 CType **t;
11601166 unsigned long *a;
11611167
1162− S->tccgen_func_vc = 144; // offset of where x8 is stored
1168+ func_vc = 144; // offset of where x8 is stored
11631169
11641170 for (sym = func_type->ref; sym; sym = sym->next)
11651171 ++n;
1166− t = n ? tcc_malloc(S, n * sizeof(*t)) : NULL;
1167− a = n ? tcc_malloc(S, n * sizeof(*a)) : NULL;
1172+ t = n ? tcc_malloc(n * sizeof(*t)) : NULL;
1173+ a = n ? tcc_malloc(n * sizeof(*a)) : NULL;
11681174
11691175 for (sym = func_type->ref; sym; sym = sym->next)
11701176 t[i++] = &sym->type;
11711177
11721178 arm64_func_va_list_stack = arm64_pcs(n - 1, t, a);
11731179
1174− o(S, 0xa9b27bfd); // stp x29,x30,[sp,#-224]!
1175− o(S, 0xad0087e0); // stp q0,q1,[sp,#16]
1176− o(S, 0xad018fe2); // stp q2,q3,[sp,#48]
1177− o(S, 0xad0297e4); // stp q4,q5,[sp,#80]
1178− o(S, 0xad039fe6); // stp q6,q7,[sp,#112]
1179− o(S, 0xa90923e8); // stp x8,x8,[sp,#144]
1180− o(S, 0xa90a07e0); // stp x0,x1,[sp,#160]
1181− o(S, 0xa90b0fe2); // stp x2,x3,[sp,#176]
1182− o(S, 0xa90c17e4); // stp x4,x5,[sp,#192]
1183− o(S, 0xa90d1fe6); // stp x6,x7,[sp,#208]
1180+ o(0xa9b27bfd); // stp x29,x30,[sp,#-224]!
1181+ o(0xad0087e0); // stp q0,q1,[sp,#16]
1182+ o(0xad018fe2); // stp q2,q3,[sp,#48]
1183+ o(0xad0297e4); // stp q4,q5,[sp,#80]
1184+ o(0xad039fe6); // stp q6,q7,[sp,#112]
1185+ o(0xa90923e8); // stp x8,x8,[sp,#144]
1186+ o(0xa90a07e0); // stp x0,x1,[sp,#160]
1187+ o(0xa90b0fe2); // stp x2,x3,[sp,#176]
1188+ o(0xa90c17e4); // stp x4,x5,[sp,#192]
1189+ o(0xa90d1fe6); // stp x6,x7,[sp,#208]
11841190
11851191 arm64_func_va_list_gr_offs = -64;
11861192 arm64_func_va_list_vr_offs = -128;
@@ -1189,7 +1195,7 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym) · 2 unmodified lines
11891195 int off = (a[i] < 16 ? 160 + a[i] / 2 * 8 :
11901196 a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 :
11911197 224 + ((a[i] - 32) >> 1 << 1));
1192− sym_push(S, sym->v & ~SYM_FIELD, &sym->type,
1198+ sym_push(sym->v & ~SYM_FIELD, &sym->type,
11931199 (a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
11941200 off);
11951201
@@ -1209,65 +1215,65 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym) · 13 unmodified lines
12091215 uint32_t j, sz, k = arm64_hfa(&sym->type, &sz);
12101216 if (sz < 16)
12111217 for (j = 0; j < k; j++) {
1212− o(S, 0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
1218+ o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
12131219 ((a[i] - 16) / 2 + j) | (off / sz + j) << 10);
12141220 // str ([sdq])(*),[sp,#(j * sz)]
12151221 }
12161222 }
12171223 }
12181224
1219− tcc_free(S, a);
1220− tcc_free(S, t);
1225+ tcc_free(a);
1226+ tcc_free(t);
12211227
1222− o(S, 0x910003fd); // mov x29,sp
1223− arm64_func_sub_sp_offset = S->tccgen_ind;
1228+ o(0x910003fd); // mov x29,sp
1229+ arm64_func_sub_sp_offset = ind;
12241230 // In gfunc_epilog these will be replaced with code to decrement SP:
1225− o(S, 0xd503201f); // nop
1226− o(S, 0xd503201f); // nop
1227− S->tccgen_loc = 0;
1231+ o(0xd503201f); // nop
1232+ o(0xd503201f); // nop
1233+ loc = 0;
12281234 #ifdef CONFIG_TCC_BCHECK
1229− if (S->do_bounds_check)
1230− gen_bounds_prolog(S);
1235+ if (tcc_state->do_bounds_check)
1236+ gen_bounds_prolog();
12311237 #endif
12321238 }
12331239
1234−ST_FUNC void gen_va_start(TCCState *S)
1240+ST_FUNC void gen_va_start(void)
12351241 {
12361242 int r;
1237− --S->tccgen_vtop; // we don't need the "arg"
1238− gaddrof(S);
1239− r = intr(S, gv(S, RC_INT));
1243+ --vtop; // we don't need the "arg"
1244+ gaddrof();
1245+ r = intr(gv(RC_INT));
12401246
12411247 if (arm64_func_va_list_stack) {
12421248 //xx could use add (immediate) here
1243− arm64_movimm(S, 30, arm64_func_va_list_stack + 224);
1244− o(S, 0x8b1e03be); // add x30,x29,x30
1249+ arm64_movimm(30, arm64_func_va_list_stack + 224);
1250+ o(0x8b1e03be); // add x30,x29,x30
12451251 }
12461252 else
1247− o(S, 0x910383be); // add x30,x29,#224
1248− o(S, 0xf900001e | r << 5); // str x30,[x(r)]
1253+ o(0x910383be); // add x30,x29,#224
1254+ o(0xf900001e | r << 5); // str x30,[x(r)]
12491255
12501256 if (arm64_func_va_list_gr_offs) {
12511257 if (arm64_func_va_list_stack)
1252− o(S, 0x910383be); // add x30,x29,#224
1253− o(S, 0xf900041e | r << 5); // str x30,[x(r),#8]
1258+ o(0x910383be); // add x30,x29,#224
1259+ o(0xf900041e | r << 5); // str x30,[x(r),#8]
12541260 }
12551261
12561262 if (arm64_func_va_list_vr_offs) {
1257− o(S, 0x910243be); // add x30,x29,#144
1258− o(S, 0xf900081e | r << 5); // str x30,[x(r),#16]
1263+ o(0x910243be); // add x30,x29,#144
1264+ o(0xf900081e | r << 5); // str x30,[x(r),#16]
12591265 }
12601266
1261− arm64_movimm(S, 30, arm64_func_va_list_gr_offs);
1262− o(S, 0xb900181e | r << 5); // str w30,[x(r),#24]
1267+ arm64_movimm(30, arm64_func_va_list_gr_offs);
1268+ o(0xb900181e | r << 5); // str w30,[x(r),#24]
12631269
1264− arm64_movimm(S, 30, arm64_func_va_list_vr_offs);
1265− o(S, 0xb9001c1e | r << 5); // str w30,[x(r),#28]
1270+ arm64_movimm(30, arm64_func_va_list_vr_offs);
1271+ o(0xb9001c1e | r << 5); // str w30,[x(r),#28]
12661272
1267− --S->tccgen_vtop;
1273+ --vtop;
12681274 }
12691275
1270−ST_FUNC void gen_va_arg(TCCState *S, CType *t)
1276+ST_FUNC void gen_va_arg(CType *t)
12711277 {
12721278 int align, size = type_size(t, &align);
12731279 unsigned fsize, hfa = arm64_hfa(t, &fsize);
@@ -1278,69 +1284,69 @@ ST_FUNC void gen_va_arg(TCCState *S, CType *t) · 4 unmodified lines
12781284 fsize = size;
12791285 }
12801286
1281− gaddrof(S);
1282− r0 = intr(S, gv(S, RC_INT));
1283− r1 = get_reg(S, RC_INT);
1284− S->tccgen_vtop[0].r = r1 | VT_LVAL;
1285− r1 = intr(S, r1);
1287+ gaddrof();
1288+ r0 = intr(gv(RC_INT));
1289+ r1 = get_reg(RC_INT);
1290+ vtop[0].r = r1 | VT_LVAL;
1291+ r1 = intr(r1);
12861292
12871293 if (!hfa) {
12881294 uint32_t n = size > 16 ? 8 : (size + 7) & -8;
1289− o(S, 0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs
1295+ o(0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs
12901296 if (align == 16) {
12911297 assert(0); // this path untested but needed for __uint128_t
1292− o(S, 0x11003fde); // add w30,w30,#15
1293− o(S, 0x121c6fde); // and w30,w30,#-16
1298+ o(0x11003fde); // add w30,w30,#15
1299+ o(0x121c6fde); // and w30,w30,#-16
12941300 }
1295− o(S, 0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n)
1296− o(S, 0x540000ad); // b.le .+20
1297− o(S, 0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
1298− o(S, 0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n)
1299− o(S, 0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
1300− o(S, 0x14000004); // b .+16
1301− o(S, 0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs
1302− o(S, 0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top
1303− o(S, 0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
1301+ o(0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n)
1302+ o(0x540000ad); // b.le .+20
1303+ o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
1304+ o(0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n)
1305+ o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
1306+ o(0x14000004); // b .+16
1307+ o(0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs
1308+ o(0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top
1309+ o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
13041310 if (size > 16)
1305− o(S, 0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)]
1311+ o(0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)]
13061312 }
13071313 else {
13081314 uint32_t rsz = hfa << 4;
13091315 uint32_t ssz = (size + 7) & -(uint32_t)8;
13101316 uint32_t b1, b2;
1311− o(S, 0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs
1312− o(S, 0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz)
1313− b1 = S->tccgen_ind; o(S, 0x5400000d); // b.le lab1
1314− o(S, 0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
1317+ o(0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs
1318+ o(0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz)
1319+ b1 = ind; o(0x5400000d); // b.le lab1
1320+ o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
13151321 if (fsize == 16) {
1316− o(S, 0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15
1317− o(S, 0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16
1322+ o(0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15
1323+ o(0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16
13181324 }
1319− o(S, 0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz)
1320− o(S, 0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
1321− b2 = S->tccgen_ind; o(S, 0x14000000); // b lab2
1325+ o(0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz)
1326+ o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
1327+ b2 = ind; o(0x14000000); // b lab2
13221328 // lab1:
1323− write32le(cur_text_section->data + b1, 0x5400000d | (S->tccgen_ind - b1) << 3);
1324− o(S, 0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs
1325− o(S, 0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top
1329+ write32le(cur_text_section->data + b1, 0x5400000d | (ind - b1) << 3);
1330+ o(0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs
1331+ o(0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top
13261332 if (hfa == 1 || fsize == 16)
1327− o(S, 0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
1333+ o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
13281334 else {
13291335 // We need to change the layout of this HFA.
13301336 // Get some space on the stack using global variable "loc":
1331− S->tccgen_loc = (S->tccgen_loc - size) & -(uint32_t)align;
1332− o(S, 0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw
1333− arm64_movimm(S, r1, S->tccgen_loc);
1334− o(S, 0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1)
1335− o(S, 0x4c402bdc | (uint32_t)fsize << 7 |
1337+ loc = (loc - size) & -(uint32_t)align;
1338+ o(0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw
1339+ arm64_movimm(r1, loc);
1340+ o(0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1)
1341+ o(0x4c402bdc | (uint32_t)fsize << 7 |
13361342 (uint32_t)(hfa == 2) << 15 |
13371343 (uint32_t)(hfa == 3) << 14); // ld1 {v28.(4s|2d),...},[x30]
1338− o(S, 0x0d00801c | r1 << 5 | (fsize == 8) << 10 |
1344+ o(0x0d00801c | r1 << 5 | (fsize == 8) << 10 |
13391345 (uint32_t)(hfa != 2) << 13 |
13401346 (uint32_t)(hfa != 3) << 21); // st(hfa) {v28.(s|d),...}[0],[x(r1)]
13411347 }
13421348 // lab2:
1343− write32le(cur_text_section->data + b2, 0x14000000 | (S->tccgen_ind - b2) >> 2);
1349+ write32le(cur_text_section->data + b2, 0x14000000 | (ind - b2) >> 2);
13441350 }
13451351 }
13461352
@@ -1350,7 +1356,7 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, · 3 unmodified lines
13501356 return 0;
13511357 }
13521358
1353−ST_FUNC void gfunc_return(TCCState *S, CType *func_type)
1359+ST_FUNC void gfunc_return(CType *func_type)
13541360 {
13551361 CType *t = func_type;
13561362 unsigned long a;
@@ -1362,52 +1368,52 @@ ST_FUNC void gfunc_return(TCCState *S, CType *func_type) · 5 unmodified lines
13621368 case 0:
13631369 if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
13641370 int align, size = type_size(func_type, &align);
1365− gaddrof(S);
1366− gv(S, RC_R(0));
1367− arm64_ldrs(S, 0, size);
1371+ gaddrof();
1372+ gv(RC_R(0));
1373+ arm64_ldrs(0, size);
13681374 }
13691375 else
1370− gv(S, RC_IRET);
1376+ gv(RC_IRET);
13711377 break;
13721378 case 1: {
13731379 CType type = *func_type;
1374− mk_pointer(S, &type);
1375− vset(S, &type, VT_LOCAL | VT_LVAL, S->tccgen_func_vc);
1376− indir(S);
1377− vswap(S);
1378− vstore(S);
1380+ mk_pointer(&type);
1381+ vset(&type, VT_LOCAL | VT_LVAL, func_vc);
1382+ indir();
1383+ vswap();
1384+ vstore();
13791385 break;
13801386 }
13811387 case 16:
13821388 if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
1383− uint32_t j, sz, n = arm64_hfa(&S->tccgen_vtop->type, &sz);
1384− gaddrof(S);
1385− gv(S, RC_R(0));
1389+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
1390+ gaddrof();
1391+ gv(RC_R(0));
13861392 for (j = 0; j < n; j++)
1387− o(S, 0x3d400000 |
1393+ o(0x3d400000 |
13881394 (sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
13891395 j | j << 10); // ldr ([sdq])(*),[x0,#(j * sz)]
13901396 }
13911397 else
1392− gv(S, RC_FRET);
1398+ gv(RC_FRET);
13931399 break;
13941400 default:
13951401 assert(0);
13961402 }
1397− S->tccgen_vtop--;
1403+ vtop--;
13981404 }
13991405
1400−ST_FUNC void gfunc_epilog(TCCState *S)
1406+ST_FUNC void gfunc_epilog(void)
14011407 {
14021408 #ifdef CONFIG_TCC_BCHECK
1403− if (S->do_bounds_check)
1404− gen_bounds_epilog(S);
1409+ if (tcc_state->do_bounds_check)
1410+ gen_bounds_epilog();
14051411 #endif
14061412
1407− if (S->tccgen_loc) {
1413+ if (loc) {
14081414 // Insert instructions to subtract size of stack frame from SP.
14091415 unsigned char *ptr = cur_text_section->data + arm64_func_sub_sp_offset;
1410− uint64_t diff = (-S->tccgen_loc + 15) & ~15;
1416+ uint64_t diff = (-loc + 15) & ~15;
14111417 if (!(diff >> 24)) {
14121418 if (diff & 0xfff) // sub sp,sp,#(diff & 0xfff)
14131419 write32le(ptr, 0xd10003ff | (diff & 0xfff) << 10);
@@ -1433,40 +1439,40 @@ ST_FUNC void gfunc_epilog(TCCState *S) · 19 unmodified lines
14331439 // sub sp,sp,x16,lsl #(j)
14341440 }
14351441 }
1436− o(S, 0x910003bf); // mov sp,x29
1437− o(S, 0xa8ce7bfd); // ldp x29,x30,[sp],#224
1442+ o(0x910003bf); // mov sp,x29
1443+ o(0xa8ce7bfd); // ldp x29,x30,[sp],#224
14381444
1439− o(S, 0xd65f03c0); // ret
1445+ o(0xd65f03c0); // ret
14401446 }
14411447
1442−ST_FUNC void gen_fill_nops(TCCState *S, int bytes)
1448+ST_FUNC void gen_fill_nops(int bytes)
14431449 {
14441450 if ((bytes & 3))
1445− tcc_error(S, "alignment of code section not multiple of 4");
1451+ tcc_error("alignment of code section not multiple of 4");
14461452 while (bytes > 0) {
1447− o(S, 0xd503201f); // nop
1453+ o(0xd503201f); // nop
14481454 bytes -= 4;
14491455 }
14501456 }
14511457
14521458 // Generate forward branch to label:
1453−ST_FUNC int gjmp(TCCState *S, int t)
1459+ST_FUNC int gjmp(int t)
14541460 {
1455− int r = S->tccgen_ind;
1456− if (S->tccgen_nocode_wanted)
1461+ int r = ind;
1462+ if (nocode_wanted)
14571463 return t;
1458− o(S, t);
1464+ o(t);
14591465 return r;
14601466 }
14611467
14621468 // Generate branch to known address:
1463−ST_FUNC void gjmp_addr(TCCState *S, int a)
1469+ST_FUNC void gjmp_addr(int a)
14641470 {
1465− assert(a - S->tccgen_ind + 0x8000000 < 0x10000000);
1466− o(S, 0x14000000 | ((a - S->tccgen_ind) >> 2 & 0x3ffffff));
1471+ assert(a - ind + 0x8000000 < 0x10000000);
1472+ o(0x14000000 | ((a - ind) >> 2 & 0x3ffffff));
14671473 }
14681474
1469−ST_FUNC int gjmp_append(TCCState *S, int n, int t)
1475+ST_FUNC int gjmp_append(int n, int t)
14701476 {
14711477 void *p;
14721478 /* insert vtop->c jump list in t */
@@ -1480,61 +1486,61 @@ ST_FUNC int gjmp_append(TCCState *S, int n, int t) · 7 unmodified lines
14801486 return t;
14811487 }
14821488
1483−void arm64_vset_VT_CMP(TCCState *S, int op)
1489+void arm64_vset_VT_CMP(int op)
14841490 {
14851491 if (op >= TOK_ULT && op <= TOK_GT) {
1486− S->tccgen_vtop->cmp_r = S->tccgen_vtop->r;
1487− vset_VT_CMP(S, 0x80);
1492+ vtop->cmp_r = vtop->r;
1493+ vset_VT_CMP(0x80);
14881494 }
14891495 }
14901496
1491−static void arm64_gen_opil(TCCState *S, int op, uint32_t l);
1497+static void arm64_gen_opil(int op, uint32_t l);
14921498
1493−static void arm64_load_cmp(TCCState *S, int r, SValue *sv)
1499+static void arm64_load_cmp(int r, SValue *sv)
14941500 {
14951501 sv->r = sv->cmp_r;
14961502 if (sv->c.i & 1) {
1497− vpushi(S, 1);
1498− arm64_gen_opil(S, '^', 0);
1503+ vpushi(1);
1504+ arm64_gen_opil('^', 0);
14991505 }
15001506 if (r != sv->r) {
1501− load(S, r, sv);
1507+ load(r, sv);
15021508 sv->r = r;
15031509 }
15041510 }
15051511
1506−ST_FUNC int gjmp_cond(TCCState *S, int op, int t)
1512+ST_FUNC int gjmp_cond(int op, int t)
15071513 {
1508− int bt = S->tccgen_vtop->type.t & VT_BTYPE;
1514+ int bt = vtop->type.t & VT_BTYPE;
15091515
15101516 int inv = op & 1;
1511− S->tccgen_vtop->r = S->tccgen_vtop->cmp_r;
1517+ vtop->r = vtop->cmp_r;
15121518
15131519 if (bt == VT_LDOUBLE) {
1514− uint32_t a, b, f = fltr(gv(S, RC_FLOAT));
1515− a = get_reg(S, RC_INT);
1516− vpushi(S, 0);
1517− S->tccgen_vtop[0].r = a;
1518− b = get_reg(S, RC_INT);
1519− a = intr(S, a);
1520− b = intr(S, b);
1521− o(S, 0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0]
1522− o(S, 0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1]
1523− o(S, 0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1
1524− o(S, 0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8
1525− --S->tccgen_vtop;
1520+ uint32_t a, b, f = fltr(gv(RC_FLOAT));
1521+ a = get_reg(RC_INT);
1522+ vpushi(0);
1523+ vtop[0].r = a;
1524+ b = get_reg(RC_INT);
1525+ a = intr(a);
1526+ b = intr(b);
1527+ o(0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0]
1528+ o(0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1]
1529+ o(0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1
1530+ o(0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8
1531+ --vtop;
15261532 }
15271533 else if (bt == VT_FLOAT || bt == VT_DOUBLE) {
1528− uint32_t a = fltr(gv(S, RC_FLOAT));
1529− o(S, 0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp
1530− o(S, 0x54000040 | !!inv); // b.eq/b.ne .+8
1534+ uint32_t a = fltr(gv(RC_FLOAT));
1535+ o(0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp
1536+ o(0x54000040 | !!inv); // b.eq/b.ne .+8
15311537 }
15321538 else {
15331539 uint32_t ll = (bt == VT_PTR || bt == VT_LLONG);
1534− uint32_t a = intr(S, gv(S, RC_INT));
1535− o(S, 0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8
1540+ uint32_t a = intr(gv(RC_INT));
1541+ o(0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8
15361542 }
1537− return gjmp(S, t);
1543+ return gjmp(t);
15381544 }
15391545
15401546 static int arm64_iconst(uint64_t *val, SValue *sv)
@@ -1551,7 +1557,7 @@ static int arm64_iconst(uint64_t *val, SValue *sv) · 10 unmodified lines
15511557 return 1;
15521558 }
15531559
1554−static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val,
1560+static int arm64_gen_opic(int op, uint32_t l, int rev, uint64_t val,
15551561 uint32_t x, uint32_t a)
15561562 {
15571563 if (op == '-' && !rev) {
@@ -1567,30 +1573,30 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val · 9 unmodified lines
15671573 val = s ? -val : val;
15681574 val = l ? val : (uint32_t)val;
15691575 if (!(val & ~(uint64_t)0xfff))
1570− o(S, 0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10);
1576+ o(0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10);
15711577 else if (!(val & ~(uint64_t)0xfff000))
1572− o(S, 0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10);
1578+ o(0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10);
15731579 else {
1574− arm64_movimm(S, 30, val); // use x30
1575− o(S, 0x0b1e0000 | l << 31 | s << 30 | x | a << 5);
1580+ arm64_movimm(30, val); // use x30
1581+ o(0x0b1e0000 | l << 31 | s << 30 | x | a << 5);
15761582 }
15771583 return 1;
15781584 }
15791585
15801586 case '-':
15811587 if (!val)
1582− o(S, 0x4b0003e0 | l << 31 | x | a << 16); // neg
1588+ o(0x4b0003e0 | l << 31 | x | a << 16); // neg
15831589 else if (val == (l ? (uint64_t)-1 : (uint32_t)-1))
1584− o(S, 0x2a2003e0 | l << 31 | x | a << 16); // mvn
1590+ o(0x2a2003e0 | l << 31 | x | a << 16); // mvn
15851591 else {
1586− arm64_movimm(S, 30, val); // use x30
1587− o(S, 0x4b0003c0 | l << 31 | x | a << 16); // sub
1592+ arm64_movimm(30, val); // use x30
1593+ o(0x4b0003c0 | l << 31 | x | a << 16); // sub
15881594 }
15891595 return 1;
15901596
15911597 case '^':
15921598 if (val == -1 || (val == 0xffffffff && !l)) {
1593− o(S, 0x2a2003e0 | l << 31 | x | a << 16); // mvn
1599+ o(0x2a2003e0 | l << 31 | x | a << 16); // mvn
15941600 return 1;
15951601 }
15961602 // fall through
@@ -1599,7 +1605,7 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val · 2 unmodified lines
15991605 int e = arm64_encode_bimm64(l ? val : val | val << 32);
16001606 if (e < 0)
16011607 return 0;
1602− o(S, (op == '&' ? 0x12000000 :
1608+ o((op == '&' ? 0x12000000 :
16031609 op == '|' ? 0x32000000 : 0x52000000) |
16041610 l << 31 | x | a << 5 | (uint32_t)e << 10);
16051611 return 1;
@@ -1614,14 +1620,14 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val · 8 unmodified lines
16141620 return 0;
16151621 if (!val) {
16161622 // tcc_warning("shift count >= width of type");
1617− o(S, 0x2a0003e0 | l << 31 | a << 16);
1623+ o(0x2a0003e0 | l << 31 | a << 16);
16181624 return 1;
16191625 }
16201626 else if (op == TOK_SHL)
1621− o(S, 0x53000000 | l << 31 | l << 22 | x | a << 5 |
1627+ o(0x53000000 | l << 31 | l << 22 | x | a << 5 |
16221628 (n - val) << 16 | (n - 1 - val) << 10); // lsl
16231629 else
1624− o(S, 0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 |
1630+ o(0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 |
16251631 x | a << 5 | val << 16 | (n - 1) << 10); // lsr/asr
16261632 return 1;
16271633 }
@@ -1630,7 +1636,7 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val · 2 unmodified lines
16301636 return 0;
16311637 }
16321638
1633−static void arm64_gen_opil(TCCState *S, int op, uint32_t l)
1639+static void arm64_gen_opil(int op, uint32_t l)
16341640 {
16351641 uint32_t x, a, b;
16361642
@@ -1639,122 +1645,122 @@ static void arm64_gen_opil(TCCState *S, int op, uint32_t l) · 2 unmodified lines
16391645 uint64_t val;
16401646 int rev = 1;
16411647
1642− if (arm64_iconst(0, &S->tccgen_vtop[0])) {
1643− vswap(S);
1648+ if (arm64_iconst(0, &vtop[0])) {
1649+ vswap();
16441650 rev = 0;
16451651 }
1646− if (arm64_iconst(&val, &S->tccgen_vtop[-1])) {
1647− gv(S, RC_INT);
1648− a = intr(S, S->tccgen_vtop[0].r);
1649− --S->tccgen_vtop;
1650− x = get_reg(S, RC_INT);
1651− ++S->tccgen_vtop;
1652− if (arm64_gen_opic(S, op, l, rev, val, intr(S, x), a)) {
1653− S->tccgen_vtop[0].r = x;
1654− vswap(S);
1655− --S->tccgen_vtop;
1652+ if (arm64_iconst(&val, &vtop[-1])) {
1653+ gv(RC_INT);
1654+ a = intr(vtop[0].r);
1655+ --vtop;
1656+ x = get_reg(RC_INT);
1657+ ++vtop;
1658+ if (arm64_gen_opic(op, l, rev, val, intr(x), a)) {
1659+ vtop[0].r = x;
1660+ vswap();
1661+ --vtop;
16561662 return;
16571663 }
16581664 }
16591665 if (!rev)
1660− vswap(S);
1666+ vswap();
16611667 }
16621668
1663− gv2(S, RC_INT, RC_INT);
1664− assert(S->tccgen_vtop[-1].r < VT_CONST && S->tccgen_vtop[0].r < VT_CONST);
1665− a = intr(S, S->tccgen_vtop[-1].r);
1666− b = intr(S, S->tccgen_vtop[0].r);
1667− S->tccgen_vtop -= 2;
1668− x = get_reg(S, RC_INT);
1669− ++S->tccgen_vtop;
1670− S->tccgen_vtop[0].r = x;
1671− x = intr(S, x);
1669+ gv2(RC_INT, RC_INT);
1670+ assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST);
1671+ a = intr(vtop[-1].r);
1672+ b = intr(vtop[0].r);
1673+ vtop -= 2;
1674+ x = get_reg(RC_INT);
1675+ ++vtop;
1676+ vtop[0].r = x;
1677+ x = intr(x);
16721678
16731679 switch (op) {
16741680 case '%':
16751681 // Use x30 for quotient:
1676− o(S, 0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv
1677− o(S, 0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
1682+ o(0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv
1683+ o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
16781684 b << 16 | a << 10); // msub
16791685 break;
16801686 case '&':
1681− o(S, 0x0a000000 | l << 31 | x | a << 5 | b << 16); // and
1687+ o(0x0a000000 | l << 31 | x | a << 5 | b << 16); // and
16821688 break;
16831689 case '*':
1684− o(S, 0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul
1690+ o(0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul
16851691 break;
16861692 case '+':
1687− o(S, 0x0b000000 | l << 31 | x | a << 5 | b << 16); // add
1693+ o(0x0b000000 | l << 31 | x | a << 5 | b << 16); // add
16881694 break;
16891695 case '-':
1690− o(S, 0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
1696+ o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
16911697 break;
16921698 case '/':
1693− o(S, 0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
1699+ o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
16941700 break;
16951701 case '^':
1696− o(S, 0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor
1702+ o(0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor
16971703 break;
16981704 case '|':
1699− o(S, 0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr
1705+ o(0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr
17001706 break;
17011707 case TOK_EQ:
1702− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1703− o(S, 0x1a9f17e0 | x); // cset wA,eq
1708+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1709+ o(0x1a9f17e0 | x); // cset wA,eq
17041710 break;
17051711 case TOK_GE:
1706− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1707− o(S, 0x1a9fb7e0 | x); // cset wA,ge
1712+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1713+ o(0x1a9fb7e0 | x); // cset wA,ge
17081714 break;
17091715 case TOK_GT:
1710− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1711− o(S, 0x1a9fd7e0 | x); // cset wA,gt
1716+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1717+ o(0x1a9fd7e0 | x); // cset wA,gt
17121718 break;
17131719 case TOK_LE:
1714− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1715− o(S, 0x1a9fc7e0 | x); // cset wA,le
1720+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1721+ o(0x1a9fc7e0 | x); // cset wA,le
17161722 break;
17171723 case TOK_LT:
1718− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1719− o(S, 0x1a9fa7e0 | x); // cset wA,lt
1724+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1725+ o(0x1a9fa7e0 | x); // cset wA,lt
17201726 break;
17211727 case TOK_NE:
1722− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1723− o(S, 0x1a9f07e0 | x); // cset wA,ne
1728+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1729+ o(0x1a9f07e0 | x); // cset wA,ne
17241730 break;
17251731 case TOK_SAR:
1726− o(S, 0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr
1732+ o(0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr
17271733 break;
17281734 case TOK_SHL:
1729− o(S, 0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl
1735+ o(0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl
17301736 break;
17311737 case TOK_SHR:
1732− o(S, 0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
1738+ o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
17331739 break;
17341740 case TOK_UDIV:
17351741 case TOK_PDIV:
1736− o(S, 0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
1742+ o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
17371743 break;
17381744 case TOK_UGE:
1739− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1740− o(S, 0x1a9f37e0 | x); // cset wA,cs
1745+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1746+ o(0x1a9f37e0 | x); // cset wA,cs
17411747 break;
17421748 case TOK_UGT:
1743− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1744− o(S, 0x1a9f97e0 | x); // cset wA,hi
1749+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1750+ o(0x1a9f97e0 | x); // cset wA,hi
17451751 break;
17461752 case TOK_ULT:
1747− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1748− o(S, 0x1a9f27e0 | x); // cset wA,cc
1753+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1754+ o(0x1a9f27e0 | x); // cset wA,cc
17491755 break;
17501756 case TOK_ULE:
1751− o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1752− o(S, 0x1a9f87e0 | x); // cset wA,ls
1757+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
1758+ o(0x1a9f87e0 | x); // cset wA,ls
17531759 break;
17541760 case TOK_UMOD:
17551761 // Use x30 for quotient:
1756− o(S, 0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv
1757− o(S, 0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
1762+ o(0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv
1763+ o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
17581764 b << 16 | a << 10); // msub
17591765 break;
17601766 default:
@@ -1762,24 +1768,24 @@ static void arm64_gen_opil(TCCState *S, int op, uint32_t l) · 1 unmodified line
17621768 }
17631769 }
17641770
1765−ST_FUNC void gen_opi(TCCState *S, int op)
1771+ST_FUNC void gen_opi(int op)
17661772 {
1767− arm64_gen_opil(S, op, 0);
1768− arm64_vset_VT_CMP(S, op);
1773+ arm64_gen_opil(op, 0);
1774+ arm64_vset_VT_CMP(op);
17691775 }
17701776
1771−ST_FUNC void gen_opl(TCCState* S, int op)
1777+ST_FUNC void gen_opl(int op)
17721778 {
1773− arm64_gen_opil(S, op, 1);
1774− arm64_vset_VT_CMP(S, op);
1779+ arm64_gen_opil(op, 1);
1780+ arm64_vset_VT_CMP(op);
17751781 }
17761782
1777−ST_FUNC void gen_opf(TCCState *S, int op)
1783+ST_FUNC void gen_opf(int op)
17781784 {
17791785 uint32_t x, a, b, dbl;
17801786
1781− if (S->tccgen_vtop[0].type.t == VT_LDOUBLE) {
1782− CType type = S->tccgen_vtop[0].type;
1787+ if (vtop[0].type.t == VT_LDOUBLE) {
1788+ CType type = vtop[0].type;
17831789 int func = 0;
17841790 int cond = -1;
17851791 switch (op) {
@@ -1795,162 +1801,162 @@ ST_FUNC void gen_opf(TCCState *S, int op) · 9 unmodified lines
17951801 case TOK_GT: func = TOK___gttf2; cond = 13; break;
17961802 default: assert(0); break;
17971803 }
1798− vpush_helper_func(S, func);
1799− vrott(S, 3);
1800− gfunc_call(S, 2);
1801− vpushi(S, 0);
1802− S->tccgen_vtop->r = cond < 0 ? REG_FRET : REG_IRET;
1804+ vpush_helper_func(func);
1805+ vrott(3);
1806+ gfunc_call(2);
1807+ vpushi(0);
1808+ vtop->r = cond < 0 ? REG_FRET : REG_IRET;
18031809 if (cond < 0)
1804− S->tccgen_vtop->type = type;
1810+ vtop->type = type;
18051811 else {
1806− o(S, 0x7100001f); // cmp w0,#0
1807− o(S, 0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond)
1812+ o(0x7100001f); // cmp w0,#0
1813+ o(0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond)
18081814 }
18091815 return;
18101816 }
18111817
1812− dbl = S->tccgen_vtop[0].type.t != VT_FLOAT;
1813− gv2(S, RC_FLOAT, RC_FLOAT);
1814− assert(S->tccgen_vtop[-1].r < VT_CONST && S->tccgen_vtop[0].r < VT_CONST);
1815− a = fltr(S->tccgen_vtop[-1].r);
1816− b = fltr(S->tccgen_vtop[0].r);
1817− S->tccgen_vtop -= 2;
1818+ dbl = vtop[0].type.t != VT_FLOAT;
1819+ gv2(RC_FLOAT, RC_FLOAT);
1820+ assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST);
1821+ a = fltr(vtop[-1].r);
1822+ b = fltr(vtop[0].r);
1823+ vtop -= 2;
18181824 switch (op) {
18191825 case TOK_EQ: case TOK_NE:
18201826 case TOK_LT: case TOK_GE: case TOK_LE: case TOK_GT:
1821− x = get_reg(S, RC_INT);
1822− ++S->tccgen_vtop;
1823− S->tccgen_vtop[0].r = x;
1824− x = intr(S, x);
1827+ x = get_reg(RC_INT);
1828+ ++vtop;
1829+ vtop[0].r = x;
1830+ x = intr(x);
18251831 break;
18261832 default:
1827− x = get_reg(S, RC_FLOAT);
1828− ++S->tccgen_vtop;
1829− S->tccgen_vtop[0].r = x;
1833+ x = get_reg(RC_FLOAT);
1834+ ++vtop;
1835+ vtop[0].r = x;
18301836 x = fltr(x);
18311837 break;
18321838 }
18331839
18341840 switch (op) {
18351841 case '*':
1836− o(S, 0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul
1842+ o(0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul
18371843 break;
18381844 case '+':
1839− o(S, 0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd
1845+ o(0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd
18401846 break;
18411847 case '-':
1842− o(S, 0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub
1848+ o(0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub
18431849 break;
18441850 case '/':
1845− o(S, 0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv
1851+ o(0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv
18461852 break;
18471853 case TOK_EQ:
1848− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1849− o(S, 0x1a9f17e0 | x); // cset w(x),eq
1854+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1855+ o(0x1a9f17e0 | x); // cset w(x),eq
18501856 break;
18511857 case TOK_GE:
1852− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1853− o(S, 0x1a9fb7e0 | x); // cset w(x),ge
1858+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1859+ o(0x1a9fb7e0 | x); // cset w(x),ge
18541860 break;
18551861 case TOK_GT:
1856− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1857− o(S, 0x1a9fd7e0 | x); // cset w(x),gt
1862+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1863+ o(0x1a9fd7e0 | x); // cset w(x),gt
18581864 break;
18591865 case TOK_LE:
1860− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1861− o(S, 0x1a9f87e0 | x); // cset w(x),ls
1866+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1867+ o(0x1a9f87e0 | x); // cset w(x),ls
18621868 break;
18631869 case TOK_LT:
1864− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1865− o(S, 0x1a9f57e0 | x); // cset w(x),mi
1870+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1871+ o(0x1a9f57e0 | x); // cset w(x),mi
18661872 break;
18671873 case TOK_NE:
1868− o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1869− o(S, 0x1a9f07e0 | x); // cset w(x),ne
1874+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
1875+ o(0x1a9f07e0 | x); // cset w(x),ne
18701876 break;
18711877 default:
18721878 assert(0);
18731879 }
1874− arm64_vset_VT_CMP(S, op);
1880+ arm64_vset_VT_CMP(op);
18751881 }
18761882
18771883 // Generate sign extension from 32 to 64 bits:
1878−ST_FUNC void gen_cvt_sxtw(TCCState *S)
1884+ST_FUNC void gen_cvt_sxtw(void)
18791885 {
1880− uint32_t r = intr(S, gv(S, RC_INT));
1881− o(S, 0x93407c00 | r | r << 5); // sxtw x(r),w(r)
1886+ uint32_t r = intr(gv(RC_INT));
1887+ o(0x93407c00 | r | r << 5); // sxtw x(r),w(r)
18821888 }
18831889
18841890 /* char/short to int conversion */
1885−ST_FUNC void gen_cvt_csti(TCCState *S, int t)
1891+ST_FUNC void gen_cvt_csti(int t)
18861892 {
1887− int r = intr(S, gv(S, RC_INT));
1888− o(S, 0x13001c00
1893+ int r = intr(gv(RC_INT));
1894+ o(0x13001c00
18891895 | ((t & VT_BTYPE) == VT_SHORT) << 13
18901896 | (uint32_t)!!(t & VT_UNSIGNED) << 30
18911897 | r | r << 5); // [su]xt[bh] w(r),w(r)
18921898 }
18931899
1894−ST_FUNC void gen_cvt_itof(TCCState *S, int t)
1900+ST_FUNC void gen_cvt_itof(int t)
18951901 {
18961902 if (t == VT_LDOUBLE) {
1897− int f = S->tccgen_vtop->type.t;
1903+ int f = vtop->type.t;
18981904 int func = (f & VT_BTYPE) == VT_LLONG ?
18991905 (f & VT_UNSIGNED ? TOK___floatunditf : TOK___floatditf) :
19001906 (f & VT_UNSIGNED ? TOK___floatunsitf : TOK___floatsitf);
1901− vpush_helper_func(S, func);
1902− vrott(S, 2);
1903− gfunc_call(S, 1);
1904− vpushi(S, 0);
1905− S->tccgen_vtop->type.t = t;
1906− S->tccgen_vtop->r = REG_FRET;
1907+ vpush_helper_func(func);
1908+ vrott(2);
1909+ gfunc_call(1);
1910+ vpushi(0);
1911+ vtop->type.t = t;
1912+ vtop->r = REG_FRET;
19071913 return;
19081914 }
19091915 else {
1910− int d, n = intr(S, gv(S, RC_INT));
1911− int s = !(S->tccgen_vtop->type.t & VT_UNSIGNED);
1912− uint32_t l = ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG);
1913− --S->tccgen_vtop;
1914− d = get_reg(S, RC_FLOAT);
1915− ++S->tccgen_vtop;
1916− S->tccgen_vtop[0].r = d;
1917− o(S, 0x1e220000 | (uint32_t)!s << 16 |
1916+ int d, n = intr(gv(RC_INT));
1917+ int s = !(vtop->type.t & VT_UNSIGNED);
1918+ uint32_t l = ((vtop->type.t & VT_BTYPE) == VT_LLONG);
1919+ --vtop;
1920+ d = get_reg(RC_FLOAT);
1921+ ++vtop;
1922+ vtop[0].r = d;
1923+ o(0x1e220000 | (uint32_t)!s << 16 |
19181924 (uint32_t)(t != VT_FLOAT) << 22 | fltr(d) |
19191925 l << 31 | n << 5); // [us]cvtf [sd](d),[wx](n)
19201926 }
19211927 }
19221928
1923−ST_FUNC void gen_cvt_ftoi(TCCState *S, int t)
1929+ST_FUNC void gen_cvt_ftoi(int t)
19241930 {
1925− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
1931+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
19261932 int func = (t & VT_BTYPE) == VT_LLONG ?
19271933 (t & VT_UNSIGNED ? TOK___fixunstfdi : TOK___fixtfdi) :
19281934 (t & VT_UNSIGNED ? TOK___fixunstfsi : TOK___fixtfsi);
1929− vpush_helper_func(S, func);
1930− vrott(S, 2);
1931− gfunc_call(S, 1);
1932− vpushi(S, 0);
1933− S->tccgen_vtop->type.t = t;
1934− S->tccgen_vtop->r = REG_IRET;
1935+ vpush_helper_func(func);
1936+ vrott(2);
1937+ gfunc_call(1);
1938+ vpushi(0);
1939+ vtop->type.t = t;
1940+ vtop->r = REG_IRET;
19351941 return;
19361942 }
19371943 else {
1938− int d, n = fltr(gv(S, RC_FLOAT));
1939− uint32_t l = ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FLOAT);
1940− --S->tccgen_vtop;
1941− d = get_reg(S, RC_INT);
1942− ++S->tccgen_vtop;
1943− S->tccgen_vtop[0].r = d;
1944− o(S, 0x1e380000 |
1944+ int d, n = fltr(gv(RC_FLOAT));
1945+ uint32_t l = ((vtop->type.t & VT_BTYPE) != VT_FLOAT);
1946+ --vtop;
1947+ d = get_reg(RC_INT);
1948+ ++vtop;
1949+ vtop[0].r = d;
1950+ o(0x1e380000 |
19451951 (uint32_t)!!(t & VT_UNSIGNED) << 16 |
1946− (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(S, d) |
1952+ (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(d) |
19471953 l << 22 | n << 5); // fcvtz[su] [wx](d),[sd](n)
19481954 }
19491955 }
19501956
1951−ST_FUNC void gen_cvt_ftof(TCCState *S, int t)
1957+ST_FUNC void gen_cvt_ftof(int t)
19521958 {
1953− int f = S->tccgen_vtop[0].type.t & VT_BTYPE;
1959+ int f = vtop[0].type.t & VT_BTYPE;
19541960 assert(t == VT_FLOAT || t == VT_DOUBLE || t == VT_LDOUBLE);
19551961 assert(f == VT_FLOAT || f == VT_DOUBLE || f == VT_LDOUBLE);
19561962 if (t == f)
@@ -1960,142 +1966,142 @@ ST_FUNC void gen_cvt_ftof(TCCState *S, int t) · 3 unmodified lines
19601966 int func = (t == VT_LDOUBLE) ?
19611967 (f == VT_FLOAT ? TOK___extendsftf2 : TOK___extenddftf2) :
19621968 (t == VT_FLOAT ? TOK___trunctfsf2 : TOK___trunctfdf2);
1963− vpush_helper_func(S, func);
1964− vrott(S, 2);
1965− gfunc_call(S, 1);
1966− vpushi(S, 0);
1967− S->tccgen_vtop->type.t = t;
1968− S->tccgen_vtop->r = REG_FRET;
1969+ vpush_helper_func(func);
1970+ vrott(2);
1971+ gfunc_call(1);
1972+ vpushi(0);
1973+ vtop->type.t = t;
1974+ vtop->r = REG_FRET;
19691975 }
19701976 else {
19711977 int x, a;
1972− gv(S, RC_FLOAT);
1973− assert(S->tccgen_vtop[0].r < VT_CONST);
1974− a = fltr(S->tccgen_vtop[0].r);
1975− --S->tccgen_vtop;
1976− x = get_reg(S, RC_FLOAT);
1977− ++S->tccgen_vtop;
1978− S->tccgen_vtop[0].r = x;
1978+ gv(RC_FLOAT);
1979+ assert(vtop[0].r < VT_CONST);
1980+ a = fltr(vtop[0].r);
1981+ --vtop;
1982+ x = get_reg(RC_FLOAT);
1983+ ++vtop;
1984+ vtop[0].r = x;
19791985 x = fltr(x);
19801986
19811987 if (f == VT_FLOAT)
1982− o(S, 0x1e22c000 | x | a << 5); // fcvt d(x),s(a)
1988+ o(0x1e22c000 | x | a << 5); // fcvt d(x),s(a)
19831989 else
1984− o(S, 0x1e624000 | x | a << 5); // fcvt s(x),d(a)
1990+ o(0x1e624000 | x | a << 5); // fcvt s(x),d(a)
19851991 }
19861992 }
19871993
19881994 /* increment tcov counter */
1989−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
1995+ST_FUNC void gen_increment_tcov (SValue *sv)
19901996 {
19911997 int r1, r2;
19921998
1993− vpushv(S, sv);
1994− S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
1995− r2 = get_reg(S, RC_INT);
1996− greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
1997− o(S, 0x90000000 | r1); // adrp r1, #sym
1998− greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
1999− o(S, 0xf9400000 | r1 | (r1 << 5)); // ld xr,[xr, #sym]
2000− o(S, 0xf9400000 | (intr(S, r1)<<5) | intr(S, r2)); // ldr r2, [r1]
2001− o(S, 0x91000400 | (intr(S, r2)<<5) | intr(S, r2)); // add r2, r2, #1
2002− o(S, 0xf9000000 | (intr(S, r1)<<5) | intr(S, r2)); // str r2, [r1]
2003− vpop(S);
1999+ vpushv(sv);
2000+ vtop->r = r1 = get_reg(RC_INT);
2001+ r2 = get_reg(RC_INT);
2002+ greloca(cur_text_section, sv->sym, ind, R_AARCH64_ADR_GOT_PAGE, 0);
2003+ o(0x90000000 | r1); // adrp r1, #sym
2004+ greloca(cur_text_section, sv->sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
2005+ o(0xf9400000 | r1 | (r1 << 5)); // ld xr,[xr, #sym]
2006+ o(0xf9400000 | (intr(r1)<<5) | intr(r2)); // ldr r2, [r1]
2007+ o(0x91000400 | (intr(r2)<<5) | intr(r2)); // add r2, r2, #1
2008+ o(0xf9000000 | (intr(r1)<<5) | intr(r2)); // str r2, [r1]
2009+ vpop();
20042010 }
20052011
2006−ST_FUNC void ggoto(TCCState *S)
2012+ST_FUNC void ggoto(void)
20072013 {
2008− arm64_gen_bl_or_b(S, 1);
2009− --S->tccgen_vtop;
2014+ arm64_gen_bl_or_b(1);
2015+ --vtop;
20102016 }
20112017
2012−ST_FUNC void gen_clear_cache(TCCState *S)
2018+ST_FUNC void gen_clear_cache(void)
20132019 {
20142020 uint32_t beg, end, dsz, isz, p, lab1, b1;
2015− gv2(S, RC_INT, RC_INT);
2016− vpushi(S, 0);
2017− S->tccgen_vtop->r = get_reg(S, RC_INT);
2018− vpushi(S, 0);
2019− S->tccgen_vtop->r = get_reg(S, RC_INT);
2020− vpushi(S, 0);
2021− S->tccgen_vtop->r = get_reg(S, RC_INT);
2022− beg = intr(S, S->tccgen_vtop[-4].r); // x0
2023− end = intr(S, S->tccgen_vtop[-3].r); // x1
2024− dsz = intr(S, S->tccgen_vtop[-2].r); // x2
2025− isz = intr(S, S->tccgen_vtop[-1].r); // x3
2026− p = intr(S, S->tccgen_vtop[0].r); // x4
2027− S->tccgen_vtop -= 5;
2028−
2029− o(S, 0xd53b0020 | isz); // mrs x(isz),ctr_el0
2030− o(S, 0x52800080 | p); // mov w(p),#4
2031− o(S, 0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4
2032− o(S, 0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz)
2033− o(S, 0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15
2034− o(S, 0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz)
2035− o(S, 0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1
2036− o(S, 0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
2037− b1 = S->tccgen_ind; o(S, 0x14000000); // b
2038− lab1 = S->tccgen_ind;
2039− o(S, 0xd50b7b20 | p); // dc cvau,x(p)
2040− o(S, 0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz)
2041− write32le(cur_text_section->data + b1, 0x14000000 | (S->tccgen_ind - b1) >> 2);
2042− o(S, 0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
2043− o(S, 0x54ffffa3 | ((lab1 - S->tccgen_ind) << 3 & 0xffffe0)); // b.cc lab1
2044− o(S, 0xd5033b9f); // dsb ish
2045− o(S, 0x51000400 | p | isz << 5); // sub w(p),w(isz),#1
2046− o(S, 0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
2047− b1 = S->tccgen_ind; o(S, 0x14000000); // b
2048− lab1 = S->tccgen_ind;
2049− o(S, 0xd50b7520 | p); // ic ivau,x(p)
2050− o(S, 0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz)
2051− write32le(cur_text_section->data + b1, 0x14000000 | (S->tccgen_ind - b1) >> 2);
2052− o(S, 0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
2053− o(S, 0x54ffffa3 | ((lab1 - S->tccgen_ind) << 3 & 0xffffe0)); // b.cc lab1
2054− o(S, 0xd5033b9f); // dsb ish
2055− o(S, 0xd5033fdf); // isb
2021+ gv2(RC_INT, RC_INT);
2022+ vpushi(0);
2023+ vtop->r = get_reg(RC_INT);
2024+ vpushi(0);
2025+ vtop->r = get_reg(RC_INT);
2026+ vpushi(0);
2027+ vtop->r = get_reg(RC_INT);
2028+ beg = intr(vtop[-4].r); // x0
2029+ end = intr(vtop[-3].r); // x1
2030+ dsz = intr(vtop[-2].r); // x2
2031+ isz = intr(vtop[-1].r); // x3
2032+ p = intr(vtop[0].r); // x4
2033+ vtop -= 5;
2034+
2035+ o(0xd53b0020 | isz); // mrs x(isz),ctr_el0
2036+ o(0x52800080 | p); // mov w(p),#4
2037+ o(0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4
2038+ o(0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz)
2039+ o(0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15
2040+ o(0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz)
2041+ o(0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1
2042+ o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
2043+ b1 = ind; o(0x14000000); // b
2044+ lab1 = ind;
2045+ o(0xd50b7b20 | p); // dc cvau,x(p)
2046+ o(0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz)
2047+ write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2);
2048+ o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
2049+ o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1
2050+ o(0xd5033b9f); // dsb ish
2051+ o(0x51000400 | p | isz << 5); // sub w(p),w(isz),#1
2052+ o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
2053+ b1 = ind; o(0x14000000); // b
2054+ lab1 = ind;
2055+ o(0xd50b7520 | p); // ic ivau,x(p)
2056+ o(0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz)
2057+ write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2);
2058+ o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
2059+ o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1
2060+ o(0xd5033b9f); // dsb ish
2061+ o(0xd5033fdf); // isb
20562062 }
20572063
2058−ST_FUNC void gen_vla_sp_save(TCCState *S, int addr) {
2059− uint32_t r = intr(S, get_reg(S, RC_INT));
2060− o(S, 0x910003e0 | r); // mov x(r),sp
2061− arm64_strx(S, 3, r, 29, addr);
2064+ST_FUNC void gen_vla_sp_save(int addr) {
2065+ uint32_t r = intr(get_reg(RC_INT));
2066+ o(0x910003e0 | r); // mov x(r),sp
2067+ arm64_strx(3, r, 29, addr);
20622068 }
20632069
2064−ST_FUNC void gen_vla_sp_restore(TCCState *S, int addr) {
2070+ST_FUNC void gen_vla_sp_restore(int addr) {
20652071 // Use x30 because this function can be called when there
20662072 // is a live return value in x0 but there is nothing on
20672073 // the value stack to prevent get_reg from returning x0.
20682074 uint32_t r = 30;
2069− arm64_ldrx(S, 0, 3, r, 29, addr);
2070− o(S, 0x9100001f | r << 5); // mov sp,x(r)
2075+ arm64_ldrx(0, 3, r, 29, addr);
2076+ o(0x9100001f | r << 5); // mov sp,x(r)
20712077 }
20722078
2073−ST_FUNC void gen_vla_alloc(TCCState *S, CType *type, int align) {
2079+ST_FUNC void gen_vla_alloc(CType *type, int align) {
20742080 uint32_t r;
20752081 #if defined(CONFIG_TCC_BCHECK)
2076− if (S->do_bounds_check)
2077− vpushv(S, S->tccgen_vtop);
2082+ if (tcc_state->do_bounds_check)
2083+ vpushv(vtop);
20782084 #endif
2079− r = intr(S, gv(S, RC_INT));
2085+ r = intr(gv(RC_INT));
20802086 #if defined(CONFIG_TCC_BCHECK)
2081− if (S->do_bounds_check)
2082− o(S, 0x91004000 | r | r << 5); // add x(r),x(r),#15+1
2087+ if (tcc_state->do_bounds_check)
2088+ o(0x91004000 | r | r << 5); // add x(r),x(r),#15+1
20832089 else
20842090 #endif
2085− o(S, 0x91003c00 | r | r << 5); // add x(r),x(r),#15
2086− o(S, 0x927cec00 | r | r << 5); // bic x(r),x(r),#15
2087− o(S, 0xcb2063ff | r << 16); // sub sp,sp,x(r)
2088− vpop(S);
2091+ o(0x91003c00 | r | r << 5); // add x(r),x(r),#15
2092+ o(0x927cec00 | r | r << 5); // bic x(r),x(r),#15
2093+ o(0xcb2063ff | r << 16); // sub sp,sp,x(r)
2094+ vpop();
20892095 #if defined(CONFIG_TCC_BCHECK)
2090− if (S->do_bounds_check) {
2091− vpushi(S, 0);
2092− S->tccgen_vtop->r = TREG_R(0);
2093− o(S, 0x910003e0 | S->tccgen_vtop->r); // mov r0,sp
2094− vswap(S);
2095− vpush_helper_func(S, TOK___bound_new_region);
2096− vrott(S, 3);
2097− gfunc_call(S, 2);
2098− S->func_bound_add_epilog = 1;
2096+ if (tcc_state->do_bounds_check) {
2097+ vpushi(0);
2098+ vtop->r = TREG_R(0);
2099+ o(0x910003e0 | vtop->r); // mov r0,sp
2100+ vswap();
2101+ vpush_helper_func(TOK___bound_new_region);
2102+ vrott(3);
2103+ gfunc_call(2);
2104+ func_bound_add_epilog = 1;
20992105 }
21002106 #endif
21012107 }
arm64-link.c+32−32
@@ -90,18 +90,18 @@ int gotplt_entry_type (int reloc_type) · 89 unmodified lines
9090 return -1;
9191 }
9292
93−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
93+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
9494 {
95− Section *plt = S->plt;
95+ Section *plt = s1->plt;
9696 uint8_t *p;
9797 unsigned plt_offset;
9898
9999 if (plt->data_offset == 0) {
100− section_ptr_add(S, plt, 32);
100+ section_ptr_add(plt, 32);
101101 }
102102 plt_offset = plt->data_offset;
103103
104− p = section_ptr_add(S, plt, 16);
104+ p = section_ptr_add(plt, 16);
105105 write32le(p, got_offset);
106106 write32le(p + 4, (uint64_t) got_offset >> 32);
107107 return plt_offset;
@@ -109,22 +109,22 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 1 unmodified line
109109
110110 /* relocate the PLT: compute addresses and offsets in the PLT now that final
111111 address for PLT and GOT are known (see fill_program_header) */
112−ST_FUNC void relocate_plt(TCCState *S)
112+ST_FUNC void relocate_plt(TCCState *s1)
113113 {
114114 uint8_t *p, *p_end;
115115
116− if (!S->plt)
116+ if (!s1->plt)
117117 return;
118118
119− p = S->plt->data;
120− p_end = p + S->plt->data_offset;
119+ p = s1->plt->data;
120+ p_end = p + s1->plt->data_offset;
121121
122122 if (p < p_end) {
123− uint64_t plt = S->plt->sh_addr;
124− uint64_t got = S->got->sh_addr + 16;
123+ uint64_t plt = s1->plt->sh_addr;
124+ uint64_t got = s1->got->sh_addr + 16;
125125 uint64_t off = (got >> 12) - (plt >> 12);
126126 if ((off + ((uint32_t)1 << 20)) >> 21)
127− tcc_error(S, "Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
127+ tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
128128 write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]!
129129 write32le(p + 4, (0x90000010 | // adrp x16,...
130130 (off & 0x1ffffc) << 3 | (off & 3) << 29));
@@ -137,13 +137,13 @@ ST_FUNC void relocate_plt(TCCState *S) · 6 unmodified lines
137137 write32le(p + 24, 0xd503201f); // nop
138138 write32le(p + 28, 0xd503201f); // nop
139139 p += 32;
140− got = S->got->sh_addr;
140+ got = s1->got->sh_addr;
141141 while (p < p_end) {
142− uint64_t pc = plt + (p - S->plt->data);
142+ uint64_t pc = plt + (p - s1->plt->data);
143143 uint64_t addr = got + read64le(p);
144144 uint64_t off = (addr >> 12) - (pc >> 12);
145145 if ((off + ((uint32_t)1 << 20)) >> 21)
146− tcc_error(S, "Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
146+ tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
147147 write32le(p, (0x90000010 | // adrp x16,...
148148 (off & 0x1ffffc) << 3 | (off & 3) << 29));
149149 write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...]
@@ -155,16 +155,16 @@ ST_FUNC void relocate_plt(TCCState *S) · 5 unmodified lines
155155 }
156156 }
157157
158− if (S->plt->reloc) {
158+ if (s1->plt->reloc) {
159159 ElfW_Rel *rel;
160− p = S->got->data;
161− for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
162− write64le(p + rel->r_offset, S->plt->sh_addr);
160+ p = s1->got->data;
161+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
162+ write64le(p + rel->r_offset, s1->plt->sh_addr);
163163 }
164164 }
165165 }
166166
167−void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
167+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
168168 {
169169 int sym_index = ELFW(R_SYM)(rel->r_info), esym_index;
170170 #ifdef DEBUG_RELOC
@@ -173,8 +173,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 2 unmodified lines
173173
174174 switch(type) {
175175 case R_AARCH64_ABS64:
176− if (S->output_type == TCC_OUTPUT_DLL) {
177− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
176+ if (s1->output_type == TCC_OUTPUT_DLL) {
177+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
178178 qrel->r_offset = rel->r_offset;
179179 if (esym_index) {
180180 qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_ABS64);
@@ -190,7 +190,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 9 unmodified lines
190190 add64le(ptr, val);
191191 return;
192192 case R_AARCH64_ABS32:
193− if (S->output_type == TCC_OUTPUT_DLL) {
193+ if (s1->output_type == TCC_OUTPUT_DLL) {
194194 /* XXX: this logic may depend on TCC's codegen
195195 now TCC uses R_AARCH64_RELATIVE even for a 64bit pointer */
196196 qrel->r_offset = rel->r_offset;
@@ -202,9 +202,9 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 5 unmodified lines
202202 add32le(ptr, val);
203203 return;
204204 case R_AARCH64_PREL32:
205− if (S->output_type == TCC_OUTPUT_DLL) {
205+ if (s1->output_type == TCC_OUTPUT_DLL) {
206206 /* DLL relocation */
207− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
207+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
208208 if (esym_index) {
209209 qrel->r_offset = rel->r_offset;
210210 qrel->r_info = ELFW(R_INFO)(esym_index, R_AARCH64_PREL32);
@@ -235,7 +235,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 24 unmodified lines
235235 case R_AARCH64_ADR_PREL_PG_HI21: {
236236 uint64_t off = (val >> 12) - (addr >> 12);
237237 if ((off + ((uint64_t)1 << 20)) >> 21)
238− tcc_error(S, "R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
238+ tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
239239 write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
240240 (off & 0x1ffffc) << 3 | (off & 3) << 29));
241241 return;
@@ -268,7 +268,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 26 unmodified lines
268268 (char *) symtab_section->link->data + sym->st_name);
269269 #endif
270270 if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
271− tcc_error(S, "R_AARCH64_(JUMP|CALL)26 relocation failed"
271+ tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed"
272272 " (val=%lx, addr=%lx)", (long)val, (long)addr);
273273 write32le(ptr, (0x14000000 |
274274 (uint32_t)(type == R_AARCH64_CALL26) << 31 |
@@ -276,10 +276,10 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 1 unmodified line
276276 return;
277277 case R_AARCH64_ADR_GOT_PAGE: {
278278 uint64_t off =
279− (((S->got->sh_addr +
280− get_sym_attr(S, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
279+ (((s1->got->sh_addr +
280+ get_sym_attr(s1, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
281281 if ((off + ((uint64_t)1 << 20)) >> 21)
282− tcc_error(S, "R_AARCH64_ADR_GOT_PAGE relocation failed");
282+ tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed");
283283 write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
284284 (off & 0x1ffffc) << 3 | (off & 3) << 29));
285285 return;
@@ -287,8 +287,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 1 unmodified line
287287 case R_AARCH64_LD64_GOT_LO12_NC:
288288 write32le(ptr,
289289 ((read32le(ptr) & 0xfff803ff) |
290− ((S->got->sh_addr +
291− get_sym_attr(S, sym_index, 0)->got_offset) & 0xff8) << 7));
290+ ((s1->got->sh_addr +
291+ get_sym_attr(s1, sym_index, 0)->got_offset) & 0xff8) << 7));
292292 return;
293293 case R_AARCH64_COPY:
294294 return;
@@ -304,7 +304,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 9 unmodified lines
304304 return;
305305 case R_AARCH64_RELATIVE:
306306 #ifdef TCC_TARGET_PE
307− add32le(ptr, val - S->pe_imagebase);
307+ add32le(ptr, val - s1->pe_imagebase);
308308 #endif
309309 /* do nothing */
310310 return;
c67-gen.c+758−758
@@ -172,7 +172,7 @@ int TotalBytesPushedOnStack; · 171 unmodified lines
172172 #define ALWAYS_ASSERT(x) \
173173 do {\
174174 if (!(x))\
175− tcc_error(S, "internal compiler error file at %s:%d", __FILE__, __LINE__);\
175+ tcc_error("internal compiler error file at %s:%d", __FILE__, __LINE__);\
176176 } while (0)
177177
178178 /******************************************************/
@@ -186,27 +186,27 @@ static int C67_compare_reg; · 7 unmodified lines
186186 FILE *f = NULL;
187187 #endif
188188
189−void C67_g(TCCState* S, int c)
189+void C67_g(int c)
190190 {
191191 int ind1;
192− if (S->tccgen_nocode_wanted)
192+ if (nocode_wanted)
193193 return;
194194 #ifdef ASSEMBLY_LISTING_C67
195195 fprintf(f, " %08X", c);
196196 #endif
197− ind1 = S->tccgen_ind + 4;
197+ ind1 = ind + 4;
198198 if (ind1 > (int) cur_text_section->data_allocated)
199− section_realloc(S, cur_text_section, ind1);
200− cur_text_section->data[S->tccgen_ind] = c & 0xff;
201− cur_text_section->data[S->tccgen_ind + 1] = (c >> 8) & 0xff;
202− cur_text_section->data[S->tccgen_ind + 2] = (c >> 16) & 0xff;
203− cur_text_section->data[S->tccgen_ind + 3] = (c >> 24) & 0xff;
204− S->tccgen_ind = ind1;
199+ section_realloc(cur_text_section, ind1);
200+ cur_text_section->data[ind] = c & 0xff;
201+ cur_text_section->data[ind + 1] = (c >> 8) & 0xff;
202+ cur_text_section->data[ind + 2] = (c >> 16) & 0xff;
203+ cur_text_section->data[ind + 3] = (c >> 24) & 0xff;
204+ ind = ind1;
205205 }
206206
207207
208208 /* output a symbol and patch all calls to it */
209−void gsym_addr(TCCState* S, int t, int a)
209+void gsym_addr(int t, int a)
210210 {
211211 int n, *ptr;
212212 while (t) {
@@ -220,9 +220,9 @@ void gsym_addr(TCCState* S, int t, int a) · 7 unmodified lines
220220
221221 // define a label that will be relocated
222222
223− sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, a, 0);
224− greloc(S, cur_text_section, sym, t, R_C60LO16);
225− greloc(S, cur_text_section, sym, t + 4, R_C60HI16);
223+ sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
224+ greloc(cur_text_section, sym, t, R_C60LO16);
225+ greloc(cur_text_section, sym, t + 4, R_C60HI16);
226226
227227 // clear out where the pointer was
228228
@@ -255,7 +255,7 @@ int ConvertRegToRegClass(int r) · 26 unmodified lines
255255
256256 // map TCC reg to C67 reg number
257257
258−int C67_map_regn(TCCState* S, int r)
258+int C67_map_regn(int r)
259259 {
260260 if (r == 0) // normal tcc regs
261261 return 0x2; // A2
@@ -296,7 +296,7 @@ int C67_map_regn(TCCState* S, int r) · 34 unmodified lines
296296 // tcc reg 1 -> A3 -> X
297297 // tcc reg B2 -> 3
298298
299−int C67_map_regc(TCCState* S, int r)
299+int C67_map_regc(int r)
300300 {
301301 if (r == 0) // normal tcc regs
302302 return 0x5;
@@ -317,7 +317,7 @@ int C67_map_regc(TCCState* S, int r) · 14 unmodified lines
317317
318318 // map TCC reg to C67 reg side A or B
319319
320−int C67_map_regs(TCCState* S, int r)
320+int C67_map_regs(int r)
321321 {
322322 if (r == 0) // normal tcc regs
323323 return 0x0;
@@ -345,7 +345,7 @@ int C67_map_regs(TCCState* S, int r) · 21 unmodified lines
345345 return 0;
346346 }
347347
348−int C67_map_S12(TCCState* S, char *s)
348+int C67_map_S12(char *s)
349349 {
350350 if (strstr(s, ".S1") != NULL)
351351 return 0;
@@ -357,7 +357,7 @@ int C67_map_S12(TCCState* S, char *s) · 5 unmodified lines
357357 return 0;
358358 }
359359
360−int C67_map_D12(TCCState* S, char *s)
360+int C67_map_D12(char *s)
361361 {
362362 if (strstr(s, ".D1") != NULL)
363363 return 0;
@@ -371,7 +371,7 @@ int C67_map_D12(TCCState* S, char *s) · 7 unmodified lines
371371
372372
373373
374−void C67_asm(TCCState* S, const char *s, int a, int b, int c)
374+void C67_asm(const char *s, int a, int b, int c)
375375 {
376376 BOOL xpath;
377377
@@ -383,14 +383,14 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 5 unmodified lines
383383 #endif
384384
385385 if (strstr(s, "MVKL") == s) {
386− C67_g(S, (C67_map_regn(S, b) << 23) |
387− ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(S, b) << 1));
386+ C67_g((C67_map_regn(b) << 23) |
387+ ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(b) << 1));
388388 } else if (strstr(s, "MVKH") == s) {
389− C67_g(S, (C67_map_regn(S, b) << 23) |
389+ C67_g((C67_map_regn(b) << 23) |
390390 (((a >> 16) & 0xffff) << 7) |
391− (0x1a << 2) | (C67_map_regs(S, b) << 1));
391+ (0x1a << 2) | (C67_map_regs(b) << 1));
392392 } else if (strstr(s, "STW.D SP POST DEC") == s) {
393− C67_g(S, (C67_map_regn(S, a) << 23) | //src
393+ C67_g((C67_map_regn(a) << 23) | //src
394394 (15 << 18) | //SP B15
395395 (2 << 13) | //ucst5 (must keep 8 byte boundary !!)
396396 (0xa << 9) | //mode a = post dec ucst
@@ -398,10 +398,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
398398 (1 << 7) | //y D1/D2 use B side
399399 (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
400400 (1 << 2) | //opcode
401− (C67_map_regs(S, a) << 1) | //side of src
401+ (C67_map_regs(a) << 1) | //side of src
402402 (0 << 0)); //parallel
403403 } else if (strstr(s, "STB.D *+SP[A0]") == s) {
404− C67_g(S, (C67_map_regn(S, a) << 23) | //src
404+ C67_g((C67_map_regn(a) << 23) | //src
405405 (15 << 18) | //base reg A15
406406 (0 << 13) | //offset reg A0
407407 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -409,10 +409,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
409409 (0 << 7) | //y D1/D2 A side
410410 (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
411411 (1 << 2) | //opcode
412− (C67_map_regs(S, a) << 1) | //side of src
412+ (C67_map_regs(a) << 1) | //side of src
413413 (0 << 0)); //parallel
414414 } else if (strstr(s, "STH.D *+SP[A0]") == s) {
415− C67_g(S, (C67_map_regn(S, a) << 23) | //src
415+ C67_g((C67_map_regn(a) << 23) | //src
416416 (15 << 18) | //base reg A15
417417 (0 << 13) | //offset reg A0
418418 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -420,10 +420,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
420420 (0 << 7) | //y D1/D2 A side
421421 (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
422422 (1 << 2) | //opcode
423− (C67_map_regs(S, a) << 1) | //side of src
423+ (C67_map_regs(a) << 1) | //side of src
424424 (0 << 0)); //parallel
425425 } else if (strstr(s, "STB.D *+SP[A0]") == s) {
426− C67_g(S, (C67_map_regn(S, a) << 23) | //src
426+ C67_g((C67_map_regn(a) << 23) | //src
427427 (15 << 18) | //base reg A15
428428 (0 << 13) | //offset reg A0
429429 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -431,10 +431,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
431431 (0 << 7) | //y D1/D2 A side
432432 (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
433433 (1 << 2) | //opcode
434− (C67_map_regs(S, a) << 1) | //side of src
434+ (C67_map_regs(a) << 1) | //side of src
435435 (0 << 0)); //parallel
436436 } else if (strstr(s, "STH.D *+SP[A0]") == s) {
437− C67_g(S, (C67_map_regn(S, a) << 23) | //src
437+ C67_g((C67_map_regn(a) << 23) | //src
438438 (15 << 18) | //base reg A15
439439 (0 << 13) | //offset reg A0
440440 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -442,10 +442,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
442442 (0 << 7) | //y D1/D2 A side
443443 (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
444444 (1 << 2) | //opcode
445− (C67_map_regs(S, a) << 1) | //side of src
445+ (C67_map_regs(a) << 1) | //side of src
446446 (0 << 0)); //parallel
447447 } else if (strstr(s, "STW.D *+SP[A0]") == s) {
448− C67_g(S, (C67_map_regn(S, a) << 23) | //src
448+ C67_g((C67_map_regn(a) << 23) | //src
449449 (15 << 18) | //base reg A15
450450 (0 << 13) | //offset reg A0
451451 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -453,55 +453,55 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
453453 (0 << 7) | //y D1/D2 A side
454454 (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
455455 (1 << 2) | //opcode
456− (C67_map_regs(S, a) << 1) | //side of src
456+ (C67_map_regs(a) << 1) | //side of src
457457 (0 << 0)); //parallel
458458 } else if (strstr(s, "STW.D *") == s) {
459− C67_g(S, (C67_map_regn(S, a) << 23) | //src
460− (C67_map_regn(S, b) << 18) | //base reg A0
459+ C67_g((C67_map_regn(a) << 23) | //src
460+ (C67_map_regn(b) << 18) | //base reg A0
461461 (0 << 13) | //cst5
462462 (1 << 9) | //mode 1 = pos cst offset
463463 (0 << 8) | //r (LDDW bit 0)
464− (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
464+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
465465 (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
466466 (1 << 2) | //opcode
467− (C67_map_regs(S, a) << 1) | //side of src
467+ (C67_map_regs(a) << 1) | //side of src
468468 (0 << 0)); //parallel
469469 } else if (strstr(s, "STH.D *") == s) {
470− C67_g(S, (C67_map_regn(S, a) << 23) | //src
471− (C67_map_regn(S, b) << 18) | //base reg A0
470+ C67_g((C67_map_regn(a) << 23) | //src
471+ (C67_map_regn(b) << 18) | //base reg A0
472472 (0 << 13) | //cst5
473473 (1 << 9) | //mode 1 = pos cst offset
474474 (0 << 8) | //r (LDDW bit 0)
475− (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
475+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
476476 (5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
477477 (1 << 2) | //opcode
478− (C67_map_regs(S, a) << 1) | //side of src
478+ (C67_map_regs(a) << 1) | //side of src
479479 (0 << 0)); //parallel
480480 } else if (strstr(s, "STB.D *") == s) {
481− C67_g(S, (C67_map_regn(S, a) << 23) | //src
482− (C67_map_regn(S, b) << 18) | //base reg A0
481+ C67_g((C67_map_regn(a) << 23) | //src
482+ (C67_map_regn(b) << 18) | //base reg A0
483483 (0 << 13) | //cst5
484484 (1 << 9) | //mode 1 = pos cst offset
485485 (0 << 8) | //r (LDDW bit 0)
486− (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
486+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
487487 (3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
488488 (1 << 2) | //opcode
489− (C67_map_regs(S, a) << 1) | //side of src
489+ (C67_map_regs(a) << 1) | //side of src
490490 (0 << 0)); //parallel
491491 } else if (strstr(s, "STW.D +*") == s) {
492492 ALWAYS_ASSERT(c < 32);
493− C67_g(S, (C67_map_regn(S, a) << 23) | //src
494− (C67_map_regn(S, b) << 18) | //base reg A0
493+ C67_g((C67_map_regn(a) << 23) | //src
494+ (C67_map_regn(b) << 18) | //base reg A0
495495 (c << 13) | //cst5
496496 (1 << 9) | //mode 1 = pos cst offset
497497 (0 << 8) | //r (LDDW bit 0)
498− (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
498+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
499499 (7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
500500 (1 << 2) | //opcode
501− (C67_map_regs(S, a) << 1) | //side of src
501+ (C67_map_regs(a) << 1) | //side of src
502502 (0 << 0)); //parallel
503503 } else if (strstr(s, "LDW.D SP PRE INC") == s) {
504− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
504+ C67_g((C67_map_regn(a) << 23) | //dst
505505 (15 << 18) | //base reg B15
506506 (2 << 13) | //ucst5 (must keep 8 byte boundary)
507507 (9 << 9) | //mode 9 = pre inc ucst5
@@ -509,10 +509,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
509509 (1 << 7) | //y D1/D2 B side
510510 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
511511 (1 << 2) | //opcode
512− (C67_map_regs(S, a) << 1) | //side of dst
512+ (C67_map_regs(a) << 1) | //side of dst
513513 (0 << 0)); //parallel
514514 } else if (strstr(s, "LDDW.D SP PRE INC") == s) {
515− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
515+ C67_g((C67_map_regn(a) << 23) | //dst
516516 (15 << 18) | //base reg B15
517517 (1 << 13) | //ucst5 (must keep 8 byte boundary)
518518 (9 << 9) | //mode 9 = pre inc ucst5
@@ -520,10 +520,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
520520 (1 << 7) | //y D1/D2 B side
521521 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
522522 (1 << 2) | //opcode
523− (C67_map_regs(S, a) << 1) | //side of dst
523+ (C67_map_regs(a) << 1) | //side of dst
524524 (0 << 0)); //parallel
525525 } else if (strstr(s, "LDW.D *+SP[A0]") == s) {
526− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
526+ C67_g((C67_map_regn(a) << 23) | //dst
527527 (15 << 18) | //base reg A15
528528 (0 << 13) | //offset reg A0
529529 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -531,10 +531,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
531531 (0 << 7) | //y D1/D2 A side
532532 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
533533 (1 << 2) | //opcode
534− (C67_map_regs(S, a) << 1) | //side of dst
534+ (C67_map_regs(a) << 1) | //side of dst
535535 (0 << 0)); //parallel
536536 } else if (strstr(s, "LDDW.D *+SP[A0]") == s) {
537− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
537+ C67_g((C67_map_regn(a) << 23) | //dst
538538 (15 << 18) | //base reg A15
539539 (0 << 13) | //offset reg A0
540540 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -542,10 +542,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
542542 (0 << 7) | //y D1/D2 A side
543543 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
544544 (1 << 2) | //opcode
545− (C67_map_regs(S, a) << 1) | //side of dst
545+ (C67_map_regs(a) << 1) | //side of dst
546546 (0 << 0)); //parallel
547547 } else if (strstr(s, "LDH.D *+SP[A0]") == s) {
548− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
548+ C67_g((C67_map_regn(a) << 23) | //dst
549549 (15 << 18) | //base reg A15
550550 (0 << 13) | //offset reg A0
551551 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -553,10 +553,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
553553 (0 << 7) | //y D1/D2 A side
554554 (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
555555 (1 << 2) | //opcode
556− (C67_map_regs(S, a) << 1) | //side of dst
556+ (C67_map_regs(a) << 1) | //side of dst
557557 (0 << 0)); //parallel
558558 } else if (strstr(s, "LDB.D *+SP[A0]") == s) {
559− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
559+ C67_g((C67_map_regn(a) << 23) | //dst
560560 (15 << 18) | //base reg A15
561561 (0 << 13) | //offset reg A0
562562 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -564,10 +564,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
564564 (0 << 7) | //y D1/D2 A side
565565 (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
566566 (1 << 2) | //opcode
567− (C67_map_regs(S, a) << 1) | //side of dst
567+ (C67_map_regs(a) << 1) | //side of dst
568568 (0 << 0)); //parallel
569569 } else if (strstr(s, "LDHU.D *+SP[A0]") == s) {
570− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
570+ C67_g((C67_map_regn(a) << 23) | //dst
571571 (15 << 18) | //base reg A15
572572 (0 << 13) | //offset reg A0
573573 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -575,10 +575,10 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
575575 (0 << 7) | //y D1/D2 A side
576576 (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
577577 (1 << 2) | //opcode
578− (C67_map_regs(S, a) << 1) | //side of dst
578+ (C67_map_regs(a) << 1) | //side of dst
579579 (0 << 0)); //parallel
580580 } else if (strstr(s, "LDBU.D *+SP[A0]") == s) {
581− C67_g(S, (C67_map_regn(S, a) << 23) | //dst
581+ C67_g((C67_map_regn(a) << 23) | //dst
582582 (15 << 18) | //base reg A15
583583 (0 << 13) | //offset reg A0
584584 (5 << 9) | //mode 5 = pos offset, base reg + off reg
@@ -586,233 +586,233 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
586586 (0 << 7) | //y D1/D2 A side
587587 (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
588588 (1 << 2) | //opcode
589− (C67_map_regs(S, a) << 1) | //side of dst
589+ (C67_map_regs(a) << 1) | //side of dst
590590 (0 << 0)); //parallel
591591 } else if (strstr(s, "LDW.D *") == s) {
592− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
593− (C67_map_regn(S, a) << 18) | //base reg A15
592+ C67_g((C67_map_regn(b) << 23) | //dst
593+ (C67_map_regn(a) << 18) | //base reg A15
594594 (0 << 13) | //cst5
595595 (1 << 9) | //mode 1 = pos cst offset
596596 (0 << 8) | //r (LDDW bit 0)
597− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
597+ (C67_map_regs(a) << 7) | //y D1/D2 src side
598598 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
599599 (1 << 2) | //opcode
600− (C67_map_regs(S, b) << 1) | //side of dst
600+ (C67_map_regs(b) << 1) | //side of dst
601601 (0 << 0)); //parallel
602602 } else if (strstr(s, "LDDW.D *") == s) {
603− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
604− (C67_map_regn(S, a) << 18) | //base reg A15
603+ C67_g((C67_map_regn(b) << 23) | //dst
604+ (C67_map_regn(a) << 18) | //base reg A15
605605 (0 << 13) | //cst5
606606 (1 << 9) | //mode 1 = pos cst offset
607607 (1 << 8) | //r (LDDW bit 1)
608− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
608+ (C67_map_regs(a) << 7) | //y D1/D2 src side
609609 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
610610 (1 << 2) | //opcode
611− (C67_map_regs(S, b) << 1) | //side of dst
611+ (C67_map_regs(b) << 1) | //side of dst
612612 (0 << 0)); //parallel
613613 } else if (strstr(s, "LDH.D *") == s) {
614− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
615− (C67_map_regn(S, a) << 18) | //base reg A15
614+ C67_g((C67_map_regn(b) << 23) | //dst
615+ (C67_map_regn(a) << 18) | //base reg A15
616616 (0 << 13) | //cst5
617617 (1 << 9) | //mode 1 = pos cst offset
618618 (0 << 8) | //r (LDDW bit 0)
619− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
619+ (C67_map_regs(a) << 7) | //y D1/D2 src side
620620 (4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
621621 (1 << 2) | //opcode
622− (C67_map_regs(S, b) << 1) | //side of dst
622+ (C67_map_regs(b) << 1) | //side of dst
623623 (0 << 0)); //parallel
624624 } else if (strstr(s, "LDB.D *") == s) {
625− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
626− (C67_map_regn(S, a) << 18) | //base reg A15
625+ C67_g((C67_map_regn(b) << 23) | //dst
626+ (C67_map_regn(a) << 18) | //base reg A15
627627 (0 << 13) | //cst5
628628 (1 << 9) | //mode 1 = pos cst offset
629629 (0 << 8) | //r (LDDW bit 0)
630− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
630+ (C67_map_regs(a) << 7) | //y D1/D2 src side
631631 (2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
632632 (1 << 2) | //opcode
633− (C67_map_regs(S, b) << 1) | //side of dst
633+ (C67_map_regs(b) << 1) | //side of dst
634634 (0 << 0)); //parallel
635635 } else if (strstr(s, "LDHU.D *") == s) {
636− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
637− (C67_map_regn(S, a) << 18) | //base reg A15
636+ C67_g((C67_map_regn(b) << 23) | //dst
637+ (C67_map_regn(a) << 18) | //base reg A15
638638 (0 << 13) | //cst5
639639 (1 << 9) | //mode 1 = pos cst offset
640640 (0 << 8) | //r (LDDW bit 0)
641− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
641+ (C67_map_regs(a) << 7) | //y D1/D2 src side
642642 (0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
643643 (1 << 2) | //opcode
644− (C67_map_regs(S, b) << 1) | //side of dst
644+ (C67_map_regs(b) << 1) | //side of dst
645645 (0 << 0)); //parallel
646646 } else if (strstr(s, "LDBU.D *") == s) {
647− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
648− (C67_map_regn(S, a) << 18) | //base reg A15
647+ C67_g((C67_map_regn(b) << 23) | //dst
648+ (C67_map_regn(a) << 18) | //base reg A15
649649 (0 << 13) | //cst5
650650 (1 << 9) | //mode 1 = pos cst offset
651651 (0 << 8) | //r (LDDW bit 0)
652− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
652+ (C67_map_regs(a) << 7) | //y D1/D2 src side
653653 (1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
654654 (1 << 2) | //opcode
655− (C67_map_regs(S, b) << 1) | //side of dst
655+ (C67_map_regs(b) << 1) | //side of dst
656656 (0 << 0)); //parallel
657657 } else if (strstr(s, "LDW.D +*") == s) {
658− C67_g(S, (C67_map_regn(S, b) << 23) | //dst
659− (C67_map_regn(S, a) << 18) | //base reg A15
658+ C67_g((C67_map_regn(b) << 23) | //dst
659+ (C67_map_regn(a) << 18) | //base reg A15
660660 (1 << 13) | //cst5
661661 (1 << 9) | //mode 1 = pos cst offset
662662 (0 << 8) | //r (LDDW bit 0)
663− (C67_map_regs(S, a) << 7) | //y D1/D2 src side
663+ (C67_map_regs(a) << 7) | //y D1/D2 src side
664664 (6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
665665 (1 << 2) | //opcode
666− (C67_map_regs(S, b) << 1) | //side of dst
666+ (C67_map_regs(b) << 1) | //side of dst
667667 (0 << 0)); //parallel
668668 } else if (strstr(s, "CMPLTSP") == s) {
669− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
670− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
669+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
670+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
671671
672− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
673− (C67_map_regn(S, b) << 18) | //src2
674− (C67_map_regn(S, a) << 13) | //src1
672+ C67_g((C67_map_regn(c) << 23) | //dst
673+ (C67_map_regn(b) << 18) | //src2
674+ (C67_map_regn(a) << 13) | //src1
675675 (xpath << 12) | //x use cross path for src2
676676 (0x3a << 6) | //opcode
677677 (0x8 << 2) | //opcode fixed
678− (C67_map_regs(S, c) << 1) | //side for reg c
678+ (C67_map_regs(c) << 1) | //side for reg c
679679 (0 << 0)); //parallel
680680 } else if (strstr(s, "CMPGTSP") == s) {
681− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
682− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
681+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
682+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
683683
684− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
685− (C67_map_regn(S, b) << 18) | //src2
686− (C67_map_regn(S, a) << 13) | //src1
684+ C67_g((C67_map_regn(c) << 23) | //dst
685+ (C67_map_regn(b) << 18) | //src2
686+ (C67_map_regn(a) << 13) | //src1
687687 (xpath << 12) | //x use cross path for src2
688688 (0x39 << 6) | //opcode
689689 (0x8 << 2) | //opcode fixed
690− (C67_map_regs(S, c) << 1) | //side for reg c
690+ (C67_map_regs(c) << 1) | //side for reg c
691691 (0 << 0)); //parallel
692692 } else if (strstr(s, "CMPEQSP") == s) {
693− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
694− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
693+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
694+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
695695
696− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
697− (C67_map_regn(S, b) << 18) | //src2
698− (C67_map_regn(S, a) << 13) | //src1
696+ C67_g((C67_map_regn(c) << 23) | //dst
697+ (C67_map_regn(b) << 18) | //src2
698+ (C67_map_regn(a) << 13) | //src1
699699 (xpath << 12) | //x use cross path for src2
700700 (0x38 << 6) | //opcode
701701 (0x8 << 2) | //opcode fixed
702− (C67_map_regs(S, c) << 1) | //side for reg c
702+ (C67_map_regs(c) << 1) | //side for reg c
703703 (0 << 0)); //parallel
704704 }
705705
706706 else if (strstr(s, "CMPLTDP") == s) {
707− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
708− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
707+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
708+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
709709
710− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
711− (C67_map_regn(S, b) << 18) | //src2
712− (C67_map_regn(S, a) << 13) | //src1
710+ C67_g((C67_map_regn(c) << 23) | //dst
711+ (C67_map_regn(b) << 18) | //src2
712+ (C67_map_regn(a) << 13) | //src1
713713 (xpath << 12) | //x use cross path for src2
714714 (0x2a << 6) | //opcode
715715 (0x8 << 2) | //opcode fixed
716− (C67_map_regs(S, c) << 1) | //side for reg c
716+ (C67_map_regs(c) << 1) | //side for reg c
717717 (0 << 0)); //parallel
718718 } else if (strstr(s, "CMPGTDP") == s) {
719− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
720− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
719+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
720+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
721721
722− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
723− (C67_map_regn(S, b) << 18) | //src2
724− (C67_map_regn(S, a) << 13) | //src1
722+ C67_g((C67_map_regn(c) << 23) | //dst
723+ (C67_map_regn(b) << 18) | //src2
724+ (C67_map_regn(a) << 13) | //src1
725725 (xpath << 12) | //x use cross path for src2
726726 (0x29 << 6) | //opcode
727727 (0x8 << 2) | //opcode fixed
728− (C67_map_regs(S, c) << 1) | //side for reg c
728+ (C67_map_regs(c) << 1) | //side for reg c
729729 (0 << 0)); //parallel
730730 } else if (strstr(s, "CMPEQDP") == s) {
731− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
732− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
731+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
732+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
733733
734− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
735− (C67_map_regn(S, b) << 18) | //src2
736− (C67_map_regn(S, a) << 13) | //src1
734+ C67_g((C67_map_regn(c) << 23) | //dst
735+ (C67_map_regn(b) << 18) | //src2
736+ (C67_map_regn(a) << 13) | //src1
737737 (xpath << 12) | //x use cross path for src2
738738 (0x28 << 6) | //opcode
739739 (0x8 << 2) | //opcode fixed
740− (C67_map_regs(S, c) << 1) | //side for reg c
740+ (C67_map_regs(c) << 1) | //side for reg c
741741 (0 << 0)); //parallel
742742 } else if (strstr(s, "CMPLT") == s) {
743− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
744− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
743+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
744+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
745745
746− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
747− (C67_map_regn(S, b) << 18) | //src2
748− (C67_map_regn(S, a) << 13) | //src1
746+ C67_g((C67_map_regn(c) << 23) | //dst
747+ (C67_map_regn(b) << 18) | //src2
748+ (C67_map_regn(a) << 13) | //src1
749749 (xpath << 12) | //x use cross path for src2
750750 (0x57 << 5) | //opcode
751751 (0x6 << 2) | //opcode fixed
752− (C67_map_regs(S, c) << 1) | //side for reg c
752+ (C67_map_regs(c) << 1) | //side for reg c
753753 (0 << 0)); //parallel
754754 } else if (strstr(s, "CMPGT") == s) {
755− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
756− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
755+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
756+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
757757
758− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
759− (C67_map_regn(S, b) << 18) | //src2
760− (C67_map_regn(S, a) << 13) | //src1
758+ C67_g((C67_map_regn(c) << 23) | //dst
759+ (C67_map_regn(b) << 18) | //src2
760+ (C67_map_regn(a) << 13) | //src1
761761 (xpath << 12) | //x use cross path for src2
762762 (0x47 << 5) | //opcode
763763 (0x6 << 2) | //opcode fixed
764− (C67_map_regs(S, c) << 1) | //side for reg c
764+ (C67_map_regs(c) << 1) | //side for reg c
765765 (0 << 0)); //parallel
766766 } else if (strstr(s, "CMPEQ") == s) {
767− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
768− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
767+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
768+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
769769
770− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
771− (C67_map_regn(S, b) << 18) | //src2
772− (C67_map_regn(S, a) << 13) | //src1
770+ C67_g((C67_map_regn(c) << 23) | //dst
771+ (C67_map_regn(b) << 18) | //src2
772+ (C67_map_regn(a) << 13) | //src1
773773 (xpath << 12) | //x use cross path for src2
774774 (0x53 << 5) | //opcode
775775 (0x6 << 2) | //opcode fixed
776− (C67_map_regs(S, c) << 1) | //side for reg c
776+ (C67_map_regs(c) << 1) | //side for reg c
777777 (0 << 0)); //parallel
778778 } else if (strstr(s, "CMPLTU") == s) {
779− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
780− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
779+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
780+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
781781
782− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
783− (C67_map_regn(S, b) << 18) | //src2
784− (C67_map_regn(S, a) << 13) | //src1
782+ C67_g((C67_map_regn(c) << 23) | //dst
783+ (C67_map_regn(b) << 18) | //src2
784+ (C67_map_regn(a) << 13) | //src1
785785 (xpath << 12) | //x use cross path for src2
786786 (0x5f << 5) | //opcode
787787 (0x6 << 2) | //opcode fixed
788− (C67_map_regs(S, c) << 1) | //side for reg c
788+ (C67_map_regs(c) << 1) | //side for reg c
789789 (0 << 0)); //parallel
790790 } else if (strstr(s, "CMPGTU") == s) {
791− xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
792− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
791+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
792+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
793793
794− C67_g(S, (C67_map_regn(S, c) << 23) | //dst
795− (C67_map_regn(S, b) << 18) | //src2
796− (C67_map_regn(S, a) << 13) | //src1
794+ C67_g((C67_map_regn(c) << 23) | //dst
795+ (C67_map_regn(b) << 18) | //src2
796+ (C67_map_regn(a) << 13) | //src1
797797 (xpath << 12) | //x use cross path for src2
798798 (0x4f << 5) | //opcode
799799 (0x6 << 2) | //opcode fixed
800− (C67_map_regs(S, c) << 1) | //side for reg c
800+ (C67_map_regs(c) << 1) | //side for reg c
801801 (0 << 0)); //parallel
802802 } else if (strstr(s, "B DISP") == s) {
803− C67_g(S, (0 << 29) | //creg
803+ C67_g((0 << 29) | //creg
804804 (0 << 28) | //z
805805 (a << 7) | //cnst
806806 (0x4 << 2) | //opcode fixed
807807 (0 << 1) | //S0/S1
808808 (0 << 0)); //parallel
809809 } else if (strstr(s, "B.") == s) {
810− xpath = C67_map_regs(S, c) ^ 1;
810+ xpath = C67_map_regs(c) ^ 1;
811811
812− C67_g(S, (C67_map_regc(S, b) << 29) | //creg
812+ C67_g((C67_map_regc(b) << 29) | //creg
813813 (a << 28) | //inv
814814 (0 << 23) | //dst
815− (C67_map_regn(S, c) << 18) | //src2
815+ (C67_map_regn(c) << 18) | //src2
816816 (0 << 13) | //
817817 (xpath << 12) | //x cross path if !B side
818818 (0xd << 6) | //opcode
@@ -820,369 +820,369 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 1 unmodified line
820820 (1 << 1) | //must be S2
821821 (0 << 0)); //parallel
822822 } else if (strstr(s, "MV.L") == s) {
823− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
823+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
824824
825− C67_g(S, (0 << 29) | //creg
825+ C67_g((0 << 29) | //creg
826826 (0 << 28) | //inv
827− (C67_map_regn(S, c) << 23) | //dst
828− (C67_map_regn(S, b) << 18) | //src2
827+ (C67_map_regn(c) << 23) | //dst
828+ (C67_map_regn(b) << 18) | //src2
829829 (0 << 13) | //src1 (cst5)
830830 (xpath << 12) | //x cross path if opposite sides
831831 (0x2 << 5) | //opcode
832832 (0x6 << 2) | //opcode fixed
833− (C67_map_regs(S, c) << 1) | //side of dest
833+ (C67_map_regs(c) << 1) | //side of dest
834834 (0 << 0)); //parallel
835835 } else if (strstr(s, "SPTRUNC.L") == s) {
836− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
836+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
837837
838− C67_g(S, (0 << 29) | //creg
838+ C67_g((0 << 29) | //creg
839839 (0 << 28) | //inv
840− (C67_map_regn(S, c) << 23) | //dst
841− (C67_map_regn(S, b) << 18) | //src2
840+ (C67_map_regn(c) << 23) | //dst
841+ (C67_map_regn(b) << 18) | //src2
842842 (0 << 13) | //src1 NA
843843 (xpath << 12) | //x cross path if opposite sides
844844 (0xb << 5) | //opcode
845845 (0x6 << 2) | //opcode fixed
846− (C67_map_regs(S, c) << 1) | //side of dest
846+ (C67_map_regs(c) << 1) | //side of dest
847847 (0 << 0)); //parallel
848848 } else if (strstr(s, "DPTRUNC.L") == s) {
849− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
849+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
850850
851− C67_g(S, (0 << 29) | //creg
851+ C67_g((0 << 29) | //creg
852852 (0 << 28) | //inv
853− (C67_map_regn(S, c) << 23) | //dst
854− ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
853+ (C67_map_regn(c) << 23) | //dst
854+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
855855 (0 << 13) | //src1 NA
856856 (xpath << 12) | //x cross path if opposite sides
857857 (0x1 << 5) | //opcode
858858 (0x6 << 2) | //opcode fixed
859− (C67_map_regs(S, c) << 1) | //side of dest
859+ (C67_map_regs(c) << 1) | //side of dest
860860 (0 << 0)); //parallel
861861 } else if (strstr(s, "INTSP.L") == s) {
862− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
862+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
863863
864− C67_g(S, (0 << 29) | //creg
864+ C67_g((0 << 29) | //creg
865865 (0 << 28) | //inv
866− (C67_map_regn(S, c) << 23) | //dst
867− (C67_map_regn(S, b) << 18) | //src2
866+ (C67_map_regn(c) << 23) | //dst
867+ (C67_map_regn(b) << 18) | //src2
868868 (0 << 13) | //src1 NA
869869 (xpath << 12) | //x cross path if opposite sides
870870 (0x4a << 5) | //opcode
871871 (0x6 << 2) | //opcode fixed
872− (C67_map_regs(S, c) << 1) | //side of dest
872+ (C67_map_regs(c) << 1) | //side of dest
873873 (0 << 0)); //parallel
874874 } else if (strstr(s, "INTSPU.L") == s) {
875− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
875+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
876876
877− C67_g(S, (0 << 29) | //creg
877+ C67_g((0 << 29) | //creg
878878 (0 << 28) | //inv
879− (C67_map_regn(S, c) << 23) | //dst
880− (C67_map_regn(S, b) << 18) | //src2
879+ (C67_map_regn(c) << 23) | //dst
880+ (C67_map_regn(b) << 18) | //src2
881881 (0 << 13) | //src1 NA
882882 (xpath << 12) | //x cross path if opposite sides
883883 (0x49 << 5) | //opcode
884884 (0x6 << 2) | //opcode fixed
885− (C67_map_regs(S, c) << 1) | //side of dest
885+ (C67_map_regs(c) << 1) | //side of dest
886886 (0 << 0)); //parallel
887887 } else if (strstr(s, "INTDP.L") == s) {
888− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
888+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
889889
890− C67_g(S, (0 << 29) | //creg
890+ C67_g((0 << 29) | //creg
891891 (0 << 28) | //inv
892− (C67_map_regn(S, c) << 23) | //dst
893− (C67_map_regn(S, b) << 18) | //src2
892+ (C67_map_regn(c) << 23) | //dst
893+ (C67_map_regn(b) << 18) | //src2
894894 (0 << 13) | //src1 NA
895895 (xpath << 12) | //x cross path if opposite sides
896896 (0x39 << 5) | //opcode
897897 (0x6 << 2) | //opcode fixed
898− (C67_map_regs(S, c) << 1) | //side of dest
898+ (C67_map_regs(c) << 1) | //side of dest
899899 (0 << 0)); //parallel
900900 } else if (strstr(s, "INTDPU.L") == s) {
901− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
901+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
902902
903− C67_g(S, (0 << 29) | //creg
903+ C67_g((0 << 29) | //creg
904904 (0 << 28) | //inv
905− (C67_map_regn(S, c) << 23) | //dst
906− ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
905+ (C67_map_regn(c) << 23) | //dst
906+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
907907 (0 << 13) | //src1 NA
908908 (xpath << 12) | //x cross path if opposite sides
909909 (0x3b << 5) | //opcode
910910 (0x6 << 2) | //opcode fixed
911− (C67_map_regs(S, c) << 1) | //side of dest
911+ (C67_map_regs(c) << 1) | //side of dest
912912 (0 << 0)); //parallel
913913 } else if (strstr(s, "SPDP.L") == s) {
914− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
914+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
915915
916− C67_g(S, (0 << 29) | //creg
916+ C67_g((0 << 29) | //creg
917917 (0 << 28) | //inv
918− (C67_map_regn(S, c) << 23) | //dst
919− (C67_map_regn(S, b) << 18) | //src2
918+ (C67_map_regn(c) << 23) | //dst
919+ (C67_map_regn(b) << 18) | //src2
920920 (0 << 13) | //src1 NA
921921 (xpath << 12) | //x cross path if opposite sides
922922 (0x2 << 6) | //opcode
923923 (0x8 << 2) | //opcode fixed
924− (C67_map_regs(S, c) << 1) | //side of dest
924+ (C67_map_regs(c) << 1) | //side of dest
925925 (0 << 0)); //parallel
926926 } else if (strstr(s, "DPSP.L") == s) {
927− ALWAYS_ASSERT(C67_map_regs(S, b) == C67_map_regs(S, c));
927+ ALWAYS_ASSERT(C67_map_regs(b) == C67_map_regs(c));
928928
929− C67_g(S, (0 << 29) | //creg
929+ C67_g((0 << 29) | //creg
930930 (0 << 28) | //inv
931− (C67_map_regn(S, c) << 23) | //dst
932− ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
931+ (C67_map_regn(c) << 23) | //dst
932+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
933933 (0 << 13) | //src1 NA
934934 (0 << 12) | //x cross path if opposite sides
935935 (0x9 << 5) | //opcode
936936 (0x6 << 2) | //opcode fixed
937− (C67_map_regs(S, c) << 1) | //side of dest
937+ (C67_map_regs(c) << 1) | //side of dest
938938 (0 << 0)); //parallel
939939 } else if (strstr(s, "ADD.L") == s) {
940− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
940+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
941941
942− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
942+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
943943
944− C67_g(S, (0 << 29) | //creg
944+ C67_g((0 << 29) | //creg
945945 (0 << 28) | //inv
946− (C67_map_regn(S, c) << 23) | //dst
947− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
948− (C67_map_regn(S, a) << 13) | //src1
946+ (C67_map_regn(c) << 23) | //dst
947+ (C67_map_regn(b) << 18) | //src2 (possible x path)
948+ (C67_map_regn(a) << 13) | //src1
949949 (xpath << 12) | //x cross path if opposite sides
950950 (0x3 << 5) | //opcode
951951 (0x6 << 2) | //opcode fixed
952− (C67_map_regs(S, c) << 1) | //side of dest
952+ (C67_map_regs(c) << 1) | //side of dest
953953 (0 << 0)); //parallel
954954 } else if (strstr(s, "SUB.L") == s) {
955− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
955+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
956956
957− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
957+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
958958
959− C67_g(S, (0 << 29) | //creg
959+ C67_g((0 << 29) | //creg
960960 (0 << 28) | //inv
961− (C67_map_regn(S, c) << 23) | //dst
962− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
963− (C67_map_regn(S, a) << 13) | //src1
961+ (C67_map_regn(c) << 23) | //dst
962+ (C67_map_regn(b) << 18) | //src2 (possible x path)
963+ (C67_map_regn(a) << 13) | //src1
964964 (xpath << 12) | //x cross path if opposite sides
965965 (0x7 << 5) | //opcode
966966 (0x6 << 2) | //opcode fixed
967− (C67_map_regs(S, c) << 1) | //side of dest
967+ (C67_map_regs(c) << 1) | //side of dest
968968 (0 << 0)); //parallel
969969 } else if (strstr(s, "OR.L") == s) {
970− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
970+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
971971
972− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
972+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
973973
974− C67_g(S, (0 << 29) | //creg
974+ C67_g((0 << 29) | //creg
975975 (0 << 28) | //inv
976− (C67_map_regn(S, c) << 23) | //dst
977− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
978− (C67_map_regn(S, a) << 13) | //src1
976+ (C67_map_regn(c) << 23) | //dst
977+ (C67_map_regn(b) << 18) | //src2 (possible x path)
978+ (C67_map_regn(a) << 13) | //src1
979979 (xpath << 12) | //x cross path if opposite sides
980980 (0x7f << 5) | //opcode
981981 (0x6 << 2) | //opcode fixed
982− (C67_map_regs(S, c) << 1) | //side of dest
982+ (C67_map_regs(c) << 1) | //side of dest
983983 (0 << 0)); //parallel
984984 } else if (strstr(s, "AND.L") == s) {
985− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
985+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
986986
987− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
987+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
988988
989− C67_g(S, (0 << 29) | //creg
989+ C67_g((0 << 29) | //creg
990990 (0 << 28) | //inv
991− (C67_map_regn(S, c) << 23) | //dst
992− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
993− (C67_map_regn(S, a) << 13) | //src1
991+ (C67_map_regn(c) << 23) | //dst
992+ (C67_map_regn(b) << 18) | //src2 (possible x path)
993+ (C67_map_regn(a) << 13) | //src1
994994 (xpath << 12) | //x cross path if opposite sides
995995 (0x7b << 5) | //opcode
996996 (0x6 << 2) | //opcode fixed
997− (C67_map_regs(S, c) << 1) | //side of dest
997+ (C67_map_regs(c) << 1) | //side of dest
998998 (0 << 0)); //parallel
999999 } else if (strstr(s, "XOR.L") == s) {
1000− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1000+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10011001
1002− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1002+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10031003
1004− C67_g(S, (0 << 29) | //creg
1004+ C67_g((0 << 29) | //creg
10051005 (0 << 28) | //inv
1006− (C67_map_regn(S, c) << 23) | //dst
1007− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1008− (C67_map_regn(S, a) << 13) | //src1
1006+ (C67_map_regn(c) << 23) | //dst
1007+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1008+ (C67_map_regn(a) << 13) | //src1
10091009 (xpath << 12) | //x cross path if opposite sides
10101010 (0x6f << 5) | //opcode
10111011 (0x6 << 2) | //opcode fixed
1012− (C67_map_regs(S, c) << 1) | //side of dest
1012+ (C67_map_regs(c) << 1) | //side of dest
10131013 (0 << 0)); //parallel
10141014 } else if (strstr(s, "ADDSP.L") == s) {
1015− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1015+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10161016
1017− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1017+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10181018
1019− C67_g(S, (0 << 29) | //creg
1019+ C67_g((0 << 29) | //creg
10201020 (0 << 28) | //inv
1021− (C67_map_regn(S, c) << 23) | //dst
1022− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1023− (C67_map_regn(S, a) << 13) | //src1
1021+ (C67_map_regn(c) << 23) | //dst
1022+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1023+ (C67_map_regn(a) << 13) | //src1
10241024 (xpath << 12) | //x cross path if opposite sides
10251025 (0x10 << 5) | //opcode
10261026 (0x6 << 2) | //opcode fixed
1027− (C67_map_regs(S, c) << 1) | //side of dest
1027+ (C67_map_regs(c) << 1) | //side of dest
10281028 (0 << 0)); //parallel
10291029 } else if (strstr(s, "ADDDP.L") == s) {
1030− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1030+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10311031
1032− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1032+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10331033
1034− C67_g(S, (0 << 29) | //creg
1034+ C67_g((0 << 29) | //creg
10351035 (0 << 28) | //inv
1036− (C67_map_regn(S, c) << 23) | //dst
1037− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1038− (C67_map_regn(S, a) << 13) | //src1
1036+ (C67_map_regn(c) << 23) | //dst
1037+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1038+ (C67_map_regn(a) << 13) | //src1
10391039 (xpath << 12) | //x cross path if opposite sides
10401040 (0x18 << 5) | //opcode
10411041 (0x6 << 2) | //opcode fixed
1042− (C67_map_regs(S, c) << 1) | //side of dest
1042+ (C67_map_regs(c) << 1) | //side of dest
10431043 (0 << 0)); //parallel
10441044 } else if (strstr(s, "SUBSP.L") == s) {
1045− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1045+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10461046
1047− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1047+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10481048
1049− C67_g(S, (0 << 29) | //creg
1049+ C67_g((0 << 29) | //creg
10501050 (0 << 28) | //inv
1051− (C67_map_regn(S, c) << 23) | //dst
1052− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1053− (C67_map_regn(S, a) << 13) | //src1
1051+ (C67_map_regn(c) << 23) | //dst
1052+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1053+ (C67_map_regn(a) << 13) | //src1
10541054 (xpath << 12) | //x cross path if opposite sides
10551055 (0x11 << 5) | //opcode
10561056 (0x6 << 2) | //opcode fixed
1057− (C67_map_regs(S, c) << 1) | //side of dest
1057+ (C67_map_regs(c) << 1) | //side of dest
10581058 (0 << 0)); //parallel
10591059 } else if (strstr(s, "SUBDP.L") == s) {
1060− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1060+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10611061
1062− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1062+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10631063
1064− C67_g(S, (0 << 29) | //creg
1064+ C67_g((0 << 29) | //creg
10651065 (0 << 28) | //inv
1066− (C67_map_regn(S, c) << 23) | //dst
1067− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1068− (C67_map_regn(S, a) << 13) | //src1
1066+ (C67_map_regn(c) << 23) | //dst
1067+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1068+ (C67_map_regn(a) << 13) | //src1
10691069 (xpath << 12) | //x cross path if opposite sides
10701070 (0x19 << 5) | //opcode
10711071 (0x6 << 2) | //opcode fixed
1072− (C67_map_regs(S, c) << 1) | //side of dest
1072+ (C67_map_regs(c) << 1) | //side of dest
10731073 (0 << 0)); //parallel
10741074 } else if (strstr(s, "MPYSP.M") == s) {
1075− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1075+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10761076
1077− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1077+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10781078
1079− C67_g(S, (0 << 29) | //creg
1079+ C67_g((0 << 29) | //creg
10801080 (0 << 28) | //inv
1081− (C67_map_regn(S, c) << 23) | //dst
1082− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1083− (C67_map_regn(S, a) << 13) | //src1
1081+ (C67_map_regn(c) << 23) | //dst
1082+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1083+ (C67_map_regn(a) << 13) | //src1
10841084 (xpath << 12) | //x cross path if opposite sides
10851085 (0x1c << 7) | //opcode
10861086 (0x0 << 2) | //opcode fixed
1087− (C67_map_regs(S, c) << 1) | //side of dest
1087+ (C67_map_regs(c) << 1) | //side of dest
10881088 (0 << 0)); //parallel
10891089 } else if (strstr(s, "MPYDP.M") == s) {
1090− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1090+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
10911091
1092− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1092+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
10931093
1094− C67_g(S, (0 << 29) | //creg
1094+ C67_g((0 << 29) | //creg
10951095 (0 << 28) | //inv
1096− (C67_map_regn(S, c) << 23) | //dst
1097− (C67_map_regn(S, b) << 18) | //src2 (possible x path)
1098− (C67_map_regn(S, a) << 13) | //src1
1096+ (C67_map_regn(c) << 23) | //dst
1097+ (C67_map_regn(b) << 18) | //src2 (possible x path)
1098+ (C67_map_regn(a) << 13) | //src1
10991099 (xpath << 12) | //x cross path if opposite sides
11001100 (0x0e << 7) | //opcode
11011101 (0x0 << 2) | //opcode fixed
1102− (C67_map_regs(S, c) << 1) | //side of dest
1102+ (C67_map_regs(c) << 1) | //side of dest
11031103 (0 << 0)); //parallel
11041104 } else if (strstr(s, "MPYI.M") == s) {
1105− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1105+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
11061106
1107− ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
1107+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
11081108
1109− C67_g(S, (0 << 29) | //creg
1109+ C67_g((0 << 29) | //creg
11101110 (0 << 28) | //inv
1111− (C67_map_regn(S, c) << 23) | //dst
1112− (C67_map_regn(S, b) << 18) | //src2
1113− (C67_map_regn(S, a) << 13) | //src1 (cst5)
1111+ (C67_map_regn(c) << 23) | //dst
1112+ (C67_map_regn(b) << 18) | //src2
1113+ (C67_map_regn(a) << 13) | //src1 (cst5)
11141114 (xpath << 12) | //x cross path if opposite sides
11151115 (0x4 << 7) | //opcode
11161116 (0x0 << 2) | //opcode fixed
1117− (C67_map_regs(S, c) << 1) | //side of dest
1117+ (C67_map_regs(c) << 1) | //side of dest
11181118 (0 << 0)); //parallel
11191119 } else if (strstr(s, "SHR.S") == s) {
1120− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1120+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
11211121
1122− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
1122+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
11231123
1124− C67_g(S, (0 << 29) | //creg
1124+ C67_g((0 << 29) | //creg
11251125 (0 << 28) | //inv
1126− (C67_map_regn(S, c) << 23) | //dst
1127− (C67_map_regn(S, b) << 18) | //src2
1128− (C67_map_regn(S, a) << 13) | //src1
1126+ (C67_map_regn(c) << 23) | //dst
1127+ (C67_map_regn(b) << 18) | //src2
1128+ (C67_map_regn(a) << 13) | //src1
11291129 (xpath << 12) | //x cross path if opposite sides
11301130 (0x37 << 6) | //opcode
11311131 (0x8 << 2) | //opcode fixed
1132− (C67_map_regs(S, c) << 1) | //side of dest
1132+ (C67_map_regs(c) << 1) | //side of dest
11331133 (0 << 0)); //parallel
11341134 } else if (strstr(s, "SHRU.S") == s) {
1135− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1135+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
11361136
1137− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
1137+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
11381138
1139− C67_g(S, (0 << 29) | //creg
1139+ C67_g((0 << 29) | //creg
11401140 (0 << 28) | //inv
1141− (C67_map_regn(S, c) << 23) | //dst
1142− (C67_map_regn(S, b) << 18) | //src2
1143− (C67_map_regn(S, a) << 13) | //src1
1141+ (C67_map_regn(c) << 23) | //dst
1142+ (C67_map_regn(b) << 18) | //src2
1143+ (C67_map_regn(a) << 13) | //src1
11441144 (xpath << 12) | //x cross path if opposite sides
11451145 (0x27 << 6) | //opcode
11461146 (0x8 << 2) | //opcode fixed
1147− (C67_map_regs(S, c) << 1) | //side of dest
1147+ (C67_map_regs(c) << 1) | //side of dest
11481148 (0 << 0)); //parallel
11491149 } else if (strstr(s, "SHL.S") == s) {
1150− xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
1150+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
11511151
1152− ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
1152+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
11531153
1154− C67_g(S, (0 << 29) | //creg
1154+ C67_g((0 << 29) | //creg
11551155 (0 << 28) | //inv
1156− (C67_map_regn(S, c) << 23) | //dst
1157− (C67_map_regn(S, b) << 18) | //src2
1158− (C67_map_regn(S, a) << 13) | //src1
1156+ (C67_map_regn(c) << 23) | //dst
1157+ (C67_map_regn(b) << 18) | //src2
1158+ (C67_map_regn(a) << 13) | //src1
11591159 (xpath << 12) | //x cross path if opposite sides
11601160 (0x33 << 6) | //opcode
11611161 (0x8 << 2) | //opcode fixed
1162− (C67_map_regs(S, c) << 1) | //side of dest
1162+ (C67_map_regs(c) << 1) | //side of dest
11631163 (0 << 0)); //parallel
11641164 } else if (strstr(s, "||ADDK") == s) {
11651165 xpath = 0; // no xpath required just use the side of the src/dst
11661166
1167− C67_g(S, (0 << 29) | //creg
1167+ C67_g((0 << 29) | //creg
11681168 (0 << 28) | //inv
1169− (C67_map_regn(S, b) << 23) | //dst
1169+ (C67_map_regn(b) << 23) | //dst
11701170 (a << 07) | //scst16
11711171 (0x14 << 2) | //opcode fixed
1172− (C67_map_regs(S, b) << 1) | //side of dst
1172+ (C67_map_regs(b) << 1) | //side of dst
11731173 (1 << 0)); //parallel
11741174 } else if (strstr(s, "ADDK") == s) {
11751175 xpath = 0; // no xpath required just use the side of the src/dst
11761176
1177− C67_g(S, (0 << 29) | //creg
1177+ C67_g((0 << 29) | //creg
11781178 (0 << 28) | //inv
1179− (C67_map_regn(S, b) << 23) | //dst
1179+ (C67_map_regn(b) << 23) | //dst
11801180 (a << 07) | //scst16
11811181 (0x14 << 2) | //opcode fixed
1182− (C67_map_regs(S, b) << 1) | //side of dst
1182+ (C67_map_regs(b) << 1) | //side of dst
11831183 (0 << 0)); //parallel
11841184 } else if (strstr(s, "NOP") == s) {
1185− C67_g(S, ((a - 1) << 13) | //no of cycles
1185+ C67_g(((a - 1) << 13) | //no of cycles
11861186 (0 << 0)); //parallel
11871187 } else
11881188 ALWAYS_ASSERT(FALSE);
@@ -1195,198 +1195,198 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c) · 6 unmodified lines
11951195
11961196 //r=reg to load, fr=from reg, symbol for relocation, constant
11971197
1198−void C67_MVKL(TCCState* S, int r, int fc)
1198+void C67_MVKL(int r, int fc)
11991199 {
1200− C67_asm(S, "MVKL.", fc, r, 0);
1200+ C67_asm("MVKL.", fc, r, 0);
12011201 }
12021202
1203−void C67_MVKH(TCCState* S, int r, int fc)
1203+void C67_MVKH(int r, int fc)
12041204 {
1205− C67_asm(S, "MVKH.", fc, r, 0);
1205+ C67_asm("MVKH.", fc, r, 0);
12061206 }
12071207
1208−void C67_STB_SP_A0(TCCState* S, int r)
1208+void C67_STB_SP_A0(int r)
12091209 {
1210− C67_asm(S, "STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0]
1210+ C67_asm("STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0]
12111211 }
12121212
1213−void C67_STH_SP_A0(TCCState* S, int r)
1213+void C67_STH_SP_A0(int r)
12141214 {
1215− C67_asm(S, "STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0]
1215+ C67_asm("STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0]
12161216 }
12171217
1218−void C67_STW_SP_A0(TCCState* S, int r)
1218+void C67_STW_SP_A0(int r)
12191219 {
1220− C67_asm(S, "STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0]
1220+ C67_asm("STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0]
12211221 }
12221222
1223−void C67_STB_PTR(TCCState* S, int r, int r2)
1223+void C67_STB_PTR(int r, int r2)
12241224 {
1225− C67_asm(S, "STB.D *", r, r2, 0); // STB r, *r2
1225+ C67_asm("STB.D *", r, r2, 0); // STB r, *r2
12261226 }
12271227
1228−void C67_STH_PTR(TCCState* S, int r, int r2)
1228+void C67_STH_PTR(int r, int r2)
12291229 {
1230− C67_asm(S, "STH.D *", r, r2, 0); // STH r, *r2
1230+ C67_asm("STH.D *", r, r2, 0); // STH r, *r2
12311231 }
12321232
1233−void C67_STW_PTR(TCCState* S, int r, int r2)
1233+void C67_STW_PTR(int r, int r2)
12341234 {
1235− C67_asm(S, "STW.D *", r, r2, 0); // STW r, *r2
1235+ C67_asm("STW.D *", r, r2, 0); // STW r, *r2
12361236 }
12371237
1238−void C67_STW_PTR_PRE_INC(TCCState* S, int r, int r2, int n)
1238+void C67_STW_PTR_PRE_INC(int r, int r2, int n)
12391239 {
1240− C67_asm(S, "STW.D +*", r, r2, n); // STW r, *+r2
1240+ C67_asm("STW.D +*", r, r2, n); // STW r, *+r2
12411241 }
12421242
1243−void C67_PUSH(TCCState* S, int r)
1243+void C67_PUSH(int r)
12441244 {
1245− C67_asm(S, "STW.D SP POST DEC", r, 0, 0); // STW r,*SP--
1245+ C67_asm("STW.D SP POST DEC", r, 0, 0); // STW r,*SP--
12461246 }
12471247
1248−void C67_LDW_SP_A0(TCCState* S, int r)
1248+void C67_LDW_SP_A0(int r)
12491249 {
1250− C67_asm(S, "LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r
1250+ C67_asm("LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r
12511251 }
12521252
1253−void C67_LDDW_SP_A0(TCCState* S, int r)
1253+void C67_LDDW_SP_A0(int r)
12541254 {
1255− C67_asm(S, "LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r
1255+ C67_asm("LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r
12561256 }
12571257
1258−void C67_LDH_SP_A0(TCCState* S, int r)
1258+void C67_LDH_SP_A0(int r)
12591259 {
1260− C67_asm(S, "LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r
1260+ C67_asm("LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r
12611261 }
12621262
1263−void C67_LDB_SP_A0(TCCState* S, int r)
1263+void C67_LDB_SP_A0(int r)
12641264 {
1265− C67_asm(S, "LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r
1265+ C67_asm("LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r
12661266 }
12671267
1268−void C67_LDHU_SP_A0(TCCState* S, int r)
1268+void C67_LDHU_SP_A0(int r)
12691269 {
1270− C67_asm(S, "LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r
1270+ C67_asm("LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r
12711271 }
12721272
1273−void C67_LDBU_SP_A0(TCCState* S, int r)
1273+void C67_LDBU_SP_A0(int r)
12741274 {
1275− C67_asm(S, "LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r
1275+ C67_asm("LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r
12761276 }
12771277
1278−void C67_LDW_PTR(TCCState* S, int r, int r2)
1278+void C67_LDW_PTR(int r, int r2)
12791279 {
1280− C67_asm(S, "LDW.D *", r, r2, 0); // LDW *r,r2
1280+ C67_asm("LDW.D *", r, r2, 0); // LDW *r,r2
12811281 }
12821282
1283−void C67_LDDW_PTR(TCCState* S, int r, int r2)
1283+void C67_LDDW_PTR(int r, int r2)
12841284 {
1285− C67_asm(S, "LDDW.D *", r, r2, 0); // LDDW *r,r2
1285+ C67_asm("LDDW.D *", r, r2, 0); // LDDW *r,r2
12861286 }
12871287
1288−void C67_LDH_PTR(TCCState* S, int r, int r2)
1288+void C67_LDH_PTR(int r, int r2)
12891289 {
1290− C67_asm(S, "LDH.D *", r, r2, 0); // LDH *r,r2
1290+ C67_asm("LDH.D *", r, r2, 0); // LDH *r,r2
12911291 }
12921292
1293−void C67_LDB_PTR(TCCState* S, int r, int r2)
1293+void C67_LDB_PTR(int r, int r2)
12941294 {
1295− C67_asm(S, "LDB.D *", r, r2, 0); // LDB *r,r2
1295+ C67_asm("LDB.D *", r, r2, 0); // LDB *r,r2
12961296 }
12971297
1298−void C67_LDHU_PTR(TCCState* S, int r, int r2)
1298+void C67_LDHU_PTR(int r, int r2)
12991299 {
1300− C67_asm(S, "LDHU.D *", r, r2, 0); // LDHU *r,r2
1300+ C67_asm("LDHU.D *", r, r2, 0); // LDHU *r,r2
13011301 }
13021302
1303−void C67_LDBU_PTR(TCCState* S, int r, int r2)
1303+void C67_LDBU_PTR(int r, int r2)
13041304 {
1305− C67_asm(S, "LDBU.D *", r, r2, 0); // LDBU *r,r2
1305+ C67_asm("LDBU.D *", r, r2, 0); // LDBU *r,r2
13061306 }
13071307
1308−void C67_LDW_PTR_PRE_INC(TCCState* S, int r, int r2)
1308+void C67_LDW_PTR_PRE_INC(int r, int r2)
13091309 {
1310− C67_asm(S, "LDW.D +*", r, r2, 0); // LDW *+r,r2
1310+ C67_asm("LDW.D +*", r, r2, 0); // LDW *+r,r2
13111311 }
13121312
1313−void C67_POP(TCCState* S, int r)
1313+void C67_POP(int r)
13141314 {
1315− C67_asm(S, "LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r
1315+ C67_asm("LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r
13161316 }
13171317
1318−void C67_POP_DW(TCCState* S, int r)
1318+void C67_POP_DW(int r)
13191319 {
1320− C67_asm(S, "LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r
1320+ C67_asm("LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r
13211321 }
13221322
1323−void C67_CMPLT(TCCState* S, int s1, int s2, int dst)
1323+void C67_CMPLT(int s1, int s2, int dst)
13241324 {
1325− C67_asm(S, "CMPLT.L1", s1, s2, dst);
1325+ C67_asm("CMPLT.L1", s1, s2, dst);
13261326 }
13271327
1328−void C67_CMPGT(TCCState* S, int s1, int s2, int dst)
1328+void C67_CMPGT(int s1, int s2, int dst)
13291329 {
1330− C67_asm(S, "CMPGT.L1", s1, s2, dst);
1330+ C67_asm("CMPGT.L1", s1, s2, dst);
13311331 }
13321332
1333−void C67_CMPEQ(TCCState* S, int s1, int s2, int dst)
1333+void C67_CMPEQ(int s1, int s2, int dst)
13341334 {
1335− C67_asm(S, "CMPEQ.L1", s1, s2, dst);
1335+ C67_asm("CMPEQ.L1", s1, s2, dst);
13361336 }
13371337
1338−void C67_CMPLTU(TCCState* S, int s1, int s2, int dst)
1338+void C67_CMPLTU(int s1, int s2, int dst)
13391339 {
1340− C67_asm(S, "CMPLTU.L1", s1, s2, dst);
1340+ C67_asm("CMPLTU.L1", s1, s2, dst);
13411341 }
13421342
1343−void C67_CMPGTU(TCCState* S, int s1, int s2, int dst)
1343+void C67_CMPGTU(int s1, int s2, int dst)
13441344 {
1345− C67_asm(S, "CMPGTU.L1", s1, s2, dst);
1345+ C67_asm("CMPGTU.L1", s1, s2, dst);
13461346 }
13471347
13481348
1349−void C67_CMPLTSP(TCCState* S, int s1, int s2, int dst)
1349+void C67_CMPLTSP(int s1, int s2, int dst)
13501350 {
1351− C67_asm(S, "CMPLTSP.S1", s1, s2, dst);
1351+ C67_asm("CMPLTSP.S1", s1, s2, dst);
13521352 }
13531353
1354−void C67_CMPGTSP(TCCState* S, int s1, int s2, int dst)
1354+void C67_CMPGTSP(int s1, int s2, int dst)
13551355 {
1356− C67_asm(S, "CMPGTSP.S1", s1, s2, dst);
1356+ C67_asm("CMPGTSP.S1", s1, s2, dst);
13571357 }
13581358
1359−void C67_CMPEQSP(TCCState* S, int s1, int s2, int dst)
1359+void C67_CMPEQSP(int s1, int s2, int dst)
13601360 {
1361− C67_asm(S, "CMPEQSP.S1", s1, s2, dst);
1361+ C67_asm("CMPEQSP.S1", s1, s2, dst);
13621362 }
13631363
1364−void C67_CMPLTDP(TCCState* S, int s1, int s2, int dst)
1364+void C67_CMPLTDP(int s1, int s2, int dst)
13651365 {
1366− C67_asm(S, "CMPLTDP.S1", s1, s2, dst);
1366+ C67_asm("CMPLTDP.S1", s1, s2, dst);
13671367 }
13681368
1369−void C67_CMPGTDP(TCCState* S, int s1, int s2, int dst)
1369+void C67_CMPGTDP(int s1, int s2, int dst)
13701370 {
1371− C67_asm(S, "CMPGTDP.S1", s1, s2, dst);
1371+ C67_asm("CMPGTDP.S1", s1, s2, dst);
13721372 }
13731373
1374−void C67_CMPEQDP(TCCState* S, int s1, int s2, int dst)
1374+void C67_CMPEQDP(int s1, int s2, int dst)
13751375 {
1376− C67_asm(S, "CMPEQDP.S1", s1, s2, dst);
1376+ C67_asm("CMPEQDP.S1", s1, s2, dst);
13771377 }
13781378
13791379
1380−void C67_IREG_B_REG(TCCState* S, int inv, int r1, int r2) // [!R] B r2
1380+void C67_IREG_B_REG(int inv, int r1, int r2) // [!R] B r2
13811381 {
1382− C67_asm(S, "B.S2", inv, r1, r2);
1382+ C67_asm("B.S2", inv, r1, r2);
13831383 }
13841384
13851385
13861386 // call with how many 32 bit words to skip
13871387 // (0 would branch to the branch instruction)
13881388
1389−void C67_B_DISP(TCCState* S, int disp) // B +2 Branch with constant displacement
1389+void C67_B_DISP(int disp) // B +2 Branch with constant displacement
13901390 {
13911391 // Branch point is relative to the 8 word fetch packet
13921392 //
@@ -1395,160 +1395,160 @@ void C67_B_DISP(TCCState* S, int disp) // B +2 Branch with constant displacem · 2 unmodified lines
13951395 // so add in how many words into the fetch packet the branch is
13961396
13971397
1398− C67_asm(S, "B DISP", disp + ((S->tccgen_ind & 31) >> 2), 0, 0);
1398+ C67_asm("B DISP", disp + ((ind & 31) >> 2), 0, 0);
13991399 }
14001400
1401−void C67_NOP(TCCState* S, int n)
1401+void C67_NOP(int n)
14021402 {
1403− C67_asm(S, "NOP", n, 0, 0);
1403+ C67_asm("NOP", n, 0, 0);
14041404 }
14051405
1406−void C67_ADDK(TCCState* S, int n, int r)
1406+void C67_ADDK(int n, int r)
14071407 {
14081408 ALWAYS_ASSERT(abs(n) < 32767);
14091409
1410− C67_asm(S, "ADDK", n, r, 0);
1410+ C67_asm("ADDK", n, r, 0);
14111411 }
14121412
1413−void C67_ADDK_PARALLEL(TCCState* S, int n, int r)
1413+void C67_ADDK_PARALLEL(int n, int r)
14141414 {
14151415 ALWAYS_ASSERT(abs(n) < 32767);
14161416
1417− C67_asm(S, "||ADDK", n, r, 0);
1417+ C67_asm("||ADDK", n, r, 0);
14181418 }
14191419
1420−void C67_Adjust_ADDK(TCCState* S, int *inst, int n)
1420+void C67_Adjust_ADDK(int *inst, int n)
14211421 {
14221422 ALWAYS_ASSERT(abs(n) < 32767);
14231423
14241424 *inst = (*inst & (~(0xffff << 7))) | ((n & 0xffff) << 7);
14251425 }
14261426
1427−void C67_MV(TCCState* S, int r, int v)
1427+void C67_MV(int r, int v)
14281428 {
1429− C67_asm(S, "MV.L", 0, r, v);
1429+ C67_asm("MV.L", 0, r, v);
14301430 }
14311431
14321432
1433−void C67_DPTRUNC(TCCState* S, int r, int v)
1433+void C67_DPTRUNC(int r, int v)
14341434 {
1435− C67_asm(S, "DPTRUNC.L", 0, r, v);
1435+ C67_asm("DPTRUNC.L", 0, r, v);
14361436 }
14371437
1438−void C67_SPTRUNC(TCCState* S, int r, int v)
1438+void C67_SPTRUNC(int r, int v)
14391439 {
1440− C67_asm(S, "SPTRUNC.L", 0, r, v);
1440+ C67_asm("SPTRUNC.L", 0, r, v);
14411441 }
14421442
1443−void C67_INTSP(TCCState* S, int r, int v)
1443+void C67_INTSP(int r, int v)
14441444 {
1445− C67_asm(S, "INTSP.L", 0, r, v);
1445+ C67_asm("INTSP.L", 0, r, v);
14461446 }
14471447
1448−void C67_INTDP(TCCState* S, int r, int v)
1448+void C67_INTDP(int r, int v)
14491449 {
1450− C67_asm(S, "INTDP.L", 0, r, v);
1450+ C67_asm("INTDP.L", 0, r, v);
14511451 }
14521452
1453−void C67_INTSPU(TCCState* S, int r, int v)
1453+void C67_INTSPU(int r, int v)
14541454 {
1455− C67_asm(S, "INTSPU.L", 0, r, v);
1455+ C67_asm("INTSPU.L", 0, r, v);
14561456 }
14571457
1458−void C67_INTDPU(TCCState* S, int r, int v)
1458+void C67_INTDPU(int r, int v)
14591459 {
1460− C67_asm(S, "INTDPU.L", 0, r, v);
1460+ C67_asm("INTDPU.L", 0, r, v);
14611461 }
14621462
1463−void C67_SPDP(TCCState* S, int r, int v)
1463+void C67_SPDP(int r, int v)
14641464 {
1465− C67_asm(S, "SPDP.L", 0, r, v);
1465+ C67_asm("SPDP.L", 0, r, v);
14661466 }
14671467
1468−void C67_DPSP(TCCState* S, int r, int v) // note regs must be on the same side
1468+void C67_DPSP(int r, int v) // note regs must be on the same side
14691469 {
1470− C67_asm(S, "DPSP.L", 0, r, v);
1470+ C67_asm("DPSP.L", 0, r, v);
14711471 }
14721472
1473−void C67_ADD(TCCState* S, int r, int v)
1473+void C67_ADD(int r, int v)
14741474 {
1475− C67_asm(S, "ADD.L", v, r, v);
1475+ C67_asm("ADD.L", v, r, v);
14761476 }
14771477
1478−void C67_SUB(TCCState* S, int r, int v)
1478+void C67_SUB(int r, int v)
14791479 {
1480− C67_asm(S, "SUB.L", v, r, v);
1480+ C67_asm("SUB.L", v, r, v);
14811481 }
14821482
1483−void C67_AND(TCCState* S, int r, int v)
1483+void C67_AND(int r, int v)
14841484 {
1485− C67_asm(S, "AND.L", v, r, v);
1485+ C67_asm("AND.L", v, r, v);
14861486 }
14871487
1488−void C67_OR(TCCState* S, int r, int v)
1488+void C67_OR(int r, int v)
14891489 {
1490− C67_asm(S, "OR.L", v, r, v);
1490+ C67_asm("OR.L", v, r, v);
14911491 }
14921492
1493−void C67_XOR(TCCState* S, int r, int v)
1493+void C67_XOR(int r, int v)
14941494 {
1495− C67_asm(S, "XOR.L", v, r, v);
1495+ C67_asm("XOR.L", v, r, v);
14961496 }
14971497
1498−void C67_ADDSP(TCCState* S, int r, int v)
1498+void C67_ADDSP(int r, int v)
14991499 {
1500− C67_asm(S, "ADDSP.L", v, r, v);
1500+ C67_asm("ADDSP.L", v, r, v);
15011501 }
15021502
1503−void C67_SUBSP(TCCState* S, int r, int v)
1503+void C67_SUBSP(int r, int v)
15041504 {
1505− C67_asm(S, "SUBSP.L", v, r, v);
1505+ C67_asm("SUBSP.L", v, r, v);
15061506 }
15071507
1508−void C67_MPYSP(TCCState* S, int r, int v)
1508+void C67_MPYSP(int r, int v)
15091509 {
1510− C67_asm(S, "MPYSP.M", v, r, v);
1510+ C67_asm("MPYSP.M", v, r, v);
15111511 }
15121512
1513−void C67_ADDDP(TCCState* S, int r, int v)
1513+void C67_ADDDP(int r, int v)
15141514 {
1515− C67_asm(S, "ADDDP.L", v, r, v);
1515+ C67_asm("ADDDP.L", v, r, v);
15161516 }
15171517
1518−void C67_SUBDP(TCCState* S, int r, int v)
1518+void C67_SUBDP(int r, int v)
15191519 {
1520− C67_asm(S, "SUBDP.L", v, r, v);
1520+ C67_asm("SUBDP.L", v, r, v);
15211521 }
15221522
1523−void C67_MPYDP(TCCState* S, int r, int v)
1523+void C67_MPYDP(int r, int v)
15241524 {
1525− C67_asm(S, "MPYDP.M", v, r, v);
1525+ C67_asm("MPYDP.M", v, r, v);
15261526 }
15271527
1528−void C67_MPYI(TCCState* S, int r, int v)
1528+void C67_MPYI(int r, int v)
15291529 {
1530− C67_asm(S, "MPYI.M", v, r, v);
1530+ C67_asm("MPYI.M", v, r, v);
15311531 }
15321532
1533−void C67_SHL(TCCState* S, int r, int v)
1533+void C67_SHL(int r, int v)
15341534 {
1535− C67_asm(S, "SHL.S", r, v, v);
1535+ C67_asm("SHL.S", r, v, v);
15361536 }
15371537
1538−void C67_SHRU(TCCState* S, int r, int v)
1538+void C67_SHRU(int r, int v)
15391539 {
1540− C67_asm(S, "SHRU.S", r, v, v);
1540+ C67_asm("SHRU.S", r, v, v);
15411541 }
15421542
1543−void C67_SHR(TCCState* S, int r, int v)
1543+void C67_SHR(int r, int v)
15441544 {
1545− C67_asm(S, "SHR.S", r, v, v);
1545+ C67_asm("SHR.S", r, v, v);
15461546 }
15471547
15481548
15491549
15501550 /* load 'r' from value 'sv' */
1551−void load(TCCState* S, int r, SValue * sv)
1551+void load(int r, SValue * sv)
15521552 {
15531553 int v, t, ft, fc, fr, size = 0, element;
15541554 BOOL Unsigned = FALSE;
@@ -1564,10 +1564,10 @@ void load(TCCState* S, int r, SValue * sv) · 9 unmodified lines
15641564 v1.type.t = VT_INT;
15651565 v1.r = VT_LOCAL | VT_LVAL;
15661566 v1.c.i = fc;
1567− load(S, r, &v1);
1567+ load(r, &v1);
15681568 fr = r;
15691569 } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
1570− tcc_error(S, "long double not supported");
1570+ tcc_error("long double not supported");
15711571 } else if ((ft & VT_TYPE) == VT_BYTE) {
15721572 size = 1;
15731573 } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
@@ -1608,109 +1608,109 @@ void load(TCCState* S, int r, SValue * sv) · 34 unmodified lines
16081608 {
16091609 if (size == 1) {
16101610 if (Unsigned)
1611− C67_LDBU_PTR(S, v, r); // LDBU *v,r
1611+ C67_LDBU_PTR(v, r); // LDBU *v,r
16121612 else
1613− C67_LDB_PTR(S, v, r); // LDB *v,r
1613+ C67_LDB_PTR(v, r); // LDB *v,r
16141614 } else if (size == 2) {
16151615 if (Unsigned)
1616− C67_LDHU_PTR(S, v, r); // LDHU *v,r
1616+ C67_LDHU_PTR(v, r); // LDHU *v,r
16171617 else
1618− C67_LDH_PTR(S, v, r); // LDH *v,r
1618+ C67_LDH_PTR(v, r); // LDH *v,r
16191619 } else if (size == 4) {
1620− C67_LDW_PTR(S, v, r); // LDW *v,r
1620+ C67_LDW_PTR(v, r); // LDW *v,r
16211621 } else if (size == 8) {
1622− C67_LDDW_PTR(S, v, r); // LDDW *v,r
1622+ C67_LDDW_PTR(v, r); // LDDW *v,r
16231623 }
16241624
1625− C67_NOP(S, 4); // NOP 4
1625+ C67_NOP(4); // NOP 4
16261626 return;
16271627 } else if (fr & VT_SYM) {
1628− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1629− greloc(S, cur_text_section, sv->sym, S->tccgen_ind + 4, R_C60HI16);
1628+ greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched
1629+ greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16);
16301630
16311631
1632− C67_MVKL(S, C67_A0, fc); //r=reg to load, constant
1633− C67_MVKH(S, C67_A0, fc); //r=reg to load, constant
1632+ C67_MVKL(C67_A0, fc); //r=reg to load, constant
1633+ C67_MVKH(C67_A0, fc); //r=reg to load, constant
16341634
16351635
16361636 if (size == 1) {
16371637 if (Unsigned)
1638− C67_LDBU_PTR(S, C67_A0, r); // LDBU *A0,r
1638+ C67_LDBU_PTR(C67_A0, r); // LDBU *A0,r
16391639 else
1640− C67_LDB_PTR(S, C67_A0, r); // LDB *A0,r
1640+ C67_LDB_PTR(C67_A0, r); // LDB *A0,r
16411641 } else if (size == 2) {
16421642 if (Unsigned)
1643− C67_LDHU_PTR(S, C67_A0, r); // LDHU *A0,r
1643+ C67_LDHU_PTR(C67_A0, r); // LDHU *A0,r
16441644 else
1645− C67_LDH_PTR(S, C67_A0, r); // LDH *A0,r
1645+ C67_LDH_PTR(C67_A0, r); // LDH *A0,r
16461646 } else if (size == 4) {
1647− C67_LDW_PTR(S, C67_A0, r); // LDW *A0,r
1647+ C67_LDW_PTR(C67_A0, r); // LDW *A0,r
16481648 } else if (size == 8) {
1649− C67_LDDW_PTR(S, C67_A0, r); // LDDW *A0,r
1649+ C67_LDDW_PTR(C67_A0, r); // LDDW *A0,r
16501650 }
16511651
1652− C67_NOP(S, 4); // NOP 4
1652+ C67_NOP(4); // NOP 4
16531653 return;
16541654 } else {
16551655 element = size;
16561656
16571657 // divide offset in bytes to create element index
1658− C67_MVKL(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1659− C67_MVKH(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1658+ C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1659+ C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
16601660
16611661 if (size == 1) {
16621662 if (Unsigned)
1663− C67_LDBU_SP_A0(S, r); // LDBU r, SP[A0]
1663+ C67_LDBU_SP_A0(r); // LDBU r, SP[A0]
16641664 else
1665− C67_LDB_SP_A0(S, r); // LDB r, SP[A0]
1665+ C67_LDB_SP_A0(r); // LDB r, SP[A0]
16661666 } else if (size == 2) {
16671667 if (Unsigned)
1668− C67_LDHU_SP_A0(S, r); // LDHU r, SP[A0]
1668+ C67_LDHU_SP_A0(r); // LDHU r, SP[A0]
16691669 else
1670− C67_LDH_SP_A0(S, r); // LDH r, SP[A0]
1670+ C67_LDH_SP_A0(r); // LDH r, SP[A0]
16711671 } else if (size == 4) {
1672− C67_LDW_SP_A0(S, r); // LDW r, SP[A0]
1672+ C67_LDW_SP_A0(r); // LDW r, SP[A0]
16731673 } else if (size == 8) {
1674− C67_LDDW_SP_A0(S, r); // LDDW r, SP[A0]
1674+ C67_LDDW_SP_A0(r); // LDDW r, SP[A0]
16751675 }
16761676
16771677
1678− C67_NOP(S, 4); // NOP 4
1678+ C67_NOP(4); // NOP 4
16791679 return;
16801680 }
16811681 } else {
16821682 if (v == VT_CONST) {
16831683 if (fr & VT_SYM) {
1684− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1685− greloc(S, cur_text_section, sv->sym, S->tccgen_ind + 4, R_C60HI16);
1684+ greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched
1685+ greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16);
16861686 }
1687− C67_MVKL(S, r, fc); //r=reg to load, constant
1688− C67_MVKH(S, r, fc); //r=reg to load, constant
1687+ C67_MVKL(r, fc); //r=reg to load, constant
1688+ C67_MVKH(r, fc); //r=reg to load, constant
16891689 } else if (v == VT_LOCAL) {
1690− C67_MVKL(S, r, fc + 8); //r=reg to load, constant C67 stack points to next free
1691− C67_MVKH(S, r, fc + 8); //r=reg to load, constant
1692− C67_ADD(S, C67_FP, r); // MV v,r v -> r
1690+ C67_MVKL(r, fc + 8); //r=reg to load, constant C67 stack points to next free
1691+ C67_MVKH(r, fc + 8); //r=reg to load, constant
1692+ C67_ADD(C67_FP, r); // MV v,r v -> r
16931693 } else if (v == VT_CMP) {
1694− C67_MV(S, C67_compare_reg, r); // MV v,r v -> r
1694+ C67_MV(C67_compare_reg, r); // MV v,r v -> r
16951695 } else if (v == VT_JMP || v == VT_JMPI) {
16961696 t = v & 1;
1697− C67_B_DISP(S, 4); // Branch with constant displacement, skip over this branch, load, nop, load
1698− C67_MVKL(S, r, t); // r=reg to load, 0 or 1 (do this while branching)
1699− C67_NOP(S, 4); // NOP 4
1700− gsym(S, fc); // modifies other branches to branch here
1701− C67_MVKL(S, r, t ^ 1); // r=reg to load, 0 or 1
1697+ C67_B_DISP(4); // Branch with constant displacement, skip over this branch, load, nop, load
1698+ C67_MVKL(r, t); // r=reg to load, 0 or 1 (do this while branching)
1699+ C67_NOP(4); // NOP 4
1700+ gsym(fc); // modifies other branches to branch here
1701+ C67_MVKL(r, t ^ 1); // r=reg to load, 0 or 1
17021702 } else if (v != r) {
1703− C67_MV(S, v, r); // MV v,r v -> r
1703+ C67_MV(v, r); // MV v,r v -> r
17041704
17051705 if ((ft & VT_BTYPE) == VT_DOUBLE)
1706− C67_MV(S, v + 1, r + 1); // MV v,r v -> r
1706+ C67_MV(v + 1, r + 1); // MV v,r v -> r
17071707 }
17081708 }
17091709 }
17101710
17111711
17121712 /* store register 'r' in lvalue 'v' */
1713−void store(TCCState* S, int r, SValue * v)
1713+void store(int r, SValue * v)
17141714 {
17151715 int fr, bt, ft, fc, size, t, element;
17161716
@@ -1721,7 +1721,7 @@ void store(TCCState* S, int r, SValue * v) · 4 unmodified lines
17211721 /* XXX: incorrect if float reg to reg */
17221722
17231723 if (bt == VT_LDOUBLE) {
1724− tcc_error(S, "long double not supported");
1724+ tcc_error("long double not supported");
17251725 } else {
17261726 if (bt == VT_SHORT)
17271727 size = 2;
@@ -1736,21 +1736,21 @@ void store(TCCState* S, int r, SValue * v) · 8 unmodified lines
17361736 /* constant memory reference */
17371737
17381738 if (v->r & VT_SYM) {
1739− greloc(S, cur_text_section, v->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1740− greloc(S, cur_text_section, v->sym, S->tccgen_ind + 4, R_C60HI16);
1739+ greloc(cur_text_section, v->sym, ind, R_C60LO16); // rem the inst need to be patched
1740+ greloc(cur_text_section, v->sym, ind + 4, R_C60HI16);
17411741 }
1742− C67_MVKL(S, C67_A0, fc); //r=reg to load, constant
1743− C67_MVKH(S, C67_A0, fc); //r=reg to load, constant
1742+ C67_MVKL(C67_A0, fc); //r=reg to load, constant
1743+ C67_MVKH(C67_A0, fc); //r=reg to load, constant
17441744
17451745 if (size == 1)
1746− C67_STB_PTR(S, r, C67_A0); // STB r, *A0
1746+ C67_STB_PTR(r, C67_A0); // STB r, *A0
17471747 else if (size == 2)
1748− C67_STH_PTR(S, r, C67_A0); // STH r, *A0
1748+ C67_STH_PTR(r, C67_A0); // STH r, *A0
17491749 else if (size == 4 || size == 8)
1750− C67_STW_PTR(S, r, C67_A0); // STW r, *A0
1750+ C67_STW_PTR(r, C67_A0); // STW r, *A0
17511751
17521752 if (size == 8)
1753− C67_STW_PTR_PRE_INC(S, r + 1, C67_A0, 1); // STW r, *+A0[1]
1753+ C67_STW_PTR_PRE_INC(r + 1, C67_A0, 1); // STW r, *+A0[1]
17541754 } else if ((v->r & VT_VALMASK) == VT_LOCAL) {
17551755 // check case of storing to passed argument that
17561756 // tcc thinks is on the stack but for C67 is
@@ -1781,68 +1781,68 @@ void store(TCCState* S, int r, SValue * v) · 24 unmodified lines
17811781 element = size;
17821782
17831783 // divide offset in bytes to create word index
1784− C67_MVKL(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1785− C67_MVKH(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1784+ C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
1785+ C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
17861786
17871787
17881788
17891789 if (size == 1)
1790− C67_STB_SP_A0(S, r); // STB r, SP[A0]
1790+ C67_STB_SP_A0(r); // STB r, SP[A0]
17911791 else if (size == 2)
1792− C67_STH_SP_A0(S, r); // STH r, SP[A0]
1792+ C67_STH_SP_A0(r); // STH r, SP[A0]
17931793 else if (size == 4 || size == 8)
1794− C67_STW_SP_A0(S, r); // STW r, SP[A0]
1794+ C67_STW_SP_A0(r); // STW r, SP[A0]
17951795
17961796 if (size == 8) {
1797− C67_ADDK(S, 1, C67_A0); // ADDK 1,A0
1798− C67_STW_SP_A0(S, r + 1); // STW r, SP[A0]
1797+ C67_ADDK(1, C67_A0); // ADDK 1,A0
1798+ C67_STW_SP_A0(r + 1); // STW r, SP[A0]
17991799 }
18001800 } else {
18011801 if (size == 1)
1802− C67_STB_PTR(S, r, fr); // STB r, *fr
1802+ C67_STB_PTR(r, fr); // STB r, *fr
18031803 else if (size == 2)
1804− C67_STH_PTR(S, r, fr); // STH r, *fr
1804+ C67_STH_PTR(r, fr); // STH r, *fr
18051805 else if (size == 4 || size == 8)
1806− C67_STW_PTR(S, r, fr); // STW r, *fr
1806+ C67_STW_PTR(r, fr); // STW r, *fr
18071807
18081808 if (size == 8) {
1809− C67_STW_PTR_PRE_INC(S, r + 1, fr, 1); // STW r, *+fr[1]
1809+ C67_STW_PTR_PRE_INC(r + 1, fr, 1); // STW r, *+fr[1]
18101810 }
18111811 }
18121812 }
18131813 }
18141814
18151815 /* 'is_jmp' is '1' if it is a jump */
1816−static void gcall_or_jmp(TCCState* S, int is_jmp)
1816+static void gcall_or_jmp(int is_jmp)
18171817 {
18181818 int r;
18191819 Sym *sym;
18201820
1821− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
1821+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
18221822 /* constant case */
1823− if (S->tccgen_vtop->r & VT_SYM) {
1823+ if (vtop->r & VT_SYM) {
18241824 /* relocation case */
18251825
18261826 // get add into A0, then start the jump B3
18271827
1828− greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1829− greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 4, R_C60HI16);
1828+ greloc(cur_text_section, vtop->sym, ind, R_C60LO16); // rem the inst need to be patched
1829+ greloc(cur_text_section, vtop->sym, ind + 4, R_C60HI16);
18301830
1831− C67_MVKL(S, C67_A0, 0); //r=reg to load, constant
1832− C67_MVKH(S, C67_A0, 0); //r=reg to load, constant
1833− C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_A0); // B.S2x A0
1831+ C67_MVKL(C67_A0, 0); //r=reg to load, constant
1832+ C67_MVKH(C67_A0, 0); //r=reg to load, constant
1833+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // B.S2x A0
18341834
18351835 if (is_jmp) {
1836− C67_NOP(S, 5); // simple jump, just put NOP
1836+ C67_NOP(5); // simple jump, just put NOP
18371837 } else {
18381838 // Call, must load return address into B3 during delay slots
18391839
1840− sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, S->tccgen_ind + 12, 0); // symbol for return address
1841− greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1842− greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
1843− C67_MVKL(S, C67_B3, 0); //r=reg to load, constant
1844− C67_MVKH(S, C67_B3, 0); //r=reg to load, constant
1845− C67_NOP(S, 3); // put remaining NOPs
1840+ sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address
1841+ greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched
1842+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
1843+ C67_MVKL(C67_B3, 0); //r=reg to load, constant
1844+ C67_MVKH(C67_B3, 0); //r=reg to load, constant
1845+ C67_NOP(3); // put remaining NOPs
18461846 }
18471847 } else {
18481848 /* put an empty PC32 relocation */
@@ -1850,20 +1850,20 @@ static void gcall_or_jmp(TCCState* S, int is_jmp) · 1 unmodified line
18501850 }
18511851 } else {
18521852 /* otherwise, indirect call */
1853− r = gv(S, RC_INT);
1854− C67_IREG_B_REG(S, 0, C67_CREG_ZERO, r); // B.S2x r
1853+ r = gv(RC_INT);
1854+ C67_IREG_B_REG(0, C67_CREG_ZERO, r); // B.S2x r
18551855
18561856 if (is_jmp) {
1857− C67_NOP(S, 5); // simple jump, just put NOP
1857+ C67_NOP(5); // simple jump, just put NOP
18581858 } else {
18591859 // Call, must load return address into B3 during delay slots
18601860
1861− sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, S->tccgen_ind + 12, 0); // symbol for return address
1862− greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
1863− greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
1864− C67_MVKL(S, C67_B3, 0); //r=reg to load, constant
1865− C67_MVKH(S, C67_B3, 0); //r=reg to load, constant
1866− C67_NOP(S, 3); // put remaining NOPs
1861+ sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address
1862+ greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched
1863+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
1864+ C67_MVKL(C67_B3, 0); //r=reg to load, constant
1865+ C67_MVKH(C67_B3, 0); //r=reg to load, constant
1866+ C67_NOP(3); // put remaining NOPs
18671867 }
18681868 }
18691869 }
@@ -1877,29 +1877,29 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int · 7 unmodified lines
18771877
18781878 /* generate function call with address in (vtop->t, vtop->c) and free function
18791879 context. Stack entry is popped */
1880−void gfunc_call(TCCState* S, int nb_args)
1880+void gfunc_call(int nb_args)
18811881 {
18821882 int i, r, size = 0;
18831883 int args_sizes[NoCallArgsPassedOnStack];
18841884
18851885 if (nb_args > NoCallArgsPassedOnStack) {
1886− tcc_error(S, "more than 10 function params not currently supported");
1886+ tcc_error("more than 10 function params not currently supported");
18871887 // handle more than 10, put some on the stack
18881888 }
18891889
18901890 for (i = 0; i < nb_args; i++) {
1891− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
1891+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
18921892 ALWAYS_ASSERT(FALSE);
18931893 } else {
18941894 /* simple type (currently always same size) */
18951895 /* XXX: implicit cast ? */
18961896
18971897
1898− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
1899− tcc_error(S, "long long not supported");
1900− } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
1901− tcc_error(S, "long double not supported");
1902− } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
1898+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
1899+ tcc_error("long long not supported");
1900+ } else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
1901+ tcc_error("long double not supported");
1902+ } else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
19031903 size = 8;
19041904 } else {
19051905 size = 4;
@@ -1907,19 +1907,19 @@ void gfunc_call(TCCState* S, int nb_args) · 1 unmodified line
19071907
19081908 // put the parameter into the corresponding reg (pair)
19091909
1910− r = gv(S, RC_C67_A4 << (2 * i));
1910+ r = gv(RC_C67_A4 << (2 * i));
19111911
19121912 // must put on stack because with 1 pass compiler , no way to tell
19131913 // if an up coming nested call might overwrite these regs
19141914
1915− C67_PUSH(S, r);
1915+ C67_PUSH(r);
19161916
19171917 if (size == 8) {
1918− C67_STW_PTR_PRE_INC(S, r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other)
1918+ C67_STW_PTR_PRE_INC(r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other)
19191919 }
19201920 args_sizes[i] = size;
19211921 }
1922− S->tccgen_vtop--;
1922+ vtop--;
19231923 }
19241924 // POP all the params on the stack into registers for the
19251925 // immediate call (in reverse order)
@@ -1927,12 +1927,12 @@ void gfunc_call(TCCState* S, int nb_args) · 1 unmodified line
19271927 for (i = nb_args - 1; i >= 0; i--) {
19281928
19291929 if (args_sizes[i] == 8)
1930− C67_POP_DW(S, TREG_C67_A4 + i * 2);
1930+ C67_POP_DW(TREG_C67_A4 + i * 2);
19311931 else
1932− C67_POP(S, TREG_C67_A4 + i * 2);
1932+ C67_POP(TREG_C67_A4 + i * 2);
19331933 }
1934− gcall_or_jmp(S, 0);
1935− S->tccgen_vtop--;
1934+ gcall_or_jmp(0);
1935+ vtop--;
19361936 }
19371937
19381938
@@ -1946,7 +1946,7 @@ void gfunc_call(TCCState* S, int nb_args) · 7 unmodified lines
19461946 // parameters are loaded and restored upon return (or if/when needed).
19471947
19481948 /* generate function prolog of type 't' */
1949−void gfunc_prolog(TCCState* S, Sym *func_sym)
1949+void gfunc_prolog(Sym *func_sym)
19501950 {
19511951 CType *func_type = &func_sym->type;
19521952 int addr, align, size, func_call, i;
@@ -1958,8 +1958,8 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 5 unmodified lines
19581958 addr = 8;
19591959 /* if the function returns a structure, then add an
19601960 implicit pointer parameter */
1961− if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT) {
1962− S->tccgen_func_vc = addr;
1961+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
1962+ func_vc = addr;
19631963 addr += 4;
19641964 }
19651965
@@ -1968,7 +1968,7 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 2 unmodified lines
19681968 /* define parameters */
19691969 while ((sym = sym->next) != NULL) {
19701970 type = &sym->type;
1971− sym_push(S, sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr);
1971+ sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr);
19721972 size = type_size(type, &align);
19731973 size = (size + 3) & ~3;
19741974
@@ -1992,76 +1992,76 @@ void gfunc_prolog(TCCState* S, Sym *func_sym) · 17 unmodified lines
19921992 if (func_call == FUNC_STDCALL)
19931993 func_ret_sub = addr - 8;
19941994
1995− C67_MV(S, C67_FP, C67_A0); // move FP -> A0
1996− C67_MV(S, C67_SP, C67_FP); // move SP -> FP
1995+ C67_MV(C67_FP, C67_A0); // move FP -> A0
1996+ C67_MV(C67_SP, C67_FP); // move SP -> FP
19971997
19981998 // place all the args passed in regs onto the stack
19991999
2000− S->tccgen_loc = 0;
2000+ loc = 0;
20012001 for (i = 0; i < NoOfCurFuncArgs; i++) {
20022002
2003− ParamLocOnStack[i] = S->tccgen_loc; // remember where the param is
2004− S->tccgen_loc += -8;
2003+ ParamLocOnStack[i] = loc; // remember where the param is
2004+ loc += -8;
20052005
2006− C67_PUSH(S, TREG_C67_A4 + i * 2);
2006+ C67_PUSH(TREG_C67_A4 + i * 2);
20072007
20082008 if (TranslateStackToReg[i] == 8) {
2009− C67_STW_PTR_PRE_INC(S, TREG_C67_A4 + i * 2 + 1, C67_SP, 3); // STW r, *+SP[1] (go back and put the other)
2009+ C67_STW_PTR_PRE_INC(TREG_C67_A4 + i * 2 + 1, C67_SP, 3); // STW r, *+SP[1] (go back and put the other)
20102010 }
20112011 }
20122012
2013− TotalBytesPushedOnStack = -S->tccgen_loc;
2013+ TotalBytesPushedOnStack = -loc;
20142014
2015− func_sub_sp_offset = S->tccgen_ind; // remember where we put the stack instruction
2016− C67_ADDK(S, 0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily)
2015+ func_sub_sp_offset = ind; // remember where we put the stack instruction
2016+ C67_ADDK(0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily)
20172017
2018− C67_PUSH(S, C67_A0);
2019− C67_PUSH(S, C67_B3);
2018+ C67_PUSH(C67_A0);
2019+ C67_PUSH(C67_B3);
20202020 }
20212021
20222022 /* generate function epilog */
2023−void gfunc_epilog(TCCState* S)
2023+void gfunc_epilog(void)
20242024 {
20252025 {
2026− int local = (-S->tccgen_loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr
2027− C67_POP(S, C67_B3);
2028− C67_NOP(S, 4); // NOP wait for load
2029− C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_B3); // B.S2 B3
2030− C67_POP(S, C67_FP);
2031− C67_ADDK(S, local, C67_SP); // ADDK.L2 loc,SP
2032− C67_Adjust_ADDK(S, (int *) (cur_text_section->data +
2026+ int local = (-loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr
2027+ C67_POP(C67_B3);
2028+ C67_NOP(4); // NOP wait for load
2029+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_B3); // B.S2 B3
2030+ C67_POP(C67_FP);
2031+ C67_ADDK(local, C67_SP); // ADDK.L2 loc,SP
2032+ C67_Adjust_ADDK((int *) (cur_text_section->data +
20332033 func_sub_sp_offset),
20342034 -local + TotalBytesPushedOnStack);
2035− C67_NOP(S, 3); // NOP
2035+ C67_NOP(3); // NOP
20362036 }
20372037 }
20382038
2039−ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
2039+ST_FUNC void gen_fill_nops(int bytes)
20402040 {
20412041 if ((bytes & 3))
2042− tcc_error(S, "alignment of code section not multiple of 4");
2042+ tcc_error("alignment of code section not multiple of 4");
20432043 while (bytes > 0) {
2044− C67_NOP(S, 4);
2044+ C67_NOP(4);
20452045 bytes -= 4;
20462046 }
20472047 }
20482048
20492049 /* generate a jump to a label */
2050−int gjmp(TCCState* S, int t)
2050+int gjmp(int t)
20512051 {
2052− int ind1 = S->tccgen_ind;
2053− if (S->tccgen_nocode_wanted)
2052+ int ind1 = ind;
2053+ if (nocode_wanted)
20542054 return t;
20552055
2056− C67_MVKL(S, C67_A0, t); //r=reg to load, constant
2057− C67_MVKH(S, C67_A0, t); //r=reg to load, constant
2058− C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0
2059− C67_NOP(S, 5);
2056+ C67_MVKL(C67_A0, t); //r=reg to load, constant
2057+ C67_MVKH(C67_A0, t); //r=reg to load, constant
2058+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0
2059+ C67_NOP(5);
20602060 return ind1;
20612061 }
20622062
20632063 /* generate a jump to a fixed address */
2064−void gjmp_addr(TCCState* S, int a)
2064+void gjmp_addr(int a)
20652065 {
20662066 Sym *sym;
20672067 // I guess this routine is used for relative short
@@ -2070,42 +2070,42 @@ void gjmp_addr(TCCState* S, int a) · 2 unmodified lines
20702070
20712071 // define a label that will be relocated
20722072
2073− sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, a, 0);
2074− greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16);
2075− greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
2073+ sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
2074+ greloc(cur_text_section, sym, ind, R_C60LO16);
2075+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
20762076
2077− gjmp(S, 0); // place a zero there later the symbol will be added to it
2077+ gjmp(0); // place a zero there later the symbol will be added to it
20782078 }
20792079
20802080 /* generate a test. set 'inv' to invert test. Stack entry is popped */
2081−ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
2081+ST_FUNC int gjmp_cond(int op, int t)
20822082 {
20832083 int ind1;
20842084 int inv = op & 1;
2085− if (S->tccgen_nocode_wanted)
2085+ if (nocode_wanted)
20862086 return t;
20872087
20882088 /* fast case : can jump directly since flags are set */
20892089 // C67 uses B2 sort of as flags register
2090− ind1 = S->tccgen_ind;
2091− C67_MVKL(S, C67_A0, t); //r=reg to load, constant
2092− C67_MVKH(S, C67_A0, t); //r=reg to load, constant
2090+ ind1 = ind;
2091+ C67_MVKL(C67_A0, t); //r=reg to load, constant
2092+ C67_MVKH(C67_A0, t); //r=reg to load, constant
20932093
20942094 if (C67_compare_reg != TREG_EAX && // check if not already in a conditional test reg
20952095 C67_compare_reg != TREG_EDX &&
20962096 C67_compare_reg != TREG_ST0 && C67_compare_reg != C67_B2) {
2097− C67_MV(S, C67_compare_reg, C67_B2);
2097+ C67_MV(C67_compare_reg, C67_B2);
20982098 C67_compare_reg = C67_B2;
20992099 }
21002100
2101− C67_IREG_B_REG(S, C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0
2102− C67_NOP(S, 5);
2101+ C67_IREG_B_REG(C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0
2102+ C67_NOP(5);
21032103 t = ind1; //return where we need to patch
21042104
21052105 return t;
21062106 }
21072107
2108−ST_FUNC int gjmp_append(TCCState* S, int n0, int t)
2108+ST_FUNC int gjmp_append(int n0, int t)
21092109 {
21102110 if (n0) {
21112111 int n = n0, *p;
@@ -2129,7 +2129,7 @@ ST_FUNC int gjmp_append(TCCState* S, int n0, int t) · 17 unmodified lines
21292129 }
21302130
21312131 /* generate an integer binary operation */
2132−void gen_opi(TCCState* S, int op)
2132+void gen_opi(int op)
21332133 {
21342134 int r, fr, opc, t;
21352135
@@ -2146,62 +2146,62 @@ void gen_opi(TCCState* S, int op) · 10 unmodified lines
21462146
21472147
21482148 if (op >= TOK_ULT && op <= TOK_GT)
2149− gv2(S, RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU
2149+ gv2(RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU
21502150 else
2151− gv2(S, RC_INT, RC_INT);
2151+ gv2(RC_INT, RC_INT);
21522152
2153− r = S->tccgen_vtop[-1].r;
2154− fr = S->tccgen_vtop[0].r;
2153+ r = vtop[-1].r;
2154+ fr = vtop[0].r;
21552155
21562156 C67_compare_reg = C67_B2;
21572157
21582158
21592159 if (op == TOK_LT) {
2160− C67_CMPLT(S, r, fr, C67_B2);
2160+ C67_CMPLT(r, fr, C67_B2);
21612161 C67_invert_test = FALSE;
21622162 } else if (op == TOK_GE) {
2163− C67_CMPLT(S, r, fr, C67_B2);
2163+ C67_CMPLT(r, fr, C67_B2);
21642164 C67_invert_test = TRUE;
21652165 } else if (op == TOK_GT) {
2166− C67_CMPGT(S, r, fr, C67_B2);
2166+ C67_CMPGT(r, fr, C67_B2);
21672167 C67_invert_test = FALSE;
21682168 } else if (op == TOK_LE) {
2169− C67_CMPGT(S, r, fr, C67_B2);
2169+ C67_CMPGT(r, fr, C67_B2);
21702170 C67_invert_test = TRUE;
21712171 } else if (op == TOK_EQ) {
2172− C67_CMPEQ(S, r, fr, C67_B2);
2172+ C67_CMPEQ(r, fr, C67_B2);
21732173 C67_invert_test = FALSE;
21742174 } else if (op == TOK_NE) {
2175− C67_CMPEQ(S, r, fr, C67_B2);
2175+ C67_CMPEQ(r, fr, C67_B2);
21762176 C67_invert_test = TRUE;
21772177 } else if (op == TOK_ULT) {
2178− C67_CMPLTU(S, r, fr, C67_B2);
2178+ C67_CMPLTU(r, fr, C67_B2);
21792179 C67_invert_test = FALSE;
21802180 } else if (op == TOK_UGE) {
2181− C67_CMPLTU(S, r, fr, C67_B2);
2181+ C67_CMPLTU(r, fr, C67_B2);
21822182 C67_invert_test = TRUE;
21832183 } else if (op == TOK_UGT) {
2184− C67_CMPGTU(S, r, fr, C67_B2);
2184+ C67_CMPGTU(r, fr, C67_B2);
21852185 C67_invert_test = FALSE;
21862186 } else if (op == TOK_ULE) {
2187− C67_CMPGTU(S, r, fr, C67_B2);
2187+ C67_CMPGTU(r, fr, C67_B2);
21882188 C67_invert_test = TRUE;
21892189 } else if (op == '+')
2190− C67_ADD(S, fr, r); // ADD r,fr,r
2190+ C67_ADD(fr, r); // ADD r,fr,r
21912191 else if (op == '-')
2192− C67_SUB(S, fr, r); // SUB r,fr,r
2192+ C67_SUB(fr, r); // SUB r,fr,r
21932193 else if (op == '&')
2194− C67_AND(S, fr, r); // AND r,fr,r
2194+ C67_AND(fr, r); // AND r,fr,r
21952195 else if (op == '|')
2196− C67_OR(S, fr, r); // OR r,fr,r
2196+ C67_OR(fr, r); // OR r,fr,r
21972197 else if (op == '^')
2198− C67_XOR(S, fr, r); // XOR r,fr,r
2198+ C67_XOR(fr, r); // XOR r,fr,r
21992199 else
22002200 ALWAYS_ASSERT(FALSE);
22012201
2202− S->tccgen_vtop--;
2202+ vtop--;
22032203 if (op >= TOK_ULT && op <= TOK_GT)
2204− vset_VT_CMP(S, 0x80);
2204+ vset_VT_CMP(0x80);
22052205 break;
22062206 case '-':
22072207 case TOK_SUBC1: /* sub with carry generation */
@@ -2224,48 +2224,48 @@ void gen_opi(TCCState* S, int op) · 16 unmodified lines
22242224 goto gen_op8;
22252225 case '*':
22262226 case TOK_UMULL:
2227− gv2(S, RC_INT, RC_INT);
2228− r = S->tccgen_vtop[-1].r;
2229− fr = S->tccgen_vtop[0].r;
2230− S->tccgen_vtop--;
2231− C67_MPYI(S, fr, r); // 32 bit multiply fr,r,fr
2232− C67_NOP(S, 8); // NOP 8 for worst case
2227+ gv2(RC_INT, RC_INT);
2228+ r = vtop[-1].r;
2229+ fr = vtop[0].r;
2230+ vtop--;
2231+ C67_MPYI(fr, r); // 32 bit multiply fr,r,fr
2232+ C67_NOP(8); // NOP 8 for worst case
22332233 break;
22342234 case TOK_SHL:
2235− gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2236− r = S->tccgen_vtop[-1].r;
2237− fr = S->tccgen_vtop[0].r;
2238− S->tccgen_vtop--;
2239− C67_SHL(S, fr, r); // arithmetic/logical shift
2235+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2236+ r = vtop[-1].r;
2237+ fr = vtop[0].r;
2238+ vtop--;
2239+ C67_SHL(fr, r); // arithmetic/logical shift
22402240 break;
22412241
22422242 case TOK_SHR:
2243− gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2244− r = S->tccgen_vtop[-1].r;
2245− fr = S->tccgen_vtop[0].r;
2246− S->tccgen_vtop--;
2247− C67_SHRU(S, fr, r); // logical shift
2243+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2244+ r = vtop[-1].r;
2245+ fr = vtop[0].r;
2246+ vtop--;
2247+ C67_SHRU(fr, r); // logical shift
22482248 break;
22492249
22502250 case TOK_SAR:
2251− gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2252− r = S->tccgen_vtop[-1].r;
2253− fr = S->tccgen_vtop[0].r;
2254− S->tccgen_vtop--;
2255− C67_SHR(S, fr, r); // arithmetic shift
2251+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
2252+ r = vtop[-1].r;
2253+ fr = vtop[0].r;
2254+ vtop--;
2255+ C67_SHR(fr, r); // arithmetic shift
22562256 break;
22572257
22582258 case '/':
22592259 t = TOK__divi;
22602260 call_func:
2261− vswap(S);
2261+ vswap();
22622262 /* call generic idiv function */
2263− vpush_helper_func(S, t);
2264− vrott(S, 3);
2265− gfunc_call(S, 2);
2266− vpushi(S, 0);
2267− S->tccgen_vtop->r = REG_IRET;
2268− S->tccgen_vtop->r2 = VT_CONST;
2263+ vpush_helper_func(t);
2264+ vrott(3);
2265+ gfunc_call(2);
2266+ vpushi(0);
2267+ vtop->r = REG_IRET;
2268+ vtop->r2 = VT_CONST;
22692269 break;
22702270 case TOK_UDIV:
22712271 case TOK_PDIV:
@@ -2287,127 +2287,127 @@ void gen_opi(TCCState* S, int op) · 15 unmodified lines
22872287 /* generate a floating point operation 'v = t1 op t2' instruction. The
22882288 two operands are guaranteed to have the same floating point type */
22892289 /* XXX: need to use ST1 too */
2290−void gen_opf(TCCState* S, int op)
2290+void gen_opf(int op)
22912291 {
22922292 int ft, fc, fr, r;
22932293
22942294 if (op >= TOK_ULT && op <= TOK_GT)
2295− gv2(S, RC_EDX, RC_EAX); // make sure src2 is on b side
2295+ gv2(RC_EDX, RC_EAX); // make sure src2 is on b side
22962296 else
2297− gv2(S, RC_FLOAT, RC_FLOAT); // make sure src2 is on b side
2297+ gv2(RC_FLOAT, RC_FLOAT); // make sure src2 is on b side
22982298
2299− ft = S->tccgen_vtop->type.t;
2300− fc = S->tccgen_vtop->c.i;
2301− r = S->tccgen_vtop->r;
2302− fr = S->tccgen_vtop[-1].r;
2299+ ft = vtop->type.t;
2300+ fc = vtop->c.i;
2301+ r = vtop->r;
2302+ fr = vtop[-1].r;
23032303
23042304
23052305 if ((ft & VT_BTYPE) == VT_LDOUBLE)
2306− tcc_error(S, "long doubles not supported");
2306+ tcc_error("long doubles not supported");
23072307
23082308 if (op >= TOK_ULT && op <= TOK_GT) {
23092309
2310− r = S->tccgen_vtop[-1].r;
2311− fr = S->tccgen_vtop[0].r;
2310+ r = vtop[-1].r;
2311+ fr = vtop[0].r;
23122312
23132313 C67_compare_reg = C67_B2;
23142314
23152315 if (op == TOK_LT) {
23162316 if ((ft & VT_BTYPE) == VT_DOUBLE)
2317− C67_CMPLTDP(S, r, fr, C67_B2);
2317+ C67_CMPLTDP(r, fr, C67_B2);
23182318 else
2319− C67_CMPLTSP(S, r, fr, C67_B2);
2319+ C67_CMPLTSP(r, fr, C67_B2);
23202320
23212321 C67_invert_test = FALSE;
23222322 } else if (op == TOK_GE) {
23232323 if ((ft & VT_BTYPE) == VT_DOUBLE)
2324− C67_CMPLTDP(S, r, fr, C67_B2);
2324+ C67_CMPLTDP(r, fr, C67_B2);
23252325 else
2326− C67_CMPLTSP(S, r, fr, C67_B2);
2326+ C67_CMPLTSP(r, fr, C67_B2);
23272327
23282328 C67_invert_test = TRUE;
23292329 } else if (op == TOK_GT) {
23302330 if ((ft & VT_BTYPE) == VT_DOUBLE)
2331− C67_CMPGTDP(S, r, fr, C67_B2);
2331+ C67_CMPGTDP(r, fr, C67_B2);
23322332 else
2333− C67_CMPGTSP(S, r, fr, C67_B2);
2333+ C67_CMPGTSP(r, fr, C67_B2);
23342334
23352335 C67_invert_test = FALSE;
23362336 } else if (op == TOK_LE) {
23372337 if ((ft & VT_BTYPE) == VT_DOUBLE)
2338− C67_CMPGTDP(S, r, fr, C67_B2);
2338+ C67_CMPGTDP(r, fr, C67_B2);
23392339 else
2340− C67_CMPGTSP(S, r, fr, C67_B2);
2340+ C67_CMPGTSP(r, fr, C67_B2);
23412341
23422342 C67_invert_test = TRUE;
23432343 } else if (op == TOK_EQ) {
23442344 if ((ft & VT_BTYPE) == VT_DOUBLE)
2345− C67_CMPEQDP(S, r, fr, C67_B2);
2345+ C67_CMPEQDP(r, fr, C67_B2);
23462346 else
2347− C67_CMPEQSP(S, r, fr, C67_B2);
2347+ C67_CMPEQSP(r, fr, C67_B2);
23482348
23492349 C67_invert_test = FALSE;
23502350 } else if (op == TOK_NE) {
23512351 if ((ft & VT_BTYPE) == VT_DOUBLE)
2352− C67_CMPEQDP(S, r, fr, C67_B2);
2352+ C67_CMPEQDP(r, fr, C67_B2);
23532353 else
2354− C67_CMPEQSP(S, r, fr, C67_B2);
2354+ C67_CMPEQSP(r, fr, C67_B2);
23552355
23562356 C67_invert_test = TRUE;
23572357 } else {
23582358 ALWAYS_ASSERT(FALSE);
23592359 }
2360− vset_VT_CMP(S, 0x80);
2360+ vset_VT_CMP(0x80);
23612361 } else {
23622362 if (op == '+') {
23632363 if ((ft & VT_BTYPE) == VT_DOUBLE) {
2364− C67_ADDDP(S, r, fr); // ADD fr,r,fr
2365− C67_NOP(S, 6);
2364+ C67_ADDDP(r, fr); // ADD fr,r,fr
2365+ C67_NOP(6);
23662366 } else {
2367− C67_ADDSP(S, r, fr); // ADD fr,r,fr
2368− C67_NOP(S, 3);
2367+ C67_ADDSP(r, fr); // ADD fr,r,fr
2368+ C67_NOP(3);
23692369 }
2370− S->tccgen_vtop--;
2370+ vtop--;
23712371 } else if (op == '-') {
23722372 if ((ft & VT_BTYPE) == VT_DOUBLE) {
2373− C67_SUBDP(S, r, fr); // SUB fr,r,fr
2374− C67_NOP(S, 6);
2373+ C67_SUBDP(r, fr); // SUB fr,r,fr
2374+ C67_NOP(6);
23752375 } else {
2376− C67_SUBSP(S, r, fr); // SUB fr,r,fr
2377− C67_NOP(S, 3);
2376+ C67_SUBSP(r, fr); // SUB fr,r,fr
2377+ C67_NOP(3);
23782378 }
2379− S->tccgen_vtop--;
2379+ vtop--;
23802380 } else if (op == '*') {
23812381 if ((ft & VT_BTYPE) == VT_DOUBLE) {
2382− C67_MPYDP(S, r, fr); // MPY fr,r,fr
2383− C67_NOP(S, 9);
2382+ C67_MPYDP(r, fr); // MPY fr,r,fr
2383+ C67_NOP(9);
23842384 } else {
2385− C67_MPYSP(S, r, fr); // MPY fr,r,fr
2386− C67_NOP(S, 3);
2385+ C67_MPYSP(r, fr); // MPY fr,r,fr
2386+ C67_NOP(3);
23872387 }
2388− S->tccgen_vtop--;
2388+ vtop--;
23892389 } else if (op == '/') {
23902390 if ((ft & VT_BTYPE) == VT_DOUBLE) {
23912391 // must call intrinsic DP floating point divide
2392− vswap(S);
2392+ vswap();
23932393 /* call generic idiv function */
2394− vpush_helper_func(S, TOK__divd);
2395− vrott(S, 3);
2396− gfunc_call(S, 2);
2397− vpushi(S, 0);
2398− S->tccgen_vtop->r = REG_FRET;
2399− S->tccgen_vtop->r2 = REG_IRE2;
2394+ vpush_helper_func(TOK__divd);
2395+ vrott(3);
2396+ gfunc_call(2);
2397+ vpushi(0);
2398+ vtop->r = REG_FRET;
2399+ vtop->r2 = REG_IRE2;
24002400
24012401 } else {
24022402 // must call intrinsic SP floating point divide
2403− vswap(S);
2403+ vswap();
24042404 /* call generic idiv function */
2405− vpush_helper_func(S, TOK__divf);
2406− vrott(S, 3);
2407− gfunc_call(S, 2);
2408− vpushi(S, 0);
2409− S->tccgen_vtop->r = REG_FRET;
2410− S->tccgen_vtop->r2 = VT_CONST;
2405+ vpush_helper_func(TOK__divf);
2406+ vrott(3);
2407+ gfunc_call(2);
2408+ vpushi(0);
2409+ vtop->r = REG_FRET;
2410+ vtop->r2 = VT_CONST;
24112411 }
24122412 } else
24132413 ALWAYS_ASSERT(FALSE);
@@ -2419,122 +2419,122 @@ void gen_opf(TCCState* S, int op) · 5 unmodified lines
24192419
24202420 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
24212421 and 'long long' cases. */
2422−void gen_cvt_itof(TCCState* S, int t)
2422+void gen_cvt_itof(int t)
24232423 {
24242424 int r;
24252425
2426− gv(S, RC_INT);
2427− r = S->tccgen_vtop->r;
2426+ gv(RC_INT);
2427+ r = vtop->r;
24282428
24292429 if ((t & VT_BTYPE) == VT_DOUBLE) {
24302430 if (t & VT_UNSIGNED)
2431− C67_INTDPU(S, r, r);
2431+ C67_INTDPU(r, r);
24322432 else
2433− C67_INTDP(S, r, r);
2433+ C67_INTDP(r, r);
24342434
2435− C67_NOP(S, 4);
2436− S->tccgen_vtop->type.t = VT_DOUBLE;
2435+ C67_NOP(4);
2436+ vtop->type.t = VT_DOUBLE;
24372437 } else {
24382438 if (t & VT_UNSIGNED)
2439− C67_INTSPU(S, r, r);
2439+ C67_INTSPU(r, r);
24402440 else
2441− C67_INTSP(S, r, r);
2442− C67_NOP(S, 3);
2443− S->tccgen_vtop->type.t = VT_FLOAT;
2441+ C67_INTSP(r, r);
2442+ C67_NOP(3);
2443+ vtop->type.t = VT_FLOAT;
24442444 }
24452445
24462446 }
24472447
24482448 /* convert fp to int 't' type */
24492449 /* XXX: handle long long case */
2450−void gen_cvt_ftoi(TCCState* S, int t)
2450+void gen_cvt_ftoi(int t)
24512451 {
24522452 int r;
24532453
2454− gv(S, RC_FLOAT);
2455− r = S->tccgen_vtop->r;
2454+ gv(RC_FLOAT);
2455+ r = vtop->r;
24562456
24572457 if (t != VT_INT)
2458− tcc_error(S, "long long not supported");
2458+ tcc_error("long long not supported");
24592459 else {
2460− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
2461− C67_DPTRUNC(S, r, r);
2462− C67_NOP(S, 3);
2460+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
2461+ C67_DPTRUNC(r, r);
2462+ C67_NOP(3);
24632463 } else {
2464− C67_SPTRUNC(S, r, r);
2465− C67_NOP(S, 3);
2464+ C67_SPTRUNC(r, r);
2465+ C67_NOP(3);
24662466 }
24672467
2468− S->tccgen_vtop->type.t = VT_INT;
2468+ vtop->type.t = VT_INT;
24692469
24702470 }
24712471 }
24722472
24732473 /* convert from one floating point type to another */
2474−void gen_cvt_ftof(TCCState* S, int t)
2474+void gen_cvt_ftof(int t)
24752475 {
24762476 int r, r2;
24772477
2478− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE &&
2478+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE &&
24792479 (t & VT_BTYPE) == VT_FLOAT) {
24802480 // convert double to float
24812481
2482− gv(S, RC_FLOAT); // get it in a register pair
2482+ gv(RC_FLOAT); // get it in a register pair
24832483
2484− r = S->tccgen_vtop->r;
2484+ r = vtop->r;
24852485
2486− C67_DPSP(S, r, r); // convert it to SP same register
2487− C67_NOP(S, 3);
2486+ C67_DPSP(r, r); // convert it to SP same register
2487+ C67_NOP(3);
24882488
2489− S->tccgen_vtop->type.t = VT_FLOAT;
2490− S->tccgen_vtop->r2 = VT_CONST; // set this as unused
2491− } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT &&
2489+ vtop->type.t = VT_FLOAT;
2490+ vtop->r2 = VT_CONST; // set this as unused
2491+ } else if ((vtop->type.t & VT_BTYPE) == VT_FLOAT &&
24922492 (t & VT_BTYPE) == VT_DOUBLE) {
24932493 // convert float to double
24942494
2495− gv(S, RC_FLOAT); // get it in a register
2495+ gv(RC_FLOAT); // get it in a register
24962496
2497− r = S->tccgen_vtop->r;
2497+ r = vtop->r;
24982498
24992499 if (r == TREG_EAX) { // make sure the paired reg is avail
2500− r2 = get_reg(S, RC_ECX);
2500+ r2 = get_reg(RC_ECX);
25012501 } else if (r == TREG_EDX) {
2502− r2 = get_reg(S, RC_ST0);
2502+ r2 = get_reg(RC_ST0);
25032503 } else {
25042504 ALWAYS_ASSERT(FALSE);
25052505 r2 = 0; /* avoid warning */
25062506 }
25072507
2508− C67_SPDP(S, r, r); // convert it to DP same register
2509− C67_NOP(S, 1);
2508+ C67_SPDP(r, r); // convert it to DP same register
2509+ C67_NOP(1);
25102510
2511− S->tccgen_vtop->type.t = VT_DOUBLE;
2512− S->tccgen_vtop->r2 = r2; // set this as unused
2511+ vtop->type.t = VT_DOUBLE;
2512+ vtop->r2 = r2; // set this as unused
25132513 } else {
25142514 ALWAYS_ASSERT(FALSE);
25152515 }
25162516 }
25172517
25182518 /* computed goto support */
2519−void ggoto(TCCState* S)
2519+void ggoto(void)
25202520 {
2521− gcall_or_jmp(S, 1);
2522− S->tccgen_vtop--;
2521+ gcall_or_jmp(1);
2522+ vtop--;
25232523 }
25242524
25252525 /* Save the stack pointer onto the stack and return the location of its address */
2526−ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
2527− tcc_error(S, "variable length arrays unsupported for this target");
2526+ST_FUNC void gen_vla_sp_save(int addr) {
2527+ tcc_error("variable length arrays unsupported for this target");
25282528 }
25292529
25302530 /* Restore the SP from a location on the stack */
2531−ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
2532− tcc_error(S, "variable length arrays unsupported for this target");
2531+ST_FUNC void gen_vla_sp_restore(int addr) {
2532+ tcc_error("variable length arrays unsupported for this target");
25332533 }
25342534
25352535 /* Subtract from the stack pointer, and push the resulting value onto the stack */
2536−ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
2537− tcc_error(S, "variable length arrays unsupported for this target");
2536+ST_FUNC void gen_vla_alloc(CType *type, int align) {
2537+ tcc_error("variable length arrays unsupported for this target");
25382538 }
25392539
25402540 /* end of C67 code generator */
c67-link.c+7−7
@@ -65,23 +65,23 @@ int gotplt_entry_type (int reloc_type) · 64 unmodified lines
6565 return -1;
6666 }
6767
68−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
68+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
6969 {
70− tcc_error(S, "C67 got not implemented");
70+ tcc_error("C67 got not implemented");
7171 return 0;
7272 }
7373
7474 /* relocate the PLT: compute addresses and offsets in the PLT now that final
7575 address for PLT and GOT are known (see fill_program_header) */
76−ST_FUNC void relocate_plt(TCCState *S)
76+ST_FUNC void relocate_plt(TCCState *s1)
7777 {
7878 uint8_t *p, *p_end;
7979
80− if (!S->plt)
80+ if (!s1->plt)
8181 return;
8282
83− p = S->plt->data;
84− p_end = p + S->plt->data_offset;
83+ p = s1->plt->data;
84+ p_end = p + s1->plt->data_offset;
8585
8686 if (p < p_end) {
8787 /* XXX: TODO */
@@ -91,7 +91,7 @@ ST_FUNC void relocate_plt(TCCState *S) · 3 unmodified lines
9191 }
9292 }
9393
94−void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
94+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
9595 {
9696 switch(type) {
9797 case R_C60_32:
i386-asm.c+187−187
@@ -253,10 +253,10 @@ static const uint16_t op0_codes[] = { · 252 unmodified lines
253253 #endif
254254 };
255255
256−static inline int get_reg_shift(TCCState *S)
256+static inline int get_reg_shift(TCCState *s1)
257257 {
258258 int shift, v;
259− v = asm_int_expr(S);
259+ v = asm_int_expr(s1);
260260 switch(v) {
261261 case 1:
262262 shift = 0;
@@ -271,7 +271,7 @@ static inline int get_reg_shift(TCCState *S) · 8 unmodified lines
271271 shift = 3;
272272 break;
273273 default:
274− expect(S, "1, 2, 4 or 8 constant");
274+ expect("1, 2, 4 or 8 constant");
275275 shift = 0;
276276 break;
277277 }
@@ -279,11 +279,11 @@ static inline int get_reg_shift(TCCState *S) · 1 unmodified line
279279 }
280280
281281 #ifdef TCC_TARGET_X86_64
282−static int asm_parse_numeric_reg(TCCState *S, int t, unsigned int *type)
282+static int asm_parse_numeric_reg(int t, unsigned int *type)
283283 {
284284 int reg = -1;
285− if (t >= TOK_IDENT && t < S->tccpp_tok_ident) {
286− const char *s = S->tccpp_table_ident[t - TOK_IDENT]->str;
285+ if (t >= TOK_IDENT && t < tok_ident) {
286+ const char *s = table_ident[t - TOK_IDENT]->str;
287287 char c;
288288 *type = OP_REG64;
289289 if (*s == 'c') {
@@ -318,51 +318,51 @@ static int asm_parse_numeric_reg(TCCState *S, int t, unsigned int *type) · 28 unmodified lines
318318 }
319319 #endif
320320
321−static int asm_parse_reg(TCCState* S, unsigned int *type)
321+static int asm_parse_reg(unsigned int *type)
322322 {
323323 int reg = 0;
324324 *type = 0;
325− if (S->tccpp_tok != '%')
325+ if (tok != '%')
326326 goto error_32;
327− next(S);
328− if (S->tccpp_tok >= TOK_ASM_eax && S->tccpp_tok <= TOK_ASM_edi) {
329− reg = S->tccpp_tok - TOK_ASM_eax;
327+ next();
328+ if (tok >= TOK_ASM_eax && tok <= TOK_ASM_edi) {
329+ reg = tok - TOK_ASM_eax;
330330 *type = OP_REG32;
331331 #ifdef TCC_TARGET_X86_64
332− } else if (S->tccpp_tok >= TOK_ASM_rax && S->tccpp_tok <= TOK_ASM_rdi) {
333− reg = S->tccpp_tok - TOK_ASM_rax;
332+ } else if (tok >= TOK_ASM_rax && tok <= TOK_ASM_rdi) {
333+ reg = tok - TOK_ASM_rax;
334334 *type = OP_REG64;
335− } else if (S->tccpp_tok == TOK_ASM_rip) {
335+ } else if (tok == TOK_ASM_rip) {
336336 reg = -2; /* Probably should use different escape code. */
337337 *type = OP_REG64;
338− } else if ((reg = asm_parse_numeric_reg(S, S->tccpp_tok, type)) >= 0
338+ } else if ((reg = asm_parse_numeric_reg(tok, type)) >= 0
339339 && (*type == OP_REG32 || *type == OP_REG64)) {
340340 ;
341341 #endif
342342 } else {
343343 error_32:
344− expect(S, "register");
344+ expect("register");
345345 }
346− next(S);
346+ next();
347347 return reg;
348348 }
349349
350−static void parse_operand(TCCState *S, Operand *op)
350+static void parse_operand(TCCState *s1, Operand *op)
351351 {
352352 ExprValue e;
353353 int reg, indir;
354354 const char *p;
355355
356356 indir = 0;
357− if (S->tccpp_tok == '*') {
358− next(S);
357+ if (tok == '*') {
358+ next();
359359 indir = OP_INDIR;
360360 }
361361
362− if (S->tccpp_tok == '%') {
363− next(S);
364− if (S->tccpp_tok >= TOK_ASM_al && S->tccpp_tok <= TOK_ASM_db7) {
365− reg = S->tccpp_tok - TOK_ASM_al;
362+ if (tok == '%') {
363+ next();
364+ if (tok >= TOK_ASM_al && tok <= TOK_ASM_db7) {
365+ reg = tok - TOK_ASM_al;
366366 op->type = 1 << (reg >> 3); /* WARNING: do not change constant order */
367367 op->reg = reg & 7;
368368 if ((op->type & OP_REG) && op->reg == TREG_XAX)
@@ -371,48 +371,48 @@ static void parse_operand(TCCState *S, Operand *op) · 2 unmodified lines
371371 op->type |= OP_CL;
372372 else if (op->type == OP_REG16 && op->reg == TREG_XDX)
373373 op->type |= OP_DX;
374− } else if (S->tccpp_tok >= TOK_ASM_dr0 && S->tccpp_tok <= TOK_ASM_dr7) {
374+ } else if (tok >= TOK_ASM_dr0 && tok <= TOK_ASM_dr7) {
375375 op->type = OP_DB;
376− op->reg = S->tccpp_tok - TOK_ASM_dr0;
377− } else if (S->tccpp_tok >= TOK_ASM_es && S->tccpp_tok <= TOK_ASM_gs) {
376+ op->reg = tok - TOK_ASM_dr0;
377+ } else if (tok >= TOK_ASM_es && tok <= TOK_ASM_gs) {
378378 op->type = OP_SEG;
379− op->reg = S->tccpp_tok - TOK_ASM_es;
380− } else if (S->tccpp_tok == TOK_ASM_st) {
379+ op->reg = tok - TOK_ASM_es;
380+ } else if (tok == TOK_ASM_st) {
381381 op->type = OP_ST;
382382 op->reg = 0;
383− next(S);
384− if (S->tccpp_tok == '(') {
385− next(S);
386− if (S->tccpp_tok != TOK_PPNUM)
383+ next();
384+ if (tok == '(') {
385+ next();
386+ if (tok != TOK_PPNUM)
387387 goto reg_error;
388− p = S->tccpp_tokc.str.data;
388+ p = tokc.str.data;
389389 reg = p[0] - '0';
390390 if ((unsigned)reg >= 8 || p[1] != '\0')
391391 goto reg_error;
392392 op->reg = reg;
393− next(S);
394− skip(S, ')');
393+ next();
394+ skip(')');
395395 }
396396 if (op->reg == 0)
397397 op->type |= OP_ST0;
398398 goto no_skip;
399399 #ifdef TCC_TARGET_X86_64
400− } else if (S->tccpp_tok >= TOK_ASM_spl && S->tccpp_tok <= TOK_ASM_dil) {
400+ } else if (tok >= TOK_ASM_spl && tok <= TOK_ASM_dil) {
401401 op->type = OP_REG8 | OP_REG8_LOW;
402− op->reg = 4 + S->tccpp_tok - TOK_ASM_spl;
403− } else if ((op->reg = asm_parse_numeric_reg(S, S->tccpp_tok, &op->type)) >= 0) {
402+ op->reg = 4 + tok - TOK_ASM_spl;
403+ } else if ((op->reg = asm_parse_numeric_reg(tok, &op->type)) >= 0) {
404404 ;
405405 #endif
406406 } else {
407407 reg_error:
408− tcc_error(S, "unknown register %%%s", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
408+ tcc_error("unknown register %%%s", get_tok_str(tok, &tokc));
409409 }
410− next(S);
410+ next();
411411 no_skip: ;
412− } else if (S->tccpp_tok == '$') {
412+ } else if (tok == '$') {
413413 /* constant value */
414− next(S);
415− asm_expr(S, &e);
414+ next();
415+ asm_expr(s1, &e);
416416 op->type = OP_IM32;
417417 op->e = e;
418418 if (!op->e.sym) {
@@ -433,45 +433,45 @@ static void parse_operand(TCCState *S, Operand *op) · 14 unmodified lines
433433 op->reg = -1;
434434 op->reg2 = -1;
435435 op->shift = 0;
436− if (S->tccpp_tok != '(') {
437− asm_expr(S, &e);
436+ if (tok != '(') {
437+ asm_expr(s1, &e);
438438 op->e = e;
439439 } else {
440− next(S);
441− if (S->tccpp_tok == '%') {
442− unget_tok(S, '(');
440+ next();
441+ if (tok == '%') {
442+ unget_tok('(');
443443 op->e.v = 0;
444444 op->e.sym = NULL;
445445 } else {
446446 /* bracketed offset expression */
447− asm_expr(S, &e);
448− if (S->tccpp_tok != ')')
449− expect(S, ")");
450− next(S);
447+ asm_expr(s1, &e);
448+ if (tok != ')')
449+ expect(")");
450+ next();
451451 op->e.v = e.v;
452452 op->e.sym = e.sym;
453453 }
454454 op->e.pcrel = 0;
455455 }
456− if (S->tccpp_tok == '(') {
456+ if (tok == '(') {
457457 unsigned int type = 0;
458− next(S);
459− if (S->tccpp_tok != ',') {
460− op->reg = asm_parse_reg(S, &type);
458+ next();
459+ if (tok != ',') {
460+ op->reg = asm_parse_reg(&type);
461461 }
462− if (S->tccpp_tok == ',') {
463− next(S);
464− if (S->tccpp_tok != ',') {
465− op->reg2 = asm_parse_reg(S, &type);
462+ if (tok == ',') {
463+ next();
464+ if (tok != ',') {
465+ op->reg2 = asm_parse_reg(&type);
466466 }
467− if (S->tccpp_tok == ',') {
468− next(S);
469− op->shift = get_reg_shift(S);
467+ if (tok == ',') {
468+ next();
469+ op->shift = get_reg_shift(s1);
470470 }
471471 }
472472 if (type & OP_REG32)
473473 op->type |= OP_EA32;
474− skip(S, ')');
474+ skip(')');
475475 }
476476 if (op->reg == -1 && op->reg2 == -1)
477477 op->type |= OP_ADDR;
@@ -480,65 +480,65 @@ static void parse_operand(TCCState *S, Operand *op) · 2 unmodified lines
480480 }
481481
482482 /* XXX: unify with C code output ? */
483−ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
483+ST_FUNC void gen_expr32(ExprValue *pe)
484484 {
485485 if (pe->pcrel)
486486 /* If PC-relative, always set VT_SYM, even without symbol,
487487 so as to force a relocation to be emitted. */
488− gen_addrpc32(S, VT_SYM, pe->sym, pe->v);
488+ gen_addrpc32(VT_SYM, pe->sym, pe->v);
489489 else
490− gen_addr32(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
490+ gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
491491 }
492492
493493 #ifdef TCC_TARGET_X86_64
494−ST_FUNC void gen_expr64(TCCState* S, ExprValue *pe)
494+ST_FUNC void gen_expr64(ExprValue *pe)
495495 {
496− gen_addr64(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
496+ gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
497497 }
498498 #endif
499499
500500 /* XXX: unify with C code output ? */
501−static void gen_disp32(TCCState* S, ExprValue *pe)
501+static void gen_disp32(ExprValue *pe)
502502 {
503503 Sym *sym = pe->sym;
504− ElfSym *esym = elfsym(S, sym);
504+ ElfSym *esym = elfsym(sym);
505505 if (esym && esym->st_shndx == cur_text_section->sh_num) {
506506 /* same section: we can output an absolute value. Note
507507 that the TCC compiler behaves differently here because
508508 it always outputs a relocation to ease (future) code
509509 elimination in the linker */
510− gen_le32(S, pe->v + esym->st_value - S->tccgen_ind - 4);
510+ gen_le32(pe->v + esym->st_value - ind - 4);
511511 } else {
512512 if (sym && sym->type.t == VT_VOID) {
513513 sym->type.t = VT_FUNC;
514514 sym->type.ref = NULL;
515515 }
516− gen_addrpc32(S, VT_SYM, sym, pe->v);
516+ gen_addrpc32(VT_SYM, sym, pe->v);
517517 }
518518 }
519519
520520 /* generate the modrm operand */
521−static inline int asm_modrm(TCCState* S, int reg, Operand *op)
521+static inline int asm_modrm(int reg, Operand *op)
522522 {
523523 int mod, reg1, reg2, sib_reg1;
524524
525525 if (op->type & (OP_REG | OP_MMX | OP_SSE)) {
526− g(S, 0xc0 + (reg << 3) + op->reg);
526+ g(0xc0 + (reg << 3) + op->reg);
527527 } else if (op->reg == -1 && op->reg2 == -1) {
528528 /* displacement only */
529529 #ifdef TCC_TARGET_X86_64
530− g(S, 0x04 + (reg << 3));
531− g(S, 0x25);
530+ g(0x04 + (reg << 3));
531+ g(0x25);
532532 #else
533− g(S, 0x05 + (reg << 3));
533+ g(0x05 + (reg << 3));
534534 #endif
535− gen_expr32(S, &op->e);
535+ gen_expr32(&op->e);
536536 #ifdef TCC_TARGET_X86_64
537537 } else if (op->reg == -2) {
538538 ExprValue *pe = &op->e;
539− g(S, 0x05 + (reg << 3));
540− gen_addrpc32(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
541− return S->tccgen_ind;
539+ g(0x05 + (reg << 3));
540+ gen_addrpc32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
541+ return ind;
542542 #endif
543543 } else {
544544 sib_reg1 = op->reg;
@@ -557,19 +557,19 @@ static inline int asm_modrm(TCCState* S, int reg, Operand *op) · 12 unmodified lines
557557 reg1 = op->reg;
558558 if (op->reg2 != -1)
559559 reg1 = 4;
560− g(S, mod + (reg << 3) + reg1);
560+ g(mod + (reg << 3) + reg1);
561561 if (reg1 == 4) {
562562 /* add sib byte */
563563 reg2 = op->reg2;
564564 if (reg2 == -1)
565565 reg2 = 4; /* indicate no index */
566− g(S, (op->shift << 6) + (reg2 << 3) + sib_reg1);
566+ g((op->shift << 6) + (reg2 << 3) + sib_reg1);
567567 }
568568 /* add offset */
569569 if (mod == 0x40) {
570− g(S, op->e.v);
570+ g(op->e.v);
571571 } else if (mod == 0x80 || op->reg == -1) {
572− gen_expr32(S, &op->e);
572+ gen_expr32(&op->e);
573573 }
574574 }
575575 return 0;
@@ -581,7 +581,7 @@ static inline int asm_modrm(TCCState* S, int reg, Operand *op) · 5 unmodified lines
581581 #define REX_X 0x42
582582 #define REX_B 0x41
583583
584−static void asm_rex(TCCState* S, int width64, Operand *ops, int nb_ops, int *op_type,
584+static void asm_rex(int width64, Operand *ops, int nb_ops, int *op_type,
585585 int regi, int rmi)
586586 {
587587 unsigned char rex = width64 ? 0x48 : 0;
@@ -631,9 +631,9 @@ static void asm_rex(TCCState* S, int width64, Operand *ops, int nb_ops, int *op_ · 43 unmodified lines
631631 }
632632 if (rex) {
633633 if (saw_high_8bit)
634− tcc_error(S, "can't encode register %%%ch when REX prefix is required",
634+ tcc_error("can't encode register %%%ch when REX prefix is required",
635635 "acdb"[saw_high_8bit-4]);
636− g(S, rex);
636+ g(rex);
637637 }
638638 }
639639 #endif
@@ -679,7 +679,7 @@ static void maybe_print_stats (void) · 39 unmodified lines
679679 }
680680 }
681681
682−ST_FUNC void asm_opcode(TCCState *S, int opcode)
682+ST_FUNC void asm_opcode(TCCState *s1, int opcode)
683683 {
684684 const ASMInstr *pa;
685685 int i, modrm_index, modreg_index, reg, v, op1, seg_prefix, pc;
@@ -697,7 +697,7 @@ ST_FUNC void asm_opcode(TCCState *S, int opcode) · 11 unmodified lines
697697 /* force synthetic ';' after prefix instruction, so we can handle */
698698 /* one-line things like "rep stosb" instead of only "rep\nstosb" */
699699 if (opcode >= TOK_ASM_wait && opcode <= TOK_ASM_repnz)
700− unget_tok(S, ';');
700+ unget_tok(';');
701701
702702 /* get operands */
703703 pop = ops;
@@ -705,27 +705,27 @@ ST_FUNC void asm_opcode(TCCState *S, int opcode) · 1 unmodified line
705705 seg_prefix = 0;
706706 alltypes = 0;
707707 for(;;) {
708− if (S->tccpp_tok == ';' || S->tccpp_tok == TOK_LINEFEED)
708+ if (tok == ';' || tok == TOK_LINEFEED)
709709 break;
710710 if (nb_ops >= MAX_OPERANDS) {
711− tcc_error(S, "incorrect number of operands");
711+ tcc_error("incorrect number of operands");
712712 }
713− parse_operand(S, pop);
714− if (S->tccpp_tok == ':') {
713+ parse_operand(s1, pop);
714+ if (tok == ':') {
715715 if (pop->type != OP_SEG || seg_prefix)
716− tcc_error(S, "incorrect prefix");
716+ tcc_error("incorrect prefix");
717717 seg_prefix = segment_prefixes[pop->reg];
718− next(S);
719− parse_operand(S, pop);
718+ next();
719+ parse_operand(s1, pop);
720720 if (!(pop->type & OP_EA)) {
721− tcc_error(S, "segment prefix must be followed by memory reference");
721+ tcc_error("segment prefix must be followed by memory reference");
722722 }
723723 }
724724 pop++;
725725 nb_ops++;
726− if (S->tccpp_tok != ',')
726+ if (tok != ',')
727727 break;
728− next(S);
728+ next();
729729 }
730730
731731 s = 0; /* avoid warning */
@@ -842,23 +842,23 @@ again: · 110 unmodified lines
842842 int b;
843843 b = op0_codes[opcode - TOK_ASM_first];
844844 if (b & 0xff00)
845− g(S, b >> 8);
846− g(S, b);
845+ g(b >> 8);
846+ g(b);
847847 return;
848848 } else if (opcode <= TOK_ASM_alllast) {
849− tcc_error(S, "bad operand with opcode '%s'",
850− get_tok_str(S, opcode, NULL));
849+ tcc_error("bad operand with opcode '%s'",
850+ get_tok_str(opcode, NULL));
851851 } else {
852852 /* Special case for cmovcc, we accept size suffixes but ignore
853853 them, but we don't want them to blow up our tables. */
854− TokenSym *ts = S->tccpp_table_ident[opcode - TOK_IDENT];
854+ TokenSym *ts = table_ident[opcode - TOK_IDENT];
855855 if (ts->len >= 6
856856 && strchr("wlq", ts->str[ts->len-1])
857857 && !memcmp(ts->str, "cmov", 4)) {
858− opcode = tok_alloc(S, ts->str, ts->len-1)->tok;
858+ opcode = tok_alloc(ts->str, ts->len-1)->tok;
859859 goto again;
860860 }
861− tcc_error(S, "unknown opcode '%s'", ts->str);
861+ tcc_error("unknown opcode '%s'", ts->str);
862862 }
863863 }
864864 /* if the size is unknown, then evaluate it (OPC_B or OPC_WL case) */
@@ -886,7 +886,7 @@ again: · 21 unmodified lines
886886 (ops[0].type & OP_EA))
887887 s = NBWLX - 2;
888888 else
889− tcc_error(S, "cannot infer opcode suffix");
889+ tcc_error("cannot infer opcode suffix");
890890 }
891891 }
892892
@@ -894,7 +894,7 @@ again: · 1 unmodified line
894894 /* Generate addr32 prefix if needed */
895895 for(i = 0; i < nb_ops; i++) {
896896 if (ops[i].type & OP_EA32) {
897− g(S, 0x67);
897+ g(0x67);
898898 break;
899899 }
900900 }
@@ -913,7 +913,7 @@ again: · 12 unmodified lines
913913 p66 = 1;
914914 }
915915 if (p66)
916− g(S, 0x66);
916+ g(0x66);
917917 #ifdef TCC_TARGET_X86_64
918918 rex64 = 0;
919919 if (pa->instr_type & OPC_48)
@@ -943,9 +943,9 @@ again: · 23 unmodified lines
943943
944944 /* now generates the operation */
945945 if (OPCT_IS(pa->instr_type, OPC_FWAIT))
946− g(S, 0x9b);
946+ g(0x9b);
947947 if (seg_prefix)
948− g(S, seg_prefix);
948+ g(seg_prefix);
949949
950950 v = pa->opcode;
951951 if (pa->instr_type & OPC_0F)
@@ -998,7 +998,7 @@ again: · 46 unmodified lines
998998 goto modrm_found;
999999 }
10001000 #ifdef ASM_DEBUG
1001− tcc_error(S, "bad op table");
1001+ tcc_error("bad op table");
10021002 #endif
10031003 modrm_found:
10041004 modrm_index = i;
@@ -1014,7 +1014,7 @@ again: · 9 unmodified lines
10141014 }
10151015 }
10161016 #ifdef TCC_TARGET_X86_64
1017− asm_rex (S, rex64, ops, nb_ops, op_type, modreg_index, modrm_index);
1017+ asm_rex (rex64, ops, nb_ops, op_type, modreg_index, modrm_index);
10181018 #endif
10191019
10201020 if (pa->instr_type & OPC_REG) {
@@ -1035,10 +1035,10 @@ again: · 14 unmodified lines
10351035 int jmp_disp;
10361036
10371037 /* see if we can really generate the jump with a byte offset */
1038− esym = elfsym(S, ops[0].e.sym);
1038+ esym = elfsym(ops[0].e.sym);
10391039 if (!esym || esym->st_shndx != cur_text_section->sh_num)
10401040 goto no_short_jump;
1041− jmp_disp = ops[0].e.v + esym->st_value - S->tccgen_ind - 2 - (v >= 0xff);
1041+ jmp_disp = ops[0].e.v + esym->st_value - ind - 2 - (v >= 0xff);
10421042 if (jmp_disp == (int8_t)jmp_disp) {
10431043 /* OK to generate jump */
10441044 ops[0].e.sym = 0;
@@ -1053,18 +1053,18 @@ again: · 8 unmodified lines
10531053 else if (v == 0x70) /* jcc */
10541054 v += 0x0f10;
10551055 else
1056− tcc_error(S, "invalid displacement");
1056+ tcc_error("invalid displacement");
10571057 }
10581058 }
10591059 if (OPCT_IS(pa->instr_type, OPC_TEST))
10601060 v += test_bits[opcode - pa->sym];
10611061 op1 = v >> 16;
10621062 if (op1)
1063− g(S, op1);
1063+ g(op1);
10641064 op1 = (v >> 8) & 0xff;
10651065 if (op1)
1066− g(S, op1);
1067− g(S, v);
1066+ g(op1);
1067+ g(v);
10681068
10691069 if (OPCT_IS(pa->instr_type, OPC_SHIFT)) {
10701070 reg = (opcode - pa->sym) / NBWLX;
@@ -1084,7 +1084,7 @@ again: · 13 unmodified lines
10841084 used instead of group */
10851085 if (modreg_index >= 0)
10861086 reg = ops[modreg_index].reg;
1087− pc = asm_modrm(S, reg, &ops[modrm_index]);
1087+ pc = asm_modrm(reg, &ops[modrm_index]);
10881088 }
10891089
10901090 /* emit constants */
@@ -1092,10 +1092,10 @@ again: · 1 unmodified line
10921092 if (!(pa->instr_type & OPC_0F)
10931093 && (pa->opcode == 0x9a || pa->opcode == 0xea)) {
10941094 /* ljmp or lcall kludge */
1095− gen_expr32(S, &ops[1].e);
1095+ gen_expr32(&ops[1].e);
10961096 if (ops[0].e.sym)
1097− tcc_error(S, "cannot relocate");
1098− gen_le16(S, ops[0].e.v);
1097+ tcc_error("cannot relocate");
1098+ gen_le16(ops[0].e.v);
10991099 return;
11001100 }
11011101 #endif
@@ -1116,32 +1116,32 @@ again: · 14 unmodified lines
11161116 }
11171117
11181118 if ((v & (OP_IM8 | OP_IM8S | OP_IM16)) && ops[i].e.sym)
1119− tcc_error(S, "cannot relocate");
1119+ tcc_error("cannot relocate");
11201120
11211121 if (v & (OP_IM8 | OP_IM8S)) {
1122− g(S, ops[i].e.v);
1122+ g(ops[i].e.v);
11231123 } else if (v & OP_IM16) {
1124− gen_le16(S, ops[i].e.v);
1124+ gen_le16(ops[i].e.v);
11251125 #ifdef TCC_TARGET_X86_64
11261126 } else if (v & OP_IM64) {
1127− gen_expr64(S, &ops[i].e);
1127+ gen_expr64(&ops[i].e);
11281128 #endif
11291129 } else if (pa->op_type[i] == OPT_DISP || pa->op_type[i] == OPT_DISP8) {
1130− gen_disp32(S, &ops[i].e);
1130+ gen_disp32(&ops[i].e);
11311131 } else {
1132− gen_expr32(S, &ops[i].e);
1132+ gen_expr32(&ops[i].e);
11331133 }
11341134 }
11351135 }
11361136
11371137 /* after immediate operands, adjust pc-relative address */
11381138 if (pc)
1139− add32le(cur_text_section->data + pc - 4, pc - S->tccgen_ind);
1139+ add32le(cur_text_section->data + pc - 4, pc - ind);
11401140 }
11411141
11421142 /* return the constraint priority (we allocate first the lowest
11431143 numbered constraints) */
1144−static inline int constraint_priority(TCCState* S, const char *str)
1144+static inline int constraint_priority(const char *str)
11451145 {
11461146 int priority, c, pr;
11471147
@@ -1182,7 +1182,7 @@ static inline int constraint_priority(TCCState* S, const char *str) · 34 unmodified lines
11821182 pr = 4;
11831183 break;
11841184 default:
1185− tcc_error(S, "unknown constraint '%c'", c);
1185+ tcc_error("unknown constraint '%c'", c);
11861186 pr = 0;
11871187 }
11881188 if (pr > priority)
@@ -1200,19 +1200,19 @@ static const char *skip_constraint_modifiers(const char *p) · 11 unmodified lines
12001200
12011201 /* If T (a token) is of the form "%reg" returns the register
12021202 number and type, otherwise return -1. */
1203−ST_FUNC int asm_parse_regvar (TCCState* S, int t)
1203+ST_FUNC int asm_parse_regvar (int t)
12041204 {
12051205 const char *s;
12061206 Operand op;
12071207 if (t < TOK_IDENT || (t & SYM_FIELD))
12081208 return -1;
1209− s = S->tccpp_table_ident[t - TOK_IDENT]->str;
1209+ s = table_ident[t - TOK_IDENT]->str;
12101210 if (s[0] != '%')
12111211 return -1;
1212− t = tok_alloc_const(S, s + 1);
1213− unget_tok(S, t);
1214− unget_tok(S, '%');
1215− parse_operand(S, &op);
1212+ t = tok_alloc_const(s + 1);
1213+ unget_tok(t);
1214+ unget_tok('%');
1215+ parse_operand(tcc_state, &op);
12161216 /* Accept only integer regs for now. */
12171217 if (op.type & OP_REG)
12181218 return op.reg;
@@ -1225,7 +1225,7 @@ ST_FUNC int asm_parse_regvar (TCCState* S, int t) · 6 unmodified lines
12251225
12261226 #define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask)
12271227
1228−ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
1228+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
12291229 int nb_operands, int nb_outputs,
12301230 const uint8_t *clobber_regs,
12311231 int *pout_reg)
@@ -1253,13 +1253,13 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 21 unmodified lines
12531253 str = skip_constraint_modifiers(str);
12541254 if (isnum(*str) || *str == '[') {
12551255 /* this is a reference to another constraint */
1256− k = find_constraint(S, operands, nb_operands, str, NULL);
1256+ k = find_constraint(operands, nb_operands, str, NULL);
12571257 if ((unsigned)k >= i || i < nb_outputs)
1258− tcc_error(S, "invalid reference in constraint %d ('%s')",
1258+ tcc_error("invalid reference in constraint %d ('%s')",
12591259 i, str);
12601260 op->ref_index = k;
12611261 if (operands[k].input_index >= 0)
1262− tcc_error(S, "cannot reference twice the same operand");
1262+ tcc_error("cannot reference twice the same operand");
12631263 operands[k].input_index = i;
12641264 op->priority = 5;
12651265 } else if ((op->vt->r & VT_VALMASK) == VT_LOCAL
@@ -1268,7 +1268,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 2 unmodified lines
12681268 op->priority = 1;
12691269 op->reg = reg;
12701270 } else {
1271− op->priority = constraint_priority(S, str);
1271+ op->priority = constraint_priority(str);
12721272 }
12731273 }
12741274
@@ -1316,7 +1316,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 41 unmodified lines
13161316 }
13171317 if (op->reg >= 0) {
13181318 if (is_reg_allocated(op->reg))
1319− tcc_error(S, "asm regvar requests register that's taken already");
1319+ tcc_error("asm regvar requests register that's taken already");
13201320 reg = op->reg;
13211321 goto reg_found;
13221322 }
@@ -1330,7 +1330,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 7 unmodified lines
13301330 /* FALL THRU */
13311331 case '&':
13321332 if (j >= nb_outputs)
1333− tcc_error(S, "'%c' modifier can only be applied to outputs", c);
1333+ tcc_error("'%c' modifier can only be applied to outputs", c);
13341334 reg_mask = REG_IN_MASK | REG_OUT_MASK;
13351335 goto try_next;
13361336 case 'A':
@@ -1424,7 +1424,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 87 unmodified lines
14241424 }
14251425 break;
14261426 default:
1427− tcc_error(S, "asm constraint %d ('%s') could not be satisfied",
1427+ tcc_error("asm constraint %d ('%s') could not be satisfied",
14281428 j, op->constraint);
14291429 break;
14301430 }
@@ -1447,7 +1447,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 16 unmodified lines
14471447 if (!(regs_allocated[reg] & REG_OUT_MASK))
14481448 goto reg_found2;
14491449 }
1450− tcc_error(S, "could not find free output register for reloading");
1450+ tcc_error("could not find free output register for reloading");
14511451 reg_found2:
14521452 *pout_reg = reg;
14531453 break;
@@ -1461,7 +1461,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 7 unmodified lines
14611461 op = &operands[j];
14621462 printf("%%%d [%s]: \"%s\" r=0x%04x reg=%d\n",
14631463 j,
1464− op->id ? get_tok_str(S, op->id, NULL) : "",
1464+ op->id ? get_tok_str(op->id, NULL) : "",
14651465 op->constraint,
14661466 op->vt->r,
14671467 op->reg);
@@ -1471,7 +1471,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, · 3 unmodified lines
14711471 #endif
14721472 }
14731473
1474−ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
1474+ST_FUNC void subst_asm_operand(CString *add_str,
14751475 SValue *sv, int modifier)
14761476 {
14771477 int r, reg, size, val;
@@ -1481,33 +1481,33 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, · 3 unmodified lines
14811481 if ((r & VT_VALMASK) == VT_CONST) {
14821482 if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' &&
14831483 modifier != 'P')
1484− cstr_ccat(S, add_str, '$');
1484+ cstr_ccat(add_str, '$');
14851485 if (r & VT_SYM) {
1486− const char *name = get_tok_str(S, sv->sym->v, NULL);
1486+ const char *name = get_tok_str(sv->sym->v, NULL);
14871487 if (sv->sym->v >= SYM_FIRST_ANOM) {
14881488 /* In case of anonymous symbols ("L.42", used
14891489 for static data labels) we can't find them
14901490 in the C symbol table when later looking up
14911491 this name. So enter them now into the asm label
14921492 list when we still know the symbol. */
1493− get_asm_sym(S, tok_alloc_const(S, name), sv->sym);
1493+ get_asm_sym(tok_alloc_const(name), sv->sym);
14941494 }
1495− if (S->leading_underscore)
1496− cstr_ccat(S, add_str, '_');
1497− cstr_cat(S, add_str, name, -1);
1495+ if (tcc_state->leading_underscore)
1496+ cstr_ccat(add_str, '_');
1497+ cstr_cat(add_str, name, -1);
14981498 if ((uint32_t)sv->c.i == 0)
14991499 goto no_offset;
1500− cstr_ccat(S, add_str, '+');
1500+ cstr_ccat(add_str, '+');
15011501 }
15021502 val = sv->c.i;
15031503 if (modifier == 'n')
15041504 val = -val;
15051505 snprintf(buf, sizeof(buf), "%d", (int)sv->c.i);
1506− cstr_cat(S, add_str, buf, -1);
1506+ cstr_cat(add_str, buf, -1);
15071507 no_offset:;
15081508 #ifdef TCC_TARGET_X86_64
15091509 if (r & VT_LVAL)
1510− cstr_cat(S, add_str, "(%rip)", -1);
1510+ cstr_cat(add_str, "(%rip)", -1);
15111511 #endif
15121512 } else if ((r & VT_VALMASK) == VT_LOCAL) {
15131513 #ifdef TCC_TARGET_X86_64
@@ -1515,24 +1515,24 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, · 1 unmodified line
15151515 #else
15161516 snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i);
15171517 #endif
1518− cstr_cat(S, add_str, buf, -1);
1518+ cstr_cat(add_str, buf, -1);
15191519 } else if (r & VT_LVAL) {
15201520 reg = r & VT_VALMASK;
15211521 if (reg >= VT_CONST)
1522− tcc_internal_error(S, "");
1522+ tcc_internal_error("");
15231523 snprintf(buf, sizeof(buf), "(%%%s)",
15241524 #ifdef TCC_TARGET_X86_64
1525− get_tok_str(S, TOK_ASM_rax + reg, NULL)
1525+ get_tok_str(TOK_ASM_rax + reg, NULL)
15261526 #else
1527− get_tok_str(S, TOK_ASM_eax + reg, NULL)
1527+ get_tok_str(TOK_ASM_eax + reg, NULL)
15281528 #endif
15291529 );
1530− cstr_cat(S, add_str, buf, -1);
1530+ cstr_cat(add_str, buf, -1);
15311531 } else {
15321532 /* register case */
15331533 reg = r & VT_VALMASK;
15341534 if (reg >= VT_CONST)
1535− tcc_internal_error(S, "");
1535+ tcc_internal_error("");
15361536
15371537 /* choose register operand size */
15381538 if ((sv->type.t & VT_BTYPE) == VT_BYTE ||
@@ -1552,11 +1552,11 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, · 13 unmodified lines
15521552
15531553 if (modifier == 'b') {
15541554 if (reg >= 4)
1555− tcc_error(S, "cannot use byte register");
1555+ tcc_error("cannot use byte register");
15561556 size = 1;
15571557 } else if (modifier == 'h') {
15581558 if (reg >= 4)
1559− tcc_error(S, "cannot use byte register");
1559+ tcc_error("cannot use byte register");
15601560 size = -1;
15611561 } else if (modifier == 'w') {
15621562 size = 2;
@@ -1587,13 +1587,13 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, · 24 unmodified lines
15871587 break;
15881588 #endif
15891589 }
1590− snprintf(buf, sizeof(buf), "%%%s", get_tok_str(S, reg, NULL));
1591− cstr_cat(S, add_str, buf, -1);
1590+ snprintf(buf, sizeof(buf), "%%%s", get_tok_str(reg, NULL));
1591+ cstr_cat(add_str, buf, -1);
15921592 }
15931593 }
15941594
15951595 /* generate prolog and epilog code for asm statement */
1596−ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
1596+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
15971597 int nb_outputs, int is_output,
15981598 uint8_t *clobber_regs,
15991599 int out_reg)
@@ -1627,8 +1627,8 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 27 unmodified lines
16271627 reg = reg_saved[i];
16281628 if (regs_allocated[reg]) {
16291629 if (reg >= 8)
1630− g(S, 0x41), reg-=8;
1631− g(S, 0x50 + reg);
1630+ g(0x41), reg-=8;
1631+ g(0x50 + reg);
16321632 }
16331633 }
16341634
@@ -1644,15 +1644,15 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 9 unmodified lines
16441644 sv = *op->vt;
16451645 sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
16461646 sv.type.t = VT_PTR;
1647− load(S, op->reg, &sv);
1647+ load(op->reg, &sv);
16481648 } else if (i >= nb_outputs || op->is_rw) {
16491649 /* load value in register */
1650− load(S, op->reg, op->vt);
1650+ load(op->reg, op->vt);
16511651 if (op->is_llong) {
16521652 SValue sv;
16531653 sv = *op->vt;
16541654 sv.c.i += 4;
1655− load(S, TREG_XDX, &sv);
1655+ load(TREG_XDX, &sv);
16561656 }
16571657 }
16581658 }
@@ -1668,19 +1668,19 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 9 unmodified lines
16681668 sv = *op->vt;
16691669 sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL;
16701670 sv.type.t = VT_PTR;
1671− load(S, out_reg, &sv);
1671+ load(out_reg, &sv);
16721672
16731673 sv = *op->vt;
16741674 sv.r = (sv.r & ~VT_VALMASK) | out_reg;
1675− store(S, op->reg, &sv);
1675+ store(op->reg, &sv);
16761676 }
16771677 } else {
1678− store(S, op->reg, op->vt);
1678+ store(op->reg, op->vt);
16791679 if (op->is_llong) {
16801680 SValue sv;
16811681 sv = *op->vt;
16821682 sv.c.i += 4;
1683− store(S, TREG_XDX, &sv);
1683+ store(TREG_XDX, &sv);
16841684 }
16851685 }
16861686 }
@@ -1690,14 +1690,14 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, · 3 unmodified lines
16901690 reg = reg_saved[i];
16911691 if (regs_allocated[reg]) {
16921692 if (reg >= 8)
1693− g(S, 0x41), reg-=8;
1694− g(S, 0x58 + reg);
1693+ g(0x41), reg-=8;
1694+ g(0x58 + reg);
16951695 }
16961696 }
16971697 }
16981698 }
16991699
1700−ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
1700+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
17011701 {
17021702 int reg;
17031703 #ifdef TCC_TARGET_X86_64
@@ -1708,7 +1708,7 @@ ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str) · 4 unmodified lines
17081708 !strcmp(str, "cc") ||
17091709 !strcmp(str, "flags"))
17101710 return;
1711− reg = tok_alloc_const(S, str);
1711+ reg = tok_alloc_const(str);
17121712 if (reg >= TOK_ASM_eax && reg <= TOK_ASM_edi) {
17131713 reg -= TOK_ASM_eax;
17141714 } else if (reg >= TOK_ASM_ax && reg <= TOK_ASM_di) {
@@ -1716,11 +1716,11 @@ ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str) · 1 unmodified line
17161716 #ifdef TCC_TARGET_X86_64
17171717 } else if (reg >= TOK_ASM_rax && reg <= TOK_ASM_rdi) {
17181718 reg -= TOK_ASM_rax;
1719− } else if ((reg = asm_parse_numeric_reg(S, reg, &type)) >= 0) {
1719+ } else if ((reg = asm_parse_numeric_reg(reg, &type)) >= 0) {
17201720 ;
17211721 #endif
17221722 } else {
1723− tcc_error(S, "invalid clobber register '%s'", str);
1723+ tcc_error("invalid clobber register '%s'", str);
17241724 }
17251725 clobber_regs[reg] = 1;
17261726 }
i386-gen.c+368−365
@@ -100,47 +100,50 @@ ST_DATA const int reg_classes[NB_REGS] = { · 99 unmodified lines
100100 static unsigned long func_sub_sp_offset;
101101 static int func_ret_sub;
102102 #ifdef CONFIG_TCC_BCHECK
103−static void gen_bounds_prolog(TCCState* S);
104−static void gen_bounds_epilog(TCCState* S);
103+static addr_t func_bound_offset;
104+static unsigned long func_bound_ind;
105+ST_DATA int func_bound_add_epilog;
106+static void gen_bounds_prolog(void);
107+static void gen_bounds_epilog(void);
105108 #endif
106109
107110 /* XXX: make it faster ? */
108−ST_FUNC void g(TCCState* S, int c)
111+ST_FUNC void g(int c)
109112 {
110113 int ind1;
111− if (S->tccgen_nocode_wanted)
114+ if (nocode_wanted)
112115 return;
113− ind1 = S->tccgen_ind + 1;
116+ ind1 = ind + 1;
114117 if (ind1 > cur_text_section->data_allocated)
115− section_realloc(S, cur_text_section, ind1);
116− cur_text_section->data[S->tccgen_ind] = c;
117− S->tccgen_ind = ind1;
118+ section_realloc(cur_text_section, ind1);
119+ cur_text_section->data[ind] = c;
120+ ind = ind1;
118121 }
119122
120−ST_FUNC void o(TCCState* S, unsigned int c)
123+ST_FUNC void o(unsigned int c)
121124 {
122125 while (c) {
123− g(S, c);
126+ g(c);
124127 c = c >> 8;
125128 }
126129 }
127130
128−ST_FUNC void gen_le16(TCCState* S, int v)
131+ST_FUNC void gen_le16(int v)
129132 {
130− g(S, v);
131− g(S, v >> 8);
133+ g(v);
134+ g(v >> 8);
132135 }
133136
134−ST_FUNC void gen_le32(TCCState* S, int c)
137+ST_FUNC void gen_le32(int c)
135138 {
136− g(S, c);
137− g(S, c >> 8);
138− g(S, c >> 16);
139− g(S, c >> 24);
139+ g(c);
140+ g(c >> 8);
141+ g(c >> 16);
142+ g(c >> 24);
140143 }
141144
142145 /* output a symbol and patch all calls to it */
143−ST_FUNC void gsym_addr(TCCState* S, int t, int a)
146+ST_FUNC void gsym_addr(int t, int a)
144147 {
145148 while (t) {
146149 unsigned char *ptr = cur_text_section->data + t;
@@ -151,73 +154,73 @@ ST_FUNC void gsym_addr(TCCState* S, int t, int a) · 4 unmodified lines
151154 }
152155
153156 /* instruction + 4 bytes data. Return the address of the data */
154−static int oad(TCCState* S, int c, int s)
157+static int oad(int c, int s)
155158 {
156159 int t;
157− if (S->tccgen_nocode_wanted)
160+ if (nocode_wanted)
158161 return s;
159− o(S, c);
160− t = S->tccgen_ind;
161− gen_le32(S, s);
162+ o(c);
163+ t = ind;
164+ gen_le32(s);
162165 return t;
163166 }
164167
165−ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
168+ST_FUNC void gen_fill_nops(int bytes)
166169 {
167170 while (bytes--)
168− g(S, 0x90);
171+ g(0x90);
169172 }
170173
171174 /* generate jmp to a label */
172−#define gjmp2(s, instr,lbl) oad(s, instr,lbl)
175+#define gjmp2(instr,lbl) oad(instr,lbl)
173176
174177 /* output constant with relocation if 'r & VT_SYM' is true */
175−ST_FUNC void gen_addr32(TCCState* S, int r, Sym *sym, int c)
178+ST_FUNC void gen_addr32(int r, Sym *sym, int c)
176179 {
177180 if (r & VT_SYM)
178− greloc(S, cur_text_section, sym, S->tccgen_ind, R_386_32);
179− gen_le32(S, c);
181+ greloc(cur_text_section, sym, ind, R_386_32);
182+ gen_le32(c);
180183 }
181184
182−ST_FUNC void gen_addrpc32(TCCState* S, int r, Sym *sym, int c)
185+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
183186 {
184187 if (r & VT_SYM)
185− greloc(S, cur_text_section, sym, S->tccgen_ind, R_386_PC32);
186− gen_le32(S, c - 4);
188+ greloc(cur_text_section, sym, ind, R_386_PC32);
189+ gen_le32(c - 4);
187190 }
188191
189192 /* generate a modrm reference. 'op_reg' contains the additional 3
190193 opcode bits */
191−static void gen_modrm(TCCState* S, int op_reg, int r, Sym *sym, int c)
194+static void gen_modrm(int op_reg, int r, Sym *sym, int c)
192195 {
193196 op_reg = op_reg << 3;
194197 if ((r & VT_VALMASK) == VT_CONST) {
195198 /* constant memory reference */
196− o(S, 0x05 | op_reg);
197− gen_addr32(S, r, sym, c);
199+ o(0x05 | op_reg);
200+ gen_addr32(r, sym, c);
198201 } else if ((r & VT_VALMASK) == VT_LOCAL) {
199202 /* currently, we use only ebp as base */
200203 if (c == (char)c) {
201204 /* short reference */
202− o(S, 0x45 | op_reg);
203− g(S, c);
205+ o(0x45 | op_reg);
206+ g(c);
204207 } else {
205− oad(S, 0x85 | op_reg, c);
208+ oad(0x85 | op_reg, c);
206209 }
207210 } else {
208− g(S, 0x00 | op_reg | (r & VT_VALMASK));
211+ g(0x00 | op_reg | (r & VT_VALMASK));
209212 }
210213 }
211214
212215 /* load 'r' from value 'sv' */
213−ST_FUNC void load(TCCState* S, int r, SValue *sv)
216+ST_FUNC void load(int r, SValue *sv)
214217 {
215218 int v, t, ft, fc, fr;
216219 SValue v1;
217220
218221 #ifdef TCC_TARGET_PE
219222 SValue v2;
220− sv = pe_getimport(S, sv, &v2);
223+ sv = pe_getimport(sv, &v2);
221224 #endif
222225
223226 fr = sv->r;
@@ -235,68 +238,68 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv) · 11 unmodified lines
235238 v1.sym = NULL;
236239 fr = r;
237240 if (!(reg_classes[fr] & RC_INT))
238− fr = get_reg(S, RC_INT);
239− load(S, fr, &v1);
241+ fr = get_reg(RC_INT);
242+ load(fr, &v1);
240243 }
241244 if ((ft & VT_BTYPE) == VT_FLOAT) {
242− o(S, 0xd9); /* flds */
245+ o(0xd9); /* flds */
243246 r = 0;
244247 } else if ((ft & VT_BTYPE) == VT_DOUBLE) {
245− o(S, 0xdd); /* fldl */
248+ o(0xdd); /* fldl */
246249 r = 0;
247250 } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
248− o(S, 0xdb); /* fldt */
251+ o(0xdb); /* fldt */
249252 r = 5;
250253 } else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) {
251− o(S, 0xbe0f); /* movsbl */
254+ o(0xbe0f); /* movsbl */
252255 } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
253− o(S, 0xb60f); /* movzbl */
256+ o(0xb60f); /* movzbl */
254257 } else if ((ft & VT_TYPE) == VT_SHORT) {
255− o(S, 0xbf0f); /* movswl */
258+ o(0xbf0f); /* movswl */
256259 } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
257− o(S, 0xb70f); /* movzwl */
260+ o(0xb70f); /* movzwl */
258261 } else {
259− o(S, 0x8b); /* movl */
262+ o(0x8b); /* movl */
260263 }
261− gen_modrm(S, r, fr, sv->sym, fc);
264+ gen_modrm(r, fr, sv->sym, fc);
262265 } else {
263266 if (v == VT_CONST) {
264− o(S, 0xb8 + r); /* mov $xx, r */
265− gen_addr32(S, fr, sv->sym, fc);
267+ o(0xb8 + r); /* mov $xx, r */
268+ gen_addr32(fr, sv->sym, fc);
266269 } else if (v == VT_LOCAL) {
267270 if (fc) {
268− o(S, 0x8d); /* lea xxx(%ebp), r */
269− gen_modrm(S, r, VT_LOCAL, sv->sym, fc);
271+ o(0x8d); /* lea xxx(%ebp), r */
272+ gen_modrm(r, VT_LOCAL, sv->sym, fc);
270273 } else {
271− o(S, 0x89);
272− o(S, 0xe8 + r); /* mov %ebp, r */
274+ o(0x89);
275+ o(0xe8 + r); /* mov %ebp, r */
273276 }
274277 } else if (v == VT_CMP) {
275− o(S, 0x0f); /* setxx %br */
276− o(S, fc);
277− o(S, 0xc0 + r);
278− o(S, 0xc0b60f + r * 0x90000); /* movzbl %al, %eax */
278+ o(0x0f); /* setxx %br */
279+ o(fc);
280+ o(0xc0 + r);
281+ o(0xc0b60f + r * 0x90000); /* movzbl %al, %eax */
279282 } else if (v == VT_JMP || v == VT_JMPI) {
280283 t = v & 1;
281− oad(S, 0xb8 + r, t); /* mov $1, r */
282− o(S, 0x05eb); /* jmp after */
283− gsym(S, fc);
284− oad(S, 0xb8 + r, t ^ 1); /* mov $0, r */
284+ oad(0xb8 + r, t); /* mov $1, r */
285+ o(0x05eb); /* jmp after */
286+ gsym(fc);
287+ oad(0xb8 + r, t ^ 1); /* mov $0, r */
285288 } else if (v != r) {
286− o(S, 0x89);
287− o(S, 0xc0 + r + v * 8); /* mov v, r */
289+ o(0x89);
290+ o(0xc0 + r + v * 8); /* mov v, r */
288291 }
289292 }
290293 }
291294
292295 /* store register 'r' in lvalue 'v' */
293−ST_FUNC void store(TCCState* S, int r, SValue *v)
296+ST_FUNC void store(int r, SValue *v)
294297 {
295298 int fr, bt, ft, fc;
296299
297300 #ifdef TCC_TARGET_PE
298301 SValue v2;
299− v = pe_getimport(S, v, &v2);
302+ v = pe_getimport(v, &v2);
300303 #endif
301304
302305 ft = v->type.t;
@@ -306,66 +309,66 @@ ST_FUNC void store(TCCState* S, int r, SValue *v) · 3 unmodified lines
306309 bt = ft & VT_BTYPE;
307310 /* XXX: incorrect if float reg to reg */
308311 if (bt == VT_FLOAT) {
309− o(S, 0xd9); /* fsts */
312+ o(0xd9); /* fsts */
310313 r = 2;
311314 } else if (bt == VT_DOUBLE) {
312− o(S, 0xdd); /* fstpl */
315+ o(0xdd); /* fstpl */
313316 r = 2;
314317 } else if (bt == VT_LDOUBLE) {
315− o(S, 0xc0d9); /* fld %st(0) */
316− o(S, 0xdb); /* fstpt */
318+ o(0xc0d9); /* fld %st(0) */
319+ o(0xdb); /* fstpt */
317320 r = 7;
318321 } else {
319322 if (bt == VT_SHORT)
320− o(S, 0x66);
323+ o(0x66);
321324 if (bt == VT_BYTE || bt == VT_BOOL)
322− o(S, 0x88);
325+ o(0x88);
323326 else
324− o(S, 0x89);
327+ o(0x89);
325328 }
326329 if (fr == VT_CONST ||
327330 fr == VT_LOCAL ||
328331 (v->r & VT_LVAL)) {
329− gen_modrm(S, r, v->r, v->sym, fc);
332+ gen_modrm(r, v->r, v->sym, fc);
330333 } else if (fr != r) {
331− o(S, 0xc0 + fr + r * 8); /* mov r, fr */
334+ o(0xc0 + fr + r * 8); /* mov r, fr */
332335 }
333336 }
334337
335−static void gadd_sp(TCCState* S, int val)
338+static void gadd_sp(int val)
336339 {
337340 if (val == (char)val) {
338− o(S, 0xc483);
339− g(S, val);
341+ o(0xc483);
342+ g(val);
340343 } else {
341− oad(S, 0xc481, val); /* add $xxx, %esp */
344+ oad(0xc481, val); /* add $xxx, %esp */
342345 }
343346 }
344347
345348 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_PE
346−static void gen_static_call(TCCState* S, int v)
349+static void gen_static_call(int v)
347350 {
348351 Sym *sym;
349352
350− sym = external_helper_sym(S, v);
351− oad(S, 0xe8, -4);
352− greloc(S, cur_text_section, sym, S->tccgen_ind-4, R_386_PC32);
353+ sym = external_helper_sym(v);
354+ oad(0xe8, -4);
355+ greloc(cur_text_section, sym, ind-4, R_386_PC32);
353356 }
354357 #endif
355358
356359 /* 'is_jmp' is '1' if it is a jump */
357−static void gcall_or_jmp(TCCState* S, int is_jmp)
360+static void gcall_or_jmp(int is_jmp)
358361 {
359362 int r;
360− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (S->tccgen_vtop->r & VT_SYM)) {
363+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) {
361364 /* constant and relocation case */
362− greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 1, R_386_PC32);
363− oad(S, 0xe8 + is_jmp, S->tccgen_vtop->c.i - 4); /* call/jmp im */
365+ greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32);
366+ oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */
364367 } else {
365368 /* otherwise, indirect call */
366− r = gv(S, RC_INT);
367− o(S, 0xff); /* call/jmp *r */
368− o(S, 0xd0 + r + (is_jmp << 4));
369+ r = gv(RC_INT);
370+ o(0xff); /* call/jmp *r */
371+ o(0xd0 + r + (is_jmp << 4));
369372 }
370373 }
371374
@@ -402,75 +405,75 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int · 30 unmodified lines
402405 /* Generate function call. The function address is pushed first, then
403406 all the parameters in call order. This functions pops all the
404407 parameters and the function address. */
405−ST_FUNC void gfunc_call(TCCState* S, int nb_args)
408+ST_FUNC void gfunc_call(int nb_args)
406409 {
407410 int size, align, r, args_size, i, func_call;
408411 Sym *func_sym;
409412
410413 #ifdef CONFIG_TCC_BCHECK
411− if (S->do_bounds_check)
412− gbound_args(S, nb_args);
414+ if (tcc_state->do_bounds_check)
415+ gbound_args(nb_args);
413416 #endif
414417
415418 args_size = 0;
416419 for(i = 0;i < nb_args; i++) {
417− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
418− size = type_size(&S->tccgen_vtop->type, &align);
420+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
421+ size = type_size(&vtop->type, &align);
419422 /* align to stack align size */
420423 size = (size + 3) & ~3;
421424 /* allocate the necessary size on stack */
422425 #ifdef TCC_TARGET_PE
423426 if (size >= 4096) {
424− r = get_reg(S, RC_EAX);
425− oad(S, 0x68, size); // push size
427+ r = get_reg(RC_EAX);
428+ oad(0x68, size); // push size
426429 /* cannot call normal 'alloca' with bound checking */
427− gen_static_call(S, tok_alloc_const(S, "__alloca"));
428− gadd_sp(S, 4);
430+ gen_static_call(tok_alloc_const("__alloca"));
431+ gadd_sp(4);
429432 } else
430433 #endif
431434 {
432− oad(S, 0xec81, size); /* sub $xxx, %esp */
435+ oad(0xec81, size); /* sub $xxx, %esp */
433436 /* generate structure store */
434− r = get_reg(S, RC_INT);
435− o(S, 0xe089 + (r << 8)); /* mov %esp, r */
437+ r = get_reg(RC_INT);
438+ o(0xe089 + (r << 8)); /* mov %esp, r */
436439 }
437− vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
438− vswap(S);
439− vstore(S);
440+ vset(&vtop->type, r | VT_LVAL, 0);
441+ vswap();
442+ vstore();
440443 args_size += size;
441− } else if (is_float(S->tccgen_vtop->type.t)) {
442− gv(S, RC_FLOAT); /* only one float register */
443− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT)
444+ } else if (is_float(vtop->type.t)) {
445+ gv(RC_FLOAT); /* only one float register */
446+ if ((vtop->type.t & VT_BTYPE) == VT_FLOAT)
444447 size = 4;
445− else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE)
448+ else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
446449 size = 8;
447450 else
448451 size = 12;
449− oad(S, 0xec81, size); /* sub $xxx, %esp */
452+ oad(0xec81, size); /* sub $xxx, %esp */
450453 if (size == 12)
451− o(S, 0x7cdb);
454+ o(0x7cdb);
452455 else
453− o(S, 0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */
454− g(S, 0x24);
455− g(S, 0x00);
456+ o(0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */
457+ g(0x24);
458+ g(0x00);
456459 args_size += size;
457460 } else {
458461 /* simple type (currently always same size) */
459462 /* XXX: implicit cast ? */
460− r = gv(S, RC_INT);
461− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
463+ r = gv(RC_INT);
464+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
462465 size = 8;
463− o(S, 0x50 + S->tccgen_vtop->r2); /* push r */
466+ o(0x50 + vtop->r2); /* push r */
464467 } else {
465468 size = 4;
466469 }
467− o(S, 0x50 + r); /* push r */
470+ o(0x50 + r); /* push r */
468471 args_size += size;
469472 }
470− S->tccgen_vtop--;
473+ vtop--;
471474 }
472− save_regs(S, 0); /* save used temporary registers */
473− func_sym = S->tccgen_vtop->type.ref;
475+ save_regs(0); /* save used temporary registers */
476+ func_sym = vtop->type.ref;
474477 func_call = func_sym->f.func_call;
475478 /* fast call case */
476479 if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) ||
@@ -487,21 +490,21 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args) · 10 unmodified lines
487490 for(i = 0;i < fastcall_nb_regs; i++) {
488491 if (args_size <= 0)
489492 break;
490− o(S, 0x58 + fastcall_regs_ptr[i]); /* pop r */
493+ o(0x58 + fastcall_regs_ptr[i]); /* pop r */
491494 /* XXX: incorrect for struct/floats */
492495 args_size -= 4;
493496 }
494497 }
495498 #if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD
496− else if ((S->tccgen_vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT)
499+ else if ((vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT)
497500 args_size -= 4;
498501 #endif
499502
500− gcall_or_jmp(S, 0);
503+ gcall_or_jmp(0);
501504
502505 if (args_size && func_call != FUNC_STDCALL && func_call != FUNC_FASTCALLW)
503− gadd_sp(S, args_size);
504− S->tccgen_vtop--;
506+ gadd_sp(args_size);
507+ vtop--;
505508 }
506509
507510 #ifdef TCC_TARGET_PE
@@ -511,7 +514,7 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args) · 3 unmodified lines
511514 #endif
512515
513516 /* generate function prolog of type 't' */
514−ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
517+ST_FUNC void gfunc_prolog(Sym *func_sym)
515518 {
516519 CType *func_type = &func_sym->type;
517520 int addr, align, size, func_call, fastcall_nb_regs;
@@ -523,8 +526,8 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 5 unmodified lines
523526 sym = func_type->ref;
524527 func_call = sym->f.func_call;
525528 addr = 8;
526− S->tccgen_loc = 0;
527− S->tccgen_func_vc = 0;
529+ loc = 0;
530+ func_vc = 0;
528531
529532 if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
530533 fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
@@ -538,19 +541,19 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 7 unmodified lines
538541 }
539542 param_index = 0;
540543
541− S->tccgen_ind += FUNC_PROLOG_SIZE;
542− func_sub_sp_offset = S->tccgen_ind;
544+ ind += FUNC_PROLOG_SIZE;
545+ func_sub_sp_offset = ind;
543546 /* if the function returns a structure, then add an
544547 implicit pointer parameter */
545548 #if defined(TCC_TARGET_PE) || TARGETOS_FreeBSD || TARGETOS_OpenBSD
546− size = type_size(&S->tccgen_func_vt,&align);
547− if (((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT)
549+ size = type_size(&func_vt,&align);
550+ if (((func_vt.t & VT_BTYPE) == VT_STRUCT)
548551 && (size > 8 || (size & (size - 1)))) {
549552 #else
550− if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT) {
553+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
551554 #endif
552555 /* XXX: fastcall case ? */
553− S->tccgen_func_vc = addr;
556+ func_vc = addr;
554557 addr += 4;
555558 param_index++;
556559 }
@@ -567,15 +570,15 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 10 unmodified lines
567570 #endif
568571 if (param_index < fastcall_nb_regs) {
569572 /* save FASTCALL register */
570− S->tccgen_loc -= 4;
571− o(S, 0x89); /* movl */
572− gen_modrm(S, fastcall_regs_ptr[param_index], VT_LOCAL, NULL, S->tccgen_loc);
573− param_addr = S->tccgen_loc;
573+ loc -= 4;
574+ o(0x89); /* movl */
575+ gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc);
576+ param_addr = loc;
574577 } else {
575578 param_addr = addr;
576579 addr += size;
577580 }
578− sym_push(S, sym->v & ~SYM_FIELD, type,
581+ sym_push(sym->v & ~SYM_FIELD, type,
579582 VT_LOCAL | VT_LVAL, param_addr);
580583 param_index++;
581584 }
@@ -584,94 +587,94 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 2 unmodified lines
584587 if (func_call == FUNC_STDCALL || func_call == FUNC_FASTCALLW)
585588 func_ret_sub = addr - 8;
586589 #if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD
587− else if (S->tccgen_func_vc)
590+ else if (func_vc)
588591 func_ret_sub = 4;
589592 #endif
590593
591594 #ifdef CONFIG_TCC_BCHECK
592− if (S->do_bounds_check)
593− gen_bounds_prolog(S);
595+ if (tcc_state->do_bounds_check)
596+ gen_bounds_prolog();
594597 #endif
595598 }
596599
597600 /* generate function epilog */
598−ST_FUNC void gfunc_epilog(TCCState* S)
601+ST_FUNC void gfunc_epilog(void)
599602 {
600603 addr_t v, saved_ind;
601604
602605 #ifdef CONFIG_TCC_BCHECK
603− if (S->do_bounds_check)
604− gen_bounds_epilog(S);
606+ if (tcc_state->do_bounds_check)
607+ gen_bounds_epilog();
605608 #endif
606609
607610 /* align local size to word & save local variables */
608− v = (-S->tccgen_loc + 3) & -4;
611+ v = (-loc + 3) & -4;
609612
610613 #if USE_EBX
611− o(S, 0x8b);
612− gen_modrm(S, TREG_EBX, VT_LOCAL, NULL, -(v+4));
614+ o(0x8b);
615+ gen_modrm(TREG_EBX, VT_LOCAL, NULL, -(v+4));
613616 #endif
614617
615− o(S, 0xc9); /* leave */
618+ o(0xc9); /* leave */
616619 if (func_ret_sub == 0) {
617− o(S, 0xc3); /* ret */
620+ o(0xc3); /* ret */
618621 } else {
619− o(S, 0xc2); /* ret n */
620− g(S, func_ret_sub);
621− g(S, func_ret_sub >> 8);
622+ o(0xc2); /* ret n */
623+ g(func_ret_sub);
624+ g(func_ret_sub >> 8);
622625 }
623− saved_ind = S->tccgen_ind;
624− S->tccgen_ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
626+ saved_ind = ind;
627+ ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
625628 #ifdef TCC_TARGET_PE
626629 if (v >= 4096) {
627− oad(S, 0xb8, v); /* mov stacksize, %eax */
628− gen_static_call(S, TOK___chkstk); /* call __chkstk, (does the stackframe too) */
630+ oad(0xb8, v); /* mov stacksize, %eax */
631+ gen_static_call(TOK___chkstk); /* call __chkstk, (does the stackframe too) */
629632 } else
630633 #endif
631634 {
632− o(S, 0xe58955); /* push %ebp, mov %esp, %ebp */
633− o(S, 0xec81); /* sub esp, stacksize */
634− gen_le32(S, v);
635+ o(0xe58955); /* push %ebp, mov %esp, %ebp */
636+ o(0xec81); /* sub esp, stacksize */
637+ gen_le32(v);
635638 #ifdef TCC_TARGET_PE
636− o(S, 0x90); /* adjust to FUNC_PROLOG_SIZE */
639+ o(0x90); /* adjust to FUNC_PROLOG_SIZE */
637640 #endif
638641 }
639− o(S, 0x53 * USE_EBX); /* push ebx */
640− S->tccgen_ind = saved_ind;
642+ o(0x53 * USE_EBX); /* push ebx */
643+ ind = saved_ind;
641644 }
642645
643646 /* generate a jump to a label */
644−ST_FUNC int gjmp(TCCState* S, int t)
647+ST_FUNC int gjmp(int t)
645648 {
646− return gjmp2(S, 0xe9, t);
649+ return gjmp2(0xe9, t);
647650 }
648651
649652 /* generate a jump to a fixed address */
650−ST_FUNC void gjmp_addr(TCCState* S, int a)
653+ST_FUNC void gjmp_addr(int a)
651654 {
652655 int r;
653− r = a - S->tccgen_ind - 2;
656+ r = a - ind - 2;
654657 if (r == (char)r) {
655− g(S, 0xeb);
656− g(S, r);
658+ g(0xeb);
659+ g(r);
657660 } else {
658− oad(S, 0xe9, a - S->tccgen_ind - 5);
661+ oad(0xe9, a - ind - 5);
659662 }
660663 }
661664
662665 #if 0
663666 /* generate a jump to a fixed address */
664−ST_FUNC void gjmp_cond_addr(TCCState* S, int a, int op)
667+ST_FUNC void gjmp_cond_addr(int a, int op)
665668 {
666− int r = a - S->tccgen_ind - 2;
669+ int r = a - ind - 2;
667670 if (r == (char)r)
668− g(S, op - 32), g(r);
671+ g(op - 32), g(r);
669672 else
670− g(S, 0x0f), gjmp2(S, op - 16, r - 4);
673+ g(0x0f), gjmp2(op - 16, r - 4);
671674 }
672675 #endif
673676
674−ST_FUNC int gjmp_append(TCCState* S, int n, int t)
677+ST_FUNC int gjmp_append(int n, int t)
675678 {
676679 void *p;
677680 /* insert vtop->c jump list in t */
@@ -685,14 +688,14 @@ ST_FUNC int gjmp_append(TCCState* S, int n, int t) · 7 unmodified lines
685688 return t;
686689 }
687690
688−ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
691+ST_FUNC int gjmp_cond(int op, int t)
689692 {
690− g(S, 0x0f);
691− t = gjmp2(S, op - 16, t);
693+ g(0x0f);
694+ t = gjmp2(op - 16, t);
692695 return t;
693696 }
694697
695−ST_FUNC void gen_opi(TCCState* S, int op)
698+ST_FUNC void gen_opi(int op)
696699 {
697700 int r, fr, opc, c;
698701
@@ -701,36 +704,36 @@ ST_FUNC void gen_opi(TCCState* S, int op) · 2 unmodified lines
701704 case TOK_ADDC1: /* add with carry generation */
702705 opc = 0;
703706 gen_op8:
704− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
707+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
705708 /* constant case */
706− vswap(S);
707− r = gv(S, RC_INT);
708− vswap(S);
709− c = S->tccgen_vtop->c.i;
709+ vswap();
710+ r = gv(RC_INT);
711+ vswap();
712+ c = vtop->c.i;
710713 if (c == (char)c) {
711714 /* generate inc and dec for smaller code */
712715 if ((c == 1 || c == -1) && (op == '+' || op == '-')) {
713716 opc = (c == 1) ^ (op == '+');
714− o(S, 0x40 | (opc << 3) | r); // inc,dec
717+ o (0x40 | (opc << 3) | r); // inc,dec
715718 } else {
716− o(S, 0x83);
717− o(S, 0xc0 | (opc << 3) | r);
718− g(S, c);
719+ o(0x83);
720+ o(0xc0 | (opc << 3) | r);
721+ g(c);
719722 }
720723 } else {
721− o(S, 0x81);
722− oad(S, 0xc0 | (opc << 3) | r, c);
724+ o(0x81);
725+ oad(0xc0 | (opc << 3) | r, c);
723726 }
724727 } else {
725− gv2(S, RC_INT, RC_INT);
726− r = S->tccgen_vtop[-1].r;
727− fr = S->tccgen_vtop[0].r;
728− o(S, (opc << 3) | 0x01);
729− o(S, 0xc0 + r + fr * 8);
728+ gv2(RC_INT, RC_INT);
729+ r = vtop[-1].r;
730+ fr = vtop[0].r;
731+ o((opc << 3) | 0x01);
732+ o(0xc0 + r + fr * 8);
730733 }
731− S->tccgen_vtop--;
734+ vtop--;
732735 if (op >= TOK_ULT && op <= TOK_GT)
733− vset_VT_CMP(S, op);
736+ vset_VT_CMP(op);
734737 break;
735738 case '-':
736739 case TOK_SUBC1: /* sub with carry generation */
@@ -752,12 +755,12 @@ ST_FUNC void gen_opi(TCCState* S, int op) · 15 unmodified lines
752755 opc = 1;
753756 goto gen_op8;
754757 case '*':
755− gv2(S, RC_INT, RC_INT);
756− r = S->tccgen_vtop[-1].r;
757− fr = S->tccgen_vtop[0].r;
758− S->tccgen_vtop--;
759− o(S, 0xaf0f); /* imul fr, r */
760− o(S, 0xc0 + fr + r * 8);
758+ gv2(RC_INT, RC_INT);
759+ r = vtop[-1].r;
760+ fr = vtop[0].r;
761+ vtop--;
762+ o(0xaf0f); /* imul fr, r */
763+ o(0xc0 + fr + r * 8);
761764 break;
762765 case TOK_SHL:
763766 opc = 4;
@@ -769,23 +772,23 @@ ST_FUNC void gen_opi(TCCState* S, int op) · 5 unmodified lines
769772 opc = 7;
770773 gen_shift:
771774 opc = 0xc0 | (opc << 3);
772− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
775+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
773776 /* constant case */
774− vswap(S);
775− r = gv(S, RC_INT);
776− vswap(S);
777− c = S->tccgen_vtop->c.i & 0x1f;
778− o(S, 0xc1); /* shl/shr/sar $xxx, r */
779− o(S, opc | r);
780− g(S, c);
777+ vswap();
778+ r = gv(RC_INT);
779+ vswap();
780+ c = vtop->c.i & 0x1f;
781+ o(0xc1); /* shl/shr/sar $xxx, r */
782+ o(opc | r);
783+ g(c);
781784 } else {
782785 /* we generate the shift in ecx */
783− gv2(S, RC_INT, RC_ECX);
784− r = S->tccgen_vtop[-1].r;
785− o(S, 0xd3); /* shl/shr/sar %cl, r */
786− o(S, opc | r);
786+ gv2(RC_INT, RC_ECX);
787+ r = vtop[-1].r;
788+ o(0xd3); /* shl/shr/sar %cl, r */
789+ o(opc | r);
787790 }
788− S->tccgen_vtop--;
791+ vtop--;
789792 break;
790793 case '/':
791794 case TOK_UDIV:
@@ -795,32 +798,32 @@ ST_FUNC void gen_opi(TCCState* S, int op) · 3 unmodified lines
795798 case TOK_UMULL:
796799 /* first operand must be in eax */
797800 /* XXX: need better constraint for second operand */
798− gv2(S, RC_EAX, RC_ECX);
799− r = S->tccgen_vtop[-1].r;
800− fr = S->tccgen_vtop[0].r;
801− S->tccgen_vtop--;
802− save_reg(S, TREG_EDX);
801+ gv2(RC_EAX, RC_ECX);
802+ r = vtop[-1].r;
803+ fr = vtop[0].r;
804+ vtop--;
805+ save_reg(TREG_EDX);
803806 /* save EAX too if used otherwise */
804− save_reg_upstack(S, TREG_EAX, 1);
807+ save_reg_upstack(TREG_EAX, 1);
805808 if (op == TOK_UMULL) {
806− o(S, 0xf7); /* mul fr */
807− o(S, 0xe0 + fr);
808− S->tccgen_vtop->r2 = TREG_EDX;
809+ o(0xf7); /* mul fr */
810+ o(0xe0 + fr);
811+ vtop->r2 = TREG_EDX;
809812 r = TREG_EAX;
810813 } else {
811814 if (op == TOK_UDIV || op == TOK_UMOD) {
812− o(S, 0xf7d231); /* xor %edx, %edx, div fr, %eax */
813− o(S, 0xf0 + fr);
815+ o(0xf7d231); /* xor %edx, %edx, div fr, %eax */
816+ o(0xf0 + fr);
814817 } else {
815− o(S, 0xf799); /* cltd, idiv fr, %eax */
816− o(S, 0xf8 + fr);
818+ o(0xf799); /* cltd, idiv fr, %eax */
819+ o(0xf8 + fr);
817820 }
818821 if (op == '%' || op == TOK_UMOD)
819822 r = TREG_EDX;
820823 else
821824 r = TREG_EAX;
822825 }
823− S->tccgen_vtop->r = r;
826+ vtop->r = r;
824827 break;
825828 default:
826829 opc = 7;
@@ -831,74 +834,74 @@ ST_FUNC void gen_opi(TCCState* S, int op) · 4 unmodified lines
831834 /* generate a floating point operation 'v = t1 op t2' instruction. The
832835 two operands are guaranteed to have the same floating point type */
833836 /* XXX: need to use ST1 too */
834−ST_FUNC void gen_opf(TCCState* S, int op)
837+ST_FUNC void gen_opf(int op)
835838 {
836839 int a, ft, fc, swapped, r;
837840
838841 if (op == TOK_NEG) { /* unary minus */
839− gv(S, RC_FLOAT);
840− o(S, 0xe0d9); /* fchs */
842+ gv(RC_FLOAT);
843+ o(0xe0d9); /* fchs */
841844 return;
842845 }
843846
844847 /* convert constants to memory references */
845− if ((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
846− vswap(S);
847− gv(S, RC_FLOAT);
848− vswap(S);
848+ if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
849+ vswap();
850+ gv(RC_FLOAT);
851+ vswap();
849852 }
850− if ((S->tccgen_vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
851− gv(S, RC_FLOAT);
853+ if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
854+ gv(RC_FLOAT);
852855
853856 /* must put at least one value in the floating point register */
854− if ((S->tccgen_vtop[-1].r & VT_LVAL) &&
855− (S->tccgen_vtop[0].r & VT_LVAL)) {
856− vswap(S);
857− gv(S, RC_FLOAT);
858− vswap(S);
857+ if ((vtop[-1].r & VT_LVAL) &&
858+ (vtop[0].r & VT_LVAL)) {
859+ vswap();
860+ gv(RC_FLOAT);
861+ vswap();
859862 }
860863 swapped = 0;
861864 /* swap the stack if needed so that t1 is the register and t2 is
862865 the memory reference */
863− if (S->tccgen_vtop[-1].r & VT_LVAL) {
864− vswap(S);
866+ if (vtop[-1].r & VT_LVAL) {
867+ vswap();
865868 swapped = 1;
866869 }
867870 if (op >= TOK_ULT && op <= TOK_GT) {
868871 /* load on stack second operand */
869− load(S, TREG_ST0, S->tccgen_vtop);
870− save_reg(S, TREG_EAX); /* eax is used by FP comparison code */
872+ load(TREG_ST0, vtop);
873+ save_reg(TREG_EAX); /* eax is used by FP comparison code */
871874 if (op == TOK_GE || op == TOK_GT)
872875 swapped = !swapped;
873876 else if (op == TOK_EQ || op == TOK_NE)
874877 swapped = 0;
875878 if (swapped)
876− o(S, 0xc9d9); /* fxch %st(1) */
879+ o(0xc9d9); /* fxch %st(1) */
877880 if (op == TOK_EQ || op == TOK_NE)
878− o(S, 0xe9da); /* fucompp */
881+ o(0xe9da); /* fucompp */
879882 else
880− o(S, 0xd9de); /* fcompp */
881− o(S, 0xe0df); /* fnstsw %ax */
883+ o(0xd9de); /* fcompp */
884+ o(0xe0df); /* fnstsw %ax */
882885 if (op == TOK_EQ) {
883− o(S, 0x45e480); /* and $0x45, %ah */
884− o(S, 0x40fC80); /* cmp $0x40, %ah */
886+ o(0x45e480); /* and $0x45, %ah */
887+ o(0x40fC80); /* cmp $0x40, %ah */
885888 } else if (op == TOK_NE) {
886− o(S, 0x45e480); /* and $0x45, %ah */
887− o(S, 0x40f480); /* xor $0x40, %ah */
889+ o(0x45e480); /* and $0x45, %ah */
890+ o(0x40f480); /* xor $0x40, %ah */
888891 op = TOK_NE;
889892 } else if (op == TOK_GE || op == TOK_LE) {
890− o(S, 0x05c4f6); /* test $0x05, %ah */
893+ o(0x05c4f6); /* test $0x05, %ah */
891894 op = TOK_EQ;
892895 } else {
893− o(S, 0x45c4f6); /* test $0x45, %ah */
896+ o(0x45c4f6); /* test $0x45, %ah */
894897 op = TOK_EQ;
895898 }
896− S->tccgen_vtop--;
897− vset_VT_CMP(S, op);
899+ vtop--;
900+ vset_VT_CMP(op);
898901 } else {
899902 /* no memory reference possible for long double operations */
900− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
901− load(S, TREG_ST0, S->tccgen_vtop);
903+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
904+ load(TREG_ST0, vtop);
902905 swapped = !swapped;
903906 }
904907
@@ -921,213 +924,213 @@ ST_FUNC void gen_opf(TCCState* S, int op) · 16 unmodified lines
921924 a++;
922925 break;
923926 }
924− ft = S->tccgen_vtop->type.t;
925− fc = S->tccgen_vtop->c.i;
927+ ft = vtop->type.t;
928+ fc = vtop->c.i;
926929 if ((ft & VT_BTYPE) == VT_LDOUBLE) {
927− o(S, 0xde); /* fxxxp %st, %st(1) */
928− o(S, 0xc1 + (a << 3));
930+ o(0xde); /* fxxxp %st, %st(1) */
931+ o(0xc1 + (a << 3));
929932 } else {
930933 /* if saved lvalue, then we must reload it */
931− r = S->tccgen_vtop->r;
934+ r = vtop->r;
932935 if ((r & VT_VALMASK) == VT_LLOCAL) {
933936 SValue v1;
934− r = get_reg(S, RC_INT);
937+ r = get_reg(RC_INT);
935938 v1.type.t = VT_INT;
936939 v1.r = VT_LOCAL | VT_LVAL;
937940 v1.c.i = fc;
938941 v1.sym = NULL;
939− load(S, r, &v1);
942+ load(r, &v1);
940943 fc = 0;
941944 }
942945
943946 if ((ft & VT_BTYPE) == VT_DOUBLE)
944− o(S, 0xdc);
947+ o(0xdc);
945948 else
946− o(S, 0xd8);
947− gen_modrm(S, a, r, S->tccgen_vtop->sym, fc);
949+ o(0xd8);
950+ gen_modrm(a, r, vtop->sym, fc);
948951 }
949− S->tccgen_vtop--;
952+ vtop--;
950953 }
951954 }
952955
953956 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
954957 and 'long long' cases. */
955−ST_FUNC void gen_cvt_itof(TCCState* S, int t)
958+ST_FUNC void gen_cvt_itof(int t)
956959 {
957− save_reg(S, TREG_ST0);
958− gv(S, RC_INT);
959− if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
960+ save_reg(TREG_ST0);
961+ gv(RC_INT);
962+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
960963 /* signed long long to float/double/long double (unsigned case
961964 is handled generically) */
962− o(S, 0x50 + S->tccgen_vtop->r2); /* push r2 */
963− o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
964− o(S, 0x242cdf); /* fildll (%esp) */
965− o(S, 0x08c483); /* add $8, %esp */
966− S->tccgen_vtop->r2 = VT_CONST;
967− } else if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
965+ o(0x50 + vtop->r2); /* push r2 */
966+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
967+ o(0x242cdf); /* fildll (%esp) */
968+ o(0x08c483); /* add $8, %esp */
969+ vtop->r2 = VT_CONST;
970+ } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
968971 (VT_INT | VT_UNSIGNED)) {
969972 /* unsigned int to float/double/long double */
970− o(S, 0x6a); /* push $0 */
971− g(S, 0x00);
972− o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
973− o(S, 0x242cdf); /* fildll (%esp) */
974− o(S, 0x08c483); /* add $8, %esp */
973+ o(0x6a); /* push $0 */
974+ g(0x00);
975+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
976+ o(0x242cdf); /* fildll (%esp) */
977+ o(0x08c483); /* add $8, %esp */
975978 } else {
976979 /* int to float/double/long double */
977− o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
978− o(S, 0x2404db); /* fildl (%esp) */
979− o(S, 0x04c483); /* add $4, %esp */
980+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
981+ o(0x2404db); /* fildl (%esp) */
982+ o(0x04c483); /* add $4, %esp */
980983 }
981− S->tccgen_vtop->r2 = VT_CONST;
982− S->tccgen_vtop->r = TREG_ST0;
984+ vtop->r2 = VT_CONST;
985+ vtop->r = TREG_ST0;
983986 }
984987
985988 /* convert fp to int 't' type */
986−ST_FUNC void gen_cvt_ftoi(TCCState* S, int t)
989+ST_FUNC void gen_cvt_ftoi(int t)
987990 {
988− int bt = S->tccgen_vtop->type.t & VT_BTYPE;
991+ int bt = vtop->type.t & VT_BTYPE;
989992 if (bt == VT_FLOAT)
990− vpush_helper_func(S, TOK___fixsfdi);
993+ vpush_helper_func(TOK___fixsfdi);
991994 else if (bt == VT_LDOUBLE)
992− vpush_helper_func(S, TOK___fixxfdi);
995+ vpush_helper_func(TOK___fixxfdi);
993996 else
994− vpush_helper_func(S, TOK___fixdfdi);
995− vswap(S);
996− gfunc_call(S, 1);
997− vpushi(S, 0);
998− S->tccgen_vtop->r = REG_IRET;
997+ vpush_helper_func(TOK___fixdfdi);
998+ vswap();
999+ gfunc_call(1);
1000+ vpushi(0);
1001+ vtop->r = REG_IRET;
9991002 if ((t & VT_BTYPE) == VT_LLONG)
1000− S->tccgen_vtop->r2 = REG_IRE2;
1003+ vtop->r2 = REG_IRE2;
10011004 }
10021005
10031006 /* convert from one floating point type to another */
1004−ST_FUNC void gen_cvt_ftof(TCCState* S, int t)
1007+ST_FUNC void gen_cvt_ftof(int t)
10051008 {
10061009 /* all we have to do on i386 is to put the float in a register */
1007− gv(S, RC_FLOAT);
1010+ gv(RC_FLOAT);
10081011 }
10091012
10101013 /* char/short to int conversion */
1011−ST_FUNC void gen_cvt_csti(TCCState* S, int t)
1014+ST_FUNC void gen_cvt_csti(int t)
10121015 {
10131016 int r, sz, xl;
1014− r = gv(S, RC_INT);
1017+ r = gv(RC_INT);
10151018 sz = !(t & VT_UNSIGNED);
10161019 xl = (t & VT_BTYPE) == VT_SHORT;
1017− o(S, 0xc0b60f /* mov[sz] %a[xl], %eax */
1020+ o(0xc0b60f /* mov[sz] %a[xl], %eax */
10181021 | (sz << 3 | xl) << 8
10191022 | (r << 3 | r) << 16
10201023 );
10211024 }
10221025
10231026 /* increment tcov counter */
1024−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
1027+ST_FUNC void gen_increment_tcov (SValue *sv)
10251028 {
1026− o(S, 0x0583); /* addl $1, xxx */
1027− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_386_32);
1028− gen_le32(S, 0);
1029− o(S, 1);
1030− o(S, 0x1583); /* addcl $0, xxx */
1031− greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_386_32);
1032− gen_le32(S, 4);
1033− g(S, 0);
1029+ o(0x0583); /* addl $1, xxx */
1030+ greloc(cur_text_section, sv->sym, ind, R_386_32);
1031+ gen_le32(0);
1032+ o(1);
1033+ o(0x1583); /* addcl $0, xxx */
1034+ greloc(cur_text_section, sv->sym, ind, R_386_32);
1035+ gen_le32(4);
1036+ g(0);
10341037 }
10351038
10361039 /* computed goto support */
1037−ST_FUNC void ggoto(TCCState* S)
1040+ST_FUNC void ggoto(void)
10381041 {
1039− gcall_or_jmp(S, 1);
1040− S->tccgen_vtop--;
1042+ gcall_or_jmp(1);
1043+ vtop--;
10411044 }
10421045
10431046 /* bound check support functions */
10441047 #ifdef CONFIG_TCC_BCHECK
10451048
1046−static void gen_bounds_prolog(TCCState* S)
1049+static void gen_bounds_prolog(void)
10471050 {
10481051 /* leave some room for bound checking code */
1049− S->func_bound_offset = lbounds_section->data_offset;
1050− S->func_bound_ind = S->tccgen_ind;
1051− S->func_bound_add_epilog = 0;
1052− oad(S, 0xb8, 0); /* lbound section pointer */
1053− oad(S, 0xb8, 0); /* call to function */
1052+ func_bound_offset = lbounds_section->data_offset;
1053+ func_bound_ind = ind;
1054+ func_bound_add_epilog = 0;
1055+ oad(0xb8, 0); /* lbound section pointer */
1056+ oad(0xb8, 0); /* call to function */
10541057 }
10551058
1056−static void gen_bounds_epilog(TCCState* S)
1059+static void gen_bounds_epilog(void)
10571060 {
10581061 addr_t saved_ind;
10591062 addr_t *bounds_ptr;
10601063 Sym *sym_data;
1061− int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
1064+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
10621065
1063− if (!offset_modified && !S->func_bound_add_epilog)
1066+ if (!offset_modified && !func_bound_add_epilog)
10641067 return;
10651068
10661069 /* add end of table info */
1067− bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
1070+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
10681071 *bounds_ptr = 0;
10691072
1070− sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
1071− S->func_bound_offset, lbounds_section->data_offset);
1073+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
1074+ func_bound_offset, lbounds_section->data_offset);
10721075
10731076 /* generate bound local allocation */
10741077 if (offset_modified) {
1075− saved_ind = S->tccgen_ind;
1076− S->tccgen_ind = S->func_bound_ind;
1077− greloc(S, cur_text_section, sym_data, S->tccgen_ind + 1, R_386_32);
1078− S->tccgen_ind = S->tccgen_ind + 5;
1079− gen_static_call(S, TOK___bound_local_new);
1080− S->tccgen_ind = saved_ind;
1078+ saved_ind = ind;
1079+ ind = func_bound_ind;
1080+ greloc(cur_text_section, sym_data, ind + 1, R_386_32);
1081+ ind = ind + 5;
1082+ gen_static_call(TOK___bound_local_new);
1083+ ind = saved_ind;
10811084 }
10821085
10831086 /* generate bound check local freeing */
1084− o(S, 0x5250); /* save returned value, if any */
1085− greloc(S, cur_text_section, sym_data, S->tccgen_ind + 1, R_386_32);
1086− oad(S, 0xb8, 0); /* mov %eax, xxx */
1087− gen_static_call(S, TOK___bound_local_delete);
1088− o(S, 0x585a); /* restore returned value, if any */
1087+ o(0x5250); /* save returned value, if any */
1088+ greloc(cur_text_section, sym_data, ind + 1, R_386_32);
1089+ oad(0xb8, 0); /* mov %eax, xxx */
1090+ gen_static_call(TOK___bound_local_delete);
1091+ o(0x585a); /* restore returned value, if any */
10891092 }
10901093 #endif
10911094
10921095 /* Save the stack pointer onto the stack */
1093−ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
1096+ST_FUNC void gen_vla_sp_save(int addr) {
10941097 /* mov %esp,addr(%ebp)*/
1095− o(S, 0x89);
1096− gen_modrm(S, TREG_ESP, VT_LOCAL, NULL, addr);
1098+ o(0x89);
1099+ gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr);
10971100 }
10981101
10991102 /* Restore the SP from a location on the stack */
1100−ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
1101− o(S, 0x8b);
1102− gen_modrm(S, TREG_ESP, VT_LOCAL, NULL, addr);
1103+ST_FUNC void gen_vla_sp_restore(int addr) {
1104+ o(0x8b);
1105+ gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr);
11031106 }
11041107
11051108 /* Subtract from the stack pointer, and push the resulting value onto the stack */
1106−ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
1109+ST_FUNC void gen_vla_alloc(CType *type, int align) {
11071110 int use_call = 0;
11081111
11091112 #if defined(CONFIG_TCC_BCHECK)
1110− use_call = S->do_bounds_check;
1113+ use_call = tcc_state->do_bounds_check;
11111114 #endif
11121115 #ifdef TCC_TARGET_PE /* alloca does more than just adjust %rsp on Windows */
11131116 use_call = 1;
11141117 #endif
11151118 if (use_call)
11161119 {
1117− vpush_helper_func(S, TOK_alloca);
1118− vswap(S); /* Move alloca ref past allocation size */
1119− gfunc_call(S, 1);
1120+ vpush_helper_func(TOK_alloca);
1121+ vswap(); /* Move alloca ref past allocation size */
1122+ gfunc_call(1);
11201123 }
11211124 else {
11221125 int r;
1123− r = gv(S, RC_INT); /* allocation size */
1126+ r = gv(RC_INT); /* allocation size */
11241127 /* sub r,%rsp */
1125− o(S, 0x2b);
1126− o(S, 0xe0 | r);
1128+ o(0x2b);
1129+ o(0xe0 | r);
11271130 /* We align to 16 bytes rather than align */
11281131 /* and ~15, %esp */
1129− o(S, 0xf0e483);
1130− vpop(S);
1132+ o(0xf0e483);
1133+ vpop();
11311134 }
11321135 }
11331136
i386-link.c+34−34
@@ -91,15 +91,15 @@ int gotplt_entry_type (int reloc_type) · 90 unmodified lines
9191 return -1;
9292 }
9393
94−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
94+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
9595 {
96− Section *plt = S->plt;
96+ Section *plt = s1->plt;
9797 uint8_t *p;
9898 int modrm;
9999 unsigned plt_offset, relofs;
100100
101101 /* on i386 if we build a DLL, we add a %ebx offset */
102− if (S->output_type == TCC_OUTPUT_DLL)
102+ if (s1->output_type == TCC_OUTPUT_DLL)
103103 modrm = 0xa3;
104104 else
105105 modrm = 0x25;
@@ -108,7 +108,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 2 unmodified lines
108108 (GOT + PTR_SIZE) and jumps to ld.so resolution routine
109109 (GOT + 2 * PTR_SIZE) */
110110 if (plt->data_offset == 0) {
111− p = section_ptr_add(S, plt, 16);
111+ p = section_ptr_add(plt, 16);
112112 p[0] = 0xff; /* pushl got + PTR_SIZE */
113113 p[1] = modrm + 0x10;
114114 write32le(p + 2, PTR_SIZE);
@@ -121,10 +121,10 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 6 unmodified lines
121121 /* The PLT slot refers to the relocation entry it needs via offset.
122122 The reloc entry is created below, so its offset is the current
123123 data_offset */
124− relofs = S->plt->reloc ? S->plt->reloc->data_offset : 0;
124+ relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
125125
126126 /* Jump to GOT entry where ld.so initially put the address of ip + 4 */
127− p = section_ptr_add(S, plt, 16);
127+ p = section_ptr_add(plt, 16);
128128 p[0] = 0xff; /* jmp *(got + x) */
129129 p[1] = modrm;
130130 write32le(p + 2, got_offset);
@@ -137,31 +137,31 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a · 6 unmodified lines
137137
138138 /* relocate the PLT: compute addresses and offsets in the PLT now that final
139139 address for PLT and GOT are known (see fill_program_header) */
140−ST_FUNC void relocate_plt(TCCState *S)
140+ST_FUNC void relocate_plt(TCCState *s1)
141141 {
142142 uint8_t *p, *p_end;
143143
144− if (!S->plt)
144+ if (!s1->plt)
145145 return;
146146
147− p = S->plt->data;
148− p_end = p + S->plt->data_offset;
147+ p = s1->plt->data;
148+ p_end = p + s1->plt->data_offset;
149149
150− if (S->output_type != TCC_OUTPUT_DLL && p < p_end) {
151− add32le(p + 2, S->got->sh_addr);
152− add32le(p + 8, S->got->sh_addr);
150+ if (s1->output_type != TCC_OUTPUT_DLL && p < p_end) {
151+ add32le(p + 2, s1->got->sh_addr);
152+ add32le(p + 8, s1->got->sh_addr);
153153 p += 16;
154154 while (p < p_end) {
155− add32le(p + 2, S->got->sh_addr);
155+ add32le(p + 2, s1->got->sh_addr);
156156 p += 16;
157157 }
158158 }
159159
160− if (S->plt->reloc) {
160+ if (s1->plt->reloc) {
161161 ElfW_Rel *rel;
162− int x = S->plt->sh_addr + 16 + 6;
163− p = S->got->data;
164− for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
162+ int x = s1->plt->sh_addr + 16 + 6;
163+ p = s1->got->data;
164+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
165165 write32le(p + rel->r_offset, x);
166166 x += 16;
167167 }
@@ -169,7 +169,7 @@ ST_FUNC void relocate_plt(TCCState *S) · 1 unmodified line
169169 }
170170 #endif
171171
172−void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
172+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
173173 {
174174 int sym_index, esym_index;
175175
@@ -177,8 +177,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 1 unmodified line
177177
178178 switch (type) {
179179 case R_386_32:
180− if (S->output_type == TCC_OUTPUT_DLL) {
181− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
180+ if (s1->output_type == TCC_OUTPUT_DLL) {
181+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
182182 qrel->r_offset = rel->r_offset;
183183 if (esym_index) {
184184 qrel->r_info = ELFW(R_INFO)(esym_index, R_386_32);
@@ -192,9 +192,9 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 7 unmodified lines
192192 add32le(ptr, val);
193193 return;
194194 case R_386_PC32:
195− if (S->output_type == TCC_OUTPUT_DLL) {
195+ if (s1->output_type == TCC_OUTPUT_DLL) {
196196 /* DLL relocation */
197− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
197+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
198198 if (esym_index) {
199199 qrel->r_offset = rel->r_offset;
200200 qrel->r_info = ELFW(R_INFO)(esym_index, R_386_PC32);
@@ -212,31 +212,31 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 11 unmodified lines
212212 write32le(ptr, val);
213213 return;
214214 case R_386_GOTPC:
215− add32le(ptr, S->got->sh_addr - addr);
215+ add32le(ptr, s1->got->sh_addr - addr);
216216 return;
217217 case R_386_GOTOFF:
218− add32le(ptr, val - S->got->sh_addr);
218+ add32le(ptr, val - s1->got->sh_addr);
219219 return;
220220 case R_386_GOT32:
221221 case R_386_GOT32X:
222222 /* we load the got offset */
223− add32le(ptr, get_sym_attr(S, sym_index, 0)->got_offset);
223+ add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
224224 return;
225225 case R_386_16:
226− if (S->output_format != TCC_OUTPUT_FORMAT_BINARY) {
226+ if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
227227 output_file:
228− tcc_error(S, "can only produce 16-bit binary files");
228+ tcc_error("can only produce 16-bit binary files");
229229 }
230230 write16le(ptr, read16le(ptr) + val);
231231 return;
232232 case R_386_PC16:
233− if (S->output_format != TCC_OUTPUT_FORMAT_BINARY)
233+ if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY)
234234 goto output_file;
235235 write16le(ptr, read16le(ptr) + val - addr);
236236 return;
237237 case R_386_RELATIVE:
238238 #ifdef TCC_TARGET_PE
239− add32le(ptr, val - S->pe_imagebase);
239+ add32le(ptr, val - s1->pe_imagebase);
240240 #endif
241241 /* do nothing */
242242 return;
@@ -267,12 +267,12 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 24 unmodified lines
267267 memcpy(ptr-3, replace, sizeof(replace));
268268 rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
269269 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
270− sec = S->sections[sym->st_shndx];
270+ sec = s1->sections[sym->st_shndx];
271271 x = sym->st_value - sec->sh_addr - sec->data_offset;
272272 add32le(ptr + 5, -x);
273273 }
274274 else
275− tcc_error(S, "unexpected R_386_TLS_GD pattern");
275+ tcc_error("unexpected R_386_TLS_GD pattern");
276276 }
277277 return;
278278 case R_386_TLS_LDM:
@@ -295,7 +295,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 16 unmodified lines
295295 rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
296296 }
297297 else
298− tcc_error(S, "unexpected R_386_TLS_LDM pattern");
298+ tcc_error("unexpected R_386_TLS_LDM pattern");
299299 }
300300 return;
301301 case R_386_TLS_LDO_32:
@@ -306,7 +306,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a · 4 unmodified lines
306306 int32_t x;
307307
308308 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
309− sec = S->sections[sym->st_shndx];
309+ sec = s1->sections[sym->st_shndx];
310310 x = val - sec->sh_addr - sec->data_offset;
311311 add32le(ptr, x);
312312 }
libtcc.c+393−470
@@ -65,6 +65,7 @@ · 64 unmodified lines
6565 /* global variables */
6666
6767 /* XXX: get rid of this ASAP (or maybe not) */
68+ST_DATA struct TCCState *tcc_state;
6869 TCC_SEM(static tcc_compile_sem);
6970
7071 #ifdef MEM_DEBUG
@@ -110,11 +111,11 @@ static inline char *config_tccdir_w32(char *path) · 39 unmodified lines
110111 #endif
111112
112113 #ifdef TCC_TARGET_PE
113−static void tcc_add_systemdir(TCCState *S)
114+static void tcc_add_systemdir(TCCState *s)
114115 {
115116 char buf[1000];
116117 GetSystemDirectory(buf, sizeof buf);
117− tcc_add_library_path(S, normalize_slashes(buf));
118+ tcc_add_library_path(s, normalize_slashes(buf));
118119 }
119120 #endif
120121 #endif
@@ -159,19 +160,19 @@ ST_FUNC void post_sem(TCCSem *p) · 38 unmodified lines
159160 #endif
160161 #endif
161162
162−PUB_FUNC void tcc_enter_state(TCCState *S)
163+PUB_FUNC void tcc_enter_state(TCCState *s1)
163164 {
164− if (S->error_set_jmp_enabled)
165+ if (s1->error_set_jmp_enabled)
165166 return;
166167 WAIT_SEM(&tcc_compile_sem);
167− /*S = S;*/
168+ tcc_state = s1;
168169 }
169170
170−PUB_FUNC void tcc_exit_state(TCCState *S)
171+PUB_FUNC void tcc_exit_state(TCCState *s1)
171172 {
172− if (S->error_set_jmp_enabled)
173+ if (s1->error_set_jmp_enabled)
173174 return;
174− S = NULL;
175+ tcc_state = NULL;
175176 POST_SEM(&tcc_compile_sem);
176177 }
177178
@@ -233,10 +234,10 @@ PUB_FUNC char *tcc_fileextension (const char *name) · 55 unmodified lines
233234 return e ? e : strchr(b, 0);
234235 }
235236
236−ST_FUNC char *tcc_load_text(TCCState* S, int fd)
237+ST_FUNC char *tcc_load_text(int fd)
237238 {
238239 int len = lseek(fd, 0, SEEK_END);
239− char *buf = load_data(S, fd, 0, len + 1);
240+ char *buf = load_data(fd, 0, len + 1);
240241 buf[len] = 0;
241242 return buf;
242243 }
@@ -248,69 +249,44 @@ ST_FUNC char *tcc_load_text(TCCState* S, int fd) · 5 unmodified lines
248249 #undef malloc
249250 #undef realloc
250251
251−PUB_FUNC void tcc_free_base(void *ptr)
252−{
253− free(ptr);
254−}
255−
256−PUB_FUNC void *tcc_malloc_base(unsigned long size)
257−{
258− void *ptr;
259− ptr = malloc(size);
260− if (!ptr && size) {
261− printf("memory full (malloc)\n");
262− exit(1);
263− }
264− return ptr;
265−}
266−
267−PUB_FUNC void *tcc_mallocz_base(unsigned long size)
268−{
269− void *ptr;
270− ptr = tcc_malloc_base(size);
271− if (size)
272− memset(ptr, 0, size);
273− return ptr;
274−}
275−
276252 #ifndef MEM_DEBUG
277253
278−PUB_FUNC void tcc_free(TCCState* S, void *ptr)
254+PUB_FUNC void tcc_free(void *ptr)
279255 {
280256 free(ptr);
281257 }
282258
283−PUB_FUNC void *tcc_malloc(TCCState* S, unsigned long size)
259+PUB_FUNC void *tcc_malloc(unsigned long size)
284260 {
285261 void *ptr;
286262 ptr = malloc(size);
287263 if (!ptr && size)
288− _tcc_error(S, "memory full (malloc)");
264+ _tcc_error("memory full (malloc)");
289265 return ptr;
290266 }
291267
292−PUB_FUNC void *tcc_mallocz(TCCState* S, unsigned long size)
268+PUB_FUNC void *tcc_mallocz(unsigned long size)
293269 {
294270 void *ptr;
295− ptr = tcc_malloc(S, size);
271+ ptr = tcc_malloc(size);
296272 if (size)
297273 memset(ptr, 0, size);
298274 return ptr;
299275 }
300276
301−PUB_FUNC void *tcc_realloc(TCCState* S, void *ptr, unsigned long size)
277+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
302278 {
303279 void *ptr1;
304280 ptr1 = realloc(ptr, size);
305281 if (!ptr1 && size)
306− _tcc_error(S, "memory full (realloc)");
282+ _tcc_error("memory full (realloc)");
307283 return ptr1;
308284 }
309285
310−PUB_FUNC char *tcc_strdup(TCCState* S, const char *str)
286+PUB_FUNC char *tcc_strdup(const char *str)
311287 {
312288 char *ptr;
313− ptr = tcc_malloc(S, strlen(str) + 1);
289+ ptr = tcc_malloc(strlen(str) + 1);
314290 strcpy(ptr, str);
315291 return ptr;
316292 }
@@ -361,14 +337,14 @@ static mem_debug_header_t *malloc_check(void *ptr, const char *msg) · 44 unmodified lines
361337 return header;
362338 }
363339
364−PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *file, int line)
340+PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line)
365341 {
366342 int ofs;
367343 mem_debug_header_t *header;
368344
369345 header = malloc(sizeof(mem_debug_header_t) + size);
370346 if (!header)
371− _tcc_error(S, "memory full (malloc)");
347+ _tcc_error("memory full (malloc)");
372348
373349 header->magic1 = MEM_DEBUG_MAGIC1;
374350 header->magic2 = MEM_DEBUG_MAGIC2;
@@ -392,7 +368,7 @@ PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *fil · 17 unmodified lines
392368 return MEM_USER_PTR(header);
393369 }
394370
395−PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr)
371+PUB_FUNC void tcc_free_debug(void *ptr)
396372 {
397373 mem_debug_header_t *header;
398374 if (!ptr)
@@ -409,26 +385,26 @@ PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr) · 10 unmodified lines
409385 free(header);
410386 }
411387
412−PUB_FUNC void *tcc_mallocz_debug(TCCState* S, unsigned long size, const char *file, int line)
388+PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line)
413389 {
414390 void *ptr;
415− ptr = tcc_malloc_debug(S, size,file,line);
391+ ptr = tcc_malloc_debug(size,file,line);
416392 memset(ptr, 0, size);
417393 return ptr;
418394 }
419395
420−PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, const char *file, int line)
396+PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line)
421397 {
422398 mem_debug_header_t *header;
423399 int mem_debug_chain_update = 0;
424400 if (!ptr)
425− return tcc_malloc_debug(S, size, file, line);
401+ return tcc_malloc_debug(size, file, line);
426402 header = malloc_check(ptr, "tcc_realloc");
427403 mem_cur_size -= header->size;
428404 mem_debug_chain_update = (header == mem_debug_chain);
429405 header = realloc(header, sizeof(mem_debug_header_t) + size);
430406 if (!header)
431− _tcc_error(S, "memory full (realloc)");
407+ _tcc_error("memory full (realloc)");
432408 header->size = size;
433409 write32le(MEM_DEBUG_CHECK3(header), MEM_DEBUG_MAGIC3);
434410 if (header->next)
@@ -443,10 +419,10 @@ PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, con · 8 unmodified lines
443419 return MEM_USER_PTR(header);
444420 }
445421
446−PUB_FUNC char *tcc_strdup_debug(TCCState* S, const char *str, const char *file, int line)
422+PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line)
447423 {
448424 char *ptr;
449− ptr = tcc_malloc_debug(S, strlen(str) + 1, file, line);
425+ ptr = tcc_malloc_debug(strlen(str) + 1, file, line);
450426 strcpy(ptr, str);
451427 return ptr;
452428 }
@@ -473,66 +449,10 @@ PUB_FUNC void tcc_memcheck(void) · 20 unmodified lines
473449 #define malloc(s) use_tcc_malloc(s)
474450 #define realloc(p, s) use_tcc_realloc(p, s)
475451
476−/********************************************************/
477−/* virtual io */
478−
479−LIBTCCAPI void tcc_set_vio_module(TCCState *S, vio_module_t *vio_module){
480− S->vio_module = vio_module;
481− vio_module->S = S;
482−}
483−
484−void vio_initialize(vio_fd *fd) {
485− fd->fd = -1;
486− fd->vio_udata = NULL;
487− fd->vio_module = NULL;
488−}
489−
490−int vio_open(struct TCCState *S, vio_fd *fd, const char *fn, int oflag) {
491− int rc;
492− vio_initialize(fd);
493− fd->vio_module = S->vio_module;
494− if(S->vio_module && (S->vio_module->call_vio_open_flags & CALL_VIO_OPEN_FIRST)) {
495− rc = S->vio_module->vio_open(fd, fn, oflag);
496− if(rc >= 0) return rc;
497− }
498−
499− fd->fd = open(fn, oflag);
500−
501− if(fd->fd < 0 && S->vio_module && (S->vio_module->call_vio_open_flags & CALL_VIO_OPEN_LAST)) {
502− rc = S->vio_module->vio_open(fd, fn, oflag);
503− if(rc >= 0) return rc;
504− }
505− //printf("vio_open = %d %s\n", fd->fd, fn);
506− return fd->fd;
507−}
508−
509−off_t vio_lseek(vio_fd fd, off_t offset, int whence) {
510− if(fd.vio_udata) {
511− return fd.vio_module->vio_lseek(fd, offset, whence);
512− }
513− return lseek(fd.fd, offset, whence);
514−}
515−
516−size_t vio_read(vio_fd fd, void *buf, size_t bytes) {
517− if(fd.vio_udata) {
518− return fd.vio_module->vio_read(fd, buf, bytes);
519− }
520− return read(fd.fd, buf, bytes);
521−}
522−
523−int vio_close(vio_fd *fd) {
524− int rc = 0;
525− if(fd->vio_udata){
526− fd->vio_module->vio_close(fd);
527− } else rc = close(fd->fd);
528− vio_initialize(fd);
529− return rc;
530−}
531−
532452 /********************************************************/
533453 /* dynarrays */
534454
535−ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data)
455+ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data)
536456 {
537457 int nb, nb_alloc;
538458 void **pp;
@@ -545,54 +465,54 @@ ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data) · 6 unmodified lines
545465 nb_alloc = 1;
546466 else
547467 nb_alloc = nb * 2;
548− pp = tcc_realloc(S, pp, nb_alloc * sizeof(void *));
468+ pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
549469 *(void***)ptab = pp;
550470 }
551471 pp[nb++] = data;
552472 *nb_ptr = nb;
553473 }
554474
555−ST_FUNC void dynarray_reset(TCCState* S, void *pp, int *n)
475+ST_FUNC void dynarray_reset(void *pp, int *n)
556476 {
557477 void **p;
558478 for (p = *(void***)pp; *n; ++p, --*n)
559479 if (*p)
560− tcc_free(S, *p);
561− tcc_free(S, *(void**)pp);
480+ tcc_free(*p);
481+ tcc_free(*(void**)pp);
562482 *(void**)pp = NULL;
563483 }
564484
565−static void tcc_split_path(TCCState *S, void *p_ary, int *p_nb_ary, const char *in)
485+static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in)
566486 {
567487 const char *p;
568488 do {
569489 int c;
570490 CString str;
571491
572− cstr_new(S, &str);
492+ cstr_new(&str);
573493 for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) {
574494 if (c == '{' && p[1] && p[2] == '}') {
575495 c = p[1], p += 2;
576496 if (c == 'B')
577− cstr_cat(S, &str, S->tcc_lib_path, -1);
578− if (c == 'f' && S->tccpp_file) {
497+ cstr_cat(&str, s->tcc_lib_path, -1);
498+ if (c == 'f' && file) {
579499 /* substitute current file's dir */
580− const char *f = S->tccpp_file->true_filename;
500+ const char *f = file->true_filename;
581501 const char *b = tcc_basename(f);
582502 if (b > f)
583− cstr_cat(S, &str, f, b - f - 1);
503+ cstr_cat(&str, f, b - f - 1);
584504 else
585− cstr_cat(S, &str, ".", 1);
505+ cstr_cat(&str, ".", 1);
586506 }
587507 } else {
588− cstr_ccat(S, &str, c);
508+ cstr_ccat(&str, c);
589509 }
590510 }
591511 if (str.size) {
592− cstr_ccat(S, &str, '\0');
593− dynarray_add(S, p_ary, p_nb_ary, tcc_strdup(S, str.data));
512+ cstr_ccat(&str, '\0');
513+ dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data));
594514 }
595− cstr_free(S, &str);
515+ cstr_free(&str);
596516 in = p+1;
597517 } while (*p);
598518 }
@@ -608,26 +528,27 @@ static void tcc_split_path(TCCState *S, void *p_ary, int *p_nb_ary, const char * · 9 unmodified lines
608528 /* error1() modes */
609529 enum { ERROR_WARN, ERROR_NOABORT, ERROR_ERROR };
610530
611−static void error1(TCCState* S, int mode, const char *fmt, va_list ap)
531+static void error1(int mode, const char *fmt, va_list ap)
612532 {
613533 BufferedFile **pf, *f;
534+ TCCState *s1 = tcc_state;
614535 CString cs;
615536
616− cstr_new(S, &cs);
537+ cstr_new(&cs);
617538
618− if (S == NULL)
539+ if (s1 == NULL)
619540 /* can happen only if called from tcc_malloc(): 'out of memory' */
620541 goto no_file;
621542
622− tcc_exit_state(S);
543+ tcc_exit_state(s1);
623544
624545 if (mode == ERROR_WARN) {
625− if (S->warn_error)
546+ if (s1->warn_error)
626547 mode = ERROR_ERROR;
627− if (S->warn_num) {
548+ if (s1->warn_num) {
628549 /* handle tcc_warning_c(warn_option)(fmt, ...) */
629− int wopt = *(&S->warn_none + S->warn_num);
630− S->warn_num = 0;
550+ int wopt = *(&s1->warn_none + s1->warn_num);
551+ s1->warn_num = 0;
631552 if (0 == (wopt & WARN_ON))
632553 return;
633554 if (wopt & WARN_ERR)
@@ -635,102 +556,102 @@ static void error1(TCCState* S, int mode, const char *fmt, va_list ap) · 1 unmodified line
635556 if (wopt & WARN_NOE)
636557 mode = ERROR_WARN;
637558 }
638− if (S->warn_none)
559+ if (s1->warn_none)
639560 return;
640561 }
641562
642563 f = NULL;
643− if (S->error_set_jmp_enabled) { /* we're called while parsing a file */
564+ if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */
644565 /* use upper file if inline ":asm:" or token ":paste:" */
645− for (f = S->tccpp_file; f && f->filename[0] == ':'; f = f->prev)
566+ for (f = file; f && f->filename[0] == ':'; f = f->prev)
646567 ;
647568 }
648569 if (f) {
649− for(pf = S->include_stack; pf < S->include_stack_ptr; pf++)
650− cstr_printf(S, &cs, "In file included from %s:%d:\n",
570+ for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
571+ cstr_printf(&cs, "In file included from %s:%d:\n",
651572 (*pf)->filename, (*pf)->line_num);
652− cstr_printf(S, &cs, "%s:%d: ",
653− f->filename, (*pf)->line_num - !!(S->tccpp_tok_flags & TOK_FLAG_BOL));
654− } else if (S->current_filename) {
655− cstr_printf(S, &cs, "%s: ", S->current_filename);
573+ cstr_printf(&cs, "%s:%d: ",
574+ f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
575+ } else if (s1->current_filename) {
576+ cstr_printf(&cs, "%s: ", s1->current_filename);
656577 }
657578
658579 no_file:
659580 if (0 == cs.size)
660− cstr_printf(S, &cs, "tcc: ");
661− cstr_printf(S, &cs, mode == ERROR_WARN ? "warning: " : "error: ");
662− cstr_vprintf(S, &cs, fmt, ap);
663− if (!S || !S->error_func) {
581+ cstr_printf(&cs, "tcc: ");
582+ cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: ");
583+ cstr_vprintf(&cs, fmt, ap);
584+ if (!s1 || !s1->error_func) {
664585 /* default case: stderr */
665− if (S && S->output_type == TCC_OUTPUT_PREPROCESS && S->ppfp == stdout)
586+ if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout)
666587 printf("\n"); /* print a newline during tcc -E */
667588 fflush(stdout); /* flush -v output */
668589 fprintf(stderr, "%s\n", (char*)cs.data);
669590 fflush(stderr); /* print error/warning now (win32) */
670591 } else {
671− S->error_func(S->error_opaque, (char*)cs.data);
592+ s1->error_func(s1->error_opaque, (char*)cs.data);
672593 }
673− cstr_free(S, &cs);
674− if (S) {
594+ cstr_free(&cs);
595+ if (s1) {
675596 if (mode != ERROR_WARN)
676− S->nb_errors++;
597+ s1->nb_errors++;
677598 if (mode != ERROR_ERROR)
678599 return;
679− if (S->error_set_jmp_enabled)
680− longjmp(S->error_jmp_buf, 1);
600+ if (s1->error_set_jmp_enabled)
601+ longjmp(s1->error_jmp_buf, 1);
681602 }
682603 exit(1);
683604 }
684605
685−LIBTCCAPI void tcc_set_error_func(TCCState *S, void *error_opaque, TCCErrorFunc error_func)
606+LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func)
686607 {
687− S->error_opaque = error_opaque;
688− S->error_func = error_func;
608+ s->error_opaque = error_opaque;
609+ s->error_func = error_func;
689610 }
690611
691−LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *S)
612+LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s)
692613 {
693− return S->error_func;
614+ return s->error_func;
694615 }
695616
696−LIBTCCAPI void *tcc_get_error_opaque(TCCState *S)
617+LIBTCCAPI void *tcc_get_error_opaque(TCCState *s)
697618 {
698− return S->error_opaque;
619+ return s->error_opaque;
699620 }
700621
701622 /* error without aborting current compilation */
702−PUB_FUNC void _tcc_error_noabort(TCCState* S, const char *fmt, ...)
623+PUB_FUNC void _tcc_error_noabort(const char *fmt, ...)
703624 {
704625 va_list ap;
705626 va_start(ap, fmt);
706− error1(S, ERROR_NOABORT, fmt, ap);
627+ error1(ERROR_NOABORT, fmt, ap);
707628 va_end(ap);
708629 }
709630
710−PUB_FUNC void _tcc_error(TCCState* S, const char *fmt, ...)
631+PUB_FUNC void _tcc_error(const char *fmt, ...)
711632 {
712633 va_list ap;
713634 va_start(ap, fmt);
714− for (;;) error1(S, ERROR_ERROR, fmt, ap);
635+ for (;;) error1(ERROR_ERROR, fmt, ap);
715636 }
716637
717−PUB_FUNC void _tcc_warning(TCCState* S, const char *fmt, ...)
638+PUB_FUNC void _tcc_warning(const char *fmt, ...)
718639 {
719640 va_list ap;
720641 va_start(ap, fmt);
721− error1(S, ERROR_WARN, fmt, ap);
642+ error1(ERROR_WARN, fmt, ap);
722643 va_end(ap);
723644 }
724645
725646 /********************************************************/
726647 /* I/O layer */
727648
728−ST_FUNC void tcc_open_bf(TCCState *S, const char *filename, int initlen)
649+ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen)
729650 {
730651 BufferedFile *bf;
731652 int buflen = initlen ? initlen : IO_BUF_SIZE;
732653
733− bf = tcc_mallocz(S, sizeof(BufferedFile) + buflen);
654+ bf = tcc_mallocz(sizeof(BufferedFile) + buflen);
734655 bf->buf_ptr = bf->buffer;
735656 bf->buf_end = bf->buffer + initlen;
736657 bf->buf_end[0] = CH_EOB; /* put eob symbol */
@@ -740,51 +661,52 @@ ST_FUNC void tcc_open_bf(TCCState *S, const char *filename, int initlen) · 3 unmodified lines
740661 #endif
741662 bf->true_filename = bf->filename;
742663 bf->line_num = 1;
743− bf->ifdef_stack_ptr = S->ifdef_stack_ptr;
664+ bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
744665 bf->fd = -1;
745− bf->prev = S->tccpp_file;
746− S->tccpp_file = bf;
747− S->tccpp_tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
666+ bf->prev = file;
667+ file = bf;
668+ tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
748669 }
749670
750−ST_FUNC void tcc_close(TCCState* S)
671+ST_FUNC void tcc_close(void)
751672 {
752− BufferedFile *bf = S->tccpp_file;
673+ TCCState *s1 = tcc_state;
674+ BufferedFile *bf = file;
753675 if (bf->fd > 0) {
754676 close(bf->fd);
755677 total_lines += bf->line_num;
756678 }
757679 if (bf->true_filename != bf->filename)
758− tcc_free(S, bf->true_filename);
759− S->tccpp_file = bf->prev;
760− tcc_free(S, bf);
680+ tcc_free(bf->true_filename);
681+ file = bf->prev;
682+ tcc_free(bf);
761683 }
762684
763−static int _tcc_open(TCCState *S, const char *filename)
685+static int _tcc_open(TCCState *s1, const char *filename)
764686 {
765687 int fd;
766688 if (strcmp(filename, "-") == 0)
767689 fd = 0, filename = "<stdin>";
768690 else
769691 fd = open(filename, O_RDONLY | O_BINARY);
770− if ((S->verbose == 2 && fd >= 0) || S->verbose == 3)
692+ if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
771693 printf("%s %*s%s\n", fd < 0 ? "nf":"->",
772− (int)(S->include_stack_ptr - S->include_stack), "", filename);
694+ (int)(s1->include_stack_ptr - s1->include_stack), "", filename);
773695 return fd;
774696 }
775697
776−ST_FUNC int tcc_open(TCCState *S, const char *filename)
698+ST_FUNC int tcc_open(TCCState *s1, const char *filename)
777699 {
778− int fd = _tcc_open(S, filename);
700+ int fd = _tcc_open(s1, filename);
779701 if (fd < 0)
780702 return -1;
781− tcc_open_bf(S, filename, 0);
782− S->tccpp_file->fd = fd;
703+ tcc_open_bf(s1, filename, 0);
704+ file->fd = fd;
783705 return 0;
784706 }
785707
786708 /* compile the file opened in 'file'. Return non zero if errors. */
787−static int tcc_compile(TCCState *S, int filetype, const char *str, int fd)
709+static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
788710 {
789711 /* Here we enter the code section where we use the global variables for
790712 parsing and code generation (tccpp.c, tccgen.c, <target>-gen.c).
@@ -793,62 +715,62 @@ static int tcc_compile(TCCState *S, int filetype, const char *str, int fd) · 2 unmodified lines
793715 Alternatively we could use thread local storage for those global
794716 variables, which may or may not have advantages */
795717
796− tcc_enter_state(S);
797− S->error_set_jmp_enabled = 1;
718+ tcc_enter_state(s1);
719+ s1->error_set_jmp_enabled = 1;
798720
799− if (setjmp(S->error_jmp_buf) == 0) {
800− S->nb_errors = 0;
721+ if (setjmp(s1->error_jmp_buf) == 0) {
722+ s1->nb_errors = 0;
801723
802724 if (fd == -1) {
803725 int len = strlen(str);
804− tcc_open_bf(S, "<string>", len);
805− memcpy(S->tccpp_file->buffer, str, len);
726+ tcc_open_bf(s1, "<string>", len);
727+ memcpy(file->buffer, str, len);
806728 } else {
807− tcc_open_bf(S, str, 0);
808− S->tccpp_file->fd = fd;
729+ tcc_open_bf(s1, str, 0);
730+ file->fd = fd;
809731 }
810732
811− tccelf_begin_file(S);
812− preprocess_start(S, filetype);
813− tccgen_init(S);
814− if (S->output_type == TCC_OUTPUT_PREPROCESS) {
815− tcc_preprocess(S);
733+ tccelf_begin_file(s1);
734+ preprocess_start(s1, filetype);
735+ tccgen_init(s1);
736+ if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
737+ tcc_preprocess(s1);
816738 } else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
817− tcc_assemble(S, !!(filetype & AFF_TYPE_ASMPP));
739+ tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
818740 } else {
819− tccgen_compile(S);
741+ tccgen_compile(s1);
820742 }
821743 }
822− tccgen_finish(S);
823− preprocess_end(S);
744+ tccgen_finish(s1);
745+ preprocess_end(s1);
824746
825− S->error_set_jmp_enabled = 0;
826− tcc_exit_state(S);
747+ s1->error_set_jmp_enabled = 0;
748+ tcc_exit_state(s1);
827749
828− tccelf_end_file(S);
829− return S->nb_errors != 0 ? -1 : 0;
750+ tccelf_end_file(s1);
751+ return s1->nb_errors != 0 ? -1 : 0;
830752 }
831753
832−LIBTCCAPI int tcc_compile_string(TCCState *S, const char *str)
754+LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
833755 {
834− return tcc_compile(S, S->filetype, str, -1);
756+ return tcc_compile(s, s->filetype, str, -1);
835757 }
836758
837759 /* define a preprocessor symbol. value can be NULL, sym can be "sym=val" */
838−LIBTCCAPI void tcc_define_symbol(TCCState *S, const char *sym, const char *value)
760+LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
839761 {
840762 const char *eq;
841763 if (NULL == (eq = strchr(sym, '=')))
842764 eq = strchr(sym, 0);
843765 if (NULL == value)
844766 value = *eq ? eq + 1 : "1";
845− cstr_printf(S, &S->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value);
767+ cstr_printf(&s1->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value);
846768 }
847769
848770 /* undefine a preprocessor symbol */
849−LIBTCCAPI void tcc_undefine_symbol(TCCState *S, const char *sym)
771+LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym)
850772 {
851− cstr_printf(S, &S->cmdline_defs, "#undef %s\n", sym);
773+ cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym);
852774 }
853775
854776
@@ -856,7 +778,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 1 unmodified line
856778 {
857779 TCCState *s;
858780
859− s = tcc_mallocz_base(sizeof(TCCState));
781+ s = tcc_mallocz(sizeof(TCCState));
860782 if (!s)
861783 return NULL;
862784 #ifdef MEM_DEBUG
@@ -898,153 +820,153 @@ LIBTCCAPI TCCState *tcc_new(void) · 35 unmodified lines
898820 return s;
899821 }
900822
901−LIBTCCAPI void tcc_delete(TCCState *S)
823+LIBTCCAPI void tcc_delete(TCCState *s1)
902824 {
903825 /* free sections */
904− tccelf_delete(S);
826+ tccelf_delete(s1);
905827
906828 /* free library paths */
907− dynarray_reset(S, &S->library_paths, &S->nb_library_paths);
908− dynarray_reset(S, &S->crt_paths, &S->nb_crt_paths);
829+ dynarray_reset(&s1->library_paths, &s1->nb_library_paths);
830+ dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths);
909831
910832 /* free include paths */
911− dynarray_reset(S, &S->include_paths, &S->nb_include_paths);
912− dynarray_reset(S, &S->sysinclude_paths, &S->nb_sysinclude_paths);
913−
914− tcc_free(S, S->tcc_lib_path);
915− tcc_free(S, S->soname);
916− tcc_free(S, S->rpath);
917− tcc_free(S, S->init_symbol);
918− tcc_free(S, S->fini_symbol);
919− tcc_free(S, S->outfile);
920− tcc_free(S, S->deps_outfile);
921− dynarray_reset(S, &S->files, &S->nb_files);
922− dynarray_reset(S, &S->target_deps, &S->nb_target_deps);
923− dynarray_reset(S, &S->pragma_libs, &S->nb_pragma_libs);
924− dynarray_reset(S, &S->argv, &S->argc);
925− cstr_free(S, &S->cmdline_defs);
926− cstr_free(S, &S->cmdline_incl);
833+ dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
834+ dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
835+
836+ tcc_free(s1->tcc_lib_path);
837+ tcc_free(s1->soname);
838+ tcc_free(s1->rpath);
839+ tcc_free(s1->init_symbol);
840+ tcc_free(s1->fini_symbol);
841+ tcc_free(s1->outfile);
842+ tcc_free(s1->deps_outfile);
843+ dynarray_reset(&s1->files, &s1->nb_files);
844+ dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
845+ dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs);
846+ dynarray_reset(&s1->argv, &s1->argc);
847+ cstr_free(&s1->cmdline_defs);
848+ cstr_free(&s1->cmdline_incl);
927849 #ifdef TCC_IS_NATIVE
928850 /* free runtime memory */
929− tcc_run_free(S);
851+ tcc_run_free(s1);
930852 #endif
931853
932− tcc_free_base(S);
854+ tcc_free(s1);
933855 #ifdef MEM_DEBUG
934856 if (0 == --nb_states)
935857 tcc_memcheck();
936858 #endif
937859 }
938860
939−LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type)
861+LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
940862 {
941− S->output_type = output_type;
863+ s->output_type = output_type;
942864
943− if (!S->nostdinc) {
865+ if (!s->nostdinc) {
944866 /* default include paths */
945867 /* -isystem paths have already been handled */
946− tcc_add_sysinclude_path(S, CONFIG_TCC_SYSINCLUDEPATHS);
868+ tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
947869 }
948870 #ifdef CONFIG_TCC_BCHECK
949− if (S->do_bounds_check) {
871+ if (s->do_bounds_check) {
950872 /* if bound checking, then add corresponding sections */
951− tccelf_bounds_new(S);
873+ tccelf_bounds_new(s);
952874 }
953875 #endif
954− if (S->do_debug) {
876+ if (s->do_debug) {
955877 /* add debug sections */
956− tccelf_stab_new(S);
878+ tccelf_stab_new(s);
957879 }
958880 if (output_type == TCC_OUTPUT_OBJ) {
959881 /* always elf for objects */
960− S->output_format = TCC_OUTPUT_FORMAT_ELF;
882+ s->output_format = TCC_OUTPUT_FORMAT_ELF;
961883 return 0;
962884 }
963885
964− tcc_add_library_path(S, CONFIG_TCC_LIBPATHS);
886+ tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
965887
966888 #ifdef TCC_TARGET_PE
967889 # ifdef _WIN32
968890 /* allow linking with system dll's directly */
969− tcc_add_systemdir(S);
891+ tcc_add_systemdir(s);
970892 # endif
971893 /* target PE has its own startup code in libtcc1.a */
972894 return 0;
973895
974896 #elif defined TCC_TARGET_MACHO
975897 # ifdef TCC_IS_NATIVE
976− tcc_add_macos_sdkpath(S);
898+ tcc_add_macos_sdkpath(s);
977899 # endif
978900 /* Mach-O with LC_MAIN doesn't need any crt startup code. */
979901 return 0;
980902
981903 #else
982904 /* paths for crt objects */
983− tcc_split_path(S, &S->crt_paths, &S->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
905+ tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
984906 /* add libc crt1/crti objects */
985907 if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
986− !S->nostdlib) {
908+ !s->nostdlib) {
987909 #if TARGETOS_OpenBSD
988910 if (output_type != TCC_OUTPUT_DLL)
989− tcc_add_crt(S, "crt0.o");
911+ tcc_add_crt(s, "crt0.o");
990912 if (output_type == TCC_OUTPUT_DLL)
991− tcc_add_crt(S, "crtbeginS.o");
913+ tcc_add_crt(s, "crtbeginS.o");
992914 else
993− tcc_add_crt(S, "crtbegin.o");
915+ tcc_add_crt(s, "crtbegin.o");
994916 #elif TARGETOS_FreeBSD
995917 if (output_type != TCC_OUTPUT_DLL)
996− tcc_add_crt(S, "crt1.o");
997− tcc_add_crt(S, "crti.o");
998− if (S->static_link)
999− tcc_add_crt(S, "crtbeginT.o");
918+ tcc_add_crt(s, "crt1.o");
919+ tcc_add_crt(s, "crti.o");
920+ if (s->static_link)
921+ tcc_add_crt(s, "crtbeginT.o");
1000922 else if (output_type == TCC_OUTPUT_DLL)
1001− tcc_add_crt(S, "crtbeginS.o");
923+ tcc_add_crt(s, "crtbeginS.o");
1002924 else
1003− tcc_add_crt(S, "crtbegin.o");
925+ tcc_add_crt(s, "crtbegin.o");
1004926 #elif TARGETOS_NetBSD
1005927 if (output_type != TCC_OUTPUT_DLL)
1006− tcc_add_crt(S, "crt0.o");
1007− tcc_add_crt(S, "crti.o");
1008− if (S->static_link)
1009− tcc_add_crt(S, "crtbeginT.o");
928+ tcc_add_crt(s, "crt0.o");
929+ tcc_add_crt(s, "crti.o");
930+ if (s->static_link)
931+ tcc_add_crt(s, "crtbeginT.o");
1010932 else if (output_type == TCC_OUTPUT_DLL)
1011− tcc_add_crt(S, "crtbeginS.o");
933+ tcc_add_crt(s, "crtbeginS.o");
1012934 else
1013− tcc_add_crt(S, "crtbegin.o");
935+ tcc_add_crt(s, "crtbegin.o");
1014936 #else
1015937 if (output_type != TCC_OUTPUT_DLL)
1016− tcc_add_crt(S, "crt1.o");
1017− tcc_add_crt(S, "crti.o");
938+ tcc_add_crt(s, "crt1.o");
939+ tcc_add_crt(s, "crti.o");
1018940 #endif
1019941 }
1020942 return 0;
1021943 #endif
1022944 }
1023945
1024−LIBTCCAPI int tcc_add_include_path(TCCState *S, const char *pathname)
946+LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
1025947 {
1026− tcc_split_path(S, &S->include_paths, &S->nb_include_paths, pathname);
948+ tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
1027949 return 0;
1028950 }
1029951
1030−LIBTCCAPI int tcc_add_sysinclude_path(TCCState *S, const char *pathname)
952+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname)
1031953 {
1032− tcc_split_path(S, &S->sysinclude_paths, &S->nb_sysinclude_paths, pathname);
954+ tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname);
1033955 return 0;
1034956 }
1035957
1036−ST_FUNC DLLReference *tcc_add_dllref(TCCState *S, const char *dllname)
958+ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname)
1037959 {
1038− DLLReference *ref = tcc_mallocz(S, sizeof(DLLReference) + strlen(dllname));
960+ DLLReference *ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname));
1039961 strcpy(ref->name, dllname);
1040− dynarray_add(S, &S->loaded_dlls, &S->nb_loaded_dlls, ref);
962+ dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref);
1041963 return ref;
1042964 }
1043965
1044966 /* OpenBSD: choose latest from libxxx.so.x.y versions */
1045967 #if defined TARGETOS_OpenBSD && !defined _WIN32
1046968 #include <glob.h>
1047−static int tcc_glob_so(TCCState *S, const char *pattern, char *buf, int size)
969+static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
1048970 {
1049971 const char *star;
1050972 glob_t g;
@@ -1066,25 +988,25 @@ static int tcc_glob_so(TCCState *S, const char *pattern, char *buf, int size) · 15 unmodified lines
1066988 }
1067989 #endif
1068990
1069−ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags)
991+ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
1070992 {
1071993 int fd, ret = -1;
1072994
1073995 #if defined TARGETOS_OpenBSD && !defined _WIN32
1074996 char buf[1024];
1075− if (tcc_glob_so(S, filename, buf, sizeof buf) >= 0)
997+ if (tcc_glob_so(s1, filename, buf, sizeof buf) >= 0)
1076998 filename = buf;
1077999 #endif
10781000
10791001 /* open the file */
1080− fd = _tcc_open(S, filename);
1002+ fd = _tcc_open(s1, filename);
10811003 if (fd < 0) {
10821004 if (flags & AFF_PRINT_ERROR)
1083− tcc_error_noabort(S, "file '%s' not found", filename);
1005+ tcc_error_noabort("file '%s' not found", filename);
10841006 return ret;
10851007 }
10861008
1087− S->current_filename = filename;
1009+ s1->current_filename = filename;
10881010 if (flags & AFF_TYPE_BIN) {
10891011 ElfW(Ehdr) ehdr;
10901012 int obj_type;
@@ -1095,22 +1017,22 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags) · 4 unmodified lines
10951017 switch (obj_type) {
10961018
10971019 case AFF_BINTYPE_REL:
1098− ret = tcc_load_object_file(S, fd, 0);
1020+ ret = tcc_load_object_file(s1, fd, 0);
10991021 break;
11001022
11011023 case AFF_BINTYPE_AR:
1102− ret = tcc_load_archive(S, fd, !(flags & AFF_WHOLE_ARCHIVE));
1024+ ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE));
11031025 break;
11041026
11051027 #ifdef TCC_TARGET_PE
11061028 default:
1107− ret = pe_load_file(S, fd, filename);
1029+ ret = pe_load_file(s1, fd, filename);
11081030 goto check_success;
11091031
11101032 #elif defined TCC_TARGET_MACHO
11111033 case AFF_BINTYPE_DYN:
11121034 case_dyn_or_tbd:
1113− if (S->output_type == TCC_OUTPUT_MEMORY) {
1035+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
11141036 #ifdef TCC_IS_NATIVE
11151037 void* dl;
11161038 const char* soname = filename;
@@ -1118,14 +1040,14 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags) · 1 unmodified line
11181040 soname = macho_tbd_soname(filename);
11191041 dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY);
11201042 if (dl)
1121− tcc_add_dllref(S, soname)->handle = dl, ret = 0;
1043+ tcc_add_dllref(s1, soname)->handle = dl, ret = 0;
11221044 if (filename != soname)
1123− tcc_free(S, (void *)soname);
1045+ tcc_free((void *)soname);
11241046 #endif
11251047 } else if (obj_type == AFF_BINTYPE_DYN) {
1126− ret = macho_load_dll(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
1048+ ret = macho_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
11271049 } else {
1128− ret = macho_load_tbd(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
1050+ ret = macho_load_tbd(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
11291051 }
11301052 break;
11311053 default:
@@ -1142,47 +1064,47 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags) · 10 unmodified lines
11421064
11431065 #else /* unix */
11441066 case AFF_BINTYPE_DYN:
1145− if (S->output_type == TCC_OUTPUT_MEMORY) {
1067+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
11461068 #ifdef TCC_IS_NATIVE
11471069 void* dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
11481070 if (dl)
1149− tcc_add_dllref(S, filename)->handle = dl, ret = 0;
1071+ tcc_add_dllref(s1, filename)->handle = dl, ret = 0;
11501072 #endif
11511073 } else
1152− ret = tcc_load_dll(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
1074+ ret = tcc_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
11531075 break;
11541076
11551077 default:
11561078 /* as GNU ld, consider it is an ld script if not recognized */
1157− ret = tcc_load_ldscript(S, fd);
1079+ ret = tcc_load_ldscript(s1, fd);
11581080 goto check_success;
11591081
11601082 #endif /* pe / macos / unix */
11611083
11621084 check_success:
11631085 if (ret < 0)
1164− tcc_error_noabort(S, "%s: unrecognized file type", filename);
1086+ tcc_error_noabort("%s: unrecognized file type", filename);
11651087 break;
11661088
11671089 #ifdef TCC_TARGET_COFF
11681090 case AFF_BINTYPE_C67:
1169− ret = tcc_load_coff(S, fd);
1091+ ret = tcc_load_coff(s1, fd);
11701092 break;
11711093 #endif
11721094 }
11731095 close(fd);
11741096 } else {
11751097 /* update target deps */
1176− dynarray_add(S, &S->target_deps, &S->nb_target_deps, tcc_strdup(S, filename));
1177− ret = tcc_compile(S, flags, filename, fd);
1098+ dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename));
1099+ ret = tcc_compile(s1, flags, filename, fd);
11781100 }
1179− S->current_filename = NULL;
1101+ s1->current_filename = NULL;
11801102 return ret;
11811103 }
11821104
1183−LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename)
1105+LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
11841106 {
1185− int filetype = S->filetype;
1107+ int filetype = s->filetype;
11861108 if (0 == (filetype & AFF_TYPE_MASK)) {
11871109 /* use a file extension to detect a filetype */
11881110 const char *ext = tcc_fileextension(filename);
@@ -1202,16 +1124,16 @@ LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename) · 13 unmodified lines
12021124 filetype = AFF_TYPE_C;
12031125 }
12041126 }
1205− return tcc_add_file_internal(S, filename, filetype | AFF_PRINT_ERROR);
1127+ return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR);
12061128 }
12071129
1208−LIBTCCAPI int tcc_add_library_path(TCCState *S, const char *pathname)
1130+LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
12091131 {
1210− tcc_split_path(S, &S->library_paths, &S->nb_library_paths, pathname);
1132+ tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname);
12111133 return 0;
12121134 }
12131135
1214−static int tcc_add_library_internal(TCCState *S, const char *fmt,
1136+static int tcc_add_library_internal(TCCState *s, const char *fmt,
12151137 const char *filename, int flags, char **paths, int nb_paths)
12161138 {
12171139 char buf[1024];
@@ -1219,7 +1141,7 @@ static int tcc_add_library_internal(TCCState *S, const char *fmt, · 1 unmodified line
12191141
12201142 for(i = 0; i < nb_paths; i++) {
12211143 snprintf(buf, sizeof(buf), fmt, paths[i], filename);
1222− if (tcc_add_file_internal(S, buf, flags | AFF_TYPE_BIN) == 0)
1144+ if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0)
12231145 return 0;
12241146 }
12251147 return -1;
@@ -1228,87 +1150,87 @@ static int tcc_add_library_internal(TCCState *S, const char *fmt, · 2 unmodified lines
12281150 #ifndef TCC_TARGET_MACHO
12291151 /* find and load a dll. Return non zero if not found */
12301152 /* XXX: add '-rpath' option support ? */
1231−ST_FUNC int tcc_add_dll(TCCState *S, const char *filename, int flags)
1153+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
12321154 {
1233− return tcc_add_library_internal(S, "%s/%s", filename, flags,
1234− S->library_paths, S->nb_library_paths);
1155+ return tcc_add_library_internal(s, "%s/%s", filename, flags,
1156+ s->library_paths, s->nb_library_paths);
12351157 }
12361158 #endif
12371159
12381160 #if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO
1239−ST_FUNC int tcc_add_crt(TCCState *S, const char *filename)
1161+ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)
12401162 {
1241− if (-1 == tcc_add_library_internal(S, "%s/%s",
1242− filename, 0, S->crt_paths, S->nb_crt_paths))
1243− tcc_error_noabort(S, "file '%s' not found", filename);
1163+ if (-1 == tcc_add_library_internal(s1, "%s/%s",
1164+ filename, 0, s1->crt_paths, s1->nb_crt_paths))
1165+ tcc_error_noabort("file '%s' not found", filename);
12441166 return 0;
12451167 }
12461168 #endif
12471169
12481170 /* the library name is the same as the argument of the '-l' option */
1249−LIBTCCAPI int tcc_add_library(TCCState *S, const char *libraryname)
1171+LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
12501172 {
12511173 #if defined TCC_TARGET_PE
12521174 static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
1253− const char * const *pp = S->static_link ? libs + 4 : libs;
1175+ const char * const *pp = s->static_link ? libs + 4 : libs;
12541176 #elif defined TCC_TARGET_MACHO
12551177 static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL };
1256− const char * const *pp = S->static_link ? libs + 2 : libs;
1178+ const char * const *pp = s->static_link ? libs + 2 : libs;
12571179 #elif defined TARGETOS_OpenBSD
12581180 static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL };
1259− const char * const *pp = S->static_link ? libs + 1 : libs;
1181+ const char * const *pp = s->static_link ? libs + 1 : libs;
12601182 #else
12611183 static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
1262− const char * const *pp = S->static_link ? libs + 1 : libs;
1184+ const char * const *pp = s->static_link ? libs + 1 : libs;
12631185 #endif
1264− int flags = S->filetype & AFF_WHOLE_ARCHIVE;
1186+ int flags = s->filetype & AFF_WHOLE_ARCHIVE;
12651187 while (*pp) {
1266− if (0 == tcc_add_library_internal(S, *pp,
1267− libraryname, flags, S->library_paths, S->nb_library_paths))
1188+ if (0 == tcc_add_library_internal(s, *pp,
1189+ libraryname, flags, s->library_paths, s->nb_library_paths))
12681190 return 0;
12691191 ++pp;
12701192 }
12711193 return -1;
12721194 }
12731195
1274−PUB_FUNC int tcc_add_library_err(TCCState *S, const char *libname)
1196+PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname)
12751197 {
1276− int ret = tcc_add_library(S, libname);
1198+ int ret = tcc_add_library(s1, libname);
12771199 if (ret < 0)
1278− tcc_error_noabort(S, "library '%s' not found", libname);
1200+ tcc_error_noabort("library '%s' not found", libname);
12791201 return ret;
12801202 }
12811203
12821204 /* handle #pragma comment(lib,) */
1283−ST_FUNC void tcc_add_pragma_libs(TCCState *S)
1205+ST_FUNC void tcc_add_pragma_libs(TCCState *s1)
12841206 {
12851207 int i;
1286− for (i = 0; i < S->nb_pragma_libs; i++)
1287− tcc_add_library_err(S, S->pragma_libs[i]);
1208+ for (i = 0; i < s1->nb_pragma_libs; i++)
1209+ tcc_add_library_err(s1, s1->pragma_libs[i]);
12881210 }
12891211
1290−LIBTCCAPI int tcc_add_symbol(TCCState *S, const char *name, const void *val)
1212+LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val)
12911213 {
12921214 #ifdef TCC_TARGET_PE
12931215 /* On x86_64 'val' might not be reachable with a 32bit offset.
12941216 So it is handled here as if it were in a DLL. */
1295− pe_putimport(S, 0, name, (uintptr_t)val);
1217+ pe_putimport(s1, 0, name, (uintptr_t)val);
12961218 #else
12971219 char buf[256];
1298− if (S->leading_underscore) {
1220+ if (s1->leading_underscore) {
12991221 buf[0] = '_';
13001222 pstrcpy(buf + 1, sizeof(buf) - 1, name);
13011223 name = buf;
13021224 }
1303− set_global_sym(S, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */
1225+ set_global_sym(s1, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */
13041226 #endif
13051227 return 0;
13061228 }
13071229
1308−LIBTCCAPI void tcc_set_lib_path(TCCState *S, const char *path)
1230+LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
13091231 {
1310− tcc_free(S, S->tcc_lib_path);
1311− S->tcc_lib_path = tcc_strdup(S, path);
1232+ tcc_free(s->tcc_lib_path);
1233+ s->tcc_lib_path = tcc_strdup(path);
13121234 }
13131235
13141236 /********************************************************/
@@ -1388,7 +1310,7 @@ static const char *skip_linker_arg(const char **str) · 73 unmodified lines
13881310 return s2;
13891311 }
13901312
1391−static void copy_linker_arg(TCCState* S, char **pp, const char *s, int sep)
1313+static void copy_linker_arg(char **pp, const char *s, int sep)
13921314 {
13931315 const char *q = s;
13941316 char *p = *pp;
@@ -1396,12 +1318,13 @@ static void copy_linker_arg(TCCState* S, char **pp, const char *s, int sep) · 1 unmodified line
13961318 if (p && sep)
13971319 p[l = strlen(p)] = sep, ++l;
13981320 skip_linker_arg(&q);
1399− pstrncpy(l + (*pp = tcc_realloc(S, p, q - s + l + 1)), s, q - s);
1321+ pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s);
14001322 }
14011323
14021324 /* set linker options */
1403−static int tcc_set_linker(TCCState *S, const char *option)
1325+static int tcc_set_linker(TCCState *s, const char *option)
14041326 {
1327+ TCCState *s1 = s;
14051328 while (*option) {
14061329
14071330 const char *p = NULL;
@@ -1410,18 +1333,18 @@ static int tcc_set_linker(TCCState *S, const char *option) · 2 unmodified lines
14101333 int ret;
14111334
14121335 if (link_option(option, "Bsymbolic", &p)) {
1413− S->symbolic = 1;
1336+ s->symbolic = 1;
14141337 } else if (link_option(option, "nostdlib", &p)) {
1415− S->nostdlib = 1;
1338+ s->nostdlib = 1;
14161339 } else if (link_option(option, "fini=", &p)) {
1417− copy_linker_arg(S, &S->fini_symbol, p, 0);
1340+ copy_linker_arg(&s->fini_symbol, p, 0);
14181341 ignoring = 1;
14191342 } else if (link_option(option, "image-base=", &p)
14201343 || link_option(option, "Ttext=", &p)) {
1421− S->text_addr = strtoull(p, &end, 16);
1422− S->has_text_addr = 1;
1344+ s->text_addr = strtoull(p, &end, 16);
1345+ s->has_text_addr = 1;
14231346 } else if (link_option(option, "init=", &p)) {
1424− copy_linker_arg(S, &S->init_symbol, p, 0);
1347+ copy_linker_arg(&s->init_symbol, p, 0);
14251348 ignoring = 1;
14261349 } else if (link_option(option, "oformat=", &p)) {
14271350 #if defined(TCC_TARGET_PE)
@@ -1431,12 +1354,12 @@ static int tcc_set_linker(TCCState *S, const char *option) · 3 unmodified lines
14311354 #else
14321355 if (strstart("elf32-", &p)) {
14331356 #endif
1434− S->output_format = TCC_OUTPUT_FORMAT_ELF;
1357+ s->output_format = TCC_OUTPUT_FORMAT_ELF;
14351358 } else if (!strcmp(p, "binary")) {
1436− S->output_format = TCC_OUTPUT_FORMAT_BINARY;
1359+ s->output_format = TCC_OUTPUT_FORMAT_BINARY;
14371360 #ifdef TCC_TARGET_COFF
14381361 } else if (!strcmp(p, "coff")) {
1439− S->output_format = TCC_OUTPUT_FORMAT_COFF;
1362+ s->output_format = TCC_OUTPUT_FORMAT_COFF;
14401363 #endif
14411364 } else
14421365 goto err;
@@ -1446,64 +1369,64 @@ static int tcc_set_linker(TCCState *S, const char *option) · 3 unmodified lines
14461369 } else if (link_option(option, "O", &p)) {
14471370 ignoring = 1;
14481371 } else if (link_option(option, "export-all-symbols", &p)) {
1449− S->rdynamic = 1;
1372+ s->rdynamic = 1;
14501373 } else if (link_option(option, "export-dynamic", &p)) {
1451− S->rdynamic = 1;
1374+ s->rdynamic = 1;
14521375 } else if (link_option(option, "rpath=", &p)) {
1453− copy_linker_arg(S, &S->rpath, p, ':');
1376+ copy_linker_arg(&s->rpath, p, ':');
14541377 } else if (link_option(option, "enable-new-dtags", &p)) {
1455− S->enable_new_dtags = 1;
1378+ s->enable_new_dtags = 1;
14561379 } else if (link_option(option, "section-alignment=", &p)) {
1457− S->section_align = strtoul(p, &end, 16);
1380+ s->section_align = strtoul(p, &end, 16);
14581381 } else if (link_option(option, "soname=", &p)) {
1459− copy_linker_arg(S, &S->soname, p, 0);
1382+ copy_linker_arg(&s->soname, p, 0);
14601383 #ifdef TCC_TARGET_PE
14611384 } else if (link_option(option, "large-address-aware", &p)) {
1462− S->pe_characteristics |= 0x20;
1385+ s->pe_characteristics |= 0x20;
14631386 } else if (link_option(option, "file-alignment=", &p)) {
1464− S->pe_file_align = strtoul(p, &end, 16);
1387+ s->pe_file_align = strtoul(p, &end, 16);
14651388 } else if (link_option(option, "stack=", &p)) {
1466− S->pe_stack_size = strtoul(p, &end, 10);
1389+ s->pe_stack_size = strtoul(p, &end, 10);
14671390 } else if (link_option(option, "subsystem=", &p)) {
14681391 #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
14691392 if (!strcmp(p, "native")) {
1470− S->pe_subsystem = 1;
1393+ s->pe_subsystem = 1;
14711394 } else if (!strcmp(p, "console")) {
1472− S->pe_subsystem = 3;
1395+ s->pe_subsystem = 3;
14731396 } else if (!strcmp(p, "gui") || !strcmp(p, "windows")) {
1474− S->pe_subsystem = 2;
1397+ s->pe_subsystem = 2;
14751398 } else if (!strcmp(p, "posix")) {
1476− S->pe_subsystem = 7;
1399+ s->pe_subsystem = 7;
14771400 } else if (!strcmp(p, "efiapp")) {
1478− S->pe_subsystem = 10;
1401+ s->pe_subsystem = 10;
14791402 } else if (!strcmp(p, "efiboot")) {
1480− S->pe_subsystem = 11;
1403+ s->pe_subsystem = 11;
14811404 } else if (!strcmp(p, "efiruntime")) {
1482− S->pe_subsystem = 12;
1405+ s->pe_subsystem = 12;
14831406 } else if (!strcmp(p, "efirom")) {
1484− S->pe_subsystem = 13;
1407+ s->pe_subsystem = 13;
14851408 #elif defined(TCC_TARGET_ARM)
14861409 if (!strcmp(p, "wince")) {
1487− S->pe_subsystem = 9;
1410+ s->pe_subsystem = 9;
14881411 #endif
14891412 } else
14901413 goto err;
14911414 #endif
14921415 } else if (ret = link_option(option, "?whole-archive", &p), ret) {
14931416 if (ret > 0)
1494− S->filetype |= AFF_WHOLE_ARCHIVE;
1417+ s->filetype |= AFF_WHOLE_ARCHIVE;
14951418 else
1496− S->filetype &= ~AFF_WHOLE_ARCHIVE;
1419+ s->filetype &= ~AFF_WHOLE_ARCHIVE;
14971420 } else if (link_option(option, "z=", &p)) {
14981421 ignoring = 1;
14991422 } else if (p) {
15001423 return 0;
15011424 } else {
15021425 err:
1503− tcc_error(S, "unsupported linker option '%s'", option);
1426+ tcc_error("unsupported linker option '%s'", option);
15041427 }
15051428 if (ignoring)
1506− tcc_warning_c(warn_unsupported)(S, "unsupported linker option '%s'", option);
1429+ tcc_warning_c(warn_unsupported)("unsupported linker option '%s'", option);
15071430 option = skip_linker_arg(&p);
15081431 }
15091432 return 1;
@@ -1681,7 +1604,7 @@ static const FlagDef options_m[] = { · 171 unmodified lines
16811604 { 0, 0, NULL }
16821605 };
16831606
1684−static int set_flag(TCCState *S, const FlagDef *flags, const char *name)
1607+static int set_flag(TCCState *s, const FlagDef *flags, const char *name)
16851608 {
16861609 int value, mask, ret;
16871610 const FlagDef *p;
@@ -1703,7 +1626,7 @@ static int set_flag(TCCState *S, const FlagDef *flags, const char *name) · 15 unmodified lines
17031626 continue;
17041627 }
17051628
1706− f = (unsigned char *)S + p->offset;
1629+ f = (unsigned char *)s + p->offset;
17071630 *f = (*f & mask) | (value ^ !!(p->flags & FD_INVERT));
17081631
17091632 if (ret) {
@@ -1715,15 +1638,15 @@ static int set_flag(TCCState *S, const FlagDef *flags, const char *name) · 5 unmodified lines
17151638 return ret;
17161639 }
17171640
1718−static void args_parser_add_file(TCCState *S, const char* filename, int filetype)
1641+static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
17191642 {
1720− struct filespec *f = tcc_malloc(S, sizeof *f + strlen(filename));
1643+ struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
17211644 f->type = filetype;
17221645 strcpy(f->name, filename);
1723− dynarray_add(S, &S->files, &S->nb_files, f);
1646+ dynarray_add(&s->files, &s->nb_files, f);
17241647 }
17251648
1726−static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char ***argv)
1649+static int args_parser_make_argv(const char *r, int *argc, char ***argv)
17271650 {
17281651 int ret = 0, q, c;
17291652 CString str;
@@ -1733,7 +1656,7 @@ static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char *** · 3 unmodified lines
17331656 if (c == 0)
17341657 break;
17351658 q = 0;
1736− cstr_new(S, &str);
1659+ cstr_new(&str);
17371660 while (c = (unsigned char)*r, c) {
17381661 ++r;
17391662 if (c == '\\' && (*r == '"' || *r == '\\')) {
@@ -1744,21 +1667,22 @@ static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char *** · 4 unmodified lines
17441667 } else if (q == 0 && c <= ' ') {
17451668 break;
17461669 }
1747− cstr_ccat(S, &str, c);
1670+ cstr_ccat(&str, c);
17481671 }
1749− cstr_ccat(S, &str, 0);
1672+ cstr_ccat(&str, 0);
17501673 //printf("<%s>\n", str.data), fflush(stdout);
1751− dynarray_add(S, argv, argc, tcc_strdup(S, str.data));
1752− cstr_free(S, &str);
1674+ dynarray_add(argv, argc, tcc_strdup(str.data));
1675+ cstr_free(&str);
17531676 ++ret;
17541677 }
17551678 return ret;
17561679 }
17571680
17581681 /* read list file */
1759−static void args_parser_listfile(TCCState *S,
1682+static void args_parser_listfile(TCCState *s,
17601683 const char *filename, int optind, int *pargc, char ***pargv)
17611684 {
1685+ TCCState *s1 = s;
17621686 int fd, i;
17631687 char *p;
17641688 int argc = 0;
@@ -1766,22 +1690,23 @@ static void args_parser_listfile(TCCState *S, · 1 unmodified line
17661690
17671691 fd = open(filename, O_RDONLY | O_BINARY);
17681692 if (fd < 0)
1769− tcc_error(S, "listfile '%s' not found", filename);
1693+ tcc_error("listfile '%s' not found", filename);
17701694
1771− p = tcc_load_text(S, fd);
1695+ p = tcc_load_text(fd);
17721696 for (i = 0; i < *pargc; ++i)
17731697 if (i == optind)
1774− args_parser_make_argv(S, p, &argc, &argv);
1698+ args_parser_make_argv(p, &argc, &argv);
17751699 else
1776− dynarray_add(S, &argv, &argc, tcc_strdup(S, (*pargv)[i]));
1700+ dynarray_add(&argv, &argc, tcc_strdup((*pargv)[i]));
17771701
1778− tcc_free(S, p);
1779− dynarray_reset(S, &S->argv, &S->argc);
1780− *pargc = S->argc = argc, *pargv = S->argv = argv;
1702+ tcc_free(p);
1703+ dynarray_reset(&s->argv, &s->argc);
1704+ *pargc = s->argc = argc, *pargv = s->argv = argv;
17811705 }
17821706
1783−PUB_FUNC int tcc_parse_args(TCCState *S, int *pargc, char ***pargv, int optind)
1707+PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
17841708 {
1709+ TCCState *s1 = s;
17851710 const TCCOption *popt;
17861711 const char *optarg, *r;
17871712 const char *run = NULL;
@@ -1791,26 +1716,26 @@ PUB_FUNC int tcc_parse_args(TCCState *S, int *pargc, char ***pargv, int optind) · 3 unmodified lines
17911716 char **argv = *pargv;
17921717 int argc = *pargc;
17931718
1794− cstr_new(S, &linker_arg);
1719+ cstr_new(&linker_arg);
17951720
17961721 while (optind < argc) {
17971722 r = argv[optind];
17981723 if (r[0] == '@' && r[1] != '\0') {
1799− args_parser_listfile(S, r + 1, optind, &argc, &argv);
1724+ args_parser_listfile(s, r + 1, optind, &argc, &argv);
18001725 continue;
18011726 }
18021727 optind++;
18031728 if (tool) {
18041729 if (r[0] == '-' && r[1] == 'v' && r[2] == 0)
1805− ++S->verbose;
1730+ ++s->verbose;
18061731 continue;
18071732 }
18081733 reparse:
18091734 if (r[0] != '-' || r[1] == '\0') {
18101735 if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */
1811− args_parser_add_file(S, r, S->filetype);
1736+ args_parser_add_file(s, r, s->filetype);
18121737 if (run) {
1813− tcc_set_options(S, run);
1738+ tcc_set_options(s, run);
18141739 arg_start = optind - 1;
18151740 break;
18161741 }
@@ -1822,7 +1747,7 @@ reparse: · 5 unmodified lines
18221747 const char *p1 = popt->name;
18231748 const char *r1 = r + 1;
18241749 if (p1 == NULL)
1825− tcc_error(S, "invalid option -- '%s'", r);
1750+ tcc_error("invalid option -- '%s'", r);
18261751 if (!strstart(p1, &r1))
18271752 continue;
18281753 optarg = r1;
@@ -1830,7 +1755,7 @@ reparse: · 1 unmodified line
18301755 if (*r1 == '\0' && !(popt->flags & TCC_OPTION_NOSEP)) {
18311756 if (optind >= argc)
18321757 arg_err:
1833− tcc_error(S, "argument to '%s' is missing", r);
1758+ tcc_error("argument to '%s' is missing", r);
18341759 optarg = argv[optind++];
18351760 }
18361761 } else if (*r1 != '\0')
@@ -1846,132 +1771,132 @@ reparse: · 9 unmodified lines
18461771 x = OPT_HELP2;
18471772 goto extra_action;
18481773 case TCC_OPTION_I:
1849− tcc_add_include_path(S, optarg);
1774+ tcc_add_include_path(s, optarg);
18501775 break;
18511776 case TCC_OPTION_D:
1852− tcc_define_symbol(S, optarg, NULL);
1777+ tcc_define_symbol(s, optarg, NULL);
18531778 break;
18541779 case TCC_OPTION_U:
1855− tcc_undefine_symbol(S, optarg);
1780+ tcc_undefine_symbol(s, optarg);
18561781 break;
18571782 case TCC_OPTION_L:
1858− tcc_add_library_path(S, optarg);
1783+ tcc_add_library_path(s, optarg);
18591784 break;
18601785 case TCC_OPTION_B:
18611786 /* set tcc utilities path (mainly for tcc development) */
1862− tcc_set_lib_path(S, optarg);
1787+ tcc_set_lib_path(s, optarg);
18631788 break;
18641789 case TCC_OPTION_l:
1865− args_parser_add_file(S, optarg, AFF_TYPE_LIB | (S->filetype & ~AFF_TYPE_MASK));
1866− S->nb_libraries++;
1790+ args_parser_add_file(s, optarg, AFF_TYPE_LIB | (s->filetype & ~AFF_TYPE_MASK));
1791+ s->nb_libraries++;
18671792 break;
18681793 case TCC_OPTION_pthread:
1869− S->option_pthread = 1;
1794+ s->option_pthread = 1;
18701795 break;
18711796 case TCC_OPTION_bench:
1872− S->do_bench = 1;
1797+ s->do_bench = 1;
18731798 break;
18741799 #ifdef CONFIG_TCC_BACKTRACE
18751800 case TCC_OPTION_bt:
1876− S->rt_num_callers = atoi(optarg);
1877− S->do_backtrace = 1;
1878− S->do_debug = 1;
1801+ s->rt_num_callers = atoi(optarg);
1802+ s->do_backtrace = 1;
1803+ s->do_debug = 1;
18791804 break;
18801805 #endif
18811806 #ifdef CONFIG_TCC_BCHECK
18821807 case TCC_OPTION_b:
1883− S->do_bounds_check = 1;
1884− S->do_backtrace = 1;
1885− S->do_debug = 1;
1808+ s->do_bounds_check = 1;
1809+ s->do_backtrace = 1;
1810+ s->do_debug = 1;
18861811 break;
18871812 #endif
18881813 case TCC_OPTION_g:
1889− S->do_debug = 1;
1814+ s->do_debug = 1;
18901815 break;
18911816 case TCC_OPTION_c:
18921817 x = TCC_OUTPUT_OBJ;
18931818 set_output_type:
1894− if (S->output_type)
1895− tcc_warning(S, "-%s: overriding compiler action already specified", popt->name);
1896− S->output_type = x;
1819+ if (s->output_type)
1820+ tcc_warning("-%s: overriding compiler action already specified", popt->name);
1821+ s->output_type = x;
18971822 break;
18981823 case TCC_OPTION_d:
18991824 if (*optarg == 'D')
1900− S->dflag = TCC_OPTION_d_D;
1825+ s->dflag = 3;
19011826 else if (*optarg == 'M')
1902− S->dflag = TCC_OPTION_d_M;
1827+ s->dflag = 7;
19031828 else if (*optarg == 't')
1904− S->dflag = TCC_OPTION_d_t;
1829+ s->dflag = 16;
19051830 else if (isnum(*optarg))
1906− S->g_debug |= atoi(optarg);
1831+ s->g_debug |= atoi(optarg);
19071832 else
19081833 goto unsupported_option;
19091834 break;
19101835 case TCC_OPTION_static:
1911− S->static_link = 1;
1836+ s->static_link = 1;
19121837 break;
19131838 case TCC_OPTION_std:
19141839 if (strcmp(optarg, "=c11") == 0)
1915− S->cversion = 201112;
1840+ s->cversion = 201112;
19161841 break;
19171842 case TCC_OPTION_shared:
19181843 x = TCC_OUTPUT_DLL;
19191844 goto set_output_type;
19201845 case TCC_OPTION_soname:
1921− S->soname = tcc_strdup(S, optarg);
1846+ s->soname = tcc_strdup(optarg);
19221847 break;
19231848 case TCC_OPTION_o:
1924− if (S->outfile) {
1925− tcc_warning(S, "multiple -o option");
1926− tcc_free(S, S->outfile);
1849+ if (s->outfile) {
1850+ tcc_warning("multiple -o option");
1851+ tcc_free(s->outfile);
19271852 }
1928− S->outfile = tcc_strdup(S, optarg);
1853+ s->outfile = tcc_strdup(optarg);
19291854 break;
19301855 case TCC_OPTION_r:
19311856 /* generate a .o merging several output files */
1932− S->option_r = 1;
1857+ s->option_r = 1;
19331858 x = TCC_OUTPUT_OBJ;
19341859 goto set_output_type;
19351860 case TCC_OPTION_isystem:
1936− tcc_add_sysinclude_path(S, optarg);
1861+ tcc_add_sysinclude_path(s, optarg);
19371862 break;
19381863 case TCC_OPTION_include:
1939− cstr_printf(S, &S->cmdline_incl, "#include \"%s\"\n", optarg);
1864+ cstr_printf(&s->cmdline_incl, "#include \"%s\"\n", optarg);
19401865 break;
19411866 case TCC_OPTION_nostdinc:
1942− S->nostdinc = 1;
1867+ s->nostdinc = 1;
19431868 break;
19441869 case TCC_OPTION_nostdlib:
1945− S->nostdlib = 1;
1870+ s->nostdlib = 1;
19461871 break;
19471872 case TCC_OPTION_run:
19481873 #ifndef TCC_IS_NATIVE
1949− tcc_error(S, "-run is not available in a cross compiler");
1874+ tcc_error("-run is not available in a cross compiler");
19501875 #endif
19511876 run = optarg;
19521877 x = TCC_OUTPUT_MEMORY;
19531878 goto set_output_type;
19541879 case TCC_OPTION_v:
1955− do ++S->verbose; while (*optarg++ == 'v');
1880+ do ++s->verbose; while (*optarg++ == 'v');
19561881 ++noaction;
19571882 break;
19581883 case TCC_OPTION_f:
1959− if (set_flag(S, options_f, optarg) < 0)
1884+ if (set_flag(s, options_f, optarg) < 0)
19601885 goto unsupported_option;
19611886 break;
19621887 #ifdef TCC_TARGET_ARM
19631888 case TCC_OPTION_mfloat_abi:
19641889 /* tcc doesn't support soft float yet */
19651890 if (!strcmp(optarg, "softfp")) {
1966− S->float_abi = ARM_SOFTFP_FLOAT;
1891+ s->float_abi = ARM_SOFTFP_FLOAT;
19671892 } else if (!strcmp(optarg, "hard"))
1968− S->float_abi = ARM_HARD_FLOAT;
1893+ s->float_abi = ARM_HARD_FLOAT;
19691894 else
1970− tcc_error(S, "unsupported float abi '%s'", optarg);
1895+ tcc_error("unsupported float abi '%s'", optarg);
19711896 break;
19721897 #endif
19731898 case TCC_OPTION_m:
1974− if (set_flag(S, options_m, optarg) < 0) {
1899+ if (set_flag(s, options_m, optarg) < 0) {
19751900 if (x = atoi(optarg), x != 32 && x != 64)
19761901 goto unsupported_option;
19771902 if (PTR_SIZE != x/8)
@@ -1980,22 +1905,22 @@ reparse: · 2 unmodified lines
19801905 }
19811906 break;
19821907 case TCC_OPTION_W:
1983− S->warn_none = 0;
1984− if (optarg[0] && set_flag(S, options_W, optarg) < 0)
1908+ s->warn_none = 0;
1909+ if (optarg[0] && set_flag(s, options_W, optarg) < 0)
19851910 goto unsupported_option;
19861911 break;
19871912 case TCC_OPTION_w:
1988− S->warn_none = 1;
1913+ s->warn_none = 1;
19891914 break;
19901915 case TCC_OPTION_rdynamic:
1991− S->rdynamic = 1;
1916+ s->rdynamic = 1;
19921917 break;
19931918 case TCC_OPTION_Wl:
19941919 if (linker_arg.size)
1995− --linker_arg.size, cstr_ccat(S, &linker_arg, ',');
1996− cstr_cat(S, &linker_arg, optarg, 0);
1997− if (tcc_set_linker(S, linker_arg.data))
1998− cstr_free(S, &linker_arg);
1920+ --linker_arg.size, cstr_ccat(&linker_arg, ',');
1921+ cstr_cat(&linker_arg, optarg, 0);
1922+ if (tcc_set_linker(s, linker_arg.data))
1923+ cstr_free(&linker_arg);
19991924 break;
20001925 case TCC_OPTION_Wp:
20011926 r = optarg;
@@ -2004,25 +1929,25 @@ reparse: · 2 unmodified lines
20041929 x = TCC_OUTPUT_PREPROCESS;
20051930 goto set_output_type;
20061931 case TCC_OPTION_P:
2007− S->Pflag = atoi(optarg) + 1;
1932+ s->Pflag = atoi(optarg) + 1;
20081933 break;
20091934 case TCC_OPTION_M:
2010− S->include_sys_deps = 1;
1935+ s->include_sys_deps = 1;
20111936 // fall through
20121937 case TCC_OPTION_MM:
2013− S->just_deps = 1;
2014− if(!S->deps_outfile)
2015− S->deps_outfile = tcc_strdup(S, "-");
1938+ s->just_deps = 1;
1939+ if(!s->deps_outfile)
1940+ s->deps_outfile = tcc_strdup("-");
20161941 // fall through
20171942 case TCC_OPTION_MMD:
2018− S->gen_deps = 1;
1943+ s->gen_deps = 1;
20191944 break;
20201945 case TCC_OPTION_MD:
2021− S->gen_deps = 1;
2022− S->include_sys_deps = 1;
1946+ s->gen_deps = 1;
1947+ s->include_sys_deps = 1;
20231948 break;
20241949 case TCC_OPTION_MF:
2025− S->deps_outfile = tcc_strdup(S, optarg);
1950+ s->deps_outfile = tcc_strdup(optarg);
20261951 break;
20271952 case TCC_OPTION_dumpversion:
20281953 printf ("%s\n", TCC_VERSION);
@@ -2039,11 +1964,11 @@ reparse: · 10 unmodified lines
20391964 else if (*optarg == 'n')
20401965 x = AFF_TYPE_NONE;
20411966 else
2042− tcc_warning(S, "unsupported language '%s'", optarg);
2043− S->filetype = x | (S->filetype & ~AFF_TYPE_MASK);
1967+ tcc_warning("unsupported language '%s'", optarg);
1968+ s->filetype = x | (s->filetype & ~AFF_TYPE_MASK);
20441969 break;
20451970 case TCC_OPTION_O:
2046− S->optimize = atoi(optarg);
1971+ s->optimize = atoi(optarg);
20471972 break;
20481973 case TCC_OPTION_print_search_dirs:
20491974 x = OPT_PRINT_DIRS;
@@ -2056,12 +1981,12 @@ reparse: · 6 unmodified lines
20561981 extra_action:
20571982 arg_start = optind - 1;
20581983 if (arg_start != noaction)
2059− tcc_error(S, "cannot parse %s here", r);
1984+ tcc_error("cannot parse %s here", r);
20601985 tool = x;
20611986 break;
20621987 default:
20631988 unsupported_option:
2064− tcc_warning_c(warn_unsupported)(S, "unsupported option '%s'", r);
1989+ tcc_warning_c(warn_unsupported)("unsupported option '%s'", r);
20651990 break;
20661991 }
20671992 }
@@ -2075,23 +2000,23 @@ unsupported_option: · 7 unmodified lines
20752000 return tool;
20762001 if (optind != noaction)
20772002 return 0;
2078− if (S->verbose == 2)
2003+ if (s->verbose == 2)
20792004 return OPT_PRINT_DIRS;
2080− if (S->verbose)
2005+ if (s->verbose)
20812006 return OPT_V;
20822007 return OPT_HELP;
20832008 }
20842009
2085−LIBTCCAPI void tcc_set_options(TCCState *S, const char *r)
2010+LIBTCCAPI void tcc_set_options(TCCState *s, const char *r)
20862011 {
20872012 char **argv = NULL;
20882013 int argc = 0;
2089− args_parser_make_argv(S, r, &argc, &argv);
2090− tcc_parse_args(S, &argc, &argv, 0);
2091− dynarray_reset(S, &argv, &argc);
2014+ args_parser_make_argv(r, &argc, &argv);
2015+ tcc_parse_args(s, &argc, &argv, 0);
2016+ dynarray_reset(&argv, &argc);
20922017 }
20932018
2094−PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time)
2019+PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time)
20952020 {
20962021 if (total_time < 1)
20972022 total_time = 1;
@@ -2104,14 +2029,12 @@ PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time) · 6 unmodified lines
21042029 (unsigned)total_lines*1000/total_time,
21052030 (double)total_bytes/1000/total_time);
21062031 fprintf(stderr, "* text %d, data.rw %d, data.ro %d, bss %d bytes\n",
2107− S->total_output[0],
2108− S->total_output[1],
2109− S->total_output[2],
2110− S->total_output[3]
2032+ s1->total_output[0],
2033+ s1->total_output[1],
2034+ s1->total_output[2],
2035+ s1->total_output[3]
21112036 );
21122037 #ifdef MEM_DEBUG
21132038 fprintf(stderr, "* %d bytes memory used\n", mem_max_size);
21142039 #endif
21152040 }
2116−
2117−#include "tccqsort.c"
libtcc.h+21−72
@@ -15,95 +15,56 @@ typedef struct TCCState TCCState; · 14 unmodified lines
1515
1616 typedef void (*TCCErrorFunc)(void *opaque, const char *msg);
1717
18−#ifndef _OFF_T_DEFINED
19−#define _OFF_T_DEFINED
20−#ifndef _OFF_T_
21−#define _OFF_T_
22− typedef long _off_t;
23−#ifndef _SIZE_T_
24−#define _SIZE_T_
25− typedef unsigned long size_t;
26−#endif
27−#if !defined(NO_OLDNAMES) || defined(_POSIX)
28− typedef long off_t;
29−#endif
30−#endif
31−#endif
32−
33−struct vio_module_t;
34−
35−typedef struct vio_fd {
36− int fd;
37− void *vio_udata;
38− struct vio_module_t *vio_module;
39−} vio_fd;
40−
41−#define CALL_VIO_OPEN_FIRST 0x01
42−#define CALL_VIO_OPEN_LAST 0x02
43−
44−typedef struct vio_module_t {
45− void *user_data;
46− struct TCCState *S;
47− int call_vio_open_flags; /*CALL_VIO_OPEN_FIRST, CALL_VIO_OPEN_LAST, one or both */
48− int (*vio_open)(vio_fd *fd, const char *fn, int oflag) ;
49− off_t (*vio_lseek)(vio_fd fd, off_t offset, int whence);
50− size_t (*vio_read)(vio_fd fd, void *buf, size_t bytes);
51− int (*vio_close)(vio_fd *fd);
52−} vio_module_t;
53−
5418 /* create a new TCC compilation context */
5519 LIBTCCAPI TCCState *tcc_new(void);
5620
5721 /* free a TCC compilation context */
58−LIBTCCAPI void tcc_delete(TCCState *S);
22+LIBTCCAPI void tcc_delete(TCCState *s);
5923
6024 /* set CONFIG_TCCDIR at runtime */
61−LIBTCCAPI void tcc_set_lib_path(TCCState *S, const char *path);
25+LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
6226
6327 /* set error/warning display callback */
64−LIBTCCAPI void tcc_set_error_func(TCCState *S, void *error_opaque, TCCErrorFunc error_func);
28+LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func);
6529
6630 /* return error/warning callback */
67−LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *S);
31+LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s);
6832
6933 /* return error/warning callback opaque pointer */
70−LIBTCCAPI void *tcc_get_error_opaque(TCCState *S);
34+LIBTCCAPI void *tcc_get_error_opaque(TCCState *s);
7135
7236 /* set options as from command line (multiple supported) */
73−LIBTCCAPI void tcc_set_options(TCCState *S, const char *str);
74−
75−/* set virtual io module */
76−LIBTCCAPI void tcc_set_vio_module(TCCState *S, vio_module_t *vio_module);
37+LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
7738
7839 /*****************************/
7940 /* preprocessor */
8041
8142 /* add include path */
82−LIBTCCAPI int tcc_add_include_path(TCCState *S, const char *pathname);
43+LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
8344
8445 /* add in system include path */
85−LIBTCCAPI int tcc_add_sysinclude_path(TCCState *S, const char *pathname);
46+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
8647
8748 /* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
88−LIBTCCAPI void tcc_define_symbol(TCCState *S, const char *sym, const char *value);
49+LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
8950
9051 /* undefine preprocess symbol 'sym' */
91−LIBTCCAPI void tcc_undefine_symbol(TCCState *S, const char *sym);
52+LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
9253
9354 /*****************************/
9455 /* compiling */
9556
9657 /* add a file (C file, dll, object, library, ld script). Return -1 if error. */
97−LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename);
58+LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
9859
9960 /* compile a string containing a C source. Return -1 if error. */
100−LIBTCCAPI int tcc_compile_string(TCCState *S, const char *buf);
61+LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
10162
10263 /*****************************/
10364 /* linking commands */
10465
10566 /* set output type. MUST BE CALLED before any compilation */
106−LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type);
67+LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
10768 #define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
10869 #define TCC_OUTPUT_EXE 2 /* executable file */
10970 #define TCC_OUTPUT_DLL 3 /* dynamic library */
@@ -111,24 +72,24 @@ LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type); · 1 unmodified line
11172 #define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
11273
11374 /* equivalent to -Lpath option */
114−LIBTCCAPI int tcc_add_library_path(TCCState *S, const char *pathname);
75+LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
11576
11677 /* the library name is the same as the argument of the '-l' option */
117−LIBTCCAPI int tcc_add_library(TCCState *S, const char *libraryname);
78+LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
11879
11980 /* add a symbol to the compiled program */
120−LIBTCCAPI int tcc_add_symbol(TCCState *S, const char *name, const void *val);
81+LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
12182
12283 /* output an executable, library or object file. DO NOT call
12384 tcc_relocate() before. */
124−LIBTCCAPI int tcc_output_file(TCCState *S, const char *filename);
85+LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
12586
12687 /* link and run main() function and return its value. DO NOT call
12788 tcc_relocate() before. */
128−LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv);
89+LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
12990
13091 /* do all relocations (needed before using tcc_get_symbol()) */
131−LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr);
92+LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
13293 /* possible values for 'ptr':
13394 - TCC_RELOCATE_AUTO : Allocate and manage memory internally
13495 - NULL : return required memory size for the step below
@@ -137,24 +98,12 @@ LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr); · 2 unmodified lines
13798 #define TCC_RELOCATE_AUTO (void*)1
13899
139100 /* return symbol value or NULL if not found */
140−LIBTCCAPI void *tcc_get_symbol(TCCState *S, const char *name);
101+LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
141102
142103 /* return symbol value or NULL if not found */
143−LIBTCCAPI void tcc_list_symbols(TCCState *S, void *ctx,
104+LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
144105 void (*symbol_cb)(void *ctx, const char *name, const void *val));
145106
146−typedef int (*tcc_cmpfun)(const void *, const void *, void *);
147−LIBTCCAPI void tcc_qsort_s(void *base, size_t nel, size_t width, tcc_cmpfun cmp, void *ctx);
148−
149−enum { /*need better names for some of then*/
150− TCC_OPTION_d_BI = 1,
151− TCC_OPTION_d_D = 3,
152− TCC_OPTION_d_4 = 4,
153− TCC_OPTION_d_M = 7,
154− TCC_OPTION_d_t = 16,
155− TCC_OPTION_d_32 = 32,
156−};
157−
158107 #ifdef __cplusplus
159108 }
160109 #endif
riscv64-asm.c+187−187
@@ -9,9 +9,9 @@ · 8 unmodified lines
99 #define CONFIG_TCC_ASM
1010 #define NB_ASM_REGS 32
1111
12−ST_FUNC void g(TCCState* S, int c);
13−ST_FUNC void gen_le16(TCCState* S, int c);
14−ST_FUNC void gen_le32(TCCState* S, int c);
12+ST_FUNC void g(int c);
13+ST_FUNC void gen_le16(int c);
14+ST_FUNC void gen_le32(int c);
1515
1616 /*************************************************************/
1717 #else
@@ -20,85 +20,85 @@ ST_FUNC void gen_le32(TCCState* S, int c); · 2 unmodified lines
2020 #include "tcc.h"
2121
2222 /* XXX: make it faster ? */
23−ST_FUNC void g(TCCState* S, int c)
23+ST_FUNC void g(int c)
2424 {
2525 int ind1;
26− if (S->tccgen_nocode_wanted)
26+ if (nocode_wanted)
2727 return;
28− ind1 = S->tccgen_ind + 1;
28+ ind1 = ind + 1;
2929 if (ind1 > cur_text_section->data_allocated)
30− section_realloc(S, cur_text_section, ind1);
31− cur_text_section->data[S->tccgen_ind] = c;
32− S->tccgen_ind = ind1;
30+ section_realloc(cur_text_section, ind1);
31+ cur_text_section->data[ind] = c;
32+ ind = ind1;
3333 }
3434
35−ST_FUNC void gen_le16 (TCCState* S, int i)
35+ST_FUNC void gen_le16 (int i)
3636 {
37− g(S, i);
38− g(S, i>>8);
37+ g(i);
38+ g(i>>8);
3939 }
4040
41−ST_FUNC void gen_le32 (TCCState* S, int i)
41+ST_FUNC void gen_le32 (int i)
4242 {
4343 int ind1;
44− if (S->tccgen_nocode_wanted)
44+ if (nocode_wanted)
4545 return;
46− ind1 = S->tccgen_ind + 4;
46+ ind1 = ind + 4;
4747 if (ind1 > cur_text_section->data_allocated)
48− section_realloc(S, cur_text_section, ind1);
49− cur_text_section->data[S->tccgen_ind++] = i & 0xFF;
50− cur_text_section->data[S->tccgen_ind++] = (i >> 8) & 0xFF;
51− cur_text_section->data[S->tccgen_ind++] = (i >> 16) & 0xFF;
52− cur_text_section->data[S->tccgen_ind++] = (i >> 24) & 0xFF;
48+ section_realloc(cur_text_section, ind1);
49+ cur_text_section->data[ind++] = i & 0xFF;
50+ cur_text_section->data[ind++] = (i >> 8) & 0xFF;
51+ cur_text_section->data[ind++] = (i >> 16) & 0xFF;
52+ cur_text_section->data[ind++] = (i >> 24) & 0xFF;
5353 }
5454
55−ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
55+ST_FUNC void gen_expr32(ExprValue *pe)
5656 {
57− gen_le32(S, pe->v);
57+ gen_le32(pe->v);
5858 }
5959
60−static void asm_emit_opcode(TCCState* S, uint32_t opcode) {
61− gen_le32(S, opcode);
60+static void asm_emit_opcode(uint32_t opcode) {
61+ gen_le32(opcode);
6262 }
6363
64−static void asm_nullary_opcode(TCCState *S, int token)
64+static void asm_nullary_opcode(TCCState *s1, int token)
6565 {
6666 switch (token) {
6767 // Sync instructions
6868
6969 case TOK_ASM_fence: // I
70− asm_emit_opcode(S, (0x3 << 2) | 3 | (0 << 12));
70+ asm_emit_opcode((0x3 << 2) | 3 | (0 << 12));
7171 return;
7272 case TOK_ASM_fence_i: // I
73− asm_emit_opcode(S, (0x3 << 2) | 3| (1 << 12));
73+ asm_emit_opcode((0x3 << 2) | 3| (1 << 12));
7474 return;
7575
7676 // System calls
7777
7878 case TOK_ASM_scall: // I (pseudo)
79− asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 12));
79+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 12));
8080 return;
8181 case TOK_ASM_sbreak: // I (pseudo)
82− asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 12) | (1 << 20));
82+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 12) | (1 << 20));
8383 return;
8484
8585 // Privileged Instructions
8686
8787 case TOK_ASM_ecall:
88− asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 20));
88+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 20));
8989 return;
9090 case TOK_ASM_ebreak:
91− asm_emit_opcode(S, (0x1C << 2) | 3 | (1 << 20));
91+ asm_emit_opcode((0x1C << 2) | 3 | (1 << 20));
9292 return;
9393
9494 // Other
9595
9696 case TOK_ASM_wfi:
97− asm_emit_opcode(S, (0x1C << 2) | 3 | (0x105 << 20));
97+ asm_emit_opcode((0x1C << 2) | 3 | (0x105 << 20));
9898 return;
9999
100100 default:
101− expect(S, "nullary instruction");
101+ expect("nullary instruction");
102102 }
103103 }
104104
@@ -121,30 +121,30 @@ typedef struct Operand { · 16 unmodified lines
121121 } Operand;
122122
123123 /* Parse a text containing operand and store the result in OP */
124−static void parse_operand(TCCState *S, Operand *op)
124+static void parse_operand(TCCState *s1, Operand *op)
125125 {
126126 ExprValue e;
127127 int8_t reg;
128128
129129 op->type = 0;
130130
131− if ((reg = asm_parse_regvar(S, S->tccpp_tok)) != -1) {
132− next(S); // skip register name
131+ if ((reg = asm_parse_regvar(tok)) != -1) {
132+ next(); // skip register name
133133 op->type = OP_REG;
134134 op->reg = (uint8_t) reg;
135135 return;
136− } else if (S->tccpp_tok == '$') {
136+ } else if (tok == '$') {
137137 /* constant value */
138− next(S); // skip '#' or '$'
138+ next(); // skip '#' or '$'
139139 }
140− asm_expr(S, &e);
140+ asm_expr(s1, &e);
141141 op->type = OP_IM32;
142142 op->e = e;
143143 if (!op->e.sym) {
144144 if ((int) op->e.v >= -2048 && (int) op->e.v < 2048)
145145 op->type = OP_IM12S;
146146 } else
147− expect(S, "operand");
147+ expect("operand");
148148 }
149149
150150 #define ENCODE_RS1(register_index) ((register_index) << 15)
@@ -152,96 +152,96 @@ static void parse_operand(TCCState *S, Operand *op) · 1 unmodified line
152152 #define ENCODE_RD(register_index) ((register_index) << 7)
153153
154154 // Note: Those all map to CSR--so they are pseudo-instructions.
155−static void asm_unary_opcode(TCCState *S, int token)
155+static void asm_unary_opcode(TCCState *s1, int token)
156156 {
157157 uint32_t opcode = (0x1C << 2) | 3 | (2 << 12);
158158 Operand op;
159− parse_operand(S, &op);
159+ parse_operand(s1, &op);
160160 if (op.type != OP_REG) {
161− expect(S, "register");
161+ expect("register");
162162 return;
163163 }
164164 opcode |= ENCODE_RD(op.reg);
165165
166166 switch (token) {
167167 case TOK_ASM_rdcycle:
168− asm_emit_opcode(S, opcode | (0xC00 << 20));
168+ asm_emit_opcode(opcode | (0xC00 << 20));
169169 return;
170170 case TOK_ASM_rdcycleh:
171− asm_emit_opcode(S, opcode | (0xC80 << 20));
171+ asm_emit_opcode(opcode | (0xC80 << 20));
172172 return;
173173 case TOK_ASM_rdtime:
174− asm_emit_opcode(S, opcode | (0xC01 << 20) | ENCODE_RD(op.reg));
174+ asm_emit_opcode(opcode | (0xC01 << 20) | ENCODE_RD(op.reg));
175175 return;
176176 case TOK_ASM_rdtimeh:
177− asm_emit_opcode(S, opcode | (0xC81 << 20) | ENCODE_RD(op.reg));
177+ asm_emit_opcode(opcode | (0xC81 << 20) | ENCODE_RD(op.reg));
178178 return;
179179 case TOK_ASM_rdinstret:
180− asm_emit_opcode(S, opcode | (0xC02 << 20) | ENCODE_RD(op.reg));
180+ asm_emit_opcode(opcode | (0xC02 << 20) | ENCODE_RD(op.reg));
181181 return;
182182 case TOK_ASM_rdinstreth:
183− asm_emit_opcode(S, opcode | (0xC82 << 20) | ENCODE_RD(op.reg));
183+ asm_emit_opcode(opcode | (0xC82 << 20) | ENCODE_RD(op.reg));
184184 return;
185185 default:
186− expect(S, "unary instruction");
186+ expect("unary instruction");
187187 }
188188 }
189189
190−static void asm_emit_u(TCCState *S, int token, uint32_t opcode, const Operand* rd, const Operand* rs2)
190+static void asm_emit_u(int token, uint32_t opcode, const Operand* rd, const Operand* rs2)
191191 {
192192 if (rd->type != OP_REG) {
193− tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
193+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
194194 return;
195195 }
196196 if (rs2->type != OP_IM12S && rs2->type != OP_IM32) {
197− tcc_error(S, "'%s': Expected second source operand that is an immediate value", get_tok_str(S, token, NULL));
197+ tcc_error("'%s': Expected second source operand that is an immediate value", get_tok_str(token, NULL));
198198 return;
199199 } else if (rs2->e.v >= 0x100000) {
200− tcc_error(S, "'%s': Expected second source operand that is an immediate value between 0 and 0xfffff", get_tok_str(S, token, NULL));
200+ tcc_error("'%s': Expected second source operand that is an immediate value between 0 and 0xfffff", get_tok_str(token, NULL));
201201 return;
202202 }
203203 /* U-type instruction:
204204 31...12 imm[31:12]
205205 11...7 rd
206206 6...0 opcode */
207− gen_le32(S, opcode | ENCODE_RD(rd->reg) | (rs2->e.v << 12));
207+ gen_le32(opcode | ENCODE_RD(rd->reg) | (rs2->e.v << 12));
208208 }
209209
210−static void asm_binary_opcode(TCCState* S, int token)
210+static void asm_binary_opcode(TCCState* s1, int token)
211211 {
212212 Operand ops[2];
213− parse_operand(S, &ops[0]);
214− if (S->tccpp_tok == ',')
215− next(S);
213+ parse_operand(s1, &ops[0]);
214+ if (tok == ',')
215+ next();
216216 else
217− expect(S, "','");
218− parse_operand(S, &ops[1]);
217+ expect("','");
218+ parse_operand(s1, &ops[1]);
219219
220220 switch (token) {
221221 case TOK_ASM_lui:
222− asm_emit_u(S, token, (0xD << 2) | 3, &ops[0], &ops[1]);
222+ asm_emit_u(token, (0xD << 2) | 3, &ops[0], &ops[1]);
223223 return;
224224 case TOK_ASM_auipc:
225− asm_emit_u(S, token, (0x05 << 2) | 3, &ops[0], &ops[1]);
225+ asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]);
226226 return;
227227 default:
228− expect(S, "binary instruction");
228+ expect("binary instruction");
229229 }
230230 }
231231
232232 /* caller: Add funct3, funct7 into opcode */
233−static void asm_emit_r(TCCState* S, int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
233+static void asm_emit_r(int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
234234 {
235235 if (rd->type != OP_REG) {
236− tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
236+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
237237 return;
238238 }
239239 if (rs1->type != OP_REG) {
240− tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
240+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
241241 return;
242242 }
243243 if (rs2->type != OP_REG) {
244− tcc_error(S, "'%s': Expected second source operand that is a register or immediate", get_tok_str(S, token, NULL));
244+ tcc_error("'%s': Expected second source operand that is a register or immediate", get_tok_str(token, NULL));
245245 return;
246246 }
247247 /* R-type instruction:
@@ -251,22 +251,22 @@ static void asm_emit_r(TCCState* S, int token, uint32_t opcode, const Operand* r · 3 unmodified lines
251251 14...12 funct3
252252 11...7 rd
253253 6...0 opcode */
254− gen_le32(S, opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg));
254+ gen_le32(opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg));
255255 }
256256
257257 /* caller: Add funct3 into opcode */
258−static void asm_emit_i(TCCState* S, int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
258+static void asm_emit_i(int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
259259 {
260260 if (rd->type != OP_REG) {
261− tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
261+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
262262 return;
263263 }
264264 if (rs1->type != OP_REG) {
265− tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
265+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
266266 return;
267267 }
268268 if (rs2->type != OP_IM12S) {
269− tcc_error(S, "'%s': Expected second source operand that is an immediate value between 0 and 4095", get_tok_str(S, token, NULL));
269+ tcc_error("'%s': Expected second source operand that is an immediate value between 0 and 4095", get_tok_str(token, NULL));
270270 return;
271271 }
272272 /* I-type instruction:
@@ -276,156 +276,156 @@ static void asm_emit_i(TCCState* S, int token, uint32_t opcode, const Operand* r · 3 unmodified lines
276276 11...7 rd
277277 6...0 opcode */
278278
279− gen_le32(S, opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | (rs2->e.v << 20));
279+ gen_le32(opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | (rs2->e.v << 20));
280280 }
281281
282−static void asm_shift_opcode(TCCState *S, int token)
282+static void asm_shift_opcode(TCCState *s1, int token)
283283 {
284284 Operand ops[3];
285− parse_operand(S, &ops[0]);
286− if (S->tccpp_tok == ',')
287− next(S);
285+ parse_operand(s1, &ops[0]);
286+ if (tok == ',')
287+ next();
288288 else
289− expect(S, "','");
290− parse_operand(S, &ops[1]);
291− if (S->tccpp_tok == ',')
292− next(S);
289+ expect("','");
290+ parse_operand(s1, &ops[1]);
291+ if (tok == ',')
292+ next();
293293 else
294− expect(S, "','");
295− parse_operand(S, &ops[2]);
294+ expect("','");
295+ parse_operand(s1, &ops[2]);
296296
297297 switch (token) {
298298 case TOK_ASM_sll:
299− asm_emit_r(S, token, (0xC << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
299+ asm_emit_r(token, (0xC << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
300300 return;
301301 case TOK_ASM_slli:
302− asm_emit_i(S, token, (4 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
302+ asm_emit_i(token, (4 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
303303 return;
304304 case TOK_ASM_srl:
305− asm_emit_r(S, token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
305+ asm_emit_r(token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
306306 return;
307307 case TOK_ASM_srli:
308− asm_emit_i(S, token, (0x4 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
308+ asm_emit_i(token, (0x4 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
309309 return;
310310 case TOK_ASM_sra:
311− asm_emit_r(S, token, (0xC << 2) | 3 | (5 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
311+ asm_emit_r(token, (0xC << 2) | 3 | (5 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
312312 return;
313313 case TOK_ASM_srai:
314− asm_emit_i(S, token, (0x4 << 2) | 3 | (5 << 12) | (16 << 26), &ops[0], &ops[1], &ops[2]);
314+ asm_emit_i(token, (0x4 << 2) | 3 | (5 << 12) | (16 << 26), &ops[0], &ops[1], &ops[2]);
315315 return;
316316 case TOK_ASM_sllw:
317− asm_emit_r(S, token, (0xE << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
317+ asm_emit_r(token, (0xE << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
318318 return;
319319 case TOK_ASM_slliw:
320− asm_emit_i(S, token, (6 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
320+ asm_emit_i(token, (6 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
321321 return;
322322 case TOK_ASM_srlw:
323− asm_emit_r(S, token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
323+ asm_emit_r(token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
324324 return;
325325 case TOK_ASM_srliw:
326− asm_emit_i(S, token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
326+ asm_emit_i(token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
327327 return;
328328 case TOK_ASM_sraw:
329− asm_emit_r(S, token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
329+ asm_emit_r(token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
330330 return;
331331 case TOK_ASM_sraiw:
332− asm_emit_i(S, token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
332+ asm_emit_i(token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
333333 return;
334334 default:
335− expect(S, "shift instruction");
335+ expect("shift instruction");
336336 }
337337 }
338338
339−static void asm_data_processing_opcode(TCCState* S, int token)
339+static void asm_data_processing_opcode(TCCState* s1, int token)
340340 {
341341 Operand ops[3];
342− parse_operand(S, &ops[0]);
343− if (S->tccpp_tok == ',')
344− next(S);
342+ parse_operand(s1, &ops[0]);
343+ if (tok == ',')
344+ next();
345345 else
346− expect(S, "','");
347− parse_operand(S, &ops[1]);
348− if (S->tccpp_tok == ',')
349− next(S);
346+ expect("','");
347+ parse_operand(s1, &ops[1]);
348+ if (tok == ',')
349+ next();
350350 else
351− expect(S, "','");
352− parse_operand(S, &ops[2]);
351+ expect("','");
352+ parse_operand(s1, &ops[2]);
353353
354354 switch (token) {
355355 // Arithmetic (RD,RS1,(RS2|IMM)); R-format, I-format or U-format
356356
357357 case TOK_ASM_add:
358− asm_emit_r(S, token, (0xC << 2) | 3, &ops[0], &ops[1], &ops[2]);
358+ asm_emit_r(token, (0xC << 2) | 3, &ops[0], &ops[1], &ops[2]);
359359 return;
360360 case TOK_ASM_addi:
361− asm_emit_i(S, token, (4 << 2) | 3, &ops[0], &ops[1], &ops[2]);
361+ asm_emit_i(token, (4 << 2) | 3, &ops[0], &ops[1], &ops[2]);
362362 return;
363363 case TOK_ASM_sub:
364− asm_emit_r(S, token, (0xC << 2) | 3 | (32 << 25), &ops[0], &ops[1], &ops[2]);
364+ asm_emit_r(token, (0xC << 2) | 3 | (32 << 25), &ops[0], &ops[1], &ops[2]);
365365 return;
366366 case TOK_ASM_addw:
367− asm_emit_r(S, token, (0xE << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
367+ asm_emit_r(token, (0xE << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
368368 return;
369369 case TOK_ASM_addiw: // 64 bit
370− asm_emit_i(S, token, (0x6 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
370+ asm_emit_i(token, (0x6 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
371371 return;
372372 case TOK_ASM_subw:
373− asm_emit_r(S, token, (0xE << 2) | 3 | (0 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
373+ asm_emit_r(token, (0xE << 2) | 3 | (0 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
374374 return;
375375
376376 // Logical (RD,RS1,(RS2|IMM)); R-format or I-format
377377
378378 case TOK_ASM_xor:
379− asm_emit_r(S, token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
379+ asm_emit_r(token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
380380 return;
381381 case TOK_ASM_xori:
382− asm_emit_i(S, token, (0x4 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
382+ asm_emit_i(token, (0x4 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
383383 return;
384384 case TOK_ASM_or:
385− asm_emit_r(S, token, (0xC << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
385+ asm_emit_r(token, (0xC << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
386386 return;
387387 case TOK_ASM_ori:
388− asm_emit_i(S, token, (0x4 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
388+ asm_emit_i(token, (0x4 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
389389 return;
390390 case TOK_ASM_and:
391− asm_emit_r(S, token, (0xC << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
391+ asm_emit_r(token, (0xC << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
392392 return;
393393 case TOK_ASM_andi:
394− asm_emit_i(S, token, (0x4 << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
394+ asm_emit_i(token, (0x4 << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
395395 return;
396396
397397 // Compare (RD,RS1,(RS2|IMM)); R-format or I-format
398398
399399 case TOK_ASM_slt:
400− asm_emit_r(S, token, (0xC << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
400+ asm_emit_r(token, (0xC << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
401401 return;
402402 case TOK_ASM_slti:
403− asm_emit_i(S, token, (0x4 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
403+ asm_emit_i(token, (0x4 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
404404 return;
405405 case TOK_ASM_sltu:
406− asm_emit_r(S, token, (0xC << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
406+ asm_emit_r(token, (0xC << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
407407 return;
408408 case TOK_ASM_sltiu:
409− asm_emit_i(S, token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
409+ asm_emit_i(token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
410410 return;
411411 default:
412− expect(S, "known data processing instruction");
412+ expect("known data processing instruction");
413413 }
414414 }
415415
416416 /* caller: Add funct3 to opcode */
417−static void asm_emit_s(TCCState* S, int token, uint32_t opcode, const Operand* rs1, const Operand* rs2, const Operand* imm)
417+static void asm_emit_s(int token, uint32_t opcode, const Operand* rs1, const Operand* rs2, const Operand* imm)
418418 {
419419 if (rs1->type != OP_REG) {
420− tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
420+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
421421 return;
422422 }
423423 if (rs2->type != OP_REG) {
424− tcc_error(S, "'%s': Expected second source operand that is a register", get_tok_str(S, token, NULL));
424+ tcc_error("'%s': Expected second source operand that is a register", get_tok_str(token, NULL));
425425 return;
426426 }
427427 if (imm->type != OP_IM12S) {
428− tcc_error(S, "'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(S, token, NULL));
428+ tcc_error("'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(token, NULL));
429429 return;
430430 }
431431 {
@@ -438,112 +438,112 @@ static void asm_emit_s(TCCState* S, int token, uint32_t opcode, const Operand* r · 6 unmodified lines
438438 11...7 imm[4:0]
439439 6...0 opcode
440440 opcode always fixed pos. */
441− gen_le32(S, opcode | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg) | ((v & 0x1F) << 7) | ((v >> 5) << 25));
441+ gen_le32(opcode | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg) | ((v & 0x1F) << 7) | ((v >> 5) << 25));
442442 }
443443 }
444444
445−static void asm_data_transfer_opcode(TCCState* S, int token)
445+static void asm_data_transfer_opcode(TCCState* s1, int token)
446446 {
447447 Operand ops[3];
448− parse_operand(S, &ops[0]);
448+ parse_operand(s1, &ops[0]);
449449 if (ops[0].type != OP_REG) {
450− expect(S, "register");
450+ expect("register");
451451 return;
452452 }
453− if (S->tccpp_tok == ',')
454− next(S);
453+ if (tok == ',')
454+ next();
455455 else
456− expect(S, "','");
457− parse_operand(S, &ops[1]);
456+ expect("','");
457+ parse_operand(s1, &ops[1]);
458458 if (ops[1].type != OP_REG) {
459− expect(S, "register");
459+ expect("register");
460460 return;
461461 }
462− if (S->tccpp_tok == ',')
463− next(S);
462+ if (tok == ',')
463+ next();
464464 else
465− expect(S, "','");
466− parse_operand(S, &ops[2]);
465+ expect("','");
466+ parse_operand(s1, &ops[2]);
467467
468468 switch (token) {
469469 // Loads (RD,RS1,I); I-format
470470
471471 case TOK_ASM_lb:
472− asm_emit_i(S, token, (0x0 << 2) | 3, &ops[0], &ops[1], &ops[2]);
472+ asm_emit_i(token, (0x0 << 2) | 3, &ops[0], &ops[1], &ops[2]);
473473 return;
474474 case TOK_ASM_lh:
475− asm_emit_i(S, token, (0x0 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
475+ asm_emit_i(token, (0x0 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
476476 return;
477477 case TOK_ASM_lw:
478− asm_emit_i(S, token, (0x0 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
478+ asm_emit_i(token, (0x0 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
479479 return;
480480 case TOK_ASM_lbu:
481− asm_emit_i(S, token, (0x0 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
481+ asm_emit_i(token, (0x0 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
482482 return;
483483 case TOK_ASM_lhu:
484− asm_emit_i(S, token, (0x0 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
484+ asm_emit_i(token, (0x0 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
485485 return;
486486 // 64 bit
487487 case TOK_ASM_ld:
488− asm_emit_i(S, token, (0x0 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
488+ asm_emit_i(token, (0x0 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
489489 return;
490490 case TOK_ASM_lwu:
491− asm_emit_i(S, token, (0x0 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
491+ asm_emit_i(token, (0x0 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
492492 return;
493493
494494 // Stores (RS1,RS2,I); S-format
495495
496496 case TOK_ASM_sb:
497− asm_emit_s(S, token, (0x8 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
497+ asm_emit_s(token, (0x8 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
498498 return;
499499 case TOK_ASM_sh:
500− asm_emit_s(S, token, (0x8 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
500+ asm_emit_s(token, (0x8 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
501501 return;
502502 case TOK_ASM_sw:
503− asm_emit_s(S, token, (0x8 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
503+ asm_emit_s(token, (0x8 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
504504 return;
505505 case TOK_ASM_sd:
506− asm_emit_s(S, token, (0x8 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
506+ asm_emit_s(token, (0x8 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
507507 return;
508508
509509 default:
510− expect(S, "known data transfer instruction");
510+ expect("known data transfer instruction");
511511 }
512512 }
513513
514−static void asm_branch_opcode(TCCState* S, int token)
514+static void asm_branch_opcode(TCCState* s1, int token)
515515 {
516516 // Branch (RS1,RS2,IMM); SB-format
517517 uint32_t opcode = (0x18 << 2) | 3;
518518 uint32_t offset = 0;
519519 Operand ops[3];
520− parse_operand(S, &ops[0]);
520+ parse_operand(s1, &ops[0]);
521521 if (ops[0].type != OP_REG) {
522− expect(S, "register");
522+ expect("register");
523523 return;
524524 }
525− if (S->tccpp_tok == ',')
526− next(S);
525+ if (tok == ',')
526+ next();
527527 else
528− expect(S, "','");
529− parse_operand(S, &ops[1]);
528+ expect("','");
529+ parse_operand(s1, &ops[1]);
530530 if (ops[1].type != OP_REG) {
531− expect(S, "register");
531+ expect("register");
532532 return;
533533 }
534− if (S->tccpp_tok == ',')
535− next(S);
534+ if (tok == ',')
535+ next();
536536 else
537− expect(S, "','");
538− parse_operand(S, &ops[2]);
537+ expect("','");
538+ parse_operand(s1, &ops[2]);
539539
540540 if (ops[2].type != OP_IM12S) {
541− tcc_error(S, "'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(S, token, NULL));
541+ tcc_error("'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(token, NULL));
542542 return;
543543 }
544544 offset = ops[2].e.v;
545545 if (offset & 1) {
546− tcc_error(S, "'%s': Expected third operand that is an even immediate value", get_tok_str(S, token, NULL));
546+ tcc_error("'%s': Expected third operand that is an even immediate value", get_tok_str(token, NULL));
547547 return;
548548 }
549549
@@ -567,12 +567,12 @@ static void asm_branch_opcode(TCCState* S, int token) · 17 unmodified lines
567567 opcode |= 7 << 12;
568568 break;
569569 default:
570− expect(S, "known branch instruction");
570+ expect("known branch instruction");
571571 }
572− asm_emit_opcode(S, opcode | ENCODE_RS1(ops[0].reg) | ENCODE_RS2(ops[1].reg) | (((offset >> 1) & 0xF) << 8) | (((offset >> 5) & 0x1f) << 25) | (((offset >> 11) & 1) << 7) | (((offset >> 12) & 1) << 31));
572+ asm_emit_opcode(opcode | ENCODE_RS1(ops[0].reg) | ENCODE_RS2(ops[1].reg) | (((offset >> 1) & 0xF) << 8) | (((offset >> 5) & 0x1f) << 25) | (((offset >> 11) & 1) << 7) | (((offset >> 12) & 1) << 31));
573573 }
574574
575−ST_FUNC void asm_opcode(TCCState *S, int token)
575+ST_FUNC void asm_opcode(TCCState *s1, int token)
576576 {
577577 switch (token) {
578578 case TOK_ASM_fence:
@@ -585,7 +585,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 6 unmodified lines
585585 case TOK_ASM_mrth:
586586 case TOK_ASM_hrts:
587587 case TOK_ASM_wfi:
588− asm_nullary_opcode(S, token);
588+ asm_nullary_opcode(s1, token);
589589 return;
590590
591591 case TOK_ASM_rdcycle:
@@ -594,12 +594,12 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 2 unmodified lines
594594 case TOK_ASM_rdtimeh:
595595 case TOK_ASM_rdinstret:
596596 case TOK_ASM_rdinstreth:
597− asm_unary_opcode(S, token);
597+ asm_unary_opcode(s1, token);
598598 return;
599599
600600 case TOK_ASM_lui:
601601 case TOK_ASM_auipc:
602− asm_binary_opcode(S, token);
602+ asm_binary_opcode(s1, token);
603603 return;
604604
605605 case TOK_ASM_sll:
@@ -620,7 +620,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 14 unmodified lines
620620 case TOK_ASM_srad:
621621 case TOK_ASM_sraiw:
622622 case TOK_ASM_sraid:
623− asm_shift_opcode(S, token);
623+ asm_shift_opcode(s1, token);
624624 return;
625625
626626 case TOK_ASM_add:
@@ -642,7 +642,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 15 unmodified lines
642642 case TOK_ASM_slti:
643643 case TOK_ASM_sltu:
644644 case TOK_ASM_sltiu:
645− asm_data_processing_opcode(S, token);
645+ asm_data_processing_opcode(s1, token);
646646
647647 case TOK_ASM_lb:
648648 case TOK_ASM_lh:
@@ -655,7 +655,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 6 unmodified lines
655655 case TOK_ASM_sh:
656656 case TOK_ASM_sw:
657657 case TOK_ASM_sd:
658− asm_data_transfer_opcode(S, token);
658+ asm_data_transfer_opcode(s1, token);
659659 return;
660660
661661 case TOK_ASM_beq:
@@ -664,35 +664,35 @@ ST_FUNC void asm_opcode(TCCState *S, int token) · 2 unmodified lines
664664 case TOK_ASM_bge:
665665 case TOK_ASM_bltu:
666666 case TOK_ASM_bgeu:
667− asm_branch_opcode(S, token);
667+ asm_branch_opcode(s1, token);
668668 return;
669669
670670 default:
671− expect(S, "known instruction");
671+ expect("known instruction");
672672 }
673673 }
674674
675−ST_FUNC void subst_asm_operand(TCCState *S, CString *add_str, SValue *sv, int modifier)
675+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
676676 {
677− tcc_error(S, "RISCV64 asm not implemented.");
677+ tcc_error("RISCV64 asm not implemented.");
678678 }
679679
680680 /* generate prolog and epilog code for asm statement */
681−ST_FUNC void asm_gen_code(TCCState *S, ASMOperand *operands, int nb_operands,
681+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
682682 int nb_outputs, int is_output,
683683 uint8_t *clobber_regs,
684684 int out_reg)
685685 {
686686 }
687687
688−ST_FUNC void asm_compute_constraints(TCCState *S, ASMOperand *operands,
688+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
689689 int nb_operands, int nb_outputs,
690690 const uint8_t *clobber_regs,
691691 int *pout_reg)
692692 {
693693 }
694694
695−ST_FUNC void asm_clobber(TCCState *S, uint8_t *clobber_regs, const char *str)
695+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
696696 {
697697 int reg;
698698 TokenSym *ts;
@@ -701,15 +701,15 @@ ST_FUNC void asm_clobber(TCCState *S, uint8_t *clobber_regs, const char *str) · 2 unmodified lines
701701 !strcmp(str, "cc") ||
702702 !strcmp(str, "flags"))
703703 return;
704− ts = tok_alloc(S, str, strlen(str));
705− reg = asm_parse_regvar(S, ts->tok);
704+ ts = tok_alloc(str, strlen(str));
705+ reg = asm_parse_regvar(ts->tok);
706706 if (reg == -1) {
707− tcc_error(S, "invalid clobber register '%s'", str);
707+ tcc_error("invalid clobber register '%s'", str);
708708 }
709709 clobber_regs[reg] = 1;
710710 }
711711
712−ST_FUNC int asm_parse_regvar (TCCState* S, int t)
712+ST_FUNC int asm_parse_regvar (int t)
713713 {
714714 if (t >= TOK_ASM_x0 && t <= TOK_ASM_pc) { /* register name */
715715 switch (t) {
riscv64-gen.c+457−451
@@ -74,6 +74,12 @@ ST_DATA const int reg_classes[NB_REGS] = { · 73 unmodified lines
7474 1 << TREG_SP
7575 };
7676
77+#if defined(CONFIG_TCC_BCHECK)
78+static addr_t func_bound_offset;
79+static unsigned long func_bound_ind;
80+ST_DATA int func_bound_add_epilog;
81+#endif
82+
7783 static int ireg(int r)
7884 {
7985 if (r == TREG_RA)
@@ -100,46 +106,46 @@ static int is_freg(int r) · 20 unmodified lines
100106 return r >= 8 && r < 16;
101107 }
102108
103−ST_FUNC void o(TCCState* S, unsigned int c)
109+ST_FUNC void o(unsigned int c)
104110 {
105− int ind1 = S->tccgen_ind + 4;
106− if (S->tccgen_nocode_wanted)
111+ int ind1 = ind + 4;
112+ if (nocode_wanted)
107113 return;
108114 if (ind1 > cur_text_section->data_allocated)
109− section_realloc(S, cur_text_section, ind1);
110− write32le(cur_text_section->data + S->tccgen_ind, c);
111− S->tccgen_ind = ind1;
115+ section_realloc(cur_text_section, ind1);
116+ write32le(cur_text_section->data + ind, c);
117+ ind = ind1;
112118 }
113119
114−static void EIu(TCCState* S, uint32_t opcode, uint32_t func3,
120+static void EIu(uint32_t opcode, uint32_t func3,
115121 uint32_t rd, uint32_t rs1, uint32_t imm)
116122 {
117− o(S, opcode | (func3 << 12) | (rd << 7) | (rs1 << 15) | (imm << 20));
123+ o(opcode | (func3 << 12) | (rd << 7) | (rs1 << 15) | (imm << 20));
118124 }
119125
120−static void ER(TCCState* S, uint32_t opcode, uint32_t func3,
126+static void ER(uint32_t opcode, uint32_t func3,
121127 uint32_t rd, uint32_t rs1, uint32_t rs2, uint32_t func7)
122128 {
123− o(S, opcode | func3 << 12 | rd << 7 | rs1 << 15 | rs2 << 20 | func7 << 25);
129+ o(opcode | func3 << 12 | rd << 7 | rs1 << 15 | rs2 << 20 | func7 << 25);
124130 }
125131
126−static void EI(TCCState* S, uint32_t opcode, uint32_t func3,
132+static void EI(uint32_t opcode, uint32_t func3,
127133 uint32_t rd, uint32_t rs1, uint32_t imm)
128134 {
129135 assert(! ((imm + (1 << 11)) >> 12));
130− EIu(S, opcode, func3, rd, rs1, imm);
136+ EIu(opcode, func3, rd, rs1, imm);
131137 }
132138
133−static void ES(TCCState* S, uint32_t opcode, uint32_t func3,
139+static void ES(uint32_t opcode, uint32_t func3,
134140 uint32_t rs1, uint32_t rs2, uint32_t imm)
135141 {
136142 assert(! ((imm + (1 << 11)) >> 12));
137− o(S, opcode | (func3 << 12) | ((imm & 0x1f) << 7) | (rs1 << 15)
143+ o(opcode | (func3 << 12) | ((imm & 0x1f) << 7) | (rs1 << 15)
138144 | (rs2 << 20) | ((imm >> 5) << 25));
139145 }
140146
141147 // Patch all branches in list pointed to by t to branch to a:
142−ST_FUNC void gsym_addr(TCCState* S, int t_, int a_)
148+ST_FUNC void gsym_addr(int t_, int a_)
143149 {
144150 uint32_t t = t_;
145151 uint32_t a = a_;
@@ -148,7 +154,7 @@ ST_FUNC void gsym_addr(TCCState* S, int t_, int a_) · 2 unmodified lines
148154 uint32_t next = read32le(ptr);
149155 uint32_t r = a - t, imm;
150156 if ((r + (1 << 21)) & ~((1U << 22) - 2))
151− tcc_error(S, "out-of-range branch chain");
157+ tcc_error("out-of-range branch chain");
152158 imm = (((r >> 12) & 0xff) << 12)
153159 | (((r >> 11) & 1) << 20)
154160 | (((r >> 1) & 0x3ff) << 21)
@@ -158,7 +164,7 @@ ST_FUNC void gsym_addr(TCCState* S, int t_, int a_) · 3 unmodified lines
158164 }
159165 }
160166
161−static int load_symofs(TCCState* S, int r, SValue *sv, int forstore)
167+static int load_symofs(int r, SValue *sv, int forstore)
162168 {
163169 int rr, doload = 0;
164170 int fc = sv->c.i, v = sv->r & VT_VALMASK;
@@ -166,56 +172,56 @@ static int load_symofs(TCCState* S, int r, SValue *sv, int forstore) · 1 unmodified line
166172 Sym label = {0};
167173 assert(v == VT_CONST);
168174 if (sv->sym->type.t & VT_STATIC) { // XXX do this per linker relax
169− greloca(S, cur_text_section, sv->sym, S->tccgen_ind,
175+ greloca(cur_text_section, sv->sym, ind,
170176 R_RISCV_PCREL_HI20, sv->c.i);
171177 sv->c.i = 0;
172178 } else {
173179 if (((unsigned)fc + (1 << 11)) >> 12)
174− tcc_error(S, "unimp: large addend for global address (0x%lx)", (long)sv->c.i);
175− greloca(S, cur_text_section, sv->sym, S->tccgen_ind,
180+ tcc_error("unimp: large addend for global address (0x%lx)", (long)sv->c.i);
181+ greloca(cur_text_section, sv->sym, ind,
176182 R_RISCV_GOT_HI20, 0);
177183 doload = 1;
178184 }
179185 label.type.t = VT_VOID | VT_STATIC;
180− put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
186+ put_extern_sym(&label, cur_text_section, ind, 0);
181187 rr = is_ireg(r) ? ireg(r) : 5;
182− o(S, 0x17 | (rr << 7)); // auipc RR, 0 %pcrel_hi(sym)+addend
183− greloca(S, cur_text_section, &label, S->tccgen_ind,
188+ o(0x17 | (rr << 7)); // auipc RR, 0 %pcrel_hi(sym)+addend
189+ greloca(cur_text_section, &label, ind,
184190 doload || !forstore
185191 ? R_RISCV_PCREL_LO12_I : R_RISCV_PCREL_LO12_S, 0);
186192 if (doload) {
187− EI(S, 0x03, 3, rr, rr, 0); // ld RR, 0(RR)
193+ EI(0x03, 3, rr, rr, 0); // ld RR, 0(RR)
188194 }
189195 } else if (v == VT_LOCAL || v == VT_LLOCAL) {
190196 rr = 8; // s0
191197 if (fc != sv->c.i)
192− tcc_error(S, "unimp: store(giant local off) (0x%lx)", (long)sv->c.i);
198+ tcc_error("unimp: store(giant local off) (0x%lx)", (long)sv->c.i);
193199 if (((unsigned)fc + (1 << 11)) >> 12) {
194200 rr = is_ireg(r) ? ireg(r) : 5; // t0
195− o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
196− ER(S, 0x33, 0, rr, rr, 8, 0); // add RR, RR, s0
201+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
202+ ER(0x33, 0, rr, rr, 8, 0); // add RR, RR, s0
197203 sv->c.i = fc << 20 >> 20;
198204 }
199205 } else
200− tcc_error(S, "uhh");
206+ tcc_error("uhh");
201207 return rr;
202208 }
203209
204−static void load_large_constant(TCCState* S, int rr, int fc, uint32_t pi)
210+static void load_large_constant(int rr, int fc, uint32_t pi)
205211 {
206212 if (fc < 0)
207213 pi++;
208− o(S, 0x37 | (rr << 7) | (((pi + 0x800) & 0xfffff000))); // lui RR, up(up(fc))
209− EI(S, 0x13, 0, rr, rr, (int)pi << 20 >> 20); // addi RR, RR, lo(up(fc))
210− EI(S, 0x13, 1, rr, rr, 12); // slli RR, RR, 12
211− EI(S, 0x13, 0, rr, rr, (fc + (1 << 19)) >> 20); // addi RR, RR, up(lo(fc))
212− EI(S, 0x13, 1, rr, rr, 12); // slli RR, RR, 12
214+ o(0x37 | (rr << 7) | (((pi + 0x800) & 0xfffff000))); // lui RR, up(up(fc))
215+ EI(0x13, 0, rr, rr, (int)pi << 20 >> 20); // addi RR, RR, lo(up(fc))
216+ EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
217+ EI(0x13, 0, rr, rr, (fc + (1 << 19)) >> 20); // addi RR, RR, up(lo(fc))
218+ EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
213219 fc = fc << 12 >> 12;
214− EI(S, 0x13, 0, rr, rr, fc >> 8); // addi RR, RR, lo1(lo(fc))
215− EI(S, 0x13, 1, rr, rr, 8); // slli RR, RR, 8
220+ EI(0x13, 0, rr, rr, fc >> 8); // addi RR, RR, lo1(lo(fc))
221+ EI(0x13, 1, rr, rr, 8); // slli RR, RR, 8
216222 }
217223
218−ST_FUNC void load(TCCState* S, int r, SValue *sv)
224+ST_FUNC void load(int r, SValue *sv)
219225 {
220226 int fr = sv->r;
221227 int v = fr & VT_VALMASK;
@@ -233,49 +239,49 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv) · 11 unmodified lines
233239 if (size < 4 && !is_float(sv->type.t) && (sv->type.t & VT_UNSIGNED))
234240 func3 |= 4;
235241 if (v == VT_LOCAL || (fr & VT_SYM)) {
236− br = load_symofs(S, r, sv, 0);
242+ br = load_symofs(r, sv, 0);
237243 fc = sv->c.i;
238244 } else if (v < VT_CONST) {
239245 br = ireg(v);
240246 /*if (((unsigned)fc + (1 << 11)) >> 12)
241− tcc_error(S, "unimp: load(large addend) (0x%x)", fc);*/
247+ tcc_error("unimp: load(large addend) (0x%x)", fc);*/
242248 fc = 0; // XXX store ofs in LVAL(reg)
243249 } else if (v == VT_LLOCAL) {
244− br = load_symofs(S, r, sv, 0);
250+ br = load_symofs(r, sv, 0);
245251 fc = sv->c.i;
246− EI(S, 0x03, 3, rr, br, fc); // ld RR, fc(BR)
252+ EI(0x03, 3, rr, br, fc); // ld RR, fc(BR)
247253 br = rr;
248254 fc = 0;
249255 } else if (v == VT_CONST) {
250256 int64_t si = sv->c.i;
251257 si >>= 32;
252258 if (si != 0) {
253− load_large_constant(S, rr, fc, si);
259+ load_large_constant(rr, fc, si);
254260 fc &= 0xff;
255261 } else {
256− o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
262+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
257263 fc = fc << 20 >> 20;
258264 }
259265 br = rr;
260266 } else {
261− tcc_error(S, "unimp: load(non-local lval)");
267+ tcc_error("unimp: load(non-local lval)");
262268 }
263− EI(S, opcode, func3, rr, br, fc); // l[bhwd][u] / fl[wd] RR, fc(BR)
269+ EI(opcode, func3, rr, br, fc); // l[bhwd][u] / fl[wd] RR, fc(BR)
264270 } else if (v == VT_CONST) {
265271 int rb = 0, do32bit = 8, zext = 0;
266272 assert((!is_float(sv->type.t) && is_ireg(r)) || bt == VT_LDOUBLE);
267273 if (fr & VT_SYM) {
268− rb = load_symofs(S, r, sv, 0);
274+ rb = load_symofs(r, sv, 0);
269275 fc = sv->c.i;
270276 do32bit = 0;
271277 }
272278 if (is_float(sv->type.t) && bt != VT_LDOUBLE)
273− tcc_error(S, "unimp: load(float)");
279+ tcc_error("unimp: load(float)");
274280 if (fc != sv->c.i) {
275281 int64_t si = sv->c.i;
276282 si >>= 32;
277283 if (si != 0) {
278− load_large_constant(S, rr, fc, si);
284+ load_large_constant(rr, fc, si);
279285 fc &= 0xff;
280286 rb = rr;
281287 do32bit = 0;
@@ -286,37 +292,37 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv) · 4 unmodified lines
286292 }
287293 }
288294 if (((unsigned)fc + (1 << 11)) >> 12)
289− o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)), rb = rr; //lui RR, upper(fc)
295+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)), rb = rr; //lui RR, upper(fc)
290296 if (fc || (rr != rb) || do32bit || (fr & VT_SYM))
291− EI(S, 0x13 | do32bit, 0, rr, rb, fc << 20 >> 20); // addi[w] R, x0|R, FC
297+ EI(0x13 | do32bit, 0, rr, rb, fc << 20 >> 20); // addi[w] R, x0|R, FC
292298 if (zext) {
293− EI(S, 0x13, 1, rr, rr, 32); // slli RR, RR, 32
294− EI(S, 0x13, 5, rr, rr, 32); // srli RR, RR, 32
299+ EI(0x13, 1, rr, rr, 32); // slli RR, RR, 32
300+ EI(0x13, 5, rr, rr, 32); // srli RR, RR, 32
295301 }
296302 } else if (v == VT_LOCAL) {
297− int br = load_symofs(S, r, sv, 0);
303+ int br = load_symofs(r, sv, 0);
298304 assert(is_ireg(r));
299305 fc = sv->c.i;
300− EI(S, 0x13, 0, rr, br, fc); // addi R, s0, FC
306+ EI(0x13, 0, rr, br, fc); // addi R, s0, FC
301307 } else if (v < VT_CONST) { /* reg-reg */
302308 //assert(!fc); XXX support offseted regs
303309 if (is_freg(r) && is_freg(v))
304− ER(S, 0x53, 0, rr, freg(v), freg(v), bt == VT_DOUBLE ? 0x11 : 0x10); //fsgnj.[sd] RR, V, V == fmv.[sd] RR, V
310+ ER(0x53, 0, rr, freg(v), freg(v), bt == VT_DOUBLE ? 0x11 : 0x10); //fsgnj.[sd] RR, V, V == fmv.[sd] RR, V
305311 else if (is_ireg(r) && is_ireg(v))
306− EI(S, 0x13, 0, rr, ireg(v), 0); // addi RR, V, 0 == mv RR, V
312+ EI(0x13, 0, rr, ireg(v), 0); // addi RR, V, 0 == mv RR, V
307313 else {
308314 int func7 = is_ireg(r) ? 0x70 : 0x78;
309315 size = type_size(&sv->type, &align);
310316 if (size == 8)
311317 func7 |= 1;
312318 assert(size == 4 || size == 8);
313− o(S, 0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)
319+ o(0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)
314320 | (func7 << 25)); // fmv.{w.x, x.w, d.x, x.d} RR, VR
315321 }
316322 } else if (v == VT_CMP) {
317− int op = S->tccgen_vtop->cmp_op;
318− int a = S->tccgen_vtop->cmp_r & 0xff;
319− int b = (S->tccgen_vtop->cmp_r >> 8) & 0xff;
323+ int op = vtop->cmp_op;
324+ int a = vtop->cmp_r & 0xff;
325+ int b = (vtop->cmp_r >> 8) & 0xff;
320326 int inv = 0;
321327 switch (op) {
322328 case TOK_ULT:
@@ -335,32 +341,32 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv) · 12 unmodified lines
335341 int t = a; a = b; b = t;
336342 inv ^= 1;
337343 }
338− ER(S, 0x33, (op > TOK_UGT) ? 2 : 3, rr, a, b, 0); // slt[u] d, a, b
344+ ER(0x33, (op > TOK_UGT) ? 2 : 3, rr, a, b, 0); // slt[u] d, a, b
339345 if (inv)
340− EI(S, 0x13, 4, rr, rr, 1); // xori d, d, 1
346+ EI(0x13, 4, rr, rr, 1); // xori d, d, 1
341347 break;
342348 case TOK_NE:
343349 case TOK_EQ:
344350 if (rr != a || b)
345− ER(S, 0x33, 0, rr, a, b, 0x20); // sub d, a, b
351+ ER(0x33, 0, rr, a, b, 0x20); // sub d, a, b
346352 if (op == TOK_NE)
347− ER(S, 0x33, 3, rr, 0, rr, 0); // sltu d, x0, d == snez d,d
353+ ER(0x33, 3, rr, 0, rr, 0); // sltu d, x0, d == snez d,d
348354 else
349− EI(S, 0x13, 3, rr, rr, 1); // sltiu d, d, 1 == seqz d,d
355+ EI(0x13, 3, rr, rr, 1); // sltiu d, d, 1 == seqz d,d
350356 break;
351357 }
352358 } else if ((v & ~1) == VT_JMP) {
353359 int t = v & 1;
354360 assert(is_ireg(r));
355− EI(S, 0x13, 0, rr, 0, t); // addi RR, x0, t
356− gjmp_addr(S, S->tccgen_ind + 8);
357− gsym(S, fc);
358− EI(S, 0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t
361+ EI(0x13, 0, rr, 0, t); // addi RR, x0, t
362+ gjmp_addr(ind + 8);
363+ gsym(fc);
364+ EI(0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t
359365 } else
360− tcc_error(S, "unimp: load(non-const)");
366+ tcc_error("unimp: load(non-const)");
361367 }
362368
363−ST_FUNC void store(TCCState* S, int r, SValue *sv)
369+ST_FUNC void store(int r, SValue *sv)
364370 {
365371 int fr = sv->r & VT_VALMASK;
366372 int rr = is_ireg(r) ? ireg(r) : freg(r), ptrreg;
@@ -373,125 +379,125 @@ ST_FUNC void store(TCCState* S, int r, SValue *sv) · 6 unmodified lines
373379 if (bt == VT_LDOUBLE)
374380 size = align = 8;
375381 if (bt == VT_STRUCT)
376− tcc_error(S, "unimp: store(struct)");
382+ tcc_error("unimp: store(struct)");
377383 if (size > 8)
378− tcc_error(S, "unimp: large sized store");
384+ tcc_error("unimp: large sized store");
379385 assert(sv->r & VT_LVAL);
380386 if (fr == VT_LOCAL || (sv->r & VT_SYM)) {
381− ptrreg = load_symofs(S, -1, sv, 1);
387+ ptrreg = load_symofs(-1, sv, 1);
382388 fc = sv->c.i;
383389 } else if (fr < VT_CONST) {
384390 ptrreg = ireg(fr);
385391 /*if (((unsigned)fc + (1 << 11)) >> 12)
386− tcc_error(S, "unimp: store(large addend) (0x%x)", fc);*/
392+ tcc_error("unimp: store(large addend) (0x%x)", fc);*/
387393 fc = 0; // XXX support offsets regs
388394 } else if (fr == VT_CONST) {
389395 int64_t si = sv->c.i;
390396 ptrreg = 8; // s0
391397 si >>= 32;
392398 if (si != 0) {
393− load_large_constant(S, ptrreg, fc, si);
399+ load_large_constant(ptrreg, fc, si);
394400 fc &= 0xff;
395401 } else {
396− o(S, 0x37 | (ptrreg << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
402+ o(0x37 | (ptrreg << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
397403 fc = fc << 20 >> 20;
398404 }
399405 } else
400− tcc_error(S, "implement me: %s(!local)", __FUNCTION__);
401− ES(S, is_freg(r) ? 0x27 : 0x23, // fs... | s...
406+ tcc_error("implement me: %s(!local)", __FUNCTION__);
407+ ES(is_freg(r) ? 0x27 : 0x23, // fs... | s...
402408 size == 1 ? 0 : size == 2 ? 1 : size == 4 ? 2 : 3, // ... [wd] | [bhwd]
403409 ptrreg, rr, fc); // RR, fc(base)
404410 }
405411
406−static void gcall_or_jmp(TCCState* S, int docall)
412+static void gcall_or_jmp(int docall)
407413 {
408414 int tr = docall ? 1 : 5; // ra or t0
409− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
410− ((S->tccgen_vtop->r & VT_SYM) && S->tccgen_vtop->c.i == (int)S->tccgen_vtop->c.i)) {
415+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
416+ ((vtop->r & VT_SYM) && vtop->c.i == (int)vtop->c.i)) {
411417 /* constant symbolic case -> simple relocation */
412− greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind,
413− R_RISCV_CALL_PLT, (int)S->tccgen_vtop->c.i);
414− o(S, 0x17 | (tr << 7)); // auipc TR, 0 %call(func)
415− EI(S, 0x67, 0, tr, tr, 0);// jalr TR, r(TR)
416− } else if (S->tccgen_vtop->r < VT_CONST) {
417− int r = ireg(S->tccgen_vtop->r);
418− EI(S, 0x67, 0, tr, r, 0); // jalr TR, 0(R)
418+ greloca(cur_text_section, vtop->sym, ind,
419+ R_RISCV_CALL_PLT, (int)vtop->c.i);
420+ o(0x17 | (tr << 7)); // auipc TR, 0 %call(func)
421+ EI(0x67, 0, tr, tr, 0);// jalr TR, r(TR)
422+ } else if (vtop->r < VT_CONST) {
423+ int r = ireg(vtop->r);
424+ EI(0x67, 0, tr, r, 0); // jalr TR, 0(R)
419425 } else {
420426 int r = TREG_RA;
421− load(S, r, S->tccgen_vtop);
427+ load(r, vtop);
422428 r = ireg(r);
423− EI(S, 0x67, 0, tr, r, 0); // jalr TR, 0(R)
429+ EI(0x67, 0, tr, r, 0); // jalr TR, 0(R)
424430 }
425431 }
426432
427433 #if defined(CONFIG_TCC_BCHECK)
428434
429−static void gen_bounds_call(TCCState* S, int v)
435+static void gen_bounds_call(int v)
430436 {
431− Sym *sym = external_helper_sym(S, v);
437+ Sym *sym = external_helper_sym(v);
432438
433− greloca(S, cur_text_section, sym, S->tccgen_ind, R_RISCV_CALL_PLT, 0);
434− o(S, 0x17 | (1 << 7)); // auipc TR, 0 %call(func)
435− EI(S, 0x67, 0, 1, 1, 0); // jalr TR, r(TR)
439+ greloca(cur_text_section, sym, ind, R_RISCV_CALL_PLT, 0);
440+ o(0x17 | (1 << 7)); // auipc TR, 0 %call(func)
441+ EI(0x67, 0, 1, 1, 0); // jalr TR, r(TR)
436442 }
437443
438−static void gen_bounds_prolog(TCCState* S)
444+static void gen_bounds_prolog(void)
439445 {
440446 /* leave some room for bound checking code */
441− S->func_bound_offset = lbounds_section->data_offset;
442− S->func_bound_ind = S->tccgen_ind;
443− S->func_bound_add_epilog = 0;
444− o(S, 0x00000013); /* ld a0,#lbound section pointer */
445− o(S, 0x00000013);
446− o(S, 0x00000013); /* nop -> call __bound_local_new */
447− o(S, 0x00000013);
447+ func_bound_offset = lbounds_section->data_offset;
448+ func_bound_ind = ind;
449+ func_bound_add_epilog = 0;
450+ o(0x00000013); /* ld a0,#lbound section pointer */
451+ o(0x00000013);
452+ o(0x00000013); /* nop -> call __bound_local_new */
453+ o(0x00000013);
448454 }
449455
450−static void gen_bounds_epilog(TCCState* S)
456+static void gen_bounds_epilog(void)
451457 {
452458 addr_t saved_ind;
453459 addr_t *bounds_ptr;
454460 Sym *sym_data;
455461 Sym label = {0};
456462
457− int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
463+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
458464
459− if (!offset_modified && !S->func_bound_add_epilog)
465+ if (!offset_modified && !func_bound_add_epilog)
460466 return;
461467
462468 /* add end of table info */
463− bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
469+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
464470 *bounds_ptr = 0;
465471
466− sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
467− S->func_bound_offset, lbounds_section->data_offset);
472+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
473+ func_bound_offset, lbounds_section->data_offset);
468474
469475 label.type.t = VT_VOID | VT_STATIC;
470476 /* generate bound local allocation */
471477 if (offset_modified) {
472− saved_ind = S->tccgen_ind;
473− S->tccgen_ind = S->func_bound_ind;
474− put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
475− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_RISCV_GOT_HI20, 0);
476− o(S, 0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
477− greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
478− EI(S, 0x03, 3, 10, 10, 0); // ld a0, 0(a0)
479− gen_bounds_call(S, TOK___bound_local_new);
480− S->tccgen_ind = saved_ind;
478+ saved_ind = ind;
479+ ind = func_bound_ind;
480+ put_extern_sym(&label, cur_text_section, ind, 0);
481+ greloca(cur_text_section, sym_data, ind, R_RISCV_GOT_HI20, 0);
482+ o(0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
483+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
484+ EI(0x03, 3, 10, 10, 0); // ld a0, 0(a0)
485+ gen_bounds_call(TOK___bound_local_new);
486+ ind = saved_ind;
481487 label.c = 0; /* force new local ELF symbol */
482488 }
483489
484490 /* generate bound check local freeing */
485− o(S, 0xe02a1101); /* addi sp,sp,-32 sd a0,0(sp) */
486− o(S, 0xa82ae42e); /* sd a1,8(sp) fsd fa0,16(sp) */
487− put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
488− greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_RISCV_GOT_HI20, 0);
489− o(S, 0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
490− greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
491− EI(S, 0x03, 3, 10, 10, 0); // ld a0, 0(a0)
492− gen_bounds_call(S, TOK___bound_local_delete);
493− o(S, 0x65a26502); /* ld a0,0(sp) ld a1,8(sp) */
494− o(S, 0x61052542); /* fld fa0,16(sp) addi sp,sp,32 */
491+ o(0xe02a1101); /* addi sp,sp,-32 sd a0,0(sp) */
492+ o(0xa82ae42e); /* sd a1,8(sp) fsd fa0,16(sp) */
493+ put_extern_sym(&label, cur_text_section, ind, 0);
494+ greloca(cur_text_section, sym_data, ind, R_RISCV_GOT_HI20, 0);
495+ o(0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
496+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
497+ EI(0x03, 3, 10, 10, 0); // ld a0, 0(a0)
498+ gen_bounds_call(TOK___bound_local_delete);
499+ o(0x65a26502); /* ld a0,0(sp) ld a1,8(sp) */
500+ o(0x61052542); /* fld fa0,16(sp) addi sp,sp,32 */
495501 }
496502 #endif
497503
@@ -540,27 +546,27 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named) · 42 unmodified lines
540546 }
541547 }
542548
543−ST_FUNC void gfunc_call(TCCState* S, int nb_args)
549+ST_FUNC void gfunc_call(int nb_args)
544550 {
545551 int i, align, size, areg[2];
546− int *info = tcc_malloc(S, (nb_args + 1) * sizeof (int));
552+ int *info = tcc_malloc((nb_args + 1) * sizeof (int));
547553 int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0;
548554 SValue *sv;
549555 Sym *sa;
550556
551557 #ifdef CONFIG_TCC_BCHECK
552− int bc_save = S->do_bounds_check;
553− if (S->do_bounds_check)
554− gbound_args(S, nb_args);
558+ int bc_save = tcc_state->do_bounds_check;
559+ if (tcc_state->do_bounds_check)
560+ gbound_args(nb_args);
555561 #endif
556562
557563 areg[0] = 0; /* int arg regs */
558564 areg[1] = 8; /* float arg regs */
559− sa = S->tccgen_vtop[-nb_args].type.ref->next;
565+ sa = vtop[-nb_args].type.ref->next;
560566 for (i = 0; i < nb_args; i++) {
561567 int nregs, byref = 0, tempofs;
562568 int prc[3], fieldofs[3];
563− sv = &S->tccgen_vtop[1 + i - nb_args];
569+ sv = &vtop[1 + i - nb_args];
564570 sv->type.t &= ~VT_ARRAY; // XXX this should be done in tccgen.c
565571 size = type_size(&sv->type, &align);
566572 if (size > 16) {
@@ -617,53 +623,53 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args) · 50 unmodified lines
617623 stack_add = stack_adj + tempspace;
618624
619625 /* fetch cpu flag before generating any code */
620− if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP)
621− gv(S, RC_INT);
626+ if ((vtop->r & VT_VALMASK) == VT_CMP)
627+ gv(RC_INT);
622628
623629 if (stack_add) {
624630 if (stack_add >= 0x1000) {
625− o(S, 0x37 | (5 << 7) | (-stack_add & 0xfffff000)); //lui t0, upper(v)
626− EI(S, 0x13, 0, 5, 5, -stack_add << 20 >> 20); // addi t0, t0, lo(v)
627− ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
631+ o(0x37 | (5 << 7) | (-stack_add & 0xfffff000)); //lui t0, upper(v)
632+ EI(0x13, 0, 5, 5, -stack_add << 20 >> 20); // addi t0, t0, lo(v)
633+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
628634 }
629635 else
630− EI(S, 0x13, 0, 2, 2, -stack_add); // addi sp, sp, -adj
636+ EI(0x13, 0, 2, 2, -stack_add); // addi sp, sp, -adj
631637 for (i = ofs = 0; i < nb_args; i++) {
632638 if (info[i] & (64 | 32)) {
633− vrotb(S, nb_args - i);
634− size = type_size(&S->tccgen_vtop->type, &align);
639+ vrotb(nb_args - i);
640+ size = type_size(&vtop->type, &align);
635641 if (info[i] & 64) {
636− vset(S, &S->tccgen_char_pointer_type, TREG_SP, 0);
637− vpushi(S, stack_adj + (info[i] >> 7));
638− gen_op(S, '+');
639− vpushv(S, S->tccgen_vtop); // this replaces the old argument
640− vrott(S, 3);
641− indir(S);
642− S->tccgen_vtop->type = S->tccgen_vtop[-1].type;
643− vswap(S);
644− vstore(S);
645− vpop(S);
642+ vset(&char_pointer_type, TREG_SP, 0);
643+ vpushi(stack_adj + (info[i] >> 7));
644+ gen_op('+');
645+ vpushv(vtop); // this replaces the old argument
646+ vrott(3);
647+ indir();
648+ vtop->type = vtop[-1].type;
649+ vswap();
650+ vstore();
651+ vpop();
646652 size = align = 8;
647653 }
648654 if (info[i] & 32) {
649655 if (align < XLEN)
650656 align = XLEN;
651657 /* Once we support offseted regs we can do this:
652− vset(S, &S->tccgen_vtop->type, TREG_SP | VT_LVAL, ofs);
658+ vset(&vtop->type, TREG_SP | VT_LVAL, ofs);
653659 to construct the lvalue for the outgoing stack slot,
654660 until then we have to jump through hoops. */
655− vset(S, &S->tccgen_char_pointer_type, TREG_SP, 0);
661+ vset(&char_pointer_type, TREG_SP, 0);
656662 ofs = (ofs + align - 1) & -align;
657− vpushi(S, ofs);
658− gen_op(S, '+');
659− indir(S);
660− S->tccgen_vtop->type = S->tccgen_vtop[-1].type;
661− vswap(S);
662− vstore(S);
663− S->tccgen_vtop->r = S->tccgen_vtop->r2 = VT_CONST; // this arg is done
663+ vpushi(ofs);
664+ gen_op('+');
665+ indir();
666+ vtop->type = vtop[-1].type;
667+ vswap();
668+ vstore();
669+ vtop->r = vtop->r2 = VT_CONST; // this arg is done
664670 ofs += size;
665671 }
666− vrott(S, nb_args - i);
672+ vrott(nb_args - i);
667673 } else if (info[i] & 16) {
668674 assert(!splitofs);
669675 splitofs = ofs;
@@ -679,12 +685,12 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args) · 9 unmodified lines
679685 r &= 15;
680686 r2 = r2 & 64 ? 0 : (r2 >> 7) & 31;
681687 assert(r2 <= 16);
682− vrotb(S, i+1);
683− origtype = S->tccgen_vtop->type;
684− size = type_size(&S->tccgen_vtop->type, &align);
688+ vrotb(i+1);
689+ origtype = vtop->type;
690+ size = type_size(&vtop->type, &align);
685691 if (size == 0)
686692 goto done;
687− loadt = S->tccgen_vtop->type.t & VT_BTYPE;
693+ loadt = vtop->type.t & VT_BTYPE;
688694 if (loadt == VT_STRUCT) {
689695 loadt = (ii >> 12) & VT_BTYPE;
690696 }
@@ -696,74 +702,74 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args) · 5 unmodified lines
696702 assert(r2);
697703 r2--;
698704 } else if (r2) {
699− test_lvalue(S);
700− vpushv(S, S->tccgen_vtop);
705+ test_lvalue();
706+ vpushv(vtop);
701707 }
702− S->tccgen_vtop->type.t = loadt | (S->tccgen_vtop->type.t & VT_UNSIGNED);
703− gv(S, r < 8 ? RC_R(r) : RC_F(r - 8));
704− S->tccgen_vtop->type = origtype;
708+ vtop->type.t = loadt | (vtop->type.t & VT_UNSIGNED);
709+ gv(r < 8 ? RC_R(r) : RC_F(r - 8));
710+ vtop->type = origtype;
705711
706712 if (r2 && loadt != VT_LDOUBLE) {
707713 r2--;
708714 assert(r2 < 16 || r2 == TREG_RA);
709− vswap(S);
710− gaddrof(S);
711− S->tccgen_vtop->type = S->tccgen_char_pointer_type;
712− vpushi(S, ii >> 20);
715+ vswap();
716+ gaddrof();
717+ vtop->type = char_pointer_type;
718+ vpushi(ii >> 20);
713719 #ifdef CONFIG_TCC_BCHECK
714720 if ((origtype.t & VT_BTYPE) == VT_STRUCT)
715− S->do_bounds_check = 0;
721+ tcc_state->do_bounds_check = 0;
716722 #endif
717− gen_op(S, '+');
723+ gen_op('+');
718724 #ifdef CONFIG_TCC_BCHECK
719− S->do_bounds_check = bc_save;
725+ tcc_state->do_bounds_check = bc_save;
720726 #endif
721− indir(S);
722− S->tccgen_vtop->type = origtype;
723− loadt = S->tccgen_vtop->type.t & VT_BTYPE;
727+ indir();
728+ vtop->type = origtype;
729+ loadt = vtop->type.t & VT_BTYPE;
724730 if (loadt == VT_STRUCT) {
725731 loadt = (ii >> 16) & VT_BTYPE;
726732 }
727− save_reg_upstack(S, r2, 1);
728− S->tccgen_vtop->type.t = loadt | (S->tccgen_vtop->type.t & VT_UNSIGNED);
729− load(S, r2, S->tccgen_vtop);
733+ save_reg_upstack(r2, 1);
734+ vtop->type.t = loadt | (vtop->type.t & VT_UNSIGNED);
735+ load(r2, vtop);
730736 assert(r2 < VT_CONST);
731− S->tccgen_vtop--;
732− S->tccgen_vtop->r2 = r2;
737+ vtop--;
738+ vtop->r2 = r2;
733739 }
734740 if (info[nb_args - 1 - i] & 16) {
735− ES(S, 0x23, 3, 2, ireg(S->tccgen_vtop->r2), splitofs); // sd t0, ofs(sp)
736− S->tccgen_vtop->r2 = VT_CONST;
737− } else if (loadt == VT_LDOUBLE && S->tccgen_vtop->r2 != r2) {
738− assert(S->tccgen_vtop->r2 <= 7 && r2 <= 7);
741+ ES(0x23, 3, 2, ireg(vtop->r2), splitofs); // sd t0, ofs(sp)
742+ vtop->r2 = VT_CONST;
743+ } else if (loadt == VT_LDOUBLE && vtop->r2 != r2) {
744+ assert(vtop->r2 <= 7 && r2 <= 7);
739745 /* XXX we'd like to have 'gv' move directly into
740746 the right class instead of us fixing it up. */
741− EI(S, 0x13, 0, ireg(r2), ireg(S->tccgen_vtop->r2), 0); // mv Ra+1, RR2
742− S->tccgen_vtop->r2 = r2;
747+ EI(0x13, 0, ireg(r2), ireg(vtop->r2), 0); // mv Ra+1, RR2
748+ vtop->r2 = r2;
743749 }
744750 done:
745− vrott(S, i+1);
751+ vrott(i+1);
746752 }
747753 }
748− vrotb(S, nb_args + 1);
749− save_regs(S, nb_args + 1);
750− gcall_or_jmp(S, 1);
751− S->tccgen_vtop -= nb_args + 1;
754+ vrotb(nb_args + 1);
755+ save_regs(nb_args + 1);
756+ gcall_or_jmp(1);
757+ vtop -= nb_args + 1;
752758 if (stack_add) {
753759 if (stack_add >= 0x1000) {
754− o(S, 0x37 | (5 << 7) | (stack_add & 0xfffff000)); //lui t0, upper(v)
755− EI(S, 0x13, 0, 5, 5, stack_add << 20 >> 20); // addi t0, t0, lo(v)
756− ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
760+ o(0x37 | (5 << 7) | (stack_add & 0xfffff000)); //lui t0, upper(v)
761+ EI(0x13, 0, 5, 5, stack_add << 20 >> 20); // addi t0, t0, lo(v)
762+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
757763 }
758764 else
759− EI(S, 0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
765+ EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
760766 }
761− tcc_free(S, info);
767+ tcc_free(info);
762768 }
763769
764770 static int func_sub_sp_offset, num_va_regs, func_va_list_ofs;
765771
766−ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
772+ST_FUNC void gfunc_prolog(Sym *func_sym)
767773 {
768774 CType *func_type = &func_sym->type;
769775 int i, addr, align, size;
@@ -773,19 +779,19 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 3 unmodified lines
773779 CType *type;
774780
775781 sym = func_type->ref;
776− S->tccgen_loc = -16; // for ra and s0
777− func_sub_sp_offset = S->tccgen_ind;
778− S->tccgen_ind += 5 * 4;
782+ loc = -16; // for ra and s0
783+ func_sub_sp_offset = ind;
784+ ind += 5 * 4;
779785
780786 areg[0] = 0, areg[1] = 0;
781787 addr = 0;
782788 /* if the function returns by reference, then add an
783789 implicit pointer parameter */
784− size = type_size(&S->tccgen_func_vt, &align);
790+ size = type_size(&func_vt, &align);
785791 if (size > 2 * XLEN) {
786− S->tccgen_loc -= 8;
787− S->tccgen_func_vc = S->tccgen_loc;
788− ES(S, 0x23, 3, 8, 10 + areg[0]++, S->tccgen_loc); // sd a0, loc(s0)
792+ loc -= 8;
793+ func_vc = loc;
794+ ES(0x23, 3, 8, 10 + areg[0]++, loc); // sd a0, loc(s0)
789795 }
790796 /* define parameters */
791797 while ((sym = sym->next) != NULL) {
@@ -795,7 +801,7 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 3 unmodified lines
795801 type = &sym->type;
796802 size = type_size(type, &align);
797803 if (size > 2 * XLEN) {
798− type = &S->tccgen_char_pointer_type;
804+ type = &char_pointer_type;
799805 size = align = byref = 8;
800806 }
801807 reg_pass(type, prc, fieldofs, 1);
@@ -810,36 +816,36 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym) · 8 unmodified lines
810816 param_addr = addr;
811817 addr += size;
812818 } else {
813− S->tccgen_loc -= regcount * 8; // XXX could reserve only 'size' bytes
814− param_addr = S->tccgen_loc;
819+ loc -= regcount * 8; // XXX could reserve only 'size' bytes
820+ param_addr = loc;
815821 for (i = 0; i < regcount; i++) {
816822 if (areg[prc[1+i] - 1] >= 8) {
817823 assert(i == 1 && regcount == 2 && !(addr & 7));
818− EI(S, 0x03, 3, 5, 8, addr); // ld t0, addr(s0)
824+ EI(0x03, 3, 5, 8, addr); // ld t0, addr(s0)
819825 addr += 8;
820− ES(S, 0x23, 3, 8, 5, S->tccgen_loc + i*8); // sd t0, loc(s0)
826+ ES(0x23, 3, 8, 5, loc + i*8); // sd t0, loc(s0)
821827 } else if (prc[1+i] == RC_FLOAT) {
822− ES(S, 0x27, (size / regcount) == 4 ? 2 : 3, 8, 10 + areg[1]++, S->tccgen_loc + (fieldofs[i+1] >> 4)); // fs[wd] FAi, loc(s0)
828+ ES(0x27, (size / regcount) == 4 ? 2 : 3, 8, 10 + areg[1]++, loc + (fieldofs[i+1] >> 4)); // fs[wd] FAi, loc(s0)
823829 } else {
824− ES(S, 0x23, 3, 8, 10 + areg[0]++, S->tccgen_loc + i*8); // sd aX, loc(s0) // XXX
830+ ES(0x23, 3, 8, 10 + areg[0]++, loc + i*8); // sd aX, loc(s0) // XXX
825831 }
826832 }
827833 }
828− sym_push(S, sym->v & ~SYM_FIELD, &sym->type,
834+ sym_push(sym->v & ~SYM_FIELD, &sym->type,
829835 (byref ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
830836 param_addr);
831837 }
832838 func_va_list_ofs = addr;
833839 num_va_regs = 0;
834− if (S->tccgen_func_var) {
840+ if (func_var) {
835841 for (; areg[0] < 8; areg[0]++) {
836842 num_va_regs++;
837− ES(S, 0x23, 3, 8, 10 + areg[0], -8 + num_va_regs * 8); // sd aX, loc(s0)
843+ ES(0x23, 3, 8, 10 + areg[0], -8 + num_va_regs * 8); // sd aX, loc(s0)
838844 }
839845 }
840846 #ifdef CONFIG_TCC_BCHECK
841− if (S->do_bounds_check)
842− gen_bounds_prolog(S);
847+ if (tcc_state->do_bounds_check)
848+ gen_bounds_prolog();
843849 #endif
844850 }
845851
@@ -864,113 +870,113 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, · 18 unmodified lines
864870 return nregs;
865871 }
866872
867−ST_FUNC void arch_transfer_ret_regs(TCCState* S, int aftercall)
873+ST_FUNC void arch_transfer_ret_regs(int aftercall)
868874 {
869875 int prc[3], fieldofs[3];
870− reg_pass(&S->tccgen_vtop->type, prc, fieldofs, 1);
876+ reg_pass(&vtop->type, prc, fieldofs, 1);
871877 assert(prc[0] == 2 && prc[1] != prc[2] && !(fieldofs[1] >> 4));
872− assert(S->tccgen_vtop->r == (VT_LOCAL | VT_LVAL));
873− vpushv(S, S->tccgen_vtop);
874− S->tccgen_vtop->type.t = fieldofs[1] & VT_BTYPE;
875− (aftercall ? store : load)(S, prc[1] == RC_INT ? REG_IRET : REG_FRET, S->tccgen_vtop);
876− S->tccgen_vtop->c.i += fieldofs[2] >> 4;
877− S->tccgen_vtop->type.t = fieldofs[2] & VT_BTYPE;
878− (aftercall ? store : load)(S, prc[2] == RC_INT ? REG_IRET : REG_FRET, S->tccgen_vtop);
879− S->tccgen_vtop--;
878+ assert(vtop->r == (VT_LOCAL | VT_LVAL));
879+ vpushv(vtop);
880+ vtop->type.t = fieldofs[1] & VT_BTYPE;
881+ (aftercall ? store : load)(prc[1] == RC_INT ? REG_IRET : REG_FRET, vtop);
882+ vtop->c.i += fieldofs[2] >> 4;
883+ vtop->type.t = fieldofs[2] & VT_BTYPE;
884+ (aftercall ? store : load)(prc[2] == RC_INT ? REG_IRET : REG_FRET, vtop);
885+ vtop--;
880886 }
881887
882−ST_FUNC void gfunc_epilog(TCCState* S)
888+ST_FUNC void gfunc_epilog(void)
883889 {
884890 int v, saved_ind, d, large_ofs_ind;
885891
886892 #ifdef CONFIG_TCC_BCHECK
887− if (S->do_bounds_check)
888− gen_bounds_epilog(S);
893+ if (tcc_state->do_bounds_check)
894+ gen_bounds_epilog();
889895 #endif
890896
891− S->tccgen_loc = (S->tccgen_loc - num_va_regs * 8);
892− d = v = (-S->tccgen_loc + 15) & -16;
897+ loc = (loc - num_va_regs * 8);
898+ d = v = (-loc + 15) & -16;
893899
894900 if (v >= (1 << 11)) {
895901 d = 16;
896− o(S, 0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
897− EI(S, 0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
898− ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
902+ o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
903+ EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
904+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
899905 }
900− EI(S, 0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)
901− EI(S, 0x03, 3, 8, 2, d - 16 - num_va_regs * 8); // ld s0, v-16(sp)
902− EI(S, 0x13, 0, 2, 2, d); // addi sp, sp, v
903− EI(S, 0x67, 0, 0, 1, 0); // jalr x0, 0(x1), aka ret
904− large_ofs_ind = S->tccgen_ind;
906+ EI(0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)
907+ EI(0x03, 3, 8, 2, d - 16 - num_va_regs * 8); // ld s0, v-16(sp)
908+ EI(0x13, 0, 2, 2, d); // addi sp, sp, v
909+ EI(0x67, 0, 0, 1, 0); // jalr x0, 0(x1), aka ret
910+ large_ofs_ind = ind;
905911 if (v >= (1 << 11)) {
906− EI(S, 0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
907− o(S, 0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
908− EI(S, 0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
909− ER(S, 0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0
910− gjmp_addr(S, func_sub_sp_offset + 5*4);
912+ EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
913+ o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
914+ EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
915+ ER(0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0
916+ gjmp_addr(func_sub_sp_offset + 5*4);
911917 }
912− saved_ind = S->tccgen_ind;
918+ saved_ind = ind;
913919
914− S->tccgen_ind = func_sub_sp_offset;
915− EI(S, 0x13, 0, 2, 2, -d); // addi sp, sp, -d
916− ES(S, 0x23, 3, 2, 1, d - 8 - num_va_regs * 8); // sd ra, d-8(sp)
917− ES(S, 0x23, 3, 2, 8, d - 16 - num_va_regs * 8); // sd s0, d-16(sp)
920+ ind = func_sub_sp_offset;
921+ EI(0x13, 0, 2, 2, -d); // addi sp, sp, -d
922+ ES(0x23, 3, 2, 1, d - 8 - num_va_regs * 8); // sd ra, d-8(sp)
923+ ES(0x23, 3, 2, 8, d - 16 - num_va_regs * 8); // sd s0, d-16(sp)
918924 if (v < (1 << 11))
919− EI(S, 0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
925+ EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
920926 else
921− gjmp_addr(S, large_ofs_ind);
922− if ((S->tccgen_ind - func_sub_sp_offset) != 5*4)
923− EI(S, 0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
924− S->tccgen_ind = saved_ind;
927+ gjmp_addr(large_ofs_ind);
928+ if ((ind - func_sub_sp_offset) != 5*4)
929+ EI(0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
930+ ind = saved_ind;
925931 }
926932
927−ST_FUNC void gen_va_start(TCCState *S)
933+ST_FUNC void gen_va_start(void)
928934 {
929− S->tccgen_vtop--;
930− vset(S, &S->tccgen_char_pointer_type, VT_LOCAL, func_va_list_ofs);
935+ vtop--;
936+ vset(&char_pointer_type, VT_LOCAL, func_va_list_ofs);
931937 }
932938
933−ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
939+ST_FUNC void gen_fill_nops(int bytes)
934940 {
935941 if ((bytes & 3))
936− tcc_error(S, "alignment of code section not multiple of 4");
942+ tcc_error("alignment of code section not multiple of 4");
937943 while (bytes > 0) {
938− EI(S, 0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
944+ EI(0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
939945 bytes -= 4;
940946 }
941947 }
942948
943949 // Generate forward branch to label:
944−ST_FUNC int gjmp(TCCState* S, int t)
950+ST_FUNC int gjmp(int t)
945951 {
946− if (S->tccgen_nocode_wanted)
952+ if (nocode_wanted)
947953 return t;
948− o(S, t);
949− return S->tccgen_ind - 4;
954+ o(t);
955+ return ind - 4;
950956 }
951957
952958 // Generate branch to known address:
953−ST_FUNC void gjmp_addr(TCCState* S, int a)
959+ST_FUNC void gjmp_addr(int a)
954960 {
955− uint32_t r = a - S->tccgen_ind, imm;
961+ uint32_t r = a - ind, imm;
956962 if ((r + (1 << 21)) & ~((1U << 22) - 2)) {
957− o(S, 0x17 | (5 << 7) | (((r + 0x800) & 0xfffff000))); // lui RR, up(r)
963+ o(0x17 | (5 << 7) | (((r + 0x800) & 0xfffff000))); // lui RR, up(r)
958964 r = (int)r << 20 >> 20;
959− EI(S, 0x67, 0, 0, 5, r); // jalr x0, r(t0)
965+ EI(0x67, 0, 0, 5, r); // jalr x0, r(t0)
960966 } else {
961967 imm = (((r >> 12) & 0xff) << 12)
962968 | (((r >> 11) & 1) << 20)
963969 | (((r >> 1) & 0x3ff) << 21)
964970 | (((r >> 20) & 1) << 31);
965− o(S, 0x6f | imm); // jal x0, imm == j imm
971+ o(0x6f | imm); // jal x0, imm == j imm
966972 }
967973 }
968974
969−ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
975+ST_FUNC int gjmp_cond(int op, int t)
970976 {
971977 int tmp;
972− int a = S->tccgen_vtop->cmp_r & 0xff;
973− int b = (S->tccgen_vtop->cmp_r >> 8) & 0xff;
978+ int a = vtop->cmp_r & 0xff;
979+ int b = (vtop->cmp_r >> 8) & 0xff;
974980 switch (op) {
975981 case TOK_ULT: op = 6; break;
976982 case TOK_UGE: op = 7; break;
@@ -983,11 +989,11 @@ ST_FUNC int gjmp_cond(TCCState* S, int op, int t) · 6 unmodified lines
983989 case TOK_NE: op = 1; break;
984990 case TOK_EQ: op = 0; break;
985991 }
986− o(S, 0x63 | (op ^ 1) << 12 | a << 15 | b << 20 | 8 << 7); // bOP a,b,+4
987− return gjmp(S, t);
992+ o(0x63 | (op ^ 1) << 12 | a << 15 | b << 20 | 8 << 7); // bOP a,b,+4
993+ return gjmp(t);
988994 }
989995
990−ST_FUNC int gjmp_append(TCCState* S, int n, int t)
996+ST_FUNC int gjmp_append(int n, int t)
991997 {
992998 void *p;
993999 /* insert jump list n into t */
@@ -1001,23 +1007,23 @@ ST_FUNC int gjmp_append(TCCState* S, int n, int t) · 7 unmodified lines
10011007 return t;
10021008 }
10031009
1004−static void gen_opil(TCCState* S, int op, int ll)
1010+static void gen_opil(int op, int ll)
10051011 {
10061012 int a, b, d;
10071013 int func3 = 0;
10081014 ll = ll ? 0 : 8;
1009− if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1010− int fc = S->tccgen_vtop->c.i;
1011− if (fc == S->tccgen_vtop->c.i && !(((unsigned)fc + (1 << 11)) >> 12)) {
1015+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
1016+ int fc = vtop->c.i;
1017+ if (fc == vtop->c.i && !(((unsigned)fc + (1 << 11)) >> 12)) {
10121018 int cll = 0;
10131019 int m = ll ? 31 : 63;
1014− vswap(S);
1015− gv(S, RC_INT);
1016− a = ireg(S->tccgen_vtop[0].r);
1017− --S->tccgen_vtop;
1018− d = get_reg(S, RC_INT);
1019− ++S->tccgen_vtop;
1020− vswap(S);
1020+ vswap();
1021+ gv(RC_INT);
1022+ a = ireg(vtop[0].r);
1023+ --vtop;
1024+ d = get_reg(RC_INT);
1025+ ++vtop;
1026+ vswap();
10211027 switch (op) {
10221028 case '-':
10231029 if (fc <= -(1 << 11))
@@ -1027,13 +1033,13 @@ static void gen_opil(TCCState* S, int op, int ll) · 3 unmodified lines
10271033 func3 = 0; // addi d, a, fc
10281034 cll = ll;
10291035 do_cop:
1030− EI(S, 0x13 | cll, func3, ireg(d), a, fc);
1031− --S->tccgen_vtop;
1036+ EI(0x13 | cll, func3, ireg(d), a, fc);
1037+ --vtop;
10321038 if (op >= TOK_ULT && op <= TOK_GT) {
1033− vset_VT_CMP(S, TOK_NE);
1034− S->tccgen_vtop->cmp_r = ireg(d) | 0 << 8;
1039+ vset_VT_CMP(TOK_NE);
1040+ vtop->cmp_r = ireg(d) | 0 << 8;
10351041 } else
1036− S->tccgen_vtop[0].r = d;
1042+ vtop[0].r = d;
10371043 return;
10381044 case TOK_LE:
10391045 if (fc >= (1 << 11) - 1)
@@ -1056,97 +1062,97 @@ static void gen_opil(TCCState* S, int op, int ll) · 16 unmodified lines
10561062 case TOK_UGT: /* -> TOK_ULE */
10571063 case TOK_GE: /* -> TOK_LT */
10581064 case TOK_GT: /* -> TOK_LE */
1059− gen_opil(S, op - 1, !ll);
1060− S->tccgen_vtop->cmp_op ^= 1;
1065+ gen_opil(op - 1, !ll);
1066+ vtop->cmp_op ^= 1;
10611067 return;
10621068
10631069 case TOK_NE:
10641070 case TOK_EQ:
10651071 if (fc)
1066− gen_opil(S, '-', !ll), a = ireg(S->tccgen_vtop++->r);
1067− --S->tccgen_vtop;
1068− vset_VT_CMP(S, op);
1069− S->tccgen_vtop->cmp_r = a | 0 << 8;
1072+ gen_opil('-', !ll), a = ireg(vtop++->r);
1073+ --vtop;
1074+ vset_VT_CMP(op);
1075+ vtop->cmp_r = a | 0 << 8;
10701076 return;
10711077 }
10721078 }
10731079 }
1074− gv2(S, RC_INT, RC_INT);
1075− a = ireg(S->tccgen_vtop[-1].r);
1076− b = ireg(S->tccgen_vtop[0].r);
1077− S->tccgen_vtop -= 2;
1078− d = get_reg(S, RC_INT);
1079− S->tccgen_vtop++;
1080− S->tccgen_vtop[0].r = d;
1080+ gv2(RC_INT, RC_INT);
1081+ a = ireg(vtop[-1].r);
1082+ b = ireg(vtop[0].r);
1083+ vtop -= 2;
1084+ d = get_reg(RC_INT);
1085+ vtop++;
1086+ vtop[0].r = d;
10811087 d = ireg(d);
10821088 switch (op) {
10831089 default:
10841090 if (op >= TOK_ULT && op <= TOK_GT) {
1085− vset_VT_CMP(S, op);
1086− S->tccgen_vtop->cmp_r = a | b << 8;
1091+ vset_VT_CMP(op);
1092+ vtop->cmp_r = a | b << 8;
10871093 break;
10881094 }
1089− tcc_error(S, "implement me: %s(%s)", __FUNCTION__, get_tok_str(S, op, NULL));
1095+ tcc_error("implement me: %s(%s)", __FUNCTION__, get_tok_str(op, NULL));
10901096 break;
10911097
10921098 case '+':
1093− ER(S, 0x33 | ll, 0, d, a, b, 0); // add d, a, b
1099+ ER(0x33 | ll, 0, d, a, b, 0); // add d, a, b
10941100 break;
10951101 case '-':
1096− ER(S, 0x33 | ll, 0, d, a, b, 0x20); // sub d, a, b
1102+ ER(0x33 | ll, 0, d, a, b, 0x20); // sub d, a, b
10971103 break;
10981104 case TOK_SAR:
1099− ER(S, 0x33 | ll | ll, 5, d, a, b, 0x20); // sra d, a, b
1105+ ER(0x33 | ll | ll, 5, d, a, b, 0x20); // sra d, a, b
11001106 break;
11011107 case TOK_SHR:
1102− ER(S, 0x33 | ll | ll, 5, d, a, b, 0); // srl d, a, b
1108+ ER(0x33 | ll | ll, 5, d, a, b, 0); // srl d, a, b
11031109 break;
11041110 case TOK_SHL:
1105− ER(S, 0x33 | ll, 1, d, a, b, 0); // sll d, a, b
1111+ ER(0x33 | ll, 1, d, a, b, 0); // sll d, a, b
11061112 break;
11071113 case '*':
1108− ER(S, 0x33 | ll, 0, d, a, b, 1); // mul d, a, b
1114+ ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b
11091115 break;
11101116 case '/':
1111− ER(S, 0x33 | ll, 4, d, a, b, 1); // div d, a, b
1117+ ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b
11121118 break;
11131119 case '&':
1114− ER(S, 0x33, 7, d, a, b, 0); // and d, a, b
1120+ ER(0x33, 7, d, a, b, 0); // and d, a, b
11151121 break;
11161122 case '^':
1117− ER(S, 0x33, 4, d, a, b, 0); // xor d, a, b
1123+ ER(0x33, 4, d, a, b, 0); // xor d, a, b
11181124 break;
11191125 case '|':
1120− ER(S, 0x33, 6, d, a, b, 0); // or d, a, b
1126+ ER(0x33, 6, d, a, b, 0); // or d, a, b
11211127 break;
11221128 case '%':
1123− ER(S, ll ? 0x3b: 0x33, 6, d, a, b, 1); // rem d, a, b
1129+ ER(ll ? 0x3b: 0x33, 6, d, a, b, 1); // rem d, a, b
11241130 break;
11251131 case TOK_UMOD:
1126− ER(S, 0x33 | ll, 7, d, a, b, 1); // remu d, a, b
1132+ ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b
11271133 break;
11281134 case TOK_PDIV:
11291135 case TOK_UDIV:
1130− ER(S, 0x33 | ll, 5, d, a, b, 1); // divu d, a, b
1136+ ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b
11311137 break;
11321138 }
11331139 }
11341140
1135−ST_FUNC void gen_opi(TCCState* S, int op)
1141+ST_FUNC void gen_opi(int op)
11361142 {
1137− gen_opil(S, op, 0);
1143+ gen_opil(op, 0);
11381144 }
11391145
1140−ST_FUNC void gen_opl(TCCState* S, int op)
1146+ST_FUNC void gen_opl(int op)
11411147 {
1142− gen_opil(S, op, 1);
1148+ gen_opil(op, 1);
11431149 }
11441150
1145−ST_FUNC void gen_opf(TCCState* S, int op)
1151+ST_FUNC void gen_opf(int op)
11461152 {
11471153 int rs1, rs2, rd, dbl, invert;
1148− if (S->tccgen_vtop[0].type.t == VT_LDOUBLE) {
1149− CType type = S->tccgen_vtop[0].type;
1154+ if (vtop[0].type.t == VT_LDOUBLE) {
1155+ CType type = vtop[0].type;
11501156 int func = 0;
11511157 int cond = -1;
11521158 switch (op) {
@@ -1162,27 +1168,27 @@ ST_FUNC void gen_opf(TCCState* S, int op) · 9 unmodified lines
11621168 case TOK_GT: func = TOK___gttf2; cond = 13; break;
11631169 default: assert(0); break;
11641170 }
1165− vpush_helper_func(S, func);
1166− vrott(S, 3);
1167− gfunc_call(S, 2);
1168− vpushi(S, 0);
1169− S->tccgen_vtop->r = REG_IRET;
1170− S->tccgen_vtop->r2 = cond < 0 ? TREG_R(1) : VT_CONST;
1171+ vpush_helper_func(func);
1172+ vrott(3);
1173+ gfunc_call(2);
1174+ vpushi(0);
1175+ vtop->r = REG_IRET;
1176+ vtop->r2 = cond < 0 ? TREG_R(1) : VT_CONST;
11711177 if (cond < 0)
1172− S->tccgen_vtop->type = type;
1178+ vtop->type = type;
11731179 else {
1174− vpushi(S, 0);
1175− gen_opil(S, op, 1);
1180+ vpushi(0);
1181+ gen_opil(op, 1);
11761182 }
11771183 return;
11781184 }
11791185
1180− gv2(S, RC_FLOAT, RC_FLOAT);
1181− assert(S->tccgen_vtop->type.t == VT_DOUBLE || S->tccgen_vtop->type.t == VT_FLOAT);
1182− dbl = S->tccgen_vtop->type.t == VT_DOUBLE;
1183− rs1 = freg(S->tccgen_vtop[-1].r);
1184− rs2 = freg(S->tccgen_vtop->r);
1185− S->tccgen_vtop--;
1186+ gv2(RC_FLOAT, RC_FLOAT);
1187+ assert(vtop->type.t == VT_DOUBLE || vtop->type.t == VT_FLOAT);
1188+ dbl = vtop->type.t == VT_DOUBLE;
1189+ rs1 = freg(vtop[-1].r);
1190+ rs2 = freg(vtop->r);
1191+ vtop--;
11861192 invert = 0;
11871193 switch(op) {
11881194 default:
@@ -1190,10 +1196,10 @@ ST_FUNC void gen_opf(TCCState* S, int op) · 1 unmodified line
11901196 case '+':
11911197 op = 0; // fadd
11921198 arithop:
1193− rd = get_reg(S, RC_FLOAT);
1194− S->tccgen_vtop->r = rd;
1199+ rd = get_reg(RC_FLOAT);
1200+ vtop->r = rd;
11951201 rd = freg(rd);
1196− ER(S, 0x53, 7, rd, rs1, rs2, dbl | (op << 2)); // fop.[sd] RD, RS1, RS2 (dyn rm)
1202+ ER(0x53, 7, rd, rs1, rs2, dbl | (op << 2)); // fop.[sd] RD, RS1, RS2 (dyn rm)
11971203 break;
11981204 case '-':
11991205 op = 1; // fsub
@@ -1207,12 +1213,12 @@ ST_FUNC void gen_opf(TCCState* S, int op) · 7 unmodified lines
12071213 case TOK_EQ:
12081214 op = 2; // EQ
12091215 cmpop:
1210− rd = get_reg(S, RC_INT);
1211− S->tccgen_vtop->r = rd;
1216+ rd = get_reg(RC_INT);
1217+ vtop->r = rd;
12121218 rd = ireg(rd);
1213− ER(S, 0x53, op, rd, rs1, rs2, dbl | 0x50); // fcmp.[sd] RD, RS1, RS2 (op == eq/lt/le)
1219+ ER(0x53, op, rd, rs1, rs2, dbl | 0x50); // fcmp.[sd] RD, RS1, RS2 (op == eq/lt/le)
12141220 if (invert)
1215− EI(S, 0x13, 4, rd, rd, 1); // xori RD, 1
1221+ EI(0x13, 4, rd, rd, 1); // xori RD, 1
12161222 break;
12171223 case TOK_NE:
12181224 invert = 1;
@@ -1235,67 +1241,67 @@ ST_FUNC void gen_opf(TCCState* S, int op) · 16 unmodified lines
12351241 }
12361242 }
12371243
1238−ST_FUNC void gen_cvt_sxtw(TCCState *S)
1244+ST_FUNC void gen_cvt_sxtw(void)
12391245 {
12401246 /* XXX on risc-v the registers are usually sign-extended already.
12411247 Let's try to not do anything here. */
12421248 }
12431249
1244−ST_FUNC void gen_cvt_itof(TCCState* S, int t)
1250+ST_FUNC void gen_cvt_itof(int t)
12451251 {
1246− int rr = ireg(gv(S, RC_INT)), dr;
1247− int u = S->tccgen_vtop->type.t & VT_UNSIGNED;
1248− int l = (S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG;
1252+ int rr = ireg(gv(RC_INT)), dr;
1253+ int u = vtop->type.t & VT_UNSIGNED;
1254+ int l = (vtop->type.t & VT_BTYPE) == VT_LLONG;
12491255 if (t == VT_LDOUBLE) {
12501256 int func = l ?
12511257 (u ? TOK___floatunditf : TOK___floatditf) :
12521258 (u ? TOK___floatunsitf : TOK___floatsitf);
1253− vpush_helper_func(S, func);
1254− vrott(S, 2);
1255− gfunc_call(S, 1);
1256− vpushi(S, 0);
1257− S->tccgen_vtop->type.t = t;
1258− S->tccgen_vtop->r = REG_IRET;
1259− S->tccgen_vtop->r2 = TREG_R(1);
1259+ vpush_helper_func(func);
1260+ vrott(2);
1261+ gfunc_call(1);
1262+ vpushi(0);
1263+ vtop->type.t = t;
1264+ vtop->r = REG_IRET;
1265+ vtop->r2 = TREG_R(1);
12601266 } else {
1261− S->tccgen_vtop--;
1262− dr = get_reg(S, RC_FLOAT);
1263− S->tccgen_vtop++;
1264− S->tccgen_vtop->r = dr;
1267+ vtop--;
1268+ dr = get_reg(RC_FLOAT);
1269+ vtop++;
1270+ vtop->r = dr;
12651271 dr = freg(dr);
1266− EIu(S, 0x53, 7, dr, rr, ((0x68 | (t == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[sd].[wl][u]
1272+ EIu(0x53, 7, dr, rr, ((0x68 | (t == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[sd].[wl][u]
12671273 }
12681274 }
12691275
1270−ST_FUNC void gen_cvt_ftoi(TCCState* S, int t)
1276+ST_FUNC void gen_cvt_ftoi(int t)
12711277 {
1272− int ft = S->tccgen_vtop->type.t & VT_BTYPE;
1278+ int ft = vtop->type.t & VT_BTYPE;
12731279 int l = (t & VT_BTYPE) == VT_LLONG;
12741280 int u = t & VT_UNSIGNED;
12751281 if (ft == VT_LDOUBLE) {
12761282 int func = l ?
12771283 (u ? TOK___fixunstfdi : TOK___fixtfdi) :
12781284 (u ? TOK___fixunstfsi : TOK___fixtfsi);
1279− vpush_helper_func(S, func);
1280− vrott(S, 2);
1281− gfunc_call(S, 1);
1282− vpushi(S, 0);
1283− S->tccgen_vtop->type.t = t;
1284− S->tccgen_vtop->r = REG_IRET;
1285+ vpush_helper_func(func);
1286+ vrott(2);
1287+ gfunc_call(1);
1288+ vpushi(0);
1289+ vtop->type.t = t;
1290+ vtop->r = REG_IRET;
12851291 } else {
1286− int rr = freg(gv(S, RC_FLOAT)), dr;
1287− S->tccgen_vtop--;
1288− dr = get_reg(S, RC_INT);
1289− S->tccgen_vtop++;
1290− S->tccgen_vtop->r = dr;
1292+ int rr = freg(gv(RC_FLOAT)), dr;
1293+ vtop--;
1294+ dr = get_reg(RC_INT);
1295+ vtop++;
1296+ vtop->r = dr;
12911297 dr = ireg(dr);
1292− EIu(S, 0x53, 1, dr, rr, ((0x60 | (ft == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[wl][u].[sd] rtz
1298+ EIu(0x53, 1, dr, rr, ((0x60 | (ft == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[wl][u].[sd] rtz
12931299 }
12941300 }
12951301
1296−ST_FUNC void gen_cvt_ftof(TCCState* S, int dt)
1302+ST_FUNC void gen_cvt_ftof(int dt)
12971303 {
1298− int st = S->tccgen_vtop->type.t & VT_BTYPE, rs, rd;
1304+ int st = vtop->type.t & VT_BTYPE, rs, rd;
12991305 dt &= VT_BTYPE;
13001306 if (st == dt)
13011307 return;
@@ -1307,109 +1313,109 @@ ST_FUNC void gen_cvt_ftof(TCCState* S, int dt) · 5 unmodified lines
13071313 functions, and on riscv unnamed float args are passed like
13081314 integers. But we really need them in the float argument registers
13091315 for extendsftf2/extenddftf2. So, do it explicitely. */
1310− save_regs(S, 1);
1316+ save_regs(1);
13111317 if (dt == VT_LDOUBLE)
1312− gv(S, RC_F(0));
1318+ gv(RC_F(0));
13131319 else {
1314− gv(S, RC_R(0));
1315− assert(S->tccgen_vtop->r2 < 7);
1316− if (S->tccgen_vtop->r2 != 1 + S->tccgen_vtop->r) {
1317− EI(S, 0x13, 0, ireg(S->tccgen_vtop->r) + 1, ireg(S->tccgen_vtop->r2), 0); // mv Ra+1, RR2
1318− S->tccgen_vtop->r2 = 1 + S->tccgen_vtop->r;
1320+ gv(RC_R(0));
1321+ assert(vtop->r2 < 7);
1322+ if (vtop->r2 != 1 + vtop->r) {
1323+ EI(0x13, 0, ireg(vtop->r) + 1, ireg(vtop->r2), 0); // mv Ra+1, RR2
1324+ vtop->r2 = 1 + vtop->r;
13191325 }
13201326 }
1321− vpush_helper_func(S, func);
1322− gcall_or_jmp(S, 1);
1323− S->tccgen_vtop -= 2;
1324− vpushi(S, 0);
1325− S->tccgen_vtop->type.t = dt;
1327+ vpush_helper_func(func);
1328+ gcall_or_jmp(1);
1329+ vtop -= 2;
1330+ vpushi(0);
1331+ vtop->type.t = dt;
13261332 if (dt == VT_LDOUBLE)
1327− S->tccgen_vtop->r = REG_IRET, S->tccgen_vtop->r2 = REG_IRET+1;
1333+ vtop->r = REG_IRET, vtop->r2 = REG_IRET+1;
13281334 else
1329− S->tccgen_vtop->r = REG_FRET;
1335+ vtop->r = REG_FRET;
13301336 } else {
13311337 assert (dt == VT_FLOAT || dt == VT_DOUBLE);
13321338 assert (st == VT_FLOAT || st == VT_DOUBLE);
1333− rs = gv(S, RC_FLOAT);
1334− rd = get_reg(S, RC_FLOAT);
1339+ rs = gv(RC_FLOAT);
1340+ rd = get_reg(RC_FLOAT);
13351341 if (dt == VT_DOUBLE)
1336− EI(S, 0x53, 0, freg(rd), freg(rs), 0x21 << 5); // fcvt.d.s RD, RS (no rm)
1342+ EI(0x53, 0, freg(rd), freg(rs), 0x21 << 5); // fcvt.d.s RD, RS (no rm)
13371343 else
1338− EI(S, 0x53, 7, freg(rd), freg(rs), (0x20 << 5) | 1); // fcvt.s.d RD, RS (dyn rm)
1339− S->tccgen_vtop->r = rd;
1344+ EI(0x53, 7, freg(rd), freg(rs), (0x20 << 5) | 1); // fcvt.s.d RD, RS (dyn rm)
1345+ vtop->r = rd;
13401346 }
13411347 }
13421348
13431349 /* increment tcov counter */
1344−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
1350+ST_FUNC void gen_increment_tcov (SValue *sv)
13451351 {
13461352 int r1, r2;
13471353 Sym label = {0};
13481354 label.type.t = VT_VOID | VT_STATIC;
13491355
1350− vpushv(S, sv);
1351− S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
1352− r2 = get_reg(S, RC_INT);
1356+ vpushv(sv);
1357+ vtop->r = r1 = get_reg(RC_INT);
1358+ r2 = get_reg(RC_INT);
13531359 r1 = ireg(r1);
13541360 r2 = ireg(r2);
1355− greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_RISCV_PCREL_HI20, 0);
1356− put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
1357− o(S, 0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
1358− greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
1359− EI(S, 0x03, 3, r2, r1, 0); // ld r2, x[r1]
1360− EI(S, 0x13, 0, r2, r2, 1); // addi r2, r2, #1
1361− greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_RISCV_PCREL_HI20, 0);
1361+ greloca(cur_text_section, sv->sym, ind, R_RISCV_PCREL_HI20, 0);
1362+ put_extern_sym(&label, cur_text_section, ind, 0);
1363+ o(0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
1364+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
1365+ EI(0x03, 3, r2, r1, 0); // ld r2, x[r1]
1366+ EI(0x13, 0, r2, r2, 1); // addi r2, r2, #1
1367+ greloca(cur_text_section, sv->sym, ind, R_RISCV_PCREL_HI20, 0);
13621368 label.c = 0; /* force new local ELF symbol */
1363− put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
1364− o(S, 0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
1365− greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_S, 0);
1366− ES(S, 0x23, 3, r1, r2, 0); // sd r2, [r1]
1367− vpop(S);
1369+ put_extern_sym(&label, cur_text_section, ind, 0);
1370+ o(0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
1371+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_S, 0);
1372+ ES(0x23, 3, r1, r2, 0); // sd r2, [r1]
1373+ vpop();
13681374 }
13691375
1370−ST_FUNC void ggoto(TCCState* S)
1376+ST_FUNC void ggoto(void)
13711377 {
1372− gcall_or_jmp(S, 0);
1373− S->tccgen_vtop--;
1378+ gcall_or_jmp(0);
1379+ vtop--;
13741380 }
13751381
1376−ST_FUNC void gen_vla_sp_save(TCCState* S, int addr)
1382+ST_FUNC void gen_vla_sp_save(int addr)
13771383 {
1378− ES(S, 0x23, 3, 8, 2, addr); // sd sp, fc(s0)
1384+ ES(0x23, 3, 8, 2, addr); // sd sp, fc(s0)
13791385 }
13801386
1381−ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr)
1387+ST_FUNC void gen_vla_sp_restore(int addr)
13821388 {
1383− EI(S, 0x03, 3, 2, 8, addr); // ld sp, fc(s0)
1389+ EI(0x03, 3, 2, 8, addr); // ld sp, fc(s0)
13841390 }
13851391
1386−ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align)
1392+ST_FUNC void gen_vla_alloc(CType *type, int align)
13871393 {
13881394 int rr;
13891395 #if defined(CONFIG_TCC_BCHECK)
1390− if (S->do_bounds_check)
1391− vpushv(S, S->tccgen_vtop);
1396+ if (tcc_state->do_bounds_check)
1397+ vpushv(vtop);
13921398 #endif
1393− rr = ireg(gv(S, RC_INT));
1399+ rr = ireg(gv(RC_INT));
13941400 #if defined(CONFIG_TCC_BCHECK)
1395− if (S->do_bounds_check)
1396− EI(S, 0x13, 0, rr, rr, 15+1); // addi RR, RR, 15+1
1401+ if (tcc_state->do_bounds_check)
1402+ EI(0x13, 0, rr, rr, 15+1); // addi RR, RR, 15+1
13971403 else
13981404 #endif
1399− EI(S, 0x13, 0, rr, rr, 15); // addi RR, RR, 15
1400− EI(S, 0x13, 7, rr, rr, -16); // andi, RR, RR, -16
1401− ER(S, 0x33, 0, 2, 2, rr, 0x20); // sub sp, sp, rr
1402− vpop(S);
1405+ EI(0x13, 0, rr, rr, 15); // addi RR, RR, 15
1406+ EI(0x13, 7, rr, rr, -16); // andi, RR, RR, -16
1407+ ER(0x33, 0, 2, 2, rr, 0x20); // sub sp, sp, rr
1408+ vpop();
14031409 #if defined(CONFIG_TCC_BCHECK)
1404− if (S->do_bounds_check) {
1405− vpushi(S, 0);
1406− S->tccgen_vtop->r = TREG_R(0);
1407− o(S, 0x00010513); /* mv a0,sp */
1408− vswap(S);
1409− vpush_helper_func(S, TOK___bound_new_region);
1410− vrott(S, 3);
1411− gfunc_call(S, 2);
1412− S->func_bound_add_epilog = 1;
1410+ if (tcc_state->do_bounds_check) {
1411+ vpushi(0);
1412+ vtop->r = TREG_R(0);
1413+ o(0x00010513); /* mv a0,sp */
1414+ vswap();
1415+ vpush_helper_func(TOK___bound_new_region);
1416+ vrott(3);
1417+ gfunc_call(2);
1418+ func_bound_add_epilog = 1;
14131419 }
14141420 #endif
14151421 }
riscv64-link.c+30−30
@@ -95,39 +95,39 @@ int gotplt_entry_type (int reloc_type) · 94 unmodified lines
9595 return -1;
9696 }
9797
98−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
98+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
9999 {
100− Section *plt = S->plt;
100+ Section *plt = s1->plt;
101101 uint8_t *p;
102102 unsigned plt_offset;
103103
104104 if (plt->data_offset == 0)
105− section_ptr_add(S, plt, 32);
105+ section_ptr_add(plt, 32);
106106 plt_offset = plt->data_offset;
107107
108− p = section_ptr_add(S, plt, 16);
108+ p = section_ptr_add(plt, 16);
109109 write64le(p, got_offset);
110110 return plt_offset;
111111 }
112112
113113 /* relocate the PLT: compute addresses and offsets in the PLT now that final
114114 address for PLT and GOT are known (see fill_program_header) */
115−ST_FUNC void relocate_plt(TCCState *S)
115+ST_FUNC void relocate_plt(TCCState *s1)
116116 {
117117 uint8_t *p, *p_end;
118118
119− if (!S->plt)
119+ if (!s1->plt)
120120 return;
121121
122− p = S->plt->data;
123− p_end = p + S->plt->data_offset;
122+ p = s1->plt->data;
123+ p_end = p + s1->plt->data_offset;
124124
125125 if (p < p_end) {
126− uint64_t plt = S->plt->sh_addr;
127− uint64_t got = S->got->sh_addr;
126+ uint64_t plt = s1->plt->sh_addr;
127+ uint64_t got = s1->got->sh_addr;
128128 uint64_t off = (got - plt + 0x800) >> 12;
129129 if ((off + ((uint32_t)1 << 20)) >> 21)
130− tcc_error(S, "Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
130+ tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
131131 write32le(p, 0x397 | (off << 12)); // auipc t2, %pcrel_hi(got)
132132 write32le(p + 4, 0x41c30333); // sub t1, t1, t3
133133 write32le(p + 8, 0x0003be03 // ld t3, %pcrel_lo(got)(t2)
@@ -140,11 +140,11 @@ ST_FUNC void relocate_plt(TCCState *S) · 6 unmodified lines
140140 write32le(p + 28, 0x000e0067); // jr t3
141141 p += 32;
142142 while (p < p_end) {
143− uint64_t pc = plt + (p - S->plt->data);
143+ uint64_t pc = plt + (p - s1->plt->data);
144144 uint64_t addr = got + read64le(p);
145145 uint64_t off = (addr - pc + 0x800) >> 12;
146146 if ((off + ((uint32_t)1 << 20)) >> 21)
147− tcc_error(S, "Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
147+ tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
148148 write32le(p, 0xe17 | (off << 12)); // auipc t3, %pcrel_hi(func@got)
149149 write32le(p + 4, 0x000e3e03 // ld t3, %pcrel_lo(func@got)(t3)
150150 | (((addr - pc) & 0xfff) << 20));
@@ -154,16 +154,16 @@ ST_FUNC void relocate_plt(TCCState *S) · 3 unmodified lines
154154 }
155155 }
156156
157− if (S->plt->reloc) {
157+ if (s1->plt->reloc) {
158158 ElfW_Rel *rel;
159− p = S->got->data;
160− for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
161− write64le(p + rel->r_offset, S->plt->sh_addr);
159+ p = s1->got->data;
160+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
161+ write64le(p + rel->r_offset, s1->plt->sh_addr);
162162 }
163163 }
164164 }
165165
166−void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
166+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
167167 addr_t addr, addr_t val)
168168 {
169169 uint64_t off64;
@@ -179,7 +179,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 9 unmodified lines
179179 case R_RISCV_BRANCH:
180180 off64 = val - addr;
181181 if ((off64 + (1 << 12)) & ~(uint64_t)0x1ffe)
182− tcc_error(S, "R_RISCV_BRANCH relocation failed"
182+ tcc_error("R_RISCV_BRANCH relocation failed"
183183 " (val=%lx, addr=%lx)", (long)val, (long)addr);
184184 off32 = off64 >> 1;
185185 write32le(ptr, (read32le(ptr) & ~0xfe000f80)
@@ -191,7 +191,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 5 unmodified lines
191191 case R_RISCV_JAL:
192192 off64 = val - addr;
193193 if ((off64 + (1 << 21)) & ~(((uint64_t)1 << 22) - 2))
194− tcc_error(S, "R_RISCV_JAL relocation failed"
194+ tcc_error("R_RISCV_JAL relocation failed"
195195 " (val=%lx, addr=%lx)", (long)val, (long)addr);
196196 off32 = off64;
197197 write32le(ptr, (read32le(ptr) & 0xfff)
@@ -213,7 +213,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 15 unmodified lines
213213 #endif
214214 off64 = (int64_t)(val - addr + 0x800) >> 12;
215215 if ((off64 + ((uint64_t)1 << 20)) >> 21)
216− tcc_error(S, "R_RISCV_PCREL_HI20 relocation failed: off=%lx cond=%lx sym=%s",
216+ tcc_error("R_RISCV_PCREL_HI20 relocation failed: off=%lx cond=%lx sym=%s",
217217 (long)off64, (long)((int64_t)(off64 + ((uint64_t)1 << 20)) >> 21),
218218 symtab_section->link->data + sym->st_name);
219219 write32le(ptr, (read32le(ptr) & 0xfff)
@@ -222,10 +222,10 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 2 unmodified lines
222222 last_hi.val = val;
223223 return;
224224 case R_RISCV_GOT_HI20:
225− val = S->got->sh_addr + get_sym_attr(S, sym_index, 0)->got_offset;
225+ val = s1->got->sh_addr + get_sym_attr(s1, sym_index, 0)->got_offset;
226226 off64 = (int64_t)(val - addr + 0x800) >> 12;
227227 if ((off64 + ((uint64_t)1 << 20)) >> 21)
228− tcc_error(S, "R_RISCV_GOT_HI20 relocation failed");
228+ tcc_error("R_RISCV_GOT_HI20 relocation failed");
229229 last_hi.addr = addr;
230230 last_hi.val = val;
231231 write32le(ptr, (read32le(ptr) & 0xfff)
@@ -236,7 +236,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 4 unmodified lines
236236 printf("PCREL_LO12_I: val=%lx addr=%lx\n", (long)val, (long)addr);
237237 #endif
238238 if (val != last_hi.addr)
239− tcc_error(S, "unsupported hi/lo pcrel reloc scheme");
239+ tcc_error("unsupported hi/lo pcrel reloc scheme");
240240 val = last_hi.val;
241241 addr = last_hi.addr;
242242 write32le(ptr, (read32le(ptr) & 0xfffff)
@@ -244,7 +244,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 1 unmodified line
244244 return;
245245 case R_RISCV_PCREL_LO12_S:
246246 if (val != last_hi.addr)
247− tcc_error(S, "unsupported hi/lo pcrel reloc scheme");
247+ tcc_error("unsupported hi/lo pcrel reloc scheme");
248248 val = last_hi.val;
249249 addr = last_hi.addr;
250250 off32 = val - addr;
@@ -256,7 +256,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 5 unmodified lines
256256 case R_RISCV_RVC_BRANCH:
257257 off64 = (val - addr);
258258 if ((off64 + (1 << 8)) & ~(uint64_t)0x1fe)
259− tcc_error(S, "R_RISCV_RVC_BRANCH relocation failed"
259+ tcc_error("R_RISCV_RVC_BRANCH relocation failed"
260260 " (val=%lx, addr=%lx)", (long)val, (long)addr);
261261 off32 = off64;
262262 write16le(ptr, (read16le(ptr) & 0xe383)
@@ -269,7 +269,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 6 unmodified lines
269269 case R_RISCV_RVC_JUMP:
270270 off64 = (val - addr);
271271 if ((off64 + (1 << 11)) & ~(uint64_t)0xffe)
272− tcc_error(S, "R_RISCV_RVC_BRANCH relocation failed"
272+ tcc_error("R_RISCV_RVC_BRANCH relocation failed"
273273 " (val=%lx, addr=%lx)", (long)val, (long)addr);
274274 off32 = off64;
275275 write16le(ptr, (read16le(ptr) & 0xe003)
@@ -284,7 +284,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 8 unmodified lines
284284 return;
285285
286286 case R_RISCV_32:
287− if (S->output_type == TCC_OUTPUT_DLL) {
287+ if (s1->output_type == TCC_OUTPUT_DLL) {
288288 /* XXX: this logic may depend on TCC's codegen
289289 now TCC uses R_RISCV_RELATIVE even for a 64bit pointer */
290290 qrel->r_offset = rel->r_offset;
@@ -296,8 +296,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, · 5 unmodified lines
296296 add32le(ptr, val);
297297 return;
298298 case R_RISCV_64:
299− if (S->output_type == TCC_OUTPUT_DLL) {
300− esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
299+ if (s1->output_type == TCC_OUTPUT_DLL) {
300+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
301301 qrel->r_offset = rel->r_offset;
302302 if (esym_index) {
303303 qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_64);
tcc.c+70−168
@@ -199,40 +199,40 @@ static void print_dirs(const char *msg, char **paths, int nb_paths) · 198 unmodified lines
199199 printf(" %s\n", paths[i]);
200200 }
201201
202−static void print_search_dirs(TCCState *S)
202+static void print_search_dirs(TCCState *s)
203203 {
204− printf("install: %s\n", S->tcc_lib_path);
204+ printf("install: %s\n", s->tcc_lib_path);
205205 /* print_dirs("programs", NULL, 0); */
206− print_dirs("include", S->sysinclude_paths, S->nb_sysinclude_paths);
207− print_dirs("libraries", S->library_paths, S->nb_library_paths);
206+ print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
207+ print_dirs("libraries", s->library_paths, s->nb_library_paths);
208208 #ifdef TCC_TARGET_PE
209− printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", S->tcc_lib_path);
209+ printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", s->tcc_lib_path);
210210 #else
211− printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", S->tcc_lib_path);
212− print_dirs("crt", S->crt_paths, S->nb_crt_paths);
213− printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(S));
211+ printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
212+ print_dirs("crt", s->crt_paths, s->nb_crt_paths);
213+ printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
214214 #endif
215215 }
216216
217−static void set_environment(TCCState *S)
217+static void set_environment(TCCState *s)
218218 {
219219 char * path;
220220
221221 path = getenv("C_INCLUDE_PATH");
222222 if(path != NULL) {
223− tcc_add_sysinclude_path(S, path);
223+ tcc_add_sysinclude_path(s, path);
224224 }
225225 path = getenv("CPATH");
226226 if(path != NULL) {
227− tcc_add_include_path(S, path);
227+ tcc_add_include_path(s, path);
228228 }
229229 path = getenv("LIBRARY_PATH");
230230 if(path != NULL) {
231− tcc_add_library_path(S, path);
231+ tcc_add_library_path(s, path);
232232 }
233233 }
234234
235−static char *default_outputfile(TCCState *S, const char *first_file)
235+static char *default_outputfile(TCCState *s, const char *first_file)
236236 {
237237 char buf[1024];
238238 char *ext;
@@ -243,18 +243,18 @@ static char *default_outputfile(TCCState *S, const char *first_file) · 4 unmodified lines
243243 snprintf(buf, sizeof(buf), "%s", name);
244244 ext = tcc_fileextension(buf);
245245 #ifdef TCC_TARGET_PE
246− if (S->output_type == TCC_OUTPUT_DLL)
246+ if (s->output_type == TCC_OUTPUT_DLL)
247247 strcpy(ext, ".dll");
248248 else
249− if (S->output_type == TCC_OUTPUT_EXE)
249+ if (s->output_type == TCC_OUTPUT_EXE)
250250 strcpy(ext, ".exe");
251251 else
252252 #endif
253− if ((S->just_deps || S->output_type == TCC_OUTPUT_OBJ) && !S->option_r && *ext)
253+ if ((s->just_deps || s->output_type == TCC_OUTPUT_OBJ) && !s->option_r && *ext)
254254 strcpy(ext, ".o");
255255 else
256256 strcpy(buf, "a.out");
257− return tcc_strdup(S, buf);
257+ return tcc_strdup(buf);
258258 }
259259
260260 static unsigned getclock_ms(void)
@@ -268,101 +268,9 @@ static unsigned getclock_ms(void) · 7 unmodified lines
268268 #endif
269269 }
270270
271−#ifdef WITH_ATTACHMENTS
272−#include "tcc_attachments.h"
273−#define ATTACH_PREFIX "/_attach_"
274−
275−static vio_module_t vio_module;
276−
277−typedef struct vio_memfile_t {
278− off_t size;
279− off_t pos;
280− const unsigned char *mem;
281−} vio_memfile_t;
282−
283−static int vio_mem_open(vio_fd *fd, const char *fn, int oflag) {
284− //printf("%d:%s\n", fd->fd, fn);
285− if(fd->vio_module && strncmp(ATTACH_PREFIX, fn, sizeof(ATTACH_PREFIX)-1) == 0){
286− int i, count = sizeof(bin2c_filesAttached)/sizeof(bin2c_filesAttached_st);
287− for(i=0; i < count; ++i) {
288− //printf("%s:%s\n", fn, bin2c_filesAttached[i].file_name);
289− if(strcmp(fn, bin2c_filesAttached[i].file_name) == 0) {
290− vio_memfile_t *mf = (vio_memfile_t*)tcc_malloc(S, fd->vio_module->tcc_state);
291− mf->mem = bin2c_filesAttached[i].sym_name;
292− mf->size = bin2c_filesAttached[i].size;
293− mf->pos = 0;
294− fd->fd = 1;
295− fd->vio_udata = mf;
296− //printf("%d:%s\n", fd->fd, fn);
297− return fd->fd;
298− }
299− }
300− }
301− return -1;
302−}
303−
304−static off_t vio_mem_lseek(vio_fd fd, off_t offset, int whence) {
305− if(fd.vio_udata) {
306− off_t loffset = 0;
307− vio_memfile_t *mf = (vio_memfile_t*)fd.vio_udata;
308− if (whence == SEEK_CUR)
309− loffset = mf->pos + offset;
310− else if (whence == SEEK_SET)
311− loffset = offset;
312− else if (whence == SEEK_END)
313− loffset = ((off_t)mf->size) + offset;
314−
315− if (loffset < 0 && loffset > mf->size)
316− return -1;
317−
318− mf->pos = loffset;
319−
320− return mf->pos;
321− }
322− return lseek(fd.fd, offset, whence);
323−}
324−
325−static size_t vio_mem_read(vio_fd fd, void *buf, size_t bytes) {
326− if(fd.vio_udata) {
327− vio_memfile_t *mf = (vio_memfile_t*)fd.vio_udata;
328− if( (mf->pos + bytes) > mf->size) {
329− long bc = mf->size - mf->pos;
330− if(bc > 0) {
331− memcpy(buf, mf->mem + mf->pos, bc);
332− mf->pos = mf->size;
333− return bc;
334− }
335− return 0;
336− }
337− memcpy(buf, mf->mem + mf->pos, bytes);
338− mf->pos += bytes;
339− return bytes;
340− }
341− return 0;
342−}
343−
344−static int vio_mem_close(vio_fd *fd) {
345− if(fd->vio_udata){
346− tcc_free(S, fd->vio_udata);
347− }
348− return 0;
349−}
350−
351−void set_vio_module(TCCState *S){
352− vio_module.user_data = NULL;
353− vio_module.call_vio_open_flags = CALL_VIO_OPEN_FIRST;
354− vio_module.vio_open = &vio_mem_open;
355− vio_module.vio_lseek = &vio_mem_lseek;
356− vio_module.vio_read = &vio_mem_read;
357− vio_module.vio_close = &vio_mem_close;
358− tcc_set_vio_module(s, &vio_module);
359−}
360−
361−#endif
362−
363271 int main(int argc0, char **argv0)
364272 {
365− TCCState *S, *s1;
273+ TCCState *s, *s1;
366274 int ret, opt, n = 0, t = 0, done;
367275 unsigned start_time = 0, end_time = 0;
368276 const char *first_file;
@@ -371,19 +279,13 @@ int main(int argc0, char **argv0) · 2 unmodified lines
371279
372280 redo:
373281 argc = argc0, argv = argv0;
374− S = s1 = tcc_new();
375− opt = tcc_parse_args(S, &argc, &argv, 1);
376−
377−#ifdef WITH_ATTACHMENTS
378− tcc_set_lib_path(S, ATTACH_PREFIX);
379− tcc_add_include_path(S, ATTACH_PREFIX);
380− set_vio_module(S);
381−#endif
282+ s = s1 = tcc_new();
283+ opt = tcc_parse_args(s, &argc, &argv, 1);
382284
383285 if (n == 0) {
384286 if (opt == OPT_HELP) {
385287 fputs(help, stdout);
386− if (!S->verbose)
288+ if (!s->verbose)
387289 return 0;
388290 ++opt;
389291 }
@@ -392,57 +294,57 @@ redo: · 2 unmodified lines
392294 return 0;
393295 }
394296 if (opt == OPT_M32 || opt == OPT_M64)
395− tcc_tool_cross(S, argv, opt); /* never returns */
396− if (S->verbose)
297+ tcc_tool_cross(s, argv, opt); /* never returns */
298+ if (s->verbose)
397299 printf(version);
398300 if (opt == OPT_AR)
399− return tcc_tool_ar(S, argc, argv);
301+ return tcc_tool_ar(s, argc, argv);
400302 #ifdef TCC_TARGET_PE
401303 if (opt == OPT_IMPDEF)
402− return tcc_tool_impdef(S, argc, argv);
304+ return tcc_tool_impdef(s, argc, argv);
403305 #endif
404306 if (opt == OPT_V)
405307 return 0;
406308 if (opt == OPT_PRINT_DIRS) {
407309 /* initialize search dirs */
408− set_environment(S);
409− tcc_set_output_type(S, TCC_OUTPUT_MEMORY);
410− print_search_dirs(S);
310+ set_environment(s);
311+ tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
312+ print_search_dirs(s);
411313 return 0;
412314 }
413315
414− if (S->nb_files == 0)
415− tcc_error(S, "no input files");
316+ if (s->nb_files == 0)
317+ tcc_error("no input files");
416318
417− if (S->output_type == TCC_OUTPUT_PREPROCESS) {
418− if (S->outfile && 0!=strcmp("-",S->outfile)) {
419− ppfp = fopen(S->outfile, "w");
319+ if (s->output_type == TCC_OUTPUT_PREPROCESS) {
320+ if (s->outfile && 0!=strcmp("-",s->outfile)) {
321+ ppfp = fopen(s->outfile, "w");
420322 if (!ppfp)
421− tcc_error(S, "could not write '%s'", S->outfile);
323+ tcc_error("could not write '%s'", s->outfile);
422324 }
423− } else if (S->output_type == TCC_OUTPUT_OBJ && !S->option_r) {
424− if (S->nb_libraries)
425− tcc_error(S, "cannot specify libraries with -c");
426− if (S->nb_files > 1 && S->outfile)
427− tcc_error(S, "cannot specify output file with -c many files");
325+ } else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
326+ if (s->nb_libraries)
327+ tcc_error("cannot specify libraries with -c");
328+ if (s->nb_files > 1 && s->outfile)
329+ tcc_error("cannot specify output file with -c many files");
428330 }
429331
430− if (S->do_bench)
332+ if (s->do_bench)
431333 start_time = getclock_ms();
432334 }
433335
434− set_environment(S);
435− if (S->output_type == 0)
436− S->output_type = TCC_OUTPUT_EXE;
437− tcc_set_output_type(S, S->output_type);
438− S->ppfp = ppfp;
336+ set_environment(s);
337+ if (s->output_type == 0)
338+ s->output_type = TCC_OUTPUT_EXE;
339+ tcc_set_output_type(s, s->output_type);
340+ s->ppfp = ppfp;
439341
440− if ((S->output_type == TCC_OUTPUT_MEMORY
441− || S->output_type == TCC_OUTPUT_PREPROCESS)
442− && (S->dflag & TCC_OPTION_d_t)) { /* -dt option */
342+ if ((s->output_type == TCC_OUTPUT_MEMORY
343+ || s->output_type == TCC_OUTPUT_PREPROCESS)
344+ && (s->dflag & 16)) { /* -dt option */
443345 if (t)
444− S->dflag |= TCC_OPTION_d_32;
445− S->run_test = ++t;
346+ s->dflag |= 32;
347+ s->run_test = ++t;
446348 if (n)
447349 --n;
448350 }
@@ -450,48 +352,48 @@ redo: · 1 unmodified line
450352 /* compile or add each files or library */
451353 first_file = NULL, ret = 0;
452354 do {
453− struct filespec *f = S->files[n];
454− S->filetype = f->type;
355+ struct filespec *f = s->files[n];
356+ s->filetype = f->type;
455357 if (f->type & AFF_TYPE_LIB) {
456− if (tcc_add_library_err(S, f->name) < 0)
358+ if (tcc_add_library_err(s, f->name) < 0)
457359 ret = 1;
458360 } else {
459− if (1 == S->verbose)
361+ if (1 == s->verbose)
460362 printf("-> %s\n", f->name);
461363 if (!first_file)
462364 first_file = f->name;
463− if (tcc_add_file(S, f->name) < 0)
365+ if (tcc_add_file(s, f->name) < 0)
464366 ret = 1;
465367 }
466− done = ret || ++n >= S->nb_files;
467− } while (!done && (S->output_type != TCC_OUTPUT_OBJ || S->option_r));
368+ done = ret || ++n >= s->nb_files;
369+ } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r));
468370
469− if (S->do_bench)
371+ if (s->do_bench)
470372 end_time = getclock_ms();
471373
472− if (S->run_test) {
374+ if (s->run_test) {
473375 t = 0;
474− } else if (S->output_type == TCC_OUTPUT_PREPROCESS) {
376+ } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
475377 ;
476378 } else if (0 == ret) {
477− if (S->output_type == TCC_OUTPUT_MEMORY) {
379+ if (s->output_type == TCC_OUTPUT_MEMORY) {
478380 #ifdef TCC_IS_NATIVE
479− ret = tcc_run(S, argc, argv);
381+ ret = tcc_run(s, argc, argv);
480382 #endif
481383 } else {
482− if (!S->outfile)
483− S->outfile = default_outputfile(S, first_file);
484− if (!S->just_deps && tcc_output_file(S, S->outfile))
384+ if (!s->outfile)
385+ s->outfile = default_outputfile(s, first_file);
386+ if (!s->just_deps && tcc_output_file(s, s->outfile))
485387 ret = 1;
486− else if (S->gen_deps)
487− gen_makedeps(S, S->outfile, S->deps_outfile);
388+ else if (s->gen_deps)
389+ gen_makedeps(s, s->outfile, s->deps_outfile);
488390 }
489391 }
490392
491− if (done && 0 == t && 0 == ret && S->do_bench)
492− tcc_print_stats(S, end_time - start_time);
393+ if (done && 0 == t && 0 == ret && s->do_bench)
394+ tcc_print_stats(s, end_time - start_time);
493395
494− tcc_delete(S);
396+ tcc_delete(s);
495397 if (!done)
496398 goto redo; /* compile more files with -c */
497399 if (t)
tcc.h+299−458
@@ -585,7 +585,7 @@ typedef struct Section { · 584 unmodified lines
585585 unsigned long data_offset; /* current data offset */
586586 unsigned char *data; /* section data */
587587 unsigned long data_allocated; /* used for realloc() handling */
588− TCCState *S;
588+ TCCState *s1;
589589 int sh_name; /* elf section name (only used during output) */
590590 int sh_num; /* elf section number */
591591 int sh_type; /* elf section type */
@@ -743,78 +743,6 @@ struct sym_attr { · 151 unmodified lines
743743 #endif
744744 };
745745
746−/*From tccpp.c*/
747−typedef struct TinyAlloc {
748− unsigned limit;
749− unsigned size;
750− uint8_t *buffer;
751− uint8_t *p;
752− unsigned nb_allocs;
753− struct TinyAlloc *next, *top;
754−#ifdef TAL_INFO
755− unsigned nb_peak;
756− unsigned nb_total;
757− unsigned nb_missed;
758− uint8_t *peak_p;
759−#endif
760−} TinyAlloc;
761−
762−/*From tccgen.c*/
763−typedef struct scope_t {
764− struct scope_t *prev;
765− struct { int loc, locorig, num; } vla;
766− struct { Sym *s; int n; } cl;
767− int *bsym, *csym;
768− Sym *lstk, *llstk;
769−} scope_t;
770−
771−typedef struct switch_t {
772− struct case_t {
773− int64_t v1, v2;
774− int sym;
775− } **p; int n; /* list of case ranges */
776− int def_sym; /* default symbol */
777− int *bsym;
778− scope_t *scope;
779− struct switch_t *prev;
780− SValue sv;
781−} switch_t;
782−
783−#define MAX_TEMP_LOCAL_VARIABLE_NUMBER 8
784−/*list of temporary local variables on the stack in current function. */
785−typedef struct temp_local_variable_t {
786− int location; //offset on stack. Svalue.c.i
787− short size;
788− short align;
789−} temp_local_variable_t;
790−
791−typedef struct {
792− unsigned long offset;
793− unsigned long last_file_name;
794− unsigned long last_func_name;
795− int ind;
796− int line;
797−} tcov_data_t;
798−
799−typedef struct {
800− int debug_type;
801− Sym *type;
802−} debug_hash_t;
803−
804−typedef struct debug_info_t {
805− int start;
806− int end;
807− int n_sym;
808− struct debug_sym {
809− int type;
810− unsigned long value;
811− char *str;
812− Section *sec;
813− int sym_index;
814− } *sym;
815− struct debug_info_t *child, *next, *last, *parent;
816−} debug_info_t;
817−
818746 struct TCCState {
819747 unsigned char verbose; /* if true, display some information during compilation */
820748 unsigned char nostdinc; /* if true, no standard headers are added */
@@ -999,11 +927,11 @@ struct TCCState { · 178 unmodified lines
999927 int nb_sym_attrs;
1000928 /* ptr to next reloc entry reused */
1001929 ElfW_Rel *qrel;
1002− #define qrel S->qrel
930+ #define qrel s1->qrel
1003931
1004932 #ifdef TCC_TARGET_RISCV64
1005933 struct pcrel_hi { addr_t addr, val; } last_hi;
1006− #define last_hi S->last_hi
934+ #define last_hi s1->last_hi
1007935 #endif
1008936
1009937 #ifdef TCC_TARGET_PE
@@ -1034,10 +962,6 @@ struct TCCState { · 24 unmodified lines
1034962 const char *runtime_main;
1035963 void **runtime_mem;
1036964 int nb_runtime_mem;
1037−# ifdef HAVE_SELINUX
1038− void *write_mem;
1039− unsigned long mem_size;
1040−# endif
1041965 #endif
1042966
1043967 #ifdef CONFIG_TCC_BACKTRACE
@@ -1067,117 +991,6 @@ struct TCCState { · 23 unmodified lines
1067991 char *deps_outfile; /* option -MF */
1068992 int argc;
1069993 char **argv;
1070−
1071− /* Entries needed to make it reentrant */
1072− vio_module_t *vio_module;
1073−
1074− /* ------------ tccpp.c ------------ */
1075−
1076− struct BufferedFile *tccpp_file;
1077− int tccpp_ch, tccpp_tok;
1078− CValue tccpp_tokc;
1079− const int *tccpp_macro_ptr;
1080− int tccpp_parse_flags;
1081− int tccpp_tok_flags;
1082− CString tccpp_tokcstr; /* current parsed string, if any */
1083− CString tccpp_cstr_buf;
1084− CString tccpp_macro_equal_buf;
1085− TokenString tccpp_tokstr_buf;
1086− TokenString *tccpp_macro_stack;
1087−
1088− /* display benchmark infos */
1089− int tccpp_total_lines;
1090− int tccpp_total_bytes;
1091− int tccpp_tok_ident;
1092− TokenSym **tccpp_table_ident;
1093−
1094− int *tccpp_macro_ptr_allocated;
1095− const int *tccpp_unget_saved_macro_ptr;
1096− int tccpp_unget_saved_buffer[TOK_MAX_SIZE + 1];
1097− int tccpp_unget_buffer_enabled;
1098− TokenSym *tccpp_hash_ident[TOK_HASH_SIZE];
1099− char tccpp_token_buf[STRING_MAX_SIZE + 1];
1100− /* true if isid(c) || isnum(c) */
1101− unsigned char tccpp_isidnum_table[256-CH_EOF];
1102−
1103− int tccpp_pp_debug_tok, tccpp_pp_debug_symv;
1104− int tccpp_pp_once;
1105− int tccpp_pp_expr;
1106− int tccpp_pp_counter;
1107−
1108− TinyAlloc *tccpp_toksym_alloc;
1109− TinyAlloc *tccpp_tokstr_alloc;
1110−
1111− /*----------- tccasm.c --------*/
1112− Section *tccasm_last_text_section; /* to handle .previous asm directive */
1113−
1114− /* ------------ tccgen.c ------------ */
1115−
1116− Sym *tccgen_global_stack;
1117− Sym *tccgen_local_stack;
1118− Sym *tccgen_local_label_stack;
1119− Sym *tccgen_global_label_stack;
1120− Sym *tccgen_define_stack;
1121− CType tccgen_int_type, tccgen_func_old_type, tccgen_char_type, tccgen_char_pointer_type;
1122− SValue *tccgen_vtop;
1123− SValue tccgen__vstack[1 + VSTACK_SIZE];
1124− int tccgen_rsym, tccgen_anon_sym, tccgen_ind, tccgen_loc;
1125− char tccgen_debug_modes;
1126−
1127− int tccgen_const_wanted; /* true if constant wanted */
1128− int tccgen_nocode_wanted; /* true if no code generation wanted for an expression */
1129− int tccgen_global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1130− CType tccgen_func_vt; /* current function return type (used by return instruction) */
1131− int tccgen_func_var; /* true if current function is variadic */
1132− int tccgen_func_vc;
1133− const char *tccgen_funcname;
1134−
1135− Sym *tccgen_sym_free_first;
1136− void **tccgen_sym_pools;
1137− int tccgen_nb_sym_pools;
1138− Sym *tccgen_all_cleanups, *tccgen_pending_gotos;
1139− int tccgen_local_scope;
1140− int tccgen_in_sizeof;
1141− int tccgen_in_generic;
1142− int tccgen_section_sym;
1143−
1144− int tccgen_last_line_num, tccgen_new_file, tccgen_func_ind; /* debug info control */
1145− CString tccgen_initstr;
1146−
1147− switch_t *tccgen_cur_switch; /* current switch */
1148−
1149− temp_local_variable_t tccgen_arr_temp_local_vars[MAX_TEMP_LOCAL_VARIABLE_NUMBER];
1150− int tccgen_nb_temp_local_vars;
1151−
1152− scope_t *tccgen_cur_scope, *tccgen_loop_scope, *tccgen_root_scope;
1153−
1154− tcov_data_t tccgen_tcov_data;
1155− int tccgen_debug_next_type;
1156− debug_hash_t *tccgen_debug_hash;
1157− int tccgen_n_debug_hash;
1158− debug_info_t *tccgen_debug_info, *tccgen_debug_info_root;
1159−
1160− unsigned char tccgen_prec[256];
1161−
1162− /*--------armg-gen.c-----------*/
1163−/*#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)*/
1164− CType armgen_float_type, armgen_double_type, armgen_func_float_type, armgen_func_double_type;
1165−/*#endif*/
1166−
1167− /*------- tccrun.c ------------*/
1168−
1169− /*--------x86_64-gen.c --------*/
1170− unsigned long x86_64_gen_func_sub_sp_offset;
1171− int x86_64_gen_func_ret_sub;
1172−#if defined(CONFIG_TCC_BCHECK)
1173− addr_t func_bound_offset;
1174− unsigned long func_bound_ind;
1175− int func_bound_add_epilog;
1176−#endif
1177−#ifdef TCC_TARGET_PE
1178− int x86_64_gen_func_scratch, x86_64_gen_func_alloca;
1179−#endif
1180−
1181994 };
1182995
1183996 struct filespec {
@@ -1361,7 +1174,7 @@ enum tcc_token { · 177 unmodified lines
13611174
13621175 /* ------------ libtcc.c ------------ */
13631176
1364−//ST_DATA struct TCCState *S;
1177+ST_DATA struct TCCState *tcc_state;
13651178
13661179 /* public functions currently used by the tcc main function */
13671180 ST_FUNC char *pstrcpy(char *buf, size_t buf_size, const char *s);
@@ -1370,56 +1183,53 @@ ST_FUNC char *pstrncpy(char *out, const char *in, size_t num); · 2 unmodified lines
13701183 PUB_FUNC char *tcc_basename(const char *name);
13711184 PUB_FUNC char *tcc_fileextension (const char *name);
13721185
1373−PUB_FUNC void tcc_free_base(void *ptr);
1374−PUB_FUNC void *tcc_malloc_base(unsigned long size);
1375−PUB_FUNC void *tcc_mallocz_base(unsigned long size);
13761186 #ifndef MEM_DEBUG
1377−PUB_FUNC void tcc_free(TCCState* S, void *ptr);
1378−PUB_FUNC void *tcc_malloc(TCCState* S, unsigned long size);
1379−PUB_FUNC void *tcc_mallocz(TCCState* S, unsigned long size);
1380−PUB_FUNC void *tcc_realloc(TCCState* S, void *ptr, unsigned long size);
1381−PUB_FUNC char *tcc_strdup(TCCState* S, const char *str);
1187+PUB_FUNC void tcc_free(void *ptr);
1188+PUB_FUNC void *tcc_malloc(unsigned long size);
1189+PUB_FUNC void *tcc_mallocz(unsigned long size);
1190+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
1191+PUB_FUNC char *tcc_strdup(const char *str);
13821192 #else
1383−#define tcc_free(s, ptr) tcc_free_debug(s, ptr)
1384−#define tcc_malloc(s, size) tcc_malloc_debug(s, size, __FILE__, __LINE__)
1385−#define tcc_mallocz(s, size) tcc_mallocz_debug(s, size, __FILE__, __LINE__)
1386−#define tcc_realloc(s, ptr, size) tcc_realloc_debug(s, ptr, size, __FILE__, __LINE__)
1387−#define tcc_strdup(s, str) tcc_strdup_debug(s, str, __FILE__, __LINE__)
1388−PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr);
1389−PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *file, int line);
1390−PUB_FUNC void *tcc_mallocz_debug(TCCState* S, unsigned long size, const char *file, int line);
1391−PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, const char *file, int line);
1392−PUB_FUNC char *tcc_strdup_debug(TCCState* S, const char *str, const char *file, int line);
1393−#endif
1394−
1395−#define free(p) use_tcc_free(S, p)
1396−#define malloc(s) use_tcc_malloc(S, s)
1397−#define realloc(p, s) use_tcc_realloc(S, p, s)
1193+#define tcc_free(ptr) tcc_free_debug(ptr)
1194+#define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
1195+#define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
1196+#define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
1197+#define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
1198+PUB_FUNC void tcc_free_debug(void *ptr);
1199+PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
1200+PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
1201+PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
1202+PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
1203+#endif
1204+
1205+#define free(p) use_tcc_free(p)
1206+#define malloc(s) use_tcc_malloc(s)
1207+#define realloc(p, s) use_tcc_realloc(p, s)
13981208 #undef strdup
1399−#define strdup(s) use_tcc_strdup(S, s)
1400−PUB_FUNC void _tcc_error_noabort(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
1401−PUB_FUNC NORETURN void _tcc_error(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
1402−PUB_FUNC void _tcc_warning(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
1403−#define tcc_internal_error(S, msg) tcc_error(S, "internal compiler error\n"\
1209+#define strdup(s) use_tcc_strdup(s)
1210+PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) PRINTF_LIKE(1,2);
1211+PUB_FUNC NORETURN void _tcc_error(const char *fmt, ...) PRINTF_LIKE(1,2);
1212+PUB_FUNC void _tcc_warning(const char *fmt, ...) PRINTF_LIKE(1,2);
1213+#define tcc_internal_error(msg) tcc_error("internal compiler error\n"\
14041214 "%s:%d: in %s(): " msg, __FILE__,__LINE__,__FUNCTION__)
14051215
14061216 /* other utilities */
1407−ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data);
1408−ST_FUNC void dynarray_reset(TCCState* S, void *pp, int *n);
1409−ST_INLN void cstr_ccat(TCCState* S, CString *cstr, int ch);
1410−ST_FUNC void cstr_cat(TCCState* S, CString *cstr, const char *str, int len);
1411−ST_FUNC void cstr_wccat(TCCState* S, CString *cstr, int ch);
1412−ST_FUNC void cstr_new(TCCState* S, CString *cstr);
1413−ST_FUNC void cstr_free(TCCState* S, CString *cstr);
1414−ST_FUNC int cstr_printf(TCCState* S, CString *cs, const char *fmt, ...) PRINTF_LIKE(3,4);
1415−ST_FUNC int cstr_vprintf(TCCState* S, CString *cstr, const char *fmt, va_list ap);
1217+ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
1218+ST_FUNC void dynarray_reset(void *pp, int *n);
1219+ST_INLN void cstr_ccat(CString *cstr, int ch);
1220+ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
1221+ST_FUNC void cstr_wccat(CString *cstr, int ch);
1222+ST_FUNC void cstr_new(CString *cstr);
1223+ST_FUNC void cstr_free(CString *cstr);
1224+ST_FUNC int cstr_printf(CString *cs, const char *fmt, ...) PRINTF_LIKE(2,3);
1225+ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap);
14161226 ST_FUNC void cstr_reset(CString *cstr);
14171227
1418−ST_FUNC void tcc_open_bf(TCCState *S, const char *filename, int initlen);
1419−ST_FUNC int tcc_open(TCCState *S, const char *filename);
1420−ST_FUNC void tcc_close(TCCState *S);
1228+ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
1229+ST_FUNC int tcc_open(TCCState *s1, const char *filename);
1230+ST_FUNC void tcc_close(void);
14211231
1422−ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags);
1232+ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
14231233 /* flags: */
14241234 #define AFF_PRINT_ERROR 0x10 /* print error if file not found */
14251235 #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
@@ -1439,26 +1249,26 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags); · 13 unmodified lines
14391249 #define AFF_BINTYPE_C67 4
14401250
14411251 #ifndef ELF_OBJ_ONLY
1442−ST_FUNC int tcc_add_crt(TCCState *S, const char *filename);
1252+ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
14431253 #endif
14441254 #ifndef TCC_TARGET_MACHO
1445−ST_FUNC int tcc_add_dll(TCCState *S, const char *filename, int flags);
1255+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
14461256 #endif
14471257 #ifdef CONFIG_TCC_BCHECK
1448−ST_FUNC void tcc_add_bcheck(TCCState *S);
1258+ST_FUNC void tcc_add_bcheck(TCCState *s1);
14491259 #endif
14501260 #ifdef CONFIG_TCC_BACKTRACE
1451−ST_FUNC void tcc_add_btstub(TCCState *S);
1261+ST_FUNC void tcc_add_btstub(TCCState *s1);
14521262 #endif
1453−ST_FUNC void tcc_add_pragma_libs(TCCState *S);
1454−PUB_FUNC int tcc_add_library_err(TCCState *S, const char *f);
1455−PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time);
1456−PUB_FUNC int tcc_parse_args(TCCState *S, int *argc, char ***argv, int optind);
1263+ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
1264+PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
1265+PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
1266+PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
14571267 #ifdef _WIN32
14581268 ST_FUNC char *normalize_slashes(char *path);
14591269 #endif
1460−ST_FUNC DLLReference *tcc_add_dllref(TCCState *S, const char *dllname);
1461−ST_FUNC char *tcc_load_text(TCCState *S, int fd);
1270+ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname);
1271+ST_FUNC char *tcc_load_text(int fd);
14621272
14631273 /* tcc_parse_args return codes: */
14641274 #define OPT_HELP 1
@@ -1472,6 +1282,18 @@ ST_FUNC char *tcc_load_text(TCCState *S, int fd); · 7 unmodified lines
14721282
14731283 /* ------------ tccpp.c ------------ */
14741284
1285+ST_DATA struct BufferedFile *file;
1286+ST_DATA int ch, tok;
1287+ST_DATA CValue tokc;
1288+ST_DATA const int *macro_ptr;
1289+ST_DATA int parse_flags;
1290+ST_DATA int tok_flags;
1291+ST_DATA CString tokcstr; /* current parsed string, if any */
1292+
1293+/* display benchmark infos */
1294+ST_DATA int tok_ident;
1295+ST_DATA TokenSym **table_ident;
1296+
14751297 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
14761298 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
14771299 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
@@ -1499,36 +1321,36 @@ enum line_macro_output_format { · 21 unmodified lines
14991321 LINE_MACRO_OUTPUT_FORMAT_P10 = 11
15001322 };
15011323
1502−ST_FUNC TokenSym *tok_alloc(TCCState* S, const char *str, int len);
1503−ST_FUNC int tok_alloc_const(TCCState* S, const char *str);
1504−ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv);
1505−ST_FUNC void begin_macro(TCCState* S, TokenString *str, int alloc);
1506−ST_FUNC void end_macro(TCCState* S);
1507−ST_FUNC int set_idnum(TCCState* S, int c, int val);
1324+ST_FUNC TokenSym *tok_alloc(const char *str, int len);
1325+ST_FUNC int tok_alloc_const(const char *str);
1326+ST_FUNC const char *get_tok_str(int v, CValue *cv);
1327+ST_FUNC void begin_macro(TokenString *str, int alloc);
1328+ST_FUNC void end_macro(void);
1329+ST_FUNC int set_idnum(int c, int val);
15081330 ST_INLN void tok_str_new(TokenString *s);
1509−ST_FUNC TokenString *tok_str_alloc(TCCState* S);
1510−ST_FUNC void tok_str_free(TCCState* S, TokenString *s);
1511−ST_FUNC void tok_str_free_str(TCCState* S, int *str);
1512−ST_FUNC void tok_str_add(TCCState* S, TokenString *s, int t);
1513−ST_FUNC void tok_str_add_tok(TCCState* S, TokenString *s);
1514−ST_INLN void define_push(TCCState* S, int v, int macro_type, int *str, Sym *first_arg);
1515−ST_FUNC void define_undef(TCCState* S, Sym *s);
1516−ST_INLN Sym *define_find(TCCState* S, int v);
1517−ST_FUNC void free_defines(TCCState* S, Sym *b);
1518−ST_FUNC Sym *label_find(TCCState* S, int v);
1519−ST_FUNC Sym *label_push(TCCState* S, Sym **ptop, int v, int flags);
1520−ST_FUNC void label_pop(TCCState* S, Sym **ptop, Sym *slast, int keep);
1521−ST_FUNC void parse_define(TCCState* S);
1522−ST_FUNC void preprocess(TCCState* S, int is_bof);
1523−ST_FUNC void next(TCCState* S);
1524−ST_INLN void unget_tok(TCCState* S, int last_tok);
1525−ST_FUNC void preprocess_start(TCCState *S, int filetype);
1526−ST_FUNC void preprocess_end(TCCState *S);
1527−ST_FUNC void tccpp_new(TCCState *S);
1528−ST_FUNC void tccpp_delete(TCCState *S);
1529−ST_FUNC int tcc_preprocess(TCCState *S);
1530−ST_FUNC void skip(TCCState* S, int c);
1531−ST_FUNC NORETURN void expect(TCCState* S, const char *msg);
1331+ST_FUNC TokenString *tok_str_alloc(void);
1332+ST_FUNC void tok_str_free(TokenString *s);
1333+ST_FUNC void tok_str_free_str(int *str);
1334+ST_FUNC void tok_str_add(TokenString *s, int t);
1335+ST_FUNC void tok_str_add_tok(TokenString *s);
1336+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
1337+ST_FUNC void define_undef(Sym *s);
1338+ST_INLN Sym *define_find(int v);
1339+ST_FUNC void free_defines(Sym *b);
1340+ST_FUNC Sym *label_find(int v);
1341+ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
1342+ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep);
1343+ST_FUNC void parse_define(void);
1344+ST_FUNC void preprocess(int is_bof);
1345+ST_FUNC void next(void);
1346+ST_INLN void unget_tok(int last_tok);
1347+ST_FUNC void preprocess_start(TCCState *s1, int filetype);
1348+ST_FUNC void preprocess_end(TCCState *s1);
1349+ST_FUNC void tccpp_new(TCCState *s);
1350+ST_FUNC void tccpp_delete(TCCState *s);
1351+ST_FUNC int tcc_preprocess(TCCState *s1);
1352+ST_FUNC void skip(int c);
1353+ST_FUNC NORETURN void expect(const char *msg);
15321354
15331355 /* space excluding newline */
15341356 static inline int is_space(int ch) {
@@ -1550,85 +1372,104 @@ static inline int toup(int c) { · 15 unmodified lines
15501372 /* ------------ tccgen.c ------------ */
15511373
15521374 #define SYM_POOL_NB (8192 / sizeof(Sym))
1553−ST_FUNC void tcc_debug_start(TCCState *S);
1554−ST_FUNC void tcc_debug_end(TCCState *S);
1555−ST_FUNC void tcc_debug_bincl(TCCState *S);
1556−ST_FUNC void tcc_debug_eincl(TCCState *S);
1557−ST_FUNC void tcc_debug_putfile(TCCState *S, const char *filename);
15581375
1559−ST_FUNC void tccgen_init(TCCState *S);
1560−ST_FUNC int tccgen_compile(TCCState *S);
1561−ST_FUNC void tccgen_finish(TCCState *S);
1562−ST_FUNC void check_vstack(TCCState* S);
1376+ST_DATA Sym *global_stack;
1377+ST_DATA Sym *local_stack;
1378+ST_DATA Sym *local_label_stack;
1379+ST_DATA Sym *global_label_stack;
1380+ST_DATA Sym *define_stack;
1381+ST_DATA CType int_type, func_old_type, char_pointer_type;
1382+ST_DATA SValue *vtop;
1383+ST_DATA int rsym, anon_sym, ind, loc;
1384+ST_DATA char debug_modes;
1385+
1386+ST_DATA int const_wanted; /* true if constant wanted */
1387+ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1388+ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1389+ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1390+ST_DATA int func_var; /* true if current function is variadic */
1391+ST_DATA int func_vc;
1392+ST_DATA const char *funcname;
1393+
1394+ST_FUNC void tcc_debug_start(TCCState *s1);
1395+ST_FUNC void tcc_debug_end(TCCState *s1);
1396+ST_FUNC void tcc_debug_bincl(TCCState *s1);
1397+ST_FUNC void tcc_debug_eincl(TCCState *s1);
1398+ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
1399+
1400+ST_FUNC void tccgen_init(TCCState *s1);
1401+ST_FUNC int tccgen_compile(TCCState *s1);
1402+ST_FUNC void tccgen_finish(TCCState *s1);
1403+ST_FUNC void check_vstack(void);
15631404
15641405 ST_INLN int is_float(int t);
15651406 ST_FUNC int ieee_finite(double d);
15661407 ST_FUNC int exact_log2p1(int i);
1567−ST_FUNC void test_lvalue(TCCState* S);
1408+ST_FUNC void test_lvalue(void);
15681409
1569−ST_FUNC ElfSym *elfsym(TCCState* S, Sym *);
1570−ST_FUNC void update_storage(TCCState* S, Sym *sym);
1571−ST_FUNC void put_extern_sym2(TCCState* S, Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
1572−ST_FUNC void put_extern_sym(TCCState* S, Sym *sym, Section *section, addr_t value, unsigned long size);
1410+ST_FUNC ElfSym *elfsym(Sym *);
1411+ST_FUNC void update_storage(Sym *sym);
1412+ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
1413+ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
15731414 #if PTR_SIZE == 4
1574−ST_FUNC void greloc(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type);
1415+ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
15751416 #endif
1576−ST_FUNC void greloca(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
1417+ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
15771418
1578−ST_INLN void sym_free(TCCState* S, Sym *sym);
1579−ST_FUNC Sym *sym_push(TCCState* S, int v, CType *type, int r, int c);
1580−ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep);
1581−ST_FUNC Sym *sym_push2(TCCState* S, Sym **ps, int v, int t, int c);
1419+ST_INLN void sym_free(Sym *sym);
1420+ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
1421+ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
1422+ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
15821423 ST_FUNC Sym *sym_find2(Sym *s, int v);
1583−ST_INLN Sym *sym_find(TCCState* S, int v);
1584−ST_INLN Sym *struct_find(TCCState* S, int v);
1585−
1586−ST_FUNC Sym *global_identifier_push(TCCState* S, int v, int t, int c);
1587−ST_FUNC Sym *external_global_sym(TCCState* S, int v, CType *type);
1588−ST_FUNC Sym *external_helper_sym(TCCState* S, int v);
1589−ST_FUNC void vpush_helper_func(TCCState* S, int v);
1590−ST_FUNC void vset(TCCState* S, CType *type, int r, int v);
1591−ST_FUNC void vset_VT_CMP(TCCState* S, int op);
1592−ST_FUNC void vpushi(TCCState* S, int v);
1593−ST_FUNC void vpushv(TCCState* S, SValue *v);
1594−ST_FUNC void vpushsym(TCCState* S, CType *type, Sym *sym);
1595−ST_FUNC void vswap(TCCState* S);
1596−ST_FUNC void vrote(TCCState* S, SValue *e, int n);
1597−ST_FUNC void vrott(TCCState* S, int n);
1598−ST_FUNC void vrotb(TCCState* S, int n);
1599−ST_FUNC void vpop(TCCState* S);
1424+ST_INLN Sym *sym_find(int v);
1425+ST_INLN Sym *struct_find(int v);
1426+
1427+ST_FUNC Sym *global_identifier_push(int v, int t, int c);
1428+ST_FUNC Sym *external_global_sym(int v, CType *type);
1429+ST_FUNC Sym *external_helper_sym(int v);
1430+ST_FUNC void vpush_helper_func(int v);
1431+ST_FUNC void vset(CType *type, int r, int v);
1432+ST_FUNC void vset_VT_CMP(int op);
1433+ST_FUNC void vpushi(int v);
1434+ST_FUNC void vpushv(SValue *v);
1435+ST_FUNC void vpushsym(CType *type, Sym *sym);
1436+ST_FUNC void vswap(void);
1437+ST_FUNC void vrote(SValue *e, int n);
1438+ST_FUNC void vrott(int n);
1439+ST_FUNC void vrotb(int n);
1440+ST_FUNC void vpop(void);
16001441 #if PTR_SIZE == 4
1601−ST_FUNC void lexpand(TCCState* S);
1442+ST_FUNC void lexpand(void);
16021443 #endif
16031444 #ifdef TCC_TARGET_ARM
1604−ST_FUNC int get_reg_ex(TCCState* S, int rc, int rc2);
1605−#endif
1606−ST_FUNC void save_reg(TCCState* S, int r);
1607−ST_FUNC void save_reg_upstack(TCCState* S, int r, int n);
1608−ST_FUNC int get_reg(TCCState* S, int rc);
1609−ST_FUNC void save_regs(TCCState* S, int n);
1610−ST_FUNC void gaddrof(TCCState* S);
1611−ST_FUNC int gv(TCCState* S, int rc);
1612−ST_FUNC void gv2(TCCState* S, int rc1, int rc2);
1613−ST_FUNC void gen_op(TCCState* S, int op);
1445+ST_FUNC int get_reg_ex(int rc, int rc2);
1446+#endif
1447+ST_FUNC void save_reg(int r);
1448+ST_FUNC void save_reg_upstack(int r, int n);
1449+ST_FUNC int get_reg(int rc);
1450+ST_FUNC void save_regs(int n);
1451+ST_FUNC void gaddrof(void);
1452+ST_FUNC int gv(int rc);
1453+ST_FUNC void gv2(int rc1, int rc2);
1454+ST_FUNC void gen_op(int op);
16141455 ST_FUNC int type_size(CType *type, int *a);
1615−ST_FUNC void mk_pointer(TCCState* S, CType *type);
1616−ST_FUNC void vstore(TCCState* S);
1617−ST_FUNC void inc(TCCState* S, int post, int c);
1618−ST_FUNC void parse_mult_str (TCCState* S, CString *astr, const char *msg);
1619−ST_FUNC void parse_asm_str(TCCState* S, CString *astr);
1620−ST_FUNC void indir(TCCState* S);
1621−ST_FUNC void unary(TCCState* S);
1622−ST_FUNC void gexpr(TCCState* S);
1623−ST_FUNC int expr_const(TCCState* S);
1456+ST_FUNC void mk_pointer(CType *type);
1457+ST_FUNC void vstore(void);
1458+ST_FUNC void inc(int post, int c);
1459+ST_FUNC void parse_mult_str (CString *astr, const char *msg);
1460+ST_FUNC void parse_asm_str(CString *astr);
1461+ST_FUNC void indir(void);
1462+ST_FUNC void unary(void);
1463+ST_FUNC void gexpr(void);
1464+ST_FUNC int expr_const(void);
16241465 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1625−ST_FUNC Sym *get_sym_ref(TCCState* S, CType *type, Section *sec, unsigned long offset, unsigned long size);
1466+ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
16261467 #endif
16271468 #if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
16281469 ST_FUNC int classify_x86_64_va_arg(CType *ty);
16291470 #endif
16301471 #ifdef CONFIG_TCC_BCHECK
1631−ST_FUNC void gbound_args(TCCState* S, int nb_args);
1472+ST_FUNC void gbound_args(int nb_args);
16321473 ST_DATA int func_bound_add_epilog;
16331474 #endif
16341475
@@ -1648,51 +1489,51 @@ typedef struct { · 13 unmodified lines
16481489 unsigned int n_value; /* value of symbol */
16491490 } Stab_Sym;
16501491
1651−ST_FUNC void tccelf_new(TCCState *S);
1652−ST_FUNC void tccelf_delete(TCCState *S);
1653−ST_FUNC void tccelf_stab_new(TCCState *S);
1654−ST_FUNC void tccelf_begin_file(TCCState *S);
1655−ST_FUNC void tccelf_end_file(TCCState *S);
1492+ST_FUNC void tccelf_new(TCCState *s);
1493+ST_FUNC void tccelf_delete(TCCState *s);
1494+ST_FUNC void tccelf_stab_new(TCCState *s);
1495+ST_FUNC void tccelf_begin_file(TCCState *s1);
1496+ST_FUNC void tccelf_end_file(TCCState *s1);
16561497 #ifdef CONFIG_TCC_BCHECK
1657−ST_FUNC void tccelf_bounds_new(TCCState *S);
1658−#endif
1659−ST_FUNC Section *new_section(TCCState *S, const char *name, int sh_type, int sh_flags);
1660−ST_FUNC void section_realloc(TCCState* S, Section *sec, unsigned long new_size);
1661−ST_FUNC size_t section_add(TCCState* S, Section *sec, addr_t size, int align);
1662−ST_FUNC void *section_ptr_add(TCCState* S, Section *sec, addr_t size);
1663−ST_FUNC Section *find_section(TCCState *S, const char *name);
1664−ST_FUNC Section *new_symtab(TCCState *S, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
1665−
1666−ST_FUNC int put_elf_str(TCCState* S, Section *s, const char *sym);
1667−ST_FUNC int put_elf_sym(TCCState* S, Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1668−ST_FUNC int set_elf_sym(Section *S, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1669−ST_FUNC int find_elf_sym(Section *S, const char *name);
1498+ST_FUNC void tccelf_bounds_new(TCCState *s);
1499+#endif
1500+ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
1501+ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
1502+ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
1503+ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
1504+ST_FUNC Section *find_section(TCCState *s1, const char *name);
1505+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);
1506+
1507+ST_FUNC int put_elf_str(Section *s, const char *sym);
1508+ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1509+ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1510+ST_FUNC int find_elf_sym(Section *s, const char *name);
16701511 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
16711512 ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
16721513
1673−ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int desc, unsigned long value);
1674−ST_FUNC void put_stabs_r(TCCState *S, const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1675−ST_FUNC void put_stabn(TCCState *S, int type, int other, int desc, int value);
1514+ST_FUNC void put_stabs(TCCState *s1, const char *str, int type, int other, int desc, unsigned long value);
1515+ST_FUNC void put_stabs_r(TCCState *s1, const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1516+ST_FUNC void put_stabn(TCCState *s1, int type, int other, int desc, int value);
16761517
1677−ST_FUNC void resolve_common_syms(TCCState *S);
1678−ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve);
1679−ST_FUNC void relocate_sections(TCCState *S);
1518+ST_FUNC void resolve_common_syms(TCCState *s1);
1519+ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
1520+ST_FUNC void relocate_sections(TCCState *s1);
16801521
16811522 ST_FUNC ssize_t full_read(int fd, void *buf, size_t count);
1682−ST_FUNC void *load_data(TCCState* S, int fd, unsigned long file_offset, unsigned long size);
1523+ST_FUNC void *load_data(int fd, unsigned long file_offset, unsigned long size);
16831524 ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
1684−ST_FUNC int tcc_load_object_file(TCCState *S, int fd, unsigned long file_offset);
1685−ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte);
1686−ST_FUNC void add_array(TCCState *S, const char *sec, int c);
1525+ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1526+ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
1527+ST_FUNC void add_array(TCCState *s1, const char *sec, int c);
16871528
16881529 #if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE)
1689−ST_FUNC void build_got_entries(TCCState *S);
1530+ST_FUNC void build_got_entries(TCCState *s1);
16901531 #endif
1691−ST_FUNC struct sym_attr *get_sym_attr(TCCState *S, int index, int alloc);
1692−ST_FUNC addr_t get_sym_addr(TCCState *S, const char *name, int err, int forc);
1693−ST_FUNC void list_elf_symbols(TCCState *S, void *ctx,
1532+ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
1533+ST_FUNC addr_t get_sym_addr(TCCState *s, const char *name, int err, int forc);
1534+ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
16941535 void (*symbol_cb)(void *ctx, const char *name, const void *val));
1695−ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t offs);
1536+ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs);
16961537
16971538 /* Browse each elem of type <type> in section <sec> starting at elem <startoff>
16981539 using variable <elem> */
@@ -1701,11 +1542,11 @@ ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t o · 2 unmodified lines
17011542 elem < (type *) (sec->data + sec->data_offset); elem++)
17021543
17031544 #ifndef ELF_OBJ_ONLY
1704−ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level);
1705−ST_FUNC int tcc_load_ldscript(TCCState *S, int fd);
1545+ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1546+ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd);
17061547 #endif
17071548 #ifndef TCC_TARGET_PE
1708−ST_FUNC void tcc_add_runtime(TCCState *S);
1549+ST_FUNC void tcc_add_runtime(TCCState *s1);
17091550 #endif
17101551
17111552 /* ------------ xxx-link.c ------------ */
@@ -1723,41 +1564,41 @@ enum gotplt_entry { · 11 unmodified lines
17231564 ST_FUNC int code_reloc (int reloc_type);
17241565 ST_FUNC int gotplt_entry_type (int reloc_type);
17251566 #if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE
1726−ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr);
1727−ST_FUNC void relocate_plt(TCCState *S);
1567+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1568+ST_FUNC void relocate_plt(TCCState *s1);
17281569 #endif
17291570 #endif
1730−ST_FUNC void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1571+ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
17311572
17321573 /* ------------ xxx-gen.c ------------ */
17331574 ST_DATA const char * const target_machine_defs;
17341575 ST_DATA const int reg_classes[NB_REGS];
17351576
1736−ST_FUNC void gsym_addr(TCCState* S, int t, int a);
1737−ST_FUNC void gsym(TCCState* S, int t);
1738−ST_FUNC void load(TCCState *S, int r, SValue *sv);
1739−ST_FUNC void store(TCCState *S, int r, SValue *v);
1577+ST_FUNC void gsym_addr(int t, int a);
1578+ST_FUNC void gsym(int t);
1579+ST_FUNC void load(int r, SValue *sv);
1580+ST_FUNC void store(int r, SValue *v);
17401581 ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
1741−ST_FUNC void gfunc_call(TCCState *S, int nb_args);
1742−ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym);
1743−ST_FUNC void gfunc_epilog(TCCState *S);
1744−ST_FUNC void gen_fill_nops(TCCState* S, int);
1745−ST_FUNC int gjmp(TCCState* S, int t);
1746−ST_FUNC void gjmp_addr(TCCState* S, int a);
1747−ST_FUNC int gjmp_cond(TCCState* S, int op, int t);
1748−ST_FUNC int gjmp_append(TCCState *S, int n, int t);
1749−ST_FUNC void gen_opi(TCCState* S, int op);
1750−ST_FUNC void gen_opf(TCCState* S, int op);
1751−ST_FUNC void gen_cvt_ftoi(TCCState *S, int t);
1752−ST_FUNC void gen_cvt_itof(TCCState *S, int t);
1753−ST_FUNC void gen_cvt_ftof(TCCState *S, int t);
1754−ST_FUNC void ggoto(TCCState *S);
1582+ST_FUNC void gfunc_call(int nb_args);
1583+ST_FUNC void gfunc_prolog(Sym *func_sym);
1584+ST_FUNC void gfunc_epilog(void);
1585+ST_FUNC void gen_fill_nops(int);
1586+ST_FUNC int gjmp(int t);
1587+ST_FUNC void gjmp_addr(int a);
1588+ST_FUNC int gjmp_cond(int op, int t);
1589+ST_FUNC int gjmp_append(int n, int t);
1590+ST_FUNC void gen_opi(int op);
1591+ST_FUNC void gen_opf(int op);
1592+ST_FUNC void gen_cvt_ftoi(int t);
1593+ST_FUNC void gen_cvt_itof(int t);
1594+ST_FUNC void gen_cvt_ftof(int t);
1595+ST_FUNC void ggoto(void);
17551596 #ifndef TCC_TARGET_C67
1756−ST_FUNC void o(TCCState* S, unsigned int c);
1597+ST_FUNC void o(unsigned int c);
17571598 #endif
1758−ST_FUNC void gen_vla_sp_save(TCCState* S, int addr);
1759−ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr);
1760−ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align);
1599+ST_FUNC void gen_vla_sp_save(int addr);
1600+ST_FUNC void gen_vla_sp_restore(int addr);
1601+ST_FUNC void gen_vla_alloc(CType *type, int align);
17611602
17621603 static inline uint16_t read16le(unsigned char *p) {
17631604 return p[0] | (uint16_t)p[1] << 8;
@@ -1786,57 +1627,57 @@ static inline void add64le(unsigned char *p, int64_t x) { · 22 unmodified lines
17861627
17871628 /* ------------ i386-gen.c ------------ */
17881629 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
1789−ST_FUNC void g(TCCState* S, int c);
1790−ST_FUNC void gen_le16(TCCState* S, int c);
1791−ST_FUNC void gen_le32(TCCState* S, int c);
1630+ST_FUNC void g(int c);
1631+ST_FUNC void gen_le16(int c);
1632+ST_FUNC void gen_le32(int c);
17921633 #endif
17931634 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1794−ST_FUNC void gen_addr32(TCCState* S, int r, Sym *sym, int c);
1795−ST_FUNC void gen_addrpc32(TCCState* S, int r, Sym *sym, int c);
1796−ST_FUNC void gen_cvt_csti(TCCState* S, int t);
1797−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
1635+ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1636+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1637+ST_FUNC void gen_cvt_csti(int t);
1638+ST_FUNC void gen_increment_tcov (SValue *sv);
17981639 #endif
17991640
18001641 /* ------------ x86_64-gen.c ------------ */
18011642 #ifdef TCC_TARGET_X86_64
1802−ST_FUNC void gen_addr64(TCCState* S, int r, Sym *sym, int64_t c);
1803−ST_FUNC void gen_opl(TCCState* S, int op);
1643+ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1644+ST_FUNC void gen_opl(int op);
18041645 #ifdef TCC_TARGET_PE
1805−ST_FUNC void gen_vla_result(TCCState* S, int addr);
1646+ST_FUNC void gen_vla_result(int addr);
18061647 #endif
1807−ST_FUNC void gen_cvt_sxtw(TCCState *S);
1808−ST_FUNC void gen_cvt_csti(TCCState* S, int t);
1648+ST_FUNC void gen_cvt_sxtw(void);
1649+ST_FUNC void gen_cvt_csti(int t);
18091650 #endif
18101651
18111652 /* ------------ arm-gen.c ------------ */
18121653 #ifdef TCC_TARGET_ARM
18131654 #if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
1814−PUB_FUNC const char *default_elfinterp(TCCState *S);
1655+PUB_FUNC const char *default_elfinterp(struct TCCState *s);
18151656 #endif
1816−ST_FUNC void arm_init(TCCState *S);
1817−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
1657+ST_FUNC void arm_init(struct TCCState *s);
1658+ST_FUNC void gen_increment_tcov (SValue *sv);
18181659 #endif
18191660
18201661 /* ------------ arm64-gen.c ------------ */
18211662 #ifdef TCC_TARGET_ARM64
1822−ST_FUNC void gen_opl(TCCState* S, int op);
1823−ST_FUNC void gfunc_return(TCCState *S, CType *func_type);
1824−ST_FUNC void gen_va_start(TCCState *S);
1825−ST_FUNC void gen_va_arg(TCCState *S, CType *t);
1826−ST_FUNC void gen_clear_cache(TCCState *S);
1827−ST_FUNC void gen_cvt_sxtw(TCCState *S);
1828−ST_FUNC void gen_cvt_csti(TCCState *S, int t);
1829−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
1663+ST_FUNC void gen_opl(int op);
1664+ST_FUNC void gfunc_return(CType *func_type);
1665+ST_FUNC void gen_va_start(void);
1666+ST_FUNC void gen_va_arg(CType *t);
1667+ST_FUNC void gen_clear_cache(void);
1668+ST_FUNC void gen_cvt_sxtw(void);
1669+ST_FUNC void gen_cvt_csti(int t);
1670+ST_FUNC void gen_increment_tcov (SValue *sv);
18301671 #endif
18311672
18321673 /* ------------ riscv64-gen.c ------------ */
18331674 #ifdef TCC_TARGET_RISCV64
1834−ST_FUNC void gen_opl(TCCState* S, int op);
1835−//ST_FUNC void gfunc_return(TCCState *S, CType *func_type);
1836−ST_FUNC void gen_va_start(TCCState *S);
1837−ST_FUNC void arch_transfer_ret_regs(TCCState* S, int);
1838−ST_FUNC void gen_cvt_sxtw(TCCState *S);
1839−ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
1675+ST_FUNC void gen_opl(int op);
1676+//ST_FUNC void gfunc_return(CType *func_type);
1677+ST_FUNC void gen_va_start(void);
1678+ST_FUNC void arch_transfer_ret_regs(int);
1679+ST_FUNC void gen_cvt_sxtw(void);
1680+ST_FUNC void gen_increment_tcov (SValue *sv);
18401681 #endif
18411682
18421683 /* ------------ c67-gen.c ------------ */
@@ -1846,44 +1687,44 @@ ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv); · 3 unmodified lines
18461687 /* ------------ tcccoff.c ------------ */
18471688
18481689 #ifdef TCC_TARGET_COFF
1849−ST_FUNC int tcc_output_coff(TCCState *S, FILE *f);
1850−ST_FUNC int tcc_load_coff(TCCState *S, int fd);
1690+ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1691+ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
18511692 #endif
18521693
18531694 /* ------------ tccasm.c ------------ */
1854−ST_FUNC void asm_instr(TCCState* S);
1855−ST_FUNC void asm_global_instr(TCCState* S);
1856−ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess);
1695+ST_FUNC void asm_instr(void);
1696+ST_FUNC void asm_global_instr(void);
1697+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
18571698 #ifdef CONFIG_TCC_ASM
1858−ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1859−ST_FUNC Sym* get_asm_sym(TCCState* S, int name, Sym *csym);
1860−ST_FUNC void asm_expr(TCCState *S, ExprValue *pe);
1861−ST_FUNC int asm_int_expr(TCCState *S);
1699+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1700+ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
1701+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1702+ST_FUNC int asm_int_expr(TCCState *s1);
18621703 /* ------------ i386-asm.c ------------ */
1863−ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe);
1704+ST_FUNC void gen_expr32(ExprValue *pe);
18641705 #ifdef TCC_TARGET_X86_64
1865−ST_FUNC void gen_expr64(TCCState* S, ExprValue *pe);
1706+ST_FUNC void gen_expr64(ExprValue *pe);
18661707 #endif
1867−ST_FUNC void asm_opcode(TCCState *S, int opcode);
1868−ST_FUNC int asm_parse_regvar(TCCState* S, int t);
1869−ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1870−ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int modifier);
1871−ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1872−ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str);
1708+ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1709+ST_FUNC int asm_parse_regvar(int t);
1710+ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1711+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1712+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1713+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
18731714 #endif
18741715
18751716 /* ------------ tccpe.c -------------- */
18761717 #ifdef TCC_TARGET_PE
1877−ST_FUNC int pe_load_file(struct TCCState *S, int fd, const char *filename);
1878−ST_FUNC int pe_output_file(TCCState * S, const char *filename);
1879−ST_FUNC int pe_putimport(TCCState *S, int dllindex, const char *name, addr_t value);
1718+ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename);
1719+ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1720+ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
18801721 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1881−ST_FUNC SValue *pe_getimport(TCCState * S, SValue *sv, SValue *v2);
1722+ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
18821723 #endif
18831724 #ifdef TCC_TARGET_X86_64
1884−ST_FUNC void pe_add_unwind_data(TCCState* S, unsigned start, unsigned end, unsigned stack);
1725+ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
18851726 #endif
1886−PUB_FUNC int tcc_get_dllexports(TCCState* S, const char *filename, char **pp);
1727+PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
18871728 /* symbol properties stored in Elf32_Sym->st_other */
18881729 # define ST_PE_EXPORT 0x10
18891730 # define ST_PE_IMPORT 0x20
@@ -1893,11 +1734,11 @@ PUB_FUNC int tcc_get_dllexports(TCCState* S, const char *filename, char **pp); · 3 unmodified lines
18931734
18941735 /* ------------ tccmacho.c ----------------- */
18951736 #ifdef TCC_TARGET_MACHO
1896−ST_FUNC int macho_output_file(TCCState * S, const char *filename);
1897−ST_FUNC int macho_load_dll(TCCState *S, int fd, const char *filename, int lev);
1898−ST_FUNC int macho_load_tbd(TCCState *S, int fd, const char *filename, int lev);
1737+ST_FUNC int macho_output_file(TCCState * s1, const char *filename);
1738+ST_FUNC int macho_load_dll(TCCState *s1, int fd, const char *filename, int lev);
1739+ST_FUNC int macho_load_tbd(TCCState *s1, int fd, const char *filename, int lev);
18991740 #ifdef TCC_IS_NATIVE
1900−ST_FUNC void tcc_add_macos_sdkpath(TCCState* S);
1741+ST_FUNC void tcc_add_macos_sdkpath(TCCState* s);
19011742 ST_FUNC const char* macho_tbd_soname(const char* filename);
19021743 #endif
19031744 #endif
@@ -1914,17 +1755,17 @@ ST_FUNC void dlclose(void *p); · 10 unmodified lines
19141755 ST_FUNC const char *dlerror(void);
19151756 ST_FUNC void *dlsym(void *handle, const char *symbol);
19161757 #endif
1917−ST_FUNC void tcc_run_free(TCCState *S);
1758+ST_FUNC void tcc_run_free(TCCState *s1);
19181759 #endif
19191760
19201761 /* ------------ tcctools.c ----------------- */
19211762 #if 0 /* included in tcc.c */
1922−ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv);
1763+ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
19231764 #ifdef TCC_TARGET_PE
1924−ST_FUNC int tcc_tool_impdef(TCCState *S, int argc, char **argv);
1765+ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
19251766 #endif
1926−ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int option);
1927−ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename);
1767+ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
1768+ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
19281769 #endif
19291770
19301771 /********************************************************/
@@ -1979,12 +1820,12 @@ ST_FUNC void post_sem(TCCSem *p); · 48 unmodified lines
19791820 #define total_lines TCC_STATE_VAR(total_lines)
19801821 #define total_bytes TCC_STATE_VAR(total_bytes)
19811822
1982−PUB_FUNC void tcc_enter_state(TCCState *S);
1983−PUB_FUNC void tcc_exit_state(TCCState *S);
1823+PUB_FUNC void tcc_enter_state(TCCState *s1);
1824+PUB_FUNC void tcc_exit_state(TCCState *s1);
19841825
19851826 /* conditional warning depending on switch */
19861827 #define tcc_warning_c(sw) TCC_SET_STATE((\
1987− S->warn_num = offsetof(TCCState, sw) \
1828+ tcc_state->warn_num = offsetof(TCCState, sw) \
19881829 - offsetof(TCCState, warn_none), _tcc_warning))
19891830
19901831 /********************************************************/
@@ -1994,10 +1835,10 @@ PUB_FUNC void tcc_exit_state(TCCState *S); · 3 unmodified lines
19941835 #undef TCC_SET_STATE
19951836
19961837 #ifdef USING_GLOBALS
1997−# define TCC_STATE_VAR(sym) S->sym
1838+# define TCC_STATE_VAR(sym) tcc_state->sym
19981839 # define TCC_SET_STATE(fn) fn
19991840 # undef USING_GLOBALS
20001841 #else
2001−# define TCC_STATE_VAR(sym) S->sym
2002−# define TCC_SET_STATE(fn) (tcc_enter_state(S),fn)
1842+# define TCC_STATE_VAR(sym) s1->sym
1843+# define TCC_SET_STATE(fn) (tcc_enter_state(s1),fn)
20031844 #endif
tccasm.c+420−418
@@ -22,16 +22,18 @@ · 21 unmodified lines
2222 #include "tcc.h"
2323 #ifdef CONFIG_TCC_ASM
2424
25−ST_FUNC int asm_get_local_label_name(TCCState *S, unsigned int n)
25+static Section *last_text_section; /* to handle .previous asm directive */
26+
27+ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
2628 {
2729 char buf[64];
2830 snprintf(buf, sizeof(buf), "L..%u", n);
29− return tok_alloc_const(S, buf);
31+ return tok_alloc_const(buf);
3032 }
3133
32−static int tcc_assemble_internal(TCCState *S, int do_preprocess, int global);
33−static Sym* asm_new_label(TCCState *S, int label, int is_local);
34−static Sym* asm_new_label1(TCCState *S, int label, int is_local, int sh_num, int value);
34+static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global);
35+static Sym* asm_new_label(TCCState *s1, int label, int is_local);
36+static Sym* asm_new_label1(TCCState *s1, int label, int is_local, int sh_num, int value);
3537
3638 /* If a C name has an _ prepended then only asm labels that start
3739 with _ are representable in C, by removing the first _. ASM names
@@ -39,44 +41,44 @@ static Sym* asm_new_label1(TCCState *S, int label, int is_local, int sh_num, int · 1 unmodified line
3941 the global C symbol table to track ASM names as well, so we need to
4042 transform those into ones that don't conflict with a C name,
4143 so prepend a '.' for them, but force the ELF asm name to be set. */
42−static int asm2cname(TCCState* S, int v, int *addeddot)
44+static int asm2cname(int v, int *addeddot)
4345 {
4446 const char *name;
4547 *addeddot = 0;
46− if (!S->leading_underscore)
48+ if (!tcc_state->leading_underscore)
4749 return v;
48− name = get_tok_str(S, v, NULL);
50+ name = get_tok_str(v, NULL);
4951 if (!name)
5052 return v;
5153 if (name[0] == '_') {
52− v = tok_alloc_const(S, name + 1);
54+ v = tok_alloc_const(name + 1);
5355 } else if (!strchr(name, '.')) {
5456 char newname[256];
5557 snprintf(newname, sizeof newname, ".%s", name);
56− v = tok_alloc_const(S, newname);
58+ v = tok_alloc_const(newname);
5759 *addeddot = 1;
5860 }
5961 return v;
6062 }
6163
62−static Sym *asm_label_find(TCCState* S, int v)
64+static Sym *asm_label_find(int v)
6365 {
6466 Sym *sym;
6567 int addeddot;
66− v = asm2cname(S, v, &addeddot);
67− sym = sym_find(S, v);
68+ v = asm2cname(v, &addeddot);
69+ sym = sym_find(v);
6870 while (sym && sym->sym_scope && !(sym->type.t & VT_STATIC))
6971 sym = sym->prev_tok;
7072 return sym;
7173 }
7274
73−static Sym *asm_label_push(TCCState* S, int v)
75+static Sym *asm_label_push(int v)
7476 {
75− int addeddot, v2 = asm2cname(S, v, &addeddot);
77+ int addeddot, v2 = asm2cname(v, &addeddot);
7678 /* We always add VT_EXTERN, for sym definition that's tentative
7779 (for .set, removed for real defs), for mere references it's correct
7880 as is. */
79− Sym *sym = global_identifier_push(S, v2, VT_ASM | VT_EXTERN | VT_STATIC, 0);
81+ Sym *sym = global_identifier_push(v2, VT_ASM | VT_EXTERN | VT_STATIC, 0);
8082 if (addeddot)
8183 sym->asm_label = v;
8284 return sym;
@@ -92,55 +94,55 @@ static Sym *asm_label_push(TCCState* S, int v) · 9 unmodified lines
9294 are anonymous in C, in this case CSYM can be used to transfer
9395 all information from that symbol to the (possibly newly created)
9496 asm symbol. */
95−ST_FUNC Sym* get_asm_sym(TCCState* S, int name, Sym *csym)
97+ST_FUNC Sym* get_asm_sym(int name, Sym *csym)
9698 {
97− Sym *sym = asm_label_find(S, name);
99+ Sym *sym = asm_label_find(name);
98100 if (!sym) {
99− sym = asm_label_push(S, name);
101+ sym = asm_label_push(name);
100102 if (csym)
101103 sym->c = csym->c;
102104 }
103105 return sym;
104106 }
105107
106−static Sym* asm_section_sym(TCCState *S, Section *sec)
108+static Sym* asm_section_sym(TCCState *s1, Section *sec)
107109 {
108110 char buf[100]; int label; Sym *sym;
109111 snprintf(buf, sizeof buf, "L.%s", sec->name);
110− label = tok_alloc_const(S, buf);
111− sym = asm_label_find(S, label);
112− return sym ? sym : asm_new_label1(S, label, 1, sec->sh_num, 0);
112+ label = tok_alloc_const(buf);
113+ sym = asm_label_find(label);
114+ return sym ? sym : asm_new_label1(s1, label, 1, sec->sh_num, 0);
113115 }
114116
115117 /* We do not use the C expression parser to handle symbols. Maybe the
116118 C expression parser could be tweaked to do so. */
117119
118−static void asm_expr_unary(TCCState *S, ExprValue *pe)
120+static void asm_expr_unary(TCCState *s1, ExprValue *pe)
119121 {
120122 Sym *sym;
121123 int op, label;
122124 uint64_t n;
123125 const char *p;
124126
125− switch(S->tccpp_tok) {
127+ switch(tok) {
126128 case TOK_PPNUM:
127− p = S->tccpp_tokc.str.data;
129+ p = tokc.str.data;
128130 n = strtoull(p, (char **)&p, 0);
129131 if (*p == 'b' || *p == 'f') {
130132 /* backward or forward label */
131− label = asm_get_local_label_name(S, n);
132− sym = asm_label_find(S, label);
133+ label = asm_get_local_label_name(s1, n);
134+ sym = asm_label_find(label);
133135 if (*p == 'b') {
134136 /* backward : find the last corresponding defined label */
135− if (sym && (!sym->c || elfsym(S, sym)->st_shndx == SHN_UNDEF))
137+ if (sym && (!sym->c || elfsym(sym)->st_shndx == SHN_UNDEF))
136138 sym = sym->prev_tok;
137139 if (!sym)
138− tcc_error(S, "local label '%d' not found backward", (int)n);
140+ tcc_error("local label '%d' not found backward", (int)n);
139141 } else {
140142 /* forward */
141− if (!sym || (sym->c && elfsym(S, sym)->st_shndx != SHN_UNDEF)) {
143+ if (!sym || (sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)) {
142144 /* if the last label is defined, then define a new one */
143− sym = asm_label_push(S, label);
145+ sym = asm_label_push(label);
144146 }
145147 }
146148 pe->v = 0;
@@ -151,21 +153,21 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe) · 4 unmodified lines
151153 pe->sym = NULL;
152154 pe->pcrel = 0;
153155 } else {
154− tcc_error(S, "invalid number syntax");
156+ tcc_error("invalid number syntax");
155157 }
156− next(S);
158+ next();
157159 break;
158160 case '+':
159− next(S);
160− asm_expr_unary(S, pe);
161+ next();
162+ asm_expr_unary(s1, pe);
161163 break;
162164 case '-':
163165 case '~':
164− op = S->tccpp_tok;
165− next(S);
166− asm_expr_unary(S, pe);
166+ op = tok;
167+ next();
168+ asm_expr_unary(s1, pe);
167169 if (pe->sym)
168− tcc_error(S, "invalid operation with label");
170+ tcc_error("invalid operation with label");
169171 if (op == '-')
170172 pe->v = -pe->v;
171173 else
@@ -173,28 +175,28 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe) · 1 unmodified line
173175 break;
174176 case TOK_CCHAR:
175177 case TOK_LCHAR:
176− pe->v = S->tccpp_tokc.i;
178+ pe->v = tokc.i;
177179 pe->sym = NULL;
178180 pe->pcrel = 0;
179− next(S);
181+ next();
180182 break;
181183 case '(':
182− next(S);
183− asm_expr(S, pe);
184− skip(S, ')');
184+ next();
185+ asm_expr(s1, pe);
186+ skip(')');
185187 break;
186188 case '.':
187− pe->v = S->tccgen_ind;
188− pe->sym = asm_section_sym(S, cur_text_section);
189+ pe->v = ind;
190+ pe->sym = asm_section_sym(s1, cur_text_section);
189191 pe->pcrel = 0;
190− next(S);
192+ next();
191193 break;
192194 default:
193− if (S->tccpp_tok >= TOK_IDENT) {
195+ if (tok >= TOK_IDENT) {
194196 ElfSym *esym;
195197 /* label case : if the label was not found, add one */
196− sym = get_asm_sym(S, S->tccpp_tok, NULL);
197− esym = elfsym(S, sym);
198+ sym = get_asm_sym(tok, NULL);
199+ esym = elfsym(sym);
198200 if (esym && esym->st_shndx == SHN_ABS) {
199201 /* if absolute symbol, no need to put a symbol value */
200202 pe->v = esym->st_value;
@@ -205,29 +207,29 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe) · 4 unmodified lines
205207 pe->sym = sym;
206208 pe->pcrel = 0;
207209 }
208− next(S);
210+ next();
209211 } else {
210− tcc_error(S, "bad expression syntax [%s]", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
212+ tcc_error("bad expression syntax [%s]", get_tok_str(tok, &tokc));
211213 }
212214 break;
213215 }
214216 }
215217
216−static void asm_expr_prod(TCCState *S, ExprValue *pe)
218+static void asm_expr_prod(TCCState *s1, ExprValue *pe)
217219 {
218220 int op;
219221 ExprValue e2;
220222
221− asm_expr_unary(S, pe);
223+ asm_expr_unary(s1, pe);
222224 for(;;) {
223− op = S->tccpp_tok;
225+ op = tok;
224226 if (op != '*' && op != '/' && op != '%' &&
225227 op != TOK_SHL && op != TOK_SAR)
226228 break;
227− next(S);
228− asm_expr_unary(S, &e2);
229+ next();
230+ asm_expr_unary(s1, &e2);
229231 if (pe->sym || e2.sym)
230− tcc_error(S, "invalid operation with label");
232+ tcc_error("invalid operation with label");
231233 switch(op) {
232234 case '*':
233235 pe->v *= e2.v;
@@ -235,7 +237,7 @@ static void asm_expr_prod(TCCState *S, ExprValue *pe) · 1 unmodified line
235237 case '/':
236238 if (e2.v == 0) {
237239 div_error:
238− tcc_error(S, "division by zero");
240+ tcc_error("division by zero");
239241 }
240242 pe->v /= e2.v;
241243 break;
@@ -255,20 +257,20 @@ static void asm_expr_prod(TCCState *S, ExprValue *pe) · 13 unmodified lines
255257 }
256258 }
257259
258−static void asm_expr_logic(TCCState *S, ExprValue *pe)
260+static void asm_expr_logic(TCCState *s1, ExprValue *pe)
259261 {
260262 int op;
261263 ExprValue e2;
262264
263− asm_expr_prod(S, pe);
265+ asm_expr_prod(s1, pe);
264266 for(;;) {
265− op = S->tccpp_tok;
267+ op = tok;
266268 if (op != '&' && op != '|' && op != '^')
267269 break;
268− next(S);
269− asm_expr_prod(S, &e2);
270+ next();
271+ asm_expr_prod(s1, &e2);
270272 if (pe->sym || e2.sym)
271− tcc_error(S, "invalid operation with label");
273+ tcc_error("invalid operation with label");
272274 switch(op) {
273275 case '&':
274276 pe->v &= e2.v;
@@ -284,18 +286,18 @@ static void asm_expr_logic(TCCState *S, ExprValue *pe) · 9 unmodified lines
284286 }
285287 }
286288
287−static inline void asm_expr_sum(TCCState *S, ExprValue *pe)
289+static inline void asm_expr_sum(TCCState *s1, ExprValue *pe)
288290 {
289291 int op;
290292 ExprValue e2;
291293
292− asm_expr_logic(S, pe);
294+ asm_expr_logic(s1, pe);
293295 for(;;) {
294− op = S->tccpp_tok;
296+ op = tok;
295297 if (op != '+' && op != '-')
296298 break;
297− next(S);
298− asm_expr_logic(S, &e2);
299+ next();
300+ asm_expr_logic(s1, &e2);
299301 if (op == '+') {
300302 if (pe->sym != NULL && e2.sym != NULL)
301303 goto cannot_relocate;
@@ -313,8 +315,8 @@ static inline void asm_expr_sum(TCCState *S, ExprValue *pe) · 11 unmodified lines
313315 pe->sym = NULL; /* same symbols can be subtracted to NULL */
314316 } else {
315317 ElfSym *esym1, *esym2;
316− esym1 = elfsym(S, pe->sym);
317− esym2 = elfsym(S, e2.sym);
318+ esym1 = elfsym(pe->sym);
319+ esym2 = elfsym(e2.sym);
318320 if (esym1 && esym1->st_shndx == esym2->st_shndx
319321 && esym1->st_shndx != SHN_UNDEF) {
320322 /* we also accept defined symbols in the same section */
@@ -323,33 +325,33 @@ static inline void asm_expr_sum(TCCState *S, ExprValue *pe) · 2 unmodified lines
323325 } else if (esym2->st_shndx == cur_text_section->sh_num) {
324326 /* When subtracting a defined symbol in current section
325327 this actually makes the value PC-relative. */
326− pe->v -= esym2->st_value - S->tccgen_ind - 4;
328+ pe->v -= esym2->st_value - ind - 4;
327329 pe->pcrel = 1;
328330 e2.sym = NULL;
329331 } else {
330332 cannot_relocate:
331− tcc_error(S, "invalid operation with label");
333+ tcc_error("invalid operation with label");
332334 }
333335 }
334336 }
335337 }
336338 }
337339
338−static inline void asm_expr_cmp(TCCState *S, ExprValue *pe)
340+static inline void asm_expr_cmp(TCCState *s1, ExprValue *pe)
339341 {
340342 int op;
341343 ExprValue e2;
342344
343− asm_expr_sum(S, pe);
345+ asm_expr_sum(s1, pe);
344346 for(;;) {
345− op = S->tccpp_tok;
347+ op = tok;
346348 if (op != TOK_EQ && op != TOK_NE
347349 && (op > TOK_GT || op < TOK_ULE))
348350 break;
349− next(S);
350− asm_expr_sum(S, &e2);
351+ next();
352+ asm_expr_sum(s1, &e2);
351353 if (pe->sym || e2.sym)
352− tcc_error(S, "invalid operation with label");
354+ tcc_error("invalid operation with label");
353355 switch(op) {
354356 case TOK_EQ:
355357 pe->v = pe->v == e2.v;
@@ -377,29 +379,29 @@ static inline void asm_expr_cmp(TCCState *S, ExprValue *pe) · 21 unmodified lines
377379 }
378380 }
379381
380−ST_FUNC void asm_expr(TCCState *S, ExprValue *pe)
382+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe)
381383 {
382− asm_expr_cmp(S, pe);
384+ asm_expr_cmp(s1, pe);
383385 }
384386
385−ST_FUNC int asm_int_expr(TCCState *S)
387+ST_FUNC int asm_int_expr(TCCState *s1)
386388 {
387389 ExprValue e;
388− asm_expr(S, &e);
390+ asm_expr(s1, &e);
389391 if (e.sym)
390− expect(S, "constant");
392+ expect("constant");
391393 return e.v;
392394 }
393395
394−static Sym* asm_new_label1(TCCState *S, int label, int is_local,
396+static Sym* asm_new_label1(TCCState *s1, int label, int is_local,
395397 int sh_num, int value)
396398 {
397399 Sym *sym;
398400 ElfSym *esym;
399401
400− sym = asm_label_find(S, label);
402+ sym = asm_label_find(label);
401403 if (sym) {
402− esym = elfsym(S, sym);
404+ esym = elfsym(sym);
403405 /* A VT_EXTERN symbol, even if it has a section is considered
404406 overridable. This is how we "define" .set targets. Real
405407 definitions won't have VT_EXTERN set. */
@@ -409,16 +411,16 @@ static Sym* asm_new_label1(TCCState *S, int label, int is_local, · 3 unmodified lines
409411 && (is_local == 1 || (sym->type.t & VT_EXTERN)))
410412 goto new_label;
411413 if (!(sym->type.t & VT_EXTERN))
412− tcc_error(S, "assembler label '%s' already defined",
413− get_tok_str(S, label, NULL));
414+ tcc_error("assembler label '%s' already defined",
415+ get_tok_str(label, NULL));
414416 }
415417 } else {
416418 new_label:
417− sym = asm_label_push(S, label);
419+ sym = asm_label_push(label);
418420 }
419421 if (!sym->c)
420− put_extern_sym2(S, sym, SHN_UNDEF, 0, 0, 1);
421− esym = elfsym(S, sym);
422+ put_extern_sym2(sym, SHN_UNDEF, 0, 0, 1);
423+ esym = elfsym(sym);
422424 esym->st_shndx = sh_num;
423425 esym->st_value = value;
424426 if (is_local != 2)
@@ -426,61 +428,61 @@ static Sym* asm_new_label1(TCCState *S, int label, int is_local, · 1 unmodified line
426428 return sym;
427429 }
428430
429−static Sym* asm_new_label(TCCState *S, int label, int is_local)
431+static Sym* asm_new_label(TCCState *s1, int label, int is_local)
430432 {
431− return asm_new_label1(S, label, is_local, cur_text_section->sh_num, S->tccgen_ind);
433+ return asm_new_label1(s1, label, is_local, cur_text_section->sh_num, ind);
432434 }
433435
434436 /* Set the value of LABEL to that of some expression (possibly
435437 involving other symbols). LABEL can be overwritten later still. */
436−static Sym* set_symbol(TCCState *S, int label)
438+static Sym* set_symbol(TCCState *s1, int label)
437439 {
438440 long n;
439441 ExprValue e;
440442 Sym *sym;
441443 ElfSym *esym;
442− next(S);
443− asm_expr(S, &e);
444+ next();
445+ asm_expr(s1, &e);
444446 n = e.v;
445− esym = elfsym(S, e.sym);
447+ esym = elfsym(e.sym);
446448 if (esym)
447449 n += esym->st_value;
448− sym = asm_new_label1(S, label, 2, esym ? esym->st_shndx : SHN_ABS, n);
449− elfsym(S, sym)->st_other |= ST_ASM_SET;
450+ sym = asm_new_label1(s1, label, 2, esym ? esym->st_shndx : SHN_ABS, n);
451+ elfsym(sym)->st_other |= ST_ASM_SET;
450452 return sym;
451453 }
452454
453−static void use_section1(TCCState *S, Section *sec)
455+static void use_section1(TCCState *s1, Section *sec)
454456 {
455− cur_text_section->data_offset = S->tccgen_ind;
457+ cur_text_section->data_offset = ind;
456458 cur_text_section = sec;
457− S->tccgen_ind = cur_text_section->data_offset;
459+ ind = cur_text_section->data_offset;
458460 }
459461
460−static void use_section(TCCState *S, const char *name)
462+static void use_section(TCCState *s1, const char *name)
461463 {
462464 Section *sec;
463− sec = find_section(S, name);
464− use_section1(S, sec);
465+ sec = find_section(s1, name);
466+ use_section1(s1, sec);
465467 }
466468
467−static void push_section(TCCState *S, const char *name)
469+static void push_section(TCCState *s1, const char *name)
468470 {
469− Section *sec = find_section(S, name);
471+ Section *sec = find_section(s1, name);
470472 sec->prev = cur_text_section;
471− use_section1(S, sec);
473+ use_section1(s1, sec);
472474 }
473475
474−static void pop_section(TCCState *S)
476+static void pop_section(TCCState *s1)
475477 {
476478 Section *prev = cur_text_section->prev;
477479 if (!prev)
478− tcc_error(S, ".popsection without .pushsection");
480+ tcc_error(".popsection without .pushsection");
479481 cur_text_section->prev = NULL;
480− use_section1(S, prev);
482+ use_section1(s1, prev);
481483 }
482484
483−static void asm_parse_directive(TCCState *S, int global)
485+static void asm_parse_directive(TCCState *s1, int global)
484486 {
485487 int n, offset, v, size, tok1;
486488 Section *sec;
@@ -488,27 +490,27 @@ static void asm_parse_directive(TCCState *S, int global) · 1 unmodified line
488490
489491 /* assembler directive */
490492 sec = cur_text_section;
491− switch(S->tccpp_tok) {
493+ switch(tok) {
492494 case TOK_ASMDIR_align:
493495 case TOK_ASMDIR_balign:
494496 case TOK_ASMDIR_p2align:
495497 case TOK_ASMDIR_skip:
496498 case TOK_ASMDIR_space:
497− tok1 = S->tccpp_tok;
498− next(S);
499− n = asm_int_expr(S);
499+ tok1 = tok;
500+ next();
501+ n = asm_int_expr(s1);
500502 if (tok1 == TOK_ASMDIR_p2align)
501503 {
502504 if (n < 0 || n > 30)
503− tcc_error(S, "invalid p2align, must be between 0 and 30");
505+ tcc_error("invalid p2align, must be between 0 and 30");
504506 n = 1 << n;
505507 tok1 = TOK_ASMDIR_align;
506508 }
507509 if (tok1 == TOK_ASMDIR_align || tok1 == TOK_ASMDIR_balign) {
508510 if (n < 0 || (n & (n-1)) != 0)
509− tcc_error(S, "alignment must be a positive power of two");
510− offset = (S->tccgen_ind + n - 1) & -n;
511− size = offset - S->tccgen_ind;
511+ tcc_error("alignment must be a positive power of two");
512+ offset = (ind + n - 1) & -n;
513+ size = offset - ind;
512514 /* the section must have a compatible alignment */
513515 if (sec->sh_addralign < n)
514516 sec->sh_addralign = n;
@@ -518,47 +520,47 @@ static void asm_parse_directive(TCCState *S, int global) · 3 unmodified lines
518520 size = n;
519521 }
520522 v = 0;
521− if (S->tccpp_tok == ',') {
522− next(S);
523− v = asm_int_expr(S);
523+ if (tok == ',') {
524+ next();
525+ v = asm_int_expr(s1);
524526 }
525527 zero_pad:
526528 if (sec->sh_type != SHT_NOBITS) {
527− sec->data_offset = S->tccgen_ind;
528− ptr = section_ptr_add(S, sec, size);
529+ sec->data_offset = ind;
530+ ptr = section_ptr_add(sec, size);
529531 memset(ptr, v, size);
530532 }
531− S->tccgen_ind += size;
533+ ind += size;
532534 break;
533535 case TOK_ASMDIR_quad:
534536 #ifdef TCC_TARGET_X86_64
535537 size = 8;
536538 goto asm_data;
537539 #else
538− next(S);
540+ next();
539541 for(;;) {
540542 uint64_t vl;
541543 const char *p;
542544
543− p = S->tccpp_tokc.str.data;
544− if (S->tccpp_tok != TOK_PPNUM) {
545+ p = tokc.str.data;
546+ if (tok != TOK_PPNUM) {
545547 error_constant:
546− tcc_error(S, "64 bit constant");
548+ tcc_error("64 bit constant");
547549 }
548550 vl = strtoll(p, (char **)&p, 0);
549551 if (*p != '\0')
550552 goto error_constant;
551− next(S);
553+ next();
552554 if (sec->sh_type != SHT_NOBITS) {
553555 /* XXX: endianness */
554− gen_le32(S, vl);
555− gen_le32(S, vl >> 32);
556+ gen_le32(vl);
557+ gen_le32(vl >> 32);
556558 } else {
557− S->tccgen_ind += 8;
559+ ind += 8;
558560 }
559− if (S->tccpp_tok != ',')
561+ if (tok != ',')
560562 break;
561− next(S);
563+ next();
562564 }
563565 break;
564566 #endif
@@ -573,57 +575,57 @@ static void asm_parse_directive(TCCState *S, int global) · 8 unmodified lines
573575 case TOK_ASMDIR_int:
574576 size = 4;
575577 asm_data:
576− next(S);
578+ next();
577579 for(;;) {
578580 ExprValue e;
579− asm_expr(S, &e);
581+ asm_expr(s1, &e);
580582 if (sec->sh_type != SHT_NOBITS) {
581583 if (size == 4) {
582− gen_expr32(S, &e);
584+ gen_expr32(&e);
583585 #ifdef TCC_TARGET_X86_64
584586 } else if (size == 8) {
585− gen_expr64(S, &e);
587+ gen_expr64(&e);
586588 #endif
587589 } else {
588590 if (e.sym)
589− expect(S, "constant");
591+ expect("constant");
590592 if (size == 1)
591− g(S, e.v);
593+ g(e.v);
592594 else
593− gen_le16(S, e.v);
595+ gen_le16(e.v);
594596 }
595597 } else {
596− S->tccgen_ind += size;
598+ ind += size;
597599 }
598− if (S->tccpp_tok != ',')
600+ if (tok != ',')
599601 break;
600− next(S);
602+ next();
601603 }
602604 break;
603605 case TOK_ASMDIR_fill:
604606 {
605607 int repeat, size, val, i, j;
606608 uint8_t repeat_buf[8];
607− next(S);
608− repeat = asm_int_expr(S);
609+ next();
610+ repeat = asm_int_expr(s1);
609611 if (repeat < 0) {
610− tcc_error(S, "repeat < 0; .fill ignored");
612+ tcc_error("repeat < 0; .fill ignored");
611613 break;
612614 }
613615 size = 1;
614616 val = 0;
615− if (S->tccpp_tok == ',') {
616− next(S);
617− size = asm_int_expr(S);
617+ if (tok == ',') {
618+ next();
619+ size = asm_int_expr(s1);
618620 if (size < 0) {
619− tcc_error(S, "size < 0; .fill ignored");
621+ tcc_error("size < 0; .fill ignored");
620622 break;
621623 }
622624 if (size > 8)
623625 size = 8;
624− if (S->tccpp_tok == ',') {
625− next(S);
626− val = asm_int_expr(S);
626+ if (tok == ',') {
627+ next();
628+ val = asm_int_expr(s1);
627629 }
628630 }
629631 /* XXX: endianness */
@@ -637,7 +639,7 @@ static void asm_parse_directive(TCCState *S, int global) · 7 unmodified lines
637639 repeat_buf[7] = 0;
638640 for(i = 0; i < repeat; i++) {
639641 for(j = 0; j < size; j++) {
640− g(S, repeat_buf[j]);
642+ g(repeat_buf[j]);
641643 }
642644 }
643645 }
@@ -646,24 +648,24 @@ static void asm_parse_directive(TCCState *S, int global) · 2 unmodified lines
646648 {
647649 int repeat;
648650 TokenString *init_str;
649− next(S);
650− repeat = asm_int_expr(S);
651− init_str = tok_str_alloc(S);
652− while (next(S), S->tccpp_tok != TOK_ASMDIR_endr) {
653− if (S->tccpp_tok == CH_EOF)
654− tcc_error(S, "we at end of file, .endr not found");
655− tok_str_add_tok(S, init_str);
651+ next();
652+ repeat = asm_int_expr(s1);
653+ init_str = tok_str_alloc();
654+ while (next(), tok != TOK_ASMDIR_endr) {
655+ if (tok == CH_EOF)
656+ tcc_error("we at end of file, .endr not found");
657+ tok_str_add_tok(init_str);
656658 }
657− tok_str_add(S, init_str, -1);
658− tok_str_add(S, init_str, 0);
659− begin_macro(S, init_str, 1);
659+ tok_str_add(init_str, -1);
660+ tok_str_add(init_str, 0);
661+ begin_macro(init_str, 1);
660662 while (repeat-- > 0) {
661− tcc_assemble_internal(S, (S->tccpp_parse_flags & PARSE_FLAG_PREPROCESS),
663+ tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS),
662664 global);
663− S->tccpp_macro_ptr = init_str->str;
665+ macro_ptr = init_str->str;
664666 }
665− end_macro(S);
666− next(S);
667+ end_macro();
668+ next();
667669 break;
668670 }
669671 case TOK_ASMDIR_org:
@@ -671,49 +673,49 @@ static void asm_parse_directive(TCCState *S, int global) · 1 unmodified line
671673 unsigned long n;
672674 ExprValue e;
673675 ElfSym *esym;
674− next(S);
675− asm_expr(S, &e);
676+ next();
677+ asm_expr(s1, &e);
676678 n = e.v;
677− esym = elfsym(S, e.sym);
679+ esym = elfsym(e.sym);
678680 if (esym) {
679681 if (esym->st_shndx != cur_text_section->sh_num)
680− expect(S, "constant or same-section symbol");
682+ expect("constant or same-section symbol");
681683 n += esym->st_value;
682684 }
683− if (n < S->tccgen_ind)
684− tcc_error(S, "attempt to .org backwards");
685+ if (n < ind)
686+ tcc_error("attempt to .org backwards");
685687 v = 0;
686− size = n - S->tccgen_ind;
688+ size = n - ind;
687689 goto zero_pad;
688690 }
689691 break;
690692 case TOK_ASMDIR_set:
691− next(S);
692− tok1 = S->tccpp_tok;
693− next(S);
693+ next();
694+ tok1 = tok;
695+ next();
694696 /* Also accept '.set stuff', but don't do anything with this.
695697 It's used in GAS to set various features like '.set mips16'. */
696− if (S->tccpp_tok == ',')
697− set_symbol(S, tok1);
698+ if (tok == ',')
699+ set_symbol(s1, tok1);
698700 break;
699701 case TOK_ASMDIR_globl:
700702 case TOK_ASMDIR_global:
701703 case TOK_ASMDIR_weak:
702704 case TOK_ASMDIR_hidden:
703− tok1 = S->tccpp_tok;
705+ tok1 = tok;
704706 do {
705707 Sym *sym;
706− next(S);
707− sym = get_asm_sym(S, S->tccpp_tok, NULL);
708+ next();
709+ sym = get_asm_sym(tok, NULL);
708710 if (tok1 != TOK_ASMDIR_hidden)
709711 sym->type.t &= ~VT_STATIC;
710712 if (tok1 == TOK_ASMDIR_weak)
711713 sym->a.weak = 1;
712714 else if (tok1 == TOK_ASMDIR_hidden)
713715 sym->a.visibility = STV_HIDDEN;
714− update_storage(S, sym);
715− next(S);
716− } while (S->tccpp_tok == ',');
716+ update_storage(sym);
717+ next();
718+ } while (tok == ',');
717719 break;
718720 case TOK_ASMDIR_string:
719721 case TOK_ASMDIR_ascii:
@@ -722,21 +724,21 @@ static void asm_parse_directive(TCCState *S, int global) · 2 unmodified lines
722724 const uint8_t *p;
723725 int i, size, t;
724726
725− t = S->tccpp_tok;
726− next(S);
727+ t = tok;
728+ next();
727729 for(;;) {
728− if (S->tccpp_tok != TOK_STR)
729− expect(S, "string constant");
730− p = S->tccpp_tokc.str.data;
731− size = S->tccpp_tokc.str.size;
730+ if (tok != TOK_STR)
731+ expect("string constant");
732+ p = tokc.str.data;
733+ size = tokc.str.size;
732734 if (t == TOK_ASMDIR_ascii && size > 0)
733735 size--;
734736 for(i = 0; i < size; i++)
735− g(S, p[i]);
736− next(S);
737− if (S->tccpp_tok == ',') {
738− next(S);
739− } else if (S->tccpp_tok != TOK_STR) {
737+ g(p[i]);
738+ next();
739+ if (tok == ',') {
740+ next();
741+ } else if (tok != TOK_STR) {
740742 break;
741743 }
742744 }
@@ -747,18 +749,18 @@ static void asm_parse_directive(TCCState *S, int global) · 4 unmodified lines
747749 case TOK_ASMDIR_bss:
748750 {
749751 char sname[64];
750− tok1 = S->tccpp_tok;
752+ tok1 = tok;
751753 n = 0;
752− next(S);
753− if (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED) {
754− n = asm_int_expr(S);
755− next(S);
754+ next();
755+ if (tok != ';' && tok != TOK_LINEFEED) {
756+ n = asm_int_expr(s1);
757+ next();
756758 }
757759 if (n)
758− sprintf(sname, "%s%d", get_tok_str(S, tok1, NULL), n);
760+ sprintf(sname, "%s%d", get_tok_str(tok1, NULL), n);
759761 else
760− sprintf(sname, "%s", get_tok_str(S, tok1, NULL));
761− use_section(S, sname);
762+ sprintf(sname, "%s", get_tok_str(tok1, NULL));
763+ use_section(s1, sname);
762764 }
763765 break;
764766 case TOK_ASMDIR_file:
@@ -766,13 +768,13 @@ static void asm_parse_directive(TCCState *S, int global) · 1 unmodified line
766768 char filename[512];
767769
768770 filename[0] = '\0';
769− next(S);
770− if (S->tccpp_tok == TOK_STR)
771− pstrcat(filename, sizeof(filename), S->tccpp_tokc.str.data);
771+ next();
772+ if (tok == TOK_STR)
773+ pstrcat(filename, sizeof(filename), tokc.str.data);
772774 else
773− pstrcat(filename, sizeof(filename), get_tok_str(S, S->tccpp_tok, NULL));
774− tcc_warning_c(warn_unsupported)(S, "ignoring .file %s", filename);
775− next(S);
775+ pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
776+ tcc_warning_c(warn_unsupported)("ignoring .file %s", filename);
777+ next();
776778 }
777779 break;
778780 case TOK_ASMDIR_ident:
@@ -780,30 +782,30 @@ static void asm_parse_directive(TCCState *S, int global) · 1 unmodified line
780782 char ident[256];
781783
782784 ident[0] = '\0';
783− next(S);
784− if (S->tccpp_tok == TOK_STR)
785− pstrcat(ident, sizeof(ident), S->tccpp_tokc.str.data);
785+ next();
786+ if (tok == TOK_STR)
787+ pstrcat(ident, sizeof(ident), tokc.str.data);
786788 else
787− pstrcat(ident, sizeof(ident), get_tok_str(S, S->tccpp_tok, NULL));
788− tcc_warning_c(warn_unsupported)(S, "ignoring .ident %s", ident);
789− next(S);
789+ pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL));
790+ tcc_warning_c(warn_unsupported)("ignoring .ident %s", ident);
791+ next();
790792 }
791793 break;
792794 case TOK_ASMDIR_size:
793795 {
794796 Sym *sym;
795797
796− next(S);
797− sym = asm_label_find(S, S->tccpp_tok);
798+ next();
799+ sym = asm_label_find(tok);
798800 if (!sym) {
799− tcc_error(S, "label not found: %s", get_tok_str(S, S->tccpp_tok, NULL));
801+ tcc_error("label not found: %s", get_tok_str(tok, NULL));
800802 }
801803 /* XXX .size name,label2-label1 */
802− tcc_warning_c(warn_unsupported)(S, "ignoring .size %s,*", get_tok_str(S, S->tccpp_tok, NULL));
803− next(S);
804− skip(S, ',');
805− while (S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != ';' && S->tccpp_tok != CH_EOF) {
806− next(S);
804+ tcc_warning_c(warn_unsupported)("ignoring .size %s,*", get_tok_str(tok, NULL));
805+ next();
806+ skip(',');
807+ while (tok != TOK_LINEFEED && tok != ';' && tok != CH_EOF) {
808+ next();
807809 }
808810 }
809811 break;
@@ -812,182 +814,182 @@ static void asm_parse_directive(TCCState *S, int global) · 2 unmodified lines
812814 Sym *sym;
813815 const char *newtype;
814816
815− next(S);
816− sym = get_asm_sym(S, S->tccpp_tok, NULL);
817− next(S);
818− skip(S, ',');
819− if (S->tccpp_tok == TOK_STR) {
820− newtype = S->tccpp_tokc.str.data;
817+ next();
818+ sym = get_asm_sym(tok, NULL);
819+ next();
820+ skip(',');
821+ if (tok == TOK_STR) {
822+ newtype = tokc.str.data;
821823 } else {
822− if (S->tccpp_tok == '@' || S->tccpp_tok == '%')
823− next(S);
824− newtype = get_tok_str(S, S->tccpp_tok, NULL);
824+ if (tok == '@' || tok == '%')
825+ next();
826+ newtype = get_tok_str(tok, NULL);
825827 }
826828
827829 if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
828830 sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC;
829831 } else
830− tcc_warning_c(warn_unsupported)(S, "change type of '%s' from 0x%x to '%s' ignored",
831− get_tok_str(S, sym->v, NULL), sym->type.t, newtype);
832+ tcc_warning_c(warn_unsupported)("change type of '%s' from 0x%x to '%s' ignored",
833+ get_tok_str(sym->v, NULL), sym->type.t, newtype);
832834
833− next(S);
835+ next();
834836 }
835837 break;
836838 case TOK_ASMDIR_pushsection:
837839 case TOK_ASMDIR_section:
838840 {
839841 char sname[256];
840− int old_nb_section = S->nb_sections;
842+ int old_nb_section = s1->nb_sections;
841843
842− tok1 = S->tccpp_tok;
844+ tok1 = tok;
843845 /* XXX: support more options */
844− next(S);
846+ next();
845847 sname[0] = '\0';
846− while (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != ',') {
847− if (S->tccpp_tok == TOK_STR)
848− pstrcat(sname, sizeof(sname), S->tccpp_tokc.str.data);
848+ while (tok != ';' && tok != TOK_LINEFEED && tok != ',') {
849+ if (tok == TOK_STR)
850+ pstrcat(sname, sizeof(sname), tokc.str.data);
849851 else
850− pstrcat(sname, sizeof(sname), get_tok_str(S, S->tccpp_tok, NULL));
851− next(S);
852+ pstrcat(sname, sizeof(sname), get_tok_str(tok, NULL));
853+ next();
852854 }
853− if (S->tccpp_tok == ',') {
855+ if (tok == ',') {
854856 /* skip section options */
855− next(S);
856− if (S->tccpp_tok != TOK_STR)
857− expect(S, "string constant");
858− next(S);
859− if (S->tccpp_tok == ',') {
860− next(S);
861− if (S->tccpp_tok == '@' || S->tccpp_tok == '%')
862− next(S);
863− next(S);
857+ next();
858+ if (tok != TOK_STR)
859+ expect("string constant");
860+ next();
861+ if (tok == ',') {
862+ next();
863+ if (tok == '@' || tok == '%')
864+ next();
865+ next();
864866 }
865867 }
866− S->tccasm_last_text_section = cur_text_section;
868+ last_text_section = cur_text_section;
867869 if (tok1 == TOK_ASMDIR_section)
868− use_section(S, sname);
870+ use_section(s1, sname);
869871 else
870− push_section(S, sname);
872+ push_section(s1, sname);
871873 /* If we just allocated a new section reset its alignment to
872874 1. new_section normally acts for GCC compatibility and
873875 sets alignment to PTR_SIZE. The assembler behaves different. */
874− if (old_nb_section != S->nb_sections)
876+ if (old_nb_section != s1->nb_sections)
875877 cur_text_section->sh_addralign = 1;
876878 }
877879 break;
878880 case TOK_ASMDIR_previous:
879881 {
880882 Section *sec;
881− next(S);
882− if (!S->tccasm_last_text_section)
883− tcc_error(S, "no previous section referenced");
883+ next();
884+ if (!last_text_section)
885+ tcc_error("no previous section referenced");
884886 sec = cur_text_section;
885− use_section1(S, S->tccasm_last_text_section);
886− S->tccasm_last_text_section = sec;
887+ use_section1(s1, last_text_section);
888+ last_text_section = sec;
887889 }
888890 break;
889891 case TOK_ASMDIR_popsection:
890− next(S);
891− pop_section(S);
892+ next();
893+ pop_section(s1);
892894 break;
893895 #ifdef TCC_TARGET_I386
894896 case TOK_ASMDIR_code16:
895897 {
896− next(S);
897− S->seg_size = 16;
898+ next();
899+ s1->seg_size = 16;
898900 }
899901 break;
900902 case TOK_ASMDIR_code32:
901903 {
902− next(S);
903− S->seg_size = 32;
904+ next();
905+ s1->seg_size = 32;
904906 }
905907 break;
906908 #endif
907909 #ifdef TCC_TARGET_X86_64
908910 /* added for compatibility with GAS */
909911 case TOK_ASMDIR_code64:
910− next(S);
912+ next();
911913 break;
912914 #endif
913915 default:
914− tcc_error(S, "unknown assembler directive '.%s'", get_tok_str(S, S->tccpp_tok, NULL));
916+ tcc_error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
915917 break;
916918 }
917919 }
918920
919921
920922 /* assemble a file */
921−static int tcc_assemble_internal(TCCState *S, int do_preprocess, int global)
923+static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
922924 {
923925 int opcode;
924− int saved_parse_flags = S->tccpp_parse_flags;
926+ int saved_parse_flags = parse_flags;
925927
926− S->tccpp_parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
928+ parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
927929 if (do_preprocess)
928− S->tccpp_parse_flags |= PARSE_FLAG_PREPROCESS;
930+ parse_flags |= PARSE_FLAG_PREPROCESS;
929931 for(;;) {
930− next(S);
931− if (S->tccpp_tok == TOK_EOF)
932+ next();
933+ if (tok == TOK_EOF)
932934 break;
933− S->tccpp_parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
935+ parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
934936 redo:
935− if (S->tccpp_tok == '#') {
937+ if (tok == '#') {
936938 /* horrible gas comment */
937− while (S->tccpp_tok != TOK_LINEFEED)
938− next(S);
939− } else if (S->tccpp_tok >= TOK_ASMDIR_FIRST && S->tccpp_tok <= TOK_ASMDIR_LAST) {
940− asm_parse_directive(S, global);
941− } else if (S->tccpp_tok == TOK_PPNUM) {
939+ while (tok != TOK_LINEFEED)
940+ next();
941+ } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
942+ asm_parse_directive(s1, global);
943+ } else if (tok == TOK_PPNUM) {
942944 const char *p;
943945 int n;
944− p = S->tccpp_tokc.str.data;
946+ p = tokc.str.data;
945947 n = strtoul(p, (char **)&p, 10);
946948 if (*p != '\0')
947− expect(S, "':'");
949+ expect("':'");
948950 /* new local label */
949− asm_new_label(S, asm_get_local_label_name(S, n), 1);
950− next(S);
951− skip(S, ':');
951+ asm_new_label(s1, asm_get_local_label_name(s1, n), 1);
952+ next();
953+ skip(':');
952954 goto redo;
953− } else if (S->tccpp_tok >= TOK_IDENT) {
955+ } else if (tok >= TOK_IDENT) {
954956 /* instruction or label */
955− opcode = S->tccpp_tok;
956− next(S);
957− if (S->tccpp_tok == ':') {
957+ opcode = tok;
958+ next();
959+ if (tok == ':') {
958960 /* new label */
959− asm_new_label(S, opcode, 0);
960− next(S);
961+ asm_new_label(s1, opcode, 0);
962+ next();
961963 goto redo;
962− } else if (S->tccpp_tok == '=') {
963− set_symbol(S, opcode);
964+ } else if (tok == '=') {
965+ set_symbol(s1, opcode);
964966 goto redo;
965967 } else {
966− asm_opcode(S, opcode);
968+ asm_opcode(s1, opcode);
967969 }
968970 }
969971 /* end of line */
970− if (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED)
971− expect(S, "end of line");
972− S->tccpp_parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
972+ if (tok != ';' && tok != TOK_LINEFEED)
973+ expect("end of line");
974+ parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
973975 }
974976
975− S->tccpp_parse_flags = saved_parse_flags;
977+ parse_flags = saved_parse_flags;
976978 return 0;
977979 }
978980
979981 /* Assemble the current file */
980−ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess)
982+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
981983 {
982984 int ret;
983− tcc_debug_start(S);
985+ tcc_debug_start(s1);
984986 /* default section is text */
985987 cur_text_section = text_section;
986− S->tccgen_ind = cur_text_section->data_offset;
987− S->tccgen_nocode_wanted = 0;
988− ret = tcc_assemble_internal(S, do_preprocess, 1);
989− cur_text_section->data_offset = S->tccgen_ind;
990− tcc_debug_end(S);
988+ ind = cur_text_section->data_offset;
989+ nocode_wanted = 0;
990+ ret = tcc_assemble_internal(s1, do_preprocess, 1);
991+ cur_text_section->data_offset = ind;
992+ tcc_debug_end(s1);
991993 return ret;
992994 }
993995
@@ -997,27 +999,27 @@ ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess) · 3 unmodified lines
997999 /* assemble the string 'str' in the current C compilation unit without
9981000 C preprocessing. NOTE: str is modified by modifying the '\0' at the
9991001 end */
1000−static void tcc_assemble_inline(TCCState *S, char *str, int len, int global)
1002+static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
10011003 {
1002− const int *saved_macro_ptr = S->tccpp_macro_ptr;
1003− int dotid = set_idnum(S, '.', IS_ID);
1004− int dolid = set_idnum(S, '$', 0);
1005−
1006− tcc_open_bf(S, ":asm:", len);
1007− memcpy(S->tccpp_file->buffer, str, len);
1008− S->tccpp_macro_ptr = NULL;
1009− tcc_assemble_internal(S, 0, global);
1010− tcc_close(S);
1011−
1012− set_idnum(S, '$', dolid);
1013− set_idnum(S, '.', dotid);
1014− S->tccpp_macro_ptr = saved_macro_ptr;
1004+ const int *saved_macro_ptr = macro_ptr;
1005+ int dotid = set_idnum('.', IS_ID);
1006+ int dolid = set_idnum('$', 0);
1007+
1008+ tcc_open_bf(s1, ":asm:", len);
1009+ memcpy(file->buffer, str, len);
1010+ macro_ptr = NULL;
1011+ tcc_assemble_internal(s1, 0, global);
1012+ tcc_close();
1013+
1014+ set_idnum('$', dolid);
1015+ set_idnum('.', dotid);
1016+ macro_ptr = saved_macro_ptr;
10151017 }
10161018
10171019 /* find a constraint by its number or id (gcc 3 extended
10181020 syntax). return -1 if not found. Return in *pp in char after the
10191021 constraint */
1020−ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands,
1022+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands,
10211023 const char *name, const char **pp)
10221024 {
10231025 int index;
@@ -1036,7 +1038,7 @@ ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands, · 12 unmodified lines
10361038 name++;
10371039 p = strchr(name, ']');

339 more lines aren’t shown here.

tcccoff.c+58−58

This diff is large: its 368 lines aren’t shown here.

tccelf.c+675−672

This diff is large: its 3251 lines aren’t shown here.

tccgen.c+2728−2636

This diff is large: its 9788 lines aren’t shown here.

tccmacho.c+113−112

This diff is large: its 616 lines aren’t shown here.

tccpe.c+178−177

This diff is large: its 960 lines aren’t shown here.

tccpp.c+1108−1063

This diff is large: its 4250 lines aren’t shown here.

tccqsort.c+0−261

This diff is large: its 262 lines aren’t shown here.

tccrun.c+64−64

This diff is large: its 311 lines aren’t shown here.

tcctools.c+27−27

This diff is large: its 188 lines aren’t shown here.

x86_64-gen.c+680−667

This diff is large: its 2366 lines aren’t shown here.

x86_64-link.c+38−38

This diff is large: its 222 lines aren’t shown here.

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