summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormingodad <mingodad@gmail.com>2021-10-22 07:39:54 +0200
committermingodad <mingodad@gmail.com>2021-10-22 07:39:54 +0200
commit16456168430c9e185dd94b8215aa77d02bbb8a2c (patch)
treef7cb864d1f6f3ea2cbfd7b7cbbc82622f1683bd8
parent2ce2dbcb09b6c2455512ab9bd54a3be8b322c0e5 (diff)
Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"
This reverts commit af686a796bda94dc92fc3ad140ef438dafa08950.
-rw-r--r--arm-asm.c1112
-rw-r--r--arm-gen.c1133
-rw-r--r--arm-link.c64
-rw-r--r--arm64-asm.c26
-rw-r--r--arm64-gen.c1288
-rw-r--r--arm64-link.c64
-rw-r--r--c67-gen.c1516
-rw-r--r--c67-link.c14
-rw-r--r--i386-asm.c374
-rw-r--r--i386-gen.c733
-rw-r--r--i386-link.c68
-rw-r--r--libtcc.c863
-rw-r--r--libtcc.h93
-rw-r--r--riscv64-asm.c374
-rw-r--r--riscv64-gen.c908
-rw-r--r--riscv64-link.c60
-rw-r--r--tcc.c238
-rw-r--r--tcc.h757
-rw-r--r--tccasm.c838
-rw-r--r--tcccoff.c116
-rw-r--r--tccelf.c1347
-rw-r--r--tccgen.c5364
-rw-r--r--tccmacho.c225
-rw-r--r--tccpe.c355
-rw-r--r--tccpp.c2171
-rw-r--r--tccqsort.c261
-rw-r--r--tccrun.c128
-rw-r--r--tcctools.c54
-rw-r--r--x86_64-gen.c1347
-rw-r--r--x86_64-link.c76
30 files changed, 10750 insertions, 11217 deletions
diff --git a/arm-asm.c b/arm-asm.c
index 88a6d05..45ccab5 100644
--- a/arm-asm.c
+++ b/arm-asm.c
@@ -24,9 +24,9 @@
#define CONFIG_TCC_ASM
#define NB_ASM_REGS 16
-ST_FUNC void g(TCCState* S, int c);
-ST_FUNC void gen_le16(TCCState* S, int c);
-ST_FUNC void gen_le32(TCCState* S, int c);
+ST_FUNC void g(int c);
+ST_FUNC void gen_le16(int c);
+ST_FUNC void gen_le32(int c);
/*************************************************************/
#else
@@ -92,7 +92,7 @@ static int asm_parse_vfp_status_regvar(int t)
}
/* Parse a text containing operand and store the result in OP */
-static void parse_operand(TCCState *S, Operand *op)
+static void parse_operand(TCCState *s1, Operand *op)
{
ExprValue e;
int8_t reg;
@@ -100,54 +100,54 @@ static void parse_operand(TCCState *S, Operand *op)
op->type = 0;
- if (S->tccpp_tok == '{') { // regset literal
- next(S); // skip '{'
- while (S->tccpp_tok != '}' && S->tccpp_tok != TOK_EOF) {
- reg = asm_parse_regvar(S, S->tccpp_tok);
+ if (tok == '{') { // regset literal
+ next(); // skip '{'
+ while (tok != '}' && tok != TOK_EOF) {
+ reg = asm_parse_regvar(tok);
if (reg == -1) {
- expect(S, "register");
+ expect("register");
return;
} else
- next(S); // skip register name
+ next(); // skip register name
if ((1 << reg) < regset)
- tcc_warning(S, "registers will be processed in ascending order by hardware--but are not specified in ascending order here");
+ tcc_warning("registers will be processed in ascending order by hardware--but are not specified in ascending order here");
regset |= 1 << reg;
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S); // skip ','
+ next(); // skip ','
}
- if (S->tccpp_tok != '}')
- expect(S, "'}'");
- next(S); // skip '}'
+ if (tok != '}')
+ expect("'}'");
+ next(); // skip '}'
if (regset == 0) {
// ARM instructions don't support empty regset.
- tcc_error(S, "empty register list is not supported");
+ tcc_error("empty register list is not supported");
} else {
op->type = OP_REGSET32;
op->regset = regset;
}
return;
- } else if ((reg = asm_parse_regvar(S, S->tccpp_tok)) != -1) {
- next(S); // skip register name
+ } else if ((reg = asm_parse_regvar(tok)) != -1) {
+ next(); // skip register name
op->type = OP_REG32;
op->reg = (uint8_t) reg;
return;
- } else if ((reg = asm_parse_vfp_regvar(S->tccpp_tok, 0)) != -1) {
- next(S); // skip register name
+ } else if ((reg = asm_parse_vfp_regvar(tok, 0)) != -1) {
+ next(); // skip register name
op->type = OP_VREG32;
op->reg = (uint8_t) reg;
return;
- } else if ((reg = asm_parse_vfp_regvar(S->tccpp_tok, 1)) != -1) {
- next(S); // skip register name
+ } else if ((reg = asm_parse_vfp_regvar(tok, 1)) != -1) {
+ next(); // skip register name
op->type = OP_VREG64;
op->reg = (uint8_t) reg;
return;
- } else if (S->tccpp_tok == '#' || S->tccpp_tok == '$') {
+ } else if (tok == '#' || tok == '$') {
/* constant value */
- next(S); // skip '#' or '$'
+ next(); // skip '#' or '$'
}
- asm_expr(S, &e);
+ asm_expr(s1, &e);
op->type = OP_IM32;
op->e = e;
if (!op->e.sym) {
@@ -156,64 +156,64 @@ static void parse_operand(TCCState *S, Operand *op)
else if (op->e.v == (uint8_t)op->e.v)
op->type = OP_IM8;
} else
- expect(S, "operand");
+ expect("operand");
}
/* XXX: make it faster ? */
-ST_FUNC void g(TCCState* S, int c)
+ST_FUNC void g(int c)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 1;
+ ind1 = ind + 1;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind] = c;
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind] = c;
+ ind = ind1;
}
-ST_FUNC void gen_le16 (TCCState* S, int i)
+ST_FUNC void gen_le16 (int i)
{
- g(S, i);
- g(S, i>>8);
+ g(i);
+ g(i>>8);
}
-ST_FUNC void gen_le32 (TCCState* S, int i)
+ST_FUNC void gen_le32 (int i)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 4;
+ ind1 = ind + 4;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind++] = i & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 8) & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 16) & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 24) & 0xFF;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind++] = i & 0xFF;
+ cur_text_section->data[ind++] = (i >> 8) & 0xFF;
+ cur_text_section->data[ind++] = (i >> 16) & 0xFF;
+ cur_text_section->data[ind++] = (i >> 24) & 0xFF;
}
-ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
+ST_FUNC void gen_expr32(ExprValue *pe)
{
- gen_le32(S, pe->v);
+ gen_le32(pe->v);
}
-static uint32_t condition_code_of_token(TCCState* S, int token) {
+static uint32_t condition_code_of_token(int token) {
if (token < TOK_ASM_nopeq) {
- expect(S, "condition-enabled instruction");
+ expect("condition-enabled instruction");
return 0;
} else
return (token - TOK_ASM_nopeq) & 15;
}
-static void asm_emit_opcode(TCCState* S, int token, uint32_t opcode) {
- gen_le32(S, (condition_code_of_token(S, token) << 28) | opcode);
+static void asm_emit_opcode(int token, uint32_t opcode) {
+ gen_le32((condition_code_of_token(token) << 28) | opcode);
}
-static void asm_emit_unconditional_opcode(TCCState* S, uint32_t opcode) {
- gen_le32(S, opcode);
+static void asm_emit_unconditional_opcode(uint32_t opcode) {
+ gen_le32(opcode);
}
-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)
+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)
{
uint32_t opcode = 0xe000000;
if (inter_processor_transfer)
@@ -230,69 +230,69 @@ static void asm_emit_coprocessor_opcode(TCCState* S, uint32_t high_nibble, uint8
opcode |= cp_opcode2 << 5;
//assert(cp_m_operand_register < 16);
opcode |= cp_m_operand_register;
- asm_emit_unconditional_opcode(S, (high_nibble << 28) | opcode);
+ asm_emit_unconditional_opcode((high_nibble << 28) | opcode);
}
-static void asm_nullary_opcode(TCCState* S, int token)
+static void asm_nullary_opcode(int token)
{
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_nopeq:
- asm_emit_opcode(S, token, 0xd << 21); // mov r0, r0
+ asm_emit_opcode(token, 0xd << 21); // mov r0, r0
break;
case TOK_ASM_wfeeq:
- asm_emit_opcode(S, token, 0x320f002);
+ asm_emit_opcode(token, 0x320f002);
case TOK_ASM_wfieq:
- asm_emit_opcode(S, token, 0x320f003);
+ asm_emit_opcode(token, 0x320f003);
break;
default:
- expect(S, "nullary instruction");
+ expect("nullary instruction");
}
}
-static void asm_unary_opcode(TCCState *S, int token)
+static void asm_unary_opcode(TCCState *s1, int token)
{
Operand op;
- parse_operand(S, &op);
+ parse_operand(s1, &op);
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_swieq:
case TOK_ASM_svceq:
if (op.type != OP_IM8)
- expect(S, "immediate 8-bit unsigned integer");
+ expect("immediate 8-bit unsigned integer");
else {
/* Note: Dummy operand (ignored by processor): ARM ref documented 0...255, ARM instruction set documented 24 bit */
- asm_emit_opcode(S, token, (0xf << 24) | op.e.v);
+ asm_emit_opcode(token, (0xf << 24) | op.e.v);
}
break;
default:
- expect(S, "unary instruction");
+ expect("unary instruction");
}
}
-static void asm_binary_opcode(TCCState *S, int token)
+static void asm_binary_opcode(TCCState *s1, int token)
{
Operand ops[2];
Operand rotation;
uint32_t encoded_rotation = 0;
uint64_t amount;
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == ',')
- next(S);
+ parse_operand(s1, &ops[0]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
+ expect("','");
+ parse_operand(s1, &ops[1]);
if (ops[0].type != OP_REG32) {
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
return;
}
if (ops[0].reg == 15) {
- tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
return;
}
if (ops[0].reg == 13)
- tcc_warning(S, "Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(S, token, NULL));
+ tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL));
if (ops[1].type != OP_REG32) {
switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -303,38 +303,38 @@ static void asm_binary_opcode(TCCState *S, int token)
uint16_t immediate_value = ops[1].e.v;
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_movteq:
- asm_emit_opcode(S, token, 0x3400000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
+ asm_emit_opcode(token, 0x3400000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
break;
case TOK_ASM_movweq:
- asm_emit_opcode(S, token, 0x3000000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
+ asm_emit_opcode(token, 0x3000000 | (ops[0].reg << 12) | (immediate_value & 0xF000) << 4 | (immediate_value & 0xFFF));
break;
}
} else
- expect(S, "(source operand) immediate 16 bit value");
+ expect("(source operand) immediate 16 bit value");
} else
- expect(S, "(source operand) immediate");
+ expect("(source operand) immediate");
break;
default:
- expect(S, "(source operand) register");
+ expect("(source operand) register");
}
return;
}
if (ops[1].reg == 15) {
- tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
return;
}
if (ops[1].reg == 13)
- tcc_warning(S, "Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(S, token, NULL));
+ tcc_warning("Using 'sp' as operand with '%s' is deprecated by ARM", get_tok_str(token, NULL));
- if (S->tccpp_tok == ',') {
- next(S); // skip ','
- if (S->tccpp_tok == TOK_ASM_ror) {
- next(S); // skip 'ror'
- parse_operand(S, &rotation);
+ if (tok == ',') {
+ next(); // skip ','
+ if (tok == TOK_ASM_ror) {
+ next(); // skip 'ror'
+ parse_operand(s1, &rotation);
if (rotation.type != OP_IM8) {
- expect(S, "immediate value for rotation");
+ expect("immediate value for rotation");
return;
} else {
amount = rotation.e.v;
@@ -349,7 +349,7 @@ static void asm_binary_opcode(TCCState *S, int token)
encoded_rotation = 3 << 10;
break;
default:
- expect(S, "'8' or '16' or '24'");
+ expect("'8' or '16' or '24'");
return;
}
}
@@ -358,27 +358,27 @@ static void asm_binary_opcode(TCCState *S, int token)
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_clzeq:
if (encoded_rotation)
- tcc_error(S, "clz does not support rotation");
- asm_emit_opcode(S, token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg);
+ tcc_error("clz does not support rotation");
+ asm_emit_opcode(token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg);
break;
case TOK_ASM_sxtbeq:
- asm_emit_opcode(S, token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
+ asm_emit_opcode(token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
break;
case TOK_ASM_sxtheq:
- asm_emit_opcode(S, token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
+ asm_emit_opcode(token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
break;
case TOK_ASM_uxtbeq:
- asm_emit_opcode(S, token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
+ asm_emit_opcode(token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
break;
case TOK_ASM_uxtheq:
- asm_emit_opcode(S, token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
+ asm_emit_opcode(token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg | encoded_rotation);
break;
default:
- expect(S, "binary instruction");
+ expect("binary instruction");
}
}
-static void asm_coprocessor_opcode(TCCState *S, int token) {
+static void asm_coprocessor_opcode(TCCState *s1, int token) {
uint8_t coprocessor;
Operand opcode1;
Operand opcode2;
@@ -387,70 +387,70 @@ static void asm_coprocessor_opcode(TCCState *S, int token) {
uint8_t high_nibble;
uint8_t mrc = 0;
- if (S->tccpp_tok >= TOK_ASM_p0 && S->tccpp_tok <= TOK_ASM_p15) {
- coprocessor = S->tccpp_tok - TOK_ASM_p0;
- next(S);
+ if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) {
+ coprocessor = tok - TOK_ASM_p0;
+ next();
} else {
- expect(S, "'p<number>'");
+ expect("'p<number>'");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
+ expect("','");
- parse_operand(S, &opcode1);
+ parse_operand(s1, &opcode1);
if (opcode1.type != OP_IM8 || opcode1.e.v > 15) {
- tcc_error(S, "opcode1 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(S, token, NULL));
+ tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL));
return;
}
for (i = 0; i < 3; ++i) {
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
+ expect("','");
if (i == 0 && token != TOK_ASM_cdp2 && (ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mrceq || ARM_INSTRUCTION_GROUP(token) == TOK_ASM_mcreq)) {
- if (S->tccpp_tok >= TOK_ASM_r0 && S->tccpp_tok <= TOK_ASM_r15) {
- registers[i] = S->tccpp_tok - TOK_ASM_r0;
- next(S);
+ if (tok >= TOK_ASM_r0 && tok <= TOK_ASM_r15) {
+ registers[i] = tok - TOK_ASM_r0;
+ next();
} else {
- expect(S, "'r<number>'");
+ expect("'r<number>'");
return;
}
} else {
- if (S->tccpp_tok >= TOK_ASM_c0 && S->tccpp_tok <= TOK_ASM_c15) {
- registers[i] = S->tccpp_tok - TOK_ASM_c0;
- next(S);
+ if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) {
+ registers[i] = tok - TOK_ASM_c0;
+ next();
} else {
- expect(S, "'c<number>'");
+ expect("'c<number>'");
return;
}
}
}
- if (S->tccpp_tok == ',') {
- next(S);
- parse_operand(S, &opcode2);
+ if (tok == ',') {
+ next();
+ parse_operand(s1, &opcode2);
} else {
opcode2.type = OP_IM8;
opcode2.e.v = 0;
}
if (opcode2.type != OP_IM8 || opcode2.e.v > 15) {
- tcc_error(S, "opcode2 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(S, token, NULL));
+ tcc_error("opcode2 of instruction '%s' must be an immediate value between 0 and 15", get_tok_str(token, NULL));
return;
}
if (token == TOK_ASM_cdp2) {
high_nibble = 0xF;
- asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
return;
} else
- high_nibble = condition_code_of_token(S, token);
+ high_nibble = condition_code_of_token(token);
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_cdpeq:
- asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, opcode1.e.v, registers[0], registers[1], registers[2], opcode2.e.v, 0);
break;
case TOK_ASM_mrceq:
// opcode1 encoding changes! highest and lowest bit gone.
@@ -459,13 +459,13 @@ static void asm_coprocessor_opcode(TCCState *S, int token) {
case TOK_ASM_mcreq:
// opcode1 encoding changes! highest and lowest bit gone.
if (opcode1.e.v > 7) {
- tcc_error(S, "opcode1 of instruction '%s' must be an immediate value between 0 and 7", get_tok_str(S, token, NULL));
+ tcc_error("opcode1 of instruction '%s' must be an immediate value between 0 and 7", get_tok_str(token, NULL));
return;
}
- asm_emit_coprocessor_opcode(S, high_nibble, coprocessor, (opcode1.e.v << 1) | mrc, registers[0], registers[1], registers[2], opcode2.e.v, 1);
+ asm_emit_coprocessor_opcode(high_nibble, coprocessor, (opcode1.e.v << 1) | mrc, registers[0], registers[1], registers[2], opcode2.e.v, 1);
break;
default:
- expect(S, "known instruction");
+ expect("known instruction");
}
}
@@ -486,27 +486,27 @@ static void asm_coprocessor_opcode(TCCState *S, int token) {
#define ENCODE_BARREL_SHIFTER_REGISTER(register_index) ((register_index) << 8)
#define ENCODE_BARREL_SHIFTER_IMMEDIATE(value) ((value) << 7)
-static void asm_block_data_transfer_opcode(TCCState *S, int token)
+static void asm_block_data_transfer_opcode(TCCState *s1, int token)
{
uint32_t opcode;
int op0_exclam = 0;
Operand ops[2];
int nb_ops = 1;
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == '!') {
+ parse_operand(s1, &ops[0]);
+ if (tok == '!') {
op0_exclam = 1;
- next(S); // skip '!'
+ next(); // skip '!'
}
- if (S->tccpp_tok == ',') {
- next(S); // skip comma
- parse_operand(S, &ops[1]);
+ if (tok == ',') {
+ next(); // skip comma
+ parse_operand(s1, &ops[1]);
++nb_ops;
}
if (nb_ops < 1) {
- expect(S, "at least one operand");
+ expect("at least one operand");
return;
} else if (ops[nb_ops - 1].type != OP_REGSET32) {
- expect(S, "(last operand) register list");
+ expect("(last operand) register list");
return;
}
@@ -522,9 +522,9 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token)
// Rn: base register
// Register List: bits 15...0
if (nb_ops != 1)
- expect(S, "exactly one operand");
+ expect("exactly one operand");
else
- asm_emit_opcode(S, token, (0x92d << 16) | ops[0].regset); // TODO: base register ?
+ asm_emit_opcode(token, (0x92d << 16) | ops[0].regset); // TODO: base register ?
break;
case TOK_ASM_popeq: // TODO: Optimize 1-register case to: ldr ?, [sp], #4
// 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)
// Rn: base register
// Register List: bits 15...0
if (nb_ops != 1)
- expect(S, "exactly one operand");
+ expect("exactly one operand");
else
- asm_emit_opcode(S, token, (0x8bd << 16) | ops[0].regset); // TODO: base register ?
+ asm_emit_opcode(token, (0x8bd << 16) | ops[0].regset); // TODO: base register ?
break;
case TOK_ASM_stmdaeq:
case TOK_ASM_ldmdaeq:
@@ -574,23 +574,23 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token)
opcode = 0x99 << 20;
break;
default:
- tcc_error(S, "internal error: This place should not be reached (fallback in asm_block_data_transfer_opcode)");
+ tcc_error("internal error: This place should not be reached (fallback in asm_block_data_transfer_opcode)");
}
// operands:
// Rn: first operand
// Register List: lower bits
if (nb_ops != 2)
- expect(S, "exactly two operands");
+ expect("exactly two operands");
else if (ops[0].type != OP_REG32)
- expect(S, "(first operand) register");
+ expect("(first operand) register");
else {
if (op0_exclam)
opcode |= 1 << 21; // writeback
- asm_emit_opcode(S, token, opcode | ENCODE_RN(ops[0].reg) | ops[1].regset);
+ asm_emit_opcode(token, opcode | ENCODE_RN(ops[0].reg) | ops[1].regset);
}
break;
default:
- expect(S, "block data transfer instruction");
+ expect("block data transfer instruction");
}
}
@@ -600,17 +600,17 @@ static void asm_block_data_transfer_opcode(TCCState *S, int token)
NB_SHIFT: will be set to 1 iff SHIFT is filled. Note that for rrx, there's no need to fill SHIFT.
SHIFT: will be filled in with the shift operand to use, if any. */
-static uint32_t asm_parse_optional_shift(TCCState* S, int* nb_shift, Operand* shift)
+static uint32_t asm_parse_optional_shift(TCCState* s1, int* nb_shift, Operand* shift)
{
uint32_t opcode = 0;
*nb_shift = 0;
- switch (S->tccpp_tok) {
+ switch (tok) {
case TOK_ASM_asl:
case TOK_ASM_lsl:
case TOK_ASM_asr:
case TOK_ASM_lsr:
case TOK_ASM_ror:
- switch (S->tccpp_tok) {
+ switch (tok) {
case TOK_ASM_asl:
/* fallthrough */
case TOK_ASM_lsl:
@@ -626,26 +626,26 @@ static uint32_t asm_parse_optional_shift(TCCState* S, int* nb_shift, Operand* sh
opcode = ENCODE_BARREL_SHIFTER_MODE_ROR;
break;
}
- next(S);
- parse_operand(S, shift);
+ next();
+ parse_operand(s1, shift);
*nb_shift = 1;
break;
case TOK_ASM_rrx:
- next(S);
+ next();
opcode = ENCODE_BARREL_SHIFTER_MODE_ROR;
break;
}
return opcode;
}
-static uint32_t asm_encode_shift(TCCState *S, Operand* shift)
+static uint32_t asm_encode_shift(Operand* shift)
{
uint64_t amount;
uint32_t operands = 0;
switch (shift->type) {
case OP_REG32:
if (shift->reg == 15)
- tcc_error(S, "r15 cannot be used as a shift count");
+ tcc_error("r15 cannot be used as a shift count");
else {
operands = ENCODE_BARREL_SHIFTER_SHIFT_BY_REGISTER;
operands |= ENCODE_BARREL_SHIFTER_REGISTER(shift->reg);
@@ -656,15 +656,15 @@ static uint32_t asm_encode_shift(TCCState *S, Operand* shift)
if (amount > 0 && amount < 32)
operands = ENCODE_BARREL_SHIFTER_IMMEDIATE(amount);
else
- tcc_error(S, "shift count out of range");
+ tcc_error("shift count out of range");
break;
default:
- tcc_error(S, "unknown shift amount");
+ tcc_error("unknown shift amount");
}
return operands;
}
-static void asm_data_processing_opcode(TCCState *S, int token)
+static void asm_data_processing_opcode(TCCState *s1, int token)
{
Operand ops[3];
int nb_ops;
@@ -677,31 +677,31 @@ static void asm_data_processing_opcode(TCCState *S, int token)
uint32_t opcode_nos = opcode_idx >> 1; // without "s"; "OpCode" in ARM docs
for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ) {
- 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)
+ 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)
break;
- parse_operand(S, &ops[nb_ops]);
+ parse_operand(s1, &ops[nb_ops]);
++nb_ops;
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S); // skip ','
+ next(); // skip ','
}
- if (S->tccpp_tok == ',')
- next(S);
- operands |= asm_parse_optional_shift(S, &nb_shift, &shift);
+ if (tok == ',')
+ next();
+ operands |= asm_parse_optional_shift(s1, &nb_shift, &shift);
if (nb_ops < 2)
- expect(S, "at least two operands");
+ expect("at least two operands");
else if (nb_ops == 2) {
memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2]
memcpy(&ops[1], &ops[0], sizeof(ops[0])); // ops[1] was implicit
nb_ops = 3;
} else if (nb_ops == 3) {
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
- tcc_error(S, "'%s' cannot be used with three operands", get_tok_str(S, token, NULL));
+ tcc_error("'%s' cannot be used with three operands", get_tok_str(token, NULL));
return;
}
}
if (nb_ops != 3) {
- expect(S, "two or three operands");
+ expect("two or three operands");
return;
} else {
uint32_t opcode = 0;
@@ -710,7 +710,7 @@ static void asm_data_processing_opcode(TCCState *S, int token)
if (nb_shift && shift.type == OP_REG32) {
if ((ops[0].type == OP_REG32 && ops[0].reg == 15) ||
(ops[1].type == OP_REG32 && ops[1].reg == 15)) {
- tcc_error(S, "Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
+ tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
return;
}
}
@@ -726,13 +726,13 @@ static void asm_data_processing_opcode(TCCState *S, int token)
/* operations in the token list are ordered by opcode */
opcode = opcode_nos << 21; // drop "s"
if (ops[0].type != OP_REG32)
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
else if (opcode_nos == 0xa || opcode_nos == 0xb || opcode_nos == 0x8 || opcode_nos == 0x9) // cmp, cmn, tst, teq
operands |= ENCODE_SET_CONDITION_CODES; // force S set, otherwise it's a completely different instruction.
else
operands |= ENCODE_RD(ops[0].reg);
if (ops[1].type != OP_REG32)
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
else if (!(opcode_nos == 0xd || opcode_nos == 0xf)) // not: mov, mvn (those have only one source operand)
operands |= ENCODE_RN(ops[1].reg);
switch (ops[2].type) {
@@ -809,7 +809,7 @@ static void asm_data_processing_opcode(TCCState *S, int token)
immediate_value = ~immediate_value;
break;
default:
- tcc_error(S, "cannot use '%s' with a negative immediate value", get_tok_str(S, token, NULL));
+ tcc_error("cannot use '%s' with a negative immediate value", get_tok_str(token, NULL));
}
for (half_immediate_rotation = 0; half_immediate_rotation < 16; ++half_immediate_rotation) {
if (immediate_value >= 0x00 && immediate_value < 0x100)
@@ -819,30 +819,30 @@ static void asm_data_processing_opcode(TCCState *S, int token)
}
if (half_immediate_rotation >= 16) {
immediate_value = ops[2].e.v;
- tcc_error(S, "immediate value 0x%X cannot be encoded into ARM immediate", (unsigned) immediate_value);
+ tcc_error("immediate value 0x%X cannot be encoded into ARM immediate", (unsigned) immediate_value);
return;
}
operands |= immediate_value;
operands |= half_immediate_rotation << 8;
break;
default:
- expect(S, "(second source operand) register or immediate value");
+ expect("(second source operand) register or immediate value");
}
if (nb_shift) {
if (operands & ENCODE_IMMEDIATE_FLAG)
- tcc_error(S, "immediate rotation not implemented");
+ tcc_error("immediate rotation not implemented");
else
- operands |= asm_encode_shift(S, &shift);
+ operands |= asm_encode_shift(&shift);
}
/* S=0 and S=1 entries alternate one after another, in that order */
opcode |= (opcode_idx & 1) ? ENCODE_SET_CONDITION_CODES : 0;
- asm_emit_opcode(S, token, opcode | operands);
+ asm_emit_opcode(token, opcode | operands);
}
}
-static void asm_shift_opcode(TCCState *S, int token)
+static void asm_shift_opcode(TCCState *s1, int token)
{
Operand ops[3];
int nb_ops;
@@ -851,20 +851,20 @@ static void asm_shift_opcode(TCCState *S, int token)
uint32_t operands = 0;
for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
- parse_operand(S, &ops[nb_ops]);
- if (S->tccpp_tok != ',') {
+ parse_operand(s1, &ops[nb_ops]);
+ if (tok != ',') {
++nb_ops;
break;
}
- next(S); // skip ','
+ next(); // skip ','
}
if (nb_ops < 2) {
- expect(S, "at least two operands");
+ expect("at least two operands");
return;
}
if (ops[0].type != OP_REG32) {
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
return;
} else
operands |= ENCODE_RD(ops[0].reg);
@@ -878,9 +878,9 @@ static void asm_shift_opcode(TCCState *S, int token)
if (ops[1].type == OP_REG32) {
operands |= ops[1].reg;
operands |= ENCODE_BARREL_SHIFTER_MODE_ROR;
- asm_emit_opcode(S, token, opcode | operands);
+ asm_emit_opcode(token, opcode | operands);
} else
- tcc_error(S, "(first source operand) register");
+ tcc_error("(first source operand) register");
return;
default:
memcpy(&ops[2], &ops[1], sizeof(ops[1])); // move ops[2]
@@ -889,7 +889,7 @@ static void asm_shift_opcode(TCCState *S, int token)
}
}
if (nb_ops != 3) {
- expect(S, "two or three operands");
+ expect("two or three operands");
return;
}
@@ -909,7 +909,7 @@ static void asm_shift_opcode(TCCState *S, int token)
case OP_IM8:
operands |= ENCODE_IMMEDIATE_FLAG;
operands |= ops[1].e.v;
- 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));
+ tcc_error("Using an immediate value as the source operand is not possible with '%s' instruction on ARM", get_tok_str(token, NULL));
return;
}
@@ -917,13 +917,13 @@ static void asm_shift_opcode(TCCState *S, int token)
case OP_REG32:
if ((ops[0].type == OP_REG32 && ops[0].reg == 15) ||
(ops[1].type == OP_REG32 && ops[1].reg == 15)) {
- tcc_error(S, "Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
+ tcc_error("Using the 'pc' register in data processing instructions that have a register-controlled shift is not implemented by ARM");
}
- operands |= asm_encode_shift(S, &ops[2]);
+ operands |= asm_encode_shift(&ops[2]);
break;
case OP_IM8:
if (ops[2].e.v)
- operands |= asm_encode_shift(S, &ops[2]);
+ operands |= asm_encode_shift(&ops[2]);
else
definitely_neutral = 1;
break;
@@ -947,28 +947,28 @@ static void asm_shift_opcode(TCCState *S, int token)
operands |= ENCODE_BARREL_SHIFTER_MODE_ROR;
break;
default:
- expect(S, "shift instruction");
+ expect("shift instruction");
return;
}
- asm_emit_opcode(S, token, opcode | operands);
+ asm_emit_opcode(token, opcode | operands);
}
-static void asm_multiplication_opcode(TCCState *S, int token)
+static void asm_multiplication_opcode(TCCState *s1, int token)
{
Operand ops[4];
int nb_ops = 0;
uint32_t opcode = 0x90;
for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
- parse_operand(S, &ops[nb_ops]);
- if (S->tccpp_tok != ',') {
+ parse_operand(s1, &ops[nb_ops]);
+ if (tok != ',') {
++nb_ops;
break;
}
- next(S); // skip ','
+ next(); // skip ','
}
if (nb_ops < 2)
- expect(S, "at least two operands");
+ expect("at least two operands");
else if (nb_ops == 2) {
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_mulseq:
@@ -976,7 +976,7 @@ static void asm_multiplication_opcode(TCCState *S, int token)
memcpy(&ops[2], &ops[0], sizeof(ops[1])); // ARM is actually like this!
break;
default:
- expect(S, "at least three operands");
+ expect("at least three operands");
return;
}
nb_ops = 3;
@@ -992,20 +992,20 @@ static void asm_multiplication_opcode(TCCState *S, int token)
if (ops[0].type == OP_REG32)
opcode |= ops[0].reg << 16;
else
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
if (ops[1].type == OP_REG32)
opcode |= ops[1].reg;
else
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
if (ops[2].type == OP_REG32)
opcode |= ops[2].reg << 8;
else
- expect(S, "(second source operand) register");
+ expect("(second source operand) register");
if (nb_ops > 3) {
if (ops[3].type == OP_REG32)
opcode |= ops[3].reg << 12;
else
- expect(S, "(third source operand) register");
+ expect("(third source operand) register");
}
switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1014,9 +1014,9 @@ static void asm_multiplication_opcode(TCCState *S, int token)
/* fallthrough */
case TOK_ASM_muleq:
if (nb_ops != 3)
- expect(S, "three operands");
+ expect("three operands");
else {
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
}
break;
case TOK_ASM_mlaseq:
@@ -1024,33 +1024,33 @@ static void asm_multiplication_opcode(TCCState *S, int token)
/* fallthrough */
case TOK_ASM_mlaeq:
if (nb_ops != 4)
- expect(S, "four operands");
+ expect("four operands");
else {
opcode |= 1 << 21; // Accumulate
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
}
break;
default:
- expect(S, "known multiplication instruction");
+ expect("known multiplication instruction");
}
}
-static void asm_long_multiplication_opcode(TCCState *S, int token)
+static void asm_long_multiplication_opcode(TCCState *s1, int token)
{
Operand ops[4];
int nb_ops = 0;
uint32_t opcode = 0x90 | (1 << 23);
for (nb_ops = 0; nb_ops < sizeof(ops)/sizeof(ops[0]); ++nb_ops) {
- parse_operand(S, &ops[nb_ops]);
- if (S->tccpp_tok != ',') {
+ parse_operand(s1, &ops[nb_ops]);
+ if (tok != ',') {
++nb_ops;
break;
}
- next(S); // skip ','
+ next(); // skip ','
}
if (nb_ops != 4) {
- expect(S, "four operands");
+ expect("four operands");
return;
}
@@ -1064,19 +1064,19 @@ static void asm_long_multiplication_opcode(TCCState *S, int token)
if (ops[0].type == OP_REG32)
opcode |= ops[0].reg << 12;
else
- expect(S, "(destination lo accumulator) register");
+ expect("(destination lo accumulator) register");
if (ops[1].type == OP_REG32)
opcode |= ops[1].reg << 16;
else
- expect(S, "(destination hi accumulator) register");
+ expect("(destination hi accumulator) register");
if (ops[2].type == OP_REG32)
opcode |= ops[2].reg;
else
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
if (ops[3].type == OP_REG32)
opcode |= ops[3].reg << 8;
else
- expect(S, "(second source operand) register");
+ expect("(second source operand) register");
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_smullseq:
@@ -1084,13 +1084,13 @@ static void asm_long_multiplication_opcode(TCCState *S, int token)
/* fallthrough */
case TOK_ASM_smulleq:
opcode |= 1 << 22; // signed
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_umullseq:
opcode |= 1 << 20; // Status
/* fallthrough */
case TOK_ASM_umulleq:
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_smlalseq:
opcode |= 1 << 20; // Status
@@ -1098,21 +1098,21 @@ static void asm_long_multiplication_opcode(TCCState *S, int token)
case TOK_ASM_smlaleq:
opcode |= 1 << 22; // signed
opcode |= 1 << 21; // Accumulate
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_umlalseq:
opcode |= 1 << 20; // Status
/* fallthrough */
case TOK_ASM_umlaleq:
opcode |= 1 << 21; // Accumulate
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
default:
- expect(S, "known long multiplication instruction");
+ expect("known long multiplication instruction");
}
}
-static void asm_single_data_transfer_opcode(TCCState *S, int token)
+static void asm_single_data_transfer_opcode(TCCState *s1, int token)
{
Operand ops[3];
Operand strex_operand;
@@ -1126,67 +1126,67 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
// Note: ldr r0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
// Note: ldr r0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
if (ops[0].type == OP_REG32)
opcode |= ENCODE_RD(ops[0].reg);
else {
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
return;
}
- if (S->tccpp_tok != ',')
- expect(S, "at least two arguments");
+ if (tok != ',')
+ expect("at least two arguments");
else
- next(S); // skip ','
+ next(); // skip ','
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_strexbeq:
case TOK_ASM_strexeq:
- parse_operand(S, &strex_operand);
+ parse_operand(s1, &strex_operand);
if (strex_operand.type != OP_REG32) {
- expect(S, "register");
+ expect("register");
return;
}
- if (S->tccpp_tok != ',')
- expect(S, "at least three arguments");
+ if (tok != ',')
+ expect("at least three arguments");
else
- next(S); // skip ','
+ next(); // skip ','
break;
}
- if (S->tccpp_tok != '[')
- expect(S, "'['");
+ if (tok != '[')
+ expect("'['");
else
- next(S); // skip '['
+ next(); // skip '['
- parse_operand(S, &ops[1]);
+ parse_operand(s1, &ops[1]);
if (ops[1].type == OP_REG32)
opcode |= ENCODE_RN(ops[1].reg);
else {
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
return;
}
- if (S->tccpp_tok == ']') {
- next(S);
+ if (tok == ']') {
+ next();
closed_bracket = 1;
// exclam = 1; // implicit in hardware; don't do it in software
}
- if (S->tccpp_tok == ',') {
- next(S); // skip ','
- if (S->tccpp_tok == '-') {
+ if (tok == ',') {
+ next(); // skip ','
+ if (tok == '-') {
op2_minus = 1;
- next(S);
+ next();
}
- parse_operand(S, &ops[2]);
+ parse_operand(s1, &ops[2]);
if (ops[2].type == OP_REG32) {
if (ops[2].reg == 15) {
- tcc_error(S, "Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(S, token, NULL));
+ tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL));
return;
}
- if (S->tccpp_tok == ',') {
- next(S);
- opcode |= asm_parse_optional_shift(S, &nb_shift, &shift);
+ if (tok == ',') {
+ next();
+ opcode |= asm_parse_optional_shift(s1, &nb_shift, &shift);
if (opcode == 0)
- expect(S, "shift directive, or no comma");
+ expect("shift directive, or no comma");
}
}
} else {
@@ -1196,14 +1196,14 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
opcode |= 1 << 24; // add offset before transfer
}
if (!closed_bracket) {
- if (S->tccpp_tok != ']')
- expect(S, "']'");
+ if (tok != ']')
+ expect("']'");
else
- next(S); // skip ']'
+ next(); // skip ']'
opcode |= 1 << 24; // add offset before transfer
- if (S->tccpp_tok == '!') {
+ if (tok == '!') {
exclam = 1;
- next(S); // skip '!'
+ next(); // skip '!'
}
}
@@ -1224,16 +1224,16 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) {
int v = ops[2].e.v;
if (op2_minus)
- tcc_error(S, "minus before '#' not supported for immediate values");
+ tcc_error("minus before '#' not supported for immediate values");
if (v >= 0) {
opcode |= 1 << 23; // up
if (v >= 0x1000)
- tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
else
opcode |= v;
} else { // down
if (v <= -0x1000)
- tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
else
opcode |= -v;
}
@@ -1243,7 +1243,7 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */
opcode |= ops[2].reg;
} else
- expect(S, "register");
+ expect("register");
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_strbeq:
@@ -1252,8 +1252,8 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
case TOK_ASM_streq:
opcode |= 1 << 26; // Load/Store
if (nb_shift)
- opcode |= asm_encode_shift(S, &shift);
- asm_emit_opcode(S, token, opcode);
+ opcode |= asm_encode_shift(&shift);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_ldrbeq:
opcode |= 1 << 22; // B
@@ -1262,56 +1262,56 @@ static void asm_single_data_transfer_opcode(TCCState *S, int token)
opcode |= 1 << 20; // L
opcode |= 1 << 26; // Load/Store
if (nb_shift)
- opcode |= asm_encode_shift(S, &shift);
- asm_emit_opcode(S, token, opcode);
+ opcode |= asm_encode_shift(&shift);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_strexbeq:
opcode |= 1 << 22; // B
/* fallthrough */
case TOK_ASM_strexeq:
if ((opcode & 0xFFF) || nb_shift) {
- tcc_error(S, "neither offset nor shift allowed with 'strex'");
+ tcc_error("neither offset nor shift allowed with 'strex'");
return;
} else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate
- tcc_error(S, "offset not allowed with 'strex'");
+ tcc_error("offset not allowed with 'strex'");
return;
}
if ((opcode & (1 << 24)) == 0) { // add offset after transfer
- tcc_error(S, "adding offset after transfer not allowed with 'strex'");
+ tcc_error("adding offset after transfer not allowed with 'strex'");
return;
}
opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL
opcode |= strex_operand.reg;
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_ldrexbeq:
opcode |= 1 << 22; // B
/* fallthrough */
case TOK_ASM_ldrexeq:
if ((opcode & 0xFFF) || nb_shift) {
- tcc_error(S, "neither offset nor shift allowed with 'ldrex'");
+ tcc_error("neither offset nor shift allowed with 'ldrex'");
return;
} else if (opcode & ENCODE_IMMEDIATE_FLAG) { // if set, it means it's NOT immediate
- tcc_error(S, "offset not allowed with 'ldrex'");
+ tcc_error("offset not allowed with 'ldrex'");
return;
}
if ((opcode & (1 << 24)) == 0) { // add offset after transfer
- tcc_error(S, "adding offset after transfer not allowed with 'ldrex'");
+ tcc_error("adding offset after transfer not allowed with 'ldrex'");
return;
}
opcode |= 1 << 20; // L
opcode |= 0x00f;
opcode |= 0xf90; // Used to mean: barrel shifter is enabled, barrel shift register is r15, mode is LSL
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
default:
- expect(S, "data transfer instruction");
+ expect("data transfer instruction");
}
}
// 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)
-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) {
+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) {
uint32_t opcode = 0x0;
opcode |= 1 << 26; // Load/Store
opcode |= 1 << 27; // coprocessor
@@ -1328,7 +1328,7 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble
opcode |= ENCODE_RD(CRd);
if (Rn->type != OP_REG32) {
- expect(S, "register");
+ expect("register");
return;
}
//assert(Rn->reg < 16);
@@ -1342,18 +1342,18 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble
if (offset->type == OP_IM8 || offset->type == OP_IM8N || offset->type == OP_IM32) {
int v = offset->e.v;
if (offset_minus)
- tcc_error(S, "minus before '#' not supported for immediate values");
+ tcc_error("minus before '#' not supported for immediate values");
if (offset->type == OP_IM8N || v < 0)
v = -v;
else
opcode |= 1 << 23; // up
if (v & 3) {
- tcc_error(S, "immediate offset must be a multiple of 4");
+ tcc_error("immediate offset must be a multiple of 4");
return;
}
v >>= 2;
if (v > 255) {
- tcc_error(S, "immediate offset must be between -1020 and 1020");
+ tcc_error("immediate offset must be between -1020 and 1020");
return;
}
opcode |= v;
@@ -1362,20 +1362,20 @@ static void asm_emit_coprocessor_data_transfer(TCCState *S, uint32_t high_nibble
opcode |= 1 << 23; // up
opcode |= ENCODE_IMMEDIATE_FLAG; /* if set, it means it's NOT immediate */
opcode |= offset->reg;
- tcc_error(S, "Using register offset to register address is not possible here");
+ tcc_error("Using register offset to register address is not possible here");
return;
} else if (offset->type == OP_VREG64) {
opcode |= 16;
opcode |= offset->reg;
} else
- expect(S, "immediate or register");
+ expect("immediate or register");
- asm_emit_unconditional_opcode(S, (high_nibble << 28) | opcode);
+ asm_emit_unconditional_opcode((high_nibble << 28) | opcode);
}
// Almost exactly the same as asm_single_data_transfer_opcode.
// Difference: Offsets are smaller and multiples of 4; no shifts, no STREX, ENCODE_IMMEDIATE_FLAG is inverted again.
-static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
+static void asm_coprocessor_data_transfer_opcode(TCCState *s1, int token)
{
Operand ops[3];
uint8_t coprocessor;
@@ -1389,61 +1389,61 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
// Note: ldc p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
// Note: ldc p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
- if (S->tccpp_tok >= TOK_ASM_p0 && S->tccpp_tok <= TOK_ASM_p15) {
- coprocessor = S->tccpp_tok - TOK_ASM_p0;
- next(S);
+ if (tok >= TOK_ASM_p0 && tok <= TOK_ASM_p15) {
+ coprocessor = tok - TOK_ASM_p0;
+ next();
} else {
- expect(S, "'c<number>'");
+ expect("'c<number>'");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
+ expect("','");
- if (S->tccpp_tok >= TOK_ASM_c0 && S->tccpp_tok <= TOK_ASM_c15) {
- coprocessor_destination_register = S->tccpp_tok - TOK_ASM_c0;
- next(S);
+ if (tok >= TOK_ASM_c0 && tok <= TOK_ASM_c15) {
+ coprocessor_destination_register = tok - TOK_ASM_c0;
+ next();
} else {
- expect(S, "'c<number>'");
+ expect("'c<number>'");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
+ expect("','");
- if (S->tccpp_tok != '[')
- expect(S, "'['");
+ if (tok != '[')
+ expect("'['");
else
- next(S); // skip '['
+ next(); // skip '['
- parse_operand(S, &ops[1]);
+ parse_operand(s1, &ops[1]);
if (ops[1].type != OP_REG32) {
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
return;
}
- if (S->tccpp_tok == ']') {
- next(S);
+ if (tok == ']') {
+ next();
closed_bracket = 1;
// exclam = 1; // implicit in hardware; don't do it in software
}
- if (S->tccpp_tok == ',') {
- next(S); // skip ','
- if (S->tccpp_tok == '-') {
+ if (tok == ',') {
+ next(); // skip ','
+ if (tok == '-') {
op2_minus = 1;
- next(S);
+ next();
}
- parse_operand(S, &ops[2]);
+ parse_operand(s1, &ops[2]);
if (ops[2].type == OP_REG32) {
if (ops[2].reg == 15) {
- tcc_error(S, "Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(S, token, NULL));
+ tcc_error("Using 'pc' for register offset in '%s' is not implemented by ARM", get_tok_str(token, NULL));
return;
}
} else if (ops[2].type == OP_VREG64) {
- tcc_error(S, "'%s' does not support VFP register operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support VFP register operand", get_tok_str(token, NULL));
return;
}
} else {
@@ -1453,14 +1453,14 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
preincrement = 1; // add offset before transfer
}
if (!closed_bracket) {
- if (S->tccpp_tok != ']')
- expect(S, "']'");
+ if (tok != ']')
+ expect("']'");
else
- next(S); // skip ']'
+ next(); // skip ']'
preincrement = 1; // add offset before transfer
- if (S->tccpp_tok == '!') {
+ if (tok == '!') {
exclam = 1;
- next(S); // skip '!'
+ next(); // skip '!'
}
}
@@ -1472,13 +1472,13 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
long_transfer = 1; // long transfer
/* fallthrough */
case TOK_ASM_ldc2:
- asm_emit_coprocessor_data_transfer(S, 0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
+ asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 1);
break;
case TOK_ASM_stc2l:
long_transfer = 1; // long transfer
/* fallthrough */
case TOK_ASM_stc2:
- asm_emit_coprocessor_data_transfer(S, 0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
+ asm_emit_coprocessor_data_transfer(0xF, coprocessor, coprocessor_destination_register, &ops[1], &ops[2], op2_minus, preincrement, exclam, long_transfer, 0);
break;
}
} else switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1486,16 +1486,16 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
long_transfer = 1;
/* fallthrough */
case TOK_ASM_stceq:
- 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);
+ 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);
break;
case TOK_ASM_ldcleq:
long_transfer = 1;
/* fallthrough */
case TOK_ASM_ldceq:
- 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);
+ 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);
break;
default:
- expect(S, "coprocessor data transfer instruction");
+ expect("coprocessor data transfer instruction");
}
}
@@ -1503,7 +1503,7 @@ static void asm_coprocessor_data_transfer_opcode(TCCState *S, int token)
#define CP_SINGLE_PRECISION_FLOAT 10
#define CP_DOUBLE_PRECISION_FLOAT 11
-static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int token)
+static void asm_floating_point_single_data_transfer_opcode(TCCState *s1, int token)
{
Operand ops[3];
uint8_t coprocessor = 0;
@@ -1513,7 +1513,7 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke
// Note: Not allowed: vldr p2, c0, [r4, #4]! ; pre-indexed: r0 = *(int*)(r4+4); r4 = r4+4
// Note: Not allowed: vldr p3, c0, [r4], #4 ; post-indexed: r0 = *(int*)(r4+0); r4 = r4+4
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
if (ops[0].type == OP_VREG32) {
coprocessor = CP_SINGLE_PRECISION_FLOAT;
coprocessor_destination_register = ops[0].reg;
@@ -1522,32 +1522,32 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke
} else if (ops[0].type == OP_VREG64) {
coprocessor = CP_DOUBLE_PRECISION_FLOAT;
coprocessor_destination_register = ops[0].reg;
- next(S);
+ next();
} else {
- expect(S, "floating point register");
+ expect("floating point register");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
+ expect("','");
- if (S->tccpp_tok != '[')
- expect(S, "'['");
+ if (tok != '[')
+ expect("'['");
else
- next(S); // skip '['
+ next(); // skip '['
- parse_operand(S, &ops[1]);
+ parse_operand(s1, &ops[1]);
if (ops[1].type != OP_REG32) {
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
return;
}
- if (S->tccpp_tok == ',') {
- next(S); // skip ','
- parse_operand(S, &ops[2]);
+ if (tok == ',') {
+ next(); // skip ','
+ parse_operand(s1, &ops[2]);
if (ops[2].type != OP_IM8 && ops[2].type != OP_IM8N) {
- expect(S, "immediate offset");
+ expect("immediate offset");
return;
}
} else {
@@ -1555,24 +1555,24 @@ static void asm_floating_point_single_data_transfer_opcode(TCCState *S, int toke
ops[2].type = OP_IM8;
ops[2].e.v = 0;
}
- if (S->tccpp_tok != ']')
- expect(S, "']'");
+ if (tok != ']')
+ expect("']'");
else
- next(S); // skip ']'
+ next(); // skip ']'
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_vldreq:
- 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);
+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 1);
break;
case TOK_ASM_vstreq:
- 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);
+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, coprocessor_destination_register, &ops[1], &ops[2], 0, 1, 0, long_transfer, 0);
break;
default:
- expect(S, "floating point data transfer instruction");
+ expect("floating point data transfer instruction");
}
}
-static void asm_floating_point_block_data_transfer_opcode(TCCState *S, int token)
+static void asm_floating_point_block_data_transfer_opcode(TCCState *s1, int token)
{
uint8_t coprocessor = 0;
int first_regset_register;
@@ -1592,56 +1592,56 @@ static void asm_floating_point_block_data_transfer_opcode(TCCState *S, int token
op0_exclam = 1;
break;
default:
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == '!') {
+ parse_operand(s1, &ops[0]);
+ if (tok == '!') {
op0_exclam = 1;
- next(S); // skip '!'
+ next(); // skip '!'
}
- if (S->tccpp_tok == ',')
- next(S); // skip comma
+ if (tok == ',')
+ next(); // skip comma
else {
- expect(S, "','");
+ expect("','");
return;
}
}
- if (S->tccpp_tok != '{') {
- expect(S, "'{'");
+ if (tok != '{') {
+ expect("'{'");
return;
}
- next(S); // skip '{'
- first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 1);
- if ((first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 1)) != -1) {
+ next(); // skip '{'
+ first_regset_register = asm_parse_vfp_regvar(tok, 1);
+ if ((first_regset_register = asm_parse_vfp_regvar(tok, 1)) != -1) {
coprocessor = CP_DOUBLE_PRECISION_FLOAT;
- next(S);
- } else if ((first_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, 0)) != -1) {
+ next();
+ } else if ((first_regset_register = asm_parse_vfp_regvar(tok, 0)) != -1) {
coprocessor = CP_SINGLE_PRECISION_FLOAT;
- next(S);
+ next();
} else {
- expect(S, "floating-point register");
+ expect("floating-point register");
return;
}
- if (S->tccpp_tok == '-') {
- next(S);
- if ((last_regset_register = asm_parse_vfp_regvar(S->tccpp_tok, coprocessor == CP_DOUBLE_PRECISION_FLOAT)) != -1)
- next(S);
+ if (tok == '-') {
+ next();
+ if ((last_regset_register = asm_parse_vfp_regvar(tok, coprocessor == CP_DOUBLE_PRECISION_FLOAT)) != -1)
+ next();
else {
- expect(S, "floating-point register");
+ expect("floating-point register");
return;
}
} else
last_regset_register = first_regset_register;
if (last_regset_register < first_regset_register) {
- tcc_error(S, "registers will be processed in ascending order by hardware--but are not specified in ascending order here");
+ tcc_error("registers will be processed in ascending order by hardware--but are not specified in ascending order here");
return;
}
- if (S->tccpp_tok != '}') {
- expect(S, "'}'");
+ if (tok != '}') {
+ expect("'}'");
return;
}
- next(S); // skip '}'
+ next(); // skip '}'
// Note: 0 (one down) is not implemented by us regardless.
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
preincrement = 1;
break;
default:
- expect(S, "floating point block data transfer instruction");
+ expect("floating point block data transfer instruction");
return;
}
if (ops[0].type != OP_REG32)
- expect(S, "(first operand) register");
+ expect("(first operand) register");
else if (ops[0].reg == 15)
- tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
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)
- tcc_error(S, "first operand of '%s' should have an exclamation mark", get_tok_str(S, token, NULL));
+ tcc_error("first operand of '%s' should have an exclamation mark", get_tok_str(token, NULL));
else
- 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);
+ 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);
}
#define VMOV_FRACTIONAL_DIGITS 7
#define VMOV_ONE 10000000 /* pow(10, VMOV_FRACTIONAL_DIGITS) */
-static uint32_t vmov_parse_fractional_part(TCCState* S, const char* s)
+static uint32_t vmov_parse_fractional_part(const char* s)
{
uint32_t result = 0;
int i;
@@ -1701,7 +1701,7 @@ static uint32_t vmov_parse_fractional_part(TCCState* S, const char* s)
}
}
if (*s)
- expect(S, "decimal numeral");
+ expect("decimal numeral");
return result;
}
@@ -1720,34 +1720,34 @@ static int vmov_linear_approx_index(uint32_t beginning, uint32_t end, uint32_t v
return -1;
}
-static uint32_t vmov_parse_immediate_value(TCCState* S) {
+static uint32_t vmov_parse_immediate_value() {
uint32_t value;
unsigned long integral_value;
const char *p;
- if (S->tccpp_tok != TOK_PPNUM) {
- expect(S, "immediate value");
+ if (tok != TOK_PPNUM) {
+ expect("immediate value");
return 0;
}
- p = S->tccpp_tokc.str.data;
+ p = tokc.str.data;
errno = 0;
integral_value = strtoul(p, (char **)&p, 0);
if (errno || integral_value >= 32) {
- tcc_error(S, "invalid floating-point immediate value");
+ tcc_error("invalid floating-point immediate value");
return 0;
}
value = (uint32_t) integral_value * VMOV_ONE;
if (*p == '.') {
++p;
- value += vmov_parse_fractional_part(S, p);
+ value += vmov_parse_fractional_part(p);
}
- next(S);
+ next();
return value;
}
-static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value)
+static uint8_t vmov_encode_immediate_value(uint32_t value)
{
uint32_t limit;
uint32_t end = 0;
@@ -1767,7 +1767,7 @@ static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value)
limit >>= 1;
}
if (r == -1 || value < beginning || value > end) {
- tcc_error(S, "invalid decimal number for vmov: %d", value);
+ tcc_error("invalid decimal number for vmov: %d", value);
return 0;
}
n = vmov_linear_approx_index(beginning, end, value);
@@ -1775,7 +1775,7 @@ static uint8_t vmov_encode_immediate_value(TCCState* S, uint32_t value)
}
// Not standalone.
-static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S, int token, uint8_t coprocessor, uint8_t CRd) {
+static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *s1, int token, uint8_t coprocessor, uint8_t CRd) {
uint8_t opcode1 = 0;
uint8_t opcode2 = 0;
uint8_t operands[3] = {0, 0, 0};
@@ -1785,14 +1785,14 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S
operands[0] = CRd;
- if (S->tccpp_tok == '#' || S->tccpp_tok == '$') {
- next(S);
+ if (tok == '#' || tok == '$') {
+ next();
}
- if (S->tccpp_tok == '-') {
+ if (tok == '-') {
op_minus = 1;
- next(S);
+ next();
}
- immediate_value = vmov_parse_immediate_value(S);
+ immediate_value = vmov_parse_immediate_value();
opcode1 = 11; // "Other" instruction
switch (ARM_INSTRUCTION_GROUP(token)) {
@@ -1801,7 +1801,7 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S
opcode2 = 2;
operands[1] = 5;
if (immediate_value) {
- expect(S, "Immediate value 0");
+ expect("Immediate value 0");
return;
}
break;
@@ -1810,7 +1810,7 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S
opcode2 = 6;
operands[1] = 5;
if (immediate_value) {
- expect(S, "Immediate value 0");
+ expect("Immediate value 0");
return;
}
break;
@@ -1821,12 +1821,12 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S
operands[1] = 0x8;
else
operands[1] = 0x0;
- code = vmov_encode_immediate_value(S, immediate_value);
+ code = vmov_encode_immediate_value(immediate_value);
operands[1] |= code >> 4;
operands[2] = code & 0xF;
break;
default:
- expect(S, "known floating point with immediate instruction");
+ expect("known floating point with immediate instruction");
return;
}
@@ -1836,17 +1836,17 @@ static void asm_floating_point_immediate_data_processing_opcode_tail(TCCState *S
operands[0] >>= 1;
}
- asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode1, operands[0], operands[1], operands[2], opcode2, 0);
+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, operands[0], operands[1], operands[2], opcode2, 0);
}
-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]) {
+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]) {
uint8_t opcode1 = 0;
uint8_t opcode2 = 0;
switch (coprocessor) {
case CP_SINGLE_PRECISION_FLOAT:
// "vmov.f32 r2, s3" or "vmov.f32 s3, r2"
if (nb_ops != 2 || nb_arm_regs != 1) {
- tcc_error(S, "vmov.f32 only implemented for one VFP register operand and one ARM register operands");
+ tcc_error("vmov.f32 only implemented for one VFP register operand and one ARM register operands");
return;
}
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
ops[0].reg >>= 1;
}
- 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);
+ 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);
break;
case CP_DOUBLE_PRECISION_FLOAT:
if (nb_ops != 3 || nb_arm_regs != 2) {
- tcc_error(S, "vmov.f32 only implemented for one VFP register operand and two ARM register operands");
+ tcc_error("vmov.f32 only implemented for one VFP register operand and two ARM register operands");
return;
}
// 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
memcpy(&ops[1], &ops[2], sizeof(ops[1]));
memcpy(&ops[2], &temp, sizeof(ops[2]));
} else {
- tcc_error(S, "vmov.f64 only implemented for one VFP register operand and two ARM register operands");
+ tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands");
return;
}
} else if (ops[0].type != OP_REG32 || ops[1].type != OP_REG32 || ops[2].type != OP_VREG64) {
- tcc_error(S, "vmov.f64 only implemented for one VFP register operand and two ARM register operands");
+ tcc_error("vmov.f64 only implemented for one VFP register operand and two ARM register operands");
return;
} else {
opcode1 |= 1;
}
- 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);
+ asm_emit_coprocessor_data_transfer(condition_code_of_token(token), coprocessor, ops[0].reg, &ops[1], &ops[2], 0, 0, 0, 1, opcode1);
break;
default:
- tcc_internal_error(S, "unknown coprocessor");
+ tcc_internal_error("unknown coprocessor");
}
}
-static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int token) {
+static void asm_floating_point_vcvt_data_processing_opcode(TCCState *s1, int token) {
uint8_t coprocessor = 0;
Operand ops[3];
uint8_t opcode1 = 11;
@@ -1928,11 +1928,11 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke
coprocessor = CP_SINGLE_PRECISION_FLOAT;
break;
default:
- tcc_error(S, "Unknown coprocessor for instruction '%s'", get_tok_str(S, token, NULL));
+ tcc_error("Unknown coprocessor for instruction '%s'", get_tok_str(token, NULL));
return;
}
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
ops[1].type = OP_IM8;
ops[1].e.v = 8;
/* floating-point -> integer */
@@ -1956,11 +1956,11 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke
break;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[2]);
+ expect("','");
+ parse_operand(s1, &ops[2]);
switch (ARM_INSTRUCTION_GROUP(token)) {
/* floating-point -> integer */
@@ -1990,7 +1990,7 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke
case TOK_ASM_vcvteq_f64_f32:
if (ops[0].type == OP_VREG64 && ops[2].type == OP_VREG32) {
} else {
- expect(S, "d<number>, s<number>");
+ expect("d<number>, s<number>");
return;
}
break;
@@ -1998,13 +1998,13 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke
if (coprocessor == CP_SINGLE_PRECISION_FLOAT) {
if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG32) {
} else {
- expect(S, "s<number>, s<number>");
+ expect("s<number>, s<number>");
return;
}
} else if (coprocessor == CP_DOUBLE_PRECISION_FLOAT) {
if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG64) {
} else {
- expect(S, "s<number>, d<number>");
+ expect("s<number>, d<number>");
return;
}
}
@@ -2020,10 +2020,10 @@ static void asm_floating_point_vcvt_data_processing_opcode(TCCState *S, int toke
opcode1 |= 4;
ops[0].reg >>= 1;
}
- 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);
+ 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);
}
-static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
+static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {
uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
uint8_t opcode1 = 0;
uint8_t opcode2 = 0; // (0 || 2) | register selection
@@ -2078,30 +2078,30 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
for (nb_ops = 0; nb_ops < 3; ) {
// Note: Necessary because parse_operand can't parse decimal numerals.
- if (nb_ops == 1 && (S->tccpp_tok == '#' || S->tccpp_tok == '$' || S->tccpp_tok == TOK_PPNUM || S->tccpp_tok == '-')) {
- asm_floating_point_immediate_data_processing_opcode_tail(S, token, coprocessor, ops[0].reg);
+ if (nb_ops == 1 && (tok == '#' || tok == '$' || tok == TOK_PPNUM || tok == '-')) {
+ asm_floating_point_immediate_data_processing_opcode_tail(s1, token, coprocessor, ops[0].reg);
return;
}
- parse_operand(S, &ops[nb_ops]);
+ parse_operand(s1, &ops[nb_ops]);
if (vmov && ops[nb_ops].type == OP_REG32) {
++nb_arm_regs;
} else if (ops[nb_ops].type == OP_VREG32) {
if (coprocessor != CP_SINGLE_PRECISION_FLOAT) {
- expect(S, "'s<number>'");
+ expect("'s<number>'");
return;
}
} else if (ops[nb_ops].type == OP_VREG64) {
if (coprocessor != CP_DOUBLE_PRECISION_FLOAT) {
- expect(S, "'d<number>'");
+ expect("'d<number>'");
return;
}
} else {
- expect(S, "floating point register");
+ expect("floating point register");
return;
}
++nb_ops;
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
break;
}
@@ -2113,7 +2113,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
nb_ops = 3;
}
if (nb_ops < 3) {
- tcc_error(S, "Not enough operands for '%s' (%u)", get_tok_str(S, token, NULL), nb_ops);
+ tcc_error("Not enough operands for '%s' (%u)", get_tok_str(token, NULL), nb_ops);
return;
}
}
@@ -2202,7 +2202,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
case TOK_ASM_vmoveq_f32:
case TOK_ASM_vmoveq_f64:
if (nb_arm_regs > 0) { // vmov.f32 r2, s3 or similar
- asm_floating_point_reg_arm_reg_transfer_opcode_tail(S, token, coprocessor, nb_arm_regs, nb_ops, ops);
+ asm_floating_point_reg_arm_reg_transfer_opcode_tail(s1, token, coprocessor, nb_arm_regs, nb_ops, ops);
return;
} else {
opcode1 = 11; // "Other" instruction
@@ -2212,7 +2212,7 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
}
break;
default:
- expect(S, "known floating point instruction");
+ expect("known floating point instruction");
return;
}
@@ -2236,10 +2236,10 @@ static void asm_floating_point_data_processing_opcode(TCCState *S, int token) {
}
}
- 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);
+ 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);
}
-static void asm_floating_point_status_register_opcode(TCCState* S, int token)
+static void asm_floating_point_status_register_opcode(TCCState* s1, int token)
{
uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
uint8_t opcode;
@@ -2248,61 +2248,61 @@ static void asm_floating_point_status_register_opcode(TCCState* S, int token)
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_vmrseq:
opcode = 0xf;
- if (S->tccpp_tok == TOK_ASM_apsr_nzcv) {
+ if (tok == TOK_ASM_apsr_nzcv) {
arm_operand.type = OP_REG32;
arm_operand.reg = 15; // not PC
- next(S); // skip apsr_nzcv
+ next(); // skip apsr_nzcv
} else {
- parse_operand(S, &arm_operand);
+ parse_operand(s1, &arm_operand);
if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) {
- tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
return;
}
}
- if (S->tccpp_tok != ',')
- expect(S, "','");
+ if (tok != ',')
+ expect("','");
else
- next(S); // skip ','
- vfp_sys_reg = asm_parse_vfp_status_regvar(S->tccpp_tok);
- next(S); // skip vfp sys reg
+ next(); // skip ','
+ vfp_sys_reg = asm_parse_vfp_status_regvar(tok);
+ next(); // skip vfp sys reg
if (arm_operand.type == OP_REG32 && arm_operand.reg == 15 && vfp_sys_reg != 1) {
- tcc_error(S, "'%s' only supports the variant 'vmrs apsr_nzcv, fpscr' here", get_tok_str(S, token, NULL));
+ tcc_error("'%s' only supports the variant 'vmrs apsr_nzcv, fpscr' here", get_tok_str(token, NULL));
return;
}
break;
case TOK_ASM_vmsreq:
opcode = 0xe;
- vfp_sys_reg = asm_parse_vfp_status_regvar(S->tccpp_tok);
- next(S); // skip vfp sys reg
- if (S->tccpp_tok != ',')
- expect(S, "','");
+ vfp_sys_reg = asm_parse_vfp_status_regvar(tok);
+ next(); // skip vfp sys reg
+ if (tok != ',')
+ expect("','");
else
- next(S); // skip ','
- parse_operand(S, &arm_operand);
+ next(); // skip ','
+ parse_operand(s1, &arm_operand);
if (arm_operand.type == OP_REG32 && arm_operand.reg == 15) {
- tcc_error(S, "'%s' does not support 'pc' as operand", get_tok_str(S, token, NULL));
+ tcc_error("'%s' does not support 'pc' as operand", get_tok_str(token, NULL));
return;
}
break;
default:
- expect(S, "floating point status register instruction");
+ expect("floating point status register instruction");
return;
}
if (vfp_sys_reg == -1) {
- expect(S, "VFP system register");
+ expect("VFP system register");
return;
}
if (arm_operand.type != OP_REG32) {
- expect(S, "ARM register");
+ expect("ARM register");
return;
}
- asm_emit_coprocessor_opcode(S, condition_code_of_token(S, token), coprocessor, opcode, arm_operand.reg, vfp_sys_reg, 0x10, 0, 0);
+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode, arm_operand.reg, vfp_sys_reg, 0x10, 0, 0);
}
#endif
-static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
+static void asm_misc_single_data_transfer_opcode(TCCState *s1, int token)
{
Operand ops[3];
int exclam = 0;
@@ -2322,42 +2322,42 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
// Here: 0 0 0 P U I W L << 20
// [compare single data transfer: 0 1 I P U B W L << 20]
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
if (ops[0].type == OP_REG32)
opcode |= ENCODE_RD(ops[0].reg);
else {
- expect(S, "(destination operand) register");
+ expect("(destination operand) register");
return;
}
- if (S->tccpp_tok != ',')
- expect(S, "at least two arguments");
+ if (tok != ',')
+ expect("at least two arguments");
else
- next(S); // skip ','
+ next(); // skip ','
- if (S->tccpp_tok != '[')
- expect(S, "'['");
+ if (tok != '[')
+ expect("'['");
else
- next(S); // skip '['
+ next(); // skip '['
- parse_operand(S, &ops[1]);
+ parse_operand(s1, &ops[1]);
if (ops[1].type == OP_REG32)
opcode |= ENCODE_RN(ops[1].reg);
else {
- expect(S, "(first source operand) register");
+ expect("(first source operand) register");
return;
}
- if (S->tccpp_tok == ']') {
- next(S);
+ if (tok == ']') {
+ next();
closed_bracket = 1;
// exclam = 1; // implicit in hardware; don't do it in software
}
- if (S->tccpp_tok == ',') {
- next(S); // skip ','
- if (S->tccpp_tok == '-') {
+ if (tok == ',') {
+ next(); // skip ','
+ if (tok == '-') {
op2_minus = 1;
- next(S);
+ next();
}
- parse_operand(S, &ops[2]);
+ parse_operand(s1, &ops[2]);
} else {
// end of input expression in brackets--assume 0 offset
ops[2].type = OP_IM8;
@@ -2365,20 +2365,20 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
opcode |= 1 << 24; // add offset before transfer
}
if (!closed_bracket) {
- if (S->tccpp_tok != ']')
- expect(S, "']'");
+ if (tok != ']')
+ expect("']'");
else
- next(S); // skip ']'
+ next(); // skip ']'
opcode |= 1 << 24; // add offset before transfer
- if (S->tccpp_tok == '!') {
+ if (tok == '!') {
exclam = 1;
- next(S); // skip '!'
+ next(); // skip '!'
}
}
if (exclam) {
if ((opcode & (1 << 24)) == 0) {
- tcc_error(S, "result of '%s' would be unpredictable here", get_tok_str(S, token, NULL));
+ tcc_error("result of '%s' would be unpredictable here", get_tok_str(token, NULL));
return;
}
opcode |= 1 << 21; // write offset back into register
@@ -2387,11 +2387,11 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
if (ops[2].type == OP_IM32 || ops[2].type == OP_IM8 || ops[2].type == OP_IM8N) {
int v = ops[2].e.v;
if (op2_minus)
- tcc_error(S, "minus before '#' not supported for immediate values");
+ tcc_error("minus before '#' not supported for immediate values");
if (v >= 0) {
opcode |= 1 << 23; // up
if (v >= 0x100)
- tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
else {
// bits 11...8: immediate hi nibble
// bits 3...0: immediate lo nibble
@@ -2400,7 +2400,7 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
}
} else { // down
if (v <= -0x100)
- tcc_error(S, "offset out of range for '%s'", get_tok_str(S, token, NULL));
+ tcc_error("offset out of range for '%s'", get_tok_str(token, NULL));
else {
v = -v;
// bits 11...8: immediate hi nibble
@@ -2415,7 +2415,7 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
opcode |= 1 << 23; // up
opcode |= ops[2].reg;
} else
- expect(S, "register");
+ expect("register");
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_ldrsheq:
@@ -2424,34 +2424,34 @@ static void asm_misc_single_data_transfer_opcode(TCCState *S, int token)
case TOK_ASM_ldrsbeq:
opcode |= 1 << 6; // sign extend
opcode |= 1 << 20; // L
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_ldrheq:
opcode |= 1 << 5; // halfword, not byte
opcode |= 1 << 20; // L
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
case TOK_ASM_strheq:
opcode |= 1 << 5; // halfword, not byte
- asm_emit_opcode(S, token, opcode);
+ asm_emit_opcode(token, opcode);
break;
}
}
/* Note: almost dupe of encbranch in arm-gen.c */
-static uint32_t encbranchoffset(TCCState* S, int pos, int addr, int fail)
+static uint32_t encbranchoffset(int pos, int addr, int fail)
{
addr-=pos+8;
addr/=4;
if(addr>=0x7fffff || addr<-0x800000) {
if(fail)
- tcc_error(S, "branch offset is too far");
+ tcc_error("branch offset is too far");
return 0;
}
return /*not 0x0A000000|*/(addr&0xffffff);
}
-static void asm_branch_opcode(TCCState *S, int token)
+static void asm_branch_opcode(TCCState *s1, int token)
{
int jmp_disp = 0;
Operand op;
@@ -2461,63 +2461,63 @@ static void asm_branch_opcode(TCCState *S, int token)
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_beq:
case TOK_ASM_bleq:
- asm_expr(S, &e);
- esym = elfsym(S, e.sym);
+ asm_expr(s1, &e);
+ esym = elfsym(e.sym);
if (!esym || esym->st_shndx != cur_text_section->sh_num) {
- tcc_error(S, "invalid branch target");
+ tcc_error("invalid branch target");
return;
}
- jmp_disp = encbranchoffset(S, S->tccgen_ind, e.v + esym->st_value, 1);
+ jmp_disp = encbranchoffset(ind, e.v + esym->st_value, 1);
break;
default:
- parse_operand(S, &op);
+ parse_operand(s1, &op);
break;
}
switch (ARM_INSTRUCTION_GROUP(token)) {
case TOK_ASM_beq:
- asm_emit_opcode(S, token, (0xa << 24) | (jmp_disp & 0xffffff));
+ asm_emit_opcode(token, (0xa << 24) | (jmp_disp & 0xffffff));
break;
case TOK_ASM_bleq:
- asm_emit_opcode(S, token, (0xb << 24) | (jmp_disp & 0xffffff));
+ asm_emit_opcode(token, (0xb << 24) | (jmp_disp & 0xffffff));
break;
case TOK_ASM_bxeq:
if (op.type != OP_REG32)
- expect(S, "register");
+ expect("register");
else
- asm_emit_opcode(S, token, (0x12fff1 << 4) | op.reg);
+ asm_emit_opcode(token, (0x12fff1 << 4) | op.reg);
break;
case TOK_ASM_blxeq:
if (op.type != OP_REG32)
- expect(S, "register");
+ expect("register");
else
- asm_emit_opcode(S, token, (0x12fff3 << 4) | op.reg);
+ asm_emit_opcode(token, (0x12fff3 << 4) | op.reg);
break;
default:
- expect(S, "branch instruction");
+ expect("branch instruction");
}
}
-ST_FUNC void asm_opcode(TCCState *S, int token)
+ST_FUNC void asm_opcode(TCCState *s1, int token)
{
while (token == TOK_LINEFEED) {
- next(S);
- token = S->tccpp_tok;
+ next();
+ token = tok;
}
if (token == TOK_EOF)
return;
if (token < TOK_ASM_nopeq) { // no condition code
switch (token) {
case TOK_ASM_cdp2:
- asm_coprocessor_opcode(S, token);
+ asm_coprocessor_opcode(s1, token);
return;
case TOK_ASM_ldc2:
case TOK_ASM_ldc2l:
case TOK_ASM_stc2:
case TOK_ASM_stc2l:
- asm_coprocessor_data_transfer_opcode(S, token);
+ asm_coprocessor_data_transfer_opcode(s1, token);
return;
default:
- expect(S, "instruction");
+ expect("instruction");
return;
}
}
@@ -2535,22 +2535,22 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_ldmdbeq:
case TOK_ASM_stmibeq:
case TOK_ASM_ldmibeq:
- asm_block_data_transfer_opcode(S, token);
+ asm_block_data_transfer_opcode(s1, token);
return;
case TOK_ASM_nopeq:
case TOK_ASM_wfeeq:
case TOK_ASM_wfieq:
- asm_nullary_opcode(S, token);
+ asm_nullary_opcode(token);
return;
case TOK_ASM_swieq:
case TOK_ASM_svceq:
- asm_unary_opcode(S, token);
+ asm_unary_opcode(s1, token);
return;
case TOK_ASM_beq:
case TOK_ASM_bleq:
case TOK_ASM_bxeq:
case TOK_ASM_blxeq:
- asm_branch_opcode(S, token);
+ asm_branch_opcode(s1, token);
return;
case TOK_ASM_clzeq:
case TOK_ASM_sxtbeq:
@@ -2559,7 +2559,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_uxtheq:
case TOK_ASM_movteq:
case TOK_ASM_movweq:
- asm_binary_opcode(S, token);
+ asm_binary_opcode(s1, token);
return;
case TOK_ASM_ldreq:
@@ -2570,14 +2570,14 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_ldrexbeq:
case TOK_ASM_strexeq:
case TOK_ASM_strexbeq:
- asm_single_data_transfer_opcode(S, token);
+ asm_single_data_transfer_opcode(s1, token);
return;
case TOK_ASM_ldrheq:
case TOK_ASM_ldrsheq:
case TOK_ASM_ldrsbeq:
case TOK_ASM_strheq:
- asm_misc_single_data_transfer_opcode(S, token);
+ asm_misc_single_data_transfer_opcode(s1, token);
return;
case TOK_ASM_andeq:
@@ -2612,7 +2612,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_movseq:
case TOK_ASM_bicseq:
case TOK_ASM_mvnseq:
- asm_data_processing_opcode(S, token);
+ asm_data_processing_opcode(s1, token);
return;
case TOK_ASM_lsleq:
@@ -2625,14 +2625,14 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_rorseq:
case TOK_ASM_rrxseq:
case TOK_ASM_rrxeq:
- asm_shift_opcode(S, token);
+ asm_shift_opcode(s1, token);
return;
case TOK_ASM_muleq:
case TOK_ASM_mulseq:
case TOK_ASM_mlaeq:
case TOK_ASM_mlaseq:
- asm_multiplication_opcode(S, token);
+ asm_multiplication_opcode(s1, token);
return;
case TOK_ASM_smulleq:
@@ -2643,26 +2643,26 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_smlalseq:
case TOK_ASM_umlaleq:
case TOK_ASM_umlalseq:
- asm_long_multiplication_opcode(S, token);
+ asm_long_multiplication_opcode(s1, token);
return;
case TOK_ASM_cdpeq:
case TOK_ASM_mcreq:
case TOK_ASM_mrceq:
- asm_coprocessor_opcode(S, token);
+ asm_coprocessor_opcode(s1, token);
return;
case TOK_ASM_ldceq:
case TOK_ASM_ldcleq:
case TOK_ASM_stceq:
case TOK_ASM_stcleq:
- asm_coprocessor_data_transfer_opcode(S, token);
+ asm_coprocessor_data_transfer_opcode(s1, token);
return;
#if defined(TCC_ARM_VFP)
case TOK_ASM_vldreq:
case TOK_ASM_vstreq:
- asm_floating_point_single_data_transfer_opcode(S, token);
+ asm_floating_point_single_data_transfer_opcode(s1, token);
return;
case TOK_ASM_vmlaeq_f32:
@@ -2695,7 +2695,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_vcmpeq_f64:
case TOK_ASM_vcmpeeq_f64:
case TOK_ASM_vmoveq_f64:
- asm_floating_point_data_processing_opcode(S, token);
+ asm_floating_point_data_processing_opcode(s1, token);
return;
case TOK_ASM_vcvtreq_s32_f32:
@@ -2712,7 +2712,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_vcvteq_f32_u32:
case TOK_ASM_vcvteq_f64_f32:
case TOK_ASM_vcvteq_f32_f64:
- asm_floating_point_vcvt_data_processing_opcode(S, token);
+ asm_floating_point_vcvt_data_processing_opcode(s1, token);
return;
case TOK_ASM_vpusheq:
@@ -2723,21 +2723,21 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_vstmeq:
case TOK_ASM_vstmiaeq:
case TOK_ASM_vstmdbeq:
- asm_floating_point_block_data_transfer_opcode(S, token);
+ asm_floating_point_block_data_transfer_opcode(s1, token);
return;
case TOK_ASM_vmsreq:
case TOK_ASM_vmrseq:
- asm_floating_point_status_register_opcode(S, token);
+ asm_floating_point_status_register_opcode(s1, token);
return;
#endif
default:
- expect(S, "known instruction");
+ expect("known instruction");
}
}
-ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int modifier)
+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
{
int r, reg, size, val;
char buf[64];
@@ -2746,45 +2746,45 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int mo
if ((r & VT_VALMASK) == VT_CONST) {
if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' &&
modifier != 'P')
- cstr_ccat(S, add_str, '#');
+ cstr_ccat(add_str, '#');
if (r & VT_SYM) {
- const char *name = get_tok_str(S, sv->sym->v, NULL);
+ const char *name = get_tok_str(sv->sym->v, NULL);
if (sv->sym->v >= SYM_FIRST_ANOM) {
/* In case of anonymous symbols ("L.42", used
for static data labels) we can't find them
in the C symbol table when later looking up
this name. So enter them now into the asm label
list when we still know the symbol. */
- get_asm_sym(S, tok_alloc(S, name, strlen(name))->tok, sv->sym);
+ get_asm_sym(tok_alloc(name, strlen(name))->tok, sv->sym);
}
- if (S->leading_underscore)
- cstr_ccat(S, add_str, '_');
- cstr_cat(S, add_str, name, -1);
+ if (tcc_state->leading_underscore)
+ cstr_ccat(add_str, '_');
+ cstr_cat(add_str, name, -1);
if ((uint32_t) sv->c.i == 0)
goto no_offset;
- cstr_ccat(S, add_str, '+');
+ cstr_ccat(add_str, '+');
}
val = sv->c.i;
if (modifier == 'n')
val = -val;
snprintf(buf, sizeof(buf), "%d", (int) sv->c.i);
- cstr_cat(S, add_str, buf, -1);
+ cstr_cat(add_str, buf, -1);
no_offset:;
} else if ((r & VT_VALMASK) == VT_LOCAL) {
snprintf(buf, sizeof(buf), "[fp,#%d]", (int) sv->c.i);
- cstr_cat(S, add_str, buf, -1);
+ cstr_cat(add_str, buf, -1);
} else if (r & VT_LVAL) {
reg = r & VT_VALMASK;
if (reg >= VT_CONST)
- tcc_internal_error(S, "");
+ tcc_internal_error("");
snprintf(buf, sizeof(buf), "[%s]",
- get_tok_str(S, TOK_ASM_r0 + reg, NULL));
- cstr_cat(S, add_str, buf, -1);
+ get_tok_str(TOK_ASM_r0 + reg, NULL));
+ cstr_cat(add_str, buf, -1);
} else {
/* register case */
reg = r & VT_VALMASK;
if (reg >= VT_CONST)
- tcc_internal_error(S, "");
+ tcc_internal_error("");
/* choose register operand size */
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
reg = TOK_ASM_r0 + reg;
break;
}
- snprintf(buf, sizeof(buf), "%s", get_tok_str(S, reg, NULL));
- cstr_cat(S, add_str, buf, -1);
+ snprintf(buf, sizeof(buf), "%s", get_tok_str(reg, NULL));
+ cstr_cat(add_str, buf, -1);
}
}
/* generate prolog and epilog code for asm statement */
-ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
int nb_outputs, int is_output,
uint8_t *clobber_regs,
int out_reg)
@@ -2844,7 +2844,7 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
if (!is_output) { // prolog
/* generate reg save code */
if (saved_regset)
- gen_le32(S, 0xe92d0000 | saved_regset); // push {...}
+ gen_le32(0xe92d0000 | saved_regset); // push {...}
/* generate load code */
for(i = 0; i < nb_operands; i++) {
@@ -2858,12 +2858,12 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
sv.type.t = VT_PTR;
- load(S, op->reg, &sv);
+ load(op->reg, &sv);
} else if (i >= nb_outputs || op->is_rw) { // not write-only
/* load value in register */
- load(S, op->reg, op->vt);
+ load(op->reg, op->vt);
if (op->is_llong)
- tcc_error(S, "long long not implemented");
+ tcc_error("long long not implemented");
}
}
}
@@ -2878,29 +2878,29 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL;
sv.type.t = VT_PTR;
- load(S, out_reg, &sv);
+ load(out_reg, &sv);
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | out_reg;
- store(S, op->reg, &sv);
+ store(op->reg, &sv);
}
} else {
- store(S, op->reg, op->vt);
+ store(op->reg, op->vt);
if (op->is_llong)
- tcc_error(S, "long long not implemented");
+ tcc_error("long long not implemented");
}
}
}
/* generate reg restore code */
if (saved_regset)
- gen_le32(S, 0xe8bd0000 | saved_regset); // pop {...}
+ gen_le32(0xe8bd0000 | saved_regset); // pop {...}
}
}
/* return the constraint priority (we allocate first the lowest
numbered constraints) */
-static inline int constraint_priority(TCCState* S, const char *str)
+static inline int constraint_priority(const char *str)
{
int priority, c, pr;
@@ -2927,7 +2927,7 @@ static inline int constraint_priority(TCCState* S, const char *str)
pr = 4;
break;
default:
- tcc_error(S, "unknown constraint '%c'", c);
+ tcc_error("unknown constraint '%c'", c);
pr = 0;
}
if (pr > priority)
@@ -2956,7 +2956,7 @@ static const char *skip_constraint_modifiers(const char *p)
#define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask)
-ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
int nb_operands, int nb_outputs,
const uint8_t *clobber_regs,
int *pout_reg)
@@ -3009,13 +3009,13 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
str = skip_constraint_modifiers(str);
if (isnum(*str) || *str == '[') {
/* this is a reference to another constraint */
- k = find_constraint(S, operands, nb_operands, str, NULL);
+ k = find_constraint(operands, nb_operands, str, NULL);
if ((unsigned) k >= i || i < nb_outputs)
- tcc_error(S, "invalid reference in constraint %d ('%s')",
+ tcc_error("invalid reference in constraint %d ('%s')",
i, str);
op->ref_index = k;
if (operands[k].input_index >= 0)
- tcc_error(S, "cannot reference twice the same operand");
+ tcc_error("cannot reference twice the same operand");
operands[k].input_index = i;
op->priority = 5;
} else if ((op->vt->r & VT_VALMASK) == VT_LOCAL
@@ -3024,7 +3024,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
op->priority = 1;
op->reg = reg;
} else {
- op->priority = constraint_priority(S, str);
+ op->priority = constraint_priority(str);
}
}
@@ -3073,7 +3073,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
if (op->reg >= 0) {
if (is_reg_allocated(op->reg))
tcc_error
- (S, "asm regvar requests register that's taken already");
+ ("asm regvar requests register that's taken already");
reg = op->reg;
goto reg_found;
}
@@ -3087,7 +3087,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
/* FALL THRU */
case '&': // Operand is clobbered before the instruction is done using the input operands
if (j >= nb_outputs)
- tcc_error(S, "'%c' modifier can only be applied to outputs",
+ tcc_error("'%c' modifier can only be applied to outputs",
c);
reg_mask = REG_IN_MASK | REG_OUT_MASK;
goto try_next;
@@ -3147,7 +3147,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
}
break;
default:
- tcc_error(S, "asm constraint %d ('%s') could not be satisfied",
+ tcc_error("asm constraint %d ('%s') could not be satisfied",
j, op->constraint);
break;
}
@@ -3169,7 +3169,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
if (!(regs_allocated[reg] & REG_OUT_MASK))
goto reg_found2;
}
- tcc_error(S, "could not find free output register for reloading");
+ tcc_error("could not find free output register for reloading");
reg_found2:
*pout_reg = reg;
break;
@@ -3183,7 +3183,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
op = &operands[j];
printf("%%%d [%s]: \"%s\" r=0x%04x reg=%d\n",
j,
- op->id ? get_tok_str(S, op->id, NULL) : "",
+ op->id ? get_tok_str(op->id, NULL) : "",
op->constraint, op->vt->r, op->reg);
}
if (*pout_reg >= 0)
@@ -3191,7 +3191,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
#endif
}
-ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
{
int reg;
TokenSym *ts;
@@ -3200,17 +3200,17 @@ ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
!strcmp(str, "cc") ||
!strcmp(str, "flags"))
return;
- ts = tok_alloc(S, str, strlen(str));
- reg = asm_parse_regvar(S, ts->tok);
+ ts = tok_alloc(str, strlen(str));
+ reg = asm_parse_regvar(ts->tok);
if (reg == -1) {
- tcc_error(S, "invalid clobber register '%s'", str);
+ tcc_error("invalid clobber register '%s'", str);
}
clobber_regs[reg] = 1;
}
/* If T refers to a register then return the register number and type.
Otherwise return -1. */
-ST_FUNC int asm_parse_regvar (TCCState *S, int t)
+ST_FUNC int asm_parse_regvar (int t)
{
if (t >= TOK_ASM_r0 && t <= TOK_ASM_pc) { /* register name */
switch (t) {
diff --git a/arm-gen.c b/arm-gen.c
index 4a1b775..2b2e626 100644
--- a/arm-gen.c
+++ b/arm-gen.c
@@ -179,17 +179,24 @@ ST_DATA const int reg_classes[NB_REGS] = {
static int func_sub_sp_offset, last_itod_magic;
static int leaffunc;
+#if defined(CONFIG_TCC_BCHECK)
+static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
+ST_DATA int func_bound_add_epilog;
+#endif
+
#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
-ST_FUNC void arm_init(TCCState *S)
+static CType float_type, double_type, func_float_type, func_double_type;
+ST_FUNC void arm_init(struct TCCState *s)
{
- S->armgen_float_type.t = VT_FLOAT;
- S->armgen_double_type.t = VT_DOUBLE;
- S->armgen_func_float_type.t = VT_FUNC;
- S->armgen_func_float_type.ref = sym_push(S, SYM_FIELD, &S->armgen_float_type, FUNC_CDECL, FUNC_OLD);
- S->armgen_func_double_type.t = VT_FUNC;
- S->armgen_func_double_type.ref = sym_push(S, SYM_FIELD, &S->armgen_double_type, FUNC_CDECL, FUNC_OLD);
-
- float_abi = S->float_abi;
+ float_type.t = VT_FLOAT;
+ double_type.t = VT_DOUBLE;
+ func_float_type.t = VT_FUNC;
+ func_float_type.ref = sym_push(SYM_FIELD, &float_type, FUNC_CDECL, FUNC_OLD);
+ func_double_type.t = VT_FUNC;
+ func_double_type.ref = sym_push(SYM_FIELD, &double_type, FUNC_CDECL, FUNC_OLD);
+
+ float_abi = s->float_abi;
#ifndef TCC_ARM_HARDFLOAT
// XXX: Works on OpenBSD
// # warning "soft float ABI currently not supported: default to softfp"
@@ -216,15 +223,15 @@ ST_FUNC void arm_init(struct TCCState *s)
#define CHECK_R(r) ((r) >= TREG_R0 && (r) <= TREG_LR)
-static int two2mask(TCCState* S, int a,int b) {
+static int two2mask(int a,int b) {
if (!CHECK_R(a) || !CHECK_R(b))
- tcc_error(S, "compiler error! registers %i,%i is not valid",a,b);
+ tcc_error("compiler error! registers %i,%i is not valid",a,b);
return (reg_classes[a]|reg_classes[b])&~(RC_INT|RC_FLOAT);
}
-static int regmask(TCCState* S, int r) {
+static int regmask(int r) {
if (!CHECK_R(r))
- tcc_error(S, "compiler error! register %i is not valid",r);
+ tcc_error("compiler error! register %i is not valid",r);
return reg_classes[r]&~(RC_INT|RC_FLOAT);
}
@@ -240,25 +247,25 @@ const char *default_elfinterp(struct TCCState *s)
}
#endif
-void o(TCCState* S, uint32_t i)
+void o(uint32_t i)
{
/* this is a good place to start adding big-endian support*/
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 4;
+ ind1 = ind + 4;
if (!cur_text_section)
- tcc_error(S, "compiler error! This happens f.ex. if the compiler\n"
+ tcc_error("compiler error! This happens f.ex. if the compiler\n"
"can't evaluate constant expressions outside of a function.");
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind++] = i&255;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind++] = i&255;
i>>=8;
- cur_text_section->data[S->tccgen_ind++] = i&255;
+ cur_text_section->data[ind++] = i&255;
i>>=8;
- cur_text_section->data[S->tccgen_ind++] = i&255;
+ cur_text_section->data[ind++] = i&255;
i>>=8;
- cur_text_section->data[S->tccgen_ind++] = i;
+ cur_text_section->data[ind++] = i;
}
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)
//only add,sub
-void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) {
+void stuff_const_harder(uint32_t op, uint32_t v) {
uint32_t x;
x=stuff_const(op,v);
if(x)
- o(S, x);
+ o(x);
else {
uint32_t a[16], nv, no, o2, n2;
int i,j,k;
@@ -330,8 +337,8 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) {
for(i=0;i<12;i++)
for(j=i<4?i+12:15;j>=i+4;j--)
if((v&(a[i]|a[j]))==v) {
- o(S, stuff_const(op,v&a[i]));
- o(S, stuff_const(o2,v&a[j]));
+ o(stuff_const(op,v&a[i]));
+ o(stuff_const(o2,v&a[j]));
return;
}
no=op^0xC00000;
@@ -340,17 +347,17 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) {
for(i=0;i<12;i++)
for(j=i<4?i+12:15;j>=i+4;j--)
if((nv&(a[i]|a[j]))==nv) {
- o(S, stuff_const(no,nv&a[i]));
- o(S, stuff_const(n2,nv&a[j]));
+ o(stuff_const(no,nv&a[i]));
+ o(stuff_const(n2,nv&a[j]));
return;
}
for(i=0;i<8;i++)
for(j=i+4;j<12;j++)
for(k=i<4?i+12:15;k>=j+4;k--)
if((v&(a[i]|a[j]|a[k]))==v) {
- o(S, stuff_const(op,v&a[i]));
- o(S, stuff_const(o2,v&a[j]));
- o(S, stuff_const(o2,v&a[k]));
+ o(stuff_const(op,v&a[i]));
+ o(stuff_const(o2,v&a[j]));
+ o(stuff_const(o2,v&a[k]));
return;
}
no=op^0xC00000;
@@ -359,31 +366,31 @@ void stuff_const_harder(TCCState* S, uint32_t op, uint32_t v) {
for(j=i+4;j<12;j++)
for(k=i<4?i+12:15;k>=j+4;k--)
if((nv&(a[i]|a[j]|a[k]))==nv) {
- o(S, stuff_const(no,nv&a[i]));
- o(S, stuff_const(n2,nv&a[j]));
- o(S, stuff_const(n2,nv&a[k]));
+ o(stuff_const(no,nv&a[i]));
+ o(stuff_const(n2,nv&a[j]));
+ o(stuff_const(n2,nv&a[k]));
return;
}
- o(S, stuff_const(op,v&a[0]));
- o(S, stuff_const(o2,v&a[4]));
- o(S, stuff_const(o2,v&a[8]));
- o(S, stuff_const(o2,v&a[12]));
+ o(stuff_const(op,v&a[0]));
+ o(stuff_const(o2,v&a[4]));
+ o(stuff_const(o2,v&a[8]));
+ o(stuff_const(o2,v&a[12]));
}
}
-uint32_t encbranch(TCCState* S, int pos, int addr, int fail)
+uint32_t encbranch(int pos, int addr, int fail)
{
addr-=pos+8;
addr/=4;
if(addr>=0x1000000 || addr<-0x1000000) {
if(fail)
- tcc_error(S, "FIXME: function bigger than 32MB");
+ tcc_error("FIXME: function bigger than 32MB");
return 0;
}
return 0x0A000000|(addr&0xffffff);
}
-int decbranch(TCCState* S, int pos)
+int decbranch(int pos)
{
int x;
x=*(uint32_t *)(cur_text_section->data + pos);
@@ -394,50 +401,50 @@ int decbranch(TCCState* S, int pos)
}
/* output a symbol and patch all calls to it */
-void gsym_addr(TCCState* S, int t, int a)
+void gsym_addr(int t, int a)
{
uint32_t *x;
int lt;
while(t) {
x=(uint32_t *)(cur_text_section->data + t);
- t=decbranch(S, lt=t);
+ t=decbranch(lt=t);
if(a==lt+4)
*x=0xE1A00000; // nop
else {
*x &= 0xff000000;
- *x |= encbranch(S, lt,a,1);
+ *x |= encbranch(lt,a,1);
}
}
}
#ifdef TCC_ARM_VFP
-static uint32_t vfpr(TCCState* S, int r)
+static uint32_t vfpr(int r)
{
if(r<TREG_F0 || r>TREG_F7)
- tcc_error(S, "compiler error! register %i is no vfp register",r);
+ tcc_error("compiler error! register %i is no vfp register",r);
return r - TREG_F0;
}
#else
-static uint32_t fpr(TCCState* S, int r)
+static uint32_t fpr(int r)
{
if(r<TREG_F0 || r>TREG_F3)
- tcc_error(S, "compiler error! register %i is no fpa register",r);
+ tcc_error("compiler error! register %i is no fpa register",r);
return r - TREG_F0;
}
#endif
-static uint32_t intr(TCCState* S, int r)
+static uint32_t intr(int r)
{
if(r == TREG_R12)
return 12;
if(r >= TREG_R0 && r <= TREG_R3)
return r - TREG_R0;
if (!(r >= TREG_SP && r <= TREG_LR))
- tcc_error(S, "compiler error! register %i is no int register",r);
+ tcc_error("compiler error! register %i is no int register",r);
return r + (13 - TREG_SP);
}
-static void calcaddr(TCCState* S, uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift)
+static void calcaddr(uint32_t *base, int *off, int *sgn, int maxoff, unsigned shift)
{
if(*off>maxoff || *off&((1<<shift)-1)) {
uint32_t x, y;
@@ -448,23 +455,23 @@ static void calcaddr(TCCState* S, uint32_t *base, int *off, int *sgn, int maxoff
*base=14; // lr
y=stuff_const(x,*off&~maxoff);
if(y) {
- o(S, y);
+ o(y);
*off&=maxoff;
return;
}
y=stuff_const(x,(*off+maxoff)&~maxoff);
if(y) {
- o(S, y);
+ o(y);
*sgn=!*sgn;
*off=((*off+maxoff)&~maxoff)-*off;
return;
}
- stuff_const_harder(S, x,*off&~maxoff);
+ stuff_const_harder(x,*off&~maxoff);
*off&=maxoff;
}
}
-static uint32_t mapcc(TCCState* S, int cc)
+static uint32_t mapcc(int cc)
{
switch(cc)
{
@@ -493,11 +500,11 @@ static uint32_t mapcc(TCCState* S, int cc)
case TOK_GT:
return 0xC0000000; /* GT */
}
- tcc_error(S, "unexpected condition code");
+ tcc_error("unexpected condition code");
return 0xE0000000; /* AL */
}
-static int negcc(TCCState* S, int cc)
+static int negcc(int cc)
{
switch(cc)
{
@@ -526,44 +533,44 @@ static int negcc(TCCState* S, int cc)
case TOK_GT:
return TOK_LE;
}
- tcc_error(S, "unexpected condition code");
+ tcc_error("unexpected condition code");
return TOK_NE;
}
/* Load value into register r.
Use relative/got addressing to avoid setting DT_TEXTREL */
-static void load_value(TCCState* S, SValue *sv, int r)
+static void load_value(SValue *sv, int r)
{
- o(S, 0xE59F0000|(intr(S, r)<<12)); /* ldr r, [pc] */
- o(S, 0xEA000000); /* b $+4 */
+ o(0xE59F0000|(intr(r)<<12)); /* ldr r, [pc] */
+ o(0xEA000000); /* b $+4 */
#ifndef CONFIG_TCC_PIE
if(sv->r & VT_SYM)
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_ARM_ABS32);
- o(S, sv->c.i);
+ greloc(cur_text_section, sv->sym, ind, R_ARM_ABS32);
+ o(sv->c.i);
#else
if(sv->r & VT_SYM) {
if (sv->sym->type.t & VT_STATIC) {
greloc(cur_text_section, sv->sym, ind, R_ARM_REL32);
- o(S, sv->c.i - 12);
- o(S, 0xe080000f | (intr(S, r)<<12) | (intr(S, r)<<16)); // add rx,rx,pc
+ o(sv->c.i - 12);
+ o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc
}
else {
greloc(cur_text_section, sv->sym, ind, R_ARM_GOT_PREL);
- o(S, -12);
- o(S, 0xe080000f | (intr(S, r)<<12) | (intr(S, r)<<16)); // add rx,rx,pc
- o(S, 0xe5900000 | (intr(S, r)<<12) | (intr(S, r)<<16)); // ldr rx,[rx]
+ o(-12);
+ o(0xe080000f | (intr(r)<<12) | (intr(r)<<16)); // add rx,rx,pc
+ o(0xe5900000 | (intr(r)<<12) | (intr(r)<<16)); // ldr rx,[rx]
if (sv->c.i)
- stuff_const_harder(S, 0xe2800000 | (intr(S, r)<<12) | (intr(S, r)<<16),
+ stuff_const_harder(0xe2800000 | (intr(r)<<12) | (intr(r)<<16),
sv->c.i);
}
}
else
- o(S, sv->c.i);
+ o(sv->c.i);
#endif
}
/* load 'r' from value 'sv' */
-void load(TCCState* S, int r, SValue *sv)
+void load(int r, SValue *sv)
{
int v, ft, fc, fr, sign;
uint32_t op;
@@ -587,7 +594,7 @@ void load(TCCState* S, int r, SValue *sv)
v1.type.t = VT_PTR;
v1.r = VT_LOCAL | VT_LVAL;
v1.c.i = sv->c.i;
- load(S, TREG_LR, &v1);
+ load(TREG_LR, &v1);
base = 14; /* lr */
fc=sign=0;
v=VT_LOCAL;
@@ -596,25 +603,25 @@ void load(TCCState* S, int r, SValue *sv)
v1.r = fr&~VT_LVAL;
v1.c.i = sv->c.i;
v1.sym=sv->sym;
- load(S, TREG_LR, &v1);
+ load(TREG_LR, &v1);
base = 14; /* lr */
fc=sign=0;
v=VT_LOCAL;
} else if(v < VT_CONST) {
- base=intr(S, v);
+ base=intr(v);
fc=sign=0;
v=VT_LOCAL;
}
if(v == VT_LOCAL) {
if(is_float(ft)) {
- calcaddr(S, &base,&fc,&sign,1020,2);
+ calcaddr(&base,&fc,&sign,1020,2);
#ifdef TCC_ARM_VFP
op=0xED100A00; /* flds */
if(!sign)
op|=0x800000;
if ((ft & VT_BTYPE) != VT_FLOAT)
op|=0x100; /* flds -> fldd */
- o(S, op|(vfpr(S, r)<<12)|(fc>>2)|(base<<16));
+ o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16));
#else
op=0xED100100;
if(!sign)
@@ -628,11 +635,11 @@ void load(TCCState* S, int r, SValue *sv)
else if ((ft & VT_BTYPE) == VT_LDOUBLE)
op|=0x400000;
#endif
- o(S, op|(fpr(S, r)<<12)|(fc>>2)|(base<<16));
+ o(op|(fpr(r)<<12)|(fc>>2)|(base<<16));
#endif
} else if((ft & (VT_BTYPE|VT_UNSIGNED)) == VT_BYTE
|| (ft & VT_BTYPE) == VT_SHORT) {
- calcaddr(S, &base,&fc,&sign,255,0);
+ calcaddr(&base,&fc,&sign,255,0);
op=0xE1500090;
if ((ft & VT_BTYPE) == VT_SHORT)
op|=0x20;
@@ -640,63 +647,63 @@ void load(TCCState* S, int r, SValue *sv)
op|=0x40;
if(!sign)
op|=0x800000;
- o(S, op|(intr(S, r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
+ o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
} else {
- calcaddr(S, &base,&fc,&sign,4095,0);
+ calcaddr(&base,&fc,&sign,4095,0);
op=0xE5100000;
if(!sign)
op|=0x800000;
if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL)
op|=0x400000;
- o(S, op|(intr(S, r)<<12)|fc|(base<<16));
+ o(op|(intr(r)<<12)|fc|(base<<16));
}
return;
}
} else {
if (v == VT_CONST) {
- op=stuff_const(0xE3A00000|(intr(S, r)<<12),sv->c.i);
+ op=stuff_const(0xE3A00000|(intr(r)<<12),sv->c.i);
if (fr & VT_SYM || !op)
- load_value(S, sv, r);
+ load_value(sv, r);
else
- o(S, op);
+ o(op);
return;
} else if (v == VT_LOCAL) {
- op=stuff_const(0xE28B0000|(intr(S, r)<<12),sv->c.i);
+ op=stuff_const(0xE28B0000|(intr(r)<<12),sv->c.i);
if (fr & VT_SYM || !op) {
- load_value(S, sv, r);
- o(S, 0xE08B0000|(intr(S, r)<<12)|intr(S, r));
+ load_value(sv, r);
+ o(0xE08B0000|(intr(r)<<12)|intr(r));
} else
- o(S, op);
+ o(op);
return;
} else if(v == VT_CMP) {
- o(S, mapcc(S, sv->c.i)|0x3A00001|(intr(S, r)<<12));
- o(S, mapcc(S, negcc(S, sv->c.i))|0x3A00000|(intr(S, r)<<12));
+ o(mapcc(sv->c.i)|0x3A00001|(intr(r)<<12));
+ o(mapcc(negcc(sv->c.i))|0x3A00000|(intr(r)<<12));
return;
} else if (v == VT_JMP || v == VT_JMPI) {
int t;
t = v & 1;
- o(S, 0xE3A00000|(intr(S, r)<<12)|t);
- o(S, 0xEA000000);
- gsym(S, sv->c.i);
- o(S, 0xE3A00000|(intr(S, r)<<12)|(t^1));
+ o(0xE3A00000|(intr(r)<<12)|t);
+ o(0xEA000000);
+ gsym(sv->c.i);
+ o(0xE3A00000|(intr(r)<<12)|(t^1));
return;
} else if (v < VT_CONST) {
if(is_float(ft))
#ifdef TCC_ARM_VFP
- o(S, 0xEEB00A40|(vfpr(S, r)<<12)|vfpr(S, v)|T2CPR(ft)); /* fcpyX */
+ o(0xEEB00A40|(vfpr(r)<<12)|vfpr(v)|T2CPR(ft)); /* fcpyX */
#else
- o(S, 0xEE008180|(fpr(S, r)<<12)|fpr(S, v));
+ o(0xEE008180|(fpr(r)<<12)|fpr(v));
#endif
else
- o(S, 0xE1A00000|(intr(S, r)<<12)|intr(S, v));
+ o(0xE1A00000|(intr(r)<<12)|intr(v));
return;
}
}
- tcc_error(S, "load unimplemented!");
+ tcc_error("load unimplemented!");
}
/* store register 'r' in lvalue 'v' */
-void store(TCCState* S, int r, SValue *sv)
+void store(int r, SValue *sv)
{
SValue v1;
int v, ft, fc, fr, sign;
@@ -717,7 +724,7 @@ void store(TCCState* S, int r, SValue *sv)
if (fr & VT_LVAL || fr == VT_LOCAL) {
uint32_t base = 0xb; /* fp */
if(v < VT_CONST) {
- base=intr(S, v);
+ base=intr(v);
v=VT_LOCAL;
fc=sign=0;
} else if(v == VT_CONST) {
@@ -725,21 +732,21 @@ void store(TCCState* S, int r, SValue *sv)
v1.r = fr&~VT_LVAL;
v1.c.i = sv->c.i;
v1.sym=sv->sym;
- load(S, TREG_LR, &v1);
+ load(TREG_LR, &v1);
base = 14; /* lr */
fc=sign=0;
v=VT_LOCAL;
}
if(v == VT_LOCAL) {
if(is_float(ft)) {
- calcaddr(S, &base,&fc,&sign,1020,2);
+ calcaddr(&base,&fc,&sign,1020,2);
#ifdef TCC_ARM_VFP
op=0xED000A00; /* fsts */
if(!sign)
op|=0x800000;
if ((ft & VT_BTYPE) != VT_FLOAT)
op|=0x100; /* fsts -> fstd */
- o(S, op|(vfpr(S, r)<<12)|(fc>>2)|(base<<16));
+ o(op|(vfpr(r)<<12)|(fc>>2)|(base<<16));
#else
op=0xED000100;
if(!sign)
@@ -753,138 +760,138 @@ void store(TCCState* S, int r, SValue *sv)
if ((ft & VT_BTYPE) == VT_LDOUBLE)
op|=0x400000;
#endif
- o(S, op|(fpr(S, r)<<12)|(fc>>2)|(base<<16));
+ o(op|(fpr(r)<<12)|(fc>>2)|(base<<16));
#endif
return;
} else if((ft & VT_BTYPE) == VT_SHORT) {
- calcaddr(S, &base,&fc,&sign,255,0);
+ calcaddr(&base,&fc,&sign,255,0);
op=0xE14000B0;
if(!sign)
op|=0x800000;
- o(S, op|(intr(S, r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
+ o(op|(intr(r)<<12)|(base<<16)|((fc&0xf0)<<4)|(fc&0xf));
} else {
- calcaddr(S, &base,&fc,&sign,4095,0);
+ calcaddr(&base,&fc,&sign,4095,0);
op=0xE5000000;
if(!sign)
op|=0x800000;
if ((ft & VT_BTYPE) == VT_BYTE || (ft & VT_BTYPE) == VT_BOOL)
op|=0x400000;
- o(S, op|(intr(S, r)<<12)|fc|(base<<16));
+ o(op|(intr(r)<<12)|fc|(base<<16));
}
return;
}
}
- tcc_error(S, "store unimplemented");
+ tcc_error("store unimplemented");
}
-static void gadd_sp(TCCState* S, int val)
+static void gadd_sp(int val)
{
- stuff_const_harder(S, 0xE28DD000,val);
+ stuff_const_harder(0xE28DD000,val);
}
/* 'is_jmp' is '1' if it is a jump */
-static void gcall_or_jmp(TCCState* S, int is_jmp)
+static void gcall_or_jmp(int is_jmp)
{
int r;
uint32_t x;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* constant case */
- if(S->tccgen_vtop->r & VT_SYM){
- x=encbranch(S, S->tccgen_ind, S->tccgen_ind+S->tccgen_vtop->c.i,0);
+ if(vtop->r & VT_SYM){
+ x=encbranch(ind,ind+vtop->c.i,0);
if(x) {
/* relocation case */
- greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind, R_ARM_PC24);
- o(S, x|(is_jmp?0xE0000000:0xE1000000));
+ greloc(cur_text_section, vtop->sym, ind, R_ARM_PC24);
+ o(x|(is_jmp?0xE0000000:0xE1000000));
} else {
r = TREG_LR;
- load_value(S, S->tccgen_vtop, r);
+ load_value(vtop, r);
if(is_jmp)
- o(S, 0xE1A0F000 | intr(S, r)); // mov pc, r
+ o(0xE1A0F000 | intr(r)); // mov pc, r
else
- o(S, 0xe12fff30 | intr(S, r)); // blx r
+ o(0xe12fff30 | intr(r)); // blx r
}
}else{
if(!is_jmp)
- o(S, 0xE28FE004); // add lr,pc,#4
- o(S, 0xE51FF004); // ldr pc,[pc,#-4]
- o(S, S->tccgen_vtop->c.i);
+ o(0xE28FE004); // add lr,pc,#4
+ o(0xE51FF004); // ldr pc,[pc,#-4]
+ o(vtop->c.i);
}
} else {
/* otherwise, indirect call */
#ifdef CONFIG_TCC_BCHECK
- S->tccgen_vtop->r &= ~VT_MUSTBOUND;
+ vtop->r &= ~VT_MUSTBOUND;
#endif
- r = gv(S, RC_INT);
+ r = gv(RC_INT);
if(!is_jmp)
- o(S, 0xE1A0E00F); // mov lr,pc
- o(S, 0xE1A0F000|intr(S, r)); // mov pc,r
+ o(0xE1A0E00F); // mov lr,pc
+ o(0xE1A0F000|intr(r)); // mov pc,r
}
}
#if defined(CONFIG_TCC_BCHECK)
-static void gen_bounds_call(TCCState* S, int v)
+static void gen_bounds_call(int v)
{
- Sym *sym = external_helper_sym(S, v);
+ Sym *sym = external_helper_sym(v);
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_ARM_PC24);
- o(S, 0xebfffffe);
+ greloc(cur_text_section, sym, ind, R_ARM_PC24);
+ o(0xebfffffe);
}
-static void gen_bounds_prolog(TCCState* S)
+static void gen_bounds_prolog(void)
{
/* leave some room for bound checking code */
- S->func_bound_offset = lbounds_section->data_offset;
- S->func_bound_ind = S->tccgen_ind;
- S->func_bound_add_epilog = 0;
- o(S, 0xe1a00000); /* ld r0,lbounds_section->data_offset */
- o(S, 0xe1a00000);
- o(S, 0xe1a00000);
- o(S, 0xe1a00000);
- o(S, 0xe1a00000); /* call __bound_local_new */
+ func_bound_offset = lbounds_section->data_offset;
+ func_bound_ind = ind;
+ func_bound_add_epilog = 0;
+ o(0xe1a00000); /* ld r0,lbounds_section->data_offset */
+ o(0xe1a00000);
+ o(0xe1a00000);
+ o(0xe1a00000);
+ o(0xe1a00000); /* call __bound_local_new */
}
-static void gen_bounds_epilog(TCCState* S)
+static void gen_bounds_epilog(void)
{
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
- int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
- if (!offset_modified && !S->func_bound_add_epilog)
+ if (!offset_modified && !func_bound_add_epilog)
return;
/* add end of table info */
- bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
- sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
- S->func_bound_offset, lbounds_section->data_offset);
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
+ func_bound_offset, lbounds_section->data_offset);
/* generate bound local allocation */
if (offset_modified) {
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->func_bound_ind;
- o(S, 0xe59f0000); /* ldr r0, [pc] */
- o(S, 0xea000000); /* b $+4 */
- greloc(S, cur_text_section, sym_data, S->tccgen_ind, R_ARM_REL32);
- o(S, -12); /* lbounds_section->data_offset */
- o(S, 0xe080000f); /* add r0,r0,pc */
- gen_bounds_call(S, TOK___bound_local_new);
- S->tccgen_ind = saved_ind;
+ saved_ind = ind;
+ ind = func_bound_ind;
+ o(0xe59f0000); /* ldr r0, [pc] */
+ o(0xea000000); /* b $+4 */
+ greloc(cur_text_section, sym_data, ind, R_ARM_REL32);
+ o(-12); /* lbounds_section->data_offset */
+ o(0xe080000f); /* add r0,r0,pc */
+ gen_bounds_call(TOK___bound_local_new);
+ ind = saved_ind;
}
/* generate bound check local freeing */
- o(S, 0xe92d0003); /* push {r0,r1} */
- o(S, 0xed2d0b02); /* vpush {d0} */
- o(S, 0xe59f0000); /* ldr r0, [pc] */
- o(S, 0xea000000); /* b $+4 */
- greloc(S, cur_text_section, sym_data, S->tccgen_ind, R_ARM_REL32);
- o(S, -12); /* lbounds_section->data_offset */
- o(S, 0xe080000f); /* add r0,r0,pc */
- gen_bounds_call(S, TOK___bound_local_delete);
- o(S, 0xecbd0b02); /* vpop {d0} */
- o(S, 0xe8bd0003); /* pop {r0,r1} */
+ o(0xe92d0003); /* push {r0,r1} */
+ o(0xed2d0b02); /* vpush {d0} */
+ o(0xe59f0000); /* ldr r0, [pc] */
+ o(0xea000000); /* b $+4 */
+ greloc(cur_text_section, sym_data, ind, R_ARM_REL32);
+ o(-12); /* lbounds_section->data_offset */
+ o(0xe080000f); /* add r0,r0,pc */
+ gen_bounds_call(TOK___bound_local_delete);
+ o(0xecbd0b02); /* vpop {d0} */
+ o(0xe8bd0003); /* pop {r0,r1} */
}
#endif
@@ -1070,7 +1077,7 @@ static void add_param_plan(struct plan* plan, int cls, int start, int end, SValu
Note: this function allocated an array in plan->pplans with tcc_malloc. It
is the responsibility of the caller to free this array once used (ie not
before copy_params). */
-static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *plan, int *todo)
+static int assign_regs(int nb_args, int float_abi, struct plan *plan, int *todo)
{
int i, size, align;
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
for(i = nb_args; i-- ;) {
int j, start_vfpreg = 0;
- CType type = S->tccgen_vtop[-i].type;
+ CType type = vtop[-i].type;
type.t &= ~VT_ARRAY;
size = type_size(&type, &align);
size = (size + 3) & ~3;
align = (align + 3) & ~3;
- switch(S->tccgen_vtop[-i].type.t & VT_BTYPE) {
+ switch(vtop[-i].type.t & VT_BTYPE) {
case VT_STRUCT:
case VT_FLOAT:
case VT_DOUBLE:
@@ -1094,15 +1101,15 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla
if (float_abi == ARM_HARD_FLOAT) {
int is_hfa = 0; /* Homogeneous float aggregate */
- if (is_float(S->tccgen_vtop[-i].type.t)
- || (is_hfa = is_hgen_float_aggr(&S->tccgen_vtop[-i].type))) {
+ if (is_float(vtop[-i].type.t)
+ || (is_hfa = is_hgen_float_aggr(&vtop[-i].type))) {
int end_vfpreg;
start_vfpreg = assign_vfpreg(&avregs, align, size);
end_vfpreg = start_vfpreg + ((size - 1) >> 2);
if (start_vfpreg >= 0) {
add_param_plan(plan, is_hfa ? VFP_STRUCT_CLASS : VFP_CLASS,
- start_vfpreg, end_vfpreg, &S->tccgen_vtop[-i]);
+ start_vfpreg, end_vfpreg, &vtop[-i]);
continue;
} else
break;
@@ -1115,7 +1122,7 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla
* CORE_STRUCT_CLASS or the first of STACK_CLASS. */
for (j = ncrn; j < 4 && j < ncrn + size / 4; j++)
*todo|=(1<<j);
- add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &S->tccgen_vtop[-i]);
+ add_param_plan(plan, CORE_STRUCT_CLASS, ncrn, j, &vtop[-i]);
ncrn += size/4;
if (ncrn > 4)
nsaa = (ncrn - 4) * 4;
@@ -1126,20 +1133,20 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla
continue;
default:
if (ncrn < 4) {
- int is_long = (S->tccgen_vtop[-i].type.t & VT_BTYPE) == VT_LLONG;
+ int is_long = (vtop[-i].type.t & VT_BTYPE) == VT_LLONG;
if (is_long) {
ncrn = (ncrn + 1) & -2;
if (ncrn == 4)
break;
}
- add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &S->tccgen_vtop[-i]);
+ add_param_plan(plan, CORE_CLASS, ncrn, ncrn + is_long, &vtop[-i]);
ncrn += 1 + is_long;
continue;
}
}
nsaa = (nsaa + (align - 1)) & ~(align - 1);
- add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &S->tccgen_vtop[-i]);
+ add_param_plan(plan, STACK_CLASS, nsaa, nsaa + size, &vtop[-i]);
nsaa += size; /* size already rounded up before */
}
return nsaa;
@@ -1153,7 +1160,7 @@ static int assign_regs(TCCState *S, int nb_args, int float_abi, struct plan *pla
todo: a bitmap indicating what core reg will hold a parameter
Returns the number of SValue added by this function on the value stack */
-static int copy_params(TCCState* S, int nb_args, struct plan *plan, int todo)
+static int copy_params(int nb_args, struct plan *plan, int todo)
{
int size, align, r, i, nb_extra_sval = 0;
struct param_plan *pplan;
@@ -1182,7 +1189,7 @@ again:
&& (i != CORE_CLASS || pplan->sval->r < VT_CONST))
continue;
- vpushv(S, pplan->sval);
+ vpushv(pplan->sval);
pplan->sval->r = pplan->sval->r2 = VT_CONST; /* disable entry */
switch(i) {
case STACK_CLASS:
@@ -1197,16 +1204,16 @@ again:
padding = pplan->start - pplan->prev->end;
size += padding; /* Add padding if any */
/* allocate the necessary size on stack */
- gadd_sp(S, -size);
+ gadd_sp(-size);
/* generate structure store */
- r = get_reg(S, RC_INT);
- o(S, 0xE28D0000|(intr(S, r)<<12)|padding); /* add r, sp, padding */
- vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
- vswap(S);
+ r = get_reg(RC_INT);
+ o(0xE28D0000|(intr(r)<<12)|padding); /* add r, sp, padding */
+ vset(&vtop->type, r | VT_LVAL, 0);
+ vswap();
/* XXX: optimize. Save all register because memcpy can use them */
- o(S, 0xED2D0A00|(0&1)<<22|(0>>1)<<12|16); /* vpush {s0-s15} */
- vstore(S); /* memcpy to current sp + potential padding */
- o(S, 0xECBD0A00|(0&1)<<22|(0>>1)<<12|16); /* vpop {s0-s15} */
+ o(0xED2D0A00|(0&1)<<22|(0>>1)<<12|16); /* vpush {s0-s15} */
+ vstore(); /* memcpy to current sp + potential padding */
+ o(0xECBD0A00|(0&1)<<22|(0>>1)<<12|16); /* vpop {s0-s15} */
/* Homogeneous float aggregate are loaded to VFP registers
immediately since there is no way of loading data in multiple
@@ -1215,23 +1222,23 @@ again:
if (i == VFP_STRUCT_CLASS) {
int first = pplan->start, nb = pplan->end - first + 1;
/* vpop.32 {pplan->start, ..., pplan->end} */
- o(S, 0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb);
+ o(0xECBD0A00|(first&1)<<22|(first>>1)<<12|nb);
/* No need to write the register used to a SValue since VFP regs
cannot be used for gcall_or_jmp */
}
} else {
if (is_float(pplan->sval->type.t)) {
#ifdef TCC_ARM_VFP
- r = vfpr(S, gv(S, RC_FLOAT)) << 12;
+ r = vfpr(gv(RC_FLOAT)) << 12;
if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT)
size = 4;
else {
size = 8;
r |= 0x101; /* vpush.32 -> vpush.64 */
}
- o(S, 0xED2D0A01 + r); /* vpush */
+ o(0xED2D0A01 + r); /* vpush */
#else
- r = fpr(S, gv(S, RC_FLOAT)) << 12;
+ r = fpr(gv(RC_FLOAT)) << 12;
if ((pplan->sval->type.t & VT_BTYPE) == VT_FLOAT)
size = 4;
else if ((pplan->sval->type.t & VT_BTYPE) == VT_DOUBLE)
@@ -1244,49 +1251,49 @@ again:
else if(size == 8)
r|=0x8000;
- o(S, 0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */
+ o(0xED2D0100|r|(size>>2)); /* some kind of vpush for FPA */
#endif
} else {
/* simple type (currently always same size) */
/* XXX: implicit cast ? */
size=4;
if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) {
- lexpand(S);
+ lexpand();
size = 8;
- r = gv(S, RC_INT);
- o(S, 0xE52D0004|(intr(S, r)<<12)); /* push r */
- S->tccgen_vtop--;
+ r = gv(RC_INT);
+ o(0xE52D0004|(intr(r)<<12)); /* push r */
+ vtop--;
}
- r = gv(S, RC_INT);
- o(S, 0xE52D0004|(intr(S, r)<<12)); /* push r */
+ r = gv(RC_INT);
+ o(0xE52D0004|(intr(r)<<12)); /* push r */
}
if (i == STACK_CLASS && pplan->prev)
- gadd_sp(S, pplan->prev->end - pplan->start); /* Add padding if any */
+ gadd_sp(pplan->prev->end - pplan->start); /* Add padding if any */
}
break;
case VFP_CLASS:
- gv(S, regmask(S, TREG_F0 + (pplan->start >> 1)));
+ gv(regmask(TREG_F0 + (pplan->start >> 1)));
if (pplan->start & 1) { /* Must be in upper part of double register */
- o(S, 0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */
- S->tccgen_vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */
+ o(0xEEF00A40|((pplan->start>>1)<<12)|(pplan->start>>1)); /* vmov.f32 s(n+1), sn */
+ vtop->r = VT_CONST; /* avoid being saved on stack by gv for next float */
}
break;
case CORE_CLASS:
if ((pplan->sval->type.t & VT_BTYPE) == VT_LLONG) {
- lexpand(S);
- gv(S, regmask(S, pplan->end));
- pplan->sval->r2 = S->tccgen_vtop->r;
- S->tccgen_vtop--;
+ lexpand();
+ gv(regmask(pplan->end));
+ pplan->sval->r2 = vtop->r;
+ vtop--;
}
- gv(S, regmask(S, pplan->start));
+ gv(regmask(pplan->start));
/* Mark register as used so that gcall_or_jmp use another one
(regs >=4 are free as never used to pass parameters) */
- pplan->sval->r = S->tccgen_vtop->r;
+ pplan->sval->r = vtop->r;
break;
}
- S->tccgen_vtop--;
+ vtop--;
}
}
@@ -1297,10 +1304,10 @@ again:
/* Manually free remaining registers since next parameters are loaded
* manually, without the help of gv(int). */
- save_regs(S, nb_args);
+ save_regs(nb_args);
if(todo) {
- o(S, 0xE8BD0000|todo); /* pop {todo} */
+ o(0xE8BD0000|todo); /* pop {todo} */
for(pplan = plan->clsplans[CORE_STRUCT_CLASS]; pplan; pplan = pplan->prev) {
int r;
pplan->sval->r = pplan->start;
@@ -1311,8 +1318,8 @@ again:
for (r = pplan->start + 1; r <= pplan->end; r++) {
if (todo & (1 << r)) {
nb_extra_sval++;
- vpushi(S, 0);
- S->tccgen_vtop->r = r;
+ vpushi(0);
+ vtop->r = r;
}
}
}
@@ -1323,7 +1330,7 @@ again:
/* Generate function call. The function address is pushed first, then
all the parameters in call order. This functions pops all the
parameters and the function address. */
-void gfunc_call(TCCState* S, int nb_args)
+void gfunc_call(int nb_args)
{
int r, args_size;
int def_float_abi = float_abi;
@@ -1334,62 +1341,62 @@ void gfunc_call(TCCState* S, int nb_args)
#endif
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
#ifdef TCC_ARM_EABI
if (float_abi == ARM_HARD_FLOAT) {
- variadic = (S->tccgen_vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS);
- if (variadic || floats_in_core_regs(&S->tccgen_vtop[-nb_args]))
+ variadic = (vtop[-nb_args].type.ref->f.func_type == FUNC_ELLIPSIS);
+ if (variadic || floats_in_core_regs(&vtop[-nb_args]))
float_abi = ARM_SOFTFP_FLOAT;
}
#endif
/* cannot let cpu flags if other instruction are generated. Also avoid leaving
VT_JMP anywhere except on the top of the stack because it would complicate
the code generator. */
- r = S->tccgen_vtop->r & VT_VALMASK;
+ r = vtop->r & VT_VALMASK;
if (r == VT_CMP || (r & ~1) == VT_JMP)
- gv(S, RC_INT);
+ gv(RC_INT);
memset(&plan, 0, sizeof plan);
if (nb_args)
- plan.pplans = tcc_malloc(S, nb_args * sizeof(*plan.pplans));
+ plan.pplans = tcc_malloc(nb_args * sizeof(*plan.pplans));
- args_size = assign_regs(S, nb_args, float_abi, &plan, &todo);
+ args_size = assign_regs(nb_args, float_abi, &plan, &todo);
#ifdef TCC_ARM_EABI
if (args_size & 7) { /* Stack must be 8 byte aligned at fct call for EABI */
args_size = (args_size + 7) & ~7;
- o(S, 0xE24DD004); /* sub sp, sp, #4 */
+ o(0xE24DD004); /* sub sp, sp, #4 */
}
#endif
- nb_args += copy_params(S, nb_args, &plan, todo);
- tcc_free(S, plan.pplans);
+ nb_args += copy_params(nb_args, &plan, todo);
+ tcc_free(plan.pplans);
/* Move fct SValue on top as required by gcall_or_jmp */
- vrotb(S, nb_args + 1);
- gcall_or_jmp(S, 0);
+ vrotb(nb_args + 1);
+ gcall_or_jmp(0);
if (args_size)
- gadd_sp(S, args_size); /* pop all parameters passed on the stack */
+ gadd_sp(args_size); /* pop all parameters passed on the stack */
#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
- if(float_abi == ARM_SOFTFP_FLOAT && is_float(S->tccgen_vtop->type.ref->type.t)) {
- if((S->tccgen_vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) {
- o(S, 0xEE000A10); /*vmov s0, r0 */
+ if(float_abi == ARM_SOFTFP_FLOAT && is_float(vtop->type.ref->type.t)) {
+ if((vtop->type.ref->type.t & VT_BTYPE) == VT_FLOAT) {
+ o(0xEE000A10); /*vmov s0, r0 */
} else {
- o(S, 0xEE000B10); /* vmov.32 d0[0], r0 */
- o(S, 0xEE201B10); /* vmov.32 d0[1], r1 */
+ o(0xEE000B10); /* vmov.32 d0[0], r0 */
+ o(0xEE201B10); /* vmov.32 d0[1], r1 */
}
}
#endif
- S->tccgen_vtop -= nb_args + 1; /* Pop all params and fct address from value stack */
+ vtop -= nb_args + 1; /* Pop all params and fct address from value stack */
leaffunc = 0; /* we are calling a function, so we aren't in a leaf function */
float_abi = def_float_abi;
}
/* generate function prolog of type 't' */
-void gfunc_prolog(TCCState* S, Sym *func_sym)
+void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
Sym *sym,*sym2;
@@ -1404,17 +1411,17 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
sym = func_type->ref;
n = nf = 0;
- if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT &&
- !gfunc_sret(&S->tccgen_func_vt, S->tccgen_func_var, &ret_type, &align, &rs))
+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT &&
+ !gfunc_sret(&func_vt, func_var, &ret_type, &align, &rs))
{
n++;
struct_ret = 1;
- S->tccgen_func_vc = 12; /* Offset from fp of the place to store the result */
+ func_vc = 12; /* Offset from fp of the place to store the result */
}
for(sym2 = sym->next; sym2 && (n < 4 || nf < 16); sym2 = sym2->next) {
size = type_size(&sym2->type, &align);
#ifdef TCC_ARM_EABI
- if (float_abi == ARM_HARD_FLOAT && !S->tccgen_func_var &&
+ if (float_abi == ARM_HARD_FLOAT && !func_var &&
(is_float(sym2->type.t) || is_hgen_float_aggr(&sym2->type))) {
int tmpnf = assign_vfpreg(&avregs, align, size);
tmpnf += (size + 3) / 4;
@@ -1424,8 +1431,8 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
if (n < 4)
n += (size + 3) / 4;
}
- o(S, 0xE1A0C00D); /* mov ip,sp */
- if (S->tccgen_func_var)
+ o(0xE1A0C00D); /* mov ip,sp */
+ if (func_var)
n=4;
if (n) {
if(n>4)
@@ -1433,22 +1440,22 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
#ifdef TCC_ARM_EABI
n=(n+1)&-2;
#endif
- o(S, 0xE92D0000|((1<<n)-1)); /* save r0-r4 on stack if needed */
+ o(0xE92D0000|((1<<n)-1)); /* save r0-r4 on stack if needed */
}
if (nf) {
if (nf>16)
nf=16;
nf=(nf+1)&-2; /* nf => HARDFLOAT => EABI */
- o(S, 0xED2D0A00|nf); /* save s0-s15 on stack if needed */
+ o(0xED2D0A00|nf); /* save s0-s15 on stack if needed */
}
- o(S, 0xE92D5800); /* save fp, ip, lr */
- o(S, 0xE1A0B00D); /* mov fp, sp */
- func_sub_sp_offset = S->tccgen_ind;
- o(S, 0xE1A00000); /* nop, leave space for stack adjustment in epilog */
+ o(0xE92D5800); /* save fp, ip, lr */
+ o(0xE1A0B00D); /* mov fp, sp */
+ func_sub_sp_offset = ind;
+ o(0xE1A00000); /* nop, leave space for stack adjustment in epilog */
#ifdef TCC_ARM_EABI
if (float_abi == ARM_HARD_FLOAT) {
- S->tccgen_func_vc += nf * 4;
+ func_vc += nf * 4;
memset(&avregs, 0, sizeof avregs);
}
#endif
@@ -1460,7 +1467,7 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
size = (size + 3) >> 2;
align = (align + 3) & ~3;
#ifdef TCC_ARM_EABI
- if (float_abi == ARM_HARD_FLOAT && !S->tccgen_func_var && (is_float(sym->type.t)
+ if (float_abi == ARM_HARD_FLOAT && !func_var && (is_float(sym->type.t)
|| is_hgen_float_aggr(&sym->type))) {
int fpn = assign_vfpreg(&avregs, align, size << 2);
if (fpn >= 0)
@@ -1485,42 +1492,42 @@ from_stack:
addr = (n + nf + sn) * 4;
sn += size;
}
- sym_push(S, sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL,
+ sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL,
addr + 12);
}
last_itod_magic=0;
leaffunc = 1;
- S->tccgen_loc = 0;
+ loc = 0;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
/* generate function epilog */
-void gfunc_epilog(TCCState* S)
+void gfunc_epilog(void)
{
uint32_t x;
int diff;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
/* Copy float return value to core register if base standard is used and
float computation is made with VFP */
#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)
- if ((float_abi == ARM_SOFTFP_FLOAT || S->tccgen_func_var) && is_float(S->tccgen_func_vt.t)) {
- if((S->tccgen_func_vt.t & VT_BTYPE) == VT_FLOAT)
- o(S, 0xEE100A10); /* fmrs r0, s0 */
+ if ((float_abi == ARM_SOFTFP_FLOAT || func_var) && is_float(func_vt.t)) {
+ if((func_vt.t & VT_BTYPE) == VT_FLOAT)
+ o(0xEE100A10); /* fmrs r0, s0 */
else {
- o(S, 0xEE100B10); /* fmrdl r0, d0 */
- o(S, 0xEE301B10); /* fmrdh r1, d0 */
+ o(0xEE100B10); /* fmrdl r0, d0 */
+ o(0xEE301B10); /* fmrdh r1, d0 */
}
}
#endif
- o(S, 0xE89BA800); /* restore fp, sp, pc */
- diff = (-S->tccgen_loc + 3) & -4;
+ o(0xE89BA800); /* restore fp, sp, pc */
+ diff = (-loc + 3) & -4;
#ifdef TCC_ARM_EABI
if(!leaffunc)
diff = ((diff + 11) & -8) - 4;
@@ -1531,74 +1538,74 @@ void gfunc_epilog(TCCState* S)
*(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = x;
else {
int addr;
- addr=S->tccgen_ind;
- o(S, 0xE59FC004); /* ldr ip,[pc+4] */
- o(S, 0xE04BD00C); /* sub sp,fp,ip */
- o(S, 0xE1A0F00E); /* mov pc,lr */
- o(S, diff);
- *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(S, func_sub_sp_offset,addr,1);
+ addr=ind;
+ o(0xE59FC004); /* ldr ip,[pc+4] */
+ o(0xE04BD00C); /* sub sp,fp,ip */
+ o(0xE1A0F00E); /* mov pc,lr */
+ o(diff);
+ *(uint32_t *)(cur_text_section->data + func_sub_sp_offset) = 0xE1000000|encbranch(func_sub_sp_offset,addr,1);
}
}
}
-ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
if ((bytes & 3))
- tcc_error(S, "alignment of code section not multiple of 4");
+ tcc_error("alignment of code section not multiple of 4");
while (bytes > 0) {
- o(S, 0xE1A00000);
+ o(0xE1A00000);
bytes -= 4;
}
}
/* generate a jump to a label */
-ST_FUNC int gjmp(TCCState* S, int t)
+ST_FUNC int gjmp(int t)
{
int r;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return t;
- r=S->tccgen_ind;
- o(S, 0xE0000000|encbranch(S, r,t,1));
+ r=ind;
+ o(0xE0000000|encbranch(r,t,1));
return r;
}
/* generate a jump to a fixed address */
-ST_FUNC void gjmp_addr(TCCState* S, int a)
+ST_FUNC void gjmp_addr(int a)
{
- gjmp(S, a);
+ gjmp(a);
}
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
int r;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return t;
- r=S->tccgen_ind;
- op=mapcc(S, op);
- op|=encbranch(S, r,t,1);
- o(S, op);
+ r=ind;
+ op=mapcc(op);
+ op|=encbranch(r,t,1);
+ o(op);
return r;
}
-ST_FUNC int gjmp_append(TCCState* S, int n, int t)
+ST_FUNC int gjmp_append(int n, int t)
{
uint32_t *x;
int p,lp;
if(n) {
p = n;
do {
- p = decbranch(S, lp=p);
+ p = decbranch(lp=p);
} while(p);
x = (uint32_t *)(cur_text_section->data + lp);
*x &= 0xff000000;
- *x |= encbranch(S, lp,t,1);
+ *x |= encbranch(lp,t,1);
t = n;
}
return t;
}
/* generate an integer binary operation */
-void gen_opi(TCCState* S, int op)
+void gen_opi(int op)
{
int c, func = 0;
uint32_t opc = 0, r, fr;
@@ -1643,11 +1650,11 @@ void gen_opi(TCCState* S, int op)
c=1;
break;
case '*':
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- o(S, 0xE0000090|(intr(S, r)<<16)|(intr(S, r)<<8)|intr(S, fr));
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ o(0xE0000090|(intr(r)<<16)|(intr(r)<<8)|intr(fr));
return;
case TOK_SHL:
opc = 0;
@@ -1689,12 +1696,12 @@ void gen_opi(TCCState* S, int op)
c=3;
break;
case TOK_UMULL:
- gv2(S, RC_INT, RC_INT);
- r=intr(S, S->tccgen_vtop[-1].r2=get_reg(S, RC_INT));
- c=S->tccgen_vtop[-1].r;
- S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, c));
- S->tccgen_vtop--;
- o(S, 0xE0800090|(r<<16)|(intr(S, S->tccgen_vtop->r)<<12)|(intr(S, c)<<8)|intr(S, S->tccgen_vtop[1].r));
+ gv2(RC_INT, RC_INT);
+ r=intr(vtop[-1].r2=get_reg(RC_INT));
+ c=vtop[-1].r;
+ vtop[-1].r=get_reg_ex(RC_INT,regmask(c));
+ vtop--;
+ o(0xE0800090|(r<<16)|(intr(vtop->r)<<12)|(intr(c)<<8)|intr(vtop[1].r));
return;
default:
opc = 0x15;
@@ -1703,128 +1710,128 @@ void gen_opi(TCCState* S, int op)
}
switch(c) {
case 1:
- if((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ if((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
if(opc == 4 || opc == 5 || opc == 0xc) {
- vswap(S);
+ vswap();
opc|=2; // sub -> rsb
}
}
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP ||
- (S->tccgen_vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
- gv(S, RC_INT);
- vswap(S);
- c=intr(S, gv(S, RC_INT));
- vswap(S);
+ if ((vtop->r & VT_VALMASK) == VT_CMP ||
+ (vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
+ gv(RC_INT);
+ vswap();
+ c=intr(gv(RC_INT));
+ vswap();
opc=0xE0000000|(opc<<20);
- if((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
uint32_t x;
- x=stuff_const(opc|0x2000000|(c<<16),S->tccgen_vtop->c.i);
+ x=stuff_const(opc|0x2000000|(c<<16),vtop->c.i);
if(x) {
if ((x & 0xfff00000) == 0xe3500000) // cmp rx,#c
- o(S, x);
+ o(x);
else {
- r=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, S->tccgen_vtop[-1].r)));
- o(S, x|(r<<12));
+ r=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r)));
+ o(x|(r<<12));
}
goto done;
}
}
- fr=intr(S, gv(S, RC_INT));
+ fr=intr(gv(RC_INT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- c=intr(S, gv(S, RC_INT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ c=intr(gv(RC_INT));
+ vswap();
}
#endif
if ((opc & 0xfff00000) == 0xe1500000) // cmp rx,ry
- o(S, opc|(c<<16)|fr);
+ o(opc|(c<<16)|fr);
else {
- 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)));
- o(S, opc|(c<<16)|(r<<12)|fr);
+ r=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r)));
+ o(opc|(c<<16)|(r<<12)|fr);
}
done:
- S->tccgen_vtop--;
+ vtop--;
if (op >= TOK_ULT && op <= TOK_GT)
- vset_VT_CMP(S, op);
+ vset_VT_CMP(op);
break;
case 2:
opc=0xE1A00000|(opc<<5);
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP ||
- (S->tccgen_vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
- gv(S, RC_INT);
- vswap(S);
- r=intr(S, gv(S, RC_INT));
- vswap(S);
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
- fr=intr(S, S->tccgen_vtop[-1].r=get_reg_ex(S, RC_INT,regmask(S, S->tccgen_vtop[-1].r)));
- c = S->tccgen_vtop->c.i & 0x1f;
- o(S, opc|r|(c<<7)|(fr<<12));
+ if ((vtop->r & VT_VALMASK) == VT_CMP ||
+ (vtop->r & (VT_VALMASK & ~1)) == VT_JMP)
+ gv(RC_INT);
+ vswap();
+ r=intr(gv(RC_INT));
+ vswap();
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ fr=intr(vtop[-1].r=get_reg_ex(RC_INT,regmask(vtop[-1].r)));
+ c = vtop->c.i & 0x1f;
+ o(opc|r|(c<<7)|(fr<<12));
} else {
- fr=intr(S, gv(S, RC_INT));
+ fr=intr(gv(RC_INT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=intr(S, gv(S, RC_INT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=intr(gv(RC_INT));
+ vswap();
}
#endif
- 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)));
- o(S, opc|r|(c<<12)|(fr<<8)|0x10);
+ c=intr(vtop[-1].r=get_reg_ex(RC_INT,two2mask(vtop->r,vtop[-1].r)));
+ o(opc|r|(c<<12)|(fr<<8)|0x10);
}
- S->tccgen_vtop--;
+ vtop--;
break;
case 3:
- vpush_helper_func(S, func);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = retreg;
+ vpush_helper_func(func);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = retreg;
break;
default:
- tcc_error(S, "gen_opi %i unimplemented!",op);
+ tcc_error("gen_opi %i unimplemented!",op);
}
}
#ifdef TCC_ARM_VFP
-static int is_zero(TCCState* S, int i)
+static int is_zero(int i)
{
- if((S->tccgen_vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
+ if((vtop[i].r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
return 0;
- if (S->tccgen_vtop[i].type.t == VT_FLOAT)
- return (S->tccgen_vtop[i].c.f == 0.f);
- else if (S->tccgen_vtop[i].type.t == VT_DOUBLE)
- return (S->tccgen_vtop[i].c.d == 0.0);
- return (S->tccgen_vtop[i].c.ld == 0.l);
+ if (vtop[i].type.t == VT_FLOAT)
+ return (vtop[i].c.f == 0.f);
+ else if (vtop[i].type.t == VT_DOUBLE)
+ return (vtop[i].c.d == 0.0);
+ return (vtop[i].c.ld == 0.l);
}
/* generate a floating point operation 'v = t1 op t2' instruction. The
* two operands are guaranteed to have the same floating point type */
-void gen_opf(TCCState* S, int op)
+void gen_opf(int op)
{
uint32_t x;
int fneg=0,r;
- x=0xEE000A00|T2CPR(S->tccgen_vtop->type.t);
+ x=0xEE000A00|T2CPR(vtop->type.t);
switch(op) {
case '+':
- if(is_zero(S, -1))
- vswap(S);
- if(is_zero(S, 0)) {
- S->tccgen_vtop--;
+ if(is_zero(-1))
+ vswap();
+ if(is_zero(0)) {
+ vtop--;
return;
}
x|=0x300000;
break;
case '-':
x|=0x300040;
- if(is_zero(S, 0)) {
- S->tccgen_vtop--;
+ if(is_zero(0)) {
+ vtop--;
return;
}
- if(is_zero(S, -1)) {
+ if(is_zero(-1)) {
x|=0x810000; /* fsubX -> fnegX */
- vswap(S);
- S->tccgen_vtop--;
+ vswap();
+ vtop--;
fneg=1;
}
break;
@@ -1836,11 +1843,11 @@ void gen_opf(TCCState* S, int op)
break;
default:
if(op < TOK_ULT || op > TOK_GT) {
- tcc_error(S, "unknown fp op %x!",op);
+ tcc_error("unknown fp op %x!",op);
return;
}
- if(is_zero(S, -1)) {
- vswap(S);
+ if(is_zero(-1)) {
+ vswap();
switch(op) {
case TOK_LT: op=TOK_GT; break;
case TOK_GE: op=TOK_ULE; break;
@@ -1851,16 +1858,16 @@ void gen_opf(TCCState* S, int op)
x|=0xB40040; /* fcmpX */
if(op!=TOK_EQ && op!=TOK_NE)
x|=0x80; /* fcmpX -> fcmpeX */
- if(is_zero(S, 0)) {
- S->tccgen_vtop--;
- o(S, x|0x10000|(vfpr(S, gv(S, RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */
+ if(is_zero(0)) {
+ vtop--;
+ o(x|0x10000|(vfpr(gv(RC_FLOAT))<<12)); /* fcmp(e)X -> fcmp(e)zX */
} else {
- gv2(S, RC_FLOAT,RC_FLOAT);
- x|=vfpr(S, S->tccgen_vtop[0].r);
- o(S, x|(vfpr(S, S->tccgen_vtop[-1].r) << 12));
- S->tccgen_vtop--;
+ gv2(RC_FLOAT,RC_FLOAT);
+ x|=vfpr(vtop[0].r);
+ o(x|(vfpr(vtop[-1].r) << 12));
+ vtop--;
}
- o(S, 0xEEF1FA10); /* fmstat */
+ o(0xEEF1FA10); /* fmstat */
switch(op) {
case TOK_LE: op=TOK_ULE; break;
@@ -1868,46 +1875,46 @@ void gen_opf(TCCState* S, int op)
case TOK_UGE: op=TOK_GE; break;
case TOK_UGT: op=TOK_GT; break;
}
- vset_VT_CMP(S, op);
+ vset_VT_CMP(op);
return;
}
- r=gv(S, RC_FLOAT);
- x|=vfpr(S, r);
- r=regmask(S, r);
+ r=gv(RC_FLOAT);
+ x|=vfpr(r);
+ r=regmask(r);
if(!fneg) {
int r2;
- vswap(S);
- r2=gv(S, RC_FLOAT);
- x|=vfpr(S, r2)<<16;
- r|=regmask(S, r2);
+ vswap();
+ r2=gv(RC_FLOAT);
+ x|=vfpr(r2)<<16;
+ r|=regmask(r2);
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=gv(S, RC_FLOAT);
- vswap(S);
- x=(x&~0xf)|vfpr(S, r);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=gv(RC_FLOAT);
+ vswap();
+ x=(x&~0xf)|vfpr(r);
}
#endif
}
- S->tccgen_vtop->r=get_reg_ex(S, RC_FLOAT,r);
+ vtop->r=get_reg_ex(RC_FLOAT,r);
if(!fneg)
- S->tccgen_vtop--;
- o(S, x|(vfpr(S, S->tccgen_vtop->r)<<12));
+ vtop--;
+ o(x|(vfpr(vtop->r)<<12));
}
#else
-static uint32_t is_fconst(TCCState* S)
+static uint32_t is_fconst()
{
long double f;
uint32_t r;
- if((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
+ if((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
return 0;
- if (S->tccgen_vtop->type.t == VT_FLOAT)
- f = S->tccgen_vtop->c.f;
- else if (S->tccgen_vtop->type.t == VT_DOUBLE)
- f = S->tccgen_vtop->c.d;
+ if (vtop->type.t == VT_FLOAT)
+ f = vtop->c.f;
+ else if (vtop->type.t == VT_DOUBLE)
+ f = vtop->c.d;
else
- f = S->tccgen_vtop->c.ld;
+ f = vtop->c.ld;
if(!ieee_finite(f))
return 0;
r=0x8;
@@ -1936,45 +1943,45 @@ static uint32_t is_fconst(TCCState* S)
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranteed to have the same floating point type */
-void gen_opf(TCCState* S, int op)
+void gen_opf(int op)
{
uint32_t x, r, r2, c1, c2;
//fputs("gen_opf\n",stderr);
- vswap(S);
- c1 = is_fconst(S);
- vswap(S);
- c2 = is_fconst(S);
+ vswap();
+ c1 = is_fconst();
+ vswap();
+ c2 = is_fconst();
x=0xEE000100;
#if LDOUBLE_SIZE == 8
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FLOAT)
+ if ((vtop->type.t & VT_BTYPE) != VT_FLOAT)
x|=0x80;
#else
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE)
+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
x|=0x80;
- else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE)
+ else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE)
x|=0x80000;
#endif
switch(op)
{
case '+':
if(!c2) {
- vswap(S);
+ vswap();
c2=c1;
}
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
if(c2) {
if(c2>0xf)
x|=0x200000; // suf
r2=c2&0xf;
} else {
- r2=fpr(S, gv(S, RC_FLOAT));
+ r2=fpr(gv(RC_FLOAT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
}
#endif
}
@@ -1984,46 +1991,46 @@ void gen_opf(TCCState* S, int op)
if(c2<=0xf)
x|=0x200000; // suf
r2=c2&0xf;
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
} else if(c1 && c1<=0xf) {
x|=0x300000; // rsf
r2=c1;
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ r=fpr(gv(RC_FLOAT));
+ vswap();
} else {
x|=0x200000; // suf
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
- r2=fpr(S, gv(S, RC_FLOAT));
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
+ r2=fpr(gv(RC_FLOAT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
}
#endif
}
break;
case '*':
if(!c2 || c2>0xf) {
- vswap(S);
+ vswap();
c2=c1;
}
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
if(c2 && c2<=0xf)
r2=c2;
else {
- r2=fpr(S, gv(S, RC_FLOAT));
+ r2=fpr(gv(RC_FLOAT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
}
#endif
}
@@ -2033,25 +2040,25 @@ void gen_opf(TCCState* S, int op)
if(c2 && c2<=0xf) {
x|=0x400000; // dvf
r2=c2;
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
} else if(c1 && c1<=0xf) {
x|=0x500000; // rdf
r2=c1;
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ r=fpr(gv(RC_FLOAT));
+ vswap();
} else {
x|=0x400000; // dvf
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
- r2=fpr(S, gv(S, RC_FLOAT));
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
+ r2=fpr(gv(RC_FLOAT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
}
#endif
}
@@ -2066,7 +2073,7 @@ void gen_opf(TCCState* S, int op)
case TOK_UGE:
case TOK_ULE:
case TOK_UGT:
- tcc_error(S, "unsigned comparison on floats?");
+ tcc_error("unsigned comparison on floats?");
break;
case TOK_LT:
op=TOK_Nset;
@@ -2081,7 +2088,7 @@ void gen_opf(TCCState* S, int op)
}
if(c1 && !c2) {
c2=c1;
- vswap(S);
+ vswap();
switch(op) {
case TOK_Nset:
op=TOK_GT;
@@ -2097,86 +2104,86 @@ void gen_opf(TCCState* S, int op)
break;
}
}
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
if(c2) {
if(c2>0xf)
x|=0x200000;
r2=c2&0xf;
} else {
- r2=fpr(S, gv(S, RC_FLOAT));
+ r2=fpr(gv(RC_FLOAT));
#ifdef CONFIG_TCC_BCHECK
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- r=fpr(S, gv(S, RC_FLOAT));
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ r=fpr(gv(RC_FLOAT));
+ vswap();
}
#endif
}
- --S->tccgen_vtop;
- vset_VT_CMP(S, op);
- ++S->tccgen_vtop;
+ --vtop;
+ vset_VT_CMP(op);
+ ++vtop;
} else {
- tcc_error(S, "unknown fp op %x!",op);
+ tcc_error("unknown fp op %x!",op);
return;
}
}
- if(S->tccgen_vtop[-1].r == VT_CMP)
+ if(vtop[-1].r == VT_CMP)
c1=15;
else {
- c1=S->tccgen_vtop->r;
+ c1=vtop->r;
if(r2&0x8)
- c1=S->tccgen_vtop[-1].r;
- S->tccgen_vtop[-1].r=get_reg_ex(S, RC_FLOAT,two2mask(S, S->tccgen_vtop[-1].r,c1));
- c1=fpr(S, S->tccgen_vtop[-1].r);
+ c1=vtop[-1].r;
+ vtop[-1].r=get_reg_ex(RC_FLOAT,two2mask(vtop[-1].r,c1));
+ c1=fpr(vtop[-1].r);
}
- S->tccgen_vtop--;
- o(S, x|(r<<16)|(c1<<12)|r2);
+ vtop--;
+ o(x|(r<<16)|(c1<<12)|r2);
}
#endif
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
-ST_FUNC void gen_cvt_itof(TCCState* S, int t)
+ST_FUNC void gen_cvt_itof(int t)
{
uint32_t r, r2;
int bt;
- bt=S->tccgen_vtop->type.t & VT_BTYPE;
+ bt=vtop->type.t & VT_BTYPE;
if(bt == VT_INT || bt == VT_SHORT || bt == VT_BYTE) {
#ifndef TCC_ARM_VFP
uint32_t dsize = 0;
#endif
- r=intr(S, gv(S, RC_INT));
+ r=intr(gv(RC_INT));
#ifdef TCC_ARM_VFP
- r2=vfpr(S, S->tccgen_vtop->r=get_reg(S, RC_FLOAT));
- o(S, 0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */
+ r2=vfpr(vtop->r=get_reg(RC_FLOAT));
+ o(0xEE000A10|(r<<12)|(r2<<16)); /* fmsr */
r2|=r2<<12;
- if(!(S->tccgen_vtop->type.t & VT_UNSIGNED))
+ if(!(vtop->type.t & VT_UNSIGNED))
r2|=0x80; /* fuitoX -> fsituX */
- o(S, 0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/
+ o(0xEEB80A40|r2|T2CPR(t)); /* fYitoX*/
#else
- r2=fpr(S, S->tccgen_vtop->r=get_reg(S, RC_FLOAT));
+ r2=fpr(vtop->r=get_reg(RC_FLOAT));
if((t & VT_BTYPE) != VT_FLOAT)
dsize=0x80; /* flts -> fltd */
- o(S, 0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */
- if((S->tccgen_vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) {
+ o(0xEE000110|dsize|(r2<<16)|(r<<12)); /* flts */
+ if((vtop->type.t & (VT_UNSIGNED|VT_BTYPE)) == (VT_UNSIGNED|VT_INT)) {
uint32_t off = 0;
- o(S, 0xE3500000|(r<<12)); /* cmp */
- r=fpr(S, get_reg(S, RC_FLOAT));
+ o(0xE3500000|(r<<12)); /* cmp */
+ r=fpr(get_reg(RC_FLOAT));
if(last_itod_magic) {
- off=S->tccgen_ind+8-last_itod_magic;
+ off=ind+8-last_itod_magic;
off/=4;
if(off>255)
off=0;
}
- o(S, 0xBD1F0100|(r<<12)|off); /* ldflts */
+ o(0xBD1F0100|(r<<12)|off); /* ldflts */
if(!off) {
- o(S, 0xEA000000); /* b */
- last_itod_magic=S->tccgen_ind;
- o(S, 0x4F800000); /* 4294967296.0f */
+ o(0xEA000000); /* b */
+ last_itod_magic=ind;
+ o(0x4F800000); /* 4294967296.0f */
}
- o(S, 0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */
+ o(0xBE000100|dsize|(r2<<16)|(r2<<12)|r); /* adflt */
}
#endif
return;
@@ -2184,15 +2191,15 @@ ST_FUNC void gen_cvt_itof(TCCState* S, int t)
int func;
CType *func_type = 0;
if((t & VT_BTYPE) == VT_FLOAT) {
- func_type = &S->armgen_func_float_type;
- if(S->tccgen_vtop->type.t & VT_UNSIGNED)
+ func_type = &func_float_type;
+ if(vtop->type.t & VT_UNSIGNED)
func=TOK___floatundisf;
else
func=TOK___floatdisf;
#if LDOUBLE_SIZE != 8
} else if((t & VT_BTYPE) == VT_LDOUBLE) {
- func_type = &S->armgen_func_ldouble_type;
- if(S->tccgen_vtop->type.t & VT_UNSIGNED)
+ func_type = &func_ldouble_type;
+ if(vtop->type.t & VT_UNSIGNED)
func=TOK___floatundixf;
else
func=TOK___floatdixf;
@@ -2200,39 +2207,39 @@ ST_FUNC void gen_cvt_itof(TCCState* S, int t)
#else
} else if((t & VT_BTYPE) == VT_DOUBLE || (t & VT_BTYPE) == VT_LDOUBLE) {
#endif
- func_type = &S->armgen_func_double_type;
- if(S->tccgen_vtop->type.t & VT_UNSIGNED)
+ func_type = &func_double_type;
+ if(vtop->type.t & VT_UNSIGNED)
func=TOK___floatundidf;
else
func=TOK___floatdidf;
}
if(func_type) {
- vpushsym(S, func_type, external_helper_sym(S, func));
- vswap(S);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->r=TREG_F0;
+ vpushsym(func_type, external_helper_sym(func));
+ vswap();
+ gfunc_call(1);
+ vpushi(0);
+ vtop->r=TREG_F0;
return;
}
}
- tcc_error(S, "unimplemented gen_cvt_itof %x!",S->tccgen_vtop->type.t);
+ tcc_error("unimplemented gen_cvt_itof %x!",vtop->type.t);
}
/* convert fp to int 't' type */
-void gen_cvt_ftoi(TCCState* S, int t)
+void gen_cvt_ftoi(int t)
{
uint32_t r, r2;
int u, func = 0;
u=t&VT_UNSIGNED;
t&=VT_BTYPE;
- r2=S->tccgen_vtop->type.t & VT_BTYPE;
+ r2=vtop->type.t & VT_BTYPE;
if(t==VT_INT) {
#ifdef TCC_ARM_VFP
- r=vfpr(S, gv(S, RC_FLOAT));
+ r=vfpr(gv(RC_FLOAT));
u=u?0:0x10000;
- o(S, 0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */
- r2=intr(S, S->tccgen_vtop->r=get_reg(S, RC_INT));
- o(S, 0xEE100A10|(r<<16)|(r2<<12));
+ o(0xEEBC0AC0|(r<<12)|r|T2CPR(r2)|u); /* ftoXizY */
+ r2=intr(vtop->r=get_reg(RC_INT));
+ o(0xEE100A10|(r<<16)|(r2<<12));
return;
#else
if(u) {
@@ -2247,9 +2254,9 @@ void gen_cvt_ftoi(TCCState* S, int t)
#endif
func=TOK___fixunsdfsi;
} else {
- r=fpr(S, gv(S, RC_FLOAT));
- r2=intr(S, S->tccgen_vtop->r=get_reg(S, RC_INT));
- o(S, 0xEE100170|(r2<<12)|r);
+ r=fpr(gv(RC_FLOAT));
+ r2=intr(vtop->r=get_reg(RC_INT));
+ o(0xEE100170|(r2<<12)|r);
return;
}
#endif
@@ -2266,93 +2273,93 @@ void gen_cvt_ftoi(TCCState* S, int t)
func=TOK___fixdfdi;
}
if(func) {
- vpush_helper_func(S, func);
- vswap(S);
- gfunc_call(S, 1);
- vpushi(S, 0);
+ vpush_helper_func(func);
+ vswap();
+ gfunc_call(1);
+ vpushi(0);
if(t == VT_LLONG)
- S->tccgen_vtop->r2 = REG_IRE2;
- S->tccgen_vtop->r = REG_IRET;
+ vtop->r2 = REG_IRE2;
+ vtop->r = REG_IRET;
return;
}
- tcc_error(S, "unimplemented gen_cvt_ftoi!");
+ tcc_error("unimplemented gen_cvt_ftoi!");
}
/* convert from one floating point type to another */
-void gen_cvt_ftof(TCCState* S, int t)
+void gen_cvt_ftof(int t)
{
#ifdef TCC_ARM_VFP
- if(((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) {
- uint32_t r = vfpr(S, gv(S, RC_FLOAT));
- o(S, 0xEEB70AC0|(r<<12)|r|T2CPR(S->tccgen_vtop->type.t));
+ if(((vtop->type.t & VT_BTYPE) == VT_FLOAT) != ((t & VT_BTYPE) == VT_FLOAT)) {
+ uint32_t r = vfpr(gv(RC_FLOAT));
+ o(0xEEB70AC0|(r<<12)|r|T2CPR(vtop->type.t));
}
#else
/* all we have to do on i386 and FPA ARM is to put the float in a register */
- gv(S, RC_FLOAT);
+ gv(RC_FLOAT);
#endif
}
/* increment tcov counter */
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
+ST_FUNC void gen_increment_tcov (SValue *sv)
{
int r1, r2;
- vpushv(S, sv);
- S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
- r2 = get_reg(S, RC_INT);
- o(S, 0xE59F0000 | (intr(S, r1)<<12)); // ldr r1,[pc]
- o(S, 0xEA000000); // b $+4
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_ARM_REL32);
- o(S, -12);
- o(S, 0xe080000f | (intr(S, r1)<<16) | (intr(S, r1)<<12)); // add r1,r1,pc
- o(S, 0xe5900000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // ldr r2, [r1]
- o(S, 0xe2900001 | (intr(S, r2)<<16) | (intr(S, r2)<<12)); // adds r2, r2, #1
- o(S, 0xe5800000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // str r2, [r1]
- o(S, 0xe2800004 | (intr(S, r1)<<16) | (intr(S, r1)<<12)); // add r1, r1, #4
- o(S, 0xe5900000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // ldr r2, [r1]
- o(S, 0xe2a00000 | (intr(S, r2)<<16) | (intr(S, r2)<<12)); // adc r2, r2, #0
- o(S, 0xe5800000 | (intr(S, r1)<<16) | (intr(S, r2)<<12)); // str r2, [r1]
- vpop(S);
+ vpushv(sv);
+ vtop->r = r1 = get_reg(RC_INT);
+ r2 = get_reg(RC_INT);
+ o(0xE59F0000 | (intr(r1)<<12)); // ldr r1,[pc]
+ o(0xEA000000); // b $+4
+ greloc(cur_text_section, sv->sym, ind, R_ARM_REL32);
+ o(-12);
+ o(0xe080000f | (intr(r1)<<16) | (intr(r1)<<12)); // add r1,r1,pc
+ o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1]
+ o(0xe2900001 | (intr(r2)<<16) | (intr(r2)<<12)); // adds r2, r2, #1
+ o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1]
+ o(0xe2800004 | (intr(r1)<<16) | (intr(r1)<<12)); // add r1, r1, #4
+ o(0xe5900000 | (intr(r1)<<16) | (intr(r2)<<12)); // ldr r2, [r1]
+ o(0xe2a00000 | (intr(r2)<<16) | (intr(r2)<<12)); // adc r2, r2, #0
+ o(0xe5800000 | (intr(r1)<<16) | (intr(r2)<<12)); // str r2, [r1]
+ vpop();
}
/* computed goto support */
-void ggoto(TCCState* S)
+void ggoto(void)
{
- gcall_or_jmp(S, 1);
- S->tccgen_vtop--;
+ gcall_or_jmp(1);
+ vtop--;
}
/* Save the stack pointer onto the stack and return the location of its address */
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
+ST_FUNC void gen_vla_sp_save(int addr) {
SValue v;
v.type.t = VT_PTR;
v.r = VT_LOCAL | VT_LVAL;
v.c.i = addr;
- store(S, TREG_SP, &v);
+ store(TREG_SP, &v);
}
/* Restore the SP from a location on the stack */
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
+ST_FUNC void gen_vla_sp_restore(int addr) {
SValue v;
v.type.t = VT_PTR;
v.r = VT_LOCAL | VT_LVAL;
v.c.i = addr;
- load(S, TREG_SP, &v);
+ load(TREG_SP, &v);
}
/* Subtract from the stack pointer, and push the resulting value onto the stack */
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
+ST_FUNC void gen_vla_alloc(CType *type, int align) {
int r;
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- vpushv(S, S->tccgen_vtop);
+ if (tcc_state->do_bounds_check)
+ vpushv(vtop);
#endif
- r = intr(S, gv(S, RC_INT));
+ r = intr(gv(RC_INT));
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- o(S, 0xe2800001 | (r<<16)|(r<<12)); /* add r,r,#1 */
+ if (tcc_state->do_bounds_check)
+ o(0xe2800001 | (r<<16)|(r<<12)); /* add r,r,#1 */
#endif
- o(S, 0xE04D0000|(r<<12)|r); /* sub r, sp, r */
+ o(0xE04D0000|(r<<12)|r); /* sub r, sp, r */
#ifdef TCC_ARM_EABI
if (align < 8)
align = 8;
@@ -2361,19 +2368,19 @@ ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
align = 4;
#endif
if (align & (align - 1))
- tcc_error(S, "alignment is not a power of 2: %i", align);
- o(S, stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */
- vpop(S);
+ tcc_error("alignment is not a power of 2: %i", align);
+ o(stuff_const(0xE3C0D000|(r<<16), align - 1)); /* bic sp, r, #align-1 */
+ vpop();
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check) {
- vpushi(S, 0);
- S->tccgen_vtop->r = TREG_R0;
- o(S, 0xe1a0000d | (S->tccgen_vtop->r << 12)); // mov r0,sp
- vswap(S);
- vpush_helper_func(S, TOK___bound_new_region);
- vrott(S, 3);
- gfunc_call(S, 2);
- S->func_bound_add_epilog = 1;
+ if (tcc_state->do_bounds_check) {
+ vpushi(0);
+ vtop->r = TREG_R0;
+ o(0xe1a0000d | (vtop->r << 12)); // mov r0,sp
+ vswap();
+ vpush_helper_func(TOK___bound_new_region);
+ vrott(3);
+ gfunc_call(2);
+ func_bound_add_epilog = 1;
}
#endif
}
diff --git a/arm-link.c b/arm-link.c
index b82eeb4..5d40f84 100644
--- a/arm-link.c
+++ b/arm-link.c
@@ -107,9 +107,9 @@ int gotplt_entry_type (int reloc_type)
}
#ifndef TCC_TARGET_PE
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- Section *plt = S->plt;
+ Section *plt = s1->plt;
uint8_t *p;
unsigned plt_offset;
@@ -119,7 +119,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* empty PLT: create PLT0 entry that push address of call site and
jump to ld.so resolution routine (GOT + 8) */
if (plt->data_offset == 0) {
- p = section_ptr_add(S, plt, 20);
+ p = section_ptr_add(plt, 20);
write32le(p, 0xe52de004); /* push {lr} */
write32le(p+4, 0xe59fe004); /* ldr lr, [pc, #4] */
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
plt_offset = plt->data_offset;
if (attr->plt_thumb_stub) {
- p = section_ptr_add(S, plt, 4);
+ p = section_ptr_add(plt, 4);
write32le(p, 0x4778); /* bx pc */
write32le(p+2, 0x46c0); /* nop */
}
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
/* save GOT offset for relocate_plt */
write32le(p + 4, got_offset);
return plt_offset;
@@ -141,22 +141,22 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
if (p < p_end) {
- int x = S->got->sh_addr - S->plt->sh_addr - 12;
- write32le(S->plt->data + 16, x - 4);
+ int x = s1->got->sh_addr - s1->plt->sh_addr - 12;
+ write32le(s1->plt->data + 16, x - 4);
p += 20;
while (p < p_end) {
- unsigned off = x + read32le(p + 4) + (S->plt->data - p) + 4;
+ unsigned off = x + read32le(p + 4) + (s1->plt->data - p) + 4;
if (read32le(p) == 0x46c04778) /* PLT Thumb stub present */
p += 4;
write32le(p, 0xe28fc200 | ((off >> 28) & 0xf)); // add ip, pc, #0xN0000000
@@ -167,17 +167,17 @@ ST_FUNC void relocate_plt(TCCState *S)
}
}
- if (S->plt->reloc) {
+ if (s1->plt->reloc) {
ElfW_Rel *rel;
- p = S->got->data;
- for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
- write32le(p + rel->r_offset, S->plt->sh_addr);
+ p = s1->got->data;
+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
+ write32le(p + rel->r_offset, s1->plt->sh_addr);
}
}
}
#endif
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
ElfW(Sym) *sym;
int sym_index, esym_index;
@@ -212,7 +212,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
h = x & 2;
th_ko = (x & 3) && (!blx_avail || !is_call);
if (th_ko || x >= 0x2000000 || x < -0x2000000)
- tcc_error(S, "can't relocate value at %x,%d",addr, type);
+ tcc_error("can't relocate value at %x,%d",addr, type);
x >>= 2;
x &= 0xffffff;
/* 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
/* Relocation infos */
to_thumb = val & 1;
- plt = S->plt;
+ plt = s1->plt;
to_plt = (val >= plt->sh_addr) &&
(val < plt->sh_addr + plt->data_offset);
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
Section *text;
name = (char *) symtab_section->link->data + sym->st_name;
- text = S->sections[sym->st_shndx];
+ text = s1->sections[sym->st_shndx];
/* Modify reloc to target a thumb stub to switch to ARM */
snprintf(buf, sizeof(buf), "%s_from_thumb", name);
- index = put_elf_sym(S, symtab_section,
+ index = put_elf_sym(symtab_section,
text->data_offset + 1,
sym->st_size, sym->st_info, 0,
sym->st_shndx, buf);
@@ -281,7 +281,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
put_elf_reloc(symtab_section, text,
text->data_offset + 4, R_ARM_JUMP24,
sym_index);
- p = section_ptr_add(S, text, 8);
+ p = section_ptr_add(text, 8);
write32le(p, 0x4778); /* bx pc */
write32le(p+2, 0x46c0); /* nop */
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
- instruction must be a call (bl) or a jump to PLT */
if (!to_thumb || x >= 0x1000000 || x < -0x1000000)
if (to_thumb || (val & 2) || (!is_call && !to_plt))
- tcc_error(S, "can't relocate value at %x,%d",addr, type);
+ tcc_error("can't relocate value at %x,%d",addr, type);
/* Compute and store final offset */
s = (x >> 24) & 1;
@@ -372,14 +372,14 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
x = (x * 2) / 2;
x += val - addr;
if((x^(x>>1))&0x40000000)
- tcc_error(S, "can't relocate value at %x,%d",addr, type);
+ tcc_error("can't relocate value at %x,%d",addr, type);
(*(int *)ptr) |= x & 0x7fffffff;
}
return;
case R_ARM_ABS32:
case R_ARM_TARGET1:
- if (S->output_type == TCC_OUTPUT_DLL) {
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
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
*(int *)ptr += val - addr;
return;
case R_ARM_GOTPC:
- *(int *)ptr += S->got->sh_addr - addr;
+ *(int *)ptr += s1->got->sh_addr - addr;
return;
case R_ARM_GOTOFF:
- *(int *)ptr += val - S->got->sh_addr;
+ *(int *)ptr += val - s1->got->sh_addr;
return;
case R_ARM_GOT32:
/* we load the got offset */
- *(int *)ptr += get_sym_attr(S, sym_index, 0)->got_offset;
+ *(int *)ptr += get_sym_attr(s1, sym_index, 0)->got_offset;
return;
case R_ARM_GOT_PREL:
/* we load the pc relative got offset */
- *(int *)ptr += S->got->sh_addr +
- get_sym_attr(S, sym_index, 0)->got_offset -
+ *(int *)ptr += s1->got->sh_addr +
+ get_sym_attr(s1, sym_index, 0)->got_offset -
addr;
return;
case R_ARM_COPY:
@@ -428,7 +428,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
return;
case R_ARM_RELATIVE:
#ifdef TCC_TARGET_PE
- add32le(ptr, val - S->pe_imagebase);
+ add32le(ptr, val - s1->pe_imagebase);
#endif
/* do nothing */
return;
diff --git a/arm64-asm.c b/arm64-asm.c
index 3c576a1..a97fd64 100644
--- a/arm64-asm.c
+++ b/arm64-asm.c
@@ -9,9 +9,9 @@
#define CONFIG_TCC_ASM
#define NB_ASM_REGS 16
-ST_FUNC void g(TCCState* S, int c);
-ST_FUNC void gen_le16(TCCState* S, int c);
-ST_FUNC void gen_le32(TCCState* S, int c);
+ST_FUNC void g(int c);
+ST_FUNC void gen_le16(int c);
+ST_FUNC void gen_le32(int c);
/*************************************************************/
#else
@@ -25,7 +25,7 @@ static void asm_error(void)
}
/* XXX: make it faster ? */
-ST_FUNC void g(TCCState* S, int c)
+ST_FUNC void g(int c)
{
int ind1;
if (nocode_wanted)
@@ -37,24 +37,24 @@ ST_FUNC void g(TCCState* S, int c)
ind = ind1;
}
-ST_FUNC void gen_le16 (TCCState* S, int i)
+ST_FUNC void gen_le16 (int i)
{
- g(S, i);
- g(S, i>>8);
+ g(i);
+ g(i>>8);
}
-ST_FUNC void gen_le32 (TCCState* S, int i)
+ST_FUNC void gen_le32 (int i)
{
- gen_le16(S, i);
- gen_le16(S, i>>16);
+ gen_le16(i);
+ gen_le16(i>>16);
}
-ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
+ST_FUNC void gen_expr32(ExprValue *pe)
{
- gen_le32(S, pe->v);
+ gen_le32(pe->v);
}
-ST_FUNC void asm_opcode(TCCState *S, int opcode)
+ST_FUNC void asm_opcode(TCCState *s1, int opcode)
{
asm_error();
}
diff --git a/arm64-gen.c b/arm64-gen.c
index 7def111..83193f6 100644
--- a/arm64-gen.c
+++ b/arm64-gen.c
@@ -90,9 +90,15 @@ ST_DATA const int reg_classes[NB_REGS] = {
RC_FLOAT | RC_F(7)
};
+#if defined(CONFIG_TCC_BCHECK)
+static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
+ST_DATA int func_bound_add_epilog;
+#endif
+
#define IS_FREG(x) ((x) >= TREG_F(0))
-static uint32_t intr(TCCState *S, int r)
+static uint32_t intr(int r)
{
assert(TREG_R(0) <= r && r <= TREG_R30);
return r < TREG_R30 ? r : 30;
@@ -105,15 +111,15 @@ static uint32_t fltr(int r)
}
// Add an instruction to text section:
-ST_FUNC void o(TCCState *S, unsigned int c)
+ST_FUNC void o(unsigned int c)
{
- int ind1 = S->tccgen_ind + 4;
- if (S->tccgen_nocode_wanted)
+ int ind1 = ind + 4;
+ if (nocode_wanted)
return;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- write32le(cur_text_section->data + S->tccgen_ind, c);
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ write32le(cur_text_section->data + ind, c);
+ ind = ind1;
}
static int arm64_encode_bimm64(uint64_t x)
@@ -202,11 +208,11 @@ static uint32_t arm64_movi(int r, uint64_t x)
return 0;
}
-static void arm64_movimm(TCCState *S, int r, uint64_t x)
+static void arm64_movimm(int r, uint64_t x)
{
uint32_t i;
if ((i = arm64_movi(r, x)))
- o(S, i); // a single MOV
+ o(i); // a single MOV
else {
// MOVZ/MOVN and 1-3 MOVKs
int z = 0, m = 0;
@@ -222,19 +228,19 @@ static void arm64_movimm(TCCState *S, int r, uint64_t x)
}
for (i = 0; i < 64; i += 16)
if (x1 >> i & 0xffff) {
- o(S, mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17);
+ o(mov1 | r | (x1 >> i & 0xffff) << 5 | i << 17);
// movz/movn x(r),#(*),lsl #(i)
break;
}
for (i += 16; i < 64; i += 16)
if (x1 >> i & 0xffff)
- o(S, 0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17);
+ o(0xf2800000 | r | (x >> i & 0xffff) << 5 | i << 17);
// movk x(r),#(*),lsl #(i)
}
}
// Patch all branches in list pointed to by t to branch to a:
-ST_FUNC void gsym_addr(TCCState *S, int t_, int a_)
+ST_FUNC void gsym_addr(int t_, int a_)
{
uint32_t t = t_;
uint32_t a = a_;
@@ -242,7 +248,7 @@ ST_FUNC void gsym_addr(TCCState *S, int t_, int a_)
unsigned char *ptr = cur_text_section->data + t;
uint32_t next = read32le(ptr);
if (a - t + 0x8000000 >= 0x10000000)
- tcc_error(S, "branch out of range");
+ tcc_error("branch out of range");
write32le(ptr, (a - t == 4 ? 0xd503201f : // nop
0x14000000 | ((a - t) >> 2 & 0x3ffffff))); // b
t = next;
@@ -272,17 +278,17 @@ static int arm64_type_size(int t)
return 0;
}
-static void arm64_spoff(TCCState *S, int reg, uint64_t off)
+static void arm64_spoff(int reg, uint64_t off)
{
uint32_t sub = off >> 63;
if (sub)
off = -off;
if (off < 4096)
- o(S, 0x910003e0 | sub << 30 | reg | off << 10);
+ o(0x910003e0 | sub << 30 | reg | off << 10);
// (add|sub) x(reg),sp,#(off)
else {
- arm64_movimm(S, 30, off); // use x30 for offset
- o(S, 0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30
+ arm64_movimm(30, off); // use x30 for offset
+ o(0x8b3e63e0 | sub << 30 | reg); // (add|sub) x(reg),sp,x30
}
}
@@ -303,41 +309,41 @@ static uint64_t arm64_check_offset(int invert, int sz_, uint64_t off)
return invert ? 0ul : off;
}
-static void arm64_ldrx(TCCState *S, int sg, int sz_, int dst, int bas, uint64_t off)
+static void arm64_ldrx(int sg, int sz_, int dst, int bas, uint64_t off)
{
uint32_t sz = sz_;
if (sz >= 2)
sg = 0;
if (!(off & ~((uint32_t)0xfff << sz)))
- o(S, 0x39400000 | dst | bas << 5 | off << (10 - sz) |
+ o(0x39400000 | dst | bas << 5 | off << (10 - sz) |
(uint32_t)!!sg << 23 | sz << 30); // ldr(*) x(dst),[x(bas),#(off)]
else if (off < 256 || -off <= 256)
- o(S, 0x38400000 | dst | bas << 5 | (off & 511) << 12 |
+ o(0x38400000 | dst | bas << 5 | (off & 511) << 12 |
(uint32_t)!!sg << 23 | sz << 30); // ldur(*) x(dst),[x(bas),#(off)]
else {
- arm64_movimm(S, 30, off); // use x30 for offset
- o(S, 0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 |
+ arm64_movimm(30, off); // use x30 for offset
+ o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 |
(uint32_t)(!!sg + 1) << 22 | sz << 30); // ldr(*) x(dst),[x(bas),x30]
}
}
-static void arm64_ldrv(TCCState *S, int sz_, int dst, int bas, uint64_t off)
+static void arm64_ldrv(int sz_, int dst, int bas, uint64_t off)
{
uint32_t sz = sz_;
if (!(off & ~((uint32_t)0xfff << sz)))
- o(S, 0x3d400000 | dst | bas << 5 | off << (10 - sz) |
+ o(0x3d400000 | dst | bas << 5 | off << (10 - sz) |
(sz & 4) << 21 | (sz & 3) << 30); // ldr (s|d|q)(dst),[x(bas),#(off)]
else if (off < 256 || -off <= 256)
- o(S, 0x3c400000 | dst | bas << 5 | (off & 511) << 12 |
+ o(0x3c400000 | dst | bas << 5 | (off & 511) << 12 |
(sz & 4) << 21 | (sz & 3) << 30); // ldur (s|d|q)(dst),[x(bas),#(off)]
else {
- arm64_movimm(S, 30, off); // use x30 for offset
- o(S, 0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 |
+ arm64_movimm(30, off); // use x30 for offset
+ o(0x3c606800 | dst | bas << 5 | (uint32_t)30 << 16 |
sz << 30 | (sz & 4) << 21); // ldr (s|d|q)(dst),[x(bas),x30]
}
}
-static void arm64_ldrs(TCCState *S, int reg_, int size)
+static void arm64_ldrs(int reg_, int size)
{
uint32_t reg = reg_;
// Use x30 for intermediate value in some cases.
@@ -347,138 +353,138 @@ static void arm64_ldrs(TCCState *S, int reg_, int size)
/* Can happen with zero size structs */
break;
case 1:
- arm64_ldrx(S, 0, 0, reg, reg, 0);
+ arm64_ldrx(0, 0, reg, reg, 0);
break;
case 2:
- arm64_ldrx(S, 0, 1, reg, reg, 0);
+ arm64_ldrx(0, 1, reg, reg, 0);
break;
case 3:
- arm64_ldrx(S, 0, 1, 30, reg, 0);
- arm64_ldrx(S, 0, 0, reg, reg, 2);
- o(S, 0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16
+ arm64_ldrx(0, 1, 30, reg, 0);
+ arm64_ldrx(0, 0, reg, reg, 2);
+ o(0x2a0043c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #16
break;
case 4:
- arm64_ldrx(S, 0, 2, reg, reg, 0);
+ arm64_ldrx(0, 2, reg, reg, 0);
break;
case 5:
- arm64_ldrx(S, 0, 2, 30, reg, 0);
- arm64_ldrx(S, 0, 0, reg, reg, 4);
- o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
+ arm64_ldrx(0, 2, 30, reg, 0);
+ arm64_ldrx(0, 0, reg, reg, 4);
+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
break;
case 6:
- arm64_ldrx(S, 0, 2, 30, reg, 0);
- arm64_ldrx(S, 0, 1, reg, reg, 4);
- o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
+ arm64_ldrx(0, 2, 30, reg, 0);
+ arm64_ldrx(0, 1, reg, reg, 4);
+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
break;
case 7:
- arm64_ldrx(S, 0, 2, 30, reg, 0);
- arm64_ldrx(S, 0, 2, reg, reg, 3);
- o(S, 0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8
- o(S, 0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
+ arm64_ldrx(0, 2, 30, reg, 0);
+ arm64_ldrx(0, 2, reg, reg, 3);
+ o(0x53087c00 | reg | reg << 5); // lsr w(reg), w(reg), #8
+ o(0xaa0083c0 | reg | reg << 16); // orr x(reg),x30,x(reg),lsl #32
break;
case 8:
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 9:
- arm64_ldrx(S, 0, 0, reg + 1, reg, 8);
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 0, reg + 1, reg, 8);
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 10:
- arm64_ldrx(S, 0, 1, reg + 1, reg, 8);
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 1, reg + 1, reg, 8);
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 11:
- arm64_ldrx(S, 0, 2, reg + 1, reg, 7);
- o(S, 0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 2, reg + 1, reg, 7);
+ o(0x53087c00 | (reg+1) | (reg+1) << 5); // lsr w(reg+1), w(reg+1), #8
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 12:
- arm64_ldrx(S, 0, 2, reg + 1, reg, 8);
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 2, reg + 1, reg, 8);
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 13:
- arm64_ldrx(S, 0, 3, reg + 1, reg, 5);
- o(S, 0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 3, reg + 1, reg, 5);
+ o(0xd358fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #24
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 14:
- arm64_ldrx(S, 0, 3, reg + 1, reg, 6);
- o(S, 0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 3, reg + 1, reg, 6);
+ o(0xd350fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #16
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 15:
- arm64_ldrx(S, 0, 3, reg + 1, reg, 7);
- o(S, 0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8
- arm64_ldrx(S, 0, 3, reg, reg, 0);
+ arm64_ldrx(0, 3, reg + 1, reg, 7);
+ o(0xd348fc00 | (reg+1) | (reg+1) << 5); // lsr x(reg+1), x(reg+1), #8
+ arm64_ldrx(0, 3, reg, reg, 0);
break;
case 16:
- o(S, 0xa9400000 | reg | (reg+1) << 10 | reg << 5);
+ o(0xa9400000 | reg | (reg+1) << 10 | reg << 5);
// ldp x(reg),x(reg+1),[x(reg)]
break;
}
}
-static void arm64_strx(TCCState *S, int sz_, int dst, int bas, uint64_t off)
+static void arm64_strx(int sz_, int dst, int bas, uint64_t off)
{
uint32_t sz = sz_;
if (!(off & ~((uint32_t)0xfff << sz)))
- o(S, 0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30);
+ o(0x39000000 | dst | bas << 5 | off << (10 - sz) | sz << 30);
// str(*) x(dst),[x(bas],#(off)]
else if (off < 256 || -off <= 256)
- o(S, 0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30);
+ o(0x38000000 | dst | bas << 5 | (off & 511) << 12 | sz << 30);
// stur(*) x(dst),[x(bas],#(off)]
else {
- arm64_movimm(S, 30, off); // use x30 for offset
- o(S, 0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30);
+ arm64_movimm(30, off); // use x30 for offset
+ o(0x38206800 | dst | bas << 5 | (uint32_t)30 << 16 | sz << 30);
// str(*) x(dst),[x(bas),x30]
}
}
-static void arm64_strv(TCCState *S, int sz_, int dst, int bas, uint64_t off)
+static void arm64_strv(int sz_, int dst, int bas, uint64_t off)
{
uint32_t sz = sz_;
if (!(off & ~((uint32_t)0xfff << sz)))
- o(S, 0x3d000000 | dst | bas << 5 | off << (10 - sz) |
+ o(0x3d000000 | dst | bas << 5 | off << (10 - sz) |
(sz & 4) << 21 | (sz & 3) << 30); // str (s|d|q)(dst),[x(bas),#(off)]
else if (off < 256 || -off <= 256)
- o(S, 0x3c000000 | dst | bas << 5 | (off & 511) << 12 |
+ o(0x3c000000 | dst | bas << 5 | (off & 511) << 12 |
(sz & 4) << 21 | (sz & 3) << 30); // stur (s|d|q)(dst),[x(bas),#(off)]
else {
- arm64_movimm(S, 30, off); // use x30 for offset
- o(S, 0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 |
+ arm64_movimm(30, off); // use x30 for offset
+ o(0x3c206800 | dst | bas << 5 | (uint32_t)30 << 16 |
sz << 30 | (sz & 4) << 21); // str (s|d|q)(dst),[x(bas),x30]
}
}
-static void arm64_sym(TCCState *S, int r, Sym *sym, unsigned long addend)
+static void arm64_sym(int r, Sym *sym, unsigned long addend)
{
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
- o(S, 0x90000000 | r); // adrp xr, #sym
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
- o(S, 0xf9400000 | r | (r << 5)); // ld xr,[xr, #sym]
+ greloca(cur_text_section, sym, ind, R_AARCH64_ADR_GOT_PAGE, 0);
+ o(0x90000000 | r); // adrp xr, #sym
+ greloca(cur_text_section, sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
+ o(0xf9400000 | r | (r << 5)); // ld xr,[xr, #sym]
if (addend) {
// add xr, xr, #addend
if (addend & 0xffful)
- o(S, 0x91000000 | r | r << 5 | (addend & 0xfff) << 10);
+ o(0x91000000 | r | r << 5 | (addend & 0xfff) << 10);
if (addend > 0xffful) {
// add xr, xr, #addend, lsl #12
if (addend & 0xfff000ul)
- o(S, 0x91400000 | r | r << 5 | ((addend >> 12) & 0xfff) << 10);
+ o(0x91400000 | r | r << 5 | ((addend >> 12) & 0xfff) << 10);
if (addend > 0xfffffful) {
/* very unlikely */
int t = r ? 0 : 1;
- o(S, 0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
- arm64_movimm(S, t, addend & ~0xfffffful); // use xt for addent
- o(S, 0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
- o(S, 0xf84107e0 | t); /* ldr xt, [sp], #16 */
+ o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
+ arm64_movimm(t, addend & ~0xfffffful); // use xt for addent
+ o(0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
+ o(0xf84107e0 | t); /* ldr xt, [sp], #16 */
}
}
}
}
-static void arm64_load_cmp(TCCState *S, int r, SValue *sv);
+static void arm64_load_cmp(int r, SValue *sv);
-ST_FUNC void load(TCCState *S, int r, SValue *sv)
+ST_FUNC void load(int r, SValue *sv)
{
int svtt = sv->type.t;
int svr = sv->r & ~VT_BOUNDED;
@@ -488,24 +494,24 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv)
if (svr == (VT_LOCAL | VT_LVAL)) {
if (IS_FREG(r))
- arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 29, svcul);
+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 29, svcul);
else
- arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
- intr(S, r), 29, svcul);
+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
+ intr(r), 29, svcul);
return;
}
if (svr == (VT_CONST | VT_LVAL)) {
if (sv->sym)
- arm64_sym(S, 30, sv->sym, // use x30 for address
+ arm64_sym(30, sv->sym, // use x30 for address
arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
else
- arm64_movimm (S, 30, sv->c.i);
+ arm64_movimm (30, sv->c.i);
if (IS_FREG(r))
- arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30,
+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
else
- arm64_ldrx(S, !(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(S, r), 30,
+ arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
return;
}
@@ -513,34 +519,34 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv)
if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) {
if ((svtt & VT_BTYPE) != VT_VOID) {
if (IS_FREG(r))
- arm64_ldrv(S, arm64_type_size(svtt), fltr(r), intr(S, svrv), 0);
+ arm64_ldrv(arm64_type_size(svtt), fltr(r), intr(svrv), 0);
else
- arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
- intr(S, r), intr(S, svrv), 0);
+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
+ intr(r), intr(svrv), 0);
}
return;
}
if (svr == (VT_CONST | VT_LVAL | VT_SYM)) {
- arm64_sym(S, 30, sv->sym, // use x30 for address
+ arm64_sym(30, sv->sym, // use x30 for address
arm64_check_offset(0, arm64_type_size(svtt), svcul));
if (IS_FREG(r))
- arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30,
+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), svcul));
else
- arm64_ldrx(S, !(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(S, r), 30,
+ arm64_ldrx(!(svtt&VT_UNSIGNED), arm64_type_size(svtt), intr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), svcul));
return;
}
if (svr == (VT_CONST | VT_SYM)) {
- arm64_sym(S, intr(S, r), sv->sym, svcul);
+ arm64_sym(intr(r), sv->sym, svcul);
return;
}
if (svr == VT_CONST) {
if ((svtt & VT_BTYPE) != VT_VOID)
- arm64_movimm(S, intr(S, r), arm64_type_size(svtt) == 3 ?
+ arm64_movimm(intr(r), arm64_type_size(svtt) == 3 ?
sv->c.i : (uint32_t)svcul);
return;
}
@@ -548,12 +554,12 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv)
if (svr < VT_CONST) {
if (IS_FREG(r) && IS_FREG(svr))
if (svtt == VT_LDOUBLE)
- o(S, 0x4ea01c00 | fltr(r) | fltr(svr) << 5);
+ o(0x4ea01c00 | fltr(r) | fltr(svr) << 5);
// mov v(r).16b,v(svr).16b
else
- o(S, 0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr)
+ o(0x1e604000 | fltr(r) | fltr(svr) << 5); // fmov d(r),d(svr)
else if (!IS_FREG(r) && !IS_FREG(svr))
- o(S, 0xaa0003e0 | intr(S, r) | intr(S, svr) << 16); // mov x(r),x(svr)
+ o(0xaa0003e0 | intr(r) | intr(svr) << 16); // mov x(r),x(svr)
else
assert(0);
return;
@@ -561,35 +567,35 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv)
if (svr == VT_LOCAL) {
if (-svcul < 0x1000)
- o(S, 0xd10003a0 | intr(S, r) | -svcul << 10); // sub x(r),x29,#...
+ o(0xd10003a0 | intr(r) | -svcul << 10); // sub x(r),x29,#...
else {
- arm64_movimm(S, 30, -svcul); // use x30 for offset
- o(S, 0xcb0003a0 | intr(S, r) | (uint32_t)30 << 16); // sub x(r),x29,x30
+ arm64_movimm(30, -svcul); // use x30 for offset
+ o(0xcb0003a0 | intr(r) | (uint32_t)30 << 16); // sub x(r),x29,x30
}
return;
}
if (svr == VT_JMP || svr == VT_JMPI) {
int t = (svr == VT_JMPI);
- arm64_movimm(S, intr(S, r), t);
- o(S, 0x14000002); // b .+8
- gsym(S, svcul);
- arm64_movimm(S, intr(S, r), t ^ 1);
+ arm64_movimm(intr(r), t);
+ o(0x14000002); // b .+8
+ gsym(svcul);
+ arm64_movimm(intr(r), t ^ 1);
return;
}
if (svr == (VT_LLOCAL | VT_LVAL)) {
- arm64_ldrx(S, 0, 3, 30, 29, svcul); // use x30 for offset
+ arm64_ldrx(0, 3, 30, 29, svcul); // use x30 for offset
if (IS_FREG(r))
- arm64_ldrv(S, arm64_type_size(svtt), fltr(r), 30, 0);
+ arm64_ldrv(arm64_type_size(svtt), fltr(r), 30, 0);
else
- arm64_ldrx(S, !(svtt & VT_UNSIGNED), arm64_type_size(svtt),
- intr(S, r), 30, 0);
+ arm64_ldrx(!(svtt & VT_UNSIGNED), arm64_type_size(svtt),
+ intr(r), 30, 0);
return;
}
if (svr == VT_CMP) {
- arm64_load_cmp(S, r, sv);
+ arm64_load_cmp(r, sv);
return;
}
@@ -597,7 +603,7 @@ ST_FUNC void load(TCCState *S, int r, SValue *sv)
assert(0);
}
-ST_FUNC void store(TCCState *S, int r, SValue *sv)
+ST_FUNC void store(int r, SValue *sv)
{
int svtt = sv->type.t;
int svr = sv->r & ~VT_BOUNDED;
@@ -607,43 +613,43 @@ ST_FUNC void store(TCCState *S, int r, SValue *sv)
if (svr == (VT_LOCAL | VT_LVAL)) {
if (IS_FREG(r))
- arm64_strv(S, arm64_type_size(svtt), fltr(r), 29, svcul);
+ arm64_strv(arm64_type_size(svtt), fltr(r), 29, svcul);
else
- arm64_strx(S, arm64_type_size(svtt), intr(S, r), 29, svcul);
+ arm64_strx(arm64_type_size(svtt), intr(r), 29, svcul);
return;
}
if (svr == (VT_CONST | VT_LVAL)) {
if (sv->sym)
- arm64_sym(S, 30, sv->sym, // use x30 for address
+ arm64_sym(30, sv->sym, // use x30 for address
arm64_check_offset(0, arm64_type_size(svtt), sv->c.i));
else
- arm64_movimm(S, 30, sv->c.i);
+ arm64_movimm (30, sv->c.i);
if (IS_FREG(r))
- arm64_strv(S, arm64_type_size(svtt), fltr(r), 30,
+ arm64_strv(arm64_type_size(svtt), fltr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
else
- arm64_strx(S, arm64_type_size(svtt), intr(S, r), 30,
+ arm64_strx(arm64_type_size(svtt), intr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), sv->c.i));
return;
}
if ((svr & ~VT_VALMASK) == VT_LVAL && svrv < VT_CONST) {
if (IS_FREG(r))
- arm64_strv(S, arm64_type_size(svtt), fltr(r), intr(S, svrv), 0);
+ arm64_strv(arm64_type_size(svtt), fltr(r), intr(svrv), 0);
else
- arm64_strx(S, arm64_type_size(svtt), intr(S, r), intr(S, svrv), 0);
+ arm64_strx(arm64_type_size(svtt), intr(r), intr(svrv), 0);
return;
}
if (svr == (VT_CONST | VT_LVAL | VT_SYM)) {
- arm64_sym(S, 30, sv->sym, // use x30 for address
+ arm64_sym(30, sv->sym, // use x30 for address
arm64_check_offset(0, arm64_type_size(svtt), svcul));
if (IS_FREG(r))
- arm64_strv(S, arm64_type_size(svtt), fltr(r), 30,
+ arm64_strv(arm64_type_size(svtt), fltr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), svcul));
else
- arm64_strx(S, arm64_type_size(svtt), intr(S, r), 30,
+ arm64_strx(arm64_type_size(svtt), intr(r), 30,
arm64_check_offset(1, arm64_type_size(svtt), svcul));
return;
}
@@ -652,82 +658,82 @@ ST_FUNC void store(TCCState *S, int r, SValue *sv)
assert(0);
}
-static void arm64_gen_bl_or_b(TCCState *S, int b)
+static void arm64_gen_bl_or_b(int b)
{
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (S->tccgen_vtop->r & VT_SYM)) {
- greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind,
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) {
+ greloca(cur_text_section, vtop->sym, ind,
b ? R_AARCH64_JUMP26 : R_AARCH64_CALL26, 0);
- o(S, 0x14000000 | (uint32_t)!b << 31); // b/bl .
+ o(0x14000000 | (uint32_t)!b << 31); // b/bl .
}
else {
#ifdef CONFIG_TCC_BCHECK
- S->tccgen_vtop->r &= ~VT_MUSTBOUND;
+ vtop->r &= ~VT_MUSTBOUND;
#endif
- o(S, 0xd61f0000 | (uint32_t)!b << 21 | intr(S, gv(S, RC_R30)) << 5); // br/blr
+ o(0xd61f0000 | (uint32_t)!b << 21 | intr(gv(RC_R30)) << 5); // br/blr
}
}
#if defined(CONFIG_TCC_BCHECK)
-static void gen_bounds_call(TCCState *S, int v)
+static void gen_bounds_call(int v)
{
- Sym *sym = external_helper_sym(S, v);
+ Sym *sym = external_helper_sym(v);
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_AARCH64_CALL26, 0);
- o(S, 0x94000000); // bl
+ greloca(cur_text_section, sym, ind, R_AARCH64_CALL26, 0);
+ o(0x94000000); // bl
}
-static void gen_bounds_prolog(TCCState *S)
+static void gen_bounds_prolog(void)
{
/* leave some room for bound checking code */
- S->func_bound_offset = lbounds_section->data_offset;
- S->func_bound_ind = S->tccgen_ind;
- S->func_bound_add_epilog = 0;
- o(S, 0xd503201f); /* nop -> mov x0, lbound section pointer */
- o(S, 0xd503201f);
- o(S, 0xd503201f);
- o(S, 0xd503201f); /* nop -> call __bound_local_new */
+ func_bound_offset = lbounds_section->data_offset;
+ func_bound_ind = ind;
+ func_bound_add_epilog = 0;
+ o(0xd503201f); /* nop -> mov x0, lbound section pointer */
+ o(0xd503201f);
+ o(0xd503201f);
+ o(0xd503201f); /* nop -> call __bound_local_new */
}
-static void gen_bounds_epilog(TCCState *S)
+static void gen_bounds_epilog(void)
{
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
- int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
- if (!offset_modified && !S->func_bound_add_epilog)
+ if (!offset_modified && !func_bound_add_epilog)
return;
/* add end of table info */
- bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
- sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
- S->func_bound_offset, lbounds_section->data_offset);
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
+ func_bound_offset, lbounds_section->data_offset);
/* generate bound local allocation */
if (offset_modified) {
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->func_bound_ind;
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
- o(S, 0x90000000 | 0); // adrp x0, #sym_data
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
- o(S, 0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
- gen_bounds_call(S, TOK___bound_local_new);
- S->tccgen_ind = saved_ind;
+ saved_ind = ind;
+ ind = func_bound_ind;
+ greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0);
+ o(0x90000000 | 0); // adrp x0, #sym_data
+ greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
+ o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
+ gen_bounds_call(TOK___bound_local_new);
+ ind = saved_ind;
}
/* generate bound check local freeing */
- o(S, 0xf81f0fe0); /* str x0, [sp, #-16]! */
- o(S, 0x3c9f0fe0); /* str q0, [sp, #-16]! */
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
- o(S, 0x90000000 | 0); // adrp x0, #sym_data
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
- o(S, 0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
- gen_bounds_call(S, TOK___bound_local_delete);
- o(S, 0x3cc107e0); /* ldr q0, [sp], #16 */
- o(S, 0xf84107e0); /* ldr x0, [sp], #16 */
+ o(0xf81f0fe0); /* str x0, [sp, #-16]! */
+ o(0x3c9f0fe0); /* str q0, [sp, #-16]! */
+ greloca(cur_text_section, sym_data, ind, R_AARCH64_ADR_GOT_PAGE, 0);
+ o(0x90000000 | 0); // adrp x0, #sym_data
+ greloca(cur_text_section, sym_data, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
+ o(0xf9400000 | 0 | (0 << 5)); // ld x0,[x0, #sym_data]
+ gen_bounds_call(TOK___bound_local_delete);
+ o(0x3cc107e0); /* ldr q0, [sp], #16 */
+ o(0xf84107e0); /* ldr x0, [sp], #16 */
}
#endif
@@ -964,7 +970,7 @@ static unsigned long arm64_pcs(int n, CType **type, unsigned long *a)
return stack;
}
-ST_FUNC void gfunc_call(TCCState *S, int nb_args)
+ST_FUNC void gfunc_call(int nb_args)
{
CType *return_type;
CType **t;
@@ -973,28 +979,28 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args)
int i;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
- return_type = &S->tccgen_vtop[-nb_args].type.ref->type;
+ return_type = &vtop[-nb_args].type.ref->type;
if ((return_type->t & VT_BTYPE) == VT_STRUCT)
--nb_args;
- t = tcc_malloc(S, (nb_args + 1) * sizeof(*t));
- a = tcc_malloc(S, (nb_args + 1) * sizeof(*a));
- a1 = tcc_malloc(S, (nb_args + 1) * sizeof(*a1));
+ t = tcc_malloc((nb_args + 1) * sizeof(*t));
+ a = tcc_malloc((nb_args + 1) * sizeof(*a));
+ a1 = tcc_malloc((nb_args + 1) * sizeof(*a1));
t[0] = return_type;
for (i = 0; i < nb_args; i++)
- t[nb_args - i] = &S->tccgen_vtop[-i].type;
+ t[nb_args - i] = &vtop[-i].type;
stack = arm64_pcs(nb_args, t, a);
// Allocate space for structs replaced by pointer:
for (i = nb_args; i; i--)
if (a[i] & 1) {
- SValue *arg = &S->tccgen_vtop[i - nb_args];
+ SValue *arg = &vtop[i - nb_args];
int align, size = type_size(&arg->type, &align);
assert((arg->type.t & VT_BTYPE) == VT_STRUCT);
stack = (stack + align - 1) & -align;
@@ -1005,134 +1011,134 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args)
stack = (stack + 15) >> 4 << 4;
/* fetch cpu flag before generating any code */
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP)
- gv(S, RC_INT);
+ if ((vtop->r & VT_VALMASK) == VT_CMP)
+ gv(RC_INT);
if (stack >= 0x1000000) // 16Mb
- tcc_error(S, "stack size too big %lu", stack);
+ tcc_error("stack size too big %lu", stack);
if (stack & 0xfff)
- o(S, 0xd10003ff | (stack & 0xfff) << 10); // sub sp,sp,#(n)
+ o(0xd10003ff | (stack & 0xfff) << 10); // sub sp,sp,#(n)
if (stack >> 12)
- o(S, 0xd14003ff | (stack >> 12) << 10);
+ o(0xd14003ff | (stack >> 12) << 10);
// First pass: set all values on stack
for (i = nb_args; i; i--) {
- vpushv(S, S->tccgen_vtop - nb_args + i);
+ vpushv(vtop - nb_args + i);
if (a[i] & 1) {
// struct replaced by pointer
- int r = get_reg(S, RC_INT);
- arm64_spoff(S, intr(S, r), a1[i]);
- vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
- vswap(S);
- vstore(S);
+ int r = get_reg(RC_INT);
+ arm64_spoff(intr(r), a1[i]);
+ vset(&vtop->type, r | VT_LVAL, 0);
+ vswap();
+ vstore();
if (a[i] >= 32) {
// pointer on stack
- r = get_reg(S, RC_INT);
- arm64_spoff(S, intr(S, r), a1[i]);
- arm64_strx(S, 3, intr(S, r), 31, (a[i] - 32) >> 1 << 1);
+ r = get_reg(RC_INT);
+ arm64_spoff(intr(r), a1[i]);
+ arm64_strx(3, intr(r), 31, (a[i] - 32) >> 1 << 1);
}
}
else if (a[i] >= 32) {
// value on stack
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
- int r = get_reg(S, RC_INT);
- arm64_spoff(S, intr(S, r), a[i] - 32);
- vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
- vswap(S);
- vstore(S);
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
+ int r = get_reg(RC_INT);
+ arm64_spoff(intr(r), a[i] - 32);
+ vset(&vtop->type, r | VT_LVAL, 0);
+ vswap();
+ vstore();
}
- else if (is_float(S->tccgen_vtop->type.t)) {
- gv(S, RC_FLOAT);
- arm64_strv(S, arm64_type_size(S->tccgen_vtop[0].type.t),
- fltr(S->tccgen_vtop[0].r), 31, a[i] - 32);
+ else if (is_float(vtop->type.t)) {
+ gv(RC_FLOAT);
+ arm64_strv(arm64_type_size(vtop[0].type.t),
+ fltr(vtop[0].r), 31, a[i] - 32);
}
else {
- gv(S, RC_INT);
- arm64_strx(S, arm64_type_size(S->tccgen_vtop[0].type.t),
- intr(S, S->tccgen_vtop[0].r), 31, a[i] - 32);
+ gv(RC_INT);
+ arm64_strx(arm64_type_size(vtop[0].type.t),
+ intr(vtop[0].r), 31, a[i] - 32);
}
}
- --S->tccgen_vtop;
+ --vtop;
}
// Second pass: assign values to registers
- for (i = nb_args; i; i--, S->tccgen_vtop--) {
+ for (i = nb_args; i; i--, vtop--) {
if (a[i] < 16 && !(a[i] & 1)) {
// value in general-purpose registers
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
- int align, size = type_size(&S->tccgen_vtop->type, &align);
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
+ int align, size = type_size(&vtop->type, &align);
if (size) {
- S->tccgen_vtop->type.t = VT_PTR;
- gaddrof(S);
- gv(S, RC_R(a[i] / 2));
- arm64_ldrs(S, a[i] / 2, size);
+ vtop->type.t = VT_PTR;
+ gaddrof();
+ gv(RC_R(a[i] / 2));
+ arm64_ldrs(a[i] / 2, size);
}
}
else
- gv(S, RC_R(a[i] / 2));
+ gv(RC_R(a[i] / 2));
}
else if (a[i] < 16)
// struct replaced by pointer in register
- arm64_spoff(S, a[i] / 2, a1[i]);
+ arm64_spoff(a[i] / 2, a1[i]);
else if (a[i] < 32) {
// value in floating-point registers
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
- uint32_t j, sz, n = arm64_hfa(&S->tccgen_vtop->type, &sz);
- S->tccgen_vtop->type.t = VT_PTR;
- gaddrof(S);
- gv(S, RC_R30);
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
+ vtop->type.t = VT_PTR;
+ gaddrof();
+ gv(RC_R30);
for (j = 0; j < n; j++)
- o(S, 0x3d4003c0 |
+ o(0x3d4003c0 |
(sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
(a[i] / 2 - 8 + j) |
j << 10); // ldr ([sdq])(*),[x30,#(j * sz)]
}
else
- gv(S, RC_F(a[i] / 2 - 8));
+ gv(RC_F(a[i] / 2 - 8));
}
}
if ((return_type->t & VT_BTYPE) == VT_STRUCT) {
if (a[0] == 1) {
// indirect return: set x8 and discard the stack value
- gv(S, RC_R(8));
- --S->tccgen_vtop;
+ gv(RC_R(8));
+ --vtop;
}
else
// return in registers: keep the address for after the call
- vswap(S);
+ vswap();
}
- save_regs(S, 0);
- arm64_gen_bl_or_b(S, 0);
- --S->tccgen_vtop;
+ save_regs(0);
+ arm64_gen_bl_or_b(0);
+ --vtop;
if (stack & 0xfff)
- o(S, 0x910003ff | (stack & 0xfff) << 10); // add sp,sp,#(n)
+ o(0x910003ff | (stack & 0xfff) << 10); // add sp,sp,#(n)
if (stack >> 12)
- o(S, 0x914003ff | (stack >> 12) << 10);
+ o(0x914003ff | (stack >> 12) << 10);
{
int rt = return_type->t;
int bt = rt & VT_BTYPE;
if (bt == VT_STRUCT && !(a[0] & 1)) {
// A struct was returned in registers, so write it out:
- gv(S, RC_R(8));
- --S->tccgen_vtop;
+ gv(RC_R(8));
+ --vtop;
if (a[0] == 0) {
int align, size = type_size(return_type, &align);
assert(size <= 16);
if (size > 8)
- o(S, 0xa9000500); // stp x0,x1,[x8]
+ o(0xa9000500); // stp x0,x1,[x8]
else if (size)
- arm64_strx(S, size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0);
+ arm64_strx(size > 4 ? 3 : size > 2 ? 2 : size > 1, 0, 8, 0);
}
else if (a[0] == 16) {
uint32_t j, sz, n = arm64_hfa(return_type, &sz);
for (j = 0; j < n; j++)
- o(S, 0x3d000100 |
+ o(0x3d000100 |
(sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
(a[i] / 2 - 8 + j) |
j << 10); // str ([sdq])(*),[x8,#(j * sz)]
@@ -1140,9 +1146,9 @@ ST_FUNC void gfunc_call(TCCState *S, int nb_args)
}
}
- tcc_free(S, a1);
- tcc_free(S, a);
- tcc_free(S, t);
+ tcc_free(a1);
+ tcc_free(a);
+ tcc_free(t);
}
static unsigned long arm64_func_va_list_stack;
@@ -1150,7 +1156,7 @@ static int arm64_func_va_list_gr_offs;
static int arm64_func_va_list_vr_offs;
static int arm64_func_sub_sp_offset;
-ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym)
+ST_FUNC void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
int n = 0;
@@ -1159,28 +1165,28 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym)
CType **t;
unsigned long *a;
- S->tccgen_func_vc = 144; // offset of where x8 is stored
+ func_vc = 144; // offset of where x8 is stored
for (sym = func_type->ref; sym; sym = sym->next)
++n;
- t = n ? tcc_malloc(S, n * sizeof(*t)) : NULL;
- a = n ? tcc_malloc(S, n * sizeof(*a)) : NULL;
+ t = n ? tcc_malloc(n * sizeof(*t)) : NULL;
+ a = n ? tcc_malloc(n * sizeof(*a)) : NULL;
for (sym = func_type->ref; sym; sym = sym->next)
t[i++] = &sym->type;
arm64_func_va_list_stack = arm64_pcs(n - 1, t, a);
- o(S, 0xa9b27bfd); // stp x29,x30,[sp,#-224]!
- o(S, 0xad0087e0); // stp q0,q1,[sp,#16]
- o(S, 0xad018fe2); // stp q2,q3,[sp,#48]
- o(S, 0xad0297e4); // stp q4,q5,[sp,#80]
- o(S, 0xad039fe6); // stp q6,q7,[sp,#112]
- o(S, 0xa90923e8); // stp x8,x8,[sp,#144]
- o(S, 0xa90a07e0); // stp x0,x1,[sp,#160]
- o(S, 0xa90b0fe2); // stp x2,x3,[sp,#176]
- o(S, 0xa90c17e4); // stp x4,x5,[sp,#192]
- o(S, 0xa90d1fe6); // stp x6,x7,[sp,#208]
+ o(0xa9b27bfd); // stp x29,x30,[sp,#-224]!
+ o(0xad0087e0); // stp q0,q1,[sp,#16]
+ o(0xad018fe2); // stp q2,q3,[sp,#48]
+ o(0xad0297e4); // stp q4,q5,[sp,#80]
+ o(0xad039fe6); // stp q6,q7,[sp,#112]
+ o(0xa90923e8); // stp x8,x8,[sp,#144]
+ o(0xa90a07e0); // stp x0,x1,[sp,#160]
+ o(0xa90b0fe2); // stp x2,x3,[sp,#176]
+ o(0xa90c17e4); // stp x4,x5,[sp,#192]
+ o(0xa90d1fe6); // stp x6,x7,[sp,#208]
arm64_func_va_list_gr_offs = -64;
arm64_func_va_list_vr_offs = -128;
@@ -1189,7 +1195,7 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym)
int off = (a[i] < 16 ? 160 + a[i] / 2 * 8 :
a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 :
224 + ((a[i] - 32) >> 1 << 1));
- sym_push(S, sym->v & ~SYM_FIELD, &sym->type,
+ sym_push(sym->v & ~SYM_FIELD, &sym->type,
(a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
off);
@@ -1209,65 +1215,65 @@ ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym)
uint32_t j, sz, k = arm64_hfa(&sym->type, &sz);
if (sz < 16)
for (j = 0; j < k; j++) {
- o(S, 0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
+ o(0x3d0003e0 | -(sz & 8) << 27 | (sz & 4) << 29 |
((a[i] - 16) / 2 + j) | (off / sz + j) << 10);
// str ([sdq])(*),[sp,#(j * sz)]
}
}
}
- tcc_free(S, a);
- tcc_free(S, t);
+ tcc_free(a);
+ tcc_free(t);
- o(S, 0x910003fd); // mov x29,sp
- arm64_func_sub_sp_offset = S->tccgen_ind;
+ o(0x910003fd); // mov x29,sp
+ arm64_func_sub_sp_offset = ind;
// In gfunc_epilog these will be replaced with code to decrement SP:
- o(S, 0xd503201f); // nop
- o(S, 0xd503201f); // nop
- S->tccgen_loc = 0;
+ o(0xd503201f); // nop
+ o(0xd503201f); // nop
+ loc = 0;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
-ST_FUNC void gen_va_start(TCCState *S)
+ST_FUNC void gen_va_start(void)
{
int r;
- --S->tccgen_vtop; // we don't need the "arg"
- gaddrof(S);
- r = intr(S, gv(S, RC_INT));
+ --vtop; // we don't need the "arg"
+ gaddrof();
+ r = intr(gv(RC_INT));
if (arm64_func_va_list_stack) {
//xx could use add (immediate) here
- arm64_movimm(S, 30, arm64_func_va_list_stack + 224);
- o(S, 0x8b1e03be); // add x30,x29,x30
+ arm64_movimm(30, arm64_func_va_list_stack + 224);
+ o(0x8b1e03be); // add x30,x29,x30
}
else
- o(S, 0x910383be); // add x30,x29,#224
- o(S, 0xf900001e | r << 5); // str x30,[x(r)]
+ o(0x910383be); // add x30,x29,#224
+ o(0xf900001e | r << 5); // str x30,[x(r)]
if (arm64_func_va_list_gr_offs) {
if (arm64_func_va_list_stack)
- o(S, 0x910383be); // add x30,x29,#224
- o(S, 0xf900041e | r << 5); // str x30,[x(r),#8]
+ o(0x910383be); // add x30,x29,#224
+ o(0xf900041e | r << 5); // str x30,[x(r),#8]
}
if (arm64_func_va_list_vr_offs) {
- o(S, 0x910243be); // add x30,x29,#144
- o(S, 0xf900081e | r << 5); // str x30,[x(r),#16]
+ o(0x910243be); // add x30,x29,#144
+ o(0xf900081e | r << 5); // str x30,[x(r),#16]
}
- arm64_movimm(S, 30, arm64_func_va_list_gr_offs);
- o(S, 0xb900181e | r << 5); // str w30,[x(r),#24]
+ arm64_movimm(30, arm64_func_va_list_gr_offs);
+ o(0xb900181e | r << 5); // str w30,[x(r),#24]
- arm64_movimm(S, 30, arm64_func_va_list_vr_offs);
- o(S, 0xb9001c1e | r << 5); // str w30,[x(r),#28]
+ arm64_movimm(30, arm64_func_va_list_vr_offs);
+ o(0xb9001c1e | r << 5); // str w30,[x(r),#28]
- --S->tccgen_vtop;
+ --vtop;
}
-ST_FUNC void gen_va_arg(TCCState *S, CType *t)
+ST_FUNC void gen_va_arg(CType *t)
{
int align, size = type_size(t, &align);
unsigned fsize, hfa = arm64_hfa(t, &fsize);
@@ -1278,69 +1284,69 @@ ST_FUNC void gen_va_arg(TCCState *S, CType *t)
fsize = size;
}
- gaddrof(S);
- r0 = intr(S, gv(S, RC_INT));
- r1 = get_reg(S, RC_INT);
- S->tccgen_vtop[0].r = r1 | VT_LVAL;
- r1 = intr(S, r1);
+ gaddrof();
+ r0 = intr(gv(RC_INT));
+ r1 = get_reg(RC_INT);
+ vtop[0].r = r1 | VT_LVAL;
+ r1 = intr(r1);
if (!hfa) {
uint32_t n = size > 16 ? 8 : (size + 7) & -8;
- o(S, 0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs
+ o(0xb940181e | r0 << 5); // ldr w30,[x(r0),#24] // __gr_offs
if (align == 16) {
assert(0); // this path untested but needed for __uint128_t
- o(S, 0x11003fde); // add w30,w30,#15
- o(S, 0x121c6fde); // and w30,w30,#-16
+ o(0x11003fde); // add w30,w30,#15
+ o(0x121c6fde); // and w30,w30,#-16
}
- o(S, 0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n)
- o(S, 0x540000ad); // b.le .+20
- o(S, 0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
- o(S, 0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n)
- o(S, 0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
- o(S, 0x14000004); // b .+16
- o(S, 0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs
- o(S, 0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top
- o(S, 0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
+ o(0x310003c0 | r1 | n << 10); // adds w(r1),w30,#(n)
+ o(0x540000ad); // b.le .+20
+ o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
+ o(0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n)
+ o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
+ o(0x14000004); // b .+16
+ o(0xb9001800 | r1 | r0 << 5); // str w(r1),[x(r0),#24] // __gr_offs
+ o(0xf9400400 | r1 | r0 << 5); // ldr x(r1),[x(r0),#8] // __gr_top
+ o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
if (size > 16)
- o(S, 0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)]
+ o(0xf9400000 | r1 | r1 << 5); // ldr x(r1),[x(r1)]
}
else {
uint32_t rsz = hfa << 4;
uint32_t ssz = (size + 7) & -(uint32_t)8;
uint32_t b1, b2;
- o(S, 0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs
- o(S, 0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz)
- b1 = S->tccgen_ind; o(S, 0x5400000d); // b.le lab1
- o(S, 0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
+ o(0xb9401c1e | r0 << 5); // ldr w30,[x(r0),#28] // __vr_offs
+ o(0x310003c0 | r1 | rsz << 10); // adds w(r1),w30,#(rsz)
+ b1 = ind; o(0x5400000d); // b.le lab1
+ o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
if (fsize == 16) {
- o(S, 0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15
- o(S, 0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16
+ o(0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15
+ o(0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16
}
- o(S, 0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz)
- o(S, 0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
- b2 = S->tccgen_ind; o(S, 0x14000000); // b lab2
+ o(0x9100001e | r1 << 5 | ssz << 10); // add x30,x(r1),#(ssz)
+ o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
+ b2 = ind; o(0x14000000); // b lab2
// lab1:
- write32le(cur_text_section->data + b1, 0x5400000d | (S->tccgen_ind - b1) << 3);
- o(S, 0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs
- o(S, 0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top
+ write32le(cur_text_section->data + b1, 0x5400000d | (ind - b1) << 3);
+ o(0xb9001c00 | r1 | r0 << 5); // str w(r1),[x(r0),#28] // __vr_offs
+ o(0xf9400800 | r1 | r0 << 5); // ldr x(r1),[x(r0),#16] // __vr_top
if (hfa == 1 || fsize == 16)
- o(S, 0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
+ o(0x8b3ec000 | r1 | r1 << 5); // add x(r1),x(r1),w30,sxtw
else {
// We need to change the layout of this HFA.
// Get some space on the stack using global variable "loc":
- S->tccgen_loc = (S->tccgen_loc - size) & -(uint32_t)align;
- o(S, 0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw
- arm64_movimm(S, r1, S->tccgen_loc);
- o(S, 0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1)
- o(S, 0x4c402bdc | (uint32_t)fsize << 7 |
+ loc = (loc - size) & -(uint32_t)align;
+ o(0x8b3ec000 | 30 | r1 << 5); // add x30,x(r1),w30,sxtw
+ arm64_movimm(r1, loc);
+ o(0x8b0003a0 | r1 | r1 << 16); // add x(r1),x29,x(r1)
+ o(0x4c402bdc | (uint32_t)fsize << 7 |
(uint32_t)(hfa == 2) << 15 |
(uint32_t)(hfa == 3) << 14); // ld1 {v28.(4s|2d),...},[x30]
- o(S, 0x0d00801c | r1 << 5 | (fsize == 8) << 10 |
+ o(0x0d00801c | r1 << 5 | (fsize == 8) << 10 |
(uint32_t)(hfa != 2) << 13 |
(uint32_t)(hfa != 3) << 21); // st(hfa) {v28.(s|d),...}[0],[x(r1)]
}
// lab2:
- write32le(cur_text_section->data + b2, 0x14000000 | (S->tccgen_ind - b2) >> 2);
+ write32le(cur_text_section->data + b2, 0x14000000 | (ind - b2) >> 2);
}
}
@@ -1350,7 +1356,7 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret,
return 0;
}
-ST_FUNC void gfunc_return(TCCState *S, CType *func_type)
+ST_FUNC void gfunc_return(CType *func_type)
{
CType *t = func_type;
unsigned long a;
@@ -1362,52 +1368,52 @@ ST_FUNC void gfunc_return(TCCState *S, CType *func_type)
case 0:
if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
int align, size = type_size(func_type, &align);
- gaddrof(S);
- gv(S, RC_R(0));
- arm64_ldrs(S, 0, size);
+ gaddrof();
+ gv(RC_R(0));
+ arm64_ldrs(0, size);
}
else
- gv(S, RC_IRET);
+ gv(RC_IRET);
break;
case 1: {
CType type = *func_type;
- mk_pointer(S, &type);
- vset(S, &type, VT_LOCAL | VT_LVAL, S->tccgen_func_vc);
- indir(S);
- vswap(S);
- vstore(S);
+ mk_pointer(&type);
+ vset(&type, VT_LOCAL | VT_LVAL, func_vc);
+ indir();
+ vswap();
+ vstore();
break;
}
case 16:
if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
- uint32_t j, sz, n = arm64_hfa(&S->tccgen_vtop->type, &sz);
- gaddrof(S);
- gv(S, RC_R(0));
+ uint32_t j, sz, n = arm64_hfa(&vtop->type, &sz);
+ gaddrof();
+ gv(RC_R(0));
for (j = 0; j < n; j++)
- o(S, 0x3d400000 |
+ o(0x3d400000 |
(sz & 16) << 19 | -(sz & 8) << 27 | (sz & 4) << 29 |
j | j << 10); // ldr ([sdq])(*),[x0,#(j * sz)]
}
else
- gv(S, RC_FRET);
+ gv(RC_FRET);
break;
default:
assert(0);
}
- S->tccgen_vtop--;
+ vtop--;
}
-ST_FUNC void gfunc_epilog(TCCState *S)
+ST_FUNC void gfunc_epilog(void)
{
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
- if (S->tccgen_loc) {
+ if (loc) {
// Insert instructions to subtract size of stack frame from SP.
unsigned char *ptr = cur_text_section->data + arm64_func_sub_sp_offset;
- uint64_t diff = (-S->tccgen_loc + 15) & ~15;
+ uint64_t diff = (-loc + 15) & ~15;
if (!(diff >> 24)) {
if (diff & 0xfff) // sub sp,sp,#(diff & 0xfff)
write32le(ptr, 0xd10003ff | (diff & 0xfff) << 10);
@@ -1433,40 +1439,40 @@ ST_FUNC void gfunc_epilog(TCCState *S)
// sub sp,sp,x16,lsl #(j)
}
}
- o(S, 0x910003bf); // mov sp,x29
- o(S, 0xa8ce7bfd); // ldp x29,x30,[sp],#224
+ o(0x910003bf); // mov sp,x29
+ o(0xa8ce7bfd); // ldp x29,x30,[sp],#224
- o(S, 0xd65f03c0); // ret
+ o(0xd65f03c0); // ret
}
-ST_FUNC void gen_fill_nops(TCCState *S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
if ((bytes & 3))
- tcc_error(S, "alignment of code section not multiple of 4");
+ tcc_error("alignment of code section not multiple of 4");
while (bytes > 0) {
- o(S, 0xd503201f); // nop
+ o(0xd503201f); // nop
bytes -= 4;
}
}
// Generate forward branch to label:
-ST_FUNC int gjmp(TCCState *S, int t)
+ST_FUNC int gjmp(int t)
{
- int r = S->tccgen_ind;
- if (S->tccgen_nocode_wanted)
+ int r = ind;
+ if (nocode_wanted)
return t;
- o(S, t);
+ o(t);
return r;
}
// Generate branch to known address:
-ST_FUNC void gjmp_addr(TCCState *S, int a)
+ST_FUNC void gjmp_addr(int a)
{
- assert(a - S->tccgen_ind + 0x8000000 < 0x10000000);
- o(S, 0x14000000 | ((a - S->tccgen_ind) >> 2 & 0x3ffffff));
+ assert(a - ind + 0x8000000 < 0x10000000);
+ o(0x14000000 | ((a - ind) >> 2 & 0x3ffffff));
}
-ST_FUNC int gjmp_append(TCCState *S, int n, int t)
+ST_FUNC int gjmp_append(int n, int t)
{
void *p;
/* insert vtop->c jump list in t */
@@ -1480,61 +1486,61 @@ ST_FUNC int gjmp_append(TCCState *S, int n, int t)
return t;
}
-void arm64_vset_VT_CMP(TCCState *S, int op)
+void arm64_vset_VT_CMP(int op)
{
if (op >= TOK_ULT && op <= TOK_GT) {
- S->tccgen_vtop->cmp_r = S->tccgen_vtop->r;
- vset_VT_CMP(S, 0x80);
+ vtop->cmp_r = vtop->r;
+ vset_VT_CMP(0x80);
}
}
-static void arm64_gen_opil(TCCState *S, int op, uint32_t l);
+static void arm64_gen_opil(int op, uint32_t l);
-static void arm64_load_cmp(TCCState *S, int r, SValue *sv)
+static void arm64_load_cmp(int r, SValue *sv)
{
sv->r = sv->cmp_r;
if (sv->c.i & 1) {
- vpushi(S, 1);
- arm64_gen_opil(S, '^', 0);
+ vpushi(1);
+ arm64_gen_opil('^', 0);
}
if (r != sv->r) {
- load(S, r, sv);
+ load(r, sv);
sv->r = r;
}
}
-ST_FUNC int gjmp_cond(TCCState *S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
- int bt = S->tccgen_vtop->type.t & VT_BTYPE;
+ int bt = vtop->type.t & VT_BTYPE;
int inv = op & 1;
- S->tccgen_vtop->r = S->tccgen_vtop->cmp_r;
+ vtop->r = vtop->cmp_r;
if (bt == VT_LDOUBLE) {
- uint32_t a, b, f = fltr(gv(S, RC_FLOAT));
- a = get_reg(S, RC_INT);
- vpushi(S, 0);
- S->tccgen_vtop[0].r = a;
- b = get_reg(S, RC_INT);
- a = intr(S, a);
- b = intr(S, b);
- o(S, 0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0]
- o(S, 0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1]
- o(S, 0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1
- o(S, 0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8
- --S->tccgen_vtop;
+ uint32_t a, b, f = fltr(gv(RC_FLOAT));
+ a = get_reg(RC_INT);
+ vpushi(0);
+ vtop[0].r = a;
+ b = get_reg(RC_INT);
+ a = intr(a);
+ b = intr(b);
+ o(0x4e083c00 | a | f << 5); // mov x(a),v(f).d[0]
+ o(0x4e183c00 | b | f << 5); // mov x(b),v(f).d[1]
+ o(0xaa000400 | a | a << 5 | b << 16); // orr x(a),x(a),x(b),lsl #1
+ o(0xb4000040 | a | !!inv << 24); // cbz/cbnz x(a),.+8
+ --vtop;
}
else if (bt == VT_FLOAT || bt == VT_DOUBLE) {
- uint32_t a = fltr(gv(S, RC_FLOAT));
- o(S, 0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp
- o(S, 0x54000040 | !!inv); // b.eq/b.ne .+8
+ uint32_t a = fltr(gv(RC_FLOAT));
+ o(0x1e202008 | a << 5 | (bt != VT_FLOAT) << 22); // fcmp
+ o(0x54000040 | !!inv); // b.eq/b.ne .+8
}
else {
uint32_t ll = (bt == VT_PTR || bt == VT_LLONG);
- uint32_t a = intr(S, gv(S, RC_INT));
- o(S, 0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8
+ uint32_t a = intr(gv(RC_INT));
+ o(0x34000040 | a | !!inv << 24 | ll << 31); // cbz/cbnz wA,.+8
}
- return gjmp(S, t);
+ return gjmp(t);
}
static int arm64_iconst(uint64_t *val, SValue *sv)
@@ -1551,7 +1557,7 @@ static int arm64_iconst(uint64_t *val, SValue *sv)
return 1;
}
-static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val,
+static int arm64_gen_opic(int op, uint32_t l, int rev, uint64_t val,
uint32_t x, uint32_t a)
{
if (op == '-' && !rev) {
@@ -1567,30 +1573,30 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val
val = s ? -val : val;
val = l ? val : (uint32_t)val;
if (!(val & ~(uint64_t)0xfff))
- o(S, 0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10);
+ o(0x11000000 | l << 31 | s << 30 | x | a << 5 | val << 10);
else if (!(val & ~(uint64_t)0xfff000))
- o(S, 0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10);
+ o(0x11400000 | l << 31 | s << 30 | x | a << 5 | val >> 12 << 10);
else {
- arm64_movimm(S, 30, val); // use x30
- o(S, 0x0b1e0000 | l << 31 | s << 30 | x | a << 5);
+ arm64_movimm(30, val); // use x30
+ o(0x0b1e0000 | l << 31 | s << 30 | x | a << 5);
}
return 1;
}
case '-':
if (!val)
- o(S, 0x4b0003e0 | l << 31 | x | a << 16); // neg
+ o(0x4b0003e0 | l << 31 | x | a << 16); // neg
else if (val == (l ? (uint64_t)-1 : (uint32_t)-1))
- o(S, 0x2a2003e0 | l << 31 | x | a << 16); // mvn
+ o(0x2a2003e0 | l << 31 | x | a << 16); // mvn
else {
- arm64_movimm(S, 30, val); // use x30
- o(S, 0x4b0003c0 | l << 31 | x | a << 16); // sub
+ arm64_movimm(30, val); // use x30
+ o(0x4b0003c0 | l << 31 | x | a << 16); // sub
}
return 1;
case '^':
if (val == -1 || (val == 0xffffffff && !l)) {
- o(S, 0x2a2003e0 | l << 31 | x | a << 16); // mvn
+ o(0x2a2003e0 | l << 31 | x | a << 16); // mvn
return 1;
}
// fall through
@@ -1599,7 +1605,7 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val
int e = arm64_encode_bimm64(l ? val : val | val << 32);
if (e < 0)
return 0;
- o(S, (op == '&' ? 0x12000000 :
+ o((op == '&' ? 0x12000000 :
op == '|' ? 0x32000000 : 0x52000000) |
l << 31 | x | a << 5 | (uint32_t)e << 10);
return 1;
@@ -1614,14 +1620,14 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val
return 0;
if (!val) {
// tcc_warning("shift count >= width of type");
- o(S, 0x2a0003e0 | l << 31 | a << 16);
+ o(0x2a0003e0 | l << 31 | a << 16);
return 1;
}
else if (op == TOK_SHL)
- o(S, 0x53000000 | l << 31 | l << 22 | x | a << 5 |
+ o(0x53000000 | l << 31 | l << 22 | x | a << 5 |
(n - val) << 16 | (n - 1 - val) << 10); // lsl
else
- o(S, 0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 |
+ o(0x13000000 | (op == TOK_SHR) << 30 | l << 31 | l << 22 |
x | a << 5 | val << 16 | (n - 1) << 10); // lsr/asr
return 1;
}
@@ -1630,7 +1636,7 @@ static int arm64_gen_opic(TCCState *S, int op, uint32_t l, int rev, uint64_t val
return 0;
}
-static void arm64_gen_opil(TCCState *S, int op, uint32_t l)
+static void arm64_gen_opil(int op, uint32_t l)
{
uint32_t x, a, b;
@@ -1639,122 +1645,122 @@ static void arm64_gen_opil(TCCState *S, int op, uint32_t l)
uint64_t val;
int rev = 1;
- if (arm64_iconst(0, &S->tccgen_vtop[0])) {
- vswap(S);
+ if (arm64_iconst(0, &vtop[0])) {
+ vswap();
rev = 0;
}
- if (arm64_iconst(&val, &S->tccgen_vtop[-1])) {
- gv(S, RC_INT);
- a = intr(S, S->tccgen_vtop[0].r);
- --S->tccgen_vtop;
- x = get_reg(S, RC_INT);
- ++S->tccgen_vtop;
- if (arm64_gen_opic(S, op, l, rev, val, intr(S, x), a)) {
- S->tccgen_vtop[0].r = x;
- vswap(S);
- --S->tccgen_vtop;
+ if (arm64_iconst(&val, &vtop[-1])) {
+ gv(RC_INT);
+ a = intr(vtop[0].r);
+ --vtop;
+ x = get_reg(RC_INT);
+ ++vtop;
+ if (arm64_gen_opic(op, l, rev, val, intr(x), a)) {
+ vtop[0].r = x;
+ vswap();
+ --vtop;
return;
}
}
if (!rev)
- vswap(S);
+ vswap();
}
- gv2(S, RC_INT, RC_INT);
- assert(S->tccgen_vtop[-1].r < VT_CONST && S->tccgen_vtop[0].r < VT_CONST);
- a = intr(S, S->tccgen_vtop[-1].r);
- b = intr(S, S->tccgen_vtop[0].r);
- S->tccgen_vtop -= 2;
- x = get_reg(S, RC_INT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = x;
- x = intr(S, x);
+ gv2(RC_INT, RC_INT);
+ assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST);
+ a = intr(vtop[-1].r);
+ b = intr(vtop[0].r);
+ vtop -= 2;
+ x = get_reg(RC_INT);
+ ++vtop;
+ vtop[0].r = x;
+ x = intr(x);
switch (op) {
case '%':
// Use x30 for quotient:
- o(S, 0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv
- o(S, 0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
+ o(0x1ac00c00 | l << 31 | 30 | a << 5 | b << 16); // sdiv
+ o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
b << 16 | a << 10); // msub
break;
case '&':
- o(S, 0x0a000000 | l << 31 | x | a << 5 | b << 16); // and
+ o(0x0a000000 | l << 31 | x | a << 5 | b << 16); // and
break;
case '*':
- o(S, 0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul
+ o(0x1b007c00 | l << 31 | x | a << 5 | b << 16); // mul
break;
case '+':
- o(S, 0x0b000000 | l << 31 | x | a << 5 | b << 16); // add
+ o(0x0b000000 | l << 31 | x | a << 5 | b << 16); // add
break;
case '-':
- o(S, 0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
+ o(0x4b000000 | l << 31 | x | a << 5 | b << 16); // sub
break;
case '/':
- o(S, 0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
+ o(0x1ac00c00 | l << 31 | x | a << 5 | b << 16); // sdiv
break;
case '^':
- o(S, 0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor
+ o(0x4a000000 | l << 31 | x | a << 5 | b << 16); // eor
break;
case '|':
- o(S, 0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr
+ o(0x2a000000 | l << 31 | x | a << 5 | b << 16); // orr
break;
case TOK_EQ:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f17e0 | x); // cset wA,eq
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f17e0 | x); // cset wA,eq
break;
case TOK_GE:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9fb7e0 | x); // cset wA,ge
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9fb7e0 | x); // cset wA,ge
break;
case TOK_GT:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9fd7e0 | x); // cset wA,gt
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9fd7e0 | x); // cset wA,gt
break;
case TOK_LE:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9fc7e0 | x); // cset wA,le
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9fc7e0 | x); // cset wA,le
break;
case TOK_LT:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9fa7e0 | x); // cset wA,lt
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9fa7e0 | x); // cset wA,lt
break;
case TOK_NE:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f07e0 | x); // cset wA,ne
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f07e0 | x); // cset wA,ne
break;
case TOK_SAR:
- o(S, 0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr
+ o(0x1ac02800 | l << 31 | x | a << 5 | b << 16); // asr
break;
case TOK_SHL:
- o(S, 0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl
+ o(0x1ac02000 | l << 31 | x | a << 5 | b << 16); // lsl
break;
case TOK_SHR:
- o(S, 0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
+ o(0x1ac02400 | l << 31 | x | a << 5 | b << 16); // lsr
break;
case TOK_UDIV:
case TOK_PDIV:
- o(S, 0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
+ o(0x1ac00800 | l << 31 | x | a << 5 | b << 16); // udiv
break;
case TOK_UGE:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f37e0 | x); // cset wA,cs
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f37e0 | x); // cset wA,cs
break;
case TOK_UGT:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f97e0 | x); // cset wA,hi
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f97e0 | x); // cset wA,hi
break;
case TOK_ULT:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f27e0 | x); // cset wA,cc
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f27e0 | x); // cset wA,cc
break;
case TOK_ULE:
- o(S, 0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
- o(S, 0x1a9f87e0 | x); // cset wA,ls
+ o(0x6b00001f | l << 31 | a << 5 | b << 16); // cmp
+ o(0x1a9f87e0 | x); // cset wA,ls
break;
case TOK_UMOD:
// Use x30 for quotient:
- o(S, 0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv
- o(S, 0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
+ o(0x1ac00800 | l << 31 | 30 | a << 5 | b << 16); // udiv
+ o(0x1b008000 | l << 31 | x | (uint32_t)30 << 5 |
b << 16 | a << 10); // msub
break;
default:
@@ -1762,24 +1768,24 @@ static void arm64_gen_opil(TCCState *S, int op, uint32_t l)
}
}
-ST_FUNC void gen_opi(TCCState *S, int op)
+ST_FUNC void gen_opi(int op)
{
- arm64_gen_opil(S, op, 0);
- arm64_vset_VT_CMP(S, op);
+ arm64_gen_opil(op, 0);
+ arm64_vset_VT_CMP(op);
}
-ST_FUNC void gen_opl(TCCState* S, int op)
+ST_FUNC void gen_opl(int op)
{
- arm64_gen_opil(S, op, 1);
- arm64_vset_VT_CMP(S, op);
+ arm64_gen_opil(op, 1);
+ arm64_vset_VT_CMP(op);
}
-ST_FUNC void gen_opf(TCCState *S, int op)
+ST_FUNC void gen_opf(int op)
{
uint32_t x, a, b, dbl;
- if (S->tccgen_vtop[0].type.t == VT_LDOUBLE) {
- CType type = S->tccgen_vtop[0].type;
+ if (vtop[0].type.t == VT_LDOUBLE) {
+ CType type = vtop[0].type;
int func = 0;
int cond = -1;
switch (op) {
@@ -1795,162 +1801,162 @@ ST_FUNC void gen_opf(TCCState *S, int op)
case TOK_GT: func = TOK___gttf2; cond = 13; break;
default: assert(0); break;
}
- vpush_helper_func(S, func);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = cond < 0 ? REG_FRET : REG_IRET;
+ vpush_helper_func(func);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = cond < 0 ? REG_FRET : REG_IRET;
if (cond < 0)
- S->tccgen_vtop->type = type;
+ vtop->type = type;
else {
- o(S, 0x7100001f); // cmp w0,#0
- o(S, 0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond)
+ o(0x7100001f); // cmp w0,#0
+ o(0x1a9f07e0 | (uint32_t)cond << 12); // cset w0,(cond)
}
return;
}
- dbl = S->tccgen_vtop[0].type.t != VT_FLOAT;
- gv2(S, RC_FLOAT, RC_FLOAT);
- assert(S->tccgen_vtop[-1].r < VT_CONST && S->tccgen_vtop[0].r < VT_CONST);
- a = fltr(S->tccgen_vtop[-1].r);
- b = fltr(S->tccgen_vtop[0].r);
- S->tccgen_vtop -= 2;
+ dbl = vtop[0].type.t != VT_FLOAT;
+ gv2(RC_FLOAT, RC_FLOAT);
+ assert(vtop[-1].r < VT_CONST && vtop[0].r < VT_CONST);
+ a = fltr(vtop[-1].r);
+ b = fltr(vtop[0].r);
+ vtop -= 2;
switch (op) {
case TOK_EQ: case TOK_NE:
case TOK_LT: case TOK_GE: case TOK_LE: case TOK_GT:
- x = get_reg(S, RC_INT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = x;
- x = intr(S, x);
+ x = get_reg(RC_INT);
+ ++vtop;
+ vtop[0].r = x;
+ x = intr(x);
break;
default:
- x = get_reg(S, RC_FLOAT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = x;
+ x = get_reg(RC_FLOAT);
+ ++vtop;
+ vtop[0].r = x;
x = fltr(x);
break;
}
switch (op) {
case '*':
- o(S, 0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul
+ o(0x1e200800 | dbl << 22 | x | a << 5 | b << 16); // fmul
break;
case '+':
- o(S, 0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd
+ o(0x1e202800 | dbl << 22 | x | a << 5 | b << 16); // fadd
break;
case '-':
- o(S, 0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub
+ o(0x1e203800 | dbl << 22 | x | a << 5 | b << 16); // fsub
break;
case '/':
- o(S, 0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv
+ o(0x1e201800 | dbl << 22 | x | a << 5 | b << 16); // fdiv
break;
case TOK_EQ:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9f17e0 | x); // cset w(x),eq
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9f17e0 | x); // cset w(x),eq
break;
case TOK_GE:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9fb7e0 | x); // cset w(x),ge
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9fb7e0 | x); // cset w(x),ge
break;
case TOK_GT:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9fd7e0 | x); // cset w(x),gt
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9fd7e0 | x); // cset w(x),gt
break;
case TOK_LE:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9f87e0 | x); // cset w(x),ls
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9f87e0 | x); // cset w(x),ls
break;
case TOK_LT:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9f57e0 | x); // cset w(x),mi
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9f57e0 | x); // cset w(x),mi
break;
case TOK_NE:
- o(S, 0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
- o(S, 0x1a9f07e0 | x); // cset w(x),ne
+ o(0x1e202000 | dbl << 22 | a << 5 | b << 16); // fcmp
+ o(0x1a9f07e0 | x); // cset w(x),ne
break;
default:
assert(0);
}
- arm64_vset_VT_CMP(S, op);
+ arm64_vset_VT_CMP(op);
}
// Generate sign extension from 32 to 64 bits:
-ST_FUNC void gen_cvt_sxtw(TCCState *S)
+ST_FUNC void gen_cvt_sxtw(void)
{
- uint32_t r = intr(S, gv(S, RC_INT));
- o(S, 0x93407c00 | r | r << 5); // sxtw x(r),w(r)
+ uint32_t r = intr(gv(RC_INT));
+ o(0x93407c00 | r | r << 5); // sxtw x(r),w(r)
}
/* char/short to int conversion */
-ST_FUNC void gen_cvt_csti(TCCState *S, int t)
+ST_FUNC void gen_cvt_csti(int t)
{
- int r = intr(S, gv(S, RC_INT));
- o(S, 0x13001c00
+ int r = intr(gv(RC_INT));
+ o(0x13001c00
| ((t & VT_BTYPE) == VT_SHORT) << 13
| (uint32_t)!!(t & VT_UNSIGNED) << 30
| r | r << 5); // [su]xt[bh] w(r),w(r)
}
-ST_FUNC void gen_cvt_itof(TCCState *S, int t)
+ST_FUNC void gen_cvt_itof(int t)
{
if (t == VT_LDOUBLE) {
- int f = S->tccgen_vtop->type.t;
+ int f = vtop->type.t;
int func = (f & VT_BTYPE) == VT_LLONG ?
(f & VT_UNSIGNED ? TOK___floatunditf : TOK___floatditf) :
(f & VT_UNSIGNED ? TOK___floatunsitf : TOK___floatsitf);
- vpush_helper_func(S, func);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = t;
- S->tccgen_vtop->r = REG_FRET;
+ vpush_helper_func(func);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ vtop->type.t = t;
+ vtop->r = REG_FRET;
return;
}
else {
- int d, n = intr(S, gv(S, RC_INT));
- int s = !(S->tccgen_vtop->type.t & VT_UNSIGNED);
- uint32_t l = ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG);
- --S->tccgen_vtop;
- d = get_reg(S, RC_FLOAT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = d;
- o(S, 0x1e220000 | (uint32_t)!s << 16 |
+ int d, n = intr(gv(RC_INT));
+ int s = !(vtop->type.t & VT_UNSIGNED);
+ uint32_t l = ((vtop->type.t & VT_BTYPE) == VT_LLONG);
+ --vtop;
+ d = get_reg(RC_FLOAT);
+ ++vtop;
+ vtop[0].r = d;
+ o(0x1e220000 | (uint32_t)!s << 16 |
(uint32_t)(t != VT_FLOAT) << 22 | fltr(d) |
l << 31 | n << 5); // [us]cvtf [sd](d),[wx](n)
}
}
-ST_FUNC void gen_cvt_ftoi(TCCState *S, int t)
+ST_FUNC void gen_cvt_ftoi(int t)
{
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
int func = (t & VT_BTYPE) == VT_LLONG ?
(t & VT_UNSIGNED ? TOK___fixunstfdi : TOK___fixtfdi) :
(t & VT_UNSIGNED ? TOK___fixunstfsi : TOK___fixtfsi);
- vpush_helper_func(S, func);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = t;
- S->tccgen_vtop->r = REG_IRET;
+ vpush_helper_func(func);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ vtop->type.t = t;
+ vtop->r = REG_IRET;
return;
}
else {
- int d, n = fltr(gv(S, RC_FLOAT));
- uint32_t l = ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FLOAT);
- --S->tccgen_vtop;
- d = get_reg(S, RC_INT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = d;
- o(S, 0x1e380000 |
+ int d, n = fltr(gv(RC_FLOAT));
+ uint32_t l = ((vtop->type.t & VT_BTYPE) != VT_FLOAT);
+ --vtop;
+ d = get_reg(RC_INT);
+ ++vtop;
+ vtop[0].r = d;
+ o(0x1e380000 |
(uint32_t)!!(t & VT_UNSIGNED) << 16 |
- (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(S, d) |
+ (uint32_t)((t & VT_BTYPE) == VT_LLONG) << 31 | intr(d) |
l << 22 | n << 5); // fcvtz[su] [wx](d),[sd](n)
}
}
-ST_FUNC void gen_cvt_ftof(TCCState *S, int t)
+ST_FUNC void gen_cvt_ftof(int t)
{
- int f = S->tccgen_vtop[0].type.t & VT_BTYPE;
+ int f = vtop[0].type.t & VT_BTYPE;
assert(t == VT_FLOAT || t == VT_DOUBLE || t == VT_LDOUBLE);
assert(f == VT_FLOAT || f == VT_DOUBLE || f == VT_LDOUBLE);
if (t == f)
@@ -1960,142 +1966,142 @@ ST_FUNC void gen_cvt_ftof(TCCState *S, int t)
int func = (t == VT_LDOUBLE) ?
(f == VT_FLOAT ? TOK___extendsftf2 : TOK___extenddftf2) :
(t == VT_FLOAT ? TOK___trunctfsf2 : TOK___trunctfdf2);
- vpush_helper_func(S, func);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = t;
- S->tccgen_vtop->r = REG_FRET;
+ vpush_helper_func(func);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ vtop->type.t = t;
+ vtop->r = REG_FRET;
}
else {
int x, a;
- gv(S, RC_FLOAT);
- assert(S->tccgen_vtop[0].r < VT_CONST);
- a = fltr(S->tccgen_vtop[0].r);
- --S->tccgen_vtop;
- x = get_reg(S, RC_FLOAT);
- ++S->tccgen_vtop;
- S->tccgen_vtop[0].r = x;
+ gv(RC_FLOAT);
+ assert(vtop[0].r < VT_CONST);
+ a = fltr(vtop[0].r);
+ --vtop;
+ x = get_reg(RC_FLOAT);
+ ++vtop;
+ vtop[0].r = x;
x = fltr(x);
if (f == VT_FLOAT)
- o(S, 0x1e22c000 | x | a << 5); // fcvt d(x),s(a)
+ o(0x1e22c000 | x | a << 5); // fcvt d(x),s(a)
else
- o(S, 0x1e624000 | x | a << 5); // fcvt s(x),d(a)
+ o(0x1e624000 | x | a << 5); // fcvt s(x),d(a)
}
}
/* increment tcov counter */
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
+ST_FUNC void gen_increment_tcov (SValue *sv)
{
int r1, r2;
- vpushv(S, sv);
- S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
- r2 = get_reg(S, RC_INT);
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_AARCH64_ADR_GOT_PAGE, 0);
- o(S, 0x90000000 | r1); // adrp r1, #sym
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
- o(S, 0xf9400000 | r1 | (r1 << 5)); // ld xr,[xr, #sym]
- o(S, 0xf9400000 | (intr(S, r1)<<5) | intr(S, r2)); // ldr r2, [r1]
- o(S, 0x91000400 | (intr(S, r2)<<5) | intr(S, r2)); // add r2, r2, #1
- o(S, 0xf9000000 | (intr(S, r1)<<5) | intr(S, r2)); // str r2, [r1]
- vpop(S);
+ vpushv(sv);
+ vtop->r = r1 = get_reg(RC_INT);
+ r2 = get_reg(RC_INT);
+ greloca(cur_text_section, sv->sym, ind, R_AARCH64_ADR_GOT_PAGE, 0);
+ o(0x90000000 | r1); // adrp r1, #sym
+ greloca(cur_text_section, sv->sym, ind, R_AARCH64_LD64_GOT_LO12_NC, 0);
+ o(0xf9400000 | r1 | (r1 << 5)); // ld xr,[xr, #sym]
+ o(0xf9400000 | (intr(r1)<<5) | intr(r2)); // ldr r2, [r1]
+ o(0x91000400 | (intr(r2)<<5) | intr(r2)); // add r2, r2, #1
+ o(0xf9000000 | (intr(r1)<<5) | intr(r2)); // str r2, [r1]
+ vpop();
}
-ST_FUNC void ggoto(TCCState *S)
+ST_FUNC void ggoto(void)
{
- arm64_gen_bl_or_b(S, 1);
- --S->tccgen_vtop;
+ arm64_gen_bl_or_b(1);
+ --vtop;
}
-ST_FUNC void gen_clear_cache(TCCState *S)
+ST_FUNC void gen_clear_cache(void)
{
uint32_t beg, end, dsz, isz, p, lab1, b1;
- gv2(S, RC_INT, RC_INT);
- vpushi(S, 0);
- S->tccgen_vtop->r = get_reg(S, RC_INT);
- vpushi(S, 0);
- S->tccgen_vtop->r = get_reg(S, RC_INT);
- vpushi(S, 0);
- S->tccgen_vtop->r = get_reg(S, RC_INT);
- beg = intr(S, S->tccgen_vtop[-4].r); // x0
- end = intr(S, S->tccgen_vtop[-3].r); // x1
- dsz = intr(S, S->tccgen_vtop[-2].r); // x2
- isz = intr(S, S->tccgen_vtop[-1].r); // x3
- p = intr(S, S->tccgen_vtop[0].r); // x4
- S->tccgen_vtop -= 5;
-
- o(S, 0xd53b0020 | isz); // mrs x(isz),ctr_el0
- o(S, 0x52800080 | p); // mov w(p),#4
- o(S, 0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4
- o(S, 0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz)
- o(S, 0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15
- o(S, 0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz)
- o(S, 0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1
- o(S, 0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
- b1 = S->tccgen_ind; o(S, 0x14000000); // b
- lab1 = S->tccgen_ind;
- o(S, 0xd50b7b20 | p); // dc cvau,x(p)
- o(S, 0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz)
- write32le(cur_text_section->data + b1, 0x14000000 | (S->tccgen_ind - b1) >> 2);
- o(S, 0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
- o(S, 0x54ffffa3 | ((lab1 - S->tccgen_ind) << 3 & 0xffffe0)); // b.cc lab1
- o(S, 0xd5033b9f); // dsb ish
- o(S, 0x51000400 | p | isz << 5); // sub w(p),w(isz),#1
- o(S, 0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
- b1 = S->tccgen_ind; o(S, 0x14000000); // b
- lab1 = S->tccgen_ind;
- o(S, 0xd50b7520 | p); // ic ivau,x(p)
- o(S, 0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz)
- write32le(cur_text_section->data + b1, 0x14000000 | (S->tccgen_ind - b1) >> 2);
- o(S, 0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
- o(S, 0x54ffffa3 | ((lab1 - S->tccgen_ind) << 3 & 0xffffe0)); // b.cc lab1
- o(S, 0xd5033b9f); // dsb ish
- o(S, 0xd5033fdf); // isb
+ gv2(RC_INT, RC_INT);
+ vpushi(0);
+ vtop->r = get_reg(RC_INT);
+ vpushi(0);
+ vtop->r = get_reg(RC_INT);
+ vpushi(0);
+ vtop->r = get_reg(RC_INT);
+ beg = intr(vtop[-4].r); // x0
+ end = intr(vtop[-3].r); // x1
+ dsz = intr(vtop[-2].r); // x2
+ isz = intr(vtop[-1].r); // x3
+ p = intr(vtop[0].r); // x4
+ vtop -= 5;
+
+ o(0xd53b0020 | isz); // mrs x(isz),ctr_el0
+ o(0x52800080 | p); // mov w(p),#4
+ o(0x53104c00 | dsz | isz << 5); // ubfx w(dsz),w(isz),#16,#4
+ o(0x1ac02000 | dsz | p << 5 | dsz << 16); // lsl w(dsz),w(p),w(dsz)
+ o(0x12000c00 | isz | isz << 5); // and w(isz),w(isz),#15
+ o(0x1ac02000 | isz | p << 5 | isz << 16); // lsl w(isz),w(p),w(isz)
+ o(0x51000400 | p | dsz << 5); // sub w(p),w(dsz),#1
+ o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
+ b1 = ind; o(0x14000000); // b
+ lab1 = ind;
+ o(0xd50b7b20 | p); // dc cvau,x(p)
+ o(0x8b000000 | p | p << 5 | dsz << 16); // add x(p),x(p),x(dsz)
+ write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2);
+ o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
+ o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1
+ o(0xd5033b9f); // dsb ish
+ o(0x51000400 | p | isz << 5); // sub w(p),w(isz),#1
+ o(0x8a240004 | p | beg << 5 | p << 16); // bic x(p),x(beg),x(p)
+ b1 = ind; o(0x14000000); // b
+ lab1 = ind;
+ o(0xd50b7520 | p); // ic ivau,x(p)
+ o(0x8b000000 | p | p << 5 | isz << 16); // add x(p),x(p),x(isz)
+ write32le(cur_text_section->data + b1, 0x14000000 | (ind - b1) >> 2);
+ o(0xeb00001f | p << 5 | end << 16); // cmp x(p),x(end)
+ o(0x54ffffa3 | ((lab1 - ind) << 3 & 0xffffe0)); // b.cc lab1
+ o(0xd5033b9f); // dsb ish
+ o(0xd5033fdf); // isb
}
-ST_FUNC void gen_vla_sp_save(TCCState *S, int addr) {
- uint32_t r = intr(S, get_reg(S, RC_INT));
- o(S, 0x910003e0 | r); // mov x(r),sp
- arm64_strx(S, 3, r, 29, addr);
+ST_FUNC void gen_vla_sp_save(int addr) {
+ uint32_t r = intr(get_reg(RC_INT));
+ o(0x910003e0 | r); // mov x(r),sp
+ arm64_strx(3, r, 29, addr);
}
-ST_FUNC void gen_vla_sp_restore(TCCState *S, int addr) {
+ST_FUNC void gen_vla_sp_restore(int addr) {
// Use x30 because this function can be called when there
// is a live return value in x0 but there is nothing on
// the value stack to prevent get_reg from returning x0.
uint32_t r = 30;
- arm64_ldrx(S, 0, 3, r, 29, addr);
- o(S, 0x9100001f | r << 5); // mov sp,x(r)
+ arm64_ldrx(0, 3, r, 29, addr);
+ o(0x9100001f | r << 5); // mov sp,x(r)
}
-ST_FUNC void gen_vla_alloc(TCCState *S, CType *type, int align) {
+ST_FUNC void gen_vla_alloc(CType *type, int align) {
uint32_t r;
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- vpushv(S, S->tccgen_vtop);
+ if (tcc_state->do_bounds_check)
+ vpushv(vtop);
#endif
- r = intr(S, gv(S, RC_INT));
+ r = intr(gv(RC_INT));
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- o(S, 0x91004000 | r | r << 5); // add x(r),x(r),#15+1
+ if (tcc_state->do_bounds_check)
+ o(0x91004000 | r | r << 5); // add x(r),x(r),#15+1
else
#endif
- o(S, 0x91003c00 | r | r << 5); // add x(r),x(r),#15
- o(S, 0x927cec00 | r | r << 5); // bic x(r),x(r),#15
- o(S, 0xcb2063ff | r << 16); // sub sp,sp,x(r)
- vpop(S);
+ o(0x91003c00 | r | r << 5); // add x(r),x(r),#15
+ o(0x927cec00 | r | r << 5); // bic x(r),x(r),#15
+ o(0xcb2063ff | r << 16); // sub sp,sp,x(r)
+ vpop();
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check) {
- vpushi(S, 0);
- S->tccgen_vtop->r = TREG_R(0);
- o(S, 0x910003e0 | S->tccgen_vtop->r); // mov r0,sp
- vswap(S);
- vpush_helper_func(S, TOK___bound_new_region);
- vrott(S, 3);
- gfunc_call(S, 2);
- S->func_bound_add_epilog = 1;
+ if (tcc_state->do_bounds_check) {
+ vpushi(0);
+ vtop->r = TREG_R(0);
+ o(0x910003e0 | vtop->r); // mov r0,sp
+ vswap();
+ vpush_helper_func(TOK___bound_new_region);
+ vrott(3);
+ gfunc_call(2);
+ func_bound_add_epilog = 1;
}
#endif
}
diff --git a/arm64-link.c b/arm64-link.c
index 9e0177d..e4305fe 100644
--- a/arm64-link.c
+++ b/arm64-link.c
@@ -90,18 +90,18 @@ int gotplt_entry_type (int reloc_type)
return -1;
}
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- Section *plt = S->plt;
+ Section *plt = s1->plt;
uint8_t *p;
unsigned plt_offset;
if (plt->data_offset == 0) {
- section_ptr_add(S, plt, 32);
+ section_ptr_add(plt, 32);
}
plt_offset = plt->data_offset;
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
write32le(p, got_offset);
write32le(p + 4, (uint64_t) got_offset >> 32);
return plt_offset;
@@ -109,22 +109,22 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
if (p < p_end) {
- uint64_t plt = S->plt->sh_addr;
- uint64_t got = S->got->sh_addr + 16;
+ uint64_t plt = s1->plt->sh_addr;
+ uint64_t got = s1->got->sh_addr + 16;
uint64_t off = (got >> 12) - (plt >> 12);
if ((off + ((uint32_t)1 << 20)) >> 21)
- tcc_error(S, "Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
+ tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
write32le(p, 0xa9bf7bf0); // stp x16,x30,[sp,#-16]!
write32le(p + 4, (0x90000010 | // adrp x16,...
(off & 0x1ffffc) << 3 | (off & 3) << 29));
@@ -137,13 +137,13 @@ ST_FUNC void relocate_plt(TCCState *S)
write32le(p + 24, 0xd503201f); // nop
write32le(p + 28, 0xd503201f); // nop
p += 32;
- got = S->got->sh_addr;
+ got = s1->got->sh_addr;
while (p < p_end) {
- uint64_t pc = plt + (p - S->plt->data);
+ uint64_t pc = plt + (p - s1->plt->data);
uint64_t addr = got + read64le(p);
uint64_t off = (addr >> 12) - (pc >> 12);
if ((off + ((uint32_t)1 << 20)) >> 21)
- tcc_error(S, "Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
+ tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
write32le(p, (0x90000010 | // adrp x16,...
(off & 0x1ffffc) << 3 | (off & 3) << 29));
write32le(p + 4, (0xf9400211 | // ldr x17,[x16,#...]
@@ -155,16 +155,16 @@ ST_FUNC void relocate_plt(TCCState *S)
}
}
- if (S->plt->reloc) {
+ if (s1->plt->reloc) {
ElfW_Rel *rel;
- p = S->got->data;
- for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
- write64le(p + rel->r_offset, S->plt->sh_addr);
+ p = s1->got->data;
+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
+ write64le(p + rel->r_offset, s1->plt->sh_addr);
}
}
}
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index = ELFW(R_SYM)(rel->r_info), esym_index;
#ifdef DEBUG_RELOC
@@ -173,8 +173,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
switch(type) {
case R_AARCH64_ABS64:
- if (S->output_type == TCC_OUTPUT_DLL) {
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
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
add64le(ptr, val);
return;
case R_AARCH64_ABS32:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* XXX: this logic may depend on TCC's codegen
now TCC uses R_AARCH64_RELATIVE even for a 64bit pointer */
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
add32le(ptr, val);
return;
case R_AARCH64_PREL32:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
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
case R_AARCH64_ADR_PREL_PG_HI21: {
uint64_t off = (val >> 12) - (addr >> 12);
if ((off + ((uint64_t)1 << 20)) >> 21)
- tcc_error(S, "R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
+ tcc_error("R_AARCH64_ADR_PREL_PG_HI21 relocation failed");
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
(off & 0x1ffffc) << 3 | (off & 3) << 29));
return;
@@ -268,7 +268,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
(char *) symtab_section->link->data + sym->st_name);
#endif
if (((val - addr) + ((uint64_t)1 << 27)) & ~(uint64_t)0xffffffc)
- tcc_error(S, "R_AARCH64_(JUMP|CALL)26 relocation failed"
+ tcc_error("R_AARCH64_(JUMP|CALL)26 relocation failed"
" (val=%lx, addr=%lx)", (long)val, (long)addr);
write32le(ptr, (0x14000000 |
(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
return;
case R_AARCH64_ADR_GOT_PAGE: {
uint64_t off =
- (((S->got->sh_addr +
- get_sym_attr(S, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
+ (((s1->got->sh_addr +
+ get_sym_attr(s1, sym_index, 0)->got_offset) >> 12) - (addr >> 12));
if ((off + ((uint64_t)1 << 20)) >> 21)
- tcc_error(S, "R_AARCH64_ADR_GOT_PAGE relocation failed");
+ tcc_error("R_AARCH64_ADR_GOT_PAGE relocation failed");
write32le(ptr, ((read32le(ptr) & 0x9f00001f) |
(off & 0x1ffffc) << 3 | (off & 3) << 29));
return;
@@ -287,8 +287,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
case R_AARCH64_LD64_GOT_LO12_NC:
write32le(ptr,
((read32le(ptr) & 0xfff803ff) |
- ((S->got->sh_addr +
- get_sym_attr(S, sym_index, 0)->got_offset) & 0xff8) << 7));
+ ((s1->got->sh_addr +
+ get_sym_attr(s1, sym_index, 0)->got_offset) & 0xff8) << 7));
return;
case R_AARCH64_COPY:
return;
@@ -304,7 +304,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
return;
case R_AARCH64_RELATIVE:
#ifdef TCC_TARGET_PE
- add32le(ptr, val - S->pe_imagebase);
+ add32le(ptr, val - s1->pe_imagebase);
#endif
/* do nothing */
return;
diff --git a/c67-gen.c b/c67-gen.c
index d80f58f..9490a27 100644
--- a/c67-gen.c
+++ b/c67-gen.c
@@ -172,7 +172,7 @@ int TotalBytesPushedOnStack;
#define ALWAYS_ASSERT(x) \
do {\
if (!(x))\
- tcc_error(S, "internal compiler error file at %s:%d", __FILE__, __LINE__);\
+ tcc_error("internal compiler error file at %s:%d", __FILE__, __LINE__);\
} while (0)
/******************************************************/
@@ -186,27 +186,27 @@ static int C67_compare_reg;
FILE *f = NULL;
#endif
-void C67_g(TCCState* S, int c)
+void C67_g(int c)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
#ifdef ASSEMBLY_LISTING_C67
fprintf(f, " %08X", c);
#endif
- ind1 = S->tccgen_ind + 4;
+ ind1 = ind + 4;
if (ind1 > (int) cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind] = c & 0xff;
- cur_text_section->data[S->tccgen_ind + 1] = (c >> 8) & 0xff;
- cur_text_section->data[S->tccgen_ind + 2] = (c >> 16) & 0xff;
- cur_text_section->data[S->tccgen_ind + 3] = (c >> 24) & 0xff;
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind] = c & 0xff;
+ cur_text_section->data[ind + 1] = (c >> 8) & 0xff;
+ cur_text_section->data[ind + 2] = (c >> 16) & 0xff;
+ cur_text_section->data[ind + 3] = (c >> 24) & 0xff;
+ ind = ind1;
}
/* output a symbol and patch all calls to it */
-void gsym_addr(TCCState* S, int t, int a)
+void gsym_addr(int t, int a)
{
int n, *ptr;
while (t) {
@@ -220,9 +220,9 @@ void gsym_addr(TCCState* S, int t, int a)
// define a label that will be relocated
- sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, a, 0);
- greloc(S, cur_text_section, sym, t, R_C60LO16);
- greloc(S, cur_text_section, sym, t + 4, R_C60HI16);
+ sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
+ greloc(cur_text_section, sym, t, R_C60LO16);
+ greloc(cur_text_section, sym, t + 4, R_C60HI16);
// clear out where the pointer was
@@ -255,7 +255,7 @@ int ConvertRegToRegClass(int r)
// map TCC reg to C67 reg number
-int C67_map_regn(TCCState* S, int r)
+int C67_map_regn(int r)
{
if (r == 0) // normal tcc regs
return 0x2; // A2
@@ -296,7 +296,7 @@ int C67_map_regn(TCCState* S, int r)
// tcc reg 1 -> A3 -> X
// tcc reg B2 -> 3
-int C67_map_regc(TCCState* S, int r)
+int C67_map_regc(int r)
{
if (r == 0) // normal tcc regs
return 0x5;
@@ -317,7 +317,7 @@ int C67_map_regc(TCCState* S, int r)
// map TCC reg to C67 reg side A or B
-int C67_map_regs(TCCState* S, int r)
+int C67_map_regs(int r)
{
if (r == 0) // normal tcc regs
return 0x0;
@@ -345,7 +345,7 @@ int C67_map_regs(TCCState* S, int r)
return 0;
}
-int C67_map_S12(TCCState* S, char *s)
+int C67_map_S12(char *s)
{
if (strstr(s, ".S1") != NULL)
return 0;
@@ -357,7 +357,7 @@ int C67_map_S12(TCCState* S, char *s)
return 0;
}
-int C67_map_D12(TCCState* S, char *s)
+int C67_map_D12(char *s)
{
if (strstr(s, ".D1") != NULL)
return 0;
@@ -371,7 +371,7 @@ int C67_map_D12(TCCState* S, char *s)
-void C67_asm(TCCState* S, const char *s, int a, int b, int c)
+void C67_asm(const char *s, int a, int b, int c)
{
BOOL xpath;
@@ -383,14 +383,14 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c)
#endif
if (strstr(s, "MVKL") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) |
- ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(S, b) << 1));
+ C67_g((C67_map_regn(b) << 23) |
+ ((a & 0xffff) << 7) | (0x0a << 2) | (C67_map_regs(b) << 1));
} else if (strstr(s, "MVKH") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) |
+ C67_g((C67_map_regn(b) << 23) |
(((a >> 16) & 0xffff) << 7) |
- (0x1a << 2) | (C67_map_regs(S, b) << 1));
+ (0x1a << 2) | (C67_map_regs(b) << 1));
} else if (strstr(s, "STW.D SP POST DEC") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //SP B15
(2 << 13) | //ucst5 (must keep 8 byte boundary !!)
(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 << 7) | //y D1/D2 use B side
(7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STB.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STH.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STB.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STH.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STW.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
+ C67_g((C67_map_regn(a) << 23) | //src
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STW.D *") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
- (C67_map_regn(S, b) << 18) | //base reg A0
+ C67_g((C67_map_regn(a) << 23) | //src
+ (C67_map_regn(b) << 18) | //base reg A0
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
(7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STH.D *") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
- (C67_map_regn(S, b) << 18) | //base reg A0
+ C67_g((C67_map_regn(a) << 23) | //src
+ (C67_map_regn(b) << 18) | //base reg A0
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
(5 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STB.D *") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
- (C67_map_regn(S, b) << 18) | //base reg A0
+ C67_g((C67_map_regn(a) << 23) | //src
+ (C67_map_regn(b) << 18) | //base reg A0
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
(3 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "STW.D +*") == s) {
ALWAYS_ASSERT(c < 32);
- C67_g(S, (C67_map_regn(S, a) << 23) | //src
- (C67_map_regn(S, b) << 18) | //base reg A0
+ C67_g((C67_map_regn(a) << 23) | //src
+ (C67_map_regn(b) << 18) | //base reg A0
(c << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, b) << 7) | //y D1/D2 base reg side
+ (C67_map_regs(b) << 7) | //y D1/D2 base reg side
(7 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of src
+ (C67_map_regs(a) << 1) | //side of src
(0 << 0)); //parallel
} else if (strstr(s, "LDW.D SP PRE INC") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg B15
(2 << 13) | //ucst5 (must keep 8 byte boundary)
(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 << 7) | //y D1/D2 B side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDDW.D SP PRE INC") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg B15
(1 << 13) | //ucst5 (must keep 8 byte boundary)
(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 << 7) | //y D1/D2 B side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDW.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDDW.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDH.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDB.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDHU.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDBU.D *+SP[A0]") == s) {
- C67_g(S, (C67_map_regn(S, a) << 23) | //dst
+ C67_g((C67_map_regn(a) << 23) | //dst
(15 << 18) | //base reg A15
(0 << 13) | //offset reg A0
(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)
(0 << 7) | //y D1/D2 A side
(1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, a) << 1) | //side of dst
+ (C67_map_regs(a) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDW.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDDW.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(1 << 8) | //r (LDDW bit 1)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDH.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(4 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDB.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(2 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDHU.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(0 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDBU.D *") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(0 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(1 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "LDW.D +*") == s) {
- C67_g(S, (C67_map_regn(S, b) << 23) | //dst
- (C67_map_regn(S, a) << 18) | //base reg A15
+ C67_g((C67_map_regn(b) << 23) | //dst
+ (C67_map_regn(a) << 18) | //base reg A15
(1 << 13) | //cst5
(1 << 9) | //mode 1 = pos cst offset
(0 << 8) | //r (LDDW bit 0)
- (C67_map_regs(S, a) << 7) | //y D1/D2 src side
+ (C67_map_regs(a) << 7) | //y D1/D2 src side
(6 << 4) | //ldst 3=STB, 5=STH 5, 7=STW, 6=LDW 4=LDH 2=LDB 0=LDHU 1=LDBU
(1 << 2) | //opcode
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "CMPLTSP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x3a << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPGTSP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x39 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPEQSP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x38 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
}
else if (strstr(s, "CMPLTDP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x2a << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPGTDP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x29 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPEQDP") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x28 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPLT") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x57 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPGT") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x47 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPEQ") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x53 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPLTU") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x5f << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "CMPGTU") == s) {
- xpath = C67_map_regs(S, a) ^ C67_map_regs(S, b);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ xpath = C67_map_regs(a) ^ C67_map_regs(b);
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ C67_g((C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x use cross path for src2
(0x4f << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side for reg c
+ (C67_map_regs(c) << 1) | //side for reg c
(0 << 0)); //parallel
} else if (strstr(s, "B DISP") == s) {
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //z
(a << 7) | //cnst
(0x4 << 2) | //opcode fixed
(0 << 1) | //S0/S1
(0 << 0)); //parallel
} else if (strstr(s, "B.") == s) {
- xpath = C67_map_regs(S, c) ^ 1;
+ xpath = C67_map_regs(c) ^ 1;
- C67_g(S, (C67_map_regc(S, b) << 29) | //creg
+ C67_g((C67_map_regc(b) << 29) | //creg
(a << 28) | //inv
(0 << 23) | //dst
- (C67_map_regn(S, c) << 18) | //src2
+ (C67_map_regn(c) << 18) | //src2
(0 << 13) | //
(xpath << 12) | //x cross path if !B side
(0xd << 6) | //opcode
@@ -820,369 +820,369 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c)
(1 << 1) | //must be S2
(0 << 0)); //parallel
} else if (strstr(s, "MV.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 (cst5)
(xpath << 12) | //x cross path if opposite sides
(0x2 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SPTRUNC.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0xb << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "DPTRUNC.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
+ (C67_map_regn(c) << 23) | //dst
+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x1 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "INTSP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x4a << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "INTSPU.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x49 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "INTDP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x39 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "INTDPU.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
+ (C67_map_regn(c) << 23) | //dst
+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x3b << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SPDP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
(0 << 13) | //src1 NA
(xpath << 12) | //x cross path if opposite sides
(0x2 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "DPSP.L") == s) {
- ALWAYS_ASSERT(C67_map_regs(S, b) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(b) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- ((C67_map_regn(S, b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
+ (C67_map_regn(c) << 23) | //dst
+ ((C67_map_regn(b) + 1) << 18) | //src2 WEIRD CPU must specify odd reg for some reason
(0 << 13) | //src1 NA
(0 << 12) | //x cross path if opposite sides
(0x9 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "ADD.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x3 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SUB.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x7 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "OR.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x7f << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "AND.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x7b << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "XOR.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x6f << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "ADDSP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x10 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "ADDDP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x18 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SUBSP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x11 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SUBDP.L") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x19 << 5) | //opcode
(0x6 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "MPYSP.M") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x1c << 7) | //opcode
(0x0 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "MPYDP.M") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2 (possible x path)
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2 (possible x path)
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x0e << 7) | //opcode
(0x0 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "MPYI.M") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, a) == C67_map_regs(S, c));
+ ALWAYS_ASSERT(C67_map_regs(a) == C67_map_regs(c));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1 (cst5)
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1 (cst5)
(xpath << 12) | //x cross path if opposite sides
(0x4 << 7) | //opcode
(0x0 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SHR.S") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x37 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SHRU.S") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x27 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "SHL.S") == s) {
- xpath = C67_map_regs(S, b) ^ C67_map_regs(S, c);
+ xpath = C67_map_regs(b) ^ C67_map_regs(c);
- ALWAYS_ASSERT(C67_map_regs(S, c) == C67_map_regs(S, a));
+ ALWAYS_ASSERT(C67_map_regs(c) == C67_map_regs(a));
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, c) << 23) | //dst
- (C67_map_regn(S, b) << 18) | //src2
- (C67_map_regn(S, a) << 13) | //src1
+ (C67_map_regn(c) << 23) | //dst
+ (C67_map_regn(b) << 18) | //src2
+ (C67_map_regn(a) << 13) | //src1
(xpath << 12) | //x cross path if opposite sides
(0x33 << 6) | //opcode
(0x8 << 2) | //opcode fixed
- (C67_map_regs(S, c) << 1) | //side of dest
+ (C67_map_regs(c) << 1) | //side of dest
(0 << 0)); //parallel
} else if (strstr(s, "||ADDK") == s) {
xpath = 0; // no xpath required just use the side of the src/dst
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, b) << 23) | //dst
+ (C67_map_regn(b) << 23) | //dst
(a << 07) | //scst16
(0x14 << 2) | //opcode fixed
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(1 << 0)); //parallel
} else if (strstr(s, "ADDK") == s) {
xpath = 0; // no xpath required just use the side of the src/dst
- C67_g(S, (0 << 29) | //creg
+ C67_g((0 << 29) | //creg
(0 << 28) | //inv
- (C67_map_regn(S, b) << 23) | //dst
+ (C67_map_regn(b) << 23) | //dst
(a << 07) | //scst16
(0x14 << 2) | //opcode fixed
- (C67_map_regs(S, b) << 1) | //side of dst
+ (C67_map_regs(b) << 1) | //side of dst
(0 << 0)); //parallel
} else if (strstr(s, "NOP") == s) {
- C67_g(S, ((a - 1) << 13) | //no of cycles
+ C67_g(((a - 1) << 13) | //no of cycles
(0 << 0)); //parallel
} else
ALWAYS_ASSERT(FALSE);
@@ -1195,198 +1195,198 @@ void C67_asm(TCCState* S, const char *s, int a, int b, int c)
//r=reg to load, fr=from reg, symbol for relocation, constant
-void C67_MVKL(TCCState* S, int r, int fc)
+void C67_MVKL(int r, int fc)
{
- C67_asm(S, "MVKL.", fc, r, 0);
+ C67_asm("MVKL.", fc, r, 0);
}
-void C67_MVKH(TCCState* S, int r, int fc)
+void C67_MVKH(int r, int fc)
{
- C67_asm(S, "MVKH.", fc, r, 0);
+ C67_asm("MVKH.", fc, r, 0);
}
-void C67_STB_SP_A0(TCCState* S, int r)
+void C67_STB_SP_A0(int r)
{
- C67_asm(S, "STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0]
+ C67_asm("STB.D *+SP[A0]", r, 0, 0); // STB r,*+SP[A0]
}
-void C67_STH_SP_A0(TCCState* S, int r)
+void C67_STH_SP_A0(int r)
{
- C67_asm(S, "STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0]
+ C67_asm("STH.D *+SP[A0]", r, 0, 0); // STH r,*+SP[A0]
}
-void C67_STW_SP_A0(TCCState* S, int r)
+void C67_STW_SP_A0(int r)
{
- C67_asm(S, "STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0]
+ C67_asm("STW.D *+SP[A0]", r, 0, 0); // STW r,*+SP[A0]
}
-void C67_STB_PTR(TCCState* S, int r, int r2)
+void C67_STB_PTR(int r, int r2)
{
- C67_asm(S, "STB.D *", r, r2, 0); // STB r, *r2
+ C67_asm("STB.D *", r, r2, 0); // STB r, *r2
}
-void C67_STH_PTR(TCCState* S, int r, int r2)
+void C67_STH_PTR(int r, int r2)
{
- C67_asm(S, "STH.D *", r, r2, 0); // STH r, *r2
+ C67_asm("STH.D *", r, r2, 0); // STH r, *r2
}
-void C67_STW_PTR(TCCState* S, int r, int r2)
+void C67_STW_PTR(int r, int r2)
{
- C67_asm(S, "STW.D *", r, r2, 0); // STW r, *r2
+ C67_asm("STW.D *", r, r2, 0); // STW r, *r2
}
-void C67_STW_PTR_PRE_INC(TCCState* S, int r, int r2, int n)
+void C67_STW_PTR_PRE_INC(int r, int r2, int n)
{
- C67_asm(S, "STW.D +*", r, r2, n); // STW r, *+r2
+ C67_asm("STW.D +*", r, r2, n); // STW r, *+r2
}
-void C67_PUSH(TCCState* S, int r)
+void C67_PUSH(int r)
{
- C67_asm(S, "STW.D SP POST DEC", r, 0, 0); // STW r,*SP--
+ C67_asm("STW.D SP POST DEC", r, 0, 0); // STW r,*SP--
}
-void C67_LDW_SP_A0(TCCState* S, int r)
+void C67_LDW_SP_A0(int r)
{
- C67_asm(S, "LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r
+ C67_asm("LDW.D *+SP[A0]", r, 0, 0); // LDW *+SP[A0],r
}
-void C67_LDDW_SP_A0(TCCState* S, int r)
+void C67_LDDW_SP_A0(int r)
{
- C67_asm(S, "LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r
+ C67_asm("LDDW.D *+SP[A0]", r, 0, 0); // LDDW *+SP[A0],r
}
-void C67_LDH_SP_A0(TCCState* S, int r)
+void C67_LDH_SP_A0(int r)
{
- C67_asm(S, "LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r
+ C67_asm("LDH.D *+SP[A0]", r, 0, 0); // LDH *+SP[A0],r
}
-void C67_LDB_SP_A0(TCCState* S, int r)
+void C67_LDB_SP_A0(int r)
{
- C67_asm(S, "LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r
+ C67_asm("LDB.D *+SP[A0]", r, 0, 0); // LDB *+SP[A0],r
}
-void C67_LDHU_SP_A0(TCCState* S, int r)
+void C67_LDHU_SP_A0(int r)
{
- C67_asm(S, "LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r
+ C67_asm("LDHU.D *+SP[A0]", r, 0, 0); // LDHU *+SP[A0],r
}
-void C67_LDBU_SP_A0(TCCState* S, int r)
+void C67_LDBU_SP_A0(int r)
{
- C67_asm(S, "LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r
+ C67_asm("LDBU.D *+SP[A0]", r, 0, 0); // LDBU *+SP[A0],r
}
-void C67_LDW_PTR(TCCState* S, int r, int r2)
+void C67_LDW_PTR(int r, int r2)
{
- C67_asm(S, "LDW.D *", r, r2, 0); // LDW *r,r2
+ C67_asm("LDW.D *", r, r2, 0); // LDW *r,r2
}
-void C67_LDDW_PTR(TCCState* S, int r, int r2)
+void C67_LDDW_PTR(int r, int r2)
{
- C67_asm(S, "LDDW.D *", r, r2, 0); // LDDW *r,r2
+ C67_asm("LDDW.D *", r, r2, 0); // LDDW *r,r2
}
-void C67_LDH_PTR(TCCState* S, int r, int r2)
+void C67_LDH_PTR(int r, int r2)
{
- C67_asm(S, "LDH.D *", r, r2, 0); // LDH *r,r2
+ C67_asm("LDH.D *", r, r2, 0); // LDH *r,r2
}
-void C67_LDB_PTR(TCCState* S, int r, int r2)
+void C67_LDB_PTR(int r, int r2)
{
- C67_asm(S, "LDB.D *", r, r2, 0); // LDB *r,r2
+ C67_asm("LDB.D *", r, r2, 0); // LDB *r,r2
}
-void C67_LDHU_PTR(TCCState* S, int r, int r2)
+void C67_LDHU_PTR(int r, int r2)
{
- C67_asm(S, "LDHU.D *", r, r2, 0); // LDHU *r,r2
+ C67_asm("LDHU.D *", r, r2, 0); // LDHU *r,r2
}
-void C67_LDBU_PTR(TCCState* S, int r, int r2)
+void C67_LDBU_PTR(int r, int r2)
{
- C67_asm(S, "LDBU.D *", r, r2, 0); // LDBU *r,r2
+ C67_asm("LDBU.D *", r, r2, 0); // LDBU *r,r2
}
-void C67_LDW_PTR_PRE_INC(TCCState* S, int r, int r2)
+void C67_LDW_PTR_PRE_INC(int r, int r2)
{
- C67_asm(S, "LDW.D +*", r, r2, 0); // LDW *+r,r2
+ C67_asm("LDW.D +*", r, r2, 0); // LDW *+r,r2
}
-void C67_POP(TCCState* S, int r)
+void C67_POP(int r)
{
- C67_asm(S, "LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r
+ C67_asm("LDW.D SP PRE INC", r, 0, 0); // LDW *++SP,r
}
-void C67_POP_DW(TCCState* S, int r)
+void C67_POP_DW(int r)
{
- C67_asm(S, "LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r
+ C67_asm("LDDW.D SP PRE INC", r, 0, 0); // LDDW *++SP,r
}
-void C67_CMPLT(TCCState* S, int s1, int s2, int dst)
+void C67_CMPLT(int s1, int s2, int dst)
{
- C67_asm(S, "CMPLT.L1", s1, s2, dst);
+ C67_asm("CMPLT.L1", s1, s2, dst);
}
-void C67_CMPGT(TCCState* S, int s1, int s2, int dst)
+void C67_CMPGT(int s1, int s2, int dst)
{
- C67_asm(S, "CMPGT.L1", s1, s2, dst);
+ C67_asm("CMPGT.L1", s1, s2, dst);
}
-void C67_CMPEQ(TCCState* S, int s1, int s2, int dst)
+void C67_CMPEQ(int s1, int s2, int dst)
{
- C67_asm(S, "CMPEQ.L1", s1, s2, dst);
+ C67_asm("CMPEQ.L1", s1, s2, dst);
}
-void C67_CMPLTU(TCCState* S, int s1, int s2, int dst)
+void C67_CMPLTU(int s1, int s2, int dst)
{
- C67_asm(S, "CMPLTU.L1", s1, s2, dst);
+ C67_asm("CMPLTU.L1", s1, s2, dst);
}
-void C67_CMPGTU(TCCState* S, int s1, int s2, int dst)
+void C67_CMPGTU(int s1, int s2, int dst)
{
- C67_asm(S, "CMPGTU.L1", s1, s2, dst);
+ C67_asm("CMPGTU.L1", s1, s2, dst);
}
-void C67_CMPLTSP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPLTSP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPLTSP.S1", s1, s2, dst);
+ C67_asm("CMPLTSP.S1", s1, s2, dst);
}
-void C67_CMPGTSP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPGTSP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPGTSP.S1", s1, s2, dst);
+ C67_asm("CMPGTSP.S1", s1, s2, dst);
}
-void C67_CMPEQSP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPEQSP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPEQSP.S1", s1, s2, dst);
+ C67_asm("CMPEQSP.S1", s1, s2, dst);
}
-void C67_CMPLTDP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPLTDP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPLTDP.S1", s1, s2, dst);
+ C67_asm("CMPLTDP.S1", s1, s2, dst);
}
-void C67_CMPGTDP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPGTDP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPGTDP.S1", s1, s2, dst);
+ C67_asm("CMPGTDP.S1", s1, s2, dst);
}
-void C67_CMPEQDP(TCCState* S, int s1, int s2, int dst)
+void C67_CMPEQDP(int s1, int s2, int dst)
{
- C67_asm(S, "CMPEQDP.S1", s1, s2, dst);
+ C67_asm("CMPEQDP.S1", s1, s2, dst);
}
-void C67_IREG_B_REG(TCCState* S, int inv, int r1, int r2) // [!R] B r2
+void C67_IREG_B_REG(int inv, int r1, int r2) // [!R] B r2
{
- C67_asm(S, "B.S2", inv, r1, r2);
+ C67_asm("B.S2", inv, r1, r2);
}
// call with how many 32 bit words to skip
// (0 would branch to the branch instruction)
-void C67_B_DISP(TCCState* S, int disp) // B +2 Branch with constant displacement
+void C67_B_DISP(int disp) // B +2 Branch with constant displacement
{
// Branch point is relative to the 8 word fetch packet
//
@@ -1395,160 +1395,160 @@ void C67_B_DISP(TCCState* S, int disp) // B +2 Branch with constant displacem
// so add in how many words into the fetch packet the branch is
- C67_asm(S, "B DISP", disp + ((S->tccgen_ind & 31) >> 2), 0, 0);
+ C67_asm("B DISP", disp + ((ind & 31) >> 2), 0, 0);
}
-void C67_NOP(TCCState* S, int n)
+void C67_NOP(int n)
{
- C67_asm(S, "NOP", n, 0, 0);
+ C67_asm("NOP", n, 0, 0);
}
-void C67_ADDK(TCCState* S, int n, int r)
+void C67_ADDK(int n, int r)
{
ALWAYS_ASSERT(abs(n) < 32767);
- C67_asm(S, "ADDK", n, r, 0);
+ C67_asm("ADDK", n, r, 0);
}
-void C67_ADDK_PARALLEL(TCCState* S, int n, int r)
+void C67_ADDK_PARALLEL(int n, int r)
{
ALWAYS_ASSERT(abs(n) < 32767);
- C67_asm(S, "||ADDK", n, r, 0);
+ C67_asm("||ADDK", n, r, 0);
}
-void C67_Adjust_ADDK(TCCState* S, int *inst, int n)
+void C67_Adjust_ADDK(int *inst, int n)
{
ALWAYS_ASSERT(abs(n) < 32767);
*inst = (*inst & (~(0xffff << 7))) | ((n & 0xffff) << 7);
}
-void C67_MV(TCCState* S, int r, int v)
+void C67_MV(int r, int v)
{
- C67_asm(S, "MV.L", 0, r, v);
+ C67_asm("MV.L", 0, r, v);
}
-void C67_DPTRUNC(TCCState* S, int r, int v)
+void C67_DPTRUNC(int r, int v)
{
- C67_asm(S, "DPTRUNC.L", 0, r, v);
+ C67_asm("DPTRUNC.L", 0, r, v);
}
-void C67_SPTRUNC(TCCState* S, int r, int v)
+void C67_SPTRUNC(int r, int v)
{
- C67_asm(S, "SPTRUNC.L", 0, r, v);
+ C67_asm("SPTRUNC.L", 0, r, v);
}
-void C67_INTSP(TCCState* S, int r, int v)
+void C67_INTSP(int r, int v)
{
- C67_asm(S, "INTSP.L", 0, r, v);
+ C67_asm("INTSP.L", 0, r, v);
}
-void C67_INTDP(TCCState* S, int r, int v)
+void C67_INTDP(int r, int v)
{
- C67_asm(S, "INTDP.L", 0, r, v);
+ C67_asm("INTDP.L", 0, r, v);
}
-void C67_INTSPU(TCCState* S, int r, int v)
+void C67_INTSPU(int r, int v)
{
- C67_asm(S, "INTSPU.L", 0, r, v);
+ C67_asm("INTSPU.L", 0, r, v);
}
-void C67_INTDPU(TCCState* S, int r, int v)
+void C67_INTDPU(int r, int v)
{
- C67_asm(S, "INTDPU.L", 0, r, v);
+ C67_asm("INTDPU.L", 0, r, v);
}
-void C67_SPDP(TCCState* S, int r, int v)
+void C67_SPDP(int r, int v)
{
- C67_asm(S, "SPDP.L", 0, r, v);
+ C67_asm("SPDP.L", 0, r, v);
}
-void C67_DPSP(TCCState* S, int r, int v) // note regs must be on the same side
+void C67_DPSP(int r, int v) // note regs must be on the same side
{
- C67_asm(S, "DPSP.L", 0, r, v);
+ C67_asm("DPSP.L", 0, r, v);
}
-void C67_ADD(TCCState* S, int r, int v)
+void C67_ADD(int r, int v)
{
- C67_asm(S, "ADD.L", v, r, v);
+ C67_asm("ADD.L", v, r, v);
}
-void C67_SUB(TCCState* S, int r, int v)
+void C67_SUB(int r, int v)
{
- C67_asm(S, "SUB.L", v, r, v);
+ C67_asm("SUB.L", v, r, v);
}
-void C67_AND(TCCState* S, int r, int v)
+void C67_AND(int r, int v)
{
- C67_asm(S, "AND.L", v, r, v);
+ C67_asm("AND.L", v, r, v);
}
-void C67_OR(TCCState* S, int r, int v)
+void C67_OR(int r, int v)
{
- C67_asm(S, "OR.L", v, r, v);
+ C67_asm("OR.L", v, r, v);
}
-void C67_XOR(TCCState* S, int r, int v)
+void C67_XOR(int r, int v)
{
- C67_asm(S, "XOR.L", v, r, v);
+ C67_asm("XOR.L", v, r, v);
}
-void C67_ADDSP(TCCState* S, int r, int v)
+void C67_ADDSP(int r, int v)
{
- C67_asm(S, "ADDSP.L", v, r, v);
+ C67_asm("ADDSP.L", v, r, v);
}
-void C67_SUBSP(TCCState* S, int r, int v)
+void C67_SUBSP(int r, int v)
{
- C67_asm(S, "SUBSP.L", v, r, v);
+ C67_asm("SUBSP.L", v, r, v);
}
-void C67_MPYSP(TCCState* S, int r, int v)
+void C67_MPYSP(int r, int v)
{
- C67_asm(S, "MPYSP.M", v, r, v);
+ C67_asm("MPYSP.M", v, r, v);
}
-void C67_ADDDP(TCCState* S, int r, int v)
+void C67_ADDDP(int r, int v)
{
- C67_asm(S, "ADDDP.L", v, r, v);
+ C67_asm("ADDDP.L", v, r, v);
}
-void C67_SUBDP(TCCState* S, int r, int v)
+void C67_SUBDP(int r, int v)
{
- C67_asm(S, "SUBDP.L", v, r, v);
+ C67_asm("SUBDP.L", v, r, v);
}
-void C67_MPYDP(TCCState* S, int r, int v)
+void C67_MPYDP(int r, int v)
{
- C67_asm(S, "MPYDP.M", v, r, v);
+ C67_asm("MPYDP.M", v, r, v);
}
-void C67_MPYI(TCCState* S, int r, int v)
+void C67_MPYI(int r, int v)
{
- C67_asm(S, "MPYI.M", v, r, v);
+ C67_asm("MPYI.M", v, r, v);
}
-void C67_SHL(TCCState* S, int r, int v)
+void C67_SHL(int r, int v)
{
- C67_asm(S, "SHL.S", r, v, v);
+ C67_asm("SHL.S", r, v, v);
}
-void C67_SHRU(TCCState* S, int r, int v)
+void C67_SHRU(int r, int v)
{
- C67_asm(S, "SHRU.S", r, v, v);
+ C67_asm("SHRU.S", r, v, v);
}
-void C67_SHR(TCCState* S, int r, int v)
+void C67_SHR(int r, int v)
{
- C67_asm(S, "SHR.S", r, v, v);
+ C67_asm("SHR.S", r, v, v);
}
/* load 'r' from value 'sv' */
-void load(TCCState* S, int r, SValue * sv)
+void load(int r, SValue * sv)
{
int v, t, ft, fc, fr, size = 0, element;
BOOL Unsigned = FALSE;
@@ -1564,10 +1564,10 @@ void load(TCCState* S, int r, SValue * sv)
v1.type.t = VT_INT;
v1.r = VT_LOCAL | VT_LVAL;
v1.c.i = fc;
- load(S, r, &v1);
+ load(r, &v1);
fr = r;
} else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
- tcc_error(S, "long double not supported");
+ tcc_error("long double not supported");
} else if ((ft & VT_TYPE) == VT_BYTE) {
size = 1;
} else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
@@ -1608,109 +1608,109 @@ void load(TCCState* S, int r, SValue * sv)
{
if (size == 1) {
if (Unsigned)
- C67_LDBU_PTR(S, v, r); // LDBU *v,r
+ C67_LDBU_PTR(v, r); // LDBU *v,r
else
- C67_LDB_PTR(S, v, r); // LDB *v,r
+ C67_LDB_PTR(v, r); // LDB *v,r
} else if (size == 2) {
if (Unsigned)
- C67_LDHU_PTR(S, v, r); // LDHU *v,r
+ C67_LDHU_PTR(v, r); // LDHU *v,r
else
- C67_LDH_PTR(S, v, r); // LDH *v,r
+ C67_LDH_PTR(v, r); // LDH *v,r
} else if (size == 4) {
- C67_LDW_PTR(S, v, r); // LDW *v,r
+ C67_LDW_PTR(v, r); // LDW *v,r
} else if (size == 8) {
- C67_LDDW_PTR(S, v, r); // LDDW *v,r
+ C67_LDDW_PTR(v, r); // LDDW *v,r
}
- C67_NOP(S, 4); // NOP 4
+ C67_NOP(4); // NOP 4
return;
} else if (fr & VT_SYM) {
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind + 4, R_C60HI16);
+ greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16);
- C67_MVKL(S, C67_A0, fc); //r=reg to load, constant
- C67_MVKH(S, C67_A0, fc); //r=reg to load, constant
+ C67_MVKL(C67_A0, fc); //r=reg to load, constant
+ C67_MVKH(C67_A0, fc); //r=reg to load, constant
if (size == 1) {
if (Unsigned)
- C67_LDBU_PTR(S, C67_A0, r); // LDBU *A0,r
+ C67_LDBU_PTR(C67_A0, r); // LDBU *A0,r
else
- C67_LDB_PTR(S, C67_A0, r); // LDB *A0,r
+ C67_LDB_PTR(C67_A0, r); // LDB *A0,r
} else if (size == 2) {
if (Unsigned)
- C67_LDHU_PTR(S, C67_A0, r); // LDHU *A0,r
+ C67_LDHU_PTR(C67_A0, r); // LDHU *A0,r
else
- C67_LDH_PTR(S, C67_A0, r); // LDH *A0,r
+ C67_LDH_PTR(C67_A0, r); // LDH *A0,r
} else if (size == 4) {
- C67_LDW_PTR(S, C67_A0, r); // LDW *A0,r
+ C67_LDW_PTR(C67_A0, r); // LDW *A0,r
} else if (size == 8) {
- C67_LDDW_PTR(S, C67_A0, r); // LDDW *A0,r
+ C67_LDDW_PTR(C67_A0, r); // LDDW *A0,r
}
- C67_NOP(S, 4); // NOP 4
+ C67_NOP(4); // NOP 4
return;
} else {
element = size;
// divide offset in bytes to create element index
- C67_MVKL(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
- C67_MVKH(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
+ C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
+ C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
if (size == 1) {
if (Unsigned)
- C67_LDBU_SP_A0(S, r); // LDBU r, SP[A0]
+ C67_LDBU_SP_A0(r); // LDBU r, SP[A0]
else
- C67_LDB_SP_A0(S, r); // LDB r, SP[A0]
+ C67_LDB_SP_A0(r); // LDB r, SP[A0]
} else if (size == 2) {
if (Unsigned)
- C67_LDHU_SP_A0(S, r); // LDHU r, SP[A0]
+ C67_LDHU_SP_A0(r); // LDHU r, SP[A0]
else
- C67_LDH_SP_A0(S, r); // LDH r, SP[A0]
+ C67_LDH_SP_A0(r); // LDH r, SP[A0]
} else if (size == 4) {
- C67_LDW_SP_A0(S, r); // LDW r, SP[A0]
+ C67_LDW_SP_A0(r); // LDW r, SP[A0]
} else if (size == 8) {
- C67_LDDW_SP_A0(S, r); // LDDW r, SP[A0]
+ C67_LDDW_SP_A0(r); // LDDW r, SP[A0]
}
- C67_NOP(S, 4); // NOP 4
+ C67_NOP(4); // NOP 4
return;
}
} else {
if (v == VT_CONST) {
if (fr & VT_SYM) {
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind + 4, R_C60HI16);
+ greloc(cur_text_section, sv->sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, sv->sym, ind + 4, R_C60HI16);
}
- C67_MVKL(S, r, fc); //r=reg to load, constant
- C67_MVKH(S, r, fc); //r=reg to load, constant
+ C67_MVKL(r, fc); //r=reg to load, constant
+ C67_MVKH(r, fc); //r=reg to load, constant
} else if (v == VT_LOCAL) {
- C67_MVKL(S, r, fc + 8); //r=reg to load, constant C67 stack points to next free
- C67_MVKH(S, r, fc + 8); //r=reg to load, constant
- C67_ADD(S, C67_FP, r); // MV v,r v -> r
+ C67_MVKL(r, fc + 8); //r=reg to load, constant C67 stack points to next free
+ C67_MVKH(r, fc + 8); //r=reg to load, constant
+ C67_ADD(C67_FP, r); // MV v,r v -> r
} else if (v == VT_CMP) {
- C67_MV(S, C67_compare_reg, r); // MV v,r v -> r
+ C67_MV(C67_compare_reg, r); // MV v,r v -> r
} else if (v == VT_JMP || v == VT_JMPI) {
t = v & 1;
- C67_B_DISP(S, 4); // Branch with constant displacement, skip over this branch, load, nop, load
- C67_MVKL(S, r, t); // r=reg to load, 0 or 1 (do this while branching)
- C67_NOP(S, 4); // NOP 4
- gsym(S, fc); // modifies other branches to branch here
- C67_MVKL(S, r, t ^ 1); // r=reg to load, 0 or 1
+ C67_B_DISP(4); // Branch with constant displacement, skip over this branch, load, nop, load
+ C67_MVKL(r, t); // r=reg to load, 0 or 1 (do this while branching)
+ C67_NOP(4); // NOP 4
+ gsym(fc); // modifies other branches to branch here
+ C67_MVKL(r, t ^ 1); // r=reg to load, 0 or 1
} else if (v != r) {
- C67_MV(S, v, r); // MV v,r v -> r
+ C67_MV(v, r); // MV v,r v -> r
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_MV(S, v + 1, r + 1); // MV v,r v -> r
+ C67_MV(v + 1, r + 1); // MV v,r v -> r
}
}
}
/* store register 'r' in lvalue 'v' */
-void store(TCCState* S, int r, SValue * v)
+void store(int r, SValue * v)
{
int fr, bt, ft, fc, size, t, element;
@@ -1721,7 +1721,7 @@ void store(TCCState* S, int r, SValue * v)
/* XXX: incorrect if float reg to reg */
if (bt == VT_LDOUBLE) {
- tcc_error(S, "long double not supported");
+ tcc_error("long double not supported");
} else {
if (bt == VT_SHORT)
size = 2;
@@ -1736,21 +1736,21 @@ void store(TCCState* S, int r, SValue * v)
/* constant memory reference */
if (v->r & VT_SYM) {
- greloc(S, cur_text_section, v->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, v->sym, S->tccgen_ind + 4, R_C60HI16);
+ greloc(cur_text_section, v->sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, v->sym, ind + 4, R_C60HI16);
}
- C67_MVKL(S, C67_A0, fc); //r=reg to load, constant
- C67_MVKH(S, C67_A0, fc); //r=reg to load, constant
+ C67_MVKL(C67_A0, fc); //r=reg to load, constant
+ C67_MVKH(C67_A0, fc); //r=reg to load, constant
if (size == 1)
- C67_STB_PTR(S, r, C67_A0); // STB r, *A0
+ C67_STB_PTR(r, C67_A0); // STB r, *A0
else if (size == 2)
- C67_STH_PTR(S, r, C67_A0); // STH r, *A0
+ C67_STH_PTR(r, C67_A0); // STH r, *A0
else if (size == 4 || size == 8)
- C67_STW_PTR(S, r, C67_A0); // STW r, *A0
+ C67_STW_PTR(r, C67_A0); // STW r, *A0
if (size == 8)
- C67_STW_PTR_PRE_INC(S, r + 1, C67_A0, 1); // STW r, *+A0[1]
+ C67_STW_PTR_PRE_INC(r + 1, C67_A0, 1); // STW r, *+A0[1]
} else if ((v->r & VT_VALMASK) == VT_LOCAL) {
// check case of storing to passed argument that
// tcc thinks is on the stack but for C67 is
@@ -1781,68 +1781,68 @@ void store(TCCState* S, int r, SValue * v)
element = size;
// divide offset in bytes to create word index
- C67_MVKL(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
- C67_MVKH(S, C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
+ C67_MVKL(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
+ C67_MVKH(C67_A0, (fc / element) + 8 / element); //r=reg to load, constant
if (size == 1)
- C67_STB_SP_A0(S, r); // STB r, SP[A0]
+ C67_STB_SP_A0(r); // STB r, SP[A0]
else if (size == 2)
- C67_STH_SP_A0(S, r); // STH r, SP[A0]
+ C67_STH_SP_A0(r); // STH r, SP[A0]
else if (size == 4 || size == 8)
- C67_STW_SP_A0(S, r); // STW r, SP[A0]
+ C67_STW_SP_A0(r); // STW r, SP[A0]
if (size == 8) {
- C67_ADDK(S, 1, C67_A0); // ADDK 1,A0
- C67_STW_SP_A0(S, r + 1); // STW r, SP[A0]
+ C67_ADDK(1, C67_A0); // ADDK 1,A0
+ C67_STW_SP_A0(r + 1); // STW r, SP[A0]
}
} else {
if (size == 1)
- C67_STB_PTR(S, r, fr); // STB r, *fr
+ C67_STB_PTR(r, fr); // STB r, *fr
else if (size == 2)
- C67_STH_PTR(S, r, fr); // STH r, *fr
+ C67_STH_PTR(r, fr); // STH r, *fr
else if (size == 4 || size == 8)
- C67_STW_PTR(S, r, fr); // STW r, *fr
+ C67_STW_PTR(r, fr); // STW r, *fr
if (size == 8) {
- C67_STW_PTR_PRE_INC(S, r + 1, fr, 1); // STW r, *+fr[1]
+ C67_STW_PTR_PRE_INC(r + 1, fr, 1); // STW r, *+fr[1]
}
}
}
}
/* 'is_jmp' is '1' if it is a jump */
-static void gcall_or_jmp(TCCState* S, int is_jmp)
+static void gcall_or_jmp(int is_jmp)
{
int r;
Sym *sym;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* constant case */
- if (S->tccgen_vtop->r & VT_SYM) {
+ if (vtop->r & VT_SYM) {
/* relocation case */
// get add into A0, then start the jump B3
- greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 4, R_C60HI16);
+ greloc(cur_text_section, vtop->sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, vtop->sym, ind + 4, R_C60HI16);
- C67_MVKL(S, C67_A0, 0); //r=reg to load, constant
- C67_MVKH(S, C67_A0, 0); //r=reg to load, constant
- C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_A0); // B.S2x A0
+ C67_MVKL(C67_A0, 0); //r=reg to load, constant
+ C67_MVKH(C67_A0, 0); //r=reg to load, constant
+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // B.S2x A0
if (is_jmp) {
- C67_NOP(S, 5); // simple jump, just put NOP
+ C67_NOP(5); // simple jump, just put NOP
} else {
// Call, must load return address into B3 during delay slots
- sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, S->tccgen_ind + 12, 0); // symbol for return address
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
- C67_MVKL(S, C67_B3, 0); //r=reg to load, constant
- C67_MVKH(S, C67_B3, 0); //r=reg to load, constant
- C67_NOP(S, 3); // put remaining NOPs
+ sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address
+ greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
+ C67_MVKL(C67_B3, 0); //r=reg to load, constant
+ C67_MVKH(C67_B3, 0); //r=reg to load, constant
+ C67_NOP(3); // put remaining NOPs
}
} else {
/* put an empty PC32 relocation */
@@ -1850,20 +1850,20 @@ static void gcall_or_jmp(TCCState* S, int is_jmp)
}
} else {
/* otherwise, indirect call */
- r = gv(S, RC_INT);
- C67_IREG_B_REG(S, 0, C67_CREG_ZERO, r); // B.S2x r
+ r = gv(RC_INT);
+ C67_IREG_B_REG(0, C67_CREG_ZERO, r); // B.S2x r
if (is_jmp) {
- C67_NOP(S, 5); // simple jump, just put NOP
+ C67_NOP(5); // simple jump, just put NOP
} else {
// Call, must load return address into B3 during delay slots
- sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, S->tccgen_ind + 12, 0); // symbol for return address
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16); // rem the inst need to be patched
- greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
- C67_MVKL(S, C67_B3, 0); //r=reg to load, constant
- C67_MVKH(S, C67_B3, 0); //r=reg to load, constant
- C67_NOP(S, 3); // put remaining NOPs
+ sym = get_sym_ref(&char_pointer_type, cur_text_section, ind + 12, 0); // symbol for return address
+ greloc(cur_text_section, sym, ind, R_C60LO16); // rem the inst need to be patched
+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
+ C67_MVKL(C67_B3, 0); //r=reg to load, constant
+ C67_MVKH(C67_B3, 0); //r=reg to load, constant
+ C67_NOP(3); // put remaining NOPs
}
}
}
@@ -1877,29 +1877,29 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int
/* generate function call with address in (vtop->t, vtop->c) and free function
context. Stack entry is popped */
-void gfunc_call(TCCState* S, int nb_args)
+void gfunc_call(int nb_args)
{
int i, r, size = 0;
int args_sizes[NoCallArgsPassedOnStack];
if (nb_args > NoCallArgsPassedOnStack) {
- tcc_error(S, "more than 10 function params not currently supported");
+ tcc_error("more than 10 function params not currently supported");
// handle more than 10, put some on the stack
}
for (i = 0; i < nb_args; i++) {
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
ALWAYS_ASSERT(FALSE);
} else {
/* simple type (currently always same size) */
/* XXX: implicit cast ? */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
- tcc_error(S, "long long not supported");
- } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
- tcc_error(S, "long double not supported");
- } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
+ tcc_error("long long not supported");
+ } else if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
+ tcc_error("long double not supported");
+ } else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
size = 8;
} else {
size = 4;
@@ -1907,19 +1907,19 @@ void gfunc_call(TCCState* S, int nb_args)
// put the parameter into the corresponding reg (pair)
- r = gv(S, RC_C67_A4 << (2 * i));
+ r = gv(RC_C67_A4 << (2 * i));
// must put on stack because with 1 pass compiler , no way to tell
// if an up coming nested call might overwrite these regs
- C67_PUSH(S, r);
+ C67_PUSH(r);
if (size == 8) {
- C67_STW_PTR_PRE_INC(S, r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other)
+ C67_STW_PTR_PRE_INC(r + 1, C67_SP, 3); // STW r, *+SP[3] (go back and put the other)
}
args_sizes[i] = size;
}
- S->tccgen_vtop--;
+ vtop--;
}
// POP all the params on the stack into registers for the
// immediate call (in reverse order)
@@ -1927,12 +1927,12 @@ void gfunc_call(TCCState* S, int nb_args)
for (i = nb_args - 1; i >= 0; i--) {
if (args_sizes[i] == 8)
- C67_POP_DW(S, TREG_C67_A4 + i * 2);
+ C67_POP_DW(TREG_C67_A4 + i * 2);
else
- C67_POP(S, TREG_C67_A4 + i * 2);
+ C67_POP(TREG_C67_A4 + i * 2);
}
- gcall_or_jmp(S, 0);
- S->tccgen_vtop--;
+ gcall_or_jmp(0);
+ vtop--;
}
@@ -1946,7 +1946,7 @@ void gfunc_call(TCCState* S, int nb_args)
// parameters are loaded and restored upon return (or if/when needed).
/* generate function prolog of type 't' */
-void gfunc_prolog(TCCState* S, Sym *func_sym)
+void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
int addr, align, size, func_call, i;
@@ -1958,8 +1958,8 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
addr = 8;
/* if the function returns a structure, then add an
implicit pointer parameter */
- if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT) {
- S->tccgen_func_vc = addr;
+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
+ func_vc = addr;
addr += 4;
}
@@ -1968,7 +1968,7 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
/* define parameters */
while ((sym = sym->next) != NULL) {
type = &sym->type;
- sym_push(S, sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr);
+ sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr);
size = type_size(type, &align);
size = (size + 3) & ~3;
@@ -1992,76 +1992,76 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
if (func_call == FUNC_STDCALL)
func_ret_sub = addr - 8;
- C67_MV(S, C67_FP, C67_A0); // move FP -> A0
- C67_MV(S, C67_SP, C67_FP); // move SP -> FP
+ C67_MV(C67_FP, C67_A0); // move FP -> A0
+ C67_MV(C67_SP, C67_FP); // move SP -> FP
// place all the args passed in regs onto the stack
- S->tccgen_loc = 0;
+ loc = 0;
for (i = 0; i < NoOfCurFuncArgs; i++) {
- ParamLocOnStack[i] = S->tccgen_loc; // remember where the param is
- S->tccgen_loc += -8;
+ ParamLocOnStack[i] = loc; // remember where the param is
+ loc += -8;
- C67_PUSH(S, TREG_C67_A4 + i * 2);
+ C67_PUSH(TREG_C67_A4 + i * 2);
if (TranslateStackToReg[i] == 8) {
- 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)
+ C67_STW_PTR_PRE_INC(TREG_C67_A4 + i * 2 + 1, C67_SP, 3); // STW r, *+SP[1] (go back and put the other)
}
}
- TotalBytesPushedOnStack = -S->tccgen_loc;
+ TotalBytesPushedOnStack = -loc;
- func_sub_sp_offset = S->tccgen_ind; // remember where we put the stack instruction
- C67_ADDK(S, 0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily)
+ func_sub_sp_offset = ind; // remember where we put the stack instruction
+ C67_ADDK(0, C67_SP); // ADDK.L2 loc,SP (just put zero temporarily)
- C67_PUSH(S, C67_A0);
- C67_PUSH(S, C67_B3);
+ C67_PUSH(C67_A0);
+ C67_PUSH(C67_B3);
}
/* generate function epilog */
-void gfunc_epilog(TCCState* S)
+void gfunc_epilog(void)
{
{
- int local = (-S->tccgen_loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr
- C67_POP(S, C67_B3);
- C67_NOP(S, 4); // NOP wait for load
- C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_B3); // B.S2 B3
- C67_POP(S, C67_FP);
- C67_ADDK(S, local, C67_SP); // ADDK.L2 loc,SP
- C67_Adjust_ADDK(S, (int *) (cur_text_section->data +
+ int local = (-loc + 7) & -8; // stack must stay aligned to 8 bytes for LDDW instr
+ C67_POP(C67_B3);
+ C67_NOP(4); // NOP wait for load
+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_B3); // B.S2 B3
+ C67_POP(C67_FP);
+ C67_ADDK(local, C67_SP); // ADDK.L2 loc,SP
+ C67_Adjust_ADDK((int *) (cur_text_section->data +
func_sub_sp_offset),
-local + TotalBytesPushedOnStack);
- C67_NOP(S, 3); // NOP
+ C67_NOP(3); // NOP
}
}
-ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
if ((bytes & 3))
- tcc_error(S, "alignment of code section not multiple of 4");
+ tcc_error("alignment of code section not multiple of 4");
while (bytes > 0) {
- C67_NOP(S, 4);
+ C67_NOP(4);
bytes -= 4;
}
}
/* generate a jump to a label */
-int gjmp(TCCState* S, int t)
+int gjmp(int t)
{
- int ind1 = S->tccgen_ind;
- if (S->tccgen_nocode_wanted)
+ int ind1 = ind;
+ if (nocode_wanted)
return t;
- C67_MVKL(S, C67_A0, t); //r=reg to load, constant
- C67_MVKH(S, C67_A0, t); //r=reg to load, constant
- C67_IREG_B_REG(S, 0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0
- C67_NOP(S, 5);
+ C67_MVKL(C67_A0, t); //r=reg to load, constant
+ C67_MVKH(C67_A0, t); //r=reg to load, constant
+ C67_IREG_B_REG(0, C67_CREG_ZERO, C67_A0); // [!R] B.S2x A0
+ C67_NOP(5);
return ind1;
}
/* generate a jump to a fixed address */
-void gjmp_addr(TCCState* S, int a)
+void gjmp_addr(int a)
{
Sym *sym;
// I guess this routine is used for relative short
@@ -2070,42 +2070,42 @@ void gjmp_addr(TCCState* S, int a)
// define a label that will be relocated
- sym = get_sym_ref(S, &S->tccgen_char_pointer_type, cur_text_section, a, 0);
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_C60LO16);
- greloc(S, cur_text_section, sym, S->tccgen_ind + 4, R_C60HI16);
+ sym = get_sym_ref(&char_pointer_type, cur_text_section, a, 0);
+ greloc(cur_text_section, sym, ind, R_C60LO16);
+ greloc(cur_text_section, sym, ind + 4, R_C60HI16);
- gjmp(S, 0); // place a zero there later the symbol will be added to it
+ gjmp(0); // place a zero there later the symbol will be added to it
}
/* generate a test. set 'inv' to invert test. Stack entry is popped */
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
int ind1;
int inv = op & 1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return t;
/* fast case : can jump directly since flags are set */
// C67 uses B2 sort of as flags register
- ind1 = S->tccgen_ind;
- C67_MVKL(S, C67_A0, t); //r=reg to load, constant
- C67_MVKH(S, C67_A0, t); //r=reg to load, constant
+ ind1 = ind;
+ C67_MVKL(C67_A0, t); //r=reg to load, constant
+ C67_MVKH(C67_A0, t); //r=reg to load, constant
if (C67_compare_reg != TREG_EAX && // check if not already in a conditional test reg
C67_compare_reg != TREG_EDX &&
C67_compare_reg != TREG_ST0 && C67_compare_reg != C67_B2) {
- C67_MV(S, C67_compare_reg, C67_B2);
+ C67_MV(C67_compare_reg, C67_B2);
C67_compare_reg = C67_B2;
}
- C67_IREG_B_REG(S, C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0
- C67_NOP(S, 5);
+ C67_IREG_B_REG(C67_invert_test ^ inv, C67_compare_reg, C67_A0); // [!R] B.S2x A0
+ C67_NOP(5);
t = ind1; //return where we need to patch
return t;
}
-ST_FUNC int gjmp_append(TCCState* S, int n0, int t)
+ST_FUNC int gjmp_append(int n0, int t)
{
if (n0) {
int n = n0, *p;
@@ -2129,7 +2129,7 @@ ST_FUNC int gjmp_append(TCCState* S, int n0, int t)
}
/* generate an integer binary operation */
-void gen_opi(TCCState* S, int op)
+void gen_opi(int op)
{
int r, fr, opc, t;
@@ -2146,62 +2146,62 @@ void gen_opi(TCCState* S, int op)
if (op >= TOK_ULT && op <= TOK_GT)
- gv2(S, RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU
+ gv2(RC_INT_BSIDE, RC_INT); // make sure r (src1) is on the B Side of CPU
else
- gv2(S, RC_INT, RC_INT);
+ gv2(RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
+ r = vtop[-1].r;
+ fr = vtop[0].r;
C67_compare_reg = C67_B2;
if (op == TOK_LT) {
- C67_CMPLT(S, r, fr, C67_B2);
+ C67_CMPLT(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_GE) {
- C67_CMPLT(S, r, fr, C67_B2);
+ C67_CMPLT(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_GT) {
- C67_CMPGT(S, r, fr, C67_B2);
+ C67_CMPGT(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_LE) {
- C67_CMPGT(S, r, fr, C67_B2);
+ C67_CMPGT(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_EQ) {
- C67_CMPEQ(S, r, fr, C67_B2);
+ C67_CMPEQ(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_NE) {
- C67_CMPEQ(S, r, fr, C67_B2);
+ C67_CMPEQ(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_ULT) {
- C67_CMPLTU(S, r, fr, C67_B2);
+ C67_CMPLTU(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_UGE) {
- C67_CMPLTU(S, r, fr, C67_B2);
+ C67_CMPLTU(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_UGT) {
- C67_CMPGTU(S, r, fr, C67_B2);
+ C67_CMPGTU(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_ULE) {
- C67_CMPGTU(S, r, fr, C67_B2);
+ C67_CMPGTU(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == '+')
- C67_ADD(S, fr, r); // ADD r,fr,r
+ C67_ADD(fr, r); // ADD r,fr,r
else if (op == '-')
- C67_SUB(S, fr, r); // SUB r,fr,r
+ C67_SUB(fr, r); // SUB r,fr,r
else if (op == '&')
- C67_AND(S, fr, r); // AND r,fr,r
+ C67_AND(fr, r); // AND r,fr,r
else if (op == '|')
- C67_OR(S, fr, r); // OR r,fr,r
+ C67_OR(fr, r); // OR r,fr,r
else if (op == '^')
- C67_XOR(S, fr, r); // XOR r,fr,r
+ C67_XOR(fr, r); // XOR r,fr,r
else
ALWAYS_ASSERT(FALSE);
- S->tccgen_vtop--;
+ vtop--;
if (op >= TOK_ULT && op <= TOK_GT)
- vset_VT_CMP(S, 0x80);
+ vset_VT_CMP(0x80);
break;
case '-':
case TOK_SUBC1: /* sub with carry generation */
@@ -2224,48 +2224,48 @@ void gen_opi(TCCState* S, int op)
goto gen_op8;
case '*':
case TOK_UMULL:
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- C67_MPYI(S, fr, r); // 32 bit multiply fr,r,fr
- C67_NOP(S, 8); // NOP 8 for worst case
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ C67_MPYI(fr, r); // 32 bit multiply fr,r,fr
+ C67_NOP(8); // NOP 8 for worst case
break;
case TOK_SHL:
- gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- C67_SHL(S, fr, r); // arithmetic/logical shift
+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ C67_SHL(fr, r); // arithmetic/logical shift
break;
case TOK_SHR:
- gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- C67_SHRU(S, fr, r); // logical shift
+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ C67_SHRU(fr, r); // logical shift
break;
case TOK_SAR:
- gv2(S, RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- C67_SHR(S, fr, r); // arithmetic shift
+ gv2(RC_INT_BSIDE, RC_INT_BSIDE); // shift amount must be on same side as dst
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ C67_SHR(fr, r); // arithmetic shift
break;
case '/':
t = TOK__divi;
call_func:
- vswap(S);
+ vswap();
/* call generic idiv function */
- vpush_helper_func(S, t);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = REG_IRET;
- S->tccgen_vtop->r2 = VT_CONST;
+ vpush_helper_func(t);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = REG_IRET;
+ vtop->r2 = VT_CONST;
break;
case TOK_UDIV:
case TOK_PDIV:
@@ -2287,127 +2287,127 @@ void gen_opi(TCCState* S, int op)
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranteed to have the same floating point type */
/* XXX: need to use ST1 too */
-void gen_opf(TCCState* S, int op)
+void gen_opf(int op)
{
int ft, fc, fr, r;
if (op >= TOK_ULT && op <= TOK_GT)
- gv2(S, RC_EDX, RC_EAX); // make sure src2 is on b side
+ gv2(RC_EDX, RC_EAX); // make sure src2 is on b side
else
- gv2(S, RC_FLOAT, RC_FLOAT); // make sure src2 is on b side
+ gv2(RC_FLOAT, RC_FLOAT); // make sure src2 is on b side
- ft = S->tccgen_vtop->type.t;
- fc = S->tccgen_vtop->c.i;
- r = S->tccgen_vtop->r;
- fr = S->tccgen_vtop[-1].r;
+ ft = vtop->type.t;
+ fc = vtop->c.i;
+ r = vtop->r;
+ fr = vtop[-1].r;
if ((ft & VT_BTYPE) == VT_LDOUBLE)
- tcc_error(S, "long doubles not supported");
+ tcc_error("long doubles not supported");
if (op >= TOK_ULT && op <= TOK_GT) {
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
+ r = vtop[-1].r;
+ fr = vtop[0].r;
C67_compare_reg = C67_B2;
if (op == TOK_LT) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPLTDP(S, r, fr, C67_B2);
+ C67_CMPLTDP(r, fr, C67_B2);
else
- C67_CMPLTSP(S, r, fr, C67_B2);
+ C67_CMPLTSP(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_GE) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPLTDP(S, r, fr, C67_B2);
+ C67_CMPLTDP(r, fr, C67_B2);
else
- C67_CMPLTSP(S, r, fr, C67_B2);
+ C67_CMPLTSP(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_GT) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPGTDP(S, r, fr, C67_B2);
+ C67_CMPGTDP(r, fr, C67_B2);
else
- C67_CMPGTSP(S, r, fr, C67_B2);
+ C67_CMPGTSP(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_LE) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPGTDP(S, r, fr, C67_B2);
+ C67_CMPGTDP(r, fr, C67_B2);
else
- C67_CMPGTSP(S, r, fr, C67_B2);
+ C67_CMPGTSP(r, fr, C67_B2);
C67_invert_test = TRUE;
} else if (op == TOK_EQ) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPEQDP(S, r, fr, C67_B2);
+ C67_CMPEQDP(r, fr, C67_B2);
else
- C67_CMPEQSP(S, r, fr, C67_B2);
+ C67_CMPEQSP(r, fr, C67_B2);
C67_invert_test = FALSE;
} else if (op == TOK_NE) {
if ((ft & VT_BTYPE) == VT_DOUBLE)
- C67_CMPEQDP(S, r, fr, C67_B2);
+ C67_CMPEQDP(r, fr, C67_B2);
else
- C67_CMPEQSP(S, r, fr, C67_B2);
+ C67_CMPEQSP(r, fr, C67_B2);
C67_invert_test = TRUE;
} else {
ALWAYS_ASSERT(FALSE);
}
- vset_VT_CMP(S, 0x80);
+ vset_VT_CMP(0x80);
} else {
if (op == '+') {
if ((ft & VT_BTYPE) == VT_DOUBLE) {
- C67_ADDDP(S, r, fr); // ADD fr,r,fr
- C67_NOP(S, 6);
+ C67_ADDDP(r, fr); // ADD fr,r,fr
+ C67_NOP(6);
} else {
- C67_ADDSP(S, r, fr); // ADD fr,r,fr
- C67_NOP(S, 3);
+ C67_ADDSP(r, fr); // ADD fr,r,fr
+ C67_NOP(3);
}
- S->tccgen_vtop--;
+ vtop--;
} else if (op == '-') {
if ((ft & VT_BTYPE) == VT_DOUBLE) {
- C67_SUBDP(S, r, fr); // SUB fr,r,fr
- C67_NOP(S, 6);
+ C67_SUBDP(r, fr); // SUB fr,r,fr
+ C67_NOP(6);
} else {
- C67_SUBSP(S, r, fr); // SUB fr,r,fr
- C67_NOP(S, 3);
+ C67_SUBSP(r, fr); // SUB fr,r,fr
+ C67_NOP(3);
}
- S->tccgen_vtop--;
+ vtop--;
} else if (op == '*') {
if ((ft & VT_BTYPE) == VT_DOUBLE) {
- C67_MPYDP(S, r, fr); // MPY fr,r,fr
- C67_NOP(S, 9);
+ C67_MPYDP(r, fr); // MPY fr,r,fr
+ C67_NOP(9);
} else {
- C67_MPYSP(S, r, fr); // MPY fr,r,fr
- C67_NOP(S, 3);
+ C67_MPYSP(r, fr); // MPY fr,r,fr
+ C67_NOP(3);
}
- S->tccgen_vtop--;
+ vtop--;
} else if (op == '/') {
if ((ft & VT_BTYPE) == VT_DOUBLE) {
// must call intrinsic DP floating point divide
- vswap(S);
+ vswap();
/* call generic idiv function */
- vpush_helper_func(S, TOK__divd);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = REG_FRET;
- S->tccgen_vtop->r2 = REG_IRE2;
+ vpush_helper_func(TOK__divd);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = REG_FRET;
+ vtop->r2 = REG_IRE2;
} else {
// must call intrinsic SP floating point divide
- vswap(S);
+ vswap();
/* call generic idiv function */
- vpush_helper_func(S, TOK__divf);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = REG_FRET;
- S->tccgen_vtop->r2 = VT_CONST;
+ vpush_helper_func(TOK__divf);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = REG_FRET;
+ vtop->r2 = VT_CONST;
}
} else
ALWAYS_ASSERT(FALSE);
@@ -2419,122 +2419,122 @@ void gen_opf(TCCState* S, int op)
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
-void gen_cvt_itof(TCCState* S, int t)
+void gen_cvt_itof(int t)
{
int r;
- gv(S, RC_INT);
- r = S->tccgen_vtop->r;
+ gv(RC_INT);
+ r = vtop->r;
if ((t & VT_BTYPE) == VT_DOUBLE) {
if (t & VT_UNSIGNED)
- C67_INTDPU(S, r, r);
+ C67_INTDPU(r, r);
else
- C67_INTDP(S, r, r);
+ C67_INTDP(r, r);
- C67_NOP(S, 4);
- S->tccgen_vtop->type.t = VT_DOUBLE;
+ C67_NOP(4);
+ vtop->type.t = VT_DOUBLE;
} else {
if (t & VT_UNSIGNED)
- C67_INTSPU(S, r, r);
+ C67_INTSPU(r, r);
else
- C67_INTSP(S, r, r);
- C67_NOP(S, 3);
- S->tccgen_vtop->type.t = VT_FLOAT;
+ C67_INTSP(r, r);
+ C67_NOP(3);
+ vtop->type.t = VT_FLOAT;
}
}
/* convert fp to int 't' type */
/* XXX: handle long long case */
-void gen_cvt_ftoi(TCCState* S, int t)
+void gen_cvt_ftoi(int t)
{
int r;
- gv(S, RC_FLOAT);
- r = S->tccgen_vtop->r;
+ gv(RC_FLOAT);
+ r = vtop->r;
if (t != VT_INT)
- tcc_error(S, "long long not supported");
+ tcc_error("long long not supported");
else {
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
- C67_DPTRUNC(S, r, r);
- C67_NOP(S, 3);
+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE) {
+ C67_DPTRUNC(r, r);
+ C67_NOP(3);
} else {
- C67_SPTRUNC(S, r, r);
- C67_NOP(S, 3);
+ C67_SPTRUNC(r, r);
+ C67_NOP(3);
}
- S->tccgen_vtop->type.t = VT_INT;
+ vtop->type.t = VT_INT;
}
}
/* convert from one floating point type to another */
-void gen_cvt_ftof(TCCState* S, int t)
+void gen_cvt_ftof(int t)
{
int r, r2;
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE &&
+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE &&
(t & VT_BTYPE) == VT_FLOAT) {
// convert double to float
- gv(S, RC_FLOAT); // get it in a register pair
+ gv(RC_FLOAT); // get it in a register pair
- r = S->tccgen_vtop->r;
+ r = vtop->r;
- C67_DPSP(S, r, r); // convert it to SP same register
- C67_NOP(S, 3);
+ C67_DPSP(r, r); // convert it to SP same register
+ C67_NOP(3);
- S->tccgen_vtop->type.t = VT_FLOAT;
- S->tccgen_vtop->r2 = VT_CONST; // set this as unused
- } else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT &&
+ vtop->type.t = VT_FLOAT;
+ vtop->r2 = VT_CONST; // set this as unused
+ } else if ((vtop->type.t & VT_BTYPE) == VT_FLOAT &&
(t & VT_BTYPE) == VT_DOUBLE) {
// convert float to double
- gv(S, RC_FLOAT); // get it in a register
+ gv(RC_FLOAT); // get it in a register
- r = S->tccgen_vtop->r;
+ r = vtop->r;
if (r == TREG_EAX) { // make sure the paired reg is avail
- r2 = get_reg(S, RC_ECX);
+ r2 = get_reg(RC_ECX);
} else if (r == TREG_EDX) {
- r2 = get_reg(S, RC_ST0);
+ r2 = get_reg(RC_ST0);
} else {
ALWAYS_ASSERT(FALSE);
r2 = 0; /* avoid warning */
}
- C67_SPDP(S, r, r); // convert it to DP same register
- C67_NOP(S, 1);
+ C67_SPDP(r, r); // convert it to DP same register
+ C67_NOP(1);
- S->tccgen_vtop->type.t = VT_DOUBLE;
- S->tccgen_vtop->r2 = r2; // set this as unused
+ vtop->type.t = VT_DOUBLE;
+ vtop->r2 = r2; // set this as unused
} else {
ALWAYS_ASSERT(FALSE);
}
}
/* computed goto support */
-void ggoto(TCCState* S)
+void ggoto(void)
{
- gcall_or_jmp(S, 1);
- S->tccgen_vtop--;
+ gcall_or_jmp(1);
+ vtop--;
}
/* Save the stack pointer onto the stack and return the location of its address */
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
- tcc_error(S, "variable length arrays unsupported for this target");
+ST_FUNC void gen_vla_sp_save(int addr) {
+ tcc_error("variable length arrays unsupported for this target");
}
/* Restore the SP from a location on the stack */
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
- tcc_error(S, "variable length arrays unsupported for this target");
+ST_FUNC void gen_vla_sp_restore(int addr) {
+ tcc_error("variable length arrays unsupported for this target");
}
/* Subtract from the stack pointer, and push the resulting value onto the stack */
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
- tcc_error(S, "variable length arrays unsupported for this target");
+ST_FUNC void gen_vla_alloc(CType *type, int align) {
+ tcc_error("variable length arrays unsupported for this target");
}
/* end of C67 code generator */
diff --git a/c67-link.c b/c67-link.c
index 3659ff3..514689c 100644
--- a/c67-link.c
+++ b/c67-link.c
@@ -65,23 +65,23 @@ int gotplt_entry_type (int reloc_type)
return -1;
}
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- tcc_error(S, "C67 got not implemented");
+ tcc_error("C67 got not implemented");
return 0;
}
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
if (p < p_end) {
/* XXX: TODO */
@@ -91,7 +91,7 @@ ST_FUNC void relocate_plt(TCCState *S)
}
}
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
switch(type) {
case R_C60_32:
diff --git a/i386-asm.c b/i386-asm.c
index fdd2787..aca6c97 100644
--- a/i386-asm.c
+++ b/i386-asm.c
@@ -253,10 +253,10 @@ static const uint16_t op0_codes[] = {
#endif
};
-static inline int get_reg_shift(TCCState *S)
+static inline int get_reg_shift(TCCState *s1)
{
int shift, v;
- v = asm_int_expr(S);
+ v = asm_int_expr(s1);
switch(v) {
case 1:
shift = 0;
@@ -271,7 +271,7 @@ static inline int get_reg_shift(TCCState *S)
shift = 3;
break;
default:
- expect(S, "1, 2, 4 or 8 constant");
+ expect("1, 2, 4 or 8 constant");
shift = 0;
break;
}
@@ -279,11 +279,11 @@ static inline int get_reg_shift(TCCState *S)
}
#ifdef TCC_TARGET_X86_64
-static int asm_parse_numeric_reg(TCCState *S, int t, unsigned int *type)
+static int asm_parse_numeric_reg(int t, unsigned int *type)
{
int reg = -1;
- if (t >= TOK_IDENT && t < S->tccpp_tok_ident) {
- const char *s = S->tccpp_table_ident[t - TOK_IDENT]->str;
+ if (t >= TOK_IDENT && t < tok_ident) {
+ const char *s = table_ident[t - TOK_IDENT]->str;
char c;
*type = OP_REG64;
if (*s == 'c') {
@@ -318,51 +318,51 @@ static int asm_parse_numeric_reg(TCCState *S, int t, unsigned int *type)
}
#endif
-static int asm_parse_reg(TCCState* S, unsigned int *type)
+static int asm_parse_reg(unsigned int *type)
{
int reg = 0;
*type = 0;
- if (S->tccpp_tok != '%')
+ if (tok != '%')
goto error_32;
- next(S);
- if (S->tccpp_tok >= TOK_ASM_eax && S->tccpp_tok <= TOK_ASM_edi) {
- reg = S->tccpp_tok - TOK_ASM_eax;
+ next();
+ if (tok >= TOK_ASM_eax && tok <= TOK_ASM_edi) {
+ reg = tok - TOK_ASM_eax;
*type = OP_REG32;
#ifdef TCC_TARGET_X86_64
- } else if (S->tccpp_tok >= TOK_ASM_rax && S->tccpp_tok <= TOK_ASM_rdi) {
- reg = S->tccpp_tok - TOK_ASM_rax;
+ } else if (tok >= TOK_ASM_rax && tok <= TOK_ASM_rdi) {
+ reg = tok - TOK_ASM_rax;
*type = OP_REG64;
- } else if (S->tccpp_tok == TOK_ASM_rip) {
+ } else if (tok == TOK_ASM_rip) {
reg = -2; /* Probably should use different escape code. */
*type = OP_REG64;
- } else if ((reg = asm_parse_numeric_reg(S, S->tccpp_tok, type)) >= 0
+ } else if ((reg = asm_parse_numeric_reg(tok, type)) >= 0
&& (*type == OP_REG32 || *type == OP_REG64)) {
;
#endif
} else {
error_32:
- expect(S, "register");
+ expect("register");
}
- next(S);
+ next();
return reg;
}
-static void parse_operand(TCCState *S, Operand *op)
+static void parse_operand(TCCState *s1, Operand *op)
{
ExprValue e;
int reg, indir;
const char *p;
indir = 0;
- if (S->tccpp_tok == '*') {
- next(S);
+ if (tok == '*') {
+ next();
indir = OP_INDIR;
}
- if (S->tccpp_tok == '%') {
- next(S);
- if (S->tccpp_tok >= TOK_ASM_al && S->tccpp_tok <= TOK_ASM_db7) {
- reg = S->tccpp_tok - TOK_ASM_al;
+ if (tok == '%') {
+ next();
+ if (tok >= TOK_ASM_al && tok <= TOK_ASM_db7) {
+ reg = tok - TOK_ASM_al;
op->type = 1 << (reg >> 3); /* WARNING: do not change constant order */
op->reg = reg & 7;
if ((op->type & OP_REG) && op->reg == TREG_XAX)
@@ -371,48 +371,48 @@ static void parse_operand(TCCState *S, Operand *op)
op->type |= OP_CL;
else if (op->type == OP_REG16 && op->reg == TREG_XDX)
op->type |= OP_DX;
- } else if (S->tccpp_tok >= TOK_ASM_dr0 && S->tccpp_tok <= TOK_ASM_dr7) {
+ } else if (tok >= TOK_ASM_dr0 && tok <= TOK_ASM_dr7) {
op->type = OP_DB;
- op->reg = S->tccpp_tok - TOK_ASM_dr0;
- } else if (S->tccpp_tok >= TOK_ASM_es && S->tccpp_tok <= TOK_ASM_gs) {
+ op->reg = tok - TOK_ASM_dr0;
+ } else if (tok >= TOK_ASM_es && tok <= TOK_ASM_gs) {
op->type = OP_SEG;
- op->reg = S->tccpp_tok - TOK_ASM_es;
- } else if (S->tccpp_tok == TOK_ASM_st) {
+ op->reg = tok - TOK_ASM_es;
+ } else if (tok == TOK_ASM_st) {
op->type = OP_ST;
op->reg = 0;
- next(S);
- if (S->tccpp_tok == '(') {
- next(S);
- if (S->tccpp_tok != TOK_PPNUM)
+ next();
+ if (tok == '(') {
+ next();
+ if (tok != TOK_PPNUM)
goto reg_error;
- p = S->tccpp_tokc.str.data;
+ p = tokc.str.data;
reg = p[0] - '0';
if ((unsigned)reg >= 8 || p[1] != '\0')
goto reg_error;
op->reg = reg;
- next(S);
- skip(S, ')');
+ next();
+ skip(')');
}
if (op->reg == 0)
op->type |= OP_ST0;
goto no_skip;
#ifdef TCC_TARGET_X86_64
- } else if (S->tccpp_tok >= TOK_ASM_spl && S->tccpp_tok <= TOK_ASM_dil) {
+ } else if (tok >= TOK_ASM_spl && tok <= TOK_ASM_dil) {
op->type = OP_REG8 | OP_REG8_LOW;
- op->reg = 4 + S->tccpp_tok - TOK_ASM_spl;
- } else if ((op->reg = asm_parse_numeric_reg(S, S->tccpp_tok, &op->type)) >= 0) {
+ op->reg = 4 + tok - TOK_ASM_spl;
+ } else if ((op->reg = asm_parse_numeric_reg(tok, &op->type)) >= 0) {
;
#endif
} else {
reg_error:
- tcc_error(S, "unknown register %%%s", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_error("unknown register %%%s", get_tok_str(tok, &tokc));
}
- next(S);
+ next();
no_skip: ;
- } else if (S->tccpp_tok == '$') {
+ } else if (tok == '$') {
/* constant value */
- next(S);
- asm_expr(S, &e);
+ next();
+ asm_expr(s1, &e);
op->type = OP_IM32;
op->e = e;
if (!op->e.sym) {
@@ -433,45 +433,45 @@ static void parse_operand(TCCState *S, Operand *op)
op->reg = -1;
op->reg2 = -1;
op->shift = 0;
- if (S->tccpp_tok != '(') {
- asm_expr(S, &e);
+ if (tok != '(') {
+ asm_expr(s1, &e);
op->e = e;
} else {
- next(S);
- if (S->tccpp_tok == '%') {
- unget_tok(S, '(');
+ next();
+ if (tok == '%') {
+ unget_tok('(');
op->e.v = 0;
op->e.sym = NULL;
} else {
/* bracketed offset expression */
- asm_expr(S, &e);
- if (S->tccpp_tok != ')')
- expect(S, ")");
- next(S);
+ asm_expr(s1, &e);
+ if (tok != ')')
+ expect(")");
+ next();
op->e.v = e.v;
op->e.sym = e.sym;
}
op->e.pcrel = 0;
}
- if (S->tccpp_tok == '(') {
+ if (tok == '(') {
unsigned int type = 0;
- next(S);
- if (S->tccpp_tok != ',') {
- op->reg = asm_parse_reg(S, &type);
+ next();
+ if (tok != ',') {
+ op->reg = asm_parse_reg(&type);
}
- if (S->tccpp_tok == ',') {
- next(S);
- if (S->tccpp_tok != ',') {
- op->reg2 = asm_parse_reg(S, &type);
+ if (tok == ',') {
+ next();
+ if (tok != ',') {
+ op->reg2 = asm_parse_reg(&type);
}
- if (S->tccpp_tok == ',') {
- next(S);
- op->shift = get_reg_shift(S);
+ if (tok == ',') {
+ next();
+ op->shift = get_reg_shift(s1);
}
}
if (type & OP_REG32)
op->type |= OP_EA32;
- skip(S, ')');
+ skip(')');
}
if (op->reg == -1 && op->reg2 == -1)
op->type |= OP_ADDR;
@@ -480,65 +480,65 @@ static void parse_operand(TCCState *S, Operand *op)
}
/* XXX: unify with C code output ? */
-ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
+ST_FUNC void gen_expr32(ExprValue *pe)
{
if (pe->pcrel)
/* If PC-relative, always set VT_SYM, even without symbol,
so as to force a relocation to be emitted. */
- gen_addrpc32(S, VT_SYM, pe->sym, pe->v);
+ gen_addrpc32(VT_SYM, pe->sym, pe->v);
else
- gen_addr32(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
+ gen_addr32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
}
#ifdef TCC_TARGET_X86_64
-ST_FUNC void gen_expr64(TCCState* S, ExprValue *pe)
+ST_FUNC void gen_expr64(ExprValue *pe)
{
- gen_addr64(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
+ gen_addr64(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
}
#endif
/* XXX: unify with C code output ? */
-static void gen_disp32(TCCState* S, ExprValue *pe)
+static void gen_disp32(ExprValue *pe)
{
Sym *sym = pe->sym;
- ElfSym *esym = elfsym(S, sym);
+ ElfSym *esym = elfsym(sym);
if (esym && esym->st_shndx == cur_text_section->sh_num) {
/* same section: we can output an absolute value. Note
that the TCC compiler behaves differently here because
it always outputs a relocation to ease (future) code
elimination in the linker */
- gen_le32(S, pe->v + esym->st_value - S->tccgen_ind - 4);
+ gen_le32(pe->v + esym->st_value - ind - 4);
} else {
if (sym && sym->type.t == VT_VOID) {
sym->type.t = VT_FUNC;
sym->type.ref = NULL;
}
- gen_addrpc32(S, VT_SYM, sym, pe->v);
+ gen_addrpc32(VT_SYM, sym, pe->v);
}
}
/* generate the modrm operand */
-static inline int asm_modrm(TCCState* S, int reg, Operand *op)
+static inline int asm_modrm(int reg, Operand *op)
{
int mod, reg1, reg2, sib_reg1;
if (op->type & (OP_REG | OP_MMX | OP_SSE)) {
- g(S, 0xc0 + (reg << 3) + op->reg);
+ g(0xc0 + (reg << 3) + op->reg);
} else if (op->reg == -1 && op->reg2 == -1) {
/* displacement only */
#ifdef TCC_TARGET_X86_64
- g(S, 0x04 + (reg << 3));
- g(S, 0x25);
+ g(0x04 + (reg << 3));
+ g(0x25);
#else
- g(S, 0x05 + (reg << 3));
+ g(0x05 + (reg << 3));
#endif
- gen_expr32(S, &op->e);
+ gen_expr32(&op->e);
#ifdef TCC_TARGET_X86_64
} else if (op->reg == -2) {
ExprValue *pe = &op->e;
- g(S, 0x05 + (reg << 3));
- gen_addrpc32(S, pe->sym ? VT_SYM : 0, pe->sym, pe->v);
- return S->tccgen_ind;
+ g(0x05 + (reg << 3));
+ gen_addrpc32(pe->sym ? VT_SYM : 0, pe->sym, pe->v);
+ return ind;
#endif
} else {
sib_reg1 = op->reg;
@@ -557,19 +557,19 @@ static inline int asm_modrm(TCCState* S, int reg, Operand *op)
reg1 = op->reg;
if (op->reg2 != -1)
reg1 = 4;
- g(S, mod + (reg << 3) + reg1);
+ g(mod + (reg << 3) + reg1);
if (reg1 == 4) {
/* add sib byte */
reg2 = op->reg2;
if (reg2 == -1)
reg2 = 4; /* indicate no index */
- g(S, (op->shift << 6) + (reg2 << 3) + sib_reg1);
+ g((op->shift << 6) + (reg2 << 3) + sib_reg1);
}
/* add offset */
if (mod == 0x40) {
- g(S, op->e.v);
+ g(op->e.v);
} else if (mod == 0x80 || op->reg == -1) {
- gen_expr32(S, &op->e);
+ gen_expr32(&op->e);
}
}
return 0;
@@ -581,7 +581,7 @@ static inline int asm_modrm(TCCState* S, int reg, Operand *op)
#define REX_X 0x42
#define REX_B 0x41
-static void asm_rex(TCCState* S, int width64, Operand *ops, int nb_ops, int *op_type,
+static void asm_rex(int width64, Operand *ops, int nb_ops, int *op_type,
int regi, int rmi)
{
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_
}
if (rex) {
if (saw_high_8bit)
- tcc_error(S, "can't encode register %%%ch when REX prefix is required",
+ tcc_error("can't encode register %%%ch when REX prefix is required",
"acdb"[saw_high_8bit-4]);
- g(S, rex);
+ g(rex);
}
}
#endif
@@ -679,7 +679,7 @@ static void maybe_print_stats (void)
}
}
-ST_FUNC void asm_opcode(TCCState *S, int opcode)
+ST_FUNC void asm_opcode(TCCState *s1, int opcode)
{
const ASMInstr *pa;
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)
/* force synthetic ';' after prefix instruction, so we can handle */
/* one-line things like "rep stosb" instead of only "rep\nstosb" */
if (opcode >= TOK_ASM_wait && opcode <= TOK_ASM_repnz)
- unget_tok(S, ';');
+ unget_tok(';');
/* get operands */
pop = ops;
@@ -705,27 +705,27 @@ ST_FUNC void asm_opcode(TCCState *S, int opcode)
seg_prefix = 0;
alltypes = 0;
for(;;) {
- if (S->tccpp_tok == ';' || S->tccpp_tok == TOK_LINEFEED)
+ if (tok == ';' || tok == TOK_LINEFEED)
break;
if (nb_ops >= MAX_OPERANDS) {
- tcc_error(S, "incorrect number of operands");
+ tcc_error("incorrect number of operands");
}
- parse_operand(S, pop);
- if (S->tccpp_tok == ':') {
+ parse_operand(s1, pop);
+ if (tok == ':') {
if (pop->type != OP_SEG || seg_prefix)
- tcc_error(S, "incorrect prefix");
+ tcc_error("incorrect prefix");
seg_prefix = segment_prefixes[pop->reg];
- next(S);
- parse_operand(S, pop);
+ next();
+ parse_operand(s1, pop);
if (!(pop->type & OP_EA)) {
- tcc_error(S, "segment prefix must be followed by memory reference");
+ tcc_error("segment prefix must be followed by memory reference");
}
}
pop++;
nb_ops++;
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S);
+ next();
}
s = 0; /* avoid warning */
@@ -842,23 +842,23 @@ again:
int b;
b = op0_codes[opcode - TOK_ASM_first];
if (b & 0xff00)
- g(S, b >> 8);
- g(S, b);
+ g(b >> 8);
+ g(b);
return;
} else if (opcode <= TOK_ASM_alllast) {
- tcc_error(S, "bad operand with opcode '%s'",
- get_tok_str(S, opcode, NULL));
+ tcc_error("bad operand with opcode '%s'",
+ get_tok_str(opcode, NULL));
} else {
/* Special case for cmovcc, we accept size suffixes but ignore
them, but we don't want them to blow up our tables. */
- TokenSym *ts = S->tccpp_table_ident[opcode - TOK_IDENT];
+ TokenSym *ts = table_ident[opcode - TOK_IDENT];
if (ts->len >= 6
&& strchr("wlq", ts->str[ts->len-1])
&& !memcmp(ts->str, "cmov", 4)) {
- opcode = tok_alloc(S, ts->str, ts->len-1)->tok;
+ opcode = tok_alloc(ts->str, ts->len-1)->tok;
goto again;
}
- tcc_error(S, "unknown opcode '%s'", ts->str);
+ tcc_error("unknown opcode '%s'", ts->str);
}
}
/* if the size is unknown, then evaluate it (OPC_B or OPC_WL case) */
@@ -886,7 +886,7 @@ again:
(ops[0].type & OP_EA))
s = NBWLX - 2;
else
- tcc_error(S, "cannot infer opcode suffix");
+ tcc_error("cannot infer opcode suffix");
}
}
@@ -894,7 +894,7 @@ again:
/* Generate addr32 prefix if needed */
for(i = 0; i < nb_ops; i++) {
if (ops[i].type & OP_EA32) {
- g(S, 0x67);
+ g(0x67);
break;
}
}
@@ -913,7 +913,7 @@ again:
p66 = 1;
}
if (p66)
- g(S, 0x66);
+ g(0x66);
#ifdef TCC_TARGET_X86_64
rex64 = 0;
if (pa->instr_type & OPC_48)
@@ -943,9 +943,9 @@ again:
/* now generates the operation */
if (OPCT_IS(pa->instr_type, OPC_FWAIT))
- g(S, 0x9b);
+ g(0x9b);
if (seg_prefix)
- g(S, seg_prefix);
+ g(seg_prefix);
v = pa->opcode;
if (pa->instr_type & OPC_0F)
@@ -998,7 +998,7 @@ again:
goto modrm_found;
}
#ifdef ASM_DEBUG
- tcc_error(S, "bad op table");
+ tcc_error("bad op table");
#endif
modrm_found:
modrm_index = i;
@@ -1014,7 +1014,7 @@ again:
}
}
#ifdef TCC_TARGET_X86_64
- asm_rex (S, rex64, ops, nb_ops, op_type, modreg_index, modrm_index);
+ asm_rex (rex64, ops, nb_ops, op_type, modreg_index, modrm_index);
#endif
if (pa->instr_type & OPC_REG) {
@@ -1035,10 +1035,10 @@ again:
int jmp_disp;
/* see if we can really generate the jump with a byte offset */
- esym = elfsym(S, ops[0].e.sym);
+ esym = elfsym(ops[0].e.sym);
if (!esym || esym->st_shndx != cur_text_section->sh_num)
goto no_short_jump;
- jmp_disp = ops[0].e.v + esym->st_value - S->tccgen_ind - 2 - (v >= 0xff);
+ jmp_disp = ops[0].e.v + esym->st_value - ind - 2 - (v >= 0xff);
if (jmp_disp == (int8_t)jmp_disp) {
/* OK to generate jump */
ops[0].e.sym = 0;
@@ -1053,18 +1053,18 @@ again:
else if (v == 0x70) /* jcc */
v += 0x0f10;
else
- tcc_error(S, "invalid displacement");
+ tcc_error("invalid displacement");
}
}
if (OPCT_IS(pa->instr_type, OPC_TEST))
v += test_bits[opcode - pa->sym];
op1 = v >> 16;
if (op1)
- g(S, op1);
+ g(op1);
op1 = (v >> 8) & 0xff;
if (op1)
- g(S, op1);
- g(S, v);
+ g(op1);
+ g(v);
if (OPCT_IS(pa->instr_type, OPC_SHIFT)) {
reg = (opcode - pa->sym) / NBWLX;
@@ -1084,7 +1084,7 @@ again:
used instead of group */
if (modreg_index >= 0)
reg = ops[modreg_index].reg;
- pc = asm_modrm(S, reg, &ops[modrm_index]);
+ pc = asm_modrm(reg, &ops[modrm_index]);
}
/* emit constants */
@@ -1092,10 +1092,10 @@ again:
if (!(pa->instr_type & OPC_0F)
&& (pa->opcode == 0x9a || pa->opcode == 0xea)) {
/* ljmp or lcall kludge */
- gen_expr32(S, &ops[1].e);
+ gen_expr32(&ops[1].e);
if (ops[0].e.sym)
- tcc_error(S, "cannot relocate");
- gen_le16(S, ops[0].e.v);
+ tcc_error("cannot relocate");
+ gen_le16(ops[0].e.v);
return;
}
#endif
@@ -1116,32 +1116,32 @@ again:
}
if ((v & (OP_IM8 | OP_IM8S | OP_IM16)) && ops[i].e.sym)
- tcc_error(S, "cannot relocate");
+ tcc_error("cannot relocate");
if (v & (OP_IM8 | OP_IM8S)) {
- g(S, ops[i].e.v);
+ g(ops[i].e.v);
} else if (v & OP_IM16) {
- gen_le16(S, ops[i].e.v);
+ gen_le16(ops[i].e.v);
#ifdef TCC_TARGET_X86_64
} else if (v & OP_IM64) {
- gen_expr64(S, &ops[i].e);
+ gen_expr64(&ops[i].e);
#endif
} else if (pa->op_type[i] == OPT_DISP || pa->op_type[i] == OPT_DISP8) {
- gen_disp32(S, &ops[i].e);
+ gen_disp32(&ops[i].e);
} else {
- gen_expr32(S, &ops[i].e);
+ gen_expr32(&ops[i].e);
}
}
}
/* after immediate operands, adjust pc-relative address */
if (pc)
- add32le(cur_text_section->data + pc - 4, pc - S->tccgen_ind);
+ add32le(cur_text_section->data + pc - 4, pc - ind);
}
/* return the constraint priority (we allocate first the lowest
numbered constraints) */
-static inline int constraint_priority(TCCState* S, const char *str)
+static inline int constraint_priority(const char *str)
{
int priority, c, pr;
@@ -1182,7 +1182,7 @@ static inline int constraint_priority(TCCState* S, const char *str)
pr = 4;
break;
default:
- tcc_error(S, "unknown constraint '%c'", c);
+ tcc_error("unknown constraint '%c'", c);
pr = 0;
}
if (pr > priority)
@@ -1200,19 +1200,19 @@ static const char *skip_constraint_modifiers(const char *p)
/* If T (a token) is of the form "%reg" returns the register
number and type, otherwise return -1. */
-ST_FUNC int asm_parse_regvar (TCCState* S, int t)
+ST_FUNC int asm_parse_regvar (int t)
{
const char *s;
Operand op;
if (t < TOK_IDENT || (t & SYM_FIELD))
return -1;
- s = S->tccpp_table_ident[t - TOK_IDENT]->str;
+ s = table_ident[t - TOK_IDENT]->str;
if (s[0] != '%')
return -1;
- t = tok_alloc_const(S, s + 1);
- unget_tok(S, t);
- unget_tok(S, '%');
- parse_operand(S, &op);
+ t = tok_alloc_const(s + 1);
+ unget_tok(t);
+ unget_tok('%');
+ parse_operand(tcc_state, &op);
/* Accept only integer regs for now. */
if (op.type & OP_REG)
return op.reg;
@@ -1225,7 +1225,7 @@ ST_FUNC int asm_parse_regvar (TCCState* S, int t)
#define is_reg_allocated(reg) (regs_allocated[reg] & reg_mask)
-ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
int nb_operands, int nb_outputs,
const uint8_t *clobber_regs,
int *pout_reg)
@@ -1253,13 +1253,13 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
str = skip_constraint_modifiers(str);
if (isnum(*str) || *str == '[') {
/* this is a reference to another constraint */
- k = find_constraint(S, operands, nb_operands, str, NULL);
+ k = find_constraint(operands, nb_operands, str, NULL);
if ((unsigned)k >= i || i < nb_outputs)
- tcc_error(S, "invalid reference in constraint %d ('%s')",
+ tcc_error("invalid reference in constraint %d ('%s')",
i, str);
op->ref_index = k;
if (operands[k].input_index >= 0)
- tcc_error(S, "cannot reference twice the same operand");
+ tcc_error("cannot reference twice the same operand");
operands[k].input_index = i;
op->priority = 5;
} else if ((op->vt->r & VT_VALMASK) == VT_LOCAL
@@ -1268,7 +1268,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
op->priority = 1;
op->reg = reg;
} else {
- op->priority = constraint_priority(S, str);
+ op->priority = constraint_priority(str);
}
}
@@ -1316,7 +1316,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
}
if (op->reg >= 0) {
if (is_reg_allocated(op->reg))
- tcc_error(S, "asm regvar requests register that's taken already");
+ tcc_error("asm regvar requests register that's taken already");
reg = op->reg;
goto reg_found;
}
@@ -1330,7 +1330,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
/* FALL THRU */
case '&':
if (j >= nb_outputs)
- tcc_error(S, "'%c' modifier can only be applied to outputs", c);
+ tcc_error("'%c' modifier can only be applied to outputs", c);
reg_mask = REG_IN_MASK | REG_OUT_MASK;
goto try_next;
case 'A':
@@ -1424,7 +1424,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
}
break;
default:
- tcc_error(S, "asm constraint %d ('%s') could not be satisfied",
+ tcc_error("asm constraint %d ('%s') could not be satisfied",
j, op->constraint);
break;
}
@@ -1447,7 +1447,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
if (!(regs_allocated[reg] & REG_OUT_MASK))
goto reg_found2;
}
- tcc_error(S, "could not find free output register for reloading");
+ tcc_error("could not find free output register for reloading");
reg_found2:
*pout_reg = reg;
break;
@@ -1461,7 +1461,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
op = &operands[j];
printf("%%%d [%s]: \"%s\" r=0x%04x reg=%d\n",
j,
- op->id ? get_tok_str(S, op->id, NULL) : "",
+ op->id ? get_tok_str(op->id, NULL) : "",
op->constraint,
op->vt->r,
op->reg);
@@ -1471,7 +1471,7 @@ ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands,
#endif
}
-ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
+ST_FUNC void subst_asm_operand(CString *add_str,
SValue *sv, int modifier)
{
int r, reg, size, val;
@@ -1481,33 +1481,33 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
if ((r & VT_VALMASK) == VT_CONST) {
if (!(r & VT_LVAL) && modifier != 'c' && modifier != 'n' &&
modifier != 'P')
- cstr_ccat(S, add_str, '$');
+ cstr_ccat(add_str, '$');
if (r & VT_SYM) {
- const char *name = get_tok_str(S, sv->sym->v, NULL);
+ const char *name = get_tok_str(sv->sym->v, NULL);
if (sv->sym->v >= SYM_FIRST_ANOM) {
/* In case of anonymous symbols ("L.42", used
for static data labels) we can't find them
in the C symbol table when later looking up
this name. So enter them now into the asm label
list when we still know the symbol. */
- get_asm_sym(S, tok_alloc_const(S, name), sv->sym);
+ get_asm_sym(tok_alloc_const(name), sv->sym);
}
- if (S->leading_underscore)
- cstr_ccat(S, add_str, '_');
- cstr_cat(S, add_str, name, -1);
+ if (tcc_state->leading_underscore)
+ cstr_ccat(add_str, '_');
+ cstr_cat(add_str, name, -1);
if ((uint32_t)sv->c.i == 0)
goto no_offset;
- cstr_ccat(S, add_str, '+');
+ cstr_ccat(add_str, '+');
}
val = sv->c.i;
if (modifier == 'n')
val = -val;
snprintf(buf, sizeof(buf), "%d", (int)sv->c.i);
- cstr_cat(S, add_str, buf, -1);
+ cstr_cat(add_str, buf, -1);
no_offset:;
#ifdef TCC_TARGET_X86_64
if (r & VT_LVAL)
- cstr_cat(S, add_str, "(%rip)", -1);
+ cstr_cat(add_str, "(%rip)", -1);
#endif
} else if ((r & VT_VALMASK) == VT_LOCAL) {
#ifdef TCC_TARGET_X86_64
@@ -1515,24 +1515,24 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
#else
snprintf(buf, sizeof(buf), "%d(%%ebp)", (int)sv->c.i);
#endif
- cstr_cat(S, add_str, buf, -1);
+ cstr_cat(add_str, buf, -1);
} else if (r & VT_LVAL) {
reg = r & VT_VALMASK;
if (reg >= VT_CONST)
- tcc_internal_error(S, "");
+ tcc_internal_error("");
snprintf(buf, sizeof(buf), "(%%%s)",
#ifdef TCC_TARGET_X86_64
- get_tok_str(S, TOK_ASM_rax + reg, NULL)
+ get_tok_str(TOK_ASM_rax + reg, NULL)
#else
- get_tok_str(S, TOK_ASM_eax + reg, NULL)
+ get_tok_str(TOK_ASM_eax + reg, NULL)
#endif
);
- cstr_cat(S, add_str, buf, -1);
+ cstr_cat(add_str, buf, -1);
} else {
/* register case */
reg = r & VT_VALMASK;
if (reg >= VT_CONST)
- tcc_internal_error(S, "");
+ tcc_internal_error("");
/* choose register operand size */
if ((sv->type.t & VT_BTYPE) == VT_BYTE ||
@@ -1552,11 +1552,11 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
if (modifier == 'b') {
if (reg >= 4)
- tcc_error(S, "cannot use byte register");
+ tcc_error("cannot use byte register");
size = 1;
} else if (modifier == 'h') {
if (reg >= 4)
- tcc_error(S, "cannot use byte register");
+ tcc_error("cannot use byte register");
size = -1;
} else if (modifier == 'w') {
size = 2;
@@ -1587,13 +1587,13 @@ ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str,
break;
#endif
}
- snprintf(buf, sizeof(buf), "%%%s", get_tok_str(S, reg, NULL));
- cstr_cat(S, add_str, buf, -1);
+ snprintf(buf, sizeof(buf), "%%%s", get_tok_str(reg, NULL));
+ cstr_cat(add_str, buf, -1);
}
}
/* generate prolog and epilog code for asm statement */
-ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
int nb_outputs, int is_output,
uint8_t *clobber_regs,
int out_reg)
@@ -1627,8 +1627,8 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
reg = reg_saved[i];
if (regs_allocated[reg]) {
if (reg >= 8)
- g(S, 0x41), reg-=8;
- g(S, 0x50 + reg);
+ g(0x41), reg-=8;
+ g(0x50 + reg);
}
}
@@ -1644,15 +1644,15 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
sv.type.t = VT_PTR;
- load(S, op->reg, &sv);
+ load(op->reg, &sv);
} else if (i >= nb_outputs || op->is_rw) {
/* load value in register */
- load(S, op->reg, op->vt);
+ load(op->reg, op->vt);
if (op->is_llong) {
SValue sv;
sv = *op->vt;
sv.c.i += 4;
- load(S, TREG_XDX, &sv);
+ load(TREG_XDX, &sv);
}
}
}
@@ -1668,19 +1668,19 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | VT_LOCAL;
sv.type.t = VT_PTR;
- load(S, out_reg, &sv);
+ load(out_reg, &sv);
sv = *op->vt;
sv.r = (sv.r & ~VT_VALMASK) | out_reg;
- store(S, op->reg, &sv);
+ store(op->reg, &sv);
}
} else {
- store(S, op->reg, op->vt);
+ store(op->reg, op->vt);
if (op->is_llong) {
SValue sv;
sv = *op->vt;
sv.c.i += 4;
- store(S, TREG_XDX, &sv);
+ store(TREG_XDX, &sv);
}
}
}
@@ -1690,14 +1690,14 @@ ST_FUNC void asm_gen_code(TCCState* S, ASMOperand *operands, int nb_operands,
reg = reg_saved[i];
if (regs_allocated[reg]) {
if (reg >= 8)
- g(S, 0x41), reg-=8;
- g(S, 0x58 + reg);
+ g(0x41), reg-=8;
+ g(0x58 + reg);
}
}
}
}
-ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
{
int reg;
#ifdef TCC_TARGET_X86_64
@@ -1708,7 +1708,7 @@ ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str)
!strcmp(str, "cc") ||
!strcmp(str, "flags"))
return;
- reg = tok_alloc_const(S, str);
+ reg = tok_alloc_const(str);
if (reg >= TOK_ASM_eax && reg <= TOK_ASM_edi) {
reg -= TOK_ASM_eax;
} 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)
#ifdef TCC_TARGET_X86_64
} else if (reg >= TOK_ASM_rax && reg <= TOK_ASM_rdi) {
reg -= TOK_ASM_rax;
- } else if ((reg = asm_parse_numeric_reg(S, reg, &type)) >= 0) {
+ } else if ((reg = asm_parse_numeric_reg(reg, &type)) >= 0) {
;
#endif
} else {
- tcc_error(S, "invalid clobber register '%s'", str);
+ tcc_error("invalid clobber register '%s'", str);
}
clobber_regs[reg] = 1;
}
diff --git a/i386-gen.c b/i386-gen.c
index 0b61683..8c245ad 100644
--- a/i386-gen.c
+++ b/i386-gen.c
@@ -100,47 +100,50 @@ ST_DATA const int reg_classes[NB_REGS] = {
static unsigned long func_sub_sp_offset;
static int func_ret_sub;
#ifdef CONFIG_TCC_BCHECK
-static void gen_bounds_prolog(TCCState* S);
-static void gen_bounds_epilog(TCCState* S);
+static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
+ST_DATA int func_bound_add_epilog;
+static void gen_bounds_prolog(void);
+static void gen_bounds_epilog(void);
#endif
/* XXX: make it faster ? */
-ST_FUNC void g(TCCState* S, int c)
+ST_FUNC void g(int c)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 1;
+ ind1 = ind + 1;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind] = c;
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind] = c;
+ ind = ind1;
}
-ST_FUNC void o(TCCState* S, unsigned int c)
+ST_FUNC void o(unsigned int c)
{
while (c) {
- g(S, c);
+ g(c);
c = c >> 8;
}
}
-ST_FUNC void gen_le16(TCCState* S, int v)
+ST_FUNC void gen_le16(int v)
{
- g(S, v);
- g(S, v >> 8);
+ g(v);
+ g(v >> 8);
}
-ST_FUNC void gen_le32(TCCState* S, int c)
+ST_FUNC void gen_le32(int c)
{
- g(S, c);
- g(S, c >> 8);
- g(S, c >> 16);
- g(S, c >> 24);
+ g(c);
+ g(c >> 8);
+ g(c >> 16);
+ g(c >> 24);
}
/* output a symbol and patch all calls to it */
-ST_FUNC void gsym_addr(TCCState* S, int t, int a)
+ST_FUNC void gsym_addr(int t, int a)
{
while (t) {
unsigned char *ptr = cur_text_section->data + t;
@@ -151,73 +154,73 @@ ST_FUNC void gsym_addr(TCCState* S, int t, int a)
}
/* instruction + 4 bytes data. Return the address of the data */
-static int oad(TCCState* S, int c, int s)
+static int oad(int c, int s)
{
int t;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return s;
- o(S, c);
- t = S->tccgen_ind;
- gen_le32(S, s);
+ o(c);
+ t = ind;
+ gen_le32(s);
return t;
}
-ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
while (bytes--)
- g(S, 0x90);
+ g(0x90);
}
/* generate jmp to a label */
-#define gjmp2(s, instr,lbl) oad(s, instr,lbl)
+#define gjmp2(instr,lbl) oad(instr,lbl)
/* output constant with relocation if 'r & VT_SYM' is true */
-ST_FUNC void gen_addr32(TCCState* S, int r, Sym *sym, int c)
+ST_FUNC void gen_addr32(int r, Sym *sym, int c)
{
if (r & VT_SYM)
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_386_32);
- gen_le32(S, c);
+ greloc(cur_text_section, sym, ind, R_386_32);
+ gen_le32(c);
}
-ST_FUNC void gen_addrpc32(TCCState* S, int r, Sym *sym, int c)
+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
{
if (r & VT_SYM)
- greloc(S, cur_text_section, sym, S->tccgen_ind, R_386_PC32);
- gen_le32(S, c - 4);
+ greloc(cur_text_section, sym, ind, R_386_PC32);
+ gen_le32(c - 4);
}
/* generate a modrm reference. 'op_reg' contains the additional 3
opcode bits */
-static void gen_modrm(TCCState* S, int op_reg, int r, Sym *sym, int c)
+static void gen_modrm(int op_reg, int r, Sym *sym, int c)
{
op_reg = op_reg << 3;
if ((r & VT_VALMASK) == VT_CONST) {
/* constant memory reference */
- o(S, 0x05 | op_reg);
- gen_addr32(S, r, sym, c);
+ o(0x05 | op_reg);
+ gen_addr32(r, sym, c);
} else if ((r & VT_VALMASK) == VT_LOCAL) {
/* currently, we use only ebp as base */
if (c == (char)c) {
/* short reference */
- o(S, 0x45 | op_reg);
- g(S, c);
+ o(0x45 | op_reg);
+ g(c);
} else {
- oad(S, 0x85 | op_reg, c);
+ oad(0x85 | op_reg, c);
}
} else {
- g(S, 0x00 | op_reg | (r & VT_VALMASK));
+ g(0x00 | op_reg | (r & VT_VALMASK));
}
}
/* load 'r' from value 'sv' */
-ST_FUNC void load(TCCState* S, int r, SValue *sv)
+ST_FUNC void load(int r, SValue *sv)
{
int v, t, ft, fc, fr;
SValue v1;
#ifdef TCC_TARGET_PE
SValue v2;
- sv = pe_getimport(S, sv, &v2);
+ sv = pe_getimport(sv, &v2);
#endif
fr = sv->r;
@@ -235,68 +238,68 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv)
v1.sym = NULL;
fr = r;
if (!(reg_classes[fr] & RC_INT))
- fr = get_reg(S, RC_INT);
- load(S, fr, &v1);
+ fr = get_reg(RC_INT);
+ load(fr, &v1);
}
if ((ft & VT_BTYPE) == VT_FLOAT) {
- o(S, 0xd9); /* flds */
+ o(0xd9); /* flds */
r = 0;
} else if ((ft & VT_BTYPE) == VT_DOUBLE) {
- o(S, 0xdd); /* fldl */
+ o(0xdd); /* fldl */
r = 0;
} else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
- o(S, 0xdb); /* fldt */
+ o(0xdb); /* fldt */
r = 5;
} else if ((ft & VT_TYPE) == VT_BYTE || (ft & VT_TYPE) == VT_BOOL) {
- o(S, 0xbe0f); /* movsbl */
+ o(0xbe0f); /* movsbl */
} else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
- o(S, 0xb60f); /* movzbl */
+ o(0xb60f); /* movzbl */
} else if ((ft & VT_TYPE) == VT_SHORT) {
- o(S, 0xbf0f); /* movswl */
+ o(0xbf0f); /* movswl */
} else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
- o(S, 0xb70f); /* movzwl */
+ o(0xb70f); /* movzwl */
} else {
- o(S, 0x8b); /* movl */
+ o(0x8b); /* movl */
}
- gen_modrm(S, r, fr, sv->sym, fc);
+ gen_modrm(r, fr, sv->sym, fc);
} else {
if (v == VT_CONST) {
- o(S, 0xb8 + r); /* mov $xx, r */
- gen_addr32(S, fr, sv->sym, fc);
+ o(0xb8 + r); /* mov $xx, r */
+ gen_addr32(fr, sv->sym, fc);
} else if (v == VT_LOCAL) {
if (fc) {
- o(S, 0x8d); /* lea xxx(%ebp), r */
- gen_modrm(S, r, VT_LOCAL, sv->sym, fc);
+ o(0x8d); /* lea xxx(%ebp), r */
+ gen_modrm(r, VT_LOCAL, sv->sym, fc);
} else {
- o(S, 0x89);
- o(S, 0xe8 + r); /* mov %ebp, r */
+ o(0x89);
+ o(0xe8 + r); /* mov %ebp, r */
}
} else if (v == VT_CMP) {
- o(S, 0x0f); /* setxx %br */
- o(S, fc);
- o(S, 0xc0 + r);
- o(S, 0xc0b60f + r * 0x90000); /* movzbl %al, %eax */
+ o(0x0f); /* setxx %br */
+ o(fc);
+ o(0xc0 + r);
+ o(0xc0b60f + r * 0x90000); /* movzbl %al, %eax */
} else if (v == VT_JMP || v == VT_JMPI) {
t = v & 1;
- oad(S, 0xb8 + r, t); /* mov $1, r */
- o(S, 0x05eb); /* jmp after */
- gsym(S, fc);
- oad(S, 0xb8 + r, t ^ 1); /* mov $0, r */
+ oad(0xb8 + r, t); /* mov $1, r */
+ o(0x05eb); /* jmp after */
+ gsym(fc);
+ oad(0xb8 + r, t ^ 1); /* mov $0, r */
} else if (v != r) {
- o(S, 0x89);
- o(S, 0xc0 + r + v * 8); /* mov v, r */
+ o(0x89);
+ o(0xc0 + r + v * 8); /* mov v, r */
}
}
}
/* store register 'r' in lvalue 'v' */
-ST_FUNC void store(TCCState* S, int r, SValue *v)
+ST_FUNC void store(int r, SValue *v)
{
int fr, bt, ft, fc;
#ifdef TCC_TARGET_PE
SValue v2;
- v = pe_getimport(S, v, &v2);
+ v = pe_getimport(v, &v2);
#endif
ft = v->type.t;
@@ -306,66 +309,66 @@ ST_FUNC void store(TCCState* S, int r, SValue *v)
bt = ft & VT_BTYPE;
/* XXX: incorrect if float reg to reg */
if (bt == VT_FLOAT) {
- o(S, 0xd9); /* fsts */
+ o(0xd9); /* fsts */
r = 2;
} else if (bt == VT_DOUBLE) {
- o(S, 0xdd); /* fstpl */
+ o(0xdd); /* fstpl */
r = 2;
} else if (bt == VT_LDOUBLE) {
- o(S, 0xc0d9); /* fld %st(0) */
- o(S, 0xdb); /* fstpt */
+ o(0xc0d9); /* fld %st(0) */
+ o(0xdb); /* fstpt */
r = 7;
} else {
if (bt == VT_SHORT)
- o(S, 0x66);
+ o(0x66);
if (bt == VT_BYTE || bt == VT_BOOL)
- o(S, 0x88);
+ o(0x88);
else
- o(S, 0x89);
+ o(0x89);
}
if (fr == VT_CONST ||
fr == VT_LOCAL ||
(v->r & VT_LVAL)) {
- gen_modrm(S, r, v->r, v->sym, fc);
+ gen_modrm(r, v->r, v->sym, fc);
} else if (fr != r) {
- o(S, 0xc0 + fr + r * 8); /* mov r, fr */
+ o(0xc0 + fr + r * 8); /* mov r, fr */
}
}
-static void gadd_sp(TCCState* S, int val)
+static void gadd_sp(int val)
{
if (val == (char)val) {
- o(S, 0xc483);
- g(S, val);
+ o(0xc483);
+ g(val);
} else {
- oad(S, 0xc481, val); /* add $xxx, %esp */
+ oad(0xc481, val); /* add $xxx, %esp */
}
}
#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_PE
-static void gen_static_call(TCCState* S, int v)
+static void gen_static_call(int v)
{
Sym *sym;
- sym = external_helper_sym(S, v);
- oad(S, 0xe8, -4);
- greloc(S, cur_text_section, sym, S->tccgen_ind-4, R_386_PC32);
+ sym = external_helper_sym(v);
+ oad(0xe8, -4);
+ greloc(cur_text_section, sym, ind-4, R_386_PC32);
}
#endif
/* 'is_jmp' is '1' if it is a jump */
-static void gcall_or_jmp(TCCState* S, int is_jmp)
+static void gcall_or_jmp(int is_jmp)
{
int r;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (S->tccgen_vtop->r & VT_SYM)) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST && (vtop->r & VT_SYM)) {
/* constant and relocation case */
- greloc(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 1, R_386_PC32);
- oad(S, 0xe8 + is_jmp, S->tccgen_vtop->c.i - 4); /* call/jmp im */
+ greloc(cur_text_section, vtop->sym, ind + 1, R_386_PC32);
+ oad(0xe8 + is_jmp, vtop->c.i - 4); /* call/jmp im */
} else {
/* otherwise, indirect call */
- r = gv(S, RC_INT);
- o(S, 0xff); /* call/jmp *r */
- o(S, 0xd0 + r + (is_jmp << 4));
+ r = gv(RC_INT);
+ o(0xff); /* call/jmp *r */
+ o(0xd0 + r + (is_jmp << 4));
}
}
@@ -402,75 +405,75 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int
/* Generate function call. The function address is pushed first, then
all the parameters in call order. This functions pops all the
parameters and the function address. */
-ST_FUNC void gfunc_call(TCCState* S, int nb_args)
+ST_FUNC void gfunc_call(int nb_args)
{
int size, align, r, args_size, i, func_call;
Sym *func_sym;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
args_size = 0;
for(i = 0;i < nb_args; i++) {
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_STRUCT) {
- size = type_size(&S->tccgen_vtop->type, &align);
+ if ((vtop->type.t & VT_BTYPE) == VT_STRUCT) {
+ size = type_size(&vtop->type, &align);
/* align to stack align size */
size = (size + 3) & ~3;
/* allocate the necessary size on stack */
#ifdef TCC_TARGET_PE
if (size >= 4096) {
- r = get_reg(S, RC_EAX);
- oad(S, 0x68, size); // push size
+ r = get_reg(RC_EAX);
+ oad(0x68, size); // push size
/* cannot call normal 'alloca' with bound checking */
- gen_static_call(S, tok_alloc_const(S, "__alloca"));
- gadd_sp(S, 4);
+ gen_static_call(tok_alloc_const("__alloca"));
+ gadd_sp(4);
} else
#endif
{
- oad(S, 0xec81, size); /* sub $xxx, %esp */
+ oad(0xec81, size); /* sub $xxx, %esp */
/* generate structure store */
- r = get_reg(S, RC_INT);
- o(S, 0xe089 + (r << 8)); /* mov %esp, r */
+ r = get_reg(RC_INT);
+ o(0xe089 + (r << 8)); /* mov %esp, r */
}
- vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
- vswap(S);
- vstore(S);
+ vset(&vtop->type, r | VT_LVAL, 0);
+ vswap();
+ vstore();
args_size += size;
- } else if (is_float(S->tccgen_vtop->type.t)) {
- gv(S, RC_FLOAT); /* only one float register */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT)
+ } else if (is_float(vtop->type.t)) {
+ gv(RC_FLOAT); /* only one float register */
+ if ((vtop->type.t & VT_BTYPE) == VT_FLOAT)
size = 4;
- else if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE)
+ else if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
size = 8;
else
size = 12;
- oad(S, 0xec81, size); /* sub $xxx, %esp */
+ oad(0xec81, size); /* sub $xxx, %esp */
if (size == 12)
- o(S, 0x7cdb);
+ o(0x7cdb);
else
- o(S, 0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */
- g(S, 0x24);
- g(S, 0x00);
+ o(0x5cd9 + size - 4); /* fstp[s|l] 0(%esp) */
+ g(0x24);
+ g(0x00);
args_size += size;
} else {
/* simple type (currently always same size) */
/* XXX: implicit cast ? */
- r = gv(S, RC_INT);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
+ r = gv(RC_INT);
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
size = 8;
- o(S, 0x50 + S->tccgen_vtop->r2); /* push r */
+ o(0x50 + vtop->r2); /* push r */
} else {
size = 4;
}
- o(S, 0x50 + r); /* push r */
+ o(0x50 + r); /* push r */
args_size += size;
}
- S->tccgen_vtop--;
+ vtop--;
}
- save_regs(S, 0); /* save used temporary registers */
- func_sym = S->tccgen_vtop->type.ref;
+ save_regs(0); /* save used temporary registers */
+ func_sym = vtop->type.ref;
func_call = func_sym->f.func_call;
/* fast call case */
if ((func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) ||
@@ -487,21 +490,21 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args)
for(i = 0;i < fastcall_nb_regs; i++) {
if (args_size <= 0)
break;
- o(S, 0x58 + fastcall_regs_ptr[i]); /* pop r */
+ o(0x58 + fastcall_regs_ptr[i]); /* pop r */
/* XXX: incorrect for struct/floats */
args_size -= 4;
}
}
#if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD
- else if ((S->tccgen_vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT)
+ else if ((vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT)
args_size -= 4;
#endif
- gcall_or_jmp(S, 0);
+ gcall_or_jmp(0);
if (args_size && func_call != FUNC_STDCALL && func_call != FUNC_FASTCALLW)
- gadd_sp(S, args_size);
- S->tccgen_vtop--;
+ gadd_sp(args_size);
+ vtop--;
}
#ifdef TCC_TARGET_PE
@@ -511,7 +514,7 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args)
#endif
/* generate function prolog of type 't' */
-ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
+ST_FUNC void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
int addr, align, size, func_call, fastcall_nb_regs;
@@ -523,8 +526,8 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
sym = func_type->ref;
func_call = sym->f.func_call;
addr = 8;
- S->tccgen_loc = 0;
- S->tccgen_func_vc = 0;
+ loc = 0;
+ func_vc = 0;
if (func_call >= FUNC_FASTCALL1 && func_call <= FUNC_FASTCALL3) {
fastcall_nb_regs = func_call - FUNC_FASTCALL1 + 1;
@@ -538,19 +541,19 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
}
param_index = 0;
- S->tccgen_ind += FUNC_PROLOG_SIZE;
- func_sub_sp_offset = S->tccgen_ind;
+ ind += FUNC_PROLOG_SIZE;
+ func_sub_sp_offset = ind;
/* if the function returns a structure, then add an
implicit pointer parameter */
#if defined(TCC_TARGET_PE) || TARGETOS_FreeBSD || TARGETOS_OpenBSD
- size = type_size(&S->tccgen_func_vt,&align);
- if (((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT)
+ size = type_size(&func_vt,&align);
+ if (((func_vt.t & VT_BTYPE) == VT_STRUCT)
&& (size > 8 || (size & (size - 1)))) {
#else
- if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_STRUCT) {
+ if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
#endif
/* XXX: fastcall case ? */
- S->tccgen_func_vc = addr;
+ func_vc = addr;
addr += 4;
param_index++;
}
@@ -567,15 +570,15 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
#endif
if (param_index < fastcall_nb_regs) {
/* save FASTCALL register */
- S->tccgen_loc -= 4;
- o(S, 0x89); /* movl */
- gen_modrm(S, fastcall_regs_ptr[param_index], VT_LOCAL, NULL, S->tccgen_loc);
- param_addr = S->tccgen_loc;
+ loc -= 4;
+ o(0x89); /* movl */
+ gen_modrm(fastcall_regs_ptr[param_index], VT_LOCAL, NULL, loc);
+ param_addr = loc;
} else {
param_addr = addr;
addr += size;
}
- sym_push(S, sym->v & ~SYM_FIELD, type,
+ sym_push(sym->v & ~SYM_FIELD, type,
VT_LOCAL | VT_LVAL, param_addr);
param_index++;
}
@@ -584,94 +587,94 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
if (func_call == FUNC_STDCALL || func_call == FUNC_FASTCALLW)
func_ret_sub = addr - 8;
#if !defined(TCC_TARGET_PE) && !TARGETOS_FreeBSD || TARGETOS_OpenBSD
- else if (S->tccgen_func_vc)
+ else if (func_vc)
func_ret_sub = 4;
#endif
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
/* generate function epilog */
-ST_FUNC void gfunc_epilog(TCCState* S)
+ST_FUNC void gfunc_epilog(void)
{
addr_t v, saved_ind;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
/* align local size to word & save local variables */
- v = (-S->tccgen_loc + 3) & -4;
+ v = (-loc + 3) & -4;
#if USE_EBX
- o(S, 0x8b);
- gen_modrm(S, TREG_EBX, VT_LOCAL, NULL, -(v+4));
+ o(0x8b);
+ gen_modrm(TREG_EBX, VT_LOCAL, NULL, -(v+4));
#endif
- o(S, 0xc9); /* leave */
+ o(0xc9); /* leave */
if (func_ret_sub == 0) {
- o(S, 0xc3); /* ret */
+ o(0xc3); /* ret */
} else {
- o(S, 0xc2); /* ret n */
- g(S, func_ret_sub);
- g(S, func_ret_sub >> 8);
+ o(0xc2); /* ret n */
+ g(func_ret_sub);
+ g(func_ret_sub >> 8);
}
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
+ saved_ind = ind;
+ ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
#ifdef TCC_TARGET_PE
if (v >= 4096) {
- oad(S, 0xb8, v); /* mov stacksize, %eax */
- gen_static_call(S, TOK___chkstk); /* call __chkstk, (does the stackframe too) */
+ oad(0xb8, v); /* mov stacksize, %eax */
+ gen_static_call(TOK___chkstk); /* call __chkstk, (does the stackframe too) */
} else
#endif
{
- o(S, 0xe58955); /* push %ebp, mov %esp, %ebp */
- o(S, 0xec81); /* sub esp, stacksize */
- gen_le32(S, v);
+ o(0xe58955); /* push %ebp, mov %esp, %ebp */
+ o(0xec81); /* sub esp, stacksize */
+ gen_le32(v);
#ifdef TCC_TARGET_PE
- o(S, 0x90); /* adjust to FUNC_PROLOG_SIZE */
+ o(0x90); /* adjust to FUNC_PROLOG_SIZE */
#endif
}
- o(S, 0x53 * USE_EBX); /* push ebx */
- S->tccgen_ind = saved_ind;
+ o(0x53 * USE_EBX); /* push ebx */
+ ind = saved_ind;
}
/* generate a jump to a label */
-ST_FUNC int gjmp(TCCState* S, int t)
+ST_FUNC int gjmp(int t)
{
- return gjmp2(S, 0xe9, t);
+ return gjmp2(0xe9, t);
}
/* generate a jump to a fixed address */
-ST_FUNC void gjmp_addr(TCCState* S, int a)
+ST_FUNC void gjmp_addr(int a)
{
int r;
- r = a - S->tccgen_ind - 2;
+ r = a - ind - 2;
if (r == (char)r) {
- g(S, 0xeb);
- g(S, r);
+ g(0xeb);
+ g(r);
} else {
- oad(S, 0xe9, a - S->tccgen_ind - 5);
+ oad(0xe9, a - ind - 5);
}
}
#if 0
/* generate a jump to a fixed address */
-ST_FUNC void gjmp_cond_addr(TCCState* S, int a, int op)
+ST_FUNC void gjmp_cond_addr(int a, int op)
{
- int r = a - S->tccgen_ind - 2;
+ int r = a - ind - 2;
if (r == (char)r)
- g(S, op - 32), g(r);
+ g(op - 32), g(r);
else
- g(S, 0x0f), gjmp2(S, op - 16, r - 4);
+ g(0x0f), gjmp2(op - 16, r - 4);
}
#endif
-ST_FUNC int gjmp_append(TCCState* S, int n, int t)
+ST_FUNC int gjmp_append(int n, int t)
{
void *p;
/* insert vtop->c jump list in t */
@@ -685,14 +688,14 @@ ST_FUNC int gjmp_append(TCCState* S, int n, int t)
return t;
}
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
- g(S, 0x0f);
- t = gjmp2(S, op - 16, t);
+ g(0x0f);
+ t = gjmp2(op - 16, t);
return t;
}
-ST_FUNC void gen_opi(TCCState* S, int op)
+ST_FUNC void gen_opi(int op)
{
int r, fr, opc, c;
@@ -701,36 +704,36 @@ ST_FUNC void gen_opi(TCCState* S, int op)
case TOK_ADDC1: /* add with carry generation */
opc = 0;
gen_op8:
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
/* constant case */
- vswap(S);
- r = gv(S, RC_INT);
- vswap(S);
- c = S->tccgen_vtop->c.i;
+ vswap();
+ r = gv(RC_INT);
+ vswap();
+ c = vtop->c.i;
if (c == (char)c) {
/* generate inc and dec for smaller code */
if ((c == 1 || c == -1) && (op == '+' || op == '-')) {
opc = (c == 1) ^ (op == '+');
- o(S, 0x40 | (opc << 3) | r); // inc,dec
+ o (0x40 | (opc << 3) | r); // inc,dec
} else {
- o(S, 0x83);
- o(S, 0xc0 | (opc << 3) | r);
- g(S, c);
+ o(0x83);
+ o(0xc0 | (opc << 3) | r);
+ g(c);
}
} else {
- o(S, 0x81);
- oad(S, 0xc0 | (opc << 3) | r, c);
+ o(0x81);
+ oad(0xc0 | (opc << 3) | r, c);
}
} else {
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- o(S, (opc << 3) | 0x01);
- o(S, 0xc0 + r + fr * 8);
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ o((opc << 3) | 0x01);
+ o(0xc0 + r + fr * 8);
}
- S->tccgen_vtop--;
+ vtop--;
if (op >= TOK_ULT && op <= TOK_GT)
- vset_VT_CMP(S, op);
+ vset_VT_CMP(op);
break;
case '-':
case TOK_SUBC1: /* sub with carry generation */
@@ -752,12 +755,12 @@ ST_FUNC void gen_opi(TCCState* S, int op)
opc = 1;
goto gen_op8;
case '*':
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- o(S, 0xaf0f); /* imul fr, r */
- o(S, 0xc0 + fr + r * 8);
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ o(0xaf0f); /* imul fr, r */
+ o(0xc0 + fr + r * 8);
break;
case TOK_SHL:
opc = 4;
@@ -769,23 +772,23 @@ ST_FUNC void gen_opi(TCCState* S, int op)
opc = 7;
gen_shift:
opc = 0xc0 | (opc << 3);
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
/* constant case */
- vswap(S);
- r = gv(S, RC_INT);
- vswap(S);
- c = S->tccgen_vtop->c.i & 0x1f;
- o(S, 0xc1); /* shl/shr/sar $xxx, r */
- o(S, opc | r);
- g(S, c);
+ vswap();
+ r = gv(RC_INT);
+ vswap();
+ c = vtop->c.i & 0x1f;
+ o(0xc1); /* shl/shr/sar $xxx, r */
+ o(opc | r);
+ g(c);
} else {
/* we generate the shift in ecx */
- gv2(S, RC_INT, RC_ECX);
- r = S->tccgen_vtop[-1].r;
- o(S, 0xd3); /* shl/shr/sar %cl, r */
- o(S, opc | r);
+ gv2(RC_INT, RC_ECX);
+ r = vtop[-1].r;
+ o(0xd3); /* shl/shr/sar %cl, r */
+ o(opc | r);
}
- S->tccgen_vtop--;
+ vtop--;
break;
case '/':
case TOK_UDIV:
@@ -795,32 +798,32 @@ ST_FUNC void gen_opi(TCCState* S, int op)
case TOK_UMULL:
/* first operand must be in eax */
/* XXX: need better constraint for second operand */
- gv2(S, RC_EAX, RC_ECX);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- save_reg(S, TREG_EDX);
+ gv2(RC_EAX, RC_ECX);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ save_reg(TREG_EDX);
/* save EAX too if used otherwise */
- save_reg_upstack(S, TREG_EAX, 1);
+ save_reg_upstack(TREG_EAX, 1);
if (op == TOK_UMULL) {
- o(S, 0xf7); /* mul fr */
- o(S, 0xe0 + fr);
- S->tccgen_vtop->r2 = TREG_EDX;
+ o(0xf7); /* mul fr */
+ o(0xe0 + fr);
+ vtop->r2 = TREG_EDX;
r = TREG_EAX;
} else {
if (op == TOK_UDIV || op == TOK_UMOD) {
- o(S, 0xf7d231); /* xor %edx, %edx, div fr, %eax */
- o(S, 0xf0 + fr);
+ o(0xf7d231); /* xor %edx, %edx, div fr, %eax */
+ o(0xf0 + fr);
} else {
- o(S, 0xf799); /* cltd, idiv fr, %eax */
- o(S, 0xf8 + fr);
+ o(0xf799); /* cltd, idiv fr, %eax */
+ o(0xf8 + fr);
}
if (op == '%' || op == TOK_UMOD)
r = TREG_EDX;
else
r = TREG_EAX;
}
- S->tccgen_vtop->r = r;
+ vtop->r = r;
break;
default:
opc = 7;
@@ -831,74 +834,74 @@ ST_FUNC void gen_opi(TCCState* S, int op)
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranteed to have the same floating point type */
/* XXX: need to use ST1 too */
-ST_FUNC void gen_opf(TCCState* S, int op)
+ST_FUNC void gen_opf(int op)
{
int a, ft, fc, swapped, r;
if (op == TOK_NEG) { /* unary minus */
- gv(S, RC_FLOAT);
- o(S, 0xe0d9); /* fchs */
+ gv(RC_FLOAT);
+ o(0xe0d9); /* fchs */
return;
}
/* convert constants to memory references */
- if ((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
- vswap(S);
- gv(S, RC_FLOAT);
- vswap(S);
+ if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ vswap();
+ gv(RC_FLOAT);
+ vswap();
}
- if ((S->tccgen_vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
- gv(S, RC_FLOAT);
+ if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
+ gv(RC_FLOAT);
/* must put at least one value in the floating point register */
- if ((S->tccgen_vtop[-1].r & VT_LVAL) &&
- (S->tccgen_vtop[0].r & VT_LVAL)) {
- vswap(S);
- gv(S, RC_FLOAT);
- vswap(S);
+ if ((vtop[-1].r & VT_LVAL) &&
+ (vtop[0].r & VT_LVAL)) {
+ vswap();
+ gv(RC_FLOAT);
+ vswap();
}
swapped = 0;
/* swap the stack if needed so that t1 is the register and t2 is
the memory reference */
- if (S->tccgen_vtop[-1].r & VT_LVAL) {
- vswap(S);
+ if (vtop[-1].r & VT_LVAL) {
+ vswap();
swapped = 1;
}
if (op >= TOK_ULT && op <= TOK_GT) {
/* load on stack second operand */
- load(S, TREG_ST0, S->tccgen_vtop);
- save_reg(S, TREG_EAX); /* eax is used by FP comparison code */
+ load(TREG_ST0, vtop);
+ save_reg(TREG_EAX); /* eax is used by FP comparison code */
if (op == TOK_GE || op == TOK_GT)
swapped = !swapped;
else if (op == TOK_EQ || op == TOK_NE)
swapped = 0;
if (swapped)
- o(S, 0xc9d9); /* fxch %st(1) */
+ o(0xc9d9); /* fxch %st(1) */
if (op == TOK_EQ || op == TOK_NE)
- o(S, 0xe9da); /* fucompp */
+ o(0xe9da); /* fucompp */
else
- o(S, 0xd9de); /* fcompp */
- o(S, 0xe0df); /* fnstsw %ax */
+ o(0xd9de); /* fcompp */
+ o(0xe0df); /* fnstsw %ax */
if (op == TOK_EQ) {
- o(S, 0x45e480); /* and $0x45, %ah */
- o(S, 0x40fC80); /* cmp $0x40, %ah */
+ o(0x45e480); /* and $0x45, %ah */
+ o(0x40fC80); /* cmp $0x40, %ah */
} else if (op == TOK_NE) {
- o(S, 0x45e480); /* and $0x45, %ah */
- o(S, 0x40f480); /* xor $0x40, %ah */
+ o(0x45e480); /* and $0x45, %ah */
+ o(0x40f480); /* xor $0x40, %ah */
op = TOK_NE;
} else if (op == TOK_GE || op == TOK_LE) {
- o(S, 0x05c4f6); /* test $0x05, %ah */
+ o(0x05c4f6); /* test $0x05, %ah */
op = TOK_EQ;
} else {
- o(S, 0x45c4f6); /* test $0x45, %ah */
+ o(0x45c4f6); /* test $0x45, %ah */
op = TOK_EQ;
}
- S->tccgen_vtop--;
- vset_VT_CMP(S, op);
+ vtop--;
+ vset_VT_CMP(op);
} else {
/* no memory reference possible for long double operations */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
- load(S, TREG_ST0, S->tccgen_vtop);
+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
+ load(TREG_ST0, vtop);
swapped = !swapped;
}
@@ -921,213 +924,213 @@ ST_FUNC void gen_opf(TCCState* S, int op)
a++;
break;
}
- ft = S->tccgen_vtop->type.t;
- fc = S->tccgen_vtop->c.i;
+ ft = vtop->type.t;
+ fc = vtop->c.i;
if ((ft & VT_BTYPE) == VT_LDOUBLE) {
- o(S, 0xde); /* fxxxp %st, %st(1) */
- o(S, 0xc1 + (a << 3));
+ o(0xde); /* fxxxp %st, %st(1) */
+ o(0xc1 + (a << 3));
} else {
/* if saved lvalue, then we must reload it */
- r = S->tccgen_vtop->r;
+ r = vtop->r;
if ((r & VT_VALMASK) == VT_LLOCAL) {
SValue v1;
- r = get_reg(S, RC_INT);
+ r = get_reg(RC_INT);
v1.type.t = VT_INT;
v1.r = VT_LOCAL | VT_LVAL;
v1.c.i = fc;
v1.sym = NULL;
- load(S, r, &v1);
+ load(r, &v1);
fc = 0;
}
if ((ft & VT_BTYPE) == VT_DOUBLE)
- o(S, 0xdc);
+ o(0xdc);
else
- o(S, 0xd8);
- gen_modrm(S, a, r, S->tccgen_vtop->sym, fc);
+ o(0xd8);
+ gen_modrm(a, r, vtop->sym, fc);
}
- S->tccgen_vtop--;
+ vtop--;
}
}
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
-ST_FUNC void gen_cvt_itof(TCCState* S, int t)
+ST_FUNC void gen_cvt_itof(int t)
{
- save_reg(S, TREG_ST0);
- gv(S, RC_INT);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
+ save_reg(TREG_ST0);
+ gv(RC_INT);
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
/* signed long long to float/double/long double (unsigned case
is handled generically) */
- o(S, 0x50 + S->tccgen_vtop->r2); /* push r2 */
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x242cdf); /* fildll (%esp) */
- o(S, 0x08c483); /* add $8, %esp */
- S->tccgen_vtop->r2 = VT_CONST;
- } else if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
+ o(0x50 + vtop->r2); /* push r2 */
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x242cdf); /* fildll (%esp) */
+ o(0x08c483); /* add $8, %esp */
+ vtop->r2 = VT_CONST;
+ } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
(VT_INT | VT_UNSIGNED)) {
/* unsigned int to float/double/long double */
- o(S, 0x6a); /* push $0 */
- g(S, 0x00);
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x242cdf); /* fildll (%esp) */
- o(S, 0x08c483); /* add $8, %esp */
+ o(0x6a); /* push $0 */
+ g(0x00);
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x242cdf); /* fildll (%esp) */
+ o(0x08c483); /* add $8, %esp */
} else {
/* int to float/double/long double */
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x2404db); /* fildl (%esp) */
- o(S, 0x04c483); /* add $4, %esp */
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x2404db); /* fildl (%esp) */
+ o(0x04c483); /* add $4, %esp */
}
- S->tccgen_vtop->r2 = VT_CONST;
- S->tccgen_vtop->r = TREG_ST0;
+ vtop->r2 = VT_CONST;
+ vtop->r = TREG_ST0;
}
/* convert fp to int 't' type */
-ST_FUNC void gen_cvt_ftoi(TCCState* S, int t)
+ST_FUNC void gen_cvt_ftoi(int t)
{
- int bt = S->tccgen_vtop->type.t & VT_BTYPE;
+ int bt = vtop->type.t & VT_BTYPE;
if (bt == VT_FLOAT)
- vpush_helper_func(S, TOK___fixsfdi);
+ vpush_helper_func(TOK___fixsfdi);
else if (bt == VT_LDOUBLE)
- vpush_helper_func(S, TOK___fixxfdi);
+ vpush_helper_func(TOK___fixxfdi);
else
- vpush_helper_func(S, TOK___fixdfdi);
- vswap(S);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->r = REG_IRET;
+ vpush_helper_func(TOK___fixdfdi);
+ vswap();
+ gfunc_call(1);
+ vpushi(0);
+ vtop->r = REG_IRET;
if ((t & VT_BTYPE) == VT_LLONG)
- S->tccgen_vtop->r2 = REG_IRE2;
+ vtop->r2 = REG_IRE2;
}
/* convert from one floating point type to another */
-ST_FUNC void gen_cvt_ftof(TCCState* S, int t)
+ST_FUNC void gen_cvt_ftof(int t)
{
/* all we have to do on i386 is to put the float in a register */
- gv(S, RC_FLOAT);
+ gv(RC_FLOAT);
}
/* char/short to int conversion */
-ST_FUNC void gen_cvt_csti(TCCState* S, int t)
+ST_FUNC void gen_cvt_csti(int t)
{
int r, sz, xl;
- r = gv(S, RC_INT);
+ r = gv(RC_INT);
sz = !(t & VT_UNSIGNED);
xl = (t & VT_BTYPE) == VT_SHORT;
- o(S, 0xc0b60f /* mov[sz] %a[xl], %eax */
+ o(0xc0b60f /* mov[sz] %a[xl], %eax */
| (sz << 3 | xl) << 8
| (r << 3 | r) << 16
);
}
/* increment tcov counter */
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
+ST_FUNC void gen_increment_tcov (SValue *sv)
{
- o(S, 0x0583); /* addl $1, xxx */
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_386_32);
- gen_le32(S, 0);
- o(S, 1);
- o(S, 0x1583); /* addcl $0, xxx */
- greloc(S, cur_text_section, sv->sym, S->tccgen_ind, R_386_32);
- gen_le32(S, 4);
- g(S, 0);
+ o(0x0583); /* addl $1, xxx */
+ greloc(cur_text_section, sv->sym, ind, R_386_32);
+ gen_le32(0);
+ o(1);
+ o(0x1583); /* addcl $0, xxx */
+ greloc(cur_text_section, sv->sym, ind, R_386_32);
+ gen_le32(4);
+ g(0);
}
/* computed goto support */
-ST_FUNC void ggoto(TCCState* S)
+ST_FUNC void ggoto(void)
{
- gcall_or_jmp(S, 1);
- S->tccgen_vtop--;
+ gcall_or_jmp(1);
+ vtop--;
}
/* bound check support functions */
#ifdef CONFIG_TCC_BCHECK
-static void gen_bounds_prolog(TCCState* S)
+static void gen_bounds_prolog(void)
{
/* leave some room for bound checking code */
- S->func_bound_offset = lbounds_section->data_offset;
- S->func_bound_ind = S->tccgen_ind;
- S->func_bound_add_epilog = 0;
- oad(S, 0xb8, 0); /* lbound section pointer */
- oad(S, 0xb8, 0); /* call to function */
+ func_bound_offset = lbounds_section->data_offset;
+ func_bound_ind = ind;
+ func_bound_add_epilog = 0;
+ oad(0xb8, 0); /* lbound section pointer */
+ oad(0xb8, 0); /* call to function */
}
-static void gen_bounds_epilog(TCCState* S)
+static void gen_bounds_epilog(void)
{
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
- int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
- if (!offset_modified && !S->func_bound_add_epilog)
+ if (!offset_modified && !func_bound_add_epilog)
return;
/* add end of table info */
- bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
- sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
- S->func_bound_offset, lbounds_section->data_offset);
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
+ func_bound_offset, lbounds_section->data_offset);
/* generate bound local allocation */
if (offset_modified) {
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->func_bound_ind;
- greloc(S, cur_text_section, sym_data, S->tccgen_ind + 1, R_386_32);
- S->tccgen_ind = S->tccgen_ind + 5;
- gen_static_call(S, TOK___bound_local_new);
- S->tccgen_ind = saved_ind;
+ saved_ind = ind;
+ ind = func_bound_ind;
+ greloc(cur_text_section, sym_data, ind + 1, R_386_32);
+ ind = ind + 5;
+ gen_static_call(TOK___bound_local_new);
+ ind = saved_ind;
}
/* generate bound check local freeing */
- o(S, 0x5250); /* save returned value, if any */
- greloc(S, cur_text_section, sym_data, S->tccgen_ind + 1, R_386_32);
- oad(S, 0xb8, 0); /* mov %eax, xxx */
- gen_static_call(S, TOK___bound_local_delete);
- o(S, 0x585a); /* restore returned value, if any */
+ o(0x5250); /* save returned value, if any */
+ greloc(cur_text_section, sym_data, ind + 1, R_386_32);
+ oad(0xb8, 0); /* mov %eax, xxx */
+ gen_static_call(TOK___bound_local_delete);
+ o(0x585a); /* restore returned value, if any */
}
#endif
/* Save the stack pointer onto the stack */
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
+ST_FUNC void gen_vla_sp_save(int addr) {
/* mov %esp,addr(%ebp)*/
- o(S, 0x89);
- gen_modrm(S, TREG_ESP, VT_LOCAL, NULL, addr);
+ o(0x89);
+ gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr);
}
/* Restore the SP from a location on the stack */
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
- o(S, 0x8b);
- gen_modrm(S, TREG_ESP, VT_LOCAL, NULL, addr);
+ST_FUNC void gen_vla_sp_restore(int addr) {
+ o(0x8b);
+ gen_modrm(TREG_ESP, VT_LOCAL, NULL, addr);
}
/* Subtract from the stack pointer, and push the resulting value onto the stack */
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
+ST_FUNC void gen_vla_alloc(CType *type, int align) {
int use_call = 0;
#if defined(CONFIG_TCC_BCHECK)
- use_call = S->do_bounds_check;
+ use_call = tcc_state->do_bounds_check;
#endif
#ifdef TCC_TARGET_PE /* alloca does more than just adjust %rsp on Windows */
use_call = 1;
#endif
if (use_call)
{
- vpush_helper_func(S, TOK_alloca);
- vswap(S); /* Move alloca ref past allocation size */
- gfunc_call(S, 1);
+ vpush_helper_func(TOK_alloca);
+ vswap(); /* Move alloca ref past allocation size */
+ gfunc_call(1);
}
else {
int r;
- r = gv(S, RC_INT); /* allocation size */
+ r = gv(RC_INT); /* allocation size */
/* sub r,%rsp */
- o(S, 0x2b);
- o(S, 0xe0 | r);
+ o(0x2b);
+ o(0xe0 | r);
/* We align to 16 bytes rather than align */
/* and ~15, %esp */
- o(S, 0xf0e483);
- vpop(S);
+ o(0xf0e483);
+ vpop();
}
}
diff --git a/i386-link.c b/i386-link.c
index 5df3ea6..a7969f0 100644
--- a/i386-link.c
+++ b/i386-link.c
@@ -91,15 +91,15 @@ int gotplt_entry_type (int reloc_type)
return -1;
}
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- Section *plt = S->plt;
+ Section *plt = s1->plt;
uint8_t *p;
int modrm;
unsigned plt_offset, relofs;
/* on i386 if we build a DLL, we add a %ebx offset */
- if (S->output_type == TCC_OUTPUT_DLL)
+ if (s1->output_type == TCC_OUTPUT_DLL)
modrm = 0xa3;
else
modrm = 0x25;
@@ -108,7 +108,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
(GOT + PTR_SIZE) and jumps to ld.so resolution routine
(GOT + 2 * PTR_SIZE) */
if (plt->data_offset == 0) {
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
p[0] = 0xff; /* pushl got + PTR_SIZE */
p[1] = modrm + 0x10;
write32le(p + 2, PTR_SIZE);
@@ -121,10 +121,10 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* The PLT slot refers to the relocation entry it needs via offset.
The reloc entry is created below, so its offset is the current
data_offset */
- relofs = S->plt->reloc ? S->plt->reloc->data_offset : 0;
+ relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
p[0] = 0xff; /* jmp *(got + x) */
p[1] = modrm;
write32le(p + 2, got_offset);
@@ -137,31 +137,31 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
- if (S->output_type != TCC_OUTPUT_DLL && p < p_end) {
- add32le(p + 2, S->got->sh_addr);
- add32le(p + 8, S->got->sh_addr);
+ if (s1->output_type != TCC_OUTPUT_DLL && p < p_end) {
+ add32le(p + 2, s1->got->sh_addr);
+ add32le(p + 8, s1->got->sh_addr);
p += 16;
while (p < p_end) {
- add32le(p + 2, S->got->sh_addr);
+ add32le(p + 2, s1->got->sh_addr);
p += 16;
}
}
- if (S->plt->reloc) {
+ if (s1->plt->reloc) {
ElfW_Rel *rel;
- int x = S->plt->sh_addr + 16 + 6;
- p = S->got->data;
- for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
+ int x = s1->plt->sh_addr + 16 + 6;
+ p = s1->got->data;
+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
write32le(p + rel->r_offset, x);
x += 16;
}
@@ -169,7 +169,7 @@ ST_FUNC void relocate_plt(TCCState *S)
}
#endif
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index, esym_index;
@@ -177,8 +177,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
switch (type) {
case R_386_32:
- if (S->output_type == TCC_OUTPUT_DLL) {
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
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
add32le(ptr, val);
return;
case R_386_PC32:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
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
write32le(ptr, val);
return;
case R_386_GOTPC:
- add32le(ptr, S->got->sh_addr - addr);
+ add32le(ptr, s1->got->sh_addr - addr);
return;
case R_386_GOTOFF:
- add32le(ptr, val - S->got->sh_addr);
+ add32le(ptr, val - s1->got->sh_addr);
return;
case R_386_GOT32:
case R_386_GOT32X:
/* we load the got offset */
- add32le(ptr, get_sym_attr(S, sym_index, 0)->got_offset);
+ add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
return;
case R_386_16:
- if (S->output_format != TCC_OUTPUT_FORMAT_BINARY) {
+ if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY) {
output_file:
- tcc_error(S, "can only produce 16-bit binary files");
+ tcc_error("can only produce 16-bit binary files");
}
write16le(ptr, read16le(ptr) + val);
return;
case R_386_PC16:
- if (S->output_format != TCC_OUTPUT_FORMAT_BINARY)
+ if (s1->output_format != TCC_OUTPUT_FORMAT_BINARY)
goto output_file;
write16le(ptr, read16le(ptr) + val - addr);
return;
case R_386_RELATIVE:
#ifdef TCC_TARGET_PE
- add32le(ptr, val - S->pe_imagebase);
+ add32le(ptr, val - s1->pe_imagebase);
#endif
/* do nothing */
return;
@@ -267,12 +267,12 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
memcpy(ptr-3, replace, sizeof(replace));
rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
- sec = S->sections[sym->st_shndx];
+ sec = s1->sections[sym->st_shndx];
x = sym->st_value - sec->sh_addr - sec->data_offset;
add32le(ptr + 5, -x);
}
else
- tcc_error(S, "unexpected R_386_TLS_GD pattern");
+ tcc_error("unexpected R_386_TLS_GD pattern");
}
return;
case R_386_TLS_LDM:
@@ -295,7 +295,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
rel[1].r_info = ELFW(R_INFO)(0, R_386_NONE);
}
else
- tcc_error(S, "unexpected R_386_TLS_LDM pattern");
+ tcc_error("unexpected R_386_TLS_LDM pattern");
}
return;
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
int32_t x;
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
- sec = S->sections[sym->st_shndx];
+ sec = s1->sections[sym->st_shndx];
x = val - sec->sh_addr - sec->data_offset;
add32le(ptr, x);
}
diff --git a/libtcc.c b/libtcc.c
index 5374525..b6b5f82 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -65,6 +65,7 @@
/* global variables */
/* XXX: get rid of this ASAP (or maybe not) */
+ST_DATA struct TCCState *tcc_state;
TCC_SEM(static tcc_compile_sem);
#ifdef MEM_DEBUG
@@ -110,11 +111,11 @@ static inline char *config_tccdir_w32(char *path)
#endif
#ifdef TCC_TARGET_PE
-static void tcc_add_systemdir(TCCState *S)
+static void tcc_add_systemdir(TCCState *s)
{
char buf[1000];
GetSystemDirectory(buf, sizeof buf);
- tcc_add_library_path(S, normalize_slashes(buf));
+ tcc_add_library_path(s, normalize_slashes(buf));
}
#endif
#endif
@@ -159,19 +160,19 @@ ST_FUNC void post_sem(TCCSem *p)
#endif
#endif
-PUB_FUNC void tcc_enter_state(TCCState *S)
+PUB_FUNC void tcc_enter_state(TCCState *s1)
{
- if (S->error_set_jmp_enabled)
+ if (s1->error_set_jmp_enabled)
return;
WAIT_SEM(&tcc_compile_sem);
- /*S = S;*/
+ tcc_state = s1;
}
-PUB_FUNC void tcc_exit_state(TCCState *S)
+PUB_FUNC void tcc_exit_state(TCCState *s1)
{
- if (S->error_set_jmp_enabled)
+ if (s1->error_set_jmp_enabled)
return;
- S = NULL;
+ tcc_state = NULL;
POST_SEM(&tcc_compile_sem);
}
@@ -233,10 +234,10 @@ PUB_FUNC char *tcc_fileextension (const char *name)
return e ? e : strchr(b, 0);
}
-ST_FUNC char *tcc_load_text(TCCState* S, int fd)
+ST_FUNC char *tcc_load_text(int fd)
{
int len = lseek(fd, 0, SEEK_END);
- char *buf = load_data(S, fd, 0, len + 1);
+ char *buf = load_data(fd, 0, len + 1);
buf[len] = 0;
return buf;
}
@@ -248,69 +249,44 @@ ST_FUNC char *tcc_load_text(TCCState* S, int fd)
#undef malloc
#undef realloc
-PUB_FUNC void tcc_free_base(void *ptr)
-{
- free(ptr);
-}
-
-PUB_FUNC void *tcc_malloc_base(unsigned long size)
-{
- void *ptr;
- ptr = malloc(size);
- if (!ptr && size) {
- printf("memory full (malloc)\n");
- exit(1);
- }
- return ptr;
-}
-
-PUB_FUNC void *tcc_mallocz_base(unsigned long size)
-{
- void *ptr;
- ptr = tcc_malloc_base(size);
- if (size)
- memset(ptr, 0, size);
- return ptr;
-}
-
#ifndef MEM_DEBUG
-PUB_FUNC void tcc_free(TCCState* S, void *ptr)
+PUB_FUNC void tcc_free(void *ptr)
{
free(ptr);
}
-PUB_FUNC void *tcc_malloc(TCCState* S, unsigned long size)
+PUB_FUNC void *tcc_malloc(unsigned long size)
{
void *ptr;
ptr = malloc(size);
if (!ptr && size)
- _tcc_error(S, "memory full (malloc)");
+ _tcc_error("memory full (malloc)");
return ptr;
}
-PUB_FUNC void *tcc_mallocz(TCCState* S, unsigned long size)
+PUB_FUNC void *tcc_mallocz(unsigned long size)
{
void *ptr;
- ptr = tcc_malloc(S, size);
+ ptr = tcc_malloc(size);
if (size)
memset(ptr, 0, size);
return ptr;
}
-PUB_FUNC void *tcc_realloc(TCCState* S, void *ptr, unsigned long size)
+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
{
void *ptr1;
ptr1 = realloc(ptr, size);
if (!ptr1 && size)
- _tcc_error(S, "memory full (realloc)");
+ _tcc_error("memory full (realloc)");
return ptr1;
}
-PUB_FUNC char *tcc_strdup(TCCState* S, const char *str)
+PUB_FUNC char *tcc_strdup(const char *str)
{
char *ptr;
- ptr = tcc_malloc(S, strlen(str) + 1);
+ ptr = tcc_malloc(strlen(str) + 1);
strcpy(ptr, str);
return ptr;
}
@@ -361,14 +337,14 @@ static mem_debug_header_t *malloc_check(void *ptr, const char *msg)
return header;
}
-PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *file, int line)
+PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line)
{
int ofs;
mem_debug_header_t *header;
header = malloc(sizeof(mem_debug_header_t) + size);
if (!header)
- _tcc_error(S, "memory full (malloc)");
+ _tcc_error("memory full (malloc)");
header->magic1 = MEM_DEBUG_MAGIC1;
header->magic2 = MEM_DEBUG_MAGIC2;
@@ -392,7 +368,7 @@ PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *fil
return MEM_USER_PTR(header);
}
-PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr)
+PUB_FUNC void tcc_free_debug(void *ptr)
{
mem_debug_header_t *header;
if (!ptr)
@@ -409,26 +385,26 @@ PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr)
free(header);
}
-PUB_FUNC void *tcc_mallocz_debug(TCCState* S, unsigned long size, const char *file, int line)
+PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line)
{
void *ptr;
- ptr = tcc_malloc_debug(S, size,file,line);
+ ptr = tcc_malloc_debug(size,file,line);
memset(ptr, 0, size);
return ptr;
}
-PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, const char *file, int line)
+PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line)
{
mem_debug_header_t *header;
int mem_debug_chain_update = 0;
if (!ptr)
- return tcc_malloc_debug(S, size, file, line);
+ return tcc_malloc_debug(size, file, line);
header = malloc_check(ptr, "tcc_realloc");
mem_cur_size -= header->size;
mem_debug_chain_update = (header == mem_debug_chain);
header = realloc(header, sizeof(mem_debug_header_t) + size);
if (!header)
- _tcc_error(S, "memory full (realloc)");
+ _tcc_error("memory full (realloc)");
header->size = size;
write32le(MEM_DEBUG_CHECK3(header), MEM_DEBUG_MAGIC3);
if (header->next)
@@ -443,10 +419,10 @@ PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, con
return MEM_USER_PTR(header);
}
-PUB_FUNC char *tcc_strdup_debug(TCCState* S, const char *str, const char *file, int line)
+PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line)
{
char *ptr;
- ptr = tcc_malloc_debug(S, strlen(str) + 1, file, line);
+ ptr = tcc_malloc_debug(strlen(str) + 1, file, line);
strcpy(ptr, str);
return ptr;
}
@@ -474,65 +450,9 @@ PUB_FUNC void tcc_memcheck(void)
#define realloc(p, s) use_tcc_realloc(p, s)
/********************************************************/
-/* virtual io */
-
-LIBTCCAPI void tcc_set_vio_module(TCCState *S, vio_module_t *vio_module){
- S->vio_module = vio_module;
- vio_module->S = S;
-}
-
-void vio_initialize(vio_fd *fd) {
- fd->fd = -1;
- fd->vio_udata = NULL;
- fd->vio_module = NULL;
-}
-
-int vio_open(struct TCCState *S, vio_fd *fd, const char *fn, int oflag) {
- int rc;
- vio_initialize(fd);
- fd->vio_module = S->vio_module;
- if(S->vio_module && (S->vio_module->call_vio_open_flags & CALL_VIO_OPEN_FIRST)) {
- rc = S->vio_module->vio_open(fd, fn, oflag);
- if(rc >= 0) return rc;
- }
-
- fd->fd = open(fn, oflag);
-
- if(fd->fd < 0 && S->vio_module && (S->vio_module->call_vio_open_flags & CALL_VIO_OPEN_LAST)) {
- rc = S->vio_module->vio_open(fd, fn, oflag);
- if(rc >= 0) return rc;
- }
- //printf("vio_open = %d %s\n", fd->fd, fn);
- return fd->fd;
-}
-
-off_t vio_lseek(vio_fd fd, off_t offset, int whence) {
- if(fd.vio_udata) {
- return fd.vio_module->vio_lseek(fd, offset, whence);
- }
- return lseek(fd.fd, offset, whence);
-}
-
-size_t vio_read(vio_fd fd, void *buf, size_t bytes) {
- if(fd.vio_udata) {
- return fd.vio_module->vio_read(fd, buf, bytes);
- }
- return read(fd.fd, buf, bytes);
-}
-
-int vio_close(vio_fd *fd) {
- int rc = 0;
- if(fd->vio_udata){
- fd->vio_module->vio_close(fd);
- } else rc = close(fd->fd);
- vio_initialize(fd);
- return rc;
-}
-
-/********************************************************/
/* dynarrays */
-ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data)
+ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data)
{
int nb, nb_alloc;
void **pp;
@@ -545,54 +465,54 @@ ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data)
nb_alloc = 1;
else
nb_alloc = nb * 2;
- pp = tcc_realloc(S, pp, nb_alloc * sizeof(void *));
+ pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
*(void***)ptab = pp;
}
pp[nb++] = data;
*nb_ptr = nb;
}
-ST_FUNC void dynarray_reset(TCCState* S, void *pp, int *n)
+ST_FUNC void dynarray_reset(void *pp, int *n)
{
void **p;
for (p = *(void***)pp; *n; ++p, --*n)
if (*p)
- tcc_free(S, *p);
- tcc_free(S, *(void**)pp);
+ tcc_free(*p);
+ tcc_free(*(void**)pp);
*(void**)pp = NULL;
}
-static void tcc_split_path(TCCState *S, void *p_ary, int *p_nb_ary, const char *in)
+static void tcc_split_path(TCCState *s, void *p_ary, int *p_nb_ary, const char *in)
{
const char *p;
do {
int c;
CString str;
- cstr_new(S, &str);
+ cstr_new(&str);
for (p = in; c = *p, c != '\0' && c != PATHSEP[0]; ++p) {
if (c == '{' && p[1] && p[2] == '}') {
c = p[1], p += 2;
if (c == 'B')
- cstr_cat(S, &str, S->tcc_lib_path, -1);
- if (c == 'f' && S->tccpp_file) {
+ cstr_cat(&str, s->tcc_lib_path, -1);
+ if (c == 'f' && file) {
/* substitute current file's dir */
- const char *f = S->tccpp_file->true_filename;
+ const char *f = file->true_filename;
const char *b = tcc_basename(f);
if (b > f)
- cstr_cat(S, &str, f, b - f - 1);
+ cstr_cat(&str, f, b - f - 1);
else
- cstr_cat(S, &str, ".", 1);
+ cstr_cat(&str, ".", 1);
}
} else {
- cstr_ccat(S, &str, c);
+ cstr_ccat(&str, c);
}
}
if (str.size) {
- cstr_ccat(S, &str, '\0');
- dynarray_add(S, p_ary, p_nb_ary, tcc_strdup(S, str.data));
+ cstr_ccat(&str, '\0');
+ dynarray_add(p_ary, p_nb_ary, tcc_strdup(str.data));
}
- cstr_free(S, &str);
+ cstr_free(&str);
in = p+1;
} while (*p);
}
@@ -608,26 +528,27 @@ static void tcc_split_path(TCCState *S, void *p_ary, int *p_nb_ary, const char *
/* error1() modes */
enum { ERROR_WARN, ERROR_NOABORT, ERROR_ERROR };
-static void error1(TCCState* S, int mode, const char *fmt, va_list ap)
+static void error1(int mode, const char *fmt, va_list ap)
{
BufferedFile **pf, *f;
+ TCCState *s1 = tcc_state;
CString cs;
- cstr_new(S, &cs);
+ cstr_new(&cs);
- if (S == NULL)
+ if (s1 == NULL)
/* can happen only if called from tcc_malloc(): 'out of memory' */
goto no_file;
- tcc_exit_state(S);
+ tcc_exit_state(s1);
if (mode == ERROR_WARN) {
- if (S->warn_error)
+ if (s1->warn_error)
mode = ERROR_ERROR;
- if (S->warn_num) {
+ if (s1->warn_num) {
/* handle tcc_warning_c(warn_option)(fmt, ...) */
- int wopt = *(&S->warn_none + S->warn_num);
- S->warn_num = 0;
+ int wopt = *(&s1->warn_none + s1->warn_num);
+ s1->warn_num = 0;
if (0 == (wopt & WARN_ON))
return;
if (wopt & WARN_ERR)
@@ -635,102 +556,102 @@ static void error1(TCCState* S, int mode, const char *fmt, va_list ap)
if (wopt & WARN_NOE)
mode = ERROR_WARN;
}
- if (S->warn_none)
+ if (s1->warn_none)
return;
}
f = NULL;
- if (S->error_set_jmp_enabled) { /* we're called while parsing a file */
+ if (s1->error_set_jmp_enabled) { /* we're called while parsing a file */
/* use upper file if inline ":asm:" or token ":paste:" */
- for (f = S->tccpp_file; f && f->filename[0] == ':'; f = f->prev)
+ for (f = file; f && f->filename[0] == ':'; f = f->prev)
;
}
if (f) {
- for(pf = S->include_stack; pf < S->include_stack_ptr; pf++)
- cstr_printf(S, &cs, "In file included from %s:%d:\n",
+ for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
+ cstr_printf(&cs, "In file included from %s:%d:\n",
(*pf)->filename, (*pf)->line_num);
- cstr_printf(S, &cs, "%s:%d: ",
- f->filename, (*pf)->line_num - !!(S->tccpp_tok_flags & TOK_FLAG_BOL));
- } else if (S->current_filename) {
- cstr_printf(S, &cs, "%s: ", S->current_filename);
+ cstr_printf(&cs, "%s:%d: ",
+ f->filename, f->line_num - !!(tok_flags & TOK_FLAG_BOL));
+ } else if (s1->current_filename) {
+ cstr_printf(&cs, "%s: ", s1->current_filename);
}
no_file:
if (0 == cs.size)
- cstr_printf(S, &cs, "tcc: ");
- cstr_printf(S, &cs, mode == ERROR_WARN ? "warning: " : "error: ");
- cstr_vprintf(S, &cs, fmt, ap);
- if (!S || !S->error_func) {
+ cstr_printf(&cs, "tcc: ");
+ cstr_printf(&cs, mode == ERROR_WARN ? "warning: " : "error: ");
+ cstr_vprintf(&cs, fmt, ap);
+ if (!s1 || !s1->error_func) {
/* default case: stderr */
- if (S && S->output_type == TCC_OUTPUT_PREPROCESS && S->ppfp == stdout)
+ if (s1 && s1->output_type == TCC_OUTPUT_PREPROCESS && s1->ppfp == stdout)
printf("\n"); /* print a newline during tcc -E */
fflush(stdout); /* flush -v output */
fprintf(stderr, "%s\n", (char*)cs.data);
fflush(stderr); /* print error/warning now (win32) */
} else {
- S->error_func(S->error_opaque, (char*)cs.data);
+ s1->error_func(s1->error_opaque, (char*)cs.data);
}
- cstr_free(S, &cs);
- if (S) {
+ cstr_free(&cs);
+ if (s1) {
if (mode != ERROR_WARN)
- S->nb_errors++;
+ s1->nb_errors++;
if (mode != ERROR_ERROR)
return;
- if (S->error_set_jmp_enabled)
- longjmp(S->error_jmp_buf, 1);
+ if (s1->error_set_jmp_enabled)
+ longjmp(s1->error_jmp_buf, 1);
}
exit(1);
}
-LIBTCCAPI void tcc_set_error_func(TCCState *S, void *error_opaque, TCCErrorFunc error_func)
+LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func)
{
- S->error_opaque = error_opaque;
- S->error_func = error_func;
+ s->error_opaque = error_opaque;
+ s->error_func = error_func;
}
-LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *S)
+LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s)
{
- return S->error_func;
+ return s->error_func;
}
-LIBTCCAPI void *tcc_get_error_opaque(TCCState *S)
+LIBTCCAPI void *tcc_get_error_opaque(TCCState *s)
{
- return S->error_opaque;
+ return s->error_opaque;
}
/* error without aborting current compilation */
-PUB_FUNC void _tcc_error_noabort(TCCState* S, const char *fmt, ...)
+PUB_FUNC void _tcc_error_noabort(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- error1(S, ERROR_NOABORT, fmt, ap);
+ error1(ERROR_NOABORT, fmt, ap);
va_end(ap);
}
-PUB_FUNC void _tcc_error(TCCState* S, const char *fmt, ...)
+PUB_FUNC void _tcc_error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- for (;;) error1(S, ERROR_ERROR, fmt, ap);
+ for (;;) error1(ERROR_ERROR, fmt, ap);
}
-PUB_FUNC void _tcc_warning(TCCState* S, const char *fmt, ...)
+PUB_FUNC void _tcc_warning(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- error1(S, ERROR_WARN, fmt, ap);
+ error1(ERROR_WARN, fmt, ap);
va_end(ap);
}
/********************************************************/
/* I/O layer */
-ST_FUNC void tcc_open_bf(TCCState *S, const char *filename, int initlen)
+ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen)
{
BufferedFile *bf;
int buflen = initlen ? initlen : IO_BUF_SIZE;
- bf = tcc_mallocz(S, sizeof(BufferedFile) + buflen);
+ bf = tcc_mallocz(sizeof(BufferedFile) + buflen);
bf->buf_ptr = bf->buffer;
bf->buf_end = bf->buffer + initlen;
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)
#endif
bf->true_filename = bf->filename;
bf->line_num = 1;
- bf->ifdef_stack_ptr = S->ifdef_stack_ptr;
+ bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
bf->fd = -1;
- bf->prev = S->tccpp_file;
- S->tccpp_file = bf;
- S->tccpp_tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
+ bf->prev = file;
+ file = bf;
+ tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
}
-ST_FUNC void tcc_close(TCCState* S)
+ST_FUNC void tcc_close(void)
{
- BufferedFile *bf = S->tccpp_file;
+ TCCState *s1 = tcc_state;
+ BufferedFile *bf = file;
if (bf->fd > 0) {
close(bf->fd);
total_lines += bf->line_num;
}
if (bf->true_filename != bf->filename)
- tcc_free(S, bf->true_filename);
- S->tccpp_file = bf->prev;
- tcc_free(S, bf);
+ tcc_free(bf->true_filename);
+ file = bf->prev;
+ tcc_free(bf);
}
-static int _tcc_open(TCCState *S, const char *filename)
+static int _tcc_open(TCCState *s1, const char *filename)
{
int fd;
if (strcmp(filename, "-") == 0)
fd = 0, filename = "<stdin>";
else
fd = open(filename, O_RDONLY | O_BINARY);
- if ((S->verbose == 2 && fd >= 0) || S->verbose == 3)
+ if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
- (int)(S->include_stack_ptr - S->include_stack), "", filename);
+ (int)(s1->include_stack_ptr - s1->include_stack), "", filename);
return fd;
}
-ST_FUNC int tcc_open(TCCState *S, const char *filename)
+ST_FUNC int tcc_open(TCCState *s1, const char *filename)
{
- int fd = _tcc_open(S, filename);
+ int fd = _tcc_open(s1, filename);
if (fd < 0)
return -1;
- tcc_open_bf(S, filename, 0);
- S->tccpp_file->fd = fd;
+ tcc_open_bf(s1, filename, 0);
+ file->fd = fd;
return 0;
}
/* compile the file opened in 'file'. Return non zero if errors. */
-static int tcc_compile(TCCState *S, int filetype, const char *str, int fd)
+static int tcc_compile(TCCState *s1, int filetype, const char *str, int fd)
{
/* Here we enter the code section where we use the global variables for
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)
Alternatively we could use thread local storage for those global
variables, which may or may not have advantages */
- tcc_enter_state(S);
- S->error_set_jmp_enabled = 1;
+ tcc_enter_state(s1);
+ s1->error_set_jmp_enabled = 1;
- if (setjmp(S->error_jmp_buf) == 0) {
- S->nb_errors = 0;
+ if (setjmp(s1->error_jmp_buf) == 0) {
+ s1->nb_errors = 0;
if (fd == -1) {
int len = strlen(str);
- tcc_open_bf(S, "<string>", len);
- memcpy(S->tccpp_file->buffer, str, len);
+ tcc_open_bf(s1, "<string>", len);
+ memcpy(file->buffer, str, len);
} else {
- tcc_open_bf(S, str, 0);
- S->tccpp_file->fd = fd;
+ tcc_open_bf(s1, str, 0);
+ file->fd = fd;
}
- tccelf_begin_file(S);
- preprocess_start(S, filetype);
- tccgen_init(S);
- if (S->output_type == TCC_OUTPUT_PREPROCESS) {
- tcc_preprocess(S);
+ tccelf_begin_file(s1);
+ preprocess_start(s1, filetype);
+ tccgen_init(s1);
+ if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
+ tcc_preprocess(s1);
} else if (filetype & (AFF_TYPE_ASM | AFF_TYPE_ASMPP)) {
- tcc_assemble(S, !!(filetype & AFF_TYPE_ASMPP));
+ tcc_assemble(s1, !!(filetype & AFF_TYPE_ASMPP));
} else {
- tccgen_compile(S);
+ tccgen_compile(s1);
}
}
- tccgen_finish(S);
- preprocess_end(S);
+ tccgen_finish(s1);
+ preprocess_end(s1);
- S->error_set_jmp_enabled = 0;
- tcc_exit_state(S);
+ s1->error_set_jmp_enabled = 0;
+ tcc_exit_state(s1);
- tccelf_end_file(S);
- return S->nb_errors != 0 ? -1 : 0;
+ tccelf_end_file(s1);
+ return s1->nb_errors != 0 ? -1 : 0;
}
-LIBTCCAPI int tcc_compile_string(TCCState *S, const char *str)
+LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
{
- return tcc_compile(S, S->filetype, str, -1);
+ return tcc_compile(s, s->filetype, str, -1);
}
/* define a preprocessor symbol. value can be NULL, sym can be "sym=val" */
-LIBTCCAPI void tcc_define_symbol(TCCState *S, const char *sym, const char *value)
+LIBTCCAPI void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
{
const char *eq;
if (NULL == (eq = strchr(sym, '=')))
eq = strchr(sym, 0);
if (NULL == value)
value = *eq ? eq + 1 : "1";
- cstr_printf(S, &S->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value);
+ cstr_printf(&s1->cmdline_defs, "#define %.*s %s\n", (int)(eq-sym), sym, value);
}
/* undefine a preprocessor symbol */
-LIBTCCAPI void tcc_undefine_symbol(TCCState *S, const char *sym)
+LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym)
{
- cstr_printf(S, &S->cmdline_defs, "#undef %s\n", sym);
+ cstr_printf(&s1->cmdline_defs, "#undef %s\n", sym);
}
@@ -856,7 +778,7 @@ LIBTCCAPI TCCState *tcc_new(void)
{
TCCState *s;
- s = tcc_mallocz_base(sizeof(TCCState));
+ s = tcc_mallocz(sizeof(TCCState));
if (!s)
return NULL;
#ifdef MEM_DEBUG
@@ -898,153 +820,153 @@ LIBTCCAPI TCCState *tcc_new(void)
return s;
}
-LIBTCCAPI void tcc_delete(TCCState *S)
+LIBTCCAPI void tcc_delete(TCCState *s1)
{
/* free sections */
- tccelf_delete(S);
+ tccelf_delete(s1);
/* free library paths */
- dynarray_reset(S, &S->library_paths, &S->nb_library_paths);
- dynarray_reset(S, &S->crt_paths, &S->nb_crt_paths);
+ dynarray_reset(&s1->library_paths, &s1->nb_library_paths);
+ dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths);
/* free include paths */
- dynarray_reset(S, &S->include_paths, &S->nb_include_paths);
- dynarray_reset(S, &S->sysinclude_paths, &S->nb_sysinclude_paths);
-
- tcc_free(S, S->tcc_lib_path);
- tcc_free(S, S->soname);
- tcc_free(S, S->rpath);
- tcc_free(S, S->init_symbol);
- tcc_free(S, S->fini_symbol);
- tcc_free(S, S->outfile);
- tcc_free(S, S->deps_outfile);
- dynarray_reset(S, &S->files, &S->nb_files);
- dynarray_reset(S, &S->target_deps, &S->nb_target_deps);
- dynarray_reset(S, &S->pragma_libs, &S->nb_pragma_libs);
- dynarray_reset(S, &S->argv, &S->argc);
- cstr_free(S, &S->cmdline_defs);
- cstr_free(S, &S->cmdline_incl);
+ dynarray_reset(&s1->include_paths, &s1->nb_include_paths);
+ dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
+
+ tcc_free(s1->tcc_lib_path);
+ tcc_free(s1->soname);
+ tcc_free(s1->rpath);
+ tcc_free(s1->init_symbol);
+ tcc_free(s1->fini_symbol);
+ tcc_free(s1->outfile);
+ tcc_free(s1->deps_outfile);
+ dynarray_reset(&s1->files, &s1->nb_files);
+ dynarray_reset(&s1->target_deps, &s1->nb_target_deps);
+ dynarray_reset(&s1->pragma_libs, &s1->nb_pragma_libs);
+ dynarray_reset(&s1->argv, &s1->argc);
+ cstr_free(&s1->cmdline_defs);
+ cstr_free(&s1->cmdline_incl);
#ifdef TCC_IS_NATIVE
/* free runtime memory */
- tcc_run_free(S);
+ tcc_run_free(s1);
#endif
- tcc_free_base(S);
+ tcc_free(s1);
#ifdef MEM_DEBUG
if (0 == --nb_states)
tcc_memcheck();
#endif
}
-LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type)
+LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
{
- S->output_type = output_type;
+ s->output_type = output_type;
- if (!S->nostdinc) {
+ if (!s->nostdinc) {
/* default include paths */
/* -isystem paths have already been handled */
- tcc_add_sysinclude_path(S, CONFIG_TCC_SYSINCLUDEPATHS);
+ tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
}
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check) {
+ if (s->do_bounds_check) {
/* if bound checking, then add corresponding sections */
- tccelf_bounds_new(S);
+ tccelf_bounds_new(s);
}
#endif
- if (S->do_debug) {
+ if (s->do_debug) {
/* add debug sections */
- tccelf_stab_new(S);
+ tccelf_stab_new(s);
}
if (output_type == TCC_OUTPUT_OBJ) {
/* always elf for objects */
- S->output_format = TCC_OUTPUT_FORMAT_ELF;
+ s->output_format = TCC_OUTPUT_FORMAT_ELF;
return 0;
}
- tcc_add_library_path(S, CONFIG_TCC_LIBPATHS);
+ tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
#ifdef TCC_TARGET_PE
# ifdef _WIN32
/* allow linking with system dll's directly */
- tcc_add_systemdir(S);
+ tcc_add_systemdir(s);
# endif
/* target PE has its own startup code in libtcc1.a */
return 0;
#elif defined TCC_TARGET_MACHO
# ifdef TCC_IS_NATIVE
- tcc_add_macos_sdkpath(S);
+ tcc_add_macos_sdkpath(s);
# endif
/* Mach-O with LC_MAIN doesn't need any crt startup code. */
return 0;
#else
/* paths for crt objects */
- tcc_split_path(S, &S->crt_paths, &S->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
+ tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
/* add libc crt1/crti objects */
if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
- !S->nostdlib) {
+ !s->nostdlib) {
#if TARGETOS_OpenBSD
if (output_type != TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crt0.o");
+ tcc_add_crt(s, "crt0.o");
if (output_type == TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crtbeginS.o");
+ tcc_add_crt(s, "crtbeginS.o");
else
- tcc_add_crt(S, "crtbegin.o");
+ tcc_add_crt(s, "crtbegin.o");
#elif TARGETOS_FreeBSD
if (output_type != TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crt1.o");
- tcc_add_crt(S, "crti.o");
- if (S->static_link)
- tcc_add_crt(S, "crtbeginT.o");
+ tcc_add_crt(s, "crt1.o");
+ tcc_add_crt(s, "crti.o");
+ if (s->static_link)
+ tcc_add_crt(s, "crtbeginT.o");
else if (output_type == TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crtbeginS.o");
+ tcc_add_crt(s, "crtbeginS.o");
else
- tcc_add_crt(S, "crtbegin.o");
+ tcc_add_crt(s, "crtbegin.o");
#elif TARGETOS_NetBSD
if (output_type != TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crt0.o");
- tcc_add_crt(S, "crti.o");
- if (S->static_link)
- tcc_add_crt(S, "crtbeginT.o");
+ tcc_add_crt(s, "crt0.o");
+ tcc_add_crt(s, "crti.o");
+ if (s->static_link)
+ tcc_add_crt(s, "crtbeginT.o");
else if (output_type == TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crtbeginS.o");
+ tcc_add_crt(s, "crtbeginS.o");
else
- tcc_add_crt(S, "crtbegin.o");
+ tcc_add_crt(s, "crtbegin.o");
#else
if (output_type != TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crt1.o");
- tcc_add_crt(S, "crti.o");
+ tcc_add_crt(s, "crt1.o");
+ tcc_add_crt(s, "crti.o");
#endif
}
return 0;
#endif
}
-LIBTCCAPI int tcc_add_include_path(TCCState *S, const char *pathname)
+LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname)
{
- tcc_split_path(S, &S->include_paths, &S->nb_include_paths, pathname);
+ tcc_split_path(s, &s->include_paths, &s->nb_include_paths, pathname);
return 0;
}
-LIBTCCAPI int tcc_add_sysinclude_path(TCCState *S, const char *pathname)
+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname)
{
- tcc_split_path(S, &S->sysinclude_paths, &S->nb_sysinclude_paths, pathname);
+ tcc_split_path(s, &s->sysinclude_paths, &s->nb_sysinclude_paths, pathname);
return 0;
}
-ST_FUNC DLLReference *tcc_add_dllref(TCCState *S, const char *dllname)
+ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname)
{
- DLLReference *ref = tcc_mallocz(S, sizeof(DLLReference) + strlen(dllname));
+ DLLReference *ref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname));
strcpy(ref->name, dllname);
- dynarray_add(S, &S->loaded_dlls, &S->nb_loaded_dlls, ref);
+ dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, ref);
return ref;
}
/* OpenBSD: choose latest from libxxx.so.x.y versions */
#if defined TARGETOS_OpenBSD && !defined _WIN32
#include <glob.h>
-static int tcc_glob_so(TCCState *S, const char *pattern, char *buf, int size)
+static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
{
const char *star;
glob_t g;
@@ -1066,25 +988,25 @@ static int tcc_glob_so(TCCState *S, const char *pattern, char *buf, int size)
}
#endif
-ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags)
+ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
{
int fd, ret = -1;
#if defined TARGETOS_OpenBSD && !defined _WIN32
char buf[1024];
- if (tcc_glob_so(S, filename, buf, sizeof buf) >= 0)
+ if (tcc_glob_so(s1, filename, buf, sizeof buf) >= 0)
filename = buf;
#endif
/* open the file */
- fd = _tcc_open(S, filename);
+ fd = _tcc_open(s1, filename);
if (fd < 0) {
if (flags & AFF_PRINT_ERROR)
- tcc_error_noabort(S, "file '%s' not found", filename);
+ tcc_error_noabort("file '%s' not found", filename);
return ret;
}
- S->current_filename = filename;
+ s1->current_filename = filename;
if (flags & AFF_TYPE_BIN) {
ElfW(Ehdr) ehdr;
int obj_type;
@@ -1095,22 +1017,22 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags)
switch (obj_type) {
case AFF_BINTYPE_REL:
- ret = tcc_load_object_file(S, fd, 0);
+ ret = tcc_load_object_file(s1, fd, 0);
break;
case AFF_BINTYPE_AR:
- ret = tcc_load_archive(S, fd, !(flags & AFF_WHOLE_ARCHIVE));
+ ret = tcc_load_archive(s1, fd, !(flags & AFF_WHOLE_ARCHIVE));
break;
#ifdef TCC_TARGET_PE
default:
- ret = pe_load_file(S, fd, filename);
+ ret = pe_load_file(s1, fd, filename);
goto check_success;
#elif defined TCC_TARGET_MACHO
case AFF_BINTYPE_DYN:
case_dyn_or_tbd:
- if (S->output_type == TCC_OUTPUT_MEMORY) {
+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
void* dl;
const char* soname = filename;
@@ -1118,14 +1040,14 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags)
soname = macho_tbd_soname(filename);
dl = dlopen(soname, RTLD_GLOBAL | RTLD_LAZY);
if (dl)
- tcc_add_dllref(S, soname)->handle = dl, ret = 0;
+ tcc_add_dllref(s1, soname)->handle = dl, ret = 0;
if (filename != soname)
- tcc_free(S, (void *)soname);
+ tcc_free((void *)soname);
#endif
} else if (obj_type == AFF_BINTYPE_DYN) {
- ret = macho_load_dll(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
+ ret = macho_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
} else {
- ret = macho_load_tbd(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
+ ret = macho_load_tbd(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
}
break;
default:
@@ -1142,47 +1064,47 @@ ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags)
#else /* unix */
case AFF_BINTYPE_DYN:
- if (S->output_type == TCC_OUTPUT_MEMORY) {
+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
void* dl = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
if (dl)
- tcc_add_dllref(S, filename)->handle = dl, ret = 0;
+ tcc_add_dllref(s1, filename)->handle = dl, ret = 0;
#endif
} else
- ret = tcc_load_dll(S, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
+ ret = tcc_load_dll(s1, fd, filename, (flags & AFF_REFERENCED_DLL) != 0);
break;
default:
/* as GNU ld, consider it is an ld script if not recognized */
- ret = tcc_load_ldscript(S, fd);
+ ret = tcc_load_ldscript(s1, fd);
goto check_success;
#endif /* pe / macos / unix */
check_success:
if (ret < 0)
- tcc_error_noabort(S, "%s: unrecognized file type", filename);
+ tcc_error_noabort("%s: unrecognized file type", filename);
break;
#ifdef TCC_TARGET_COFF
case AFF_BINTYPE_C67:
- ret = tcc_load_coff(S, fd);
+ ret = tcc_load_coff(s1, fd);
break;
#endif
}
close(fd);
} else {
/* update target deps */
- dynarray_add(S, &S->target_deps, &S->nb_target_deps, tcc_strdup(S, filename));
- ret = tcc_compile(S, flags, filename, fd);
+ dynarray_add(&s1->target_deps, &s1->nb_target_deps, tcc_strdup(filename));
+ ret = tcc_compile(s1, flags, filename, fd);
}
- S->current_filename = NULL;
+ s1->current_filename = NULL;
return ret;
}
-LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename)
+LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
{
- int filetype = S->filetype;
+ int filetype = s->filetype;
if (0 == (filetype & AFF_TYPE_MASK)) {
/* use a file extension to detect a filetype */
const char *ext = tcc_fileextension(filename);
@@ -1202,16 +1124,16 @@ LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename)
filetype = AFF_TYPE_C;
}
}
- return tcc_add_file_internal(S, filename, filetype | AFF_PRINT_ERROR);
+ return tcc_add_file_internal(s, filename, filetype | AFF_PRINT_ERROR);
}
-LIBTCCAPI int tcc_add_library_path(TCCState *S, const char *pathname)
+LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
{
- tcc_split_path(S, &S->library_paths, &S->nb_library_paths, pathname);
+ tcc_split_path(s, &s->library_paths, &s->nb_library_paths, pathname);
return 0;
}
-static int tcc_add_library_internal(TCCState *S, const char *fmt,
+static int tcc_add_library_internal(TCCState *s, const char *fmt,
const char *filename, int flags, char **paths, int nb_paths)
{
char buf[1024];
@@ -1219,7 +1141,7 @@ static int tcc_add_library_internal(TCCState *S, const char *fmt,
for(i = 0; i < nb_paths; i++) {
snprintf(buf, sizeof(buf), fmt, paths[i], filename);
- if (tcc_add_file_internal(S, buf, flags | AFF_TYPE_BIN) == 0)
+ if (tcc_add_file_internal(s, buf, flags | AFF_TYPE_BIN) == 0)
return 0;
}
return -1;
@@ -1228,87 +1150,87 @@ static int tcc_add_library_internal(TCCState *S, const char *fmt,
#ifndef TCC_TARGET_MACHO
/* find and load a dll. Return non zero if not found */
/* XXX: add '-rpath' option support ? */
-ST_FUNC int tcc_add_dll(TCCState *S, const char *filename, int flags)
+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
{
- return tcc_add_library_internal(S, "%s/%s", filename, flags,
- S->library_paths, S->nb_library_paths);
+ return tcc_add_library_internal(s, "%s/%s", filename, flags,
+ s->library_paths, s->nb_library_paths);
}
#endif
#if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO
-ST_FUNC int tcc_add_crt(TCCState *S, const char *filename)
+ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)
{
- if (-1 == tcc_add_library_internal(S, "%s/%s",
- filename, 0, S->crt_paths, S->nb_crt_paths))
- tcc_error_noabort(S, "file '%s' not found", filename);
+ if (-1 == tcc_add_library_internal(s1, "%s/%s",
+ filename, 0, s1->crt_paths, s1->nb_crt_paths))
+ tcc_error_noabort("file '%s' not found", filename);
return 0;
}
#endif
/* the library name is the same as the argument of the '-l' option */
-LIBTCCAPI int tcc_add_library(TCCState *S, const char *libraryname)
+LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
{
#if defined TCC_TARGET_PE
static const char * const libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
- const char * const *pp = S->static_link ? libs + 4 : libs;
+ const char * const *pp = s->static_link ? libs + 4 : libs;
#elif defined TCC_TARGET_MACHO
static const char * const libs[] = { "%s/lib%s.dylib", "%s/lib%s.tbd", "%s/lib%s.a", NULL };
- const char * const *pp = S->static_link ? libs + 2 : libs;
+ const char * const *pp = s->static_link ? libs + 2 : libs;
#elif defined TARGETOS_OpenBSD
static const char * const libs[] = { "%s/lib%s.so.*", "%s/lib%s.a", NULL };
- const char * const *pp = S->static_link ? libs + 1 : libs;
+ const char * const *pp = s->static_link ? libs + 1 : libs;
#else
static const char * const libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
- const char * const *pp = S->static_link ? libs + 1 : libs;
+ const char * const *pp = s->static_link ? libs + 1 : libs;
#endif
- int flags = S->filetype & AFF_WHOLE_ARCHIVE;
+ int flags = s->filetype & AFF_WHOLE_ARCHIVE;
while (*pp) {
- if (0 == tcc_add_library_internal(S, *pp,
- libraryname, flags, S->library_paths, S->nb_library_paths))
+ if (0 == tcc_add_library_internal(s, *pp,
+ libraryname, flags, s->library_paths, s->nb_library_paths))
return 0;
++pp;
}
return -1;
}
-PUB_FUNC int tcc_add_library_err(TCCState *S, const char *libname)
+PUB_FUNC int tcc_add_library_err(TCCState *s1, const char *libname)
{
- int ret = tcc_add_library(S, libname);
+ int ret = tcc_add_library(s1, libname);
if (ret < 0)
- tcc_error_noabort(S, "library '%s' not found", libname);
+ tcc_error_noabort("library '%s' not found", libname);
return ret;
}
/* handle #pragma comment(lib,) */
-ST_FUNC void tcc_add_pragma_libs(TCCState *S)
+ST_FUNC void tcc_add_pragma_libs(TCCState *s1)
{
int i;
- for (i = 0; i < S->nb_pragma_libs; i++)
- tcc_add_library_err(S, S->pragma_libs[i]);
+ for (i = 0; i < s1->nb_pragma_libs; i++)
+ tcc_add_library_err(s1, s1->pragma_libs[i]);
}
-LIBTCCAPI int tcc_add_symbol(TCCState *S, const char *name, const void *val)
+LIBTCCAPI int tcc_add_symbol(TCCState *s1, const char *name, const void *val)
{
#ifdef TCC_TARGET_PE
/* On x86_64 'val' might not be reachable with a 32bit offset.
So it is handled here as if it were in a DLL. */
- pe_putimport(S, 0, name, (uintptr_t)val);
+ pe_putimport(s1, 0, name, (uintptr_t)val);
#else
char buf[256];
- if (S->leading_underscore) {
+ if (s1->leading_underscore) {
buf[0] = '_';
pstrcpy(buf + 1, sizeof(buf) - 1, name);
name = buf;
}
- set_global_sym(S, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */
+ set_global_sym(s1, name, NULL, (addr_t)(uintptr_t)val); /* NULL: SHN_ABS */
#endif
return 0;
}
-LIBTCCAPI void tcc_set_lib_path(TCCState *S, const char *path)
+LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
{
- tcc_free(S, S->tcc_lib_path);
- S->tcc_lib_path = tcc_strdup(S, path);
+ tcc_free(s->tcc_lib_path);
+ s->tcc_lib_path = tcc_strdup(path);
}
/********************************************************/
@@ -1388,7 +1310,7 @@ static const char *skip_linker_arg(const char **str)
return s2;
}
-static void copy_linker_arg(TCCState* S, char **pp, const char *s, int sep)
+static void copy_linker_arg(char **pp, const char *s, int sep)
{
const char *q = s;
char *p = *pp;
@@ -1396,12 +1318,13 @@ static void copy_linker_arg(TCCState* S, char **pp, const char *s, int sep)
if (p && sep)
p[l = strlen(p)] = sep, ++l;
skip_linker_arg(&q);
- pstrncpy(l + (*pp = tcc_realloc(S, p, q - s + l + 1)), s, q - s);
+ pstrncpy(l + (*pp = tcc_realloc(p, q - s + l + 1)), s, q - s);
}
/* set linker options */
-static int tcc_set_linker(TCCState *S, const char *option)
+static int tcc_set_linker(TCCState *s, const char *option)
{
+ TCCState *s1 = s;
while (*option) {
const char *p = NULL;
@@ -1410,18 +1333,18 @@ static int tcc_set_linker(TCCState *S, const char *option)
int ret;
if (link_option(option, "Bsymbolic", &p)) {
- S->symbolic = 1;
+ s->symbolic = 1;
} else if (link_option(option, "nostdlib", &p)) {
- S->nostdlib = 1;
+ s->nostdlib = 1;
} else if (link_option(option, "fini=", &p)) {
- copy_linker_arg(S, &S->fini_symbol, p, 0);
+ copy_linker_arg(&s->fini_symbol, p, 0);
ignoring = 1;
} else if (link_option(option, "image-base=", &p)
|| link_option(option, "Ttext=", &p)) {
- S->text_addr = strtoull(p, &end, 16);
- S->has_text_addr = 1;
+ s->text_addr = strtoull(p, &end, 16);
+ s->has_text_addr = 1;
} else if (link_option(option, "init=", &p)) {
- copy_linker_arg(S, &S->init_symbol, p, 0);
+ copy_linker_arg(&s->init_symbol, p, 0);
ignoring = 1;
} else if (link_option(option, "oformat=", &p)) {
#if defined(TCC_TARGET_PE)
@@ -1431,12 +1354,12 @@ static int tcc_set_linker(TCCState *S, const char *option)
#else
if (strstart("elf32-", &p)) {
#endif
- S->output_format = TCC_OUTPUT_FORMAT_ELF;
+ s->output_format = TCC_OUTPUT_FORMAT_ELF;
} else if (!strcmp(p, "binary")) {
- S->output_format = TCC_OUTPUT_FORMAT_BINARY;
+ s->output_format = TCC_OUTPUT_FORMAT_BINARY;
#ifdef TCC_TARGET_COFF
} else if (!strcmp(p, "coff")) {
- S->output_format = TCC_OUTPUT_FORMAT_COFF;
+ s->output_format = TCC_OUTPUT_FORMAT_COFF;
#endif
} else
goto err;
@@ -1446,64 +1369,64 @@ static int tcc_set_linker(TCCState *S, const char *option)
} else if (link_option(option, "O", &p)) {
ignoring = 1;
} else if (link_option(option, "export-all-symbols", &p)) {
- S->rdynamic = 1;
+ s->rdynamic = 1;
} else if (link_option(option, "export-dynamic", &p)) {
- S->rdynamic = 1;
+ s->rdynamic = 1;
} else if (link_option(option, "rpath=", &p)) {
- copy_linker_arg(S, &S->rpath, p, ':');
+ copy_linker_arg(&s->rpath, p, ':');
} else if (link_option(option, "enable-new-dtags", &p)) {
- S->enable_new_dtags = 1;
+ s->enable_new_dtags = 1;
} else if (link_option(option, "section-alignment=", &p)) {
- S->section_align = strtoul(p, &end, 16);
+ s->section_align = strtoul(p, &end, 16);
} else if (link_option(option, "soname=", &p)) {
- copy_linker_arg(S, &S->soname, p, 0);
+ copy_linker_arg(&s->soname, p, 0);
#ifdef TCC_TARGET_PE
} else if (link_option(option, "large-address-aware", &p)) {
- S->pe_characteristics |= 0x20;
+ s->pe_characteristics |= 0x20;
} else if (link_option(option, "file-alignment=", &p)) {
- S->pe_file_align = strtoul(p, &end, 16);
+ s->pe_file_align = strtoul(p, &end, 16);
} else if (link_option(option, "stack=", &p)) {
- S->pe_stack_size = strtoul(p, &end, 10);
+ s->pe_stack_size = strtoul(p, &end, 10);
} else if (link_option(option, "subsystem=", &p)) {
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
if (!strcmp(p, "native")) {
- S->pe_subsystem = 1;
+ s->pe_subsystem = 1;
} else if (!strcmp(p, "console")) {
- S->pe_subsystem = 3;
+ s->pe_subsystem = 3;
} else if (!strcmp(p, "gui") || !strcmp(p, "windows")) {
- S->pe_subsystem = 2;
+ s->pe_subsystem = 2;
} else if (!strcmp(p, "posix")) {
- S->pe_subsystem = 7;
+ s->pe_subsystem = 7;
} else if (!strcmp(p, "efiapp")) {
- S->pe_subsystem = 10;
+ s->pe_subsystem = 10;
} else if (!strcmp(p, "efiboot")) {
- S->pe_subsystem = 11;
+ s->pe_subsystem = 11;
} else if (!strcmp(p, "efiruntime")) {
- S->pe_subsystem = 12;
+ s->pe_subsystem = 12;
} else if (!strcmp(p, "efirom")) {
- S->pe_subsystem = 13;
+ s->pe_subsystem = 13;
#elif defined(TCC_TARGET_ARM)
if (!strcmp(p, "wince")) {
- S->pe_subsystem = 9;
+ s->pe_subsystem = 9;
#endif
} else
goto err;
#endif
} else if (ret = link_option(option, "?whole-archive", &p), ret) {
if (ret > 0)
- S->filetype |= AFF_WHOLE_ARCHIVE;
+ s->filetype |= AFF_WHOLE_ARCHIVE;
else
- S->filetype &= ~AFF_WHOLE_ARCHIVE;
+ s->filetype &= ~AFF_WHOLE_ARCHIVE;
} else if (link_option(option, "z=", &p)) {
ignoring = 1;
} else if (p) {
return 0;
} else {
err:
- tcc_error(S, "unsupported linker option '%s'", option);
+ tcc_error("unsupported linker option '%s'", option);
}
if (ignoring)
- tcc_warning_c(warn_unsupported)(S, "unsupported linker option '%s'", option);
+ tcc_warning_c(warn_unsupported)("unsupported linker option '%s'", option);
option = skip_linker_arg(&p);
}
return 1;
@@ -1681,7 +1604,7 @@ static const FlagDef options_m[] = {
{ 0, 0, NULL }
};
-static int set_flag(TCCState *S, const FlagDef *flags, const char *name)
+static int set_flag(TCCState *s, const FlagDef *flags, const char *name)
{
int value, mask, ret;
const FlagDef *p;
@@ -1703,7 +1626,7 @@ static int set_flag(TCCState *S, const FlagDef *flags, const char *name)
continue;
}
- f = (unsigned char *)S + p->offset;
+ f = (unsigned char *)s + p->offset;
*f = (*f & mask) | (value ^ !!(p->flags & FD_INVERT));
if (ret) {
@@ -1715,15 +1638,15 @@ static int set_flag(TCCState *S, const FlagDef *flags, const char *name)
return ret;
}
-static void args_parser_add_file(TCCState *S, const char* filename, int filetype)
+static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
{
- struct filespec *f = tcc_malloc(S, sizeof *f + strlen(filename));
+ struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
f->type = filetype;
strcpy(f->name, filename);
- dynarray_add(S, &S->files, &S->nb_files, f);
+ dynarray_add(&s->files, &s->nb_files, f);
}
-static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char ***argv)
+static int args_parser_make_argv(const char *r, int *argc, char ***argv)
{
int ret = 0, q, c;
CString str;
@@ -1733,7 +1656,7 @@ static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char ***
if (c == 0)
break;
q = 0;
- cstr_new(S, &str);
+ cstr_new(&str);
while (c = (unsigned char)*r, c) {
++r;
if (c == '\\' && (*r == '"' || *r == '\\')) {
@@ -1744,21 +1667,22 @@ static int args_parser_make_argv(TCCState* S, const char *r, int *argc, char ***
} else if (q == 0 && c <= ' ') {
break;
}
- cstr_ccat(S, &str, c);
+ cstr_ccat(&str, c);
}
- cstr_ccat(S, &str, 0);
+ cstr_ccat(&str, 0);
//printf("<%s>\n", str.data), fflush(stdout);
- dynarray_add(S, argv, argc, tcc_strdup(S, str.data));
- cstr_free(S, &str);
+ dynarray_add(argv, argc, tcc_strdup(str.data));
+ cstr_free(&str);
++ret;
}
return ret;
}
/* read list file */
-static void args_parser_listfile(TCCState *S,
+static void args_parser_listfile(TCCState *s,
const char *filename, int optind, int *pargc, char ***pargv)
{
+ TCCState *s1 = s;
int fd, i;
char *p;
int argc = 0;
@@ -1766,22 +1690,23 @@ static void args_parser_listfile(TCCState *S,
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
- tcc_error(S, "listfile '%s' not found", filename);
+ tcc_error("listfile '%s' not found", filename);
- p = tcc_load_text(S, fd);
+ p = tcc_load_text(fd);
for (i = 0; i < *pargc; ++i)
if (i == optind)
- args_parser_make_argv(S, p, &argc, &argv);
+ args_parser_make_argv(p, &argc, &argv);
else
- dynarray_add(S, &argv, &argc, tcc_strdup(S, (*pargv)[i]));
+ dynarray_add(&argv, &argc, tcc_strdup((*pargv)[i]));
- tcc_free(S, p);
- dynarray_reset(S, &S->argv, &S->argc);
- *pargc = S->argc = argc, *pargv = S->argv = argv;
+ tcc_free(p);
+ dynarray_reset(&s->argv, &s->argc);
+ *pargc = s->argc = argc, *pargv = s->argv = argv;
}
-PUB_FUNC int tcc_parse_args(TCCState *S, int *pargc, char ***pargv, int optind)
+PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv, int optind)
{
+ TCCState *s1 = s;
const TCCOption *popt;
const char *optarg, *r;
const char *run = NULL;
@@ -1791,26 +1716,26 @@ PUB_FUNC int tcc_parse_args(TCCState *S, int *pargc, char ***pargv, int optind)
char **argv = *pargv;
int argc = *pargc;
- cstr_new(S, &linker_arg);
+ cstr_new(&linker_arg);
while (optind < argc) {
r = argv[optind];
if (r[0] == '@' && r[1] != '\0') {
- args_parser_listfile(S, r + 1, optind, &argc, &argv);
+ args_parser_listfile(s, r + 1, optind, &argc, &argv);
continue;
}
optind++;
if (tool) {
if (r[0] == '-' && r[1] == 'v' && r[2] == 0)
- ++S->verbose;
+ ++s->verbose;
continue;
}
reparse:
if (r[0] != '-' || r[1] == '\0') {
if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */
- args_parser_add_file(S, r, S->filetype);
+ args_parser_add_file(s, r, s->filetype);
if (run) {
- tcc_set_options(S, run);
+ tcc_set_options(s, run);
arg_start = optind - 1;
break;
}
@@ -1822,7 +1747,7 @@ reparse:
const char *p1 = popt->name;
const char *r1 = r + 1;
if (p1 == NULL)
- tcc_error(S, "invalid option -- '%s'", r);
+ tcc_error("invalid option -- '%s'", r);
if (!strstart(p1, &r1))
continue;
optarg = r1;
@@ -1830,7 +1755,7 @@ reparse:
if (*r1 == '\0' && !(popt->flags & TCC_OPTION_NOSEP)) {
if (optind >= argc)
arg_err:
- tcc_error(S, "argument to '%s' is missing", r);
+ tcc_error("argument to '%s' is missing", r);
optarg = argv[optind++];
}
} else if (*r1 != '\0')
@@ -1846,132 +1771,132 @@ reparse:
x = OPT_HELP2;
goto extra_action;
case TCC_OPTION_I:
- tcc_add_include_path(S, optarg);
+ tcc_add_include_path(s, optarg);
break;
case TCC_OPTION_D:
- tcc_define_symbol(S, optarg, NULL);
+ tcc_define_symbol(s, optarg, NULL);
break;
case TCC_OPTION_U:
- tcc_undefine_symbol(S, optarg);
+ tcc_undefine_symbol(s, optarg);
break;
case TCC_OPTION_L:
- tcc_add_library_path(S, optarg);
+ tcc_add_library_path(s, optarg);
break;
case TCC_OPTION_B:
/* set tcc utilities path (mainly for tcc development) */
- tcc_set_lib_path(S, optarg);
+ tcc_set_lib_path(s, optarg);
break;
case TCC_OPTION_l:
- args_parser_add_file(S, optarg, AFF_TYPE_LIB | (S->filetype & ~AFF_TYPE_MASK));
- S->nb_libraries++;
+ args_parser_add_file(s, optarg, AFF_TYPE_LIB | (s->filetype & ~AFF_TYPE_MASK));
+ s->nb_libraries++;
break;
case TCC_OPTION_pthread:
- S->option_pthread = 1;
+ s->option_pthread = 1;
break;
case TCC_OPTION_bench:
- S->do_bench = 1;
+ s->do_bench = 1;
break;
#ifdef CONFIG_TCC_BACKTRACE
case TCC_OPTION_bt:
- S->rt_num_callers = atoi(optarg);
- S->do_backtrace = 1;
- S->do_debug = 1;
+ s->rt_num_callers = atoi(optarg);
+ s->do_backtrace = 1;
+ s->do_debug = 1;
break;
#endif
#ifdef CONFIG_TCC_BCHECK
case TCC_OPTION_b:
- S->do_bounds_check = 1;
- S->do_backtrace = 1;
- S->do_debug = 1;
+ s->do_bounds_check = 1;
+ s->do_backtrace = 1;
+ s->do_debug = 1;
break;
#endif
case TCC_OPTION_g:
- S->do_debug = 1;
+ s->do_debug = 1;
break;
case TCC_OPTION_c:
x = TCC_OUTPUT_OBJ;
set_output_type:
- if (S->output_type)
- tcc_warning(S, "-%s: overriding compiler action already specified", popt->name);
- S->output_type = x;
+ if (s->output_type)
+ tcc_warning("-%s: overriding compiler action already specified", popt->name);
+ s->output_type = x;
break;
case TCC_OPTION_d:
if (*optarg == 'D')
- S->dflag = TCC_OPTION_d_D;
+ s->dflag = 3;
else if (*optarg == 'M')
- S->dflag = TCC_OPTION_d_M;
+ s->dflag = 7;
else if (*optarg == 't')
- S->dflag = TCC_OPTION_d_t;
+ s->dflag = 16;
else if (isnum(*optarg))
- S->g_debug |= atoi(optarg);
+ s->g_debug |= atoi(optarg);
else
goto unsupported_option;
break;
case TCC_OPTION_static:
- S->static_link = 1;
+ s->static_link = 1;
break;
case TCC_OPTION_std:
if (strcmp(optarg, "=c11") == 0)
- S->cversion = 201112;
+ s->cversion = 201112;
break;
case TCC_OPTION_shared:
x = TCC_OUTPUT_DLL;
goto set_output_type;
case TCC_OPTION_soname:
- S->soname = tcc_strdup(S, optarg);
+ s->soname = tcc_strdup(optarg);
break;
case TCC_OPTION_o:
- if (S->outfile) {
- tcc_warning(S, "multiple -o option");
- tcc_free(S, S->outfile);
+ if (s->outfile) {
+ tcc_warning("multiple -o option");
+ tcc_free(s->outfile);
}
- S->outfile = tcc_strdup(S, optarg);
+ s->outfile = tcc_strdup(optarg);
break;
case TCC_OPTION_r:
/* generate a .o merging several output files */
- S->option_r = 1;
+ s->option_r = 1;
x = TCC_OUTPUT_OBJ;
goto set_output_type;
case TCC_OPTION_isystem:
- tcc_add_sysinclude_path(S, optarg);
+ tcc_add_sysinclude_path(s, optarg);
break;
case TCC_OPTION_include:
- cstr_printf(S, &S->cmdline_incl, "#include \"%s\"\n", optarg);
+ cstr_printf(&s->cmdline_incl, "#include \"%s\"\n", optarg);
break;
case TCC_OPTION_nostdinc:
- S->nostdinc = 1;
+ s->nostdinc = 1;
break;
case TCC_OPTION_nostdlib:
- S->nostdlib = 1;
+ s->nostdlib = 1;
break;
case TCC_OPTION_run:
#ifndef TCC_IS_NATIVE
- tcc_error(S, "-run is not available in a cross compiler");
+ tcc_error("-run is not available in a cross compiler");
#endif
run = optarg;
x = TCC_OUTPUT_MEMORY;
goto set_output_type;
case TCC_OPTION_v:
- do ++S->verbose; while (*optarg++ == 'v');
+ do ++s->verbose; while (*optarg++ == 'v');
++noaction;
break;
case TCC_OPTION_f:
- if (set_flag(S, options_f, optarg) < 0)
+ if (set_flag(s, options_f, optarg) < 0)
goto unsupported_option;
break;
#ifdef TCC_TARGET_ARM
case TCC_OPTION_mfloat_abi:
/* tcc doesn't support soft float yet */
if (!strcmp(optarg, "softfp")) {
- S->float_abi = ARM_SOFTFP_FLOAT;
+ s->float_abi = ARM_SOFTFP_FLOAT;
} else if (!strcmp(optarg, "hard"))
- S->float_abi = ARM_HARD_FLOAT;
+ s->float_abi = ARM_HARD_FLOAT;
else
- tcc_error(S, "unsupported float abi '%s'", optarg);
+ tcc_error("unsupported float abi '%s'", optarg);
break;
#endif
case TCC_OPTION_m:
- if (set_flag(S, options_m, optarg) < 0) {
+ if (set_flag(s, options_m, optarg) < 0) {
if (x = atoi(optarg), x != 32 && x != 64)
goto unsupported_option;
if (PTR_SIZE != x/8)
@@ -1980,22 +1905,22 @@ reparse:
}
break;
case TCC_OPTION_W:
- S->warn_none = 0;
- if (optarg[0] && set_flag(S, options_W, optarg) < 0)
+ s->warn_none = 0;
+ if (optarg[0] && set_flag(s, options_W, optarg) < 0)
goto unsupported_option;
break;
case TCC_OPTION_w:
- S->warn_none = 1;
+ s->warn_none = 1;
break;
case TCC_OPTION_rdynamic:
- S->rdynamic = 1;
+ s->rdynamic = 1;
break;
case TCC_OPTION_Wl:
if (linker_arg.size)
- --linker_arg.size, cstr_ccat(S, &linker_arg, ',');
- cstr_cat(S, &linker_arg, optarg, 0);
- if (tcc_set_linker(S, linker_arg.data))
- cstr_free(S, &linker_arg);
+ --linker_arg.size, cstr_ccat(&linker_arg, ',');
+ cstr_cat(&linker_arg, optarg, 0);
+ if (tcc_set_linker(s, linker_arg.data))
+ cstr_free(&linker_arg);
break;
case TCC_OPTION_Wp:
r = optarg;
@@ -2004,25 +1929,25 @@ reparse:
x = TCC_OUTPUT_PREPROCESS;
goto set_output_type;
case TCC_OPTION_P:
- S->Pflag = atoi(optarg) + 1;
+ s->Pflag = atoi(optarg) + 1;
break;
case TCC_OPTION_M:
- S->include_sys_deps = 1;
+ s->include_sys_deps = 1;
// fall through
case TCC_OPTION_MM:
- S->just_deps = 1;
- if(!S->deps_outfile)
- S->deps_outfile = tcc_strdup(S, "-");
+ s->just_deps = 1;
+ if(!s->deps_outfile)
+ s->deps_outfile = tcc_strdup("-");
// fall through
case TCC_OPTION_MMD:
- S->gen_deps = 1;
+ s->gen_deps = 1;
break;
case TCC_OPTION_MD:
- S->gen_deps = 1;
- S->include_sys_deps = 1;
+ s->gen_deps = 1;
+ s->include_sys_deps = 1;
break;
case TCC_OPTION_MF:
- S->deps_outfile = tcc_strdup(S, optarg);
+ s->deps_outfile = tcc_strdup(optarg);
break;
case TCC_OPTION_dumpversion:
printf ("%s\n", TCC_VERSION);
@@ -2039,11 +1964,11 @@ reparse:
else if (*optarg == 'n')
x = AFF_TYPE_NONE;
else
- tcc_warning(S, "unsupported language '%s'", optarg);
- S->filetype = x | (S->filetype & ~AFF_TYPE_MASK);
+ tcc_warning("unsupported language '%s'", optarg);
+ s->filetype = x | (s->filetype & ~AFF_TYPE_MASK);
break;
case TCC_OPTION_O:
- S->optimize = atoi(optarg);
+ s->optimize = atoi(optarg);
break;
case TCC_OPTION_print_search_dirs:
x = OPT_PRINT_DIRS;
@@ -2056,12 +1981,12 @@ reparse:
extra_action:
arg_start = optind - 1;
if (arg_start != noaction)
- tcc_error(S, "cannot parse %s here", r);
+ tcc_error("cannot parse %s here", r);
tool = x;
break;
default:
unsupported_option:
- tcc_warning_c(warn_unsupported)(S, "unsupported option '%s'", r);
+ tcc_warning_c(warn_unsupported)("unsupported option '%s'", r);
break;
}
}
@@ -2075,23 +2000,23 @@ unsupported_option:
return tool;
if (optind != noaction)
return 0;
- if (S->verbose == 2)
+ if (s->verbose == 2)
return OPT_PRINT_DIRS;
- if (S->verbose)
+ if (s->verbose)
return OPT_V;
return OPT_HELP;
}
-LIBTCCAPI void tcc_set_options(TCCState *S, const char *r)
+LIBTCCAPI void tcc_set_options(TCCState *s, const char *r)
{
char **argv = NULL;
int argc = 0;
- args_parser_make_argv(S, r, &argc, &argv);
- tcc_parse_args(S, &argc, &argv, 0);
- dynarray_reset(S, &argv, &argc);
+ args_parser_make_argv(r, &argc, &argv);
+ tcc_parse_args(s, &argc, &argv, 0);
+ dynarray_reset(&argv, &argc);
}
-PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time)
+PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time)
{
if (total_time < 1)
total_time = 1;
@@ -2104,14 +2029,12 @@ PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time)
(unsigned)total_lines*1000/total_time,
(double)total_bytes/1000/total_time);
fprintf(stderr, "* text %d, data.rw %d, data.ro %d, bss %d bytes\n",
- S->total_output[0],
- S->total_output[1],
- S->total_output[2],
- S->total_output[3]
+ s1->total_output[0],
+ s1->total_output[1],
+ s1->total_output[2],
+ s1->total_output[3]
);
#ifdef MEM_DEBUG
fprintf(stderr, "* %d bytes memory used\n", mem_max_size);
#endif
}
-
-#include "tccqsort.c"
diff --git a/libtcc.h b/libtcc.h
index 226cfd7..25d247a 100644
--- a/libtcc.h
+++ b/libtcc.h
@@ -15,95 +15,56 @@ typedef struct TCCState TCCState;
typedef void (*TCCErrorFunc)(void *opaque, const char *msg);
-#ifndef _OFF_T_DEFINED
-#define _OFF_T_DEFINED
-#ifndef _OFF_T_
-#define _OFF_T_
- typedef long _off_t;
-#ifndef _SIZE_T_
-#define _SIZE_T_
- typedef unsigned long size_t;
-#endif
-#if !defined(NO_OLDNAMES) || defined(_POSIX)
- typedef long off_t;
-#endif
-#endif
-#endif
-
-struct vio_module_t;
-
-typedef struct vio_fd {
- int fd;
- void *vio_udata;
- struct vio_module_t *vio_module;
-} vio_fd;
-
-#define CALL_VIO_OPEN_FIRST 0x01
-#define CALL_VIO_OPEN_LAST 0x02
-
-typedef struct vio_module_t {
- void *user_data;
- struct TCCState *S;
- int call_vio_open_flags; /*CALL_VIO_OPEN_FIRST, CALL_VIO_OPEN_LAST, one or both */
- int (*vio_open)(vio_fd *fd, const char *fn, int oflag) ;
- off_t (*vio_lseek)(vio_fd fd, off_t offset, int whence);
- size_t (*vio_read)(vio_fd fd, void *buf, size_t bytes);
- int (*vio_close)(vio_fd *fd);
-} vio_module_t;
-
/* create a new TCC compilation context */
LIBTCCAPI TCCState *tcc_new(void);
/* free a TCC compilation context */
-LIBTCCAPI void tcc_delete(TCCState *S);
+LIBTCCAPI void tcc_delete(TCCState *s);
/* set CONFIG_TCCDIR at runtime */
-LIBTCCAPI void tcc_set_lib_path(TCCState *S, const char *path);
+LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
/* set error/warning display callback */
-LIBTCCAPI void tcc_set_error_func(TCCState *S, void *error_opaque, TCCErrorFunc error_func);
+LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque, TCCErrorFunc error_func);
/* return error/warning callback */
-LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *S);
+LIBTCCAPI TCCErrorFunc tcc_get_error_func(TCCState *s);
/* return error/warning callback opaque pointer */
-LIBTCCAPI void *tcc_get_error_opaque(TCCState *S);
+LIBTCCAPI void *tcc_get_error_opaque(TCCState *s);
/* set options as from command line (multiple supported) */
-LIBTCCAPI void tcc_set_options(TCCState *S, const char *str);
-
-/* set virtual io module */
-LIBTCCAPI void tcc_set_vio_module(TCCState *S, vio_module_t *vio_module);
+LIBTCCAPI void tcc_set_options(TCCState *s, const char *str);
/*****************************/
/* preprocessor */
/* add include path */
-LIBTCCAPI int tcc_add_include_path(TCCState *S, const char *pathname);
+LIBTCCAPI int tcc_add_include_path(TCCState *s, const char *pathname);
/* add in system include path */
-LIBTCCAPI int tcc_add_sysinclude_path(TCCState *S, const char *pathname);
+LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname);
/* define preprocessor symbol 'sym'. value can be NULL, sym can be "sym=val" */
-LIBTCCAPI void tcc_define_symbol(TCCState *S, const char *sym, const char *value);
+LIBTCCAPI void tcc_define_symbol(TCCState *s, const char *sym, const char *value);
/* undefine preprocess symbol 'sym' */
-LIBTCCAPI void tcc_undefine_symbol(TCCState *S, const char *sym);
+LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym);
/*****************************/
/* compiling */
/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
-LIBTCCAPI int tcc_add_file(TCCState *S, const char *filename);
+LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);
/* compile a string containing a C source. Return -1 if error. */
-LIBTCCAPI int tcc_compile_string(TCCState *S, const char *buf);
+LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
/*****************************/
/* linking commands */
/* set output type. MUST BE CALLED before any compilation */
-LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type);
+LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type);
#define TCC_OUTPUT_MEMORY 1 /* output will be run in memory (default) */
#define TCC_OUTPUT_EXE 2 /* executable file */
#define TCC_OUTPUT_DLL 3 /* dynamic library */
@@ -111,24 +72,24 @@ LIBTCCAPI int tcc_set_output_type(TCCState *S, int output_type);
#define TCC_OUTPUT_PREPROCESS 5 /* only preprocess (used internally) */
/* equivalent to -Lpath option */
-LIBTCCAPI int tcc_add_library_path(TCCState *S, const char *pathname);
+LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname);
/* the library name is the same as the argument of the '-l' option */
-LIBTCCAPI int tcc_add_library(TCCState *S, const char *libraryname);
+LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname);
/* add a symbol to the compiled program */
-LIBTCCAPI int tcc_add_symbol(TCCState *S, const char *name, const void *val);
+LIBTCCAPI int tcc_add_symbol(TCCState *s, const char *name, const void *val);
/* output an executable, library or object file. DO NOT call
tcc_relocate() before. */
-LIBTCCAPI int tcc_output_file(TCCState *S, const char *filename);
+LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename);
/* link and run main() function and return its value. DO NOT call
tcc_relocate() before. */
-LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv);
+LIBTCCAPI int tcc_run(TCCState *s, int argc, char **argv);
/* do all relocations (needed before using tcc_get_symbol()) */
-LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr);
+LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr);
/* possible values for 'ptr':
- TCC_RELOCATE_AUTO : Allocate and manage memory internally
- NULL : return required memory size for the step below
@@ -137,24 +98,12 @@ LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr);
#define TCC_RELOCATE_AUTO (void*)1
/* return symbol value or NULL if not found */
-LIBTCCAPI void *tcc_get_symbol(TCCState *S, const char *name);
+LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name);
/* return symbol value or NULL if not found */
-LIBTCCAPI void tcc_list_symbols(TCCState *S, void *ctx,
+LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
void (*symbol_cb)(void *ctx, const char *name, const void *val));
-typedef int (*tcc_cmpfun)(const void *, const void *, void *);
-LIBTCCAPI void tcc_qsort_s(void *base, size_t nel, size_t width, tcc_cmpfun cmp, void *ctx);
-
-enum { /*need better names for some of then*/
- TCC_OPTION_d_BI = 1,
- TCC_OPTION_d_D = 3,
- TCC_OPTION_d_4 = 4,
- TCC_OPTION_d_M = 7,
- TCC_OPTION_d_t = 16,
- TCC_OPTION_d_32 = 32,
-};
-
#ifdef __cplusplus
}
#endif
diff --git a/riscv64-asm.c b/riscv64-asm.c
index fbb60ba..30662df 100644
--- a/riscv64-asm.c
+++ b/riscv64-asm.c
@@ -9,9 +9,9 @@
#define CONFIG_TCC_ASM
#define NB_ASM_REGS 32
-ST_FUNC void g(TCCState* S, int c);
-ST_FUNC void gen_le16(TCCState* S, int c);
-ST_FUNC void gen_le32(TCCState* S, int c);
+ST_FUNC void g(int c);
+ST_FUNC void gen_le16(int c);
+ST_FUNC void gen_le32(int c);
/*************************************************************/
#else
@@ -20,85 +20,85 @@ ST_FUNC void gen_le32(TCCState* S, int c);
#include "tcc.h"
/* XXX: make it faster ? */
-ST_FUNC void g(TCCState* S, int c)
+ST_FUNC void g(int c)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 1;
+ ind1 = ind + 1;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind] = c;
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind] = c;
+ ind = ind1;
}
-ST_FUNC void gen_le16 (TCCState* S, int i)
+ST_FUNC void gen_le16 (int i)
{
- g(S, i);
- g(S, i>>8);
+ g(i);
+ g(i>>8);
}
-ST_FUNC void gen_le32 (TCCState* S, int i)
+ST_FUNC void gen_le32 (int i)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 4;
+ ind1 = ind + 4;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind++] = i & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 8) & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 16) & 0xFF;
- cur_text_section->data[S->tccgen_ind++] = (i >> 24) & 0xFF;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind++] = i & 0xFF;
+ cur_text_section->data[ind++] = (i >> 8) & 0xFF;
+ cur_text_section->data[ind++] = (i >> 16) & 0xFF;
+ cur_text_section->data[ind++] = (i >> 24) & 0xFF;
}
-ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe)
+ST_FUNC void gen_expr32(ExprValue *pe)
{
- gen_le32(S, pe->v);
+ gen_le32(pe->v);
}
-static void asm_emit_opcode(TCCState* S, uint32_t opcode) {
- gen_le32(S, opcode);
+static void asm_emit_opcode(uint32_t opcode) {
+ gen_le32(opcode);
}
-static void asm_nullary_opcode(TCCState *S, int token)
+static void asm_nullary_opcode(TCCState *s1, int token)
{
switch (token) {
// Sync instructions
case TOK_ASM_fence: // I
- asm_emit_opcode(S, (0x3 << 2) | 3 | (0 << 12));
+ asm_emit_opcode((0x3 << 2) | 3 | (0 << 12));
return;
case TOK_ASM_fence_i: // I
- asm_emit_opcode(S, (0x3 << 2) | 3| (1 << 12));
+ asm_emit_opcode((0x3 << 2) | 3| (1 << 12));
return;
// System calls
case TOK_ASM_scall: // I (pseudo)
- asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 12));
+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 12));
return;
case TOK_ASM_sbreak: // I (pseudo)
- asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 12) | (1 << 20));
+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 12) | (1 << 20));
return;
// Privileged Instructions
case TOK_ASM_ecall:
- asm_emit_opcode(S, (0x1C << 2) | 3 | (0 << 20));
+ asm_emit_opcode((0x1C << 2) | 3 | (0 << 20));
return;
case TOK_ASM_ebreak:
- asm_emit_opcode(S, (0x1C << 2) | 3 | (1 << 20));
+ asm_emit_opcode((0x1C << 2) | 3 | (1 << 20));
return;
// Other
case TOK_ASM_wfi:
- asm_emit_opcode(S, (0x1C << 2) | 3 | (0x105 << 20));
+ asm_emit_opcode((0x1C << 2) | 3 | (0x105 << 20));
return;
default:
- expect(S, "nullary instruction");
+ expect("nullary instruction");
}
}
@@ -121,30 +121,30 @@ typedef struct Operand {
} Operand;
/* Parse a text containing operand and store the result in OP */
-static void parse_operand(TCCState *S, Operand *op)
+static void parse_operand(TCCState *s1, Operand *op)
{
ExprValue e;
int8_t reg;
op->type = 0;
- if ((reg = asm_parse_regvar(S, S->tccpp_tok)) != -1) {
- next(S); // skip register name
+ if ((reg = asm_parse_regvar(tok)) != -1) {
+ next(); // skip register name
op->type = OP_REG;
op->reg = (uint8_t) reg;
return;
- } else if (S->tccpp_tok == '$') {
+ } else if (tok == '$') {
/* constant value */
- next(S); // skip '#' or '$'
+ next(); // skip '#' or '$'
}
- asm_expr(S, &e);
+ asm_expr(s1, &e);
op->type = OP_IM32;
op->e = e;
if (!op->e.sym) {
if ((int) op->e.v >= -2048 && (int) op->e.v < 2048)
op->type = OP_IM12S;
} else
- expect(S, "operand");
+ expect("operand");
}
#define ENCODE_RS1(register_index) ((register_index) << 15)
@@ -152,96 +152,96 @@ static void parse_operand(TCCState *S, Operand *op)
#define ENCODE_RD(register_index) ((register_index) << 7)
// Note: Those all map to CSR--so they are pseudo-instructions.
-static void asm_unary_opcode(TCCState *S, int token)
+static void asm_unary_opcode(TCCState *s1, int token)
{
uint32_t opcode = (0x1C << 2) | 3 | (2 << 12);
Operand op;
- parse_operand(S, &op);
+ parse_operand(s1, &op);
if (op.type != OP_REG) {
- expect(S, "register");
+ expect("register");
return;
}
opcode |= ENCODE_RD(op.reg);
switch (token) {
case TOK_ASM_rdcycle:
- asm_emit_opcode(S, opcode | (0xC00 << 20));
+ asm_emit_opcode(opcode | (0xC00 << 20));
return;
case TOK_ASM_rdcycleh:
- asm_emit_opcode(S, opcode | (0xC80 << 20));
+ asm_emit_opcode(opcode | (0xC80 << 20));
return;
case TOK_ASM_rdtime:
- asm_emit_opcode(S, opcode | (0xC01 << 20) | ENCODE_RD(op.reg));
+ asm_emit_opcode(opcode | (0xC01 << 20) | ENCODE_RD(op.reg));
return;
case TOK_ASM_rdtimeh:
- asm_emit_opcode(S, opcode | (0xC81 << 20) | ENCODE_RD(op.reg));
+ asm_emit_opcode(opcode | (0xC81 << 20) | ENCODE_RD(op.reg));
return;
case TOK_ASM_rdinstret:
- asm_emit_opcode(S, opcode | (0xC02 << 20) | ENCODE_RD(op.reg));
+ asm_emit_opcode(opcode | (0xC02 << 20) | ENCODE_RD(op.reg));
return;
case TOK_ASM_rdinstreth:
- asm_emit_opcode(S, opcode | (0xC82 << 20) | ENCODE_RD(op.reg));
+ asm_emit_opcode(opcode | (0xC82 << 20) | ENCODE_RD(op.reg));
return;
default:
- expect(S, "unary instruction");
+ expect("unary instruction");
}
}
-static void asm_emit_u(TCCState *S, int token, uint32_t opcode, const Operand* rd, const Operand* rs2)
+static void asm_emit_u(int token, uint32_t opcode, const Operand* rd, const Operand* rs2)
{
if (rd->type != OP_REG) {
- tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs2->type != OP_IM12S && rs2->type != OP_IM32) {
- tcc_error(S, "'%s': Expected second source operand that is an immediate value", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected second source operand that is an immediate value", get_tok_str(token, NULL));
return;
} else if (rs2->e.v >= 0x100000) {
- tcc_error(S, "'%s': Expected second source operand that is an immediate value between 0 and 0xfffff", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected second source operand that is an immediate value between 0 and 0xfffff", get_tok_str(token, NULL));
return;
}
/* U-type instruction:
31...12 imm[31:12]
11...7 rd
6...0 opcode */
- gen_le32(S, opcode | ENCODE_RD(rd->reg) | (rs2->e.v << 12));
+ gen_le32(opcode | ENCODE_RD(rd->reg) | (rs2->e.v << 12));
}
-static void asm_binary_opcode(TCCState* S, int token)
+static void asm_binary_opcode(TCCState* s1, int token)
{
Operand ops[2];
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == ',')
- next(S);
+ parse_operand(s1, &ops[0]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
+ expect("','");
+ parse_operand(s1, &ops[1]);
switch (token) {
case TOK_ASM_lui:
- asm_emit_u(S, token, (0xD << 2) | 3, &ops[0], &ops[1]);
+ asm_emit_u(token, (0xD << 2) | 3, &ops[0], &ops[1]);
return;
case TOK_ASM_auipc:
- asm_emit_u(S, token, (0x05 << 2) | 3, &ops[0], &ops[1]);
+ asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]);
return;
default:
- expect(S, "binary instruction");
+ expect("binary instruction");
}
}
/* caller: Add funct3, funct7 into opcode */
-static void asm_emit_r(TCCState* S, int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
+static void asm_emit_r(int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
{
if (rd->type != OP_REG) {
- tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs1->type != OP_REG) {
- tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs2->type != OP_REG) {
- tcc_error(S, "'%s': Expected second source operand that is a register or immediate", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected second source operand that is a register or immediate", get_tok_str(token, NULL));
return;
}
/* R-type instruction:
@@ -251,22 +251,22 @@ static void asm_emit_r(TCCState* S, int token, uint32_t opcode, const Operand* r
14...12 funct3
11...7 rd
6...0 opcode */
- gen_le32(S, opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg));
+ gen_le32(opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg));
}
/* caller: Add funct3 into opcode */
-static void asm_emit_i(TCCState* S, int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
+static void asm_emit_i(int token, uint32_t opcode, const Operand* rd, const Operand* rs1, const Operand* rs2)
{
if (rd->type != OP_REG) {
- tcc_error(S, "'%s': Expected destination operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected destination operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs1->type != OP_REG) {
- tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs2->type != OP_IM12S) {
- tcc_error(S, "'%s': Expected second source operand that is an immediate value between 0 and 4095", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected second source operand that is an immediate value between 0 and 4095", get_tok_str(token, NULL));
return;
}
/* I-type instruction:
@@ -276,156 +276,156 @@ static void asm_emit_i(TCCState* S, int token, uint32_t opcode, const Operand* r
11...7 rd
6...0 opcode */
- gen_le32(S, opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | (rs2->e.v << 20));
+ gen_le32(opcode | ENCODE_RD(rd->reg) | ENCODE_RS1(rs1->reg) | (rs2->e.v << 20));
}
-static void asm_shift_opcode(TCCState *S, int token)
+static void asm_shift_opcode(TCCState *s1, int token)
{
Operand ops[3];
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == ',')
- next(S);
+ parse_operand(s1, &ops[0]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
- if (S->tccpp_tok == ',')
- next(S);
+ expect("','");
+ parse_operand(s1, &ops[1]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[2]);
+ expect("','");
+ parse_operand(s1, &ops[2]);
switch (token) {
case TOK_ASM_sll:
- asm_emit_r(S, token, (0xC << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_slli:
- asm_emit_i(S, token, (4 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (4 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_srl:
- asm_emit_r(S, token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_srli:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sra:
- asm_emit_r(S, token, (0xC << 2) | 3 | (5 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (5 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_srai:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (5 << 12) | (16 << 26), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (5 << 12) | (16 << 26), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sllw:
- asm_emit_r(S, token, (0xE << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xE << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_slliw:
- asm_emit_i(S, token, (6 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (6 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_srlw:
- asm_emit_r(S, token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_srliw:
- asm_emit_i(S, token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sraw:
- asm_emit_r(S, token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xE << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sraiw:
- asm_emit_i(S, token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x6 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
default:
- expect(S, "shift instruction");
+ expect("shift instruction");
}
}
-static void asm_data_processing_opcode(TCCState* S, int token)
+static void asm_data_processing_opcode(TCCState* s1, int token)
{
Operand ops[3];
- parse_operand(S, &ops[0]);
- if (S->tccpp_tok == ',')
- next(S);
+ parse_operand(s1, &ops[0]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
- if (S->tccpp_tok == ',')
- next(S);
+ expect("','");
+ parse_operand(s1, &ops[1]);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[2]);
+ expect("','");
+ parse_operand(s1, &ops[2]);
switch (token) {
// Arithmetic (RD,RS1,(RS2|IMM)); R-format, I-format or U-format
case TOK_ASM_add:
- asm_emit_r(S, token, (0xC << 2) | 3, &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3, &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_addi:
- asm_emit_i(S, token, (4 << 2) | 3, &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (4 << 2) | 3, &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sub:
- asm_emit_r(S, token, (0xC << 2) | 3 | (32 << 25), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (32 << 25), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_addw:
- asm_emit_r(S, token, (0xE << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xE << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_addiw: // 64 bit
- asm_emit_i(S, token, (0x6 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x6 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_subw:
- asm_emit_r(S, token, (0xE << 2) | 3 | (0 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xE << 2) | 3 | (0 << 12) | (32 << 25), &ops[0], &ops[1], &ops[2]);
return;
// Logical (RD,RS1,(RS2|IMM)); R-format or I-format
case TOK_ASM_xor:
- asm_emit_r(S, token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_xori:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_or:
- asm_emit_r(S, token, (0xC << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_ori:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_and:
- asm_emit_r(S, token, (0xC << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_andi:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (7 << 12), &ops[0], &ops[1], &ops[2]);
return;
// Compare (RD,RS1,(RS2|IMM)); R-format or I-format
case TOK_ASM_slt:
- asm_emit_r(S, token, (0xC << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_slti:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sltu:
- asm_emit_r(S, token, (0xC << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_r(token, (0xC << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sltiu:
- asm_emit_i(S, token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x4 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
return;
default:
- expect(S, "known data processing instruction");
+ expect("known data processing instruction");
}
}
/* caller: Add funct3 to opcode */
-static void asm_emit_s(TCCState* S, int token, uint32_t opcode, const Operand* rs1, const Operand* rs2, const Operand* imm)
+static void asm_emit_s(int token, uint32_t opcode, const Operand* rs1, const Operand* rs2, const Operand* imm)
{
if (rs1->type != OP_REG) {
- tcc_error(S, "'%s': Expected first source operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected first source operand that is a register", get_tok_str(token, NULL));
return;
}
if (rs2->type != OP_REG) {
- tcc_error(S, "'%s': Expected second source operand that is a register", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected second source operand that is a register", get_tok_str(token, NULL));
return;
}
if (imm->type != OP_IM12S) {
- tcc_error(S, "'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(token, NULL));
return;
}
{
@@ -438,112 +438,112 @@ static void asm_emit_s(TCCState* S, int token, uint32_t opcode, const Operand* r
11...7 imm[4:0]
6...0 opcode
opcode always fixed pos. */
- gen_le32(S, opcode | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg) | ((v & 0x1F) << 7) | ((v >> 5) << 25));
+ gen_le32(opcode | ENCODE_RS1(rs1->reg) | ENCODE_RS2(rs2->reg) | ((v & 0x1F) << 7) | ((v >> 5) << 25));
}
}
-static void asm_data_transfer_opcode(TCCState* S, int token)
+static void asm_data_transfer_opcode(TCCState* s1, int token)
{
Operand ops[3];
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
if (ops[0].type != OP_REG) {
- expect(S, "register");
+ expect("register");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
+ expect("','");
+ parse_operand(s1, &ops[1]);
if (ops[1].type != OP_REG) {
- expect(S, "register");
+ expect("register");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[2]);
+ expect("','");
+ parse_operand(s1, &ops[2]);
switch (token) {
// Loads (RD,RS1,I); I-format
case TOK_ASM_lb:
- asm_emit_i(S, token, (0x0 << 2) | 3, &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3, &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_lh:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_lw:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_lbu:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (4 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_lhu:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (5 << 12), &ops[0], &ops[1], &ops[2]);
return;
// 64 bit
case TOK_ASM_ld:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_lwu:
- asm_emit_i(S, token, (0x0 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_i(token, (0x0 << 2) | 3 | (6 << 12), &ops[0], &ops[1], &ops[2]);
return;
// Stores (RS1,RS2,I); S-format
case TOK_ASM_sb:
- asm_emit_s(S, token, (0x8 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_s(token, (0x8 << 2) | 3 | (0 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sh:
- asm_emit_s(S, token, (0x8 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_s(token, (0x8 << 2) | 3 | (1 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sw:
- asm_emit_s(S, token, (0x8 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_s(token, (0x8 << 2) | 3 | (2 << 12), &ops[0], &ops[1], &ops[2]);
return;
case TOK_ASM_sd:
- asm_emit_s(S, token, (0x8 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
+ asm_emit_s(token, (0x8 << 2) | 3 | (3 << 12), &ops[0], &ops[1], &ops[2]);
return;
default:
- expect(S, "known data transfer instruction");
+ expect("known data transfer instruction");
}
}
-static void asm_branch_opcode(TCCState* S, int token)
+static void asm_branch_opcode(TCCState* s1, int token)
{
// Branch (RS1,RS2,IMM); SB-format
uint32_t opcode = (0x18 << 2) | 3;
uint32_t offset = 0;
Operand ops[3];
- parse_operand(S, &ops[0]);
+ parse_operand(s1, &ops[0]);
if (ops[0].type != OP_REG) {
- expect(S, "register");
+ expect("register");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[1]);
+ expect("','");
+ parse_operand(s1, &ops[1]);
if (ops[1].type != OP_REG) {
- expect(S, "register");
+ expect("register");
return;
}
- if (S->tccpp_tok == ',')
- next(S);
+ if (tok == ',')
+ next();
else
- expect(S, "','");
- parse_operand(S, &ops[2]);
+ expect("','");
+ parse_operand(s1, &ops[2]);
if (ops[2].type != OP_IM12S) {
- tcc_error(S, "'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected third operand that is an immediate value between 0 and 0xfff", get_tok_str(token, NULL));
return;
}
offset = ops[2].e.v;
if (offset & 1) {
- tcc_error(S, "'%s': Expected third operand that is an even immediate value", get_tok_str(S, token, NULL));
+ tcc_error("'%s': Expected third operand that is an even immediate value", get_tok_str(token, NULL));
return;
}
@@ -567,12 +567,12 @@ static void asm_branch_opcode(TCCState* S, int token)
opcode |= 7 << 12;
break;
default:
- expect(S, "known branch instruction");
+ expect("known branch instruction");
}
- 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));
+ 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));
}
-ST_FUNC void asm_opcode(TCCState *S, int token)
+ST_FUNC void asm_opcode(TCCState *s1, int token)
{
switch (token) {
case TOK_ASM_fence:
@@ -585,7 +585,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_mrth:
case TOK_ASM_hrts:
case TOK_ASM_wfi:
- asm_nullary_opcode(S, token);
+ asm_nullary_opcode(s1, token);
return;
case TOK_ASM_rdcycle:
@@ -594,12 +594,12 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_rdtimeh:
case TOK_ASM_rdinstret:
case TOK_ASM_rdinstreth:
- asm_unary_opcode(S, token);
+ asm_unary_opcode(s1, token);
return;
case TOK_ASM_lui:
case TOK_ASM_auipc:
- asm_binary_opcode(S, token);
+ asm_binary_opcode(s1, token);
return;
case TOK_ASM_sll:
@@ -620,7 +620,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_srad:
case TOK_ASM_sraiw:
case TOK_ASM_sraid:
- asm_shift_opcode(S, token);
+ asm_shift_opcode(s1, token);
return;
case TOK_ASM_add:
@@ -642,7 +642,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_slti:
case TOK_ASM_sltu:
case TOK_ASM_sltiu:
- asm_data_processing_opcode(S, token);
+ asm_data_processing_opcode(s1, token);
case TOK_ASM_lb:
case TOK_ASM_lh:
@@ -655,7 +655,7 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_sh:
case TOK_ASM_sw:
case TOK_ASM_sd:
- asm_data_transfer_opcode(S, token);
+ asm_data_transfer_opcode(s1, token);
return;
case TOK_ASM_beq:
@@ -664,35 +664,35 @@ ST_FUNC void asm_opcode(TCCState *S, int token)
case TOK_ASM_bge:
case TOK_ASM_bltu:
case TOK_ASM_bgeu:
- asm_branch_opcode(S, token);
+ asm_branch_opcode(s1, token);
return;
default:
- expect(S, "known instruction");
+ expect("known instruction");
}
}
-ST_FUNC void subst_asm_operand(TCCState *S, CString *add_str, SValue *sv, int modifier)
+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
{
- tcc_error(S, "RISCV64 asm not implemented.");
+ tcc_error("RISCV64 asm not implemented.");
}
/* generate prolog and epilog code for asm statement */
-ST_FUNC void asm_gen_code(TCCState *S, ASMOperand *operands, int nb_operands,
+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
int nb_outputs, int is_output,
uint8_t *clobber_regs,
int out_reg)
{
}
-ST_FUNC void asm_compute_constraints(TCCState *S, ASMOperand *operands,
+ST_FUNC void asm_compute_constraints(ASMOperand *operands,
int nb_operands, int nb_outputs,
const uint8_t *clobber_regs,
int *pout_reg)
{
}
-ST_FUNC void asm_clobber(TCCState *S, uint8_t *clobber_regs, const char *str)
+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
{
int reg;
TokenSym *ts;
@@ -701,15 +701,15 @@ ST_FUNC void asm_clobber(TCCState *S, uint8_t *clobber_regs, const char *str)
!strcmp(str, "cc") ||
!strcmp(str, "flags"))
return;
- ts = tok_alloc(S, str, strlen(str));
- reg = asm_parse_regvar(S, ts->tok);
+ ts = tok_alloc(str, strlen(str));
+ reg = asm_parse_regvar(ts->tok);
if (reg == -1) {
- tcc_error(S, "invalid clobber register '%s'", str);
+ tcc_error("invalid clobber register '%s'", str);
}
clobber_regs[reg] = 1;
}
-ST_FUNC int asm_parse_regvar (TCCState* S, int t)
+ST_FUNC int asm_parse_regvar (int t)
{
if (t >= TOK_ASM_x0 && t <= TOK_ASM_pc) { /* register name */
switch (t) {
diff --git a/riscv64-gen.c b/riscv64-gen.c
index 8a1ef7c..04b591f 100644
--- a/riscv64-gen.c
+++ b/riscv64-gen.c
@@ -74,6 +74,12 @@ ST_DATA const int reg_classes[NB_REGS] = {
1 << TREG_SP
};
+#if defined(CONFIG_TCC_BCHECK)
+static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
+ST_DATA int func_bound_add_epilog;
+#endif
+
static int ireg(int r)
{
if (r == TREG_RA)
@@ -100,46 +106,46 @@ static int is_freg(int r)
return r >= 8 && r < 16;
}
-ST_FUNC void o(TCCState* S, unsigned int c)
+ST_FUNC void o(unsigned int c)
{
- int ind1 = S->tccgen_ind + 4;
- if (S->tccgen_nocode_wanted)
+ int ind1 = ind + 4;
+ if (nocode_wanted)
return;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- write32le(cur_text_section->data + S->tccgen_ind, c);
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ write32le(cur_text_section->data + ind, c);
+ ind = ind1;
}
-static void EIu(TCCState* S, uint32_t opcode, uint32_t func3,
+static void EIu(uint32_t opcode, uint32_t func3,
uint32_t rd, uint32_t rs1, uint32_t imm)
{
- o(S, opcode | (func3 << 12) | (rd << 7) | (rs1 << 15) | (imm << 20));
+ o(opcode | (func3 << 12) | (rd << 7) | (rs1 << 15) | (imm << 20));
}
-static void ER(TCCState* S, uint32_t opcode, uint32_t func3,
+static void ER(uint32_t opcode, uint32_t func3,
uint32_t rd, uint32_t rs1, uint32_t rs2, uint32_t func7)
{
- o(S, opcode | func3 << 12 | rd << 7 | rs1 << 15 | rs2 << 20 | func7 << 25);
+ o(opcode | func3 << 12 | rd << 7 | rs1 << 15 | rs2 << 20 | func7 << 25);
}
-static void EI(TCCState* S, uint32_t opcode, uint32_t func3,
+static void EI(uint32_t opcode, uint32_t func3,
uint32_t rd, uint32_t rs1, uint32_t imm)
{
assert(! ((imm + (1 << 11)) >> 12));
- EIu(S, opcode, func3, rd, rs1, imm);
+ EIu(opcode, func3, rd, rs1, imm);
}
-static void ES(TCCState* S, uint32_t opcode, uint32_t func3,
+static void ES(uint32_t opcode, uint32_t func3,
uint32_t rs1, uint32_t rs2, uint32_t imm)
{
assert(! ((imm + (1 << 11)) >> 12));
- o(S, opcode | (func3 << 12) | ((imm & 0x1f) << 7) | (rs1 << 15)
+ o(opcode | (func3 << 12) | ((imm & 0x1f) << 7) | (rs1 << 15)
| (rs2 << 20) | ((imm >> 5) << 25));
}
// Patch all branches in list pointed to by t to branch to a:
-ST_FUNC void gsym_addr(TCCState* S, int t_, int a_)
+ST_FUNC void gsym_addr(int t_, int a_)
{
uint32_t t = t_;
uint32_t a = a_;
@@ -148,7 +154,7 @@ ST_FUNC void gsym_addr(TCCState* S, int t_, int a_)
uint32_t next = read32le(ptr);
uint32_t r = a - t, imm;
if ((r + (1 << 21)) & ~((1U << 22) - 2))
- tcc_error(S, "out-of-range branch chain");
+ tcc_error("out-of-range branch chain");
imm = (((r >> 12) & 0xff) << 12)
| (((r >> 11) & 1) << 20)
| (((r >> 1) & 0x3ff) << 21)
@@ -158,7 +164,7 @@ ST_FUNC void gsym_addr(TCCState* S, int t_, int a_)
}
}
-static int load_symofs(TCCState* S, int r, SValue *sv, int forstore)
+static int load_symofs(int r, SValue *sv, int forstore)
{
int rr, doload = 0;
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)
Sym label = {0};
assert(v == VT_CONST);
if (sv->sym->type.t & VT_STATIC) { // XXX do this per linker relax
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind,
+ greloca(cur_text_section, sv->sym, ind,
R_RISCV_PCREL_HI20, sv->c.i);
sv->c.i = 0;
} else {
if (((unsigned)fc + (1 << 11)) >> 12)
- tcc_error(S, "unimp: large addend for global address (0x%lx)", (long)sv->c.i);
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind,
+ tcc_error("unimp: large addend for global address (0x%lx)", (long)sv->c.i);
+ greloca(cur_text_section, sv->sym, ind,
R_RISCV_GOT_HI20, 0);
doload = 1;
}
label.type.t = VT_VOID | VT_STATIC;
- put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
+ put_extern_sym(&label, cur_text_section, ind, 0);
rr = is_ireg(r) ? ireg(r) : 5;
- o(S, 0x17 | (rr << 7)); // auipc RR, 0 %pcrel_hi(sym)+addend
- greloca(S, cur_text_section, &label, S->tccgen_ind,
+ o(0x17 | (rr << 7)); // auipc RR, 0 %pcrel_hi(sym)+addend
+ greloca(cur_text_section, &label, ind,
doload || !forstore
? R_RISCV_PCREL_LO12_I : R_RISCV_PCREL_LO12_S, 0);
if (doload) {
- EI(S, 0x03, 3, rr, rr, 0); // ld RR, 0(RR)
+ EI(0x03, 3, rr, rr, 0); // ld RR, 0(RR)
}
} else if (v == VT_LOCAL || v == VT_LLOCAL) {
rr = 8; // s0
if (fc != sv->c.i)
- tcc_error(S, "unimp: store(giant local off) (0x%lx)", (long)sv->c.i);
+ tcc_error("unimp: store(giant local off) (0x%lx)", (long)sv->c.i);
if (((unsigned)fc + (1 << 11)) >> 12) {
rr = is_ireg(r) ? ireg(r) : 5; // t0
- o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
- ER(S, 0x33, 0, rr, rr, 8, 0); // add RR, RR, s0
+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
+ ER(0x33, 0, rr, rr, 8, 0); // add RR, RR, s0
sv->c.i = fc << 20 >> 20;
}
} else
- tcc_error(S, "uhh");
+ tcc_error("uhh");
return rr;
}
-static void load_large_constant(TCCState* S, int rr, int fc, uint32_t pi)
+static void load_large_constant(int rr, int fc, uint32_t pi)
{
if (fc < 0)
pi++;
- o(S, 0x37 | (rr << 7) | (((pi + 0x800) & 0xfffff000))); // lui RR, up(up(fc))
- EI(S, 0x13, 0, rr, rr, (int)pi << 20 >> 20); // addi RR, RR, lo(up(fc))
- EI(S, 0x13, 1, rr, rr, 12); // slli RR, RR, 12
- EI(S, 0x13, 0, rr, rr, (fc + (1 << 19)) >> 20); // addi RR, RR, up(lo(fc))
- EI(S, 0x13, 1, rr, rr, 12); // slli RR, RR, 12
+ o(0x37 | (rr << 7) | (((pi + 0x800) & 0xfffff000))); // lui RR, up(up(fc))
+ EI(0x13, 0, rr, rr, (int)pi << 20 >> 20); // addi RR, RR, lo(up(fc))
+ EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
+ EI(0x13, 0, rr, rr, (fc + (1 << 19)) >> 20); // addi RR, RR, up(lo(fc))
+ EI(0x13, 1, rr, rr, 12); // slli RR, RR, 12
fc = fc << 12 >> 12;
- EI(S, 0x13, 0, rr, rr, fc >> 8); // addi RR, RR, lo1(lo(fc))
- EI(S, 0x13, 1, rr, rr, 8); // slli RR, RR, 8
+ EI(0x13, 0, rr, rr, fc >> 8); // addi RR, RR, lo1(lo(fc))
+ EI(0x13, 1, rr, rr, 8); // slli RR, RR, 8
}
-ST_FUNC void load(TCCState* S, int r, SValue *sv)
+ST_FUNC void load(int r, SValue *sv)
{
int fr = sv->r;
int v = fr & VT_VALMASK;
@@ -233,49 +239,49 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv)
if (size < 4 && !is_float(sv->type.t) && (sv->type.t & VT_UNSIGNED))
func3 |= 4;
if (v == VT_LOCAL || (fr & VT_SYM)) {
- br = load_symofs(S, r, sv, 0);
+ br = load_symofs(r, sv, 0);
fc = sv->c.i;
} else if (v < VT_CONST) {
br = ireg(v);
/*if (((unsigned)fc + (1 << 11)) >> 12)
- tcc_error(S, "unimp: load(large addend) (0x%x)", fc);*/
+ tcc_error("unimp: load(large addend) (0x%x)", fc);*/
fc = 0; // XXX store ofs in LVAL(reg)
} else if (v == VT_LLOCAL) {
- br = load_symofs(S, r, sv, 0);
+ br = load_symofs(r, sv, 0);
fc = sv->c.i;
- EI(S, 0x03, 3, rr, br, fc); // ld RR, fc(BR)
+ EI(0x03, 3, rr, br, fc); // ld RR, fc(BR)
br = rr;
fc = 0;
} else if (v == VT_CONST) {
int64_t si = sv->c.i;
si >>= 32;
if (si != 0) {
- load_large_constant(S, rr, fc, si);
+ load_large_constant(rr, fc, si);
fc &= 0xff;
} else {
- o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
fc = fc << 20 >> 20;
}
br = rr;
} else {
- tcc_error(S, "unimp: load(non-local lval)");
+ tcc_error("unimp: load(non-local lval)");
}
- EI(S, opcode, func3, rr, br, fc); // l[bhwd][u] / fl[wd] RR, fc(BR)
+ EI(opcode, func3, rr, br, fc); // l[bhwd][u] / fl[wd] RR, fc(BR)
} else if (v == VT_CONST) {
int rb = 0, do32bit = 8, zext = 0;
assert((!is_float(sv->type.t) && is_ireg(r)) || bt == VT_LDOUBLE);
if (fr & VT_SYM) {
- rb = load_symofs(S, r, sv, 0);
+ rb = load_symofs(r, sv, 0);
fc = sv->c.i;
do32bit = 0;
}
if (is_float(sv->type.t) && bt != VT_LDOUBLE)
- tcc_error(S, "unimp: load(float)");
+ tcc_error("unimp: load(float)");
if (fc != sv->c.i) {
int64_t si = sv->c.i;
si >>= 32;
if (si != 0) {
- load_large_constant(S, rr, fc, si);
+ load_large_constant(rr, fc, si);
fc &= 0xff;
rb = rr;
do32bit = 0;
@@ -286,37 +292,37 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv)
}
}
if (((unsigned)fc + (1 << 11)) >> 12)
- o(S, 0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)), rb = rr; //lui RR, upper(fc)
+ o(0x37 | (rr << 7) | ((0x800 + fc) & 0xfffff000)), rb = rr; //lui RR, upper(fc)
if (fc || (rr != rb) || do32bit || (fr & VT_SYM))
- EI(S, 0x13 | do32bit, 0, rr, rb, fc << 20 >> 20); // addi[w] R, x0|R, FC
+ EI(0x13 | do32bit, 0, rr, rb, fc << 20 >> 20); // addi[w] R, x0|R, FC
if (zext) {
- EI(S, 0x13, 1, rr, rr, 32); // slli RR, RR, 32
- EI(S, 0x13, 5, rr, rr, 32); // srli RR, RR, 32
+ EI(0x13, 1, rr, rr, 32); // slli RR, RR, 32
+ EI(0x13, 5, rr, rr, 32); // srli RR, RR, 32
}
} else if (v == VT_LOCAL) {
- int br = load_symofs(S, r, sv, 0);
+ int br = load_symofs(r, sv, 0);
assert(is_ireg(r));
fc = sv->c.i;
- EI(S, 0x13, 0, rr, br, fc); // addi R, s0, FC
+ EI(0x13, 0, rr, br, fc); // addi R, s0, FC
} else if (v < VT_CONST) { /* reg-reg */
//assert(!fc); XXX support offseted regs
if (is_freg(r) && is_freg(v))
- ER(S, 0x53, 0, rr, freg(v), freg(v), bt == VT_DOUBLE ? 0x11 : 0x10); //fsgnj.[sd] RR, V, V == fmv.[sd] RR, V
+ ER(0x53, 0, rr, freg(v), freg(v), bt == VT_DOUBLE ? 0x11 : 0x10); //fsgnj.[sd] RR, V, V == fmv.[sd] RR, V
else if (is_ireg(r) && is_ireg(v))
- EI(S, 0x13, 0, rr, ireg(v), 0); // addi RR, V, 0 == mv RR, V
+ EI(0x13, 0, rr, ireg(v), 0); // addi RR, V, 0 == mv RR, V
else {
int func7 = is_ireg(r) ? 0x70 : 0x78;
size = type_size(&sv->type, &align);
if (size == 8)
func7 |= 1;
assert(size == 4 || size == 8);
- o(S, 0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)
+ o(0x53 | (rr << 7) | ((is_freg(v) ? freg(v) : ireg(v)) << 15)
| (func7 << 25)); // fmv.{w.x, x.w, d.x, x.d} RR, VR
}
} else if (v == VT_CMP) {
- int op = S->tccgen_vtop->cmp_op;
- int a = S->tccgen_vtop->cmp_r & 0xff;
- int b = (S->tccgen_vtop->cmp_r >> 8) & 0xff;
+ int op = vtop->cmp_op;
+ int a = vtop->cmp_r & 0xff;
+ int b = (vtop->cmp_r >> 8) & 0xff;
int inv = 0;
switch (op) {
case TOK_ULT:
@@ -335,32 +341,32 @@ ST_FUNC void load(TCCState* S, int r, SValue *sv)
int t = a; a = b; b = t;
inv ^= 1;
}
- ER(S, 0x33, (op > TOK_UGT) ? 2 : 3, rr, a, b, 0); // slt[u] d, a, b
+ ER(0x33, (op > TOK_UGT) ? 2 : 3, rr, a, b, 0); // slt[u] d, a, b
if (inv)
- EI(S, 0x13, 4, rr, rr, 1); // xori d, d, 1
+ EI(0x13, 4, rr, rr, 1); // xori d, d, 1
break;
case TOK_NE:
case TOK_EQ:
if (rr != a || b)
- ER(S, 0x33, 0, rr, a, b, 0x20); // sub d, a, b
+ ER(0x33, 0, rr, a, b, 0x20); // sub d, a, b
if (op == TOK_NE)
- ER(S, 0x33, 3, rr, 0, rr, 0); // sltu d, x0, d == snez d,d
+ ER(0x33, 3, rr, 0, rr, 0); // sltu d, x0, d == snez d,d
else
- EI(S, 0x13, 3, rr, rr, 1); // sltiu d, d, 1 == seqz d,d
+ EI(0x13, 3, rr, rr, 1); // sltiu d, d, 1 == seqz d,d
break;
}
} else if ((v & ~1) == VT_JMP) {
int t = v & 1;
assert(is_ireg(r));
- EI(S, 0x13, 0, rr, 0, t); // addi RR, x0, t
- gjmp_addr(S, S->tccgen_ind + 8);
- gsym(S, fc);
- EI(S, 0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t
+ EI(0x13, 0, rr, 0, t); // addi RR, x0, t
+ gjmp_addr(ind + 8);
+ gsym(fc);
+ EI(0x13, 0, rr, 0, t ^ 1); // addi RR, x0, !t
} else
- tcc_error(S, "unimp: load(non-const)");
+ tcc_error("unimp: load(non-const)");
}
-ST_FUNC void store(TCCState* S, int r, SValue *sv)
+ST_FUNC void store(int r, SValue *sv)
{
int fr = sv->r & VT_VALMASK;
int rr = is_ireg(r) ? ireg(r) : freg(r), ptrreg;
@@ -373,125 +379,125 @@ ST_FUNC void store(TCCState* S, int r, SValue *sv)
if (bt == VT_LDOUBLE)
size = align = 8;
if (bt == VT_STRUCT)
- tcc_error(S, "unimp: store(struct)");
+ tcc_error("unimp: store(struct)");
if (size > 8)
- tcc_error(S, "unimp: large sized store");
+ tcc_error("unimp: large sized store");
assert(sv->r & VT_LVAL);
if (fr == VT_LOCAL || (sv->r & VT_SYM)) {
- ptrreg = load_symofs(S, -1, sv, 1);
+ ptrreg = load_symofs(-1, sv, 1);
fc = sv->c.i;
} else if (fr < VT_CONST) {
ptrreg = ireg(fr);
/*if (((unsigned)fc + (1 << 11)) >> 12)
- tcc_error(S, "unimp: store(large addend) (0x%x)", fc);*/
+ tcc_error("unimp: store(large addend) (0x%x)", fc);*/
fc = 0; // XXX support offsets regs
} else if (fr == VT_CONST) {
int64_t si = sv->c.i;
ptrreg = 8; // s0
si >>= 32;
if (si != 0) {
- load_large_constant(S, ptrreg, fc, si);
+ load_large_constant(ptrreg, fc, si);
fc &= 0xff;
} else {
- o(S, 0x37 | (ptrreg << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
+ o(0x37 | (ptrreg << 7) | ((0x800 + fc) & 0xfffff000)); //lui RR, upper(fc)
fc = fc << 20 >> 20;
}
} else
- tcc_error(S, "implement me: %s(!local)", __FUNCTION__);
- ES(S, is_freg(r) ? 0x27 : 0x23, // fs... | s...
+ tcc_error("implement me: %s(!local)", __FUNCTION__);
+ ES(is_freg(r) ? 0x27 : 0x23, // fs... | s...
size == 1 ? 0 : size == 2 ? 1 : size == 4 ? 2 : 3, // ... [wd] | [bhwd]
ptrreg, rr, fc); // RR, fc(base)
}
-static void gcall_or_jmp(TCCState* S, int docall)
+static void gcall_or_jmp(int docall)
{
int tr = docall ? 1 : 5; // ra or t0
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
- ((S->tccgen_vtop->r & VT_SYM) && S->tccgen_vtop->c.i == (int)S->tccgen_vtop->c.i)) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
+ ((vtop->r & VT_SYM) && vtop->c.i == (int)vtop->c.i)) {
/* constant symbolic case -> simple relocation */
- greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind,
- R_RISCV_CALL_PLT, (int)S->tccgen_vtop->c.i);
- o(S, 0x17 | (tr << 7)); // auipc TR, 0 %call(func)
- EI(S, 0x67, 0, tr, tr, 0);// jalr TR, r(TR)
- } else if (S->tccgen_vtop->r < VT_CONST) {
- int r = ireg(S->tccgen_vtop->r);
- EI(S, 0x67, 0, tr, r, 0); // jalr TR, 0(R)
+ greloca(cur_text_section, vtop->sym, ind,
+ R_RISCV_CALL_PLT, (int)vtop->c.i);
+ o(0x17 | (tr << 7)); // auipc TR, 0 %call(func)
+ EI(0x67, 0, tr, tr, 0);// jalr TR, r(TR)
+ } else if (vtop->r < VT_CONST) {
+ int r = ireg(vtop->r);
+ EI(0x67, 0, tr, r, 0); // jalr TR, 0(R)
} else {
int r = TREG_RA;
- load(S, r, S->tccgen_vtop);
+ load(r, vtop);
r = ireg(r);
- EI(S, 0x67, 0, tr, r, 0); // jalr TR, 0(R)
+ EI(0x67, 0, tr, r, 0); // jalr TR, 0(R)
}
}
#if defined(CONFIG_TCC_BCHECK)
-static void gen_bounds_call(TCCState* S, int v)
+static void gen_bounds_call(int v)
{
- Sym *sym = external_helper_sym(S, v);
+ Sym *sym = external_helper_sym(v);
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_RISCV_CALL_PLT, 0);
- o(S, 0x17 | (1 << 7)); // auipc TR, 0 %call(func)
- EI(S, 0x67, 0, 1, 1, 0); // jalr TR, r(TR)
+ greloca(cur_text_section, sym, ind, R_RISCV_CALL_PLT, 0);
+ o(0x17 | (1 << 7)); // auipc TR, 0 %call(func)
+ EI(0x67, 0, 1, 1, 0); // jalr TR, r(TR)
}
-static void gen_bounds_prolog(TCCState* S)
+static void gen_bounds_prolog(void)
{
/* leave some room for bound checking code */
- S->func_bound_offset = lbounds_section->data_offset;
- S->func_bound_ind = S->tccgen_ind;
- S->func_bound_add_epilog = 0;
- o(S, 0x00000013); /* ld a0,#lbound section pointer */
- o(S, 0x00000013);
- o(S, 0x00000013); /* nop -> call __bound_local_new */
- o(S, 0x00000013);
+ func_bound_offset = lbounds_section->data_offset;
+ func_bound_ind = ind;
+ func_bound_add_epilog = 0;
+ o(0x00000013); /* ld a0,#lbound section pointer */
+ o(0x00000013);
+ o(0x00000013); /* nop -> call __bound_local_new */
+ o(0x00000013);
}
-static void gen_bounds_epilog(TCCState* S)
+static void gen_bounds_epilog(void)
{
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
Sym label = {0};
- int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
- if (!offset_modified && !S->func_bound_add_epilog)
+ if (!offset_modified && !func_bound_add_epilog)
return;
/* add end of table info */
- bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
- sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
- S->func_bound_offset, lbounds_section->data_offset);
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
+ func_bound_offset, lbounds_section->data_offset);
label.type.t = VT_VOID | VT_STATIC;
/* generate bound local allocation */
if (offset_modified) {
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->func_bound_ind;
- put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_RISCV_GOT_HI20, 0);
- o(S, 0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
- greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
- EI(S, 0x03, 3, 10, 10, 0); // ld a0, 0(a0)
- gen_bounds_call(S, TOK___bound_local_new);
- S->tccgen_ind = saved_ind;
+ saved_ind = ind;
+ ind = func_bound_ind;
+ put_extern_sym(&label, cur_text_section, ind, 0);
+ greloca(cur_text_section, sym_data, ind, R_RISCV_GOT_HI20, 0);
+ o(0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
+ EI(0x03, 3, 10, 10, 0); // ld a0, 0(a0)
+ gen_bounds_call(TOK___bound_local_new);
+ ind = saved_ind;
label.c = 0; /* force new local ELF symbol */
}
/* generate bound check local freeing */
- o(S, 0xe02a1101); /* addi sp,sp,-32 sd a0,0(sp) */
- o(S, 0xa82ae42e); /* sd a1,8(sp) fsd fa0,16(sp) */
- put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
- greloca(S, cur_text_section, sym_data, S->tccgen_ind, R_RISCV_GOT_HI20, 0);
- o(S, 0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
- greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
- EI(S, 0x03, 3, 10, 10, 0); // ld a0, 0(a0)
- gen_bounds_call(S, TOK___bound_local_delete);
- o(S, 0x65a26502); /* ld a0,0(sp) ld a1,8(sp) */
- o(S, 0x61052542); /* fld fa0,16(sp) addi sp,sp,32 */
+ o(0xe02a1101); /* addi sp,sp,-32 sd a0,0(sp) */
+ o(0xa82ae42e); /* sd a1,8(sp) fsd fa0,16(sp) */
+ put_extern_sym(&label, cur_text_section, ind, 0);
+ greloca(cur_text_section, sym_data, ind, R_RISCV_GOT_HI20, 0);
+ o(0x17 | (10 << 7)); // auipc a0, 0 %pcrel_hi(sym)+addend
+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
+ EI(0x03, 3, 10, 10, 0); // ld a0, 0(a0)
+ gen_bounds_call(TOK___bound_local_delete);
+ o(0x65a26502); /* ld a0,0(sp) ld a1,8(sp) */
+ o(0x61052542); /* fld fa0,16(sp) addi sp,sp,32 */
}
#endif
@@ -540,27 +546,27 @@ static void reg_pass(CType *type, int *prc, int *fieldofs, int named)
}
}
-ST_FUNC void gfunc_call(TCCState* S, int nb_args)
+ST_FUNC void gfunc_call(int nb_args)
{
int i, align, size, areg[2];
- int *info = tcc_malloc(S, (nb_args + 1) * sizeof (int));
+ int *info = tcc_malloc((nb_args + 1) * sizeof (int));
int stack_adj = 0, tempspace = 0, stack_add, ofs, splitofs = 0;
SValue *sv;
Sym *sa;
#ifdef CONFIG_TCC_BCHECK
- int bc_save = S->do_bounds_check;
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ int bc_save = tcc_state->do_bounds_check;
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
areg[0] = 0; /* int arg regs */
areg[1] = 8; /* float arg regs */
- sa = S->tccgen_vtop[-nb_args].type.ref->next;
+ sa = vtop[-nb_args].type.ref->next;
for (i = 0; i < nb_args; i++) {
int nregs, byref = 0, tempofs;
int prc[3], fieldofs[3];
- sv = &S->tccgen_vtop[1 + i - nb_args];
+ sv = &vtop[1 + i - nb_args];
sv->type.t &= ~VT_ARRAY; // XXX this should be done in tccgen.c
size = type_size(&sv->type, &align);
if (size > 16) {
@@ -617,53 +623,53 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args)
stack_add = stack_adj + tempspace;
/* fetch cpu flag before generating any code */
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP)
- gv(S, RC_INT);
+ if ((vtop->r & VT_VALMASK) == VT_CMP)
+ gv(RC_INT);
if (stack_add) {
if (stack_add >= 0x1000) {
- o(S, 0x37 | (5 << 7) | (-stack_add & 0xfffff000)); //lui t0, upper(v)
- EI(S, 0x13, 0, 5, 5, -stack_add << 20 >> 20); // addi t0, t0, lo(v)
- ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
+ o(0x37 | (5 << 7) | (-stack_add & 0xfffff000)); //lui t0, upper(v)
+ EI(0x13, 0, 5, 5, -stack_add << 20 >> 20); // addi t0, t0, lo(v)
+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
}
else
- EI(S, 0x13, 0, 2, 2, -stack_add); // addi sp, sp, -adj
+ EI(0x13, 0, 2, 2, -stack_add); // addi sp, sp, -adj
for (i = ofs = 0; i < nb_args; i++) {
if (info[i] & (64 | 32)) {
- vrotb(S, nb_args - i);
- size = type_size(&S->tccgen_vtop->type, &align);
+ vrotb(nb_args - i);
+ size = type_size(&vtop->type, &align);
if (info[i] & 64) {
- vset(S, &S->tccgen_char_pointer_type, TREG_SP, 0);
- vpushi(S, stack_adj + (info[i] >> 7));
- gen_op(S, '+');
- vpushv(S, S->tccgen_vtop); // this replaces the old argument
- vrott(S, 3);
- indir(S);
- S->tccgen_vtop->type = S->tccgen_vtop[-1].type;
- vswap(S);
- vstore(S);
- vpop(S);
+ vset(&char_pointer_type, TREG_SP, 0);
+ vpushi(stack_adj + (info[i] >> 7));
+ gen_op('+');
+ vpushv(vtop); // this replaces the old argument
+ vrott(3);
+ indir();
+ vtop->type = vtop[-1].type;
+ vswap();
+ vstore();
+ vpop();
size = align = 8;
}
if (info[i] & 32) {
if (align < XLEN)
align = XLEN;
/* Once we support offseted regs we can do this:
- vset(S, &S->tccgen_vtop->type, TREG_SP | VT_LVAL, ofs);
+ vset(&vtop->type, TREG_SP | VT_LVAL, ofs);
to construct the lvalue for the outgoing stack slot,
until then we have to jump through hoops. */
- vset(S, &S->tccgen_char_pointer_type, TREG_SP, 0);
+ vset(&char_pointer_type, TREG_SP, 0);
ofs = (ofs + align - 1) & -align;
- vpushi(S, ofs);
- gen_op(S, '+');
- indir(S);
- S->tccgen_vtop->type = S->tccgen_vtop[-1].type;
- vswap(S);
- vstore(S);
- S->tccgen_vtop->r = S->tccgen_vtop->r2 = VT_CONST; // this arg is done
+ vpushi(ofs);
+ gen_op('+');
+ indir();
+ vtop->type = vtop[-1].type;
+ vswap();
+ vstore();
+ vtop->r = vtop->r2 = VT_CONST; // this arg is done
ofs += size;
}
- vrott(S, nb_args - i);
+ vrott(nb_args - i);
} else if (info[i] & 16) {
assert(!splitofs);
splitofs = ofs;
@@ -679,12 +685,12 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args)
r &= 15;
r2 = r2 & 64 ? 0 : (r2 >> 7) & 31;
assert(r2 <= 16);
- vrotb(S, i+1);
- origtype = S->tccgen_vtop->type;
- size = type_size(&S->tccgen_vtop->type, &align);
+ vrotb(i+1);
+ origtype = vtop->type;
+ size = type_size(&vtop->type, &align);
if (size == 0)
goto done;
- loadt = S->tccgen_vtop->type.t & VT_BTYPE;
+ loadt = vtop->type.t & VT_BTYPE;
if (loadt == VT_STRUCT) {
loadt = (ii >> 12) & VT_BTYPE;
}
@@ -696,74 +702,74 @@ ST_FUNC void gfunc_call(TCCState* S, int nb_args)
assert(r2);
r2--;
} else if (r2) {
- test_lvalue(S);
- vpushv(S, S->tccgen_vtop);
+ test_lvalue();
+ vpushv(vtop);
}
- S->tccgen_vtop->type.t = loadt | (S->tccgen_vtop->type.t & VT_UNSIGNED);
- gv(S, r < 8 ? RC_R(r) : RC_F(r - 8));
- S->tccgen_vtop->type = origtype;
+ vtop->type.t = loadt | (vtop->type.t & VT_UNSIGNED);
+ gv(r < 8 ? RC_R(r) : RC_F(r - 8));
+ vtop->type = origtype;
if (r2 && loadt != VT_LDOUBLE) {
r2--;
assert(r2 < 16 || r2 == TREG_RA);
- vswap(S);
- gaddrof(S);
- S->tccgen_vtop->type = S->tccgen_char_pointer_type;
- vpushi(S, ii >> 20);
+ vswap();
+ gaddrof();
+ vtop->type = char_pointer_type;
+ vpushi(ii >> 20);
#ifdef CONFIG_TCC_BCHECK
if ((origtype.t & VT_BTYPE) == VT_STRUCT)
- S->do_bounds_check = 0;
+ tcc_state->do_bounds_check = 0;
#endif
- gen_op(S, '+');
+ gen_op('+');
#ifdef CONFIG_TCC_BCHECK
- S->do_bounds_check = bc_save;
+ tcc_state->do_bounds_check = bc_save;
#endif
- indir(S);
- S->tccgen_vtop->type = origtype;
- loadt = S->tccgen_vtop->type.t & VT_BTYPE;
+ indir();
+ vtop->type = origtype;
+ loadt = vtop->type.t & VT_BTYPE;
if (loadt == VT_STRUCT) {
loadt = (ii >> 16) & VT_BTYPE;
}
- save_reg_upstack(S, r2, 1);
- S->tccgen_vtop->type.t = loadt | (S->tccgen_vtop->type.t & VT_UNSIGNED);
- load(S, r2, S->tccgen_vtop);
+ save_reg_upstack(r2, 1);
+ vtop->type.t = loadt | (vtop->type.t & VT_UNSIGNED);
+ load(r2, vtop);
assert(r2 < VT_CONST);
- S->tccgen_vtop--;
- S->tccgen_vtop->r2 = r2;
+ vtop--;
+ vtop->r2 = r2;
}
if (info[nb_args - 1 - i] & 16) {
- ES(S, 0x23, 3, 2, ireg(S->tccgen_vtop->r2), splitofs); // sd t0, ofs(sp)
- S->tccgen_vtop->r2 = VT_CONST;
- } else if (loadt == VT_LDOUBLE && S->tccgen_vtop->r2 != r2) {
- assert(S->tccgen_vtop->r2 <= 7 && r2 <= 7);
+ ES(0x23, 3, 2, ireg(vtop->r2), splitofs); // sd t0, ofs(sp)
+ vtop->r2 = VT_CONST;
+ } else if (loadt == VT_LDOUBLE && vtop->r2 != r2) {
+ assert(vtop->r2 <= 7 && r2 <= 7);
/* XXX we'd like to have 'gv' move directly into
the right class instead of us fixing it up. */
- EI(S, 0x13, 0, ireg(r2), ireg(S->tccgen_vtop->r2), 0); // mv Ra+1, RR2
- S->tccgen_vtop->r2 = r2;
+ EI(0x13, 0, ireg(r2), ireg(vtop->r2), 0); // mv Ra+1, RR2
+ vtop->r2 = r2;
}
done:
- vrott(S, i+1);
+ vrott(i+1);
}
}
- vrotb(S, nb_args + 1);
- save_regs(S, nb_args + 1);
- gcall_or_jmp(S, 1);
- S->tccgen_vtop -= nb_args + 1;
+ vrotb(nb_args + 1);
+ save_regs(nb_args + 1);
+ gcall_or_jmp(1);
+ vtop -= nb_args + 1;
if (stack_add) {
if (stack_add >= 0x1000) {
- o(S, 0x37 | (5 << 7) | (stack_add & 0xfffff000)); //lui t0, upper(v)
- EI(S, 0x13, 0, 5, 5, stack_add << 20 >> 20); // addi t0, t0, lo(v)
- ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
+ o(0x37 | (5 << 7) | (stack_add & 0xfffff000)); //lui t0, upper(v)
+ EI(0x13, 0, 5, 5, stack_add << 20 >> 20); // addi t0, t0, lo(v)
+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
}
else
- EI(S, 0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
+ EI(0x13, 0, 2, 2, stack_add); // addi sp, sp, adj
}
- tcc_free(S, info);
+ tcc_free(info);
}
static int func_sub_sp_offset, num_va_regs, func_va_list_ofs;
-ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
+ST_FUNC void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
int i, addr, align, size;
@@ -773,19 +779,19 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
CType *type;
sym = func_type->ref;
- S->tccgen_loc = -16; // for ra and s0
- func_sub_sp_offset = S->tccgen_ind;
- S->tccgen_ind += 5 * 4;
+ loc = -16; // for ra and s0
+ func_sub_sp_offset = ind;
+ ind += 5 * 4;
areg[0] = 0, areg[1] = 0;
addr = 0;
/* if the function returns by reference, then add an
implicit pointer parameter */
- size = type_size(&S->tccgen_func_vt, &align);
+ size = type_size(&func_vt, &align);
if (size > 2 * XLEN) {
- S->tccgen_loc -= 8;
- S->tccgen_func_vc = S->tccgen_loc;
- ES(S, 0x23, 3, 8, 10 + areg[0]++, S->tccgen_loc); // sd a0, loc(s0)
+ loc -= 8;
+ func_vc = loc;
+ ES(0x23, 3, 8, 10 + areg[0]++, loc); // sd a0, loc(s0)
}
/* define parameters */
while ((sym = sym->next) != NULL) {
@@ -795,7 +801,7 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
type = &sym->type;
size = type_size(type, &align);
if (size > 2 * XLEN) {
- type = &S->tccgen_char_pointer_type;
+ type = &char_pointer_type;
size = align = byref = 8;
}
reg_pass(type, prc, fieldofs, 1);
@@ -810,36 +816,36 @@ ST_FUNC void gfunc_prolog(TCCState* S, Sym *func_sym)
param_addr = addr;
addr += size;
} else {
- S->tccgen_loc -= regcount * 8; // XXX could reserve only 'size' bytes
- param_addr = S->tccgen_loc;
+ loc -= regcount * 8; // XXX could reserve only 'size' bytes
+ param_addr = loc;
for (i = 0; i < regcount; i++) {
if (areg[prc[1+i] - 1] >= 8) {
assert(i == 1 && regcount == 2 && !(addr & 7));
- EI(S, 0x03, 3, 5, 8, addr); // ld t0, addr(s0)
+ EI(0x03, 3, 5, 8, addr); // ld t0, addr(s0)
addr += 8;
- ES(S, 0x23, 3, 8, 5, S->tccgen_loc + i*8); // sd t0, loc(s0)
+ ES(0x23, 3, 8, 5, loc + i*8); // sd t0, loc(s0)
} else if (prc[1+i] == RC_FLOAT) {
- ES(S, 0x27, (size / regcount) == 4 ? 2 : 3, 8, 10 + areg[1]++, S->tccgen_loc + (fieldofs[i+1] >> 4)); // fs[wd] FAi, loc(s0)
+ ES(0x27, (size / regcount) == 4 ? 2 : 3, 8, 10 + areg[1]++, loc + (fieldofs[i+1] >> 4)); // fs[wd] FAi, loc(s0)
} else {
- ES(S, 0x23, 3, 8, 10 + areg[0]++, S->tccgen_loc + i*8); // sd aX, loc(s0) // XXX
+ ES(0x23, 3, 8, 10 + areg[0]++, loc + i*8); // sd aX, loc(s0) // XXX
}
}
}
- sym_push(S, sym->v & ~SYM_FIELD, &sym->type,
+ sym_push(sym->v & ~SYM_FIELD, &sym->type,
(byref ? VT_LLOCAL : VT_LOCAL) | VT_LVAL,
param_addr);
}
func_va_list_ofs = addr;
num_va_regs = 0;
- if (S->tccgen_func_var) {
+ if (func_var) {
for (; areg[0] < 8; areg[0]++) {
num_va_regs++;
- ES(S, 0x23, 3, 8, 10 + areg[0], -8 + num_va_regs * 8); // sd aX, loc(s0)
+ ES(0x23, 3, 8, 10 + areg[0], -8 + num_va_regs * 8); // sd aX, loc(s0)
}
}
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
@@ -864,113 +870,113 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret,
return nregs;
}
-ST_FUNC void arch_transfer_ret_regs(TCCState* S, int aftercall)
+ST_FUNC void arch_transfer_ret_regs(int aftercall)
{
int prc[3], fieldofs[3];
- reg_pass(&S->tccgen_vtop->type, prc, fieldofs, 1);
+ reg_pass(&vtop->type, prc, fieldofs, 1);
assert(prc[0] == 2 && prc[1] != prc[2] && !(fieldofs[1] >> 4));
- assert(S->tccgen_vtop->r == (VT_LOCAL | VT_LVAL));
- vpushv(S, S->tccgen_vtop);
- S->tccgen_vtop->type.t = fieldofs[1] & VT_BTYPE;
- (aftercall ? store : load)(S, prc[1] == RC_INT ? REG_IRET : REG_FRET, S->tccgen_vtop);
- S->tccgen_vtop->c.i += fieldofs[2] >> 4;
- S->tccgen_vtop->type.t = fieldofs[2] & VT_BTYPE;
- (aftercall ? store : load)(S, prc[2] == RC_INT ? REG_IRET : REG_FRET, S->tccgen_vtop);
- S->tccgen_vtop--;
+ assert(vtop->r == (VT_LOCAL | VT_LVAL));
+ vpushv(vtop);
+ vtop->type.t = fieldofs[1] & VT_BTYPE;
+ (aftercall ? store : load)(prc[1] == RC_INT ? REG_IRET : REG_FRET, vtop);
+ vtop->c.i += fieldofs[2] >> 4;
+ vtop->type.t = fieldofs[2] & VT_BTYPE;
+ (aftercall ? store : load)(prc[2] == RC_INT ? REG_IRET : REG_FRET, vtop);
+ vtop--;
}
-ST_FUNC void gfunc_epilog(TCCState* S)
+ST_FUNC void gfunc_epilog(void)
{
int v, saved_ind, d, large_ofs_ind;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
- S->tccgen_loc = (S->tccgen_loc - num_va_regs * 8);
- d = v = (-S->tccgen_loc + 15) & -16;
+ loc = (loc - num_va_regs * 8);
+ d = v = (-loc + 15) & -16;
if (v >= (1 << 11)) {
d = 16;
- o(S, 0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
- EI(S, 0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
- ER(S, 0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
+ o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
+ EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
+ ER(0x33, 0, 2, 2, 5, 0); // add sp, sp, t0
}
- EI(S, 0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)
- EI(S, 0x03, 3, 8, 2, d - 16 - num_va_regs * 8); // ld s0, v-16(sp)
- EI(S, 0x13, 0, 2, 2, d); // addi sp, sp, v
- EI(S, 0x67, 0, 0, 1, 0); // jalr x0, 0(x1), aka ret
- large_ofs_ind = S->tccgen_ind;
+ EI(0x03, 3, 1, 2, d - 8 - num_va_regs * 8); // ld ra, v-8(sp)
+ EI(0x03, 3, 8, 2, d - 16 - num_va_regs * 8); // ld s0, v-16(sp)
+ EI(0x13, 0, 2, 2, d); // addi sp, sp, v
+ EI(0x67, 0, 0, 1, 0); // jalr x0, 0(x1), aka ret
+ large_ofs_ind = ind;
if (v >= (1 << 11)) {
- EI(S, 0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
- o(S, 0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
- EI(S, 0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
- ER(S, 0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0
- gjmp_addr(S, func_sub_sp_offset + 5*4);
+ EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
+ o(0x37 | (5 << 7) | ((0x800 + (v-16)) & 0xfffff000)); //lui t0, upper(v)
+ EI(0x13, 0, 5, 5, (v-16) << 20 >> 20); // addi t0, t0, lo(v)
+ ER(0x33, 0, 2, 2, 5, 0x20); // sub sp, sp, t0
+ gjmp_addr(func_sub_sp_offset + 5*4);
}
- saved_ind = S->tccgen_ind;
+ saved_ind = ind;
- S->tccgen_ind = func_sub_sp_offset;
- EI(S, 0x13, 0, 2, 2, -d); // addi sp, sp, -d
- ES(S, 0x23, 3, 2, 1, d - 8 - num_va_regs * 8); // sd ra, d-8(sp)
- ES(S, 0x23, 3, 2, 8, d - 16 - num_va_regs * 8); // sd s0, d-16(sp)
+ ind = func_sub_sp_offset;
+ EI(0x13, 0, 2, 2, -d); // addi sp, sp, -d
+ ES(0x23, 3, 2, 1, d - 8 - num_va_regs * 8); // sd ra, d-8(sp)
+ ES(0x23, 3, 2, 8, d - 16 - num_va_regs * 8); // sd s0, d-16(sp)
if (v < (1 << 11))
- EI(S, 0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
+ EI(0x13, 0, 8, 2, d - num_va_regs * 8); // addi s0, sp, d
else
- gjmp_addr(S, large_ofs_ind);
- if ((S->tccgen_ind - func_sub_sp_offset) != 5*4)
- EI(S, 0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
- S->tccgen_ind = saved_ind;
+ gjmp_addr(large_ofs_ind);
+ if ((ind - func_sub_sp_offset) != 5*4)
+ EI(0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
+ ind = saved_ind;
}
-ST_FUNC void gen_va_start(TCCState *S)
+ST_FUNC void gen_va_start(void)
{
- S->tccgen_vtop--;
- vset(S, &S->tccgen_char_pointer_type, VT_LOCAL, func_va_list_ofs);
+ vtop--;
+ vset(&char_pointer_type, VT_LOCAL, func_va_list_ofs);
}
-ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
if ((bytes & 3))
- tcc_error(S, "alignment of code section not multiple of 4");
+ tcc_error("alignment of code section not multiple of 4");
while (bytes > 0) {
- EI(S, 0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
+ EI(0x13, 0, 0, 0, 0); // addi x0, x0, 0 == nop
bytes -= 4;
}
}
// Generate forward branch to label:
-ST_FUNC int gjmp(TCCState* S, int t)
+ST_FUNC int gjmp(int t)
{
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return t;
- o(S, t);
- return S->tccgen_ind - 4;
+ o(t);
+ return ind - 4;
}
// Generate branch to known address:
-ST_FUNC void gjmp_addr(TCCState* S, int a)
+ST_FUNC void gjmp_addr(int a)
{
- uint32_t r = a - S->tccgen_ind, imm;
+ uint32_t r = a - ind, imm;
if ((r + (1 << 21)) & ~((1U << 22) - 2)) {
- o(S, 0x17 | (5 << 7) | (((r + 0x800) & 0xfffff000))); // lui RR, up(r)
+ o(0x17 | (5 << 7) | (((r + 0x800) & 0xfffff000))); // lui RR, up(r)
r = (int)r << 20 >> 20;
- EI(S, 0x67, 0, 0, 5, r); // jalr x0, r(t0)
+ EI(0x67, 0, 0, 5, r); // jalr x0, r(t0)
} else {
imm = (((r >> 12) & 0xff) << 12)
| (((r >> 11) & 1) << 20)
| (((r >> 1) & 0x3ff) << 21)
| (((r >> 20) & 1) << 31);
- o(S, 0x6f | imm); // jal x0, imm == j imm
+ o(0x6f | imm); // jal x0, imm == j imm
}
}
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
int tmp;
- int a = S->tccgen_vtop->cmp_r & 0xff;
- int b = (S->tccgen_vtop->cmp_r >> 8) & 0xff;
+ int a = vtop->cmp_r & 0xff;
+ int b = (vtop->cmp_r >> 8) & 0xff;
switch (op) {
case TOK_ULT: op = 6; break;
case TOK_UGE: op = 7; break;
@@ -983,11 +989,11 @@ ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
case TOK_NE: op = 1; break;
case TOK_EQ: op = 0; break;
}
- o(S, 0x63 | (op ^ 1) << 12 | a << 15 | b << 20 | 8 << 7); // bOP a,b,+4
- return gjmp(S, t);
+ o(0x63 | (op ^ 1) << 12 | a << 15 | b << 20 | 8 << 7); // bOP a,b,+4
+ return gjmp(t);
}
-ST_FUNC int gjmp_append(TCCState* S, int n, int t)
+ST_FUNC int gjmp_append(int n, int t)
{
void *p;
/* insert jump list n into t */
@@ -1001,23 +1007,23 @@ ST_FUNC int gjmp_append(TCCState* S, int n, int t)
return t;
}
-static void gen_opil(TCCState* S, int op, int ll)
+static void gen_opil(int op, int ll)
{
int a, b, d;
int func3 = 0;
ll = ll ? 0 : 8;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
- int fc = S->tccgen_vtop->c.i;
- if (fc == S->tccgen_vtop->c.i && !(((unsigned)fc + (1 << 11)) >> 12)) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ int fc = vtop->c.i;
+ if (fc == vtop->c.i && !(((unsigned)fc + (1 << 11)) >> 12)) {
int cll = 0;
int m = ll ? 31 : 63;
- vswap(S);
- gv(S, RC_INT);
- a = ireg(S->tccgen_vtop[0].r);
- --S->tccgen_vtop;
- d = get_reg(S, RC_INT);
- ++S->tccgen_vtop;
- vswap(S);
+ vswap();
+ gv(RC_INT);
+ a = ireg(vtop[0].r);
+ --vtop;
+ d = get_reg(RC_INT);
+ ++vtop;
+ vswap();
switch (op) {
case '-':
if (fc <= -(1 << 11))
@@ -1027,13 +1033,13 @@ static void gen_opil(TCCState* S, int op, int ll)
func3 = 0; // addi d, a, fc
cll = ll;
do_cop:
- EI(S, 0x13 | cll, func3, ireg(d), a, fc);
- --S->tccgen_vtop;
+ EI(0x13 | cll, func3, ireg(d), a, fc);
+ --vtop;
if (op >= TOK_ULT && op <= TOK_GT) {
- vset_VT_CMP(S, TOK_NE);
- S->tccgen_vtop->cmp_r = ireg(d) | 0 << 8;
+ vset_VT_CMP(TOK_NE);
+ vtop->cmp_r = ireg(d) | 0 << 8;
} else
- S->tccgen_vtop[0].r = d;
+ vtop[0].r = d;
return;
case TOK_LE:
if (fc >= (1 << 11) - 1)
@@ -1056,97 +1062,97 @@ static void gen_opil(TCCState* S, int op, int ll)
case TOK_UGT: /* -> TOK_ULE */
case TOK_GE: /* -> TOK_LT */
case TOK_GT: /* -> TOK_LE */
- gen_opil(S, op - 1, !ll);
- S->tccgen_vtop->cmp_op ^= 1;
+ gen_opil(op - 1, !ll);
+ vtop->cmp_op ^= 1;
return;
case TOK_NE:
case TOK_EQ:
if (fc)
- gen_opil(S, '-', !ll), a = ireg(S->tccgen_vtop++->r);
- --S->tccgen_vtop;
- vset_VT_CMP(S, op);
- S->tccgen_vtop->cmp_r = a | 0 << 8;
+ gen_opil('-', !ll), a = ireg(vtop++->r);
+ --vtop;
+ vset_VT_CMP(op);
+ vtop->cmp_r = a | 0 << 8;
return;
}
}
}
- gv2(S, RC_INT, RC_INT);
- a = ireg(S->tccgen_vtop[-1].r);
- b = ireg(S->tccgen_vtop[0].r);
- S->tccgen_vtop -= 2;
- d = get_reg(S, RC_INT);
- S->tccgen_vtop++;
- S->tccgen_vtop[0].r = d;
+ gv2(RC_INT, RC_INT);
+ a = ireg(vtop[-1].r);
+ b = ireg(vtop[0].r);
+ vtop -= 2;
+ d = get_reg(RC_INT);
+ vtop++;
+ vtop[0].r = d;
d = ireg(d);
switch (op) {
default:
if (op >= TOK_ULT && op <= TOK_GT) {
- vset_VT_CMP(S, op);
- S->tccgen_vtop->cmp_r = a | b << 8;
+ vset_VT_CMP(op);
+ vtop->cmp_r = a | b << 8;
break;
}
- tcc_error(S, "implement me: %s(%s)", __FUNCTION__, get_tok_str(S, op, NULL));
+ tcc_error("implement me: %s(%s)", __FUNCTION__, get_tok_str(op, NULL));
break;
case '+':
- ER(S, 0x33 | ll, 0, d, a, b, 0); // add d, a, b
+ ER(0x33 | ll, 0, d, a, b, 0); // add d, a, b
break;
case '-':
- ER(S, 0x33 | ll, 0, d, a, b, 0x20); // sub d, a, b
+ ER(0x33 | ll, 0, d, a, b, 0x20); // sub d, a, b
break;
case TOK_SAR:
- ER(S, 0x33 | ll | ll, 5, d, a, b, 0x20); // sra d, a, b
+ ER(0x33 | ll | ll, 5, d, a, b, 0x20); // sra d, a, b
break;
case TOK_SHR:
- ER(S, 0x33 | ll | ll, 5, d, a, b, 0); // srl d, a, b
+ ER(0x33 | ll | ll, 5, d, a, b, 0); // srl d, a, b
break;
case TOK_SHL:
- ER(S, 0x33 | ll, 1, d, a, b, 0); // sll d, a, b
+ ER(0x33 | ll, 1, d, a, b, 0); // sll d, a, b
break;
case '*':
- ER(S, 0x33 | ll, 0, d, a, b, 1); // mul d, a, b
+ ER(0x33 | ll, 0, d, a, b, 1); // mul d, a, b
break;
case '/':
- ER(S, 0x33 | ll, 4, d, a, b, 1); // div d, a, b
+ ER(0x33 | ll, 4, d, a, b, 1); // div d, a, b
break;
case '&':
- ER(S, 0x33, 7, d, a, b, 0); // and d, a, b
+ ER(0x33, 7, d, a, b, 0); // and d, a, b
break;
case '^':
- ER(S, 0x33, 4, d, a, b, 0); // xor d, a, b
+ ER(0x33, 4, d, a, b, 0); // xor d, a, b
break;
case '|':
- ER(S, 0x33, 6, d, a, b, 0); // or d, a, b
+ ER(0x33, 6, d, a, b, 0); // or d, a, b
break;
case '%':
- ER(S, ll ? 0x3b: 0x33, 6, d, a, b, 1); // rem d, a, b
+ ER(ll ? 0x3b: 0x33, 6, d, a, b, 1); // rem d, a, b
break;
case TOK_UMOD:
- ER(S, 0x33 | ll, 7, d, a, b, 1); // remu d, a, b
+ ER(0x33 | ll, 7, d, a, b, 1); // remu d, a, b
break;
case TOK_PDIV:
case TOK_UDIV:
- ER(S, 0x33 | ll, 5, d, a, b, 1); // divu d, a, b
+ ER(0x33 | ll, 5, d, a, b, 1); // divu d, a, b
break;
}
}
-ST_FUNC void gen_opi(TCCState* S, int op)
+ST_FUNC void gen_opi(int op)
{
- gen_opil(S, op, 0);
+ gen_opil(op, 0);
}
-ST_FUNC void gen_opl(TCCState* S, int op)
+ST_FUNC void gen_opl(int op)
{
- gen_opil(S, op, 1);
+ gen_opil(op, 1);
}
-ST_FUNC void gen_opf(TCCState* S, int op)
+ST_FUNC void gen_opf(int op)
{
int rs1, rs2, rd, dbl, invert;
- if (S->tccgen_vtop[0].type.t == VT_LDOUBLE) {
- CType type = S->tccgen_vtop[0].type;
+ if (vtop[0].type.t == VT_LDOUBLE) {
+ CType type = vtop[0].type;
int func = 0;
int cond = -1;
switch (op) {
@@ -1162,27 +1168,27 @@ ST_FUNC void gen_opf(TCCState* S, int op)
case TOK_GT: func = TOK___gttf2; cond = 13; break;
default: assert(0); break;
}
- vpush_helper_func(S, func);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = REG_IRET;
- S->tccgen_vtop->r2 = cond < 0 ? TREG_R(1) : VT_CONST;
+ vpush_helper_func(func);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = REG_IRET;
+ vtop->r2 = cond < 0 ? TREG_R(1) : VT_CONST;
if (cond < 0)
- S->tccgen_vtop->type = type;
+ vtop->type = type;
else {
- vpushi(S, 0);
- gen_opil(S, op, 1);
+ vpushi(0);
+ gen_opil(op, 1);
}
return;
}
- gv2(S, RC_FLOAT, RC_FLOAT);
- assert(S->tccgen_vtop->type.t == VT_DOUBLE || S->tccgen_vtop->type.t == VT_FLOAT);
- dbl = S->tccgen_vtop->type.t == VT_DOUBLE;
- rs1 = freg(S->tccgen_vtop[-1].r);
- rs2 = freg(S->tccgen_vtop->r);
- S->tccgen_vtop--;
+ gv2(RC_FLOAT, RC_FLOAT);
+ assert(vtop->type.t == VT_DOUBLE || vtop->type.t == VT_FLOAT);
+ dbl = vtop->type.t == VT_DOUBLE;
+ rs1 = freg(vtop[-1].r);
+ rs2 = freg(vtop->r);
+ vtop--;
invert = 0;
switch(op) {
default:
@@ -1190,10 +1196,10 @@ ST_FUNC void gen_opf(TCCState* S, int op)
case '+':
op = 0; // fadd
arithop:
- rd = get_reg(S, RC_FLOAT);
- S->tccgen_vtop->r = rd;
+ rd = get_reg(RC_FLOAT);
+ vtop->r = rd;
rd = freg(rd);
- ER(S, 0x53, 7, rd, rs1, rs2, dbl | (op << 2)); // fop.[sd] RD, RS1, RS2 (dyn rm)
+ ER(0x53, 7, rd, rs1, rs2, dbl | (op << 2)); // fop.[sd] RD, RS1, RS2 (dyn rm)
break;
case '-':
op = 1; // fsub
@@ -1207,12 +1213,12 @@ ST_FUNC void gen_opf(TCCState* S, int op)
case TOK_EQ:
op = 2; // EQ
cmpop:
- rd = get_reg(S, RC_INT);
- S->tccgen_vtop->r = rd;
+ rd = get_reg(RC_INT);
+ vtop->r = rd;
rd = ireg(rd);
- ER(S, 0x53, op, rd, rs1, rs2, dbl | 0x50); // fcmp.[sd] RD, RS1, RS2 (op == eq/lt/le)
+ ER(0x53, op, rd, rs1, rs2, dbl | 0x50); // fcmp.[sd] RD, RS1, RS2 (op == eq/lt/le)
if (invert)
- EI(S, 0x13, 4, rd, rd, 1); // xori RD, 1
+ EI(0x13, 4, rd, rd, 1); // xori RD, 1
break;
case TOK_NE:
invert = 1;
@@ -1235,67 +1241,67 @@ ST_FUNC void gen_opf(TCCState* S, int op)
}
}
-ST_FUNC void gen_cvt_sxtw(TCCState *S)
+ST_FUNC void gen_cvt_sxtw(void)
{
/* XXX on risc-v the registers are usually sign-extended already.
Let's try to not do anything here. */
}
-ST_FUNC void gen_cvt_itof(TCCState* S, int t)
+ST_FUNC void gen_cvt_itof(int t)
{
- int rr = ireg(gv(S, RC_INT)), dr;
- int u = S->tccgen_vtop->type.t & VT_UNSIGNED;
- int l = (S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG;
+ int rr = ireg(gv(RC_INT)), dr;
+ int u = vtop->type.t & VT_UNSIGNED;
+ int l = (vtop->type.t & VT_BTYPE) == VT_LLONG;
if (t == VT_LDOUBLE) {
int func = l ?
(u ? TOK___floatunditf : TOK___floatditf) :
(u ? TOK___floatunsitf : TOK___floatsitf);
- vpush_helper_func(S, func);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = t;
- S->tccgen_vtop->r = REG_IRET;
- S->tccgen_vtop->r2 = TREG_R(1);
+ vpush_helper_func(func);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ vtop->type.t = t;
+ vtop->r = REG_IRET;
+ vtop->r2 = TREG_R(1);
} else {
- S->tccgen_vtop--;
- dr = get_reg(S, RC_FLOAT);
- S->tccgen_vtop++;
- S->tccgen_vtop->r = dr;
+ vtop--;
+ dr = get_reg(RC_FLOAT);
+ vtop++;
+ vtop->r = dr;
dr = freg(dr);
- EIu(S, 0x53, 7, dr, rr, ((0x68 | (t == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[sd].[wl][u]
+ EIu(0x53, 7, dr, rr, ((0x68 | (t == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[sd].[wl][u]
}
}
-ST_FUNC void gen_cvt_ftoi(TCCState* S, int t)
+ST_FUNC void gen_cvt_ftoi(int t)
{
- int ft = S->tccgen_vtop->type.t & VT_BTYPE;
+ int ft = vtop->type.t & VT_BTYPE;
int l = (t & VT_BTYPE) == VT_LLONG;
int u = t & VT_UNSIGNED;
if (ft == VT_LDOUBLE) {
int func = l ?
(u ? TOK___fixunstfdi : TOK___fixtfdi) :
(u ? TOK___fixunstfsi : TOK___fixtfsi);
- vpush_helper_func(S, func);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = t;
- S->tccgen_vtop->r = REG_IRET;
+ vpush_helper_func(func);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ vtop->type.t = t;
+ vtop->r = REG_IRET;
} else {
- int rr = freg(gv(S, RC_FLOAT)), dr;
- S->tccgen_vtop--;
- dr = get_reg(S, RC_INT);
- S->tccgen_vtop++;
- S->tccgen_vtop->r = dr;
+ int rr = freg(gv(RC_FLOAT)), dr;
+ vtop--;
+ dr = get_reg(RC_INT);
+ vtop++;
+ vtop->r = dr;
dr = ireg(dr);
- EIu(S, 0x53, 1, dr, rr, ((0x60 | (ft == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[wl][u].[sd] rtz
+ EIu(0x53, 1, dr, rr, ((0x60 | (ft == VT_DOUBLE ? 1 : 0)) << 5) | (u ? 1 : 0) | (l ? 2 : 0)); // fcvt.[wl][u].[sd] rtz
}
}
-ST_FUNC void gen_cvt_ftof(TCCState* S, int dt)
+ST_FUNC void gen_cvt_ftof(int dt)
{
- int st = S->tccgen_vtop->type.t & VT_BTYPE, rs, rd;
+ int st = vtop->type.t & VT_BTYPE, rs, rd;
dt &= VT_BTYPE;
if (st == dt)
return;
@@ -1307,109 +1313,109 @@ ST_FUNC void gen_cvt_ftof(TCCState* S, int dt)
functions, and on riscv unnamed float args are passed like
integers. But we really need them in the float argument registers
for extendsftf2/extenddftf2. So, do it explicitely. */
- save_regs(S, 1);
+ save_regs(1);
if (dt == VT_LDOUBLE)
- gv(S, RC_F(0));
+ gv(RC_F(0));
else {
- gv(S, RC_R(0));
- assert(S->tccgen_vtop->r2 < 7);
- if (S->tccgen_vtop->r2 != 1 + S->tccgen_vtop->r) {
- EI(S, 0x13, 0, ireg(S->tccgen_vtop->r) + 1, ireg(S->tccgen_vtop->r2), 0); // mv Ra+1, RR2
- S->tccgen_vtop->r2 = 1 + S->tccgen_vtop->r;
+ gv(RC_R(0));
+ assert(vtop->r2 < 7);
+ if (vtop->r2 != 1 + vtop->r) {
+ EI(0x13, 0, ireg(vtop->r) + 1, ireg(vtop->r2), 0); // mv Ra+1, RR2
+ vtop->r2 = 1 + vtop->r;
}
}
- vpush_helper_func(S, func);
- gcall_or_jmp(S, 1);
- S->tccgen_vtop -= 2;
- vpushi(S, 0);
- S->tccgen_vtop->type.t = dt;
+ vpush_helper_func(func);
+ gcall_or_jmp(1);
+ vtop -= 2;
+ vpushi(0);
+ vtop->type.t = dt;
if (dt == VT_LDOUBLE)
- S->tccgen_vtop->r = REG_IRET, S->tccgen_vtop->r2 = REG_IRET+1;
+ vtop->r = REG_IRET, vtop->r2 = REG_IRET+1;
else
- S->tccgen_vtop->r = REG_FRET;
+ vtop->r = REG_FRET;
} else {
assert (dt == VT_FLOAT || dt == VT_DOUBLE);
assert (st == VT_FLOAT || st == VT_DOUBLE);
- rs = gv(S, RC_FLOAT);
- rd = get_reg(S, RC_FLOAT);
+ rs = gv(RC_FLOAT);
+ rd = get_reg(RC_FLOAT);
if (dt == VT_DOUBLE)
- EI(S, 0x53, 0, freg(rd), freg(rs), 0x21 << 5); // fcvt.d.s RD, RS (no rm)
+ EI(0x53, 0, freg(rd), freg(rs), 0x21 << 5); // fcvt.d.s RD, RS (no rm)
else
- EI(S, 0x53, 7, freg(rd), freg(rs), (0x20 << 5) | 1); // fcvt.s.d RD, RS (dyn rm)
- S->tccgen_vtop->r = rd;
+ EI(0x53, 7, freg(rd), freg(rs), (0x20 << 5) | 1); // fcvt.s.d RD, RS (dyn rm)
+ vtop->r = rd;
}
}
/* increment tcov counter */
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
+ST_FUNC void gen_increment_tcov (SValue *sv)
{
int r1, r2;
Sym label = {0};
label.type.t = VT_VOID | VT_STATIC;
- vpushv(S, sv);
- S->tccgen_vtop->r = r1 = get_reg(S, RC_INT);
- r2 = get_reg(S, RC_INT);
+ vpushv(sv);
+ vtop->r = r1 = get_reg(RC_INT);
+ r2 = get_reg(RC_INT);
r1 = ireg(r1);
r2 = ireg(r2);
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_RISCV_PCREL_HI20, 0);
- put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
- o(S, 0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
- greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_I, 0);
- EI(S, 0x03, 3, r2, r1, 0); // ld r2, x[r1]
- EI(S, 0x13, 0, r2, r2, 1); // addi r2, r2, #1
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_RISCV_PCREL_HI20, 0);
+ greloca(cur_text_section, sv->sym, ind, R_RISCV_PCREL_HI20, 0);
+ put_extern_sym(&label, cur_text_section, ind, 0);
+ o(0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_I, 0);
+ EI(0x03, 3, r2, r1, 0); // ld r2, x[r1]
+ EI(0x13, 0, r2, r2, 1); // addi r2, r2, #1
+ greloca(cur_text_section, sv->sym, ind, R_RISCV_PCREL_HI20, 0);
label.c = 0; /* force new local ELF symbol */
- put_extern_sym(S, &label, cur_text_section, S->tccgen_ind, 0);
- o(S, 0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
- greloca(S, cur_text_section, &label, S->tccgen_ind, R_RISCV_PCREL_LO12_S, 0);
- ES(S, 0x23, 3, r1, r2, 0); // sd r2, [r1]
- vpop(S);
+ put_extern_sym(&label, cur_text_section, ind, 0);
+ o(0x17 | (r1 << 7)); // auipc RR, 0 %pcrel_hi(sym)
+ greloca(cur_text_section, &label, ind, R_RISCV_PCREL_LO12_S, 0);
+ ES(0x23, 3, r1, r2, 0); // sd r2, [r1]
+ vpop();
}
-ST_FUNC void ggoto(TCCState* S)
+ST_FUNC void ggoto(void)
{
- gcall_or_jmp(S, 0);
- S->tccgen_vtop--;
+ gcall_or_jmp(0);
+ vtop--;
}
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr)
+ST_FUNC void gen_vla_sp_save(int addr)
{
- ES(S, 0x23, 3, 8, 2, addr); // sd sp, fc(s0)
+ ES(0x23, 3, 8, 2, addr); // sd sp, fc(s0)
}
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr)
+ST_FUNC void gen_vla_sp_restore(int addr)
{
- EI(S, 0x03, 3, 2, 8, addr); // ld sp, fc(s0)
+ EI(0x03, 3, 2, 8, addr); // ld sp, fc(s0)
}
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align)
+ST_FUNC void gen_vla_alloc(CType *type, int align)
{
int rr;
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- vpushv(S, S->tccgen_vtop);
+ if (tcc_state->do_bounds_check)
+ vpushv(vtop);
#endif
- rr = ireg(gv(S, RC_INT));
+ rr = ireg(gv(RC_INT));
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check)
- EI(S, 0x13, 0, rr, rr, 15+1); // addi RR, RR, 15+1
+ if (tcc_state->do_bounds_check)
+ EI(0x13, 0, rr, rr, 15+1); // addi RR, RR, 15+1
else
#endif
- EI(S, 0x13, 0, rr, rr, 15); // addi RR, RR, 15
- EI(S, 0x13, 7, rr, rr, -16); // andi, RR, RR, -16
- ER(S, 0x33, 0, 2, 2, rr, 0x20); // sub sp, sp, rr
- vpop(S);
+ EI(0x13, 0, rr, rr, 15); // addi RR, RR, 15
+ EI(0x13, 7, rr, rr, -16); // andi, RR, RR, -16
+ ER(0x33, 0, 2, 2, rr, 0x20); // sub sp, sp, rr
+ vpop();
#if defined(CONFIG_TCC_BCHECK)
- if (S->do_bounds_check) {
- vpushi(S, 0);
- S->tccgen_vtop->r = TREG_R(0);
- o(S, 0x00010513); /* mv a0,sp */
- vswap(S);
- vpush_helper_func(S, TOK___bound_new_region);
- vrott(S, 3);
- gfunc_call(S, 2);
- S->func_bound_add_epilog = 1;
+ if (tcc_state->do_bounds_check) {
+ vpushi(0);
+ vtop->r = TREG_R(0);
+ o(0x00010513); /* mv a0,sp */
+ vswap();
+ vpush_helper_func(TOK___bound_new_region);
+ vrott(3);
+ gfunc_call(2);
+ func_bound_add_epilog = 1;
}
#endif
}
diff --git a/riscv64-link.c b/riscv64-link.c
index d25315a..2aeefef 100644
--- a/riscv64-link.c
+++ b/riscv64-link.c
@@ -95,39 +95,39 @@ int gotplt_entry_type (int reloc_type)
return -1;
}
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- Section *plt = S->plt;
+ Section *plt = s1->plt;
uint8_t *p;
unsigned plt_offset;
if (plt->data_offset == 0)
- section_ptr_add(S, plt, 32);
+ section_ptr_add(plt, 32);
plt_offset = plt->data_offset;
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
write64le(p, got_offset);
return plt_offset;
}
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
if (p < p_end) {
- uint64_t plt = S->plt->sh_addr;
- uint64_t got = S->got->sh_addr;
+ uint64_t plt = s1->plt->sh_addr;
+ uint64_t got = s1->got->sh_addr;
uint64_t off = (got - plt + 0x800) >> 12;
if ((off + ((uint32_t)1 << 20)) >> 21)
- tcc_error(S, "Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
+ tcc_error("Failed relocating PLT (off=0x%lx, got=0x%lx, plt=0x%lx)", (long)off, (long)got, (long)plt);
write32le(p, 0x397 | (off << 12)); // auipc t2, %pcrel_hi(got)
write32le(p + 4, 0x41c30333); // sub t1, t1, t3
write32le(p + 8, 0x0003be03 // ld t3, %pcrel_lo(got)(t2)
@@ -140,11 +140,11 @@ ST_FUNC void relocate_plt(TCCState *S)
write32le(p + 28, 0x000e0067); // jr t3
p += 32;
while (p < p_end) {
- uint64_t pc = plt + (p - S->plt->data);
+ uint64_t pc = plt + (p - s1->plt->data);
uint64_t addr = got + read64le(p);
uint64_t off = (addr - pc + 0x800) >> 12;
if ((off + ((uint32_t)1 << 20)) >> 21)
- tcc_error(S, "Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
+ tcc_error("Failed relocating PLT (off=0x%lx, addr=0x%lx, pc=0x%lx)", (long)off, (long)addr, (long)pc);
write32le(p, 0xe17 | (off << 12)); // auipc t3, %pcrel_hi(func@got)
write32le(p + 4, 0x000e3e03 // ld t3, %pcrel_lo(func@got)(t3)
| (((addr - pc) & 0xfff) << 20));
@@ -154,16 +154,16 @@ ST_FUNC void relocate_plt(TCCState *S)
}
}
- if (S->plt->reloc) {
+ if (s1->plt->reloc) {
ElfW_Rel *rel;
- p = S->got->data;
- for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
- write64le(p + rel->r_offset, S->plt->sh_addr);
+ p = s1->got->data;
+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
+ write64le(p + rel->r_offset, s1->plt->sh_addr);
}
}
}
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr,
addr_t addr, addr_t val)
{
uint64_t off64;
@@ -179,7 +179,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
case R_RISCV_BRANCH:
off64 = val - addr;
if ((off64 + (1 << 12)) & ~(uint64_t)0x1ffe)
- tcc_error(S, "R_RISCV_BRANCH relocation failed"
+ tcc_error("R_RISCV_BRANCH relocation failed"
" (val=%lx, addr=%lx)", (long)val, (long)addr);
off32 = off64 >> 1;
write32le(ptr, (read32le(ptr) & ~0xfe000f80)
@@ -191,7 +191,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
case R_RISCV_JAL:
off64 = val - addr;
if ((off64 + (1 << 21)) & ~(((uint64_t)1 << 22) - 2))
- tcc_error(S, "R_RISCV_JAL relocation failed"
+ tcc_error("R_RISCV_JAL relocation failed"
" (val=%lx, addr=%lx)", (long)val, (long)addr);
off32 = off64;
write32le(ptr, (read32le(ptr) & 0xfff)
@@ -213,7 +213,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
#endif
off64 = (int64_t)(val - addr + 0x800) >> 12;
if ((off64 + ((uint64_t)1 << 20)) >> 21)
- tcc_error(S, "R_RISCV_PCREL_HI20 relocation failed: off=%lx cond=%lx sym=%s",
+ tcc_error("R_RISCV_PCREL_HI20 relocation failed: off=%lx cond=%lx sym=%s",
(long)off64, (long)((int64_t)(off64 + ((uint64_t)1 << 20)) >> 21),
symtab_section->link->data + sym->st_name);
write32le(ptr, (read32le(ptr) & 0xfff)
@@ -222,10 +222,10 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
last_hi.val = val;
return;
case R_RISCV_GOT_HI20:
- val = S->got->sh_addr + get_sym_attr(S, sym_index, 0)->got_offset;
+ val = s1->got->sh_addr + get_sym_attr(s1, sym_index, 0)->got_offset;
off64 = (int64_t)(val - addr + 0x800) >> 12;
if ((off64 + ((uint64_t)1 << 20)) >> 21)
- tcc_error(S, "R_RISCV_GOT_HI20 relocation failed");
+ tcc_error("R_RISCV_GOT_HI20 relocation failed");
last_hi.addr = addr;
last_hi.val = val;
write32le(ptr, (read32le(ptr) & 0xfff)
@@ -236,7 +236,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
printf("PCREL_LO12_I: val=%lx addr=%lx\n", (long)val, (long)addr);
#endif
if (val != last_hi.addr)
- tcc_error(S, "unsupported hi/lo pcrel reloc scheme");
+ tcc_error("unsupported hi/lo pcrel reloc scheme");
val = last_hi.val;
addr = last_hi.addr;
write32le(ptr, (read32le(ptr) & 0xfffff)
@@ -244,7 +244,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
return;
case R_RISCV_PCREL_LO12_S:
if (val != last_hi.addr)
- tcc_error(S, "unsupported hi/lo pcrel reloc scheme");
+ tcc_error("unsupported hi/lo pcrel reloc scheme");
val = last_hi.val;
addr = last_hi.addr;
off32 = val - addr;
@@ -256,7 +256,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
case R_RISCV_RVC_BRANCH:
off64 = (val - addr);
if ((off64 + (1 << 8)) & ~(uint64_t)0x1fe)
- tcc_error(S, "R_RISCV_RVC_BRANCH relocation failed"
+ tcc_error("R_RISCV_RVC_BRANCH relocation failed"
" (val=%lx, addr=%lx)", (long)val, (long)addr);
off32 = off64;
write16le(ptr, (read16le(ptr) & 0xe383)
@@ -269,7 +269,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
case R_RISCV_RVC_JUMP:
off64 = (val - addr);
if ((off64 + (1 << 11)) & ~(uint64_t)0xffe)
- tcc_error(S, "R_RISCV_RVC_BRANCH relocation failed"
+ tcc_error("R_RISCV_RVC_BRANCH relocation failed"
" (val=%lx, addr=%lx)", (long)val, (long)addr);
off32 = off64;
write16le(ptr, (read16le(ptr) & 0xe003)
@@ -284,7 +284,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
return;
case R_RISCV_32:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* XXX: this logic may depend on TCC's codegen
now TCC uses R_RISCV_RELATIVE even for a 64bit pointer */
qrel->r_offset = rel->r_offset;
@@ -296,8 +296,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr,
add32le(ptr, val);
return;
case R_RISCV_64:
- if (S->output_type == TCC_OUTPUT_DLL) {
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
qrel->r_info = ELFW(R_INFO)(esym_index, R_RISCV_64);
diff --git a/tcc.c b/tcc.c
index c2e5d81..42a251b 100644
--- a/tcc.c
+++ b/tcc.c
@@ -199,40 +199,40 @@ static void print_dirs(const char *msg, char **paths, int nb_paths)
printf(" %s\n", paths[i]);
}
-static void print_search_dirs(TCCState *S)
+static void print_search_dirs(TCCState *s)
{
- printf("install: %s\n", S->tcc_lib_path);
+ printf("install: %s\n", s->tcc_lib_path);
/* print_dirs("programs", NULL, 0); */
- print_dirs("include", S->sysinclude_paths, S->nb_sysinclude_paths);
- print_dirs("libraries", S->library_paths, S->nb_library_paths);
+ print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths);
+ print_dirs("libraries", s->library_paths, s->nb_library_paths);
#ifdef TCC_TARGET_PE
- printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", S->tcc_lib_path);
+ printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", s->tcc_lib_path);
#else
- printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", S->tcc_lib_path);
- print_dirs("crt", S->crt_paths, S->nb_crt_paths);
- printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(S));
+ printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
+ print_dirs("crt", s->crt_paths, s->nb_crt_paths);
+ printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
#endif
}
-static void set_environment(TCCState *S)
+static void set_environment(TCCState *s)
{
char * path;
path = getenv("C_INCLUDE_PATH");
if(path != NULL) {
- tcc_add_sysinclude_path(S, path);
+ tcc_add_sysinclude_path(s, path);
}
path = getenv("CPATH");
if(path != NULL) {
- tcc_add_include_path(S, path);
+ tcc_add_include_path(s, path);
}
path = getenv("LIBRARY_PATH");
if(path != NULL) {
- tcc_add_library_path(S, path);
+ tcc_add_library_path(s, path);
}
}
-static char *default_outputfile(TCCState *S, const char *first_file)
+static char *default_outputfile(TCCState *s, const char *first_file)
{
char buf[1024];
char *ext;
@@ -243,18 +243,18 @@ static char *default_outputfile(TCCState *S, const char *first_file)
snprintf(buf, sizeof(buf), "%s", name);
ext = tcc_fileextension(buf);
#ifdef TCC_TARGET_PE
- if (S->output_type == TCC_OUTPUT_DLL)
+ if (s->output_type == TCC_OUTPUT_DLL)
strcpy(ext, ".dll");
else
- if (S->output_type == TCC_OUTPUT_EXE)
+ if (s->output_type == TCC_OUTPUT_EXE)
strcpy(ext, ".exe");
else
#endif
- if ((S->just_deps || S->output_type == TCC_OUTPUT_OBJ) && !S->option_r && *ext)
+ if ((s->just_deps || s->output_type == TCC_OUTPUT_OBJ) && !s->option_r && *ext)
strcpy(ext, ".o");
else
strcpy(buf, "a.out");
- return tcc_strdup(S, buf);
+ return tcc_strdup(buf);
}
static unsigned getclock_ms(void)
@@ -268,101 +268,9 @@ static unsigned getclock_ms(void)
#endif
}
-#ifdef WITH_ATTACHMENTS
-#include "tcc_attachments.h"
-#define ATTACH_PREFIX "/_attach_"
-
-static vio_module_t vio_module;
-
-typedef struct vio_memfile_t {
- off_t size;
- off_t pos;
- const unsigned char *mem;
-} vio_memfile_t;
-
-static int vio_mem_open(vio_fd *fd, const char *fn, int oflag) {
- //printf("%d:%s\n", fd->fd, fn);
- if(fd->vio_module && strncmp(ATTACH_PREFIX, fn, sizeof(ATTACH_PREFIX)-1) == 0){
- int i, count = sizeof(bin2c_filesAttached)/sizeof(bin2c_filesAttached_st);
- for(i=0; i < count; ++i) {
- //printf("%s:%s\n", fn, bin2c_filesAttached[i].file_name);
- if(strcmp(fn, bin2c_filesAttached[i].file_name) == 0) {
- vio_memfile_t *mf = (vio_memfile_t*)tcc_malloc(S, fd->vio_module->tcc_state);
- mf->mem = bin2c_filesAttached[i].sym_name;
- mf->size = bin2c_filesAttached[i].size;
- mf->pos = 0;
- fd->fd = 1;
- fd->vio_udata = mf;
- //printf("%d:%s\n", fd->fd, fn);
- return fd->fd;
- }
- }
- }
- return -1;
-}
-
-static off_t vio_mem_lseek(vio_fd fd, off_t offset, int whence) {
- if(fd.vio_udata) {
- off_t loffset = 0;
- vio_memfile_t *mf = (vio_memfile_t*)fd.vio_udata;
- if (whence == SEEK_CUR)
- loffset = mf->pos + offset;
- else if (whence == SEEK_SET)
- loffset = offset;
- else if (whence == SEEK_END)
- loffset = ((off_t)mf->size) + offset;
-
- if (loffset < 0 && loffset > mf->size)
- return -1;
-
- mf->pos = loffset;
-
- return mf->pos;
- }
- return lseek(fd.fd, offset, whence);
-}
-
-static size_t vio_mem_read(vio_fd fd, void *buf, size_t bytes) {
- if(fd.vio_udata) {
- vio_memfile_t *mf = (vio_memfile_t*)fd.vio_udata;
- if( (mf->pos + bytes) > mf->size) {
- long bc = mf->size - mf->pos;
- if(bc > 0) {
- memcpy(buf, mf->mem + mf->pos, bc);
- mf->pos = mf->size;
- return bc;
- }
- return 0;
- }
- memcpy(buf, mf->mem + mf->pos, bytes);
- mf->pos += bytes;
- return bytes;
- }
- return 0;
-}
-
-static int vio_mem_close(vio_fd *fd) {
- if(fd->vio_udata){
- tcc_free(S, fd->vio_udata);
- }
- return 0;
-}
-
-void set_vio_module(TCCState *S){
- vio_module.user_data = NULL;
- vio_module.call_vio_open_flags = CALL_VIO_OPEN_FIRST;
- vio_module.vio_open = &vio_mem_open;
- vio_module.vio_lseek = &vio_mem_lseek;
- vio_module.vio_read = &vio_mem_read;
- vio_module.vio_close = &vio_mem_close;
- tcc_set_vio_module(s, &vio_module);
-}
-
-#endif
-
int main(int argc0, char **argv0)
{
- TCCState *S, *s1;
+ TCCState *s, *s1;
int ret, opt, n = 0, t = 0, done;
unsigned start_time = 0, end_time = 0;
const char *first_file;
@@ -371,19 +279,13 @@ int main(int argc0, char **argv0)
redo:
argc = argc0, argv = argv0;
- S = s1 = tcc_new();
- opt = tcc_parse_args(S, &argc, &argv, 1);
-
-#ifdef WITH_ATTACHMENTS
- tcc_set_lib_path(S, ATTACH_PREFIX);
- tcc_add_include_path(S, ATTACH_PREFIX);
- set_vio_module(S);
-#endif
+ s = s1 = tcc_new();
+ opt = tcc_parse_args(s, &argc, &argv, 1);
if (n == 0) {
if (opt == OPT_HELP) {
fputs(help, stdout);
- if (!S->verbose)
+ if (!s->verbose)
return 0;
++opt;
}
@@ -392,57 +294,57 @@ redo:
return 0;
}
if (opt == OPT_M32 || opt == OPT_M64)
- tcc_tool_cross(S, argv, opt); /* never returns */
- if (S->verbose)
+ tcc_tool_cross(s, argv, opt); /* never returns */
+ if (s->verbose)
printf(version);
if (opt == OPT_AR)
- return tcc_tool_ar(S, argc, argv);
+ return tcc_tool_ar(s, argc, argv);
#ifdef TCC_TARGET_PE
if (opt == OPT_IMPDEF)
- return tcc_tool_impdef(S, argc, argv);
+ return tcc_tool_impdef(s, argc, argv);
#endif
if (opt == OPT_V)
return 0;
if (opt == OPT_PRINT_DIRS) {
/* initialize search dirs */
- set_environment(S);
- tcc_set_output_type(S, TCC_OUTPUT_MEMORY);
- print_search_dirs(S);
+ set_environment(s);
+ tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
+ print_search_dirs(s);
return 0;
}
- if (S->nb_files == 0)
- tcc_error(S, "no input files");
+ if (s->nb_files == 0)
+ tcc_error("no input files");
- if (S->output_type == TCC_OUTPUT_PREPROCESS) {
- if (S->outfile && 0!=strcmp("-",S->outfile)) {
- ppfp = fopen(S->outfile, "w");
+ if (s->output_type == TCC_OUTPUT_PREPROCESS) {
+ if (s->outfile && 0!=strcmp("-",s->outfile)) {
+ ppfp = fopen(s->outfile, "w");
if (!ppfp)
- tcc_error(S, "could not write '%s'", S->outfile);
+ tcc_error("could not write '%s'", s->outfile);
}
- } else if (S->output_type == TCC_OUTPUT_OBJ && !S->option_r) {
- if (S->nb_libraries)
- tcc_error(S, "cannot specify libraries with -c");
- if (S->nb_files > 1 && S->outfile)
- tcc_error(S, "cannot specify output file with -c many files");
+ } else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) {
+ if (s->nb_libraries)
+ tcc_error("cannot specify libraries with -c");
+ if (s->nb_files > 1 && s->outfile)
+ tcc_error("cannot specify output file with -c many files");
}
- if (S->do_bench)
+ if (s->do_bench)
start_time = getclock_ms();
}
- set_environment(S);
- if (S->output_type == 0)
- S->output_type = TCC_OUTPUT_EXE;
- tcc_set_output_type(S, S->output_type);
- S->ppfp = ppfp;
+ set_environment(s);
+ if (s->output_type == 0)
+ s->output_type = TCC_OUTPUT_EXE;
+ tcc_set_output_type(s, s->output_type);
+ s->ppfp = ppfp;
- if ((S->output_type == TCC_OUTPUT_MEMORY
- || S->output_type == TCC_OUTPUT_PREPROCESS)
- && (S->dflag & TCC_OPTION_d_t)) { /* -dt option */
+ if ((s->output_type == TCC_OUTPUT_MEMORY
+ || s->output_type == TCC_OUTPUT_PREPROCESS)
+ && (s->dflag & 16)) { /* -dt option */
if (t)
- S->dflag |= TCC_OPTION_d_32;
- S->run_test = ++t;
+ s->dflag |= 32;
+ s->run_test = ++t;
if (n)
--n;
}
@@ -450,48 +352,48 @@ redo:
/* compile or add each files or library */
first_file = NULL, ret = 0;
do {
- struct filespec *f = S->files[n];
- S->filetype = f->type;
+ struct filespec *f = s->files[n];
+ s->filetype = f->type;
if (f->type & AFF_TYPE_LIB) {
- if (tcc_add_library_err(S, f->name) < 0)
+ if (tcc_add_library_err(s, f->name) < 0)
ret = 1;
} else {
- if (1 == S->verbose)
+ if (1 == s->verbose)
printf("-> %s\n", f->name);
if (!first_file)
first_file = f->name;
- if (tcc_add_file(S, f->name) < 0)
+ if (tcc_add_file(s, f->name) < 0)
ret = 1;
}
- done = ret || ++n >= S->nb_files;
- } while (!done && (S->output_type != TCC_OUTPUT_OBJ || S->option_r));
+ done = ret || ++n >= s->nb_files;
+ } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r));
- if (S->do_bench)
+ if (s->do_bench)
end_time = getclock_ms();
- if (S->run_test) {
+ if (s->run_test) {
t = 0;
- } else if (S->output_type == TCC_OUTPUT_PREPROCESS) {
+ } else if (s->output_type == TCC_OUTPUT_PREPROCESS) {
;
} else if (0 == ret) {
- if (S->output_type == TCC_OUTPUT_MEMORY) {
+ if (s->output_type == TCC_OUTPUT_MEMORY) {
#ifdef TCC_IS_NATIVE
- ret = tcc_run(S, argc, argv);
+ ret = tcc_run(s, argc, argv);
#endif
} else {
- if (!S->outfile)
- S->outfile = default_outputfile(S, first_file);
- if (!S->just_deps && tcc_output_file(S, S->outfile))
+ if (!s->outfile)
+ s->outfile = default_outputfile(s, first_file);
+ if (!s->just_deps && tcc_output_file(s, s->outfile))
ret = 1;
- else if (S->gen_deps)
- gen_makedeps(S, S->outfile, S->deps_outfile);
+ else if (s->gen_deps)
+ gen_makedeps(s, s->outfile, s->deps_outfile);
}
}
- if (done && 0 == t && 0 == ret && S->do_bench)
- tcc_print_stats(S, end_time - start_time);
+ if (done && 0 == t && 0 == ret && s->do_bench)
+ tcc_print_stats(s, end_time - start_time);
- tcc_delete(S);
+ tcc_delete(s);
if (!done)
goto redo; /* compile more files with -c */
if (t)
diff --git a/tcc.h b/tcc.h
index b020b90..ef69ef5 100644
--- a/tcc.h
+++ b/tcc.h
@@ -585,7 +585,7 @@ typedef struct Section {
unsigned long data_offset; /* current data offset */
unsigned char *data; /* section data */
unsigned long data_allocated; /* used for realloc() handling */
- TCCState *S;
+ TCCState *s1;
int sh_name; /* elf section name (only used during output) */
int sh_num; /* elf section number */
int sh_type; /* elf section type */
@@ -743,78 +743,6 @@ struct sym_attr {
#endif
};
-/*From tccpp.c*/
-typedef struct TinyAlloc {
- unsigned limit;
- unsigned size;
- uint8_t *buffer;
- uint8_t *p;
- unsigned nb_allocs;
- struct TinyAlloc *next, *top;
-#ifdef TAL_INFO
- unsigned nb_peak;
- unsigned nb_total;
- unsigned nb_missed;
- uint8_t *peak_p;
-#endif
-} TinyAlloc;
-
-/*From tccgen.c*/
-typedef struct scope_t {
- struct scope_t *prev;
- struct { int loc, locorig, num; } vla;
- struct { Sym *s; int n; } cl;
- int *bsym, *csym;
- Sym *lstk, *llstk;
-} scope_t;
-
-typedef struct switch_t {
- struct case_t {
- int64_t v1, v2;
- int sym;
- } **p; int n; /* list of case ranges */
- int def_sym; /* default symbol */
- int *bsym;
- scope_t *scope;
- struct switch_t *prev;
- SValue sv;
-} switch_t;
-
-#define MAX_TEMP_LOCAL_VARIABLE_NUMBER 8
-/*list of temporary local variables on the stack in current function. */
-typedef struct temp_local_variable_t {
- int location; //offset on stack. Svalue.c.i
- short size;
- short align;
-} temp_local_variable_t;
-
-typedef struct {
- unsigned long offset;
- unsigned long last_file_name;
- unsigned long last_func_name;
- int ind;
- int line;
-} tcov_data_t;
-
-typedef struct {
- int debug_type;
- Sym *type;
-} debug_hash_t;
-
-typedef struct debug_info_t {
- int start;
- int end;
- int n_sym;
- struct debug_sym {
- int type;
- unsigned long value;
- char *str;
- Section *sec;
- int sym_index;
- } *sym;
- struct debug_info_t *child, *next, *last, *parent;
-} debug_info_t;
-
struct TCCState {
unsigned char verbose; /* if true, display some information during compilation */
unsigned char nostdinc; /* if true, no standard headers are added */
@@ -999,11 +927,11 @@ struct TCCState {
int nb_sym_attrs;
/* ptr to next reloc entry reused */
ElfW_Rel *qrel;
- #define qrel S->qrel
+ #define qrel s1->qrel
#ifdef TCC_TARGET_RISCV64
struct pcrel_hi { addr_t addr, val; } last_hi;
- #define last_hi S->last_hi
+ #define last_hi s1->last_hi
#endif
#ifdef TCC_TARGET_PE
@@ -1034,10 +962,6 @@ struct TCCState {
const char *runtime_main;
void **runtime_mem;
int nb_runtime_mem;
-# ifdef HAVE_SELINUX
- void *write_mem;
- unsigned long mem_size;
-# endif
#endif
#ifdef CONFIG_TCC_BACKTRACE
@@ -1067,117 +991,6 @@ struct TCCState {
char *deps_outfile; /* option -MF */
int argc;
char **argv;
-
- /* Entries needed to make it reentrant */
- vio_module_t *vio_module;
-
- /* ------------ tccpp.c ------------ */
-
- struct BufferedFile *tccpp_file;
- int tccpp_ch, tccpp_tok;
- CValue tccpp_tokc;
- const int *tccpp_macro_ptr;
- int tccpp_parse_flags;
- int tccpp_tok_flags;
- CString tccpp_tokcstr; /* current parsed string, if any */
- CString tccpp_cstr_buf;
- CString tccpp_macro_equal_buf;
- TokenString tccpp_tokstr_buf;
- TokenString *tccpp_macro_stack;
-
- /* display benchmark infos */
- int tccpp_total_lines;
- int tccpp_total_bytes;
- int tccpp_tok_ident;
- TokenSym **tccpp_table_ident;
-
- int *tccpp_macro_ptr_allocated;
- const int *tccpp_unget_saved_macro_ptr;
- int tccpp_unget_saved_buffer[TOK_MAX_SIZE + 1];
- int tccpp_unget_buffer_enabled;
- TokenSym *tccpp_hash_ident[TOK_HASH_SIZE];
- char tccpp_token_buf[STRING_MAX_SIZE + 1];
- /* true if isid(c) || isnum(c) */
- unsigned char tccpp_isidnum_table[256-CH_EOF];
-
- int tccpp_pp_debug_tok, tccpp_pp_debug_symv;
- int tccpp_pp_once;
- int tccpp_pp_expr;
- int tccpp_pp_counter;
-
- TinyAlloc *tccpp_toksym_alloc;
- TinyAlloc *tccpp_tokstr_alloc;
-
- /*----------- tccasm.c --------*/
- Section *tccasm_last_text_section; /* to handle .previous asm directive */
-
- /* ------------ tccgen.c ------------ */
-
- Sym *tccgen_global_stack;
- Sym *tccgen_local_stack;
- Sym *tccgen_local_label_stack;
- Sym *tccgen_global_label_stack;
- Sym *tccgen_define_stack;
- CType tccgen_int_type, tccgen_func_old_type, tccgen_char_type, tccgen_char_pointer_type;
- SValue *tccgen_vtop;
- SValue tccgen__vstack[1 + VSTACK_SIZE];
- int tccgen_rsym, tccgen_anon_sym, tccgen_ind, tccgen_loc;
- char tccgen_debug_modes;
-
- int tccgen_const_wanted; /* true if constant wanted */
- int tccgen_nocode_wanted; /* true if no code generation wanted for an expression */
- int tccgen_global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
- CType tccgen_func_vt; /* current function return type (used by return instruction) */
- int tccgen_func_var; /* true if current function is variadic */
- int tccgen_func_vc;
- const char *tccgen_funcname;
-
- Sym *tccgen_sym_free_first;
- void **tccgen_sym_pools;
- int tccgen_nb_sym_pools;
- Sym *tccgen_all_cleanups, *tccgen_pending_gotos;
- int tccgen_local_scope;
- int tccgen_in_sizeof;
- int tccgen_in_generic;
- int tccgen_section_sym;
-
- int tccgen_last_line_num, tccgen_new_file, tccgen_func_ind; /* debug info control */
- CString tccgen_initstr;
-
- switch_t *tccgen_cur_switch; /* current switch */
-
- temp_local_variable_t tccgen_arr_temp_local_vars[MAX_TEMP_LOCAL_VARIABLE_NUMBER];
- int tccgen_nb_temp_local_vars;
-
- scope_t *tccgen_cur_scope, *tccgen_loop_scope, *tccgen_root_scope;
-
- tcov_data_t tccgen_tcov_data;
- int tccgen_debug_next_type;
- debug_hash_t *tccgen_debug_hash;
- int tccgen_n_debug_hash;
- debug_info_t *tccgen_debug_info, *tccgen_debug_info_root;
-
- unsigned char tccgen_prec[256];
-
- /*--------armg-gen.c-----------*/
-/*#if defined(TCC_ARM_EABI) && defined(TCC_ARM_VFP)*/
- CType armgen_float_type, armgen_double_type, armgen_func_float_type, armgen_func_double_type;
-/*#endif*/
-
- /*------- tccrun.c ------------*/
-
- /*--------x86_64-gen.c --------*/
- unsigned long x86_64_gen_func_sub_sp_offset;
- int x86_64_gen_func_ret_sub;
-#if defined(CONFIG_TCC_BCHECK)
- addr_t func_bound_offset;
- unsigned long func_bound_ind;
- int func_bound_add_epilog;
-#endif
-#ifdef TCC_TARGET_PE
- int x86_64_gen_func_scratch, x86_64_gen_func_alloca;
-#endif
-
};
struct filespec {
@@ -1361,7 +1174,7 @@ enum tcc_token {
/* ------------ libtcc.c ------------ */
-//ST_DATA struct TCCState *S;
+ST_DATA struct TCCState *tcc_state;
/* public functions currently used by the tcc main function */
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);
PUB_FUNC char *tcc_basename(const char *name);
PUB_FUNC char *tcc_fileextension (const char *name);
-PUB_FUNC void tcc_free_base(void *ptr);
-PUB_FUNC void *tcc_malloc_base(unsigned long size);
-PUB_FUNC void *tcc_mallocz_base(unsigned long size);
#ifndef MEM_DEBUG
-PUB_FUNC void tcc_free(TCCState* S, void *ptr);
-PUB_FUNC void *tcc_malloc(TCCState* S, unsigned long size);
-PUB_FUNC void *tcc_mallocz(TCCState* S, unsigned long size);
-PUB_FUNC void *tcc_realloc(TCCState* S, void *ptr, unsigned long size);
-PUB_FUNC char *tcc_strdup(TCCState* S, const char *str);
+PUB_FUNC void tcc_free(void *ptr);
+PUB_FUNC void *tcc_malloc(unsigned long size);
+PUB_FUNC void *tcc_mallocz(unsigned long size);
+PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
+PUB_FUNC char *tcc_strdup(const char *str);
#else
-#define tcc_free(s, ptr) tcc_free_debug(s, ptr)
-#define tcc_malloc(s, size) tcc_malloc_debug(s, size, __FILE__, __LINE__)
-#define tcc_mallocz(s, size) tcc_mallocz_debug(s, size, __FILE__, __LINE__)
-#define tcc_realloc(s, ptr, size) tcc_realloc_debug(s, ptr, size, __FILE__, __LINE__)
-#define tcc_strdup(s, str) tcc_strdup_debug(s, str, __FILE__, __LINE__)
-PUB_FUNC void tcc_free_debug(TCCState* S, void *ptr);
-PUB_FUNC void *tcc_malloc_debug(TCCState* S, unsigned long size, const char *file, int line);
-PUB_FUNC void *tcc_mallocz_debug(TCCState* S, unsigned long size, const char *file, int line);
-PUB_FUNC void *tcc_realloc_debug(TCCState* S, void *ptr, unsigned long size, const char *file, int line);
-PUB_FUNC char *tcc_strdup_debug(TCCState* S, const char *str, const char *file, int line);
-#endif
-
-#define free(p) use_tcc_free(S, p)
-#define malloc(s) use_tcc_malloc(S, s)
-#define realloc(p, s) use_tcc_realloc(S, p, s)
+#define tcc_free(ptr) tcc_free_debug(ptr)
+#define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
+#define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
+#define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
+#define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
+PUB_FUNC void tcc_free_debug(void *ptr);
+PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
+PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
+PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
+PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
+#endif
+
+#define free(p) use_tcc_free(p)
+#define malloc(s) use_tcc_malloc(s)
+#define realloc(p, s) use_tcc_realloc(p, s)
#undef strdup
-#define strdup(s) use_tcc_strdup(S, s)
-PUB_FUNC void _tcc_error_noabort(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
-PUB_FUNC NORETURN void _tcc_error(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
-PUB_FUNC void _tcc_warning(TCCState* S, const char *fmt, ...) PRINTF_LIKE(2,3);
-#define tcc_internal_error(S, msg) tcc_error(S, "internal compiler error\n"\
+#define strdup(s) use_tcc_strdup(s)
+PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) PRINTF_LIKE(1,2);
+PUB_FUNC NORETURN void _tcc_error(const char *fmt, ...) PRINTF_LIKE(1,2);
+PUB_FUNC void _tcc_warning(const char *fmt, ...) PRINTF_LIKE(1,2);
+#define tcc_internal_error(msg) tcc_error("internal compiler error\n"\
"%s:%d: in %s(): " msg, __FILE__,__LINE__,__FUNCTION__)
/* other utilities */
-ST_FUNC void dynarray_add(TCCState* S, void *ptab, int *nb_ptr, void *data);
-ST_FUNC void dynarray_reset(TCCState* S, void *pp, int *n);
-ST_INLN void cstr_ccat(TCCState* S, CString *cstr, int ch);
-ST_FUNC void cstr_cat(TCCState* S, CString *cstr, const char *str, int len);
-ST_FUNC void cstr_wccat(TCCState* S, CString *cstr, int ch);
-ST_FUNC void cstr_new(TCCState* S, CString *cstr);
-ST_FUNC void cstr_free(TCCState* S, CString *cstr);
-ST_FUNC int cstr_printf(TCCState* S, CString *cs, const char *fmt, ...) PRINTF_LIKE(3,4);
-ST_FUNC int cstr_vprintf(TCCState* S, CString *cstr, const char *fmt, va_list ap);
+ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
+ST_FUNC void dynarray_reset(void *pp, int *n);
+ST_INLN void cstr_ccat(CString *cstr, int ch);
+ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
+ST_FUNC void cstr_wccat(CString *cstr, int ch);
+ST_FUNC void cstr_new(CString *cstr);
+ST_FUNC void cstr_free(CString *cstr);
+ST_FUNC int cstr_printf(CString *cs, const char *fmt, ...) PRINTF_LIKE(2,3);
+ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap);
ST_FUNC void cstr_reset(CString *cstr);
-ST_FUNC void tcc_open_bf(TCCState *S, const char *filename, int initlen);
-ST_FUNC int tcc_open(TCCState *S, const char *filename);
-ST_FUNC void tcc_close(TCCState *S);
+ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
+ST_FUNC int tcc_open(TCCState *s1, const char *filename);
+ST_FUNC void tcc_close(void);
-ST_FUNC int tcc_add_file_internal(TCCState *S, const char *filename, int flags);
+ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
/* flags: */
#define AFF_PRINT_ERROR 0x10 /* print error if file not found */
#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);
#define AFF_BINTYPE_C67 4
#ifndef ELF_OBJ_ONLY
-ST_FUNC int tcc_add_crt(TCCState *S, const char *filename);
+ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
#endif
#ifndef TCC_TARGET_MACHO
-ST_FUNC int tcc_add_dll(TCCState *S, const char *filename, int flags);
+ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
#endif
#ifdef CONFIG_TCC_BCHECK
-ST_FUNC void tcc_add_bcheck(TCCState *S);
+ST_FUNC void tcc_add_bcheck(TCCState *s1);
#endif
#ifdef CONFIG_TCC_BACKTRACE
-ST_FUNC void tcc_add_btstub(TCCState *S);
+ST_FUNC void tcc_add_btstub(TCCState *s1);
#endif
-ST_FUNC void tcc_add_pragma_libs(TCCState *S);
-PUB_FUNC int tcc_add_library_err(TCCState *S, const char *f);
-PUB_FUNC void tcc_print_stats(TCCState *S, unsigned total_time);
-PUB_FUNC int tcc_parse_args(TCCState *S, int *argc, char ***argv, int optind);
+ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
+PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
+PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
+PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
#ifdef _WIN32
ST_FUNC char *normalize_slashes(char *path);
#endif
-ST_FUNC DLLReference *tcc_add_dllref(TCCState *S, const char *dllname);
-ST_FUNC char *tcc_load_text(TCCState *S, int fd);
+ST_FUNC DLLReference *tcc_add_dllref(TCCState *s1, const char *dllname);
+ST_FUNC char *tcc_load_text(int fd);
/* tcc_parse_args return codes: */
#define OPT_HELP 1
@@ -1472,6 +1282,18 @@ ST_FUNC char *tcc_load_text(TCCState *S, int fd);
/* ------------ tccpp.c ------------ */
+ST_DATA struct BufferedFile *file;
+ST_DATA int ch, tok;
+ST_DATA CValue tokc;
+ST_DATA const int *macro_ptr;
+ST_DATA int parse_flags;
+ST_DATA int tok_flags;
+ST_DATA CString tokcstr; /* current parsed string, if any */
+
+/* display benchmark infos */
+ST_DATA int tok_ident;
+ST_DATA TokenSym **table_ident;
+
#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
@@ -1499,36 +1321,36 @@ enum line_macro_output_format {
LINE_MACRO_OUTPUT_FORMAT_P10 = 11
};
-ST_FUNC TokenSym *tok_alloc(TCCState* S, const char *str, int len);
-ST_FUNC int tok_alloc_const(TCCState* S, const char *str);
-ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv);
-ST_FUNC void begin_macro(TCCState* S, TokenString *str, int alloc);
-ST_FUNC void end_macro(TCCState* S);
-ST_FUNC int set_idnum(TCCState* S, int c, int val);
+ST_FUNC TokenSym *tok_alloc(const char *str, int len);
+ST_FUNC int tok_alloc_const(const char *str);
+ST_FUNC const char *get_tok_str(int v, CValue *cv);
+ST_FUNC void begin_macro(TokenString *str, int alloc);
+ST_FUNC void end_macro(void);
+ST_FUNC int set_idnum(int c, int val);
ST_INLN void tok_str_new(TokenString *s);
-ST_FUNC TokenString *tok_str_alloc(TCCState* S);
-ST_FUNC void tok_str_free(TCCState* S, TokenString *s);
-ST_FUNC void tok_str_free_str(TCCState* S, int *str);
-ST_FUNC void tok_str_add(TCCState* S, TokenString *s, int t);
-ST_FUNC void tok_str_add_tok(TCCState* S, TokenString *s);
-ST_INLN void define_push(TCCState* S, int v, int macro_type, int *str, Sym *first_arg);
-ST_FUNC void define_undef(TCCState* S, Sym *s);
-ST_INLN Sym *define_find(TCCState* S, int v);
-ST_FUNC void free_defines(TCCState* S, Sym *b);
-ST_FUNC Sym *label_find(TCCState* S, int v);
-ST_FUNC Sym *label_push(TCCState* S, Sym **ptop, int v, int flags);
-ST_FUNC void label_pop(TCCState* S, Sym **ptop, Sym *slast, int keep);
-ST_FUNC void parse_define(TCCState* S);
-ST_FUNC void preprocess(TCCState* S, int is_bof);
-ST_FUNC void next(TCCState* S);
-ST_INLN void unget_tok(TCCState* S, int last_tok);
-ST_FUNC void preprocess_start(TCCState *S, int filetype);
-ST_FUNC void preprocess_end(TCCState *S);
-ST_FUNC void tccpp_new(TCCState *S);
-ST_FUNC void tccpp_delete(TCCState *S);
-ST_FUNC int tcc_preprocess(TCCState *S);
-ST_FUNC void skip(TCCState* S, int c);
-ST_FUNC NORETURN void expect(TCCState* S, const char *msg);
+ST_FUNC TokenString *tok_str_alloc(void);
+ST_FUNC void tok_str_free(TokenString *s);
+ST_FUNC void tok_str_free_str(int *str);
+ST_FUNC void tok_str_add(TokenString *s, int t);
+ST_FUNC void tok_str_add_tok(TokenString *s);
+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
+ST_FUNC void define_undef(Sym *s);
+ST_INLN Sym *define_find(int v);
+ST_FUNC void free_defines(Sym *b);
+ST_FUNC Sym *label_find(int v);
+ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
+ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep);
+ST_FUNC void parse_define(void);
+ST_FUNC void preprocess(int is_bof);
+ST_FUNC void next(void);
+ST_INLN void unget_tok(int last_tok);
+ST_FUNC void preprocess_start(TCCState *s1, int filetype);
+ST_FUNC void preprocess_end(TCCState *s1);
+ST_FUNC void tccpp_new(TCCState *s);
+ST_FUNC void tccpp_delete(TCCState *s);
+ST_FUNC int tcc_preprocess(TCCState *s1);
+ST_FUNC void skip(int c);
+ST_FUNC NORETURN void expect(const char *msg);
/* space excluding newline */
static inline int is_space(int ch) {
@@ -1550,85 +1372,104 @@ static inline int toup(int c) {
/* ------------ tccgen.c ------------ */
#define SYM_POOL_NB (8192 / sizeof(Sym))
-ST_FUNC void tcc_debug_start(TCCState *S);
-ST_FUNC void tcc_debug_end(TCCState *S);
-ST_FUNC void tcc_debug_bincl(TCCState *S);
-ST_FUNC void tcc_debug_eincl(TCCState *S);
-ST_FUNC void tcc_debug_putfile(TCCState *S, const char *filename);
-ST_FUNC void tccgen_init(TCCState *S);
-ST_FUNC int tccgen_compile(TCCState *S);
-ST_FUNC void tccgen_finish(TCCState *S);
-ST_FUNC void check_vstack(TCCState* S);
+ST_DATA Sym *global_stack;
+ST_DATA Sym *local_stack;
+ST_DATA Sym *local_label_stack;
+ST_DATA Sym *global_label_stack;
+ST_DATA Sym *define_stack;
+ST_DATA CType int_type, func_old_type, char_pointer_type;
+ST_DATA SValue *vtop;
+ST_DATA int rsym, anon_sym, ind, loc;
+ST_DATA char debug_modes;
+
+ST_DATA int const_wanted; /* true if constant wanted */
+ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
+ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
+ST_DATA CType func_vt; /* current function return type (used by return instruction) */
+ST_DATA int func_var; /* true if current function is variadic */
+ST_DATA int func_vc;
+ST_DATA const char *funcname;
+
+ST_FUNC void tcc_debug_start(TCCState *s1);
+ST_FUNC void tcc_debug_end(TCCState *s1);
+ST_FUNC void tcc_debug_bincl(TCCState *s1);
+ST_FUNC void tcc_debug_eincl(TCCState *s1);
+ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
+
+ST_FUNC void tccgen_init(TCCState *s1);
+ST_FUNC int tccgen_compile(TCCState *s1);
+ST_FUNC void tccgen_finish(TCCState *s1);
+ST_FUNC void check_vstack(void);
ST_INLN int is_float(int t);
ST_FUNC int ieee_finite(double d);
ST_FUNC int exact_log2p1(int i);
-ST_FUNC void test_lvalue(TCCState* S);
+ST_FUNC void test_lvalue(void);
-ST_FUNC ElfSym *elfsym(TCCState* S, Sym *);
-ST_FUNC void update_storage(TCCState* S, Sym *sym);
-ST_FUNC void put_extern_sym2(TCCState* S, Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
-ST_FUNC void put_extern_sym(TCCState* S, Sym *sym, Section *section, addr_t value, unsigned long size);
+ST_FUNC ElfSym *elfsym(Sym *);
+ST_FUNC void update_storage(Sym *sym);
+ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
+ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
#if PTR_SIZE == 4
-ST_FUNC void greloc(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type);
+ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
#endif
-ST_FUNC void greloca(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
+ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
-ST_INLN void sym_free(TCCState* S, Sym *sym);
-ST_FUNC Sym *sym_push(TCCState* S, int v, CType *type, int r, int c);
-ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep);
-ST_FUNC Sym *sym_push2(TCCState* S, Sym **ps, int v, int t, int c);
+ST_INLN void sym_free(Sym *sym);
+ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
+ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
+ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
ST_FUNC Sym *sym_find2(Sym *s, int v);
-ST_INLN Sym *sym_find(TCCState* S, int v);
-ST_INLN Sym *struct_find(TCCState* S, int v);
-
-ST_FUNC Sym *global_identifier_push(TCCState* S, int v, int t, int c);
-ST_FUNC Sym *external_global_sym(TCCState* S, int v, CType *type);
-ST_FUNC Sym *external_helper_sym(TCCState* S, int v);
-ST_FUNC void vpush_helper_func(TCCState* S, int v);
-ST_FUNC void vset(TCCState* S, CType *type, int r, int v);
-ST_FUNC void vset_VT_CMP(TCCState* S, int op);
-ST_FUNC void vpushi(TCCState* S, int v);
-ST_FUNC void vpushv(TCCState* S, SValue *v);
-ST_FUNC void vpushsym(TCCState* S, CType *type, Sym *sym);
-ST_FUNC void vswap(TCCState* S);
-ST_FUNC void vrote(TCCState* S, SValue *e, int n);
-ST_FUNC void vrott(TCCState* S, int n);
-ST_FUNC void vrotb(TCCState* S, int n);
-ST_FUNC void vpop(TCCState* S);
+ST_INLN Sym *sym_find(int v);
+ST_INLN Sym *struct_find(int v);
+
+ST_FUNC Sym *global_identifier_push(int v, int t, int c);
+ST_FUNC Sym *external_global_sym(int v, CType *type);
+ST_FUNC Sym *external_helper_sym(int v);
+ST_FUNC void vpush_helper_func(int v);
+ST_FUNC void vset(CType *type, int r, int v);
+ST_FUNC void vset_VT_CMP(int op);
+ST_FUNC void vpushi(int v);
+ST_FUNC void vpushv(SValue *v);
+ST_FUNC void vpushsym(CType *type, Sym *sym);
+ST_FUNC void vswap(void);
+ST_FUNC void vrote(SValue *e, int n);
+ST_FUNC void vrott(int n);
+ST_FUNC void vrotb(int n);
+ST_FUNC void vpop(void);
#if PTR_SIZE == 4
-ST_FUNC void lexpand(TCCState* S);
+ST_FUNC void lexpand(void);
#endif
#ifdef TCC_TARGET_ARM
-ST_FUNC int get_reg_ex(TCCState* S, int rc, int rc2);
-#endif
-ST_FUNC void save_reg(TCCState* S, int r);
-ST_FUNC void save_reg_upstack(TCCState* S, int r, int n);
-ST_FUNC int get_reg(TCCState* S, int rc);
-ST_FUNC void save_regs(TCCState* S, int n);
-ST_FUNC void gaddrof(TCCState* S);
-ST_FUNC int gv(TCCState* S, int rc);
-ST_FUNC void gv2(TCCState* S, int rc1, int rc2);
-ST_FUNC void gen_op(TCCState* S, int op);
+ST_FUNC int get_reg_ex(int rc, int rc2);
+#endif
+ST_FUNC void save_reg(int r);
+ST_FUNC void save_reg_upstack(int r, int n);
+ST_FUNC int get_reg(int rc);
+ST_FUNC void save_regs(int n);
+ST_FUNC void gaddrof(void);
+ST_FUNC int gv(int rc);
+ST_FUNC void gv2(int rc1, int rc2);
+ST_FUNC void gen_op(int op);
ST_FUNC int type_size(CType *type, int *a);
-ST_FUNC void mk_pointer(TCCState* S, CType *type);
-ST_FUNC void vstore(TCCState* S);
-ST_FUNC void inc(TCCState* S, int post, int c);
-ST_FUNC void parse_mult_str (TCCState* S, CString *astr, const char *msg);
-ST_FUNC void parse_asm_str(TCCState* S, CString *astr);
-ST_FUNC void indir(TCCState* S);
-ST_FUNC void unary(TCCState* S);
-ST_FUNC void gexpr(TCCState* S);
-ST_FUNC int expr_const(TCCState* S);
+ST_FUNC void mk_pointer(CType *type);
+ST_FUNC void vstore(void);
+ST_FUNC void inc(int post, int c);
+ST_FUNC void parse_mult_str (CString *astr, const char *msg);
+ST_FUNC void parse_asm_str(CString *astr);
+ST_FUNC void indir(void);
+ST_FUNC void unary(void);
+ST_FUNC void gexpr(void);
+ST_FUNC int expr_const(void);
#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
-ST_FUNC Sym *get_sym_ref(TCCState* S, CType *type, Section *sec, unsigned long offset, unsigned long size);
+ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
#endif
#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
ST_FUNC int classify_x86_64_va_arg(CType *ty);
#endif
#ifdef CONFIG_TCC_BCHECK
-ST_FUNC void gbound_args(TCCState* S, int nb_args);
+ST_FUNC void gbound_args(int nb_args);
ST_DATA int func_bound_add_epilog;
#endif
@@ -1648,51 +1489,51 @@ typedef struct {
unsigned int n_value; /* value of symbol */
} Stab_Sym;
-ST_FUNC void tccelf_new(TCCState *S);
-ST_FUNC void tccelf_delete(TCCState *S);
-ST_FUNC void tccelf_stab_new(TCCState *S);
-ST_FUNC void tccelf_begin_file(TCCState *S);
-ST_FUNC void tccelf_end_file(TCCState *S);
+ST_FUNC void tccelf_new(TCCState *s);
+ST_FUNC void tccelf_delete(TCCState *s);
+ST_FUNC void tccelf_stab_new(TCCState *s);
+ST_FUNC void tccelf_begin_file(TCCState *s1);
+ST_FUNC void tccelf_end_file(TCCState *s1);
#ifdef CONFIG_TCC_BCHECK
-ST_FUNC void tccelf_bounds_new(TCCState *S);
-#endif
-ST_FUNC Section *new_section(TCCState *S, const char *name, int sh_type, int sh_flags);
-ST_FUNC void section_realloc(TCCState* S, Section *sec, unsigned long new_size);
-ST_FUNC size_t section_add(TCCState* S, Section *sec, addr_t size, int align);
-ST_FUNC void *section_ptr_add(TCCState* S, Section *sec, addr_t size);
-ST_FUNC Section *find_section(TCCState *S, const char *name);
-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);
-
-ST_FUNC int put_elf_str(TCCState* S, Section *s, const char *sym);
-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);
-ST_FUNC int set_elf_sym(Section *S, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
-ST_FUNC int find_elf_sym(Section *S, const char *name);
+ST_FUNC void tccelf_bounds_new(TCCState *s);
+#endif
+ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
+ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
+ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
+ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
+ST_FUNC Section *find_section(TCCState *s1, const char *name);
+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);
+
+ST_FUNC int put_elf_str(Section *s, const char *sym);
+ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
+ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
+ST_FUNC int find_elf_sym(Section *s, const char *name);
ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
-ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int desc, unsigned long value);
-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);
-ST_FUNC void put_stabn(TCCState *S, int type, int other, int desc, int value);
+ST_FUNC void put_stabs(TCCState *s1, const char *str, int type, int other, int desc, unsigned long value);
+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);
+ST_FUNC void put_stabn(TCCState *s1, int type, int other, int desc, int value);
-ST_FUNC void resolve_common_syms(TCCState *S);
-ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve);
-ST_FUNC void relocate_sections(TCCState *S);
+ST_FUNC void resolve_common_syms(TCCState *s1);
+ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
+ST_FUNC void relocate_sections(TCCState *s1);
ST_FUNC ssize_t full_read(int fd, void *buf, size_t count);
-ST_FUNC void *load_data(TCCState* S, int fd, unsigned long file_offset, unsigned long size);
+ST_FUNC void *load_data(int fd, unsigned long file_offset, unsigned long size);
ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
-ST_FUNC int tcc_load_object_file(TCCState *S, int fd, unsigned long file_offset);
-ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte);
-ST_FUNC void add_array(TCCState *S, const char *sec, int c);
+ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
+ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
+ST_FUNC void add_array(TCCState *s1, const char *sec, int c);
#if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE)
-ST_FUNC void build_got_entries(TCCState *S);
+ST_FUNC void build_got_entries(TCCState *s1);
#endif
-ST_FUNC struct sym_attr *get_sym_attr(TCCState *S, int index, int alloc);
-ST_FUNC addr_t get_sym_addr(TCCState *S, const char *name, int err, int forc);
-ST_FUNC void list_elf_symbols(TCCState *S, void *ctx,
+ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
+ST_FUNC addr_t get_sym_addr(TCCState *s, const char *name, int err, int forc);
+ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
void (*symbol_cb)(void *ctx, const char *name, const void *val));
-ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t offs);
+ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs);
/* Browse each elem of type <type> in section <sec> starting at elem <startoff>
using variable <elem> */
@@ -1701,11 +1542,11 @@ ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t o
elem < (type *) (sec->data + sec->data_offset); elem++)
#ifndef ELF_OBJ_ONLY
-ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level);
-ST_FUNC int tcc_load_ldscript(TCCState *S, int fd);
+ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
+ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd);
#endif
#ifndef TCC_TARGET_PE
-ST_FUNC void tcc_add_runtime(TCCState *S);
+ST_FUNC void tcc_add_runtime(TCCState *s1);
#endif
/* ------------ xxx-link.c ------------ */
@@ -1723,41 +1564,41 @@ enum gotplt_entry {
ST_FUNC int code_reloc (int reloc_type);
ST_FUNC int gotplt_entry_type (int reloc_type);
#if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr);
-ST_FUNC void relocate_plt(TCCState *S);
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
+ST_FUNC void relocate_plt(TCCState *s1);
#endif
#endif
-ST_FUNC void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
+ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
/* ------------ xxx-gen.c ------------ */
ST_DATA const char * const target_machine_defs;
ST_DATA const int reg_classes[NB_REGS];
-ST_FUNC void gsym_addr(TCCState* S, int t, int a);
-ST_FUNC void gsym(TCCState* S, int t);
-ST_FUNC void load(TCCState *S, int r, SValue *sv);
-ST_FUNC void store(TCCState *S, int r, SValue *v);
+ST_FUNC void gsym_addr(int t, int a);
+ST_FUNC void gsym(int t);
+ST_FUNC void load(int r, SValue *sv);
+ST_FUNC void store(int r, SValue *v);
ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
-ST_FUNC void gfunc_call(TCCState *S, int nb_args);
-ST_FUNC void gfunc_prolog(TCCState *S, Sym *func_sym);
-ST_FUNC void gfunc_epilog(TCCState *S);
-ST_FUNC void gen_fill_nops(TCCState* S, int);
-ST_FUNC int gjmp(TCCState* S, int t);
-ST_FUNC void gjmp_addr(TCCState* S, int a);
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t);
-ST_FUNC int gjmp_append(TCCState *S, int n, int t);
-ST_FUNC void gen_opi(TCCState* S, int op);
-ST_FUNC void gen_opf(TCCState* S, int op);
-ST_FUNC void gen_cvt_ftoi(TCCState *S, int t);
-ST_FUNC void gen_cvt_itof(TCCState *S, int t);
-ST_FUNC void gen_cvt_ftof(TCCState *S, int t);
-ST_FUNC void ggoto(TCCState *S);
+ST_FUNC void gfunc_call(int nb_args);
+ST_FUNC void gfunc_prolog(Sym *func_sym);
+ST_FUNC void gfunc_epilog(void);
+ST_FUNC void gen_fill_nops(int);
+ST_FUNC int gjmp(int t);
+ST_FUNC void gjmp_addr(int a);
+ST_FUNC int gjmp_cond(int op, int t);
+ST_FUNC int gjmp_append(int n, int t);
+ST_FUNC void gen_opi(int op);
+ST_FUNC void gen_opf(int op);
+ST_FUNC void gen_cvt_ftoi(int t);
+ST_FUNC void gen_cvt_itof(int t);
+ST_FUNC void gen_cvt_ftof(int t);
+ST_FUNC void ggoto(void);
#ifndef TCC_TARGET_C67
-ST_FUNC void o(TCCState* S, unsigned int c);
+ST_FUNC void o(unsigned int c);
#endif
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr);
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr);
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align);
+ST_FUNC void gen_vla_sp_save(int addr);
+ST_FUNC void gen_vla_sp_restore(int addr);
+ST_FUNC void gen_vla_alloc(CType *type, int align);
static inline uint16_t read16le(unsigned char *p) {
return p[0] | (uint16_t)p[1] << 8;
@@ -1786,57 +1627,57 @@ static inline void add64le(unsigned char *p, int64_t x) {
/* ------------ i386-gen.c ------------ */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
-ST_FUNC void g(TCCState* S, int c);
-ST_FUNC void gen_le16(TCCState* S, int c);
-ST_FUNC void gen_le32(TCCState* S, int c);
+ST_FUNC void g(int c);
+ST_FUNC void gen_le16(int c);
+ST_FUNC void gen_le32(int c);
#endif
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
-ST_FUNC void gen_addr32(TCCState* S, int r, Sym *sym, int c);
-ST_FUNC void gen_addrpc32(TCCState* S, int r, Sym *sym, int c);
-ST_FUNC void gen_cvt_csti(TCCState* S, int t);
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
+ST_FUNC void gen_addr32(int r, Sym *sym, int c);
+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
+ST_FUNC void gen_cvt_csti(int t);
+ST_FUNC void gen_increment_tcov (SValue *sv);
#endif
/* ------------ x86_64-gen.c ------------ */
#ifdef TCC_TARGET_X86_64
-ST_FUNC void gen_addr64(TCCState* S, int r, Sym *sym, int64_t c);
-ST_FUNC void gen_opl(TCCState* S, int op);
+ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
+ST_FUNC void gen_opl(int op);
#ifdef TCC_TARGET_PE
-ST_FUNC void gen_vla_result(TCCState* S, int addr);
+ST_FUNC void gen_vla_result(int addr);
#endif
-ST_FUNC void gen_cvt_sxtw(TCCState *S);
-ST_FUNC void gen_cvt_csti(TCCState* S, int t);
+ST_FUNC void gen_cvt_sxtw(void);
+ST_FUNC void gen_cvt_csti(int t);
#endif
/* ------------ arm-gen.c ------------ */
#ifdef TCC_TARGET_ARM
#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
-PUB_FUNC const char *default_elfinterp(TCCState *S);
+PUB_FUNC const char *default_elfinterp(struct TCCState *s);
#endif
-ST_FUNC void arm_init(TCCState *S);
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
+ST_FUNC void arm_init(struct TCCState *s);
+ST_FUNC void gen_increment_tcov (SValue *sv);
#endif
/* ------------ arm64-gen.c ------------ */
#ifdef TCC_TARGET_ARM64
-ST_FUNC void gen_opl(TCCState* S, int op);
-ST_FUNC void gfunc_return(TCCState *S, CType *func_type);
-ST_FUNC void gen_va_start(TCCState *S);
-ST_FUNC void gen_va_arg(TCCState *S, CType *t);
-ST_FUNC void gen_clear_cache(TCCState *S);
-ST_FUNC void gen_cvt_sxtw(TCCState *S);
-ST_FUNC void gen_cvt_csti(TCCState *S, int t);
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
+ST_FUNC void gen_opl(int op);
+ST_FUNC void gfunc_return(CType *func_type);
+ST_FUNC void gen_va_start(void);
+ST_FUNC void gen_va_arg(CType *t);
+ST_FUNC void gen_clear_cache(void);
+ST_FUNC void gen_cvt_sxtw(void);
+ST_FUNC void gen_cvt_csti(int t);
+ST_FUNC void gen_increment_tcov (SValue *sv);
#endif
/* ------------ riscv64-gen.c ------------ */
#ifdef TCC_TARGET_RISCV64
-ST_FUNC void gen_opl(TCCState* S, int op);
-//ST_FUNC void gfunc_return(TCCState *S, CType *func_type);
-ST_FUNC void gen_va_start(TCCState *S);
-ST_FUNC void arch_transfer_ret_regs(TCCState* S, int);
-ST_FUNC void gen_cvt_sxtw(TCCState *S);
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
+ST_FUNC void gen_opl(int op);
+//ST_FUNC void gfunc_return(CType *func_type);
+ST_FUNC void gen_va_start(void);
+ST_FUNC void arch_transfer_ret_regs(int);
+ST_FUNC void gen_cvt_sxtw(void);
+ST_FUNC void gen_increment_tcov (SValue *sv);
#endif
/* ------------ c67-gen.c ------------ */
@@ -1846,44 +1687,44 @@ ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv);
/* ------------ tcccoff.c ------------ */
#ifdef TCC_TARGET_COFF
-ST_FUNC int tcc_output_coff(TCCState *S, FILE *f);
-ST_FUNC int tcc_load_coff(TCCState *S, int fd);
+ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
+ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
#endif
/* ------------ tccasm.c ------------ */
-ST_FUNC void asm_instr(TCCState* S);
-ST_FUNC void asm_global_instr(TCCState* S);
-ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess);
+ST_FUNC void asm_instr(void);
+ST_FUNC void asm_global_instr(void);
+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
#ifdef CONFIG_TCC_ASM
-ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands, const char *name, const char **pp);
-ST_FUNC Sym* get_asm_sym(TCCState* S, int name, Sym *csym);
-ST_FUNC void asm_expr(TCCState *S, ExprValue *pe);
-ST_FUNC int asm_int_expr(TCCState *S);
+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
+ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
+ST_FUNC int asm_int_expr(TCCState *s1);
/* ------------ i386-asm.c ------------ */
-ST_FUNC void gen_expr32(TCCState* S, ExprValue *pe);
+ST_FUNC void gen_expr32(ExprValue *pe);
#ifdef TCC_TARGET_X86_64
-ST_FUNC void gen_expr64(TCCState* S, ExprValue *pe);
+ST_FUNC void gen_expr64(ExprValue *pe);
#endif
-ST_FUNC void asm_opcode(TCCState *S, int opcode);
-ST_FUNC int asm_parse_regvar(TCCState* S, int t);
-ST_FUNC void asm_compute_constraints(TCCState* S, ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
-ST_FUNC void subst_asm_operand(TCCState* S, CString *add_str, SValue *sv, int modifier);
-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);
-ST_FUNC void asm_clobber(TCCState* S, uint8_t *clobber_regs, const char *str);
+ST_FUNC void asm_opcode(TCCState *s1, int opcode);
+ST_FUNC int asm_parse_regvar(int t);
+ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
+ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
+ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
+ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
#endif
/* ------------ tccpe.c -------------- */
#ifdef TCC_TARGET_PE
-ST_FUNC int pe_load_file(struct TCCState *S, int fd, const char *filename);
-ST_FUNC int pe_output_file(TCCState * S, const char *filename);
-ST_FUNC int pe_putimport(TCCState *S, int dllindex, const char *name, addr_t value);
+ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename);
+ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
+ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
-ST_FUNC SValue *pe_getimport(TCCState * S, SValue *sv, SValue *v2);
+ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
#endif
#ifdef TCC_TARGET_X86_64
-ST_FUNC void pe_add_unwind_data(TCCState* S, unsigned start, unsigned end, unsigned stack);
+ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
#endif
-PUB_FUNC int tcc_get_dllexports(TCCState* S, const char *filename, char **pp);
+PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
/* symbol properties stored in Elf32_Sym->st_other */
# define ST_PE_EXPORT 0x10
# define ST_PE_IMPORT 0x20
@@ -1893,11 +1734,11 @@ PUB_FUNC int tcc_get_dllexports(TCCState* S, const char *filename, char **pp);
/* ------------ tccmacho.c ----------------- */
#ifdef TCC_TARGET_MACHO
-ST_FUNC int macho_output_file(TCCState * S, const char *filename);
-ST_FUNC int macho_load_dll(TCCState *S, int fd, const char *filename, int lev);
-ST_FUNC int macho_load_tbd(TCCState *S, int fd, const char *filename, int lev);
+ST_FUNC int macho_output_file(TCCState * s1, const char *filename);
+ST_FUNC int macho_load_dll(TCCState *s1, int fd, const char *filename, int lev);
+ST_FUNC int macho_load_tbd(TCCState *s1, int fd, const char *filename, int lev);
#ifdef TCC_IS_NATIVE
-ST_FUNC void tcc_add_macos_sdkpath(TCCState* S);
+ST_FUNC void tcc_add_macos_sdkpath(TCCState* s);
ST_FUNC const char* macho_tbd_soname(const char* filename);
#endif
#endif
@@ -1914,17 +1755,17 @@ ST_FUNC void dlclose(void *p);
ST_FUNC const char *dlerror(void);
ST_FUNC void *dlsym(void *handle, const char *symbol);
#endif
-ST_FUNC void tcc_run_free(TCCState *S);
+ST_FUNC void tcc_run_free(TCCState *s1);
#endif
/* ------------ tcctools.c ----------------- */
#if 0 /* included in tcc.c */
-ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv);
+ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
#ifdef TCC_TARGET_PE
-ST_FUNC int tcc_tool_impdef(TCCState *S, int argc, char **argv);
+ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
#endif
-ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int option);
-ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename);
+ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
+ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
#endif
/********************************************************/
@@ -1979,12 +1820,12 @@ ST_FUNC void post_sem(TCCSem *p);
#define total_lines TCC_STATE_VAR(total_lines)
#define total_bytes TCC_STATE_VAR(total_bytes)
-PUB_FUNC void tcc_enter_state(TCCState *S);
-PUB_FUNC void tcc_exit_state(TCCState *S);
+PUB_FUNC void tcc_enter_state(TCCState *s1);
+PUB_FUNC void tcc_exit_state(TCCState *s1);
/* conditional warning depending on switch */
#define tcc_warning_c(sw) TCC_SET_STATE((\
- S->warn_num = offsetof(TCCState, sw) \
+ tcc_state->warn_num = offsetof(TCCState, sw) \
- offsetof(TCCState, warn_none), _tcc_warning))
/********************************************************/
@@ -1994,10 +1835,10 @@ PUB_FUNC void tcc_exit_state(TCCState *S);
#undef TCC_SET_STATE
#ifdef USING_GLOBALS
-# define TCC_STATE_VAR(sym) S->sym
+# define TCC_STATE_VAR(sym) tcc_state->sym
# define TCC_SET_STATE(fn) fn
# undef USING_GLOBALS
#else
-# define TCC_STATE_VAR(sym) S->sym
-# define TCC_SET_STATE(fn) (tcc_enter_state(S),fn)
+# define TCC_STATE_VAR(sym) s1->sym
+# define TCC_SET_STATE(fn) (tcc_enter_state(s1),fn)
#endif
diff --git a/tccasm.c b/tccasm.c
index be8b7cb..2dd8921 100644
--- a/tccasm.c
+++ b/tccasm.c
@@ -22,16 +22,18 @@
#include "tcc.h"
#ifdef CONFIG_TCC_ASM
-ST_FUNC int asm_get_local_label_name(TCCState *S, unsigned int n)
+static Section *last_text_section; /* to handle .previous asm directive */
+
+ST_FUNC int asm_get_local_label_name(TCCState *s1, unsigned int n)
{
char buf[64];
snprintf(buf, sizeof(buf), "L..%u", n);
- return tok_alloc_const(S, buf);
+ return tok_alloc_const(buf);
}
-static int tcc_assemble_internal(TCCState *S, int do_preprocess, int global);
-static Sym* asm_new_label(TCCState *S, int label, int is_local);
-static Sym* asm_new_label1(TCCState *S, int label, int is_local, int sh_num, int value);
+static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global);
+static Sym* asm_new_label(TCCState *s1, int label, int is_local);
+static Sym* asm_new_label1(TCCState *s1, int label, int is_local, int sh_num, int value);
/* If a C name has an _ prepended then only asm labels that start
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
the global C symbol table to track ASM names as well, so we need to
transform those into ones that don't conflict with a C name,
so prepend a '.' for them, but force the ELF asm name to be set. */
-static int asm2cname(TCCState* S, int v, int *addeddot)
+static int asm2cname(int v, int *addeddot)
{
const char *name;
*addeddot = 0;
- if (!S->leading_underscore)
+ if (!tcc_state->leading_underscore)
return v;
- name = get_tok_str(S, v, NULL);
+ name = get_tok_str(v, NULL);
if (!name)
return v;
if (name[0] == '_') {
- v = tok_alloc_const(S, name + 1);
+ v = tok_alloc_const(name + 1);
} else if (!strchr(name, '.')) {
char newname[256];
snprintf(newname, sizeof newname, ".%s", name);
- v = tok_alloc_const(S, newname);
+ v = tok_alloc_const(newname);
*addeddot = 1;
}
return v;
}
-static Sym *asm_label_find(TCCState* S, int v)
+static Sym *asm_label_find(int v)
{
Sym *sym;
int addeddot;
- v = asm2cname(S, v, &addeddot);
- sym = sym_find(S, v);
+ v = asm2cname(v, &addeddot);
+ sym = sym_find(v);
while (sym && sym->sym_scope && !(sym->type.t & VT_STATIC))
sym = sym->prev_tok;
return sym;
}
-static Sym *asm_label_push(TCCState* S, int v)
+static Sym *asm_label_push(int v)
{
- int addeddot, v2 = asm2cname(S, v, &addeddot);
+ int addeddot, v2 = asm2cname(v, &addeddot);
/* We always add VT_EXTERN, for sym definition that's tentative
(for .set, removed for real defs), for mere references it's correct
as is. */
- Sym *sym = global_identifier_push(S, v2, VT_ASM | VT_EXTERN | VT_STATIC, 0);
+ Sym *sym = global_identifier_push(v2, VT_ASM | VT_EXTERN | VT_STATIC, 0);
if (addeddot)
sym->asm_label = v;
return sym;
@@ -92,55 +94,55 @@ static Sym *asm_label_push(TCCState* S, int v)
are anonymous in C, in this case CSYM can be used to transfer
all information from that symbol to the (possibly newly created)
asm symbol. */
-ST_FUNC Sym* get_asm_sym(TCCState* S, int name, Sym *csym)
+ST_FUNC Sym* get_asm_sym(int name, Sym *csym)
{
- Sym *sym = asm_label_find(S, name);
+ Sym *sym = asm_label_find(name);
if (!sym) {
- sym = asm_label_push(S, name);
+ sym = asm_label_push(name);
if (csym)
sym->c = csym->c;
}
return sym;
}
-static Sym* asm_section_sym(TCCState *S, Section *sec)
+static Sym* asm_section_sym(TCCState *s1, Section *sec)
{
char buf[100]; int label; Sym *sym;
snprintf(buf, sizeof buf, "L.%s", sec->name);
- label = tok_alloc_const(S, buf);
- sym = asm_label_find(S, label);
- return sym ? sym : asm_new_label1(S, label, 1, sec->sh_num, 0);
+ label = tok_alloc_const(buf);
+ sym = asm_label_find(label);
+ return sym ? sym : asm_new_label1(s1, label, 1, sec->sh_num, 0);
}
/* We do not use the C expression parser to handle symbols. Maybe the
C expression parser could be tweaked to do so. */
-static void asm_expr_unary(TCCState *S, ExprValue *pe)
+static void asm_expr_unary(TCCState *s1, ExprValue *pe)
{
Sym *sym;
int op, label;
uint64_t n;
const char *p;
- switch(S->tccpp_tok) {
+ switch(tok) {
case TOK_PPNUM:
- p = S->tccpp_tokc.str.data;
+ p = tokc.str.data;
n = strtoull(p, (char **)&p, 0);
if (*p == 'b' || *p == 'f') {
/* backward or forward label */
- label = asm_get_local_label_name(S, n);
- sym = asm_label_find(S, label);
+ label = asm_get_local_label_name(s1, n);
+ sym = asm_label_find(label);
if (*p == 'b') {
/* backward : find the last corresponding defined label */
- if (sym && (!sym->c || elfsym(S, sym)->st_shndx == SHN_UNDEF))
+ if (sym && (!sym->c || elfsym(sym)->st_shndx == SHN_UNDEF))
sym = sym->prev_tok;
if (!sym)
- tcc_error(S, "local label '%d' not found backward", (int)n);
+ tcc_error("local label '%d' not found backward", (int)n);
} else {
/* forward */
- if (!sym || (sym->c && elfsym(S, sym)->st_shndx != SHN_UNDEF)) {
+ if (!sym || (sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)) {
/* if the last label is defined, then define a new one */
- sym = asm_label_push(S, label);
+ sym = asm_label_push(label);
}
}
pe->v = 0;
@@ -151,21 +153,21 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe)
pe->sym = NULL;
pe->pcrel = 0;
} else {
- tcc_error(S, "invalid number syntax");
+ tcc_error("invalid number syntax");
}
- next(S);
+ next();
break;
case '+':
- next(S);
- asm_expr_unary(S, pe);
+ next();
+ asm_expr_unary(s1, pe);
break;
case '-':
case '~':
- op = S->tccpp_tok;
- next(S);
- asm_expr_unary(S, pe);
+ op = tok;
+ next();
+ asm_expr_unary(s1, pe);
if (pe->sym)
- tcc_error(S, "invalid operation with label");
+ tcc_error("invalid operation with label");
if (op == '-')
pe->v = -pe->v;
else
@@ -173,28 +175,28 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe)
break;
case TOK_CCHAR:
case TOK_LCHAR:
- pe->v = S->tccpp_tokc.i;
+ pe->v = tokc.i;
pe->sym = NULL;
pe->pcrel = 0;
- next(S);
+ next();
break;
case '(':
- next(S);
- asm_expr(S, pe);
- skip(S, ')');
+ next();
+ asm_expr(s1, pe);
+ skip(')');
break;
case '.':
- pe->v = S->tccgen_ind;
- pe->sym = asm_section_sym(S, cur_text_section);
+ pe->v = ind;
+ pe->sym = asm_section_sym(s1, cur_text_section);
pe->pcrel = 0;
- next(S);
+ next();
break;
default:
- if (S->tccpp_tok >= TOK_IDENT) {
+ if (tok >= TOK_IDENT) {
ElfSym *esym;
/* label case : if the label was not found, add one */
- sym = get_asm_sym(S, S->tccpp_tok, NULL);
- esym = elfsym(S, sym);
+ sym = get_asm_sym(tok, NULL);
+ esym = elfsym(sym);
if (esym && esym->st_shndx == SHN_ABS) {
/* if absolute symbol, no need to put a symbol value */
pe->v = esym->st_value;
@@ -205,29 +207,29 @@ static void asm_expr_unary(TCCState *S, ExprValue *pe)
pe->sym = sym;
pe->pcrel = 0;
}
- next(S);
+ next();
} else {
- tcc_error(S, "bad expression syntax [%s]", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_error("bad expression syntax [%s]", get_tok_str(tok, &tokc));
}
break;
}
}
-static void asm_expr_prod(TCCState *S, ExprValue *pe)
+static void asm_expr_prod(TCCState *s1, ExprValue *pe)
{
int op;
ExprValue e2;
- asm_expr_unary(S, pe);
+ asm_expr_unary(s1, pe);
for(;;) {
- op = S->tccpp_tok;
+ op = tok;
if (op != '*' && op != '/' && op != '%' &&
op != TOK_SHL && op != TOK_SAR)
break;
- next(S);
- asm_expr_unary(S, &e2);
+ next();
+ asm_expr_unary(s1, &e2);
if (pe->sym || e2.sym)
- tcc_error(S, "invalid operation with label");
+ tcc_error("invalid operation with label");
switch(op) {
case '*':
pe->v *= e2.v;
@@ -235,7 +237,7 @@ static void asm_expr_prod(TCCState *S, ExprValue *pe)
case '/':
if (e2.v == 0) {
div_error:
- tcc_error(S, "division by zero");
+ tcc_error("division by zero");
}
pe->v /= e2.v;
break;
@@ -255,20 +257,20 @@ static void asm_expr_prod(TCCState *S, ExprValue *pe)
}
}
-static void asm_expr_logic(TCCState *S, ExprValue *pe)
+static void asm_expr_logic(TCCState *s1, ExprValue *pe)
{
int op;
ExprValue e2;
- asm_expr_prod(S, pe);
+ asm_expr_prod(s1, pe);
for(;;) {
- op = S->tccpp_tok;
+ op = tok;
if (op != '&' && op != '|' && op != '^')
break;
- next(S);
- asm_expr_prod(S, &e2);
+ next();
+ asm_expr_prod(s1, &e2);
if (pe->sym || e2.sym)
- tcc_error(S, "invalid operation with label");
+ tcc_error("invalid operation with label");
switch(op) {
case '&':
pe->v &= e2.v;
@@ -284,18 +286,18 @@ static void asm_expr_logic(TCCState *S, ExprValue *pe)
}
}
-static inline void asm_expr_sum(TCCState *S, ExprValue *pe)
+static inline void asm_expr_sum(TCCState *s1, ExprValue *pe)
{
int op;
ExprValue e2;
- asm_expr_logic(S, pe);
+ asm_expr_logic(s1, pe);
for(;;) {
- op = S->tccpp_tok;
+ op = tok;
if (op != '+' && op != '-')
break;
- next(S);
- asm_expr_logic(S, &e2);
+ next();
+ asm_expr_logic(s1, &e2);
if (op == '+') {
if (pe->sym != NULL && e2.sym != NULL)
goto cannot_relocate;
@@ -313,8 +315,8 @@ static inline void asm_expr_sum(TCCState *S, ExprValue *pe)
pe->sym = NULL; /* same symbols can be subtracted to NULL */
} else {
ElfSym *esym1, *esym2;
- esym1 = elfsym(S, pe->sym);
- esym2 = elfsym(S, e2.sym);
+ esym1 = elfsym(pe->sym);
+ esym2 = elfsym(e2.sym);
if (esym1 && esym1->st_shndx == esym2->st_shndx
&& esym1->st_shndx != SHN_UNDEF) {
/* we also accept defined symbols in the same section */
@@ -323,33 +325,33 @@ static inline void asm_expr_sum(TCCState *S, ExprValue *pe)
} else if (esym2->st_shndx == cur_text_section->sh_num) {
/* When subtracting a defined symbol in current section
this actually makes the value PC-relative. */
- pe->v -= esym2->st_value - S->tccgen_ind - 4;
+ pe->v -= esym2->st_value - ind - 4;
pe->pcrel = 1;
e2.sym = NULL;
} else {
cannot_relocate:
- tcc_error(S, "invalid operation with label");
+ tcc_error("invalid operation with label");
}
}
}
}
}
-static inline void asm_expr_cmp(TCCState *S, ExprValue *pe)
+static inline void asm_expr_cmp(TCCState *s1, ExprValue *pe)
{
int op;
ExprValue e2;
- asm_expr_sum(S, pe);
+ asm_expr_sum(s1, pe);
for(;;) {
- op = S->tccpp_tok;
+ op = tok;
if (op != TOK_EQ && op != TOK_NE
&& (op > TOK_GT || op < TOK_ULE))
break;
- next(S);
- asm_expr_sum(S, &e2);
+ next();
+ asm_expr_sum(s1, &e2);
if (pe->sym || e2.sym)
- tcc_error(S, "invalid operation with label");
+ tcc_error("invalid operation with label");
switch(op) {
case TOK_EQ:
pe->v = pe->v == e2.v;
@@ -377,29 +379,29 @@ static inline void asm_expr_cmp(TCCState *S, ExprValue *pe)
}
}
-ST_FUNC void asm_expr(TCCState *S, ExprValue *pe)
+ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe)
{
- asm_expr_cmp(S, pe);
+ asm_expr_cmp(s1, pe);
}
-ST_FUNC int asm_int_expr(TCCState *S)
+ST_FUNC int asm_int_expr(TCCState *s1)
{
ExprValue e;
- asm_expr(S, &e);
+ asm_expr(s1, &e);
if (e.sym)
- expect(S, "constant");
+ expect("constant");
return e.v;
}
-static Sym* asm_new_label1(TCCState *S, int label, int is_local,
+static Sym* asm_new_label1(TCCState *s1, int label, int is_local,
int sh_num, int value)
{
Sym *sym;
ElfSym *esym;
- sym = asm_label_find(S, label);
+ sym = asm_label_find(label);
if (sym) {
- esym = elfsym(S, sym);
+ esym = elfsym(sym);
/* A VT_EXTERN symbol, even if it has a section is considered
overridable. This is how we "define" .set targets. Real
definitions won't have VT_EXTERN set. */
@@ -409,16 +411,16 @@ static Sym* asm_new_label1(TCCState *S, int label, int is_local,
&& (is_local == 1 || (sym->type.t & VT_EXTERN)))
goto new_label;
if (!(sym->type.t & VT_EXTERN))
- tcc_error(S, "assembler label '%s' already defined",
- get_tok_str(S, label, NULL));
+ tcc_error("assembler label '%s' already defined",
+ get_tok_str(label, NULL));
}
} else {
new_label:
- sym = asm_label_push(S, label);
+ sym = asm_label_push(label);
}
if (!sym->c)
- put_extern_sym2(S, sym, SHN_UNDEF, 0, 0, 1);
- esym = elfsym(S, sym);
+ put_extern_sym2(sym, SHN_UNDEF, 0, 0, 1);
+ esym = elfsym(sym);
esym->st_shndx = sh_num;
esym->st_value = value;
if (is_local != 2)
@@ -426,61 +428,61 @@ static Sym* asm_new_label1(TCCState *S, int label, int is_local,
return sym;
}
-static Sym* asm_new_label(TCCState *S, int label, int is_local)
+static Sym* asm_new_label(TCCState *s1, int label, int is_local)
{
- return asm_new_label1(S, label, is_local, cur_text_section->sh_num, S->tccgen_ind);
+ return asm_new_label1(s1, label, is_local, cur_text_section->sh_num, ind);
}
/* Set the value of LABEL to that of some expression (possibly
involving other symbols). LABEL can be overwritten later still. */
-static Sym* set_symbol(TCCState *S, int label)
+static Sym* set_symbol(TCCState *s1, int label)
{
long n;
ExprValue e;
Sym *sym;
ElfSym *esym;
- next(S);
- asm_expr(S, &e);
+ next();
+ asm_expr(s1, &e);
n = e.v;
- esym = elfsym(S, e.sym);
+ esym = elfsym(e.sym);
if (esym)
n += esym->st_value;
- sym = asm_new_label1(S, label, 2, esym ? esym->st_shndx : SHN_ABS, n);
- elfsym(S, sym)->st_other |= ST_ASM_SET;
+ sym = asm_new_label1(s1, label, 2, esym ? esym->st_shndx : SHN_ABS, n);
+ elfsym(sym)->st_other |= ST_ASM_SET;
return sym;
}
-static void use_section1(TCCState *S, Section *sec)
+static void use_section1(TCCState *s1, Section *sec)
{
- cur_text_section->data_offset = S->tccgen_ind;
+ cur_text_section->data_offset = ind;
cur_text_section = sec;
- S->tccgen_ind = cur_text_section->data_offset;
+ ind = cur_text_section->data_offset;
}
-static void use_section(TCCState *S, const char *name)
+static void use_section(TCCState *s1, const char *name)
{
Section *sec;
- sec = find_section(S, name);
- use_section1(S, sec);
+ sec = find_section(s1, name);
+ use_section1(s1, sec);
}
-static void push_section(TCCState *S, const char *name)
+static void push_section(TCCState *s1, const char *name)
{
- Section *sec = find_section(S, name);
+ Section *sec = find_section(s1, name);
sec->prev = cur_text_section;
- use_section1(S, sec);
+ use_section1(s1, sec);
}
-static void pop_section(TCCState *S)
+static void pop_section(TCCState *s1)
{
Section *prev = cur_text_section->prev;
if (!prev)
- tcc_error(S, ".popsection without .pushsection");
+ tcc_error(".popsection without .pushsection");
cur_text_section->prev = NULL;
- use_section1(S, prev);
+ use_section1(s1, prev);
}
-static void asm_parse_directive(TCCState *S, int global)
+static void asm_parse_directive(TCCState *s1, int global)
{
int n, offset, v, size, tok1;
Section *sec;
@@ -488,27 +490,27 @@ static void asm_parse_directive(TCCState *S, int global)
/* assembler directive */
sec = cur_text_section;
- switch(S->tccpp_tok) {
+ switch(tok) {
case TOK_ASMDIR_align:
case TOK_ASMDIR_balign:
case TOK_ASMDIR_p2align:
case TOK_ASMDIR_skip:
case TOK_ASMDIR_space:
- tok1 = S->tccpp_tok;
- next(S);
- n = asm_int_expr(S);
+ tok1 = tok;
+ next();
+ n = asm_int_expr(s1);
if (tok1 == TOK_ASMDIR_p2align)
{
if (n < 0 || n > 30)
- tcc_error(S, "invalid p2align, must be between 0 and 30");
+ tcc_error("invalid p2align, must be between 0 and 30");
n = 1 << n;
tok1 = TOK_ASMDIR_align;
}
if (tok1 == TOK_ASMDIR_align || tok1 == TOK_ASMDIR_balign) {
if (n < 0 || (n & (n-1)) != 0)
- tcc_error(S, "alignment must be a positive power of two");
- offset = (S->tccgen_ind + n - 1) & -n;
- size = offset - S->tccgen_ind;
+ tcc_error("alignment must be a positive power of two");
+ offset = (ind + n - 1) & -n;
+ size = offset - ind;
/* the section must have a compatible alignment */
if (sec->sh_addralign < n)
sec->sh_addralign = n;
@@ -518,47 +520,47 @@ static void asm_parse_directive(TCCState *S, int global)
size = n;
}
v = 0;
- if (S->tccpp_tok == ',') {
- next(S);
- v = asm_int_expr(S);
+ if (tok == ',') {
+ next();
+ v = asm_int_expr(s1);
}
zero_pad:
if (sec->sh_type != SHT_NOBITS) {
- sec->data_offset = S->tccgen_ind;
- ptr = section_ptr_add(S, sec, size);
+ sec->data_offset = ind;
+ ptr = section_ptr_add(sec, size);
memset(ptr, v, size);
}
- S->tccgen_ind += size;
+ ind += size;
break;
case TOK_ASMDIR_quad:
#ifdef TCC_TARGET_X86_64
size = 8;
goto asm_data;
#else
- next(S);
+ next();
for(;;) {
uint64_t vl;
const char *p;
- p = S->tccpp_tokc.str.data;
- if (S->tccpp_tok != TOK_PPNUM) {
+ p = tokc.str.data;
+ if (tok != TOK_PPNUM) {
error_constant:
- tcc_error(S, "64 bit constant");
+ tcc_error("64 bit constant");
}
vl = strtoll(p, (char **)&p, 0);
if (*p != '\0')
goto error_constant;
- next(S);
+ next();
if (sec->sh_type != SHT_NOBITS) {
/* XXX: endianness */
- gen_le32(S, vl);
- gen_le32(S, vl >> 32);
+ gen_le32(vl);
+ gen_le32(vl >> 32);
} else {
- S->tccgen_ind += 8;
+ ind += 8;
}
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S);
+ next();
}
break;
#endif
@@ -573,57 +575,57 @@ static void asm_parse_directive(TCCState *S, int global)
case TOK_ASMDIR_int:
size = 4;
asm_data:
- next(S);
+ next();
for(;;) {
ExprValue e;
- asm_expr(S, &e);
+ asm_expr(s1, &e);
if (sec->sh_type != SHT_NOBITS) {
if (size == 4) {
- gen_expr32(S, &e);
+ gen_expr32(&e);
#ifdef TCC_TARGET_X86_64
} else if (size == 8) {
- gen_expr64(S, &e);
+ gen_expr64(&e);
#endif
} else {
if (e.sym)
- expect(S, "constant");
+ expect("constant");
if (size == 1)
- g(S, e.v);
+ g(e.v);
else
- gen_le16(S, e.v);
+ gen_le16(e.v);
}
} else {
- S->tccgen_ind += size;
+ ind += size;
}
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S);
+ next();
}
break;
case TOK_ASMDIR_fill:
{
int repeat, size, val, i, j;
uint8_t repeat_buf[8];
- next(S);
- repeat = asm_int_expr(S);
+ next();
+ repeat = asm_int_expr(s1);
if (repeat < 0) {
- tcc_error(S, "repeat < 0; .fill ignored");
+ tcc_error("repeat < 0; .fill ignored");
break;
}
size = 1;
val = 0;
- if (S->tccpp_tok == ',') {
- next(S);
- size = asm_int_expr(S);
+ if (tok == ',') {
+ next();
+ size = asm_int_expr(s1);
if (size < 0) {
- tcc_error(S, "size < 0; .fill ignored");
+ tcc_error("size < 0; .fill ignored");
break;
}
if (size > 8)
size = 8;
- if (S->tccpp_tok == ',') {
- next(S);
- val = asm_int_expr(S);
+ if (tok == ',') {
+ next();
+ val = asm_int_expr(s1);
}
}
/* XXX: endianness */
@@ -637,7 +639,7 @@ static void asm_parse_directive(TCCState *S, int global)
repeat_buf[7] = 0;
for(i = 0; i < repeat; i++) {
for(j = 0; j < size; j++) {
- g(S, repeat_buf[j]);
+ g(repeat_buf[j]);
}
}
}
@@ -646,24 +648,24 @@ static void asm_parse_directive(TCCState *S, int global)
{
int repeat;
TokenString *init_str;
- next(S);
- repeat = asm_int_expr(S);
- init_str = tok_str_alloc(S);
- while (next(S), S->tccpp_tok != TOK_ASMDIR_endr) {
- if (S->tccpp_tok == CH_EOF)
- tcc_error(S, "we at end of file, .endr not found");
- tok_str_add_tok(S, init_str);
+ next();
+ repeat = asm_int_expr(s1);
+ init_str = tok_str_alloc();
+ while (next(), tok != TOK_ASMDIR_endr) {
+ if (tok == CH_EOF)
+ tcc_error("we at end of file, .endr not found");
+ tok_str_add_tok(init_str);
}
- tok_str_add(S, init_str, -1);
- tok_str_add(S, init_str, 0);
- begin_macro(S, init_str, 1);
+ tok_str_add(init_str, -1);
+ tok_str_add(init_str, 0);
+ begin_macro(init_str, 1);
while (repeat-- > 0) {
- tcc_assemble_internal(S, (S->tccpp_parse_flags & PARSE_FLAG_PREPROCESS),
+ tcc_assemble_internal(s1, (parse_flags & PARSE_FLAG_PREPROCESS),
global);
- S->tccpp_macro_ptr = init_str->str;
+ macro_ptr = init_str->str;
}
- end_macro(S);
- next(S);
+ end_macro();
+ next();
break;
}
case TOK_ASMDIR_org:
@@ -671,49 +673,49 @@ static void asm_parse_directive(TCCState *S, int global)
unsigned long n;
ExprValue e;
ElfSym *esym;
- next(S);
- asm_expr(S, &e);
+ next();
+ asm_expr(s1, &e);
n = e.v;
- esym = elfsym(S, e.sym);
+ esym = elfsym(e.sym);
if (esym) {
if (esym->st_shndx != cur_text_section->sh_num)
- expect(S, "constant or same-section symbol");
+ expect("constant or same-section symbol");
n += esym->st_value;
}
- if (n < S->tccgen_ind)
- tcc_error(S, "attempt to .org backwards");
+ if (n < ind)
+ tcc_error("attempt to .org backwards");
v = 0;
- size = n - S->tccgen_ind;
+ size = n - ind;
goto zero_pad;
}
break;
case TOK_ASMDIR_set:
- next(S);
- tok1 = S->tccpp_tok;
- next(S);
+ next();
+ tok1 = tok;
+ next();
/* Also accept '.set stuff', but don't do anything with this.
It's used in GAS to set various features like '.set mips16'. */
- if (S->tccpp_tok == ',')
- set_symbol(S, tok1);
+ if (tok == ',')
+ set_symbol(s1, tok1);
break;
case TOK_ASMDIR_globl:
case TOK_ASMDIR_global:
case TOK_ASMDIR_weak:
case TOK_ASMDIR_hidden:
- tok1 = S->tccpp_tok;
+ tok1 = tok;
do {
Sym *sym;
- next(S);
- sym = get_asm_sym(S, S->tccpp_tok, NULL);
+ next();
+ sym = get_asm_sym(tok, NULL);
if (tok1 != TOK_ASMDIR_hidden)
sym->type.t &= ~VT_STATIC;
if (tok1 == TOK_ASMDIR_weak)
sym->a.weak = 1;
else if (tok1 == TOK_ASMDIR_hidden)
sym->a.visibility = STV_HIDDEN;
- update_storage(S, sym);
- next(S);
- } while (S->tccpp_tok == ',');
+ update_storage(sym);
+ next();
+ } while (tok == ',');
break;
case TOK_ASMDIR_string:
case TOK_ASMDIR_ascii:
@@ -722,21 +724,21 @@ static void asm_parse_directive(TCCState *S, int global)
const uint8_t *p;
int i, size, t;
- t = S->tccpp_tok;
- next(S);
+ t = tok;
+ next();
for(;;) {
- if (S->tccpp_tok != TOK_STR)
- expect(S, "string constant");
- p = S->tccpp_tokc.str.data;
- size = S->tccpp_tokc.str.size;
+ if (tok != TOK_STR)
+ expect("string constant");
+ p = tokc.str.data;
+ size = tokc.str.size;
if (t == TOK_ASMDIR_ascii && size > 0)
size--;
for(i = 0; i < size; i++)
- g(S, p[i]);
- next(S);
- if (S->tccpp_tok == ',') {
- next(S);
- } else if (S->tccpp_tok != TOK_STR) {
+ g(p[i]);
+ next();
+ if (tok == ',') {
+ next();
+ } else if (tok != TOK_STR) {
break;
}
}
@@ -747,18 +749,18 @@ static void asm_parse_directive(TCCState *S, int global)
case TOK_ASMDIR_bss:
{
char sname[64];
- tok1 = S->tccpp_tok;
+ tok1 = tok;
n = 0;
- next(S);
- if (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED) {
- n = asm_int_expr(S);
- next(S);
+ next();
+ if (tok != ';' && tok != TOK_LINEFEED) {
+ n = asm_int_expr(s1);
+ next();
}
if (n)
- sprintf(sname, "%s%d", get_tok_str(S, tok1, NULL), n);
+ sprintf(sname, "%s%d", get_tok_str(tok1, NULL), n);
else
- sprintf(sname, "%s", get_tok_str(S, tok1, NULL));
- use_section(S, sname);
+ sprintf(sname, "%s", get_tok_str(tok1, NULL));
+ use_section(s1, sname);
}
break;
case TOK_ASMDIR_file:
@@ -766,13 +768,13 @@ static void asm_parse_directive(TCCState *S, int global)
char filename[512];
filename[0] = '\0';
- next(S);
- if (S->tccpp_tok == TOK_STR)
- pstrcat(filename, sizeof(filename), S->tccpp_tokc.str.data);
+ next();
+ if (tok == TOK_STR)
+ pstrcat(filename, sizeof(filename), tokc.str.data);
else
- pstrcat(filename, sizeof(filename), get_tok_str(S, S->tccpp_tok, NULL));
- tcc_warning_c(warn_unsupported)(S, "ignoring .file %s", filename);
- next(S);
+ pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
+ tcc_warning_c(warn_unsupported)("ignoring .file %s", filename);
+ next();
}
break;
case TOK_ASMDIR_ident:
@@ -780,30 +782,30 @@ static void asm_parse_directive(TCCState *S, int global)
char ident[256];
ident[0] = '\0';
- next(S);
- if (S->tccpp_tok == TOK_STR)
- pstrcat(ident, sizeof(ident), S->tccpp_tokc.str.data);
+ next();
+ if (tok == TOK_STR)
+ pstrcat(ident, sizeof(ident), tokc.str.data);
else
- pstrcat(ident, sizeof(ident), get_tok_str(S, S->tccpp_tok, NULL));
- tcc_warning_c(warn_unsupported)(S, "ignoring .ident %s", ident);
- next(S);
+ pstrcat(ident, sizeof(ident), get_tok_str(tok, NULL));
+ tcc_warning_c(warn_unsupported)("ignoring .ident %s", ident);
+ next();
}
break;
case TOK_ASMDIR_size:
{
Sym *sym;
- next(S);
- sym = asm_label_find(S, S->tccpp_tok);
+ next();
+ sym = asm_label_find(tok);
if (!sym) {
- tcc_error(S, "label not found: %s", get_tok_str(S, S->tccpp_tok, NULL));
+ tcc_error("label not found: %s", get_tok_str(tok, NULL));
}
/* XXX .size name,label2-label1 */
- tcc_warning_c(warn_unsupported)(S, "ignoring .size %s,*", get_tok_str(S, S->tccpp_tok, NULL));
- next(S);
- skip(S, ',');
- while (S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != ';' && S->tccpp_tok != CH_EOF) {
- next(S);
+ tcc_warning_c(warn_unsupported)("ignoring .size %s,*", get_tok_str(tok, NULL));
+ next();
+ skip(',');
+ while (tok != TOK_LINEFEED && tok != ';' && tok != CH_EOF) {
+ next();
}
}
break;
@@ -812,182 +814,182 @@ static void asm_parse_directive(TCCState *S, int global)
Sym *sym;
const char *newtype;
- next(S);
- sym = get_asm_sym(S, S->tccpp_tok, NULL);
- next(S);
- skip(S, ',');
- if (S->tccpp_tok == TOK_STR) {
- newtype = S->tccpp_tokc.str.data;
+ next();
+ sym = get_asm_sym(tok, NULL);
+ next();
+ skip(',');
+ if (tok == TOK_STR) {
+ newtype = tokc.str.data;
} else {
- if (S->tccpp_tok == '@' || S->tccpp_tok == '%')
- next(S);
- newtype = get_tok_str(S, S->tccpp_tok, NULL);
+ if (tok == '@' || tok == '%')
+ next();
+ newtype = get_tok_str(tok, NULL);
}
if (!strcmp(newtype, "function") || !strcmp(newtype, "STT_FUNC")) {
sym->type.t = (sym->type.t & ~VT_BTYPE) | VT_FUNC;
} else
- tcc_warning_c(warn_unsupported)(S, "change type of '%s' from 0x%x to '%s' ignored",
- get_tok_str(S, sym->v, NULL), sym->type.t, newtype);
+ tcc_warning_c(warn_unsupported)("change type of '%s' from 0x%x to '%s' ignored",
+ get_tok_str(sym->v, NULL), sym->type.t, newtype);
- next(S);
+ next();
}
break;
case TOK_ASMDIR_pushsection:
case TOK_ASMDIR_section:
{
char sname[256];
- int old_nb_section = S->nb_sections;
+ int old_nb_section = s1->nb_sections;
- tok1 = S->tccpp_tok;
+ tok1 = tok;
/* XXX: support more options */
- next(S);
+ next();
sname[0] = '\0';
- while (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != ',') {
- if (S->tccpp_tok == TOK_STR)
- pstrcat(sname, sizeof(sname), S->tccpp_tokc.str.data);
+ while (tok != ';' && tok != TOK_LINEFEED && tok != ',') {
+ if (tok == TOK_STR)
+ pstrcat(sname, sizeof(sname), tokc.str.data);
else
- pstrcat(sname, sizeof(sname), get_tok_str(S, S->tccpp_tok, NULL));
- next(S);
+ pstrcat(sname, sizeof(sname), get_tok_str(tok, NULL));
+ next();
}
- if (S->tccpp_tok == ',') {
+ if (tok == ',') {
/* skip section options */
- next(S);
- if (S->tccpp_tok != TOK_STR)
- expect(S, "string constant");
- next(S);
- if (S->tccpp_tok == ',') {
- next(S);
- if (S->tccpp_tok == '@' || S->tccpp_tok == '%')
- next(S);
- next(S);
+ next();
+ if (tok != TOK_STR)
+ expect("string constant");
+ next();
+ if (tok == ',') {
+ next();
+ if (tok == '@' || tok == '%')
+ next();
+ next();
}
}
- S->tccasm_last_text_section = cur_text_section;
+ last_text_section = cur_text_section;
if (tok1 == TOK_ASMDIR_section)
- use_section(S, sname);
+ use_section(s1, sname);
else
- push_section(S, sname);
+ push_section(s1, sname);
/* If we just allocated a new section reset its alignment to
1. new_section normally acts for GCC compatibility and
sets alignment to PTR_SIZE. The assembler behaves different. */
- if (old_nb_section != S->nb_sections)
+ if (old_nb_section != s1->nb_sections)
cur_text_section->sh_addralign = 1;
}
break;
case TOK_ASMDIR_previous:
{
Section *sec;
- next(S);
- if (!S->tccasm_last_text_section)
- tcc_error(S, "no previous section referenced");
+ next();
+ if (!last_text_section)
+ tcc_error("no previous section referenced");
sec = cur_text_section;
- use_section1(S, S->tccasm_last_text_section);
- S->tccasm_last_text_section = sec;
+ use_section1(s1, last_text_section);
+ last_text_section = sec;
}
break;
case TOK_ASMDIR_popsection:
- next(S);
- pop_section(S);
+ next();
+ pop_section(s1);
break;
#ifdef TCC_TARGET_I386
case TOK_ASMDIR_code16:
{
- next(S);
- S->seg_size = 16;
+ next();
+ s1->seg_size = 16;
}
break;
case TOK_ASMDIR_code32:
{
- next(S);
- S->seg_size = 32;
+ next();
+ s1->seg_size = 32;
}
break;
#endif
#ifdef TCC_TARGET_X86_64
/* added for compatibility with GAS */
case TOK_ASMDIR_code64:
- next(S);
+ next();
break;
#endif
default:
- tcc_error(S, "unknown assembler directive '.%s'", get_tok_str(S, S->tccpp_tok, NULL));
+ tcc_error("unknown assembler directive '.%s'", get_tok_str(tok, NULL));
break;
}
}
/* assemble a file */
-static int tcc_assemble_internal(TCCState *S, int do_preprocess, int global)
+static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
{
int opcode;
- int saved_parse_flags = S->tccpp_parse_flags;
+ int saved_parse_flags = parse_flags;
- S->tccpp_parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
+ parse_flags = PARSE_FLAG_ASM_FILE | PARSE_FLAG_TOK_STR;
if (do_preprocess)
- S->tccpp_parse_flags |= PARSE_FLAG_PREPROCESS;
+ parse_flags |= PARSE_FLAG_PREPROCESS;
for(;;) {
- next(S);
- if (S->tccpp_tok == TOK_EOF)
+ next();
+ if (tok == TOK_EOF)
break;
- S->tccpp_parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
+ parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
redo:
- if (S->tccpp_tok == '#') {
+ if (tok == '#') {
/* horrible gas comment */
- while (S->tccpp_tok != TOK_LINEFEED)
- next(S);
- } else if (S->tccpp_tok >= TOK_ASMDIR_FIRST && S->tccpp_tok <= TOK_ASMDIR_LAST) {
- asm_parse_directive(S, global);
- } else if (S->tccpp_tok == TOK_PPNUM) {
+ while (tok != TOK_LINEFEED)
+ next();
+ } else if (tok >= TOK_ASMDIR_FIRST && tok <= TOK_ASMDIR_LAST) {
+ asm_parse_directive(s1, global);
+ } else if (tok == TOK_PPNUM) {
const char *p;
int n;
- p = S->tccpp_tokc.str.data;
+ p = tokc.str.data;
n = strtoul(p, (char **)&p, 10);
if (*p != '\0')
- expect(S, "':'");
+ expect("':'");
/* new local label */
- asm_new_label(S, asm_get_local_label_name(S, n), 1);
- next(S);
- skip(S, ':');
+ asm_new_label(s1, asm_get_local_label_name(s1, n), 1);
+ next();
+ skip(':');
goto redo;
- } else if (S->tccpp_tok >= TOK_IDENT) {
+ } else if (tok >= TOK_IDENT) {
/* instruction or label */
- opcode = S->tccpp_tok;
- next(S);
- if (S->tccpp_tok == ':') {
+ opcode = tok;
+ next();
+ if (tok == ':') {
/* new label */
- asm_new_label(S, opcode, 0);
- next(S);
+ asm_new_label(s1, opcode, 0);
+ next();
goto redo;
- } else if (S->tccpp_tok == '=') {
- set_symbol(S, opcode);
+ } else if (tok == '=') {
+ set_symbol(s1, opcode);
goto redo;
} else {
- asm_opcode(S, opcode);
+ asm_opcode(s1, opcode);
}
}
/* end of line */
- if (S->tccpp_tok != ';' && S->tccpp_tok != TOK_LINEFEED)
- expect(S, "end of line");
- S->tccpp_parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
+ if (tok != ';' && tok != TOK_LINEFEED)
+ expect("end of line");
+ parse_flags &= ~PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
}
- S->tccpp_parse_flags = saved_parse_flags;
+ parse_flags = saved_parse_flags;
return 0;
}
/* Assemble the current file */
-ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess)
+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
{
int ret;
- tcc_debug_start(S);
+ tcc_debug_start(s1);
/* default section is text */
cur_text_section = text_section;
- S->tccgen_ind = cur_text_section->data_offset;
- S->tccgen_nocode_wanted = 0;
- ret = tcc_assemble_internal(S, do_preprocess, 1);
- cur_text_section->data_offset = S->tccgen_ind;
- tcc_debug_end(S);
+ ind = cur_text_section->data_offset;
+ nocode_wanted = 0;
+ ret = tcc_assemble_internal(s1, do_preprocess, 1);
+ cur_text_section->data_offset = ind;
+ tcc_debug_end(s1);
return ret;
}
@@ -997,27 +999,27 @@ ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess)
/* assemble the string 'str' in the current C compilation unit without
C preprocessing. NOTE: str is modified by modifying the '\0' at the
end */
-static void tcc_assemble_inline(TCCState *S, char *str, int len, int global)
+static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
{
- const int *saved_macro_ptr = S->tccpp_macro_ptr;
- int dotid = set_idnum(S, '.', IS_ID);
- int dolid = set_idnum(S, '$', 0);
-
- tcc_open_bf(S, ":asm:", len);
- memcpy(S->tccpp_file->buffer, str, len);
- S->tccpp_macro_ptr = NULL;
- tcc_assemble_internal(S, 0, global);
- tcc_close(S);
-
- set_idnum(S, '$', dolid);
- set_idnum(S, '.', dotid);
- S->tccpp_macro_ptr = saved_macro_ptr;
+ const int *saved_macro_ptr = macro_ptr;
+ int dotid = set_idnum('.', IS_ID);
+ int dolid = set_idnum('$', 0);
+
+ tcc_open_bf(s1, ":asm:", len);
+ memcpy(file->buffer, str, len);
+ macro_ptr = NULL;
+ tcc_assemble_internal(s1, 0, global);
+ tcc_close();
+
+ set_idnum('$', dolid);
+ set_idnum('.', dotid);
+ macro_ptr = saved_macro_ptr;
}
/* find a constraint by its number or id (gcc 3 extended
syntax). return -1 if not found. Return in *pp in char after the
constraint */
-ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands,
+ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands,
const char *name, const char **pp)
{
int index;
@@ -1036,7 +1038,7 @@ ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands,
name++;
p = strchr(name, ']');
if (p) {
- ts = tok_alloc(S, name, p - name);
+ ts = tok_alloc(name, p - name);
for(index = 0; index < nb_operands; index++) {
if (operands[index].id == ts->tok)
goto found;
@@ -1055,7 +1057,7 @@ ST_FUNC int find_constraint(TCCState* S, ASMOperand *operands, int nb_operands,
return index;
}
-static void subst_asm_operands(TCCState* S, ASMOperand *operands, int nb_operands,
+static void subst_asm_operands(ASMOperand *operands, int nb_operands,
CString *out_str, CString *in_str)
{
int c, index, modifier;
@@ -1063,7 +1065,7 @@ static void subst_asm_operands(TCCState* S, ASMOperand *operands, int nb_operand
ASMOperand *op;
SValue sv;
- cstr_new(S, out_str);
+ cstr_new(out_str);
str = in_str->data;
for(;;) {
c = *str++;
@@ -1080,9 +1082,9 @@ static void subst_asm_operands(TCCState* S, ASMOperand *operands, int nb_operand
and make literal operands not be decorated with '$'. */
*str == 'P')
modifier = *str++;
- index = find_constraint(S, operands, nb_operands, str, &str);
+ index = find_constraint(operands, nb_operands, str, &str);
if (index < 0)
- tcc_error(S, "invalid operand reference after %%");
+ tcc_error("invalid operand reference after %%");
op = &operands[index];
sv = *op->vt;
if (op->reg >= 0) {
@@ -1090,10 +1092,10 @@ static void subst_asm_operands(TCCState* S, ASMOperand *operands, int nb_operand
if ((op->vt->r & VT_VALMASK) == VT_LLOCAL && op->is_memory)
sv.r |= VT_LVAL;
}
- subst_asm_operand(S, out_str, &sv, modifier);
+ subst_asm_operand(out_str, &sv, modifier);
} else {
add_char:
- cstr_ccat(S, out_str, c);
+ cstr_ccat(out_str, c);
if (c == '\0')
break;
}
@@ -1101,53 +1103,53 @@ static void subst_asm_operands(TCCState* S, ASMOperand *operands, int nb_operand
}
-static void parse_asm_operands(TCCState* S, ASMOperand *operands, int *nb_operands_ptr,
+static void parse_asm_operands(ASMOperand *operands, int *nb_operands_ptr,
int is_output)
{
ASMOperand *op;
int nb_operands;
- if (S->tccpp_tok != ':') {
+ if (tok != ':') {
nb_operands = *nb_operands_ptr;
for(;;) {
CString astr;
if (nb_operands >= MAX_ASM_OPERANDS)
- tcc_error(S, "too many asm operands");
+ tcc_error("too many asm operands");
op = &operands[nb_operands++];
op->id = 0;
- if (S->tccpp_tok == '[') {
- next(S);
- if (S->tccpp_tok < TOK_IDENT)
- expect(S, "identifier");
- op->id = S->tccpp_tok;
- next(S);
- skip(S, ']');
+ if (tok == '[') {
+ next();
+ if (tok < TOK_IDENT)
+ expect("identifier");
+ op->id = tok;
+ next();
+ skip(']');
}
- parse_mult_str(S, &astr, "string constant");
- op->constraint = tcc_malloc(S, astr.size);
+ parse_mult_str(&astr, "string constant");
+ op->constraint = tcc_malloc(astr.size);
strcpy(op->constraint, astr.data);
- cstr_free(S, &astr);
- skip(S, '(');
- gexpr(S);
+ cstr_free(&astr);
+ skip('(');
+ gexpr();
if (is_output) {
- if (!(S->tccgen_vtop->type.t & VT_ARRAY))
- test_lvalue(S);
+ if (!(vtop->type.t & VT_ARRAY))
+ test_lvalue();
} else {
/* we want to avoid LLOCAL case, except when the 'm'
constraint is used. Note that it may come from
register storage, so we need to convert (reg)
case */
- if ((S->tccgen_vtop->r & VT_LVAL) &&
- ((S->tccgen_vtop->r & VT_VALMASK) == VT_LLOCAL ||
- (S->tccgen_vtop->r & VT_VALMASK) < VT_CONST) &&
+ if ((vtop->r & VT_LVAL) &&
+ ((vtop->r & VT_VALMASK) == VT_LLOCAL ||
+ (vtop->r & VT_VALMASK) < VT_CONST) &&
!strchr(op->constraint, 'm')) {
- gv(S, RC_INT);
+ gv(RC_INT);
}
}
- op->vt = S->tccgen_vtop;
- skip(S, ')');
- if (S->tccpp_tok == ',') {
- next(S);
+ op->vt = vtop;
+ skip(')');
+ if (tok == ',') {
+ next();
} else {
break;
}
@@ -1157,7 +1159,7 @@ static void parse_asm_operands(TCCState* S, ASMOperand *operands, int *nb_operan
}
/* parse the GCC asm() instruction */
-ST_FUNC void asm_instr(TCCState* S)
+ST_FUNC void asm_instr(void)
{
CString astr, astr1;
ASMOperand operands[MAX_ASM_OPERANDS];
@@ -1167,36 +1169,36 @@ ST_FUNC void asm_instr(TCCState* S)
/* since we always generate the asm() instruction, we can ignore
volatile */
- if (S->tccpp_tok == TOK_VOLATILE1 || S->tccpp_tok == TOK_VOLATILE2 || S->tccpp_tok == TOK_VOLATILE3) {
- next(S);
+ if (tok == TOK_VOLATILE1 || tok == TOK_VOLATILE2 || tok == TOK_VOLATILE3) {
+ next();
}
- parse_asm_str(S, &astr);
+ parse_asm_str(&astr);
nb_operands = 0;
nb_outputs = 0;
must_subst = 0;
memset(clobber_regs, 0, sizeof(clobber_regs));
- if (S->tccpp_tok == ':') {
- next(S);
+ if (tok == ':') {
+ next();
must_subst = 1;
/* output args */
- parse_asm_operands(S, operands, &nb_operands, 1);
+ parse_asm_operands(operands, &nb_operands, 1);
nb_outputs = nb_operands;
- if (S->tccpp_tok == ':') {
- next(S);
- if (S->tccpp_tok != ')') {
+ if (tok == ':') {
+ next();
+ if (tok != ')') {
/* input args */
- parse_asm_operands(S, operands, &nb_operands, 0);
- if (S->tccpp_tok == ':') {
+ parse_asm_operands(operands, &nb_operands, 0);
+ if (tok == ':') {
/* clobber list */
/* XXX: handle registers */
- next(S);
+ next();
for(;;) {
- if (S->tccpp_tok != TOK_STR)
- expect(S, "string constant");
- asm_clobber(S, clobber_regs, S->tccpp_tokc.str.data);
- next(S);
- if (S->tccpp_tok == ',') {
- next(S);
+ if (tok != TOK_STR)
+ expect("string constant");
+ asm_clobber(clobber_regs, tokc.str.data);
+ next();
+ if (tok == ',') {
+ next();
} else {
break;
}
@@ -1205,17 +1207,17 @@ ST_FUNC void asm_instr(TCCState* S)
}
}
}
- skip(S, ')');
+ skip(')');
/* NOTE: we do not eat the ';' so that we can restore the current
token after the assembler parsing */
- if (S->tccpp_tok != ';')
- expect(S, "';'");
+ if (tok != ';')
+ expect("';'");
/* save all values in the memory */
- save_regs(S, 0);
+ save_regs(0);
/* compute constraints */
- asm_compute_constraints(S, operands, nb_operands, nb_outputs,
+ asm_compute_constraints(operands, nb_operands, nb_outputs,
clobber_regs, &out_reg);
/* substitute the operands in the asm string. No substitution is
@@ -1224,8 +1226,8 @@ ST_FUNC void asm_instr(TCCState* S)
printf("asm: \"%s\"\n", (char *)astr.data);
#endif
if (must_subst) {
- subst_asm_operands(S, operands, nb_operands, &astr1, &astr);
- cstr_free(S, &astr);
+ subst_asm_operands(operands, nb_operands, &astr1, &astr);
+ cstr_free(&astr);
} else {
astr1 = astr;
}
@@ -1234,83 +1236,83 @@ ST_FUNC void asm_instr(TCCState* S)
#endif
/* generate loads */
- asm_gen_code(S, operands, nb_operands, nb_outputs, 0,
+ asm_gen_code(operands, nb_operands, nb_outputs, 0,
clobber_regs, out_reg);
/* We don't allow switching section within inline asm to
bleed out to surrounding code. */
sec = cur_text_section;
/* assemble the string with tcc internal assembler */
- tcc_assemble_inline(S, astr1.data, astr1.size - 1, 0);
+ tcc_assemble_inline(tcc_state, astr1.data, astr1.size - 1, 0);
if (sec != cur_text_section) {
- tcc_warning(S, "inline asm tries to change current section");
- use_section1(S, sec);
+ tcc_warning("inline asm tries to change current section");
+ use_section1(tcc_state, sec);
}
/* restore the current C token */
- next(S);
+ next();
/* store the output values if needed */
- asm_gen_code(S, operands, nb_operands, nb_outputs, 1,
+ asm_gen_code(operands, nb_operands, nb_outputs, 1,
clobber_regs, out_reg);
/* free everything */
for(i=0;i<nb_operands;i++) {
ASMOperand *op;
op = &operands[i];
- tcc_free(S, op->constraint);
- vpop(S);
+ tcc_free(op->constraint);
+ vpop();
}
- cstr_free(S, &astr1);
+ cstr_free(&astr1);
}
-ST_FUNC void asm_global_instr(TCCState* S)
+ST_FUNC void asm_global_instr(void)
{
CString astr;
- int saved_nocode_wanted = S->tccgen_nocode_wanted;
+ int saved_nocode_wanted = nocode_wanted;
/* Global asm blocks are always emitted. */
- S->tccgen_nocode_wanted = 0;
- next(S);
- parse_asm_str(S, &astr);
- skip(S, ')');
+ nocode_wanted = 0;
+ next();
+ parse_asm_str(&astr);
+ skip(')');
/* NOTE: we do not eat the ';' so that we can restore the current
token after the assembler parsing */
- if (S->tccpp_tok != ';')
- expect(S, "';'");
+ if (tok != ';')
+ expect("';'");
#ifdef ASM_DEBUG
printf("asm_global: \"%s\"\n", (char *)astr.data);
#endif
cur_text_section = text_section;
- S->tccgen_ind = cur_text_section->data_offset;
+ ind = cur_text_section->data_offset;
/* assemble the string with tcc internal assembler */
- tcc_assemble_inline(S, astr.data, astr.size - 1, 1);
+ tcc_assemble_inline(tcc_state, astr.data, astr.size - 1, 1);
- cur_text_section->data_offset = S->tccgen_ind;
+ cur_text_section->data_offset = ind;
/* restore the current C token */
- next(S);
+ next();
- cstr_free(S, &astr);
- S->tccgen_nocode_wanted = saved_nocode_wanted;
+ cstr_free(&astr);
+ nocode_wanted = saved_nocode_wanted;
}
/********************************************************/
#else
-ST_FUNC int tcc_assemble(TCCState *S, int do_preprocess)
+ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
{
- tcc_error(S, "asm not supported");
+ tcc_error("asm not supported");
}
-ST_FUNC void asm_instr(S)
+ST_FUNC void asm_instr(void)
{
- tcc_error(S, "inline asm() not supported");
+ tcc_error("inline asm() not supported");
}
-ST_FUNC void asm_global_instr(S)
+ST_FUNC void asm_global_instr(void)
{
- tcc_error(S, "inline asm() not supported");
+ tcc_error("inline asm() not supported");
}
#endif /* CONFIG_TCC_ASM */
diff --git a/tcccoff.c b/tcccoff.c
index de5a29c..651bbe8 100644
--- a/tcccoff.c
+++ b/tcccoff.c
@@ -40,12 +40,12 @@ int FuncEntries[MAX_FUNCS];
int OutputTheSection(Section * sect);
short int GetCoffFlags(const char *s);
-void SortSymbolTable(TCCState *S);
-Section *FindSection(TCCState * S, const char *sname);
+void SortSymbolTable(TCCState *s1);
+Section *FindSection(TCCState * s1, const char *sname);
int C67_main_entry_point;
-int FindCoffSymbolIndex(TCCState * S, const char *func_name);
+int FindCoffSymbolIndex(TCCState * s1, const char *func_name);
int nb_syms;
typedef struct {
@@ -74,7 +74,7 @@ typedef struct {
unsigned short dummy4;
} AUXEF;
-ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
+ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f)
{
Section *tcc_sect;
SCNHDR *coff_sec;
@@ -87,12 +87,12 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
Coff_str_table = pCoff_str_table = NULL;
- stext = FindSection(S, ".text");
- sdata = FindSection(S, ".data");
- sbss = FindSection(S, ".bss");
+ stext = FindSection(s1, ".text");
+ sdata = FindSection(s1, ".data");
+ sbss = FindSection(s1, ".bss");
nb_syms = symtab_section->data_offset / sizeof(Elf32_Sym);
- coff_nb_syms = FindCoffSymbolIndex(S, "XXXXXXXXXX1");
+ coff_nb_syms = FindCoffSymbolIndex(s1, "XXXXXXXXXX1");
file_hdr.f_magic = COFF_C67_MAGIC; /* magic number */
file_hdr.f_timdat = 0; /* time & date stamp */
@@ -116,9 +116,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
CoffTextSectionNo = -1;
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
NSectionsToOutput++;
@@ -149,9 +149,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// for the raw data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put raw data
@@ -163,9 +163,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// now loop through and determine file pointer locations
// for the relocation data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
@@ -179,14 +179,14 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// now loop through and determine file pointer locations
// for the line number data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
coff_sec->s_nlnno = 0;
coff_sec->s_lnnoptr = 0;
- if (S->do_debug && tcc_sect == stext) {
+ if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
// also find association between source file name and function
@@ -314,7 +314,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
file_hdr.f_symptr = file_pointer; /* file pointer to symtab */
- if (S->do_debug)
+ if (s1->do_debug)
file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */
else
file_hdr.f_nsyms = 0;
@@ -328,9 +328,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
fwrite(&o_filehdr, sizeof(o_filehdr), 1, f);
// write section headers
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(coff_sec, sizeof(SCNHDR), 1, f);
@@ -338,9 +338,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
}
// write raw data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
fwrite(tcc_sect->data, tcc_sect->data_offset, 1, f);
@@ -348,9 +348,9 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
}
// write relocation data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
if (OutputTheSection(tcc_sect)) {
// put relocations data
@@ -365,16 +365,16 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
- if (S->do_debug)
- SortSymbolTable(S);
+ if (s1->do_debug)
+ SortSymbolTable(s1);
// write line no data
- for (i = 1; i < S->nb_sections; i++) {
+ for (i = 1; i < s1->nb_sections; i++) {
coff_sec = &section_header[i];
- tcc_sect = S->sections[i];
+ tcc_sect = s1->sections[i];
- if (S->do_debug && tcc_sect == stext) {
+ if (s1->do_debug && tcc_sect == stext) {
// count how many line nos data
@@ -437,7 +437,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// output a function begin
CoffLineNo.l_addr.l_symndx =
- FindCoffSymbolIndex(S, func_name);
+ FindCoffSymbolIndex(s1, func_name);
CoffLineNo.l_lnno = 0;
fwrite(&CoffLineNo, 6, 1, f);
@@ -502,7 +502,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
}
// write symbol table
- if (S->do_debug) {
+ if (s1->do_debug) {
int k;
struct syment csym;
AUXFUNC auxfunc;
@@ -514,7 +514,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
int nstr;
int n = 0;
- Coff_str_table = (char *) tcc_malloc(S, MAX_STR_TABLE);
+ Coff_str_table = (char *) tcc_malloc(MAX_STR_TABLE);
pCoff_str_table = Coff_str_table;
nstr = 0;
@@ -533,7 +533,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
} else {
if (pCoff_str_table - Coff_str_table + strlen(name) >
MAX_STR_TABLE - 1)
- tcc_error(S, "String table too large");
+ tcc_error("String table too large");
csym._n._n_n._n_zeroes = 0;
csym._n._n_n._n_offset =
@@ -563,7 +563,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
}
if (k >= nFuncs) {
- tcc_error(S, "debug info can't find function: %s", name);
+ tcc_error("debug info can't find function: %s", name);
}
// put a Function Name
@@ -669,7 +669,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
}
}
- if (S->do_debug) {
+ if (s1->do_debug) {
// write string table
// first write the size
@@ -679,7 +679,7 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// then write the strings
fwrite(Coff_str_table, i, 1, f);
- tcc_free(S, Coff_str_table);
+ tcc_free(Coff_str_table);
}
return 0;
@@ -690,13 +690,13 @@ ST_FUNC int tcc_output_coff(TCCState *S, FILE *f)
// group the symbols in order of filename, func1, func2, etc
// finally global symbols
-void SortSymbolTable(TCCState *S)
+void SortSymbolTable(TCCState *s1)
{
int i, j, k, n = 0;
Elf32_Sym *p, *p2, *NewTable;
char *name, *name2;
- NewTable = (Elf32_Sym *) tcc_malloc(S, nb_syms * sizeof(Elf32_Sym));
+ NewTable = (Elf32_Sym *) tcc_malloc(nb_syms * sizeof(Elf32_Sym));
p = (Elf32_Sym *) symtab_section->data;
@@ -730,7 +730,7 @@ void SortSymbolTable(TCCState *S)
}
if (k >= nFuncs) {
- tcc_error(S, "debug (sort) info can't find function: %s", name2);
+ tcc_error("debug (sort) info can't find function: %s", name2);
}
if (strcmp(AssociatedFile[k], name) == 0) {
@@ -757,7 +757,7 @@ void SortSymbolTable(TCCState *S)
}
if (n != nb_syms)
- tcc_error(S, "Internal Compiler error, debug info");
+ tcc_error("Internal Compiler error, debug info");
// copy it all back
@@ -766,11 +766,11 @@ void SortSymbolTable(TCCState *S)
*p++ = NewTable[i];
}
- tcc_free(S, NewTable);
+ tcc_free(NewTable);
}
-int FindCoffSymbolIndex(TCCState *S, const char *func_name)
+int FindCoffSymbolIndex(TCCState *s1, const char *func_name)
{
int i, n = 0;
Elf32_Sym *p;
@@ -842,23 +842,23 @@ short int GetCoffFlags(const char *s)
return 0;
}
-Section *FindSection(TCCState * S, const char *sname)
+Section *FindSection(TCCState * s1, const char *sname)
{
Section *s;
int i;
- for (i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for (i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (!strcmp(sname, s->name))
return s;
}
- tcc_error(S, "could not find section %s", sname);
+ tcc_error("could not find section %s", sname);
return 0;
}
-ST_FUNC int tcc_load_coff(TCCState * S, int fd)
+ST_FUNC int tcc_load_coff(TCCState * s1, int fd)
{
// tktk TokenSym *ts;
@@ -872,39 +872,39 @@ ST_FUNC int tcc_load_coff(TCCState * S, int fd)
f = fdopen(fd, "rb");
if (!f) {
- tcc_error(S, "Unable to open .out file for input");
+ tcc_error("Unable to open .out file for input");
}
if (fread(&file_hdr, FILHSZ, 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
if (fread(&o_filehdr, sizeof(o_filehdr), 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
// first read the string table
if (fseek(f, file_hdr.f_symptr + file_hdr.f_nsyms * SYMESZ, SEEK_SET))
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
if (fread(&str_size, sizeof(int), 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
- Coff_str_table = (char *) tcc_malloc(S, str_size);
+ Coff_str_table = (char *) tcc_malloc(str_size);
if (fread(Coff_str_table, str_size - 4, 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
// read/process all the symbols
// seek back to symbols
if (fseek(f, file_hdr.f_symptr, SEEK_SET))
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
for (i = 0; i < file_hdr.f_nsyms; i++) {
if (fread(&csym, SYMESZ, 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
if (csym._n._n_n._n_zeroes == 0) {
name = Coff_str_table + csym._n._n_n._n_offset - 4;
@@ -933,13 +933,13 @@ ST_FUNC int tcc_load_coff(TCCState * S, int fd)
if (name[0] == '_' && strcmp(name, "_main") != 0)
name++;
- tcc_add_symbol(S, name, (void*)(uintptr_t)csym.n_value);
+ tcc_add_symbol(s1, name, (void*)(uintptr_t)csym.n_value);
}
// skip any aux records
if (csym.n_numaux == 1) {
if (fread(&csym, SYMESZ, 1, f) != 1)
- tcc_error(S, "error reading .out file for input");
+ tcc_error("error reading .out file for input");
i++;
}
}
diff --git a/tccelf.c b/tccelf.c
index 16337da..ddbce88 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -34,13 +34,13 @@ struct sym_version {
int prev_same_lib;
};
-#define nb_sym_versions S->nb_sym_versions
-#define sym_versions S->sym_versions
-#define nb_sym_to_version S->nb_sym_to_version
-#define sym_to_version S->sym_to_version
-#define dt_verneednum S->dt_verneednum
-#define versym_section S->versym_section
-#define verneed_section S->verneed_section
+#define nb_sym_versions s1->nb_sym_versions
+#define sym_versions s1->sym_versions
+#define nb_sym_to_version s1->nb_sym_to_version
+#define sym_to_version s1->sym_to_version
+#define dt_verneednum s1->dt_verneednum
+#define versym_section s1->versym_section
+#define verneed_section s1->verneed_section
/* special flag to indicate that the section should not be linked to the other ones */
#define SHF_PRIVATE 0x80000000
@@ -49,96 +49,99 @@ struct sym_version {
/* ------------------------------------------------------------------------- */
-ST_FUNC void tccelf_new(TCCState *S)
+ST_FUNC void tccelf_new(TCCState *s)
{
+ TCCState *s1 = s;
/* no section zero */
- dynarray_add(S, &S->sections, &S->nb_sections, NULL);
+ dynarray_add(&s->sections, &s->nb_sections, NULL);
/* create standard sections */
- text_section = new_section(S, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
- data_section = new_section(S, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ text_section = new_section(s, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
+ data_section = new_section(s, ".data", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
#ifdef TCC_TARGET_PE
- rodata_section = new_section(S, ".rdata", SHT_PROGBITS, SHF_ALLOC);
+ rodata_section = new_section(s, ".rdata", SHT_PROGBITS, SHF_ALLOC);
#else
/* create ro data section (make ro after relocation done with GNU_RELRO) */
- rodata_section = new_section(S, ".data.ro", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ rodata_section = new_section(s, ".data.ro", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
#endif
- bss_section = new_section(S, ".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
- common_section = new_section(S, ".common", SHT_NOBITS, SHF_PRIVATE);
+ bss_section = new_section(s, ".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+ common_section = new_section(s, ".common", SHT_NOBITS, SHF_PRIVATE);
common_section->sh_num = SHN_COMMON;
/* symbols are always generated for linking stage */
- symtab_section = new_symtab(S, ".symtab", SHT_SYMTAB, 0,
+ symtab_section = new_symtab(s, ".symtab", SHT_SYMTAB, 0,
".strtab",
".hashtab", SHF_PRIVATE);
- S->symtab = symtab_section;
+ s->symtab = symtab_section;
/* private symbol table for dynamic symbols */
- S->dynsymtab_section = new_symtab(S, ".dynsymtab", SHT_SYMTAB, SHF_PRIVATE|SHF_DYNSYM,
+ s->dynsymtab_section = new_symtab(s, ".dynsymtab", SHT_SYMTAB, SHF_PRIVATE|SHF_DYNSYM,
".dynstrtab",
".dynhashtab", SHF_PRIVATE);
- get_sym_attr(S, 0, 1);
+ get_sym_attr(s, 0, 1);
}
#ifdef CONFIG_TCC_BCHECK
-ST_FUNC void tccelf_bounds_new(TCCState *S)
+ST_FUNC void tccelf_bounds_new(TCCState *s)
{
+ TCCState *s1 = s;
/* create bounds sections (make ro after relocation done with GNU_RELRO) */
- bounds_section = new_section(S, ".bounds",
+ bounds_section = new_section(s, ".bounds",
SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
- lbounds_section = new_section(S, ".lbounds",
+ lbounds_section = new_section(s, ".lbounds",
SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
}
#endif
-ST_FUNC void tccelf_stab_new(TCCState *S)
+ST_FUNC void tccelf_stab_new(TCCState *s)
{
+ TCCState *s1 = s;
int shf = 0;
#ifdef CONFIG_TCC_BACKTRACE
/* include stab info with standalone backtrace support */
- if (S->do_backtrace && S->output_type != TCC_OUTPUT_MEMORY)
+ if (s->do_backtrace && s->output_type != TCC_OUTPUT_MEMORY)
shf = SHF_ALLOC | SHF_WRITE; // SHF_WRITE needed for musl/SELINUX
#endif
- stab_section = new_section(S, ".stab", SHT_PROGBITS, shf);
+ stab_section = new_section(s, ".stab", SHT_PROGBITS, shf);
stab_section->sh_entsize = sizeof(Stab_Sym);
stab_section->sh_addralign = sizeof ((Stab_Sym*)0)->n_value;
- stab_section->link = new_section(S, ".stabstr", SHT_STRTAB, shf);
+ stab_section->link = new_section(s, ".stabstr", SHT_STRTAB, shf);
/* put first entry */
- put_stabs(S, "", 0, 0, 0, 0);
+ put_stabs(s, "", 0, 0, 0, 0);
}
-static void free_section(TCCState* S, Section *s)
+static void free_section(Section *s)
{
- tcc_free(S, s->data);
+ tcc_free(s->data);
}
-ST_FUNC void tccelf_delete(TCCState *S)
+ST_FUNC void tccelf_delete(TCCState *s1)
{
int i;
#ifndef ELF_OBJ_ONLY
/* free symbol versions */
for (i = 0; i < nb_sym_versions; i++) {
- tcc_free(S, sym_versions[i].version);
- tcc_free(S, sym_versions[i].lib);
+ tcc_free(sym_versions[i].version);
+ tcc_free(sym_versions[i].lib);
}
- tcc_free(S, sym_versions);
- tcc_free(S, sym_to_version);
+ tcc_free(sym_versions);
+ tcc_free(sym_to_version);
#endif
/* free all sections */
- for(i = 1; i < S->nb_sections; i++)
- free_section(S, S->sections[i]);
- dynarray_reset(S, &S->sections, &S->nb_sections);
+ for(i = 1; i < s1->nb_sections; i++)
+ free_section(s1->sections[i]);
+ dynarray_reset(&s1->sections, &s1->nb_sections);
- for(i = 0; i < S->nb_priv_sections; i++)
- free_section(S, S->priv_sections[i]);
- dynarray_reset(S, &S->priv_sections, &S->nb_priv_sections);
+ for(i = 0; i < s1->nb_priv_sections; i++)
+ free_section(s1->priv_sections[i]);
+ dynarray_reset(&s1->priv_sections, &s1->nb_priv_sections);
/* free any loaded DLLs */
#ifdef TCC_IS_NATIVE
- for ( i = 0; i < S->nb_loaded_dlls; i++) {
- DLLReference *ref = S->loaded_dlls[i];
+ for ( i = 0; i < s1->nb_loaded_dlls; i++) {
+ DLLReference *ref = s1->loaded_dlls[i];
if ( ref->handle )
# ifdef _WIN32
FreeLibrary((HMODULE)ref->handle);
@@ -148,32 +151,32 @@ ST_FUNC void tccelf_delete(TCCState *S)
}
#endif
/* free loaded dlls array */
- dynarray_reset(S, &S->loaded_dlls, &S->nb_loaded_dlls);
- tcc_free(S, S->sym_attrs);
+ dynarray_reset(&s1->loaded_dlls, &s1->nb_loaded_dlls);
+ tcc_free(s1->sym_attrs);
symtab_section = NULL; /* for tccrun.c:rt_printline() */
}
/* save section data state */
-ST_FUNC void tccelf_begin_file(TCCState *S)
+ST_FUNC void tccelf_begin_file(TCCState *s1)
{
Section *s; int i;
- for (i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for (i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
s->sh_offset = s->data_offset;
}
/* disable symbol hashing during compilation */
- s = S->symtab, s->reloc = s->hash, s->hash = NULL;
+ s = s1->symtab, s->reloc = s->hash, s->hash = NULL;
#if defined TCC_TARGET_X86_64 && defined TCC_TARGET_PE
- S->uw_sym = 0;
+ s1->uw_sym = 0;
#endif
}
/* At the end of compilation, convert any UNDEF syms to global, and merge
with previously existing symbols */
-ST_FUNC void tccelf_end_file(TCCState *S)
+ST_FUNC void tccelf_end_file(TCCState *s1)
{
- Section *s = S->symtab;
+ Section *s = s1->symtab;
int first_sym, nb_syms, *tr, i;
first_sym = s->sh_offset / sizeof (ElfSym);
@@ -181,7 +184,7 @@ ST_FUNC void tccelf_end_file(TCCState *S)
s->data_offset = s->sh_offset;
s->link->data_offset = s->link->sh_offset;
s->hash = s->reloc, s->reloc = NULL;
- tr = tcc_mallocz(S, nb_syms * sizeof *tr);
+ tr = tcc_mallocz(nb_syms * sizeof *tr);
for (i = 0; i < nb_syms; ++i) {
ElfSym *sym = (ElfSym*)s->data + first_sym + i;
@@ -192,33 +195,33 @@ ST_FUNC void tccelf_end_file(TCCState *S)
sym->st_other, sym->st_shndx, (char*)s->link->data + sym->st_name);
}
/* now update relocations */
- for (i = 1; i < S->nb_sections; i++) {
- Section *sr = S->sections[i];
+ for (i = 1; i < s1->nb_sections; i++) {
+ Section *sr = s1->sections[i];
if (sr->sh_type == SHT_RELX && sr->link == s) {
ElfW_Rel *rel = (ElfW_Rel*)(sr->data + sr->sh_offset);
ElfW_Rel *rel_end = (ElfW_Rel*)(sr->data + sr->data_offset);
for (; rel < rel_end; ++rel) {
int n = ELFW(R_SYM)(rel->r_info) - first_sym;
- //if (n < 0) tcc_error(S, "internal: invalid symbol index in relocation");
+ //if (n < 0) tcc_error("internal: invalid symbol index in relocation");
rel->r_info = ELFW(R_INFO)(tr[n], ELFW(R_TYPE)(rel->r_info));
}
}
}
- tcc_free(S, tr);
+ tcc_free(tr);
/* record text/data/bss output for -bench info */
for (i = 0; i < 4; ++i) {
- s = S->sections[i + 1];
- S->total_output[i] += s->data_offset - s->sh_offset;
+ s = s1->sections[i + 1];
+ s1->total_output[i] += s->data_offset - s->sh_offset;
}
}
-ST_FUNC Section *new_section(TCCState *S, const char *name, int sh_type, int sh_flags)
+ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags)
{
Section *sec;
- sec = tcc_mallocz(S, sizeof(Section) + strlen(name));
- sec->S = S;
+ sec = tcc_mallocz(sizeof(Section) + strlen(name));
+ sec->s1 = s1;
strcpy(sec->name, name);
sec->sh_type = sh_type;
sec->sh_flags = sh_flags;
@@ -245,16 +248,16 @@ ST_FUNC Section *new_section(TCCState *S, const char *name, int sh_type, int sh_
}
if (sh_flags & SHF_PRIVATE) {
- dynarray_add(S, &S->priv_sections, &S->nb_priv_sections, sec);
+ dynarray_add(&s1->priv_sections, &s1->nb_priv_sections, sec);
} else {
- sec->sh_num = S->nb_sections;
- dynarray_add(S, &S->sections, &S->nb_sections, sec);
+ sec->sh_num = s1->nb_sections;
+ dynarray_add(&s1->sections, &s1->nb_sections, sec);
}
return sec;
}
-ST_FUNC Section *new_symtab(TCCState *S,
+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)
@@ -262,21 +265,21 @@ ST_FUNC Section *new_symtab(TCCState *S,
Section *symtab, *strtab, *hash;
int *ptr, nb_buckets;
- symtab = new_section(S, symtab_name, sh_type, sh_flags);
+ symtab = new_section(s1, symtab_name, sh_type, sh_flags);
symtab->sh_entsize = sizeof(ElfW(Sym));
- strtab = new_section(S, strtab_name, SHT_STRTAB, sh_flags);
- put_elf_str(S, strtab, "");
+ strtab = new_section(s1, strtab_name, SHT_STRTAB, sh_flags);
+ put_elf_str(strtab, "");
symtab->link = strtab;
- put_elf_sym(S, symtab, 0, 0, 0, 0, 0, NULL);
+ put_elf_sym(symtab, 0, 0, 0, 0, 0, NULL);
nb_buckets = 1;
- hash = new_section(S, hash_name, SHT_HASH, hash_sh_flags);
+ hash = new_section(s1, hash_name, SHT_HASH, hash_sh_flags);
hash->sh_entsize = sizeof(int);
symtab->hash = hash;
hash->link = symtab;
- ptr = section_ptr_add(S, hash, (2 + nb_buckets + 1) * sizeof(int));
+ ptr = section_ptr_add(hash, (2 + nb_buckets + 1) * sizeof(int));
ptr[0] = nb_buckets;
ptr[1] = 1;
memset(ptr + 2, 0, (nb_buckets + 1) * sizeof(int));
@@ -284,7 +287,7 @@ ST_FUNC Section *new_symtab(TCCState *S,
}
/* realloc section and set its content to zero */
-ST_FUNC void section_realloc(TCCState* S, Section *sec, unsigned long new_size)
+ST_FUNC void section_realloc(Section *sec, unsigned long new_size)
{
unsigned long size;
unsigned char *data;
@@ -294,7 +297,7 @@ ST_FUNC void section_realloc(TCCState* S, Section *sec, unsigned long new_size)
size = 1;
while (size < new_size)
size = size * 2;
- data = tcc_realloc(S, sec->data, size);
+ data = tcc_realloc(sec->data, size);
memset(data + sec->data_allocated, 0, size - sec->data_allocated);
sec->data = data;
sec->data_allocated = size;
@@ -302,14 +305,14 @@ ST_FUNC void section_realloc(TCCState* S, Section *sec, unsigned long new_size)
/* reserve at least 'size' bytes aligned per 'align' in section
'sec' from current offset, and return the aligned offset */
-ST_FUNC size_t section_add(TCCState* S, Section *sec, addr_t size, int align)
+ST_FUNC size_t section_add(Section *sec, addr_t size, int align)
{
size_t offset, offset1;
offset = (sec->data_offset + align - 1) & -align;
offset1 = offset + size;
if (sec->sh_type != SHT_NOBITS && offset1 > sec->data_allocated)
- section_realloc(S, sec, offset1);
+ section_realloc(sec, offset1);
sec->data_offset = offset1;
if (align > sec->sh_addralign)
sec->sh_addralign = align;
@@ -318,53 +321,53 @@ ST_FUNC size_t section_add(TCCState* S, Section *sec, addr_t size, int align)
/* reserve at least 'size' bytes in section 'sec' from
sec->data_offset. */
-ST_FUNC void *section_ptr_add(TCCState* S, Section *sec, addr_t size)
+ST_FUNC void *section_ptr_add(Section *sec, addr_t size)
{
- size_t offset = section_add(S, sec, size, 1);
+ size_t offset = section_add(sec, size, 1);
return sec->data + offset;
}
#ifndef ELF_OBJ_ONLY
/* reserve at least 'size' bytes from section start */
-static void section_reserve(TCCState* S, Section *sec, unsigned long size)
+static void section_reserve(Section *sec, unsigned long size)
{
if (size > sec->data_allocated)
- section_realloc(S, sec, size);
+ section_realloc(sec, size);
if (size > sec->data_offset)
sec->data_offset = size;
}
#endif
-static Section *find_section_create (TCCState *S, const char *name, int create)
+static Section *find_section_create (TCCState *s1, const char *name, int create)
{
Section *sec;
int i;
- for(i = 1; i < S->nb_sections; i++) {
- sec = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ sec = s1->sections[i];
if (!strcmp(name, sec->name))
return sec;
}
/* sections are created as PROGBITS */
- return create ? new_section(S, name, SHT_PROGBITS, SHF_ALLOC) : NULL;
+ return create ? new_section(s1, name, SHT_PROGBITS, SHF_ALLOC) : NULL;
}
/* return a reference to a section, and create it if it does not
exists */
-ST_FUNC Section *find_section(TCCState *S, const char *name)
+ST_FUNC Section *find_section(TCCState *s1, const char *name)
{
- return find_section_create (S, name, 1);
+ return find_section_create (s1, name, 1);
}
/* ------------------------------------------------------------------------- */
-ST_FUNC int put_elf_str(TCCState* S, Section *s, const char *sym)
+ST_FUNC int put_elf_str(Section *s, const char *sym)
{
int offset, len;
char *ptr;
len = strlen(sym) + 1;
offset = s->data_offset;
- ptr = section_ptr_add(S, s, len);
+ ptr = section_ptr_add(s, len);
memmove(ptr, sym, len);
return offset;
}
@@ -386,7 +389,7 @@ static unsigned long elf_hash(const unsigned char *name)
/* rebuild hash table of section s */
/* NOTE: we do factorize the hash table code to go faster */
-static void rebuild_hash(TCCState* S, Section *s, unsigned int nb_buckets)
+static void rebuild_hash(Section *s, unsigned int nb_buckets)
{
ElfW(Sym) *sym;
int *ptr, *hash, nb_syms, sym_index, h;
@@ -399,7 +402,7 @@ static void rebuild_hash(TCCState* S, Section *s, unsigned int nb_buckets)
nb_buckets = ((int*)s->hash->data)[0];
s->hash->data_offset = 0;
- ptr = section_ptr_add(S, s->hash, (2 + nb_buckets + nb_syms) * sizeof(int));
+ ptr = section_ptr_add(s->hash, (2 + nb_buckets + nb_syms) * sizeof(int));
ptr[0] = nb_buckets;
ptr[1] = nb_syms;
ptr += 2;
@@ -422,7 +425,7 @@ static void rebuild_hash(TCCState* S, Section *s, unsigned int nb_buckets)
}
/* return the symbol number */
-ST_FUNC int put_elf_sym(TCCState* S, Section *s, addr_t value, unsigned long size,
+ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size,
int info, int other, int shndx, const char *name)
{
int name_offset, sym_index;
@@ -430,9 +433,9 @@ ST_FUNC int put_elf_sym(TCCState* S, Section *s, addr_t value, unsigned long siz
ElfW(Sym) *sym;
Section *hs;
- sym = section_ptr_add(S, s, sizeof(ElfW(Sym)));
+ sym = section_ptr_add(s, sizeof(ElfW(Sym)));
if (name && name[0])
- name_offset = put_elf_str(S, s->link, name);
+ name_offset = put_elf_str(s->link, name);
else
name_offset = 0;
/* XXX: endianness */
@@ -446,7 +449,7 @@ ST_FUNC int put_elf_sym(TCCState* S, Section *s, addr_t value, unsigned long siz
hs = s->hash;
if (hs) {
int *ptr, *base;
- ptr = section_ptr_add(S, hs, sizeof(int));
+ ptr = section_ptr_add(hs, sizeof(int));
base = (int *)hs->data;
/* only add global or weak symbols. */
if (ELFW(ST_BIND)(info) != STB_LOCAL) {
@@ -459,7 +462,7 @@ ST_FUNC int put_elf_sym(TCCState* S, Section *s, addr_t value, unsigned long siz
/* we resize the hash table */
hs->nb_hashed_syms++;
if (hs->nb_hashed_syms > 2 * nbuckets) {
- rebuild_hash(S, s, 2 * nbuckets);
+ rebuild_hash(s, 2 * nbuckets);
}
} else {
*ptr = 0;
@@ -494,12 +497,12 @@ ST_FUNC int find_elf_sym(Section *s, const char *name)
/* return elf symbol value, signal error if 'err' is nonzero, decorate
name if FORC */
-ST_FUNC addr_t get_sym_addr(TCCState *S, const char *name, int err, int forc)
+ST_FUNC addr_t get_sym_addr(TCCState *s1, const char *name, int err, int forc)
{
int sym_index;
ElfW(Sym) *sym;
char buf[256];
- if (forc && S->leading_underscore
+ if (forc && s1->leading_underscore
#ifdef TCC_TARGET_PE
/* win32-32bit stdcall symbols always have _ already */
&& !strchr(name, '@')
@@ -509,25 +512,25 @@ ST_FUNC addr_t get_sym_addr(TCCState *S, const char *name, int err, int forc)
pstrcpy(buf + 1, sizeof(buf) - 1, name);
name = buf;
}
- sym_index = find_elf_sym(S->symtab, name);
- sym = &((ElfW(Sym) *)S->symtab->data)[sym_index];
+ sym_index = find_elf_sym(s1->symtab, name);
+ sym = &((ElfW(Sym) *)s1->symtab->data)[sym_index];
if (!sym_index || sym->st_shndx == SHN_UNDEF) {
if (err)
- tcc_error(S, "%s not defined", name);
+ tcc_error("%s not defined", name);
return (addr_t)-1;
}
return sym->st_value;
}
/* return elf symbol value */
-LIBTCCAPI void *tcc_get_symbol(TCCState *S, const char *name)
+LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name)
{
- addr_t addr = get_sym_addr(S, name, 0, 1);
+ addr_t addr = get_sym_addr(s, name, 0, 1);
return addr == -1 ? NULL : (void*)(uintptr_t)addr;
}
/* list elf symbol names and values */
-ST_FUNC void list_elf_symbols(TCCState *S, void *ctx,
+ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
void (*symbol_cb)(void *ctx, const char *name, const void *val))
{
ElfW(Sym) *sym;
@@ -536,7 +539,7 @@ ST_FUNC void list_elf_symbols(TCCState *S, void *ctx,
const char *name;
unsigned char sym_vis, sym_bind;
- symtab = S->symtab;
+ symtab = s->symtab;
end_sym = symtab->data_offset / sizeof (ElfSym);
for (sym_index = 0; sym_index < end_sym; ++sym_index) {
sym = &((ElfW(Sym) *)symtab->data)[sym_index];
@@ -551,15 +554,15 @@ ST_FUNC void list_elf_symbols(TCCState *S, void *ctx,
}
/* list elf symbol names and values */
-LIBTCCAPI void tcc_list_symbols(TCCState *S, void *ctx,
+LIBTCCAPI void tcc_list_symbols(TCCState *s, void *ctx,
void (*symbol_cb)(void *ctx, const char *name, const void *val))
{
- list_elf_symbols(S, ctx, symbol_cb);
+ list_elf_symbols(s, ctx, symbol_cb);
}
#ifndef ELF_OBJ_ONLY
static void
-version_add (TCCState *S)
+version_add (TCCState *s1)
{
int i;
ElfW(Sym) *sym;
@@ -571,19 +574,19 @@ version_add (TCCState *S)
if (0 == nb_sym_versions)
return;
- versym_section = new_section(S, ".gnu.version", SHT_GNU_versym, SHF_ALLOC);
+ versym_section = new_section(s1, ".gnu.version", SHT_GNU_versym, SHF_ALLOC);
versym_section->sh_entsize = sizeof(ElfW(Half));
- versym_section->link = S->dynsym;
+ versym_section->link = s1->dynsym;
/* add needed symbols */
- symtab = S->dynsym;
+ symtab = s1->dynsym;
end_sym = symtab->data_offset / sizeof (ElfSym);
- versym = section_ptr_add(S, versym_section, end_sym * sizeof(ElfW(Half)));
+ versym = section_ptr_add(versym_section, end_sym * sizeof(ElfW(Half)));
for (sym_index = 0; sym_index < end_sym; ++sym_index) {
int dllindex, verndx;
sym = &((ElfW(Sym) *)symtab->data)[sym_index];
name = (char *) symtab->link->data + sym->st_name;
- dllindex = find_elf_sym(S->dynsymtab_section, name);
+ dllindex = find_elf_sym(s1->dynsymtab_section, name);
verndx = (dllindex && dllindex < nb_sym_to_version)
? sym_to_version[dllindex] : -1;
if (verndx >= 0) {
@@ -597,9 +600,9 @@ version_add (TCCState *S)
dynamic linkers look at their contents even when DTVERNEEDNUM and
section size is zero. */
if (nb_versions > 2) {
- verneed_section = new_section(S, ".gnu.version_r",
+ verneed_section = new_section(s1, ".gnu.version_r",
SHT_GNU_verneed, SHF_ALLOC);
- verneed_section->link = S->dynsym->link;
+ verneed_section->link = s1->dynsym->link;
for (i = nb_sym_versions; i-- > 0;) {
struct sym_version *sv = &sym_versions[i];
int n_same_libs = 0, prev;
@@ -607,20 +610,20 @@ version_add (TCCState *S)
ElfW(Vernaux) *vna = 0;
if (sv->out_index < 1)
continue;
- vnofs = section_add(S, verneed_section, sizeof(*vn), 1);
+ vnofs = section_add(verneed_section, sizeof(*vn), 1);
vn = (ElfW(Verneed)*)(verneed_section->data + vnofs);
vn->vn_version = 1;
- vn->vn_file = put_elf_str(S, verneed_section->link, sv->lib);
+ vn->vn_file = put_elf_str(verneed_section->link, sv->lib);
vn->vn_aux = sizeof (*vn);
do {
prev = sv->prev_same_lib;
if (sv->out_index > 0) {
- vna = section_ptr_add(S, verneed_section, sizeof(*vna));
+ vna = section_ptr_add(verneed_section, sizeof(*vna));
vna->vna_hash = elf_hash ((const unsigned char *)sv->version);
vna->vna_flags = 0;
vna->vna_other = sv->out_index;
sv->out_index = -2;
- vna->vna_name = put_elf_str(S, verneed_section->link, sv->version);
+ vna->vna_name = put_elf_str(verneed_section->link, sv->version);
vna->vna_next = sizeof (*vna);
n_same_libs++;
}
@@ -646,7 +649,7 @@ version_add (TCCState *S)
ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
int info, int other, int shndx, const char *name)
{
- TCCState *S = s->S;
+ TCCState *s1 = s->s1;
ElfW(Sym) *esym;
int sym_bind, sym_index, sym_type, esym_bind;
unsigned char sym_vis, esym_vis, new_vis;
@@ -710,20 +713,20 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis);
#endif
- tcc_error_noabort(S, "'%s' defined twice", name);
+ tcc_error_noabort("'%s' defined twice", name);
}
} else {
do_patch:
esym->st_info = ELFW(ST_INFO)(sym_bind, sym_type);
esym->st_shndx = shndx;
- S->new_undef_sym = 1;
+ s1->new_undef_sym = 1;
esym->st_value = value;
esym->st_size = size;
esym->st_other = other;
}
} else {
do_def:
- sym_index = put_elf_sym(S, s, value, size,
+ sym_index = put_elf_sym(s, value, size,
ELFW(ST_INFO)(sym_bind, sym_type), other,
shndx, name);
}
@@ -734,7 +737,7 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset,
int type, int symbol, addr_t addend)
{
- TCCState *S = s->S;
+ TCCState *s1 = s->s1;
char buf[256];
Section *sr;
ElfW_Rel *rel;
@@ -745,20 +748,20 @@ ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset,
snprintf(buf, sizeof(buf), REL_SECTION_FMT, s->name);
/* if the symtab is allocated, then we consider the relocation
are also */
- sr = new_section(s->S, buf, SHT_RELX, symtab->sh_flags);
+ sr = new_section(s->s1, buf, SHT_RELX, symtab->sh_flags);
sr->sh_entsize = sizeof(ElfW_Rel);
sr->link = symtab;
sr->sh_info = s->sh_num;
s->reloc = sr;
}
- rel = section_ptr_add(S, sr, sizeof(ElfW_Rel));
+ rel = section_ptr_add(sr, sizeof(ElfW_Rel));
rel->r_offset = offset;
rel->r_info = ELFW(R_INFO)(symbol, type);
#if SHT_RELX == SHT_RELA
rel->r_addend = addend;
#endif
if (SHT_RELX != SHT_RELA && addend)
- tcc_error(S, "non-zero addend on REL architecture");
+ tcc_error("non-zero addend on REL architecture");
}
ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
@@ -768,7 +771,7 @@ ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset,
}
/* put stab debug information */
-ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int desc,
+ST_FUNC void put_stabs(TCCState *s1, const char *str, int type, int other, int desc,
unsigned long value)
{
Stab_Sym *sym;
@@ -784,9 +787,9 @@ ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int de
return;
}
- sym = section_ptr_add(S, stab_section, sizeof(Stab_Sym));
+ sym = section_ptr_add(stab_section, sizeof(Stab_Sym));
if (str) {
- sym->n_strx = put_elf_str(S, stab_section->link, str);
+ sym->n_strx = put_elf_str(stab_section->link, str);
} else {
sym->n_strx = 0;
}
@@ -796,47 +799,47 @@ ST_FUNC void put_stabs(TCCState *S, const char *str, int type, int other, int de
sym->n_value = value;
}
-ST_FUNC void put_stabs_r(TCCState *S, const char *str, int type, int other, int desc,
+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)
{
put_elf_reloc(symtab_section, stab_section,
stab_section->data_offset + 8,
sizeof ((Stab_Sym*)0)->n_value == PTR_SIZE ? R_DATA_PTR : R_DATA_32,
sym_index);
- put_stabs(S, str, type, other, desc, value);
+ put_stabs(s1, str, type, other, desc, value);
}
-ST_FUNC void put_stabn(TCCState *S, int type, int other, int desc, int value)
+ST_FUNC void put_stabn(TCCState *s1, int type, int other, int desc, int value)
{
- put_stabs(S, NULL, type, other, desc, value);
+ put_stabs(s1, NULL, type, other, desc, value);
}
-ST_FUNC struct sym_attr *get_sym_attr(TCCState *S, int index, int alloc)
+ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc)
{
int n;
struct sym_attr *tab;
- if (index >= S->nb_sym_attrs) {
+ if (index >= s1->nb_sym_attrs) {
if (!alloc)
- return S->sym_attrs;
+ return s1->sym_attrs;
/* find immediately bigger power of 2 and reallocate array */
n = 1;
while (index >= n)
n *= 2;
- tab = tcc_realloc(S, S->sym_attrs, n * sizeof(*S->sym_attrs));
- S->sym_attrs = tab;
- memset(S->sym_attrs + S->nb_sym_attrs, 0,
- (n - S->nb_sym_attrs) * sizeof(*S->sym_attrs));
- S->nb_sym_attrs = n;
+ tab = tcc_realloc(s1->sym_attrs, n * sizeof(*s1->sym_attrs));
+ s1->sym_attrs = tab;
+ memset(s1->sym_attrs + s1->nb_sym_attrs, 0,
+ (n - s1->nb_sym_attrs) * sizeof(*s1->sym_attrs));
+ s1->nb_sym_attrs = n;
}
- return &S->sym_attrs[index];
+ return &s1->sym_attrs[index];
}
/* In an ELF file symbol table, the local symbols must appear below
the global and weak ones. Since TCC cannot sort it while generating
the code, we must do it after. All the relocation tables are also
modified to take into account the symbol table sorting */
-static void sort_syms(TCCState *S, Section *s)
+static void sort_syms(TCCState *s1, Section *s)
{
int *old_to_new_syms;
ElfW(Sym) *new_syms;
@@ -847,8 +850,8 @@ static void sort_syms(TCCState *S, Section *s)
int type, sym_index;
nb_syms = s->data_offset / sizeof(ElfW(Sym));
- new_syms = tcc_malloc(S, nb_syms * sizeof(ElfW(Sym)));
- old_to_new_syms = tcc_malloc(S, nb_syms * sizeof(int));
+ new_syms = tcc_malloc(nb_syms * sizeof(ElfW(Sym)));
+ old_to_new_syms = tcc_malloc(nb_syms * sizeof(int));
/* first pass for local symbols */
p = (ElfW(Sym) *)s->data;
@@ -876,11 +879,11 @@ static void sort_syms(TCCState *S, Section *s)
/* we copy the new symbols to the old */
memcpy(s->data, new_syms, nb_syms * sizeof(ElfW(Sym)));
- tcc_free(S, new_syms);
+ tcc_free(new_syms);
/* now we modify all the relocations */
- for(i = 1; i < S->nb_sections; i++) {
- sr = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ sr = s1->sections[i];
if (sr->sh_type == SHT_RELX && sr->link == s) {
for_each_elem(sr, 0, rel, ElfW_Rel) {
sym_index = ELFW(R_SYM)(rel->r_info);
@@ -891,12 +894,12 @@ static void sort_syms(TCCState *S, Section *s)
}
}
- tcc_free(S, old_to_new_syms);
+ tcc_free(old_to_new_syms);
}
/* relocate symbol table, resolve undefined symbols if do_resolve is
true and output error if undefined symbol. */
-ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve)
+ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve)
{
ElfW(Sym) *sym;
int sym_bind, sh_num;
@@ -905,17 +908,17 @@ ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve)
for_each_elem(symtab, 1, sym, ElfW(Sym)) {
sh_num = sym->st_shndx;
if (sh_num == SHN_UNDEF) {
- name = (char *) S->symtab->link->data + sym->st_name;
+ name = (char *) s1->symtab->link->data + sym->st_name;
/* Use ld.so to resolve symbol for us (for tcc -run) */
if (do_resolve) {
#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE
/* dlsym() needs the undecorated name. */
- void *addr = dlsym(RTLD_DEFAULT, &name[S->leading_underscore]);
+ void *addr = dlsym(RTLD_DEFAULT, &name[s1->leading_underscore]);
#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
if (addr == NULL) {
int i;
- for (i = 0; i < S->nb_loaded_dlls; i++)
- if ((addr = dlsym(S->loaded_dlls[i]->handle, name)))
+ for (i = 0; i < s1->nb_loaded_dlls; i++)
+ if ((addr = dlsym(s1->loaded_dlls[i]->handle, name)))
break;
}
#endif
@@ -928,7 +931,7 @@ ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve)
}
#endif
/* if dynamic symbol exist, it will be used in relocate_section */
- } else if (S->dynsym && find_elf_sym(S->dynsym, name))
+ } else if (s1->dynsym && find_elf_sym(s1->dynsym, name))
goto found;
/* XXX: _fp_hw seems to be part of the ABI, so we ignore
it */
@@ -940,10 +943,10 @@ ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve)
if (sym_bind == STB_WEAK)
sym->st_value = 0;
else
- tcc_error_noabort(S, "undefined symbol '%s'", name);
+ tcc_error_noabort("undefined symbol '%s'", name);
} else if (sh_num < SHN_LORESERVE) {
/* add section base */
- sym->st_value += S->sections[sym->st_shndx]->sh_addr;
+ sym->st_value += s1->sections[sym->st_shndx]->sh_addr;
}
found: ;
}
@@ -951,7 +954,7 @@ ST_FUNC void relocate_syms(TCCState *S, Section *symtab, int do_resolve)
/* relocate a given section (CPU dependent) by applying the relocations
in the associated relocation section */
-static void relocate_section(TCCState *S, Section *s, Section *sr)
+static void relocate_section(TCCState *s1, Section *s, Section *sr)
{
ElfW_Rel *rel;
ElfW(Sym) *sym;
@@ -970,13 +973,13 @@ static void relocate_section(TCCState *S, Section *s, Section *sr)
tgt += rel->r_addend;
#endif
addr = s->sh_addr + rel->r_offset;
- relocate(S, rel, type, ptr, addr, tgt);
+ relocate(s1, rel, type, ptr, addr, tgt);
}
#ifndef ELF_OBJ_ONLY
/* if the relocation is allocated, we change its symbol table */
if (sr->sh_flags & SHF_ALLOC) {
- sr->link = S->dynsym;
- if (S->output_type == TCC_OUTPUT_DLL) {
+ sr->link = s1->dynsym;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
size_t r = (uint8_t*)qrel - sr->data;
if (sizeof ((Stab_Sym*)0)->n_value < PTR_SIZE
&& 0 == strcmp(s->name, ".stab"))
@@ -988,23 +991,23 @@ static void relocate_section(TCCState *S, Section *s, Section *sr)
}
/* relocate all sections */
-ST_FUNC void relocate_sections(TCCState *S)
+ST_FUNC void relocate_sections(TCCState *s1)
{
int i;
Section *s, *sr;
- for (i = 1; i < S->nb_sections; ++i) {
- sr = S->sections[i];
+ for (i = 1; i < s1->nb_sections; ++i) {
+ sr = s1->sections[i];
if (sr->sh_type != SHT_RELX)
continue;
- s = S->sections[sr->sh_info];
+ s = s1->sections[sr->sh_info];
#ifndef TCC_TARGET_MACHO
- if (s != S->got
- || S->static_link
- || S->output_type == TCC_OUTPUT_MEMORY)
+ if (s != s1->got
+ || s1->static_link
+ || s1->output_type == TCC_OUTPUT_MEMORY)
#endif
{
- relocate_section(S, s, sr);
+ relocate_section(s1, s, sr);
}
#ifndef ELF_OBJ_ONLY
if (sr->sh_flags & SHF_ALLOC) {
@@ -1020,7 +1023,7 @@ ST_FUNC void relocate_sections(TCCState *S)
#ifndef ELF_OBJ_ONLY
/* count the number of dynamic relocations so that we can reserve
their space */
-static int prepare_dynamic_rel(TCCState *S, Section *sr)
+static int prepare_dynamic_rel(TCCState *s1, Section *sr)
{
int count = 0;
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) || \
@@ -1033,7 +1036,7 @@ static int prepare_dynamic_rel(TCCState *S, Section *sr)
switch(type) {
#if defined(TCC_TARGET_I386)
case R_386_32:
- if (!get_sym_attr(S, sym_index, 0)->dyn_index
+ if (!get_sym_attr(s1, sym_index, 0)->dyn_index
&& ((ElfW(Sym)*)symtab_section->data + sym_index)->st_shndx == SHN_UNDEF) {
/* don't fixup unresolved (weak) symbols */
rel->r_info = ELFW(R_INFO)(sym_index, R_386_RELATIVE);
@@ -1074,7 +1077,7 @@ static int prepare_dynamic_rel(TCCState *S, Section *sr)
#elif defined(TCC_TARGET_ARM64)
case R_AARCH64_PREL32:
#endif
- if (get_sym_attr(S, sym_index, 0)->dyn_index)
+ if (get_sym_attr(s1, sym_index, 0)->dyn_index)
count++;
break;
default:
@@ -1087,22 +1090,22 @@ static int prepare_dynamic_rel(TCCState *S, Section *sr)
#endif
#if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE)
-static void build_got(TCCState *S)
+static void build_got(TCCState *s1)
{
/* if no got, then create it */
- S->got = new_section(S, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
- S->got->sh_entsize = 4;
+ s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ s1->got->sh_entsize = 4;
set_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
- 0, S->got->sh_num, "_GLOBAL_OFFSET_TABLE_");
+ 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_");
/* keep space for _DYNAMIC pointer and two dummy got entries */
- section_ptr_add(S, S->got, 3 * PTR_SIZE);
+ section_ptr_add(s1->got, 3 * PTR_SIZE);
}
/* Create a GOT and (for function call) a PLT entry corresponding to a symbol
- in S->symtab. When creating the dynamic symbol table entry for the GOT
+ in s1->symtab. When creating the dynamic symbol table entry for the GOT
relocation, use 'size' and 'info' for the corresponding symbol metadata.
Returns the offset of the GOT or (if any) PLT entry. */
-static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
+static struct sym_attr * put_got_entry(TCCState *s1, int dyn_reloc_type,
int sym_index)
{
int need_plt_entry;
@@ -1115,7 +1118,7 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
Section *s_rel;
need_plt_entry = (dyn_reloc_type == R_JMP_SLOT);
- attr = get_sym_attr(S, sym_index, 1);
+ attr = get_sym_attr(s1, sym_index, 1);
/* In case a function is both called and its address taken 2 GOT entries
are created, one for taking the address (GOT) and the other for the PLT
@@ -1123,18 +1126,18 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
if (need_plt_entry ? attr->plt_offset : attr->got_offset)
return attr;
- s_rel = S->got;
+ s_rel = s1->got;
if (need_plt_entry) {
- if (!S->plt) {
- S->plt = new_section(S, ".plt", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
- S->plt->sh_entsize = 4;
+ if (!s1->plt) {
+ s1->plt = new_section(s1, ".plt", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
+ s1->plt->sh_entsize = 4;
}
- s_rel = S->plt;
+ s_rel = s1->plt;
}
/* create the GOT entry */
- got_offset = S->got->data_offset;
- section_ptr_add(S, S->got, PTR_SIZE);
+ got_offset = s1->got->data_offset;
+ section_ptr_add(s1->got, PTR_SIZE);
/* Create the GOT relocation that will insert the address of the object or
function of interest in the GOT entry. This is a static relocation for
@@ -1148,7 +1151,7 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
name = (char *) symtab_section->link->data + sym->st_name;
//printf("sym %d %s\n", need_plt_entry, name);
- if (S->dynsym) {
+ if (s1->dynsym) {
if (ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) {
/* Hack alarm. We don't want to emit dynamic symbols
and symbol based relocs for STB_LOCAL symbols, but rather
@@ -1157,30 +1160,30 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
have to create a RELATIVE reloc anyway, so we misuse the
relocation slot to smuggle the symbol reference until
fill_local_got_entries. Not that the sym_index is
- relative to symtab_section, not S->dynsym! Nevertheless
- we use S->dyn_sym so that if this is the first call
+ relative to symtab_section, not s1->dynsym! Nevertheless
+ we use s1->dyn_sym so that if this is the first call
that got->reloc is correctly created. Also note that
RELATIVE relocs are not normally created for the .got,
so the types serves as a marker for later (and is retained
also for the final output, which is okay because then the
got is just normal data). */
- put_elf_reloc(S->dynsym, S->got, got_offset, R_RELATIVE,
+ put_elf_reloc(s1->dynsym, s1->got, got_offset, R_RELATIVE,
sym_index);
} else {
if (0 == attr->dyn_index)
- attr->dyn_index = set_elf_sym(S->dynsym, sym->st_value,
+ attr->dyn_index = set_elf_sym(s1->dynsym, sym->st_value,
sym->st_size, sym->st_info, 0,
sym->st_shndx, name);
- put_elf_reloc(S->dynsym, s_rel, got_offset, dyn_reloc_type,
+ put_elf_reloc(s1->dynsym, s_rel, got_offset, dyn_reloc_type,
attr->dyn_index);
}
} else {
- put_elf_reloc(symtab_section, S->got, got_offset, dyn_reloc_type,
+ put_elf_reloc(symtab_section, s1->got, got_offset, dyn_reloc_type,
sym_index);
}
if (need_plt_entry) {
- attr->plt_offset = create_plt_entry(S, got_offset, attr);
+ attr->plt_offset = create_plt_entry(s1, got_offset, attr);
/* create a symbol 'sym@plt' for the PLT jump vector */
len = strlen(name);
@@ -1188,8 +1191,8 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
len = sizeof plt_name - 5;
memcpy(plt_name, name, len);
strcpy(plt_name + len, "@plt");
- attr->plt_sym = put_elf_sym(S, S->symtab, attr->plt_offset, sym->st_size,
- ELFW(ST_INFO)(STB_GLOBAL, STT_FUNC), 0, S->plt->sh_num, plt_name);
+ attr->plt_sym = put_elf_sym(s1->symtab, attr->plt_offset, sym->st_size,
+ ELFW(ST_INFO)(STB_GLOBAL, STT_FUNC), 0, s1->plt->sh_num, plt_name);
} else {
attr->got_offset = got_offset;
}
@@ -1200,7 +1203,7 @@ static struct sym_attr * put_got_entry(TCCState *S, int dyn_reloc_type,
/* build GOT and PLT entries */
/* Two passes because R_JMP_SLOT should become first. Some targets
(arm, arm64) do not allow mixing R_JMP_SLOT and R_GLOB_DAT. */
-ST_FUNC void build_got_entries(TCCState *S)
+ST_FUNC void build_got_entries(TCCState *s1)
{
Section *s;
ElfW_Rel *rel;
@@ -1210,8 +1213,8 @@ ST_FUNC void build_got_entries(TCCState *S)
int pass = 0;
redo:
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (s->sh_type != SHT_RELX)
continue;
/* no need to handle got relocations */
@@ -1221,7 +1224,7 @@ redo:
type = ELFW(R_TYPE)(rel->r_info);
gotplt_entry = gotplt_entry_type(type);
if (gotplt_entry == -1)
- tcc_error(S, "Unknown relocation type for got: %d", type);
+ tcc_error ("Unknown relocation type for got: %d", type);
sym_index = ELFW(R_SYM)(rel->r_info);
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
@@ -1237,7 +1240,7 @@ redo:
if (sym->st_shndx == SHN_UNDEF) {
ElfW(Sym) *esym;
int dynindex;
- if (S->output_type == TCC_OUTPUT_DLL && ! PCRELATIVE_DLLPLT)
+ if (s1->output_type == TCC_OUTPUT_DLL && ! PCRELATIVE_DLLPLT)
continue;
/* Relocations for UNDEF symbols would normally need
to be transferred into the executable or shared object.
@@ -1249,10 +1252,10 @@ redo:
bind_exe_dynsyms (and the symbol adjusted to be defined),
and for functions we were generated a dynamic symbol
of function type. */
- if (S->dynsym) {
+ if (s1->dynsym) {
/* dynsym isn't set for -run :-/ */
- dynindex = get_sym_attr(S, sym_index, 0)->dyn_index;
- esym = (ElfW(Sym) *)S->dynsym->data + dynindex;
+ dynindex = get_sym_attr(s1, sym_index, 0)->dyn_index;
+ esym = (ElfW(Sym) *)s1->dynsym->data + dynindex;
if (dynindex
&& (ELFW(ST_TYPE)(esym->st_info) == STT_FUNC
|| (ELFW(ST_TYPE)(esym->st_info) == STT_NOTYPE
@@ -1277,7 +1280,7 @@ redo:
sym->st_shndx != SHN_UNDEF &&
(ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT ||
ELFW(ST_BIND)(sym->st_info) == STB_LOCAL ||
- S->output_type == TCC_OUTPUT_EXE)) {
+ s1->output_type == TCC_OUTPUT_EXE)) {
if (pass != 0)
continue;
rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32);
@@ -1286,7 +1289,7 @@ redo:
#endif
reloc_type = code_reloc(type);
if (reloc_type == -1)
- tcc_error(S, "Unknown relocation type: %d", type);
+ tcc_error ("Unknown relocation type: %d", type);
if (reloc_type != 0) {
jmp_slot:
@@ -1299,13 +1302,13 @@ redo:
reloc_type = R_GLOB_DAT;
}
- if (!S->got)
- build_got(S);
+ if (!s1->got)
+ build_got(s1);
if (gotplt_entry == BUILD_GOT_ONLY)
continue;
- attr = put_got_entry(S, reloc_type, sym_index);
+ attr = put_got_entry(s1, reloc_type, sym_index);
if (reloc_type == R_JMP_SLOT)
rel->r_info = ELFW(R_INFO)(attr->plt_sym, type);
@@ -1315,13 +1318,13 @@ redo:
goto redo;
/* .rel.plt refers to .got actually */
- if (S->plt && S->plt->reloc)
- S->plt->reloc->sh_info = S->got->sh_num;
+ if (s1->plt && s1->plt->reloc)
+ s1->plt->reloc->sh_info = s1->got->sh_num;
}
#endif
-ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t offs)
+ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs)
{
int shn = sec ? sec->sh_num : offs || !name ? SHN_ABS : SHN_UNDEF;
if (sec && offs == -1)
@@ -1330,12 +1333,12 @@ ST_FUNC int set_global_sym(TCCState *S, const char *name, Section *sec, addr_t o
ELFW(ST_INFO)(name ? STB_GLOBAL : STB_LOCAL, STT_NOTYPE), 0, shn, name);
}
-static void add_init_array_defines(TCCState *S, const char *section_name)
+static void add_init_array_defines(TCCState *s1, const char *section_name)
{
Section *s;
addr_t end_offset;
char buf[1024];
- s = find_section_create(S, section_name, 0);
+ s = find_section_create(s1, section_name, 0);
if (!s) {
end_offset = 0;
s = data_section;
@@ -1343,48 +1346,48 @@ static void add_init_array_defines(TCCState *S, const char *section_name)
end_offset = s->data_offset;
}
snprintf(buf, sizeof(buf), "__%s_start", section_name + 1);
- set_global_sym(S, buf, s, 0);
+ set_global_sym(s1, buf, s, 0);
snprintf(buf, sizeof(buf), "__%s_end", section_name + 1);
- set_global_sym(S, buf, s, end_offset);
+ set_global_sym(s1, buf, s, end_offset);
}
#ifndef TCC_TARGET_PE
-static void tcc_add_support(TCCState *S, const char *filename)
+static void tcc_add_support(TCCState *s1, const char *filename)
{
char buf[1024];
- snprintf(buf, sizeof(buf), "%s/%s", S->tcc_lib_path, filename);
- tcc_add_file(S, buf);
+ snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename);
+ tcc_add_file(s1, buf);
}
#endif
-ST_FUNC void add_array (TCCState *S, const char *sec, int c)
+ST_FUNC void add_array (TCCState *s1, const char *sec, int c)
{
Section *s;
- s = find_section(S, sec);
+ s = find_section(s1, sec);
s->sh_flags |= SHF_WRITE;
#ifndef TCC_TARGET_PE
s->sh_type = sec[1] == 'i' ? SHT_INIT_ARRAY : SHT_FINI_ARRAY;
#endif
- put_elf_reloc (S->symtab, s, s->data_offset, R_DATA_PTR, c);
- section_ptr_add(S, s, PTR_SIZE);
+ put_elf_reloc (s1->symtab, s, s->data_offset, R_DATA_PTR, c);
+ section_ptr_add(s, PTR_SIZE);
}
#ifdef CONFIG_TCC_BCHECK
-ST_FUNC void tcc_add_bcheck(TCCState *S)
+ST_FUNC void tcc_add_bcheck(TCCState *s1)
{
- if (0 == S->do_bounds_check)
+ if (0 == s1->do_bounds_check)
return;
- section_ptr_add(S, bounds_section, sizeof(addr_t));
+ section_ptr_add(bounds_section, sizeof(addr_t));
}
#endif
/* set symbol to STB_LOCAL and resolve. The point is to not export it as
a dynamic symbol to allow so's to have one each with a different value. */
-static void set_local_sym(TCCState *S, const char *name, Section *s, int offset)
+static void set_local_sym(TCCState *s1, const char *name, Section *s, int offset)
{
- int c = find_elf_sym(S->symtab, name);
+ int c = find_elf_sym(s1->symtab, name);
if (c) {
- ElfW(Sym) *esym = (ElfW(Sym)*)S->symtab->data + c;
+ ElfW(Sym) *esym = (ElfW(Sym)*)s1->symtab->data + c;
esym->st_info = ELFW(ST_INFO)(STB_LOCAL, STT_NOTYPE);
esym->st_value = offset;
esym->st_shndx = s->sh_num;
@@ -1392,16 +1395,16 @@ static void set_local_sym(TCCState *S, const char *name, Section *s, int offset)
}
#ifdef CONFIG_TCC_BACKTRACE
-static void put_ptr(TCCState *S, Section *s, int offs)
+static void put_ptr(TCCState *s1, Section *s, int offs)
{
int c;
- c = set_global_sym(S, NULL, s, offs);
+ c = set_global_sym(s1, NULL, s, offs);
s = data_section;
- put_elf_reloc (S->symtab, s, s->data_offset, R_DATA_PTR, c);
- section_ptr_add(S, s, PTR_SIZE);
+ put_elf_reloc (s1->symtab, s, s->data_offset, R_DATA_PTR, c);
+ section_ptr_add(s, PTR_SIZE);
}
-ST_FUNC void tcc_add_btstub(TCCState *S)
+ST_FUNC void tcc_add_btstub(TCCState *s1)
{
Section *s;
int n, o;
@@ -1409,45 +1412,45 @@ ST_FUNC void tcc_add_btstub(TCCState *S)
s = data_section;
/* Align to PTR_SIZE */
- section_ptr_add(S, s, -s->data_offset & (PTR_SIZE - 1));
+ section_ptr_add(s, -s->data_offset & (PTR_SIZE - 1));
o = s->data_offset;
/* create (part of) a struct rt_context (see tccrun.c) */
- put_ptr(S, stab_section, 0);
- put_ptr(S, stab_section, -1);
- put_ptr(S, stab_section->link, 0);
- section_ptr_add(S, s, 3 * PTR_SIZE);
+ put_ptr(s1, stab_section, 0);
+ put_ptr(s1, stab_section, -1);
+ put_ptr(s1, stab_section->link, 0);
+ section_ptr_add(s, 3 * PTR_SIZE);
/* prog_base : local nameless symbol with offset 0 at SHN_ABS */
- put_ptr(S, NULL, 0);
+ put_ptr(s1, NULL, 0);
n = 2 * PTR_SIZE;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check) {
- put_ptr(S, bounds_section, 0);
+ if (s1->do_bounds_check) {
+ put_ptr(s1, bounds_section, 0);
n -= PTR_SIZE;
}
#endif
- section_ptr_add(S, s, n);
- cstr_new(S, &cstr);
- cstr_printf(S, &cstr,
+ section_ptr_add(s, n);
+ cstr_new(&cstr);
+ cstr_printf(&cstr,
"extern void __bt_init(),__bt_init_dll();"
"static void *__rt_info[];"
"__attribute__((constructor)) static void __bt_init_rt(){");
#ifdef TCC_TARGET_PE
- if (S->output_type == TCC_OUTPUT_DLL)
+ if (s1->output_type == TCC_OUTPUT_DLL)
#ifdef CONFIG_TCC_BCHECK
- cstr_printf(S, &cstr, "__bt_init_dll(%d);", S->do_bounds_check);
+ cstr_printf(&cstr, "__bt_init_dll(%d);", s1->do_bounds_check);
#else
- cstr_printf(S, &cstr, "__bt_init_dll(0);");
+ cstr_printf(&cstr, "__bt_init_dll(0);");
#endif
#endif
- cstr_printf(S, &cstr, "__bt_init(__rt_info,%d);}",
- S->output_type == TCC_OUTPUT_DLL ? 0 : S->rt_num_callers + 1);
- tcc_compile_string(S, cstr.data);
- cstr_free(S, &cstr);
- set_local_sym(S, &"___rt_info"[!S->leading_underscore], s, o);
+ cstr_printf(&cstr, "__bt_init(__rt_info,%d);}",
+ s1->output_type == TCC_OUTPUT_DLL ? 0 : s1->rt_num_callers + 1);
+ tcc_compile_string(s1, cstr.data);
+ cstr_free(&cstr);
+ set_local_sym(s1, &"___rt_info"[!s1->leading_underscore], s, o);
}
#endif
-static void tcc_tcov_add_file(TCCState *S, const char *filename)
+static void tcc_tcov_add_file(TCCState *s1, const char *filename)
{
CString cstr;
void *ptr;
@@ -1455,100 +1458,100 @@ static void tcc_tcov_add_file(TCCState *S, const char *filename)
if (tcov_section == NULL)
return;
- section_ptr_add(S, tcov_section, 1);
+ section_ptr_add(tcov_section, 1);
write32le (tcov_section->data, tcov_section->data_offset);
- cstr_new (S, &cstr);
+ cstr_new (&cstr);
if (filename[0] == '/')
- cstr_printf (S, &cstr, "%s.tcov", filename);
+ cstr_printf (&cstr, "%s.tcov", filename);
else {
getcwd (wd, sizeof(wd));
- cstr_printf (S, &cstr, "%s/%s.tcov", wd, filename);
+ cstr_printf (&cstr, "%s/%s.tcov", wd, filename);
}
- ptr = section_ptr_add(S, tcov_section, cstr.size + 1);
+ ptr = section_ptr_add(tcov_section, cstr.size + 1);
strcpy((char *)ptr, cstr.data);
unlink((char *)ptr);
#ifdef _WIN32
normalize_slashes((char *)ptr);
#endif
- cstr_free (S, &cstr);
+ cstr_free (&cstr);
- cstr_new(S, &cstr);
- cstr_printf(S, &cstr,
+ cstr_new(&cstr);
+ cstr_printf(&cstr,
"extern char *__tcov_data[];"
"extern void __store_test_coverage ();"
"__attribute__((destructor)) static void __tcov_exit() {"
"__store_test_coverage(__tcov_data);"
"}");
- tcc_compile_string(S, cstr.data);
- cstr_free(S, &cstr);
- set_local_sym(S, &"___tcov_data"[!S->leading_underscore], tcov_section, 0);
+ tcc_compile_string(s1, cstr.data);
+ cstr_free(&cstr);
+ set_local_sym(s1, &"___tcov_data"[!s1->leading_underscore], tcov_section, 0);
}
#ifndef TCC_TARGET_PE
/* add tcc runtime libraries */
-ST_FUNC void tcc_add_runtime(TCCState *S)
+ST_FUNC void tcc_add_runtime(TCCState *s1)
{
- S->filetype = 0;
+ s1->filetype = 0;
#ifdef CONFIG_TCC_BCHECK
- tcc_add_bcheck(S);
+ tcc_add_bcheck(s1);
#endif
- tcc_add_pragma_libs(S);
+ tcc_add_pragma_libs(s1);
/* add libc */
- if (!S->nostdlib) {
- if (S->option_pthread)
- tcc_add_library_err(S, "pthread");
- tcc_add_library_err(S, "c");
+ if (!s1->nostdlib) {
+ if (s1->option_pthread)
+ tcc_add_library_err(s1, "pthread");
+ tcc_add_library_err(s1, "c");
#ifdef TCC_LIBGCC
- if (!S->static_link) {
+ if (!s1->static_link) {
if (TCC_LIBGCC[0] == '/')
- tcc_add_file(S, TCC_LIBGCC);
+ tcc_add_file(s1, TCC_LIBGCC);
else
- tcc_add_dll(S, TCC_LIBGCC, 0);
+ tcc_add_dll(s1, TCC_LIBGCC, 0);
}
#endif
#if TCC_TARGET_ARM && TARGETOS_FreeBSD
- tcc_add_library_err(S, "gcc_s"); // unwind code
+ tcc_add_library_err(s1, "gcc_s"); // unwind code
#endif
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check && S->output_type != TCC_OUTPUT_DLL) {
- tcc_add_library_err(S, "pthread");
+ if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL) {
+ tcc_add_library_err(s1, "pthread");
#if !TARGETOS_OpenBSD && !TARGETOS_NetBSD
- tcc_add_library_err(S, "dl");
+ tcc_add_library_err(s1, "dl");
#endif
- tcc_add_support(S, "bcheck.o");
- if (S->static_link)
- tcc_add_library_err(S, "c");
+ tcc_add_support(s1, "bcheck.o");
+ if (s1->static_link)
+ tcc_add_library_err(s1, "c");
}
#endif
#ifdef CONFIG_TCC_BACKTRACE
- if (S->do_backtrace) {
- if (S->output_type == TCC_OUTPUT_EXE)
- tcc_add_support(S, "bt-exe.o");
- if (S->output_type != TCC_OUTPUT_DLL)
- tcc_add_support(S, "bt-log.o");
- if (S->output_type != TCC_OUTPUT_MEMORY)
- tcc_add_btstub(S);
+ if (s1->do_backtrace) {
+ if (s1->output_type == TCC_OUTPUT_EXE)
+ tcc_add_support(s1, "bt-exe.o");
+ if (s1->output_type != TCC_OUTPUT_DLL)
+ tcc_add_support(s1, "bt-log.o");
+ if (s1->output_type != TCC_OUTPUT_MEMORY)
+ tcc_add_btstub(s1);
}
#endif
if (TCC_LIBTCC1[0])
- tcc_add_support(S, TCC_LIBTCC1);
+ tcc_add_support(s1, TCC_LIBTCC1);
#if TARGETOS_OpenBSD || TARGETOS_FreeBSD || TARGETOS_NetBSD
/* add crt end if not memory output */
- if (S->output_type != TCC_OUTPUT_MEMORY) {
- if (S->output_type == TCC_OUTPUT_DLL)
- tcc_add_crt(S, "crtendS.o");
+ if (s1->output_type != TCC_OUTPUT_MEMORY) {
+ if (s1->output_type == TCC_OUTPUT_DLL)
+ tcc_add_crt(s1, "crtendS.o");
else
- tcc_add_crt(S, "crtend.o");
+ tcc_add_crt(s1, "crtend.o");
#if TARGETOS_FreeBSD || TARGETOS_NetBSD
- tcc_add_crt(S, "crtn.o");
+ tcc_add_crt(s1, "crtn.o");
#endif
}
#elif !defined(TCC_TARGET_MACHO)
/* add crt end if not memory output */
- if (S->output_type != TCC_OUTPUT_MEMORY)
- tcc_add_crt(S, "crtn.o");
+ if (s1->output_type != TCC_OUTPUT_MEMORY)
+ tcc_add_crt(s1, "crtn.o");
#endif
}
}
@@ -1557,32 +1560,32 @@ ST_FUNC void tcc_add_runtime(TCCState *S)
/* add various standard linker symbols (must be done after the
sections are filled (for example after allocating common
symbols)) */
-static void tcc_add_linker_symbols(TCCState *S)
+static void tcc_add_linker_symbols(TCCState *s1)
{
char buf[1024];
int i;
Section *s;
- set_global_sym(S, "_etext", text_section, -1);
- set_global_sym(S, "_edata", data_section, -1);
- set_global_sym(S, "_end", bss_section, -1);
+ set_global_sym(s1, "_etext", text_section, -1);
+ set_global_sym(s1, "_edata", data_section, -1);
+ set_global_sym(s1, "_end", bss_section, -1);
#if TARGETOS_OpenBSD
- set_global_sym(S, "__executable_start", NULL, ELF_START_ADDR);
+ set_global_sym(s1, "__executable_start", NULL, ELF_START_ADDR);
#endif
#ifdef TCC_TARGET_RISCV64
/* XXX should be .sdata+0x800, not .data+0x800 */
- set_global_sym(S, "__global_pointer$", data_section, 0x800);
+ set_global_sym(s1, "__global_pointer$", data_section, 0x800);
#endif
/* horrible new standard ldscript defines */
#ifndef TCC_TARGET_PE
- add_init_array_defines(S, ".preinit_array");
+ add_init_array_defines(s1, ".preinit_array");
#endif
- add_init_array_defines(S, ".init_array");
- add_init_array_defines(S, ".fini_array");
+ add_init_array_defines(s1, ".init_array");
+ add_init_array_defines(s1, ".fini_array");
/* add start and stop symbols for sections whose name can be
expressed in C */
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if ((s->sh_flags & SHF_ALLOC)
&& (s->sh_type == SHT_PROGBITS
|| s->sh_type == SHT_STRTAB)) {
@@ -1598,15 +1601,15 @@ static void tcc_add_linker_symbols(TCCState *S)
p++;
}
snprintf(buf, sizeof(buf), "__start_%s", s->name);
- set_global_sym(S, buf, s, 0);
+ set_global_sym(s1, buf, s, 0);
snprintf(buf, sizeof(buf), "__stop_%s", s->name);
- set_global_sym(S, buf, s, -1);
+ set_global_sym(s1, buf, s, -1);
}
next_sec: ;
}
}
-ST_FUNC void resolve_common_syms(TCCState *S)
+ST_FUNC void resolve_common_syms(TCCState *s1)
{
ElfW(Sym) *sym;
@@ -1614,44 +1617,44 @@ ST_FUNC void resolve_common_syms(TCCState *S)
for_each_elem(symtab_section, 1, sym, ElfW(Sym)) {
if (sym->st_shndx == SHN_COMMON) {
/* symbol alignment is in st_value for SHN_COMMONs */
- sym->st_value = section_add(S, bss_section, sym->st_size,
+ sym->st_value = section_add(bss_section, sym->st_size,
sym->st_value);
sym->st_shndx = bss_section->sh_num;
}
}
/* Now assign linker provided symbols their value. */
- tcc_add_linker_symbols(S);
+ tcc_add_linker_symbols(s1);
}
#ifndef ELF_OBJ_ONLY
-ST_FUNC void fill_got_entry(TCCState *S, ElfW_Rel *rel)
+ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel)
{
int sym_index = ELFW(R_SYM) (rel->r_info);
ElfW(Sym) *sym = &((ElfW(Sym) *) symtab_section->data)[sym_index];
- struct sym_attr *attr = get_sym_attr(S, sym_index, 0);
+ struct sym_attr *attr = get_sym_attr(s1, sym_index, 0);
unsigned offset = attr->got_offset;
if (0 == offset)
return;
- section_reserve(S, S->got, offset + PTR_SIZE);
+ section_reserve(s1->got, offset + PTR_SIZE);
#if PTR_SIZE == 8
- write64le(S->got->data + offset, sym->st_value);
+ write64le(s1->got->data + offset, sym->st_value);
#else
- write32le(S->got->data + offset, sym->st_value);
+ write32le(s1->got->data + offset, sym->st_value);
#endif
}
/* Perform relocation to GOT or PLT entries */
-ST_FUNC void fill_got(TCCState *S)
+ST_FUNC void fill_got(TCCState *s1)
{
Section *s;
ElfW_Rel *rel;
int i;
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (s->sh_type != SHT_RELX)
continue;
/* no need to handle got relocations */
@@ -1664,7 +1667,7 @@ ST_FUNC void fill_got(TCCState *S)
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_PLT32:
- fill_got_entry(S, rel);
+ fill_got_entry(s1, rel);
break;
}
}
@@ -1673,25 +1676,25 @@ ST_FUNC void fill_got(TCCState *S)
/* See put_got_entry for a description. This is the second stage
where GOT references to local defined symbols are rewritten. */
-static void fill_local_got_entries(TCCState *S)
+static void fill_local_got_entries(TCCState *s1)
{
ElfW_Rel *rel;
- if (!S->got->reloc)
+ if (!s1->got->reloc)
return;
- for_each_elem(S->got->reloc, 0, rel, ElfW_Rel) {
+ for_each_elem(s1->got->reloc, 0, rel, ElfW_Rel) {
if (ELFW(R_TYPE)(rel->r_info) == R_RELATIVE) {
int sym_index = ELFW(R_SYM) (rel->r_info);
ElfW(Sym) *sym = &((ElfW(Sym) *) symtab_section->data)[sym_index];
- struct sym_attr *attr = get_sym_attr(S, sym_index, 0);
+ struct sym_attr *attr = get_sym_attr(s1, sym_index, 0);
unsigned offset = attr->got_offset;
- if (offset != rel->r_offset - S->got->sh_addr)
- tcc_error_noabort(S, "huh");
+ if (offset != rel->r_offset - s1->got->sh_addr)
+ tcc_error_noabort("huh");
rel->r_info = ELFW(R_INFO)(0, R_RELATIVE);
#if SHT_RELX == SHT_RELA
rel->r_addend = sym->st_value;
#else
/* All our REL architectures also happen to be 32bit LE. */
- write32le(S->got->data + offset, sym->st_value);
+ write32le(s1->got->data + offset, sym->st_value);
#endif
}
}
@@ -1700,7 +1703,7 @@ static void fill_local_got_entries(TCCState *S)
/* Bind symbols of executable: resolve undefined symbols from exported symbols
in shared libraries and export non local defined symbols to shared libraries
if -rdynamic switch was given on command line */
-static void bind_exe_dynsyms(TCCState *S)
+static void bind_exe_dynsyms(TCCState *s1)
{
const char *name;
int sym_index, index;
@@ -1713,9 +1716,9 @@ static void bind_exe_dynsyms(TCCState *S)
for_each_elem(symtab_section, 1, sym, ElfW(Sym)) {
if (sym->st_shndx == SHN_UNDEF) {
name = (char *) symtab_section->link->data + sym->st_name;
- sym_index = find_elf_sym(S->dynsymtab_section, name);
+ sym_index = find_elf_sym(s1->dynsymtab_section, name);
if (sym_index) {
- esym = &((ElfW(Sym) *)S->dynsymtab_section->data)[sym_index];
+ esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index];
type = ELFW(ST_TYPE)(esym->st_info);
if ((type == STT_FUNC) || (type == STT_GNU_IFUNC)) {
/* Indirect functions shall have STT_FUNC type in executable
@@ -1726,31 +1729,31 @@ static void bind_exe_dynsyms(TCCState *S)
* the address of the function that would return that
* address */
int dynindex
- = put_elf_sym(S, S->dynsym, 0, esym->st_size,
+ = put_elf_sym(s1->dynsym, 0, esym->st_size,
ELFW(ST_INFO)(STB_GLOBAL,STT_FUNC), 0, 0,
name);
int index = sym - (ElfW(Sym) *) symtab_section->data;
- get_sym_attr(S, index, 1)->dyn_index = dynindex;
+ get_sym_attr(s1, index, 1)->dyn_index = dynindex;
} else if (type == STT_OBJECT) {
unsigned long offset;
ElfW(Sym) *dynsym;
offset = bss_section->data_offset;
/* XXX: which alignment ? */
offset = (offset + 16 - 1) & -16;
- set_elf_sym (S->symtab, offset, esym->st_size,
+ set_elf_sym (s1->symtab, offset, esym->st_size,
esym->st_info, 0, bss_section->sh_num, name);
- index = put_elf_sym(S, S->dynsym, offset, esym->st_size,
+ index = put_elf_sym(s1->dynsym, offset, esym->st_size,
esym->st_info, 0, bss_section->sh_num,
name);
/* Ensure R_COPY works for weak symbol aliases */
if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) {
- for_each_elem(S->dynsymtab_section, 1, dynsym, ElfW(Sym)) {
+ for_each_elem(s1->dynsymtab_section, 1, dynsym, ElfW(Sym)) {
if ((dynsym->st_value == esym->st_value)
&& (ELFW(ST_BIND)(dynsym->st_info) == STB_GLOBAL)) {
- char *dynname = (char *) S->dynsymtab_section->link->data
+ char *dynname = (char *) s1->dynsymtab_section->link->data
+ dynsym->st_name;
- put_elf_sym(S, S->dynsym, offset, dynsym->st_size,
+ put_elf_sym(s1->dynsym, offset, dynsym->st_size,
dynsym->st_info, 0,
bss_section->sh_num, dynname);
break;
@@ -1758,7 +1761,7 @@ static void bind_exe_dynsyms(TCCState *S)
}
}
- put_elf_reloc(S->dynsym, bss_section,
+ put_elf_reloc(s1->dynsym, bss_section,
offset, R_COPY, index);
offset += esym->st_size;
bss_section->data_offset = offset;
@@ -1769,13 +1772,13 @@ static void bind_exe_dynsyms(TCCState *S)
if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK ||
!strcmp(name, "_fp_hw")) {
} else {
- tcc_error_noabort(S, "undefined symbol '%s'", name);
+ tcc_error_noabort("undefined symbol '%s'", name);
}
}
- } else if (S->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
+ } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
/* if -rdynamic option, then export all non local symbols */
name = (char *) symtab_section->link->data + sym->st_name;
- set_elf_sym(S->dynsym, sym->st_value, sym->st_size, sym->st_info,
+ set_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
0, sym->st_shndx, name);
}
}
@@ -1786,24 +1789,24 @@ static void bind_exe_dynsyms(TCCState *S)
search symbol first in executable and then in libraries. Therefore a
reference to a symbol already defined by a library can still be resolved by
a symbol in the executable. */
-static void bind_libs_dynsyms(TCCState *S)
+static void bind_libs_dynsyms(TCCState *s1)
{
const char *name;
int sym_index;
ElfW(Sym) *sym, *esym;
- for_each_elem(S->dynsymtab_section, 1, esym, ElfW(Sym)) {
- name = (char *) S->dynsymtab_section->link->data + esym->st_name;
+ for_each_elem(s1->dynsymtab_section, 1, esym, ElfW(Sym)) {
+ name = (char *) s1->dynsymtab_section->link->data + esym->st_name;
sym_index = find_elf_sym(symtab_section, name);
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
if (sym_index && sym->st_shndx != SHN_UNDEF
&& ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
- set_elf_sym(S->dynsym, sym->st_value, sym->st_size,
+ set_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
sym->st_info, 0, sym->st_shndx, name);
} else if (esym->st_shndx == SHN_UNDEF) {
/* weak symbols can stay undefined */
if (ELFW(ST_BIND)(esym->st_info) != STB_WEAK)
- tcc_warning(S, "undefined dynamic symbol '%s'", name);
+ tcc_warning("undefined dynamic symbol '%s'", name);
}
}
}
@@ -1812,7 +1815,7 @@ static void bind_libs_dynsyms(TCCState *S)
non local symbols they define can resolve a reference in another shared
library or in the executable. Correspondingly, it allows undefined local
symbols to be resolved by other shared libraries or by the executable. */
-static void export_global_syms(TCCState *S)
+static void export_global_syms(TCCState *s1)
{
int dynindex, index;
const char *name;
@@ -1821,36 +1824,36 @@ static void export_global_syms(TCCState *S)
for_each_elem(symtab_section, 1, sym, ElfW(Sym)) {
if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
name = (char *) symtab_section->link->data + sym->st_name;
- dynindex = put_elf_sym(S, S->dynsym, sym->st_value, sym->st_size,
+ dynindex = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
sym->st_info, 0, sym->st_shndx, name);
index = sym - (ElfW(Sym) *) symtab_section->data;
- get_sym_attr(S, index, 1)->dyn_index = dynindex;
+ get_sym_attr(s1, index, 1)->dyn_index = dynindex;
}
}
}
/* decide if an unallocated section should be output. */
-static int set_sec_sizes(TCCState *S)
+static int set_sec_sizes(TCCState *s1)
{
int i;
Section *s;
int textrel = 0;
- int file_type = S->output_type;
+ int file_type = s1->output_type;
/* Allocate strings for section names */
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (s->sh_type == SHT_RELX && !(s->sh_flags & SHF_ALLOC)) {
/* when generating a DLL, we include relocations but
we may patch them */
if (file_type == TCC_OUTPUT_DLL
- && (S->sections[s->sh_info]->sh_flags & SHF_ALLOC)) {
- int count = prepare_dynamic_rel(S, s);
+ && (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC)) {
+ int count = prepare_dynamic_rel(s1, s);
if (count) {
/* allocate the section */
s->sh_flags |= SHF_ALLOC;
s->sh_size = count * sizeof(ElfW_Rel);
- if (!(S->sections[s->sh_info]->sh_flags & SHF_WRITE))
+ if (!(s1->sections[s->sh_info]->sh_flags & SHF_WRITE))
textrel = 1;
}
}
@@ -1858,7 +1861,7 @@ static int set_sec_sizes(TCCState *S)
#ifdef TCC_TARGET_ARM
|| s->sh_type == SHT_ARM_ATTRIBUTES
#endif
- || S->do_debug) {
+ || s1->do_debug) {
s->sh_size = s->data_offset;
}
@@ -1892,16 +1895,16 @@ struct ro_inf {
};
static void alloc_sec_names(
- TCCState *S, int is_obj
+ TCCState *s1, int is_obj
);
static int layout_any_sections(
- TCCState *S, int file_offset, int *sec_order, int is_obj
+ TCCState *s1, int file_offset, int *sec_order, int is_obj
);
/* Assign sections to segments and decide how are sections laid out when loaded
in memory. This function also fills corresponding program headers. */
-static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
+static int layout_sections(TCCState *s1, ElfW(Phdr) *phdr,
int phnum, int phfill,
Section *interp,
struct ro_inf *roinf, int *sec_order)
@@ -1910,7 +1913,7 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
Section *s;
file_offset = 0;
- if (S->output_format == TCC_OUTPUT_FORMAT_ELF)
+ if (s1->output_format == TCC_OUTPUT_FORMAT_ELF)
file_offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr));
{
@@ -1918,15 +1921,15 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
long long tmp;
addr_t addr;
ElfW(Phdr) *ph;
- int j, k, f, file_type = S->output_type;
+ int j, k, f, file_type = s1->output_type;
s_align = ELF_PAGE_SIZE;
- if (S->section_align)
- s_align = S->section_align;
+ if (s1->section_align)
+ s_align = s1->section_align;
- if (S->has_text_addr) {
+ if (s1->has_text_addr) {
int a_offset, p_offset;
- addr = S->text_addr;
+ addr = s1->text_addr;
/* we ensure that (addr % ELF_PAGE_SIZE) == file_offset %
ELF_PAGE_SIZE */
a_offset = (int) (addr & (s_align - 1));
@@ -1968,8 +1971,8 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
/* XXX: do faster and simpler sorting */
f = -1;
for(k = 0; k < 7; k++) {
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
/* compute if section should be included */
if (j == 0) {
if ((s->sh_flags & (SHF_ALLOC | SHF_WRITE | SHF_TLS)) !=
@@ -1994,7 +1997,7 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
if (k != 1)
continue;
} else if (s->sh_type == SHT_RELX) {
- if (S->plt && s == S->plt->reloc) {
+ if (s1->plt && s == s1->plt->reloc) {
if (k != 3)
continue;
} else {
@@ -2064,7 +2067,7 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
ph->p_memsz = addr - ph->p_vaddr;
ph++;
if (j == 0) {
- if (S->output_format == TCC_OUTPUT_FORMAT_ELF) {
+ if (s1->output_format == TCC_OUTPUT_FORMAT_ELF) {
/* if in the middle of a page, we duplicate the page in
memory so that one copy is RX and the other is RW */
if ((addr & (s_align - 1)) != 0)
@@ -2078,14 +2081,14 @@ static int layout_sections(TCCState *S, ElfW(Phdr) *phdr,
}
/* all other sections come after */
- return layout_any_sections(S, file_offset, sec_order, 0);
+ return layout_any_sections(s1, file_offset, sec_order, 0);
}
/* put dynamic tag */
-static void put_dt(TCCState* S, Section *dynamic, int dt, addr_t val)
+static void put_dt(Section *dynamic, int dt, addr_t val)
{
ElfW(Dyn) *dyn;
- dyn = section_ptr_add(S, dynamic, sizeof(ElfW(Dyn)));
+ dyn = section_ptr_add(dynamic, sizeof(ElfW(Dyn)));
dyn->d_tag = dt;
dyn->d_un.d_val = val;
}
@@ -2161,72 +2164,72 @@ static void fill_unloadable_phdr(ElfW(Phdr) *phdr, int phnum, Section *interp,
/* Fill the dynamic section with tags describing the address and size of
sections */
-static void fill_dynamic(TCCState *S, struct dyn_inf *dyninf)
+static void fill_dynamic(TCCState *s1, struct dyn_inf *dyninf)
{
Section *dynamic = dyninf->dynamic;
Section *s;
/* put dynamic section entries */
- put_dt(S, dynamic, DT_HASH, S->dynsym->hash->sh_addr);
- put_dt(S, dynamic, DT_STRTAB, dyninf->dynstr->sh_addr);
- put_dt(S, dynamic, DT_SYMTAB, S->dynsym->sh_addr);
- put_dt(S, dynamic, DT_STRSZ, dyninf->dynstr->data_offset);
- put_dt(S, dynamic, DT_SYMENT, sizeof(ElfW(Sym)));
+ put_dt(dynamic, DT_HASH, s1->dynsym->hash->sh_addr);
+ put_dt(dynamic, DT_STRTAB, dyninf->dynstr->sh_addr);
+ put_dt(dynamic, DT_SYMTAB, s1->dynsym->sh_addr);
+ put_dt(dynamic, DT_STRSZ, dyninf->dynstr->data_offset);
+ put_dt(dynamic, DT_SYMENT, sizeof(ElfW(Sym)));
#if PTR_SIZE == 8
- put_dt(S, dynamic, DT_RELA, dyninf->rel_addr);
- put_dt(S, dynamic, DT_RELASZ, dyninf->rel_size);
- put_dt(S, dynamic, DT_RELAENT, sizeof(ElfW_Rel));
- if (S->plt && S->plt->reloc) {
- put_dt(S, dynamic, DT_PLTGOT, S->got->sh_addr);
- put_dt(S, dynamic, DT_PLTRELSZ, S->plt->reloc->data_offset);
- put_dt(S, dynamic, DT_JMPREL, S->plt->reloc->sh_addr);
- put_dt(S, dynamic, DT_PLTREL, DT_RELA);
- }
- put_dt(S, dynamic, DT_RELACOUNT, 0);
+ put_dt(dynamic, DT_RELA, dyninf->rel_addr);
+ put_dt(dynamic, DT_RELASZ, dyninf->rel_size);
+ put_dt(dynamic, DT_RELAENT, sizeof(ElfW_Rel));
+ if (s1->plt && s1->plt->reloc) {
+ put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr);
+ put_dt(dynamic, DT_PLTRELSZ, s1->plt->reloc->data_offset);
+ put_dt(dynamic, DT_JMPREL, s1->plt->reloc->sh_addr);
+ put_dt(dynamic, DT_PLTREL, DT_RELA);
+ }
+ put_dt(dynamic, DT_RELACOUNT, 0);
#else
- put_dt(S, dynamic, DT_REL, dyninf->rel_addr);
- put_dt(S, dynamic, DT_RELSZ, dyninf->rel_size);
- put_dt(S, dynamic, DT_RELENT, sizeof(ElfW_Rel));
- if (S->plt && S->plt->reloc) {
- put_dt(S, dynamic, DT_PLTGOT, S->got->sh_addr);
- put_dt(S, dynamic, DT_PLTRELSZ, S->plt->reloc->data_offset);
- put_dt(S, dynamic, DT_JMPREL, S->plt->reloc->sh_addr);
- put_dt(S, dynamic, DT_PLTREL, DT_REL);
+ put_dt(dynamic, DT_REL, dyninf->rel_addr);
+ put_dt(dynamic, DT_RELSZ, dyninf->rel_size);
+ put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel));
+ if (s1->plt && s1->plt->reloc) {
+ put_dt(dynamic, DT_PLTGOT, s1->got->sh_addr);
+ put_dt(dynamic, DT_PLTRELSZ, s1->plt->reloc->data_offset);
+ put_dt(dynamic, DT_JMPREL, s1->plt->reloc->sh_addr);
+ put_dt(dynamic, DT_PLTREL, DT_REL);
}
- put_dt(S, dynamic, DT_RELCOUNT, 0);
+ put_dt(dynamic, DT_RELCOUNT, 0);
#endif
if (versym_section && verneed_section) {
/* The dynamic linker can not handle VERSYM without VERNEED */
- put_dt(S, dynamic, DT_VERSYM, versym_section->sh_addr);
- put_dt(S, dynamic, DT_VERNEED, verneed_section->sh_addr);
- put_dt(S, dynamic, DT_VERNEEDNUM, dt_verneednum);
+ put_dt(dynamic, DT_VERSYM, versym_section->sh_addr);
+ put_dt(dynamic, DT_VERNEED, verneed_section->sh_addr);
+ put_dt(dynamic, DT_VERNEEDNUM, dt_verneednum);
}
- s = find_section_create (S, ".preinit_array", 0);
+ s = find_section_create (s1, ".preinit_array", 0);
if (s && s->data_offset) {
- put_dt(S, dynamic, DT_PREINIT_ARRAY, s->sh_addr);
- put_dt(S, dynamic, DT_PREINIT_ARRAYSZ, s->data_offset);
+ put_dt(dynamic, DT_PREINIT_ARRAY, s->sh_addr);
+ put_dt(dynamic, DT_PREINIT_ARRAYSZ, s->data_offset);
}
- s = find_section_create (S, ".init_array", 0);
+ s = find_section_create (s1, ".init_array", 0);
if (s && s->data_offset) {
- put_dt(S, dynamic, DT_INIT_ARRAY, s->sh_addr);
- put_dt(S, dynamic, DT_INIT_ARRAYSZ, s->data_offset);
+ put_dt(dynamic, DT_INIT_ARRAY, s->sh_addr);
+ put_dt(dynamic, DT_INIT_ARRAYSZ, s->data_offset);
}
- s = find_section_create (S, ".fini_array", 0);
+ s = find_section_create (s1, ".fini_array", 0);
if (s && s->data_offset) {
- put_dt(S, dynamic, DT_FINI_ARRAY, s->sh_addr);
- put_dt(S, dynamic, DT_FINI_ARRAYSZ, s->data_offset);
+ put_dt(dynamic, DT_FINI_ARRAY, s->sh_addr);
+ put_dt(dynamic, DT_FINI_ARRAYSZ, s->data_offset);
}
- s = find_section_create (S, ".init", 0);
+ s = find_section_create (s1, ".init", 0);
if (s && s->data_offset) {
- put_dt(S, dynamic, DT_INIT, s->sh_addr);
+ put_dt(dynamic, DT_INIT, s->sh_addr);
}
- s = find_section_create (S, ".fini", 0);
+ s = find_section_create (s1, ".fini", 0);
if (s && s->data_offset) {
- put_dt(S, dynamic, DT_FINI, s->sh_addr);
+ put_dt(dynamic, DT_FINI, s->sh_addr);
}
- if (S->do_debug)
- put_dt(S, dynamic, DT_DEBUG, 0);
- put_dt(S, dynamic, DT_NULL, 0);
+ if (s1->do_debug)
+ put_dt(dynamic, DT_DEBUG, 0);
+ put_dt(dynamic, DT_NULL, 0);
}
/* Remove gaps between RELX sections.
@@ -2234,18 +2237,18 @@ static void fill_dynamic(TCCState *S, struct dyn_inf *dyninf)
The gaps are then filled with 0 in tcc_output_elf. The 0 is intepreted as
R_...NONE reloc. This does work on most targets but on OpenBSD/arm64 this
is illegal. OpenBSD/arm64 does not support R_...NONE reloc. */
-static void update_reloc_sections(TCCState *S, struct dyn_inf *dyninf)
+static void update_reloc_sections(TCCState *s1, struct dyn_inf *dyninf)
{
int i;
unsigned long file_offset = 0;
Section *s;
- Section *relocplt = S->plt ? S->plt->reloc : NULL;
+ Section *relocplt = s1->plt ? s1->plt->reloc : NULL;
/* dynamic relocation table information, for .dynamic section */
dyninf->rel_addr = dyninf->rel_size = 0;
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (s->sh_type == SHT_RELX && s != relocplt) {
if (dyninf->rel_size == 0) {
dyninf->rel_addr = s->sh_addr;
@@ -2264,7 +2267,7 @@ static void update_reloc_sections(TCCState *S, struct dyn_inf *dyninf)
/* Create an ELF file on disk.
This function handle ELF specific layout requirements */
-static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
+static void tcc_output_elf(TCCState *s1, FILE *f, int phnum, ElfW(Phdr) *phdr,
int file_offset, int *sec_order)
{
int i, shnum, offset, size, file_type;
@@ -2272,8 +2275,8 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
ElfW(Ehdr) ehdr;
ElfW(Shdr) shdr, *sh;
- file_type = S->output_type;
- shnum = S->nb_sections;
+ file_type = s1->output_type;
+ shnum = s1->nb_sections;
memset(&ehdr, 0, sizeof(ehdr));
@@ -2303,7 +2306,7 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
ehdr.e_flags = EF_ARM_EABI_VER4;
if (file_type == TCC_OUTPUT_EXE || file_type == TCC_OUTPUT_DLL)
ehdr.e_flags |= EF_ARM_HASENTRY;
- if (S->float_abi == ARM_HARD_FLOAT)
+ if (s1->float_abi == ARM_HARD_FLOAT)
ehdr.e_flags |= EF_ARM_VFP_FLOAT;
else
ehdr.e_flags |= EF_ARM_SOFT_FLOAT;
@@ -2317,7 +2320,7 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
default:
case TCC_OUTPUT_EXE:
ehdr.e_type = ET_EXEC;
- ehdr.e_entry = get_sym_addr(S, "_start", 1, 0);
+ ehdr.e_entry = get_sym_addr(s1, "_start", 1, 0);
break;
case TCC_OUTPUT_DLL:
ehdr.e_type = ET_DYN;
@@ -2340,9 +2343,9 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
fwrite(phdr, 1, phnum * sizeof(ElfW(Phdr)), f);
offset = sizeof(ElfW(Ehdr)) + phnum * sizeof(ElfW(Phdr));
- sort_syms(S, symtab_section);
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[sec_order[i]];
+ sort_syms(s1, symtab_section);
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[sec_order[i]];
if (s->sh_type != SHT_NOBITS) {
while (offset < s->sh_offset) {
fputc(0, f);
@@ -2361,10 +2364,10 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
offset++;
}
- for(i = 0; i < S->nb_sections; i++) {
+ for(i = 0; i < s1->nb_sections; i++) {
sh = &shdr;
memset(sh, 0, sizeof(ElfW(Shdr)));
- s = S->sections[i];
+ s = s1->sections[i];
if (s) {
sh->sh_name = s->sh_name;
sh->sh_type = s->sh_type;
@@ -2382,15 +2385,15 @@ static void tcc_output_elf(TCCState *S, FILE *f, int phnum, ElfW(Phdr) *phdr,
}
}
-static void tcc_output_binary(TCCState *S, FILE *f,
+static void tcc_output_binary(TCCState *s1, FILE *f,
const int *sec_order)
{
Section *s;
int i, offset, size;
offset = 0;
- for(i=1;i<S->nb_sections;i++) {
- s = S->sections[sec_order[i]];
+ for(i=1;i<s1->nb_sections;i++) {
+ s = s1->sections[sec_order[i]];
if (s->sh_type != SHT_NOBITS &&
(s->sh_flags & SHF_ALLOC)) {
while (offset < s->sh_offset) {
@@ -2405,13 +2408,13 @@ static void tcc_output_binary(TCCState *S, FILE *f,
}
/* Write an elf, coff or "binary" file */
-static int tcc_write_elf_file(TCCState *S, const char *filename, int phnum,
+static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum,
ElfW(Phdr) *phdr, int file_offset, int *sec_order)
{
int fd, mode, file_type;
FILE *f;
- file_type = S->output_type;
+ file_type = s1->output_type;
if (file_type == TCC_OUTPUT_OBJ)
mode = 0666;
else
@@ -2419,22 +2422,22 @@ static int tcc_write_elf_file(TCCState *S, const char *filename, int phnum,
unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
if (fd < 0) {
- tcc_error_noabort(S, "could not write '%s'", filename);
+ tcc_error_noabort("could not write '%s'", filename);
return -1;
}
f = fdopen(fd, "wb");
- if (S->verbose)
+ if (s1->verbose)
printf("<- %s\n", filename);
#ifdef TCC_TARGET_COFF
- if (S->output_format == TCC_OUTPUT_FORMAT_COFF)
- tcc_output_coff(S, f);
+ if (s1->output_format == TCC_OUTPUT_FORMAT_COFF)
+ tcc_output_coff(s1, f);
else
#endif
- if (S->output_format == TCC_OUTPUT_FORMAT_ELF)
- tcc_output_elf(S, f, phnum, phdr, file_offset, sec_order);
+ if (s1->output_format == TCC_OUTPUT_FORMAT_ELF)
+ tcc_output_elf(s1, f, phnum, phdr, file_offset, sec_order);
else
- tcc_output_binary(S, f, sec_order);
+ tcc_output_binary(s1, f, sec_order);
fclose(f);
return 0;
@@ -2443,16 +2446,16 @@ static int tcc_write_elf_file(TCCState *S, const char *filename, int phnum,
#ifndef ELF_OBJ_ONLY
/* Sort section headers by assigned sh_addr, remove sections
that we aren't going to output. */
-static void tidy_section_headers(TCCState *S, int *sec_order)
+static void tidy_section_headers(TCCState *s1, int *sec_order)
{
int i, nnew, l, *backmap;
Section **snew, *s;
ElfW(Sym) *sym;
- snew = tcc_malloc(S, S->nb_sections * sizeof(snew[0]));
- backmap = tcc_malloc(S, S->nb_sections * sizeof(backmap[0]));
- for (i = 0, nnew = 0, l = S->nb_sections; i < S->nb_sections; i++) {
- s = S->sections[sec_order[i]];
+ snew = tcc_malloc(s1->nb_sections * sizeof(snew[0]));
+ backmap = tcc_malloc(s1->nb_sections * sizeof(backmap[0]));
+ for (i = 0, nnew = 0, l = s1->nb_sections; i < s1->nb_sections; i++) {
+ s = s1->sections[sec_order[i]];
if (!i || s->sh_name) {
backmap[sec_order[i]] = nnew;
snew[nnew] = s;
@@ -2474,21 +2477,21 @@ static void tidy_section_headers(TCCState *S, int *sec_order)
for_each_elem(symtab_section, 1, sym, ElfW(Sym))
if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE)
sym->st_shndx = backmap[sym->st_shndx];
- if ( !S->static_link ) {
- for_each_elem(S->dynsym, 1, sym, ElfW(Sym))
+ if ( !s1->static_link ) {
+ for_each_elem(s1->dynsym, 1, sym, ElfW(Sym))
if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE)
sym->st_shndx = backmap[sym->st_shndx];
}
- for (i = 0; i < S->nb_sections; i++)
+ for (i = 0; i < s1->nb_sections; i++)
sec_order[i] = i;
- tcc_free(S, S->sections);
- S->sections = snew;
- S->nb_sections = nnew;
- tcc_free(S, backmap);
+ tcc_free(s1->sections);
+ s1->sections = snew;
+ s1->nb_sections = nnew;
+ tcc_free(backmap);
}
#ifdef TCC_TARGET_ARM
-static void create_arm_attribute_section(TCCState *S)
+static void create_arm_attribute_section(TCCState *s1)
{
// Needed for DLL support.
static const unsigned char arm_attr[] = {
@@ -2511,11 +2514,11 @@ static void create_arm_attribute_section(TCCState *S)
0x1c, 0x01, // 'ABI_VFP_args', 'VFP registers'
0x22, 0x01 // 'CPU_unaligned_access', 'v6'
};
- Section *attr = new_section(S, ".ARM.attributes", SHT_ARM_ATTRIBUTES, 0);
- unsigned char *ptr = section_ptr_add(S, attr, sizeof(arm_attr));
+ Section *attr = new_section(s1, ".ARM.attributes", SHT_ARM_ATTRIBUTES, 0);
+ unsigned char *ptr = section_ptr_add(attr, sizeof(arm_attr));
attr->sh_addralign = 1;
memcpy(ptr, arm_attr, sizeof(arm_attr));
- if (S->float_abi != ARM_HARD_FLOAT) {
+ if (s1->float_abi != ARM_HARD_FLOAT) {
ptr[26] = 0x00; // 'FP_arch', 'No'
ptr[41] = 0x1e; // 'ABI_optimization_goals'
ptr[42] = 0x06; // 'Aggressive Debug'
@@ -2524,14 +2527,14 @@ static void create_arm_attribute_section(TCCState *S)
#endif
#if TARGETOS_OpenBSD || TARGETOS_NetBSD
-static Section *create_bsd_note_section(TCCState *S,
+static Section *create_bsd_note_section(TCCState *s1,
const char *name,
const char *value)
{
- Section *s = find_section (S, name);
+ Section *s = find_section (s1, name);
if (s->data_offset == 0) {
- char *ptr = section_ptr_add(S, s, sizeof(ElfW(Nhdr)) + 8 + 4);
+ char *ptr = section_ptr_add(s, sizeof(ElfW(Nhdr)) + 8 + 4);
ElfW(Nhdr) *note = (ElfW(Nhdr) *) ptr;
s->sh_type = SHT_NOTE;
@@ -2546,7 +2549,7 @@ static Section *create_bsd_note_section(TCCState *S,
/* Output an elf, coff or binary file */
/* XXX: suppress unneeded sections */
-static int elf_output_file(TCCState *S, const char *filename)
+static int elf_output_file(TCCState *s1, const char *filename)
{
int i, ret, phnum, phfill, shnum, file_type, file_offset, *sec_order;
struct dyn_inf dyninf = {0};
@@ -2556,121 +2559,121 @@ static int elf_output_file(TCCState *S, const char *filename)
struct ro_inf *roinf_use = NULL;
int textrel;
- file_type = S->output_type;
- S->nb_errors = 0;
+ file_type = s1->output_type;
+ s1->nb_errors = 0;
ret = -1;
phdr = NULL;
sec_order = NULL;
interp = dynamic = dynstr = note = NULL;
#ifdef TCC_TARGET_ARM
- create_arm_attribute_section (S);
+ create_arm_attribute_section (s1);
#endif
#if TARGETOS_OpenBSD
- note = create_bsd_note_section (S, ".note.openbsd.ident", "OpenBSD");
+ note = create_bsd_note_section (s1, ".note.openbsd.ident", "OpenBSD");
#endif
#if TARGETOS_NetBSD
- note = create_bsd_note_section (S, ".note.netbsd.ident", "NetBSD");
+ note = create_bsd_note_section (s1, ".note.netbsd.ident", "NetBSD");
#endif
{
/* if linking, also link in runtime libraries (libc, libgcc, etc.) */
- tcc_add_runtime(S);
- resolve_common_syms(S);
+ tcc_add_runtime(s1);
+ resolve_common_syms(s1);
- if (!S->static_link) {
+ if (!s1->static_link) {
if (file_type == TCC_OUTPUT_EXE) {
char *ptr;
/* allow override the dynamic loader */
const char *elfint = getenv("LD_SO");
if (elfint == NULL)
- elfint = DEFAULT_ELFINTERP(S);
+ elfint = DEFAULT_ELFINTERP(s1);
/* add interpreter section only if executable */
- interp = new_section(S, ".interp", SHT_PROGBITS, SHF_ALLOC);
+ interp = new_section(s1, ".interp", SHT_PROGBITS, SHF_ALLOC);
interp->sh_addralign = 1;
- ptr = section_ptr_add(S, interp, 1 + strlen(elfint));
+ ptr = section_ptr_add(interp, 1 + strlen(elfint));
strcpy(ptr, elfint);
}
/* add dynamic symbol table */
- S->dynsym = new_symtab(S, ".dynsym", SHT_DYNSYM, SHF_ALLOC,
+ s1->dynsym = new_symtab(s1, ".dynsym", SHT_DYNSYM, SHF_ALLOC,
".dynstr",
".hash", SHF_ALLOC);
/* Number of local symbols (readelf complains if not set) */
- S->dynsym->sh_info = 1;
- dynstr = S->dynsym->link;
+ s1->dynsym->sh_info = 1;
+ dynstr = s1->dynsym->link;
/* add dynamic section */
- dynamic = new_section(S, ".dynamic", SHT_DYNAMIC,
+ dynamic = new_section(s1, ".dynamic", SHT_DYNAMIC,
SHF_ALLOC | SHF_WRITE);
dynamic->link = dynstr;
dynamic->sh_entsize = sizeof(ElfW(Dyn));
- build_got(S);
+ build_got(s1);
if (file_type == TCC_OUTPUT_EXE) {
- bind_exe_dynsyms(S);
- if (S->nb_errors)
+ bind_exe_dynsyms(s1);
+ if (s1->nb_errors)
goto the_end;
- bind_libs_dynsyms(S);
+ bind_libs_dynsyms(s1);
} else {
/* shared library case: simply export all global symbols */
- export_global_syms(S);
+ export_global_syms(s1);
}
}
- build_got_entries(S);
- version_add (S);
+ build_got_entries(s1);
+ version_add (s1);
}
- textrel = set_sec_sizes(S);
- alloc_sec_names(S, 0);
+ textrel = set_sec_sizes(s1);
+ alloc_sec_names(s1, 0);
- if (!S->static_link) {
+ if (!s1->static_link) {
int i;
/* add a list of needed dlls */
- for(i = 0; i < S->nb_loaded_dlls; i++) {
- DLLReference *dllref = S->loaded_dlls[i];
+ for(i = 0; i < s1->nb_loaded_dlls; i++) {
+ DLLReference *dllref = s1->loaded_dlls[i];
if (dllref->level == 0)
- put_dt(S, dynamic, DT_NEEDED, put_elf_str(S, dynstr, dllref->name));
+ put_dt(dynamic, DT_NEEDED, put_elf_str(dynstr, dllref->name));
}
- if (S->rpath)
- put_dt(S, dynamic, S->enable_new_dtags ? DT_RUNPATH : DT_RPATH,
- put_elf_str(S, dynstr, S->rpath));
+ if (s1->rpath)
+ put_dt(dynamic, s1->enable_new_dtags ? DT_RUNPATH : DT_RPATH,
+ put_elf_str(dynstr, s1->rpath));
if (file_type == TCC_OUTPUT_DLL) {
- if (S->soname)
- put_dt(S, dynamic, DT_SONAME, put_elf_str(S, dynstr, S->soname));
+ if (s1->soname)
+ put_dt(dynamic, DT_SONAME, put_elf_str(dynstr, s1->soname));
/* XXX: currently, since we do not handle PIC code, we
must relocate the readonly segments */
if (textrel)
- put_dt(S, dynamic, DT_TEXTREL, 0);
+ put_dt(dynamic, DT_TEXTREL, 0);
}
- if (S->symbolic)
- put_dt(S, dynamic, DT_SYMBOLIC, 0);
+ if (s1->symbolic)
+ put_dt(dynamic, DT_SYMBOLIC, 0);
dyninf.dynamic = dynamic;
dyninf.dynstr = dynstr;
/* remember offset and reserve space for 2nd call below */
dyninf.data_offset = dynamic->data_offset;
- fill_dynamic(S, &dyninf);
+ fill_dynamic(s1, &dyninf);
dynamic->sh_size = dynamic->data_offset;
dynstr->sh_size = dynstr->data_offset;
}
- for (i = 1; i < S->nb_sections &&
- !(S->sections[i]->sh_flags & SHF_TLS); i++);
- phfill = 2 + (i < S->nb_sections);
+ for (i = 1; i < s1->nb_sections &&
+ !(s1->sections[i]->sh_flags & SHF_TLS); i++);
+ phfill = 2 + (i < s1->nb_sections);
/* compute number of program headers */
if (file_type == TCC_OUTPUT_DLL)
phnum = 3;
- else if (S->static_link)
+ else if (s1->static_link)
phnum = 3;
else {
- phnum = 5 + (i < S->nb_sections);
+ phnum = 5 + (i < s1->nb_sections);
}
phnum += note != NULL;
@@ -2680,15 +2683,15 @@ static int elf_output_file(TCCState *S, const char *filename)
#endif
/* allocate program segment headers */
- phdr = tcc_mallocz(S, phnum * sizeof(ElfW(Phdr)));
+ phdr = tcc_mallocz(phnum * sizeof(ElfW(Phdr)));
/* compute number of sections */
- shnum = S->nb_sections;
+ shnum = s1->nb_sections;
/* this array is used to reorder sections in the output file */
- sec_order = tcc_malloc(S, sizeof(int) * shnum);
+ sec_order = tcc_malloc(sizeof(int) * shnum);
sec_order[0] = 0;
/* compute section to program header mapping */
- file_offset = layout_sections(S, phdr, phnum, phfill, interp, &roinf, sec_order + 1);
+ file_offset = layout_sections(s1, phdr, phnum, phfill, interp, &roinf, sec_order + 1);
/* Fill remaining program header and finalize relocation related to dynamic
linking. */
@@ -2698,75 +2701,75 @@ static int elf_output_file(TCCState *S, const char *filename)
ElfW(Sym) *sym;
/* put in GOT the dynamic section address and relocate PLT */
- write32le(S->got->data, dynamic->sh_addr);
+ write32le(s1->got->data, dynamic->sh_addr);
if (file_type == TCC_OUTPUT_EXE
|| (RELOCATE_DLLPLT && file_type == TCC_OUTPUT_DLL))
- relocate_plt(S);
+ relocate_plt(s1);
/* relocate symbols in .dynsym now that final addresses are known */
- for_each_elem(S->dynsym, 1, sym, ElfW(Sym)) {
+ for_each_elem(s1->dynsym, 1, sym, ElfW(Sym)) {
if (sym->st_shndx != SHN_UNDEF && sym->st_shndx < SHN_LORESERVE) {
/* do symbol relocation */
- sym->st_value += S->sections[sym->st_shndx]->sh_addr;
+ sym->st_value += s1->sections[sym->st_shndx]->sh_addr;
}
}
}
/* if building executable or DLL, then relocate each section
except the GOT which is already relocated */
- relocate_syms(S, S->symtab, 0);
+ relocate_syms(s1, s1->symtab, 0);
ret = -1;
- if (S->nb_errors != 0)
+ if (s1->nb_errors != 0)
goto the_end;
- relocate_sections(S);
+ relocate_sections(s1);
if (dynamic) {
- update_reloc_sections (S, &dyninf);
+ update_reloc_sections (s1, &dyninf);
dynamic->data_offset = dyninf.data_offset;
- fill_dynamic(S, &dyninf);
+ fill_dynamic(s1, &dyninf);
}
- tidy_section_headers(S, sec_order);
+ tidy_section_headers(s1, sec_order);
/* Perform relocation to GOT or PLT entries */
- if (file_type == TCC_OUTPUT_EXE && S->static_link)
- fill_got(S);
- else if (S->got)
- fill_local_got_entries(S);
+ if (file_type == TCC_OUTPUT_EXE && s1->static_link)
+ fill_got(s1);
+ else if (s1->got)
+ fill_local_got_entries(s1);
}
/* Create the ELF file with name 'filename' */
- ret = tcc_write_elf_file(S, filename, phnum, phdr, file_offset, sec_order);
- S->nb_sections = shnum;
+ ret = tcc_write_elf_file(s1, filename, phnum, phdr, file_offset, sec_order);
+ s1->nb_sections = shnum;
the_end:
- tcc_free(S, sec_order);
- tcc_free(S, phdr);
+ tcc_free(sec_order);
+ tcc_free(phdr);
return ret;
}
#endif /* ndef ELF_OBJ_ONLY */
/* Allocate strings for section names */
-static void alloc_sec_names(TCCState *S, int is_obj)
+static void alloc_sec_names(TCCState *s1, int is_obj)
{
int i;
Section *s, *strsec;
- strsec = new_section(S, ".shstrtab", SHT_STRTAB, 0);
- put_elf_str(S, strsec, "");
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ strsec = new_section(s1, ".shstrtab", SHT_STRTAB, 0);
+ put_elf_str(strsec, "");
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (is_obj)
s->sh_size = s->data_offset;
if (s == strsec || s->sh_size || (s->sh_flags & SHF_ALLOC))
- s->sh_name = put_elf_str(S, strsec, s->name);
+ s->sh_name = put_elf_str(strsec, s->name);
}
strsec->sh_size = strsec->data_offset;
}
-static int layout_any_sections(TCCState *S, int file_offset, int *sec_order, int is_obj)
+static int layout_any_sections(TCCState *s1, int file_offset, int *sec_order, int is_obj)
{
int i;
Section *s;
- for(i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ for(i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (!is_obj && (s->sh_flags & SHF_ALLOC))
continue;
*sec_order++ = i;
@@ -2780,38 +2783,38 @@ static int layout_any_sections(TCCState *S, int file_offset, int *sec_order, int
}
/* Output an elf .o file */
-static int elf_output_obj(TCCState *S, const char *filename)
+static int elf_output_obj(TCCState *s1, const char *filename)
{
int ret, file_offset;
int *sec_order;
- S->nb_errors = 0;
+ s1->nb_errors = 0;
/* Allocate strings for section names */
- alloc_sec_names(S, 1);
+ alloc_sec_names(s1, 1);
/* this array is used to reorder sections in the output file */
- sec_order = tcc_malloc(S, sizeof(int) * S->nb_sections);
+ sec_order = tcc_malloc(sizeof(int) * s1->nb_sections);
sec_order[0] = 0;
- file_offset = layout_any_sections(S, sizeof (ElfW(Ehdr)), sec_order + 1, 1);
+ file_offset = layout_any_sections(s1, sizeof (ElfW(Ehdr)), sec_order + 1, 1);
/* Create the ELF file with name 'filename' */
- ret = tcc_write_elf_file(S, filename, 0, NULL, file_offset, sec_order);
- tcc_free(S, sec_order);
+ ret = tcc_write_elf_file(s1, filename, 0, NULL, file_offset, sec_order);
+ tcc_free(sec_order);
return ret;
}
-LIBTCCAPI int tcc_output_file(TCCState *S, const char *filename)
+LIBTCCAPI int tcc_output_file(TCCState *s, const char *filename)
{
- if (S->test_coverage)
- tcc_tcov_add_file(S, filename);
- if (S->output_type == TCC_OUTPUT_OBJ)
- return elf_output_obj(S, filename);
+ if (s->test_coverage)
+ tcc_tcov_add_file(s, filename);
+ if (s->output_type == TCC_OUTPUT_OBJ)
+ return elf_output_obj(s, filename);
#ifdef TCC_TARGET_PE
- return pe_output_file(S, filename);
+ return pe_output_file(s, filename);
#elif TCC_TARGET_MACHO
- return macho_output_file(S, filename);
+ return macho_output_file(s, filename);
#else
- return elf_output_file(S, filename);
+ return elf_output_file(s, filename);
#endif
}
@@ -2827,11 +2830,11 @@ ST_FUNC ssize_t full_read(int fd, void *buf, size_t count) {
}
}
-ST_FUNC void *load_data(TCCState* S, int fd, unsigned long file_offset, unsigned long size)
+ST_FUNC void *load_data(int fd, unsigned long file_offset, unsigned long size)
{
void *data;
- data = tcc_malloc(S, size);
+ data = tcc_malloc(size);
lseek(fd, file_offset, SEEK_SET);
full_read(fd, data, size);
return data;
@@ -2865,7 +2868,7 @@ ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h)
/* load an object file and merge it with current files */
/* XXX: handle correctly stab (debug) info */
-ST_FUNC int tcc_load_object_file(TCCState *S,
+ST_FUNC int tcc_load_object_file(TCCState *s1,
int fd, unsigned long file_offset)
{
ElfW(Ehdr) ehdr;
@@ -2887,17 +2890,17 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
if (ehdr.e_ident[5] != ELFDATA2LSB ||
ehdr.e_machine != EM_TCC_TARGET) {
fail1:
- tcc_error_noabort(S, "invalid object file");
+ tcc_error_noabort("invalid object file");
return -1;
}
/* read sections */
- shdr = load_data(S, fd, file_offset + ehdr.e_shoff,
+ shdr = load_data(fd, file_offset + ehdr.e_shoff,
sizeof(ElfW(Shdr)) * ehdr.e_shnum);
- sm_table = tcc_mallocz(S, sizeof(SectionMergeInfo) * ehdr.e_shnum);
+ sm_table = tcc_mallocz(sizeof(SectionMergeInfo) * ehdr.e_shnum);
/* load section names */
sh = &shdr[ehdr.e_shstrndx];
- strsec = load_data(S, fd, file_offset + sh->sh_offset, sh->sh_size);
+ strsec = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
/* load symtab and strtab */
old_to_new_syms = NULL;
@@ -2911,18 +2914,18 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
sh = &shdr[i];
if (sh->sh_type == SHT_SYMTAB) {
if (symtab) {
- tcc_error_noabort(S, "object must contain only one symtab");
+ tcc_error_noabort("object must contain only one symtab");
fail:
ret = -1;
goto the_end;
}
nb_syms = sh->sh_size / sizeof(ElfW(Sym));
- symtab = load_data(S, fd, file_offset + sh->sh_offset, sh->sh_size);
+ symtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
sm_table[i].s = symtab_section;
/* now load strtab */
sh = &shdr[sh->sh_link];
- strtab = load_data(S, fd, file_offset + sh->sh_offset, sh->sh_size);
+ strtab = load_data(fd, file_offset + sh->sh_offset, sh->sh_size);
}
if (sh->sh_flags & SHF_COMPRESSED)
seencompressed = 1;
@@ -2962,8 +2965,8 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
if (sh->sh_addralign < 1)
sh->sh_addralign = 1;
/* find corresponding section, if any */
- for(j = 1; j < S->nb_sections;j++) {
- s = S->sections[j];
+ for(j = 1; j < s1->nb_sections;j++) {
+ s = s1->sections[j];
if (!strcmp(s->name, sh_name)) {
if (!strncmp(sh_name, ".gnu.linkonce",
sizeof(".gnu.linkonce") - 1)) {
@@ -2984,7 +2987,7 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
}
}
/* not found: create new section */
- s = new_section(S, sh_name, sh->sh_type, sh->sh_flags & ~SHF_GROUP);
+ s = new_section(s1, sh_name, sh->sh_type, sh->sh_flags & ~SHF_GROUP);
/* take as much info as possible from the section. sh_link and
sh_info will be updated later */
s->sh_addralign = sh->sh_addralign;
@@ -2996,7 +2999,7 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
if (strcmp (s->name, ".eh_frame"))
#endif
{
- tcc_error_noabort(S, "invalid section type");
+ tcc_error_noabort("invalid section type");
goto fail;
}
}
@@ -3011,7 +3014,7 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
if (sh->sh_type != SHT_NOBITS) {
unsigned char *ptr;
lseek(fd, file_offset + sh->sh_offset, SEEK_SET);
- ptr = section_ptr_add(S, s, size);
+ ptr = section_ptr_add(s, size);
full_read(fd, ptr, size);
} else {
s->data_offset += size;
@@ -3046,12 +3049,12 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
if (sh->sh_type == SHT_RELX) {
s->sh_info = sm_table[sh->sh_info].s->sh_num;
/* update backward link */
- S->sections[s->sh_info]->reloc = s;
+ s1->sections[s->sh_info]->reloc = s;
}
}
/* resolve symbols */
- old_to_new_syms = tcc_mallocz(S, nb_syms * sizeof(int));
+ old_to_new_syms = tcc_mallocz(nb_syms * sizeof(int));
sym = symtab + 1;
for(i = 1; i < nb_syms; i++, sym++) {
@@ -3120,7 +3123,7 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
#endif
) {
invalid_reloc:
- tcc_error_noabort(S, "Invalid relocation entry [%2d] '%s' @ %.8x",
+ tcc_error_noabort("Invalid relocation entry [%2d] '%s' @ %.8x",
i, strsec + sh->sh_name, (int)rel->r_offset);
goto fail;
}
@@ -3137,7 +3140,7 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
switch to ARM mode. We set bit plt_thumb_stub of the
attribute of a symbol to indicate such a case. */
if (type == R_ARM_THM_JUMP24)
- get_sym_attr(S, sym_index, 1)->plt_thumb_stub = 1;
+ get_sym_attr(s1, sym_index, 1)->plt_thumb_stub = 1;
#endif
}
break;
@@ -3148,12 +3151,12 @@ ST_FUNC int tcc_load_object_file(TCCState *S,
ret = 0;
the_end:
- tcc_free(S, symtab);
- tcc_free(S, strtab);
- tcc_free(S, old_to_new_syms);
- tcc_free(S, sm_table);
- tcc_free(S, strsec);
- tcc_free(S, shdr);
+ tcc_free(symtab);
+ tcc_free(strtab);
+ tcc_free(old_to_new_syms);
+ tcc_free(sm_table);
+ tcc_free(strsec);
+ tcc_free(shdr);
return ret;
}
@@ -3194,7 +3197,7 @@ static int read_ar_header(int fd, int offset, ArchiveHeader *hdr)
}
/* load only the objects which resolve undefined symbols */
-static int tcc_load_alacarte(TCCState *S, int fd, int size, int entrysize)
+static int tcc_load_alacarte(TCCState *s1, int fd, int size, int entrysize)
{
int i, bound, nsyms, sym_index, len, ret = -1;
unsigned long long off;
@@ -3204,7 +3207,7 @@ static int tcc_load_alacarte(TCCState *S, int fd, int size, int entrysize)
ElfW(Sym) *sym;
ArchiveHeader hdr;
- data = tcc_malloc(S, size);
+ data = tcc_malloc(size);
if (full_read(fd, data, size) != size)
goto the_end;
nsyms = get_be(data, entrysize);
@@ -3224,25 +3227,25 @@ static int tcc_load_alacarte(TCCState *S, int fd, int size, int entrysize)
off = get_be(ar_index + i * entrysize, entrysize);
len = read_ar_header(fd, off, &hdr);
if (len <= 0 || memcmp(hdr.ar_fmag, ARFMAG, 2)) {
- tcc_error_noabort(S, "invalid archive");
+ tcc_error_noabort("invalid archive");
goto the_end;
}
off += len;
- if (S->verbose == 2)
+ if (s1->verbose == 2)
printf(" -> %s\n", hdr.ar_name);
- if (tcc_load_object_file(S, fd, off) < 0)
+ if (tcc_load_object_file(s1, fd, off) < 0)
goto the_end;
++bound;
}
} while(bound);
ret = 0;
the_end:
- tcc_free(S, data);
+ tcc_free(data);
return ret;
}
/* load a '.a' file */
-ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte)
+ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte)
{
ArchiveHeader hdr;
/* char magic[8]; */
@@ -3259,7 +3262,7 @@ ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte)
if (len == 0)
return 0;
if (len < 0) {
- tcc_error_noabort(S, "invalid archive");
+ tcc_error_noabort("invalid archive");
return -1;
}
file_offset += len;
@@ -3269,13 +3272,13 @@ ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte)
if (alacarte) {
/* coff symbol table : we handle it */
if (!strcmp(hdr.ar_name, "/"))
- return tcc_load_alacarte(S, fd, size, 4);
+ return tcc_load_alacarte(s1, fd, size, 4);
if (!strcmp(hdr.ar_name, "/SYM64/"))
- return tcc_load_alacarte(S, fd, size, 8);
+ return tcc_load_alacarte(s1, fd, size, 8);
} else if (tcc_object_type(fd, &ehdr) == AFF_BINTYPE_REL) {
- if (S->verbose == 2)
+ if (s1->verbose == 2)
printf(" -> %s\n", hdr.ar_name);
- if (tcc_load_object_file(S, fd, file_offset) < 0)
+ if (tcc_load_object_file(s1, fd, file_offset) < 0)
return -1;
}
file_offset += size;
@@ -3285,10 +3288,10 @@ ST_FUNC int tcc_load_archive(TCCState *S, int fd, int alacarte)
#ifndef ELF_OBJ_ONLY
/* Set LV[I] to the global index of sym-version (LIB,VERSION). Maybe resizes
LV, maybe create a new entry for (LIB,VERSION). */
-static void set_ver_to_ver(TCCState *S, int *n, int **lv, int i, char *lib, char *version)
+static void set_ver_to_ver(TCCState *s1, int *n, int **lv, int i, char *lib, char *version)
{
while (i >= *n) {
- *lv = tcc_realloc(S, *lv, (*n + 1) * sizeof(**lv));
+ *lv = tcc_realloc(*lv, (*n + 1) * sizeof(**lv));
(*lv)[(*n)++] = -1;
}
if ((*lv)[i] == -1) {
@@ -3301,10 +3304,10 @@ static void set_ver_to_ver(TCCState *S, int *n, int **lv, int i, char *lib, char
break;
}
if (v == nb_sym_versions) {
- sym_versions = tcc_realloc (S, sym_versions,
+ sym_versions = tcc_realloc (sym_versions,
(v + 1) * sizeof(*sym_versions));
- sym_versions[v].lib = tcc_strdup(S, lib);
- sym_versions[v].version = tcc_strdup(S, version);
+ sym_versions[v].lib = tcc_strdup(lib);
+ sym_versions[v].version = tcc_strdup(version);
sym_versions[v].out_index = 0;
sym_versions[v].prev_same_lib = prev_same_lib;
nb_sym_versions++;
@@ -3316,11 +3319,11 @@ static void set_ver_to_ver(TCCState *S, int *n, int **lv, int i, char *lib, char
/* Associates symbol SYM_INDEX (in dynsymtab) with sym-version index
VERNDX. */
static void
-set_sym_version(TCCState *S, int sym_index, int verndx)
+set_sym_version(TCCState *s1, int sym_index, int verndx)
{
if (sym_index >= nb_sym_to_version) {
int newelems = sym_index ? sym_index * 2 : 1;
- sym_to_version = tcc_realloc(S, sym_to_version,
+ sym_to_version = tcc_realloc(sym_to_version,
newelems * sizeof(*sym_to_version));
memset(sym_to_version + nb_sym_to_version, -1,
(newelems - nb_sym_to_version) * sizeof(*sym_to_version));
@@ -3339,7 +3342,7 @@ struct versym_info {
};
-static void store_version(TCCState *S, struct versym_info *v, char *dynstr)
+static void store_version(TCCState *s1, struct versym_info *v, char *dynstr)
{
char *lib, *version;
uint32_t next;
@@ -3365,7 +3368,7 @@ static void store_version(TCCState *S, struct versym_info *v, char *dynstr)
if (lib == NULL)
lib = version;
else
- set_ver_to_ver(S, &v->nb_local_ver, &v->local_ver, vdef->vd_ndx,
+ set_ver_to_ver(s1, &v->nb_local_ver, &v->local_ver, vdef->vd_ndx,
lib, version);
#if DEBUG_VERSION
printf (" verdaux(%u): %s\n", vdef->vd_ndx, version);
@@ -3388,7 +3391,7 @@ static void store_version(TCCState *S, struct versym_info *v, char *dynstr)
for (i = 0; i < vneed->vn_cnt; i++) {
if ((vernaux->vna_other & 0x8000) == 0) { /* hidden */
version = dynstr + vernaux->vna_name;
- set_ver_to_ver(S, &v->nb_local_ver, &v->local_ver, vernaux->vna_other,
+ set_ver_to_ver(s1, &v->nb_local_ver, &v->local_ver, vernaux->vna_other,
lib, version);
#if DEBUG_VERSION
printf (" vernaux(%u): %u %u %s\n",
@@ -3417,7 +3420,7 @@ static void store_version(TCCState *S, struct versym_info *v, char *dynstr)
/* load a DLL and all referenced DLLs. 'level = 0' means that the DLL
is referenced by the user (so it should be added as DT_NEEDED in
the generated ELF file) */
-ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
+ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level)
{
ElfW(Ehdr) ehdr;
ElfW(Shdr) *shdr, *sh, *sh1;
@@ -3436,12 +3439,12 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
/* test CPU specific stuff */
if (ehdr.e_ident[5] != ELFDATA2LSB ||
ehdr.e_machine != EM_TCC_TARGET) {
- tcc_error_noabort(S, "bad architecture");
+ tcc_error_noabort("bad architecture");
return -1;
}
/* read sections */
- shdr = load_data(S, fd, ehdr.e_shoff, sizeof(ElfW(Shdr)) * ehdr.e_shnum);
+ shdr = load_data(fd, ehdr.e_shoff, sizeof(ElfW(Shdr)) * ehdr.e_shnum);
/* load dynamic section and dynamic symbols */
nb_syms = 0;
@@ -3455,23 +3458,23 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
switch(sh->sh_type) {
case SHT_DYNAMIC:
nb_dts = sh->sh_size / sizeof(ElfW(Dyn));
- dynamic = load_data(S, fd, sh->sh_offset, sh->sh_size);
+ dynamic = load_data(fd, sh->sh_offset, sh->sh_size);
break;
case SHT_DYNSYM:
nb_syms = sh->sh_size / sizeof(ElfW(Sym));
- dynsym = load_data(S, fd, sh->sh_offset, sh->sh_size);
+ dynsym = load_data(fd, sh->sh_offset, sh->sh_size);
sh1 = &shdr[sh->sh_link];
- dynstr = load_data(S, fd, sh1->sh_offset, sh1->sh_size);
+ dynstr = load_data(fd, sh1->sh_offset, sh1->sh_size);
break;
case SHT_GNU_verdef:
- v.verdef = load_data(S, fd, sh->sh_offset, sh->sh_size);
+ v.verdef = load_data(fd, sh->sh_offset, sh->sh_size);
break;
case SHT_GNU_verneed:
- v.verneed = load_data(S, fd, sh->sh_offset, sh->sh_size);
+ v.verneed = load_data(fd, sh->sh_offset, sh->sh_size);
break;
case SHT_GNU_versym:
v.nb_versyms = sh->sh_size / sizeof(ElfW(Half));
- v.versym = load_data(S, fd, sh->sh_offset, sh->sh_size);
+ v.versym = load_data(fd, sh->sh_offset, sh->sh_size);
break;
default:
break;
@@ -3488,8 +3491,8 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
}
/* if the dll is already loaded, do not load it */
- for(i = 0; i < S->nb_loaded_dlls; i++) {
- dllref = S->loaded_dlls[i];
+ for(i = 0; i < s1->nb_loaded_dlls; i++) {
+ dllref = s1->loaded_dlls[i];
if (!strcmp(soname, dllref->name)) {
/* but update level if needed */
if (level < dllref->level)
@@ -3500,12 +3503,12 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
}
if (v.nb_versyms != nb_syms)
- tcc_free (S, v.versym), v.versym = NULL;
+ tcc_free (v.versym), v.versym = NULL;
else
- store_version(S, &v, dynstr);
+ store_version(s1, &v, dynstr);
/* add the dll and its level */
- tcc_add_dllref(S, soname)->level = level;
+ tcc_add_dllref(s1, soname)->level = level;
/* add dynamic symbols in dynsym_section */
for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) {
@@ -3513,12 +3516,12 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
if (sym_bind == STB_LOCAL)
continue;
name = dynstr + sym->st_name;
- sym_index = set_elf_sym(S->dynsymtab_section, sym->st_value, sym->st_size,
+ sym_index = set_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,
sym->st_info, sym->st_other, sym->st_shndx, name);
if (v.versym) {
ElfW(Half) vsym = v.versym[i];
if ((vsym & 0x8000) == 0 && vsym > 0 && vsym < v.nb_local_ver)
- set_sym_version(S, sym_index, v.local_ver[vsym]);
+ set_sym_version(s1, sym_index, v.local_ver[vsym]);
}
}
@@ -3527,13 +3530,13 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
switch(dt->d_tag) {
case DT_NEEDED:
name = dynstr + dt->d_un.d_val;
- for(j = 0; j < S->nb_loaded_dlls; j++) {
- dllref = S->loaded_dlls[j];
+ for(j = 0; j < s1->nb_loaded_dlls; j++) {
+ dllref = s1->loaded_dlls[j];
if (!strcmp(name, dllref->name))
goto already_loaded;
}
- if (tcc_add_dll(S, name, AFF_REFERENCED_DLL) < 0) {
- tcc_error_noabort(S, "referenced dll '%s' not found", name);
+ if (tcc_add_dll(s1, name, AFF_REFERENCED_DLL) < 0) {
+ tcc_error_noabort("referenced dll '%s' not found", name);
ret = -1;
goto the_end;
}
@@ -3543,41 +3546,41 @@ ST_FUNC int tcc_load_dll(TCCState *S, int fd, const char *filename, int level)
}
ret = 0;
the_end:
- tcc_free(S, dynstr);
- tcc_free(S, dynsym);
- tcc_free(S, dynamic);
- tcc_free(S, shdr);
- tcc_free(S, v.local_ver);
- tcc_free(S, v.verdef);
- tcc_free(S, v.verneed);
- tcc_free(S, v.versym);
+ tcc_free(dynstr);
+ tcc_free(dynsym);
+ tcc_free(dynamic);
+ tcc_free(shdr);
+ tcc_free(v.local_ver);
+ tcc_free(v.verdef);
+ tcc_free(v.verneed);
+ tcc_free(v.versym);
return ret;
}
#define LD_TOK_NAME 256
#define LD_TOK_EOF (-1)
-static int ld_inp(TCCState *S)
+static int ld_inp(TCCState *s1)
{
char b;
- if (S->cc != -1) {
- int c = S->cc;
- S->cc = -1;
+ if (s1->cc != -1) {
+ int c = s1->cc;
+ s1->cc = -1;
return c;
}
- if (1 == read(S->fd, &b, 1))
+ if (1 == read(s1->fd, &b, 1))
return b;
return CH_EOF;
}
/* return next ld script token */
-static int ld_next(TCCState *S, char *name, int name_size)
+static int ld_next(TCCState *s1, char *name, int name_size)
{
int c, d, ch;
char *q;
redo:
- ch = ld_inp(S);
+ ch = ld_inp(s1);
switch(ch) {
case ' ':
case '\t':
@@ -3587,10 +3590,10 @@ static int ld_next(TCCState *S, char *name, int name_size)
case '\n':
goto redo;
case '/':
- ch = ld_inp(S);
+ ch = ld_inp(s1);
if (ch == '*') { /* comment */
for (d = 0;; d = ch) {
- ch = ld_inp(S);
+ ch = ld_inp(s1);
if (ch == CH_EOF || (ch == '/' && d == '*'))
break;
}
@@ -3671,9 +3674,9 @@ static int ld_next(TCCState *S, char *name, int name_size)
if ((q - name) < name_size - 1) {
*q++ = ch;
}
- ch = ld_inp(S);
+ ch = ld_inp(s1);
}
- S->cc = ch;
+ s1->cc = ch;
*q = '\0';
c = LD_TOK_NAME;
break;
@@ -3687,18 +3690,18 @@ static int ld_next(TCCState *S, char *name, int name_size)
return c;
}
-static int ld_add_file(TCCState *S, const char filename[])
+static int ld_add_file(TCCState *s1, const char filename[])
{
if (filename[0] == '/') {
if (CONFIG_SYSROOT[0] == '\0'
- && tcc_add_file_internal(S, filename, AFF_TYPE_BIN) == 0)
+ && tcc_add_file_internal(s1, filename, AFF_TYPE_BIN) == 0)
return 0;
filename = tcc_basename(filename);
}
- return tcc_add_dll(S, filename, 0);
+ return tcc_add_dll(s1, filename, 0);
}
-static int ld_add_file_list(TCCState *S, const char *cmd, int as_needed)
+static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
{
char filename[1024], libname[1024];
int t, group, nblibs = 0, ret = 0;
@@ -3706,109 +3709,109 @@ static int ld_add_file_list(TCCState *S, const char *cmd, int as_needed)
group = !strcmp(cmd, "GROUP");
if (!as_needed)
- S->new_undef_sym = 0;
- t = ld_next(S, filename, sizeof(filename));
+ s1->new_undef_sym = 0;
+ t = ld_next(s1, filename, sizeof(filename));
if (t != '(') {
- tcc_error_noabort(S, "( expected");
+ tcc_error_noabort("( expected");
ret = -1;
goto lib_parse_error;
}
- t = ld_next(S, filename, sizeof(filename));
+ t = ld_next(s1, filename, sizeof(filename));
for(;;) {
libname[0] = '\0';
if (t == LD_TOK_EOF) {
- tcc_error_noabort(S, "unexpected end of file");
+ tcc_error_noabort("unexpected end of file");
ret = -1;
goto lib_parse_error;
} else if (t == ')') {
break;
} else if (t == '-') {
- t = ld_next(S, filename, sizeof(filename));
+ t = ld_next(s1, filename, sizeof(filename));
if ((t != LD_TOK_NAME) || (filename[0] != 'l')) {
- tcc_error_noabort(S, "library name expected");
+ tcc_error_noabort("library name expected");
ret = -1;
goto lib_parse_error;
}
pstrcpy(libname, sizeof libname, &filename[1]);
- if (S->static_link) {
+ if (s1->static_link) {
snprintf(filename, sizeof filename, "lib%s.a", libname);
} else {
snprintf(filename, sizeof filename, "lib%s.so", libname);
}
} else if (t != LD_TOK_NAME) {
- tcc_error_noabort(S, "filename expected");
+ tcc_error_noabort("filename expected");
ret = -1;
goto lib_parse_error;
}
if (!strcmp(filename, "AS_NEEDED")) {
- ret = ld_add_file_list(S, cmd, 1);
+ ret = ld_add_file_list(s1, cmd, 1);
if (ret)
goto lib_parse_error;
} else {
/* TODO: Implement AS_NEEDED support. Ignore it for now */
if (!as_needed) {
- ret = ld_add_file(S, filename);
+ ret = ld_add_file(s1, filename);
if (ret)
goto lib_parse_error;
if (group) {
/* Add the filename *and* the libname to avoid future conversions */
- dynarray_add(S, &libs, &nblibs, tcc_strdup(S, filename));
+ dynarray_add(&libs, &nblibs, tcc_strdup(filename));
if (libname[0] != '\0')
- dynarray_add(S, &libs, &nblibs, tcc_strdup(S, libname));
+ dynarray_add(&libs, &nblibs, tcc_strdup(libname));
}
}
}
- t = ld_next(S, filename, sizeof(filename));
+ t = ld_next(s1, filename, sizeof(filename));
if (t == ',') {
- t = ld_next(S, filename, sizeof(filename));
+ t = ld_next(s1, filename, sizeof(filename));
}
}
if (group && !as_needed) {
- while (S->new_undef_sym) {
+ while (s1->new_undef_sym) {
int i;
- S->new_undef_sym = 0;
+ s1->new_undef_sym = 0;
for (i = 0; i < nblibs; i ++)
- ld_add_file(S, libs[i]);
+ ld_add_file(s1, libs[i]);
}
}
lib_parse_error:
- dynarray_reset(S, &libs, &nblibs);
+ dynarray_reset(&libs, &nblibs);
return ret;
}
/* interpret a subset of GNU ldscripts to handle the dummy libc.so
files */
-ST_FUNC int tcc_load_ldscript(TCCState *S, int fd)
+ST_FUNC int tcc_load_ldscript(TCCState *s1, int fd)
{
char cmd[64];
char filename[1024];
int t, ret;
- S->fd = fd;
- S->cc = -1;
+ s1->fd = fd;
+ s1->cc = -1;
for(;;) {
- t = ld_next(S, cmd, sizeof(cmd));
+ t = ld_next(s1, cmd, sizeof(cmd));
if (t == LD_TOK_EOF)
return 0;
else if (t != LD_TOK_NAME)
return -1;
if (!strcmp(cmd, "INPUT") ||
!strcmp(cmd, "GROUP")) {
- ret = ld_add_file_list(S, cmd, 0);
+ ret = ld_add_file_list(s1, cmd, 0);
if (ret)
return ret;
} else if (!strcmp(cmd, "OUTPUT_FORMAT") ||
!strcmp(cmd, "TARGET")) {
/* ignore some commands */
- t = ld_next(S, cmd, sizeof(cmd));
+ t = ld_next(s1, cmd, sizeof(cmd));
if (t != '(') {
- tcc_error_noabort(S, "( expected");
+ tcc_error_noabort("( expected");
return -1;
}
for(;;) {
- t = ld_next(S, filename, sizeof(filename));
+ t = ld_next(s1, filename, sizeof(filename));
if (t == LD_TOK_EOF) {
- tcc_error_noabort(S, "unexpected end of file");
+ tcc_error_noabort("unexpected end of file");
return -1;
} else if (t == ')') {
break;
diff --git a/tccgen.c b/tccgen.c
index c1fb291..e0b5fd6 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -29,32 +29,63 @@
rsym: return symbol
anon_sym: anonymous symbol index
*/
-//static SValue _vstack[1 + VSTACK_SIZE];
-#define vstack (S->tccgen__vstack + 1)
-
+ST_DATA int rsym, anon_sym, ind, loc;
+
+ST_DATA Sym *global_stack;
+ST_DATA Sym *local_stack;
+ST_DATA Sym *define_stack;
+ST_DATA Sym *global_label_stack;
+ST_DATA Sym *local_label_stack;
+
+static Sym *sym_free_first;
+static void **sym_pools;
+static int nb_sym_pools;
+
+static Sym *all_cleanups, *pending_gotos;
+static int local_scope;
+static int in_sizeof;
+static int in_generic;
+static int section_sym;
+ST_DATA char debug_modes;
+
+ST_DATA SValue *vtop;
+static SValue _vstack[1 + VSTACK_SIZE];
+#define vstack (_vstack + 1)
+
+ST_DATA int const_wanted; /* true if constant wanted */
+ST_DATA int nocode_wanted; /* no code generation wanted */
#define unevalmask 0xffff /* unevaluated subexpression */
-#define NODATA_WANTED (S->tccgen_nocode_wanted > 0) /* no static data output wanted either */
-#define STATIC_DATA_WANTED (S->tccgen_nocode_wanted & 0xC0000000) /* only static data output */
+#define NODATA_WANTED (nocode_wanted > 0) /* no static data output wanted either */
+#define STATIC_DATA_WANTED (nocode_wanted & 0xC0000000) /* only static data output */
/* Automagical code suppression ----> */
-#define CODE_OFF() (S->tccgen_nocode_wanted |= 0x20000000)
-#define CODE_ON() (S->tccgen_nocode_wanted &= ~0x20000000)
+#define CODE_OFF() (nocode_wanted |= 0x20000000)
+#define CODE_ON() (nocode_wanted &= ~0x20000000)
-static void tcc_tcov_block_begin(TCCState* S);
+static void tcc_tcov_block_begin(void);
/* Clear 'nocode_wanted' at label if it was used */
-ST_FUNC void gsym(TCCState* S, int t) { if (t) { gsym_addr(S, t, S->tccgen_ind); CODE_ON(); }}
-static int gind(TCCState* S) { int t = S->tccgen_ind; CODE_ON(); if (S->tccgen_debug_modes) tcc_tcov_block_begin(S); return t; }
+ST_FUNC void gsym(int t) { if (t) { gsym_addr(t, ind); CODE_ON(); }}
+static int gind(void) { int t = ind; CODE_ON(); if (debug_modes) tcc_tcov_block_begin(); return t; }
/* Set 'nocode_wanted' after unconditional jumps */
-static void gjmp_addr_acs(TCCState* S, int t) { gjmp_addr(S, t); CODE_OFF(); }
-static int gjmp_acs(TCCState* S, int t) { t = gjmp(S, t); CODE_OFF(); return t; }
+static void gjmp_addr_acs(int t) { gjmp_addr(t); CODE_OFF(); }
+static int gjmp_acs(int t) { t = gjmp(t); CODE_OFF(); return t; }
/* These are #undef'd at the end of this file */
#define gjmp_addr gjmp_addr_acs
#define gjmp gjmp_acs
/* <---- */
+ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
+ST_DATA CType func_vt; /* current function return type (used by return instruction) */
+ST_DATA int func_var; /* true if current function is variadic (used by return instruction) */
+ST_DATA int func_vc;
+static int last_line_num, new_file, func_ind; /* debug info control */
+ST_DATA const char *funcname;
+ST_DATA CType int_type, func_old_type, char_type, char_pointer_type;
+static CString initstr;
+
#if PTR_SIZE == 4
#define VT_SIZE_T (VT_INT | VT_UNSIGNED)
#define VT_PTRDIFF_T VT_INT
@@ -66,6 +97,35 @@ static int gjmp_acs(TCCState* S, int t) { t = gjmp(S, t); CODE_OFF(); return t;
#define VT_PTRDIFF_T (VT_LONG | VT_LLONG)
#endif
+static struct switch_t {
+ struct case_t {
+ int64_t v1, v2;
+ int sym;
+ } **p; int n; /* list of case ranges */
+ int def_sym; /* default symbol */
+ int *bsym;
+ struct scope *scope;
+ struct switch_t *prev;
+ SValue sv;
+} *cur_switch; /* current switch */
+
+#define MAX_TEMP_LOCAL_VARIABLE_NUMBER 8
+/*list of temporary local variables on the stack in current function. */
+static struct temp_local_variable {
+ int location; //offset on stack. Svalue.c.i
+ short size;
+ short align;
+} arr_temp_local_vars[MAX_TEMP_LOCAL_VARIABLE_NUMBER];
+static int nb_temp_local_vars;
+
+static struct scope {
+ struct scope *prev;
+ struct { int loc, locorig, num; } vla;
+ struct { Sym *s; int n; } cl;
+ int *bsym, *csym;
+ Sym *lstk, *llstk;
+} *cur_scope, *loop_scope, *root_scope;
+
typedef struct {
Section *sec;
int local_offset;
@@ -74,7 +134,7 @@ typedef struct {
#if 1
#define precedence_parser
-static void init_prec(TCCState* S);
+static void init_prec(void);
#endif
/********************************************************/
@@ -128,34 +188,65 @@ static const struct {
{ VT_VOID, "void:t27=27" },
};
+static int debug_next_type;
+
+static struct debug_hash {
+ int debug_type;
+ Sym *type;
+} *debug_hash;
+
+static int n_debug_hash;
+
+static struct debug_info {
+ int start;
+ int end;
+ int n_sym;
+ struct debug_sym {
+ int type;
+ unsigned long value;
+ char *str;
+ Section *sec;
+ int sym_index;
+ } *sym;
+ struct debug_info *child, *next, *last, *parent;
+} *debug_info, *debug_info_root;
+
+static struct {
+ unsigned long offset;
+ unsigned long last_file_name;
+ unsigned long last_func_name;
+ int ind;
+ int line;
+} tcov_data;
+
/********************************************************/
-static void gen_cast(TCCState* S, CType *type);
-static void gen_cast_s(TCCState* S, int t);
+static void gen_cast(CType *type);
+static void gen_cast_s(int t);
static inline CType *pointed_type(CType *type);
static int is_compatible_types(CType *type1, CType *type2);
-static int parse_btype(TCCState* S, CType *type, AttributeDef *ad);
-static CType *type_decl(TCCState* S, CType *type, AttributeDef *ad, int *v, int td);
-static void parse_expr_type(TCCState* S, CType *type);
-static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c);
-static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned long c, int flags);
-static void block(TCCState* S, int is_expr);
-static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
-static void decl(TCCState* S, int l);
-static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *);
-static void expr_eq(TCCState* S);
-static void vla_runtime_type_size(TCCState* S, CType *type, int *a);
+static int parse_btype(CType *type, AttributeDef *ad);
+static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td);
+static void parse_expr_type(CType *type);
+static void init_putv(init_params *p, CType *type, unsigned long c);
+static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags);
+static void block(int is_expr);
+static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, int has_init, int v, int scope);
+static void decl(int l);
+static int decl0(int l, int is_for_loop_init, Sym *);
+static void expr_eq(void);
+static void vla_runtime_type_size(CType *type, int *a);
static int is_compatible_unqualified_types(CType *type1, CType *type2);
-static inline int64_t expr_const64(TCCState* S);
-static void vpush64(TCCState* S, int ty, unsigned long long v);
-static void vpush(TCCState* S, CType *type);
-static int gvtst(TCCState* S, int inv, int t);
-static void gen_inline_functions(TCCState *S);
-static void free_inline_functions(TCCState *S);
-static void skip_or_save_block(TCCState* S, TokenString **str);
-static void gv_dup(TCCState* S);
-static int get_temp_local_var(TCCState* S, int size,int align);
+static inline int64_t expr_const64(void);
+static void vpush64(int ty, unsigned long long v);
+static void vpush(CType *type);
+static int gvtst(int inv, int t);
+static void gen_inline_functions(TCCState *s);
+static void free_inline_functions(TCCState *s);
+static void skip_or_save_block(TokenString **str);
+static void gv_dup(void);
+static int get_temp_local_var(int size,int align);
static void clear_temp_local_var_list();
-static void cast_error(TCCState* S, CType *st, CType *dt);
+static void cast_error(CType *st, CType *dt);
ST_INLN int is_float(int t)
{
@@ -284,17 +375,17 @@ ST_FUNC int ieee_finite(double d)
# define TCC_IS_NATIVE_387
#endif
-ST_FUNC void test_lvalue(TCCState* S)
+ST_FUNC void test_lvalue(void)
{
- if (!(S->tccgen_vtop->r & VT_LVAL))
- expect(S, "lvalue");
+ if (!(vtop->r & VT_LVAL))
+ expect("lvalue");
}
-ST_FUNC void check_vstack(TCCState* S)
+ST_FUNC void check_vstack(void)
{
- if (S->tccgen_vtop != vstack - 1)
- tcc_error(S, "internal compiler error: vstack leak (%d)",
- (int)(S->tccgen_vtop - vstack + 1));
+ if (vtop != vstack - 1)
+ tcc_error("internal compiler error: vstack leak (%d)",
+ (int)(vtop - vstack + 1));
}
/* ------------------------------------------------------------------------- */
@@ -305,7 +396,7 @@ void pv (const char *lbl, int a, int b)
{
int i;
for (i = a; i < a + b; ++i) {
- SValue *p = &S->tccgen_vtop[-i];
+ SValue *p = &vtop[-i];
printf("%s vtop[-%d] : type.t:%04x r:%04x r2:%04x c.i:%d\n",
lbl, i, p->type.t, p->r, p->r2, (int)p->c.i);
}
@@ -314,14 +405,14 @@ void pv (const char *lbl, int a, int b)
/* ------------------------------------------------------------------------- */
/* start of translation unit info */
-ST_FUNC void tcc_debug_start(TCCState *S)
+ST_FUNC void tcc_debug_start(TCCState *s1)
{
- if (S->do_debug) {
+ if (s1->do_debug) {
int i;
char buf[512];
/* file info: full path + filename */
- S->tccgen_section_sym = put_elf_sym(S, symtab_section, 0, 0,
+ section_sym = put_elf_sym(symtab_section, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
text_section->sh_num, NULL);
getcwd(buf, sizeof(buf));
@@ -329,154 +420,154 @@ ST_FUNC void tcc_debug_start(TCCState *S)
normalize_slashes(buf);
#endif
pstrcat(buf, sizeof(buf), "/");
- put_stabs_r(S, buf, N_SO, 0, 0,
- text_section->data_offset, text_section, S->tccgen_section_sym);
- put_stabs_r(S, S->tccpp_file->prev ? S->tccpp_file->prev->filename : S->tccpp_file->filename,
+ put_stabs_r(s1, buf, N_SO, 0, 0,
+ text_section->data_offset, text_section, section_sym);
+ put_stabs_r(s1, file->prev ? file->prev->filename : file->filename,
N_SO, 0, 0,
- text_section->data_offset, text_section, S->tccgen_section_sym);
+ text_section->data_offset, text_section, section_sym);
for (i = 0; i < sizeof (default_debug) / sizeof (default_debug[0]); i++)
- put_stabs(S, default_debug[i].name, N_LSYM, 0, 0, 0);
+ put_stabs(s1, default_debug[i].name, N_LSYM, 0, 0, 0);
- S->tccgen_new_file = S->tccgen_last_line_num = 0;
- S->tccgen_func_ind = -1;
- S->tccgen_debug_next_type = sizeof(default_debug) / sizeof(default_debug[0]);
- S->tccgen_debug_hash = NULL;
- S->tccgen_n_debug_hash = 0;
+ new_file = last_line_num = 0;
+ func_ind = -1;
+ debug_next_type = sizeof(default_debug) / sizeof(default_debug[0]);
+ debug_hash = NULL;
+ n_debug_hash = 0;
/* we're currently 'including' the <command line> */
- tcc_debug_bincl(S);
+ tcc_debug_bincl(s1);
}
/* an elf symbol of type STT_FILE must be put so that STB_LOCAL
symbols can be safely used */
- put_elf_sym(S, symtab_section, 0, 0,
+ put_elf_sym(symtab_section, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_FILE), 0,
- SHN_ABS, S->tccpp_file->filename);
+ SHN_ABS, file->filename);
}
/* put end of translation unit info */
-ST_FUNC void tcc_debug_end(TCCState *S)
+ST_FUNC void tcc_debug_end(TCCState *s1)
{
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- put_stabs_r(S, NULL, N_SO, 0, 0,
- text_section->data_offset, text_section, S->tccgen_section_sym);
- tcc_free(S, S->tccgen_debug_hash);
+ put_stabs_r(s1, NULL, N_SO, 0, 0,
+ text_section->data_offset, text_section, section_sym);
+ tcc_free(debug_hash);
}
-static BufferedFile* put_new_file(TCCState *S)
+static BufferedFile* put_new_file(TCCState *s1)
{
- BufferedFile *f = S->tccpp_file;
+ BufferedFile *f = file;
/* use upper file if from inline ":asm:" */
if (f->filename[0] == ':')
f = f->prev;
- if (f && S->tccgen_new_file) {
- put_stabs_r(S, f->filename, N_SOL, 0, 0, S->tccgen_ind, text_section, S->tccgen_section_sym);
- S->tccgen_new_file = S->tccgen_last_line_num = 0;
+ if (f && new_file) {
+ put_stabs_r(s1, f->filename, N_SOL, 0, 0, ind, text_section, section_sym);
+ new_file = last_line_num = 0;
}
return f;
}
/* put alternative filename */
-ST_FUNC void tcc_debug_putfile(TCCState *S, const char *filename)
+ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename)
{
- if (0 == strcmp(S->tccpp_file->filename, filename))
+ if (0 == strcmp(file->filename, filename))
return;
- pstrcpy(S->tccpp_file->filename, sizeof(S->tccpp_file->filename), filename);
- S->tccgen_new_file = 1;
+ pstrcpy(file->filename, sizeof(file->filename), filename);
+ new_file = 1;
}
/* begin of #include */
-ST_FUNC void tcc_debug_bincl(TCCState *S)
+ST_FUNC void tcc_debug_bincl(TCCState *s1)
{
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- put_stabs(S, S->tccpp_file->filename, N_BINCL, 0, 0, 0);
- S->tccgen_new_file = 1;
+ put_stabs(s1, file->filename, N_BINCL, 0, 0, 0);
+ new_file = 1;
}
/* end of #include */
-ST_FUNC void tcc_debug_eincl(TCCState *S)
+ST_FUNC void tcc_debug_eincl(TCCState *s1)
{
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- put_stabn(S, N_EINCL, 0, 0, 0);
- S->tccgen_new_file = 1;
+ put_stabn(s1, N_EINCL, 0, 0, 0);
+ new_file = 1;
}
/* generate line number info */
-static void tcc_debug_line(TCCState *S)
+static void tcc_debug_line(TCCState *s1)
{
BufferedFile *f;
- if (!S->do_debug
+ if (!s1->do_debug
|| cur_text_section != text_section
- || !(f = put_new_file(S))
- || S->tccgen_last_line_num == f->line_num)
+ || !(f = put_new_file(s1))
+ || last_line_num == f->line_num)
return;
- if (S->tccgen_func_ind != -1) {
- put_stabn(S, N_SLINE, 0, f->line_num, S->tccgen_ind - S->tccgen_func_ind);
+ if (func_ind != -1) {
+ put_stabn(s1, N_SLINE, 0, f->line_num, ind - func_ind);
} else {
/* from tcc_assemble */
- put_stabs_r(S, NULL, N_SLINE, 0, f->line_num, S->tccgen_ind, text_section, S->tccgen_section_sym);
+ put_stabs_r(s1, NULL, N_SLINE, 0, f->line_num, ind, text_section, section_sym);
}
- S->tccgen_last_line_num = f->line_num;
+ last_line_num = f->line_num;
}
-static void tcc_debug_stabs (TCCState *S, const char *str, int type, unsigned long value,
+static void tcc_debug_stabs (TCCState *s1, const char *str, int type, unsigned long value,
Section *sec, int sym_index)
{
struct debug_sym *s;
- if (S->tccgen_debug_info) {
- S->tccgen_debug_info->sym =
- (struct debug_sym *)tcc_realloc (S, S->tccgen_debug_info->sym,
+ if (debug_info) {
+ debug_info->sym =
+ (struct debug_sym *)tcc_realloc (debug_info->sym,
sizeof(struct debug_sym) *
- (S->tccgen_debug_info->n_sym + 1));
- s = S->tccgen_debug_info->sym + S->tccgen_debug_info->n_sym++;
+ (debug_info->n_sym + 1));
+ s = debug_info->sym + debug_info->n_sym++;
s->type = type;
s->value = value;
- s->str = tcc_strdup(S, str);
+ s->str = tcc_strdup(str);
s->sec = sec;
s->sym_index = sym_index;
}
else if (sec)
- put_stabs_r (S, str, type, 0, 0, value, sec, sym_index);
+ put_stabs_r (s1, str, type, 0, 0, value, sec, sym_index);
else
- put_stabs (S, str, type, 0, 0, value);
+ put_stabs (s1, str, type, 0, 0, value);
}
-static void tcc_debug_stabn(TCCState *S, int type, int value)
+static void tcc_debug_stabn(TCCState *s1, int type, int value)
{
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
if (type == N_LBRAC) {
- debug_info_t *info =
- (debug_info_t *) tcc_mallocz(S, sizeof (*info));
+ struct debug_info *info =
+ (struct debug_info *) tcc_mallocz(sizeof (*info));
info->start = value;
- info->parent = S->tccgen_debug_info;
- if (S->tccgen_debug_info) {
- if (S->tccgen_debug_info->child) {
- if (S->tccgen_debug_info->child->last)
- S->tccgen_debug_info->child->last->next = info;
+ info->parent = debug_info;
+ if (debug_info) {
+ if (debug_info->child) {
+ if (debug_info->child->last)
+ debug_info->child->last->next = info;
else
- S->tccgen_debug_info->child->next = info;
- S->tccgen_debug_info->child->last = info;
+ debug_info->child->next = info;
+ debug_info->child->last = info;
}
else
- S->tccgen_debug_info->child = info;
+ debug_info->child = info;
}
else
- S->tccgen_debug_info_root = info;
- S->tccgen_debug_info = info;
+ debug_info_root = info;
+ debug_info = info;
}
else {
- S->tccgen_debug_info->end = value;
- S->tccgen_debug_info = S->tccgen_debug_info->parent;
+ debug_info->end = value;
+ debug_info = debug_info->parent;
}
}
-static void tcc_get_debug_info(TCCState *S, Sym *s, CString *result)
+static void tcc_get_debug_info(TCCState *s1, Sym *s, CString *result)
{
int type;
int n = 0;
@@ -497,23 +588,23 @@ static void tcc_get_debug_info(TCCState *S, Sym *s, CString *result)
int i;
t = t->type.ref;
- for (i = 0; i < S->tccgen_n_debug_hash; i++) {
- if (t == S->tccgen_debug_hash[i].type) {
- debug_type = S->tccgen_debug_hash[i].debug_type;
+ for (i = 0; i < n_debug_hash; i++) {
+ if (t == debug_hash[i].type) {
+ debug_type = debug_hash[i].debug_type;
break;
}
}
if (debug_type == -1) {
- debug_type = ++S->tccgen_debug_next_type;
- S->tccgen_debug_hash = (debug_hash_t *)
- tcc_realloc (S, S->tccgen_debug_hash,
- (S->tccgen_n_debug_hash + 1) * sizeof(*S->tccgen_debug_hash));
- S->tccgen_debug_hash[S->tccgen_n_debug_hash].debug_type = debug_type;
- S->tccgen_debug_hash[S->tccgen_n_debug_hash++].type = t;
- cstr_new (S, &str);
- cstr_printf (S, &str, "%s:T%d=%c%d",
+ debug_type = ++debug_next_type;
+ debug_hash = (struct debug_hash *)
+ tcc_realloc (debug_hash,
+ (n_debug_hash + 1) * sizeof(*debug_hash));
+ debug_hash[n_debug_hash].debug_type = debug_type;
+ debug_hash[n_debug_hash++].type = t;
+ cstr_new (&str);
+ cstr_printf (&str, "%s:T%d=%c%d",
(t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
- ? "" : get_tok_str(S, t->v & ~SYM_STRUCT, NULL),
+ ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL),
debug_type,
IS_UNION (t->type.t) ? 'u' : 's',
t->c);
@@ -521,10 +612,10 @@ static void tcc_get_debug_info(TCCState *S, Sym *s, CString *result)
int pos, size, align;
t = t->next;
- cstr_printf (S, &str, "%s:",
+ cstr_printf (&str, "%s:",
(t->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
- ? "" : get_tok_str(S, t->v & ~SYM_FIELD, NULL));
- tcc_get_debug_info (S, t, &str);
+ ? "" : get_tok_str(t->v & ~SYM_FIELD, NULL));
+ tcc_get_debug_info (s1, t, &str);
if (t->type.t & VT_BITFIELD) {
pos = t->c * 8 + BIT_POS(t->type.t);
size = BIT_SIZE(t->type.t);
@@ -533,33 +624,33 @@ static void tcc_get_debug_info(TCCState *S, Sym *s, CString *result)
pos = t->c * 8;
size = type_size(&t->type, &align) * 8;
}
- cstr_printf (S, &str, ",%d,%d;", pos, size);
+ cstr_printf (&str, ",%d,%d;", pos, size);
}
- cstr_printf (S, &str, ";");
- tcc_debug_stabs(S, str.data, N_LSYM, 0, NULL, 0);
- cstr_free (S, &str);
+ cstr_printf (&str, ";");
+ tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0);
+ cstr_free (&str);
}
}
else if (IS_ENUM(type)) {
Sym *e = t = t->type.ref;
- debug_type = ++S->tccgen_debug_next_type;
- cstr_new (S, &str);
- cstr_printf (S, &str, "%s:T%d=e",
+ debug_type = ++debug_next_type;
+ cstr_new (&str);
+ cstr_printf (&str, "%s:T%d=e",
(t->v & ~SYM_STRUCT) >= SYM_FIRST_ANOM
- ? "" : get_tok_str(S, t->v & ~SYM_STRUCT, NULL),
+ ? "" : get_tok_str(t->v & ~SYM_STRUCT, NULL),
debug_type);
while (t->next) {
t = t->next;
- cstr_printf (S, &str, "%s:",
+ cstr_printf (&str, "%s:",
(t->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
- ? "" : get_tok_str(S, t->v & ~SYM_FIELD, NULL));
- cstr_printf (S, &str, e->type.t & VT_UNSIGNED ? "%u," : "%d,",
+ ? "" : get_tok_str(t->v & ~SYM_FIELD, NULL));
+ cstr_printf (&str, e->type.t & VT_UNSIGNED ? "%u," : "%d,",
(int)t->enum_val);
}
- cstr_printf (S, &str, ";");
- tcc_debug_stabs(S, str.data, N_LSYM, 0, NULL, 0);
- cstr_free (S, &str);
+ cstr_printf (&str, ";");
+ tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0);
+ cstr_free (&str);
}
else if ((type & VT_BTYPE) != VT_FUNC) {
type &= ~VT_STRUCT_MASK;
@@ -572,211 +663,211 @@ static void tcc_get_debug_info(TCCState *S, Sym *s, CString *result)
return;
}
if (n > 0)
- cstr_printf (S, result, "%d=", ++S->tccgen_debug_next_type);
+ cstr_printf (result, "%d=", ++debug_next_type);
t = s;
for (;;) {
type = t->type.t & ~(VT_STORAGE | VT_CONSTANT | VT_VOLATILE);
if ((type & VT_BTYPE) != VT_BYTE)
type &= ~VT_DEFSIGN;
if (type == VT_PTR)
- cstr_printf (S, result, "%d=*", ++S->tccgen_debug_next_type);
+ cstr_printf (result, "%d=*", ++debug_next_type);
else if (type == (VT_PTR | VT_ARRAY))
- cstr_printf (S, result, "%d=ar1;0;%d;",
- ++S->tccgen_debug_next_type, t->type.ref->c - 1);
+ cstr_printf (result, "%d=ar1;0;%d;",
+ ++debug_next_type, t->type.ref->c - 1);
else if (type == VT_FUNC) {
- cstr_printf (S, result, "%d=f", ++S->tccgen_debug_next_type);
- tcc_get_debug_info (S, t->type.ref, result);
+ cstr_printf (result, "%d=f", ++debug_next_type);
+ tcc_get_debug_info (s1, t->type.ref, result);
return;
}
else
break;
t = t->type.ref;
}
- cstr_printf (S, result, "%d", debug_type);
+ cstr_printf (result, "%d", debug_type);
}
-static void tcc_debug_finish (TCCState *S, debug_info_t *cur)
+static void tcc_debug_finish (TCCState *s1, struct debug_info *cur)
{
while (cur) {
int i;
- debug_info_t *next = cur->next;
+ struct debug_info *next = cur->next;
for (i = 0; i < cur->n_sym; i++) {
struct debug_sym *s = &cur->sym[i];
if (s->sec)
- put_stabs_r(S, s->str, s->type, 0, 0, s->value,
+ put_stabs_r(s1, s->str, s->type, 0, 0, s->value,
s->sec, s->sym_index);
else
- put_stabs(S, s->str, s->type, 0, 0, s->value);
- tcc_free (S, s->str);
- }
- tcc_free (S, cur->sym);
- put_stabn(S, N_LBRAC, 0, 0, cur->start);
- tcc_debug_finish (S, cur->child);
- put_stabn(S, N_RBRAC, 0, 0, cur->end);
- tcc_free (S, cur);
+ put_stabs(s1, s->str, s->type, 0, 0, s->value);
+ tcc_free (s->str);
+ }
+ tcc_free (cur->sym);
+ put_stabn(s1, N_LBRAC, 0, 0, cur->start);
+ tcc_debug_finish (s1, cur->child);
+ put_stabn(s1, N_RBRAC, 0, 0, cur->end);
+ tcc_free (cur);
cur = next;
}
}
-static void tcc_add_debug_info(TCCState *S, int param, Sym *s, Sym *e)
+static void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e)
{
CString debug_str;
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- cstr_new (S, &debug_str);
+ cstr_new (&debug_str);
for (; s != e; s = s->prev) {
if (!s->v || (s->r & VT_VALMASK) != VT_LOCAL)
continue;
cstr_reset (&debug_str);
- cstr_printf (S, &debug_str, "%s:%s", get_tok_str(S, s->v, NULL), param ? "p" : "");
- tcc_get_debug_info(S, s, &debug_str);
- tcc_debug_stabs(S, debug_str.data, param ? N_PSYM : N_LSYM, s->c, NULL, 0);
+ cstr_printf (&debug_str, "%s:%s", get_tok_str(s->v, NULL), param ? "p" : "");
+ tcc_get_debug_info(s1, s, &debug_str);
+ tcc_debug_stabs(s1, debug_str.data, param ? N_PSYM : N_LSYM, s->c, NULL, 0);
}
- cstr_free (S, &debug_str);
+ cstr_free (&debug_str);
}
/* put function symbol */
-static void tcc_debug_funcstart(TCCState *S, Sym *sym)
+static void tcc_debug_funcstart(TCCState *s1, Sym *sym)
{
CString debug_str;
BufferedFile *f;
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- S->tccgen_debug_info_root = NULL;
- S->tccgen_debug_info = NULL;
- tcc_debug_stabn(S, N_LBRAC, S->tccgen_ind - S->tccgen_func_ind);
- if (!(f = put_new_file(S)))
+ debug_info_root = NULL;
+ debug_info = NULL;
+ tcc_debug_stabn(s1, N_LBRAC, ind - func_ind);
+ if (!(f = put_new_file(s1)))
return;
- cstr_new (S, &debug_str);
- cstr_printf(S, &debug_str, "%s:%c", S->tccgen_funcname, sym->type.t & VT_STATIC ? 'f' : 'F');
- tcc_get_debug_info(S, sym->type.ref, &debug_str);
- put_stabs_r(S, debug_str.data, N_FUN, 0, f->line_num, 0, cur_text_section, sym->c);
- cstr_free (S, &debug_str);
+ cstr_new (&debug_str);
+ cstr_printf(&debug_str, "%s:%c", funcname, sym->type.t & VT_STATIC ? 'f' : 'F');
+ tcc_get_debug_info(s1, sym->type.ref, &debug_str);
+ put_stabs_r(s1, debug_str.data, N_FUN, 0, f->line_num, 0, cur_text_section, sym->c);
+ cstr_free (&debug_str);
- tcc_debug_line(S);
+ tcc_debug_line(s1);
}
/* put function size */
-static void tcc_debug_funcend(TCCState *S, int size)
+static void tcc_debug_funcend(TCCState *s1, int size)
{
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- tcc_debug_stabn(S, N_RBRAC, size);
- tcc_debug_finish (S, S->tccgen_debug_info_root);
+ tcc_debug_stabn(s1, N_RBRAC, size);
+ tcc_debug_finish (s1, debug_info_root);
}
-static void tcc_debug_extern_sym(TCCState *S, Sym *sym, int sh_num, int sym_bind, int sym_type)
+static void tcc_debug_extern_sym(TCCState *s1, Sym *sym, int sh_num, int sym_bind, int sym_type)
{
Section *s;
CString str;
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
if (sym_type == STT_FUNC || sym->v >= SYM_FIRST_ANOM)
return;
- s = S->sections[sh_num];
+ s = s1->sections[sh_num];
- cstr_new (S, &str);
- cstr_printf (S, &str, "%s:%c",
- get_tok_str(S, sym->v, NULL),
- sym_bind == STB_GLOBAL ? 'G' : S->tccgen_local_scope ? 'V' : 'S'
+ cstr_new (&str);
+ cstr_printf (&str, "%s:%c",
+ get_tok_str(sym->v, NULL),
+ sym_bind == STB_GLOBAL ? 'G' : local_scope ? 'V' : 'S'
);
- tcc_get_debug_info(S, sym, &str);
+ tcc_get_debug_info(s1, sym, &str);
if (sym_bind == STB_GLOBAL)
- tcc_debug_stabs(S, str.data, N_GSYM, 0, NULL, 0);
+ tcc_debug_stabs(s1, str.data, N_GSYM, 0, NULL, 0);
else
- tcc_debug_stabs(S, str.data,
+ tcc_debug_stabs(s1, str.data,
(sym->type.t & VT_STATIC) && data_section == s
? N_STSYM : N_LCSYM, 0, s, sym->c);
- cstr_free (S, &str);
+ cstr_free (&str);
}
-static void tcc_debug_typedef(TCCState *S, Sym *sym)
+static void tcc_debug_typedef(TCCState *s1, Sym *sym)
{
CString str;
- if (!S->do_debug)
+ if (!s1->do_debug)
return;
- cstr_new (S, &str);
- cstr_printf (S, &str, "%s:t",
+ cstr_new (&str);
+ cstr_printf (&str, "%s:t",
(sym->v & ~SYM_FIELD) >= SYM_FIRST_ANOM
- ? "" : get_tok_str(S, sym->v & ~SYM_FIELD, NULL));
- tcc_get_debug_info(S, sym, &str);
- tcc_debug_stabs(S, str.data, N_LSYM, 0, NULL, 0);
- cstr_free (S, &str);
+ ? "" : get_tok_str(sym->v & ~SYM_FIELD, NULL));
+ tcc_get_debug_info(s1, sym, &str);
+ tcc_debug_stabs(s1, str.data, N_LSYM, 0, NULL, 0);
+ cstr_free (&str);
}
/* ------------------------------------------------------------------------- */
/* for section layout see lib/tcov.c */
-static void tcc_tcov_block_end(TCCState* S, int line);
+static void tcc_tcov_block_end(int line);
-static void tcc_tcov_block_begin(TCCState* S)
+static void tcc_tcov_block_begin(void)
{
SValue sv;
void *ptr;
- unsigned long last_offset = S->tccgen_tcov_data.offset;
+ unsigned long last_offset = tcov_data.offset;
- tcc_tcov_block_end (S, 0);
- if (S->test_coverage == 0 || S->tccgen_nocode_wanted)
+ tcc_tcov_block_end (0);
+ if (tcc_state->test_coverage == 0 || nocode_wanted)
return;
- if (S->tccgen_tcov_data.last_file_name == 0 ||
- strcmp ((const char *)(tcov_section->data + S->tccgen_tcov_data.last_file_name),
- S->tccpp_file->true_filename) != 0) {
+ if (tcov_data.last_file_name == 0 ||
+ strcmp ((const char *)(tcov_section->data + tcov_data.last_file_name),
+ file->true_filename) != 0) {
char wd[1024];
CString cstr;
- if (S->tccgen_tcov_data.last_func_name)
- section_ptr_add(S, tcov_section, 1);
- if (S->tccgen_tcov_data.last_file_name)
- section_ptr_add(S, tcov_section, 1);
- S->tccgen_tcov_data.last_func_name = 0;
- cstr_new (S, &cstr);
- if (S->tccpp_file->true_filename[0] == '/') {
- S->tccgen_tcov_data.last_file_name = tcov_section->data_offset;
- cstr_printf (S, &cstr, "%s", S->tccpp_file->true_filename);
+ if (tcov_data.last_func_name)
+ section_ptr_add(tcov_section, 1);
+ if (tcov_data.last_file_name)
+ section_ptr_add(tcov_section, 1);
+ tcov_data.last_func_name = 0;
+ cstr_new (&cstr);
+ if (file->true_filename[0] == '/') {
+ tcov_data.last_file_name = tcov_section->data_offset;
+ cstr_printf (&cstr, "%s", file->true_filename);
}
else {
getcwd (wd, sizeof(wd));
- S->tccgen_tcov_data.last_file_name = tcov_section->data_offset + strlen(wd) + 1;
- cstr_printf (S, &cstr, "%s/%s", wd, S->tccpp_file->true_filename);
+ tcov_data.last_file_name = tcov_section->data_offset + strlen(wd) + 1;
+ cstr_printf (&cstr, "%s/%s", wd, file->true_filename);
}
- ptr = section_ptr_add(S, tcov_section, cstr.size + 1);
+ ptr = section_ptr_add(tcov_section, cstr.size + 1);
strcpy((char *)ptr, cstr.data);
#ifdef _WIN32
normalize_slashes((char *)ptr);
#endif
- cstr_free (S, &cstr);
+ cstr_free (&cstr);
}
- if (S->tccgen_tcov_data.last_func_name == 0 ||
- strcmp ((const char *)(tcov_section->data + S->tccgen_tcov_data.last_func_name),
- S->tccgen_funcname) != 0) {
+ if (tcov_data.last_func_name == 0 ||
+ strcmp ((const char *)(tcov_section->data + tcov_data.last_func_name),
+ funcname) != 0) {
size_t len;
- if (S->tccgen_tcov_data.last_func_name)
- section_ptr_add(S, tcov_section, 1);
- S->tccgen_tcov_data.last_func_name = tcov_section->data_offset;
- len = strlen (S->tccgen_funcname);
- ptr = section_ptr_add(S, tcov_section, len + 1);
- strcpy((char *)ptr, S->tccgen_funcname);
- section_ptr_add(S, tcov_section, -tcov_section->data_offset & 7);
- ptr = section_ptr_add(S, tcov_section, 8);
- write64le (ptr, S->tccpp_file->line_num);
- }
- if (S->tccgen_ind == S->tccgen_tcov_data.ind && S->tccgen_tcov_data.line == S->tccpp_file->line_num)
- S->tccgen_tcov_data.offset = last_offset;
+ if (tcov_data.last_func_name)
+ section_ptr_add(tcov_section, 1);
+ tcov_data.last_func_name = tcov_section->data_offset;
+ len = strlen (funcname);
+ ptr = section_ptr_add(tcov_section, len + 1);
+ strcpy((char *)ptr, funcname);
+ section_ptr_add(tcov_section, -tcov_section->data_offset & 7);
+ ptr = section_ptr_add(tcov_section, 8);
+ write64le (ptr, file->line_num);
+ }
+ if (ind == tcov_data.ind && tcov_data.line == file->line_num)
+ tcov_data.offset = last_offset;
else {
Sym label = {0};
label.type.t = VT_LLONG | VT_STATIC;
- ptr = section_ptr_add(S, tcov_section, 16);
- S->tccgen_tcov_data.line = S->tccpp_file->line_num;
- write64le (ptr, (S->tccgen_tcov_data.line << 8) | 0xff);
- put_extern_sym(S, &label, tcov_section,
+ ptr = section_ptr_add(tcov_section, 16);
+ tcov_data.line = file->line_num;
+ write64le (ptr, (tcov_data.line << 8) | 0xff);
+ put_extern_sym(&label, tcov_section,
((unsigned char *)ptr - tcov_section->data) + 8, 0);
sv.type = label.type;
sv.r = VT_SYM | VT_LVAL | VT_CONST;
@@ -786,138 +877,138 @@ static void tcc_tcov_block_begin(TCCState* S)
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || \
defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 || \
defined TCC_TARGET_RISCV64
- gen_increment_tcov (S, &sv);
+ gen_increment_tcov (&sv);
#else
- vpushv(S, &sv);
- inc(S, 0, TOK_INC);
- vpop(S);
+ vpushv(&sv);
+ inc(0, TOK_INC);
+ vpop();
#endif
- S->tccgen_tcov_data.offset = (unsigned char *)ptr - tcov_section->data;
- S->tccgen_tcov_data.ind = S->tccgen_ind;
+ tcov_data.offset = (unsigned char *)ptr - tcov_section->data;
+ tcov_data.ind = ind;
}
}
-static void tcc_tcov_block_end(TCCState* S, int line)
+static void tcc_tcov_block_end(int line)
{
- if (S->test_coverage == 0)
+ if (tcc_state->test_coverage == 0)
return;
- if (S->tccgen_tcov_data.offset) {
- void *ptr = tcov_section->data + S->tccgen_tcov_data.offset;
- unsigned long long nline = line ? line : S->tccpp_file->line_num;
+ if (tcov_data.offset) {
+ void *ptr = tcov_section->data + tcov_data.offset;
+ unsigned long long nline = line ? line : file->line_num;
write64le (ptr, (read64le (ptr) & 0xfffffffffull) | (nline << 36));
- S->tccgen_tcov_data.offset = 0;
+ tcov_data.offset = 0;
}
}
-static void tcc_tcov_check_line(TCCState* S, int start)
+static void tcc_tcov_check_line(int start)
{
- if (S->test_coverage == 0)
+ if (tcc_state->test_coverage == 0)
return;
- if (S->tccgen_tcov_data.line != S->tccpp_file->line_num) {
- if ((S->tccgen_tcov_data.line + 1) != S->tccpp_file->line_num) {
- tcc_tcov_block_end (S, S->tccgen_tcov_data.line);
+ if (tcov_data.line != file->line_num) {
+ if ((tcov_data.line + 1) != file->line_num) {
+ tcc_tcov_block_end (tcov_data.line);
if (start)
- tcc_tcov_block_begin (S);
+ tcc_tcov_block_begin ();
}
else
- S->tccgen_tcov_data.line = S->tccpp_file->line_num;
+ tcov_data.line = file->line_num;
}
}
-static void tcc_tcov_start(TCCState* S)
+static void tcc_tcov_start(void)
{
- if (S->test_coverage == 0)
+ if (tcc_state->test_coverage == 0)
return;
- memset (&S->tccgen_tcov_data, 0, sizeof (S->tccgen_tcov_data));
+ memset (&tcov_data, 0, sizeof (tcov_data));
if (tcov_section == NULL) {
- tcov_section = new_section(S, ".tcov", SHT_PROGBITS,
+ tcov_section = new_section(tcc_state, ".tcov", SHT_PROGBITS,
SHF_ALLOC | SHF_WRITE);
- section_ptr_add(S, tcov_section, 4); // pointer to executable name
+ section_ptr_add(tcov_section, 4); // pointer to executable name
}
}
-static void tcc_tcov_end(TCCState* S)
+static void tcc_tcov_end(void)
{
- if (S->test_coverage == 0)
+ if (tcc_state->test_coverage == 0)
return;
- if (S->tccgen_tcov_data.last_func_name)
- section_ptr_add(S, tcov_section, 1);
- if (S->tccgen_tcov_data.last_file_name)
- section_ptr_add(S, tcov_section, 1);
+ if (tcov_data.last_func_name)
+ section_ptr_add(tcov_section, 1);
+ if (tcov_data.last_file_name)
+ section_ptr_add(tcov_section, 1);
}
/* ------------------------------------------------------------------------- */
/* initialize vstack and types. This must be done also for tcc -E */
-ST_FUNC void tccgen_init(TCCState *S)
+ST_FUNC void tccgen_init(TCCState *s1)
{
- S->tccgen_vtop = vstack - 1;
- memset(S->tccgen_vtop, 0, sizeof *S->tccgen_vtop);
+ vtop = vstack - 1;
+ memset(vtop, 0, sizeof *vtop);
/* define some often used types */
- S->tccgen_int_type.t = VT_INT;
-
- S->tccgen_char_type.t = VT_BYTE;
- if (S->char_is_unsigned)
- S->tccgen_char_type.t |= VT_UNSIGNED;
- S->tccgen_char_pointer_type = S->tccgen_char_type;
- mk_pointer(S, &S->tccgen_char_pointer_type);
-
- S->tccgen_func_old_type.t = VT_FUNC;
- S->tccgen_func_old_type.ref = sym_push(S, SYM_FIELD, &S->tccgen_int_type, 0, 0);
- S->tccgen_func_old_type.ref->f.func_call = FUNC_CDECL;
- S->tccgen_func_old_type.ref->f.func_type = FUNC_OLD;
+ int_type.t = VT_INT;
+
+ char_type.t = VT_BYTE;
+ if (s1->char_is_unsigned)
+ char_type.t |= VT_UNSIGNED;
+ char_pointer_type = char_type;
+ mk_pointer(&char_pointer_type);
+
+ func_old_type.t = VT_FUNC;
+ func_old_type.ref = sym_push(SYM_FIELD, &int_type, 0, 0);
+ func_old_type.ref->f.func_call = FUNC_CDECL;
+ func_old_type.ref->f.func_type = FUNC_OLD;
#ifdef precedence_parser
- init_prec(S);
+ init_prec();
#endif
- cstr_new(S, &S->tccgen_initstr);
+ cstr_new(&initstr);
}
-ST_FUNC int tccgen_compile(TCCState *S)
+ST_FUNC int tccgen_compile(TCCState *s1)
{
cur_text_section = NULL;
- S->tccgen_funcname = "";
- S->tccgen_anon_sym = SYM_FIRST_ANOM;
- S->tccgen_section_sym = 0;
- S->tccgen_const_wanted = 0;
- S->tccgen_nocode_wanted = 0x80000000;
- S->tccgen_local_scope = 0;
- S->tccgen_debug_modes = S->do_debug | S->test_coverage << 1;
-
- tcc_debug_start(S);
- tcc_tcov_start (S);
+ funcname = "";
+ anon_sym = SYM_FIRST_ANOM;
+ section_sym = 0;
+ const_wanted = 0;
+ nocode_wanted = 0x80000000;
+ local_scope = 0;
+ debug_modes = s1->do_debug | s1->test_coverage << 1;
+
+ tcc_debug_start(s1);
+ tcc_tcov_start ();
#ifdef TCC_TARGET_ARM
- arm_init(S);
+ arm_init(s1);
#endif
#ifdef INC_DEBUG
printf("%s: **** new file\n", file->filename);
#endif
- S->tccpp_parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR;
- next(S);
- decl(S, VT_CONST);
- gen_inline_functions(S);
- check_vstack(S);
+ parse_flags = PARSE_FLAG_PREPROCESS | PARSE_FLAG_TOK_NUM | PARSE_FLAG_TOK_STR;
+ next();
+ decl(VT_CONST);
+ gen_inline_functions(s1);
+ check_vstack();
/* end of translation unit info */
- tcc_debug_end(S);
- tcc_tcov_end (S);
+ tcc_debug_end(s1);
+ tcc_tcov_end ();
return 0;
}
-ST_FUNC void tccgen_finish(TCCState *S)
+ST_FUNC void tccgen_finish(TCCState *s1)
{
- cstr_free(S, &S->tccgen_initstr);
- free_inline_functions(S);
- sym_pop(S, &S->tccgen_global_stack, NULL, 0);
- sym_pop(S, &S->tccgen_local_stack, NULL, 0);
+ cstr_free(&initstr);
+ free_inline_functions(s1);
+ sym_pop(&global_stack, NULL, 0);
+ sym_pop(&local_stack, NULL, 0);
/* free preprocessor macros */
- free_defines(S, NULL);
+ free_defines(NULL);
/* free sym_pools */
- dynarray_reset(S, &S->tccgen_sym_pools, &S->tccgen_nb_sym_pools);
- S->tccgen_sym_free_first = NULL;
+ dynarray_reset(&sym_pools, &nb_sym_pools);
+ sym_free_first = NULL;
}
/* ------------------------------------------------------------------------- */
-ST_FUNC ElfSym *elfsym(TCCState* S, Sym *s)
+ST_FUNC ElfSym *elfsym(Sym *s)
{
if (!s || !s->c)
return NULL;
@@ -925,12 +1016,12 @@ ST_FUNC ElfSym *elfsym(TCCState* S, Sym *s)
}
/* apply storage attributes to Elf symbol */
-ST_FUNC void update_storage(TCCState* S, Sym *sym)
+ST_FUNC void update_storage(Sym *sym)
{
ElfSym *esym;
int sym_bind, old_sym_bind;
- esym = elfsym(S, sym);
+ esym = elfsym(sym);
if (!esym)
return;
@@ -958,7 +1049,7 @@ ST_FUNC void update_storage(TCCState* S, Sym *sym)
#if 0
printf("storage %s: bind=%c vis=%d exp=%d imp=%d\n",
- get_tok_str(S, sym->v, NULL),
+ get_tok_str(sym->v, NULL),
sym_bind == STB_WEAK ? 'w' : sym_bind == STB_LOCAL ? 'l' : 'g',
sym->a.visibility,
sym->a.dllexport,
@@ -971,7 +1062,7 @@ ST_FUNC void update_storage(TCCState* S, Sym *sym)
/* update sym->c so that it points to an external symbol in section
'section' with value 'value' */
-ST_FUNC void put_extern_sym2(TCCState* S, Sym *sym, int sh_num,
+ST_FUNC void put_extern_sym2(Sym *sym, int sh_num,
addr_t value, unsigned long size,
int can_add_underscore)
{
@@ -981,7 +1072,7 @@ ST_FUNC void put_extern_sym2(TCCState* S, Sym *sym, int sh_num,
char buf1[256];
if (!sym->c) {
- name = get_tok_str(S, sym->v, NULL);
+ name = get_tok_str(sym->v, NULL);
t = sym->type.t;
if ((t & VT_BTYPE) == VT_FUNC) {
sym_type = STT_FUNC;
@@ -1014,50 +1105,50 @@ ST_FUNC void put_extern_sym2(TCCState* S, Sym *sym, int sh_num,
#endif
if (sym->asm_label) {
- name = get_tok_str(S, sym->asm_label, NULL);
+ name = get_tok_str(sym->asm_label, NULL);
can_add_underscore = 0;
}
- if (S->leading_underscore && can_add_underscore) {
+ if (tcc_state->leading_underscore && can_add_underscore) {
buf1[0] = '_';
pstrcpy(buf1 + 1, sizeof(buf1) - 1, name);
name = buf1;
}
info = ELFW(ST_INFO)(sym_bind, sym_type);
- sym->c = put_elf_sym(S, symtab_section, value, size, info, other, sh_num, name);
+ sym->c = put_elf_sym(symtab_section, value, size, info, other, sh_num, name);
- if (S->tccgen_debug_modes)
- tcc_debug_extern_sym(S, sym, sh_num, sym_bind, sym_type);
+ if (debug_modes)
+ tcc_debug_extern_sym(tcc_state, sym, sh_num, sym_bind, sym_type);
} else {
- esym = elfsym(S, sym);
+ esym = elfsym(sym);
esym->st_value = value;
esym->st_size = size;
esym->st_shndx = sh_num;
}
- update_storage(S, sym);
+ update_storage(sym);
}
-ST_FUNC void put_extern_sym(TCCState* S, Sym *sym, Section *section,
+ST_FUNC void put_extern_sym(Sym *sym, Section *section,
addr_t value, unsigned long size)
{
int sh_num = section ? section->sh_num : SHN_UNDEF;
- put_extern_sym2(S, sym, sh_num, value, size, 1);
+ put_extern_sym2(sym, sh_num, value, size, 1);
}
/* add a new relocation entry to symbol 'sym' in section 's' */
-ST_FUNC void greloca(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type,
+ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type,
addr_t addend)
{
int c = 0;
- if (S->tccgen_nocode_wanted && s == cur_text_section)
+ if (nocode_wanted && s == cur_text_section)
return;
if (sym) {
if (0 == sym->c)
- put_extern_sym(S, sym, NULL, 0, 0);
+ put_extern_sym(sym, NULL, 0, 0);
c = sym->c;
}
@@ -1066,64 +1157,64 @@ ST_FUNC void greloca(TCCState* S, Section *s, Sym *sym, unsigned long offset, in
}
#if PTR_SIZE == 4
-ST_FUNC void greloc(TCCState* S, Section *s, Sym *sym, unsigned long offset, int type)
+ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type)
{
- greloca(S, s, sym, offset, type, 0);
+ greloca(s, sym, offset, type, 0);
}
#endif
/* ------------------------------------------------------------------------- */
/* symbol allocator */
-static Sym *__sym_malloc(TCCState* S)
+static Sym *__sym_malloc(void)
{
Sym *sym_pool, *sym, *last_sym;
int i;
- sym_pool = tcc_malloc(S, SYM_POOL_NB * sizeof(Sym));
- dynarray_add(S, &S->tccgen_sym_pools, &S->tccgen_nb_sym_pools, sym_pool);
+ sym_pool = tcc_malloc(SYM_POOL_NB * sizeof(Sym));
+ dynarray_add(&sym_pools, &nb_sym_pools, sym_pool);
- last_sym = S->tccgen_sym_free_first;
+ last_sym = sym_free_first;
sym = sym_pool;
for(i = 0; i < SYM_POOL_NB; i++) {
sym->next = last_sym;
last_sym = sym;
sym++;
}
- S->tccgen_sym_free_first = last_sym;
+ sym_free_first = last_sym;
return last_sym;
}
-static inline Sym *sym_malloc(TCCState* S)
+static inline Sym *sym_malloc(void)
{
Sym *sym;
#ifndef SYM_DEBUG
- sym = S->tccgen_sym_free_first;
+ sym = sym_free_first;
if (!sym)
- sym = __sym_malloc(S);
- S->tccgen_sym_free_first = sym->next;
+ sym = __sym_malloc();
+ sym_free_first = sym->next;
return sym;
#else
- sym = tcc_malloc(S, sizeof(Sym));
+ sym = tcc_malloc(sizeof(Sym));
return sym;
#endif
}
-ST_INLN void sym_free(TCCState* S, Sym *sym)
+ST_INLN void sym_free(Sym *sym)
{
#ifndef SYM_DEBUG
- sym->next = S->tccgen_sym_free_first;
- S->tccgen_sym_free_first = sym;
+ sym->next = sym_free_first;
+ sym_free_first = sym;
#else
- tcc_free(S, sym);
+ tcc_free(sym);
#endif
}
/* push, without hashing */
-ST_FUNC Sym *sym_push2(TCCState* S, Sym **ps, int v, int t, int c)
+ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c)
{
Sym *s;
- s = sym_malloc(S);
+ s = sym_malloc();
memset(s, 0, sizeof *s);
s->v = v;
s->type.t = t;
@@ -1149,21 +1240,21 @@ ST_FUNC Sym *sym_find2(Sym *s, int v)
}
/* structure lookup */
-ST_INLN Sym *struct_find(TCCState* S, int v)
+ST_INLN Sym *struct_find(int v)
{
v -= TOK_IDENT;
- if ((unsigned)v >= (unsigned)(S->tccpp_tok_ident - TOK_IDENT))
+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
- return S->tccpp_table_ident[v]->sym_struct;
+ return table_ident[v]->sym_struct;
}
/* find an identifier */
-ST_INLN Sym *sym_find(TCCState* S, int v)
+ST_INLN Sym *sym_find(int v)
{
v -= TOK_IDENT;
- if ((unsigned)v >= (unsigned)(S->tccpp_tok_ident - TOK_IDENT))
+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
- return S->tccpp_table_ident[v]->sym_identifier;
+ return table_ident[v]->sym_identifier;
}
static int sym_scope(Sym *s)
@@ -1175,46 +1266,46 @@ static int sym_scope(Sym *s)
}
/* push a given symbol on the symbol stack */
-ST_FUNC Sym *sym_push(TCCState* S, int v, CType *type, int r, int c)
+ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
{
Sym *s, **ps;
TokenSym *ts;
- if (S->tccgen_local_stack)
- ps = &S->tccgen_local_stack;
+ if (local_stack)
+ ps = &local_stack;
else
- ps = &S->tccgen_global_stack;
- s = sym_push2(S, ps, v, type->t, c);
+ ps = &global_stack;
+ s = sym_push2(ps, v, type->t, c);
s->type.ref = type->ref;
s->r = r;
/* don't record fields or anonymous symbols */
/* XXX: simplify */
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
/* record symbol in token array */
- ts = S->tccpp_table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
+ ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
if (v & SYM_STRUCT)
ps = &ts->sym_struct;
else
ps = &ts->sym_identifier;
s->prev_tok = *ps;
*ps = s;
- s->sym_scope = S->tccgen_local_scope;
+ s->sym_scope = local_scope;
if (s->prev_tok && sym_scope(s->prev_tok) == s->sym_scope)
- tcc_error(S, "redeclaration of '%s'",
- get_tok_str(S, v & ~SYM_STRUCT, NULL));
+ tcc_error("redeclaration of '%s'",
+ get_tok_str(v & ~SYM_STRUCT, NULL));
}
return s;
}
/* push a global identifier */
-ST_FUNC Sym *global_identifier_push(TCCState* S, int v, int t, int c)
+ST_FUNC Sym *global_identifier_push(int v, int t, int c)
{
Sym *s, **ps;
- s = sym_push2(S, &S->tccgen_global_stack, v, t, c);
+ s = sym_push2(&global_stack, v, t, c);
s->r = VT_CONST | VT_SYM;
/* don't record anonymous symbol */
if (v < SYM_FIRST_ANOM) {
- ps = &S->tccpp_table_ident[v - TOK_IDENT]->sym_identifier;
+ ps = &table_ident[v - TOK_IDENT]->sym_identifier;
/* modify the top most local identifier, so that sym_identifier will
point to 's' when popped; happens when called from inline asm */
while (*ps != NULL && (*ps)->sym_scope)
@@ -1227,7 +1318,7 @@ ST_FUNC Sym *global_identifier_push(TCCState* S, int v, int t, int c)
/* pop symbols until top reaches 'b'. If KEEP is non-zero don't really
pop them yet from the list, but do remove them from the token array. */
-ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep)
+ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep)
{
Sym *s, *ss, **ps;
TokenSym *ts;
@@ -1240,7 +1331,7 @@ ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep)
/* remove symbol in token array */
/* XXX: simplify */
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
- ts = S->tccpp_table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
+ ts = table_ident[(v & ~SYM_STRUCT) - TOK_IDENT];
if (v & SYM_STRUCT)
ps = &ts->sym_struct;
else
@@ -1248,7 +1339,7 @@ ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep)
*ps = s->prev_tok;
}
if (!keep)
- sym_free(S, s);
+ sym_free(s);
s = ss;
}
if (!keep)
@@ -1256,7 +1347,7 @@ ST_FUNC void sym_pop(TCCState* S, Sym **ptop, Sym *b, int keep)
}
/* ------------------------------------------------------------------------- */
-static void vcheck_cmp(TCCState* S)
+static void vcheck_cmp(void)
{
/* cannot let cpu flags if other instruction are generated. Also
avoid leaving VT_JMP anywhere except on the top of the stack
@@ -1270,139 +1361,139 @@ static void vcheck_cmp(TCCState* S)
again, so that the VT_CMP/VT_JMP value will be in vtop
when code is unsuppressed again. */
- if (S->tccgen_vtop->r == VT_CMP && !S->tccgen_nocode_wanted)
- gv(S, RC_INT);
+ if (vtop->r == VT_CMP && !nocode_wanted)
+ gv(RC_INT);
}
-static void vsetc(TCCState* S, CType *type, int r, CValue *vc)
+static void vsetc(CType *type, int r, CValue *vc)
{
- if (S->tccgen_vtop >= vstack + (VSTACK_SIZE - 1))
- tcc_error(S, "memory full (vstack)");
- vcheck_cmp(S);
- S->tccgen_vtop++;
- S->tccgen_vtop->type = *type;
- S->tccgen_vtop->r = r;
- S->tccgen_vtop->r2 = VT_CONST;
- S->tccgen_vtop->c = *vc;
- S->tccgen_vtop->sym = NULL;
+ if (vtop >= vstack + (VSTACK_SIZE - 1))
+ tcc_error("memory full (vstack)");
+ vcheck_cmp();
+ vtop++;
+ vtop->type = *type;
+ vtop->r = r;
+ vtop->r2 = VT_CONST;
+ vtop->c = *vc;
+ vtop->sym = NULL;
}
-ST_FUNC void vswap(TCCState* S)
+ST_FUNC void vswap(void)
{
SValue tmp;
- vcheck_cmp(S);
- tmp = S->tccgen_vtop[0];
- S->tccgen_vtop[0] = S->tccgen_vtop[-1];
- S->tccgen_vtop[-1] = tmp;
+ vcheck_cmp();
+ tmp = vtop[0];
+ vtop[0] = vtop[-1];
+ vtop[-1] = tmp;
}
/* pop stack value */
-ST_FUNC void vpop(TCCState* S)
+ST_FUNC void vpop(void)
{
int v;
- v = S->tccgen_vtop->r & VT_VALMASK;
+ v = vtop->r & VT_VALMASK;
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
/* for x86, we need to pop the FP stack */
if (v == TREG_ST0) {
- o(S, 0xd8dd); /* fstp %st(0) */
+ o(0xd8dd); /* fstp %st(0) */
} else
#endif
if (v == VT_CMP) {
/* need to put correct jump if && or || without test */
- gsym(S, S->tccgen_vtop->jtrue);
- gsym(S, S->tccgen_vtop->jfalse);
+ gsym(vtop->jtrue);
+ gsym(vtop->jfalse);
}
- S->tccgen_vtop--;
+ vtop--;
}
/* push constant of type "type" with useless value */
-static void vpush(TCCState* S, CType *type)
+static void vpush(CType *type)
{
- vset(S, type, VT_CONST, 0);
+ vset(type, VT_CONST, 0);
}
/* push arbitrary 64bit constant */
-static void vpush64(TCCState* S, int ty, unsigned long long v)
+static void vpush64(int ty, unsigned long long v)
{
CValue cval;
CType ctype;
ctype.t = ty;
ctype.ref = NULL;
cval.i = v;
- vsetc(S, &ctype, VT_CONST, &cval);
+ vsetc(&ctype, VT_CONST, &cval);
}
/* push integer constant */
-ST_FUNC void vpushi(TCCState* S, int v)
+ST_FUNC void vpushi(int v)
{
- vpush64(S, VT_INT, v);
+ vpush64(VT_INT, v);
}
/* push a pointer sized constant */
-static void vpushs(TCCState* S, addr_t v)
+static void vpushs(addr_t v)
{
- vpush64(S, VT_SIZE_T, v);
+ vpush64(VT_SIZE_T, v);
}
/* push long long constant */
-static inline void vpushll(TCCState* S, long long v)
+static inline void vpushll(long long v)
{
- vpush64(S, VT_LLONG, v);
+ vpush64(VT_LLONG, v);
}
-ST_FUNC void vset(TCCState* S, CType *type, int r, int v)
+ST_FUNC void vset(CType *type, int r, int v)
{
CValue cval;
cval.i = v;
- vsetc(S, type, r, &cval);
+ vsetc(type, r, &cval);
}
-static void vseti(TCCState* S, int r, int v)
+static void vseti(int r, int v)
{
CType type;
type.t = VT_INT;
type.ref = NULL;
- vset(S, &type, r, v);
+ vset(&type, r, v);
}
-ST_FUNC void vpushv(TCCState* S, SValue *v)
+ST_FUNC void vpushv(SValue *v)
{
- if (S->tccgen_vtop >= vstack + (VSTACK_SIZE - 1))
- tcc_error(S, "memory full (vstack)");
- S->tccgen_vtop++;
- *S->tccgen_vtop = *v;
+ if (vtop >= vstack + (VSTACK_SIZE - 1))
+ tcc_error("memory full (vstack)");
+ vtop++;
+ *vtop = *v;
}
-static void vdup(TCCState* S)
+static void vdup(void)
{
- vpushv(S, S->tccgen_vtop);
+ vpushv(vtop);
}
/* rotate n first stack elements to the bottom
I1 ... In -> I2 ... In I1 [top is right]
*/
-ST_FUNC void vrotb(TCCState* S, int n)
+ST_FUNC void vrotb(int n)
{
int i;
SValue tmp;
- vcheck_cmp(S);
- tmp = S->tccgen_vtop[-n + 1];
+ vcheck_cmp();
+ tmp = vtop[-n + 1];
for(i=-n+1;i!=0;i++)
- S->tccgen_vtop[i] = S->tccgen_vtop[i+1];
- S->tccgen_vtop[0] = tmp;
+ vtop[i] = vtop[i+1];
+ vtop[0] = tmp;
}
/* rotate the n elements before entry e towards the top
I1 ... In ... -> In I1 ... I(n-1) ... [top is right]
*/
-ST_FUNC void vrote(TCCState* S, SValue *e, int n)
+ST_FUNC void vrote(SValue *e, int n)
{
int i;
SValue tmp;
- vcheck_cmp(S);
+ vcheck_cmp();
tmp = *e;
for(i = 0;i < n - 1; i++)
e[-i] = e[-i - 1];
@@ -1412,157 +1503,157 @@ ST_FUNC void vrote(TCCState* S, SValue *e, int n)
/* rotate n first stack elements to the top
I1 ... In -> In I1 ... I(n-1) [top is right]
*/
-ST_FUNC void vrott(TCCState* S, int n)
+ST_FUNC void vrott(int n)
{
- vrote(S, S->tccgen_vtop, n);
+ vrote(vtop, n);
}
/* ------------------------------------------------------------------------- */
/* vtop->r = VT_CMP means CPU-flags have been set from comparison or test. */
/* called from generators to set the result from relational ops */
-ST_FUNC void vset_VT_CMP(TCCState* S, int op)
+ST_FUNC void vset_VT_CMP(int op)
{
- S->tccgen_vtop->r = VT_CMP;
- S->tccgen_vtop->cmp_op = op;
- S->tccgen_vtop->jfalse = 0;
- S->tccgen_vtop->jtrue = 0;
+ vtop->r = VT_CMP;
+ vtop->cmp_op = op;
+ vtop->jfalse = 0;
+ vtop->jtrue = 0;
}
/* called once before asking generators to load VT_CMP to a register */
-static void vset_VT_JMP(TCCState* S)
+static void vset_VT_JMP(void)
{
- int op = S->tccgen_vtop->cmp_op;
+ int op = vtop->cmp_op;
- if (S->tccgen_vtop->jtrue || S->tccgen_vtop->jfalse) {
+ if (vtop->jtrue || vtop->jfalse) {
/* we need to jump to 'mov $0,%R' or 'mov $1,%R' */
int inv = op & (op < 2); /* small optimization */
- vseti(S, VT_JMP+inv, gvtst(S, inv, 0));
+ vseti(VT_JMP+inv, gvtst(inv, 0));
} else {
/* otherwise convert flags (rsp. 0/1) to register */
- S->tccgen_vtop->c.i = op;
+ vtop->c.i = op;
if (op < 2) /* doesn't seem to happen */
- S->tccgen_vtop->r = VT_CONST;
+ vtop->r = VT_CONST;
}
}
/* Set CPU Flags, doesn't yet jump */
-static void gvtst_set(TCCState* S, int inv, int t)
+static void gvtst_set(int inv, int t)
{
int *p;
- if (S->tccgen_vtop->r != VT_CMP) {
- vpushi(S, 0);
- gen_op(S, TOK_NE);
- if (S->tccgen_vtop->r != VT_CMP) /* must be VT_CONST then */
- vset_VT_CMP(S, S->tccgen_vtop->c.i != 0);
+ if (vtop->r != VT_CMP) {
+ vpushi(0);
+ gen_op(TOK_NE);
+ if (vtop->r != VT_CMP) /* must be VT_CONST then */
+ vset_VT_CMP(vtop->c.i != 0);
}
- p = inv ? &S->tccgen_vtop->jfalse : &S->tccgen_vtop->jtrue;
- *p = gjmp_append(S, *p, t);
+ p = inv ? &vtop->jfalse : &vtop->jtrue;
+ *p = gjmp_append(*p, t);
}
/* Generate value test
*
* Generate a test for any value (jump, comparison and integers) */
-static int gvtst(TCCState* S, int inv, int t)
+static int gvtst(int inv, int t)
{
int op, x, u;
- gvtst_set(S, inv, t);
- t = S->tccgen_vtop->jtrue, u = S->tccgen_vtop->jfalse;
+ gvtst_set(inv, t);
+ t = vtop->jtrue, u = vtop->jfalse;
if (inv)
x = u, u = t, t = x;
- op = S->tccgen_vtop->cmp_op;
+ op = vtop->cmp_op;
/* jump to the wanted target */
if (op > 1)
- t = gjmp_cond(S, op ^ inv, t);
+ t = gjmp_cond(op ^ inv, t);
else if (op != inv)
- t = gjmp(S, t);
+ t = gjmp(t);
/* resolve complementary jumps to here */
- gsym(S, u);
+ gsym(u);
- S->tccgen_vtop--;
+ vtop--;
return t;
}
/* generate a zero or nozero test */
-static void gen_test_zero(TCCState* S, int op)
+static void gen_test_zero(int op)
{
- if (S->tccgen_vtop->r == VT_CMP) {
+ if (vtop->r == VT_CMP) {
int j;
if (op == TOK_EQ) {
- j = S->tccgen_vtop->jfalse;
- S->tccgen_vtop->jfalse = S->tccgen_vtop->jtrue;
- S->tccgen_vtop->jtrue = j;
- S->tccgen_vtop->cmp_op ^= 1;
+ j = vtop->jfalse;
+ vtop->jfalse = vtop->jtrue;
+ vtop->jtrue = j;
+ vtop->cmp_op ^= 1;
}
} else {
- vpushi(S, 0);
- gen_op(S, op);
+ vpushi(0);
+ gen_op(op);
}
}
/* ------------------------------------------------------------------------- */
/* push a symbol value of TYPE */
-ST_FUNC void vpushsym(TCCState* S, CType *type, Sym *sym)
+ST_FUNC void vpushsym(CType *type, Sym *sym)
{
CValue cval;
cval.i = 0;
- vsetc(S, type, VT_CONST | VT_SYM, &cval);
- S->tccgen_vtop->sym = sym;
+ vsetc(type, VT_CONST | VT_SYM, &cval);
+ vtop->sym = sym;
}
/* Return a static symbol pointing to a section */
-ST_FUNC Sym *get_sym_ref(TCCState* S, CType *type, Section *sec, unsigned long offset, unsigned long size)
+ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
{
int v;
Sym *sym;
- v = S->tccgen_anon_sym++;
- sym = sym_push(S, v, type, VT_CONST | VT_SYM, 0);
+ v = anon_sym++;
+ sym = sym_push(v, type, VT_CONST | VT_SYM, 0);
sym->type.t |= VT_STATIC;
- put_extern_sym(S, sym, sec, offset, size);
+ put_extern_sym(sym, sec, offset, size);
return sym;
}
/* push a reference to a section offset by adding a dummy symbol */
-static void vpush_ref(TCCState* S, CType *type, Section *sec, unsigned long offset, unsigned long size)
+static void vpush_ref(CType *type, Section *sec, unsigned long offset, unsigned long size)
{
- vpushsym(S, type, get_sym_ref(S, type, sec, offset, size));
+ vpushsym(type, get_sym_ref(type, sec, offset, size));
}
/* define a new external reference to a symbol 'v' of type 'u' */
-ST_FUNC Sym *external_global_sym(TCCState* S, int v, CType *type)
+ST_FUNC Sym *external_global_sym(int v, CType *type)
{
Sym *s;
- s = sym_find(S, v);
+ s = sym_find(v);
if (!s) {
/* push forward reference */
- s = global_identifier_push(S, v, type->t | VT_EXTERN, 0);
+ s = global_identifier_push(v, type->t | VT_EXTERN, 0);
s->type.ref = type->ref;
} else if (IS_ASM_SYM(s)) {
s->type.t = type->t | (s->type.t & VT_EXTERN);
s->type.ref = type->ref;
- update_storage(S, s);
+ update_storage(s);
}
return s;
}
/* create an external reference with no specific type similar to asm labels.
This avoids type conflicts if the symbol is used from C too */
-ST_FUNC Sym *external_helper_sym(TCCState* S, int v)
+ST_FUNC Sym *external_helper_sym(int v)
{
CType ct = { VT_ASM_FUNC, NULL };
- return external_global_sym(S, v, &ct);
+ return external_global_sym(v, &ct);
}
/* push a reference to an helper function (such as memmove) */
-ST_FUNC void vpush_helper_func(TCCState* S, int v)
+ST_FUNC void vpush_helper_func(int v)
{
- vpushsym(S, &S->tccgen_func_old_type, external_helper_sym(S, v));
+ vpushsym(&func_old_type, external_helper_sym(v));
}
/* Merge symbol attributes. */
@@ -1618,11 +1709,11 @@ static void merge_attr(AttributeDef *ad, AttributeDef *ad1)
}
/* Merge some type attributes. */
-static void patch_type(TCCState* S, Sym *sym, CType *type)
+static void patch_type(Sym *sym, CType *type)
{
if (!(type->t & VT_EXTERN) || IS_ENUM_VAL(sym->type.t)) {
if (!(sym->type.t & VT_EXTERN))
- tcc_error(S, "redefinition of '%s'", get_tok_str(S, sym->v, NULL));
+ tcc_error("redefinition of '%s'", get_tok_str(sym->v, NULL));
sym->type.t &= ~VT_EXTERN;
}
@@ -1633,8 +1724,8 @@ static void patch_type(TCCState* S, Sym *sym, CType *type)
}
if (!is_compatible_types(&sym->type, type)) {
- tcc_error(S, "incompatible types for redefinition of '%s'",
- get_tok_str(S, sym->v, NULL));
+ tcc_error("incompatible types for redefinition of '%s'",
+ get_tok_str(sym->v, NULL));
} else if ((sym->type.t & VT_BTYPE) == VT_FUNC) {
int static_proto = sym->type.t & VT_STATIC;
@@ -1644,8 +1735,8 @@ static void patch_type(TCCState* S, Sym *sym, CType *type)
implement gnu-inline mode again it silences a warning for
mingw caused by our workarounds. */
&& !((type->t | sym->type.t) & VT_INLINE))
- tcc_warning(S, "static storage ignored for redefinition of '%s'",
- get_tok_str(S, sym->v, NULL));
+ tcc_warning("static storage ignored for redefinition of '%s'",
+ get_tok_str(sym->v, NULL));
/* set 'inline' if both agree or if one has static */
if ((type->t | sym->type.t) & VT_INLINE) {
@@ -1675,111 +1766,111 @@ static void patch_type(TCCState* S, Sym *sym, CType *type)
sym->type.ref->c = type->ref->c;
}
if ((type->t ^ sym->type.t) & VT_STATIC)
- tcc_warning(S, "storage mismatch for redefinition of '%s'",
- get_tok_str(S, sym->v, NULL));
+ tcc_warning("storage mismatch for redefinition of '%s'",
+ get_tok_str(sym->v, NULL));
}
}
/* Merge some storage attributes. */
-static void patch_storage(TCCState* S, Sym *sym, AttributeDef *ad, CType *type)
+static void patch_storage(Sym *sym, AttributeDef *ad, CType *type)
{
if (type)
- patch_type(S, sym, type);
+ patch_type(sym, type);
#ifdef TCC_TARGET_PE
if (sym->a.dllimport != ad->a.dllimport)
- tcc_error(S, "incompatible dll linkage for redefinition of '%s'",
- get_tok_str(S, sym->v, NULL));
+ tcc_error("incompatible dll linkage for redefinition of '%s'",
+ get_tok_str(sym->v, NULL));
#endif
merge_symattr(&sym->a, &ad->a);
if (ad->asm_label)
sym->asm_label = ad->asm_label;
- update_storage(S, sym);
+ update_storage(sym);
}
/* copy sym to other stack */
-static Sym *sym_copy(TCCState* S, Sym *s0, Sym **ps)
+static Sym *sym_copy(Sym *s0, Sym **ps)
{
Sym *s;
- s = sym_malloc(S), *s = *s0;
+ s = sym_malloc(), *s = *s0;
s->prev = *ps, *ps = s;
if (s->v < SYM_FIRST_ANOM) {
- ps = &S->tccpp_table_ident[s->v - TOK_IDENT]->sym_identifier;
+ ps = &table_ident[s->v - TOK_IDENT]->sym_identifier;
s->prev_tok = *ps, *ps = s;
}
return s;
}
/* copy s->type.ref to stack 'ps' for VT_FUNC and VT_PTR */
-static void sym_copy_ref(TCCState* S, Sym *s, Sym **ps)
+static void sym_copy_ref(Sym *s, Sym **ps)
{
int bt = s->type.t & VT_BTYPE;
if (bt == VT_FUNC || bt == VT_PTR || (bt == VT_STRUCT && s->sym_scope)) {
Sym **sp = &s->type.ref;
for (s = *sp, *sp = NULL; s; s = s->next) {
- Sym *s2 = sym_copy(S, s, ps);
+ Sym *s2 = sym_copy(s, ps);
sp = &(*sp = s2)->next;
- sym_copy_ref(S, s2, ps);
+ sym_copy_ref(s2, ps);
}
}
}
/* define a new external reference to a symbol 'v' */
-static Sym *external_sym(TCCState* S, int v, CType *type, int r, AttributeDef *ad)
+static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad)
{
Sym *s;
/* look for global symbol */
- s = sym_find(S, v);
+ s = sym_find(v);
while (s && s->sym_scope)
s = s->prev_tok;
if (!s) {
/* push forward reference */
- s = global_identifier_push(S, v, type->t, 0);
+ s = global_identifier_push(v, type->t, 0);
s->r |= r;
s->a = ad->a;
s->asm_label = ad->asm_label;
s->type.ref = type->ref;
/* copy type to the global stack */
- if (S->tccgen_local_stack)
- sym_copy_ref(S, s, &S->tccgen_global_stack);
+ if (local_stack)
+ sym_copy_ref(s, &global_stack);
} else {
- patch_storage(S, s, ad, type);
+ patch_storage(s, ad, type);
}
/* push variables on local_stack if any */
- if (S->tccgen_local_stack && (s->type.t & VT_BTYPE) != VT_FUNC)
- s = sym_copy(S, s, &S->tccgen_local_stack);
+ if (local_stack && (s->type.t & VT_BTYPE) != VT_FUNC)
+ s = sym_copy(s, &local_stack);
return s;
}
/* save registers up to (vtop - n) stack entry */
-ST_FUNC void save_regs(TCCState* S, int n)
+ST_FUNC void save_regs(int n)
{
SValue *p, *p1;
- for(p = vstack, p1 = S->tccgen_vtop - n; p <= p1; p++)
- save_reg(S, p->r);
+ for(p = vstack, p1 = vtop - n; p <= p1; p++)
+ save_reg(p->r);
}
/* save r to the memory stack, and mark it as being free */
-ST_FUNC void save_reg(TCCState* S, int r)
+ST_FUNC void save_reg(int r)
{
- save_reg_upstack(S, r, 0);
+ save_reg_upstack(r, 0);
}
/* save r to the memory stack, and mark it as being free,
if seen up to (vtop - n) stack entry */
-ST_FUNC void save_reg_upstack(TCCState* S, int r, int n)
+ST_FUNC void save_reg_upstack(int r, int n)
{
int l, size, align, bt;
SValue *p, *p1, sv;
if ((r &= VT_VALMASK) >= VT_CONST)
return;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
l = 0;
- for(p = vstack, p1 = S->tccgen_vtop - n; p <= p1; p++) {
+ for(p = vstack, p1 = vtop - n; p <= p1; p++) {
if ((p->r & VT_VALMASK) == r || p->r2 == r) {
/* must save value on stack if not already done */
if (!l) {
@@ -1790,20 +1881,20 @@ ST_FUNC void save_reg_upstack(TCCState* S, int r, int n)
bt = VT_PTR;
sv.type.t = bt;
size = type_size(&sv.type, &align);
- l = get_temp_local_var(S, size,align);
+ l = get_temp_local_var(size,align);
sv.r = VT_LOCAL | VT_LVAL;
sv.c.i = l;
- store(S, p->r & VT_VALMASK, &sv);
+ store(p->r & VT_VALMASK, &sv);
#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
/* x86 specific: need to pop fp register ST0 if saved */
if (r == TREG_ST0) {
- o(S, 0xd8dd); /* fstp %st(0) */
+ o(0xd8dd); /* fstp %st(0) */
}
#endif
/* special long long case */
if (p->r2 < VT_CONST && USING_TWO_WORDS(bt)) {
sv.c.i += PTR_SIZE;
- store(S, p->r2, &sv);
+ store(p->r2, &sv);
}
}
/* mark that stack entry as being saved on the stack */
@@ -1825,7 +1916,7 @@ ST_FUNC void save_reg_upstack(TCCState* S, int r, int n)
#ifdef TCC_TARGET_ARM
/* find a register of class 'rc2' with at most one reference on stack.
* If none, call get_reg(rc) */
-ST_FUNC int get_reg_ex(TCCState* S, int rc, int rc2)
+ST_FUNC int get_reg_ex(int rc, int rc2)
{
int r;
SValue *p;
@@ -1834,7 +1925,7 @@ ST_FUNC int get_reg_ex(TCCState* S, int rc, int rc2)
if (reg_classes[r] & rc2) {
int n;
n=0;
- for(p = vstack; p <= S->tccgen_vtop; p++) {
+ for(p = vstack; p <= vtop; p++) {
if ((p->r & VT_VALMASK) == r ||
p->r2 == r)
n++;
@@ -1843,12 +1934,12 @@ ST_FUNC int get_reg_ex(TCCState* S, int rc, int rc2)
return r;
}
}
- return get_reg(S, rc);
+ return get_reg(rc);
}
#endif
/* find a free register of class 'rc'. If none, save one register */
-ST_FUNC int get_reg(TCCState* S, int rc)
+ST_FUNC int get_reg(int rc)
{
int r;
SValue *p;
@@ -1856,9 +1947,9 @@ ST_FUNC int get_reg(TCCState* S, int rc)
/* find a free register */
for(r=0;r<NB_REGS;r++) {
if (reg_classes[r] & rc) {
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return r;
- for(p=vstack;p<=S->tccgen_vtop;p++) {
+ for(p=vstack;p<=vtop;p++) {
if ((p->r & VT_VALMASK) == r ||
p->r2 == r)
goto notfound;
@@ -1871,7 +1962,7 @@ ST_FUNC int get_reg(TCCState* S, int rc)
/* no register left : free the first one on the stack (VERY
IMPORTANT to start from the bottom to ensure that we don't
spill registers used in gen_opi()) */
- for(p=vstack;p<=S->tccgen_vtop;p++) {
+ for(p=vstack;p<=vtop;p++) {
/* look at second register (if long long) */
r = p->r2;
if (r < VT_CONST && (reg_classes[r] & rc))
@@ -1879,7 +1970,7 @@ ST_FUNC int get_reg(TCCState* S, int rc)
r = p->r & VT_VALMASK;
if (r < VT_CONST && (reg_classes[r] & rc)) {
save_found:
- save_reg(S, r);
+ save_reg(r);
return r;
}
}
@@ -1888,23 +1979,23 @@ ST_FUNC int get_reg(TCCState* S, int rc)
}
/* find a free temporary local variable (return the offset on stack) match the size and align. If none, add new temporary stack variable*/
-static int get_temp_local_var(TCCState* S, int size,int align){
+static int get_temp_local_var(int size,int align){
int i;
- temp_local_variable_t *temp_var;
+ struct temp_local_variable *temp_var;
int found_var;
SValue *p;
int r;
char free;
char found;
found=0;
- for(i=0;i<S->tccgen_nb_temp_local_vars;i++){
- temp_var=&S->tccgen_arr_temp_local_vars[i];
+ for(i=0;i<nb_temp_local_vars;i++){
+ temp_var=&arr_temp_local_vars[i];
if(temp_var->size<size||align!=temp_var->align){
continue;
}
/*check if temp_var is free*/
free=1;
- for(p=vstack;p<=S->tccgen_vtop;p++) {
+ for(p=vstack;p<=vtop;p++) {
r=p->r&VT_VALMASK;
if(r==VT_LOCAL||r==VT_LLOCAL){
if(p->c.i==temp_var->location){
@@ -1920,83 +2011,83 @@ static int get_temp_local_var(TCCState* S, int size,int align){
}
}
if(!found){
- S->tccgen_loc = (S->tccgen_loc - size) & -align;
- if(S->tccgen_nb_temp_local_vars<MAX_TEMP_LOCAL_VARIABLE_NUMBER){
- temp_var=&S->tccgen_arr_temp_local_vars[i];
- temp_var->location=S->tccgen_loc;
+ loc = (loc - size) & -align;
+ if(nb_temp_local_vars<MAX_TEMP_LOCAL_VARIABLE_NUMBER){
+ temp_var=&arr_temp_local_vars[i];
+ temp_var->location=loc;
temp_var->size=size;
temp_var->align=align;
- S->tccgen_nb_temp_local_vars++;
+ nb_temp_local_vars++;
}
- found_var=S->tccgen_loc;
+ found_var=loc;
}
return found_var;
}
-static void clear_temp_local_var_list(TCCState* S){
- S->tccgen_nb_temp_local_vars=0;
+static void clear_temp_local_var_list(){
+ nb_temp_local_vars=0;
}
/* move register 's' (of type 't') to 'r', and flush previous value of r to memory
if needed */
-static void move_reg(TCCState* S, int r, int s, int t)
+static void move_reg(int r, int s, int t)
{
SValue sv;
if (r != s) {
- save_reg(S, r);
+ save_reg(r);
sv.type.t = t;
sv.type.ref = NULL;
sv.r = s;
sv.c.i = 0;
- load(S, r, &sv);
+ load(r, &sv);
}
}
/* get address of vtop (vtop MUST BE an lvalue) */
-ST_FUNC void gaddrof(TCCState* S)
+ST_FUNC void gaddrof(void)
{
- S->tccgen_vtop->r &= ~VT_LVAL;
+ vtop->r &= ~VT_LVAL;
/* tricky: if saved lvalue, then we can go back to lvalue */
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_LLOCAL)
- S->tccgen_vtop->r = (S->tccgen_vtop->r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
+ if ((vtop->r & VT_VALMASK) == VT_LLOCAL)
+ vtop->r = (vtop->r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL;
}
#ifdef CONFIG_TCC_BCHECK
/* generate a bounded pointer addition */
-static void gen_bounded_ptr_add(TCCState* S)
+static void gen_bounded_ptr_add(void)
{
- int save = (S->tccgen_vtop[-1].r & VT_VALMASK) == VT_LOCAL;
+ int save = (vtop[-1].r & VT_VALMASK) == VT_LOCAL;
if (save) {
- vpushv(S, &S->tccgen_vtop[-1]);
- vrott(S, 3);
- }
- vpush_helper_func(S, TOK___bound_ptr_add);
- vrott(S, 3);
- gfunc_call(S, 2);
- S->tccgen_vtop -= save;
- vpushi(S, 0);
+ vpushv(&vtop[-1]);
+ vrott(3);
+ }
+ vpush_helper_func(TOK___bound_ptr_add);
+ vrott(3);
+ gfunc_call(2);
+ vtop -= save;
+ vpushi(0);
/* returned pointer is in REG_IRET */
- S->tccgen_vtop->r = REG_IRET | VT_BOUNDED;
- if (S->tccgen_nocode_wanted)
+ vtop->r = REG_IRET | VT_BOUNDED;
+ if (nocode_wanted)
return;
/* relocation offset of the bounding function call point */
- S->tccgen_vtop->c.i = (cur_text_section->reloc->data_offset - sizeof(ElfW_Rel));
+ vtop->c.i = (cur_text_section->reloc->data_offset - sizeof(ElfW_Rel));
}
/* patch pointer addition in vtop so that pointer dereferencing is
also tested */
-static void gen_bounded_ptr_deref(TCCState* S)
+static void gen_bounded_ptr_deref(void)
{
addr_t func;
int size, align;
ElfW_Rel *rel;
Sym *sym;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- size = type_size(&S->tccgen_vtop->type, &align);
+ size = type_size(&vtop->type, &align);
switch(size) {
case 1: func = TOK___bound_ptr_indir1; break;
case 2: func = TOK___bound_ptr_indir2; break;
@@ -2008,54 +2099,54 @@ static void gen_bounded_ptr_deref(TCCState* S)
/* may happen with struct member access */
return;
}
- sym = external_helper_sym(S, func);
+ sym = external_helper_sym(func);
if (!sym->c)
- put_extern_sym(S, sym, NULL, 0, 0);
+ put_extern_sym(sym, NULL, 0, 0);
/* patch relocation */
/* XXX: find a better solution ? */
- rel = (ElfW_Rel *)(cur_text_section->reloc->data + S->tccgen_vtop->c.i);
+ rel = (ElfW_Rel *)(cur_text_section->reloc->data + vtop->c.i);
rel->r_info = ELFW(R_INFO)(sym->c, ELFW(R_TYPE)(rel->r_info));
}
/* generate lvalue bound code */
-static void gbound(TCCState* S)
+static void gbound(void)
{
CType type1;
- S->tccgen_vtop->r &= ~VT_MUSTBOUND;
+ vtop->r &= ~VT_MUSTBOUND;
/* if lvalue, then use checking code before dereferencing */
- if (S->tccgen_vtop->r & VT_LVAL) {
+ if (vtop->r & VT_LVAL) {
/* if not VT_BOUNDED value, then make one */
- if (!(S->tccgen_vtop->r & VT_BOUNDED)) {
+ if (!(vtop->r & VT_BOUNDED)) {
/* must save type because we must set it to int to get pointer */
- type1 = S->tccgen_vtop->type;
- S->tccgen_vtop->type.t = VT_PTR;
- gaddrof(S);
- vpushi(S, 0);
- gen_bounded_ptr_add(S);
- S->tccgen_vtop->r |= VT_LVAL;
- S->tccgen_vtop->type = type1;
+ type1 = vtop->type;
+ vtop->type.t = VT_PTR;
+ gaddrof();
+ vpushi(0);
+ gen_bounded_ptr_add();
+ vtop->r |= VT_LVAL;
+ vtop->type = type1;
}
/* then check for dereferencing */
- gen_bounded_ptr_deref(S);
+ gen_bounded_ptr_deref();
}
}
/* we need to call __bound_ptr_add before we start to load function
args into registers */
-ST_FUNC void gbound_args(TCCState* S, int nb_args)
+ST_FUNC void gbound_args(int nb_args)
{
int i, v;
SValue *sv;
for (i = 1; i <= nb_args; ++i)
- if (S->tccgen_vtop[1 - i].r & VT_MUSTBOUND) {
- vrotb(S, i);
- gbound(S);
- vrott(S, i);
+ if (vtop[1 - i].r & VT_MUSTBOUND) {
+ vrotb(i);
+ gbound();
+ vrott(i);
}
- sv = S->tccgen_vtop - nb_args;
+ sv = vtop - nb_args;
if (sv->r & VT_SYM) {
v = sv->sym->v;
if (v == TOK_setjmp
@@ -2065,14 +2156,14 @@ ST_FUNC void gbound_args(TCCState* S, int nb_args)
|| v == TOK___sigsetjmp
#endif
) {
- vpush_helper_func(S, TOK___bound_setjmp);
- vpushv(S, sv + 1);
- gfunc_call(S, 1);
- S->func_bound_add_epilog = 1;
+ vpush_helper_func(TOK___bound_setjmp);
+ vpushv(sv + 1);
+ gfunc_call(1);
+ func_bound_add_epilog = 1;
}
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
if (v == TOK_alloca)
- S->func_bound_add_epilog = 1;
+ func_bound_add_epilog = 1;
#endif
#if TARGETOS_NetBSD
if (v == TOK_longjmp) /* undo rename to __longjmp14 */
@@ -2082,7 +2173,7 @@ ST_FUNC void gbound_args(TCCState* S, int nb_args)
}
/* Add bounds for local symbols from S to E (via ->prev) */
-static void add_local_bounds(TCCState* S, Sym *s, Sym *e)
+static void add_local_bounds(Sym *s, Sym *e)
{
for (; s != e; s = s->prev) {
if (!s->v || (s->r & VT_VALMASK) != VT_LOCAL)
@@ -2093,7 +2184,7 @@ static void add_local_bounds(TCCState* S, Sym *s, Sym *e)
|| s->a.addrtaken) {
/* add local bound info */
int align, size = type_size(&s->type, &align);
- addr_t *bounds_ptr = section_ptr_add(S, lbounds_section,
+ addr_t *bounds_ptr = section_ptr_add(lbounds_section,
2 * sizeof(addr_t));
bounds_ptr[0] = s->c;
bounds_ptr[1] = size;
@@ -2103,93 +2194,93 @@ static void add_local_bounds(TCCState* S, Sym *s, Sym *e)
#endif
/* Wrapper around sym_pop, that potentially also registers local bounds. */
-static void pop_local_syms(TCCState* S, Sym *b, int keep)
+static void pop_local_syms(Sym *b, int keep)
{
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check && !keep && (S->tccgen_local_scope || !S->tccgen_func_var))
- add_local_bounds(S, S->tccgen_local_stack, b);
+ if (tcc_state->do_bounds_check && !keep && (local_scope || !func_var))
+ add_local_bounds(local_stack, b);
#endif
- if (S->tccgen_debug_modes)
- tcc_add_debug_info (S, !S->tccgen_local_scope, S->tccgen_local_stack, b);
- sym_pop(S, &S->tccgen_local_stack, b, keep);
+ if (debug_modes)
+ tcc_add_debug_info (tcc_state, !local_scope, local_stack, b);
+ sym_pop(&local_stack, b, keep);
}
-static void incr_bf_adr(TCCState* S, int o)
+static void incr_bf_adr(int o)
{
- S->tccgen_vtop->type = S->tccgen_char_pointer_type;
- gaddrof(S);
- vpushs(S, o);
- gen_op(S, '+');
- S->tccgen_vtop->type.t = VT_BYTE | VT_UNSIGNED;
- S->tccgen_vtop->r |= VT_LVAL;
+ vtop->type = char_pointer_type;
+ gaddrof();
+ vpushs(o);
+ gen_op('+');
+ vtop->type.t = VT_BYTE | VT_UNSIGNED;
+ vtop->r |= VT_LVAL;
}
/* single-byte load mode for packed or otherwise unaligned bitfields */
-static void load_packed_bf(TCCState* S, CType *type, int bit_pos, int bit_size)
+static void load_packed_bf(CType *type, int bit_pos, int bit_size)
{
int n, o, bits;
- save_reg_upstack(S, S->tccgen_vtop->r, 1);
- vpush64(S, type->t & VT_BTYPE, 0); // B X
+ save_reg_upstack(vtop->r, 1);
+ vpush64(type->t & VT_BTYPE, 0); // B X
bits = 0, o = bit_pos >> 3, bit_pos &= 7;
do {
- vswap(S); // X B
- incr_bf_adr(S, o);
- vdup(S); // X B B
+ vswap(); // X B
+ incr_bf_adr(o);
+ vdup(); // X B B
n = 8 - bit_pos;
if (n > bit_size)
n = bit_size;
if (bit_pos)
- vpushi(S, bit_pos), gen_op(S, TOK_SHR), bit_pos = 0; // X B Y
+ vpushi(bit_pos), gen_op(TOK_SHR), bit_pos = 0; // X B Y
if (n < 8)
- vpushi(S, (1 << n) - 1), gen_op(S, '&');
- gen_cast(S, type);
+ vpushi((1 << n) - 1), gen_op('&');
+ gen_cast(type);
if (bits)
- vpushi(S, bits), gen_op(S, TOK_SHL);
- vrotb(S, 3); // B Y X
- gen_op(S, '|'); // B X
+ vpushi(bits), gen_op(TOK_SHL);
+ vrotb(3); // B Y X
+ gen_op('|'); // B X
bits += n, bit_size -= n, o = 1;
} while (bit_size);
- vswap(S), vpop(S);
+ vswap(), vpop();
if (!(type->t & VT_UNSIGNED)) {
n = ((type->t & VT_BTYPE) == VT_LLONG ? 64 : 32) - bits;
- vpushi(S, n), gen_op(S, TOK_SHL);
- vpushi(S, n), gen_op(S, TOK_SAR);
+ vpushi(n), gen_op(TOK_SHL);
+ vpushi(n), gen_op(TOK_SAR);
}
}
/* single-byte store mode for packed or otherwise unaligned bitfields */
-static void store_packed_bf(TCCState* S, int bit_pos, int bit_size)
+static void store_packed_bf(int bit_pos, int bit_size)
{
int bits, n, o, m, c;
- c = (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
- vswap(S); // X B
- save_reg_upstack(S, S->tccgen_vtop->r, 1);
+ c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
+ vswap(); // X B
+ save_reg_upstack(vtop->r, 1);
bits = 0, o = bit_pos >> 3, bit_pos &= 7;
do {
- incr_bf_adr(S, o); // X B
- vswap(S); //B X
- c ? vdup(S) : gv_dup(S); // B V X
- vrott(S, 3); // X B V
+ incr_bf_adr(o); // X B
+ vswap(); //B X
+ c ? vdup() : gv_dup(); // B V X
+ vrott(3); // X B V
if (bits)
- vpushi(S, bits), gen_op(S, TOK_SHR);
+ vpushi(bits), gen_op(TOK_SHR);
if (bit_pos)
- vpushi(S, bit_pos), gen_op(S, TOK_SHL);
+ vpushi(bit_pos), gen_op(TOK_SHL);
n = 8 - bit_pos;
if (n > bit_size)
n = bit_size;
if (n < 8) {
m = ((1 << n) - 1) << bit_pos;
- vpushi(S, m), gen_op(S, '&'); // X B V1
- vpushv(S, S->tccgen_vtop-1); // X B V1 B
- vpushi(S, m & 0x80 ? ~m & 0x7f : ~m);
- gen_op(S, '&'); // X B V1 B1
- gen_op(S, '|'); // X B V2
- }
- vdup(S), S->tccgen_vtop[-1] = S->tccgen_vtop[-2]; // X B B V2
- vstore(S), vpop(S); // X B
+ vpushi(m), gen_op('&'); // X B V1
+ vpushv(vtop-1); // X B V1 B
+ vpushi(m & 0x80 ? ~m & 0x7f : ~m);
+ gen_op('&'); // X B V1 B1
+ gen_op('|'); // X B V2
+ }
+ vdup(), vtop[-1] = vtop[-2]; // X B B V2
+ vstore(), vpop(); // X B
bits += n, bit_size -= n, bit_pos = 0, o = 1;
} while (bit_size);
- vpop(S), vpop(S);
+ vpop(), vpop();
}
static int adjust_bf(SValue *sv, int bit_pos, int bit_size)
@@ -2208,68 +2299,68 @@ static int adjust_bf(SValue *sv, int bit_pos, int bit_size)
/* store vtop a register belonging to class 'rc'. lvalues are
converted to values. Cannot be used if cannot be converted to
register value (such as structures). */
-ST_FUNC int gv(TCCState* S, int rc)
+ST_FUNC int gv(int rc)
{
int r, r2, r_ok, r2_ok, rc2, bt;
int bit_pos, bit_size, size, align;
/* NOTE: get_reg can modify vstack[] */
- if (S->tccgen_vtop->type.t & VT_BITFIELD) {
+ if (vtop->type.t & VT_BITFIELD) {
CType type;
- bit_pos = BIT_POS(S->tccgen_vtop->type.t);
- bit_size = BIT_SIZE(S->tccgen_vtop->type.t);
+ bit_pos = BIT_POS(vtop->type.t);
+ bit_size = BIT_SIZE(vtop->type.t);
/* remove bit field info to avoid loops */
- S->tccgen_vtop->type.t &= ~VT_STRUCT_MASK;
+ vtop->type.t &= ~VT_STRUCT_MASK;
type.ref = NULL;
- type.t = S->tccgen_vtop->type.t & VT_UNSIGNED;
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_BOOL)
+ type.t = vtop->type.t & VT_UNSIGNED;
+ if ((vtop->type.t & VT_BTYPE) == VT_BOOL)
type.t |= VT_UNSIGNED;
- r = adjust_bf(S->tccgen_vtop, bit_pos, bit_size);
+ r = adjust_bf(vtop, bit_pos, bit_size);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG)
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG)
type.t |= VT_LLONG;
else
type.t |= VT_INT;
if (r == VT_STRUCT) {
- load_packed_bf(S, &type, bit_pos, bit_size);
+ load_packed_bf(&type, bit_pos, bit_size);
} else {
int bits = (type.t & VT_BTYPE) == VT_LLONG ? 64 : 32;
/* cast to int to propagate signedness in following ops */
- gen_cast(S, &type);
+ gen_cast(&type);
/* generate shifts */
- vpushi(S, bits - (bit_pos + bit_size));
- gen_op(S, TOK_SHL);
- vpushi(S, bits - bit_size);
+ vpushi(bits - (bit_pos + bit_size));
+ gen_op(TOK_SHL);
+ vpushi(bits - bit_size);
/* NOTE: transformed to SHR if unsigned */
- gen_op(S, TOK_SAR);
+ gen_op(TOK_SAR);
}
- r = gv(S, rc);
+ r = gv(rc);
} else {
- if (is_float(S->tccgen_vtop->type.t) &&
- (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ if (is_float(vtop->type.t) &&
+ (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* CPUs usually cannot use float constants, so we store them
generically in data segment */
init_params p = { rodata_section };
unsigned long offset;
- size = type_size(&S->tccgen_vtop->type, &align);
+ size = type_size(&vtop->type, &align);
if (NODATA_WANTED)
size = 0, align = 1;
- offset = section_add(S, p.sec, size, align);
- vpush_ref(S, &S->tccgen_vtop->type, p.sec, offset, size);
- vswap(S);
- init_putv(S, &p, &S->tccgen_vtop->type, offset);
- S->tccgen_vtop->r |= VT_LVAL;
+ offset = section_add(p.sec, size, align);
+ vpush_ref(&vtop->type, p.sec, offset, size);
+ vswap();
+ init_putv(&p, &vtop->type, offset);
+ vtop->r |= VT_LVAL;
}
#ifdef CONFIG_TCC_BCHECK
- if (S->tccgen_vtop->r & VT_MUSTBOUND)
- gbound(S);
+ if (vtop->r & VT_MUSTBOUND)
+ gbound();
#endif
- bt = S->tccgen_vtop->type.t & VT_BTYPE;
+ bt = vtop->type.t & VT_BTYPE;
#ifdef TCC_TARGET_RISCV64
/* XXX mega hack */
@@ -2282,182 +2373,182 @@ ST_FUNC int gv(TCCState* S, int rc)
- constant
- lvalue (need to dereference pointer)
- already a register, but not in the right class */
- r = S->tccgen_vtop->r & VT_VALMASK;
- r_ok = !(S->tccgen_vtop->r & VT_LVAL) && (r < VT_CONST) && (reg_classes[r] & rc);
- r2_ok = !rc2 || ((S->tccgen_vtop->r2 < VT_CONST) && (reg_classes[S->tccgen_vtop->r2] & rc2));
+ r = vtop->r & VT_VALMASK;
+ r_ok = !(vtop->r & VT_LVAL) && (r < VT_CONST) && (reg_classes[r] & rc);
+ r2_ok = !rc2 || ((vtop->r2 < VT_CONST) && (reg_classes[vtop->r2] & rc2));
if (!r_ok || !r2_ok) {
if (!r_ok)
- r = get_reg(S, rc);
+ r = get_reg(rc);
if (rc2) {
int load_type = (bt == VT_QFLOAT) ? VT_DOUBLE : VT_PTRDIFF_T;
- int original_type = S->tccgen_vtop->type.t;
+ int original_type = vtop->type.t;
/* two register type load :
expand to two words temporarily */
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
/* load constant */
- unsigned long long ll = S->tccgen_vtop->c.i;
- S->tccgen_vtop->c.i = ll; /* first word */
- load(S, r, S->tccgen_vtop);
- S->tccgen_vtop->r = r; /* save register value */
- vpushi(S, ll >> 32); /* second word */
- } else if (S->tccgen_vtop->r & VT_LVAL) {
+ unsigned long long ll = vtop->c.i;
+ vtop->c.i = ll; /* first word */
+ load(r, vtop);
+ vtop->r = r; /* save register value */
+ vpushi(ll >> 32); /* second word */
+ } else if (vtop->r & VT_LVAL) {
/* We do not want to modifier the long long pointer here.
So we save any other instances down the stack */
- save_reg_upstack(S, S->tccgen_vtop->r, 1);
+ save_reg_upstack(vtop->r, 1);
/* load from memory */
- S->tccgen_vtop->type.t = load_type;
- load(S, r, S->tccgen_vtop);
- vdup(S);
- S->tccgen_vtop[-1].r = r; /* save register value */
+ vtop->type.t = load_type;
+ load(r, vtop);
+ vdup();
+ vtop[-1].r = r; /* save register value */
/* increment pointer to get second word */
- S->tccgen_vtop->type.t = VT_PTRDIFF_T;
- gaddrof(S);
- vpushs(S, PTR_SIZE);
- gen_op(S, '+');
- S->tccgen_vtop->r |= VT_LVAL;
- S->tccgen_vtop->type.t = load_type;
+ vtop->type.t = VT_PTRDIFF_T;
+ gaddrof();
+ vpushs(PTR_SIZE);
+ gen_op('+');
+ vtop->r |= VT_LVAL;
+ vtop->type.t = load_type;
} else {
/* move registers */
if (!r_ok)
- load(S, r, S->tccgen_vtop);
- if (r2_ok && S->tccgen_vtop->r2 < VT_CONST)
+ load(r, vtop);
+ if (r2_ok && vtop->r2 < VT_CONST)
goto done;
- vdup(S);
- S->tccgen_vtop[-1].r = r; /* save register value */
- S->tccgen_vtop->r = S->tccgen_vtop[-1].r2;
+ vdup();
+ vtop[-1].r = r; /* save register value */
+ vtop->r = vtop[-1].r2;
}
/* Allocate second register. Here we rely on the fact that
get_reg() tries first to free r2 of an SValue. */
- r2 = get_reg(S, rc2);
- load(S, r2, S->tccgen_vtop);
- vpop(S);
+ r2 = get_reg(rc2);
+ load(r2, vtop);
+ vpop();
/* write second register */
- S->tccgen_vtop->r2 = r2;
+ vtop->r2 = r2;
done:
- S->tccgen_vtop->type.t = original_type;
+ vtop->type.t = original_type;
} else {
- if (S->tccgen_vtop->r == VT_CMP)
- vset_VT_JMP(S);
+ if (vtop->r == VT_CMP)
+ vset_VT_JMP();
/* one register type load */
- load(S, r, S->tccgen_vtop);
+ load(r, vtop);
}
}
- S->tccgen_vtop->r = r;
+ vtop->r = r;
#ifdef TCC_TARGET_C67
/* uses register pairs for doubles */
if (bt == VT_DOUBLE)
- S->tccgen_vtop->r2 = r+1;
+ vtop->r2 = r+1;
#endif
}
return r;
}
/* generate vtop[-1] and vtop[0] in resp. classes rc1 and rc2 */
-ST_FUNC void gv2(TCCState* S, int rc1, int rc2)
+ST_FUNC void gv2(int rc1, int rc2)
{
/* generate more generic register first. But VT_JMP or VT_CMP
values must be generated first in all cases to avoid possible
reload errors */
- if (S->tccgen_vtop->r != VT_CMP && rc1 <= rc2) {
- vswap(S);
- gv(S, rc1);
- vswap(S);
- gv(S, rc2);
+ if (vtop->r != VT_CMP && rc1 <= rc2) {
+ vswap();
+ gv(rc1);
+ vswap();
+ gv(rc2);
/* test if reload is needed for first register */
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) >= VT_CONST) {
- vswap(S);
- gv(S, rc1);
- vswap(S);
+ if ((vtop[-1].r & VT_VALMASK) >= VT_CONST) {
+ vswap();
+ gv(rc1);
+ vswap();
}
} else {
- gv(S, rc2);
- vswap(S);
- gv(S, rc1);
- vswap(S);
+ gv(rc2);
+ vswap();
+ gv(rc1);
+ vswap();
/* test if reload is needed for first register */
- if ((S->tccgen_vtop[0].r & VT_VALMASK) >= VT_CONST) {
- gv(S, rc2);
+ if ((vtop[0].r & VT_VALMASK) >= VT_CONST) {
+ gv(rc2);
}
}
}
#if PTR_SIZE == 4
/* expand 64bit on stack in two ints */
-ST_FUNC void lexpand(TCCState* S)
+ST_FUNC void lexpand(void)
{
int u, v;
- u = S->tccgen_vtop->type.t & (VT_DEFSIGN | VT_UNSIGNED);
- v = S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL);
+ u = vtop->type.t & (VT_DEFSIGN | VT_UNSIGNED);
+ v = vtop->r & (VT_VALMASK | VT_LVAL);
if (v == VT_CONST) {
- vdup(S);
- S->tccgen_vtop[0].c.i >>= 32;
+ vdup();
+ vtop[0].c.i >>= 32;
} else if (v == (VT_LVAL|VT_CONST) || v == (VT_LVAL|VT_LOCAL)) {
- vdup(S);
- S->tccgen_vtop[0].c.i += 4;
+ vdup();
+ vtop[0].c.i += 4;
} else {
- gv(S, RC_INT);
- vdup(S);
- S->tccgen_vtop[0].r = S->tccgen_vtop[-1].r2;
- S->tccgen_vtop[0].r2 = S->tccgen_vtop[-1].r2 = VT_CONST;
+ gv(RC_INT);
+ vdup();
+ vtop[0].r = vtop[-1].r2;
+ vtop[0].r2 = vtop[-1].r2 = VT_CONST;
}
- S->tccgen_vtop[0].type.t = S->tccgen_vtop[-1].type.t = VT_INT | u;
+ vtop[0].type.t = vtop[-1].type.t = VT_INT | u;
}
#endif
#if PTR_SIZE == 4
/* build a long long from two ints */
-static void lbuild(TCCState* S, int t)
+static void lbuild(int t)
{
- gv2(S, RC_INT, RC_INT);
- S->tccgen_vtop[-1].r2 = S->tccgen_vtop[0].r;
- S->tccgen_vtop[-1].type.t = t;
- vpop(S);
+ gv2(RC_INT, RC_INT);
+ vtop[-1].r2 = vtop[0].r;
+ vtop[-1].type.t = t;
+ vpop();
}
#endif
/* convert stack entry to register and duplicate its value in another
register */
-static void gv_dup(TCCState* S)
+static void gv_dup(void)
{
int t, rc, r;
- t = S->tccgen_vtop->type.t;
+ t = vtop->type.t;
#if PTR_SIZE == 4
if ((t & VT_BTYPE) == VT_LLONG) {
if (t & VT_BITFIELD) {
- gv(S, RC_INT);
- t = S->tccgen_vtop->type.t;
- }
- lexpand(S);
- gv_dup(S);
- vswap(S);
- vrotb(S, 3);
- gv_dup(S);
- vrotb(S, 4);
+ gv(RC_INT);
+ t = vtop->type.t;
+ }
+ lexpand();
+ gv_dup();
+ vswap();
+ vrotb(3);
+ gv_dup();
+ vrotb(4);
/* stack: H L L1 H1 */
- lbuild(S, t);
- vrotb(S, 3);
- vrotb(S, 3);
- vswap(S);
- lbuild(S, t);
- vswap(S);
+ lbuild(t);
+ vrotb(3);
+ vrotb(3);
+ vswap();
+ lbuild(t);
+ vswap();
return;
}
#endif
/* duplicate value */
rc = RC_TYPE(t);
- gv(S, rc);
- r = get_reg(S, rc);
- vdup(S);
- load(S, r, S->tccgen_vtop);
- S->tccgen_vtop->r = r;
+ gv(rc);
+ r = get_reg(rc);
+ vdup();
+ load(r, vtop);
+ vtop->r = r;
}
#if PTR_SIZE == 4
/* generate CPU independent (unsigned) long long operations */
-static void gen_opl(TCCState* S, int op)
+static void gen_opl(int op)
{
int t, a, b, op1, c, i;
int func;
@@ -2485,12 +2576,12 @@ static void gen_opl(TCCState* S, int op)
#endif
gen_func:
/* call generic long long function */
- vpush_helper_func(S, func);
- vrott(S, 3);
- gfunc_call(S, 2);
- vpushi(S, 0);
- S->tccgen_vtop->r = reg_iret;
- S->tccgen_vtop->r2 = reg_lret;
+ vpush_helper_func(func);
+ vrott(3);
+ gfunc_call(2);
+ vpushi(0);
+ vtop->r = reg_iret;
+ vtop->r2 = reg_lret;
break;
case '^':
case '&':
@@ -2499,119 +2590,119 @@ static void gen_opl(TCCState* S, int op)
case '+':
case '-':
//pv("gen_opl A",0,2);
- t = S->tccgen_vtop->type.t;
- vswap(S);
- lexpand(S);
- vrotb(S, 3);
- lexpand(S);
+ t = vtop->type.t;
+ vswap();
+ lexpand();
+ vrotb(3);
+ lexpand();
/* stack: L1 H1 L2 H2 */
- tmp = S->tccgen_vtop[0];
- S->tccgen_vtop[0] = S->tccgen_vtop[-3];
- S->tccgen_vtop[-3] = tmp;
- tmp = S->tccgen_vtop[-2];
- S->tccgen_vtop[-2] = S->tccgen_vtop[-3];
- S->tccgen_vtop[-3] = tmp;
- vswap(S);
+ tmp = vtop[0];
+ vtop[0] = vtop[-3];
+ vtop[-3] = tmp;
+ tmp = vtop[-2];
+ vtop[-2] = vtop[-3];
+ vtop[-3] = tmp;
+ vswap();
/* stack: H1 H2 L1 L2 */
//pv("gen_opl B",0,4);
if (op == '*') {
- vpushv(S, S->tccgen_vtop - 1);
- vpushv(S, S->tccgen_vtop - 1);
- gen_op(S, TOK_UMULL);
- lexpand(S);
+ vpushv(vtop - 1);
+ vpushv(vtop - 1);
+ gen_op(TOK_UMULL);
+ lexpand();
/* stack: H1 H2 L1 L2 ML MH */
for(i=0;i<4;i++)
- vrotb(S, 6);
+ vrotb(6);
/* stack: ML MH H1 H2 L1 L2 */
- tmp = S->tccgen_vtop[0];
- S->tccgen_vtop[0] = S->tccgen_vtop[-2];
- S->tccgen_vtop[-2] = tmp;
+ tmp = vtop[0];
+ vtop[0] = vtop[-2];
+ vtop[-2] = tmp;
/* stack: ML MH H1 L2 H2 L1 */
- gen_op(S, '*');
- vrotb(S, 3);
- vrotb(S, 3);
- gen_op(S, '*');
+ gen_op('*');
+ vrotb(3);
+ vrotb(3);
+ gen_op('*');
/* stack: ML MH M1 M2 */
- gen_op(S, '+');
- gen_op(S, '+');
+ gen_op('+');
+ gen_op('+');
} else if (op == '+' || op == '-') {
/* XXX: add non carry method too (for MIPS or alpha) */
if (op == '+')
op1 = TOK_ADDC1;
else
op1 = TOK_SUBC1;
- gen_op(S, op1);
+ gen_op(op1);
/* stack: H1 H2 (L1 op L2) */
- vrotb(S, 3);
- vrotb(S, 3);
- gen_op(S, op1 + 1); /* TOK_xxxC2 */
+ vrotb(3);
+ vrotb(3);
+ gen_op(op1 + 1); /* TOK_xxxC2 */
} else {
- gen_op(S, op);
+ gen_op(op);
/* stack: H1 H2 (L1 op L2) */
- vrotb(S, 3);
- vrotb(S, 3);
+ vrotb(3);
+ vrotb(3);
/* stack: (L1 op L2) H1 H2 */
- gen_op(S, op);
+ gen_op(op);
/* stack: (L1 op L2) (H1 op H2) */
}
/* stack: L H */
- lbuild(S, t);
+ lbuild(t);
break;
case TOK_SAR:
case TOK_SHR:
case TOK_SHL:
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
- t = S->tccgen_vtop[-1].type.t;
- vswap(S);
- lexpand(S);
- vrotb(S, 3);
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ t = vtop[-1].type.t;
+ vswap();
+ lexpand();
+ vrotb(3);
/* stack: L H shift */
- c = (int)S->tccgen_vtop->c.i;
+ c = (int)vtop->c.i;
/* constant: simpler */
/* NOTE: all comments are for SHL. the other cases are
done by swapping words */
- vpop(S);
+ vpop();
if (op != TOK_SHL)
- vswap(S);
+ vswap();
if (c >= 32) {
/* stack: L H */
- vpop(S);
+ vpop();
if (c > 32) {
- vpushi(S, c - 32);
- gen_op(S, op);
+ vpushi(c - 32);
+ gen_op(op);
}
if (op != TOK_SAR) {
- vpushi(S, 0);
+ vpushi(0);
} else {
- gv_dup(S);
- vpushi(S, 31);
- gen_op(S, TOK_SAR);
+ gv_dup();
+ vpushi(31);
+ gen_op(TOK_SAR);
}
- vswap(S);
+ vswap();
} else {
- vswap(S);
- gv_dup(S);
+ vswap();
+ gv_dup();
/* stack: H L L */
- vpushi(S, c);
- gen_op(S, op);
- vswap(S);
- vpushi(S, 32 - c);
+ vpushi(c);
+ gen_op(op);
+ vswap();
+ vpushi(32 - c);
if (op == TOK_SHL)
- gen_op(S, TOK_SHR);
+ gen_op(TOK_SHR);
else
- gen_op(S, TOK_SHL);
- vrotb(S, 3);
+ gen_op(TOK_SHL);
+ vrotb(3);
/* stack: L L H */
- vpushi(S, c);
+ vpushi(c);
if (op == TOK_SHL)
- gen_op(S, TOK_SHL);
+ gen_op(TOK_SHL);
else
- gen_op(S, TOK_SHR);
- gen_op(S, '|');
+ gen_op(TOK_SHR);
+ gen_op('|');
}
if (op != TOK_SHL)
- vswap(S);
- lbuild(S, t);
+ vswap();
+ lbuild(t);
} else {
/* XXX: should provide a faster fallback on x86 ? */
switch(op) {
@@ -2629,17 +2720,17 @@ static void gen_opl(TCCState* S, int op)
break;
default:
/* compare operations */
- t = S->tccgen_vtop->type.t;
- vswap(S);
- lexpand(S);
- vrotb(S, 3);
- lexpand(S);
+ t = vtop->type.t;
+ vswap();
+ lexpand();
+ vrotb(3);
+ lexpand();
/* stack: L1 H1 L2 H2 */
- tmp = S->tccgen_vtop[-1];
- S->tccgen_vtop[-1] = S->tccgen_vtop[-2];
- S->tccgen_vtop[-2] = tmp;
+ tmp = vtop[-1];
+ vtop[-1] = vtop[-2];
+ vtop[-2] = tmp;
/* stack: L1 L2 H1 H2 */
- save_regs(S, 4);
+ save_regs(4);
/* compare high */
op1 = op;
/* when values are equal, we need to compare low words. since
@@ -2654,16 +2745,16 @@ static void gen_opl(TCCState* S, int op)
op1 = TOK_UGE;
a = 0;
b = 0;
- gen_op(S, op1);
+ gen_op(op1);
if (op == TOK_NE) {
- b = gvtst(S, 0, 0);
+ b = gvtst(0, 0);
} else {
- a = gvtst(S, 1, 0);
+ a = gvtst(1, 0);
if (op != TOK_EQ) {
/* generate non equal test */
- vpushi(S, 0);
- vset_VT_CMP(S, TOK_NE);
- b = gvtst(S, 0, 0);
+ vpushi(0);
+ vset_VT_CMP(TOK_NE);
+ b = gvtst(0, 0);
}
}
/* compare low. Always unsigned */
@@ -2676,13 +2767,13 @@ static void gen_opl(TCCState* S, int op)
op1 = TOK_UGT;
else if (op1 == TOK_GE)
op1 = TOK_UGE;
- gen_op(S, op1);
+ gen_op(op1);
#if 0//def TCC_TARGET_I386
- if (op == TOK_NE) { gsym(S, b); break; }
- if (op == TOK_EQ) { gsym(S, a); break; }
+ if (op == TOK_NE) { gsym(b); break; }
+ if (op == TOK_EQ) { gsym(a); break; }
#endif
- gvtst_set(S, 1, a);
- gvtst_set(S, 0, b);
+ gvtst_set(1, a);
+ gvtst_set(0, b);
break;
}
}
@@ -2701,10 +2792,10 @@ static int gen_opic_lt(uint64_t a, uint64_t b)
/* handle integer constant optimizations and various machine
independent opt */
-static void gen_opic(TCCState* S, int op)
+static void gen_opic(int op)
{
- SValue *v1 = S->tccgen_vtop - 1;
- SValue *v2 = S->tccgen_vtop;
+ SValue *v1 = vtop - 1;
+ SValue *v2 = vtop;
int t1 = v1->type.t & VT_BTYPE;
int t2 = v2->type.t & VT_BTYPE;
int c1 = (v1->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
@@ -2736,8 +2827,8 @@ static void gen_opic(TCCState* S, int op)
case TOK_UMOD:
/* if division by zero, generate explicit division */
if (l2 == 0) {
- if (S->tccgen_const_wanted && !(S->tccgen_nocode_wanted & unevalmask))
- tcc_error(S, "division by zero in constant");
+ if (const_wanted && !(nocode_wanted & unevalmask))
+ tcc_error("division by zero in constant");
goto general_case;
}
switch(op) {
@@ -2773,31 +2864,31 @@ static void gen_opic(TCCState* S, int op)
l1 = ((uint32_t)l1 |
(v1->type.t & VT_UNSIGNED ? 0 : -(l1 & 0x80000000)));
v1->c.i = l1;
- S->tccgen_vtop--;
+ vtop--;
} else {
/* if commutative ops, put c2 as constant */
if (c1 && (op == '+' || op == '&' || op == '^' ||
op == '|' || op == '*' || op == TOK_EQ || op == TOK_NE)) {
- vswap(S);
+ vswap();
c2 = c1; //c = c1, c1 = c2, c2 = c;
l2 = l1; //l = l1, l1 = l2, l2 = l;
}
- if (!S->tccgen_const_wanted &&
+ if (!const_wanted &&
c1 && ((l1 == 0 &&
(op == TOK_SHL || op == TOK_SHR || op == TOK_SAR)) ||
(l1 == -1 && op == TOK_SAR))) {
/* treat (0 << x), (0 >> x) and (-1 >> x) as constant */
- S->tccgen_vtop--;
- } else if (!S->tccgen_const_wanted &&
+ vtop--;
+ } else if (!const_wanted &&
c2 && ((l2 == 0 && (op == '&' || op == '*')) ||
(op == '|' &&
(l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))) ||
(l2 == 1 && (op == '%' || op == TOK_UMOD)))) {
/* treat (x & 0), (x * 0), (x | -1) and (x % 1) as constant */
if (l2 == 1)
- S->tccgen_vtop->c.i = 0;
- vswap(S);
- S->tccgen_vtop--;
+ vtop->c.i = 0;
+ vswap();
+ vtop--;
} else if (c2 && (((op == '*' || op == '/' || op == TOK_UDIV ||
op == TOK_PDIV) &&
l2 == 1) ||
@@ -2807,7 +2898,7 @@ static void gen_opic(TCCState* S, int op)
(op == '&' &&
(l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))))) {
/* filter out NOP operations like x*1, x-0, x&-1... */
- S->tccgen_vtop--;
+ vtop--;
} else if (c2 && (op == '*' || op == TOK_PDIV || op == TOK_UDIV)) {
/* try to use shifts instead of muls or divs */
if (l2 > 0 && (l2 & (l2 - 1)) == 0) {
@@ -2816,7 +2907,7 @@ static void gen_opic(TCCState* S, int op)
l2 >>= 1;
n++;
}
- S->tccgen_vtop->c.i = n;
+ vtop->c.i = n;
if (op == '*')
op = TOK_SHL;
else if (op == TOK_PDIV)
@@ -2826,26 +2917,26 @@ static void gen_opic(TCCState* S, int op)
}
goto general_case;
} else if (c2 && (op == '+' || op == '-') &&
- (((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM))
- || (S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_LOCAL)) {
+ (((vtop[-1].r & (VT_VALMASK | VT_LVAL | VT_SYM)) == (VT_CONST | VT_SYM))
+ || (vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_LOCAL)) {
/* symbol + constant case */
if (op == '-')
l2 = -l2;
- l2 += S->tccgen_vtop[-1].c.i;
+ l2 += vtop[-1].c.i;
/* The backends can't always deal with addends to symbols
larger than +-1<<31. Don't construct such. */
if ((int)l2 != l2)
goto general_case;
- S->tccgen_vtop--;
- S->tccgen_vtop->c.i = l2;
+ vtop--;
+ vtop->c.i = l2;
} else {
general_case:
/* call low level op generator */
if (t1 == VT_LLONG || t2 == VT_LLONG ||
(PTR_SIZE == 8 && (t1 == VT_PTR || t2 == VT_PTR)))
- gen_opl(S, op);
+ gen_opl(op);
else
- gen_opi(S, op);
+ gen_opi(op);
}
}
}
@@ -2853,14 +2944,14 @@ static void gen_opic(TCCState* S, int op)
#if defined TCC_TARGET_X86_64 || defined TCC_TARGET_I386
# define gen_negf gen_opf
#elif defined TCC_TARGET_ARM
-void gen_negf(TCCState* S, int op)
+void gen_negf(int op)
{
/* arm will detect 0-x and replace by vneg */
- vpushi(S, 0), vswap(S), gen_op(S, '-');
+ vpushi(0), vswap(), gen_op('-');
}
#else
/* XXX: implement in gen_opf() for other backends too */
-void gen_negf(TCCState* S, int op)
+void gen_negf(int op)
{
/* In IEEE negate(x) isn't subtract(0,x). Without NaNs it's
subtract(-0, x), but with them it's really a sign flip
@@ -2870,21 +2961,21 @@ void gen_negf(TCCState* S, int op)
int align, size, bt;
- size = type_size(&S->tccgen_vtop->type, &align);
- bt = S->tccgen_vtop->type.t & VT_BTYPE;
- save_reg(S, gv(S, RC_TYPE(bt)));
- vdup(S);
- incr_bf_adr(S, size - 1);
- vdup(S);
- vpushi(S, 0x80); /* flip sign */
- gen_op(S, '^');
- vstore(S);
- vpop(S);
+ size = type_size(&vtop->type, &align);
+ bt = vtop->type.t & VT_BTYPE;
+ save_reg(gv(RC_TYPE(bt)));
+ vdup();
+ incr_bf_adr(size - 1);
+ vdup();
+ vpushi(0x80); /* flip sign */
+ gen_op('^');
+ vstore();
+ vpop();
}
#endif
/* generate a floating point operation with constant propagation */
-static void gen_opif(TCCState* S, int op)
+static void gen_opif(int op)
{
int c1, c2;
SValue *v1, *v2;
@@ -2894,8 +2985,8 @@ static void gen_opif(TCCState* S, int op)
#endif
long double f1, f2;
- v1 = S->tccgen_vtop - 1;
- v2 = S->tccgen_vtop;
+ v1 = vtop - 1;
+ v2 = vtop;
if (op == TOK_NEG)
v1 = v2;
@@ -2915,7 +3006,7 @@ static void gen_opif(TCCState* S, int op)
}
/* NOTE: we only do constant propagation if finite number (not
NaN or infinity) (ANSI spec) */
- if (!(ieee_finite(f1) || !ieee_finite(f2)) && !S->tccgen_const_wanted)
+ if (!(ieee_finite(f1) || !ieee_finite(f2)) && !const_wanted)
goto general_case;
switch(op) {
case '+': f1 += f2; break;
@@ -2926,7 +3017,7 @@ static void gen_opif(TCCState* S, int op)
union { float f; unsigned u; } x1, x2, y;
/* If not in initializer we need to potentially generate
FP exceptions at runtime, otherwise we want to fold. */
- if (!S->tccgen_const_wanted)
+ if (!const_wanted)
goto general_case;
/* the run-time result of 0.0/0.0 on x87, also of other compilers
when used to compile the f1 /= f2 below, would be -nan */
@@ -2948,7 +3039,7 @@ static void gen_opif(TCCState* S, int op)
default:
goto general_case;
}
- S->tccgen_vtop--;
+ vtop--;
unary_result:
/* XXX: overflow test ? */
if (v1->type.t == VT_FLOAT) {
@@ -2961,9 +3052,9 @@ static void gen_opif(TCCState* S, int op)
} else {
general_case:
if (op == TOK_NEG) {
- gen_negf(S, op);
+ gen_negf(op);
} else {
- gen_opf(S, op);
+ gen_opf(op);
}
}
}
@@ -2972,7 +3063,7 @@ static void gen_opif(TCCState* S, int op)
printed in the type */
/* XXX: union */
/* XXX: add array and function pointers */
-static void type_to_str(TCCState* S, char *buf, int buf_size,
+static void type_to_str(char *buf, int buf_size,
CType *type, const char *varstr)
{
int bt, v, t;
@@ -3055,7 +3146,7 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
if (v >= SYM_FIRST_ANOM)
pstrcat(buf, buf_size, "<anonymous>");
else
- pstrcat(buf, buf_size, get_tok_str(S, v, NULL));
+ pstrcat(buf, buf_size, get_tok_str(v, NULL));
break;
case VT_FUNC:
s = type->ref;
@@ -3069,7 +3160,7 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
sa = s->next;
while (sa != NULL) {
char buf2[256];
- type_to_str(S, buf2, sizeof(buf2), &sa->type, NULL);
+ type_to_str(buf2, sizeof(buf2), &sa->type, NULL);
pstrcat(buf1, sizeof(buf1), buf2);
sa = sa->next;
if (sa)
@@ -3078,7 +3169,7 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
if (s->f.func_type == FUNC_ELLIPSIS)
pstrcat(buf1, sizeof(buf1), ", ...");
pstrcat(buf1, sizeof(buf1), ")");
- type_to_str(S, buf, buf_size, &s->type, buf1);
+ type_to_str(buf, buf_size, &s->type, buf1);
goto no_var;
case VT_PTR:
s = type->ref;
@@ -3087,7 +3178,7 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
snprintf(buf1, sizeof(buf1), "(%s)[%d]", varstr, s->c);
else
snprintf(buf1, sizeof(buf1), "%s[%d]", varstr ? varstr : "", s->c);
- type_to_str(S, buf, buf_size, &s->type, buf1);
+ type_to_str(buf, buf_size, &s->type, buf1);
goto no_var;
}
pstrcpy(buf1, sizeof(buf1), "*");
@@ -3097,7 +3188,7 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
pstrcat(buf1, buf_size, "volatile ");
if (varstr)
pstrcat(buf1, sizeof(buf1), varstr);
- type_to_str(S, buf, buf_size, &s->type, buf1);
+ type_to_str(buf, buf_size, &s->type, buf1);
goto no_var;
}
if (varstr) {
@@ -3107,20 +3198,20 @@ static void type_to_str(TCCState* S, char *buf, int buf_size,
no_var: ;
}
-static void type_incompatibility_error(TCCState* S, CType* st, CType* dt, const char* fmt)
+static void type_incompatibility_error(CType* st, CType* dt, const char* fmt)
{
char buf1[256], buf2[256];
- type_to_str(S, buf1, sizeof(buf1), st, NULL);
- type_to_str(S, buf2, sizeof(buf2), dt, NULL);
- tcc_error(S, fmt, buf1, buf2);
+ type_to_str(buf1, sizeof(buf1), st, NULL);
+ type_to_str(buf2, sizeof(buf2), dt, NULL);
+ tcc_error(fmt, buf1, buf2);
}
-static void type_incompatibility_warning(TCCState* S, CType* st, CType* dt, const char* fmt)
+static void type_incompatibility_warning(CType* st, CType* dt, const char* fmt)
{
char buf1[256], buf2[256];
- type_to_str(S, buf1, sizeof(buf1), st, NULL);
- type_to_str(S, buf2, sizeof(buf2), dt, NULL);
- tcc_warning(S, fmt, buf1, buf2);
+ type_to_str(buf1, sizeof(buf1), st, NULL);
+ type_to_str(buf2, sizeof(buf2), dt, NULL);
+ tcc_warning(fmt, buf1, buf2);
}
static int pointed_size(CType *type)
@@ -3129,10 +3220,10 @@ static int pointed_size(CType *type)
return type_size(pointed_type(type), &align);
}
-static void vla_runtime_pointed_size(TCCState* S, CType *type)
+static void vla_runtime_pointed_size(CType *type)
{
int align;
- vla_runtime_type_size(S, pointed_type(type), &align);
+ vla_runtime_type_size(pointed_type(type), &align);
}
static inline int is_null_pointer(SValue *p)
@@ -3226,7 +3317,7 @@ static int compare_types(CType *type1, CType *type2, int unqualified)
/* Check if OP1 and OP2 can be "combined" with operation OP, the combined
type is stored in DEST if non-null (except for pointer plus/minus) . */
-static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int op)
+static int combine_types(CType *dest, SValue *op1, SValue *op2, int op)
{
CType *type1 = &op1->type, *type2 = &op2->type, type;
int t1 = type1->t, t2 = type2->t, bt1 = t1 & VT_BTYPE, bt2 = t2 & VT_BTYPE;
@@ -3250,7 +3341,7 @@ static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int
with a warning */
if ((op == '?' || TOK_ISCOND(op))
&& (is_integer_btype(bt1) || is_integer_btype(bt2)))
- tcc_warning(S, "pointer/integer mismatch in %s",
+ tcc_warning("pointer/integer mismatch in %s",
op == '?' ? "conditional expression" : "comparison");
else if (op != '-' || !is_integer_btype(bt2))
ret = 0;
@@ -3266,7 +3357,7 @@ static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int
if (op != '?' && !TOK_ISCOND(op))
ret = 0;
else
- type_incompatibility_warning(S, type1, type2,
+ type_incompatibility_warning(type1, type2,
op == '?'
? "pointer type mismatch in conditional expression ('%s' and '%s')"
: "pointer type mismatch in comparison('%s' and '%s')");
@@ -3281,7 +3372,7 @@ static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int
& newquals)
{
/* copy the pointer target symbol */
- type.ref = sym_push(S, SYM_FIELD, &type.ref->type,
+ type.ref = sym_push(SYM_FIELD, &type.ref->type,
0, type.ref->c);
copied = 1;
pointed_type(&type)->t |= newquals;
@@ -3294,10 +3385,10 @@ static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int
&& (pt1->ref->c > 0 || pt2->ref->c > 0))
{
if (!copied)
- type.ref = sym_push(S, SYM_FIELD, &type.ref->type,
+ type.ref = sym_push(SYM_FIELD, &type.ref->type,
0, type.ref->c);
pointed_type(&type)->ref =
- sym_push(S, SYM_FIELD, &pointed_type(&type)->ref->type,
+ sym_push(SYM_FIELD, &pointed_type(&type)->ref->type,
0, pointed_type(&type)->ref->c);
pointed_type(&type)->ref->c =
0 < pt1->ref->c ? pt1->ref->c : pt2->ref->c;
@@ -3343,32 +3434,32 @@ static int combine_types(TCCState* S, CType *dest, SValue *op1, SValue *op2, int
}
/* generic gen_op: handles types problems */
-ST_FUNC void gen_op(TCCState* S, int op)
+ST_FUNC void gen_op(int op)
{
int u, t1, t2, bt1, bt2, t;
CType type1, combtype;
redo:
- t1 = S->tccgen_vtop[-1].type.t;
- t2 = S->tccgen_vtop[0].type.t;
+ t1 = vtop[-1].type.t;
+ t2 = vtop[0].type.t;
bt1 = t1 & VT_BTYPE;
bt2 = t2 & VT_BTYPE;
if (bt1 == VT_FUNC || bt2 == VT_FUNC) {
if (bt2 == VT_FUNC) {
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
+ mk_pointer(&vtop->type);
+ gaddrof();
}
if (bt1 == VT_FUNC) {
- vswap(S);
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
- vswap(S);
+ vswap();
+ mk_pointer(&vtop->type);
+ gaddrof();
+ vswap();
}
goto redo;
- } else if (!combine_types(S, &combtype, S->tccgen_vtop - 1, S->tccgen_vtop, op)) {
- tcc_error_noabort(S, "invalid operand types for binary operation");
- vpop(S);
+ } else if (!combine_types(&combtype, vtop - 1, vtop, op)) {
+ tcc_error_noabort("invalid operand types for binary operation");
+ vpop();
} else if (bt1 == VT_PTR || bt2 == VT_PTR) {
/* at least one operand is a pointer */
/* relational op: must be both pointers */
@@ -3377,71 +3468,71 @@ redo:
/* if both pointers, then it must be the '-' op */
if (bt1 == VT_PTR && bt2 == VT_PTR) {
if (op != '-')
- tcc_error(S, "cannot use pointers here");
- if (S->tccgen_vtop[-1].type.t & VT_VLA) {
- vla_runtime_pointed_size(S, &S->tccgen_vtop[-1].type);
+ tcc_error("cannot use pointers here");
+ if (vtop[-1].type.t & VT_VLA) {
+ vla_runtime_pointed_size(&vtop[-1].type);
} else {
- vpushi(S, pointed_size(&S->tccgen_vtop[-1].type));
+ vpushi(pointed_size(&vtop[-1].type));
}
- vrott(S, 3);
- gen_opic(S, op);
- S->tccgen_vtop->type.t = VT_PTRDIFF_T;
- vswap(S);
- gen_op(S, TOK_PDIV);
+ vrott(3);
+ gen_opic(op);
+ vtop->type.t = VT_PTRDIFF_T;
+ vswap();
+ gen_op(TOK_PDIV);
} else {
/* exactly one pointer : must be '+' or '-'. */
if (op != '-' && op != '+')
- tcc_error(S, "cannot use pointers here");
+ tcc_error("cannot use pointers here");
/* Put pointer as first operand */
if (bt2 == VT_PTR) {
- vswap(S);
+ vswap();
t = t1, t1 = t2, t2 = t;
}
#if PTR_SIZE == 4
- if ((S->tccgen_vtop[0].type.t & VT_BTYPE) == VT_LLONG)
+ if ((vtop[0].type.t & VT_BTYPE) == VT_LLONG)
/* XXX: truncate here because gen_opl can't handle ptr + long long */
- gen_cast_s(S, VT_INT);
+ gen_cast_s(VT_INT);
#endif
- type1 = S->tccgen_vtop[-1].type;
- if (S->tccgen_vtop[-1].type.t & VT_VLA)
- vla_runtime_pointed_size(S, &S->tccgen_vtop[-1].type);
+ type1 = vtop[-1].type;
+ if (vtop[-1].type.t & VT_VLA)
+ vla_runtime_pointed_size(&vtop[-1].type);
else {
- u = pointed_size(&S->tccgen_vtop[-1].type);
+ u = pointed_size(&vtop[-1].type);
if (u < 0)
- tcc_error(S, "unknown array element size");
+ tcc_error("unknown array element size");
#if PTR_SIZE == 8
- vpushll(S, u);
+ vpushll(u);
#else
/* XXX: cast to int ? (long long case) */
- vpushi(S, u);
+ vpushi(u);
#endif
}
- gen_op(S, '*');
+ gen_op('*');
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check && !S->tccgen_const_wanted) {
+ if (tcc_state->do_bounds_check && !const_wanted) {
/* if bounded pointers, we generate a special code to
test bounds */
if (op == '-') {
- vpushi(S, 0);
- vswap(S);
- gen_op(S, '-');
+ vpushi(0);
+ vswap();
+ gen_op('-');
}
- gen_bounded_ptr_add(S);
+ gen_bounded_ptr_add();
} else
#endif
{
- gen_opic(S, op);
+ gen_opic(op);
}
type1.t &= ~VT_ARRAY;
/* put again type if gen_opic() swaped operands */
- S->tccgen_vtop->type = type1;
+ vtop->type = type1;
}
} else {
/* floats can only be used for a few operations */
if (is_float(combtype.t)
&& op != '+' && op != '-' && op != '*' && op != '/'
&& !TOK_ISCOND(op))
- tcc_error(S, "invalid operands for binary operation");
+ tcc_error("invalid operands for binary operation");
else if (op == TOK_SHR || op == TOK_SAR || op == TOK_SHL) {
t = bt1 == VT_LLONG ? VT_LLONG : VT_INT;
if ((t1 & (VT_BTYPE | VT_UNSIGNED | VT_BITFIELD)) == (t | VT_UNSIGNED))
@@ -3469,53 +3560,53 @@ redo:
else if (op == TOK_GE)
op = TOK_UGE;
}
- vswap(S);
- gen_cast_s(S, t);
- vswap(S);
+ vswap();
+ gen_cast_s(t);
+ vswap();
/* special case for shifts and long long: we keep the shift as
an integer */
if (op == TOK_SHR || op == TOK_SAR || op == TOK_SHL)
t2 = VT_INT;
- gen_cast_s(S, t2);
+ gen_cast_s(t2);
if (is_float(t))
- gen_opif(S, op);
+ gen_opif(op);
else
- gen_opic(S, op);
+ gen_opic(op);
if (TOK_ISCOND(op)) {
/* relational op: the result is an int */
- S->tccgen_vtop->type.t = VT_INT;
+ vtop->type.t = VT_INT;
} else {
- S->tccgen_vtop->type.t = t;
+ vtop->type.t = t;
}
}
// Make sure that we have converted to an rvalue:
- if (S->tccgen_vtop->r & VT_LVAL)
- gv(S, is_float(S->tccgen_vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT);
+ if (vtop->r & VT_LVAL)
+ gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT);
}
#if defined TCC_TARGET_ARM64 || defined TCC_TARGET_RISCV64 || defined TCC_TARGET_ARM
#define gen_cvt_itof1 gen_cvt_itof
#else
/* generic itof for unsigned long long case */
-static void gen_cvt_itof1(TCCState* S, int t)
+static void gen_cvt_itof1(int t)
{
- if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
+ if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
(VT_LLONG | VT_UNSIGNED)) {
if (t == VT_FLOAT)
- vpush_helper_func(S, TOK___floatundisf);
+ vpush_helper_func(TOK___floatundisf);
#if LDOUBLE_SIZE != 8
else if (t == VT_LDOUBLE)
- vpush_helper_func(S, TOK___floatundixf);
+ vpush_helper_func(TOK___floatundixf);
#endif
else
- vpush_helper_func(S, TOK___floatundidf);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- PUT_R_RET(S->tccgen_vtop, t);
+ vpush_helper_func(TOK___floatundidf);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ PUT_R_RET(vtop, t);
} else {
- gen_cvt_itof(S, t);
+ gen_cvt_itof(t);
}
}
#endif
@@ -3524,65 +3615,65 @@ static void gen_cvt_itof1(TCCState* S, int t)
#define gen_cvt_ftoi1 gen_cvt_ftoi
#else
/* generic ftoi for unsigned long long case */
-static void gen_cvt_ftoi1(TCCState* S, int t)
+static void gen_cvt_ftoi1(int t)
{
int st;
if (t == (VT_LLONG | VT_UNSIGNED)) {
/* not handled natively */
- st = S->tccgen_vtop->type.t & VT_BTYPE;
+ st = vtop->type.t & VT_BTYPE;
if (st == VT_FLOAT)
- vpush_helper_func(S, TOK___fixunssfdi);
+ vpush_helper_func(TOK___fixunssfdi);
#if LDOUBLE_SIZE != 8
else if (st == VT_LDOUBLE)
- vpush_helper_func(S, TOK___fixunsxfdi);
+ vpush_helper_func(TOK___fixunsxfdi);
#endif
else
- vpush_helper_func(S, TOK___fixunsdfdi);
- vrott(S, 2);
- gfunc_call(S, 1);
- vpushi(S, 0);
- PUT_R_RET(S->tccgen_vtop, t);
+ vpush_helper_func(TOK___fixunsdfdi);
+ vrott(2);
+ gfunc_call(1);
+ vpushi(0);
+ PUT_R_RET(vtop, t);
} else {
- gen_cvt_ftoi(S, t);
+ gen_cvt_ftoi(t);
}
}
#endif
/* special delayed cast for char/short */
-static void force_charshort_cast(TCCState* S)
+static void force_charshort_cast(void)
{
- int sbt = BFGET(S->tccgen_vtop->r, VT_MUSTCAST) == 2 ? VT_LLONG : VT_INT;
- int dbt = S->tccgen_vtop->type.t;
- S->tccgen_vtop->r &= ~VT_MUSTCAST;
- S->tccgen_vtop->type.t = sbt;
- gen_cast_s(S, dbt == VT_BOOL ? VT_BYTE|VT_UNSIGNED : dbt);
- S->tccgen_vtop->type.t = dbt;
+ int sbt = BFGET(vtop->r, VT_MUSTCAST) == 2 ? VT_LLONG : VT_INT;
+ int dbt = vtop->type.t;
+ vtop->r &= ~VT_MUSTCAST;
+ vtop->type.t = sbt;
+ gen_cast_s(dbt == VT_BOOL ? VT_BYTE|VT_UNSIGNED : dbt);
+ vtop->type.t = dbt;
}
-static void gen_cast_s(TCCState* S, int t)
+static void gen_cast_s(int t)
{
CType type;
type.t = t;
type.ref = NULL;
- gen_cast(S, &type);
+ gen_cast(&type);
}
/* cast 'vtop' to 'type'. Casting to bitfields is forbidden. */
-static void gen_cast(TCCState* S, CType *type)
+static void gen_cast(CType *type)
{
int sbt, dbt, sf, df, c;
int dbt_bt, sbt_bt, ds, ss, bits, trunc;
/* special delayed cast for char/short */
- if (S->tccgen_vtop->r & VT_MUSTCAST)
- force_charshort_cast(S);
+ if (vtop->r & VT_MUSTCAST)
+ force_charshort_cast();
/* bitfields first get cast to ints */
- if (S->tccgen_vtop->type.t & VT_BITFIELD)
- gv(S, RC_INT);
+ if (vtop->type.t & VT_BITFIELD)
+ gv(RC_INT);
dbt = type->t & (VT_BTYPE | VT_UNSIGNED);
- sbt = S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED);
+ sbt = vtop->type.t & (VT_BTYPE | VT_UNSIGNED);
if (sbt == VT_FUNC)
sbt = VT_PTR;
@@ -3596,71 +3687,71 @@ again:
goto done;
if (sbt_bt == VT_VOID) {
error:
- cast_error(S, &S->tccgen_vtop->type, type);
+ cast_error(&vtop->type, type);
}
- c = (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
+ c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
#if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387
- c &= (dbt != VT_LDOUBLE) | !!S->tccgen_nocode_wanted;
+ c &= (dbt != VT_LDOUBLE) | !!nocode_wanted;
#endif
if (c) {
/* constant case: we can do it now */
/* XXX: in ISOC, cannot do it if error in convert */
if (sbt == VT_FLOAT)
- S->tccgen_vtop->c.ld = S->tccgen_vtop->c.f;
+ vtop->c.ld = vtop->c.f;
else if (sbt == VT_DOUBLE)
- S->tccgen_vtop->c.ld = S->tccgen_vtop->c.d;
+ vtop->c.ld = vtop->c.d;
if (df) {
if (sbt_bt == VT_LLONG) {
- if ((sbt & VT_UNSIGNED) || !(S->tccgen_vtop->c.i >> 63))
- S->tccgen_vtop->c.ld = S->tccgen_vtop->c.i;
+ if ((sbt & VT_UNSIGNED) || !(vtop->c.i >> 63))
+ vtop->c.ld = vtop->c.i;
else
- S->tccgen_vtop->c.ld = -(long double)-S->tccgen_vtop->c.i;
+ vtop->c.ld = -(long double)-vtop->c.i;
} else if(!sf) {
- if ((sbt & VT_UNSIGNED) || !(S->tccgen_vtop->c.i >> 31))
- S->tccgen_vtop->c.ld = (uint32_t)S->tccgen_vtop->c.i;
+ if ((sbt & VT_UNSIGNED) || !(vtop->c.i >> 31))
+ vtop->c.ld = (uint32_t)vtop->c.i;
else
- S->tccgen_vtop->c.ld = -(long double)-(uint32_t)S->tccgen_vtop->c.i;
+ vtop->c.ld = -(long double)-(uint32_t)vtop->c.i;
}
if (dbt == VT_FLOAT)
- S->tccgen_vtop->c.f = (float)S->tccgen_vtop->c.ld;
+ vtop->c.f = (float)vtop->c.ld;
else if (dbt == VT_DOUBLE)
- S->tccgen_vtop->c.d = (double)S->tccgen_vtop->c.ld;
+ vtop->c.d = (double)vtop->c.ld;
} else if (sf && dbt == VT_BOOL) {
- S->tccgen_vtop->c.i = (S->tccgen_vtop->c.ld != 0);
+ vtop->c.i = (vtop->c.ld != 0);
} else {
if(sf)
- S->tccgen_vtop->c.i = S->tccgen_vtop->c.ld;
+ vtop->c.i = vtop->c.ld;
else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR))
;
else if (sbt & VT_UNSIGNED)
- S->tccgen_vtop->c.i = (uint32_t)S->tccgen_vtop->c.i;
+ vtop->c.i = (uint32_t)vtop->c.i;
else
- S->tccgen_vtop->c.i = ((uint32_t)S->tccgen_vtop->c.i | -(S->tccgen_vtop->c.i & 0x80000000));
+ vtop->c.i = ((uint32_t)vtop->c.i | -(vtop->c.i & 0x80000000));
if (dbt_bt == VT_LLONG || (PTR_SIZE == 8 && dbt == VT_PTR))
;
else if (dbt == VT_BOOL)
- S->tccgen_vtop->c.i = (S->tccgen_vtop->c.i != 0);
+ vtop->c.i = (vtop->c.i != 0);
else {
uint32_t m = dbt_bt == VT_BYTE ? 0xff :
dbt_bt == VT_SHORT ? 0xffff :
0xffffffff;
- S->tccgen_vtop->c.i &= m;
+ vtop->c.i &= m;
if (!(dbt & VT_UNSIGNED))
- S->tccgen_vtop->c.i |= -(S->tccgen_vtop->c.i & ((m >> 1) + 1));
+ vtop->c.i |= -(vtop->c.i & ((m >> 1) + 1));
}
}
goto done;
} else if (dbt == VT_BOOL
- && (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM))
+ && (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM))
== (VT_CONST | VT_SYM)) {
/* addresses are considered non-zero (see tcctest.c:sinit23) */
- S->tccgen_vtop->r = VT_CONST;
- S->tccgen_vtop->c.i = 1;
+ vtop->r = VT_CONST;
+ vtop->c.i = 1;
goto done;
}
@@ -3670,23 +3761,23 @@ error:
/* non constant case: generate code */
if (dbt == VT_BOOL) {
- gen_test_zero(S, TOK_NE);
+ gen_test_zero(TOK_NE);
goto done;
}
if (sf || df) {
if (sf && df) {
/* convert from fp to fp */
- gen_cvt_ftof(S, dbt);
+ gen_cvt_ftof(dbt);
} else if (df) {
/* convert int to fp */
- gen_cvt_itof1(S, dbt);
+ gen_cvt_itof1(dbt);
} else {
/* convert fp to int */
sbt = dbt;
if (dbt_bt != VT_LLONG && dbt_bt != VT_INT)
sbt = VT_INT;
- gen_cvt_ftoi1(S, sbt);
+ gen_cvt_ftoi1(sbt);
goto again; /* may need char/short cast */
}
goto done;
@@ -3698,16 +3789,16 @@ error:
goto error;
if (IS_ENUM(type->t) && type->ref->c < 0)
- tcc_error(S, "cast to incomplete type");
+ tcc_error("cast to incomplete type");
/* same size and no sign conversion needed */
if (ds == ss && ds >= 4)
goto done;
if (dbt_bt == VT_PTR || sbt_bt == VT_PTR) {
- tcc_warning(S, "cast between pointer and integer of different size");
+ tcc_warning("cast between pointer and integer of different size");
if (sbt_bt == VT_PTR) {
/* put integer type to allow logical operations below */
- S->tccgen_vtop->type.t = (PTR_SIZE == 8 ? VT_LLONG : VT_INT);
+ vtop->type.t = (PTR_SIZE == 8 ? VT_LLONG : VT_INT);
}
}
@@ -3716,35 +3807,35 @@ error:
change the type and read it still later. */
#define ALLOW_SUBTYPE_ACCESS 1
- if (ALLOW_SUBTYPE_ACCESS && (S->tccgen_vtop->r & VT_LVAL)) {
+ if (ALLOW_SUBTYPE_ACCESS && (vtop->r & VT_LVAL)) {
/* value still in memory */
if (ds <= ss)
goto done;
/* ss <= 4 here */
if (ds <= 4 && !(dbt == (VT_SHORT | VT_UNSIGNED) && sbt == VT_BYTE)) {
- gv(S, RC_INT);
+ gv(RC_INT);
goto done; /* no 64bit envolved */
}
}
- gv(S, RC_INT);
+ gv(RC_INT);
trunc = 0;
#if PTR_SIZE == 4
if (ds == 8) {
/* generate high word */
if (sbt & VT_UNSIGNED) {
- vpushi(S, 0);
- gv(S, RC_INT);
+ vpushi(0);
+ gv(RC_INT);
} else {
- gv_dup(S);
- vpushi(S, 31);
- gen_op(S, TOK_SAR);
+ gv_dup();
+ vpushi(31);
+ gen_op(TOK_SAR);
}
- lbuild(S, dbt);
+ lbuild(dbt);
} else if (ss == 8) {
/* from long long: just take low order word */
- lexpand(S);
- vpop(S);
+ lexpand();
+ vpop();
}
ss = 4;
@@ -3760,7 +3851,7 @@ error:
goto done;
#endif
} else {
- gen_cvt_sxtw(S);
+ gen_cvt_sxtw();
goto done;
}
ss = ds, ds = 4, dbt = sbt;
@@ -3780,23 +3871,23 @@ error:
goto done;
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM64
if (ss == 4) {
- gen_cvt_csti(S, dbt);
+ gen_cvt_csti(dbt);
goto done;
}
#endif
bits = (ss - ds) * 8;
/* for unsigned, gen_op will convert SAR to SHR */
- S->tccgen_vtop->type.t = (ss == 8 ? VT_LLONG : VT_INT) | (dbt & VT_UNSIGNED);
- vpushi(S, bits);
- gen_op(S, TOK_SHL);
- vpushi(S, bits - trunc);
- gen_op(S, TOK_SAR);
- vpushi(S, trunc);
- gen_op(S, TOK_SHR);
+ vtop->type.t = (ss == 8 ? VT_LLONG : VT_INT) | (dbt & VT_UNSIGNED);
+ vpushi(bits);
+ gen_op(TOK_SHL);
+ vpushi(bits - trunc);
+ gen_op(TOK_SAR);
+ vpushi(trunc);
+ gen_op(TOK_SHR);
}
done:
- S->tccgen_vtop->type = *type;
- S->tccgen_vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY );
+ vtop->type = *type;
+ vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY );
}
/* return type size as known at compile time. Put alignment at 'a' */
@@ -3866,13 +3957,13 @@ ST_FUNC int type_size(CType *type, int *a)
/* push type size as known at runtime time on top of value stack. Put
alignment at 'a' */
-ST_FUNC void vla_runtime_type_size(TCCState* S, CType *type, int *a)
+ST_FUNC void vla_runtime_type_size(CType *type, int *a)
{
if (type->t & VT_VLA) {
type_size(&type->ref->type, a);
- vset(S, &S->tccgen_int_type, VT_LOCAL|VT_LVAL, type->ref->c);
+ vset(&int_type, VT_LOCAL|VT_LVAL, type->ref->c);
} else {
- vpushi(S, type_size(type, a));
+ vpushi(type_size(type, a));
}
}
@@ -3883,10 +3974,10 @@ static inline CType *pointed_type(CType *type)
}
/* modify type so that its it is a pointer to type. */
-ST_FUNC void mk_pointer(TCCState* S, CType *type)
+ST_FUNC void mk_pointer(CType *type)
{
Sym *s;
- s = sym_push(S, SYM_FIELD, type, 0, -1);
+ s = sym_push(SYM_FIELD, type, 0, -1);
type->t = VT_PTR | (type->t & VT_STORAGE);
type->ref = s;
}
@@ -3906,35 +3997,35 @@ static int is_compatible_unqualified_types(CType *type1, CType *type2)
return compare_types(type1,type2,1);
}
-static void cast_error(TCCState* S, CType *st, CType *dt)
+static void cast_error(CType *st, CType *dt)
{
- type_incompatibility_error(S, st, dt, "cannot convert '%s' to '%s'");
+ type_incompatibility_error(st, dt, "cannot convert '%s' to '%s'");
}
/* verify type compatibility to store vtop in 'dt' type */
-static void verify_assign_cast(TCCState* S, CType *dt)
+static void verify_assign_cast(CType *dt)
{
CType *st, *type1, *type2;
int dbt, sbt, qualwarn, lvl;
- st = &S->tccgen_vtop->type; /* source type */
+ st = &vtop->type; /* source type */
dbt = dt->t & VT_BTYPE;
sbt = st->t & VT_BTYPE;
if (dt->t & VT_CONSTANT)
- tcc_warning(S, "assignment of read-only location");
+ tcc_warning("assignment of read-only location");
switch(dbt) {
case VT_VOID:
if (sbt != dbt)
- tcc_error(S, "assignment to void expression");
+ tcc_error("assignment to void expression");
break;
case VT_PTR:
/* special cases for pointers */
/* '0' can also be a pointer */
- if (is_null_pointer(S->tccgen_vtop))
+ if (is_null_pointer(vtop))
break;
/* accept implicit pointer to integer cast with warning */
if (is_integer_btype(sbt)) {
- tcc_warning(S, "assignment makes pointer from integer without a cast");
+ tcc_warning("assignment makes pointer from integer without a cast");
break;
}
type1 = pointed_type(dt);
@@ -3969,19 +4060,19 @@ static void verify_assign_cast(TCCState* S, CType *dt)
base types, though, in particular for unsigned enums
and signed int targets. */
} else {
- tcc_warning(S, "assignment from incompatible pointer type");
+ tcc_warning("assignment from incompatible pointer type");
break;
}
}
if (qualwarn)
- tcc_warning_c(warn_discarded_qualifiers)(S, "assignment discards qualifiers from pointer target type");
+ tcc_warning_c(warn_discarded_qualifiers)("assignment discards qualifiers from pointer target type");
break;
case VT_BYTE:
case VT_SHORT:
case VT_INT:
case VT_LLONG:
if (sbt == VT_PTR || sbt == VT_FUNC) {
- tcc_warning(S, "assignment makes integer from pointer without a cast");
+ tcc_warning("assignment makes integer from pointer without a cast");
} else if (sbt == VT_STRUCT) {
goto case_VT_STRUCT;
}
@@ -3991,221 +4082,221 @@ static void verify_assign_cast(TCCState* S, CType *dt)
case_VT_STRUCT:
if (!is_compatible_unqualified_types(dt, st)) {
error:
- cast_error(S, st, dt);
+ cast_error(st, dt);
}
break;
}
}
-static void gen_assign_cast(TCCState* S, CType *dt)
+static void gen_assign_cast(CType *dt)
{
- verify_assign_cast(S, dt);
- gen_cast(S, dt);
+ verify_assign_cast(dt);
+ gen_cast(dt);
}
/* store vtop in lvalue pushed on stack */
-ST_FUNC void vstore(TCCState* S)
+ST_FUNC void vstore(void)
{
int sbt, dbt, ft, r, size, align, bit_size, bit_pos, delayed_cast;
- ft = S->tccgen_vtop[-1].type.t;
- sbt = S->tccgen_vtop->type.t & VT_BTYPE;
+ ft = vtop[-1].type.t;
+ sbt = vtop->type.t & VT_BTYPE;
dbt = ft & VT_BTYPE;
- verify_assign_cast(S, &S->tccgen_vtop[-1].type);
+ verify_assign_cast(&vtop[-1].type);
if (sbt == VT_STRUCT) {
/* if structure, only generate pointer */
/* structure assignment : generate memcpy */
/* XXX: optimize if small size */
- size = type_size(&S->tccgen_vtop->type, &align);
+ size = type_size(&vtop->type, &align);
/* destination */
- vswap(S);
+ vswap();
#ifdef CONFIG_TCC_BCHECK
- if (S->tccgen_vtop->r & VT_MUSTBOUND)
- gbound(S); /* check would be wrong after gaddrof() */
+ if (vtop->r & VT_MUSTBOUND)
+ gbound(); /* check would be wrong after gaddrof() */
#endif
- S->tccgen_vtop->type.t = VT_PTR;
- gaddrof(S);
+ vtop->type.t = VT_PTR;
+ gaddrof();
/* address of memcpy() */
#ifdef TCC_ARM_EABI
if(!(align & 7))
- vpush_helper_func(S, TOK_memmove8);
+ vpush_helper_func(TOK_memmove8);
else if(!(align & 3))
- vpush_helper_func(S, TOK_memmove4);
+ vpush_helper_func(TOK_memmove4);
else
#endif
/* Use memmove, rather than memcpy, as dest and src may be same: */
- vpush_helper_func(S, TOK_memmove);
+ vpush_helper_func(TOK_memmove);
- vswap(S);
+ vswap();
/* source */
- vpushv(S, S->tccgen_vtop - 2);
+ vpushv(vtop - 2);
#ifdef CONFIG_TCC_BCHECK
- if (S->tccgen_vtop->r & VT_MUSTBOUND)
- gbound(S);
+ if (vtop->r & VT_MUSTBOUND)
+ gbound();
#endif
- S->tccgen_vtop->type.t = VT_PTR;
- gaddrof(S);
+ vtop->type.t = VT_PTR;
+ gaddrof();
/* type size */
- vpushi(S, size);
- gfunc_call(S, 3);
+ vpushi(size);
+ gfunc_call(3);
/* leave source on stack */
} else if (ft & VT_BITFIELD) {
/* bitfield store handling */
/* save lvalue as expression result (example: s.b = s.a = n;) */
- vdup(S), S->tccgen_vtop[-1] = S->tccgen_vtop[-2];
+ vdup(), vtop[-1] = vtop[-2];
bit_pos = BIT_POS(ft);
bit_size = BIT_SIZE(ft);
/* remove bit field info to avoid loops */
- S->tccgen_vtop[-1].type.t = ft & ~VT_STRUCT_MASK;
+ vtop[-1].type.t = ft & ~VT_STRUCT_MASK;
if (dbt == VT_BOOL) {
- gen_cast(S, &S->tccgen_vtop[-1].type);
- S->tccgen_vtop[-1].type.t = (S->tccgen_vtop[-1].type.t & ~VT_BTYPE) | (VT_BYTE | VT_UNSIGNED);
+ gen_cast(&vtop[-1].type);
+ vtop[-1].type.t = (vtop[-1].type.t & ~VT_BTYPE) | (VT_BYTE | VT_UNSIGNED);
}
- r = adjust_bf(S->tccgen_vtop - 1, bit_pos, bit_size);
+ r = adjust_bf(vtop - 1, bit_pos, bit_size);
if (dbt != VT_BOOL) {
- gen_cast(S, &S->tccgen_vtop[-1].type);
- dbt = S->tccgen_vtop[-1].type.t & VT_BTYPE;
+ gen_cast(&vtop[-1].type);
+ dbt = vtop[-1].type.t & VT_BTYPE;
}
if (r == VT_STRUCT) {
- store_packed_bf(S, bit_pos, bit_size);
+ store_packed_bf(bit_pos, bit_size);
} else {
unsigned long long mask = (1ULL << bit_size) - 1;
if (dbt != VT_BOOL) {
/* mask source */
if (dbt == VT_LLONG)
- vpushll(S, mask);
+ vpushll(mask);
else
- vpushi(S, (unsigned)mask);
- gen_op(S, '&');
+ vpushi((unsigned)mask);
+ gen_op('&');
}
/* shift source */
- vpushi(S, bit_pos);
- gen_op(S, TOK_SHL);
- vswap(S);
+ vpushi(bit_pos);
+ gen_op(TOK_SHL);
+ vswap();
/* duplicate destination */
- vdup(S);
- vrott(S, 3);
+ vdup();
+ vrott(3);
/* load destination, mask and or with source */
if (dbt == VT_LLONG)
- vpushll(S, ~(mask << bit_pos));
+ vpushll(~(mask << bit_pos));
else
- vpushi(S, ~((unsigned)mask << bit_pos));
- gen_op(S, '&');
- gen_op(S, '|');
+ vpushi(~((unsigned)mask << bit_pos));
+ gen_op('&');
+ gen_op('|');
/* store result */
- vstore(S);
+ vstore();
/* ... and discard */
- vpop(S);
+ vpop();
}
} else if (dbt == VT_VOID) {
- --S->tccgen_vtop;
+ --vtop;
} else {
/* optimize char/short casts */
delayed_cast = 0;
if ((dbt == VT_BYTE || dbt == VT_SHORT)
&& is_integer_btype(sbt)
) {
- if ((S->tccgen_vtop->r & VT_MUSTCAST)
+ if ((vtop->r & VT_MUSTCAST)
&& btype_size(dbt) > btype_size(sbt)
)
- force_charshort_cast(S);
+ force_charshort_cast();
delayed_cast = 1;
} else {
- gen_cast(S, &S->tccgen_vtop[-1].type);
+ gen_cast(&vtop[-1].type);
}
#ifdef CONFIG_TCC_BCHECK
/* bound check case */
- if (S->tccgen_vtop[-1].r & VT_MUSTBOUND) {
- vswap(S);
- gbound(S);
- vswap(S);
+ if (vtop[-1].r & VT_MUSTBOUND) {
+ vswap();
+ gbound();
+ vswap();
}
#endif
- gv(S, RC_TYPE(dbt)); /* generate value */
+ gv(RC_TYPE(dbt)); /* generate value */
if (delayed_cast) {
- S->tccgen_vtop->r |= BFVAL(VT_MUSTCAST, (sbt == VT_LLONG) + 1);
- //tcc_warning(S, "deley cast %x -> %x", sbt, dbt);
- S->tccgen_vtop->type.t = ft & VT_TYPE;
+ vtop->r |= BFVAL(VT_MUSTCAST, (sbt == VT_LLONG) + 1);
+ //tcc_warning("deley cast %x -> %x", sbt, dbt);
+ vtop->type.t = ft & VT_TYPE;
}
/* if lvalue was saved on stack, must read it */
- if ((S->tccgen_vtop[-1].r & VT_VALMASK) == VT_LLOCAL) {
+ if ((vtop[-1].r & VT_VALMASK) == VT_LLOCAL) {
SValue sv;
- r = get_reg(S, RC_INT);
+ r = get_reg(RC_INT);
sv.type.t = VT_PTRDIFF_T;
sv.r = VT_LOCAL | VT_LVAL;
- sv.c.i = S->tccgen_vtop[-1].c.i;
- load(S, r, &sv);
- S->tccgen_vtop[-1].r = r | VT_LVAL;
+ sv.c.i = vtop[-1].c.i;
+ load(r, &sv);
+ vtop[-1].r = r | VT_LVAL;
}
- r = S->tccgen_vtop->r & VT_VALMASK;
+ r = vtop->r & VT_VALMASK;
/* two word case handling :
store second register at word + 4 (or +8 for x86-64) */
if (USING_TWO_WORDS(dbt)) {
int load_type = (dbt == VT_QFLOAT) ? VT_DOUBLE : VT_PTRDIFF_T;
- S->tccgen_vtop[-1].type.t = load_type;
- store(S, r, S->tccgen_vtop - 1);
- vswap(S);
+ vtop[-1].type.t = load_type;
+ store(r, vtop - 1);
+ vswap();
/* convert to int to increment easily */
- S->tccgen_vtop->type.t = VT_PTRDIFF_T;
- gaddrof(S);
- vpushs(S, PTR_SIZE);
- gen_op(S, '+');
- S->tccgen_vtop->r |= VT_LVAL;
- vswap(S);
- S->tccgen_vtop[-1].type.t = load_type;
+ vtop->type.t = VT_PTRDIFF_T;
+ gaddrof();
+ vpushs(PTR_SIZE);
+ gen_op('+');
+ vtop->r |= VT_LVAL;
+ vswap();
+ vtop[-1].type.t = load_type;
/* XXX: it works because r2 is spilled last ! */
- store(S, S->tccgen_vtop->r2, S->tccgen_vtop - 1);
+ store(vtop->r2, vtop - 1);
} else {
/* single word */
- store(S, r, S->tccgen_vtop - 1);
+ store(r, vtop - 1);
}
- vswap(S);
- S->tccgen_vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
+ vswap();
+ vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
}
}
/* post defines POST/PRE add. c is the token ++ or -- */
-ST_FUNC void inc(TCCState* S, int post, int c)
+ST_FUNC void inc(int post, int c)
{
- test_lvalue(S);
- vdup(S); /* save lvalue */
+ test_lvalue();
+ vdup(); /* save lvalue */
if (post) {
- gv_dup(S); /* duplicate value */
- vrotb(S, 3);
- vrotb(S, 3);
+ gv_dup(); /* duplicate value */
+ vrotb(3);
+ vrotb(3);
}
/* add constant */
- vpushi(S, c - TOK_MID);
- gen_op(S, '+');
- vstore(S); /* store value */
+ vpushi(c - TOK_MID);
+ gen_op('+');
+ vstore(); /* store value */
if (post)
- vpop(S); /* if post op, return saved value */
+ vpop(); /* if post op, return saved value */
}
-ST_FUNC void parse_mult_str (TCCState* S, CString *astr, const char *msg)
+ST_FUNC void parse_mult_str (CString *astr, const char *msg)
{
/* read the string */
- if (S->tccpp_tok != TOK_STR)
- expect(S, msg);
- cstr_new(S, astr);
- while (S->tccpp_tok == TOK_STR) {
+ if (tok != TOK_STR)
+ expect(msg);
+ cstr_new(astr);
+ while (tok == TOK_STR) {
/* XXX: add \0 handling too ? */
- cstr_cat(S, astr, S->tccpp_tokc.str.data, -1);
- next(S);
+ cstr_cat(astr, tokc.str.data, -1);
+ next();
}
- cstr_ccat(S, astr, '\0');
+ cstr_ccat(astr, '\0');
}
/* If I is >= 1 and a power of two, returns log2(i)+1.
@@ -4227,39 +4318,39 @@ ST_FUNC int exact_log2p1(int i)
}
/* Parse __attribute__((...)) GNUC extension. */
-static void parse_attribute(TCCState* S, AttributeDef *ad)
+static void parse_attribute(AttributeDef *ad)
{
int t, n;
CString astr;
redo:
- if (S->tccpp_tok != TOK_ATTRIBUTE1 && S->tccpp_tok != TOK_ATTRIBUTE2)
+ if (tok != TOK_ATTRIBUTE1 && tok != TOK_ATTRIBUTE2)
return;
- next(S);
- skip(S, '(');
- skip(S, '(');
- while (S->tccpp_tok != ')') {
- if (S->tccpp_tok < TOK_IDENT)
- expect(S, "attribute name");
- t = S->tccpp_tok;
- next(S);
+ next();
+ skip('(');
+ skip('(');
+ while (tok != ')') {
+ if (tok < TOK_IDENT)
+ expect("attribute name");
+ t = tok;
+ next();
switch(t) {
case TOK_CLEANUP1:
case TOK_CLEANUP2:
{
Sym *s;
- skip(S, '(');
- s = sym_find(S, S->tccpp_tok);
+ skip('(');
+ s = sym_find(tok);
if (!s) {
- tcc_warning_c(warn_implicit_function_declaration)(S,
- "implicit declaration of function '%s'", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
- s = external_global_sym(S, S->tccpp_tok, &S->tccgen_func_old_type);
+ tcc_warning_c(warn_implicit_function_declaration)(
+ "implicit declaration of function '%s'", get_tok_str(tok, &tokc));
+ s = external_global_sym(tok, &func_old_type);
} else if ((s->type.t & VT_BTYPE) != VT_FUNC)
- tcc_error(S, "'%s' is not declared as function", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_error("'%s' is not declared as function", get_tok_str(tok, &tokc));
ad->cleanup_func = s;
- next(S);
- skip(S, ')');
+ next();
+ skip(')');
break;
}
case TOK_CONSTRUCTOR1:
@@ -4276,25 +4367,25 @@ redo:
break;
case TOK_SECTION1:
case TOK_SECTION2:
- skip(S, '(');
- parse_mult_str(S, &astr, "section name");
- ad->section = find_section(S, (char *)astr.data);
- skip(S, ')');
- cstr_free(S, &astr);
+ skip('(');
+ parse_mult_str(&astr, "section name");
+ ad->section = find_section(tcc_state, (char *)astr.data);
+ skip(')');
+ cstr_free(&astr);
break;
case TOK_ALIAS1:
case TOK_ALIAS2:
- skip(S, '(');
- parse_mult_str(S, &astr, "alias(\"target\")");
+ skip('(');
+ parse_mult_str(&astr, "alias(\"target\")");
ad->alias_target = /* save string as token, for later */
- tok_alloc(S, (char*)astr.data, astr.size-1)->tok;
- skip(S, ')');
- cstr_free(S, &astr);
+ tok_alloc((char*)astr.data, astr.size-1)->tok;
+ skip(')');
+ cstr_free(&astr);
break;
case TOK_VISIBILITY1:
case TOK_VISIBILITY2:
- skip(S, '(');
- parse_mult_str(S, &astr,
+ skip('(');
+ parse_mult_str(&astr,
"visibility(\"default|hidden|internal|protected\")");
if (!strcmp (astr.data, "default"))
ad->a.visibility = STV_DEFAULT;
@@ -4305,24 +4396,24 @@ redo:
else if (!strcmp (astr.data, "protected"))
ad->a.visibility = STV_PROTECTED;
else
- expect(S, "visibility(\"default|hidden|internal|protected\")");
- skip(S, ')');
- cstr_free(S, &astr);
+ expect("visibility(\"default|hidden|internal|protected\")");
+ skip(')');
+ cstr_free(&astr);
break;
case TOK_ALIGNED1:
case TOK_ALIGNED2:
- if (S->tccpp_tok == '(') {
- next(S);
- n = expr_const(S);
+ if (tok == '(') {
+ next();
+ n = expr_const();
if (n <= 0 || (n & (n - 1)) != 0)
- tcc_error(S, "alignment must be a positive power of two");
- skip(S, ')');
+ tcc_error("alignment must be a positive power of two");
+ skip(')');
} else {
n = MAX_ALIGN;
}
ad->a.aligned = exact_log2p1(n);
if (n != 1 << (ad->a.aligned - 1))
- tcc_error(S, "alignment of %d is larger than implemented", n);
+ tcc_error("alignment of %d is larger than implemented", n);
break;
case TOK_PACKED1:
case TOK_PACKED2:
@@ -4354,15 +4445,15 @@ redo:
#ifdef TCC_TARGET_I386
case TOK_REGPARM1:
case TOK_REGPARM2:
- skip(S, '(');
- n = expr_const(S);
+ skip('(');
+ n = expr_const();
if (n > 3)
n = 3;
else if (n < 0)
n = 0;
if (n > 0)
ad->f.func_call = FUNC_FASTCALL1 + n - 1;
- skip(S, ')');
+ skip(')');
break;
case TOK_FASTCALL1:
case TOK_FASTCALL2:
@@ -4371,8 +4462,8 @@ redo:
break;
#endif
case TOK_MODE:
- skip(S, '(');
- switch(S->tccpp_tok) {
+ skip('(');
+ switch(tok) {
case TOK_MODE_DI:
ad->attr_mode = VT_LLONG + 1;
break;
@@ -4387,11 +4478,11 @@ redo:
ad->attr_mode = VT_INT + 1;
break;
default:
- tcc_warning(S, "__mode__(%s) not supported\n", get_tok_str(S, S->tccpp_tok, NULL));
+ tcc_warning("__mode__(%s) not supported\n", get_tok_str(tok, NULL));
break;
}
- next(S);
- skip(S, ')');
+ next();
+ skip(')');
break;
case TOK_DLLEXPORT:
ad->a.dllexport = 1;
@@ -4403,26 +4494,26 @@ redo:
ad->a.dllimport = 1;
break;
default:
- tcc_warning_c(warn_unsupported)(S, "'%s' attribute ignored", get_tok_str(S, t, NULL));
+ tcc_warning_c(warn_unsupported)("'%s' attribute ignored", get_tok_str(t, NULL));
/* skip parameters */
- if (S->tccpp_tok == '(') {
+ if (tok == '(') {
int parenthesis = 0;
do {
- if (S->tccpp_tok == '(')
+ if (tok == '(')
parenthesis++;
- else if (S->tccpp_tok == ')')
+ else if (tok == ')')
parenthesis--;
- next(S);
- } while (parenthesis && S->tccpp_tok != -1);
+ next();
+ } while (parenthesis && tok != -1);
}
break;
}
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S);
+ next();
}
- skip(S, ')');
- skip(S, ')');
+ skip(')');
+ skip(')');
goto redo;
}
@@ -4446,28 +4537,28 @@ static Sym * find_field (CType *type, int v, int *cumofs)
return s;
}
-static void check_fields (TCCState* S, CType *type, int check)
+static void check_fields (CType *type, int check)
{
Sym *s = type->ref;
while ((s = s->next) != NULL) {
int v = s->v & ~SYM_FIELD;
if (v < SYM_FIRST_ANOM) {
- TokenSym *ts = S->tccpp_table_ident[v - TOK_IDENT];
+ TokenSym *ts = table_ident[v - TOK_IDENT];
if (check && (ts->tok & SYM_FIELD))
- tcc_error(S, "duplicate member '%s'", get_tok_str(S, v, NULL));
+ tcc_error("duplicate member '%s'", get_tok_str(v, NULL));
ts->tok ^= SYM_FIELD;
} else if ((s->type.t & VT_BTYPE) == VT_STRUCT)
- check_fields (S, &s->type, check);
+ check_fields (&s->type, check);
}
}
-static void struct_layout(TCCState* S, CType *type, AttributeDef *ad)
+static void struct_layout(CType *type, AttributeDef *ad)
{
int size, align, maxalign, offset, c, bit_pos, bit_size;
int packed, a, bt, prevbt, prev_bit_size;
- int pcc = !S->ms_bitfields;
- int pragma_pack = *S->pack_stack_ptr;
+ int pcc = !tcc_state->ms_bitfields;
+ int pragma_pack = *tcc_state->pack_stack_ptr;
Sym *f;
maxalign = 1;
@@ -4601,7 +4692,7 @@ static void struct_layout(TCCState* S, CType *type, AttributeDef *ad)
#ifdef BF_DEBUG
printf("set field %s offset %-2d size %-2d align %-2d",
- get_tok_str(S, f->v & ~SYM_FIELD, NULL), offset, size, align);
+ get_tok_str(f->v & ~SYM_FIELD, NULL), offset, size, align);
if (f->type.t & VT_BITFIELD) {
printf(" pos %-2d bits %-2d",
BIT_POS(f->type.t),
@@ -4697,7 +4788,7 @@ static void struct_layout(TCCState* S, CType *type, AttributeDef *ad)
#ifdef BF_DEBUG
printf("FIX field %s offset %-2d size %-2d align %-2d "
"pos %-2d bits %-2d\n",
- get_tok_str(S, f->v & ~SYM_FIELD, NULL),
+ get_tok_str(f->v & ~SYM_FIELD, NULL),
cx, s, align, px, bit_size);
#endif
} else {
@@ -4705,14 +4796,14 @@ static void struct_layout(TCCState* S, CType *type, AttributeDef *ad)
f->auxtype = VT_STRUCT;
#ifdef BF_DEBUG
printf("FIX field %s : load byte-wise\n",
- get_tok_str(S, f->v & ~SYM_FIELD, NULL));
+ get_tok_str(f->v & ~SYM_FIELD, NULL));
#endif
}
}
}
/* enum/struct/union declaration. u is VT_ENUM/VT_STRUCT/VT_UNION */
-static void struct_decl(TCCState* S, CType *type, int u)
+static void struct_decl(CType *type, int u)
{
int v, c, size, align, flexible;
int bit_size, bsize, bt;
@@ -4721,39 +4812,39 @@ static void struct_decl(TCCState* S, CType *type, int u)
CType type1, btype;
memset(&ad, 0, sizeof ad);
- next(S);
- parse_attribute(S, &ad);
- if (S->tccpp_tok != '{') {
- v = S->tccpp_tok;
- next(S);
+ next();
+ parse_attribute(&ad);
+ if (tok != '{') {
+ v = tok;
+ next();
/* struct already defined ? return it */
if (v < TOK_IDENT)
- expect(S, "struct/union/enum name");
- s = struct_find(S, v);
- if (s && (s->sym_scope == S->tccgen_local_scope || S->tccpp_tok != '{')) {
+ expect("struct/union/enum name");
+ s = struct_find(v);
+ if (s && (s->sym_scope == local_scope || tok != '{')) {
if (u == s->type.t)
goto do_decl;
if (u == VT_ENUM && IS_ENUM(s->type.t))
goto do_decl;
- tcc_error(S, "redefinition of '%s'", get_tok_str(S, v, NULL));
+ tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
}
} else {
- v = S->tccgen_anon_sym++;
+ v = anon_sym++;
}
/* Record the original enum/struct/union token. */
type1.t = u == VT_ENUM ? u | VT_INT | VT_UNSIGNED : u;
type1.ref = NULL;
/* we put an undefined size for struct/union */
- s = sym_push(S, v | SYM_STRUCT, &type1, 0, -1);
+ s = sym_push(v | SYM_STRUCT, &type1, 0, -1);
s->r = 0; /* default alignment is zero as gcc */
do_decl:
type->t = s->type.t;
type->ref = s;
- if (S->tccpp_tok == '{') {
- next(S);
+ if (tok == '{') {
+ next();
if (s->c != -1)
- tcc_error(S, "struct/union/enum already defined");
+ tcc_error("struct/union/enum already defined");
s->c = -2;
/* cannot be empty */
/* non empty enums are not allowed */
@@ -4765,34 +4856,34 @@ do_decl:
/* enum symbols have static storage */
t.t = VT_INT|VT_STATIC|VT_ENUM_VAL;
for(;;) {
- v = S->tccpp_tok;
+ v = tok;
if (v < TOK_UIDENT)
- expect(S, "identifier");
- ss = sym_find(S, v);
- if (ss && !S->tccgen_local_stack)
- tcc_error(S, "redefinition of enumerator '%s'",
- get_tok_str(S, v, NULL));
- next(S);
- if (S->tccpp_tok == '=') {
- next(S);
- ll = expr_const64(S);
+ expect("identifier");
+ ss = sym_find(v);
+ if (ss && !local_stack)
+ tcc_error("redefinition of enumerator '%s'",
+ get_tok_str(v, NULL));
+ next();
+ if (tok == '=') {
+ next();
+ ll = expr_const64();
}
- ss = sym_push(S, v, &t, VT_CONST, 0);
+ ss = sym_push(v, &t, VT_CONST, 0);
ss->enum_val = ll;
*ps = ss, ps = &ss->next;
if (ll < nl)
nl = ll;
if (ll > pl)
pl = ll;
- if (S->tccpp_tok != ',')
+ if (tok != ',')
break;
- next(S);
+ next();
ll++;
/* NOTE: we accept a trailing comma */
- if (S->tccpp_tok == '}')
+ if (tok == '}')
break;
}
- skip(S, '}');
+ skip('}');
/* set integral type of the enum */
t.t = VT_INT;
if (nl >= 0) {
@@ -4819,29 +4910,29 @@ do_decl:
} else {
c = 0;
flexible = 0;
- while (S->tccpp_tok != '}') {
- if (!parse_btype(S, &btype, &ad1)) {
- skip(S, ';');
+ while (tok != '}') {
+ if (!parse_btype(&btype, &ad1)) {
+ skip(';');
continue;
}
while (1) {
if (flexible)
- tcc_error(S, "flexible array member '%s' not at the end of struct",
- get_tok_str(S, v, NULL));
+ tcc_error("flexible array member '%s' not at the end of struct",
+ get_tok_str(v, NULL));
bit_size = -1;
v = 0;
type1 = btype;
- if (S->tccpp_tok != ':') {
- if (S->tccpp_tok != ';')
- type_decl(S, &type1, &ad1, &v, TYPE_DIRECT);
+ if (tok != ':') {
+ if (tok != ';')
+ type_decl(&type1, &ad1, &v, TYPE_DIRECT);
if (v == 0) {
if ((type1.t & VT_BTYPE) != VT_STRUCT)
- expect(S, "identifier");
+ expect("identifier");
else {
int v = btype.ref->v;
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) < SYM_FIRST_ANOM) {
- if (S->ms_extensions == 0)
- expect(S, "identifier");
+ if (tcc_state->ms_extensions == 0)
+ expect("identifier");
}
}
}
@@ -4849,26 +4940,26 @@ do_decl:
if ((u == VT_STRUCT) && (type1.t & VT_ARRAY) && c)
flexible = 1;
else
- tcc_error(S, "field '%s' has incomplete type",
- get_tok_str(S, v, NULL));
+ tcc_error("field '%s' has incomplete type",
+ get_tok_str(v, NULL));
}
if ((type1.t & VT_BTYPE) == VT_FUNC ||
(type1.t & VT_BTYPE) == VT_VOID ||
(type1.t & VT_STORAGE))
- tcc_error(S, "invalid type for '%s'",
- get_tok_str(S, v, NULL));
+ tcc_error("invalid type for '%s'",
+ get_tok_str(v, NULL));
}
- if (S->tccpp_tok == ':') {
- next(S);
- bit_size = expr_const(S);
+ if (tok == ':') {
+ next();
+ bit_size = expr_const();
/* XXX: handle v = 0 case for messages */
if (bit_size < 0)
- tcc_error(S, "negative width in bit-field '%s'",
- get_tok_str(S, v, NULL));
+ tcc_error("negative width in bit-field '%s'",
+ get_tok_str(v, NULL));
if (v && bit_size == 0)
- tcc_error(S, "zero width for bit-field '%s'",
- get_tok_str(S, v, NULL));
- parse_attribute(S, &ad1);
+ tcc_error("zero width for bit-field '%s'",
+ get_tok_str(v, NULL));
+ parse_attribute(&ad1);
}
size = type_size(&type1, &align);
if (bit_size >= 0) {
@@ -4878,17 +4969,17 @@ do_decl:
bt != VT_SHORT &&
bt != VT_BOOL &&
bt != VT_LLONG)
- tcc_error(S, "bitfields must have scalar type");
+ tcc_error("bitfields must have scalar type");
bsize = size * 8;
if (bit_size > bsize) {
- tcc_error(S, "width of '%s' exceeds its type",
- get_tok_str(S, v, NULL));
+ tcc_error("width of '%s' exceeds its type",
+ get_tok_str(v, NULL));
} else if (bit_size == bsize
&& !ad.a.packed && !ad1.a.packed) {
/* no need for bit fields */
;
} else if (bit_size == 64) {
- tcc_error(S, "field width 64 not implemented");
+ tcc_error("field width 64 not implemented");
} else {
type1.t = (type1.t & ~VT_STRUCT_MASK)
| VT_BITFIELD
@@ -4905,28 +4996,28 @@ do_decl:
if (v == 0 &&
((type1.t & VT_BTYPE) == VT_STRUCT ||
bit_size >= 0)) {
- v = S->tccgen_anon_sym++;
+ v = anon_sym++;
}
if (v) {
- ss = sym_push(S, v | SYM_FIELD, &type1, 0, 0);
+ ss = sym_push(v | SYM_FIELD, &type1, 0, 0);
ss->a = ad1.a;
*ps = ss;
ps = &ss->next;
}
- if (S->tccpp_tok == ';' || S->tccpp_tok == TOK_EOF)
+ if (tok == ';' || tok == TOK_EOF)
break;
- skip(S, ',');
+ skip(',');
}
- skip(S, ';');
+ skip(';');
}
- skip(S, '}');
- parse_attribute(S, &ad);
+ skip('}');
+ parse_attribute(&ad);
if (ad.cleanup_func) {
- tcc_warning(S, "attribute '__cleanup__' ignored on type");
+ tcc_warning("attribute '__cleanup__' ignored on type");
}
- check_fields(S, type, 1);
- check_fields(S, type, 0);
- struct_layout(S, type, &ad);
+ check_fields(type, 1);
+ check_fields(type, 0);
+ struct_layout(type, &ad);
}
}
}
@@ -4939,10 +5030,10 @@ static void sym_to_attr(AttributeDef *ad, Sym *s)
/* Add type qualifiers to a type. If the type is an array then the qualifiers
are added to the element type, copied because it could be a typedef. */
-static void parse_btype_qualify(TCCState* S, CType *type, int qualifiers)
+static void parse_btype_qualify(CType *type, int qualifiers)
{
while (type->t & VT_ARRAY) {
- type->ref = sym_push(S, SYM_FIELD, &type->ref->type, 0, type->ref->c);
+ type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c);
type = &type->ref->type;
}
type->t |= qualifiers;
@@ -4951,7 +5042,7 @@ static void parse_btype_qualify(TCCState* S, CType *type, int qualifiers)
/* return 0 if no type declaration. otherwise, return the basic type
and skip it.
*/
-static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
+static int parse_btype(CType *type, AttributeDef *ad)
{
int t, u, bt, st, type_found, typespec_found, g, n;
Sym *s;
@@ -4965,21 +5056,21 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
type->ref = NULL;
while(1) {
- switch(S->tccpp_tok) {
+ switch(tok) {
case TOK_EXTENSION:
/* currently, we really ignore extension */
- next(S);
+ next();
continue;
/* basic types */
case TOK_CHAR:
u = VT_BYTE;
basic_type:
- next(S);
+ next();
basic_type1:
if (u == VT_SHORT || u == VT_LONG) {
if (st != -1 || (bt != -1 && bt != VT_INT))
- tmbt: tcc_error(S, "too many basic types");
+ tmbt: tcc_error("too many basic types");
st = u;
} else {
if (bt != -1 || (st != -1 && u != VT_INT))
@@ -5002,21 +5093,21 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
case TOK_ALIGNAS:
{ int n;
AttributeDef ad1;
- next(S);
- skip(S, '(');
+ next();
+ skip('(');
memset(&ad1, 0, sizeof(AttributeDef));
- if (parse_btype(S, &type1, &ad1)) {
- type_decl(S, &type1, &ad1, &n, TYPE_ABSTRACT);
+ if (parse_btype(&type1, &ad1)) {
+ type_decl(&type1, &ad1, &n, TYPE_ABSTRACT);
if (ad1.a.aligned)
n = 1 << (ad1.a.aligned - 1);
else
type_size(&type1, &n);
} else {
- n = expr_const(S);
+ n = expr_const();
if (n <= 0 || (n & (n - 1)) != 0)
- tcc_error(S, "alignment must be a positive power of two");
+ tcc_error("alignment must be a positive power of two");
}
- skip(S, ')');
+ skip(')');
ad->a.aligned = exact_log2p1(n);
}
continue;
@@ -5029,7 +5120,7 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
u = VT_LONG;
goto basic_type;
}
- next(S);
+ next();
break;
#ifdef TCC_TARGET_ARM64
case TOK_UINT128:
@@ -5051,29 +5142,29 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
u = VT_DOUBLE;
goto basic_type;
}
- next(S);
+ next();
break;
case TOK_ENUM:
- struct_decl(S, &type1, VT_ENUM);
+ struct_decl(&type1, VT_ENUM);
basic_type2:
u = type1.t;
type->ref = type1.ref;
goto basic_type1;
case TOK_STRUCT:
- struct_decl(S, &type1, VT_STRUCT);
+ struct_decl(&type1, VT_STRUCT);
goto basic_type2;
case TOK_UNION:
- struct_decl(S, &type1, VT_UNION);
+ struct_decl(&type1, VT_UNION);
goto basic_type2;
/* type modifiers */
case TOK__Atomic:
- next(S);
+ next();
type->t = t;
- parse_btype_qualify(S, type, VT_ATOMIC);
+ parse_btype_qualify(type, VT_ATOMIC);
t = type->t;
- if (S->tccpp_tok == '(') {
- parse_expr_type(S, &type1);
+ if (tok == '(') {
+ parse_expr_type(&type1);
/* remove all storage modifiers except typedef */
type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
if (type1.ref)
@@ -5085,25 +5176,25 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
case TOK_CONST2:
case TOK_CONST3:
type->t = t;
- parse_btype_qualify(S, type, VT_CONSTANT);
+ parse_btype_qualify(type, VT_CONSTANT);
t = type->t;
- next(S);
+ next();
break;
case TOK_VOLATILE1:
case TOK_VOLATILE2:
case TOK_VOLATILE3:
type->t = t;
- parse_btype_qualify(S, type, VT_VOLATILE);
+ parse_btype_qualify(type, VT_VOLATILE);
t = type->t;
- next(S);
+ next();
break;
case TOK_SIGNED1:
case TOK_SIGNED2:
case TOK_SIGNED3:
if ((t & (VT_DEFSIGN|VT_UNSIGNED)) == (VT_DEFSIGN|VT_UNSIGNED))
- tcc_error(S, "signed and unsigned modifier");
+ tcc_error("signed and unsigned modifier");
t |= VT_DEFSIGN;
- next(S);
+ next();
typespec_found = 1;
break;
case TOK_REGISTER:
@@ -5111,13 +5202,13 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
case TOK_RESTRICT1:
case TOK_RESTRICT2:
case TOK_RESTRICT3:
- next(S);
+ next();
break;
case TOK_UNSIGNED:
if ((t & (VT_DEFSIGN|VT_UNSIGNED)) == VT_DEFSIGN)
- tcc_error(S, "signed and unsigned modifier");
+ tcc_error("signed and unsigned modifier");
t |= VT_DEFSIGN | VT_UNSIGNED;
- next(S);
+ next();
typespec_found = 1;
break;
@@ -5133,24 +5224,24 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
goto storage;
storage:
if (t & (VT_EXTERN|VT_STATIC|VT_TYPEDEF) & ~g)
- tcc_error(S, "multiple storage classes");
+ tcc_error("multiple storage classes");
t |= g;
- next(S);
+ next();
break;
case TOK_INLINE1:
case TOK_INLINE2:
case TOK_INLINE3:
t |= VT_INLINE;
- next(S);
+ next();
break;
case TOK_NORETURN3:
- next(S);
+ next();
ad->f.func_noreturn = 1;
break;
/* GNUC attribute */
case TOK_ATTRIBUTE1:
case TOK_ATTRIBUTE2:
- parse_attribute(S, ad);
+ parse_attribute(ad);
if (ad->attr_mode) {
u = ad->attr_mode -1;
t = (t & ~(VT_BTYPE|VT_LONG)) | u;
@@ -5160,8 +5251,8 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
case TOK_TYPEOF1:
case TOK_TYPEOF2:
case TOK_TYPEOF3:
- next(S);
- parse_expr_type(S, &type1);
+ next();
+ parse_expr_type(&type1);
/* remove all storage modifiers except typedef */
type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
if (type1.ref)
@@ -5170,14 +5261,14 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
default:
if (typespec_found)
goto the_end;
- s = sym_find(S, S->tccpp_tok);
+ s = sym_find(tok);
if (!s || !(s->type.t & VT_TYPEDEF))
goto the_end;
- n = S->tccpp_tok, next(S);
- if (S->tccpp_tok == ':' && !S->tccgen_in_generic) {
+ n = tok, next();
+ if (tok == ':' && !in_generic) {
/* ignore if it's a label */
- unget_tok(S, n);
+ unget_tok(n);
goto the_end;
}
@@ -5186,7 +5277,7 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
type->t = (s->type.t & ~VT_TYPEDEF) | u;
type->ref = s->type.ref;
if (t)
- parse_btype_qualify(S, type, t);
+ parse_btype_qualify(type, t);
t = type->t;
/* get attributes from typedef */
sym_to_attr(ad, s);
@@ -5197,7 +5288,7 @@ static int parse_btype(TCCState* S, CType *type, AttributeDef *ad)
type_found = 1;
}
the_end:
- if (S->char_is_unsigned) {
+ if (tcc_state->char_is_unsigned) {
if ((t & (VT_DEFSIGN|VT_BTYPE)) == VT_BYTE)
t |= VT_UNSIGNED;
}
@@ -5215,7 +5306,7 @@ the_end:
/* convert a function parameter type (array to pointer and function to
function pointer) */
-static inline void convert_parameter_type(TCCState* S, CType *pt)
+static inline void convert_parameter_type(CType *pt)
{
/* remove const and volatile qualifiers (XXX: const could be used
to indicate a const function parameter */
@@ -5223,48 +5314,48 @@ static inline void convert_parameter_type(TCCState* S, CType *pt)
/* array must be transformed to pointer according to ANSI C */
pt->t &= ~VT_ARRAY;
if ((pt->t & VT_BTYPE) == VT_FUNC) {
- mk_pointer(S, pt);
+ mk_pointer(pt);
}
}
-ST_FUNC void parse_asm_str(TCCState* S, CString *astr)
+ST_FUNC void parse_asm_str(CString *astr)
{
- skip(S, '(');
- parse_mult_str(S, astr, "string constant");
+ skip('(');
+ parse_mult_str(astr, "string constant");
}
/* Parse an asm label and return the token */
-static int asm_label_instr(TCCState* S)
+static int asm_label_instr(void)
{
int v;
CString astr;
- next(S);
- parse_asm_str(S, &astr);
- skip(S, ')');
+ next();
+ parse_asm_str(&astr);
+ skip(')');
#ifdef ASM_DEBUG
printf("asm_alias: \"%s\"\n", (char *)astr.data);
#endif
- v = tok_alloc(S, astr.data, astr.size - 1)->tok;
- cstr_free(S, &astr);
+ v = tok_alloc(astr.data, astr.size - 1)->tok;
+ cstr_free(&astr);
return v;
}
-static int post_type(TCCState* S, CType *type, AttributeDef *ad, int storage, int td)
+static int post_type(CType *type, AttributeDef *ad, int storage, int td)
{
int n, l, t1, arg_size, align, unused_align;
Sym **plast, *s, *first;
AttributeDef ad1;
CType pt;
- if (S->tccpp_tok == '(') {
+ if (tok == '(') {
/* function type, or recursive declarator (return if so) */
- next(S);
+ next();
if (td && !(td & TYPE_ABSTRACT))
return 0;
- if (S->tccpp_tok == ')')
+ if (tok == ')')
l = 0;
- else if (parse_btype(S, &pt, &ad1))
+ else if (parse_btype(&pt, &ad1))
l = FUNC_NEW;
else if (td) {
merge_attr (ad, &ad1);
@@ -5278,74 +5369,74 @@ static int post_type(TCCState* S, CType *type, AttributeDef *ad, int storage, in
for(;;) {
/* read param name and compute offset */
if (l != FUNC_OLD) {
- if ((pt.t & VT_BTYPE) == VT_VOID && S->tccpp_tok == ')')
+ if ((pt.t & VT_BTYPE) == VT_VOID && tok == ')')
break;
- type_decl(S, &pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
+ type_decl(&pt, &ad1, &n, TYPE_DIRECT | TYPE_ABSTRACT);
if ((pt.t & VT_BTYPE) == VT_VOID)
- tcc_error(S, "parameter declared as void");
+ tcc_error("parameter declared as void");
} else {
- n = S->tccpp_tok;
+ n = tok;
if (n < TOK_UIDENT)
- expect(S, "identifier");
+ expect("identifier");
pt.t = VT_VOID; /* invalid type */
pt.ref = NULL;
- next(S);
+ next();
}
- convert_parameter_type(S, &pt);
+ convert_parameter_type(&pt);
arg_size += (type_size(&pt, &align) + PTR_SIZE - 1) / PTR_SIZE;
- s = sym_push(S, n | SYM_FIELD, &pt, 0, 0);
+ s = sym_push(n | SYM_FIELD, &pt, 0, 0);
*plast = s;
plast = &s->next;
- if (S->tccpp_tok == ')')
+ if (tok == ')')
break;
- skip(S, ',');
- if (l == FUNC_NEW && S->tccpp_tok == TOK_DOTS) {
+ skip(',');
+ if (l == FUNC_NEW && tok == TOK_DOTS) {
l = FUNC_ELLIPSIS;
- next(S);
+ next();
break;
}
- if (l == FUNC_NEW && !parse_btype(S, &pt, &ad1))
- tcc_error(S, "invalid type");
+ if (l == FUNC_NEW && !parse_btype(&pt, &ad1))
+ tcc_error("invalid type");
}
} else
/* if no parameters, then old type prototype */
l = FUNC_OLD;
- skip(S, ')');
+ skip(')');
/* NOTE: const is ignored in returned type as it has a special
meaning in gcc / C++ */
type->t &= ~VT_CONSTANT;
/* some ancient pre-K&R C allows a function to return an array
and the array brackets to be put after the arguments, such
that "int c()[]" means something like "int[] c()" */
- if (S->tccpp_tok == '[') {
- next(S);
- skip(S, ']'); /* only handle simple "[]" */
- mk_pointer(S, type);
+ if (tok == '[') {
+ next();
+ skip(']'); /* only handle simple "[]" */
+ mk_pointer(type);
}
/* we push a anonymous symbol which will contain the function prototype */
ad->f.func_args = arg_size;
ad->f.func_type = l;
- s = sym_push(S, SYM_FIELD, type, 0, 0);
+ s = sym_push(SYM_FIELD, type, 0, 0);
s->a = ad->a;
s->f = ad->f;
s->next = first;
type->t = VT_FUNC;
type->ref = s;
- } else if (S->tccpp_tok == '[') {
- int saved_nocode_wanted = S->tccgen_nocode_wanted;
+ } else if (tok == '[') {
+ int saved_nocode_wanted = nocode_wanted;
/* array definition */
- next(S);
+ next();
while (1) {
/* XXX The optional type-quals and static should only be accepted
in parameter decls. The '*' as well, and then even only
in prototypes (not function defs). */
- switch (S->tccpp_tok) {
+ switch (tok) {
case TOK_RESTRICT1: case TOK_RESTRICT2: case TOK_RESTRICT3:
case TOK_CONST1:
case TOK_VOLATILE1:
case TOK_STATIC:
case '*':
- next(S);
+ next();
continue;
default:
break;
@@ -5354,60 +5445,60 @@ static int post_type(TCCState* S, CType *type, AttributeDef *ad, int storage, in
}
n = -1;
t1 = 0;
- if (S->tccpp_tok != ']') {
- if (!S->tccgen_local_stack || (storage & VT_STATIC))
- vpushi(S, expr_const(S));
+ if (tok != ']') {
+ if (!local_stack || (storage & VT_STATIC))
+ vpushi(expr_const());
else {
/* VLAs (which can only happen with local_stack && !VT_STATIC)
length must always be evaluated, even under nocode_wanted,
so that its size slot is initialized (e.g. under sizeof
or typeof). */
- S->tccgen_nocode_wanted = 0;
- gexpr(S);
+ nocode_wanted = 0;
+ gexpr();
}
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
- n = S->tccgen_vtop->c.i;
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) {
+ n = vtop->c.i;
if (n < 0)
- tcc_error(S, "invalid array size");
+ tcc_error("invalid array size");
} else {
- if (!is_integer_btype(S->tccgen_vtop->type.t & VT_BTYPE))
- tcc_error(S, "size of variable length array should be an integer");
+ if (!is_integer_btype(vtop->type.t & VT_BTYPE))
+ tcc_error("size of variable length array should be an integer");
n = 0;
t1 = VT_VLA;
}
}
- skip(S, ']');
+ skip(']');
/* parse next post type */
- post_type(S, type, ad, storage, 0);
+ post_type(type, ad, storage, 0);
if ((type->t & VT_BTYPE) == VT_FUNC)
- tcc_error(S, "declaration of an array of functions");
+ tcc_error("declaration of an array of functions");
if ((type->t & VT_BTYPE) == VT_VOID
|| type_size(type, &unused_align) < 0)
- tcc_error(S, "declaration of an array of incomplete type elements");
+ tcc_error("declaration of an array of incomplete type elements");
t1 |= type->t & VT_VLA;
if (t1 & VT_VLA) {
if (n < 0)
- tcc_error(S, "need explicit inner array size in VLAs");
- S->tccgen_loc -= type_size(&S->tccgen_int_type, &align);
- S->tccgen_loc &= -align;
- n = S->tccgen_loc;
+ tcc_error("need explicit inner array size in VLAs");
+ loc -= type_size(&int_type, &align);
+ loc &= -align;
+ n = loc;
- vla_runtime_type_size(S, type, &align);
- gen_op(S, '*');
- vset(S, &S->tccgen_int_type, VT_LOCAL|VT_LVAL, n);
- vswap(S);
- vstore(S);
+ vla_runtime_type_size(type, &align);
+ gen_op('*');
+ vset(&int_type, VT_LOCAL|VT_LVAL, n);
+ vswap();
+ vstore();
}
if (n != -1)
- vpop(S);
- S->tccgen_nocode_wanted = saved_nocode_wanted;
+ vpop();
+ nocode_wanted = saved_nocode_wanted;
/* we push an anonymous symbol which will contain the array
element type */
- s = sym_push(S, SYM_FIELD, type, 0, n);
+ s = sym_push(SYM_FIELD, type, 0, n);
type->t = (t1 ? VT_VLA : VT_ARRAY) | VT_PTR;
type->ref = s;
}
@@ -5421,7 +5512,7 @@ static int post_type(TCCState* S, CType *type, AttributeDef *ad, int storage, in
type_decl(). If this (possibly abstract) declarator is a pointer chain
it returns the innermost pointed to type (equals *type, but is a different
pointer), otherwise returns type itself, that's used for recursive calls. */
-static CType *type_decl(TCCState* S, CType *type, AttributeDef *ad, int *v, int td)
+static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
{
CType *post, *ret;
int qualifiers, storage;
@@ -5431,11 +5522,11 @@ static CType *type_decl(TCCState* S, CType *type, AttributeDef *ad, int *v, int
type->t &= ~VT_STORAGE;
post = ret = type;
- while (S->tccpp_tok == '*') {
+ while (tok == '*') {
qualifiers = 0;
redo:
- next(S);
- switch(S->tccpp_tok) {
+ next();
+ switch(tok) {
case TOK__Atomic:
qualifiers |= VT_ATOMIC;
goto redo;
@@ -5456,70 +5547,70 @@ static CType *type_decl(TCCState* S, CType *type, AttributeDef *ad, int *v, int
/* XXX: clarify attribute handling */
case TOK_ATTRIBUTE1:
case TOK_ATTRIBUTE2:
- parse_attribute(S, ad);
+ parse_attribute(ad);
break;
}
- mk_pointer(S, type);
+ mk_pointer(type);
type->t |= qualifiers;
if (ret == type)
/* innermost pointed to type is the one for the first derivation */
ret = pointed_type(type);
}
- if (S->tccpp_tok == '(') {
+ if (tok == '(') {
/* This is possibly a parameter type list for abstract declarators
('int ()'), use post_type for testing this. */
- if (!post_type(S, type, ad, 0, td)) {
+ if (!post_type(type, ad, 0, td)) {
/* It's not, so it's a nested declarator, and the post operations
apply to the innermost pointed to type (if any). */
/* XXX: this is not correct to modify 'ad' at this point, but
the syntax is not clear */
- parse_attribute(S, ad);
- post = type_decl(S, type, ad, v, td);
- skip(S, ')');
+ parse_attribute(ad);
+ post = type_decl(type, ad, v, td);
+ skip(')');
} else
goto abstract;
- } else if (S->tccpp_tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
+ } else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
/* type identifier */
- *v = S->tccpp_tok;
- next(S);
+ *v = tok;
+ next();
} else {
abstract:
if (!(td & TYPE_ABSTRACT))
- expect(S, "identifier");
+ expect("identifier");
*v = 0;
}
- post_type(S, post, ad, storage, 0);
- parse_attribute(S, ad);
+ post_type(post, ad, storage, 0);
+ parse_attribute(ad);
type->t |= storage;
return ret;
}
/* indirection with full error checking and bound check */
-ST_FUNC void indir(TCCState* S)
+ST_FUNC void indir(void)
{
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_PTR) {
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FUNC)
+ if ((vtop->type.t & VT_BTYPE) != VT_PTR) {
+ if ((vtop->type.t & VT_BTYPE) == VT_FUNC)
return;
- expect(S, "pointer");
+ expect("pointer");
}
- if (S->tccgen_vtop->r & VT_LVAL)
- gv(S, RC_INT);
- S->tccgen_vtop->type = *pointed_type(&S->tccgen_vtop->type);
+ if (vtop->r & VT_LVAL)
+ gv(RC_INT);
+ vtop->type = *pointed_type(&vtop->type);
/* Arrays and functions are never lvalues */
- if (!(S->tccgen_vtop->type.t & (VT_ARRAY | VT_VLA))
- && (S->tccgen_vtop->type.t & VT_BTYPE) != VT_FUNC) {
- S->tccgen_vtop->r |= VT_LVAL;
+ if (!(vtop->type.t & (VT_ARRAY | VT_VLA))
+ && (vtop->type.t & VT_BTYPE) != VT_FUNC) {
+ vtop->r |= VT_LVAL;
/* if bound checking, the referenced pointer must be checked */
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- S->tccgen_vtop->r |= VT_MUSTBOUND;
+ if (tcc_state->do_bounds_check)
+ vtop->r |= VT_MUSTBOUND;
#endif
}
}
/* pass a parameter to a function and do type checking and casting */
-static void gfunc_param_typed(TCCState* S, Sym *func, Sym *arg)
+static void gfunc_param_typed(Sym *func, Sym *arg)
{
int func_type;
CType type;
@@ -5528,79 +5619,79 @@ static void gfunc_param_typed(TCCState* S, Sym *func, Sym *arg)
if (func_type == FUNC_OLD ||
(func_type == FUNC_ELLIPSIS && arg == NULL)) {
/* default casting : only need to convert float to double */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FLOAT) {
- gen_cast_s(S, VT_DOUBLE);
- } else if (S->tccgen_vtop->type.t & VT_BITFIELD) {
- type.t = S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED);
- type.ref = S->tccgen_vtop->type.ref;
- gen_cast(S, &type);
- } else if (S->tccgen_vtop->r & VT_MUSTCAST) {
- force_charshort_cast(S);
+ if ((vtop->type.t & VT_BTYPE) == VT_FLOAT) {
+ gen_cast_s(VT_DOUBLE);
+ } else if (vtop->type.t & VT_BITFIELD) {
+ type.t = vtop->type.t & (VT_BTYPE | VT_UNSIGNED);
+ type.ref = vtop->type.ref;
+ gen_cast(&type);
+ } else if (vtop->r & VT_MUSTCAST) {
+ force_charshort_cast();
}
} else if (arg == NULL) {
- tcc_error(S, "too many arguments to function");
+ tcc_error("too many arguments to function");
} else {
type = arg->type;
type.t &= ~VT_CONSTANT; /* need to do that to avoid false warning */
- gen_assign_cast(S, &type);
+ gen_assign_cast(&type);
}
}
/* parse an expression and return its type without any side effect. */
-static void expr_type(TCCState* S, CType *type, void (*expr_fn)(TCCState* S))
+static void expr_type(CType *type, void (*expr_fn)(void))
{
- S->tccgen_nocode_wanted++;
- expr_fn(S);
- *type = S->tccgen_vtop->type;
- vpop(S);
- S->tccgen_nocode_wanted--;
+ nocode_wanted++;
+ expr_fn();
+ *type = vtop->type;
+ vpop();
+ nocode_wanted--;
}
/* parse an expression of the form '(type)' or '(expr)' and return its
type */
-static void parse_expr_type(TCCState* S, CType *type)
+static void parse_expr_type(CType *type)
{
int n;
AttributeDef ad;
- skip(S, '(');
- if (parse_btype(S, type, &ad)) {
- type_decl(S, type, &ad, &n, TYPE_ABSTRACT);
+ skip('(');
+ if (parse_btype(type, &ad)) {
+ type_decl(type, &ad, &n, TYPE_ABSTRACT);
} else {
- expr_type(S, type, gexpr);
+ expr_type(type, gexpr);
}
- skip(S, ')');
+ skip(')');
}
-static void parse_type(TCCState* S, CType *type)
+static void parse_type(CType *type)
{
AttributeDef ad;
int n;
- if (!parse_btype(S, type, &ad)) {
- expect(S, "type");
+ if (!parse_btype(type, &ad)) {
+ expect("type");
}
- type_decl(S, type, &ad, &n, TYPE_ABSTRACT);
+ type_decl(type, &ad, &n, TYPE_ABSTRACT);
}
-static void parse_builtin_params(TCCState* S, int nc, const char *args)
+static void parse_builtin_params(int nc, const char *args)
{
char c, sep = '(';
CType type;
if (nc)
- S->tccgen_nocode_wanted++;
- next(S);
+ nocode_wanted++;
+ next();
if (*args == 0)
- skip(S, sep);
+ skip(sep);
while ((c = *args++)) {
- skip(S, sep);
+ skip(sep);
sep = ',';
if (c == 't') {
- parse_type(S, &type);
- vpush(S, &type);
+ parse_type(&type);
+ vpush(&type);
continue;
}
- expr_eq(S);
+ expr_eq();
type.ref = NULL;
type.t = 0;
switch (c) {
@@ -5610,13 +5701,13 @@ static void parse_builtin_params(TCCState* S, int nc, const char *args)
type.t = VT_CONSTANT;
case 'v':
type.t |= VT_VOID;
- mk_pointer (S, &type);
+ mk_pointer (&type);
break;
case 'S':
type.t = VT_CONSTANT;
case 's':
- type.t |= S->tccgen_char_type.t;
- mk_pointer (S, &type);
+ type.t |= char_type.t;
+ mk_pointer (&type);
break;
case 'i':
type.t = VT_INT;
@@ -5627,14 +5718,14 @@ static void parse_builtin_params(TCCState* S, int nc, const char *args)
default:
break;
}
- gen_assign_cast(S, &type);
+ gen_assign_cast(&type);
}
- skip(S, ')');
+ skip(')');
if (nc)
- S->tccgen_nocode_wanted--;
+ nocode_wanted--;
}
-static void parse_atomic(TCCState* S, int atok)
+static void parse_atomic(int atok)
{
int size, align, arg;
CType *atom, *atom_ptr, ct = {0};
@@ -5668,16 +5759,16 @@ static void parse_atomic(TCCState* S, int atok)
atom = atom_ptr = NULL;
size = 0; /* pacify compiler */
- next(S);
- skip(S, '(');
+ next();
+ skip('(');
for (arg = 0;;) {
- expr_eq(S);
+ expr_eq();
switch (template[arg]) {
case 'a':
case 'A':
- atom_ptr = &S->tccgen_vtop->type;
+ atom_ptr = &vtop->type;
if ((atom_ptr->t & VT_BTYPE) != VT_PTR)
- expect(S, "pointer");
+ expect("pointer");
atom = pointed_type(atom_ptr);
size = type_size(atom, &align);
if (size > 8
@@ -5685,34 +5776,34 @@ static void parse_atomic(TCCState* S, int atok)
|| (atok > TOK___atomic_compare_exchange
&& (0 == btype_size(atom->t & VT_BTYPE)
|| (atom->t & VT_BTYPE) == VT_PTR)))
- expect(S, "integral or integer-sized pointer target type");
+ expect("integral or integer-sized pointer target type");
/* GCC does not care either: */
/* if (!(atom->t & VT_ATOMIC))
- tcc_warning(S, "pointer target declaration is missing '_Atomic'"); */
+ tcc_warning("pointer target declaration is missing '_Atomic'"); */
break;
case 'p':
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_PTR
- || type_size(pointed_type(&S->tccgen_vtop->type), &align) != size)
- tcc_error(S, "pointer target type mismatch in argument %d", arg + 1);
- gen_assign_cast(S, atom_ptr);
+ if ((vtop->type.t & VT_BTYPE) != VT_PTR
+ || type_size(pointed_type(&vtop->type), &align) != size)
+ tcc_error("pointer target type mismatch in argument %d", arg + 1);
+ gen_assign_cast(atom_ptr);
break;
case 'v':
- gen_assign_cast(S, atom);
+ gen_assign_cast(atom);
break;
case 'm':
- gen_assign_cast(S, &S->tccgen_int_type);
+ gen_assign_cast(&int_type);
break;
case 'b':
ct.t = VT_BOOL;
- gen_assign_cast(S, &ct);
+ gen_assign_cast(&ct);
break;
}
if ('.' == template[++arg])
break;
- skip(S, ',');
+ skip(',');
}
- skip(S, ')');
+ skip(')');
ct.t = VT_VOID;
switch (template[arg + 1]) {
@@ -5724,23 +5815,23 @@ static void parse_atomic(TCCState* S, int atok)
break;
}
- sprintf(buf, "%s_%d", get_tok_str(S, atok, 0), size);
- vpush_helper_func(S, tok_alloc_const(S, buf));
- vrott(S, arg + 1);
- gfunc_call(S, arg);
+ sprintf(buf, "%s_%d", get_tok_str(atok, 0), size);
+ vpush_helper_func(tok_alloc_const(buf));
+ vrott(arg + 1);
+ gfunc_call(arg);
- vpush(S, &ct);
- PUT_R_RET(S->tccgen_vtop, ct.t);
+ vpush(&ct);
+ PUT_R_RET(vtop, ct.t);
if (ct.t == VT_BOOL) {
#ifdef PROMOTE_RET
- S->tccgen_vtop->r |= BFVAL(VT_MUSTCAST, 1);
+ vtop->r |= BFVAL(VT_MUSTCAST, 1);
#else
- S->tccgen_vtop->type.t = VT_INT;
+ vtop->type.t = VT_INT;
#endif
}
}
-ST_FUNC void unary(TCCState* S)
+ST_FUNC void unary(void)
{
int n, t, align, size, r, sizeof_caller;
CType type;
@@ -5748,18 +5839,18 @@ ST_FUNC void unary(TCCState* S)
AttributeDef ad;
/* generate line number info */
- if (S->tccgen_debug_modes)
- tcc_debug_line(S), tcc_tcov_check_line (S, 1);
+ if (debug_modes)
+ tcc_debug_line(tcc_state), tcc_tcov_check_line (1);
- sizeof_caller = S->tccgen_in_sizeof;
- S->tccgen_in_sizeof = 0;
+ sizeof_caller = in_sizeof;
+ in_sizeof = 0;
type.ref = NULL;
/* XXX: GCC 2.95.3 does not generate a table although it should be
better here */
tok_next:
- switch(S->tccpp_tok) {
+ switch(tok) {
case TOK_EXTENSION:
- next(S);
+ next();
goto tok_next;
case TOK_LCHAR:
#ifdef TCC_TARGET_PE
@@ -5771,8 +5862,8 @@ ST_FUNC void unary(TCCState* S)
t = VT_INT;
push_tokc:
type.t = t;
- vsetc(S, &type, VT_CONST, &S->tccpp_tokc);
- next(S);
+ vsetc(&type, VT_CONST, &tokc);
+ next();
break;
case TOK_CUINT:
t = VT_INT | VT_UNSIGNED;
@@ -5807,19 +5898,19 @@ ST_FUNC void unary(TCCState* S)
Section *sec;
int len;
/* special function name identifier */
- len = strlen(S->tccgen_funcname) + 1;
+ len = strlen(funcname) + 1;
/* generate char[len] type */
- type.t = S->tccgen_char_type.t;
- if (S->warn_write_strings & WARN_ON)
+ type.t = char_type.t;
+ if (tcc_state->warn_write_strings & WARN_ON)
type.t |= VT_CONSTANT;
- mk_pointer(S, &type);
+ mk_pointer(&type);
type.t |= VT_ARRAY;
type.ref->c = len;
sec = rodata_section;
- vpush_ref(S, &type, sec, sec->data_offset, len);
+ vpush_ref(&type, sec, sec->data_offset, len);
if (!NODATA_WANTED)
- memcpy(section_ptr_add(S, sec, len), S->tccgen_funcname, len);
- next(S);
+ memcpy(section_ptr_add(sec, len), funcname, len);
+ next();
}
break;
case TOK_LSTR:
@@ -5831,27 +5922,27 @@ ST_FUNC void unary(TCCState* S)
goto str_init;
case TOK_STR:
/* string parsing */
- t = S->tccgen_char_type.t;
+ t = char_type.t;
str_init:
- if (S->warn_write_strings & WARN_ON)
+ if (tcc_state->warn_write_strings & WARN_ON)
t |= VT_CONSTANT;
type.t = t;
- mk_pointer(S, &type);
+ mk_pointer(&type);
type.t |= VT_ARRAY;
memset(&ad, 0, sizeof(AttributeDef));
ad.section = rodata_section;
- decl_initializer_alloc(S, &type, &ad, VT_CONST, 2, 0, 0);
+ decl_initializer_alloc(&type, &ad, VT_CONST, 2, 0, 0);
break;
case '(':
- next(S);
+ next();
/* cast ? */
- if (parse_btype(S, &type, &ad)) {
- type_decl(S, &type, &ad, &n, TYPE_ABSTRACT);
- skip(S, ')');
+ if (parse_btype(&type, &ad)) {
+ type_decl(&type, &ad, &n, TYPE_ABSTRACT);
+ skip(')');
/* check ISOC99 compound literal */
- if (S->tccpp_tok == '{') {
+ if (tok == '{') {
/* data is allocated locally by default */
- if (S->tccgen_global_expr)
+ if (global_expr)
r = VT_CONST;
else
r = VT_LOCAL;
@@ -5859,259 +5950,259 @@ ST_FUNC void unary(TCCState* S)
if (!(type.t & VT_ARRAY))
r |= VT_LVAL;
memset(&ad, 0, sizeof(AttributeDef));
- decl_initializer_alloc(S, &type, &ad, r, 1, 0, 0);
+ decl_initializer_alloc(&type, &ad, r, 1, 0, 0);
} else {
if (sizeof_caller) {
- vpush(S, &type);
+ vpush(&type);
return;
}
- unary(S);
- gen_cast(S, &type);
+ unary();
+ gen_cast(&type);
}
- } else if (S->tccpp_tok == '{') {
- int saved_nocode_wanted = S->tccgen_nocode_wanted;
- if (S->tccgen_const_wanted && !(S->tccgen_nocode_wanted & unevalmask))
- expect(S, "constant");
- if (0 == S->tccgen_local_scope)
- tcc_error(S, "statement expression outside of function");
+ } else if (tok == '{') {
+ int saved_nocode_wanted = nocode_wanted;
+ if (const_wanted && !(nocode_wanted & unevalmask))
+ expect("constant");
+ if (0 == local_scope)
+ tcc_error("statement expression outside of function");
/* save all registers */
- save_regs(S, 0);
+ save_regs(0);
/* statement expression : we do not accept break/continue
inside as GCC does. We do retain the nocode_wanted state,
as statement expressions can't ever be entered from the
outside, so any reactivation of code emission (from labels
or loop heads) can be disabled again after the end of it. */
- block(S, 1);
- S->tccgen_nocode_wanted = saved_nocode_wanted;
- skip(S, ')');
+ block(1);
+ nocode_wanted = saved_nocode_wanted;
+ skip(')');
} else {
- gexpr(S);
- skip(S, ')');
+ gexpr();
+ skip(')');
}
break;
case '*':
- next(S);
- unary(S);
- indir(S);
+ next();
+ unary();
+ indir();
break;
case '&':
- next(S);
- unary(S);
+ next();
+ unary();
/* functions names must be treated as function pointers,
except for unary '&' and sizeof. Since we consider that
functions are not lvalues, we only have to handle it
there and in function calls. */
/* arrays can also be used although they are not lvalues */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FUNC &&
- !(S->tccgen_vtop->type.t & VT_ARRAY))
- test_lvalue(S);
- if (S->tccgen_vtop->sym)
- S->tccgen_vtop->sym->a.addrtaken = 1;
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
+ if ((vtop->type.t & VT_BTYPE) != VT_FUNC &&
+ !(vtop->type.t & VT_ARRAY))
+ test_lvalue();
+ if (vtop->sym)
+ vtop->sym->a.addrtaken = 1;
+ mk_pointer(&vtop->type);
+ gaddrof();
break;
case '!':
- next(S);
- unary(S);
- gen_test_zero(S, TOK_EQ);
+ next();
+ unary();
+ gen_test_zero(TOK_EQ);
break;
case '~':
- next(S);
- unary(S);
- vpushi(S, -1);
- gen_op(S, '^');
+ next();
+ unary();
+ vpushi(-1);
+ gen_op('^');
break;
case '+':
- next(S);
- unary(S);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_PTR)
- tcc_error(S, "pointer not accepted for unary plus");
+ next();
+ unary();
+ if ((vtop->type.t & VT_BTYPE) == VT_PTR)
+ tcc_error("pointer not accepted for unary plus");
/* In order to force cast, we add zero, except for floating point
where we really need an noop (otherwise -0.0 will be transformed
into +0.0). */
- if (!is_float(S->tccgen_vtop->type.t)) {
- vpushi(S, 0);
- gen_op(S, '+');
+ if (!is_float(vtop->type.t)) {
+ vpushi(0);
+ gen_op('+');
}
break;
case TOK_SIZEOF:
case TOK_ALIGNOF1:
case TOK_ALIGNOF2:
case TOK_ALIGNOF3:
- t = S->tccpp_tok;
- next(S);
- S->tccgen_in_sizeof++;
- expr_type(S, &type, unary); /* Perform a in_sizeof = 0; */
+ t = tok;
+ next();
+ in_sizeof++;
+ expr_type(&type, unary); /* Perform a in_sizeof = 0; */
s = NULL;
- if (S->tccgen_vtop[1].r & VT_SYM)
- s = S->tccgen_vtop[1].sym; /* hack: accessing previous vtop */
+ if (vtop[1].r & VT_SYM)
+ s = vtop[1].sym; /* hack: accessing previous vtop */
size = type_size(&type, &align);
if (s && s->a.aligned)
align = 1 << (s->a.aligned - 1);
if (t == TOK_SIZEOF) {
if (!(type.t & VT_VLA)) {
if (size < 0)
- tcc_error(S, "sizeof applied to an incomplete type");
- vpushs(S, size);
+ tcc_error("sizeof applied to an incomplete type");
+ vpushs(size);
} else {
- vla_runtime_type_size(S, &type, &align);
+ vla_runtime_type_size(&type, &align);
}
} else {
- vpushs(S, align);
+ vpushs(align);
}
- S->tccgen_vtop->type.t |= VT_UNSIGNED;
+ vtop->type.t |= VT_UNSIGNED;
break;
case TOK_builtin_expect:
/* __builtin_expect is a no-op for now */
- parse_builtin_params(S, 0, "ee");
- vpop(S);
+ parse_builtin_params(0, "ee");
+ vpop();
break;
case TOK_builtin_types_compatible_p:
- parse_builtin_params(S, 0, "tt");
- S->tccgen_vtop[-1].type.t &= ~(VT_CONSTANT | VT_VOLATILE);
- S->tccgen_vtop[0].type.t &= ~(VT_CONSTANT | VT_VOLATILE);
- n = is_compatible_types(&S->tccgen_vtop[-1].type, &S->tccgen_vtop[0].type);
- S->tccgen_vtop -= 2;
- vpushi(S, n);
+ parse_builtin_params(0, "tt");
+ vtop[-1].type.t &= ~(VT_CONSTANT | VT_VOLATILE);
+ vtop[0].type.t &= ~(VT_CONSTANT | VT_VOLATILE);
+ n = is_compatible_types(&vtop[-1].type, &vtop[0].type);
+ vtop -= 2;
+ vpushi(n);
break;
case TOK_builtin_choose_expr:
{
int64_t c;
- next(S);
- skip(S, '(');
- c = expr_const64(S);
- skip(S, ',');
+ next();
+ skip('(');
+ c = expr_const64();
+ skip(',');
if (!c) {
- S->tccgen_nocode_wanted++;
+ nocode_wanted++;
}
- expr_eq(S);
+ expr_eq();
if (!c) {
- vpop(S);
- S->tccgen_nocode_wanted--;
+ vpop();
+ nocode_wanted--;
}
- skip(S, ',');
+ skip(',');
if (c) {
- S->tccgen_nocode_wanted++;
+ nocode_wanted++;
}
- expr_eq(S);
+ expr_eq();
if (c) {
- vpop(S);
- S->tccgen_nocode_wanted--;
+ vpop();
+ nocode_wanted--;
}
- skip(S, ')');
+ skip(')');
}
break;
case TOK_builtin_constant_p:
- parse_builtin_params(S, 1, "e");
- n = (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
- !((S->tccgen_vtop->r & VT_SYM) && S->tccgen_vtop->sym->a.addrtaken);
- S->tccgen_vtop--;
- vpushi(S, n);
+ parse_builtin_params(1, "e");
+ n = (vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
+ !((vtop->r & VT_SYM) && vtop->sym->a.addrtaken);
+ vtop--;
+ vpushi(n);
break;
case TOK_builtin_frame_address:
case TOK_builtin_return_address:
{
- int tok1 = S->tccpp_tok;
+ int tok1 = tok;
int level;
- next(S);
- skip(S, '(');
- if (S->tccpp_tok != TOK_CINT) {
- tcc_error(S, "%s only takes positive integers",
+ next();
+ skip('(');
+ if (tok != TOK_CINT) {
+ tcc_error("%s only takes positive integers",
tok1 == TOK_builtin_return_address ?
"__builtin_return_address" :
"__builtin_frame_address");
}
- level = (uint32_t)S->tccpp_tokc.i;
- next(S);
- skip(S, ')');
+ level = (uint32_t)tokc.i;
+ next();
+ skip(')');
type.t = VT_VOID;
- mk_pointer(S, &type);
- vset(S, &type, VT_LOCAL, 0); /* local frame */
+ mk_pointer(&type);
+ vset(&type, VT_LOCAL, 0); /* local frame */
while (level--) {
#ifdef TCC_TARGET_RISCV64
- vpushi(S, 2*PTR_SIZE);
- gen_op(S, '-');
+ vpushi(2*PTR_SIZE);
+ gen_op('-');
#endif
- mk_pointer(S, &S->tccgen_vtop->type);
- indir(S); /* -> parent frame */
+ mk_pointer(&vtop->type);
+ indir(); /* -> parent frame */
}
if (tok1 == TOK_builtin_return_address) {
// assume return address is just above frame pointer on stack
#ifdef TCC_TARGET_ARM
- vpushi(S, 2*PTR_SIZE);
- gen_op(S, '+');
+ vpushi(2*PTR_SIZE);
+ gen_op('+');
#elif defined TCC_TARGET_RISCV64
- vpushi(S, PTR_SIZE);
- gen_op(S, '-');
+ vpushi(PTR_SIZE);
+ gen_op('-');
#else
- vpushi(S, PTR_SIZE);
- gen_op(S, '+');
+ vpushi(PTR_SIZE);
+ gen_op('+');
#endif
- mk_pointer(S, &S->tccgen_vtop->type);
- indir(S);
+ mk_pointer(&vtop->type);
+ indir();
}
}
break;
#ifdef TCC_TARGET_RISCV64
case TOK_builtin_va_start:
- parse_builtin_params(S, 0, "ee");
- r = S->tccgen_vtop->r & VT_VALMASK;
+ parse_builtin_params(0, "ee");
+ r = vtop->r & VT_VALMASK;
if (r == VT_LLOCAL)
r = VT_LOCAL;
if (r != VT_LOCAL)
- tcc_error(S, "__builtin_va_start expects a local variable");
- gen_va_start(S);
- vstore(S);
+ tcc_error("__builtin_va_start expects a local variable");
+ gen_va_start();
+ vstore();
break;
#endif
#ifdef TCC_TARGET_X86_64
#ifdef TCC_TARGET_PE
case TOK_builtin_va_start:
- parse_builtin_params(S, 0, "ee");
- r = S->tccgen_vtop->r & VT_VALMASK;
+ parse_builtin_params(0, "ee");
+ r = vtop->r & VT_VALMASK;
if (r == VT_LLOCAL)
r = VT_LOCAL;
if (r != VT_LOCAL)
- tcc_error(S, "__builtin_va_start expects a local variable");
- S->tccgen_vtop->r = r;
- S->tccgen_vtop->type = S->tccgen_char_pointer_type;
- S->tccgen_vtop->c.i += 8;
- vstore(S);
+ tcc_error("__builtin_va_start expects a local variable");
+ vtop->r = r;
+ vtop->type = char_pointer_type;
+ vtop->c.i += 8;
+ vstore();
break;
#else
case TOK_builtin_va_arg_types:
- parse_builtin_params(S, 0, "t");
- vpushi(S, classify_x86_64_va_arg(&S->tccgen_vtop->type));
- vswap(S);
- vpop(S);
+ parse_builtin_params(0, "t");
+ vpushi(classify_x86_64_va_arg(&vtop->type));
+ vswap();
+ vpop();
break;
#endif
#endif
#ifdef TCC_TARGET_ARM64
case TOK_builtin_va_start: {
- parse_builtin_params(S, 0, "ee");
+ parse_builtin_params(0, "ee");
//xx check types
- gen_va_start(S);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = VT_VOID;
+ gen_va_start();
+ vpushi(0);
+ vtop->type.t = VT_VOID;
break;
}
case TOK_builtin_va_arg: {
- parse_builtin_params(S, 0, "et");
- type = S->tccgen_vtop->type;
- vpop(S);
+ parse_builtin_params(0, "et");
+ type = vtop->type;
+ vpop();
//xx check types
- gen_va_arg(S, &type);
- S->tccgen_vtop->type = type;
+ gen_va_arg(&type);
+ vtop->type = type;
break;
}
case TOK___arm64_clear_cache: {
- parse_builtin_params(S, 0, "ee");
- gen_clear_cache(S);
- vpushi(S, 0);
- S->tccgen_vtop->type.t = VT_VOID;
+ parse_builtin_params(0, "ee");
+ gen_clear_cache();
+ vpushi(0);
+ vtop->type.t = VT_VOID;
break;
}
#endif
@@ -6126,49 +6217,49 @@ ST_FUNC void unary(TCCState* S)
case TOK___atomic_fetch_or:
case TOK___atomic_fetch_xor:
case TOK___atomic_fetch_and:
- parse_atomic(S, S->tccpp_tok);
+ parse_atomic(tok);
break;
/* pre operations */
case TOK_INC:
case TOK_DEC:
- t = S->tccpp_tok;
- next(S);
- unary(S);
- inc(S, 0, t);
+ t = tok;
+ next();
+ unary();
+ inc(0, t);
break;
case '-':
- next(S);
- unary(S);
- if (is_float(S->tccgen_vtop->type.t)) {
- gen_opif(S, TOK_NEG);
+ next();
+ unary();
+ if (is_float(vtop->type.t)) {
+ gen_opif(TOK_NEG);
} else {
- vpushi(S, 0);
- vswap(S);
- gen_op(S, '-');
+ vpushi(0);
+ vswap();
+ gen_op('-');
}
break;
case TOK_LAND:
if (!gnu_ext)
goto tok_identifier;
- next(S);
+ next();
/* allow to take the address of a label */
- if (S->tccpp_tok < TOK_UIDENT)
- expect(S, "label identifier");
- s = label_find(S, S->tccpp_tok);
+ if (tok < TOK_UIDENT)
+ expect("label identifier");
+ s = label_find(tok);
if (!s) {
- s = label_push(S, &S->tccgen_global_label_stack, S->tccpp_tok, LABEL_FORWARD);
+ s = label_push(&global_label_stack, tok, LABEL_FORWARD);
} else {
if (s->r == LABEL_DECLARED)
s->r = LABEL_FORWARD;
}
if (!s->type.t) {
s->type.t = VT_VOID;
- mk_pointer(S, &s->type);
+ mk_pointer(&s->type);
s->type.t |= VT_STATIC;
}
- vpushsym(S, &s->type, s);
- next(S);
+ vpushsym(&s->type, s);
+ next();
break;
case TOK_GENERIC:
@@ -6178,76 +6269,76 @@ ST_FUNC void unary(TCCState* S)
int has_match = 0;
int learn = 0;
TokenString *str = NULL;
- int saved_const_wanted = S->tccgen_const_wanted;
+ int saved_const_wanted = const_wanted;
- next(S);
- skip(S, '(');
- S->tccgen_const_wanted = 0;
- expr_type(S, &controlling_type, expr_eq);
+ next();
+ skip('(');
+ const_wanted = 0;
+ expr_type(&controlling_type, expr_eq);
controlling_type.t &= ~(VT_CONSTANT | VT_VOLATILE | VT_ARRAY);
if ((controlling_type.t & VT_BTYPE) == VT_FUNC)
- mk_pointer(S, &controlling_type);
- S->tccgen_const_wanted = saved_const_wanted;
+ mk_pointer(&controlling_type);
+ const_wanted = saved_const_wanted;
for (;;) {
learn = 0;
- skip(S, ',');
- if (S->tccpp_tok == TOK_DEFAULT) {
+ skip(',');
+ if (tok == TOK_DEFAULT) {
if (has_default)
- tcc_error(S, "too many 'default'");
+ tcc_error("too many 'default'");
has_default = 1;
if (!has_match)
learn = 1;
- next(S);
+ next();
} else {
AttributeDef ad_tmp;
int itmp;
CType cur_type;
- S->tccgen_in_generic++;
- parse_btype(S, &cur_type, &ad_tmp);
- S->tccgen_in_generic--;
+ in_generic++;
+ parse_btype(&cur_type, &ad_tmp);
+ in_generic--;
- type_decl(S, &cur_type, &ad_tmp, &itmp, TYPE_ABSTRACT);
+ type_decl(&cur_type, &ad_tmp, &itmp, TYPE_ABSTRACT);
if (compare_types(&controlling_type, &cur_type, 0)) {
if (has_match) {
- tcc_error(S, "type match twice");
+ tcc_error("type match twice");
}
has_match = 1;
learn = 1;
}
}
- skip(S, ':');
+ skip(':');
if (learn) {
if (str)
- tok_str_free(S, str);
- skip_or_save_block(S, &str);
+ tok_str_free(str);
+ skip_or_save_block(&str);
} else {
- skip_or_save_block(S, NULL);
+ skip_or_save_block(NULL);
}
- if (S->tccpp_tok == ')')
+ if (tok == ')')
break;
}
if (!str) {
char buf[60];
- type_to_str(S, buf, sizeof buf, &controlling_type, NULL);
- tcc_error(S, "type '%s' does not match any association", buf);
+ type_to_str(buf, sizeof buf, &controlling_type, NULL);
+ tcc_error("type '%s' does not match any association", buf);
}
- begin_macro(S, str, 1);
- next(S);
- expr_eq(S);
- if (S->tccpp_tok != TOK_EOF)
- expect(S, ",");
- end_macro(S);
- next(S);
+ begin_macro(str, 1);
+ next();
+ expr_eq();
+ if (tok != TOK_EOF)
+ expect(",");
+ end_macro();
+ next();
break;
}
// special qnan , snan and infinity values
case TOK___NAN__:
n = 0x7fc00000;
special_math_val:
- vpushi(S, n);
- S->tccgen_vtop->type.t = VT_FLOAT;
- next(S);
+ vpushi(n);
+ vtop->type.t = VT_FLOAT;
+ next();
break;
case TOK___SNAN__:
n = 0x7f800001;
@@ -6258,20 +6349,20 @@ special_math_val:
default:
tok_identifier:
- t = S->tccpp_tok;
- next(S);
+ t = tok;
+ next();
if (t < TOK_UIDENT)
- expect(S, "identifier");
- s = sym_find(S, t);
+ expect("identifier");
+ s = sym_find(t);
if (!s || IS_ASM_SYM(s)) {
- const char *name = get_tok_str(S, t, NULL);
- if (S->tccpp_tok != '(')
- tcc_error(S, "'%s' undeclared", name);
+ const char *name = get_tok_str(t, NULL);
+ if (tok != '(')
+ tcc_error("'%s' undeclared", name);
/* for simple function calls, we tolerate undeclared
external reference to int() function */
- tcc_warning_c(warn_implicit_function_declaration)(S,
+ tcc_warning_c(warn_implicit_function_declaration)(
"implicit declaration of function '%s'", name);
- s = external_global_sym(S, t, &S->tccgen_func_old_type);
+ s = external_global_sym(t, &func_old_type);
}
r = s->r;
@@ -6280,89 +6371,89 @@ special_math_val:
if ((r & VT_VALMASK) < VT_CONST)
r = (r & ~VT_VALMASK) | VT_LOCAL;
- vset(S, &s->type, r, s->c);
+ vset(&s->type, r, s->c);
/* Point to s as backpointer (even without r&VT_SYM).
Will be used by at least the x86 inline asm parser for
regvars. */
- S->tccgen_vtop->sym = s;
+ vtop->sym = s;
if (r & VT_SYM) {
- S->tccgen_vtop->c.i = 0;
+ vtop->c.i = 0;
} else if (r == VT_CONST && IS_ENUM_VAL(s->type.t)) {
- S->tccgen_vtop->c.i = s->enum_val;
+ vtop->c.i = s->enum_val;
}
break;
}
/* post operations */
while (1) {
- if (S->tccpp_tok == TOK_INC || S->tccpp_tok == TOK_DEC) {
- inc(S, 1, S->tccpp_tok);
- next(S);
- } else if (S->tccpp_tok == '.' || S->tccpp_tok == TOK_ARROW || S->tccpp_tok == TOK_CDOUBLE) {
+ if (tok == TOK_INC || tok == TOK_DEC) {
+ inc(1, tok);
+ next();
+ } else if (tok == '.' || tok == TOK_ARROW || tok == TOK_CDOUBLE) {
int qualifiers, cumofs = 0;
/* field */
- if (S->tccpp_tok == TOK_ARROW)
- indir(S);
- qualifiers = S->tccgen_vtop->type.t & (VT_CONSTANT | VT_VOLATILE);
- test_lvalue(S);
- gaddrof(S);
+ if (tok == TOK_ARROW)
+ indir();
+ qualifiers = vtop->type.t & (VT_CONSTANT | VT_VOLATILE);
+ test_lvalue();
+ gaddrof();
/* expect pointer on structure */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_STRUCT)
- expect(S, "struct or union");
- if (S->tccpp_tok == TOK_CDOUBLE)
- expect(S, "field name");
- next(S);
- if (S->tccpp_tok == TOK_CINT || S->tccpp_tok == TOK_CUINT)
- expect(S, "field name");
- s = find_field(&S->tccgen_vtop->type, S->tccpp_tok, &cumofs);
+ if ((vtop->type.t & VT_BTYPE) != VT_STRUCT)
+ expect("struct or union");
+ if (tok == TOK_CDOUBLE)
+ expect("field name");
+ next();
+ if (tok == TOK_CINT || tok == TOK_CUINT)
+ expect("field name");
+ s = find_field(&vtop->type, tok, &cumofs);
if (!s)
- tcc_error(S, "field not found: %s", get_tok_str(S, S->tccpp_tok & ~SYM_FIELD, &S->tccpp_tokc));
+ tcc_error("field not found: %s", get_tok_str(tok & ~SYM_FIELD, &tokc));
/* add field offset to pointer */
- S->tccgen_vtop->type = S->tccgen_char_pointer_type; /* change type to 'char *' */
- vpushi(S, cumofs + s->c);
- gen_op(S, '+');
+ vtop->type = char_pointer_type; /* change type to 'char *' */
+ vpushi(cumofs + s->c);
+ gen_op('+');
/* change type to field type, and set to lvalue */
- S->tccgen_vtop->type = s->type;
- S->tccgen_vtop->type.t |= qualifiers;
+ vtop->type = s->type;
+ vtop->type.t |= qualifiers;
/* an array is never an lvalue */
- if (!(S->tccgen_vtop->type.t & VT_ARRAY)) {
- S->tccgen_vtop->r |= VT_LVAL;
+ if (!(vtop->type.t & VT_ARRAY)) {
+ vtop->r |= VT_LVAL;
#ifdef CONFIG_TCC_BCHECK
/* if bound checking, the referenced pointer must be checked */
- if (S->do_bounds_check)
- S->tccgen_vtop->r |= VT_MUSTBOUND;
+ if (tcc_state->do_bounds_check)
+ vtop->r |= VT_MUSTBOUND;
#endif
}
- next(S);
- } else if (S->tccpp_tok == '[') {
- next(S);
- gexpr(S);
- gen_op(S, '+');
- indir(S);
- skip(S, ']');
- } else if (S->tccpp_tok == '(') {
+ next();
+ } else if (tok == '[') {
+ next();
+ gexpr();
+ gen_op('+');
+ indir();
+ skip(']');
+ } else if (tok == '(') {
SValue ret;
Sym *sa;
int nb_args, ret_nregs, ret_align, regsize, variadic;
/* function call */
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FUNC) {
+ if ((vtop->type.t & VT_BTYPE) != VT_FUNC) {
/* pointer test (no array accepted) */
- if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_ARRAY)) == VT_PTR) {
- S->tccgen_vtop->type = *pointed_type(&S->tccgen_vtop->type);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_FUNC)
+ if ((vtop->type.t & (VT_BTYPE | VT_ARRAY)) == VT_PTR) {
+ vtop->type = *pointed_type(&vtop->type);
+ if ((vtop->type.t & VT_BTYPE) != VT_FUNC)
goto error_func;
} else {
error_func:
- expect(S, "function pointer");
+ expect("function pointer");
}
} else {
- S->tccgen_vtop->r &= ~VT_LVAL; /* no lvalue */
+ vtop->r &= ~VT_LVAL; /* no lvalue */
}
/* get return type */
- s = S->tccgen_vtop->type.ref;
- next(S);
+ s = vtop->type.ref;
+ next();
sa = s->next; /* first parameter */
nb_args = regsize = 0;
ret.r2 = VT_CONST;
@@ -6383,19 +6474,19 @@ special_math_val:
while (size & (size - 1))
size = (size | (size - 1)) + 1;
#endif
- S->tccgen_loc = (S->tccgen_loc - size) & -align;
+ loc = (loc - size) & -align;
ret.type = s->type;
ret.r = VT_LOCAL | VT_LVAL;
/* pass it as 'int' to avoid structure arg passing
problems */
- vseti(S, VT_LOCAL, S->tccgen_loc);
+ vseti(VT_LOCAL, loc);
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- --S->tccgen_loc;
+ if (tcc_state->do_bounds_check)
+ --loc;
#endif
- ret.c = S->tccgen_vtop->c;
+ ret.c = vtop->c;
if (ret_nregs < 0)
- S->tccgen_vtop--;
+ vtop--;
else
nb_args++;
}
@@ -6409,33 +6500,33 @@ special_math_val:
ret.c.i = 0;
PUT_R_RET(&ret, ret.type.t);
}
- if (S->tccpp_tok != ')') {
+ if (tok != ')') {
for(;;) {
- expr_eq(S);
- gfunc_param_typed(S, s, sa);
+ expr_eq();
+ gfunc_param_typed(s, sa);
nb_args++;
if (sa)
sa = sa->next;
- if (S->tccpp_tok == ')')
+ if (tok == ')')
break;
- skip(S, ',');
+ skip(',');
}
}
if (sa)
- tcc_error(S, "too few arguments to function");
- skip(S, ')');
- gfunc_call(S, nb_args);
+ tcc_error("too few arguments to function");
+ skip(')');
+ gfunc_call(nb_args);
if (ret_nregs < 0) {
- vsetc(S, &ret.type, ret.r, &ret.c);
+ vsetc(&ret.type, ret.r, &ret.c);
#ifdef TCC_TARGET_RISCV64
- arch_transfer_ret_regs(S, 1);
+ arch_transfer_ret_regs(1);
#endif
} else {
/* return value */
for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {
- vsetc(S, &ret.type, r, &ret.c);
- S->tccgen_vtop->r2 = ret.r2; /* Loop only happens when r2 is VT_CONST */
+ vsetc(&ret.type, r, &ret.c);
+ vtop->r2 = ret.r2; /* Loop only happens when r2 is VT_CONST */
}
/* handle packed struct return */
@@ -6447,19 +6538,19 @@ special_math_val:
space. Assume register size is power of 2. */
if (regsize > align)
align = regsize;
- S->tccgen_loc = (S->tccgen_loc - size) & -align;
- addr = S->tccgen_loc;
+ loc = (loc - size) & -align;
+ addr = loc;
offset = 0;
for (;;) {
- vset(S, &ret.type, VT_LOCAL | VT_LVAL, addr + offset);
- vswap(S);
- vstore(S);
- S->tccgen_vtop--;
+ vset(&ret.type, VT_LOCAL | VT_LVAL, addr + offset);
+ vswap();
+ vstore();
+ vtop--;
if (--ret_nregs == 0)
break;
offset += regsize;
}
- vset(S, &s->type, VT_LOCAL | VT_LVAL, addr);
+ vset(&s->type, VT_LOCAL | VT_LVAL, addr);
}
/* Promote char/short return values. This is matters only
@@ -6470,15 +6561,15 @@ special_math_val:
t = s->type.t & VT_BTYPE;
if (t == VT_BYTE || t == VT_SHORT || t == VT_BOOL) {
#ifdef PROMOTE_RET
- S->tccgen_vtop->r |= BFVAL(VT_MUSTCAST, 1);
+ vtop->r |= BFVAL(VT_MUSTCAST, 1);
#else
- S->tccgen_vtop->type.t = VT_INT;
+ vtop->type.t = VT_INT;
#endif
}
}
if (s->f.func_noreturn) {
- if (S->tccgen_debug_modes)
- tcc_tcov_block_end (S, S->tccgen_tcov_data.line);
+ if (debug_modes)
+ tcc_tcov_block_end (tcov_data.line);
CODE_OFF();
}
} else {
@@ -6493,11 +6584,11 @@ static void expr_prod(void)
{
int t;
- unary(S);
- while ((t = Stccpp_tok) == '*' || t == '/' || t == '%') {
- next(S);
- unary(S);
- gen_op(S, t);
+ unary();
+ while ((t = tok) == '*' || t == '/' || t == '%') {
+ next();
+ unary();
+ gen_op(t);
}
}
@@ -6506,10 +6597,10 @@ static void expr_sum(void)
int t;
expr_prod();
- while ((t = Stccpp_tok) == '+' || t == '-') {
- next(S);
+ while ((t = tok) == '+' || t == '-') {
+ next();
expr_prod();
- gen_op(S, t);
+ gen_op(t);
}
}
@@ -6518,10 +6609,10 @@ static void expr_shift(void)
int t;
expr_sum();
- while ((t = Stccpp_tok) == TOK_SHL || t == TOK_SAR) {
- next(S);
+ while ((t = tok) == TOK_SHL || t == TOK_SAR) {
+ next();
expr_sum();
- gen_op(S, t);
+ gen_op(t);
}
}
@@ -6530,11 +6621,11 @@ static void expr_cmp(void)
int t;
expr_shift();
- while (((t = Stccpp_tok) >= TOK_ULE && t <= TOK_GT) ||
+ while (((t = tok) >= TOK_ULE && t <= TOK_GT) ||
t == TOK_ULT || t == TOK_UGE) {
- next(S);
+ next();
expr_shift();
- gen_op(S, t);
+ gen_op(t);
}
}
@@ -6543,63 +6634,63 @@ static void expr_cmpeq(void)
int t;
expr_cmp();
- while ((t = Stccpp_tok) == TOK_EQ || t == TOK_NE) {
- next(S);
+ while ((t = tok) == TOK_EQ || t == TOK_NE) {
+ next();
expr_cmp();
- gen_op(S, t);
+ gen_op(t);
}
}
static void expr_and(void)
{
expr_cmpeq();
- while (Stccpp_tok == '&') {
- next(S);
+ while (tok == '&') {
+ next();
expr_cmpeq();
- gen_op(S, '&');
+ gen_op('&');
}
}
static void expr_xor(void)
{
expr_and();
- while (Stccpp_tok == '^') {
- next(S);
+ while (tok == '^') {
+ next();
expr_and();
- gen_op(S, '^');
+ gen_op('^');
}
}
static void expr_or(void)
{
expr_xor();
- while (Stccpp_tok == '|') {
- next(S);
+ while (tok == '|') {
+ next();
expr_xor();
- gen_op(S, '|');
+ gen_op('|');
}
}
-static void expr_landor(S, int op);
+static void expr_landor(int op);
static void expr_land(void)
{
expr_or();
- if (Stccpp_tok == TOK_LAND)
- expr_landor(S, Stccpp_tok);
+ if (tok == TOK_LAND)
+ expr_landor(tok);
}
static void expr_lor(void)
{
expr_land();
- if (Stccpp_tok == TOK_LOR)
- expr_landor(S, Stccpp_tok);
+ if (tok == TOK_LOR)
+ expr_landor(tok);
}
# define expr_landor_next(op) op == TOK_LAND ? expr_or() : expr_land()
#else /* defined precedence_parser */
-# define expr_landor_next(op) unary(S), expr_infix(S, precedence(op) + 1)
-# define expr_lor() unary(S), expr_infix(S, 1)
+# define expr_landor_next(op) unary(), expr_infix(precedence(op) + 1)
+# define expr_lor() unary(), expr_infix(1)
static int precedence(int tok)
{
@@ -6620,30 +6711,31 @@ static int precedence(int tok)
return 0;
}
}
-static void init_prec(TCCState* S)
+static unsigned char prec[256];
+static void init_prec(void)
{
int i;
for (i = 0; i < 256; i++)
- S->tccgen_prec[i] = precedence(i);
+ prec[i] = precedence(i);
}
-#define precedence(i) ((unsigned)i < 256 ? S->tccgen_prec[i] : 0)
+#define precedence(i) ((unsigned)i < 256 ? prec[i] : 0)
-static void expr_landor(TCCState* S, int op);
+static void expr_landor(int op);
-static void expr_infix(TCCState* S, int p)
+static void expr_infix(int p)
{
- int t = S->tccpp_tok, p2;
+ int t = tok, p2;
while ((p2 = precedence(t)) >= p) {
if (t == TOK_LOR || t == TOK_LAND) {
- expr_landor(S, t);
+ expr_landor(t);
} else {
- next(S);
- unary(S);
- if (precedence(S->tccpp_tok) > p2)
- expr_infix(S, p2 + 1);
- gen_op(S, t);
+ next();
+ unary();
+ if (precedence(tok) > p2)
+ expr_infix(p2 + 1);
+ gen_op(t);
}
- t = S->tccpp_tok;
+ t = tok;
}
}
#endif
@@ -6651,44 +6743,44 @@ static void expr_infix(TCCState* S, int p)
/* Assuming vtop is a value used in a conditional context
(i.e. compared with zero) return 0 if it's false, 1 if
true and -1 if it can't be statically determined. */
-static int condition_3way(TCCState* S)
+static int condition_3way(void)
{
int c = -1;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
- (!(S->tccgen_vtop->r & VT_SYM) || !S->tccgen_vtop->sym->a.weak)) {
- vdup(S);
- gen_cast_s(S, VT_BOOL);
- c = S->tccgen_vtop->c.i;
- vpop(S);
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
+ (!(vtop->r & VT_SYM) || !vtop->sym->a.weak)) {
+ vdup();
+ gen_cast_s(VT_BOOL);
+ c = vtop->c.i;
+ vpop();
}
return c;
}
-static void expr_landor(TCCState* S, int op)
+static void expr_landor(int op)
{
int t = 0, cc = 1, f = 0, i = op == TOK_LAND, c;
for(;;) {
- c = f ? i : condition_3way(S);
+ c = f ? i : condition_3way();
if (c < 0)
- save_regs(S, 1), cc = 0;
+ save_regs(1), cc = 0;
else if (c != i)
- S->tccgen_nocode_wanted++, f = 1;
- if (S->tccpp_tok != op)
+ nocode_wanted++, f = 1;
+ if (tok != op)
break;
if (c < 0)
- t = gvtst(S, i, t);
+ t = gvtst(i, t);
else
- vpop(S);
- next(S);
+ vpop();
+ next();
expr_landor_next(op);
}
if (cc || f) {
- vpop(S);
- vpushi(S, i ^ f);
- gsym(S, t);
- S->tccgen_nocode_wanted -= f;
+ vpop();
+ vpushi(i ^ f);
+ gsym(t);
+ nocode_wanted -= f;
} else {
- gvtst_set(S, i, t);
+ gvtst_set(i, t);
}
}
@@ -6702,7 +6794,7 @@ static int is_cond_bool(SValue *sv)
return 0;
}
-static void expr_cond(TCCState* S)
+static void expr_cond(void)
{
int tt, u, r1, r2, rc, t1, t2, islv, c, g;
SValue sv;
@@ -6710,86 +6802,86 @@ static void expr_cond(TCCState* S)
int ncw_prev;
expr_lor();
- if (S->tccpp_tok == '?') {
- next(S);
- c = condition_3way(S);
- g = (S->tccpp_tok == ':' && gnu_ext);
+ if (tok == '?') {
+ next();
+ c = condition_3way();
+ g = (tok == ':' && gnu_ext);
tt = 0;
if (!g) {
if (c < 0) {
- save_regs(S, 1);
- tt = gvtst(S, 1, 0);
+ save_regs(1);
+ tt = gvtst(1, 0);
} else {
- vpop(S);
+ vpop();
}
} else if (c < 0) {
/* needed to avoid having different registers saved in
each branch */
- save_regs(S, 1);
- gv_dup(S);
- tt = gvtst(S, 0, 0);
+ save_regs(1);
+ gv_dup();
+ tt = gvtst(0, 0);
}
- ncw_prev = S->tccgen_nocode_wanted;
+ ncw_prev = nocode_wanted;
if (c == 0)
- S->tccgen_nocode_wanted++;
+ nocode_wanted++;
if (!g)
- gexpr(S);
+ gexpr();
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FUNC)
- mk_pointer(S, &S->tccgen_vtop->type);
- sv = *S->tccgen_vtop; /* save value to handle it later */
- S->tccgen_vtop--; /* no vpop so that FP stack is not flushed */
+ if ((vtop->type.t & VT_BTYPE) == VT_FUNC)
+ mk_pointer(&vtop->type);
+ sv = *vtop; /* save value to handle it later */
+ vtop--; /* no vpop so that FP stack is not flushed */
if (g) {
u = tt;
} else if (c < 0) {
- u = gjmp(S, 0);
- gsym(S, tt);
+ u = gjmp(0);
+ gsym(tt);
} else
u = 0;
- S->tccgen_nocode_wanted = ncw_prev;
+ nocode_wanted = ncw_prev;
if (c == 1)
- S->tccgen_nocode_wanted++;
- skip(S, ':');
- expr_cond(S);
+ nocode_wanted++;
+ skip(':');
+ expr_cond();
- if (c < 0 && is_cond_bool(S->tccgen_vtop) && is_cond_bool(&sv)) {
+ if (c < 0 && is_cond_bool(vtop) && is_cond_bool(&sv)) {
/* optimize "if (f ? a > b : c || d) ..." for example, where normally
"a < b" and "c || d" would be forced to "(int)0/1" first, whereas
this code jumps directly to the if's then/else branches. */
- t1 = gvtst(S, 0, 0);
- t2 = gjmp(S, 0);
- gsym(S, u);
- vpushv(S, &sv);
+ t1 = gvtst(0, 0);
+ t2 = gjmp(0);
+ gsym(u);
+ vpushv(&sv);
/* combine jump targets of 2nd op with VT_CMP of 1st op */
- gvtst_set(S, 0, t1);
- gvtst_set(S, 1, t2);
- S->tccgen_nocode_wanted = ncw_prev;
- // tcc_warning(S, "two conditions expr_cond");
+ gvtst_set(0, t1);
+ gvtst_set(1, t2);
+ nocode_wanted = ncw_prev;
+ // tcc_warning("two conditions expr_cond");
return;
}
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_FUNC)
- mk_pointer(S, &S->tccgen_vtop->type);
+ if ((vtop->type.t & VT_BTYPE) == VT_FUNC)
+ mk_pointer(&vtop->type);
/* cast operands to correct type according to ISOC rules */
- if (!combine_types(S, &type, &sv, S->tccgen_vtop, '?'))
- type_incompatibility_error(S, &sv.type, &S->tccgen_vtop->type,
+ if (!combine_types(&type, &sv, vtop, '?'))
+ type_incompatibility_error(&sv.type, &vtop->type,
"type mismatch in conditional expression (have '%s' and '%s')");
/* keep structs lvalue by transforming `(expr ? a : b)` to `*(expr ? &a : &b)` so
that `(expr ? a : b).mem` does not error with "lvalue expected" */
- islv = (S->tccgen_vtop->r & VT_LVAL) && (sv.r & VT_LVAL) && VT_STRUCT == (type.t & VT_BTYPE);
+ islv = (vtop->r & VT_LVAL) && (sv.r & VT_LVAL) && VT_STRUCT == (type.t & VT_BTYPE);
/* now we convert second operand */
if (c != 1) {
- gen_cast(S, &type);
+ gen_cast(&type);
if (islv) {
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
- } else if (VT_STRUCT == (S->tccgen_vtop->type.t & VT_BTYPE))
- gaddrof(S);
+ mk_pointer(&vtop->type);
+ gaddrof();
+ } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE))
+ gaddrof();
}
rc = RC_TYPE(type.t);
@@ -6800,97 +6892,97 @@ static void expr_cond(TCCState* S)
tt = r2 = 0;
if (c < 0) {
- r2 = gv(S, rc);
- tt = gjmp(S, 0);
+ r2 = gv(rc);
+ tt = gjmp(0);
}
- gsym(S, u);
- S->tccgen_nocode_wanted = ncw_prev;
+ gsym(u);
+ nocode_wanted = ncw_prev;
/* this is horrible, but we must also convert first
operand */
if (c != 0) {
- *S->tccgen_vtop = sv;
- gen_cast(S, &type);
+ *vtop = sv;
+ gen_cast(&type);
if (islv) {
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
- } else if (VT_STRUCT == (S->tccgen_vtop->type.t & VT_BTYPE))
- gaddrof(S);
+ mk_pointer(&vtop->type);
+ gaddrof();
+ } else if (VT_STRUCT == (vtop->type.t & VT_BTYPE))
+ gaddrof();
}
if (c < 0) {
- r1 = gv(S, rc);
- move_reg(S, r2, r1, islv ? VT_PTR : type.t);
- S->tccgen_vtop->r = r2;
- gsym(S, tt);
+ r1 = gv(rc);
+ move_reg(r2, r1, islv ? VT_PTR : type.t);
+ vtop->r = r2;
+ gsym(tt);
}
if (islv)
- indir(S);
+ indir();
}
}
-static void expr_eq(TCCState* S)
+static void expr_eq(void)
{
int t;
- expr_cond(S);
- if ((t = S->tccpp_tok) == '=' || TOK_ASSIGN(t)) {
- test_lvalue(S);
- next(S);
+ expr_cond();
+ if ((t = tok) == '=' || TOK_ASSIGN(t)) {
+ test_lvalue();
+ next();
if (t == '=') {
- expr_eq(S);
+ expr_eq();
} else {
- vdup(S);
- expr_eq(S);
- gen_op(S, TOK_ASSIGN_OP(t));
+ vdup();
+ expr_eq();
+ gen_op(TOK_ASSIGN_OP(t));
}
- vstore(S);
+ vstore();
}
}
-ST_FUNC void gexpr(TCCState* S)
+ST_FUNC void gexpr(void)
{
while (1) {
- expr_eq(S);
- if (S->tccpp_tok != ',')
+ expr_eq();
+ if (tok != ',')
break;
- vpop(S);
- next(S);
+ vpop();
+ next();
}
}
/* parse a constant expression and return value in vtop. */
-static void expr_const1(TCCState* S)
+static void expr_const1(void)
{
- S->tccgen_const_wanted++;
- S->tccgen_nocode_wanted += unevalmask + 1;
- expr_cond(S);
- S->tccgen_nocode_wanted -= unevalmask + 1;
- S->tccgen_const_wanted--;
+ const_wanted++;
+ nocode_wanted += unevalmask + 1;
+ expr_cond();
+ nocode_wanted -= unevalmask + 1;
+ const_wanted--;
}
/* parse an integer constant and return its value. */
-static inline int64_t expr_const64(TCCState* S)
+static inline int64_t expr_const64(void)
{
int64_t c;
- expr_const1(S);
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
- expect(S, "constant expression");
- c = S->tccgen_vtop->c.i;
- vpop(S);
+ expr_const1();
+ if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) != VT_CONST)
+ expect("constant expression");
+ c = vtop->c.i;
+ vpop();
return c;
}
/* parse an integer constant and return its value.
Complain if it doesn't fit 32bit (signed or unsigned). */
-ST_FUNC int expr_const(TCCState* S)
+ST_FUNC int expr_const(void)
{
int c;
- int64_t wc = expr_const64(S);
+ int64_t wc = expr_const64();
c = wc;
if (c != wc && (unsigned)c != wc)
- tcc_error(S, "constant exceeds 32 bit");
+ tcc_error("constant exceeds 32 bit");
return c;
}
@@ -6898,81 +6990,81 @@ ST_FUNC int expr_const(TCCState* S)
/* return from function */
#ifndef TCC_TARGET_ARM64
-static void gfunc_return(TCCState* S, CType *func_type)
+static void gfunc_return(CType *func_type)
{
if ((func_type->t & VT_BTYPE) == VT_STRUCT) {
CType type, ret_type;
int ret_align, ret_nregs, regsize;
- ret_nregs = gfunc_sret(func_type, S->tccgen_func_var, &ret_type,
+ ret_nregs = gfunc_sret(func_type, func_var, &ret_type,
&ret_align, &regsize);
if (ret_nregs < 0) {
#ifdef TCC_TARGET_RISCV64
- arch_transfer_ret_regs(S, 0);
+ arch_transfer_ret_regs(0);
#endif
} else if (0 == ret_nregs) {
/* if returning structure, must copy it to implicit
first pointer arg location */
type = *func_type;
- mk_pointer(S, &type);
- vset(S, &type, VT_LOCAL | VT_LVAL, S->tccgen_func_vc);
- indir(S);
- vswap(S);
+ mk_pointer(&type);
+ vset(&type, VT_LOCAL | VT_LVAL, func_vc);
+ indir();
+ vswap();
/* copy structure value to pointer */
- vstore(S);
+ vstore();
} else {
/* returning structure packed into registers */
int size, addr, align, rc;
size = type_size(func_type,&align);
- if ((S->tccgen_vtop->r != (VT_LOCAL | VT_LVAL) ||
- (S->tccgen_vtop->c.i & (ret_align-1)))
+ if ((vtop->r != (VT_LOCAL | VT_LVAL) ||
+ (vtop->c.i & (ret_align-1)))
&& (align & (ret_align-1))) {
- S->tccgen_loc = (S->tccgen_loc - size) & -ret_align;
- addr = S->tccgen_loc;
+ loc = (loc - size) & -ret_align;
+ addr = loc;
type = *func_type;
- vset(S, &type, VT_LOCAL | VT_LVAL, addr);
- vswap(S);
- vstore(S);
- vpop(S);
- vset(S, &ret_type, VT_LOCAL | VT_LVAL, addr);
+ vset(&type, VT_LOCAL | VT_LVAL, addr);
+ vswap();
+ vstore();
+ vpop();
+ vset(&ret_type, VT_LOCAL | VT_LVAL, addr);
}
- S->tccgen_vtop->type = ret_type;
+ vtop->type = ret_type;
rc = RC_RET(ret_type.t);
if (ret_nregs == 1)
- gv(S, rc);
+ gv(rc);
else {
for (;;) {
- vdup(S);
- gv(S, rc);
- vpop(S);
+ vdup();
+ gv(rc);
+ vpop();
if (--ret_nregs == 0)
break;
/* We assume that when a structure is returned in multiple
registers, their classes are consecutive values of the
suite s(n) = 2^n */
rc <<= 1;
- S->tccgen_vtop->c.i += regsize;
+ vtop->c.i += regsize;
}
}
}
} else {
- gv(S, RC_RET(func_type->t));
+ gv(RC_RET(func_type->t));
}
- S->tccgen_vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
+ vtop--; /* NOT vpop() because on x86 it would flush the fp stack */
}
#endif
-static void check_func_return(TCCState* S)
+static void check_func_return(void)
{
- if ((S->tccgen_func_vt.t & VT_BTYPE) == VT_VOID)
+ if ((func_vt.t & VT_BTYPE) == VT_VOID)
return;
- if (!strcmp (S->tccgen_funcname, "main")
- && (S->tccgen_func_vt.t & VT_BTYPE) == VT_INT) {
+ if (!strcmp (funcname, "main")
+ && (func_vt.t & VT_BTYPE) == VT_INT) {
/* main returns 0 by default */
- vpushi(S, 0);
- gen_assign_cast(S, &S->tccgen_func_vt);
- gfunc_return(S, &S->tccgen_func_vt);
+ vpushi(0);
+ gen_assign_cast(&func_vt);
+ gfunc_return(&func_vt);
} else {
- tcc_warning(S, "function might return no value: '%s'", S->tccgen_funcname);
+ tcc_warning("function might return no value: '%s'", funcname);
}
}
@@ -6993,120 +7085,120 @@ static int case_cmpu(const void *pa, const void *pb)
return a < b ? -1 : a > b;
}
-static void gtst_addr(TCCState* S, int t, int a)
+static void gtst_addr(int t, int a)
{
- gsym_addr(S, gvtst(S, 0, t), a);
+ gsym_addr(gvtst(0, t), a);
}
-static void gcase(TCCState* S, struct case_t **base, int len, int *bsym)
+static void gcase(struct case_t **base, int len, int *bsym)
{
struct case_t *p;
int e;
- int ll = (S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG;
+ int ll = (vtop->type.t & VT_BTYPE) == VT_LLONG;
while (len > 8) {
/* binary search */
p = base[len/2];
- vdup(S);
+ vdup();
if (ll)
- vpushll(S, p->v2);
+ vpushll(p->v2);
else
- vpushi(S, p->v2);
- gen_op(S, TOK_LE);
- e = gvtst(S, 1, 0);
- vdup(S);
+ vpushi(p->v2);
+ gen_op(TOK_LE);
+ e = gvtst(1, 0);
+ vdup();
if (ll)
- vpushll(S, p->v1);
+ vpushll(p->v1);
else
- vpushi(S, p->v1);
- gen_op(S, TOK_GE);
- gtst_addr(S, 0, p->sym); /* v1 <= x <= v2 */
+ vpushi(p->v1);
+ gen_op(TOK_GE);
+ gtst_addr(0, p->sym); /* v1 <= x <= v2 */
/* x < v1 */
- gcase(S, base, len/2, bsym);
+ gcase(base, len/2, bsym);
/* x > v2 */
- gsym(S, e);
+ gsym(e);
e = len/2 + 1;
base += e; len -= e;
}
/* linear scan */
while (len--) {
p = *base++;
- vdup(S);
+ vdup();
if (ll)
- vpushll(S, p->v2);
+ vpushll(p->v2);
else
- vpushi(S, p->v2);
+ vpushi(p->v2);
if (p->v1 == p->v2) {
- gen_op(S, TOK_EQ);
- gtst_addr(S, 0, p->sym);
+ gen_op(TOK_EQ);
+ gtst_addr(0, p->sym);
} else {
- gen_op(S, TOK_LE);
- e = gvtst(S, 1, 0);
- vdup(S);
+ gen_op(TOK_LE);
+ e = gvtst(1, 0);
+ vdup();
if (ll)
- vpushll(S, p->v1);
+ vpushll(p->v1);
else
- vpushi(S, p->v1);
- gen_op(S, TOK_GE);
- gtst_addr(S, 0, p->sym);
- gsym(S, e);
+ vpushi(p->v1);
+ gen_op(TOK_GE);
+ gtst_addr(0, p->sym);
+ gsym(e);
}
}
- *bsym = gjmp(S, *bsym);
+ *bsym = gjmp(*bsym);
}
/* ------------------------------------------------------------------------- */
/* __attribute__((cleanup(fn))) */
-static void try_call_scope_cleanup(TCCState* S, Sym *stop)
+static void try_call_scope_cleanup(Sym *stop)
{
- Sym *cls = S->tccgen_cur_scope->cl.s;
+ Sym *cls = cur_scope->cl.s;
for (; cls != stop; cls = cls->ncl) {
Sym *fs = cls->next;
Sym *vs = cls->prev_tok;
- vpushsym(S, &fs->type, fs);
- vset(S, &vs->type, vs->r, vs->c);
- S->tccgen_vtop->sym = vs;
- mk_pointer(S, &S->tccgen_vtop->type);
- gaddrof(S);
- gfunc_call(S, 1);
+ vpushsym(&fs->type, fs);
+ vset(&vs->type, vs->r, vs->c);
+ vtop->sym = vs;
+ mk_pointer(&vtop->type);
+ gaddrof();
+ gfunc_call(1);
}
}
-static void try_call_cleanup_goto(TCCState* S, Sym *cleanupstate)
+static void try_call_cleanup_goto(Sym *cleanupstate)
{
Sym *oc, *cc;
int ocd, ccd;
- if (!S->tccgen_cur_scope->cl.s)
+ if (!cur_scope->cl.s)
return;
/* search NCA of both cleanup chains given parents and initial depth */
ocd = cleanupstate ? cleanupstate->v & ~SYM_FIELD : 0;
- for (ccd = S->tccgen_cur_scope->cl.n, oc = cleanupstate; ocd > ccd; --ocd, oc = oc->ncl)
+ for (ccd = cur_scope->cl.n, oc = cleanupstate; ocd > ccd; --ocd, oc = oc->ncl)
;
- for (cc = S->tccgen_cur_scope->cl.s; ccd > ocd; --ccd, cc = cc->ncl)
+ for (cc = cur_scope->cl.s; ccd > ocd; --ccd, cc = cc->ncl)
;
for (; cc != oc; cc = cc->ncl, oc = oc->ncl, --ccd)
;
- try_call_scope_cleanup(S, cc);
+ try_call_scope_cleanup(cc);
}
/* call 'func' for each __attribute__((cleanup(func))) */
-static void block_cleanup(TCCState* S, scope_t *o)
+static void block_cleanup(struct scope *o)
{
int jmp = 0;
Sym *g, **pg;
- for (pg = &S->tccgen_pending_gotos; (g = *pg) && g->c > o->cl.n;) {
+ for (pg = &pending_gotos; (g = *pg) && g->c > o->cl.n;) {
if (g->prev_tok->r & LABEL_FORWARD) {
Sym *pcl = g->next;
if (!jmp)
- jmp = gjmp(S, 0);
- gsym(S, pcl->jnext);
- try_call_scope_cleanup(S, o->cl.s);
- pcl->jnext = gjmp(S, 0);
+ jmp = gjmp(0);
+ gsym(pcl->jnext);
+ try_call_scope_cleanup(o->cl.s);
+ pcl->jnext = gjmp(0);
if (!o->cl.n)
goto remove_pending;
g->c = o->cl.n;
@@ -7114,61 +7206,61 @@ static void block_cleanup(TCCState* S, scope_t *o)
} else {
remove_pending:
*pg = g->prev;
- sym_free(S, g);
+ sym_free(g);
}
}
- gsym(S, jmp);
- try_call_scope_cleanup(S, o->cl.s);
+ gsym(jmp);
+ try_call_scope_cleanup(o->cl.s);
}
/* ------------------------------------------------------------------------- */
/* VLA */
-static void vla_restore(TCCState * S, int loc)
+static void vla_restore(int loc)
{
if (loc)
- gen_vla_sp_restore(S, loc);
+ gen_vla_sp_restore(loc);
}
-static void vla_leave(TCCState * S, scope_t *o)
+static void vla_leave(struct scope *o)
{
- scope_t *c = S->tccgen_cur_scope, *v = NULL;
+ struct scope *c = cur_scope, *v = NULL;
for (; c != o && c; c = c->prev)
if (c->vla.num)
v = c;
if (v)
- vla_restore(S, v->vla.locorig);
+ vla_restore(v->vla.locorig);
}
/* ------------------------------------------------------------------------- */
/* local scopes */
-static void new_scope(TCCState* S, scope_t *o)
+static void new_scope(struct scope *o)
{
/* copy and link previous scope */
- *o = *S->tccgen_cur_scope;
- o->prev = S->tccgen_cur_scope;
- S->tccgen_cur_scope = o;
- S->tccgen_cur_scope->vla.num = 0;
+ *o = *cur_scope;
+ o->prev = cur_scope;
+ cur_scope = o;
+ cur_scope->vla.num = 0;
/* record local declaration stack position */
- o->lstk = S->tccgen_local_stack;
- o->llstk = S->tccgen_local_label_stack;
- ++S->tccgen_local_scope;
+ o->lstk = local_stack;
+ o->llstk = local_label_stack;
+ ++local_scope;
- if (S->tccgen_debug_modes)
- tcc_debug_stabn(S, N_LBRAC, S->tccgen_ind - S->tccgen_func_ind);
+ if (debug_modes)
+ tcc_debug_stabn(tcc_state, N_LBRAC, ind - func_ind);
}
-static void prev_scope(TCCState* S, scope_t *o, int is_expr)
+static void prev_scope(struct scope *o, int is_expr)
{
- vla_leave(S, o->prev);
+ vla_leave(o->prev);
if (o->cl.s != o->prev->cl.s)
- block_cleanup(S, o->prev);
+ block_cleanup(o->prev);
/* pop locally defined labels */
- label_pop(S, &S->tccgen_local_label_stack, o->llstk, is_expr);
+ label_pop(&local_label_stack, o->llstk, is_expr);
/* In the is_expr case (a statement expression is finished here),
vtop might refer to symbols on the local_stack. Either via the
@@ -7179,238 +7271,238 @@ static void prev_scope(TCCState* S, scope_t *o, int is_expr)
tables, though. sym_pop will do that. */
/* pop locally defined symbols */
- pop_local_syms(S, o->lstk, is_expr);
- S->tccgen_cur_scope = o->prev;
- --S->tccgen_local_scope;
+ pop_local_syms(o->lstk, is_expr);
+ cur_scope = o->prev;
+ --local_scope;
- if (S->tccgen_debug_modes)
- tcc_debug_stabn(S, N_RBRAC, S->tccgen_ind - S->tccgen_func_ind);
+ if (debug_modes)
+ tcc_debug_stabn(tcc_state, N_RBRAC, ind - func_ind);
}
/* leave a scope via break/continue(/goto) */
-static void leave_scope(TCCState* S, scope_t *o)
+static void leave_scope(struct scope *o)
{
if (!o)
return;
- try_call_scope_cleanup(S, o->cl.s);
- vla_leave(S, o);
+ try_call_scope_cleanup(o->cl.s);
+ vla_leave(o);
}
/* ------------------------------------------------------------------------- */
/* call block from 'for do while' loops */
-static void lblock(TCCState* S, int *bsym, int *csym)
+static void lblock(int *bsym, int *csym)
{
- scope_t *lo = S->tccgen_loop_scope, *co = S->tccgen_cur_scope;
+ struct scope *lo = loop_scope, *co = cur_scope;
int *b = co->bsym, *c = co->csym;
if (csym) {
co->csym = csym;
- S->tccgen_loop_scope = co;
+ loop_scope = co;
}
co->bsym = bsym;
- block(S, 0);
+ block(0);
co->bsym = b;
if (csym) {
co->csym = c;
- S->tccgen_loop_scope = lo;
+ loop_scope = lo;
}
}
-static void block(TCCState* S, int is_expr)
+static void block(int is_expr)
{
int a, b, c, d, e, t;
- scope_t o;
+ struct scope o;
Sym *s;
if (is_expr) {
/* default return value is (void) */
- vpushi(S, 0);
- S->tccgen_vtop->type.t = VT_VOID;
+ vpushi(0);
+ vtop->type.t = VT_VOID;
}
again:
- t = S->tccpp_tok;
+ t = tok;
/* If the token carries a value, next() might destroy it. Only with
invalid code such as f(){"123"4;} */
if (TOK_HAS_VALUE(t))
goto expr;
- next(S);
+ next();
- if (S->tccgen_debug_modes)
- tcc_tcov_check_line (S, 0), tcc_tcov_block_begin (S);
+ if (debug_modes)
+ tcc_tcov_check_line (0), tcc_tcov_block_begin ();
if (t == TOK_IF) {
- skip(S, '(');
- gexpr(S);
- skip(S, ')');
- a = gvtst(S, 1, 0);
- block(S, 0);
- if (S->tccpp_tok == TOK_ELSE) {
- d = gjmp(S, 0);
- gsym(S, a);
- next(S);
- block(S, 0);
- gsym(S, d); /* patch else jmp */
+ skip('(');
+ gexpr();
+ skip(')');
+ a = gvtst(1, 0);
+ block(0);
+ if (tok == TOK_ELSE) {
+ d = gjmp(0);
+ gsym(a);
+ next();
+ block(0);
+ gsym(d); /* patch else jmp */
} else {
- gsym(S, a);
+ gsym(a);
}
} else if (t == TOK_WHILE) {
- d = gind(S);
- skip(S, '(');
- gexpr(S);
- skip(S, ')');
- a = gvtst(S, 1, 0);
+ d = gind();
+ skip('(');
+ gexpr();
+ skip(')');
+ a = gvtst(1, 0);
b = 0;
- lblock(S, &a, &b);
- gjmp_addr(S, d);
- gsym_addr(S, b, d);
- gsym(S, a);
+ lblock(&a, &b);
+ gjmp_addr(d);
+ gsym_addr(b, d);
+ gsym(a);
} else if (t == '{') {
- new_scope(S, &o);
+ new_scope(&o);
/* handle local labels declarations */
- while (S->tccpp_tok == TOK_LABEL) {
+ while (tok == TOK_LABEL) {
do {
- next(S);
- if (S->tccpp_tok < TOK_UIDENT)
- expect(S, "label identifier");
- label_push(S, &S->tccgen_local_label_stack, S->tccpp_tok, LABEL_DECLARED);
- next(S);
- } while (S->tccpp_tok == ',');
- skip(S, ';');
- }
-
- while (S->tccpp_tok != '}') {
- decl(S, VT_LOCAL);
- if (S->tccpp_tok != '}') {
+ next();
+ if (tok < TOK_UIDENT)
+ expect("label identifier");
+ label_push(&local_label_stack, tok, LABEL_DECLARED);
+ next();
+ } while (tok == ',');
+ skip(';');
+ }
+
+ while (tok != '}') {
+ decl(VT_LOCAL);
+ if (tok != '}') {
if (is_expr)
- vpop(S);
- block(S, is_expr);
+ vpop();
+ block(is_expr);
}
}
- prev_scope(S, &o, is_expr);
- if (S->tccgen_local_scope)
- next(S);
- else if (!S->tccgen_nocode_wanted)
- check_func_return(S);
+ prev_scope(&o, is_expr);
+ if (local_scope)
+ next();
+ else if (!nocode_wanted)
+ check_func_return();
} else if (t == TOK_RETURN) {
- b = (S->tccgen_func_vt.t & VT_BTYPE) != VT_VOID;
- if (S->tccpp_tok != ';') {
- gexpr(S);
+ b = (func_vt.t & VT_BTYPE) != VT_VOID;
+ if (tok != ';') {
+ gexpr();
if (b) {
- gen_assign_cast(S, &S->tccgen_func_vt);
+ gen_assign_cast(&func_vt);
} else {
- if (S->tccgen_vtop->type.t != VT_VOID)
- tcc_warning(S, "void function returns a value");
- S->tccgen_vtop--;
+ if (vtop->type.t != VT_VOID)
+ tcc_warning("void function returns a value");
+ vtop--;
}
} else if (b) {
- tcc_warning(S, "'return' with no value");
+ tcc_warning("'return' with no value");
b = 0;
}
- leave_scope(S, S->tccgen_root_scope);
+ leave_scope(root_scope);
if (b)
- gfunc_return(S, &S->tccgen_func_vt);
- skip(S, ';');
+ gfunc_return(&func_vt);
+ skip(';');
/* jump unless last stmt in top-level block */
- if (S->tccpp_tok != '}' || S->tccgen_local_scope != 1)
- S->tccgen_rsym = gjmp(S, S->tccgen_rsym);
- if (S->tccgen_debug_modes)
- tcc_tcov_block_end (S, S->tccgen_tcov_data.line);
+ if (tok != '}' || local_scope != 1)
+ rsym = gjmp(rsym);
+ if (debug_modes)
+ tcc_tcov_block_end (tcov_data.line);
CODE_OFF();
} else if (t == TOK_BREAK) {
/* compute jump */
- if (!S->tccgen_cur_scope->bsym)
- tcc_error(S, "cannot break");
- if (S->tccgen_cur_switch && S->tccgen_cur_scope->bsym == S->tccgen_cur_switch->bsym)
- leave_scope(S, S->tccgen_cur_switch->scope);
+ if (!cur_scope->bsym)
+ tcc_error("cannot break");
+ if (cur_switch && cur_scope->bsym == cur_switch->bsym)
+ leave_scope(cur_switch->scope);
else
- leave_scope(S, S->tccgen_loop_scope);
- *S->tccgen_cur_scope->bsym = gjmp(S, *S->tccgen_cur_scope->bsym);
- skip(S, ';');
+ leave_scope(loop_scope);
+ *cur_scope->bsym = gjmp(*cur_scope->bsym);
+ skip(';');
} else if (t == TOK_CONTINUE) {
/* compute jump */
- if (!S->tccgen_cur_scope->csym)
- tcc_error(S, "cannot continue");
- leave_scope(S, S->tccgen_loop_scope);
- *S->tccgen_cur_scope->csym = gjmp(S, *S->tccgen_cur_scope->csym);
- skip(S, ';');
+ if (!cur_scope->csym)
+ tcc_error("cannot continue");
+ leave_scope(loop_scope);
+ *cur_scope->csym = gjmp(*cur_scope->csym);
+ skip(';');
} else if (t == TOK_FOR) {
- new_scope(S, &o);
+ new_scope(&o);
- skip(S, '(');
- if (S->tccpp_tok != ';') {
+ skip('(');
+ if (tok != ';') {
/* c99 for-loop init decl? */
- if (!decl0(S, VT_LOCAL, 1, NULL)) {
+ if (!decl0(VT_LOCAL, 1, NULL)) {
/* no, regular for-loop init expr */
- gexpr(S);
- vpop(S);
+ gexpr();
+ vpop();
}
}
- skip(S, ';');
+ skip(';');
a = b = 0;
- c = d = gind(S);
- if (S->tccpp_tok != ';') {
- gexpr(S);
- a = gvtst(S, 1, 0);
- }
- skip(S, ';');
- if (S->tccpp_tok != ')') {
- e = gjmp(S, 0);
- d = gind(S);
- gexpr(S);
- vpop(S);
- gjmp_addr(S, c);
- gsym(S, e);
- }
- skip(S, ')');
- lblock(S, &a, &b);
- gjmp_addr(S, d);
- gsym_addr(S, b, d);
- gsym(S, a);
- prev_scope(S, &o, 0);
+ c = d = gind();
+ if (tok != ';') {
+ gexpr();
+ a = gvtst(1, 0);
+ }
+ skip(';');
+ if (tok != ')') {
+ e = gjmp(0);
+ d = gind();
+ gexpr();
+ vpop();
+ gjmp_addr(c);
+ gsym(e);
+ }
+ skip(')');
+ lblock(&a, &b);
+ gjmp_addr(d);
+ gsym_addr(b, d);
+ gsym(a);
+ prev_scope(&o, 0);
} else if (t == TOK_DO) {
a = b = 0;
- d = gind(S);
- lblock(S, &a, &b);
- gsym(S, b);
- skip(S, TOK_WHILE);
- skip(S, '(');
- gexpr(S);
- skip(S, ')');
- skip(S, ';');
- c = gvtst(S, 0, 0);
- gsym_addr(S, c, d);
- gsym(S, a);
+ d = gind();
+ lblock(&a, &b);
+ gsym(b);
+ skip(TOK_WHILE);
+ skip('(');
+ gexpr();
+ skip(')');
+ skip(';');
+ c = gvtst(0, 0);
+ gsym_addr(c, d);
+ gsym(a);
} else if (t == TOK_SWITCH) {
struct switch_t *sw;
- sw = tcc_mallocz(S, sizeof *sw);
+ sw = tcc_mallocz(sizeof *sw);
sw->bsym = &a;
- sw->scope = S->tccgen_cur_scope;
- sw->prev = S->tccgen_cur_switch;
- S->tccgen_cur_switch = sw;
+ sw->scope = cur_scope;
+ sw->prev = cur_switch;
+ cur_switch = sw;
- skip(S, '(');
- gexpr(S);
- skip(S, ')');
- sw->sv = *S->tccgen_vtop--; /* save switch value */
+ skip('(');
+ gexpr();
+ skip(')');
+ sw->sv = *vtop--; /* save switch value */
a = 0;
- b = gjmp(S, 0); /* jump to first case */
- lblock(S, &a, NULL);
- a = gjmp(S, a); /* add implicit break */
+ b = gjmp(0); /* jump to first case */
+ lblock(&a, NULL);
+ a = gjmp(a); /* add implicit break */
/* case lookup */
- gsym(S, b);
+ gsym(b);
if (sw->sv.type.t & VT_UNSIGNED)
qsort(sw->p, sw->n, sizeof(void*), case_cmpu);
@@ -7421,143 +7513,143 @@ again:
if (sw->sv.type.t & VT_UNSIGNED
? (uint64_t)sw->p[b - 1]->v2 >= (uint64_t)sw->p[b]->v1
: sw->p[b - 1]->v2 >= sw->p[b]->v1)
- tcc_error(S, "duplicate case value");
+ tcc_error("duplicate case value");
- vpushv(S, &sw->sv);
- gv(S, RC_INT);
- d = 0, gcase(S, sw->p, sw->n, &d);
- vpop(S);
+ vpushv(&sw->sv);
+ gv(RC_INT);
+ d = 0, gcase(sw->p, sw->n, &d);
+ vpop();
if (sw->def_sym)
- gsym_addr(S, d, sw->def_sym);
+ gsym_addr(d, sw->def_sym);
else
- gsym(S, d);
+ gsym(d);
/* break label */
- gsym(S, a);
+ gsym(a);
- dynarray_reset(S, &sw->p, &sw->n);
- S->tccgen_cur_switch = sw->prev;
- tcc_free(S, sw);
+ dynarray_reset(&sw->p, &sw->n);
+ cur_switch = sw->prev;
+ tcc_free(sw);
} else if (t == TOK_CASE) {
- struct case_t *cr = tcc_malloc(S, sizeof(struct case_t));
- if (!S->tccgen_cur_switch)
- expect(S, "switch");
- cr->v1 = cr->v2 = expr_const64(S);
- if (gnu_ext && S->tccpp_tok == TOK_DOTS) {
- next(S);
- cr->v2 = expr_const64(S);
- if ((!(S->tccgen_cur_switch->sv.type.t & VT_UNSIGNED) && cr->v2 < cr->v1)
- || (S->tccgen_cur_switch->sv.type.t & VT_UNSIGNED && (uint64_t)cr->v2 < (uint64_t)cr->v1))
- tcc_warning(S, "empty case range");
- }
- S->tccgen_tcov_data.ind = 0;
- cr->sym = gind(S);
- dynarray_add(S, &S->tccgen_cur_switch->p, &S->tccgen_cur_switch->n, cr);
- skip(S, ':');
+ struct case_t *cr = tcc_malloc(sizeof(struct case_t));
+ if (!cur_switch)
+ expect("switch");
+ cr->v1 = cr->v2 = expr_const64();
+ if (gnu_ext && tok == TOK_DOTS) {
+ next();
+ cr->v2 = expr_const64();
+ if ((!(cur_switch->sv.type.t & VT_UNSIGNED) && cr->v2 < cr->v1)
+ || (cur_switch->sv.type.t & VT_UNSIGNED && (uint64_t)cr->v2 < (uint64_t)cr->v1))
+ tcc_warning("empty case range");
+ }
+ tcov_data.ind = 0;
+ cr->sym = gind();
+ dynarray_add(&cur_switch->p, &cur_switch->n, cr);
+ skip(':');
is_expr = 0;
goto block_after_label;
} else if (t == TOK_DEFAULT) {
- if (!S->tccgen_cur_switch)
- expect(S, "switch");
- if (S->tccgen_cur_switch->def_sym)
- tcc_error(S, "too many 'default'");
- S->tccgen_tcov_data.ind = 0;
- S->tccgen_cur_switch->def_sym = gind(S);
- skip(S, ':');
+ if (!cur_switch)
+ expect("switch");
+ if (cur_switch->def_sym)
+ tcc_error("too many 'default'");
+ tcov_data.ind = 0;
+ cur_switch->def_sym = gind();
+ skip(':');
is_expr = 0;
goto block_after_label;
} else if (t == TOK_GOTO) {
- if (S->tccgen_cur_scope->vla.num)
- vla_restore(S, S->tccgen_cur_scope->vla.locorig);
- if (S->tccpp_tok == '*' && gnu_ext) {
+ if (cur_scope->vla.num)
+ vla_restore(cur_scope->vla.locorig);
+ if (tok == '*' && gnu_ext) {
/* computed goto */
- next(S);
- gexpr(S);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) != VT_PTR)
- expect(S, "pointer");
- ggoto(S);
-
- } else if (S->tccpp_tok >= TOK_UIDENT) {
- s = label_find(S, S->tccpp_tok);
+ next();
+ gexpr();
+ if ((vtop->type.t & VT_BTYPE) != VT_PTR)
+ expect("pointer");
+ ggoto();
+
+ } else if (tok >= TOK_UIDENT) {
+ s = label_find(tok);
/* put forward definition if needed */
if (!s)
- s = label_push(S, &S->tccgen_global_label_stack, S->tccpp_tok, LABEL_FORWARD);
+ s = label_push(&global_label_stack, tok, LABEL_FORWARD);
else if (s->r == LABEL_DECLARED)
s->r = LABEL_FORWARD;
if (s->r & LABEL_FORWARD) {
/* start new goto chain for cleanups, linked via label->next */
- if (S->tccgen_cur_scope->cl.s && !S->tccgen_nocode_wanted) {
- sym_push2(S, &S->tccgen_pending_gotos, SYM_FIELD, 0, S->tccgen_cur_scope->cl.n);
- S->tccgen_pending_gotos->prev_tok = s;
- s = sym_push2(S, &s->next, SYM_FIELD, 0, 0);
- S->tccgen_pending_gotos->next = s;
+ if (cur_scope->cl.s && !nocode_wanted) {
+ sym_push2(&pending_gotos, SYM_FIELD, 0, cur_scope->cl.n);
+ pending_gotos->prev_tok = s;
+ s = sym_push2(&s->next, SYM_FIELD, 0, 0);
+ pending_gotos->next = s;
}
- s->jnext = gjmp(S, s->jnext);
+ s->jnext = gjmp(s->jnext);
} else {
- try_call_cleanup_goto(S, s->cleanupstate);
- gjmp_addr(S, s->jnext);
+ try_call_cleanup_goto(s->cleanupstate);
+ gjmp_addr(s->jnext);
}
- next(S);
+ next();
} else {
- expect(S, "label identifier");
+ expect("label identifier");
}
- skip(S, ';');
+ skip(';');
} else if (t == TOK_ASM1 || t == TOK_ASM2 || t == TOK_ASM3) {
- asm_instr(S);
+ asm_instr();
} else {
- if (S->tccpp_tok == ':' && t >= TOK_UIDENT) {
+ if (tok == ':' && t >= TOK_UIDENT) {
/* label case */
- next(S);
- s = label_find(S, t);
+ next();
+ s = label_find(t);
if (s) {
if (s->r == LABEL_DEFINED)
- tcc_error(S, "duplicate label '%s'", get_tok_str(S, s->v, NULL));
+ tcc_error("duplicate label '%s'", get_tok_str(s->v, NULL));
s->r = LABEL_DEFINED;
if (s->next) {
Sym *pcl; /* pending cleanup goto */
for (pcl = s->next; pcl; pcl = pcl->prev)
- gsym(S, pcl->jnext);
- sym_pop(S, &s->next, NULL, 0);
+ gsym(pcl->jnext);
+ sym_pop(&s->next, NULL, 0);
} else
- gsym(S, s->jnext);
+ gsym(s->jnext);
} else {
- s = label_push(S, &S->tccgen_global_label_stack, t, LABEL_DEFINED);
+ s = label_push(&global_label_stack, t, LABEL_DEFINED);
}
- s->jnext = gind(S);
- s->cleanupstate = S->tccgen_cur_scope->cl.s;
+ s->jnext = gind();
+ s->cleanupstate = cur_scope->cl.s;
block_after_label:
- vla_restore(S, S->tccgen_cur_scope->vla.loc);
- if (S->tccpp_tok != '}')
+ vla_restore(cur_scope->vla.loc);
+ if (tok != '}')
goto again;
/* we accept this, but it is a mistake */
- tcc_warning_c(warn_all)(S, "deprecated use of label at end of compound statement");
+ tcc_warning_c(warn_all)("deprecated use of label at end of compound statement");
} else {
/* expression case */
if (t != ';') {
- unget_tok(S, t);
+ unget_tok(t);
expr:
if (is_expr) {
- vpop(S);
- gexpr(S);
+ vpop();
+ gexpr();
} else {
- gexpr(S);
- vpop(S);
+ gexpr();
+ vpop();
}
- skip(S, ';');
+ skip(';');
}
}
}
- if (S->tccgen_debug_modes)
- tcc_tcov_check_line (S, 0), tcc_tcov_block_end (S, 0);
+ if (debug_modes)
+ tcc_tcov_check_line (0), tcc_tcov_block_end (0);
}
/* This skips over a stream of tokens containing balanced {} and ()
@@ -7565,25 +7657,25 @@ again:
with a '{'). If STR then allocates and stores the skipped tokens
in *STR. This doesn't check if () and {} are nested correctly,
i.e. "({)}" is accepted. */
-static void skip_or_save_block(TCCState* S, TokenString **str)
+static void skip_or_save_block(TokenString **str)
{
- int braces = S->tccpp_tok == '{';
+ int braces = tok == '{';
int level = 0;
if (str)
- *str = tok_str_alloc(S);
+ *str = tok_str_alloc();
- while ((level > 0 || (S->tccpp_tok != '}' && S->tccpp_tok != ',' && S->tccpp_tok != ';' && S->tccpp_tok != ')'))) {
+ while ((level > 0 || (tok != '}' && tok != ',' && tok != ';' && tok != ')'))) {
int t;
- if (S->tccpp_tok == TOK_EOF) {
+ if (tok == TOK_EOF) {
if (str || level > 0)
- tcc_error(S, "unexpected end of file");
+ tcc_error("unexpected end of file");
else
break;
}
if (str)
- tok_str_add_tok(S, *str);
- t = S->tccpp_tok;
- next(S);
+ tok_str_add_tok(*str);
+ t = tok;
+ next();
if (t == '{' || t == '(') {
level++;
} else if (t == '}' || t == ')') {
@@ -7593,69 +7685,69 @@ static void skip_or_save_block(TCCState* S, TokenString **str)
}
}
if (str) {
- tok_str_add(S, *str, -1);
- tok_str_add(S, *str, 0);
+ tok_str_add(*str, -1);
+ tok_str_add(*str, 0);
}
}
#define EXPR_CONST 1
#define EXPR_ANY 2
-static void parse_init_elem(TCCState* S, int expr_type)
+static void parse_init_elem(int expr_type)
{
int saved_global_expr;
switch(expr_type) {
case EXPR_CONST:
/* compound literals must be allocated globally in this case */
- saved_global_expr = S->tccgen_global_expr;
- S->tccgen_global_expr = 1;
- expr_const1(S);
- S->tccgen_global_expr = saved_global_expr;
+ saved_global_expr = global_expr;
+ global_expr = 1;
+ expr_const1();
+ global_expr = saved_global_expr;
/* NOTE: symbols are accepted, as well as lvalue for anon symbols
(compound literals). */
- if (((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST
- && ((S->tccgen_vtop->r & (VT_SYM|VT_LVAL)) != (VT_SYM|VT_LVAL)
- || S->tccgen_vtop->sym->v < SYM_FIRST_ANOM))
+ if (((vtop->r & (VT_VALMASK | VT_LVAL)) != VT_CONST
+ && ((vtop->r & (VT_SYM|VT_LVAL)) != (VT_SYM|VT_LVAL)
+ || vtop->sym->v < SYM_FIRST_ANOM))
#ifdef TCC_TARGET_PE
- || ((S->tccgen_vtop->r & VT_SYM) && S->tccgen_vtop->sym->a.dllimport)
+ || ((vtop->r & VT_SYM) && vtop->sym->a.dllimport)
#endif
)
- tcc_error(S, "initializer element is not constant");
+ tcc_error("initializer element is not constant");
break;
case EXPR_ANY:
- expr_eq(S);
+ expr_eq();
break;
}
}
#if 1
-static void init_assert(TCCState* S, init_params *p, int offset)
+static void init_assert(init_params *p, int offset)
{
if (p->sec ? !NODATA_WANTED && offset > p->sec->data_offset
- : !S->tccgen_nocode_wanted && offset > p->local_offset)
- tcc_internal_error(S, "initializer overflow");
+ : !nocode_wanted && offset > p->local_offset)
+ tcc_internal_error("initializer overflow");
}
#else
-#define init_assert(S, sec, offset)
+#define init_assert(sec, offset)
#endif
/* put zeros for variable based init */
-static void init_putz(TCCState* S, init_params *p, unsigned long c, int size)
+static void init_putz(init_params *p, unsigned long c, int size)
{
- init_assert(S, p, c + size);
+ init_assert(p, c + size);
if (p->sec) {
/* nothing to do because globals are already set to zero */
} else {
- vpush_helper_func(S, TOK_memset);
- vseti(S, VT_LOCAL, c);
+ vpush_helper_func(TOK_memset);
+ vseti(VT_LOCAL, c);
#ifdef TCC_TARGET_ARM
- vpushs(S, size);
- vpushi(S, 0);
+ vpushs(size);
+ vpushi(0);
#else
- vpushi(S, 0);
- vpushs(S, size);
+ vpushi(0);
+ vpushs(size);
#endif
- gfunc_call(S, 3);
+ gfunc_call(3);
}
}
@@ -7685,13 +7777,13 @@ static void decl_design_delrels(Section *sec, int c, int size)
}
}
-static void decl_design_flex(TCCState* S, init_params *p, Sym *ref, int index)
+static void decl_design_flex(init_params *p, Sym *ref, int index)
{
if (ref == p->flex_array_ref) {
if (index >= ref->c)
ref->c = index + 1;
} else if (ref->c < 0)
- tcc_error(S, "flexible array has zero size in this context");
+ tcc_error("flexible array has zero size in this context");
}
/* t is the array or struct type. c is the array or struct
@@ -7700,7 +7792,7 @@ static void decl_design_flex(TCCState* S, init_params *p, Sym *ref, int index)
index. 'flags' is as in decl_initializer.
'al' contains the already initialized length of the
current container (starting at c). This returns the new length of that. */
-static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned long c,
+static int decl_designator(init_params *p, CType *type, unsigned long c,
Sym **cur_field, int flags, int al)
{
Sym *s, *f;
@@ -7713,29 +7805,29 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
if (flags & DIF_HAVE_ELEM)
goto no_designator;
- if (gnu_ext && S->tccpp_tok >= TOK_UIDENT) {
- l = S->tccpp_tok, next(S);
- if (S->tccpp_tok == ':')
+ if (gnu_ext && tok >= TOK_UIDENT) {
+ l = tok, next();
+ if (tok == ':')
goto struct_field;
- unget_tok(S, l);
+ unget_tok(l);
}
/* NOTE: we only support ranges for last designator */
- while (nb_elems == 1 && (S->tccpp_tok == '[' || S->tccpp_tok == '.')) {
- if (S->tccpp_tok == '[') {
+ while (nb_elems == 1 && (tok == '[' || tok == '.')) {
+ if (tok == '[') {
if (!(type->t & VT_ARRAY))
- expect(S, "array type");
- next(S);
- index = index_last = expr_const(S);
- if (S->tccpp_tok == TOK_DOTS && gnu_ext) {
- next(S);
- index_last = expr_const(S);
+ expect("array type");
+ next();
+ index = index_last = expr_const();
+ if (tok == TOK_DOTS && gnu_ext) {
+ next();
+ index_last = expr_const();
}
- skip(S, ']');
+ skip(']');
s = type->ref;
- decl_design_flex(S, p, s, index_last);
+ decl_design_flex(p, s, index_last);
if (index < 0 || index_last >= s->c || index_last < index)
- tcc_error(S, "index exceeds array bounds or range is empty");
+ tcc_error("index exceeds array bounds or range is empty");
if (cur_field)
(*cur_field)->c = index_last;
type = pointed_type(type);
@@ -7744,16 +7836,16 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
nb_elems = index_last - index + 1;
} else {
int cumofs;
- next(S);
- l = S->tccpp_tok;
+ next();
+ l = tok;
struct_field:
- next(S);
+ next();
if ((type->t & VT_BTYPE) != VT_STRUCT)
- expect(S, "struct/union type");
+ expect("struct/union type");
cumofs = 0;
f = find_field(type, l, &cumofs);
if (!f)
- expect(S, "field");
+ expect("field");
if (cur_field)
*cur_field = f;
type = &f->type;
@@ -7762,19 +7854,19 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
cur_field = NULL;
}
if (!cur_field) {
- if (S->tccpp_tok == '=') {
- next(S);
+ if (tok == '=') {
+ next();
} else if (!gnu_ext) {
- expect(S, "=");
+ expect("=");
}
} else {
no_designator:
if (type->t & VT_ARRAY) {
index = (*cur_field)->c;
s = type->ref;
- decl_design_flex(S, p, s, index);
+ decl_design_flex(p, s, index);
if (index >= s->c)
- tcc_error(S, "too many initializers");
+ tcc_error("too many initializers");
type = pointed_type(type);
elem_size = type_size(type, &align);
c += index * elem_size;
@@ -7783,7 +7875,7 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
while (f && (f->v & SYM_FIRST_ANOM) && (f->type.t & VT_BITFIELD))
*cur_field = f = f->next;
if (!f)
- tcc_error(S, "too many initializers");
+ tcc_error("too many initializers");
type = &f->type;
c += f->c;
}
@@ -7800,7 +7892,7 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
flags &= ~DIF_CLEAR; /* mark stack dirty too */
}
- decl_initializer(S, p, type, c, flags & ~DIF_FIRST);
+ decl_initializer(p, type, c, flags & ~DIF_FIRST);
if (!(flags & DIF_SIZE_ONLY) && nb_elems > 1) {
Sym aref = {0};
@@ -7813,14 +7905,14 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
type = &t1;
}
if (p->sec)
- vpush_ref(S, type, p->sec, c, elem_size);
+ vpush_ref(type, p->sec, c, elem_size);
else
- vset(S, type, VT_LOCAL|VT_LVAL, c);
+ vset(type, VT_LOCAL|VT_LVAL, c);
for (i = 1; i < nb_elems; i++) {
- vdup(S);
- init_putv(S, p, type, c + elem_size * i);
+ vdup();
+ init_putv(p, type, c + elem_size * i);
}
- vpop(S);
+ vpop();
}
c += nb_elems * elem_size;
@@ -7830,7 +7922,7 @@ static int decl_designator(TCCState* S, init_params *p, CType *type, unsigned lo
}
/* store a value or an expression directly in global data or in local array */
-static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
+static void init_putv(init_params *p, CType *type, unsigned long c)
{
int bt;
void *ptr;
@@ -7845,33 +7937,33 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
size = type_size(type, &align);
if (type->t & VT_BITFIELD)
size = (BIT_POS(type->t) + BIT_SIZE(type->t) + 7) / 8;
- init_assert(S, p, c + size);
+ init_assert(p, c + size);
if (sec) {
/* XXX: not portable */
/* XXX: generate error if incorrect relocation */
- gen_assign_cast(S, &dtype);
+ gen_assign_cast(&dtype);
bt = type->t & VT_BTYPE;
- if ((S->tccgen_vtop->r & VT_SYM)
+ if ((vtop->r & VT_SYM)
&& bt != VT_PTR
&& (bt != (PTR_SIZE == 8 ? VT_LLONG : VT_INT)
|| (type->t & VT_BITFIELD))
- && !((S->tccgen_vtop->r & VT_CONST) && S->tccgen_vtop->sym->v >= SYM_FIRST_ANOM)
+ && !((vtop->r & VT_CONST) && vtop->sym->v >= SYM_FIRST_ANOM)
)
- tcc_error(S, "initializer element is not computable at load time");
+ tcc_error("initializer element is not computable at load time");
if (NODATA_WANTED) {
- S->tccgen_vtop--;
+ vtop--;
return;
}
ptr = sec->data + c;
- val = S->tccgen_vtop->c.i;
+ val = vtop->c.i;
/* XXX: make code faster ? */
- if ((S->tccgen_vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) &&
- S->tccgen_vtop->sym->v >= SYM_FIRST_ANOM &&
+ if ((vtop->r & (VT_SYM|VT_CONST)) == (VT_SYM|VT_CONST) &&
+ vtop->sym->v >= SYM_FIRST_ANOM &&
/* XXX This rejects compound literals like
'(void *){ptr}'. The problem is that '&sym' is
represented the same way, which would be ruled out
@@ -7882,14 +7974,14 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
between '(void *){x}' and '&(void *){x}'. Ignore
pointer typed entities here. Hopefully no real code
will ever use compound literals with scalar type. */
- (S->tccgen_vtop->type.t & VT_BTYPE) != VT_PTR) {
+ (vtop->type.t & VT_BTYPE) != VT_PTR) {
/* These come from compound literals, memcpy stuff over. */
Section *ssec;
ElfSym *esym;
ElfW_Rel *rel;
- esym = elfsym(S, S->tccgen_vtop->sym);
- ssec = S->sections[esym->st_shndx];
- memmove (ptr, ssec->data + esym->st_value + (int)S->tccgen_vtop->c.i, size);
+ esym = elfsym(vtop->sym);
+ ssec = tcc_state->sections[esym->st_shndx];
+ memmove (ptr, ssec->data + esym->st_value + (int)vtop->c.i, size);
if (ssec->reloc) {
/* We need to copy over all memory contents, and that
includes relocations. Use the fact that relocs are
@@ -7919,8 +8011,8 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
if (type->t & VT_BITFIELD) {
int bit_pos, bit_size, bits, n;
unsigned char *p, v, m;
- bit_pos = BIT_POS(S->tccgen_vtop->type.t);
- bit_size = BIT_SIZE(S->tccgen_vtop->type.t);
+ bit_pos = BIT_POS(vtop->type.t);
+ bit_size = BIT_SIZE(vtop->type.t);
p = (unsigned char*)ptr + (bit_pos >> 3);
bit_pos &= 7, bits = 0;
while (bit_size) {
@@ -7959,24 +8051,24 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
In any case we avoid possibly random bytes 11 and 12.
*/
if (sizeof (long double) >= 10)
- memcpy(ptr, &S->tccgen_vtop->c.ld, 10);
+ memcpy(ptr, &vtop->c.ld, 10);
#ifdef __TINYC__
else if (sizeof (long double) == sizeof (double))
- __asm__("fldl %1\nfstpt %0\n" : "=m" (*ptr) : "m" (S->tccgen_vtop->c.ld));
+ __asm__("fldl %1\nfstpt %0\n" : "=m" (*ptr) : "m" (vtop->c.ld));
#endif
- else if (S->tccgen_vtop->c.ld == 0.0)
+ else if (vtop->c.ld == 0.0)
;
else
#endif
/* For other platforms it should work natively, but may not work
for cross compilers */
if (sizeof(long double) == LDOUBLE_SIZE)
- memcpy(ptr, &S->tccgen_vtop->c.ld, LDOUBLE_SIZE);
+ memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
else if (sizeof(double) == LDOUBLE_SIZE)
- memcpy(ptr, &S->tccgen_vtop->c.ld, LDOUBLE_SIZE);
+ memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
#ifndef TCC_CROSS_TEST
else
- tcc_error(S, "can't cross compile long double constants");
+ tcc_error("can't cross compile long double constants");
#endif
break;
@@ -7984,8 +8076,8 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
/* intptr_t may need a reloc too, see tcctest.c:relocation_test() */
case VT_LLONG:
case VT_PTR:
- if (S->tccgen_vtop->r & VT_SYM)
- greloca(S, sec, S->tccgen_vtop->sym, c, R_DATA_PTR, val);
+ if (vtop->r & VT_SYM)
+ greloca(sec, vtop->sym, c, R_DATA_PTR, val);
else
write64le(ptr, val);
break;
@@ -7998,8 +8090,8 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
break;
case VT_PTR:
case VT_INT:
- if (S->tccgen_vtop->r & VT_SYM)
- greloc(S, sec, S->tccgen_vtop->sym, c, R_DATA_PTR);
+ if (vtop->r & VT_SYM)
+ greloc(sec, vtop->sym, c, R_DATA_PTR);
write32le(ptr, val);
break;
#endif
@@ -8008,12 +8100,12 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
break;
}
}
- S->tccgen_vtop--;
+ vtop--;
} else {
- vset(S, &dtype, VT_LOCAL|VT_LVAL, c);
- vswap(S);
- vstore(S);
- vpop(S);
+ vset(&dtype, VT_LOCAL|VT_LVAL, c);
+ vswap();
+ vstore();
+ vpop();
}
}
@@ -8022,7 +8114,7 @@ static void init_putv(TCCState* S, init_params *p, CType *type, unsigned long c)
allocation. 'flags & DIF_FIRST' is true if array '{' must be read (multi
dimension implicit array init handling). 'flags & DIF_SIZE_ONLY' is true if
size only evaluation is wanted (only for arrays). */
-static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned long c, int flags)
+static void decl_initializer(init_params *p, CType *type, unsigned long c, int flags)
{
int len, n, no_oblock, i;
int size1, align1;
@@ -8031,16 +8123,16 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
CType *t1;
/* generate line number info */
- if (S->tccgen_debug_modes && !p->sec)
- tcc_debug_line(S), tcc_tcov_check_line (S, 1);
+ if (debug_modes && !p->sec)
+ tcc_debug_line(tcc_state), tcc_tcov_check_line (1);
- if (!(flags & DIF_HAVE_ELEM) && S->tccpp_tok != '{' &&
+ if (!(flags & DIF_HAVE_ELEM) && tok != '{' &&
/* In case of strings we have special handling for arrays, so
don't consume them as initializer value (which would commit them
to some anonymous symbol). */
- S->tccpp_tok != TOK_LSTR && S->tccpp_tok != TOK_STR &&
+ tok != TOK_LSTR && tok != TOK_STR &&
!(flags & DIF_SIZE_ONLY)) {
- parse_init_elem(S, !p->sec ? EXPR_ANY : EXPR_CONST);
+ parse_init_elem(!p->sec ? EXPR_ANY : EXPR_CONST);
flags |= DIF_HAVE_ELEM;
}
@@ -8049,14 +8141,14 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
/* Use i_c_parameter_t, to strip toplevel qualifiers.
The source type might have VT_CONSTANT set, which is
of course assignable to non-const elements. */
- is_compatible_unqualified_types(type, &S->tccgen_vtop->type)) {
+ is_compatible_unqualified_types(type, &vtop->type)) {
goto init_putv;
} else if (type->t & VT_ARRAY) {
no_oblock = 1;
- if (((flags & DIF_FIRST) && S->tccpp_tok != TOK_LSTR && S->tccpp_tok != TOK_STR) ||
- S->tccpp_tok == '{') {
- skip(S, '{');
+ if (((flags & DIF_FIRST) && tok != TOK_LSTR && tok != TOK_STR) ||
+ tok == '{') {
+ skip('{');
no_oblock = 0;
}
@@ -8067,51 +8159,51 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
/* only parse strings here if correct type (otherwise: handle
them as ((w)char *) expressions */
- if ((S->tccpp_tok == TOK_LSTR &&
+ if ((tok == TOK_LSTR &&
#ifdef TCC_TARGET_PE
(t1->t & VT_BTYPE) == VT_SHORT && (t1->t & VT_UNSIGNED)
#else
(t1->t & VT_BTYPE) == VT_INT
#endif
- ) || (S->tccpp_tok == TOK_STR && (t1->t & VT_BTYPE) == VT_BYTE)) {
+ ) || (tok == TOK_STR && (t1->t & VT_BTYPE) == VT_BYTE)) {
len = 0;
- cstr_reset(&S->tccgen_initstr);
- if (size1 != (S->tccpp_tok == TOK_STR ? 1 : sizeof(nwchar_t)))
- tcc_error(S, "unhandled string literal merging");
- while (S->tccpp_tok == TOK_STR || S->tccpp_tok == TOK_LSTR) {
- if (S->tccgen_initstr.size)
- S->tccgen_initstr.size -= size1;
- if (S->tccpp_tok == TOK_STR)
- len += S->tccpp_tokc.str.size;
+ cstr_reset(&initstr);
+ if (size1 != (tok == TOK_STR ? 1 : sizeof(nwchar_t)))
+ tcc_error("unhandled string literal merging");
+ while (tok == TOK_STR || tok == TOK_LSTR) {
+ if (initstr.size)
+ initstr.size -= size1;
+ if (tok == TOK_STR)
+ len += tokc.str.size;
else
- len += S->tccpp_tokc.str.size / sizeof(nwchar_t);
+ len += tokc.str.size / sizeof(nwchar_t);
len--;
- cstr_cat(S, &S->tccgen_initstr, S->tccpp_tokc.str.data, S->tccpp_tokc.str.size);
- next(S);
+ cstr_cat(&initstr, tokc.str.data, tokc.str.size);
+ next();
}
- if (S->tccpp_tok != ')' && S->tccpp_tok != '}' && S->tccpp_tok != ',' && S->tccpp_tok != ';'
- && S->tccpp_tok != TOK_EOF) {
+ if (tok != ')' && tok != '}' && tok != ',' && tok != ';'
+ && tok != TOK_EOF) {
/* Not a lone literal but part of a bigger expression. */
- unget_tok(S, size1 == 1 ? TOK_STR : TOK_LSTR);
- S->tccpp_tokc.str.size = S->tccgen_initstr.size;
- S->tccpp_tokc.str.data = S->tccgen_initstr.data;
+ unget_tok(size1 == 1 ? TOK_STR : TOK_LSTR);
+ tokc.str.size = initstr.size;
+ tokc.str.data = initstr.data;
goto do_init_array;
}
- decl_design_flex(S, p, s, len);
+ decl_design_flex(p, s, len);
if (!(flags & DIF_SIZE_ONLY)) {
int nb = n;
if (len < nb)
nb = len;
if (len > nb)
- tcc_warning(S, "initializer-string for array is too long");
+ tcc_warning("initializer-string for array is too long");
/* in order to go faster for common case (char
string in global variable, we handle it
specifically */
if (p->sec && size1 == 1) {
- init_assert(S, p, c + nb);
+ init_assert(p, c + nb);
if (!NODATA_WANTED)
- memcpy(p->sec->data + c, S->tccgen_initstr.data, nb);
+ memcpy(p->sec->data + c, initstr.data, nb);
} else {
for(i=0;i<n;i++) {
if (i >= nb) {
@@ -8120,16 +8212,16 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
if (flags & DIF_CLEAR)
break;
if (n - i >= 4) {
- init_putz(S, p, c + i * size1, (n - i) * size1);
+ init_putz(p, c + i * size1, (n - i) * size1);
break;
}
- S->tccpp_ch = 0;
+ ch = 0;
} else if (size1 == 1)
- S->tccpp_ch = ((unsigned char *)S->tccgen_initstr.data)[i];
+ ch = ((unsigned char *)initstr.data)[i];
else
- S->tccpp_ch = ((nwchar_t *)S->tccgen_initstr.data)[i];
- vpushi(S, S->tccpp_ch);
- init_putv(S, p, t1, c + i * size1);
+ ch = ((nwchar_t *)initstr.data)[i];
+ vpushi(ch);
+ init_putv(p, t1, c + i * size1);
}
}
}
@@ -8142,13 +8234,13 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
do_init_list:
/* zero memory once in advance */
if (!(flags & (DIF_CLEAR | DIF_SIZE_ONLY))) {
- init_putz(S, p, c, n*size1);
+ init_putz(p, c, n*size1);
flags |= DIF_CLEAR;
}
len = 0;
- while (S->tccpp_tok != '}' || (flags & DIF_HAVE_ELEM)) {
- len = decl_designator(S, p, type, c, &f, flags, len);
+ while (tok != '}' || (flags & DIF_HAVE_ELEM)) {
+ len = decl_designator(p, type, c, &f, flags, len);
flags &= ~DIF_HAVE_ELEM;
if (type->t & VT_ARRAY) {
++indexsym.c;
@@ -8166,17 +8258,17 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
break;
}
- if (S->tccpp_tok == '}')
+ if (tok == '}')
break;
- skip(S, ',');
+ skip(',');
}
}
if (!no_oblock)
- skip(S, '}');
+ skip('}');
} else if ((type->t & VT_BTYPE) == VT_STRUCT) {
no_oblock = 1;
- if ((flags & DIF_FIRST) || S->tccpp_tok == '{') {
- skip(S, '{');
+ if ((flags & DIF_FIRST) || tok == '{') {
+ skip('{');
no_oblock = 0;
}
s = type->ref;
@@ -8184,12 +8276,12 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
n = s->c;
size1 = 1;
goto do_init_list;
- } else if (S->tccpp_tok == '{') {
+ } else if (tok == '{') {
if (flags & DIF_HAVE_ELEM)
- skip(S, ';');
- next(S);
- decl_initializer(S, p, type, c, flags & ~DIF_HAVE_ELEM);
- skip(S, '}');
+ skip(';');
+ next();
+ decl_initializer(p, type, c, flags & ~DIF_HAVE_ELEM);
+ skip('}');
} else if ((flags & DIF_SIZE_ONLY)) {
/* If we supported only ISO C we wouldn't have to accept calling
this on anything than an array if DIF_SIZE_ONLY (and even then
@@ -8198,25 +8290,25 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
But GNU C supports it, so we need to recurse even into
subfields of structs and arrays when DIF_SIZE_ONLY is set. */
/* just skip expression */
- skip_or_save_block(S, NULL);
+ skip_or_save_block(NULL);
} else {
if (!(flags & DIF_HAVE_ELEM)) {
/* This should happen only when we haven't parsed
the init element above for fear of committing a
string constant to memory too early. */
- if (S->tccpp_tok != TOK_STR && S->tccpp_tok != TOK_LSTR)
- expect(S, "string constant");
- parse_init_elem(S, !p->sec ? EXPR_ANY : EXPR_CONST);
+ if (tok != TOK_STR && tok != TOK_LSTR)
+ expect("string constant");
+ parse_init_elem(!p->sec ? EXPR_ANY : EXPR_CONST);
}
init_putv:
if (!p->sec && (flags & DIF_CLEAR) /* container was already zero'd */
- && (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST
- && S->tccgen_vtop->c.i == 0
+ && (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST
+ && vtop->c.i == 0
&& btype_size(type->t & VT_BTYPE) /* not for fp constants */
)
- vpop(S);
+ vpop();
else
- init_putv(S, p, type, c);
+ init_putv(p, type, c);
}
}
@@ -8227,7 +8319,7 @@ static void decl_initializer(TCCState* S, init_params *p, CType *type, unsigned
are parsed. If 'v' is zero, then a reference to the new object
is put in the value stack. If 'has_init' is 2, a special parsing
is done to handle string constants. */
-static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, int r,
+static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
int has_init, int v, int scope)
{
int size, align, addr;
@@ -8236,15 +8328,15 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
Section *sec;
Sym *flexible_array;
Sym *sym;
- int saved_nocode_wanted = S->tccgen_nocode_wanted;
+ int saved_nocode_wanted = nocode_wanted;
#ifdef CONFIG_TCC_BCHECK
- int bcheck = S->do_bounds_check && !NODATA_WANTED;
+ int bcheck = tcc_state->do_bounds_check && !NODATA_WANTED;
#endif
init_params p = {0};
/* Always allocate static or global variables */
if (v && (r & VT_VALMASK) == VT_CONST)
- S->tccgen_nocode_wanted |= 0x80000000;
+ nocode_wanted |= 0x80000000;
flexible_array = NULL;
size = type_size(type, &align);
@@ -8257,7 +8349,7 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
(like in 'typedef int arr[]; arr x = {1};') then we will
overwrite the unknown size by the real one for this decl.
We need to unshare the ref symbol holding that size. */
- type->ref = sym_push(S, SYM_FIELD, &type->ref->type, 0, type->ref->c);
+ type->ref = sym_push(SYM_FIELD, &type->ref->type, 0, type->ref->c);
p.flex_array_ref = type->ref;
} else if (has_init && (type->t & VT_BTYPE) == VT_STRUCT) {
@@ -8276,32 +8368,32 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
if (size < 0) {
/* If unknown size, do a dry-run 1st pass */
if (!has_init)
- tcc_error(S, "unknown type size");
+ tcc_error("unknown type size");
if (has_init == 2) {
/* only get strings */
- init_str = tok_str_alloc(S);
- while (S->tccpp_tok == TOK_STR || S->tccpp_tok == TOK_LSTR) {
- tok_str_add_tok(S, init_str);
- next(S);
+ init_str = tok_str_alloc();
+ while (tok == TOK_STR || tok == TOK_LSTR) {
+ tok_str_add_tok(init_str);
+ next();
}
- tok_str_add(S, init_str, -1);
- tok_str_add(S, init_str, 0);
+ tok_str_add(init_str, -1);
+ tok_str_add(init_str, 0);
} else
- skip_or_save_block(S, &init_str);
- unget_tok(S, 0);
+ skip_or_save_block(&init_str);
+ unget_tok(0);
/* compute size */
- begin_macro(S, init_str, 1);
- next(S);
- decl_initializer(S, &p, type, 0, DIF_FIRST | DIF_SIZE_ONLY);
+ begin_macro(init_str, 1);
+ next();
+ decl_initializer(&p, type, 0, DIF_FIRST | DIF_SIZE_ONLY);
/* prepare second initializer parsing */
- S->tccpp_macro_ptr = init_str->str;
- next(S);
+ macro_ptr = init_str->str;
+ next();
/* if still unknown size, error */
size = type_size(type, &align);
if (size < 0)
- tcc_error(S, "unknown type size");
+ tcc_error("unknown type size");
/* If there's a flex member and it was used in the initializer
adjust size. */
@@ -8327,47 +8419,47 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
#ifdef CONFIG_TCC_BCHECK
if (bcheck && v) {
/* add padding between stack variables for bound checking */
- S->tccgen_loc -= align;
+ loc -= align;
}
#endif
- S->tccgen_loc = (S->tccgen_loc - size) & -align;
- addr = S->tccgen_loc;
+ loc = (loc - size) & -align;
+ addr = loc;
p.local_offset = addr + size;
#ifdef CONFIG_TCC_BCHECK
if (bcheck && v) {
/* add padding between stack variables for bound checking */
- S->tccgen_loc -= align;
+ loc -= align;
}
#endif
if (v) {
/* local variable */
#ifdef CONFIG_TCC_ASM
if (ad->asm_label) {
- int reg = asm_parse_regvar(S, ad->asm_label);
+ int reg = asm_parse_regvar(ad->asm_label);
if (reg >= 0)
r = (r & ~VT_VALMASK) | reg;
}
#endif
- sym = sym_push(S, v, type, r, addr);
+ sym = sym_push(v, type, r, addr);
if (ad->cleanup_func) {
- Sym *cls = sym_push2(S, &S->tccgen_all_cleanups,
- SYM_FIELD | ++S->tccgen_cur_scope->cl.n, 0, 0);
+ Sym *cls = sym_push2(&all_cleanups,
+ SYM_FIELD | ++cur_scope->cl.n, 0, 0);
cls->prev_tok = sym;
cls->next = ad->cleanup_func;
- cls->ncl = S->tccgen_cur_scope->cl.s;
- S->tccgen_cur_scope->cl.s = cls;
+ cls->ncl = cur_scope->cl.s;
+ cur_scope->cl.s = cls;
}
sym->a = ad->a;
} else {
/* push local reference */
- vset(S, type, r, addr);
+ vset(type, r, addr);
}
} else {
sym = NULL;
if (v && scope == VT_CONST) {
/* see if the symbol was already defined */
- sym = sym_find(S, v);
+ sym = sym_find(v);
if (sym) {
if (p.flex_array_ref && (sym->type.t & type->t & VT_ARRAY)
&& sym->type.ref->c > type->ref->c) {
@@ -8377,9 +8469,9 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
type->ref->c = sym->type.ref->c;
size = type_size(type, &align);
}
- patch_storage(S, sym, ad, type);
+ patch_storage(sym, ad, type);
/* we accept several definitions of the same global variable. */
- if (!has_init && sym->c && elfsym(S, sym)->st_shndx != SHN_UNDEF)
+ if (!has_init && sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)
goto no_alloc;
}
}
@@ -8395,17 +8487,17 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
} else if (has_init) {
sec = data_section;
/*if (tcc_state->g_debug & 4)
- tcc_warning(S, "rw data: %s", get_tok_str(v, 0));*/
- } else if (S->nocommon)
+ tcc_warning("rw data: %s", get_tok_str(v, 0));*/
+ } else if (tcc_state->nocommon)
sec = bss_section;
}
if (sec) {
- addr = section_add(S, sec, size, align);
+ addr = section_add(sec, size, align);
#ifdef CONFIG_TCC_BCHECK
/* add padding if bound check */
if (bcheck)
- section_add(S, sec, 1, 1);
+ section_add(sec, 1, 1);
#endif
} else {
addr = align; /* SHN_COMMON is special, symbol value is align */
@@ -8414,16 +8506,16 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
if (v) {
if (!sym) {
- sym = sym_push(S, v, type, r | VT_SYM, 0);
- patch_storage(S, sym, ad, NULL);
+ sym = sym_push(v, type, r | VT_SYM, 0);
+ patch_storage(sym, ad, NULL);
}
/* update symbol definition */
- put_extern_sym(S, sym, sec, addr, size);
+ put_extern_sym(sym, sec, addr, size);
} else {
/* push global reference */
- vpush_ref(S, type, sec, addr, size);
- sym = S->tccgen_vtop->sym;
- S->tccgen_vtop->r |= r;
+ vpush_ref(type, sec, addr, size);
+ sym = vtop->sym;
+ vtop->r |= r;
}
#ifdef CONFIG_TCC_BCHECK
@@ -8432,9 +8524,9 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
if (bcheck) {
addr_t *bounds_ptr;
- greloca(S, bounds_section, sym, bounds_section->data_offset, R_DATA_PTR, 0);
+ greloca(bounds_section, sym, bounds_section->data_offset, R_DATA_PTR, 0);
/* then add global bound info */
- bounds_ptr = section_ptr_add(S, bounds_section, 2 * sizeof(addr_t));
+ bounds_ptr = section_ptr_add(bounds_section, 2 * sizeof(addr_t));
bounds_ptr[0] = 0; /* relocated */
bounds_ptr[1] = size;
}
@@ -8448,28 +8540,28 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
goto no_alloc;
/* save before-VLA stack pointer if needed */
- if (S->tccgen_cur_scope->vla.num == 0) {
- if (S->tccgen_cur_scope->prev && S->tccgen_cur_scope->prev->vla.num) {
- S->tccgen_cur_scope->vla.locorig = S->tccgen_cur_scope->prev->vla.loc;
+ if (cur_scope->vla.num == 0) {
+ if (cur_scope->prev && cur_scope->prev->vla.num) {
+ cur_scope->vla.locorig = cur_scope->prev->vla.loc;
} else {
- gen_vla_sp_save(S, S->tccgen_loc -= PTR_SIZE);
- S->tccgen_cur_scope->vla.locorig = S->tccgen_loc;
+ gen_vla_sp_save(loc -= PTR_SIZE);
+ cur_scope->vla.locorig = loc;
}
}
- vla_runtime_type_size(S, type, &a);
- gen_vla_alloc(S, type, a);
+ vla_runtime_type_size(type, &a);
+ gen_vla_alloc(type, a);
#if defined TCC_TARGET_PE && defined TCC_TARGET_X86_64
/* on _WIN64, because of the function args scratch area, the
result of alloca differs from RSP and is returned in RAX. */
- gen_vla_result(S, addr), addr = (S->tccgen_loc -= PTR_SIZE);
+ gen_vla_result(addr), addr = (loc -= PTR_SIZE);
#endif
- gen_vla_sp_save(S, addr);
- S->tccgen_cur_scope->vla.loc = addr;
- S->tccgen_cur_scope->vla.num++;
+ gen_vla_sp_save(addr);
+ cur_scope->vla.loc = addr;
+ cur_scope->vla.num++;
} else if (has_init) {
p.sec = sec;
- decl_initializer(S, &p, type, addr, DIF_FIRST);
+ decl_initializer(&p, type, addr, DIF_FIRST);
/* patch flexible array member size back to -1, */
/* for possible subsequent similar declarations */
if (flexible_array)
@@ -8479,119 +8571,119 @@ static void decl_initializer_alloc(TCCState* S, CType *type, AttributeDef *ad, i
no_alloc:
/* restore parse state if needed */
if (init_str) {
- end_macro(S);
- next(S);
+ end_macro();
+ next();
}
- S->tccgen_nocode_wanted = saved_nocode_wanted;
+ nocode_wanted = saved_nocode_wanted;
}
/* parse a function defined by symbol 'sym' and generate its code in
'cur_text_section' */
-static void gen_function(TCCState* S, Sym *sym)
+static void gen_function(Sym *sym)
{
- scope_t f = { 0 };
- S->tccgen_cur_scope = S->tccgen_root_scope = &f;
- S->tccgen_nocode_wanted = 0;
- S->tccgen_ind = cur_text_section->data_offset;
+ struct scope f = { 0 };
+ cur_scope = root_scope = &f;
+ nocode_wanted = 0;
+ ind = cur_text_section->data_offset;
if (sym->a.aligned) {
- size_t newoff = section_add(S, cur_text_section, 0,
+ size_t newoff = section_add(cur_text_section, 0,
1 << (sym->a.aligned - 1));
- gen_fill_nops(S, newoff - S->tccgen_ind);
+ gen_fill_nops(newoff - ind);
}
/* NOTE: we patch the symbol size later */
- put_extern_sym(S, sym, cur_text_section, S->tccgen_ind, 0);
+ put_extern_sym(sym, cur_text_section, ind, 0);
if (sym->type.ref->f.func_ctor)
- add_array (S, ".init_array", sym->c);
+ add_array (tcc_state, ".init_array", sym->c);
if (sym->type.ref->f.func_dtor)
- add_array (S, ".fini_array", sym->c);
+ add_array (tcc_state, ".fini_array", sym->c);
- S->tccgen_funcname = get_tok_str(S, sym->v, NULL);
- S->tccgen_func_ind = S->tccgen_ind;
- S->tccgen_func_vt = sym->type.ref->type;
- S->tccgen_func_var = sym->type.ref->f.func_type == FUNC_ELLIPSIS;
+ funcname = get_tok_str(sym->v, NULL);
+ func_ind = ind;
+ func_vt = sym->type.ref->type;
+ func_var = sym->type.ref->f.func_type == FUNC_ELLIPSIS;
/* put debug symbol */
- tcc_debug_funcstart(S, sym);
+ tcc_debug_funcstart(tcc_state, sym);
/* push a dummy symbol to enable local sym storage */
- sym_push2(S, &S->tccgen_local_stack, SYM_FIELD, 0, 0);
- S->tccgen_local_scope = 1; /* for function parameters */
- gfunc_prolog(S, sym);
- S->tccgen_local_scope = 0;
- S->tccgen_rsym = 0;
- clear_temp_local_var_list(S);
- block(S, 0);
- gsym(S, S->tccgen_rsym);
- S->tccgen_nocode_wanted = 0;
+ sym_push2(&local_stack, SYM_FIELD, 0, 0);
+ local_scope = 1; /* for function parameters */
+ gfunc_prolog(sym);
+ local_scope = 0;
+ rsym = 0;
+ clear_temp_local_var_list();
+ block(0);
+ gsym(rsym);
+ nocode_wanted = 0;
/* reset local stack */
- pop_local_syms(S, NULL, 0);
- gfunc_epilog(S);
- cur_text_section->data_offset = S->tccgen_ind;
- S->tccgen_local_scope = 0;
- label_pop(S, &S->tccgen_global_label_stack, NULL, 0);
- sym_pop(S, &S->tccgen_all_cleanups, NULL, 0);
+ pop_local_syms(NULL, 0);
+ gfunc_epilog();
+ cur_text_section->data_offset = ind;
+ local_scope = 0;
+ label_pop(&global_label_stack, NULL, 0);
+ sym_pop(&all_cleanups, NULL, 0);
/* patch symbol size */
- elfsym(S, sym)->st_size = S->tccgen_ind - S->tccgen_func_ind;
+ elfsym(sym)->st_size = ind - func_ind;
/* end of function */
- tcc_debug_funcend(S, S->tccgen_ind - S->tccgen_func_ind);
+ tcc_debug_funcend(tcc_state, ind - func_ind);
/* It's better to crash than to generate wrong code */
cur_text_section = NULL;
- S->tccgen_funcname = ""; /* for safety */
- S->tccgen_func_vt.t = VT_VOID; /* for safety */
- S->tccgen_func_var = 0; /* for safety */
- S->tccgen_ind = 0; /* for safety */
- S->tccgen_nocode_wanted = 0x80000000;
- check_vstack(S);
+ funcname = ""; /* for safety */
+ func_vt.t = VT_VOID; /* for safety */
+ func_var = 0; /* for safety */
+ ind = 0; /* for safety */
+ nocode_wanted = 0x80000000;
+ check_vstack();
/* do this after funcend debug info */
- next(S);
+ next();
}
-static void gen_inline_functions(TCCState *S)
+static void gen_inline_functions(TCCState *s)
{
Sym *sym;
int inline_generated, i;
struct InlineFunc *fn;
- tcc_open_bf(S, ":inline:", 0);
+ tcc_open_bf(s, ":inline:", 0);
/* iterate while inline function are referenced */
do {
inline_generated = 0;
- for (i = 0; i < S->nb_inline_fns; ++i) {
- fn = S->inline_fns[i];
+ for (i = 0; i < s->nb_inline_fns; ++i) {
+ fn = s->inline_fns[i];
sym = fn->sym;
if (sym && (sym->c || !(sym->type.t & VT_INLINE))) {
/* the function was used or forced (and then not internal):
generate its code and convert it to a normal function */
fn->sym = NULL;
- tcc_debug_putfile(S, fn->filename);
- begin_macro(S, fn->func_str, 1);
- next(S);
+ tcc_debug_putfile(s, fn->filename);
+ begin_macro(fn->func_str, 1);
+ next();
cur_text_section = text_section;
- gen_function(S, sym);
- end_macro(S);
+ gen_function(sym);
+ end_macro();
inline_generated = 1;
}
}
} while (inline_generated);
- tcc_close(S);
+ tcc_close();
}
-static void free_inline_functions(TCCState *S)
+static void free_inline_functions(TCCState *s)
{
int i;
/* free tokens of unused inline functions */
- for (i = 0; i < S->nb_inline_fns; ++i) {
- struct InlineFunc *fn = S->inline_fns[i];
+ for (i = 0; i < s->nb_inline_fns; ++i) {
+ struct InlineFunc *fn = s->inline_fns[i];
if (fn->sym)
- tok_str_free(S, fn->func_str);
+ tok_str_free(fn->func_str);
}
- dynarray_reset(S, &S->inline_fns, &S->nb_inline_fns);
+ dynarray_reset(&s->inline_fns, &s->nb_inline_fns);
}
/* 'l' is VT_LOCAL or VT_CONST to define default storage type, or VT_CMP
if parsing old style parameter decl list (and FUNC_SYM is set then) */
-static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
+static int decl0(int l, int is_for_loop_init, Sym *func_sym)
{
int v, has_init, r, oldint;
CType type, btype;
@@ -8599,70 +8691,70 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
AttributeDef ad, adbase;
while (1) {
- if (S->tccpp_tok == TOK_STATIC_ASSERT) {
+ if (tok == TOK_STATIC_ASSERT) {
CString error_str;
int c;
- next(S);
- skip(S, '(');
- c = expr_const(S);
+ next();
+ skip('(');
+ c = expr_const();
- if (S->tccpp_tok == ')') {
+ if (tok == ')') {
if (!c)
- tcc_error(S, "_Static_assert fail");
- next(S);
+ tcc_error("_Static_assert fail");
+ next();
goto static_assert_out;
}
- skip(S, ',');
- parse_mult_str(S, &error_str, "string constant");
+ skip(',');
+ parse_mult_str(&error_str, "string constant");
if (c == 0)
- tcc_error(S, "%s", (char *)error_str.data);
- cstr_free(S, &error_str);
- skip(S, ')');
+ tcc_error("%s", (char *)error_str.data);
+ cstr_free(&error_str);
+ skip(')');
static_assert_out:
- skip(S, ';');
+ skip(';');
continue;
}
oldint = 0;
- if (!parse_btype(S, &btype, &adbase)) {
+ if (!parse_btype(&btype, &adbase)) {
if (is_for_loop_init)
return 0;
/* skip redundant ';' if not in old parameter decl scope */
- if (S->tccpp_tok == ';' && l != VT_CMP) {
- next(S);
+ if (tok == ';' && l != VT_CMP) {
+ next();
continue;
}
if (l != VT_CONST)
break;
- if (S->tccpp_tok == TOK_ASM1 || S->tccpp_tok == TOK_ASM2 || S->tccpp_tok == TOK_ASM3) {
+ if (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3) {
/* global asm block */
- asm_global_instr(S);
+ asm_global_instr();
continue;
}
- if (S->tccpp_tok >= TOK_UIDENT) {
+ if (tok >= TOK_UIDENT) {
/* special test for old K&R protos without explicit int
type. Only accepted when defining global data */
btype.t = VT_INT;
oldint = 1;
} else {
- if (S->tccpp_tok != TOK_EOF)
- expect(S, "declaration");
+ if (tok != TOK_EOF)
+ expect("declaration");
break;
}
}
- if (S->tccpp_tok == ';') {
+ if (tok == ';') {
if ((btype.t & VT_BTYPE) == VT_STRUCT) {
v = btype.ref->v;
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) >= SYM_FIRST_ANOM)
- tcc_warning(S, "unnamed struct/union that defines no instances");
- next(S);
+ tcc_warning("unnamed struct/union that defines no instances");
+ next();
continue;
}
if (IS_ENUM(btype.t)) {
- next(S);
+ next();
continue;
}
}
@@ -8670,22 +8762,22 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
while (1) { /* iterate thru each declaration */
type = btype;
ad = adbase;
- type_decl(S, &type, &ad, &v, TYPE_DIRECT);
+ type_decl(&type, &ad, &v, TYPE_DIRECT);
#if 0
{
char buf[500];
- type_to_str(S, buf, sizeof(buf), &type, get_tok_str(S, v, NULL));
+ type_to_str(buf, sizeof(buf), &type, get_tok_str(v, NULL));
printf("type = '%s'\n", buf);
}
#endif
if ((type.t & VT_BTYPE) == VT_FUNC) {
if ((type.t & VT_STATIC) && (l == VT_LOCAL))
- tcc_error(S, "function without file scope cannot be static");
+ tcc_error("function without file scope cannot be static");
/* if old style function prototype, we accept a
declaration list */
sym = type.ref;
if (sym->f.func_type == FUNC_OLD && l == VT_CONST)
- decl0(S, VT_CMP, 0, sym);
+ decl0(VT_CMP, 0, sym);
#ifdef TCC_TARGET_MACHO
if (sym->f.func_alwinl
&& ((type.t & (VT_EXTERN | VT_INLINE))
@@ -8703,27 +8795,27 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
type.t &= ~VT_INLINE;
} else if (oldint) {
- tcc_warning(S, "type defaults to int");
+ tcc_warning("type defaults to int");
}
- if (gnu_ext && (S->tccpp_tok == TOK_ASM1 || S->tccpp_tok == TOK_ASM2 || S->tccpp_tok == TOK_ASM3)) {
- ad.asm_label = asm_label_instr(S);
+ if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
+ ad.asm_label = asm_label_instr();
/* parse one last attribute list, after asm label */
- parse_attribute(S, &ad);
+ parse_attribute(&ad);
#if 0
/* gcc does not allow __asm__("label") with function definition,
but why not ... */
- if (Stccpp_tok == '{')
- expect(S, ";");
+ if (tok == '{')
+ expect(";");
#endif
}
#ifdef TCC_TARGET_PE
if (ad.a.dllimport || ad.a.dllexport) {
if (type.t & VT_STATIC)
- tcc_error(S, "cannot have dll linkage with static");
+ tcc_error("cannot have dll linkage with static");
if (type.t & VT_TYPEDEF) {
- tcc_warning(S, "'%s' attribute ignored for typedef",
+ tcc_warning("'%s' attribute ignored for typedef",
ad.a.dllimport ? (ad.a.dllimport = 0, "dllimport") :
(ad.a.dllexport = 0, "dllexport"));
} else if (ad.a.dllimport) {
@@ -8734,20 +8826,20 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
}
}
#endif
- if (S->tccpp_tok == '{') {
+ if (tok == '{') {
if (l != VT_CONST)
- tcc_error(S, "cannot use local functions");
+ tcc_error("cannot use local functions");
if ((type.t & VT_BTYPE) != VT_FUNC)
- expect(S, "function definition");
+ expect("function definition");
/* reject abstract declarators in function definition
make old style params without decl have int type */
sym = type.ref;
while ((sym = sym->next) != NULL) {
if (!(sym->v & ~SYM_FIELD))
- expect(S, "identifier");
+ expect("identifier");
if (sym->type.t == VT_VOID)
- sym->type = S->tccgen_int_type;
+ sym->type = int_type;
}
/* apply post-declaraton attributes */
@@ -8755,25 +8847,25 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
/* put function symbol */
type.t &= ~VT_EXTERN;
- sym = external_sym(S, v, &type, 0, &ad);
+ sym = external_sym(v, &type, 0, &ad);
/* static inline functions are just recorded as a kind
of macro. Their code will be emitted at the end of
the compilation unit only if they are used */
if (sym->type.t & VT_INLINE) {
struct InlineFunc *fn;
- fn = tcc_malloc(S, sizeof *fn + strlen(S->tccpp_file->filename));
- strcpy(fn->filename, S->tccpp_file->filename);
+ fn = tcc_malloc(sizeof *fn + strlen(file->filename));
+ strcpy(fn->filename, file->filename);
fn->sym = sym;
- skip_or_save_block(S, &fn->func_str);
- dynarray_add(S, &S->inline_fns,
- &S->nb_inline_fns, fn);
+ skip_or_save_block(&fn->func_str);
+ dynarray_add(&tcc_state->inline_fns,
+ &tcc_state->nb_inline_fns, fn);
} else {
/* compute text section */
cur_text_section = ad.section;
if (!cur_text_section)
cur_text_section = text_section;
- gen_function(S, sym);
+ gen_function(sym);
}
break;
} else {
@@ -8782,37 +8874,37 @@ static int decl0(TCCState* S, int l, int is_for_loop_init, Sym *func_sym)
for (sym = func_sym->next; sym; sym = sym->next)
if ((sym->v & ~SYM_FIELD) == v)
goto found;
- tcc_error(S, "declaration for parameter '%s' but no such parameter",
- get_tok_str(S, v, NULL));
+ tcc_error("declaration for parameter '%s' but no such parameter",
+ get_tok_str(v, NULL));
found:
if (type.t & VT_STORAGE) /* 'register' is okay */
- tcc_error(S, "storage class specified for '%s'",
- get_tok_str(S, v, NULL));
+ tcc_error("storage class specified for '%s'",
+ get_tok_str(v, NULL));
if (sym->type.t != VT_VOID)
- tcc_error(S, "redefinition of parameter '%s'",
- get_tok_str(S, v, NULL));
- convert_parameter_type(S, &type);
+ tcc_error("redefinition of parameter '%s'",
+ get_tok_str(v, NULL));
+ convert_parameter_type(&type);
sym->type = type;
} else if (type.t & VT_TYPEDEF) {
/* save typedefed type */
/* XXX: test storage specifiers ? */
- sym = sym_find(S, v);
- if (sym && sym->sym_scope == S->tccgen_local_scope) {
+ sym = sym_find(v);
+ if (sym && sym->sym_scope == local_scope) {
if (!is_compatible_types(&sym->type, &type)
|| !(sym->type.t & VT_TYPEDEF))
- tcc_error(S, "incompatible redefinition of '%s'",
- get_tok_str(S, v, NULL));
+ tcc_error("incompatible redefinition of '%s'",
+ get_tok_str(v, NULL));
sym->type = type;
} else {
- sym = sym_push(S, v, &type, 0, 0);
+ sym = sym_push(v, &type, 0, 0);
}
sym->a = ad.a;
sym->f = ad.f;
- if (S->tccgen_debug_modes)
- tcc_debug_typedef (S, sym);
+ if (debug_modes)
+ tcc_debug_typedef (tcc_state, sym);
} else if ((type.t & VT_BTYPE) == VT_VOID
&& !(type.t & VT_EXTERN)) {
- tcc_error(S, "declaration of void object");
+ tcc_error("declaration of void object");
} else {
r = 0;
if ((type.t & VT_BTYPE) == VT_FUNC) {
@@ -8823,9 +8915,9 @@ found:
/* not lvalue if array */
r |= VT_LVAL;
}
- has_init = (S->tccpp_tok == '=');
+ has_init = (tok == '=');
if (has_init && (type.t & VT_VLA))
- tcc_error(S, "variable length array cannot be initialized");
+ tcc_error("variable length array cannot be initialized");
if (((type.t & VT_EXTERN) && (!has_init || l != VT_CONST))
|| (type.t & VT_BTYPE) == VT_FUNC
/* as with GCC, uninitialized global arrays with no size
@@ -8835,7 +8927,7 @@ found:
) {
/* external variable or function */
type.t |= VT_EXTERN;
- sym = external_sym(S, v, &type, r, &ad);
+ sym = external_sym(v, &type, r, &ad);
if (ad.alias_target) {
/* Aliases need to be emitted when their target
symbol is emitted, even if perhaps unreferenced.
@@ -8843,11 +8935,11 @@ found:
already defined, otherwise we would need
deferring to emit the aliases until the end of
the compile unit. */
- Sym *alias_target = sym_find(S, ad.alias_target);
- ElfSym *esym = elfsym(S, alias_target);
+ Sym *alias_target = sym_find(ad.alias_target);
+ ElfSym *esym = elfsym(alias_target);
if (!esym)
- tcc_error(S, "unsupported forward __alias__ attribute");
- put_extern_sym2(S, sym, esym->st_shndx,
+ tcc_error("unsupported forward __alias__ attribute");
+ put_extern_sym2(sym, esym->st_shndx,
esym->st_value, esym->st_size, 1);
}
} else {
@@ -8856,29 +8948,29 @@ found:
else
r |= l;
if (has_init)
- next(S);
+ next();
else if (l == VT_CONST)
/* uninitialized global variables may be overridden */
type.t |= VT_EXTERN;
- decl_initializer_alloc(S, &type, &ad, r, has_init, v, l);
+ decl_initializer_alloc(&type, &ad, r, has_init, v, l);
}
}
- if (S->tccpp_tok != ',') {
+ if (tok != ',') {
if (is_for_loop_init)
return 1;
- skip(S, ';');
+ skip(';');
break;
}
- next(S);
+ next();
}
}
}
return 0;
}
-static void decl(TCCState* S, int l)
+static void decl(int l)
{
- decl0(S, l, 0, NULL);
+ decl0(l, 0, NULL);
}
/* ------------------------------------------------------------------------- */
diff --git a/tccmacho.c b/tccmacho.c
index 3f41a7a..57c62c3 100644
--- a/tccmacho.c
+++ b/tccmacho.c
@@ -249,19 +249,19 @@ struct macho {
#define SHT_LINKEDIT (SHT_LOOS + 42)
#define SHN_FROMDLL (SHN_LOOS + 2) /* Symbol is undefined, comes from a DLL */
-static void * add_lc(TCCState* S, struct macho *mo, uint32_t cmd, uint32_t cmdsize)
+static void * add_lc(struct macho *mo, uint32_t cmd, uint32_t cmdsize)
{
- struct load_command *lc = tcc_mallocz(S, cmdsize);
+ struct load_command *lc = tcc_mallocz(cmdsize);
lc->cmd = cmd;
lc->cmdsize = cmdsize;
- mo->lc = tcc_realloc(S, mo->lc, sizeof(mo->lc[0]) * (mo->nlc + 1));
+ mo->lc = tcc_realloc(mo->lc, sizeof(mo->lc[0]) * (mo->nlc + 1));
mo->lc[mo->nlc++] = lc;
return lc;
}
-static struct segment_command_64 * add_segment(TCCState* S, struct macho *mo, const char *name)
+static struct segment_command_64 * add_segment(struct macho *mo, const char *name)
{
- struct segment_command_64 *sc = add_lc(S, mo, LC_SEGMENT_64, sizeof(*sc));
+ struct segment_command_64 *sc = add_lc(mo, LC_SEGMENT_64, sizeof(*sc));
strncpy(sc->segname, name, 16);
mo->seg2lc[mo->nseg++] = mo->nlc - 1;
return sc;
@@ -272,14 +272,14 @@ static struct segment_command_64 * get_segment(struct macho *mo, int i)
return (struct segment_command_64 *) (mo->lc[mo->seg2lc[i]]);
}
-static int add_section(TCCState* S, struct macho *mo, struct segment_command_64 **_seg, const char *name)
+static int add_section(struct macho *mo, struct segment_command_64 **_seg, const char *name)
{
struct segment_command_64 *seg = *_seg;
int ret = seg->nsects;
struct section_64 *sec;
seg->nsects++;
seg->cmdsize += sizeof(*sec);
- seg = tcc_realloc(S, seg, sizeof(*seg) + seg->nsects * sizeof(*sec));
+ seg = tcc_realloc(seg, sizeof(*seg) + seg->nsects * sizeof(*sec));
sec = (struct section_64*)((char*)seg + sizeof(*seg)) + ret;
memset(sec, 0, sizeof(*sec));
strncpy(sec->sectname, name, 16);
@@ -293,11 +293,11 @@ static struct section_64 *get_section(struct segment_command_64 *seg, int i)
return (struct section_64*)((char*)seg + sizeof(*seg)) + i;
}
-static void * add_dylib(TCCState* S, struct macho *mo, char *name)
+static void * add_dylib(struct macho *mo, char *name)
{
struct dylib_command *lc;
int sz = (sizeof(*lc) + strlen(name) + 1 + 7) & -8;
- lc = add_lc(S, mo, LC_LOAD_DYLIB, sz);
+ lc = add_lc(mo, LC_LOAD_DYLIB, sz);
lc->name = sizeof(*lc);
strcpy((char*)lc + lc->name, name);
lc->timestamp = 2;
@@ -306,7 +306,7 @@ static void * add_dylib(TCCState* S, struct macho *mo, char *name)
return lc;
}
-static void check_relocs(TCCState *S, struct macho *mo)
+static void check_relocs(TCCState *s1, struct macho *mo)
{
Section *s;
ElfW_Rel *rel;
@@ -314,10 +314,10 @@ static void check_relocs(TCCState *S, struct macho *mo)
int i, type, gotplt_entry, sym_index, for_code;
struct sym_attr *attr;
- S->got = new_section(S, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
- mo->indirsyms = new_section(S, "LEINDIR", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
- for (i = 1; i < S->nb_sections; i++) {
- s = S->sections[i];
+ s1->got = new_section(s1, ".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE);
+ mo->indirsyms = new_section(s1, "LEINDIR", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
+ for (i = 1; i < s1->nb_sections; i++) {
+ s = s1->sections[i];
if (s->sh_type != SHT_RELX)
continue;
for_each_elem(s, 0, rel, ElfW_Rel) {
@@ -331,21 +331,21 @@ static void check_relocs(TCCState *S, struct macho *mo)
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
if (sym->st_shndx == SHN_UNDEF
|| gotplt_entry == ALWAYS_GOTPLT_ENTRY) {
- attr = get_sym_attr(S, sym_index, 1);
+ attr = get_sym_attr(s1, sym_index, 1);
if (!attr->dyn_index) {
- uint32_t *pi = section_ptr_add(S, mo->indirsyms, sizeof(*pi));
- attr->got_offset = S->got->data_offset;
+ uint32_t *pi = section_ptr_add(mo->indirsyms, sizeof(*pi));
+ attr->got_offset = s1->got->data_offset;
attr->plt_offset = -1;
attr->dyn_index = 1; /* used as flag */
- section_ptr_add(S, S->got, PTR_SIZE);
+ section_ptr_add(s1->got, PTR_SIZE);
if (ELFW(ST_BIND)(sym->st_info) == STB_LOCAL) {
if (sym->st_shndx == SHN_UNDEF)
- tcc_error(S, "undefined local symbol???");
+ tcc_error("undefined local symbol???");
*pi = INDIRECT_SYMBOL_LOCAL;
/* The pointer slot we generated must point to the
symbol, whose address is only known after layout,
so register a simple relocation for that. */
- put_elf_reloc(S->symtab, S->got, attr->got_offset,
+ put_elf_reloc(s1->symtab, s1->got, attr->got_offset,
R_DATA_PTR, sym_index);
} else
*pi = mo->e2msym[sym_index];
@@ -354,10 +354,10 @@ static void check_relocs(TCCState *S, struct macho *mo)
if (attr->plt_offset == -1) {
uint8_t *jmp;
attr->plt_offset = mo->stubs->data_offset;
- jmp = section_ptr_add(S, mo->stubs, 6);
+ jmp = section_ptr_add(mo->stubs, 6);
jmp[0] = 0xff; /* jmpq *ofs(%rip) */
jmp[1] = 0x25;
- put_elf_reloc(S->symtab, mo->stubs,
+ put_elf_reloc(s1->symtab, mo->stubs,
attr->plt_offset + 2,
R_X86_64_GOTPCREL, sym_index);
}
@@ -369,7 +369,7 @@ static void check_relocs(TCCState *S, struct macho *mo)
}
}
-static int check_symbols(TCCState *S, struct macho *mo)
+static int check_symbols(TCCState *s1, struct macho *mo)
{
int sym_index, sym_end;
int ret = 0;
@@ -391,17 +391,17 @@ static int check_symbols(TCCState *S, struct macho *mo)
if (mo->ilocal == -1)
mo->ilocal = sym_index - 1;
if (mo->iextdef != -1 || mo->iundef != -1)
- tcc_error(S, "local syms after global ones");
+ tcc_error("local syms after global ones");
} else if (sym->st_shndx != SHN_UNDEF) {
if (mo->iextdef == -1)
mo->iextdef = sym_index - 1;
if (mo->iundef != -1)
- tcc_error(S, "external defined symbol after undefined");
+ tcc_error("external defined symbol after undefined");
} else if (sym->st_shndx == SHN_UNDEF) {
if (mo->iundef == -1)
mo->iundef = sym_index - 1;
if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK
- || find_elf_sym(S->dynsymtab_section, name)) {
+ || find_elf_sym(s1->dynsymtab_section, name)) {
/* Mark the symbol as coming from a dylib so that
relocate_syms doesn't complain. Normally bind_exe_dynsyms
would do this check, and place the symbol into dynsym
@@ -410,14 +410,14 @@ static int check_symbols(TCCState *S, struct macho *mo)
sym->st_shndx = SHN_FROMDLL;
continue;
}
- tcc_error_noabort(S, "undefined symbol '%s'", name);
+ tcc_error_noabort("undefined symbol '%s'", name);
ret = -1;
}
}
return ret;
}
-static void convert_symbol(TCCState *S, struct macho *mo, struct nlist_64 *pn)
+static void convert_symbol(TCCState *s1, struct macho *mo, struct nlist_64 *pn)
{
struct nlist_64 n = *pn;
ElfSym *sym = (ElfW(Sym) *)symtab_section->data + pn->n_value;
@@ -433,19 +433,19 @@ static void convert_symbol(TCCState *S, struct macho *mo, struct nlist_64 *pn)
n.n_type = N_ABS;
break;
default:
- tcc_error(S, "unhandled ELF symbol type %d %s",
+ tcc_error("unhandled ELF symbol type %d %s",
ELFW(ST_TYPE)(sym->st_info), name);
}
if (sym->st_shndx == SHN_UNDEF)
- tcc_error(S, "should have been rewritten to SHN_FROMDLL: %s", name);
+ tcc_error("should have been rewritten to SHN_FROMDLL: %s", name);
else if (sym->st_shndx == SHN_FROMDLL)
n.n_type = N_UNDF, n.n_sect = 0;
else if (sym->st_shndx == SHN_ABS)
n.n_type = N_ABS, n.n_sect = 0;
else if (sym->st_shndx >= SHN_LORESERVE)
- tcc_error(S, "unhandled ELF symbol section %d %s", sym->st_shndx, name);
+ tcc_error("unhandled ELF symbol section %d %s", sym->st_shndx, name);
else if (!mo->elfsectomacho[sym->st_shndx])
- tcc_error(S, "ELF section %d not mapped into Mach-O for symbol %s",
+ tcc_error("ELF section %d not mapped into Mach-O for symbol %s",
sym->st_shndx, name);
else
n.n_sect = mo->elfsectomacho[sym->st_shndx];
@@ -458,15 +458,16 @@ static void convert_symbol(TCCState *S, struct macho *mo, struct nlist_64 *pn)
*pn = n;
}
-static void convert_symbols(TCCState *S, struct macho *mo)
+static void convert_symbols(TCCState *s1, struct macho *mo)
{
struct nlist_64 *pn;
for_each_elem(mo->symtab, 0, pn, struct nlist_64)
- convert_symbol(S, mo, pn);
+ convert_symbol(s1, mo, pn);
}
-static int machosymcmp(const void *_a, const void *_b, TCCState *S)
+static int machosymcmp(const void *_a, const void *_b)
{
+ TCCState *s1 = tcc_state;
int ea = ((struct nlist_64 *)_a)->n_value;
int eb = ((struct nlist_64 *)_b)->n_value;
ElfSym *sa = (ElfSym *)symtab_section->data + ea;
@@ -491,33 +492,33 @@ static int machosymcmp(const void *_a, const void *_b, TCCState *S)
return ea - eb;
}
-static void create_symtab(TCCState *S, struct macho *mo)
+static void create_symtab(TCCState *s1, struct macho *mo)
{
int sym_index, sym_end;
struct nlist_64 *pn;
/* Stub creation belongs to check_relocs, but we need to create
the symbol now, so its included in the sorting. */
- mo->stubs = new_section(S, "__stubs", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
- mo->stubsym = put_elf_sym(S, S->symtab, 0, 0,
+ mo->stubs = new_section(s1, "__stubs", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
+ mo->stubsym = put_elf_sym(s1->symtab, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
mo->stubs->sh_num, ".__stubs");
- mo->symtab = new_section(S, "LESYMTAB", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
- mo->strtab = new_section(S, "LESTRTAB", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
- put_elf_str(S, mo->strtab, " "); /* Mach-O starts strtab with a space */
+ mo->symtab = new_section(s1, "LESYMTAB", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
+ mo->strtab = new_section(s1, "LESTRTAB", SHT_LINKEDIT, SHF_ALLOC | SHF_WRITE);
+ put_elf_str(mo->strtab, " "); /* Mach-O starts strtab with a space */
sym_end = symtab_section->data_offset / sizeof(ElfW(Sym));
- pn = section_ptr_add(S, mo->symtab, sizeof(*pn) * (sym_end - 1));
+ pn = section_ptr_add(mo->symtab, sizeof(*pn) * (sym_end - 1));
for (sym_index = 1; sym_index < sym_end; ++sym_index) {
ElfW(Sym) *sym = (ElfW(Sym) *)symtab_section->data + sym_index;
const char *name = (char*)symtab_section->link->data + sym->st_name;
- pn[sym_index - 1].n_strx = put_elf_str(S, mo->strtab, name);
+ pn[sym_index - 1].n_strx = put_elf_str(mo->strtab, name);
pn[sym_index - 1].n_value = sym_index;
}
- tcc_enter_state(S); /* qsort needs global state */
- tcc_qsort_s(pn, sym_end - 1, sizeof(*pn), (tcc_cmpfun)machosymcmp, S);
- tcc_exit_state(S);
- mo->e2msym = tcc_malloc(S, sym_end * sizeof(*mo->e2msym));
+ tcc_enter_state(s1); /* qsort needs global state */
+ qsort(pn, sym_end - 1, sizeof(*pn), machosymcmp);
+ tcc_exit_state(s1);
+ mo->e2msym = tcc_malloc(sym_end * sizeof(*mo->e2msym));
mo->e2msym[0] = -1;
for (sym_index = 1; sym_index < sym_end; ++sym_index) {
mo->e2msym[pn[sym_index - 1].n_value] = sym_index - 1;
@@ -545,7 +546,7 @@ const struct {
/*[sk_linkedit] =*/ { 3, S_REGULAR, NULL },
};
-static void collect_sections(TCCState *S, struct macho *mo)
+static void collect_sections(TCCState *s1, struct macho *mo)
{
int i, sk, numsec;
uint64_t curaddr, fileofs;
@@ -556,49 +557,49 @@ static void collect_sections(TCCState *S, struct macho *mo)
struct dysymtab_command *dysymlc;
char *str;
- seg = add_segment(S, mo, "__PAGEZERO");
+ seg = add_segment(mo, "__PAGEZERO");
seg->vmsize = (uint64_t)1 << 32;
- seg = add_segment(S, mo, "__TEXT");
+ seg = add_segment(mo, "__TEXT");
seg->vmaddr = (uint64_t)1 << 32;
seg->maxprot = 7; // rwx
seg->initprot = 5; // r-x
- seg = add_segment(S, mo, "__DATA");
+ seg = add_segment(mo, "__DATA");
seg->vmaddr = -1;
seg->maxprot = 7; // rwx
seg->initprot = 3; // rw-
- seg = add_segment(S, mo, "__LINKEDIT");
+ seg = add_segment(mo, "__LINKEDIT");
seg->vmaddr = -1;
seg->maxprot = 7; // rwx
seg->initprot = 1; // r--
- mo->ep = add_lc(S, mo, LC_MAIN, sizeof(*mo->ep));
+ mo->ep = add_lc(mo, LC_MAIN, sizeof(*mo->ep));
mo->ep->entryoff = 4096;
i = (sizeof(*dyldlc) + strlen("/usr/lib/dyld") + 1 + 7) &-8;
- dyldlc = add_lc(S, mo, LC_LOAD_DYLINKER, i);
+ dyldlc = add_lc(mo, LC_LOAD_DYLINKER, i);
dyldlc->name = sizeof(*dyldlc);
str = (char*)dyldlc + dyldlc->name;
strcpy(str, "/usr/lib/dyld");
- symlc = add_lc(S, mo, LC_SYMTAB, sizeof(*symlc));
- dysymlc = add_lc(S, mo, LC_DYSYMTAB, sizeof(*dysymlc));
+ symlc = add_lc(mo, LC_SYMTAB, sizeof(*symlc));
+ dysymlc = add_lc(mo, LC_DYSYMTAB, sizeof(*dysymlc));
- for(i = 0; i < S->nb_loaded_dlls; i++) {
- DLLReference *dllref = S->loaded_dlls[i];
+ for(i = 0; i < s1->nb_loaded_dlls; i++) {
+ DLLReference *dllref = s1->loaded_dlls[i];
if (dllref->level == 0)
- add_dylib(S, mo, dllref->name);
+ add_dylib(mo, dllref->name);
}
/* dyld requires a writable segment with classic Mach-O, but it ignores
zero-sized segments for this, so force to have some data. */
- section_ptr_add(S, data_section, 1);
+ section_ptr_add(data_section, 1);
memset (mo->sk_to_sect, 0, sizeof(mo->sk_to_sect));
- for (i = S->nb_sections; i-- > 1;) {
+ for (i = s1->nb_sections; i-- > 1;) {
int type, flags;
- s = S->sections[i];
+ s = s1->sections[i];
type = s->sh_type;
flags = s->sh_flags;
sk = sk_unknown;
@@ -613,7 +614,7 @@ static void collect_sections(TCCState *S, struct macho *mo)
case SHT_RELX: sk = sk_discard; break;
case SHT_LINKEDIT: sk = sk_linkedit; break;
case SHT_PROGBITS:
- if (s == S->got)
+ if (s == s1->got)
sk = sk_nl_ptr;
else if (flags & SHF_EXECINSTR)
sk = sk_text;
@@ -633,7 +634,7 @@ static void collect_sections(TCCState *S, struct macho *mo)
curaddr += 4096;
seg = NULL;
numsec = 0;
- mo->elfsectomacho = tcc_mallocz(S, sizeof(*mo->elfsectomacho) * S->nb_sections);
+ mo->elfsectomacho = tcc_mallocz(sizeof(*mo->elfsectomacho) * s1->nb_sections);
for (sk = sk_unknown; sk < sk_last; sk++) {
struct section_64 *sec = NULL;
if (seg) {
@@ -645,7 +646,7 @@ static void collect_sections(TCCState *S, struct macho *mo)
int si;
seg = get_segment(mo, skinfo[sk].seg);
if (skinfo[sk].name) {
- si = add_section(S, mo, &seg, skinfo[sk].name);
+ si = add_section(mo, &seg, skinfo[sk].name);
numsec++;
mo->lc[mo->seg2lc[skinfo[sk].seg]] = (struct load_command*)seg;
mo->sk_to_sect[sk].machosect = si;
@@ -669,7 +670,7 @@ static void collect_sections(TCCState *S, struct macho *mo)
sec->align = al;
al = 1ULL << al;
if (al > 4096)
- tcc_warning(S, "alignment > 4096"), sec->align = 12, al = 4096;
+ tcc_warning("alignment > 4096"), sec->align = 12, al = 4096;
curaddr = (curaddr + al - 1) & -al;
fileofs = (fileofs + al - 1) & -al;
if (sec) {
@@ -738,7 +739,7 @@ static void collect_sections(TCCState *S, struct macho *mo)
dysymlc->nindirectsyms = mo->indirsyms->data_offset / sizeof(uint32_t);
}
-static void macho_write(TCCState *S, struct macho *mo, FILE *fp)
+static void macho_write(TCCState *s1, struct macho *mo, FILE *fp)
{
int i, sk;
uint64_t fileofs = 0;
@@ -778,7 +779,7 @@ static void macho_write(TCCState *S, struct macho *mo, FILE *fp)
}
}
-ST_FUNC int macho_output_file(TCCState *S, const char *filename)
+ST_FUNC int macho_output_file(TCCState *s1, const char *filename)
{
int fd, mode, file_type;
FILE *fp;
@@ -787,7 +788,7 @@ ST_FUNC int macho_output_file(TCCState *S, const char *filename)
(void)memset(&mo, 0, sizeof(mo));
- file_type = S->output_type;
+ file_type = s1->output_type;
if (file_type == TCC_OUTPUT_OBJ)
mode = 0666;
else
@@ -795,36 +796,36 @@ ST_FUNC int macho_output_file(TCCState *S, const char *filename)
unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
if (fd < 0) {
- tcc_error_noabort(S, "could not write '%s: %s'", filename, strerror(errno));
+ tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));
return -1;
}
fp = fdopen(fd, "wb");
- if (S->verbose)
+ if (s1->verbose)
printf("<- %s\n", filename);
- tcc_add_runtime(S);
- resolve_common_syms(S);
- create_symtab(S, &mo);
- check_relocs(S, &mo);
- ret = check_symbols(S, &mo);
+ tcc_add_runtime(s1);
+ resolve_common_syms(s1);
+ create_symtab(s1, &mo);
+ check_relocs(s1, &mo);
+ ret = check_symbols(s1, &mo);
if (!ret) {
- collect_sections(S, &mo);
- relocate_syms(S, S->symtab, 0);
- mo.ep->entryoff = get_sym_addr(S, "main", 1, 1)
+ collect_sections(s1, &mo);
+ relocate_syms(s1, s1->symtab, 0);
+ mo.ep->entryoff = get_sym_addr(s1, "main", 1, 1)
- get_segment(&mo, 1)->vmaddr;
- if (S->nb_errors)
+ if (s1->nb_errors)
goto do_ret;
- relocate_sections(S);
- convert_symbols(S, &mo);
- macho_write(S, &mo, fp);
+ relocate_sections(s1);
+ convert_symbols(s1, &mo);
+ macho_write(s1, &mo, fp);
}
do_ret:
for (i = 0; i < mo.nlc; i++)
- tcc_free(S, mo.lc[i]);
- tcc_free(S, mo.lc);
- tcc_free(S, mo.elfsectomacho);
- tcc_free(S, mo.e2msym);
+ tcc_free(mo.lc[i]);
+ tcc_free(mo.lc);
+ tcc_free(mo.elfsectomacho);
+ tcc_free(mo.e2msym);
fclose(fp);
return ret;
@@ -836,13 +837,13 @@ static uint32_t macho_swap32(uint32_t x)
}
#define SWAP(x) (swap ? macho_swap32(x) : (x))
-ST_FUNC int macho_add_dllref(TCCState* S, int lev, const char* soname)
+ST_FUNC int macho_add_dllref(TCCState* s1, int lev, const char* soname)
{
/* if the dll is already loaded, do not load it */
DLLReference *dllref;
int i;
- for(i = 0; i < S->nb_loaded_dlls; i++) {
- dllref = S->loaded_dlls[i];
+ for(i = 0; i < s1->nb_loaded_dlls; i++) {
+ dllref = s1->loaded_dlls[i];
if (!strcmp(soname, dllref->name)) {
/* but update level if needed */
if (lev < dllref->level)
@@ -850,7 +851,7 @@ ST_FUNC int macho_add_dllref(TCCState* S, int lev, const char* soname)
return -1;
}
}
- tcc_add_dllref(S, soname)->level = lev;
+ tcc_add_dllref(s1, soname)->level = lev;
return 0;
}
@@ -912,12 +913,12 @@ the_end:
}
#endif /* TCC_IS_NATIVE */
-ST_FUNC int macho_load_tbd(TCCState* S, int fd, const char* filename, int lev)
+ST_FUNC int macho_load_tbd(TCCState* s1, int fd, const char* filename, int lev)
{
char *soname, *data, *pos;
int ret = -1;
- pos = data = tcc_load_text(S, fd);
+ pos = data = tcc_load_text(fd);
if (!tbd_parse_movepast("install-name: ")) goto the_end;
tbd_parse_skipws;
tbd_parse_tramplequote;
@@ -925,7 +926,7 @@ ST_FUNC int macho_load_tbd(TCCState* S, int fd, const char* filename, int lev)
if (!tbd_parse_movetoany("\n \"'")) goto the_end;
tbd_parse_trample;
ret = 0;
- if (macho_add_dllref(S, lev, soname) != 0) goto the_end;
+ if (macho_add_dllref(s1, lev, soname) != 0) goto the_end;
while(pos) {
char* sym = NULL;
int cont = 1;
@@ -941,17 +942,17 @@ ST_FUNC int macho_load_tbd(TCCState* S, int fd, const char* filename, int lev)
tbd_parse_skipws;
if (*pos==0||*pos==']') cont=0;
tbd_parse_trample;
- set_elf_sym(S->dynsymtab_section, 0, 0,
+ set_elf_sym(s1->dynsymtab_section, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, SHN_UNDEF, sym);
}
}
the_end:
- tcc_free(S, data);
+ tcc_free(data);
return ret;
}
-ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
+ST_FUNC int macho_load_dll(TCCState * s1, int fd, const char* filename, int lev)
{
unsigned char buf[sizeof(struct mach_header_64)];
void *buf2;
@@ -973,7 +974,7 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
return -1;
memcpy(&fh, buf, sizeof(fh));
if (fh.magic == FAT_MAGIC || fh.magic == FAT_CIGAM) {
- struct fat_arch *fa = load_data(S, fd, sizeof(fh),
+ struct fat_arch *fa = load_data(fd, sizeof(fh),
fh.nfat_arch * sizeof(*fa));
swap = fh.magic == FAT_CIGAM;
for (i = 0; i < SWAP(fh.nfat_arch); i++)
@@ -981,15 +982,15 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
&& SWAP(fa[i].cpusubtype) == 3) /* CPU_SUBTYPE_X86_ALL */
break;
if (i == SWAP(fh.nfat_arch)) {
- tcc_free(S, fa);
+ tcc_free(fa);
return -1;
}
machofs = SWAP(fa[i].offset);
- tcc_free(S, fa);
+ tcc_free(fa);
lseek(fd, machofs, SEEK_SET);
goto again;
} else if (fh.magic == FAT_MAGIC_64 || fh.magic == FAT_CIGAM_64) {
- tcc_warning(S, "%s: Mach-O fat 64bit files of type 0x%x not handled",
+ tcc_warning("%s: Mach-O fat 64bit files of type 0x%x not handled",
filename, fh.magic);
return -1;
}
@@ -998,7 +999,7 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
if (mh.magic != MH_MAGIC_64)
return -1;
dprintf("found Mach-O at %d\n", machofs);
- buf2 = load_data(S, fd, machofs + sizeof(struct mach_header_64), mh.sizeofcmds);
+ buf2 = load_data(fd, machofs + sizeof(struct mach_header_64), mh.sizeofcmds);
for (i = 0, lc = buf2; i < mh.ncmds; i++) {
dprintf("lc %2d: 0x%08x\n", i, lc->cmd);
switch (lc->cmd) {
@@ -1006,9 +1007,9 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
{
struct symtab_command *sc = (struct symtab_command*)lc;
nsyms = sc->nsyms;
- symtab = load_data(S, fd, machofs + sc->symoff, nsyms * sizeof(*symtab));
+ symtab = load_data(fd, machofs + sc->symoff, nsyms * sizeof(*symtab));
strsize = sc->strsize;
- strtab = load_data(S, fd, machofs + sc->stroff, strsize);
+ strtab = load_data(fd, machofs + sc->stroff, strsize);
break;
}
case LC_ID_DYLIB:
@@ -1027,11 +1028,11 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
int subfd = open(name, O_RDONLY | O_BINARY);
dprintf(" REEXPORT %s\n", name);
if (subfd < 0)
- tcc_warning(S, "can't open %s (reexported from %s)", name, filename);
+ tcc_warning("can't open %s (reexported from %s)", name, filename);
else {
/* Hopefully the REEXPORTs never form a cycle, we don't check
for that! */
- macho_load_dll(S, subfd, name, lev + 1);
+ macho_load_dll(s1, subfd, name, lev + 1);
close(subfd);
}
break;
@@ -1047,11 +1048,11 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
lc = (struct load_command*) ((char*)lc + lc->cmdsize);
}
- if (0 != macho_add_dllref(S, lev, soname))
+ if (0 != macho_add_dllref(s1, lev, soname))
goto the_end;
if (!nsyms || !nextdef)
- tcc_warning(S, "%s doesn't export any symbols?", filename);
+ tcc_warning("%s doesn't export any symbols?", filename);
//dprintf("symbols (all):\n");
dprintf("symbols (exported):\n");
@@ -1062,14 +1063,14 @@ ST_FUNC int macho_load_dll(TCCState * S, int fd, const char* filename, int lev)
dprintf("%5d: %3d %3d 0x%04x 0x%016lx %s\n",
i, sym->n_type, sym->n_sect, sym->n_desc, (long)sym->n_value,
strtab + sym->n_strx);
- set_elf_sym(S->dynsymtab_section, 0, 0,
+ set_elf_sym(s1->dynsymtab_section, 0, 0,
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE),
0, SHN_UNDEF, strtab + sym->n_strx);
}
the_end:
- tcc_free(S, strtab);
- tcc_free(S, symtab);
- tcc_free(S, buf2);
+ tcc_free(strtab);
+ tcc_free(symtab);
+ tcc_free(buf2);
return 0;
}
diff --git a/tccpe.c b/tccpe.c
index 6eb9ef3..07501a9 100644
--- a/tccpe.c
+++ b/tccpe.c
@@ -345,7 +345,7 @@ struct pe_import_info {
};
struct pe_info {
- TCCState *S;
+ TCCState *s1;
Section *reloc;
Section *thunk;
const char *filename;
@@ -377,15 +377,15 @@ struct pe_info {
/* --------------------------------------------*/
-static const char *pe_export_name(TCCState *S, ElfW(Sym) *sym)
+static const char *pe_export_name(TCCState *s1, ElfW(Sym) *sym)
{
const char *name = (char*)symtab_section->link->data + sym->st_name;
- if (S->leading_underscore && name[0] == '_' && !(sym->st_other & ST_PE_STDCALL))
+ if (s1->leading_underscore && name[0] == '_' && !(sym->st_other & ST_PE_STDCALL))
return name + 1;
return name;
}
-static int pe_find_import(TCCState * S, ElfW(Sym) *sym)
+static int pe_find_import(TCCState * s1, ElfW(Sym) *sym)
{
char buffer[200];
const char *s, *p;
@@ -393,7 +393,7 @@ static int pe_find_import(TCCState * S, ElfW(Sym) *sym)
int a, err = 0;
do {
- s = pe_export_name(S, sym);
+ s = pe_export_name(s1, sym);
a = 0;
if (n) {
/* second try: */
@@ -414,7 +414,7 @@ static int pe_find_import(TCCState * S, ElfW(Sym) *sym)
}
s = buffer;
}
- sym_index = find_elf_sym(S->dynsymtab_section, s);
+ sym_index = find_elf_sym(s1->dynsymtab_section, s);
// printf("find (%d) %d %s\n", n, sym_index, s);
if (sym_index
&& ELFW(ST_TYPE)(sym->st_info) == STT_OBJECT
@@ -460,7 +460,7 @@ static void pe_align_section(Section *s, int a)
{
int i = s->data_offset & (a-1);
if (i)
- section_ptr_add(s->S, s, a - i);
+ section_ptr_add(s, a - i);
}
static void pe_set_datadir(struct pe_header *hdr, int dir, DWORD addr, DWORD size)
@@ -615,11 +615,11 @@ static int pe_write(struct pe_info *pe)
DWORD file_offset;
struct section_info *si;
IMAGE_SECTION_HEADER *psh;
- TCCState *S = pe->S;
+ TCCState *s1 = pe->s1;
pf.op = fopen(pe->filename, "wb");
if (NULL == pf.op) {
- tcc_error_noabort(S, "could not write '%s': %s", pe->filename, strerror(errno));
+ tcc_error_noabort("could not write '%s': %s", pe->filename, strerror(errno));
return -1;
}
@@ -630,7 +630,7 @@ static int pe_write(struct pe_info *pe)
file_offset = pe->sizeofheaders;
- if (2 == pe->S->verbose)
+ if (2 == pe->s1->verbose)
printf("-------------------------------"
"\n virt file size section" "\n");
for (i = 0; i < pe->sec_count; ++i) {
@@ -643,7 +643,7 @@ static int pe_write(struct pe_info *pe)
size = si->sh_size;
psh = &si->ish;
- if (2 == pe->S->verbose)
+ if (2 == pe->s1->verbose)
printf("%6x %6x %6x %s\n",
(unsigned)addr, (unsigned)file_offset, (unsigned)size, sh_name);
@@ -712,11 +712,11 @@ static int pe_write(struct pe_info *pe)
pe_header.opthdr.SizeOfHeaders = pe->sizeofheaders;
pe_header.opthdr.ImageBase = pe->imagebase;
pe_header.opthdr.Subsystem = pe->subsystem;
- if (pe->S->pe_stack_size)
- pe_header.opthdr.SizeOfStackReserve = pe->S->pe_stack_size;
+ if (pe->s1->pe_stack_size)
+ pe_header.opthdr.SizeOfStackReserve = pe->s1->pe_stack_size;
if (PE_DLL == pe->type)
pe_header.filehdr.Characteristics = CHARACTERISTICS_DLL;
- pe_header.filehdr.Characteristics |= pe->S->pe_characteristics;
+ pe_header.filehdr.Characteristics |= pe->s1->pe_characteristics;
pe_fwrite(&pe_header, sizeof pe_header, &pf);
for (i = 0; i < pe->sec_count; ++i)
@@ -747,9 +747,9 @@ static int pe_write(struct pe_info *pe)
chmod(pe->filename, 0777);
#endif
- if (2 == pe->S->verbose)
+ if (2 == pe->s1->verbose)
printf("-------------------------------\n");
- if (pe->S->verbose)
+ if (pe->s1->verbose)
printf("<- %s (%u bytes)\n", pe->filename, (unsigned)file_offset);
return 0;
@@ -765,7 +765,7 @@ static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
struct import_symbol *s;
ElfW(Sym) *isym;
- isym = (ElfW(Sym) *)pe->S->dynsymtab_section->data + sym_index;
+ isym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;
dll_index = isym->st_size;
i = dynarray_assoc ((void**)pe->imp_info, pe->imp_count, dll_index);
@@ -773,17 +773,17 @@ static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index)
p = pe->imp_info[i];
goto found_dll;
}
- p = tcc_mallocz(pe->S, sizeof *p);
+ p = tcc_mallocz(sizeof *p);
p->dll_index = dll_index;
- dynarray_add(pe->S, &pe->imp_info, &pe->imp_count, p);
+ dynarray_add(&pe->imp_info, &pe->imp_count, p);
found_dll:
i = dynarray_assoc ((void**)p->symbols, p->sym_count, sym_index);
if (-1 != i)
return p->symbols[i];
- s = tcc_mallocz(pe->S, sizeof *s);
- dynarray_add(pe->S, &p->symbols, &p->sym_count, s);
+ s = tcc_mallocz(sizeof *s);
+ dynarray_add(&p->symbols, &p->sym_count, s);
s->sym_index = sym_index;
return s;
}
@@ -793,9 +793,9 @@ void pe_free_imports(struct pe_info *pe)
int i;
for (i = 0; i < pe->imp_count; ++i) {
struct pe_import_info *p = pe->imp_info[i];
- dynarray_reset(pe->S, &p->symbols, &p->sym_count);
+ dynarray_reset(&p->symbols, &p->sym_count);
}
- dynarray_reset(pe->S, &pe->imp_info, &pe->imp_count);
+ dynarray_reset(&pe->imp_info, &pe->imp_count);
}
/*----------------------------------------------------------------------------*/
@@ -804,7 +804,7 @@ static void pe_build_imports(struct pe_info *pe)
int thk_ptr, ent_ptr, dll_ptr, sym_cnt, i;
DWORD rva_base = pe->thunk->sh_addr - pe->imagebase;
int ndlls = pe->imp_count;
- TCCState *S = pe->S;
+ TCCState *s1 = pe->s1;
for (sym_cnt = i = 0; i < ndlls; ++i)
sym_cnt += pe->imp_info[i]->sym_count;
@@ -820,7 +820,7 @@ static void pe_build_imports(struct pe_info *pe)
ent_ptr = thk_ptr + pe->iat_size;
pe->imp_offs = dll_ptr + rva_base;
pe->iat_offs = thk_ptr + rva_base;
- section_ptr_add(pe->S, pe->thunk, pe->imp_size + 2*pe->iat_size);
+ section_ptr_add(pe->thunk, pe->imp_size + 2*pe->iat_size);
for (i = 0; i < pe->imp_count; ++i) {
IMAGE_IMPORT_DESCRIPTOR *hdr;
@@ -832,12 +832,12 @@ static void pe_build_imports(struct pe_info *pe)
dllindex = p->dll_index;
if (dllindex)
- name = tcc_basename((dllref = pe->S->loaded_dlls[dllindex-1])->name);
+ name = tcc_basename((dllref = pe->s1->loaded_dlls[dllindex-1])->name);
else
name = "", dllref = NULL;
/* put the dll name into the import header */
- v = put_elf_str(pe->S, pe->thunk, name);
+ v = put_elf_str(pe->thunk, name);
hdr = (IMAGE_IMPORT_DESCRIPTOR*)(pe->thunk->data + dll_ptr);
hdr->FirstThunk = thk_ptr + rva_base;
hdr->OriginalFirstThunk = ent_ptr + rva_base;
@@ -847,9 +847,9 @@ static void pe_build_imports(struct pe_info *pe)
if (k < n) {
int iat_index = p->symbols[k]->iat_index;
int sym_index = p->symbols[k]->sym_index;
- ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->S->dynsymtab_section->data + sym_index;
+ ElfW(Sym) *imp_sym = (ElfW(Sym) *)pe->s1->dynsymtab_section->data + sym_index;
ElfW(Sym) *org_sym = (ElfW(Sym) *)symtab_section->data + iat_index;
- const char *name = (char*)pe->S->dynsymtab_section->link->data + imp_sym->st_name;
+ const char *name = (char*)pe->s1->dynsymtab_section->link->data + imp_sym->st_name;
int ordinal;
org_sym->st_value = thk_ptr;
@@ -875,8 +875,8 @@ static void pe_build_imports(struct pe_info *pe)
v = ordinal | (ADDR3264)1 << (sizeof(ADDR3264)*8 - 1);
} else {
v = pe->thunk->data_offset + rva_base;
- section_ptr_add(pe->S, pe->thunk, sizeof(WORD)); /* hint, not used */
- put_elf_str(pe->S, pe->thunk, name);
+ section_ptr_add(pe->thunk, sizeof(WORD)); /* hint, not used */
+ put_elf_str(pe->thunk, name);
}
} else {
@@ -915,7 +915,7 @@ static void pe_build_exports(struct pe_info *pe)
IMAGE_EXPORT_DIRECTORY *hdr;
int sym_count, ord;
struct pe_sort_sym **sorted, *p;
- TCCState *S = pe->S;
+ TCCState *s1 = pe->s1;
FILE *op;
char buf[260];
@@ -928,12 +928,12 @@ static void pe_build_exports(struct pe_info *pe)
sym_end = symtab_section->data_offset / sizeof(ElfW(Sym));
for (sym_index = 1; sym_index < sym_end; ++sym_index) {
sym = (ElfW(Sym)*)symtab_section->data + sym_index;
- name = pe_export_name(pe->S, sym);
+ name = pe_export_name(pe->s1, sym);
if (sym->st_other & ST_PE_EXPORT) {
- p = tcc_malloc(pe->S, sizeof *p);
+ p = tcc_malloc(sizeof *p);
p->index = sym_index;
p->name = name;
- dynarray_add(pe->S, &sorted, &sym_count, p);
+ dynarray_add(&sorted, &sym_count, p);
}
#if 0
if (sym->st_other & ST_PE_EXPORT)
@@ -957,7 +957,7 @@ static void pe_build_exports(struct pe_info *pe)
ord_o = name_o + sym_count * sizeof (DWORD);
str_o = ord_o + sym_count * sizeof(WORD);
- hdr = section_ptr_add(pe->S, pe->thunk, str_o - base_o);
+ hdr = section_ptr_add(pe->thunk, str_o - base_o);
hdr->Characteristics = 0;
hdr->Base = 1;
hdr->NumberOfFunctions = sym_count;
@@ -966,7 +966,7 @@ static void pe_build_exports(struct pe_info *pe)
hdr->AddressOfNames = name_o + rva_base;
hdr->AddressOfNameOrdinals = ord_o + rva_base;
hdr->Name = str_o + rva_base;
- put_elf_str(pe->S, pe->thunk, dllname);
+ put_elf_str(pe->thunk, dllname);
#if 1
/* automatically write exports to <output-filename>.def */
@@ -974,10 +974,10 @@ static void pe_build_exports(struct pe_info *pe)
strcpy(tcc_fileextension(buf), ".def");
op = fopen(buf, "wb");
if (NULL == op) {
- tcc_error_noabort(pe->S, "could not create '%s': %s", buf, strerror(errno));
+ tcc_error_noabort("could not create '%s': %s", buf, strerror(errno));
} else {
fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname);
- if (pe->S->verbose)
+ if (pe->s1->verbose)
printf("<- %s (%d symbol%s)\n", buf, sym_count, &"s"[sym_count < 2]);
}
#endif
@@ -992,7 +992,7 @@ static void pe_build_exports(struct pe_info *pe)
= pe->thunk->data_offset + rva_base;
*(WORD*)(pe->thunk->data + ord_o)
= ord;
- put_elf_str(pe->S, pe->thunk, name);
+ put_elf_str(pe->thunk, name);
func_o += sizeof (DWORD);
name_o += sizeof (DWORD);
ord_o += sizeof (WORD);
@@ -1002,7 +1002,7 @@ static void pe_build_exports(struct pe_info *pe)
pe->exp_offs = base_o + rva_base;
pe->exp_size = pe->thunk->data_offset - base_o;
- dynarray_reset(pe->S, &sorted, &sym_count);
+ dynarray_reset(&sorted, &sym_count);
if (op)
fclose(op);
}
@@ -1028,11 +1028,11 @@ static void pe_build_reloc (struct pe_info *pe)
continue;
if (count == 0) { /* new block */
block_ptr = pe->reloc->data_offset;
- section_ptr_add(pe->S, pe->reloc, sizeof(struct pe_reloc_header));
+ section_ptr_add(pe->reloc, sizeof(struct pe_reloc_header));
offset = addr & 0xFFFFFFFF<<12;
}
if ((addr -= offset) < (1<<12)) { /* one block spans 4k addresses */
- WORD *wp = section_ptr_add(pe->S, pe->reloc, sizeof (WORD));
+ WORD *wp = section_ptr_add(pe->reloc, sizeof (WORD));
*wp = addr | PE_IMAGE_REL<<12;
++count;
continue;
@@ -1058,7 +1058,7 @@ static void pe_build_reloc (struct pe_info *pe)
/* fill the last block and ready for a new one */
if (count & 1) /* align for DWORDS */
- section_ptr_add(pe->S, pe->reloc, sizeof(WORD)), ++count;
+ section_ptr_add(pe->reloc, sizeof(WORD)), ++count;
hdr = (struct pe_reloc_header *)(pe->reloc->data + block_ptr);
hdr -> offset = offset - pe->imagebase;
hdr -> size = count * sizeof(WORD) + sizeof(struct pe_reloc_header);
@@ -1110,16 +1110,16 @@ static int pe_assign_addresses (struct pe_info *pe)
int *section_order;
struct section_info *si;
Section *s;
- TCCState *S = pe->S;
+ TCCState *s1 = pe->s1;
if (PE_DLL == pe->type)
- pe->reloc = new_section(pe->S, ".reloc", SHT_PROGBITS, 0);
- // pe->thunk = new_section(pe->S, ".iedat", SHT_PROGBITS, SHF_ALLOC);
+ pe->reloc = new_section(pe->s1, ".reloc", SHT_PROGBITS, 0);
+ // pe->thunk = new_section(pe->s1, ".iedat", SHT_PROGBITS, SHF_ALLOC);
- section_order = tcc_malloc(pe->S, pe->S->nb_sections * sizeof (int));
+ section_order = tcc_malloc(pe->s1->nb_sections * sizeof (int));
for (o = k = 0 ; k < sec_last; ++k) {
- for (i = 1; i < S->nb_sections; ++i) {
- s = S->sections[i];
+ for (i = 1; i < s1->nb_sections; ++i) {
+ s = s1->sections[i];
if (k == pe_section_class(s))
section_order[o++] = i;
}
@@ -1130,10 +1130,10 @@ static int pe_assign_addresses (struct pe_info *pe)
for (i = 0; i < o; ++i) {
k = section_order[i];
- s = S->sections[k];
+ s = s1->sections[k];
c = pe_section_class(s);
- if ((c == sec_stab || c == sec_stabstr) && 0 == S->do_debug)
+ if ((c == sec_stab || c == sec_stabstr) && 0 == s1->do_debug)
continue;
if (PE_MERGE_DATA && c == sec_bss)
@@ -1164,8 +1164,8 @@ static int pe_assign_addresses (struct pe_info *pe)
if (si)
goto add_section;
- si = tcc_mallocz(pe->S, sizeof *si);
- dynarray_add(pe->S, &pe->sec_info, &pe->sec_count, si);
+ si = tcc_mallocz(sizeof *si);
+ dynarray_add(&pe->sec_info, &pe->sec_count, si);
strcpy(si->name, s->name);
si->cls = c;
@@ -1195,10 +1195,10 @@ add_section:
}
//printf("%08x %05x %08x %s\n", si->sh_addr, si->sh_size, si->pe_flags, s->name);
}
- tcc_free(pe->S, section_order);
+ tcc_free(section_order);
#if 0
- for (i = 1; i < S->nb_sections; ++i) {
- Section *s = S->sections[i];
+ for (i = 1; i < s1->nb_sections; ++i) {
+ Section *s = s1->sections[i];
int type = s->sh_type;
int flags = s->sh_flags;
printf("section %-16s %-10s %08x %04x %s,%s,%s\n",
@@ -1215,14 +1215,14 @@ add_section:
flags & SHF_EXECINSTR ? "exec" : ""
);
}
- S->verbose = 2;
+ s1->verbose = 2;
#endif
return 0;
}
/*----------------------------------------------------------------------------*/
-static int pe_isafunc(TCCState *S, int sym_index)
+static int pe_isafunc(TCCState *s1, int sym_index)
{
Section *sr = text_section->reloc;
ElfW_Rel *rel, *rel_end;
@@ -1250,7 +1250,7 @@ static int pe_check_symbols(struct pe_info *pe)
ElfW(Sym) *sym;
int sym_index, sym_end;
int ret = 0;
- TCCState *S = pe->S;
+ TCCState *s1 = pe->s1;
pe_align_section(text_section, 8);
@@ -1262,7 +1262,7 @@ static int pe_check_symbols(struct pe_info *pe)
const char *name = (char*)symtab_section->link->data + sym->st_name;
unsigned type = ELFW(ST_TYPE)(sym->st_info);
- int imp_sym = pe_find_import(pe->S, sym);
+ int imp_sym = pe_find_import(pe->s1, sym);
struct import_symbol *is;
if (imp_sym <= 0)
@@ -1270,7 +1270,7 @@ static int pe_check_symbols(struct pe_info *pe)
if (type == STT_NOTYPE) {
/* symbols from assembler have no type, find out which */
- if (pe_isafunc(S, sym_index))
+ if (pe_isafunc(s1, sym_index))
type = STT_FUNC;
else
type = STT_OBJECT;
@@ -1289,7 +1289,7 @@ static int pe_check_symbols(struct pe_info *pe)
/* add a helper symbol, will be patched later in
pe_build_imports */
sprintf(buffer, "IAT.%s", name);
- is->iat_index = put_elf_sym(pe->S,
+ is->iat_index = put_elf_sym(
symtab_section, 0, sizeof(DWORD),
ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
0, SHN_UNDEF, buffer);
@@ -1299,13 +1299,13 @@ static int pe_check_symbols(struct pe_info *pe)
/* add the 'jmp IAT[x]' instruction */
#ifdef TCC_TARGET_ARM
- p = section_ptr_add(pe->S, text_section, 8+4); // room for code and address
+ p = section_ptr_add(text_section, 8+4); // room for code and address
write32le(p + 0, 0xE59FC000); // arm code ldr ip, [pc] ; PC+8+0 = 0001xxxx
write32le(p + 4, 0xE59CF000); // arm code ldr pc, [ip]
put_elf_reloc(symtab_section, text_section,
offset + 8, R_XXX_THUNKFIX, is->iat_index); // offset to IAT position
#else
- p = section_ptr_add(pe->S, text_section, 8);
+ p = section_ptr_add(text_section, 8);
write16le(p, 0x25FF);
#ifdef TCC_TARGET_X86_64
write32le(p + 2, (DWORD)-4);
@@ -1336,11 +1336,11 @@ static int pe_check_symbols(struct pe_info *pe)
if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK)
/* STB_WEAK undefined symbols are accepted */
continue;
- tcc_error_noabort(pe->S, "undefined symbol '%s'%s", name,
+ tcc_error_noabort("undefined symbol '%s'%s", name,
imp_sym < 0 ? ", missing __declspec(dllimport)?":"");
ret = -1;
- } else if (pe->S->rdynamic
+ } else if (pe->s1->rdynamic
&& ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
/* if -rdynamic option, then export all non local symbols */
sym->st_other |= ST_PE_EXPORT;
@@ -1473,17 +1473,17 @@ static void pe_print_section(FILE * f, Section * s)
fprintf(f, "\n\n");
}
-static void pe_print_sections(TCCState *S, const char *fname)
+static void pe_print_sections(TCCState *s1, const char *fname)
{
Section *s;
FILE *f;
int i;
f = fopen(fname, "w");
- for (i = 1; i < S->nb_sections; ++i) {
- s = S->sections[i];
+ for (i = 1; i < s1->nb_sections; ++i) {
+ s = s1->sections[i];
pe_print_section(f, s);
}
- pe_print_section(f, S->dynsymtab_section);
+ pe_print_section(f, s1->dynsymtab_section);
fclose(f);
}
#endif
@@ -1492,7 +1492,7 @@ static void pe_print_sections(TCCState *S, const char *fname)
/* helper function for load/store to insert one more indirection */
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
-ST_FUNC SValue *pe_getimport(TCCState* S, SValue *sv, SValue *v2)
+ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2)
{
int r2;
if ((sv->r & (VT_VALMASK|VT_SYM)) != (VT_CONST|VT_SYM) || (sv->r2 != VT_CONST))
@@ -1505,14 +1505,14 @@ ST_FUNC SValue *pe_getimport(TCCState* S, SValue *sv, SValue *v2)
v2->r = VT_CONST | VT_SYM | VT_LVAL;
v2->sym = sv->sym;
- r2 = get_reg(S, RC_INT);
- load(S, r2, v2);
+ r2 = get_reg(RC_INT);
+ load(r2, v2);
v2->r = r2;
if ((uint32_t)sv->c.i) {
- vpushv(S, v2);
- vpushi(S, sv->c.i);
- gen_opi(S, '+');
- *v2 = *S->tccgen_vtop--;
+ vpushv(v2);
+ vpushi(sv->c.i);
+ gen_opi('+');
+ *v2 = *vtop--;
}
v2->type.t = sv->type.t;
v2->r |= sv->r & VT_LVAL;
@@ -1520,10 +1520,10 @@ ST_FUNC SValue *pe_getimport(TCCState* S, SValue *sv, SValue *v2)
}
#endif
-ST_FUNC int pe_putimport(TCCState *S, int dllindex, const char *name, addr_t value)
+ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value)
{
return set_elf_sym(
- S->dynsymtab_section,
+ s1->dynsymtab_section,
value,
dllindex, /* st_size */
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE),
@@ -1533,14 +1533,14 @@ ST_FUNC int pe_putimport(TCCState *S, int dllindex, const char *name, addr_t val
);
}
-static int pe_add_dllref(TCCState *S, const char *dllname)
+static int pe_add_dllref(TCCState *s1, const char *dllname)
{
int i;
- for (i = 0; i < S->nb_loaded_dlls; ++i)
- if (0 == strcmp(S->loaded_dlls[i]->name, dllname))
+ for (i = 0; i < s1->nb_loaded_dlls; ++i)
+ if (0 == strcmp(s1->loaded_dlls[i]->name, dllname))
return i + 1;
- tcc_add_dllref(S, dllname);
- return S->nb_loaded_dlls;
+ tcc_add_dllref(s1, dllname);
+ return s1->nb_loaded_dlls;
}
static int read_mem(int fd, unsigned offset, void *buffer, unsigned len)
@@ -1551,7 +1551,7 @@ static int read_mem(int fd, unsigned offset, void *buffer, unsigned len)
/* ------------------------------------------------------------- */
-static int get_dllexports(TCCState* S, int fd, char **pp)
+static int get_dllexports(int fd, char **pp)
{
int l, i, n, n0, ret;
char *p;
@@ -1618,9 +1618,9 @@ found:
namep += sizeof ptr;
for (l = 0;;) {
if (n+1 >= n0)
- p = tcc_realloc(S, p, n0 = n0 ? n0 * 2 : 256);
+ p = tcc_realloc(p, n0 = n0 ? n0 * 2 : 256);
if (!read_mem(fd, ptr - ref + l++, p + n, 1)) {
- tcc_free(S, p), p = NULL;
+ tcc_free(p), p = NULL;
goto the_end;
}
if (p[n++] == 0)
@@ -1641,7 +1641,7 @@ the_end:
* as generated by 'windres.exe -O coff ...'.
*/
-static int pe_load_res(TCCState *S, int fd)
+static int pe_load_res(TCCState *s1, int fd)
{
struct pe_rsrc_header hdr;
Section *rsrc_section;
@@ -1657,13 +1657,13 @@ static int pe_load_res(TCCState *S, int fd)
|| strcmp((char*)hdr.sectionhdr.Name, ".rsrc") != 0)
goto quit;
- rsrc_section = new_section(S, ".rsrc", SHT_PROGBITS, SHF_ALLOC);
- ptr = section_ptr_add(S, rsrc_section, hdr.sectionhdr.SizeOfRawData);
+ rsrc_section = new_section(s1, ".rsrc", SHT_PROGBITS, SHF_ALLOC);
+ ptr = section_ptr_add(rsrc_section, hdr.sectionhdr.SizeOfRawData);
offs = hdr.sectionhdr.PointerToRawData;
if (!read_mem(fd, offs, ptr, hdr.sectionhdr.SizeOfRawData))
goto quit;
offs = hdr.sectionhdr.PointerToRelocations;
- sym_index = put_elf_sym(S, symtab_section, 0, 0, 0, 0, rsrc_section->sh_num, ".rsrc");
+ sym_index = put_elf_sym(symtab_section, 0, 0, 0, 0, rsrc_section->sh_num, ".rsrc");
for (i = 0; i < hdr.sectionhdr.NumberOfRelocations; ++i) {
struct pe_rsrc_reloc rel;
if (!read_mem(fd, offs, &rel, sizeof rel))
@@ -1709,12 +1709,12 @@ static char *get_token(char **s, char *f)
return p;
}
-static int pe_load_def(TCCState *S, int fd)
+static int pe_load_def(TCCState *s1, int fd)
{
int state = 0, ret = -1, dllindex = 0, ord;
char dllname[80], *buf, *line, *p, *x, next;
- buf = tcc_load_text(S, fd);
+ buf = tcc_load_text(fd);
for (line = buf;; ++line) {
p = get_token(&line, &next);
if (!(*p && *p != ';'))
@@ -1732,7 +1732,7 @@ static int pe_load_def(TCCState *S, int fd)
++state;
break;
case 2:
- dllindex = pe_add_dllref(S, dllname);
+ dllindex = pe_add_dllref(s1, dllname);
++state;
/* fall through */
default:
@@ -1743,7 +1743,7 @@ static int pe_load_def(TCCState *S, int fd)
ord = (int)strtol(x + 1, &x, 10);
}
//printf("token %s ; %s : %d\n", dllname, p, ord);
- pe_putimport(S, dllindex, p, ord);
+ pe_putimport(s1, dllindex, p, ord);
break;
}
skip:
@@ -1754,63 +1754,63 @@ skip:
}
ret = 0;
quit:
- tcc_free(S, buf);
+ tcc_free(buf);
return ret;
}
/* ------------------------------------------------------------- */
-static int pe_load_dll(TCCState *S, int fd, const char *filename)
+static int pe_load_dll(TCCState *s1, int fd, const char *filename)
{
char *p, *q;
int index, ret;
- ret = get_dllexports(S, fd, &p);
+ ret = get_dllexports(fd, &p);
if (ret) {
return -1;
} else if (p) {
- index = pe_add_dllref(S, filename);
+ index = pe_add_dllref(s1, filename);
for (q = p; *q; q += 1 + strlen(q))
- pe_putimport(S, index, q, 0);
- tcc_free(S, p);
+ pe_putimport(s1, index, q, 0);
+ tcc_free(p);
}
return 0;
}
-ST_FUNC int pe_load_file(TCCState *S, int fd, const char *filename)
+ST_FUNC int pe_load_file(struct TCCState *s1, int fd, const char *filename)
{
int ret = -1;
char buf[10];
if (0 == strcmp(tcc_fileextension(filename), ".def"))
- ret = pe_load_def(S, fd);
- else if (pe_load_res(S, fd) == 0)
+ ret = pe_load_def(s1, fd);
+ else if (pe_load_res(s1, fd) == 0)
ret = 0;
else if (read_mem(fd, 0, buf, 4) && 0 == memcmp(buf, "MZ", 2))
- ret = pe_load_dll(S, fd, filename);
+ ret = pe_load_dll(s1, fd, filename);
return ret;
}
-PUB_FUNC int tcc_get_dllexports(TCCState *S, const char *filename, char **pp)
+PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp)
{
int ret, fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
return -1;
- ret = get_dllexports(S, fd, pp);
+ ret = get_dllexports(fd, pp);
close(fd);
return ret;
}
/* ------------------------------------------------------------- */
#ifdef TCC_TARGET_X86_64
-static unsigned pe_add_uwwind_info(TCCState *S)
+static unsigned pe_add_uwwind_info(TCCState *s1)
{
- if (NULL == S->uw_pdata) {
- S->uw_pdata = find_section(S, ".pdata");
- S->uw_pdata->sh_addralign = 4;
+ if (NULL == s1->uw_pdata) {
+ s1->uw_pdata = find_section(s1, ".pdata");
+ s1->uw_pdata->sh_addralign = 4;
}
- if (0 == S->uw_sym)
- S->uw_sym = put_elf_sym(S, symtab_section, 0, 0, 0, 0, text_section->sh_num, ".uw_base");
- if (0 == S->uw_offs) {
+ if (0 == s1->uw_sym)
+ s1->uw_sym = put_elf_sym(symtab_section, 0, 0, 0, 0, text_section->sh_num, ".uw_base");
+ if (0 == s1->uw_offs) {
/* As our functions all have the same stackframe, we use one entry for all */
static const unsigned char uw_info[] = {
0x01, // UBYTE: 3 Version , UBYTE: 5 Flags
@@ -1826,17 +1826,18 @@ static unsigned pe_add_uwwind_info(TCCState *S)
Section *s = text_section;
unsigned char *p;
- section_ptr_add(S, s, -s->data_offset & 3); /* align */
- S->uw_offs = s->data_offset;
- p = section_ptr_add(S, s, sizeof uw_info);
+ section_ptr_add(s, -s->data_offset & 3); /* align */
+ s1->uw_offs = s->data_offset;
+ p = section_ptr_add(s, sizeof uw_info);
memcpy(p, uw_info, sizeof uw_info);
}
- return S->uw_offs;
+ return s1->uw_offs;
}
-ST_FUNC void pe_add_unwind_data(TCCState *S, unsigned start, unsigned end, unsigned stack)
+ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack)
{
+ TCCState *s1 = tcc_state;
Section *pd;
unsigned o, n, d;
struct /* _RUNTIME_FUNCTION */ {
@@ -1845,10 +1846,10 @@ ST_FUNC void pe_add_unwind_data(TCCState *S, unsigned start, unsigned end, unsig
DWORD UnwindData;
} *p;
- d = pe_add_uwwind_info(S);
- pd = S->uw_pdata;
+ d = pe_add_uwwind_info(s1);
+ pd = s1->uw_pdata;
o = pd->data_offset;
- p = section_ptr_add(S, pd, sizeof *p);
+ p = section_ptr_add(pd, sizeof *p);
/* record this function */
p->BeginAddress = start;
@@ -1857,7 +1858,7 @@ ST_FUNC void pe_add_unwind_data(TCCState *S, unsigned start, unsigned end, unsig
/* put relocations on it */
for (n = o + sizeof *p; o < n; o += sizeof p->BeginAddress)
- put_elf_reloc(symtab_section, pd, o, R_XXX_RELATIVE, S->uw_sym);
+ put_elf_reloc(symtab_section, pd, o, R_XXX_RELATIVE, s1->uw_sym);
}
#endif
/* ------------------------------------------------------------- */
@@ -1867,18 +1868,18 @@ ST_FUNC void pe_add_unwind_data(TCCState *S, unsigned start, unsigned end, unsig
#define PE_STDSYM(n,s) "_" n s
#endif
-static void tcc_add_support(TCCState *S, const char *filename)
+static void tcc_add_support(TCCState *s1, const char *filename)
{
- if (tcc_add_dll(S, filename, 0) < 0)
- tcc_error_noabort(S, "%s not found", filename);
+ if (tcc_add_dll(s1, filename, 0) < 0)
+ tcc_error_noabort("%s not found", filename);
}
-static void pe_add_runtime(TCCState *S, struct pe_info *pe)
+static void pe_add_runtime(TCCState *s1, struct pe_info *pe)
{
const char *start_symbol;
int pe_type;
- if (TCC_OUTPUT_DLL == S->output_type) {
+ if (TCC_OUTPUT_DLL == s1->output_type) {
pe_type = PE_DLL;
start_symbol = PE_STDSYM("__dllstart","@12");
} else {
@@ -1901,61 +1902,61 @@ static void pe_add_runtime(TCCState *S, struct pe_info *pe)
pe_type = PE_EXE;
}
- if (TCC_OUTPUT_MEMORY == S->output_type)
+ if (TCC_OUTPUT_MEMORY == s1->output_type)
start_symbol = run_symbol;
}
pe->start_symbol = start_symbol + 1;
- if (!S->leading_underscore || strchr(start_symbol, '@'))
+ if (!s1->leading_underscore || strchr(start_symbol, '@'))
++start_symbol;
#ifdef CONFIG_TCC_BACKTRACE
- if (S->do_backtrace) {
+ if (s1->do_backtrace) {
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check && S->output_type != TCC_OUTPUT_DLL)
- tcc_add_support(S, "bcheck.o");
+ if (s1->do_bounds_check && s1->output_type != TCC_OUTPUT_DLL)
+ tcc_add_support(s1, "bcheck.o");
#endif
- if (S->output_type == TCC_OUTPUT_EXE)
- tcc_add_support(S, "bt-exe.o");
- if (S->output_type == TCC_OUTPUT_DLL)
- tcc_add_support(S, "bt-dll.o");
- if (S->output_type != TCC_OUTPUT_DLL)
- tcc_add_support(S, "bt-log.o");
- if (S->output_type != TCC_OUTPUT_MEMORY)
- tcc_add_btstub(S);
+ if (s1->output_type == TCC_OUTPUT_EXE)
+ tcc_add_support(s1, "bt-exe.o");
+ if (s1->output_type == TCC_OUTPUT_DLL)
+ tcc_add_support(s1, "bt-dll.o");
+ if (s1->output_type != TCC_OUTPUT_DLL)
+ tcc_add_support(s1, "bt-log.o");
+ if (s1->output_type != TCC_OUTPUT_MEMORY)
+ tcc_add_btstub(s1);
}
#endif
/* grab the startup code from libtcc1.a */
#ifdef TCC_IS_NATIVE
- if (TCC_OUTPUT_MEMORY != S->output_type || S->runtime_main)
+ if (TCC_OUTPUT_MEMORY != s1->output_type || s1->runtime_main)
#endif
- set_global_sym(S, start_symbol, NULL, 0);
+ set_global_sym(s1, start_symbol, NULL, 0);
- if (0 == S->nostdlib) {
+ if (0 == s1->nostdlib) {
static const char * const libs[] = {
"msvcrt", "kernel32", "", "user32", "gdi32", NULL
};
const char * const *pp, *p;
if (TCC_LIBTCC1[0])
- tcc_add_support(S, TCC_LIBTCC1);
+ tcc_add_support(s1, TCC_LIBTCC1);
for (pp = libs; 0 != (p = *pp); ++pp) {
if (*p)
- tcc_add_library_err(S, p);
+ tcc_add_library_err(s1, p);
else if (PE_DLL != pe_type && PE_GUI != pe_type)
break;
}
}
/* need this for 'tccelf.c:relocate_sections()' */
- if (TCC_OUTPUT_DLL == S->output_type)
- S->output_type = TCC_OUTPUT_EXE;
- if (TCC_OUTPUT_MEMORY == S->output_type)
+ if (TCC_OUTPUT_DLL == s1->output_type)
+ s1->output_type = TCC_OUTPUT_EXE;
+ if (TCC_OUTPUT_MEMORY == s1->output_type)
pe_type = PE_RUN;
pe->type = pe_type;
}
-static void pe_set_options(TCCState * S, struct pe_info *pe)
+static void pe_set_options(TCCState * s1, struct pe_info *pe)
{
if (PE_DLL == pe->type) {
/* XXX: check if is correct for arm-pe target */
@@ -1978,8 +1979,8 @@ static void pe_set_options(TCCState * S, struct pe_info *pe)
pe->subsystem = 3;
#endif
/* Allow override via -Wl,-subsystem=... option */
- if (S->pe_subsystem != 0)
- pe->subsystem = S->pe_subsystem;
+ if (s1->pe_subsystem != 0)
+ pe->subsystem = s1->pe_subsystem;
/* set default file/section alignment */
if (pe->subsystem == 1) {
@@ -1990,58 +1991,58 @@ static void pe_set_options(TCCState * S, struct pe_info *pe)
pe->file_align = 0x200;
}
- if (S->section_align != 0)
- pe->section_align = S->section_align;
- if (S->pe_file_align != 0)
- pe->file_align = S->pe_file_align;
+ if (s1->section_align != 0)
+ pe->section_align = s1->section_align;
+ if (s1->pe_file_align != 0)
+ pe->file_align = s1->pe_file_align;
if ((pe->subsystem >= 10) && (pe->subsystem <= 12))
pe->imagebase = 0;
- if (S->has_text_addr)
- pe->imagebase = S->text_addr;
+ if (s1->has_text_addr)
+ pe->imagebase = s1->text_addr;
}
-ST_FUNC int pe_output_file(TCCState *S, const char *filename)
+ST_FUNC int pe_output_file(TCCState *s1, const char *filename)
{
int ret;
struct pe_info pe;
memset(&pe, 0, sizeof pe);
pe.filename = filename;
- pe.S = S;
- S->filetype = 0;
+ pe.s1 = s1;
+ s1->filetype = 0;
#ifdef CONFIG_TCC_BCHECK
- tcc_add_bcheck(S);
+ tcc_add_bcheck(s1);
#endif
- tcc_add_pragma_libs(S);
- pe_add_runtime(S, &pe);
- resolve_common_syms(S);
- pe_set_options(S, &pe);
+ tcc_add_pragma_libs(s1);
+ pe_add_runtime(s1, &pe);
+ resolve_common_syms(s1);
+ pe_set_options(s1, &pe);
ret = pe_check_symbols(&pe);
if (ret)
;
else if (filename) {
pe_assign_addresses(&pe);
- relocate_syms(S, S->symtab, 0);
- S->pe_imagebase = pe.imagebase;
- relocate_sections(S);
+ relocate_syms(s1, s1->symtab, 0);
+ s1->pe_imagebase = pe.imagebase;
+ relocate_sections(s1);
pe.start_addr = (DWORD)
- (get_sym_addr(S, pe.start_symbol, 1, 1) - pe.imagebase);
- if (S->nb_errors)
+ (get_sym_addr(s1, pe.start_symbol, 1, 1) - pe.imagebase);
+ if (s1->nb_errors)
ret = -1;
else
ret = pe_write(&pe);
- dynarray_reset(S, &pe.sec_info, &pe.sec_count);
+ dynarray_reset(&pe.sec_info, &pe.sec_count);
} else {
#ifdef TCC_IS_NATIVE
pe.thunk = data_section;
pe_build_imports(&pe);
- S->runtime_main = pe.start_symbol;
+ s1->runtime_main = pe.start_symbol;
#ifdef TCC_TARGET_X86_64
- S->uw_pdata = find_section(S, ".pdata");
+ s1->uw_pdata = find_section(s1, ".pdata");
#endif
#endif
}
@@ -2049,8 +2050,8 @@ ST_FUNC int pe_output_file(TCCState *S, const char *filename)
pe_free_imports(&pe);
#if PE_PRINT_SECTIONS
- if (S->g_debug & 8)
- pe_print_sections(S, "tcc.log");
+ if (s1->g_debug & 8)
+ pe_print_sections(s1, "tcc.log");
#endif
return ret;
}
diff --git a/tccpp.c b/tccpp.c
index 4a73f95..6b828c9 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -24,9 +24,37 @@
/********************************************************/
/* global variables */
+ST_DATA int tok_flags;
+ST_DATA int parse_flags;
+
+ST_DATA struct BufferedFile *file;
+ST_DATA int ch, tok;
+ST_DATA CValue tokc;
+ST_DATA const int *macro_ptr;
+ST_DATA CString tokcstr; /* current parsed string, if any */
+
+/* display benchmark infos */
+ST_DATA int tok_ident;
+ST_DATA TokenSym **table_ident;
+
/* ------------------------------------------------------------------------- */
-static void tok_print(TCCState* S, const char *msg, const int *str);
+static TokenSym *hash_ident[TOK_HASH_SIZE];
+static char token_buf[STRING_MAX_SIZE + 1];
+static CString cstr_buf;
+static CString macro_equal_buf;
+static TokenString tokstr_buf;
+static unsigned char isidnum_table[256 - CH_EOF];
+static int pp_debug_tok, pp_debug_symv;
+static int pp_once;
+static int pp_expr;
+static int pp_counter;
+static void tok_print(const char *msg, const int *str);
+
+static struct TinyAlloc *toksym_alloc;
+static struct TinyAlloc *tokstr_alloc;
+
+static TokenString *macro_stack;
static const char tcc_keywords[] =
#define DEF(id, str) str "\0"
@@ -65,18 +93,18 @@ static const unsigned char tok_two_chars[] =
0
};
-static void next_nomacro(TCCState* S);
+static void next_nomacro(void);
-ST_FUNC void skip(TCCState* S, int c)
+ST_FUNC void skip(int c)
{
- if (S->tccpp_tok != c)
- tcc_error(S, "'%c' expected (got \"%s\")", c, get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
- next(S);
+ if (tok != c)
+ tcc_error("'%c' expected (got \"%s\")", c, get_tok_str(tok, &tokc));
+ next();
}
-ST_FUNC void expect(TCCState* S, const char *msg)
+ST_FUNC void expect(const char *msg)
{
- tcc_error(S, "%s expected", msg);
+ tcc_error("%s expected", msg);
}
/* ------------------------------------------------------------------------- */
@@ -85,20 +113,20 @@ ST_FUNC void expect(TCCState* S, const char *msg)
#define USE_TAL
#ifndef USE_TAL
-#define tal_free(S, al, p) tcc_free(S, p)
-#define tal_realloc(S, al, p, size) tcc_realloc(S, p, size)
-#define tal_new(S, a, b, c)
-#define tal_delete(S, a)
+#define tal_free(al, p) tcc_free(p)
+#define tal_realloc(al, p, size) tcc_realloc(p, size)
+#define tal_new(a,b,c)
+#define tal_delete(a)
#else
#if !defined(MEM_DEBUG)
-#define tal_free(S, al, p) tal_free_impl(S, al, p)
-#define tal_realloc(S, al, p, size) tal_realloc_impl(S, &al, p, size)
+#define tal_free(al, p) tal_free_impl(al, p)
+#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size)
#define TAL_DEBUG_PARAMS
#else
#define TAL_DEBUG 1
//#define TAL_INFO 1 /* collect and dump allocators stats */
-#define tal_free(S, al, p) tal_free_impl(S, al, p, __FILE__, __LINE__)
-#define tal_realloc(S, al, p, size) tal_realloc_impl(S, &al, p, size, __FILE__, __LINE__)
+#define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__)
+#define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__)
#define TAL_DEBUG_PARAMS , const char *file, int line
#define TAL_DEBUG_FILE_LEN 40
#endif
@@ -110,6 +138,21 @@ ST_FUNC void expect(TCCState* S, const char *msg)
#define TOKSTR_TAL_LIMIT 128 /* 32 * sizeof(int) */
#define CSTR_TAL_LIMIT 1024
+typedef struct TinyAlloc {
+ unsigned limit;
+ unsigned size;
+ uint8_t *buffer;
+ uint8_t *p;
+ unsigned nb_allocs;
+ struct TinyAlloc *next, *top;
+#ifdef TAL_INFO
+ unsigned nb_peak;
+ unsigned nb_total;
+ unsigned nb_missed;
+ uint8_t *peak_p;
+#endif
+} TinyAlloc;
+
typedef struct tal_header_t {
unsigned size;
#ifdef TAL_DEBUG
@@ -120,17 +163,17 @@ typedef struct tal_header_t {
/* ------------------------------------------------------------------------- */
-static TinyAlloc *tal_new(TCCState* S, TinyAlloc **pal, unsigned limit, unsigned size)
+static TinyAlloc *tal_new(TinyAlloc **pal, unsigned limit, unsigned size)
{
- TinyAlloc *al = tcc_mallocz(S, sizeof(TinyAlloc));
- al->p = al->buffer = tcc_malloc(S, size);
+ TinyAlloc *al = tcc_mallocz(sizeof(TinyAlloc));
+ al->p = al->buffer = tcc_malloc(size);
al->limit = limit;
al->size = size;
if (pal) *pal = al;
return al;
}
-static void tal_delete(TCCState* S, TinyAlloc *al)
+static void tal_delete(TinyAlloc *al)
{
TinyAlloc *next;
@@ -162,13 +205,13 @@ tail_call:
}
#endif
next = al->next;
- tcc_free(S, al->buffer);
- tcc_free(S, al);
+ tcc_free(al->buffer);
+ tcc_free(al);
al = next;
goto tail_call;
}
-static void tal_free_impl(TCCState* S, TinyAlloc *al, void *p TAL_DEBUG_PARAMS)
+static void tal_free_impl(TinyAlloc *al, void *p TAL_DEBUG_PARAMS)
{
if (!p)
return;
@@ -192,10 +235,10 @@ tail_call:
goto tail_call;
}
else
- tcc_free(S, p);
+ tcc_free(p);
}
-static void *tal_realloc_impl(TCCState* S, TinyAlloc **pal, void *p, unsigned size TAL_DEBUG_PARAMS)
+static void *tal_realloc_impl(TinyAlloc **pal, void *p, unsigned size TAL_DEBUG_PARAMS)
{
tal_header_t *header;
void *ret;
@@ -236,7 +279,7 @@ tail_call:
return ret;
} else if (is_own) {
al->nb_allocs--;
- ret = tal_realloc(S, *pal, 0, size);
+ ret = tal_realloc(*pal, 0, size);
header = (((tal_header_t *)p) - 1);
if (p) memcpy(ret, p, header->size);
#ifdef TAL_DEBUG
@@ -249,7 +292,7 @@ tail_call:
} else {
TinyAlloc *bottom = al, *next = al->top ? al->top : al;
- al = tal_new(S, pal, next->limit, next->size * 2);
+ al = tal_new(pal, next->limit, next->size * 2);
al->next = next;
bottom->top = al;
}
@@ -257,7 +300,7 @@ tail_call:
}
if (is_own) {
al->nb_allocs--;
- ret = tcc_malloc(S, size);
+ ret = tcc_malloc(size);
header = (((tal_header_t *)p) - 1);
if (p) memcpy(ret, p, header->size);
#ifdef TAL_DEBUG
@@ -267,7 +310,7 @@ tail_call:
al = al->next;
goto tail_call;
} else
- ret = tcc_realloc(S, p, size);
+ ret = tcc_realloc(p, size);
#ifdef TAL_INFO
al->nb_missed++;
#endif
@@ -278,7 +321,7 @@ tail_call:
/* ------------------------------------------------------------------------- */
/* CString handling */
-static void cstr_realloc(TCCState* S, CString *cstr, int new_size)
+static void cstr_realloc(CString *cstr, int new_size)
{
int size;
@@ -287,17 +330,17 @@ static void cstr_realloc(TCCState* S, CString *cstr, int new_size)
size = 8; /* no need to allocate a too small first string */
while (size < new_size)
size = size * 2;
- cstr->data = tcc_realloc(S, cstr->data, size);
+ cstr->data = tcc_realloc(cstr->data, size);
cstr->size_allocated = size;
}
/* add a byte */
-ST_INLN void cstr_ccat(TCCState* S, CString *cstr, int ch)
+ST_INLN void cstr_ccat(CString *cstr, int ch)
{
int size;
size = cstr->size + 1;
if (size > cstr->size_allocated)
- cstr_realloc(S, cstr, size);
+ cstr_realloc(cstr, size);
((unsigned char *)cstr->data)[size - 1] = ch;
cstr->size = size;
}
@@ -313,46 +356,46 @@ ST_INLN char *unicode_to_utf8 (char *b, uint32_t Uc)
}
/* add a unicode character expanded into utf8 */
-ST_INLN void cstr_u8cat(TCCState* S, CString *cstr, int ch)
+ST_INLN void cstr_u8cat(CString *cstr, int ch)
{
char buf[4], *e;
e = unicode_to_utf8(buf, (uint32_t)ch);
- cstr_cat(S, cstr, buf, e - buf);
+ cstr_cat(cstr, buf, e - buf);
}
-ST_FUNC void cstr_cat(TCCState* S, CString *cstr, const char *str, int len)
+ST_FUNC void cstr_cat(CString *cstr, const char *str, int len)
{
int size;
if (len <= 0)
len = strlen(str) + 1 + len;
size = cstr->size + len;
if (size > cstr->size_allocated)
- cstr_realloc(S, cstr, size);
+ cstr_realloc(cstr, size);
memmove(((unsigned char *)cstr->data) + cstr->size, str, len);
cstr->size = size;
}
/* add a wide char */
-ST_FUNC void cstr_wccat(TCCState* S, CString *cstr, int ch)
+ST_FUNC void cstr_wccat(CString *cstr, int ch)
{
int size;
size = cstr->size + sizeof(nwchar_t);
if (size > cstr->size_allocated)
- cstr_realloc(S, cstr, size);
+ cstr_realloc(cstr, size);
*(nwchar_t *)(((unsigned char *)cstr->data) + size - sizeof(nwchar_t)) = ch;
cstr->size = size;
}
-ST_FUNC void cstr_new(TCCState* S, CString *cstr)
+ST_FUNC void cstr_new(CString *cstr)
{
memset(cstr, 0, sizeof(CString));
}
/* free string and reset it to NULL */
-ST_FUNC void cstr_free(TCCState* S, CString *cstr)
+ST_FUNC void cstr_free(CString *cstr)
{
- tcc_free(S, cstr->data);
- cstr_new(S, cstr);
+ tcc_free(cstr->data);
+ cstr_new(cstr);
}
/* reset string to empty */
@@ -361,14 +404,14 @@ ST_FUNC void cstr_reset(CString *cstr)
cstr->size = 0;
}
-ST_FUNC int cstr_vprintf(TCCState* S, CString *cstr, const char *fmt, va_list ap)
+ST_FUNC int cstr_vprintf(CString *cstr, const char *fmt, va_list ap)
{
va_list v;
int len, size = 80;
for (;;) {
size += cstr->size;
if (size > cstr->size_allocated)
- cstr_realloc(S, cstr, size);
+ cstr_realloc(cstr, size);
size = cstr->size_allocated - cstr->size;
va_copy(v, ap);
len = vsnprintf((char*)cstr->data + cstr->size, size, fmt, v);
@@ -381,56 +424,56 @@ ST_FUNC int cstr_vprintf(TCCState* S, CString *cstr, const char *fmt, va_list ap
return len;
}
-ST_FUNC int cstr_printf(TCCState* S, CString *cstr, const char *fmt, ...)
+ST_FUNC int cstr_printf(CString *cstr, const char *fmt, ...)
{
va_list ap; int len;
va_start(ap, fmt);
- len = cstr_vprintf(S, cstr, fmt, ap);
+ len = cstr_vprintf(cstr, fmt, ap);
va_end(ap);
return len;
}
/* XXX: unicode ? */
-static void add_char(TCCState* S, CString *cstr, int c)
+static void add_char(CString *cstr, int c)
{
if (c == '\'' || c == '\"' || c == '\\') {
/* XXX: could be more precise if char or string */
- cstr_ccat(S, cstr, '\\');
+ cstr_ccat(cstr, '\\');
}
if (c >= 32 && c <= 126) {
- cstr_ccat(S, cstr, c);
+ cstr_ccat(cstr, c);
} else {
- cstr_ccat(S, cstr, '\\');
+ cstr_ccat(cstr, '\\');
if (c == '\n') {
- cstr_ccat(S, cstr, 'n');
+ cstr_ccat(cstr, 'n');
} else {
- cstr_ccat(S, cstr, '0' + ((c >> 6) & 7));
- cstr_ccat(S, cstr, '0' + ((c >> 3) & 7));
- cstr_ccat(S, cstr, '0' + (c & 7));
+ cstr_ccat(cstr, '0' + ((c >> 6) & 7));
+ cstr_ccat(cstr, '0' + ((c >> 3) & 7));
+ cstr_ccat(cstr, '0' + (c & 7));
}
}
}
/* ------------------------------------------------------------------------- */
/* allocate a new token */
-static TokenSym *tok_alloc_new(TCCState* S, TokenSym **pts, const char *str, int len)
+static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
{
TokenSym *ts, **ptable;
int i;
- if (S->tccpp_tok_ident >= SYM_FIRST_ANOM)
- tcc_error(S, "memory full (symbols)");
+ if (tok_ident >= SYM_FIRST_ANOM)
+ tcc_error("memory full (symbols)");
/* expand token table if needed */
- i = S->tccpp_tok_ident - TOK_IDENT;
+ i = tok_ident - TOK_IDENT;
if ((i % TOK_ALLOC_INCR) == 0) {
- ptable = tcc_realloc(S, S->tccpp_table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
- S->tccpp_table_ident = ptable;
+ ptable = tcc_realloc(table_ident, (i + TOK_ALLOC_INCR) * sizeof(TokenSym *));
+ table_ident = ptable;
}
- ts = tal_realloc(S, S->tccpp_toksym_alloc, 0, sizeof(TokenSym) + len);
- S->tccpp_table_ident[i] = ts;
- ts->tok = S->tccpp_tok_ident++;
+ ts = tal_realloc(toksym_alloc, 0, sizeof(TokenSym) + len);
+ table_ident[i] = ts;
+ ts->tok = tok_ident++;
ts->sym_define = NULL;
ts->sym_label = NULL;
ts->sym_struct = NULL;
@@ -448,7 +491,7 @@ static TokenSym *tok_alloc_new(TCCState* S, TokenSym **pts, const char *str, int
/* find a token and add it if not found */
-ST_FUNC TokenSym *tok_alloc(TCCState* S, const char *str, int len)
+ST_FUNC TokenSym *tok_alloc(const char *str, int len)
{
TokenSym *ts, **pts;
int i;
@@ -459,7 +502,7 @@ ST_FUNC TokenSym *tok_alloc(TCCState* S, const char *str, int len)
h = TOK_HASH_FUNC(h, ((unsigned char *)str)[i]);
h &= (TOK_HASH_SIZE - 1);
- pts = &S->tccpp_hash_ident[h];
+ pts = &hash_ident[h];
for(;;) {
ts = *pts;
if (!ts)
@@ -468,24 +511,24 @@ ST_FUNC TokenSym *tok_alloc(TCCState* S, const char *str, int len)
return ts;
pts = &(ts->hash_next);
}
- return tok_alloc_new(S, pts, str, len);
+ return tok_alloc_new(pts, str, len);
}
-ST_FUNC int tok_alloc_const(TCCState* S, const char *str)
+ST_FUNC int tok_alloc_const(const char *str)
{
- return tok_alloc(S, str, strlen(str))->tok;
+ return tok_alloc(str, strlen(str))->tok;
}
/* XXX: buffer overflow */
/* XXX: float tokens */
-ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv)
+ST_FUNC const char *get_tok_str(int v, CValue *cv)
{
char *p;
int i, len;
- cstr_reset(&S->tccpp_cstr_buf);
- p = S->tccpp_cstr_buf.data;
+ cstr_reset(&cstr_buf);
+ p = cstr_buf.data;
switch(v) {
case TOK_CINT:
@@ -502,44 +545,44 @@ ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv)
#endif
break;
case TOK_LCHAR:
- cstr_ccat(S, &S->tccpp_cstr_buf, 'L');
+ cstr_ccat(&cstr_buf, 'L');
case TOK_CCHAR:
- cstr_ccat(S, &S->tccpp_cstr_buf, '\'');
- add_char(S, &S->tccpp_cstr_buf, cv->i);
- cstr_ccat(S, &S->tccpp_cstr_buf, '\'');
- cstr_ccat(S, &S->tccpp_cstr_buf, '\0');
+ cstr_ccat(&cstr_buf, '\'');
+ add_char(&cstr_buf, cv->i);
+ cstr_ccat(&cstr_buf, '\'');
+ cstr_ccat(&cstr_buf, '\0');
break;
case TOK_PPNUM:
case TOK_PPSTR:
return (char*)cv->str.data;
case TOK_LSTR:
- cstr_ccat(S, &S->tccpp_cstr_buf, 'L');
+ cstr_ccat(&cstr_buf, 'L');
case TOK_STR:
- cstr_ccat(S, &S->tccpp_cstr_buf, '\"');
+ cstr_ccat(&cstr_buf, '\"');
if (v == TOK_STR) {
len = cv->str.size - 1;
for(i=0;i<len;i++)
- add_char(S, &S->tccpp_cstr_buf, ((unsigned char *)cv->str.data)[i]);
+ add_char(&cstr_buf, ((unsigned char *)cv->str.data)[i]);
} else {
len = (cv->str.size / sizeof(nwchar_t)) - 1;
for(i=0;i<len;i++)
- add_char(S, &S->tccpp_cstr_buf, ((nwchar_t *)cv->str.data)[i]);
+ add_char(&cstr_buf, ((nwchar_t *)cv->str.data)[i]);
}
- cstr_ccat(S, &S->tccpp_cstr_buf, '\"');
- cstr_ccat(S, &S->tccpp_cstr_buf, '\0');
+ cstr_ccat(&cstr_buf, '\"');
+ cstr_ccat(&cstr_buf, '\0');
break;
case TOK_CFLOAT:
- cstr_cat(S, &S->tccpp_cstr_buf, "<float>", 0);
+ cstr_cat(&cstr_buf, "<float>", 0);
break;
case TOK_CDOUBLE:
- cstr_cat(S, &S->tccpp_cstr_buf, "<double>", 0);
+ cstr_cat(&cstr_buf, "<double>", 0);
break;
case TOK_CLDOUBLE:
- cstr_cat(S, &S->tccpp_cstr_buf, "<long double>", 0);
+ cstr_cat(&cstr_buf, "<long double>", 0);
break;
case TOK_LINENUM:
- cstr_cat(S, &S->tccpp_cstr_buf, "<linenumber>", 0);
+ cstr_cat(&cstr_buf, "<linenumber>", 0);
break;
/* above tokens have value, the ones below don't */
@@ -566,20 +609,20 @@ ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv)
*p++ = q[0];
*p++ = q[1];
*p = '\0';
- return S->tccpp_cstr_buf.data;
+ return cstr_buf.data;
}
q += 3;
}
if (v >= 127) {
- sprintf(S->tccpp_cstr_buf.data, "<%02x>", v);
- return S->tccpp_cstr_buf.data;
+ sprintf(cstr_buf.data, "<%02x>", v);
+ return cstr_buf.data;
}
addv:
*p++ = v;
case 0: /* nameless anonymous symbol */
*p = '\0';
- } else if (v < S->tccpp_tok_ident) {
- return S->tccpp_table_ident[v - TOK_IDENT]->str;
+ } else if (v < tok_ident) {
+ return table_ident[v - TOK_IDENT]->str;
} else if (v >= SYM_FIRST_ANOM) {
/* special name for anonymous symbol */
sprintf(p, "L.%u", v - SYM_FIRST_ANOM);
@@ -589,14 +632,14 @@ ST_FUNC const char *get_tok_str(TCCState* S, int v, CValue *cv)
}
break;
}
- return S->tccpp_cstr_buf.data;
+ return cstr_buf.data;
}
/* return the current character, handling end of block if necessary
(but not stray) */
-static int handle_eob(TCCState* S)
+static int handle_eob(void)
{
- BufferedFile *bf = S->tccpp_file;
+ BufferedFile *bf = file;
int len;
/* only tries to read if really end of buffer */
@@ -627,28 +670,28 @@ static int handle_eob(TCCState* S)
}
/* read next char from current input file and handle end of input buffer */
-static inline void inp(TCCState* S)
+static inline void inp(void)
{
- S->tccpp_ch = *(++(S->tccpp_file->buf_ptr));
+ ch = *(++(file->buf_ptr));
/* end of buffer/file handling */
- if (S->tccpp_ch == CH_EOB)
- S->tccpp_ch = handle_eob(S);
+ if (ch == CH_EOB)
+ ch = handle_eob();
}
/* handle '\[\r]\n' */
-static int handle_stray_noerror(TCCState* S)
-{
- while (S->tccpp_ch == '\\') {
- inp(S);
- if (S->tccpp_ch == '\n') {
- S->tccpp_file->line_num++;
- inp(S);
- } else if (S->tccpp_ch == '\r') {
- inp(S);
- if (S->tccpp_ch != '\n')
+static int handle_stray_noerror(void)
+{
+ while (ch == '\\') {
+ inp();
+ if (ch == '\n') {
+ file->line_num++;
+ inp();
+ } else if (ch == '\r') {
+ inp();
+ if (ch != '\n')
goto fail;
- S->tccpp_file->line_num++;
- inp(S);
+ file->line_num++;
+ inp();
} else {
fail:
return 1;
@@ -657,32 +700,32 @@ static int handle_stray_noerror(TCCState* S)
return 0;
}
-static void handle_stray(TCCState* S)
+static void handle_stray(void)
{
- if (handle_stray_noerror(S))
- tcc_error(S, "stray '\\' in program");
+ if (handle_stray_noerror())
+ tcc_error("stray '\\' in program");
}
/* skip the stray and handle the \\n case. Output an error if
incorrect char after the stray */
-static int handle_stray1(TCCState* S, uint8_t *p)
+static int handle_stray1(uint8_t *p)
{
int c;
- S->tccpp_file->buf_ptr = p;
- if (p >= S->tccpp_file->buf_end) {
- c = handle_eob(S);
+ file->buf_ptr = p;
+ if (p >= file->buf_end) {
+ c = handle_eob();
if (c != '\\')
return c;
- p = S->tccpp_file->buf_ptr;
+ p = file->buf_ptr;
}
- S->tccpp_ch = *p;
- if (handle_stray_noerror(S)) {
- if (!(S->tccpp_parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
- tcc_error(S, "stray '\\' in program");
- *--S->tccpp_file->buf_ptr = '\\';
+ ch = *p;
+ if (handle_stray_noerror()) {
+ if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
+ tcc_error("stray '\\' in program");
+ *--file->buf_ptr = '\\';
}
- p = S->tccpp_file->buf_ptr;
+ p = file->buf_ptr;
c = *p;
return c;
}
@@ -693,9 +736,9 @@ static int handle_stray1(TCCState* S, uint8_t *p)
p++;\
c = *p;\
if (c == '\\') {\
- S->tccpp_file->buf_ptr = p;\
- c = handle_eob(S);\
- p = S->tccpp_file->buf_ptr;\
+ file->buf_ptr = p;\
+ c = handle_eob();\
+ p = file->buf_ptr;\
}\
}
@@ -705,23 +748,23 @@ static int handle_stray1(TCCState* S, uint8_t *p)
p++;\
c = *p;\
if (c == '\\') {\
- c = handle_stray1(S, p);\
- p = S->tccpp_file->buf_ptr;\
+ c = handle_stray1(p);\
+ p = file->buf_ptr;\
}\
}
/* input with '\[\r]\n' handling. Note that this function cannot
handle other characters after '\', so you cannot call it inside
strings or comments */
-static void minp(TCCState* S)
+static void minp(void)
{
- inp(S);
- if (S->tccpp_ch == '\\')
- handle_stray(S);
+ inp();
+ if (ch == '\\')
+ handle_stray();
}
/* single line C++ comments */
-static uint8_t *parse_line_comment(TCCState* S, uint8_t *p)
+static uint8_t *parse_line_comment(uint8_t *p)
{
int c;
@@ -732,18 +775,18 @@ static uint8_t *parse_line_comment(TCCState* S, uint8_t *p)
if (c == '\n' || c == CH_EOF) {
break;
} else if (c == '\\') {
- S->tccpp_file->buf_ptr = p;
- c = handle_eob(S);
- p = S->tccpp_file->buf_ptr;
+ file->buf_ptr = p;
+ c = handle_eob();
+ p = file->buf_ptr;
if (c == '\\') {
PEEKC_EOB(c, p);
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
PEEKC_EOB(c, p);
} else if (c == '\r') {
PEEKC_EOB(c, p);
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
PEEKC_EOB(c, p);
}
}
@@ -758,7 +801,7 @@ static uint8_t *parse_line_comment(TCCState* S, uint8_t *p)
}
/* C comments */
-static uint8_t *parse_comment(TCCState* S, uint8_t *p)
+static uint8_t *parse_comment(uint8_t *p)
{
int c;
@@ -777,7 +820,7 @@ static uint8_t *parse_comment(TCCState* S, uint8_t *p)
}
/* now we can handle all the cases */
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
p++;
} else if (c == '*') {
p++;
@@ -788,22 +831,22 @@ static uint8_t *parse_comment(TCCState* S, uint8_t *p)
} else if (c == '/') {
goto end_of_comment;
} else if (c == '\\') {
- S->tccpp_file->buf_ptr = p;
- c = handle_eob(S);
- p = S->tccpp_file->buf_ptr;
+ file->buf_ptr = p;
+ c = handle_eob();
+ p = file->buf_ptr;
if (c == CH_EOF)
- tcc_error(S, "unexpected end of file in comment");
+ tcc_error("unexpected end of file in comment");
if (c == '\\') {
/* skip '\[\r]\n', otherwise just skip the stray */
while (c == '\\') {
PEEKC_EOB(c, p);
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
PEEKC_EOB(c, p);
} else if (c == '\r') {
PEEKC_EOB(c, p);
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
PEEKC_EOB(c, p);
}
} else {
@@ -818,11 +861,11 @@ static uint8_t *parse_comment(TCCState* S, uint8_t *p)
after_star: ;
} else {
/* stray, eob or eof */
- S->tccpp_file->buf_ptr = p;
- c = handle_eob(S);
- p = S->tccpp_file->buf_ptr;
+ file->buf_ptr = p;
+ c = handle_eob();
+ p = file->buf_ptr;
if (c == CH_EOF) {
- tcc_error(S, "unexpected end of file in comment");
+ tcc_error("unexpected end of file in comment");
} else if (c == '\\') {
p++;
}
@@ -833,24 +876,24 @@ static uint8_t *parse_comment(TCCState* S, uint8_t *p)
return p;
}
-ST_FUNC int set_idnum(TCCState* S, int c, int val)
+ST_FUNC int set_idnum(int c, int val)
{
- int prev = S->tccpp_isidnum_table[c - CH_EOF];
- S->tccpp_isidnum_table[c - CH_EOF] = val;
+ int prev = isidnum_table[c - CH_EOF];
+ isidnum_table[c - CH_EOF] = val;
return prev;
}
#define cinp minp
-static inline void skip_spaces(TCCState* S)
+static inline void skip_spaces(void)
{
- while (S->tccpp_isidnum_table[S->tccpp_ch - CH_EOF] & IS_SPC)
- cinp(S);
+ while (isidnum_table[ch - CH_EOF] & IS_SPC)
+ cinp();
}
-static inline int check_space(TCCState* S, int t, int *spc)
+static inline int check_space(int t, int *spc)
{
- if (t < 256 && (S->tccpp_isidnum_table[t - CH_EOF] & IS_SPC)) {
+ if (t < 256 && (isidnum_table[t - CH_EOF] & IS_SPC)) {
if (*spc)
return 1;
*spc = 1;
@@ -860,7 +903,7 @@ static inline int check_space(TCCState* S, int t, int *spc)
}
/* parse a string without interpreting escapes */
-static uint8_t *parse_pp_string(TCCState* S, uint8_t *p,
+static uint8_t *parse_pp_string(uint8_t *p,
int sep, CString *str)
{
int c;
@@ -870,51 +913,51 @@ static uint8_t *parse_pp_string(TCCState* S, uint8_t *p,
if (c == sep) {
break;
} else if (c == '\\') {
- S->tccpp_file->buf_ptr = p;
- c = handle_eob(S);
- p = S->tccpp_file->buf_ptr;
+ file->buf_ptr = p;
+ c = handle_eob();
+ p = file->buf_ptr;
if (c == CH_EOF) {
unterminated_string:
/* XXX: indicate line number of start of string */
- tcc_error(S, "missing terminating %c character", sep);
+ tcc_error("missing terminating %c character", sep);
} else if (c == '\\') {
/* escape : just skip \[\r]\n */
PEEKC_EOB(c, p);
if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
p++;
} else if (c == '\r') {
PEEKC_EOB(c, p);
if (c != '\n')
- expect(S, "'\n' after '\r'");
- S->tccpp_file->line_num++;
+ expect("'\n' after '\r'");
+ file->line_num++;
p++;
} else if (c == CH_EOF) {
goto unterminated_string;
} else {
if (str) {
- cstr_ccat(S, str, '\\');
- cstr_ccat(S, str, c);
+ cstr_ccat(str, '\\');
+ cstr_ccat(str, c);
}
p++;
}
}
} else if (c == '\n') {
- S->tccpp_file->line_num++;
+ file->line_num++;
goto add_char;
} else if (c == '\r') {
PEEKC_EOB(c, p);
if (c != '\n') {
if (str)
- cstr_ccat(S, str, '\r');
+ cstr_ccat(str, '\r');
} else {
- S->tccpp_file->line_num++;
+ file->line_num++;
goto add_char;
}
} else {
add_char:
if (str)
- cstr_ccat(S, str, c);
+ cstr_ccat(str, c);
p++;
}
}
@@ -924,12 +967,12 @@ static uint8_t *parse_pp_string(TCCState* S, uint8_t *p,
/* skip block of text until #else, #elif or #endif. skip also pairs of
#if/#endif */
-static void preprocess_skip(TCCState* S)
+static void preprocess_skip(void)
{
int a, start_of_line, c, in_warn_or_error;
uint8_t *p;
- p = S->tccpp_file->buf_ptr;
+ p = file->buf_ptr;
a = 0;
redo_start:
start_of_line = 1;
@@ -946,64 +989,64 @@ redo_start:
p++;
goto redo_no_start;
case '\n':
- S->tccpp_file->line_num++;
+ file->line_num++;
p++;
goto redo_start;
case '\\':
- S->tccpp_file->buf_ptr = p;
- c = handle_eob(S);
+ file->buf_ptr = p;
+ c = handle_eob();
if (c == CH_EOF) {
- expect(S, "#endif");
+ expect("#endif");
} else if (c == '\\') {
- S->tccpp_ch = S->tccpp_file->buf_ptr[0];
- handle_stray_noerror(S);
+ ch = file->buf_ptr[0];
+ handle_stray_noerror();
}
- p = S->tccpp_file->buf_ptr;
+ p = file->buf_ptr;
goto redo_no_start;
/* skip strings */
case '\"':
case '\'':
if (in_warn_or_error)
goto _default;
- p = parse_pp_string(S, p, c, NULL);
+ p = parse_pp_string(p, c, NULL);
break;
/* skip comments */
case '/':
if (in_warn_or_error)
goto _default;
- S->tccpp_file->buf_ptr = p;
- S->tccpp_ch = *p;
- minp(S);
- p = S->tccpp_file->buf_ptr;
- if (S->tccpp_ch == '*') {
- p = parse_comment(S, p);
- } else if (S->tccpp_ch == '/') {
- p = parse_line_comment(S, p);
+ file->buf_ptr = p;
+ ch = *p;
+ minp();
+ p = file->buf_ptr;
+ if (ch == '*') {
+ p = parse_comment(p);
+ } else if (ch == '/') {
+ p = parse_line_comment(p);
}
break;
case '#':
p++;
if (start_of_line) {
- S->tccpp_file->buf_ptr = p;
- next_nomacro(S);
- p = S->tccpp_file->buf_ptr;
+ file->buf_ptr = p;
+ next_nomacro();
+ p = file->buf_ptr;
if (a == 0 &&
- (S->tccpp_tok == TOK_ELSE || S->tccpp_tok == TOK_ELIF || S->tccpp_tok == TOK_ENDIF))
+ (tok == TOK_ELSE || tok == TOK_ELIF || tok == TOK_ENDIF))
goto the_end;
- if (S->tccpp_tok == TOK_IF || S->tccpp_tok == TOK_IFDEF || S->tccpp_tok == TOK_IFNDEF)
+ if (tok == TOK_IF || tok == TOK_IFDEF || tok == TOK_IFNDEF)
a++;
- else if (S->tccpp_tok == TOK_ENDIF)
+ else if (tok == TOK_ENDIF)
a--;
- else if( S->tccpp_tok == TOK_ERROR || S->tccpp_tok == TOK_WARNING)
+ else if( tok == TOK_ERROR || tok == TOK_WARNING)
in_warn_or_error = 1;
- else if (S->tccpp_tok == TOK_LINEFEED)
+ else if (tok == TOK_LINEFEED)
goto redo_start;
- else if (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
- p = parse_line_comment(S, p - 1);
+ else if (parse_flags & PARSE_FLAG_ASM_FILE)
+ p = parse_line_comment(p - 1);
}
#if !defined(TCC_TARGET_ARM)
- else if (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
- p = parse_line_comment(S, p - 1);
+ else if (parse_flags & PARSE_FLAG_ASM_FILE)
+ p = parse_line_comment(p - 1);
#else
/* ARM assembly uses '#' for constants */
#endif
@@ -1016,7 +1059,7 @@ _default:
start_of_line = 0;
}
the_end: ;
- S->tccpp_file->buf_ptr = p;
+ file->buf_ptr = p;
}
#if 0
@@ -1062,34 +1105,34 @@ ST_INLN void tok_str_new(TokenString *s)
s->last_line_num = -1;
}
-ST_FUNC TokenString *tok_str_alloc(TCCState* S)
+ST_FUNC TokenString *tok_str_alloc(void)
{
- TokenString *str = tal_realloc(S, S->tccpp_tokstr_alloc, 0, sizeof *str);
+ TokenString *str = tal_realloc(tokstr_alloc, 0, sizeof *str);
tok_str_new(str);
return str;
}
-ST_FUNC int *tok_str_dup(TCCState* S, TokenString *s)
+ST_FUNC int *tok_str_dup(TokenString *s)
{
int *str;
- str = tal_realloc(S, S->tccpp_tokstr_alloc, 0, s->len * sizeof(int));
+ str = tal_realloc(tokstr_alloc, 0, s->len * sizeof(int));
memcpy(str, s->str, s->len * sizeof(int));
return str;
}
-ST_FUNC void tok_str_free_str(TCCState* S, int *str)
+ST_FUNC void tok_str_free_str(int *str)
{
- tal_free(S, S->tccpp_tokstr_alloc, str);
+ tal_free(tokstr_alloc, str);
}
-ST_FUNC void tok_str_free(TCCState* S, TokenString *str)
+ST_FUNC void tok_str_free(TokenString *str)
{
- tok_str_free_str(S, str->str);
- tal_free(S, S->tccpp_tokstr_alloc, str);
+ tok_str_free_str(str->str);
+ tal_free(tokstr_alloc, str);
}
-ST_FUNC int *tok_str_realloc(TCCState* S, TokenString *s, int new_size)
+ST_FUNC int *tok_str_realloc(TokenString *s, int new_size)
{
int *str, size;
@@ -1099,49 +1142,49 @@ ST_FUNC int *tok_str_realloc(TCCState* S, TokenString *s, int new_size)
while (size < new_size)
size = size * 2;
if (size > s->allocated_len) {
- str = tal_realloc(S, S->tccpp_tokstr_alloc, s->str, size * sizeof(int));
+ str = tal_realloc(tokstr_alloc, s->str, size * sizeof(int));
s->allocated_len = size;
s->str = str;
}
return s->str;
}
-ST_FUNC void tok_str_add(TCCState* S, TokenString *s, int t)
+ST_FUNC void tok_str_add(TokenString *s, int t)
{
int len, *str;
len = s->len;
str = s->str;
if (len >= s->allocated_len)
- str = tok_str_realloc(S, s, len + 1);
+ str = tok_str_realloc(s, len + 1);
str[len++] = t;
s->len = len;
}
-ST_FUNC void begin_macro(TCCState* S, TokenString *str, int alloc)
+ST_FUNC void begin_macro(TokenString *str, int alloc)
{
str->alloc = alloc;
- str->prev = S->tccpp_macro_stack;
- str->prev_ptr = S->tccpp_macro_ptr;
- str->save_line_num = S->tccpp_file->line_num;
- S->tccpp_macro_ptr = str->str;
- S->tccpp_macro_stack = str;
+ str->prev = macro_stack;
+ str->prev_ptr = macro_ptr;
+ str->save_line_num = file->line_num;
+ macro_ptr = str->str;
+ macro_stack = str;
}
-ST_FUNC void end_macro(TCCState* S)
+ST_FUNC void end_macro(void)
{
- TokenString *str = S->tccpp_macro_stack;
- S->tccpp_macro_stack = str->prev;
- S->tccpp_macro_ptr = str->prev_ptr;
- S->tccpp_file->line_num = str->save_line_num;
+ TokenString *str = macro_stack;
+ macro_stack = str->prev;
+ macro_ptr = str->prev_ptr;
+ file->line_num = str->save_line_num;
if (str->alloc != 0) {
if (str->alloc == 2)
str->str = NULL; /* don't free */
- tok_str_free(S, str);
+ tok_str_free(str);
}
}
-static void tok_str_add2(TCCState* S, TokenString *s, int t, CValue *cv)
+static void tok_str_add2(TokenString *s, int t, CValue *cv)
{
int len, *str;
@@ -1150,7 +1193,7 @@ static void tok_str_add2(TCCState* S, TokenString *s, int t, CValue *cv)
/* allocate space for worst case */
if (len + TOK_MAX_SIZE >= s->allocated_len)
- str = tok_str_realloc(S, s, len + TOK_MAX_SIZE + 1);
+ str = tok_str_realloc(s, len + TOK_MAX_SIZE + 1);
str[len++] = t;
switch(t) {
case TOK_CINT:
@@ -1174,7 +1217,7 @@ static void tok_str_add2(TCCState* S, TokenString *s, int t, CValue *cv)
size_t nb_words =
1 + (cv->str.size + sizeof(int) - 1) / sizeof(int);
if (len + nb_words >= s->allocated_len)
- str = tok_str_realloc(S, s, len + nb_words + 1);
+ str = tok_str_realloc(s, len + nb_words + 1);
str[len] = cv->str.size;
memcpy(&str[len + 1], cv->str.data, cv->str.size);
len += nb_words;
@@ -1215,17 +1258,17 @@ static void tok_str_add2(TCCState* S, TokenString *s, int t, CValue *cv)
}
/* add the current parse token in token string 's' */
-ST_FUNC void tok_str_add_tok(TCCState* S, TokenString *s)
+ST_FUNC void tok_str_add_tok(TokenString *s)
{
CValue cval;
/* save line number info */
- if (S->tccpp_file->line_num != s->last_line_num) {
- s->last_line_num = S->tccpp_file->line_num;
+ if (file->line_num != s->last_line_num) {
+ s->last_line_num = file->line_num;
cval.i = s->last_line_num;
- tok_str_add2(S, s, TOK_LINENUM, &cval);
+ tok_str_add2(s, TOK_LINENUM, &cval);
}
- tok_str_add2(S, s, S->tccpp_tok, &S->tccpp_tokc);
+ tok_str_add2(s, tok, &tokc);
}
/* get a token from an integer array and increment pointer. */
@@ -1304,7 +1347,7 @@ static inline void tok_get(int *t, const int **pp, CValue *cv)
} while (0)
#endif
-static int macro_is_equal(TCCState* S, const int *a, const int *b)
+static int macro_is_equal(const int *a, const int *b)
{
CValue cv;
int t;
@@ -1314,75 +1357,75 @@ static int macro_is_equal(TCCState* S, const int *a, const int *b)
while (*a && *b) {
/* first time preallocate macro_equal_buf, next time only reset position to start */
- cstr_reset(&S->tccpp_macro_equal_buf);
+ cstr_reset(&macro_equal_buf);
TOK_GET(&t, &a, &cv);
- cstr_cat(S, &S->tccpp_macro_equal_buf, get_tok_str(S, t, &cv), 0);
+ cstr_cat(&macro_equal_buf, get_tok_str(t, &cv), 0);
TOK_GET(&t, &b, &cv);
- if (strcmp(S->tccpp_macro_equal_buf.data, get_tok_str(S, t, &cv)))
+ if (strcmp(macro_equal_buf.data, get_tok_str(t, &cv)))
return 0;
}
return !(*a || *b);
}
/* defines handling */
-ST_INLN void define_push(TCCState* S, int v, int macro_type, int *str, Sym *first_arg)
+ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
{
Sym *s, *o;
- o = define_find(S, v);
- s = sym_push2(S, &S->tccgen_define_stack, v, macro_type, 0);
+ o = define_find(v);
+ s = sym_push2(&define_stack, v, macro_type, 0);
s->d = str;
s->next = first_arg;
- S->tccpp_table_ident[v - TOK_IDENT]->sym_define = s;
+ table_ident[v - TOK_IDENT]->sym_define = s;
- if (o && !macro_is_equal(S, o->d, s->d))
- tcc_warning(S, "%s redefined", get_tok_str(S, v, NULL));
+ if (o && !macro_is_equal(o->d, s->d))
+ tcc_warning("%s redefined", get_tok_str(v, NULL));
}
/* undefined a define symbol. Its name is just set to zero */
-ST_FUNC void define_undef(TCCState* S, Sym *s)
+ST_FUNC void define_undef(Sym *s)
{
int v = s->v;
- if (v >= TOK_IDENT && v < S->tccpp_tok_ident)
- S->tccpp_table_ident[v - TOK_IDENT]->sym_define = NULL;
+ if (v >= TOK_IDENT && v < tok_ident)
+ table_ident[v - TOK_IDENT]->sym_define = NULL;
}
-ST_INLN Sym *define_find(TCCState* S, int v)
+ST_INLN Sym *define_find(int v)
{
v -= TOK_IDENT;
- if ((unsigned)v >= (unsigned)(S->tccpp_tok_ident - TOK_IDENT))
+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
- return S->tccpp_table_ident[v]->sym_define;
+ return table_ident[v]->sym_define;
}
/* free define stack until top reaches 'b' */
-ST_FUNC void free_defines(TCCState* S, Sym *b)
-{
- while (S->tccgen_define_stack != b) {
- Sym *top = S->tccgen_define_stack;
- S->tccgen_define_stack = top->prev;
- tok_str_free_str(S, top->d);
- define_undef(S, top);
- sym_free(S, top);
+ST_FUNC void free_defines(Sym *b)
+{
+ while (define_stack != b) {
+ Sym *top = define_stack;
+ define_stack = top->prev;
+ tok_str_free_str(top->d);
+ define_undef(top);
+ sym_free(top);
}
}
/* label lookup */
-ST_FUNC Sym *label_find(TCCState* S, int v)
+ST_FUNC Sym *label_find(int v)
{
v -= TOK_IDENT;
- if ((unsigned)v >= (unsigned)(S->tccpp_tok_ident - TOK_IDENT))
+ if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
return NULL;
- return S->tccpp_table_ident[v]->sym_label;
+ return table_ident[v]->sym_label;
}
-ST_FUNC Sym *label_push(TCCState* S, Sym **ptop, int v, int flags)
+ST_FUNC Sym *label_push(Sym **ptop, int v, int flags)
{
Sym *s, **ps;
- s = sym_push2(S, ptop, v, 0, 0);
+ s = sym_push2(ptop, v, 0, 0);
s->r = flags;
- ps = &S->tccpp_table_ident[v - TOK_IDENT]->sym_label;
- if (ptop == &S->tccgen_global_label_stack) {
+ ps = &table_ident[v - TOK_IDENT]->sym_label;
+ if (ptop == &global_label_stack) {
/* modify the top most local identifier, so that
sym_identifier will point to 's' when popped */
while (*ps != NULL)
@@ -1395,28 +1438,28 @@ ST_FUNC Sym *label_push(TCCState* S, Sym **ptop, int v, int flags)
/* pop labels until element last is reached. Look if any labels are
undefined. Define symbols if '&&label' was used. */
-ST_FUNC void label_pop(TCCState* S, Sym **ptop, Sym *slast, int keep)
+ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep)
{
Sym *s, *s1;
for(s = *ptop; s != slast; s = s1) {
s1 = s->prev;
if (s->r == LABEL_DECLARED) {
- tcc_warning_c(warn_all)(S, "label '%s' declared but not used", get_tok_str(S, s->v, NULL));
+ tcc_warning_c(warn_all)("label '%s' declared but not used", get_tok_str(s->v, NULL));
} else if (s->r == LABEL_FORWARD) {
- tcc_error(S, "label '%s' used but not defined",
- get_tok_str(S, s->v, NULL));
+ tcc_error("label '%s' used but not defined",
+ get_tok_str(s->v, NULL));
} else {
if (s->c) {
/* define corresponding symbol. A size of
1 is put. */
- put_extern_sym(S, s, cur_text_section, s->jnext, 1);
+ put_extern_sym(s, cur_text_section, s->jnext, 1);
}
}
/* remove label */
if (s->r != LABEL_GONE)
- S->tccpp_table_ident[s->v - TOK_IDENT]->sym_label = s->prev_tok;
+ table_ident[s->v - TOK_IDENT]->sym_label = s->prev_tok;
if (!keep)
- sym_free(S, s);
+ sym_free(s);
else
s->r = LABEL_GONE;
}
@@ -1425,93 +1468,93 @@ ST_FUNC void label_pop(TCCState* S, Sym **ptop, Sym *slast, int keep)
}
/* fake the nth "#if defined test_..." for tcc -dt -run */
-static void maybe_run_test(TCCState *S)
+static void maybe_run_test(TCCState *s)
{
const char *p;
- if (S->include_stack_ptr != S->include_stack)
+ if (s->include_stack_ptr != s->include_stack)
return;
- p = get_tok_str(S, S->tccpp_tok, NULL);
+ p = get_tok_str(tok, NULL);
if (0 != memcmp(p, "test_", 5))
return;
- if (0 != --S->run_test)
+ if (0 != --s->run_test)
return;
- fprintf(S->ppfp, &"\n[%s]\n"[!(S->dflag & TCC_OPTION_d_32)], p), fflush(S->ppfp);
- define_push(S, S->tccpp_tok, MACRO_OBJ, NULL, NULL);
+ fprintf(s->ppfp, &"\n[%s]\n"[!(s->dflag & 32)], p), fflush(s->ppfp);
+ define_push(tok, MACRO_OBJ, NULL, NULL);
}
/* eval an expression for #if/#elif */
-static int expr_preprocess(TCCState* S)
+static int expr_preprocess(void)
{
int c, t;
TokenString *str;
- str = tok_str_alloc(S);
- S->tccpp_pp_expr = 1;
- while (S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != TOK_EOF) {
- next(S); /* do macro subst */
+ str = tok_str_alloc();
+ pp_expr = 1;
+ while (tok != TOK_LINEFEED && tok != TOK_EOF) {
+ next(); /* do macro subst */
redo:
- if (S->tccpp_tok == TOK_DEFINED) {
- next_nomacro(S);
- t = S->tccpp_tok;
+ if (tok == TOK_DEFINED) {
+ next_nomacro();
+ t = tok;
if (t == '(')
- next_nomacro(S);
- if (S->tccpp_tok < TOK_IDENT)
- expect(S, "identifier");
- if (S->run_test)
- maybe_run_test(S);
- c = define_find(S, S->tccpp_tok) != 0;
+ next_nomacro();
+ if (tok < TOK_IDENT)
+ expect("identifier");
+ if (tcc_state->run_test)
+ maybe_run_test(tcc_state);
+ c = define_find(tok) != 0;
if (t == '(') {
- next_nomacro(S);
- if (S->tccpp_tok != ')')
- expect(S, "')'");
+ next_nomacro();
+ if (tok != ')')
+ expect("')'");
}
- S->tccpp_tok = TOK_CINT;
- S->tccpp_tokc.i = c;
- } else if (1 && S->tccpp_tok == TOK___HAS_INCLUDE) {
- next(S); /* XXX check if correct to use expansion */
- skip(S, '(');
- while (S->tccpp_tok != ')' && S->tccpp_tok != TOK_EOF)
- next(S);
- if (S->tccpp_tok != ')')
- expect(S, "')'");
- S->tccpp_tok = TOK_CINT;
- S->tccpp_tokc.i = 0;
- } else if (S->tccpp_tok >= TOK_IDENT) {
+ tok = TOK_CINT;
+ tokc.i = c;
+ } else if (1 && tok == TOK___HAS_INCLUDE) {
+ next(); /* XXX check if correct to use expansion */
+ skip('(');
+ while (tok != ')' && tok != TOK_EOF)
+ next();
+ if (tok != ')')
+ expect("')'");
+ tok = TOK_CINT;
+ tokc.i = 0;
+ } else if (tok >= TOK_IDENT) {
/* if undefined macro, replace with zero, check for func-like */
- t = S->tccpp_tok;
- S->tccpp_tok = TOK_CINT;
- S->tccpp_tokc.i = 0;
- tok_str_add_tok(S, str);
- next(S);
- if (S->tccpp_tok == '(')
- tcc_error(S, "function-like macro '%s' is not defined",
- get_tok_str(S, t, NULL));
+ t = tok;
+ tok = TOK_CINT;
+ tokc.i = 0;
+ tok_str_add_tok(str);
+ next();
+ if (tok == '(')
+ tcc_error("function-like macro '%s' is not defined",
+ get_tok_str(t, NULL));
goto redo;
}
- tok_str_add_tok(S, str);
+ tok_str_add_tok(str);
}
- S->tccpp_pp_expr = 0;
- tok_str_add(S, str, -1); /* simulate end of file */
- tok_str_add(S, str, 0);
+ pp_expr = 0;
+ tok_str_add(str, -1); /* simulate end of file */
+ tok_str_add(str, 0);
/* now evaluate C constant expression */
- begin_macro(S, str, 1);
- next(S);
- c = expr_const(S);
- end_macro(S);
+ begin_macro(str, 1);
+ next();
+ c = expr_const();
+ end_macro();
return c != 0;
}
/* parse after #define */
-ST_FUNC void parse_define(TCCState* S)
+ST_FUNC void parse_define(void)
{
Sym *s, *first, **ps;
int v, t, varg, is_vaargs, spc;
- int saved_parse_flags = S->tccpp_parse_flags;
+ int saved_parse_flags = parse_flags;
- v = S->tccpp_tok;
+ v = tok;
if (v < TOK_IDENT || v == TOK_DEFINED)
- tcc_error(S, "invalid macro name '%s'", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));
/* XXX: should check if same macro (ANSI) */
first = NULL;
t = MACRO_OBJ;
@@ -1519,81 +1562,81 @@ ST_FUNC void parse_define(TCCState* S)
no line comment with '#' must be ignored. Also for function
macros the argument list must be parsed without '.' being an ID
character. */
- S->tccpp_parse_flags = ((S->tccpp_parse_flags & ~PARSE_FLAG_ASM_FILE) | PARSE_FLAG_SPACES);
+ parse_flags = ((parse_flags & ~PARSE_FLAG_ASM_FILE) | PARSE_FLAG_SPACES);
/* '(' must be just after macro definition for MACRO_FUNC */
- next_nomacro(S);
- S->tccpp_parse_flags &= ~PARSE_FLAG_SPACES;
- if (S->tccpp_tok == '(') {
- int dotid = set_idnum(S, '.', 0);
- next_nomacro(S);
+ next_nomacro();
+ parse_flags &= ~PARSE_FLAG_SPACES;
+ if (tok == '(') {
+ int dotid = set_idnum('.', 0);
+ next_nomacro();
ps = &first;
- if (S->tccpp_tok != ')') for (;;) {
- varg = S->tccpp_tok;
- next_nomacro(S);
+ if (tok != ')') for (;;) {
+ varg = tok;
+ next_nomacro();
is_vaargs = 0;
if (varg == TOK_DOTS) {
varg = TOK___VA_ARGS__;
is_vaargs = 1;
- } else if (S->tccpp_tok == TOK_DOTS && gnu_ext) {
+ } else if (tok == TOK_DOTS && gnu_ext) {
is_vaargs = 1;
- next_nomacro(S);
+ next_nomacro();
}
if (varg < TOK_IDENT)
bad_list:
- tcc_error(S, "bad macro parameter list");
- s = sym_push2(S, &S->tccgen_define_stack, varg | SYM_FIELD, is_vaargs, 0);
+ tcc_error("bad macro parameter list");
+ s = sym_push2(&define_stack, varg | SYM_FIELD, is_vaargs, 0);
*ps = s;
ps = &s->next;
- if (S->tccpp_tok == ')')
+ if (tok == ')')
break;
- if (S->tccpp_tok != ',' || is_vaargs)
+ if (tok != ',' || is_vaargs)
goto bad_list;
- next_nomacro(S);
+ next_nomacro();
}
- S->tccpp_parse_flags |= PARSE_FLAG_SPACES;
- next_nomacro(S);
+ parse_flags |= PARSE_FLAG_SPACES;
+ next_nomacro();
t = MACRO_FUNC;
- set_idnum(S, '.', dotid);
+ set_idnum('.', dotid);
}
- S->tccpp_tokstr_buf.len = 0;
+ tokstr_buf.len = 0;
spc = 2;
- S->tccpp_parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED;
+ parse_flags |= PARSE_FLAG_ACCEPT_STRAYS | PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED;
/* The body of a macro definition should be parsed such that identifiers
are parsed like the file mode determines (i.e. with '.' being an
ID character in asm mode). But '#' should be retained instead of
regarded as line comment leader, so still don't set ASM_FILE
in parse_flags. */
- while (S->tccpp_tok != TOK_LINEFEED && S->tccpp_tok != TOK_EOF) {
+ while (tok != TOK_LINEFEED && tok != TOK_EOF) {
/* remove spaces around ## and after '#' */
- if (TOK_TWOSHARPS == S->tccpp_tok) {
+ if (TOK_TWOSHARPS == tok) {
if (2 == spc)
goto bad_twosharp;
if (1 == spc)
- --S->tccpp_tokstr_buf.len;
+ --tokstr_buf.len;
spc = 3;
- S->tccpp_tok = TOK_PPJOIN;
- } else if ('#' == S->tccpp_tok) {
+ tok = TOK_PPJOIN;
+ } else if ('#' == tok) {
spc = 4;
- } else if (check_space(S, S->tccpp_tok, &spc)) {
+ } else if (check_space(tok, &spc)) {
goto skip;
}
- tok_str_add2(S, &S->tccpp_tokstr_buf, S->tccpp_tok, &S->tccpp_tokc);
+ tok_str_add2(&tokstr_buf, tok, &tokc);
skip:
- next_nomacro(S);
+ next_nomacro();
}
- S->tccpp_parse_flags = saved_parse_flags;
+ parse_flags = saved_parse_flags;
if (spc == 1)
- --S->tccpp_tokstr_buf.len; /* remove trailing space */
- tok_str_add(S, &S->tccpp_tokstr_buf, 0);
+ --tokstr_buf.len; /* remove trailing space */
+ tok_str_add(&tokstr_buf, 0);
if (3 == spc)
bad_twosharp:
- tcc_error(S, "'##' cannot appear at either end of macro");
- define_push(S, v, t, tok_str_dup(S, &S->tccpp_tokstr_buf), first);
+ tcc_error("'##' cannot appear at either end of macro");
+ define_push(v, t, tok_str_dup(&tokstr_buf), first);
}
-static CachedInclude *search_cached_include(TCCState *S, const char *filename, int add)
+static CachedInclude *search_cached_include(TCCState *s1, const char *filename, int add)
{
const unsigned char *s;
unsigned int h;
@@ -1612,11 +1655,11 @@ static CachedInclude *search_cached_include(TCCState *S, const char *filename, i
}
h &= (CACHED_INCLUDES_HASH_SIZE - 1);
- i = S->cached_includes_hash[h];
+ i = s1->cached_includes_hash[h];
for(;;) {
if (i == 0)
break;
- e = S->cached_includes[i - 1];
+ e = s1->cached_includes[i - 1];
if (0 == PATHCMP(e->filename, filename))
return e;
i = e->hash_next;
@@ -1624,224 +1667,225 @@ static CachedInclude *search_cached_include(TCCState *S, const char *filename, i
if (!add)
return NULL;
- e = tcc_malloc(S, sizeof(CachedInclude) + strlen(filename));
+ e = tcc_malloc(sizeof(CachedInclude) + strlen(filename));
strcpy(e->filename, filename);
e->ifndef_macro = e->once = 0;
- dynarray_add(S, &S->cached_includes, &S->nb_cached_includes, e);
+ dynarray_add(&s1->cached_includes, &s1->nb_cached_includes, e);
/* add in hash table */
- e->hash_next = S->cached_includes_hash[h];
- S->cached_includes_hash[h] = S->nb_cached_includes;
+ e->hash_next = s1->cached_includes_hash[h];
+ s1->cached_includes_hash[h] = s1->nb_cached_includes;
#ifdef INC_DEBUG
printf("adding cached '%s'\n", filename);
#endif
return e;
}
-static void pragma_parse(TCCState *S)
+static void pragma_parse(TCCState *s1)
{
- next_nomacro(S);
- if (S->tccpp_tok == TOK_push_macro || S->tccpp_tok == TOK_pop_macro) {
- int t = S->tccpp_tok, v;
+ next_nomacro();
+ if (tok == TOK_push_macro || tok == TOK_pop_macro) {
+ int t = tok, v;
Sym *s;
- if (next(S), S->tccpp_tok != '(')
+ if (next(), tok != '(')
goto pragma_err;
- if (next(S), S->tccpp_tok != TOK_STR)
+ if (next(), tok != TOK_STR)
goto pragma_err;
- v = tok_alloc(S, S->tccpp_tokc.str.data, S->tccpp_tokc.str.size - 1)->tok;
- if (next(S), S->tccpp_tok != ')')
+ v = tok_alloc(tokc.str.data, tokc.str.size - 1)->tok;
+ if (next(), tok != ')')
goto pragma_err;
if (t == TOK_push_macro) {
- while (NULL == (s = define_find(S, v)))
- define_push(S, v, 0, NULL, NULL);
+ while (NULL == (s = define_find(v)))
+ define_push(v, 0, NULL, NULL);
s->type.ref = s; /* set push boundary */
} else {
- for (s = S->tccgen_define_stack; s; s = s->prev)
+ for (s = define_stack; s; s = s->prev)
if (s->v == v && s->type.ref == s) {
s->type.ref = NULL;
break;
}
}
if (s)
- S->tccpp_table_ident[v - TOK_IDENT]->sym_define = s->d ? s : NULL;
+ table_ident[v - TOK_IDENT]->sym_define = s->d ? s : NULL;
else
- tcc_warning(S, "unbalanced #pragma pop_macro");
- S->tccpp_pp_debug_tok = t, S->tccpp_pp_debug_symv = v;
+ tcc_warning("unbalanced #pragma pop_macro");
+ pp_debug_tok = t, pp_debug_symv = v;
- } else if (S->tccpp_tok == TOK_once) {
- search_cached_include(S, S->tccpp_file->filename, 1)->once = S->tccpp_pp_once;
+ } else if (tok == TOK_once) {
+ search_cached_include(s1, file->filename, 1)->once = pp_once;
- } else if (S->output_type == TCC_OUTPUT_PREPROCESS) {
+ } else if (s1->output_type == TCC_OUTPUT_PREPROCESS) {
/* tcc -E: keep pragmas below unchanged */
- unget_tok(S, ' ');
- unget_tok(S, TOK_PRAGMA);
- unget_tok(S, '#');
- unget_tok(S, TOK_LINEFEED);
+ unget_tok(' ');
+ unget_tok(TOK_PRAGMA);
+ unget_tok('#');
+ unget_tok(TOK_LINEFEED);
- } else if (S->tccpp_tok == TOK_pack) {
+ } else if (tok == TOK_pack) {
/* This may be:
#pragma pack(1) // set
#pragma pack() // reset to default
#pragma pack(push) // push current
#pragma pack(push,1) // push & set
#pragma pack(pop) // restore previous */
- next(S);
- skip(S, '(');
- if (S->tccpp_tok == TOK_ASM_pop) {
- next(S);
- if (S->pack_stack_ptr <= S->pack_stack) {
+ next();
+ skip('(');
+ if (tok == TOK_ASM_pop) {
+ next();
+ if (s1->pack_stack_ptr <= s1->pack_stack) {
stk_error:
- tcc_error(S, "out of pack stack");
+ tcc_error("out of pack stack");
}
- S->pack_stack_ptr--;
+ s1->pack_stack_ptr--;
} else {
int val = 0;
- if (S->tccpp_tok != ')') {
- if (S->tccpp_tok == TOK_ASM_push) {
- next(S);
- if (S->pack_stack_ptr >= S->pack_stack + PACK_STACK_SIZE - 1)
+ if (tok != ')') {
+ if (tok == TOK_ASM_push) {
+ next();
+ if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE - 1)
goto stk_error;
- val = *S->pack_stack_ptr++;
- if (S->tccpp_tok != ',')
+ val = *s1->pack_stack_ptr++;
+ if (tok != ',')
goto pack_set;
- next(S);
+ next();
}
- if (S->tccpp_tok != TOK_CINT)
+ if (tok != TOK_CINT)
goto pragma_err;
- val = S->tccpp_tokc.i;
+ val = tokc.i;
if (val < 1 || val > 16 || (val & (val - 1)) != 0)
goto pragma_err;
- next(S);
+ next();
}
pack_set:
- *S->pack_stack_ptr = val;
+ *s1->pack_stack_ptr = val;
}
- if (S->tccpp_tok != ')')
+ if (tok != ')')
goto pragma_err;
- } else if (S->tccpp_tok == TOK_comment) {
+ } else if (tok == TOK_comment) {
char *p; int t;
- next(S);
- skip(S, '(');
- t = S->tccpp_tok;
- next(S);
- skip(S, ',');
- if (S->tccpp_tok != TOK_STR)
+ next();
+ skip('(');
+ t = tok;
+ next();
+ skip(',');
+ if (tok != TOK_STR)
goto pragma_err;
- p = tcc_strdup(S, (char *)S->tccpp_tokc.str.data);
- next(S);
- if (S->tccpp_tok != ')')
+ p = tcc_strdup((char *)tokc.str.data);
+ next();
+ if (tok != ')')
goto pragma_err;
if (t == TOK_lib) {
- dynarray_add(S, &S->pragma_libs, &S->nb_pragma_libs, p);
+ dynarray_add(&s1->pragma_libs, &s1->nb_pragma_libs, p);
} else {
if (t == TOK_option)
- tcc_set_options(S, p);
- tcc_free(S, p);
+ tcc_set_options(s1, p);
+ tcc_free(p);
}
} else
- tcc_warning_c(warn_unsupported)(S, "#pragma %s ignored", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_warning_c(warn_unsupported)("#pragma %s ignored", get_tok_str(tok, &tokc));
return;
pragma_err:
- tcc_error(S, "malformed #pragma directive");
+ tcc_error("malformed #pragma directive");
return;
}
/* is_bof is true if first non space token at beginning of file */
-ST_FUNC void preprocess(TCCState* S, int is_bof)
+ST_FUNC void preprocess(int is_bof)
{
+ TCCState *s1 = tcc_state;
int i, c, n, saved_parse_flags;
char buf[1024], *q;
Sym *s;
- saved_parse_flags = S->tccpp_parse_flags;
- S->tccpp_parse_flags = PARSE_FLAG_PREPROCESS
+ saved_parse_flags = parse_flags;
+ parse_flags = PARSE_FLAG_PREPROCESS
| PARSE_FLAG_TOK_NUM
| PARSE_FLAG_TOK_STR
| PARSE_FLAG_LINEFEED
- | (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
+ | (parse_flags & PARSE_FLAG_ASM_FILE)
;
- next_nomacro(S);
+ next_nomacro();
redo:
- switch(S->tccpp_tok) {
+ switch(tok) {
case TOK_DEFINE:
- S->tccpp_pp_debug_tok = S->tccpp_tok;
- next_nomacro(S);
- S->tccpp_pp_debug_symv = S->tccpp_tok;
- parse_define(S);
+ pp_debug_tok = tok;
+ next_nomacro();
+ pp_debug_symv = tok;
+ parse_define();
break;
case TOK_UNDEF:
- S->tccpp_pp_debug_tok = S->tccpp_tok;
- next_nomacro(S);
- S->tccpp_pp_debug_symv = S->tccpp_tok;
- s = define_find(S, S->tccpp_tok);
+ pp_debug_tok = tok;
+ next_nomacro();
+ pp_debug_symv = tok;
+ s = define_find(tok);
/* undefine symbol by putting an invalid name */
if (s)
- define_undef(S, s);
+ define_undef(s);
break;
case TOK_INCLUDE:
case TOK_INCLUDE_NEXT:
- S->tccpp_ch = S->tccpp_file->buf_ptr[0];
+ ch = file->buf_ptr[0];
/* XXX: incorrect if comments : use next_nomacro with a special mode */
- skip_spaces(S);
- if (S->tccpp_ch == '<') {
+ skip_spaces();
+ if (ch == '<') {
c = '>';
goto read_name;
- } else if (S->tccpp_ch == '\"') {
- c = S->tccpp_ch;
+ } else if (ch == '\"') {
+ c = ch;
read_name:
- inp(S);
+ inp();
q = buf;
- while (S->tccpp_ch != c && S->tccpp_ch != '\n' && S->tccpp_ch != CH_EOF) {
+ while (ch != c && ch != '\n' && ch != CH_EOF) {
if ((q - buf) < sizeof(buf) - 1)
- *q++ = S->tccpp_ch;
- if (S->tccpp_ch == '\\') {
- if (handle_stray_noerror(S) == 0)
+ *q++ = ch;
+ if (ch == '\\') {
+ if (handle_stray_noerror() == 0)
--q;
} else
- inp(S);
+ inp();
}
*q = '\0';
- minp(S);
+ minp();
#if 0
/* eat all spaces and comments after include */
/* XXX: slightly incorrect */
while (ch1 != '\n' && ch1 != CH_EOF)
- inp(S);
+ inp();
#endif
} else {
int len;
/* computed #include : concatenate everything up to linefeed,
the result must be one of the two accepted forms.
Don't convert pp-tokens to tokens here. */
- S->tccpp_parse_flags = (PARSE_FLAG_PREPROCESS
+ parse_flags = (PARSE_FLAG_PREPROCESS
| PARSE_FLAG_LINEFEED
- | (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE));
- next(S);
+ | (parse_flags & PARSE_FLAG_ASM_FILE));
+ next();
buf[0] = '\0';
- while (S->tccpp_tok != TOK_LINEFEED) {
- pstrcat(buf, sizeof(buf), get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
- next(S);
+ while (tok != TOK_LINEFEED) {
+ pstrcat(buf, sizeof(buf), get_tok_str(tok, &tokc));
+ next();
}
len = strlen(buf);
/* check syntax and remove '<>|""' */
if ((len < 2 || ((buf[0] != '"' || buf[len-1] != '"') &&
(buf[0] != '<' || buf[len-1] != '>'))))
- tcc_error(S, "'#include' expects \"FILENAME\" or <FILENAME>");
+ tcc_error("'#include' expects \"FILENAME\" or <FILENAME>");
c = buf[len-1];
memmove(buf, buf + 1, len - 2);
buf[len - 2] = '\0';
}
- if (S->include_stack_ptr >= S->include_stack + INCLUDE_STACK_SIZE)
- tcc_error(S,"#include recursion too deep");
- i = S->tccpp_tok == TOK_INCLUDE_NEXT ? S->tccpp_file->include_next_index + 1 : 0;
- n = 2 + S->nb_include_paths + S->nb_sysinclude_paths;
+ if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
+ tcc_error("#include recursion too deep");
+ i = tok == TOK_INCLUDE_NEXT ? file->include_next_index + 1 : 0;
+ n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
for (; i < n; ++i) {
- char buf1[sizeof S->tccpp_file->filename];
+ char buf1[sizeof file->filename];
CachedInclude *e;
const char *path;
@@ -1856,182 +1900,182 @@ ST_FUNC void preprocess(TCCState* S, int is_bof)
if (c != '\"')
continue;
/* https://savannah.nongnu.org/bugs/index.php?50847 */
- path = S->tccpp_file->true_filename;
+ path = file->true_filename;
pstrncpy(buf1, path, tcc_basename(path) - path);
} else {
/* search in all the include paths */
- int j = i - 2, k = j - S->nb_include_paths;
- path = k < 0 ? S->include_paths[j] : S->sysinclude_paths[k];
+ int j = i - 2, k = j - s1->nb_include_paths;
+ path = k < 0 ? s1->include_paths[j] : s1->sysinclude_paths[k];
pstrcpy(buf1, sizeof(buf1), path);
pstrcat(buf1, sizeof(buf1), "/");
}
pstrcat(buf1, sizeof(buf1), buf);
- e = search_cached_include(S, buf1, 0);
- if (e && (define_find(S, e->ifndef_macro) || e->once == S->tccpp_pp_once)) {
+ e = search_cached_include(s1, buf1, 0);
+ if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) {
/* no need to parse the include because the 'ifndef macro'
is defined (or had #pragma once) */
#ifdef INC_DEBUG
- printf("%s: skipping cached %s\n", S->tccpp_file->filename, buf1);
+ printf("%s: skipping cached %s\n", file->filename, buf1);
#endif
goto include_done;
}
- if (tcc_open(S, buf1) < 0)
+ if (tcc_open(s1, buf1) < 0)
continue;
/* push previous file on stack */
- *S->include_stack_ptr++ = S->tccpp_file->prev;
- S->tccpp_file->include_next_index = i;
+ *s1->include_stack_ptr++ = file->prev;
+ file->include_next_index = i;
#ifdef INC_DEBUG
- printf("%s: including %s\n", S->tccpp_file->prev->filename, S->tccpp_file->filename);
+ printf("%s: including %s\n", file->prev->filename, file->filename);
#endif
/* update target deps */
- if (S->gen_deps) {
- BufferedFile *bf = S->tccpp_file;
+ if (s1->gen_deps) {
+ BufferedFile *bf = file;
while (i == 1 && (bf = bf->prev))
i = bf->include_next_index;
/* skip system include files */
- if (S->include_sys_deps || n - i > S->nb_sysinclude_paths)
- dynarray_add(S, &S->target_deps, &S->nb_target_deps,
- tcc_strdup(S, buf1));
+ if (s1->include_sys_deps || n - i > s1->nb_sysinclude_paths)
+ dynarray_add(&s1->target_deps, &s1->nb_target_deps,
+ tcc_strdup(buf1));
}
/* add include file debug info */
- tcc_debug_bincl(S);
- S->tccpp_tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
- S->tccpp_ch = S->tccpp_file->buf_ptr[0];
+ tcc_debug_bincl(tcc_state);
+ tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
+ ch = file->buf_ptr[0];
goto the_end;
}
- tcc_error(S,"include file '%s' not found", buf);
+ tcc_error("include file '%s' not found", buf);
include_done:
break;
case TOK_IFNDEF:
c = 1;
goto do_ifdef;
case TOK_IF:
- c = expr_preprocess(S);
+ c = expr_preprocess();
goto do_if;
case TOK_IFDEF:
c = 0;
do_ifdef:
- next_nomacro(S);
- if (S->tccpp_tok < TOK_IDENT)
- tcc_error(S,"invalid argument for '#if%sdef'", c ? "n" : "");
+ next_nomacro();
+ if (tok < TOK_IDENT)
+ tcc_error("invalid argument for '#if%sdef'", c ? "n" : "");
if (is_bof) {
if (c) {
#ifdef INC_DEBUG
- printf("#ifndef %s\n", get_tok_str(S, S->tccpp_tok, NULL));
+ printf("#ifndef %s\n", get_tok_str(tok, NULL));
#endif
- S->tccpp_file->ifndef_macro = S->tccpp_tok;
+ file->ifndef_macro = tok;
}
}
- c = (define_find(S, S->tccpp_tok) != 0) ^ c;
+ c = (define_find(tok) != 0) ^ c;
do_if:
- if (S->ifdef_stack_ptr >= S->ifdef_stack + IFDEF_STACK_SIZE)
- tcc_error(S,"memory full (ifdef)");
- *S->ifdef_stack_ptr++ = c;
+ if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE)
+ tcc_error("memory full (ifdef)");
+ *s1->ifdef_stack_ptr++ = c;
goto test_skip;
case TOK_ELSE:
- if (S->ifdef_stack_ptr == S->ifdef_stack)
- tcc_error(S,"#else without matching #if");
- if (S->ifdef_stack_ptr[-1] & 2)
- tcc_error(S,"#else after #else");
- c = (S->ifdef_stack_ptr[-1] ^= 3);
+ if (s1->ifdef_stack_ptr == s1->ifdef_stack)
+ tcc_error("#else without matching #if");
+ if (s1->ifdef_stack_ptr[-1] & 2)
+ tcc_error("#else after #else");
+ c = (s1->ifdef_stack_ptr[-1] ^= 3);
goto test_else;
case TOK_ELIF:
- if (S->ifdef_stack_ptr == S->ifdef_stack)
- tcc_error(S,"#elif without matching #if");
- c = S->ifdef_stack_ptr[-1];
+ if (s1->ifdef_stack_ptr == s1->ifdef_stack)
+ tcc_error("#elif without matching #if");
+ c = s1->ifdef_stack_ptr[-1];
if (c > 1)
- tcc_error(S,"#elif after #else");
+ tcc_error("#elif after #else");
/* last #if/#elif expression was true: we skip */
if (c == 1) {
c = 0;
} else {
- c = expr_preprocess(S);
- S->ifdef_stack_ptr[-1] = c;
+ c = expr_preprocess();
+ s1->ifdef_stack_ptr[-1] = c;
}
test_else:
- if (S->ifdef_stack_ptr == S->tccpp_file->ifdef_stack_ptr + 1)
- S->tccpp_file->ifndef_macro = 0;
+ if (s1->ifdef_stack_ptr == file->ifdef_stack_ptr + 1)
+ file->ifndef_macro = 0;
test_skip:
if (!(c & 1)) {
- preprocess_skip(S);
+ preprocess_skip();
is_bof = 0;
goto redo;
}
break;
case TOK_ENDIF:
- if (S->ifdef_stack_ptr <= S->tccpp_file->ifdef_stack_ptr)
- tcc_error(S,"#endif without matching #if");
- S->ifdef_stack_ptr--;
+ if (s1->ifdef_stack_ptr <= file->ifdef_stack_ptr)
+ tcc_error("#endif without matching #if");
+ s1->ifdef_stack_ptr--;
/* '#ifndef macro' was at the start of file. Now we check if
an '#endif' is exactly at the end of file */
- if (S->tccpp_file->ifndef_macro &&
- S->ifdef_stack_ptr == S->tccpp_file->ifdef_stack_ptr) {
- S->tccpp_file->ifndef_macro_saved = S->tccpp_file->ifndef_macro;
+ if (file->ifndef_macro &&
+ s1->ifdef_stack_ptr == file->ifdef_stack_ptr) {
+ file->ifndef_macro_saved = file->ifndef_macro;
/* need to set to zero to avoid false matches if another
#ifndef at middle of file */
- S->tccpp_file->ifndef_macro = 0;
- while (S->tccpp_tok != TOK_LINEFEED)
- next_nomacro(S);
- S->tccpp_tok_flags |= TOK_FLAG_ENDIF;
+ file->ifndef_macro = 0;
+ while (tok != TOK_LINEFEED)
+ next_nomacro();
+ tok_flags |= TOK_FLAG_ENDIF;
goto the_end;
}
break;
case TOK_PPNUM:
- n = strtoul((char*)S->tccpp_tokc.str.data, &q, 10);
+ n = strtoul((char*)tokc.str.data, &q, 10);
goto _line_num;
case TOK_LINE:
- next(S);
- if (S->tccpp_tok != TOK_CINT)
+ next();
+ if (tok != TOK_CINT)
_line_err:
- tcc_error(S,"wrong #line format");
- n = S->tccpp_tokc.i;
+ tcc_error("wrong #line format");
+ n = tokc.i;
_line_num:
- next(S);
- if (S->tccpp_tok != TOK_LINEFEED) {
- if (S->tccpp_tok == TOK_STR) {
- if (S->tccpp_file->true_filename == S->tccpp_file->filename)
- S->tccpp_file->true_filename = tcc_strdup(S, S->tccpp_file->filename);
+ next();
+ if (tok != TOK_LINEFEED) {
+ if (tok == TOK_STR) {
+ if (file->true_filename == file->filename)
+ file->true_filename = tcc_strdup(file->filename);
/* prepend directory from real file */
- pstrcpy(buf, sizeof buf, S->tccpp_file->true_filename);
+ pstrcpy(buf, sizeof buf, file->true_filename);
*tcc_basename(buf) = 0;
- pstrcat(buf, sizeof buf, (char *)S->tccpp_tokc.str.data);
- tcc_debug_putfile(S, buf);
- } else if (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
+ pstrcat(buf, sizeof buf, (char *)tokc.str.data);
+ tcc_debug_putfile(s1, buf);
+ } else if (parse_flags & PARSE_FLAG_ASM_FILE)
break;
else
goto _line_err;
--n;
}
- if (S->tccpp_file->fd > 0)
- total_lines += S->tccpp_file->line_num - n;
- S->tccpp_file->line_num = n;
+ if (file->fd > 0)
+ total_lines += file->line_num - n;
+ file->line_num = n;
break;
case TOK_ERROR:
case TOK_WARNING:
- c = S->tccpp_tok;
- S->tccpp_ch = S->tccpp_file->buf_ptr[0];
- skip_spaces(S);
+ c = tok;
+ ch = file->buf_ptr[0];
+ skip_spaces();
q = buf;
- while (S->tccpp_ch != '\n' && S->tccpp_ch != CH_EOF) {
+ while (ch != '\n' && ch != CH_EOF) {
if ((q - buf) < sizeof(buf) - 1)
- *q++ = S->tccpp_ch;
- if (S->tccpp_ch == '\\') {
- if (handle_stray_noerror(S) == 0)
+ *q++ = ch;
+ if (ch == '\\') {
+ if (handle_stray_noerror() == 0)
--q;
} else
- inp(S);
+ inp();
}
*q = '\0';
if (c == TOK_ERROR)
- tcc_error(S,"#error %s", buf);
+ tcc_error("#error %s", buf);
else
- tcc_warning(S,"#warning %s", buf);
+ tcc_warning("#warning %s", buf);
break;
case TOK_PRAGMA:
- pragma_parse(S);
+ pragma_parse(s1);
break;
case TOK_LINEFEED:
goto the_end;
@@ -2039,23 +2083,23 @@ include_done:
/* ignore gas line comment in an 'S' file. */
if (saved_parse_flags & PARSE_FLAG_ASM_FILE)
goto ignore;
- if (S->tccpp_tok == '!' && is_bof)
+ if (tok == '!' && is_bof)
/* '!' is ignored at beginning to allow C scripts. */
goto ignore;
- tcc_warning(S,"Ignoring unknown preprocessing directive #%s", get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ tcc_warning("Ignoring unknown preprocessing directive #%s", get_tok_str(tok, &tokc));
ignore:
- S->tccpp_file->buf_ptr = parse_line_comment(S, S->tccpp_file->buf_ptr - 1);
+ file->buf_ptr = parse_line_comment(file->buf_ptr - 1);
goto the_end;
}
/* ignore other preprocess commands or #! for C scripts */
- while (S->tccpp_tok != TOK_LINEFEED)
- next_nomacro(S);
+ while (tok != TOK_LINEFEED)
+ next_nomacro();
the_end:
- S->tccpp_parse_flags = saved_parse_flags;
+ parse_flags = saved_parse_flags;
}
/* evaluate escape codes in a string. */
-static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf, int is_long)
+static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long)
{
int c, n, i;
const uint8_t *p;
@@ -2102,7 +2146,7 @@ static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf
else if (isnum(c))
c = c - '0';
else if (i > 0)
- expect(S, "more hex digits in universal-character-name");
+ expect("more hex digits in universal-character-name");
else {
c = n;
goto add_char_nonext;
@@ -2110,7 +2154,7 @@ static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf
n = n * 16 + c;
p++;
} while (--i);
- cstr_u8cat(S, outstr, n);
+ cstr_u8cat(outstr, n);
continue;
case 'a':
c = '\a';
@@ -2146,9 +2190,9 @@ static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf
default:
invalid_escape:
if (c >= '!' && c <= '~')
- tcc_warning(S,"unknown escape sequence: \'\\%c\'", c);
+ tcc_warning("unknown escape sequence: \'\\%c\'", c);
else
- tcc_warning(S,"unknown escape sequence: \'\\x%x\'", c);
+ tcc_warning("unknown escape sequence: \'\\x%x\'", c);
break;
}
} else if (is_long && c >= 0x80) {
@@ -2200,7 +2244,7 @@ static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf
/* error handling */
invalid_utf8_sequence:
- tcc_warning(S,"ill-formed UTF-8 subsequence starting with: \'\\x%x\'", c);
+ tcc_warning("ill-formed UTF-8 subsequence starting with: \'\\x%x\'", c);
c = 0xFFFD;
p += skip;
goto add_char_nonext;
@@ -2209,30 +2253,30 @@ static void parse_escape_string(TCCState* S, CString *outstr, const uint8_t *buf
p++;
add_char_nonext:
if (!is_long)
- cstr_ccat(S, outstr, c);
+ cstr_ccat(outstr, c);
else {
#ifdef TCC_TARGET_PE
/* store as UTF-16 */
if (c < 0x10000) {
- cstr_wccat(S, outstr, c);
+ cstr_wccat(outstr, c);
} else {
c -= 0x10000;
- cstr_wccat(S, outstr, (c >> 10) + 0xD800);
- cstr_wccat(S, outstr, (c & 0x3FF) + 0xDC00);
+ cstr_wccat(outstr, (c >> 10) + 0xD800);
+ cstr_wccat(outstr, (c & 0x3FF) + 0xDC00);
}
#else
- cstr_wccat(S, outstr, c);
+ cstr_wccat(outstr, c);
#endif
}
}
/* add a trailing '\0' */
if (!is_long)
- cstr_ccat(S, outstr, '\0');
+ cstr_ccat(outstr, '\0');
else
- cstr_wccat(S, outstr, '\0');
+ cstr_wccat(outstr, '\0');
}
-static void parse_string(TCCState* S, const char *s, int len)
+static void parse_string(const char *s, int len)
{
uint8_t buf[1000], *p = buf;
int is_long, sep;
@@ -2242,41 +2286,41 @@ static void parse_string(TCCState* S, const char *s, int len)
sep = *s++;
len -= 2;
if (len >= sizeof buf)
- p = tcc_malloc(S, len + 1);
+ p = tcc_malloc(len + 1);
memcpy(p, s, len);
p[len] = 0;
- cstr_reset(&S->tccpp_tokcstr);
- parse_escape_string(S, &S->tccpp_tokcstr, p, is_long);
+ cstr_reset(&tokcstr);
+ parse_escape_string(&tokcstr, p, is_long);
if (p != buf)
- tcc_free(S, p);
+ tcc_free(p);
if (sep == '\'') {
int char_size, i, n, c;
/* XXX: make it portable */
if (!is_long)
- S->tccpp_tok = TOK_CCHAR, char_size = 1;
+ tok = TOK_CCHAR, char_size = 1;
else
- S->tccpp_tok = TOK_LCHAR, char_size = sizeof(nwchar_t);
- n = S->tccpp_tokcstr.size / char_size - 1;
+ tok = TOK_LCHAR, char_size = sizeof(nwchar_t);
+ n = tokcstr.size / char_size - 1;
if (n < 1)
- tcc_error(S,"empty character constant");
+ tcc_error("empty character constant");
if (n > 1)
- tcc_warning_c(warn_all)(S,"multi-character character constant");
+ tcc_warning_c(warn_all)("multi-character character constant");
for (c = i = 0; i < n; ++i) {
if (is_long)
- c = ((nwchar_t *)S->tccpp_tokcstr.data)[i];
+ c = ((nwchar_t *)tokcstr.data)[i];
else
- c = (c << 8) | ((char *)S->tccpp_tokcstr.data)[i];
+ c = (c << 8) | ((char *)tokcstr.data)[i];
}
- S->tccpp_tokc.i = c;
+ tokc.i = c;
} else {
- S->tccpp_tokc.str.size = S->tccpp_tokcstr.size;
- S->tccpp_tokc.str.data = S->tccpp_tokcstr.data;
+ tokc.str.size = tokcstr.size;
+ tokc.str.data = tokcstr.data;
if (!is_long)
- S->tccpp_tok = TOK_STR;
+ tok = TOK_STR;
else
- S->tccpp_tok = TOK_LSTR;
+ tok = TOK_LSTR;
}
}
@@ -2305,7 +2349,7 @@ static void bn_zero(unsigned int *bn)
/* parse number in null terminated string 'p' and return it in the
current token */
-static void parse_number(TCCState* S, const char *p)
+static void parse_number(const char *p)
{
int b, t, shift, frac_bits, s, exp_val, ch;
char *q;
@@ -2313,7 +2357,7 @@ static void parse_number(TCCState* S, const char *p)
double d;
/* number */
- q = S->tccpp_token_buf;
+ q = token_buf;
ch = *p++;
t = ch;
ch = *p++;
@@ -2326,7 +2370,7 @@ static void parse_number(TCCState* S, const char *p)
q--;
ch = *p++;
b = 16;
- } else if (S->tcc_ext && (ch == 'b' || ch == 'B')) {
+ } else if (tcc_state->tcc_ext && (ch == 'b' || ch == 'B')) {
q--;
ch = *p++;
b = 2;
@@ -2345,9 +2389,9 @@ static void parse_number(TCCState* S, const char *p)
break;
if (t >= b)
break;
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE) {
+ if (q >= token_buf + STRING_MAX_SIZE) {
num_too_long:
- tcc_error(S,"number too long");
+ tcc_error("number too long");
}
*q++ = ch;
ch = *p++;
@@ -2367,7 +2411,7 @@ static void parse_number(TCCState* S, const char *p)
else
shift = 1;
bn_zero(bn);
- q = S->tccpp_token_buf;
+ q = token_buf;
while (1) {
t = *q++;
if (t == '\0') {
@@ -2396,14 +2440,14 @@ static void parse_number(TCCState* S, const char *p)
break;
}
if (t >= b)
- tcc_error(S,"invalid digit");
+ tcc_error("invalid digit");
bn_lshift(bn, shift, t);
frac_bits += shift;
ch = *p++;
}
}
if (ch != 'p' && ch != 'P')
- expect(S, "exponent");
+ expect("exponent");
ch = *p++;
s = 1;
exp_val = 0;
@@ -2414,7 +2458,7 @@ static void parse_number(TCCState* S, const char *p)
ch = *p++;
}
if (ch < '0' || ch > '9')
- expect(S, "exponent digits");
+ expect("exponent digits");
while (ch >= '0' && ch <= '9') {
exp_val = exp_val * 10 + ch - '0';
ch = *p++;
@@ -2428,53 +2472,53 @@ static void parse_number(TCCState* S, const char *p)
t = toup(ch);
if (t == 'F') {
ch = *p++;
- S->tccpp_tok = TOK_CFLOAT;
+ tok = TOK_CFLOAT;
/* float : should handle overflow */
- S->tccpp_tokc.f = (float)d;
+ tokc.f = (float)d;
} else if (t == 'L') {
ch = *p++;
#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
- S->tccpp_tok = TOK_CDOUBLE;
- S->tccpp_tokc.d = d;
+ tok = TOK_CDOUBLE;
+ tokc.d = d;
#else
- S->tccpp_tok = TOK_CLDOUBLE;
+ tok = TOK_CLDOUBLE;
/* XXX: not large enough */
- S->tccpp_tokc.ld = (long double)d;
+ tokc.ld = (long double)d;
#endif
} else {
- S->tccpp_tok = TOK_CDOUBLE;
- S->tccpp_tokc.d = d;
+ tok = TOK_CDOUBLE;
+ tokc.d = d;
}
} else {
/* decimal floats */
if (ch == '.') {
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE)
+ if (q >= token_buf + STRING_MAX_SIZE)
goto num_too_long;
*q++ = ch;
ch = *p++;
float_frac_parse:
while (ch >= '0' && ch <= '9') {
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE)
+ if (q >= token_buf + STRING_MAX_SIZE)
goto num_too_long;
*q++ = ch;
ch = *p++;
}
}
if (ch == 'e' || ch == 'E') {
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE)
+ if (q >= token_buf + STRING_MAX_SIZE)
goto num_too_long;
*q++ = ch;
ch = *p++;
if (ch == '-' || ch == '+') {
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE)
+ if (q >= token_buf + STRING_MAX_SIZE)
goto num_too_long;
*q++ = ch;
ch = *p++;
}
if (ch < '0' || ch > '9')
- expect(S, "exponent digits");
+ expect("exponent digits");
while (ch >= '0' && ch <= '9') {
- if (q >= S->tccpp_token_buf + STRING_MAX_SIZE)
+ if (q >= token_buf + STRING_MAX_SIZE)
goto num_too_long;
*q++ = ch;
ch = *p++;
@@ -2485,20 +2529,20 @@ static void parse_number(TCCState* S, const char *p)
errno = 0;
if (t == 'F') {
ch = *p++;
- S->tccpp_tok = TOK_CFLOAT;
- S->tccpp_tokc.f = strtof(S->tccpp_token_buf, NULL);
+ tok = TOK_CFLOAT;
+ tokc.f = strtof(token_buf, NULL);
} else if (t == 'L') {
ch = *p++;
#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
- S->tccpp_tok = TOK_CDOUBLE;
- S->tccpp_tokc.d = strtod(S->tccpp_token_buf, NULL);
+ tok = TOK_CDOUBLE;
+ tokc.d = strtod(token_buf, NULL);
#else
- S->tccpp_tok = TOK_CLDOUBLE;
- S->tccpp_tokc.ld = strtold(S->tccpp_token_buf, NULL);
+ tok = TOK_CLDOUBLE;
+ tokc.ld = strtold(token_buf, NULL);
#endif
} else {
- S->tccpp_tok = TOK_CDOUBLE;
- S->tccpp_tokc.d = strtod(S->tccpp_token_buf, NULL);
+ tok = TOK_CDOUBLE;
+ tokc.d = strtod(token_buf, NULL);
}
}
} else {
@@ -2508,7 +2552,7 @@ static void parse_number(TCCState* S, const char *p)
/* integer number */
*q = '\0';
- q = S->tccpp_token_buf;
+ q = token_buf;
if (b == 10 && *q == '0') {
b = 8;
q++;
@@ -2526,7 +2570,7 @@ static void parse_number(TCCState* S, const char *p)
else
t = t - '0';
if (t >= b)
- tcc_error(S,"invalid digit");
+ tcc_error("invalid digit");
n1 = n;
n = n * b + t;
/* detect overflow */
@@ -2542,14 +2586,14 @@ static void parse_number(TCCState* S, const char *p)
t = toup(ch);
if (t == 'L') {
if (lcount >= 2)
- tcc_error(S,"three 'l's in integer constant");
+ tcc_error("three 'l's in integer constant");
if (lcount && *(p - 1) != ch)
- tcc_error(S,"incorrect integer suffix: %s", p1);
+ tcc_error("incorrect integer suffix: %s", p1);
lcount++;
ch = *p++;
} else if (t == 'U') {
if (ucount >= 1)
- tcc_error(S,"two 'u's in integer constant");
+ tcc_error("two 'u's in integer constant");
ucount++;
ch = *p++;
} else {
@@ -2577,20 +2621,20 @@ static void parse_number(TCCState* S, const char *p)
}
if (ov)
- tcc_warning(S, "integer constant overflow");
+ tcc_warning("integer constant overflow");
- S->tccpp_tok = TOK_CINT;
+ tok = TOK_CINT;
if (lcount) {
- S->tccpp_tok = TOK_CLONG;
+ tok = TOK_CLONG;
if (lcount == 2)
- S->tccpp_tok = TOK_CLLONG;
+ tok = TOK_CLLONG;
}
if (ucount)
- ++S->tccpp_tok; /* TOK_CU... */
- S->tccpp_tokc.i = n;
+ ++tok; /* TOK_CU... */
+ tokc.i = n;
}
if (ch)
- tcc_error(S,"invalid number");
+ tcc_error("invalid number");
}
@@ -2599,32 +2643,32 @@ static void parse_number(TCCState* S, const char *p)
PEEKC(c, p); \
if (c == c2) { \
p++; \
- S->tccpp_tok = tok2; \
+ tok = tok2; \
} else { \
- S->tccpp_tok = tok1; \
+ tok = tok1; \
} \
break;
/* return next token without macro substitution */
-static inline void next_nomacro1(TCCState* S)
+static inline void next_nomacro1(void)
{
int t, c, is_long, len;
TokenSym *ts;
uint8_t *p, *p1;
unsigned int h;
- p = S->tccpp_file->buf_ptr;
+ p = file->buf_ptr;
redo_no_start:
c = *p;
switch(c) {
case ' ':
case '\t':
- S->tccpp_tok = c;
+ tok = c;
p++;
maybe_space:
- if (S->tccpp_parse_flags & PARSE_FLAG_SPACES)
+ if (parse_flags & PARSE_FLAG_SPACES)
goto keep_tok_flags;
- while (S->tccpp_isidnum_table[*p - CH_EOF] & IS_SPC)
+ while (isidnum_table[*p - CH_EOF] & IS_SPC)
++p;
goto redo_no_start;
case '\f':
@@ -2634,85 +2678,86 @@ static inline void next_nomacro1(TCCState* S)
goto redo_no_start;
case '\\':
/* first look if it is in fact an end of buffer */
- c = handle_stray1(S, p);
- p = S->tccpp_file->buf_ptr;
+ c = handle_stray1(p);
+ p = file->buf_ptr;
if (c == '\\')
goto parse_simple;
if (c != CH_EOF)
goto redo_no_start;
{
- if ((S->tccpp_parse_flags & PARSE_FLAG_LINEFEED)
- && !(S->tccpp_tok_flags & TOK_FLAG_EOF)) {
- S->tccpp_tok_flags |= TOK_FLAG_EOF;
- S->tccpp_tok = TOK_LINEFEED;
+ TCCState *s1 = tcc_state;
+ if ((parse_flags & PARSE_FLAG_LINEFEED)
+ && !(tok_flags & TOK_FLAG_EOF)) {
+ tok_flags |= TOK_FLAG_EOF;
+ tok = TOK_LINEFEED;
goto keep_tok_flags;
- } else if (!(S->tccpp_parse_flags & PARSE_FLAG_PREPROCESS)) {
- S->tccpp_tok = TOK_EOF;
- } else if (S->ifdef_stack_ptr != S->tccpp_file->ifdef_stack_ptr) {
- tcc_error(S,"missing #endif");
- } else if (S->include_stack_ptr == S->include_stack) {
+ } else if (!(parse_flags & PARSE_FLAG_PREPROCESS)) {
+ tok = TOK_EOF;
+ } else if (s1->ifdef_stack_ptr != file->ifdef_stack_ptr) {
+ tcc_error("missing #endif");
+ } else if (s1->include_stack_ptr == s1->include_stack) {
/* no include left : end of file. */
- S->tccpp_tok = TOK_EOF;
+ tok = TOK_EOF;
} else {
- S->tccpp_tok_flags &= ~TOK_FLAG_EOF;
+ tok_flags &= ~TOK_FLAG_EOF;
/* pop include file */
/* test if previous '#endif' was after a #ifdef at
start of file */
- if (S->tccpp_tok_flags & TOK_FLAG_ENDIF) {
+ if (tok_flags & TOK_FLAG_ENDIF) {
#ifdef INC_DEBUG
- printf("#endif %s\n", get_tok_str(S, S->tccpp_file->ifndef_macro_saved, NULL));
+ printf("#endif %s\n", get_tok_str(file->ifndef_macro_saved, NULL));
#endif
- search_cached_include(S, S->tccpp_file->filename, 1)
- ->ifndef_macro = S->tccpp_file->ifndef_macro_saved;
- S->tccpp_tok_flags &= ~TOK_FLAG_ENDIF;
+ search_cached_include(s1, file->filename, 1)
+ ->ifndef_macro = file->ifndef_macro_saved;
+ tok_flags &= ~TOK_FLAG_ENDIF;
}
/* add end of include file debug info */
- tcc_debug_eincl(S);
+ tcc_debug_eincl(tcc_state);
/* pop include stack */
- tcc_close(S);
- S->include_stack_ptr--;
- p = S->tccpp_file->buf_ptr;
- if (p == S->tccpp_file->buffer)
- S->tccpp_tok_flags = TOK_FLAG_BOF|TOK_FLAG_BOL;
+ tcc_close();
+ s1->include_stack_ptr--;
+ p = file->buf_ptr;
+ if (p == file->buffer)
+ tok_flags = TOK_FLAG_BOF|TOK_FLAG_BOL;
goto redo_no_start;
}
}
break;
case '\n':
- S->tccpp_file->line_num++;
- S->tccpp_tok_flags |= TOK_FLAG_BOL;
+ file->line_num++;
+ tok_flags |= TOK_FLAG_BOL;
p++;
maybe_newline:
- if (0 == (S->tccpp_parse_flags & PARSE_FLAG_LINEFEED))
+ if (0 == (parse_flags & PARSE_FLAG_LINEFEED))
goto redo_no_start;
- S->tccpp_tok = TOK_LINEFEED;
+ tok = TOK_LINEFEED;
goto keep_tok_flags;
case '#':
/* XXX: simplify */
PEEKC(c, p);
- if ((S->tccpp_tok_flags & TOK_FLAG_BOL) &&
- (S->tccpp_parse_flags & PARSE_FLAG_PREPROCESS)) {
- S->tccpp_file->buf_ptr = p;
- preprocess(S, S->tccpp_tok_flags & TOK_FLAG_BOF);
- p = S->tccpp_file->buf_ptr;
+ if ((tok_flags & TOK_FLAG_BOL) &&
+ (parse_flags & PARSE_FLAG_PREPROCESS)) {
+ file->buf_ptr = p;
+ preprocess(tok_flags & TOK_FLAG_BOF);
+ p = file->buf_ptr;
goto maybe_newline;
} else {
if (c == '#') {
p++;
- S->tccpp_tok = TOK_TWOSHARPS;
+ tok = TOK_TWOSHARPS;
} else {
#if !defined(TCC_TARGET_ARM)
- if (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE) {
- p = parse_line_comment(S, p - 1);
+ if (parse_flags & PARSE_FLAG_ASM_FILE) {
+ p = parse_line_comment(p - 1);
goto redo_no_start;
} else
#endif
{
- S->tccpp_tok = '#';
+ tok = '#';
}
}
}
@@ -2720,8 +2765,8 @@ maybe_newline:
/* dollar is allowed to start identifiers when not parsing asm */
case '$':
- if (!(S->tccpp_isidnum_table[c - CH_EOF] & IS_ID)
- || (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE))
+ if (!(isidnum_table[c - CH_EOF] & IS_ID)
+ || (parse_flags & PARSE_FLAG_ASM_FILE))
goto parse_simple;
case 'a': case 'b': case 'c': case 'd':
@@ -2743,7 +2788,7 @@ maybe_newline:
p1 = p;
h = TOK_HASH_INIT;
h = TOK_HASH_FUNC(h, c);
- while (c = *++p, S->tccpp_isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
+ while (c = *++p, isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
h = TOK_HASH_FUNC(h, c);
len = p - p1;
if (c != '\\') {
@@ -2752,7 +2797,7 @@ maybe_newline:
/* fast case : no stray found, so we have the full token
and we have already hashed it */
h &= (TOK_HASH_SIZE - 1);
- pts = &S->tccpp_hash_ident[h];
+ pts = &hash_ident[h];
for(;;) {
ts = *pts;
if (!ts)
@@ -2761,23 +2806,23 @@ maybe_newline:
goto token_found;
pts = &(ts->hash_next);
}
- ts = tok_alloc_new(S, pts, (char *) p1, len);
+ ts = tok_alloc_new(pts, (char *) p1, len);
token_found: ;
} else {
/* slower case */
- cstr_reset(&S->tccpp_tokcstr);
- cstr_cat(S, &S->tccpp_tokcstr, (char *) p1, len);
+ cstr_reset(&tokcstr);
+ cstr_cat(&tokcstr, (char *) p1, len);
p--;
PEEKC(c, p);
parse_ident_slow:
- while (S->tccpp_isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
+ while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
{
- cstr_ccat(S, &S->tccpp_tokcstr, c);
+ cstr_ccat(&tokcstr, c);
PEEKC(c, p);
}
- ts = tok_alloc(S, S->tccpp_tokcstr.data, S->tccpp_tokcstr.size);
+ ts = tok_alloc(tokcstr.data, tokcstr.size);
}
- S->tccpp_tok = ts->tok;
+ tok = ts->tok;
break;
case 'L':
t = p[1];
@@ -2790,8 +2835,8 @@ maybe_newline:
is_long = 1;
goto str_const;
} else {
- cstr_reset(&S->tccpp_tokcstr);
- cstr_ccat(S, &S->tccpp_tokcstr, 'L');
+ cstr_reset(&tokcstr);
+ cstr_ccat(&tokcstr, 'L');
goto parse_ident_slow;
}
}
@@ -2805,27 +2850,27 @@ maybe_newline:
/* after the first digit, accept digits, alpha, '.' or sign if
prefixed by 'eEpP' */
parse_num:
- cstr_reset(&S->tccpp_tokcstr);
+ cstr_reset(&tokcstr);
for(;;) {
- cstr_ccat(S, &S->tccpp_tokcstr, t);
- if (!((S->tccpp_isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
+ cstr_ccat(&tokcstr, t);
+ if (!((isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))
|| c == '.'
|| ((c == '+' || c == '-')
&& (((t == 'e' || t == 'E')
- && !(S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE
+ && !(parse_flags & PARSE_FLAG_ASM_FILE
/* 0xe+1 is 3 tokens in asm */
- && ((char*)S->tccpp_tokcstr.data)[0] == '0'
- && toup(((char*)S->tccpp_tokcstr.data)[1]) == 'X'))
+ && ((char*)tokcstr.data)[0] == '0'
+ && toup(((char*)tokcstr.data)[1]) == 'X'))
|| t == 'p' || t == 'P'))))
break;
t = c;
PEEKC(c, p);
}
/* We add a trailing '\0' to ease parsing */
- cstr_ccat(S, &S->tccpp_tokcstr, '\0');
- S->tccpp_tokc.str.size = S->tccpp_tokcstr.size;
- S->tccpp_tokc.str.data = S->tccpp_tokcstr.data;
- S->tccpp_tok = TOK_PPNUM;
+ cstr_ccat(&tokcstr, '\0');
+ tokc.str.size = tokcstr.size;
+ tokc.str.data = tokcstr.data;
+ tok = TOK_PPNUM;
break;
case '.':
@@ -2834,71 +2879,71 @@ maybe_newline:
if (isnum(c)) {
t = '.';
goto parse_num;
- } else if ((S->tccpp_isidnum_table['.' - CH_EOF] & IS_ID)
- && (S->tccpp_isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) {
+ } else if ((isidnum_table['.' - CH_EOF] & IS_ID)
+ && (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM))) {
*--p = c = '.';
goto parse_ident_fast;
} else if (c == '.') {
PEEKC(c, p);
if (c == '.') {
p++;
- S->tccpp_tok = TOK_DOTS;
+ tok = TOK_DOTS;
} else {
*--p = '.'; /* may underflow into file->unget[] */
- S->tccpp_tok = '.';
+ tok = '.';
}
} else {
- S->tccpp_tok = '.';
+ tok = '.';
}
break;
case '\'':
case '\"':
is_long = 0;
str_const:
- cstr_reset(&S->tccpp_tokcstr);
+ cstr_reset(&tokcstr);
if (is_long)
- cstr_ccat(S, &S->tccpp_tokcstr, 'L');
- cstr_ccat(S, &S->tccpp_tokcstr, c);
- p = parse_pp_string(S, p, c, &S->tccpp_tokcstr);
- cstr_ccat(S, &S->tccpp_tokcstr, c);
- cstr_ccat(S, &S->tccpp_tokcstr, '\0');
- S->tccpp_tokc.str.size = S->tccpp_tokcstr.size;
- S->tccpp_tokc.str.data = S->tccpp_tokcstr.data;
- S->tccpp_tok = TOK_PPSTR;
+ cstr_ccat(&tokcstr, 'L');
+ cstr_ccat(&tokcstr, c);
+ p = parse_pp_string(p, c, &tokcstr);
+ cstr_ccat(&tokcstr, c);
+ cstr_ccat(&tokcstr, '\0');
+ tokc.str.size = tokcstr.size;
+ tokc.str.data = tokcstr.data;
+ tok = TOK_PPSTR;
break;
case '<':
PEEKC(c, p);
if (c == '=') {
p++;
- S->tccpp_tok = TOK_LE;
+ tok = TOK_LE;
} else if (c == '<') {
PEEKC(c, p);
if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_SHL;
+ tok = TOK_A_SHL;
} else {
- S->tccpp_tok = TOK_SHL;
+ tok = TOK_SHL;
}
} else {
- S->tccpp_tok = TOK_LT;
+ tok = TOK_LT;
}
break;
case '>':
PEEKC(c, p);
if (c == '=') {
p++;
- S->tccpp_tok = TOK_GE;
+ tok = TOK_GE;
} else if (c == '>') {
PEEKC(c, p);
if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_SAR;
+ tok = TOK_A_SAR;
} else {
- S->tccpp_tok = TOK_SAR;
+ tok = TOK_SAR;
}
} else {
- S->tccpp_tok = TOK_GT;
+ tok = TOK_GT;
}
break;
@@ -2906,12 +2951,12 @@ maybe_newline:
PEEKC(c, p);
if (c == '&') {
p++;
- S->tccpp_tok = TOK_LAND;
+ tok = TOK_LAND;
} else if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_AND;
+ tok = TOK_A_AND;
} else {
- S->tccpp_tok = '&';
+ tok = '&';
}
break;
@@ -2919,12 +2964,12 @@ maybe_newline:
PEEKC(c, p);
if (c == '|') {
p++;
- S->tccpp_tok = TOK_LOR;
+ tok = TOK_LOR;
} else if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_OR;
+ tok = TOK_A_OR;
} else {
- S->tccpp_tok = '|';
+ tok = '|';
}
break;
@@ -2932,12 +2977,12 @@ maybe_newline:
PEEKC(c, p);
if (c == '+') {
p++;
- S->tccpp_tok = TOK_INC;
+ tok = TOK_INC;
} else if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_ADD;
+ tok = TOK_A_ADD;
} else {
- S->tccpp_tok = '+';
+ tok = '+';
}
break;
@@ -2945,15 +2990,15 @@ maybe_newline:
PEEKC(c, p);
if (c == '-') {
p++;
- S->tccpp_tok = TOK_DEC;
+ tok = TOK_DEC;
} else if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_SUB;
+ tok = TOK_A_SUB;
} else if (c == '>') {
p++;
- S->tccpp_tok = TOK_ARROW;
+ tok = TOK_ARROW;
} else {
- S->tccpp_tok = '-';
+ tok = '-';
}
break;
@@ -2967,19 +3012,19 @@ maybe_newline:
case '/':
PEEKC(c, p);
if (c == '*') {
- p = parse_comment(S, p);
+ p = parse_comment(p);
/* comments replaced by a blank */
- S->tccpp_tok = ' ';
+ tok = ' ';
goto maybe_space;
} else if (c == '/') {
- p = parse_line_comment(S, p);
- S->tccpp_tok = ' ';
+ p = parse_line_comment(p);
+ tok = ' ';
goto maybe_space;
} else if (c == '=') {
p++;
- S->tccpp_tok = TOK_A_DIV;
+ tok = TOK_A_DIV;
} else {
- S->tccpp_tok = '/';
+ tok = '/';
}
break;
@@ -2997,26 +3042,26 @@ maybe_newline:
case '~':
case '@': /* only used in assembler */
parse_simple:
- S->tccpp_tok = c;
+ tok = c;
p++;
break;
default:
if (c >= 0x80 && c <= 0xFF) /* utf8 identifiers */
goto parse_ident_fast;
- if (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
+ if (parse_flags & PARSE_FLAG_ASM_FILE)
goto parse_simple;
- tcc_error(S,"unrecognized character \\x%02x", c);
+ tcc_error("unrecognized character \\x%02x", c);
break;
}
- S->tccpp_tok_flags = 0;
+ tok_flags = 0;
keep_tok_flags:
- S->tccpp_file->buf_ptr = p;
+ file->buf_ptr = p;
#if defined(PARSE_DEBUG)
- printf("token = %d %s\n", S->tccpp_tok, get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc));
+ printf("token = %d %s\n", tok, get_tok_str(tok, &tokc));
#endif
}
-static void macro_subst(TCCState* S,
+static void macro_subst(
TokenString *tok_str,
Sym **nested_list,
const int *macro_str
@@ -3024,7 +3069,7 @@ static void macro_subst(TCCState* S,
/* substitute arguments in replacement lists in macro_str by the values in
args (field d) and return allocated string */
-static int *macro_arg_subst(TCCState* S, Sym **nested_list, const int *macro_str, Sym *args)
+static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args)
{
int t, t0, t1, spc;
const int *st;
@@ -3046,39 +3091,39 @@ static int *macro_arg_subst(TCCState* S, Sym **nested_list, const int *macro_str
goto bad_stringy;
s = sym_find2(args, t);
if (s) {
- cstr_new(S, &cstr);
- cstr_ccat(S, &cstr, '\"');
+ cstr_new(&cstr);
+ cstr_ccat(&cstr, '\"');
st = s->d;
spc = 0;
while (*st >= 0) {
TOK_GET(&t, &st, &cval);
if (t != TOK_PLCHLDR
&& t != TOK_NOSUBST
- && 0 == check_space(S, t, &spc)) {
- const char *s = get_tok_str(S, t, &cval);
+ && 0 == check_space(t, &spc)) {
+ const char *s = get_tok_str(t, &cval);
while (*s) {
if (t == TOK_PPSTR && *s != '\'')
- add_char(S, &cstr, *s);
+ add_char(&cstr, *s);
else
- cstr_ccat(S, &cstr, *s);
+ cstr_ccat(&cstr, *s);
++s;
}
}
}
cstr.size -= spc;
- cstr_ccat(S, &cstr, '\"');
- cstr_ccat(S, &cstr, '\0');
+ cstr_ccat(&cstr, '\"');
+ cstr_ccat(&cstr, '\0');
#ifdef PP_DEBUG
printf("\nstringize: <%s>\n", (char *)cstr.data);
#endif
/* add string */
cval.str.size = cstr.size;
cval.str.data = cstr.data;
- tok_str_add2(S, &str, TOK_PPSTR, &cval);
- cstr_free(S, &cstr);
+ tok_str_add2(&str, TOK_PPSTR, &cval);
+ cstr_free(&cstr);
} else {
bad_stringy:
- expect(S, "macro parameter after '#'");
+ expect("macro parameter after '#'");
}
} else if (t >= TOK_IDENT) {
s = sym_find2(args, t);
@@ -3107,10 +3152,10 @@ static int *macro_arg_subst(TCCState* S, Sym **nested_list, const int *macro_str
used multiple times, but not if the argument
contains the __COUNTER__ macro. */
TokenString str2;
- sym_push2(S, &s->next, s->v, s->type.t, 0);
+ sym_push2(&s->next, s->v, s->type.t, 0);
tok_str_new(&str2);
- macro_subst(S, &str2, nested_list, st);
- tok_str_add(S, &str2, 0);
+ macro_subst(&str2, nested_list, st);
+ tok_str_add(&str2, 0);
s->next->d = str2.str;
}
st = s->next->d;
@@ -3120,19 +3165,19 @@ static int *macro_arg_subst(TCCState* S, Sym **nested_list, const int *macro_str
TOK_GET(&t2, &st, &cval);
if (t2 <= 0)
break;
- tok_str_add2(S, &str, t2, &cval);
+ tok_str_add2(&str, t2, &cval);
}
if (str.len == l0) /* expanded to empty string */
- tok_str_add(S, &str, TOK_PLCHLDR);
+ tok_str_add(&str, TOK_PLCHLDR);
} else {
- tok_str_add(S, &str, t);
+ tok_str_add(&str, t);
}
} else {
- tok_str_add2(S, &str, t, &cval);
+ tok_str_add2(&str, t, &cval);
}
t0 = t1, t1 = t;
}
- tok_str_add(S, &str, 0);
+ tok_str_add(&str, 0);
return str.str;
}
@@ -3142,42 +3187,42 @@ static char const ab_month_name[12][4] =
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
-static int paste_tokens(TCCState* S, int t1, CValue *v1, int t2, CValue *v2)
+static int paste_tokens(int t1, CValue *v1, int t2, CValue *v2)
{
CString cstr;
int n, ret = 1;
- cstr_new(S, &cstr);
+ cstr_new(&cstr);
if (t1 != TOK_PLCHLDR)
- cstr_cat(S, &cstr, get_tok_str(S, t1, v1), -1);
+ cstr_cat(&cstr, get_tok_str(t1, v1), -1);
n = cstr.size;
if (t2 != TOK_PLCHLDR)
- cstr_cat(S, &cstr, get_tok_str(S, t2, v2), -1);
- cstr_ccat(S, &cstr, '\0');
+ cstr_cat(&cstr, get_tok_str(t2, v2), -1);
+ cstr_ccat(&cstr, '\0');
- tcc_open_bf(S, ":paste:", cstr.size);
- memcpy(S->tccpp_file->buffer, cstr.data, cstr.size);
- S->tccpp_tok_flags = 0;
+ tcc_open_bf(tcc_state, ":paste:", cstr.size);
+ memcpy(file->buffer, cstr.data, cstr.size);
+ tok_flags = 0;
for (;;) {
- next_nomacro1(S);
- if (0 == *S->tccpp_file->buf_ptr)
+ next_nomacro1();
+ if (0 == *file->buf_ptr)
break;
- if (is_space(S->tccpp_tok))
+ if (is_space(tok))
continue;
- tcc_warning(S, "pasting \"%.*s\" and \"%s\" does not give a valid"
+ tcc_warning("pasting \"%.*s\" and \"%s\" does not give a valid"
" preprocessing token", n, (char *)cstr.data, (char*)cstr.data + n);
ret = 0;
break;
}
- tcc_close(S);
+ tcc_close();
//printf("paste <%s>\n", (char*)cstr.data);
- cstr_free(S, &cstr);
+ cstr_free(&cstr);
return ret;
}
/* handle the '##' operator. Return NULL if no '##' seen. Otherwise
return the resulting string (which must be freed). */
-static inline int *macro_twosharps(TCCState* S, const int *ptr0)
+static inline int *macro_twosharps(const int *ptr0)
{
int t;
CValue cval;
@@ -3214,10 +3259,10 @@ static inline int *macro_twosharps(TCCState* S, const int *ptr0)
if (t1 && t1 != TOK_PPJOIN) {
TOK_GET(&t1, &ptr, &cv1);
if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {
- if (paste_tokens(S, t, &cval, t1, &cv1)) {
- t = S->tccpp_tok, cval = S->tccpp_tokc;
+ if (paste_tokens(t, &cval, t1, &cv1)) {
+ t = tok, cval = tokc;
} else {
- tok_str_add2(S, &macro_str1, t, &cval);
+ tok_str_add2(&macro_str1, t, &cval);
t = t1, cval = cv1;
}
}
@@ -3229,30 +3274,30 @@ static inline int *macro_twosharps(TCCState* S, const int *ptr0)
} else {
start_of_nosubsts = -1;
}
- tok_str_add2(S, &macro_str1, t, &cval);
+ tok_str_add2(&macro_str1, t, &cval);
}
- tok_str_add(S, &macro_str1, 0);
+ tok_str_add(&macro_str1, 0);
//tok_print(" ###", macro_str1.str);
return macro_str1.str;
}
/* peek or read [ws_str == NULL] next token from function macro call,
walking up macro levels up to the file if necessary */
-static int next_argstream(TCCState* S, Sym **nested_list, TokenString *ws_str)
+static int next_argstream(Sym **nested_list, TokenString *ws_str)
{
int t;
const int *p;
Sym *sa;
for (;;) {
- if (S->tccpp_macro_ptr) {
- p = S->tccpp_macro_ptr, t = *p;
+ if (macro_ptr) {
+ p = macro_ptr, t = *p;
if (ws_str) {
while (is_space(t) || TOK_LINEFEED == t || TOK_PLCHLDR == t)
- tok_str_add(S, ws_str, t), t = *++p;
+ tok_str_add(ws_str, t), t = *++p;
}
if (t == 0) {
- end_macro(S);
+ end_macro();
/* also, end of scope for nested defined symbol */
sa = *nested_list;
while (sa && sa->v == 0)
@@ -3262,37 +3307,37 @@ static int next_argstream(TCCState* S, Sym **nested_list, TokenString *ws_str)
continue;
}
} else {
- S->tccpp_ch = handle_eob(S);
+ ch = handle_eob();
if (ws_str) {
- while (is_space(S->tccpp_ch) || S->tccpp_ch == '\n' || S->tccpp_ch == '/') {
- if (S->tccpp_ch == '/') {
+ while (is_space(ch) || ch == '\n' || ch == '/') {
+ if (ch == '/') {
int c;
- uint8_t *p = S->tccpp_file->buf_ptr;
+ uint8_t *p = file->buf_ptr;
PEEKC(c, p);
if (c == '*') {
- p = parse_comment(S, p);
- S->tccpp_file->buf_ptr = p - 1;
+ p = parse_comment(p);
+ file->buf_ptr = p - 1;
} else if (c == '/') {
- p = parse_line_comment(S, p);
- S->tccpp_file->buf_ptr = p - 1;
+ p = parse_line_comment(p);
+ file->buf_ptr = p - 1;
} else
break;
- S->tccpp_ch = ' ';
+ ch = ' ';
}
- if (S->tccpp_ch == '\n')
- S->tccpp_file->line_num++;
- if (!(S->tccpp_ch == '\f' || S->tccpp_ch == '\v' || S->tccpp_ch == '\r'))
- tok_str_add(S, ws_str, S->tccpp_ch);
- cinp(S);
+ if (ch == '\n')
+ file->line_num++;
+ if (!(ch == '\f' || ch == '\v' || ch == '\r'))
+ tok_str_add(ws_str, ch);
+ cinp();
}
}
- t = S->tccpp_ch;
+ t = ch;
}
if (ws_str)
return t;
- next_nomacro(S);
- return S->tccpp_tok;
+ next_nomacro();
+ return tok;
}
}
@@ -3300,7 +3345,7 @@ static int next_argstream(TCCState* S, Sym **nested_list, TokenString *ws_str)
result to (tok_str,tok_len). 'nested_list' is the list of all
macros we got inside to avoid recursing. Return non zero if no
substitution needs to be done */
-static int macro_subst_tok(TCCState* S,
+static int macro_subst_tok(
TokenString *tok_str,
Sym **nested_list,
Sym *s)
@@ -3315,22 +3360,22 @@ static int macro_subst_tok(TCCState* S,
/* if symbol is a macro, prepare substitution */
/* special macros */
- if (S->tccpp_tok == TOK___LINE__ || S->tccpp_tok == TOK___COUNTER__) {
- t = S->tccpp_tok == TOK___LINE__ ? S->tccpp_file->line_num : S->tccpp_pp_counter++;
+ if (tok == TOK___LINE__ || tok == TOK___COUNTER__) {
+ t = tok == TOK___LINE__ ? file->line_num : pp_counter++;
snprintf(buf, sizeof(buf), "%d", t);
cstrval = buf;
t1 = TOK_PPNUM;
goto add_cstr1;
- } else if (S->tccpp_tok == TOK___FILE__) {
- cstrval = S->tccpp_file->filename;
+ } else if (tok == TOK___FILE__) {
+ cstrval = file->filename;
goto add_cstr;
- } else if (S->tccpp_tok == TOK___DATE__ || S->tccpp_tok == TOK___TIME__) {
+ } else if (tok == TOK___DATE__ || tok == TOK___TIME__) {
time_t ti;
struct tm *tm;
time(&ti);
tm = localtime(&ti);
- if (S->tccpp_tok == TOK___DATE__) {
+ if (tok == TOK___DATE__) {
snprintf(buf, sizeof(buf), "%s %2d %d",
ab_month_name[tm->tm_mon], tm->tm_mday, tm->tm_year + 1900);
} else {
@@ -3341,14 +3386,14 @@ static int macro_subst_tok(TCCState* S,
add_cstr:
t1 = TOK_STR;
add_cstr1:
- cstr_new(S, &cstr);
- cstr_cat(S, &cstr, cstrval, 0);
+ cstr_new(&cstr);
+ cstr_cat(&cstr, cstrval, 0);
cval.str.size = cstr.size;
cval.str.data = cstr.data;
- tok_str_add2(S, tok_str, t1, &cval);
- cstr_free(S, &cstr);
+ tok_str_add2(tok_str, t1, &cval);
+ cstr_free(&cstr);
} else if (s->d) {
- int saved_parse_flags = S->tccpp_parse_flags;
+ int saved_parse_flags = parse_flags;
int *joined_str = NULL;
int *mstr = s->d;
@@ -3358,31 +3403,31 @@ static int macro_subst_tok(TCCState* S,
tok_str_new(&ws_str);
spc = 0;
- S->tccpp_parse_flags |= PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED
+ parse_flags |= PARSE_FLAG_SPACES | PARSE_FLAG_LINEFEED
| PARSE_FLAG_ACCEPT_STRAYS;
/* get next token from argument stream */
- t = next_argstream(S, nested_list, &ws_str);
+ t = next_argstream(nested_list, &ws_str);
if (t != '(') {
/* not a macro substitution after all, restore the
* macro token plus all whitespace we've read.
* whitespace is intentionally not merged to preserve
* newlines. */
- S->tccpp_parse_flags = saved_parse_flags;
- tok_str_add(S, tok_str, S->tccpp_tok);
- if (S->tccpp_parse_flags & PARSE_FLAG_SPACES) {
+ parse_flags = saved_parse_flags;
+ tok_str_add(tok_str, tok);
+ if (parse_flags & PARSE_FLAG_SPACES) {
int i;
for (i = 0; i < ws_str.len; i++)
- tok_str_add(S, tok_str, ws_str.str[i]);
+ tok_str_add(tok_str, ws_str.str[i]);
}
- tok_str_free_str(S, ws_str.str);
+ tok_str_free_str(ws_str.str);
return 0;
} else {
- tok_str_free_str(S, ws_str.str);
+ tok_str_free_str(ws_str.str);
}
do {
- next_nomacro(S); /* eat '(' */
- } while (S->tccpp_tok == TOK_PLCHLDR || is_space(S->tccpp_tok));
+ next_nomacro(); /* eat '(' */
+ } while (tok == TOK_PLCHLDR || is_space(tok));
/* argument macro */
args = NULL;
@@ -3390,87 +3435,87 @@ static int macro_subst_tok(TCCState* S,
/* NOTE: empty args are allowed, except if no args */
for(;;) {
do {
- next_argstream(S, nested_list, NULL);
- } while (S->tccpp_tok == TOK_PLCHLDR || is_space(S->tccpp_tok) ||
- TOK_LINEFEED == S->tccpp_tok);
+ next_argstream(nested_list, NULL);
+ } while (tok == TOK_PLCHLDR || is_space(tok) ||
+ TOK_LINEFEED == tok);
empty_arg:
/* handle '()' case */
- if (!args && !sa && S->tccpp_tok == ')')
+ if (!args && !sa && tok == ')')
break;
if (!sa)
- tcc_error(S,"macro '%s' used with too many args",
- get_tok_str(S, s->v, 0));
+ tcc_error("macro '%s' used with too many args",
+ get_tok_str(s->v, 0));
tok_str_new(&str);
parlevel = spc = 0;
/* NOTE: non zero sa->t indicates VA_ARGS */
while ((parlevel > 0 ||
- (S->tccpp_tok != ')' &&
- (S->tccpp_tok != ',' || sa->type.t)))) {
- if (S->tccpp_tok == TOK_EOF || S->tccpp_tok == 0)
+ (tok != ')' &&
+ (tok != ',' || sa->type.t)))) {
+ if (tok == TOK_EOF || tok == 0)
break;
- if (S->tccpp_tok == '(')
+ if (tok == '(')
parlevel++;
- else if (S->tccpp_tok == ')')
+ else if (tok == ')')
parlevel--;
- if (S->tccpp_tok == TOK_LINEFEED)
- S->tccpp_tok = ' ';
- if (!check_space(S, S->tccpp_tok, &spc))
- tok_str_add2(S, &str, S->tccpp_tok, &S->tccpp_tokc);
- next_argstream(S, nested_list, NULL);
+ if (tok == TOK_LINEFEED)
+ tok = ' ';
+ if (!check_space(tok, &spc))
+ tok_str_add2(&str, tok, &tokc);
+ next_argstream(nested_list, NULL);
}
if (parlevel)
- expect(S, ")");
+ expect(")");
str.len -= spc;
- tok_str_add(S, &str, -1);
- tok_str_add(S, &str, 0);
- sa1 = sym_push2(S, &args, sa->v & ~SYM_FIELD, sa->type.t, 0);
+ tok_str_add(&str, -1);
+ tok_str_add(&str, 0);
+ sa1 = sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, 0);
sa1->d = str.str;
sa = sa->next;
- if (S->tccpp_tok == ')') {
+ if (tok == ')') {
/* special case for gcc var args: add an empty
var arg argument if it is omitted */
if (sa && sa->type.t && gnu_ext)
goto empty_arg;
break;
}
- if (S->tccpp_tok != ',')
- expect(S, ",");
+ if (tok != ',')
+ expect(",");
}
if (sa) {
- tcc_error(S,"macro '%s' used with too few args",
- get_tok_str(S, s->v, 0));
+ tcc_error("macro '%s' used with too few args",
+ get_tok_str(s->v, 0));
}
/* now subst each arg */
- mstr = macro_arg_subst(S, nested_list, mstr, args);
+ mstr = macro_arg_subst(nested_list, mstr, args);
/* free memory */
sa = args;
while (sa) {
sa1 = sa->prev;
- tok_str_free_str(S, sa->d);
+ tok_str_free_str(sa->d);
if (sa->next) {
- tok_str_free_str(S, sa->next->d);
- sym_free(S, sa->next);
+ tok_str_free_str(sa->next->d);
+ sym_free(sa->next);
}
- sym_free(S, sa);
+ sym_free(sa);
sa = sa1;
}
- S->tccpp_parse_flags = saved_parse_flags;
+ parse_flags = saved_parse_flags;
}
- sym_push2(S, nested_list, s->v, 0, 0);
- S->tccpp_parse_flags = saved_parse_flags;
- joined_str = macro_twosharps(S, mstr);
- macro_subst(S, tok_str, nested_list, joined_str ? joined_str : mstr);
+ sym_push2(nested_list, s->v, 0, 0);
+ parse_flags = saved_parse_flags;
+ joined_str = macro_twosharps(mstr);
+ macro_subst(tok_str, nested_list, joined_str ? joined_str : mstr);
/* pop nested defined symbol */
sa1 = *nested_list;
*nested_list = sa1->prev;
- sym_free(S, sa1);
+ sym_free(sa1);
if (joined_str)
- tok_str_free_str(S, joined_str);
+ tok_str_free_str(joined_str);
if (mstr != s->d)
- tok_str_free_str(S, mstr);
+ tok_str_free_str(mstr);
}
return 0;
}
@@ -3478,7 +3523,7 @@ static int macro_subst_tok(TCCState* S,
/* do macro substitution of macro_str and add result to
(tok_str,tok_len). 'nested_list' is the list of all macros we got
inside to avoid recursing. */
-static void macro_subst(TCCState* S,
+static void macro_subst(
TokenString *tok_str,
Sym **nested_list,
const int *macro_str
@@ -3496,39 +3541,39 @@ static void macro_subst(TCCState* S,
break;
if (t >= TOK_IDENT && 0 == nosubst) {
- s = define_find(S, t);
+ s = define_find(t);
if (s == NULL)
goto no_subst;
/* if nested substitution, do nothing */
if (sym_find2(*nested_list, t)) {
/* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */
- tok_str_add2(S, tok_str, TOK_NOSUBST, NULL);
+ tok_str_add2(tok_str, TOK_NOSUBST, NULL);
goto no_subst;
}
{
- TokenString *str = tok_str_alloc(S);
+ TokenString *str = tok_str_alloc();
str->str = (int*)macro_str;
- begin_macro(S, str, 2);
+ begin_macro(str, 2);
- S->tccpp_tok = t;
- macro_subst_tok(S, tok_str, nested_list, s);
+ tok = t;
+ macro_subst_tok(tok_str, nested_list, s);
- if (S->tccpp_macro_stack != str) {
+ if (macro_stack != str) {
/* already finished by reading function macro arguments */
break;
}
- macro_str = S->tccpp_macro_ptr;
- end_macro (S);
+ macro_str = macro_ptr;
+ end_macro ();
}
if (tok_str->len)
spc = is_space(t = tok_str->str[tok_str->lastlen]);
} else {
no_subst:
- if (!check_space(S, t, &spc))
- tok_str_add2(S, tok_str, t, &cval);
+ if (!check_space(t, &spc))
+ tok_str_add2(tok_str, t, &cval);
if (nosubst) {
if (nosubst > 1 && (spc || (++nosubst == 3 && t == '(')))
@@ -3539,94 +3584,94 @@ no_subst:
nosubst = 1;
}
/* GCC supports 'defined' as result of a macro substitution */
- if (t == TOK_DEFINED && S->tccpp_pp_expr)
+ if (t == TOK_DEFINED && pp_expr)
nosubst = 2;
}
}
/* return next token without macro substitution. Can read input from
macro_ptr buffer */
-static void next_nomacro(TCCState* S)
+static void next_nomacro(void)
{
int t;
- if (S->tccpp_macro_ptr) {
+ if (macro_ptr) {
redo:
- t = *S->tccpp_macro_ptr;
+ t = *macro_ptr;
if (TOK_HAS_VALUE(t)) {
- tok_get(&S->tccpp_tok, &S->tccpp_macro_ptr, &S->tccpp_tokc);
+ tok_get(&tok, &macro_ptr, &tokc);
if (t == TOK_LINENUM) {
- S->tccpp_file->line_num = S->tccpp_tokc.i;
+ file->line_num = tokc.i;
goto redo;
}
} else {
- S->tccpp_macro_ptr++;
+ macro_ptr++;
if (t < TOK_IDENT) {
- if (!(S->tccpp_parse_flags & PARSE_FLAG_SPACES)
- && (S->tccpp_isidnum_table[t - CH_EOF] & IS_SPC))
+ if (!(parse_flags & PARSE_FLAG_SPACES)
+ && (isidnum_table[t - CH_EOF] & IS_SPC))
goto redo;
}
- S->tccpp_tok = t;
+ tok = t;
}
} else {
- next_nomacro1(S);
+ next_nomacro1();
}
}
/* return next token with macro substitution */
-ST_FUNC void next(TCCState* S)
+ST_FUNC void next(void)
{
int t;
redo:
- next_nomacro(S);
- t = S->tccpp_tok;
- if (S->tccpp_macro_ptr) {
+ next_nomacro();
+ t = tok;
+ if (macro_ptr) {
if (!TOK_HAS_VALUE(t)) {
if (t == TOK_NOSUBST || t == TOK_PLCHLDR) {
/* discard preprocessor markers */
goto redo;
} else if (t == 0) {
/* end of macro or unget token string */
- end_macro(S);
+ end_macro();
goto redo;
} else if (t == '\\') {
- if (!(S->tccpp_parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
- tcc_error(S, "stray '\\' in program");
+ if (!(parse_flags & PARSE_FLAG_ACCEPT_STRAYS))
+ tcc_error("stray '\\' in program");
}
return;
}
- } else if (t >= TOK_IDENT && (S->tccpp_parse_flags & PARSE_FLAG_PREPROCESS)) {
+ } else if (t >= TOK_IDENT && (parse_flags & PARSE_FLAG_PREPROCESS)) {
/* if reading from file, try to substitute macros */
- Sym *s = define_find(S, t);
+ Sym *s = define_find(t);
if (s) {
Sym *nested_list = NULL;
- S->tccpp_tokstr_buf.len = 0;
- macro_subst_tok(S, &S->tccpp_tokstr_buf, &nested_list, s);
- tok_str_add(S, &S->tccpp_tokstr_buf, 0);
- begin_macro(S, &S->tccpp_tokstr_buf, 0);
+ tokstr_buf.len = 0;
+ macro_subst_tok(&tokstr_buf, &nested_list, s);
+ tok_str_add(&tokstr_buf, 0);
+ begin_macro(&tokstr_buf, 0);
goto redo;
}
return;
}
/* convert preprocessor tokens into C tokens */
if (t == TOK_PPNUM) {
- if (S->tccpp_parse_flags & PARSE_FLAG_TOK_NUM)
- parse_number(S, (char *)S->tccpp_tokc.str.data);
+ if (parse_flags & PARSE_FLAG_TOK_NUM)
+ parse_number((char *)tokc.str.data);
} else if (t == TOK_PPSTR) {
- if (S->tccpp_parse_flags & PARSE_FLAG_TOK_STR)
- parse_string(S, (char *)S->tccpp_tokc.str.data, S->tccpp_tokc.str.size - 1);
+ if (parse_flags & PARSE_FLAG_TOK_STR)
+ parse_string((char *)tokc.str.data, tokc.str.size - 1);
}
}
/* push back current token and set current token to 'last_tok'. Only
identifier case handled for labels. */
-ST_INLN void unget_tok(TCCState* S, int last_tok)
+ST_INLN void unget_tok(int last_tok)
{
- TokenString *str = tok_str_alloc(S);
- tok_str_add2(S, str, S->tccpp_tok, &S->tccpp_tokc);
- tok_str_add(S, str, 0);
- begin_macro(S, str, 1);
- S->tccpp_tok = last_tok;
+ TokenString *str = tok_str_alloc();
+ tok_str_add2(str, tok, &tokc);
+ tok_str_add(str, 0);
+ begin_macro(str, 1);
+ tok = last_tok;
}
/* ------------------------------------------------------------------------- */
@@ -3658,50 +3703,50 @@ static const char * const target_os_defs =
#endif
;
-static void putdef(TCCState* S, CString *cs, const char *p)
+static void putdef(CString *cs, const char *p)
{
- cstr_printf(S, cs, "#define %s%s\n", p, &" 1"[!!strchr(p, ' ')*2]);
+ cstr_printf(cs, "#define %s%s\n", p, &" 1"[!!strchr(p, ' ')*2]);
}
-static void tcc_predefs(TCCState *S, CString *cs, int is_asm)
+static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
{
int a, b, c;
const char *defs[] = { target_machine_defs, target_os_defs, NULL };
const char *p;
sscanf(TCC_VERSION, "%d.%d.%d", &a, &b, &c);
- cstr_printf(S, cs, "#define __TINYC__ %d\n", a*10000 + b*100 + c);
+ cstr_printf(cs, "#define __TINYC__ %d\n", a*10000 + b*100 + c);
for (a = 0; defs[a]; ++a)
for (p = defs[a]; *p; p = strchr(p, 0) + 1)
- putdef(S, cs, p);
+ putdef(cs, p);
#ifdef TCC_TARGET_ARM
- if (S->float_abi == ARM_HARD_FLOAT)
- putdef(S, cs, "__ARM_PCS_VFP");
+ if (s1->float_abi == ARM_HARD_FLOAT)
+ putdef(cs, "__ARM_PCS_VFP");
#endif
if (is_asm)
- putdef(S, cs, "__ASSEMBLER__");
- if (S->output_type == TCC_OUTPUT_PREPROCESS)
- putdef(S, cs, "__TCC_PP__");
- if (S->output_type == TCC_OUTPUT_MEMORY)
- putdef(S, cs, "__TCC_RUN__");
- if (S->char_is_unsigned)
- putdef(S, cs, "__CHAR_UNSIGNED__");
- if (S->optimize > 0)
- putdef(S, cs, "__OPTIMIZE__");
- if (S->option_pthread)
- putdef(S, cs, "_REENTRANT");
- if (S->leading_underscore)
- putdef(S, cs, "__leading_underscore");
+ putdef(cs, "__ASSEMBLER__");
+ if (s1->output_type == TCC_OUTPUT_PREPROCESS)
+ putdef(cs, "__TCC_PP__");
+ if (s1->output_type == TCC_OUTPUT_MEMORY)
+ putdef(cs, "__TCC_RUN__");
+ if (s1->char_is_unsigned)
+ putdef(cs, "__CHAR_UNSIGNED__");
+ if (s1->optimize > 0)
+ putdef(cs, "__OPTIMIZE__");
+ if (s1->option_pthread)
+ putdef(cs, "_REENTRANT");
+ if (s1->leading_underscore)
+ putdef(cs, "__leading_underscore");
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- putdef(S, cs, "__BOUNDS_CHECKING_ON");
+ if (s1->do_bounds_check)
+ putdef(cs, "__BOUNDS_CHECKING_ON");
#endif
- cstr_printf(S, cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
- cstr_printf(S, cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
+ cstr_printf(cs, "#define __SIZEOF_POINTER__ %d\n", PTR_SIZE);
+ cstr_printf(cs, "#define __SIZEOF_LONG__ %d\n", LONG_SIZE);
if (!is_asm) {
- putdef(S, cs, "__STDC__");
- cstr_printf(S, cs, "#define __STDC_VERSION__ %dL\n", S->cversion);
- cstr_cat(S, cs,
+ putdef(cs, "__STDC__");
+ cstr_printf(cs, "#define __STDC_VERSION__ %dL\n", s1->cversion);
+ cstr_cat(cs,
/* load more predefs and __builtins */
#if CONFIG_TCC_PREDEFS
#include "tccdefs_.h" /* include as strings */
@@ -3710,87 +3755,87 @@ static void tcc_predefs(TCCState *S, CString *cs, int is_asm)
#endif
, -1);
}
- cstr_printf(S, cs, "#define __BASE_FILE__ \"%s\"\n", S->tccpp_file->filename);
+ cstr_printf(cs, "#define __BASE_FILE__ \"%s\"\n", file->filename);
}
-ST_FUNC void preprocess_start(TCCState *S, int filetype)
+ST_FUNC void preprocess_start(TCCState *s1, int filetype)
{
int is_asm = !!(filetype & (AFF_TYPE_ASM|AFF_TYPE_ASMPP));
CString cstr;
- tccpp_new(S);
+ tccpp_new(s1);
- S->include_stack_ptr = S->include_stack;
- S->ifdef_stack_ptr = S->ifdef_stack;
- S->tccpp_file->ifdef_stack_ptr = S->ifdef_stack_ptr;
- S->tccpp_pp_expr = 0;
- S->tccpp_pp_counter = 0;
- S->tccpp_pp_debug_tok = S->tccpp_pp_debug_symv = 0;
- S->tccpp_pp_once++;
- S->pack_stack[0] = 0;
- S->pack_stack_ptr = S->pack_stack;
+ s1->include_stack_ptr = s1->include_stack;
+ s1->ifdef_stack_ptr = s1->ifdef_stack;
+ file->ifdef_stack_ptr = s1->ifdef_stack_ptr;
+ pp_expr = 0;
+ pp_counter = 0;
+ pp_debug_tok = pp_debug_symv = 0;
+ pp_once++;
+ s1->pack_stack[0] = 0;
+ s1->pack_stack_ptr = s1->pack_stack;
- set_idnum(S, '$', !is_asm && S->dollars_in_identifiers ? IS_ID : 0);
- set_idnum(S, '.', is_asm ? IS_ID : 0);
+ set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0);
+ set_idnum('.', is_asm ? IS_ID : 0);
if (!(filetype & AFF_TYPE_ASM)) {
- cstr_new(S, &cstr);
- tcc_predefs(S, &cstr, is_asm);
- if (S->cmdline_defs.size)
- cstr_cat(S, &cstr, S->cmdline_defs.data, S->cmdline_defs.size);
- if (S->cmdline_incl.size)
- cstr_cat(S, &cstr, S->cmdline_incl.data, S->cmdline_incl.size);
+ cstr_new(&cstr);
+ tcc_predefs(s1, &cstr, is_asm);
+ if (s1->cmdline_defs.size)
+ cstr_cat(&cstr, s1->cmdline_defs.data, s1->cmdline_defs.size);
+ if (s1->cmdline_incl.size)
+ cstr_cat(&cstr, s1->cmdline_incl.data, s1->cmdline_incl.size);
//printf("%s\n", (char*)cstr.data);
- *S->include_stack_ptr++ = S->tccpp_file;
- tcc_open_bf(S, "<command line>", cstr.size);
- memcpy(S->tccpp_file->buffer, cstr.data, cstr.size);
- cstr_free(S, &cstr);
+ *s1->include_stack_ptr++ = file;
+ tcc_open_bf(s1, "<command line>", cstr.size);
+ memcpy(file->buffer, cstr.data, cstr.size);
+ cstr_free(&cstr);
}
- S->tccpp_parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
- S->tccpp_tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
+ parse_flags = is_asm ? PARSE_FLAG_ASM_FILE : 0;
+ tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
}
/* cleanup from error/setjmp */
-ST_FUNC void preprocess_end(TCCState *S)
+ST_FUNC void preprocess_end(TCCState *s1)
{
- while (S->tccpp_macro_stack)
- end_macro(S);
- S->tccpp_macro_ptr = NULL;
- while (S->tccpp_file)
- tcc_close(S);
- tccpp_delete(S);
+ while (macro_stack)
+ end_macro();
+ macro_ptr = NULL;
+ while (file)
+ tcc_close();
+ tccpp_delete(s1);
}
-ST_FUNC void tccpp_new(TCCState *S)
+ST_FUNC void tccpp_new(TCCState *s)
{
int i, c;
const char *p, *r;
/* init isid table */
for(i = CH_EOF; i<128; i++)
- set_idnum(S, i,
+ set_idnum(i,
is_space(i) ? IS_SPC
: isid(i) ? IS_ID
: isnum(i) ? IS_NUM
: 0);
for(i = 128; i<256; i++)
- set_idnum(S, i, IS_ID);
+ set_idnum(i, IS_ID);
/* init allocators */
- tal_new(S, &S->tccpp_toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE);
- tal_new(S, &S->tccpp_tokstr_alloc, TOKSTR_TAL_LIMIT, TOKSTR_TAL_SIZE);
+ tal_new(&toksym_alloc, TOKSYM_TAL_LIMIT, TOKSYM_TAL_SIZE);
+ tal_new(&tokstr_alloc, TOKSTR_TAL_LIMIT, TOKSTR_TAL_SIZE);
- memset(S->tccpp_hash_ident, 0, TOK_HASH_SIZE * sizeof(TokenSym *));
- memset(S->cached_includes_hash, 0, sizeof S->cached_includes_hash);
+ memset(hash_ident, 0, TOK_HASH_SIZE * sizeof(TokenSym *));
+ memset(s->cached_includes_hash, 0, sizeof s->cached_includes_hash);
- cstr_new(S, &S->tccpp_cstr_buf);
- cstr_realloc(S, &S->tccpp_cstr_buf, STRING_MAX_SIZE);
- tok_str_new(&S->tccpp_tokstr_buf);
- tok_str_realloc(S, &S->tccpp_tokstr_buf, TOKSTR_MAX_SIZE);
+ cstr_new(&cstr_buf);
+ cstr_realloc(&cstr_buf, STRING_MAX_SIZE);
+ tok_str_new(&tokstr_buf);
+ tok_str_realloc(&tokstr_buf, TOKSTR_MAX_SIZE);
- S->tccpp_tok_ident = TOK_IDENT;
+ tok_ident = TOK_IDENT;
p = tcc_keywords;
while (*p) {
r = p;
@@ -3799,133 +3844,133 @@ ST_FUNC void tccpp_new(TCCState *S)
if (c == '\0')
break;
}
- tok_alloc(S, p, r - p - 1);
+ tok_alloc(p, r - p - 1);
p = r;
}
/* we add dummy defines for some special macros to speed up tests
and to have working defined() */
- define_push(S, TOK___LINE__, MACRO_OBJ, NULL, NULL);
- define_push(S, TOK___FILE__, MACRO_OBJ, NULL, NULL);
- define_push(S, TOK___DATE__, MACRO_OBJ, NULL, NULL);
- define_push(S, TOK___TIME__, MACRO_OBJ, NULL, NULL);
- define_push(S, TOK___COUNTER__, MACRO_OBJ, NULL, NULL);
+ define_push(TOK___LINE__, MACRO_OBJ, NULL, NULL);
+ define_push(TOK___FILE__, MACRO_OBJ, NULL, NULL);
+ define_push(TOK___DATE__, MACRO_OBJ, NULL, NULL);
+ define_push(TOK___TIME__, MACRO_OBJ, NULL, NULL);
+ define_push(TOK___COUNTER__, MACRO_OBJ, NULL, NULL);
}
-ST_FUNC void tccpp_delete(TCCState *S)
+ST_FUNC void tccpp_delete(TCCState *s)
{
int i, n;
- dynarray_reset(S, &S->cached_includes, &S->nb_cached_includes);
+ dynarray_reset(&s->cached_includes, &s->nb_cached_includes);
/* free tokens */
- n = S->tccpp_tok_ident - TOK_IDENT;
+ n = tok_ident - TOK_IDENT;
if (n > total_idents)
total_idents = n;
for(i = 0; i < n; i++)
- tal_free(S, S->tccpp_toksym_alloc, S->tccpp_table_ident[i]);
- tcc_free(S, S->tccpp_table_ident);
- S->tccpp_table_ident = NULL;
+ tal_free(toksym_alloc, table_ident[i]);
+ tcc_free(table_ident);
+ table_ident = NULL;
/* free static buffers */
- cstr_free(S, &S->tccpp_tokcstr);
- cstr_free(S, &S->tccpp_cstr_buf);
- cstr_free(S, &S->tccpp_macro_equal_buf);
- tok_str_free_str(S, S->tccpp_tokstr_buf.str);
+ cstr_free(&tokcstr);
+ cstr_free(&cstr_buf);
+ cstr_free(&macro_equal_buf);
+ tok_str_free_str(tokstr_buf.str);
/* free allocators */
- tal_delete(S, S->tccpp_toksym_alloc);
- S->tccpp_toksym_alloc = NULL;
- tal_delete(S, S->tccpp_tokstr_alloc);
- S->tccpp_tokstr_alloc = NULL;
+ tal_delete(toksym_alloc);
+ toksym_alloc = NULL;
+ tal_delete(tokstr_alloc);
+ tokstr_alloc = NULL;
}
/* ------------------------------------------------------------------------- */
/* tcc -E [-P[1]] [-dD} support */
-static void tok_print(TCCState* S, const char *msg, const int *str)
+static void tok_print(const char *msg, const int *str)
{
FILE *fp;
int t, s = 0;
CValue cval;
- fp = S->ppfp;
+ fp = tcc_state->ppfp;
fprintf(fp, "%s", msg);
while (str) {
TOK_GET(&t, &str, &cval);
if (!t)
break;
- fprintf(fp, &" %s"[s], get_tok_str(S, t, &cval)), s = 1;
+ fprintf(fp, &" %s"[s], get_tok_str(t, &cval)), s = 1;
}
fprintf(fp, "\n");
}
-static void pp_line(TCCState *S, BufferedFile *f, int level)
+static void pp_line(TCCState *s1, BufferedFile *f, int level)
{
int d = f->line_num - f->line_ref;
- if (S->dflag & TCC_OPTION_d_4)
+ if (s1->dflag & 4)
return;
- if (S->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) {
+ if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) {
;
} else if (level == 0 && f->line_ref && d < 8) {
while (d > 0)
- fputs("\n", S->ppfp), --d;
- } else if (S->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
- fprintf(S->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename);
+ fputs("\n", s1->ppfp), --d;
+ } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {
+ fprintf(s1->ppfp, "#line %d \"%s\"\n", f->line_num, f->filename);
} else {
- fprintf(S->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename,
+ fprintf(s1->ppfp, "# %d \"%s\"%s\n", f->line_num, f->filename,
level > 0 ? " 1" : level < 0 ? " 2" : "");
}
f->line_ref = f->line_num;
}
-static void define_print(TCCState *S, int v)
+static void define_print(TCCState *s1, int v)
{
FILE *fp;
Sym *s;
- s = define_find(S, v);
+ s = define_find(v);
if (NULL == s || NULL == s->d)
return;
- fp = S->ppfp;
- fprintf(fp, "#define %s", get_tok_str(S, v, NULL));
+ fp = s1->ppfp;
+ fprintf(fp, "#define %s", get_tok_str(v, NULL));
if (s->type.t == MACRO_FUNC) {
Sym *a = s->next;
fprintf(fp,"(");
if (a)
for (;;) {
- fprintf(fp,"%s", get_tok_str(S, a->v & ~SYM_FIELD, NULL));
+ fprintf(fp,"%s", get_tok_str(a->v & ~SYM_FIELD, NULL));
if (!(a = a->next))
break;
fprintf(fp,",");
}
fprintf(fp,")");
}
- tok_print(S, "", s->d);
+ tok_print("", s->d);
}
-static void pp_debug_defines(TCCState *S)
+static void pp_debug_defines(TCCState *s1)
{
int v, t;
const char *vs;
FILE *fp;
- t = S->tccpp_pp_debug_tok;
+ t = pp_debug_tok;
if (t == 0)
return;
- S->tccpp_file->line_num--;
- pp_line(S, S->tccpp_file, 0);
- S->tccpp_file->line_ref = ++S->tccpp_file->line_num;
+ file->line_num--;
+ pp_line(s1, file, 0);
+ file->line_ref = ++file->line_num;
- fp = S->ppfp;
- v = S->tccpp_pp_debug_symv;
- vs = get_tok_str(S, v, NULL);
+ fp = s1->ppfp;
+ v = pp_debug_symv;
+ vs = get_tok_str(v, NULL);
if (t == TOK_DEFINE) {
- define_print(S, v);
+ define_print(s1, v);
} else if (t == TOK_UNDEF) {
fprintf(fp, "#undef %s\n", vs);
} else if (t == TOK_push_macro) {
@@ -3933,14 +3978,14 @@ static void pp_debug_defines(TCCState *S)
} else if (t == TOK_pop_macro) {
fprintf(fp, "#pragma pop_macro(\"%s\")\n", vs);
}
- S->tccpp_pp_debug_tok = 0;
+ pp_debug_tok = 0;
}
-static void pp_debug_builtins(TCCState *S)
+static void pp_debug_builtins(TCCState *s1)
{
int v;
- for (v = TOK_IDENT; v < S->tccpp_tok_ident; ++v)
- define_print(S, v);
+ for (v = TOK_IDENT; v < tok_ident; ++v)
+ define_print(s1, v);
}
/* Add a space between tokens a and b to avoid unwanted textual pasting */
@@ -3963,15 +4008,15 @@ static int pp_check_he0xE(int t, const char *p)
}
/* Preprocess the current file */
-ST_FUNC int tcc_preprocess(TCCState *S)
+ST_FUNC int tcc_preprocess(TCCState *s1)
{
BufferedFile **iptr;
int token_seen, spcs, level;
const char *p;
char white[400];
- S->tccpp_parse_flags = PARSE_FLAG_PREPROCESS
- | (S->tccpp_parse_flags & PARSE_FLAG_ASM_FILE)
+ parse_flags = PARSE_FLAG_PREPROCESS
+ | (parse_flags & PARSE_FLAG_ASM_FILE)
| PARSE_FLAG_LINEFEED
| PARSE_FLAG_SPACES
| PARSE_FLAG_ACCEPT_STRAYS
@@ -3979,60 +4024,60 @@ ST_FUNC int tcc_preprocess(TCCState *S)
/* Credits to Fabrice Bellard's initial revision to demonstrate its
capability to compile and run itself, provided all numbers are
given as decimals. tcc -E -P10 will do. */
- if (S->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
- S->tccpp_parse_flags |= PARSE_FLAG_TOK_NUM, S->Pflag = 1;
+ if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
+ parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;
- if (S->do_bench) {
+ if (s1->do_bench) {
/* for PP benchmarks */
- do next(S); while (S->tccpp_tok != TOK_EOF);
+ do next(); while (tok != TOK_EOF);
return 0;
}
- if (S->dflag & TCC_OPTION_d_BI) {
- pp_debug_builtins(S);
- S->dflag &= ~TCC_OPTION_d_BI;
+ if (s1->dflag & 1) {
+ pp_debug_builtins(s1);
+ s1->dflag &= ~1;
}
token_seen = TOK_LINEFEED, spcs = 0, level = 0;
- if (S->tccpp_file->prev)
- pp_line(S, S->tccpp_file->prev, level++);
- pp_line(S, S->tccpp_file, level);
+ if (file->prev)
+ pp_line(s1, file->prev, level++);
+ pp_line(s1, file, level);
for (;;) {
- iptr = S->include_stack_ptr;
- next(S);
- if (S->tccpp_tok == TOK_EOF)
+ iptr = s1->include_stack_ptr;
+ next();
+ if (tok == TOK_EOF)
break;
- level = S->include_stack_ptr - iptr;
+ level = s1->include_stack_ptr - iptr;
if (level) {
if (level > 0)
- pp_line(S, *iptr, 0);
- pp_line(S, S->tccpp_file, level);
+ pp_line(s1, *iptr, 0);
+ pp_line(s1, file, level);
}
- if (S->dflag & TCC_OPTION_d_M) {
- pp_debug_defines(S);
- if (S->dflag & TCC_OPTION_d_4)
+ if (s1->dflag & 7) {
+ pp_debug_defines(s1);
+ if (s1->dflag & 4)
continue;
}
- if (is_space(S->tccpp_tok)) {
+ if (is_space(tok)) {
if (spcs < sizeof white - 1)
- white[spcs++] = S->tccpp_tok;
+ white[spcs++] = tok;
continue;
- } else if (S->tccpp_tok == TOK_LINEFEED) {
+ } else if (tok == TOK_LINEFEED) {
spcs = 0;
if (token_seen == TOK_LINEFEED)
continue;
- ++S->tccpp_file->line_ref;
+ ++file->line_ref;
} else if (token_seen == TOK_LINEFEED) {
- pp_line(S, S->tccpp_file, 0);
- } else if (spcs == 0 && pp_need_space(token_seen, S->tccpp_tok)) {
+ pp_line(s1, file, 0);
+ } else if (spcs == 0 && pp_need_space(token_seen, tok)) {
white[spcs++] = ' ';
}
- white[spcs] = 0, fputs(white, S->ppfp), spcs = 0;
- fputs(p = get_tok_str(S, S->tccpp_tok, &S->tccpp_tokc), S->ppfp);
- token_seen = pp_check_he0xE(S->tccpp_tok, p);
+ white[spcs] = 0, fputs(white, s1->ppfp), spcs = 0;
+ fputs(p = get_tok_str(tok, &tokc), s1->ppfp);
+ token_seen = pp_check_he0xE(tok, p);
}
return 0;
}
diff --git a/tccqsort.c b/tccqsort.c
deleted file mode 100644
index eb55147..0000000
--- a/tccqsort.c
+++ /dev/null
@@ -1,261 +0,0 @@
-/* Copyright (C) 2011 by Valentin Ochs
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-/* Minor changes by Rich Felker for integration in musl, 2011-04-27. */
-
-/* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1).
- Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-//#include "atomic.h"
-#ifndef a_ctz_32
-#define a_ctz_32 a_ctz_32
-static inline int a_ctz_32(uint32_t x)
-{
-#ifdef a_clz_32
- return 31-a_clz_32(x&-x);
-#else
- static const char debruijn32[32] = {
- 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
- 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
- };
- return debruijn32[(x&-x)*0x076be629 >> 27];
-#endif
-}
-#endif
-
-#ifndef a_ctz_64
-#define a_ctz_64 a_ctz_64
-static inline int a_ctz_64(uint64_t x)
-{
- static const char debruijn64[64] = {
- 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
- 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
- 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
- 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12
- };
- if (sizeof(long) < 8) {
- uint32_t y = x;
- if (!y) {
- y = x>>32;
- return 32 + a_ctz_32(y);
- }
- return a_ctz_32(y);
- }
- return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58];
-}
-#endif
-
-static inline int a_ctz_l(unsigned long x)
-{
- return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x);
-}
-
-#define ntz(x) a_ctz_l((x))
-
-typedef int (*tcc_cmpfun)(const void *, const void *, void *);
-
-static inline int pntz(size_t p[2]) {
- int r = ntz(p[0] - 1);
- if(r != 0 || (r = 8*sizeof(size_t) + ntz(p[1])) != 8*sizeof(size_t)) {
- return r;
- }
- return 0;
-}
-
-static void cycle(size_t width, unsigned char* ar[], int n)
-{
- unsigned char tmp[256];
- size_t l;
- int i;
-
- if(n < 2) {
- return;
- }
-
- ar[n] = tmp;
- while(width) {
- l = sizeof(tmp) < width ? sizeof(tmp) : width;
- memcpy(ar[n], ar[0], l);
- for(i = 0; i < n; i++) {
- memcpy(ar[i], ar[i + 1], l);
- ar[i] += l;
- }
- width -= l;
- }
-}
-
-/* shl() and shr() need n > 0 */
-static inline void shl(size_t p[2], int n)
-{
- if(n >= 8 * sizeof(size_t)) {
- n -= 8 * sizeof(size_t);
- p[1] = p[0];
- p[0] = 0;
- }
- p[1] <<= n;
- p[1] |= p[0] >> (sizeof(size_t) * 8 - n);
- p[0] <<= n;
-}
-
-static inline void shr(size_t p[2], int n)
-{
- if(n >= 8 * sizeof(size_t)) {
- n -= 8 * sizeof(size_t);
- p[0] = p[1];
- p[1] = 0;
- }
- p[0] >>= n;
- p[0] |= p[1] << (sizeof(size_t) * 8 - n);
- p[1] >>= n;
-}
-
-static void sift(unsigned char *head, size_t width, tcc_cmpfun cmp, int pshift, size_t lp[], void* ctx)
-{
- unsigned char *rt, *lf;
- unsigned char *ar[14 * sizeof(size_t) + 1];
- int i = 1;
-
- ar[0] = head;
- while(pshift > 1) {
- rt = head - width;
- lf = head - width - lp[pshift - 2];
-
- if((*cmp)(ar[0], lf, ctx) >= 0 && (*cmp)(ar[0], rt, ctx) >= 0) {
- break;
- }
- if((*cmp)(lf, rt, ctx) >= 0) {
- ar[i++] = lf;
- head = lf;
- pshift -= 1;
- } else {
- ar[i++] = rt;
- head = rt;
- pshift -= 2;
- }
- }
- cycle(width, ar, i);
-}
-
-static void trinkle(unsigned char *head, size_t width, tcc_cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[], void* ctx)
-{
- unsigned char *stepson,
- *rt, *lf;
- size_t p[2];
- unsigned char *ar[14 * sizeof(size_t) + 1];
- int i = 1;
- int trail;
-
- p[0] = pp[0];
- p[1] = pp[1];
-
- ar[0] = head;
- while(p[0] != 1 || p[1] != 0) {
- stepson = head - lp[pshift];
- if((*cmp)(stepson, ar[0], ctx) <= 0) {
- break;
- }
- if(!trusty && pshift > 1) {
- rt = head - width;
- lf = head - width - lp[pshift - 2];
- if((*cmp)(rt, stepson, ctx) >= 0 || (*cmp)(lf, stepson, ctx) >= 0) {
- break;
- }
- }
-
- ar[i++] = stepson;
- head = stepson;
- trail = pntz(p);
- shr(p, trail);
- pshift += trail;
- trusty = 0;
- }
- if(!trusty) {
- cycle(width, ar, i);
- sift(head, width, cmp, pshift, lp, ctx);
- }
-}
-
-LIBTCCAPI void tcc_qsort_s(void *base, size_t nel, size_t width, tcc_cmpfun cmp, void *ctx)
-{
- size_t lp[12*sizeof(size_t)];
- size_t i, size = width * nel;
- unsigned char *head, *high;
- size_t p[2] = {1, 0};
- int pshift = 1;
- int trail;
-
- if (!size) return;
-
- head = base;
- high = head + size - width;
-
- /* Precompute Leonardo numbers, scaled by element width */
- for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++);
-
- while(head < high) {
- if((p[0] & 3) == 3) {
- sift(head, width, cmp, pshift, lp, ctx);
- shr(p, 2);
- pshift += 2;
- } else {
- if(lp[pshift - 1] >= high - head) {
- trinkle(head, width, cmp, p, pshift, 0, lp, ctx);
- } else {
- sift(head, width, cmp, pshift, lp, ctx);
- }
-
- if(pshift == 1) {
- shl(p, 1);
- pshift = 0;
- } else {
- shl(p, pshift - 1);
- pshift = 1;
- }
- }
-
- p[0] |= 1;
- head += width;
- }
-
- trinkle(head, width, cmp, p, pshift, 0, lp, ctx);
-
- while(pshift != 1 || p[0] != 1 || p[1] != 0) {
- if(pshift <= 1) {
- trail = pntz(p);
- shr(p, trail);
- pshift += trail;
- } else {
- shl(p, 2);
- pshift -= 2;
- p[0] ^= 7;
- shr(p, 1);
- trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp, ctx);
- shl(p, 1);
- p[0] |= 1;
- trinkle(head - width, width, cmp, p, pshift, 1, lp, ctx);
- }
- head -= width;
- }
-}
diff --git a/tccrun.c b/tccrun.c
index 2e92e1d..9c9f4e0 100644
--- a/tccrun.c
+++ b/tccrun.c
@@ -55,11 +55,11 @@ static void rt_exit(int code);
# include <sys/mman.h>
#endif
-static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long length);
-static int tcc_relocate_ex(TCCState *S, void *ptr, addr_t ptr_diff);
+static void set_pages_executable(TCCState *s1, int mode, void *ptr, unsigned long length);
+static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff);
#ifdef _WIN64
-static void *win64_add_function_table(TCCState *S);
+static void *win64_add_function_table(TCCState *s1);
static void win64_del_function_table(void *);
#endif
@@ -67,15 +67,15 @@ static void win64_del_function_table(void *);
/* Do all relocations (needed before using tcc_get_symbol())
Returns -1 on error. */
-LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr)
+LIBTCCAPI int tcc_relocate(TCCState *s1, void *ptr)
{
int size;
addr_t ptr_diff = 0;
if (TCC_RELOCATE_AUTO != ptr)
- return tcc_relocate_ex(S, ptr, 0);
+ return tcc_relocate_ex(s1, ptr, 0);
- size = tcc_relocate_ex(S, NULL, 0);
+ size = tcc_relocate_ex(s1, NULL, 0);
if (size < 0)
return -1;
@@ -93,52 +93,52 @@ LIBTCCAPI int tcc_relocate(TCCState *S, void *ptr)
/* mmap RX memory at a fixed distance */
prx = mmap((char*)ptr + size, size, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, fd, 0);
if (ptr == MAP_FAILED || prx == MAP_FAILED)
- tcc_error(S, "tccrun: could not map memory");
+ tcc_error("tccrun: could not map memory");
ptr_diff = (char*)prx - (char*)ptr;
close(fd);
//printf("map %p %p %p\n", ptr, prx, (void*)ptr_diff);
}
#else
- ptr = tcc_malloc(S, size);
+ ptr = tcc_malloc(size);
#endif
- tcc_relocate_ex(S, ptr, ptr_diff); /* no more errors expected */
- dynarray_add(S, &S->runtime_mem, &S->nb_runtime_mem, (void*)(addr_t)size);
- dynarray_add(S, &S->runtime_mem, &S->nb_runtime_mem, ptr);
+ tcc_relocate_ex(s1, ptr, ptr_diff); /* no more errors expected */
+ dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, (void*)(addr_t)size);
+ dynarray_add(&s1->runtime_mem, &s1->nb_runtime_mem, ptr);
return 0;
}
-ST_FUNC void tcc_run_free(TCCState *S)
+ST_FUNC void tcc_run_free(TCCState *s1)
{
int i;
- for (i = 0; i < S->nb_runtime_mem; i += 2) {
- unsigned size = (unsigned)(addr_t)S->runtime_mem[i];
- void *ptr = S->runtime_mem[i+1];
+ for (i = 0; i < s1->nb_runtime_mem; i += 2) {
+ unsigned size = (unsigned)(addr_t)s1->runtime_mem[i];
+ void *ptr = s1->runtime_mem[i+1];
#ifdef HAVE_SELINUX
munmap(ptr, size * 2);
#else
/* unprotect memory to make it usable for malloc again */
- set_pages_executable(S, 2, ptr, size);
+ set_pages_executable(s1, 2, ptr, size);
#ifdef _WIN64
win64_del_function_table(*(void**)ptr);
#endif
- tcc_free(S, ptr);
+ tcc_free(ptr);
#endif
}
- tcc_free(S, S->runtime_mem);
+ tcc_free(s1->runtime_mem);
}
-static void run_cdtors(TCCState *S, const char *start, const char *end,
+static void run_cdtors(TCCState *s1, const char *start, const char *end,
int argc, char **argv, char **envp)
{
- void **a = (void **)get_sym_addr(S, start, 0, 0);
- void **b = (void **)get_sym_addr(S, end, 0, 0);
+ void **a = (void **)get_sym_addr(s1, start, 0, 0);
+ void **b = (void **)get_sym_addr(s1, end, 0, 0);
while (a != b)
((void(*)(int, char **, char **))*a++)(argc, argv, envp);
}
/* launch the compiled program with the given arguments */
-LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv)
+LIBTCCAPI int tcc_run(TCCState *s1, int argc, char **argv)
{
int (*prog_main)(int, char **, char **), ret;
#ifdef CONFIG_TCC_BACKTRACE
@@ -154,20 +154,20 @@ LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv)
char **envp = environ;
#endif
- S->runtime_main = S->nostdlib ? "_start" : "main";
- if ((S->dflag & TCC_OPTION_d_t) && (addr_t)-1 == get_sym_addr(S, S->runtime_main, 0, 1))
+ s1->runtime_main = s1->nostdlib ? "_start" : "main";
+ if ((s1->dflag & 16) && (addr_t)-1 == get_sym_addr(s1, s1->runtime_main, 0, 1))
return 0;
#ifdef CONFIG_TCC_BACKTRACE
- if (S->do_debug)
- tcc_add_symbol(S, "exit", rt_exit);
+ if (s1->do_debug)
+ tcc_add_symbol(s1, "exit", rt_exit);
#endif
- if (tcc_relocate(S, TCC_RELOCATE_AUTO) < 0)
+ if (tcc_relocate(s1, TCC_RELOCATE_AUTO) < 0)
return -1;
- prog_main = (void*)get_sym_addr(S, S->runtime_main, 1, 1);
+ prog_main = (void*)get_sym_addr(s1, s1->runtime_main, 1, 1);
#ifdef CONFIG_TCC_BACKTRACE
memset(rc, 0, sizeof *rc);
- if (S->do_debug) {
+ if (s1->do_debug) {
void *p;
rc->stab_sym = (Stab_Sym *)stab_section->data;
rc->stab_sym_end = (Stab_Sym *)(stab_section->data + stab_section->data_offset);
@@ -178,15 +178,15 @@ LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv)
#if PTR_SIZE == 8
rc->prog_base = text_section->sh_addr & 0xffffffff00000000ULL;
#endif
- rc->top_func = tcc_get_symbol(S, "main");
- rc->num_callers = S->rt_num_callers;
+ rc->top_func = tcc_get_symbol(s1, "main");
+ rc->num_callers = s1->rt_num_callers;
rc->do_jmp = 1;
- if ((p = tcc_get_symbol(S, "__rt_error")))
+ if ((p = tcc_get_symbol(s1, "__rt_error")))
*(void**)p = _rt_error;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check) {
+ if (s1->do_bounds_check) {
rc->bounds_start = (void*)bounds_section->sh_addr;
- if ((p = tcc_get_symbol(S, "__bound_init")))
+ if ((p = tcc_get_symbol(s1, "__bound_init")))
((void(*)(void*,int))p)(rc->bounds_start, 1);
}
#endif
@@ -198,16 +198,16 @@ LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv)
fflush(stdout);
fflush(stderr);
/* These aren't C symbols, so don't need leading underscore handling. */
- run_cdtors(S, "__init_array_start", "__init_array_end", argc, argv, envp);
+ run_cdtors(s1, "__init_array_start", "__init_array_end", argc, argv, envp);
#ifdef CONFIG_TCC_BACKTRACE
if (!rc->do_jmp || !(ret = setjmp(rc->jmp_buf)))
#endif
{
ret = prog_main(argc, argv, envp);
}
- run_cdtors(S, "__fini_array_start", "__fini_array_end", 0, NULL, NULL);
- if ((S->dflag & TCC_OPTION_d_t) && ret)
- fprintf(S->ppfp, "[returns %d]\n", ret), fflush(S->ppfp);
+ run_cdtors(s1, "__fini_array_start", "__fini_array_end", 0, NULL, NULL);
+ if ((s1->dflag & 16) && ret)
+ fprintf(s1->ppfp, "[returns %d]\n", ret), fflush(s1->ppfp);
return ret;
}
@@ -229,7 +229,7 @@ LIBTCCAPI int tcc_run(TCCState *S, int argc, char **argv)
/* relocate code. Return -1 on error, required size if ptr is NULL,
otherwise copy code into buffer passed by the caller */
-static int tcc_relocate_ex(TCCState *S, void *ptr, addr_t ptr_diff)
+static int tcc_relocate_ex(TCCState *s1, void *ptr, addr_t ptr_diff)
{
Section *s;
unsigned offset, length, align, max_align, i, k, f;
@@ -237,15 +237,15 @@ static int tcc_relocate_ex(TCCState *S, void *ptr, addr_t ptr_diff)
addr_t mem, addr;
if (NULL == ptr) {
- S->nb_errors = 0;
+ s1->nb_errors = 0;
#ifdef TCC_TARGET_PE
- pe_output_file(S, NULL);
+ pe_output_file(s1, NULL);
#else
- tcc_add_runtime(S);
- resolve_common_syms(S);
- build_got_entries(S);
+ tcc_add_runtime(s1);
+ resolve_common_syms(s1);
+ build_got_entries(s1);
#endif
- if (S->nb_errors)
+ if (s1->nb_errors)
return -1;
}
@@ -257,11 +257,11 @@ static int tcc_relocate_ex(TCCState *S, void *ptr, addr_t ptr_diff)
redo:
for (k = 0; k < 3; ++k) { /* 0:rx, 1:ro, 2:rw sections */
n = 0; addr = 0;
- for(i = 1; i < S->nb_sections; i++) {
+ for(i = 1; i < s1->nb_sections; i++) {
static const char shf[] = {
SHF_ALLOC|SHF_EXECINSTR, SHF_ALLOC, SHF_ALLOC|SHF_WRITE
};
- s = S->sections[i];
+ s = s1->sections[i];
if (shf[k] != (s->sh_flags & (SHF_ALLOC|SHF_WRITE|SHF_EXECINSTR)))
continue;
length = s->data_offset;
@@ -277,11 +277,11 @@ redo:
else
memcpy(ptr, s->data, length);
#ifdef _WIN64
- if (s == S->uw_pdata)
- *(void**)mem = win64_add_function_table(S);
+ if (s == s1->uw_pdata)
+ *(void**)mem = win64_add_function_table(s1);
#endif
if (s->data) {
- tcc_free(S, s->data);
+ tcc_free(s->data);
s->data = NULL;
s->data_allocated = 0;
}
@@ -316,7 +316,7 @@ redo:
printf("protect %d %p %04x\n", f, (void*)addr, n);
#endif
if (n)
- set_pages_executable(S, f, (void*)addr, n);
+ set_pages_executable(s1, f, (void*)addr, n);
}
}
@@ -324,21 +324,21 @@ redo:
return 0;
/* relocate symbols */
- relocate_syms(S, S->symtab, !(S->nostdlib));
- if (S->nb_errors)
+ relocate_syms(s1, s1->symtab, !(s1->nostdlib));
+ if (s1->nb_errors)
return -1;
if (0 == mem)
return offset + max_align;
#ifdef TCC_TARGET_PE
- S->pe_imagebase = mem;
+ s1->pe_imagebase = mem;
#endif
/* relocate sections */
#ifndef TCC_TARGET_PE
- relocate_plt(S);
+ relocate_plt(s1);
#endif
- relocate_sections(S);
+ relocate_sections(s1);
copy = 1;
goto redo;
}
@@ -346,7 +346,7 @@ redo:
/* ------------------------------------------------------------- */
/* allow to run code in memory */
-static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long length)
+static void set_pages_executable(TCCState *s1, int mode, void *ptr, unsigned long length)
{
#ifdef _WIN32
static const unsigned char protect[] = {
@@ -369,7 +369,7 @@ static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long
end = (addr_t)ptr + length;
end = (end + PAGESIZE - 1) & ~(PAGESIZE - 1);
if (mprotect((void *)start, end - start, protect[mode]))
- tcc_error(S, "mprotect failed: did you mean to configure --with-selinux?");
+ tcc_error("mprotect failed: did you mean to configure --with-selinux?");
/* XXX: BSD sometimes dump core with bad system call */
# if (TCC_TARGET_ARM && !TARGETOS_BSD) || TCC_TARGET_ARM64
@@ -383,17 +383,17 @@ static void set_pages_executable(TCCState *S, int mode, void *ptr, unsigned long
}
#ifdef _WIN64
-static void *win64_add_function_table(TCCState *S)
+static void *win64_add_function_table(TCCState *s1)
{
void *p = NULL;
- if (S->uw_pdata) {
- p = (void*)S->uw_pdata->sh_addr;
+ if (s1->uw_pdata) {
+ p = (void*)s1->uw_pdata->sh_addr;
RtlAddFunctionTable(
(RUNTIME_FUNCTION*)p,
- S->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
- S->pe_imagebase
+ s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
+ s1->pe_imagebase
);
- S->uw_pdata = NULL;
+ s1->uw_pdata = NULL;
}
return p;
}
diff --git a/tcctools.c b/tcctools.c
index 47a8720..cf17496 100644
--- a/tcctools.c
+++ b/tcctools.c
@@ -66,7 +66,7 @@ static int ar_usage(int ret) {
return ret;
}
-ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
+ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
{
static const ArHdr arhdr_init = {
"/ ",
@@ -135,7 +135,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
}
funcmax = 250;
- afpos = tcc_realloc(S, NULL, funcmax * sizeof *afpos); // 250 func
+ afpos = tcc_realloc(NULL, funcmax * sizeof *afpos); // 250 func
memcpy(&arhdro.ar_mode, "100666", 6);
// i_obj = first input object file
@@ -155,7 +155,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
fseek(fi, 0, SEEK_END);
fsize = ftell(fi);
fseek(fi, 0, SEEK_SET);
- buf = tcc_malloc(S, fsize + 1);
+ buf = tcc_malloc(fsize + 1);
fread(buf, fsize, 1, fi);
fclose(fi);
@@ -203,12 +203,12 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
)) {
//printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
istrlen = strlen(strtab + sym->st_name)+1;
- anames = tcc_realloc(S, anames, strpos+istrlen);
+ anames = tcc_realloc(anames, strpos+istrlen);
strcpy(anames + strpos, strtab + sym->st_name);
strpos += istrlen;
if (++funccnt >= funcmax) {
funcmax += 250;
- afpos = tcc_realloc(S, afpos, funcmax * sizeof *afpos); // 250 func more
+ afpos = tcc_realloc(afpos, funcmax * sizeof *afpos); // 250 func more
}
afpos[funccnt] = fpos;
}
@@ -229,7 +229,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
memcpy(&arhdro.ar_size, stmp, 10);
fwrite(&arhdro, sizeof(arhdro), 1, fo);
fwrite(buf, fsize, 1, fo);
- tcc_free(S, buf);
+ tcc_free(buf);
i_obj++;
fpos += (fsize + sizeof(arhdro));
}
@@ -253,16 +253,16 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
fseek(fo, 0, SEEK_END);
fsize = ftell(fo);
fseek(fo, 0, SEEK_SET);
- buf = tcc_malloc(S, fsize + 1);
+ buf = tcc_malloc(fsize + 1);
fread(buf, fsize, 1, fo);
fwrite(buf, fsize, 1, fh);
- tcc_free(S, buf);
+ tcc_free(buf);
ret = 0;
the_end:
if (anames)
- tcc_free(S, anames);
+ tcc_free(anames);
if (afpos)
- tcc_free(S, afpos);
+ tcc_free(afpos);
if (fh)
fclose(fh);
if (fo)
@@ -294,7 +294,7 @@ the_end:
#ifdef TCC_TARGET_PE
-ST_FUNC int tcc_tool_impdef(TCCState *S, int argc, char **argv)
+ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv)
{
int ret, v, i;
char infile[260];
@@ -353,7 +353,7 @@ usage:
if (SearchPath(NULL, file, ".dll", sizeof path, path, NULL))
file = path;
#endif
- ret = tcc_get_dllexports(S, file, &p);
+ ret = tcc_get_dllexports(file, &p);
if (ret || !p) {
fprintf(stderr, "tcc: impdef: %s '%s'\n",
ret == -1 ? "can't find file" :
@@ -386,7 +386,7 @@ usage:
the_end:
if (p)
- tcc_free(S, p);
+ tcc_free(p);
if (fp)
fclose(fp);
if (op)
@@ -421,9 +421,9 @@ the_end:
#if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64
-ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int option)
+ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int option)
{
- tcc_error(S, "-m%d not implemented.", option);
+ tcc_error("-m%d not implemented.", option);
}
#else
@@ -439,7 +439,7 @@ static char *str_replace(const char *str, const char *p, const char *r)
sl = strlen(str);
pl = strlen(p);
rl = strlen(r);
- for (d0 = NULL;; d0 = tcc_malloc(S, sl + 1)) {
+ for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) {
for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) {
if (d) {
memcpy(d, s0, sl = s - s0), d += sl;
@@ -470,7 +470,7 @@ static int execvp_win32(const char *prog, char **argv)
#define execvp execvp_win32
#endif /* _WIN32 */
-ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int target)
+ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int target)
{
char program[4096];
char *a0 = argv[0];
@@ -489,7 +489,7 @@ ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int target)
if (strcmp(a0, program))
execvp(argv[0] = program, argv);
- tcc_error(S, "could not run '%s'", program);
+ tcc_error("could not run '%s'", program);
}
#endif /* TCC_TARGET_I386 && TCC_TARGET_X86_64 */
@@ -506,8 +506,8 @@ const int _dowildcard = 1;
/* -------------------------------------------------------------- */
/* generate xxx.d file */
-static char *escape_target_dep(TCCState *S, const char *s) {
- char *res = tcc_malloc(S, strlen(s) * 2 + 1);
+static char *escape_target_dep(const char *s) {
+ char *res = tcc_malloc(strlen(s) * 2 + 1);
int j;
for (j = 0; *s; s++, j++) {
if (is_space(*s)) {
@@ -519,7 +519,7 @@ static char *escape_target_dep(TCCState *S, const char *s) {
return res;
}
-ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
+ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename)
{
FILE *depout;
char buf[1024], *escaped_target;
@@ -532,7 +532,7 @@ ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
filename = buf;
}
- if (S->verbose)
+ if (s1->verbose)
printf("<- %s\n", filename);
if(!strcmp(filename, "-"))
@@ -541,15 +541,15 @@ ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
/* XXX return err codes instead of error() ? */
depout = fopen(filename, "w");
if (!depout)
- tcc_error(S, "could not open '%s'", filename);
+ tcc_error("could not open '%s'", filename);
fprintf(depout, "%s:", target);
- for (i = 0; i<S->nb_target_deps; ++i) {
+ for (i = 0; i<s1->nb_target_deps; ++i) {
for (k = 0; k < i; ++k)
- if (0 == strcmp(S->target_deps[i], S->target_deps[k]))
+ if (0 == strcmp(s1->target_deps[i], s1->target_deps[k]))
goto next;
- escaped_target = escape_target_dep(S, S->target_deps[i]);
+ escaped_target = escape_target_dep(s1->target_deps[i]);
fprintf(depout, " \\\n %s", escaped_target);
- tcc_free(S, escaped_target);
+ tcc_free(escaped_target);
next:;
}
fprintf(depout, "\n");
diff --git a/x86_64-gen.c b/x86_64-gen.c
index 07704fd..81ec5d9 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -148,66 +148,79 @@ ST_DATA const int reg_classes[NB_REGS] = {
/* st0 */ RC_ST0
};
+static unsigned long func_sub_sp_offset;
+static int func_ret_sub;
+
+#if defined(CONFIG_TCC_BCHECK)
+static addr_t func_bound_offset;
+static unsigned long func_bound_ind;
+ST_DATA int func_bound_add_epilog;
+#endif
+
+#ifdef TCC_TARGET_PE
+static int func_scratch, func_alloca;
+#endif
+
/* XXX: make it faster ? */
-ST_FUNC void g(TCCState* S, int c)
+ST_FUNC void g(int c)
{
int ind1;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return;
- ind1 = S->tccgen_ind + 1;
+ ind1 = ind + 1;
if (ind1 > cur_text_section->data_allocated)
- section_realloc(S, cur_text_section, ind1);
- cur_text_section->data[S->tccgen_ind] = c;
- S->tccgen_ind = ind1;
+ section_realloc(cur_text_section, ind1);
+ cur_text_section->data[ind] = c;
+ ind = ind1;
}
-ST_FUNC void o(TCCState* S, unsigned int c)
+ST_FUNC void o(unsigned int c)
{
while (c) {
- g(S, c);
+ g(c);
c = c >> 8;
}
}
-ST_FUNC void gen_le16(TCCState* S, int v)
+ST_FUNC void gen_le16(int v)
{
- g(S, v);
- g(S, v >> 8);
+ g(v);
+ g(v >> 8);
}
-ST_FUNC void gen_le32(TCCState* S, int c)
+ST_FUNC void gen_le32(int c)
{
- g(S, c);
- g(S, c >> 8);
- g(S, c >> 16);
- g(S, c >> 24);
+ g(c);
+ g(c >> 8);
+ g(c >> 16);
+ g(c >> 24);
}
-ST_FUNC void gen_le64(TCCState* S, int64_t c)
+ST_FUNC void gen_le64(int64_t c)
{
- g(S, c);
- g(S, c >> 8);
- g(S, c >> 16);
- g(S, c >> 24);
- g(S, c >> 32);
- g(S, c >> 40);
- g(S, c >> 48);
- g(S, c >> 56);
+ g(c);
+ g(c >> 8);
+ g(c >> 16);
+ g(c >> 24);
+ g(c >> 32);
+ g(c >> 40);
+ g(c >> 48);
+ g(c >> 56);
}
-static void orex(TCCState* S, int ll, int r, int r2, int b)
+static void orex(int ll, int r, int r2, int b)
{
if ((r & VT_VALMASK) >= VT_CONST)
r = 0;
if ((r2 & VT_VALMASK) >= VT_CONST)
r2 = 0;
if (ll || REX_BASE(r) || REX_BASE(r2))
- o(S, 0x40 | REX_BASE(r) | (REX_BASE(r2) << 2) | (ll << 3));
- o(S, b);
+ o(0x40 | REX_BASE(r) | (REX_BASE(r2) << 2) | (ll << 3));
+ o(b);
}
/* output a symbol and patch all calls to it */
-ST_FUNC void gsym_addr(TCCState* S, int t, int a)
+ST_FUNC void gsym_addr(int t, int a)
{
while (t) {
unsigned char *ptr = cur_text_section->data + t;
@@ -225,136 +238,136 @@ static int is64_type(int t)
}
/* instruction + 4 bytes data. Return the address of the data */
-static int oad(TCCState *S, int c, int s)
+static int oad(int c, int s)
{
int t;
- if (S->tccgen_nocode_wanted)
+ if (nocode_wanted)
return s;
- o(S, c);
- t = S->tccgen_ind;
- gen_le32(S, s);
+ o(c);
+ t = ind;
+ gen_le32(s);
return t;
}
/* generate jmp to a label */
-#define gjmp2(S, instr,lbl) oad(S, instr,lbl)
+#define gjmp2(instr,lbl) oad(instr,lbl)
-ST_FUNC void gen_addr32(TCCState *S, int r, Sym *sym, int c)
+ST_FUNC void gen_addr32(int r, Sym *sym, int c)
{
if (r & VT_SYM)
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_X86_64_32S, c), c=0;
- gen_le32(S, c);
+ greloca(cur_text_section, sym, ind, R_X86_64_32S, c), c=0;
+ gen_le32(c);
}
/* output constant with relocation if 'r & VT_SYM' is true */
-ST_FUNC void gen_addr64(TCCState *S, int r, Sym *sym, int64_t c)
+ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c)
{
if (r & VT_SYM)
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_X86_64_64, c), c=0;
- gen_le64(S, c);
+ greloca(cur_text_section, sym, ind, R_X86_64_64, c), c=0;
+ gen_le64(c);
}
/* output constant with relocation if 'r & VT_SYM' is true */
-ST_FUNC void gen_addrpc32(TCCState *S, int r, Sym *sym, int c)
+ST_FUNC void gen_addrpc32(int r, Sym *sym, int c)
{
if (r & VT_SYM)
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_X86_64_PC32, c-4), c=4;
- gen_le32(S, c-4);
+ greloca(cur_text_section, sym, ind, R_X86_64_PC32, c-4), c=4;
+ gen_le32(c-4);
}
/* output got address with relocation */
-static void gen_gotpcrel(TCCState *S, int r, Sym *sym, int c)
+static void gen_gotpcrel(int r, Sym *sym, int c)
{
#ifdef TCC_TARGET_PE
- tcc_error(S, "internal error: no GOT on PE: %s %x %x | %02x %02x %02x\n",
- get_tok_str(S, sym->v, NULL), c, r,
- cur_text_section->data[S->tccgen_ind-3],
- cur_text_section->data[S->tccgen_ind-2],
- cur_text_section->data[S->tccgen_ind-1]
+ tcc_error("internal error: no GOT on PE: %s %x %x | %02x %02x %02x\n",
+ get_tok_str(sym->v, NULL), c, r,
+ cur_text_section->data[ind-3],
+ cur_text_section->data[ind-2],
+ cur_text_section->data[ind-1]
);
#endif
- greloca(S, cur_text_section, sym, S->tccgen_ind, R_X86_64_GOTPCREL, -4);
- gen_le32(S, 0);
+ greloca(cur_text_section, sym, ind, R_X86_64_GOTPCREL, -4);
+ gen_le32(0);
if (c) {
/* we use add c, %xxx for displacement */
- orex(S, 1, r, 0, 0x81);
- o(S, 0xc0 + REG_VALUE(r));
- gen_le32(S, c);
+ orex(1, r, 0, 0x81);
+ o(0xc0 + REG_VALUE(r));
+ gen_le32(c);
}
}
-static void gen_modrm_impl(TCCState *S, int op_reg, int r, Sym *sym, int c, int is_got)
+static void gen_modrm_impl(int op_reg, int r, Sym *sym, int c, int is_got)
{
op_reg = REG_VALUE(op_reg) << 3;
if ((r & VT_VALMASK) == VT_CONST) {
/* constant memory reference */
if (!(r & VT_SYM)) {
/* Absolute memory reference */
- o(S, 0x04 | op_reg); /* [sib] | destreg */
- oad(S, 0x25, c); /* disp32 */
+ o(0x04 | op_reg); /* [sib] | destreg */
+ oad(0x25, c); /* disp32 */
} else {
- o(S, 0x05 | op_reg); /* (%rip)+disp32 | destreg */
+ o(0x05 | op_reg); /* (%rip)+disp32 | destreg */
if (is_got) {
- gen_gotpcrel(S, r, sym, c);
+ gen_gotpcrel(r, sym, c);
} else {
- gen_addrpc32(S, r, sym, c);
+ gen_addrpc32(r, sym, c);
}
}
} else if ((r & VT_VALMASK) == VT_LOCAL) {
/* currently, we use only ebp as base */
if (c == (char)c) {
/* short reference */
- o(S, 0x45 | op_reg);
- g(S, c);
+ o(0x45 | op_reg);
+ g(c);
} else {
- oad(S, 0x85 | op_reg, c);
+ oad(0x85 | op_reg, c);
}
} else if ((r & VT_VALMASK) >= TREG_MEM) {
if (c) {
- g(S, 0x80 | op_reg | REG_VALUE(r));
- gen_le32(S, c);
+ g(0x80 | op_reg | REG_VALUE(r));
+ gen_le32(c);
} else {
- g(S, 0x00 | op_reg | REG_VALUE(r));
+ g(0x00 | op_reg | REG_VALUE(r));
}
} else {
- g(S, 0x00 | op_reg | REG_VALUE(r));
+ g(0x00 | op_reg | REG_VALUE(r));
}
}
/* generate a modrm reference. 'op_reg' contains the additional 3
opcode bits */
-static void gen_modrm(TCCState *S, int op_reg, int r, Sym *sym, int c)
+static void gen_modrm(int op_reg, int r, Sym *sym, int c)
{
- gen_modrm_impl(S, op_reg, r, sym, c, 0);
+ gen_modrm_impl(op_reg, r, sym, c, 0);
}
/* generate a modrm reference. 'op_reg' contains the additional 3
opcode bits */
-static void gen_modrm64(TCCState *S, int opcode, int op_reg, int r, Sym *sym, int c)
+static void gen_modrm64(int opcode, int op_reg, int r, Sym *sym, int c)
{
int is_got;
is_got = (op_reg & TREG_MEM) && !(sym->type.t & VT_STATIC);
- orex(S, 1, r, op_reg, opcode);
- gen_modrm_impl(S, op_reg, r, sym, c, is_got);
+ orex(1, r, op_reg, opcode);
+ gen_modrm_impl(op_reg, r, sym, c, is_got);
}
/* load 'r' from value 'sv' */
-void load(TCCState *S, int r, SValue *sv)
+void load(int r, SValue *sv)
{
int v, t, ft, fc, fr;
SValue v1;
#ifdef TCC_TARGET_PE
SValue v2;
- sv = pe_getimport(S, sv, &v2);
+ sv = pe_getimport(sv, &v2);
#endif
fr = sv->r;
ft = sv->type.t & ~VT_DEFSIGN;
fc = sv->c.i;
if (fc != sv->c.i && (fr & VT_SYM))
- tcc_error(S, "64 bit addend in load");
+ tcc_error("64 bit addend in load");
ft &= ~(VT_VOLATILE | VT_CONSTANT);
@@ -366,9 +379,9 @@ void load(TCCState *S, int r, SValue *sv)
int tr = r | TREG_MEM;
if (is_float(ft)) {
/* we cannot use float registers as a temporal register */
- tr = get_reg(S, RC_INT) | TREG_MEM;
+ tr = get_reg(RC_INT) | TREG_MEM;
}
- gen_modrm64(S, 0x8b, tr, fr, sv->sym, 0);
+ gen_modrm64(0x8b, tr, fr, sv->sym, 0);
/* load from the temporal register */
fr = tr | VT_LVAL;
@@ -384,8 +397,8 @@ void load(TCCState *S, int r, SValue *sv)
v1.c.i = fc;
fr = r;
if (!(reg_classes[fr] & (RC_INT|RC_R11)))
- fr = get_reg(S, RC_INT);
- load(S, fr, &v1);
+ fr = get_reg(RC_INT);
+ load(fr, &v1);
}
if (fc != sv->c.i) {
/* If the addends doesn't fit into a 32bit signed
@@ -396,8 +409,8 @@ void load(TCCState *S, int r, SValue *sv)
v1.c.i = sv->c.i;
fr = r;
if (!(reg_classes[fr] & (RC_INT|RC_R11)))
- fr = get_reg(S, RC_INT);
- load(S, fr, &v1);
+ fr = get_reg(RC_INT);
+ load(fr, &v1);
fc = 0;
}
ll = 0;
@@ -413,7 +426,7 @@ void load(TCCState *S, int r, SValue *sv)
case 4: ft = VT_INT; break;
case 8: ft = VT_LLONG; break;
default:
- tcc_error(S, "invalid aggregate type for register load");
+ tcc_error("invalid aggregate type for register load");
break;
}
}
@@ -446,101 +459,101 @@ void load(TCCState *S, int r, SValue *sv)
b = 0x8b;
}
if (ll) {
- gen_modrm64(S, b, r, fr, sv->sym, fc);
+ gen_modrm64(b, r, fr, sv->sym, fc);
} else {
- orex(S, ll, fr, r, b);
- gen_modrm(S, r, fr, sv->sym, fc);
+ orex(ll, fr, r, b);
+ gen_modrm(r, fr, sv->sym, fc);
}
} else {
if (v == VT_CONST) {
if (fr & VT_SYM) {
#ifdef TCC_TARGET_PE
- orex(S, 1,0,r,0x8d);
- o(S, 0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
- gen_addrpc32(S, fr, sv->sym, fc);
+ orex(1,0,r,0x8d);
+ o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
+ gen_addrpc32(fr, sv->sym, fc);
#else
if (sv->sym->type.t & VT_STATIC) {
- orex(S, 1,0,r,0x8d);
- o(S, 0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
- gen_addrpc32(S, fr, sv->sym, fc);
+ orex(1,0,r,0x8d);
+ o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
+ gen_addrpc32(fr, sv->sym, fc);
} else {
- orex(S, 1,0,r,0x8b);
- o(S, 0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */
- gen_gotpcrel(S, r, sv->sym, fc);
+ orex(1,0,r,0x8b);
+ o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */
+ gen_gotpcrel(r, sv->sym, fc);
}
#endif
} else if (is64_type(ft)) {
- orex(S, 1,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
- gen_le64(S, sv->c.i);
+ orex(1,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
+ gen_le64(sv->c.i);
} else {
- orex(S, 0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
- gen_le32(S, fc);
+ orex(0,r,0, 0xb8 + REG_VALUE(r)); /* mov $xx, r */
+ gen_le32(fc);
}
} else if (v == VT_LOCAL) {
- orex(S, 1,0,r,0x8d); /* lea xxx(%ebp), r */
- gen_modrm(S, r, VT_LOCAL, sv->sym, fc);
+ orex(1,0,r,0x8d); /* lea xxx(%ebp), r */
+ gen_modrm(r, VT_LOCAL, sv->sym, fc);
} else if (v == VT_CMP) {
if (fc & 0x100)
{
- v = S->tccgen_vtop->cmp_r;
+ v = vtop->cmp_r;
fc &= ~0x100;
/* This was a float compare. If the parity bit is
set the result was unordered, meaning false for everything
except TOK_NE, and true for TOK_NE. */
- orex(S, 0, r, 0, 0xb0 + REG_VALUE(r)); /* mov $0/1,%al */
- g(S, v ^ fc ^ (v == TOK_NE));
- o(S, 0x037a + (REX_BASE(r) << 8));
+ orex(0, r, 0, 0xb0 + REG_VALUE(r)); /* mov $0/1,%al */
+ g(v ^ fc ^ (v == TOK_NE));
+ o(0x037a + (REX_BASE(r) << 8));
}
- orex(S, 0,r,0, 0x0f); /* setxx %br */
- o(S, fc);
- o(S, 0xc0 + REG_VALUE(r));
- orex(S, 0,r,0, 0x0f);
- o(S, 0xc0b6 + REG_VALUE(r) * 0x900); /* movzbl %al, %eax */
+ orex(0,r,0, 0x0f); /* setxx %br */
+ o(fc);
+ o(0xc0 + REG_VALUE(r));
+ orex(0,r,0, 0x0f);
+ o(0xc0b6 + REG_VALUE(r) * 0x900); /* movzbl %al, %eax */
} else if (v == VT_JMP || v == VT_JMPI) {
t = v & 1;
- orex(S, 0,r,0,0);
- oad(S, 0xb8 + REG_VALUE(r), t); /* mov $1, r */
- o(S, 0x05eb + (REX_BASE(r) << 8)); /* jmp after */
- gsym(S, fc);
- orex(S, 0,r,0,0);
- oad(S, 0xb8 + REG_VALUE(r), t ^ 1); /* mov $0, r */
+ orex(0,r,0,0);
+ oad(0xb8 + REG_VALUE(r), t); /* mov $1, r */
+ o(0x05eb + (REX_BASE(r) << 8)); /* jmp after */
+ gsym(fc);
+ orex(0,r,0,0);
+ oad(0xb8 + REG_VALUE(r), t ^ 1); /* mov $0, r */
} else if (v != r) {
if ((r >= TREG_XMM0) && (r <= TREG_XMM7)) {
if (v == TREG_ST0) {
/* gen_cvt_ftof(VT_DOUBLE); */
- o(S, 0xf0245cdd); /* fstpl -0x10(%rsp) */
+ o(0xf0245cdd); /* fstpl -0x10(%rsp) */
/* movsd -0x10(%rsp),%xmmN */
- o(S, 0x100ff2);
- o(S, 0x44 + REG_VALUE(r)*8); /* %xmmN */
- o(S, 0xf024);
+ o(0x100ff2);
+ o(0x44 + REG_VALUE(r)*8); /* %xmmN */
+ o(0xf024);
} else {
assert((v >= TREG_XMM0) && (v <= TREG_XMM7));
if ((ft & VT_BTYPE) == VT_FLOAT) {
- o(S, 0x100ff3);
+ o(0x100ff3);
} else {
assert((ft & VT_BTYPE) == VT_DOUBLE);
- o(S, 0x100ff2);
+ o(0x100ff2);
}
- o(S, 0xc0 + REG_VALUE(v) + REG_VALUE(r)*8);
+ o(0xc0 + REG_VALUE(v) + REG_VALUE(r)*8);
}
} else if (r == TREG_ST0) {
assert((v >= TREG_XMM0) && (v <= TREG_XMM7));
/* gen_cvt_ftof(VT_LDOUBLE); */
/* movsd %xmmN,-0x10(%rsp) */
- o(S, 0x110ff2);
- o(S, 0x44 + REG_VALUE(r)*8); /* %xmmN */
- o(S, 0xf024);
- o(S, 0xf02444dd); /* fldl -0x10(%rsp) */
+ o(0x110ff2);
+ o(0x44 + REG_VALUE(r)*8); /* %xmmN */
+ o(0xf024);
+ o(0xf02444dd); /* fldl -0x10(%rsp) */
} else {
- orex(S, is64_type(ft), r, v, 0x89);
- o(S, 0xc0 + REG_VALUE(r) + REG_VALUE(v) * 8); /* mov v, r */
+ orex(is64_type(ft), r, v, 0x89);
+ o(0xc0 + REG_VALUE(r) + REG_VALUE(v) * 8); /* mov v, r */
}
}
}
}
/* store register 'r' in lvalue 'v' */
-void store(TCCState *S, int r, SValue *v)
+void store(int r, SValue *v)
{
int fr, bt, ft, fc;
int op64 = 0;
@@ -549,14 +562,14 @@ void store(TCCState *S, int r, SValue *v)
#ifdef TCC_TARGET_PE
SValue v2;
- v = pe_getimport(S, v, &v2);
+ v = pe_getimport(v, &v2);
#endif
fr = v->r & VT_VALMASK;
ft = v->type.t;
fc = v->c.i;
if (fc != v->c.i && (fr & VT_SYM))
- tcc_error(S, "64 bit addend in store");
+ tcc_error("64 bit addend in store");
ft &= ~(VT_VOLATILE | VT_CONSTANT);
bt = ft & VT_BTYPE;
@@ -566,93 +579,93 @@ void store(TCCState *S, int r, SValue *v)
&& (v->r & VT_SYM)
&& !(v->sym->type.t & VT_STATIC)) {
/* mov xx(%rip), %r11 */
- o(S, 0x1d8b4c);
- gen_gotpcrel(S, TREG_R11, v->sym, v->c.i);
+ o(0x1d8b4c);
+ gen_gotpcrel(TREG_R11, v->sym, v->c.i);
pic = is64_type(bt) ? 0x49 : 0x41;
}
#endif
/* XXX: incorrect if float reg to reg */
if (bt == VT_FLOAT) {
- o(S, 0x66);
- o(S, pic);
- o(S, 0x7e0f); /* movd */
+ o(0x66);
+ o(pic);
+ o(0x7e0f); /* movd */
r = REG_VALUE(r);
} else if (bt == VT_DOUBLE) {
- o(S, 0x66);
- o(S, pic);
- o(S, 0xd60f); /* movq */
+ o(0x66);
+ o(pic);
+ o(0xd60f); /* movq */
r = REG_VALUE(r);
} else if (bt == VT_LDOUBLE) {
- o(S, 0xc0d9); /* fld %st(0) */
- o(S, pic);
- o(S, 0xdb); /* fstpt */
+ o(0xc0d9); /* fld %st(0) */
+ o(pic);
+ o(0xdb); /* fstpt */
r = 7;
} else {
if (bt == VT_SHORT)
- o(S, 0x66);
- o(S, pic);
+ o(0x66);
+ o(pic);
if (bt == VT_BYTE || bt == VT_BOOL)
- orex(S, 0, 0, r, 0x88);
+ orex(0, 0, r, 0x88);
else if (is64_type(bt))
op64 = 0x89;
else
- orex(S, 0, 0, r, 0x89);
+ orex(0, 0, r, 0x89);
}
if (pic) {
/* xxx r, (%r11) where xxx is mov, movq, fld, or etc */
if (op64)
- o(S, op64);
- o(S, 3 + (r << 3));
+ o(op64);
+ o(3 + (r << 3));
} else if (op64) {
if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) {
- gen_modrm64(S, op64, r, v->r, v->sym, fc);
+ gen_modrm64(op64, r, v->r, v->sym, fc);
} else if (fr != r) {
- orex(S, 1, fr, r, op64);
- o(S, 0xc0 + fr + r * 8); /* mov r, fr */
+ orex(1, fr, r, op64);
+ o(0xc0 + fr + r * 8); /* mov r, fr */
}
} else {
if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) {
- gen_modrm(S, r, v->r, v->sym, fc);
+ gen_modrm(r, v->r, v->sym, fc);
} else if (fr != r) {
- o(S, 0xc0 + fr + r * 8); /* mov r, fr */
+ o(0xc0 + fr + r * 8); /* mov r, fr */
}
}
}
/* 'is_jmp' is '1' if it is a jump */
-static void gcall_or_jmp(TCCState *S, int is_jmp)
+static void gcall_or_jmp(int is_jmp)
{
int r;
- if ((S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
- ((S->tccgen_vtop->r & VT_SYM) && (S->tccgen_vtop->c.i-4) == (int)(S->tccgen_vtop->c.i-4))) {
+ if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
+ ((vtop->r & VT_SYM) && (vtop->c.i-4) == (int)(vtop->c.i-4))) {
/* constant symbolic case -> simple relocation */
#ifdef TCC_TARGET_PE
- greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 1, R_X86_64_PC32, (int)(S->tccgen_vtop->c.i-4));
+ greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PC32, (int)(vtop->c.i-4));
#else
- greloca(S, cur_text_section, S->tccgen_vtop->sym, S->tccgen_ind + 1, R_X86_64_PLT32, (int)(S->tccgen_vtop->c.i-4));
+ greloca(cur_text_section, vtop->sym, ind + 1, R_X86_64_PLT32, (int)(vtop->c.i-4));
#endif
- oad(S, 0xe8 + is_jmp, 0); /* call/jmp im */
+ oad(0xe8 + is_jmp, 0); /* call/jmp im */
} else {
/* otherwise, indirect call */
r = TREG_R11;
- load(S, r, S->tccgen_vtop);
- o(S, 0x41); /* REX */
- o(S, 0xff); /* call/jmp *r */
- o(S, 0xd0 + REG_VALUE(r) + (is_jmp << 4));
+ load(r, vtop);
+ o(0x41); /* REX */
+ o(0xff); /* call/jmp *r */
+ o(0xd0 + REG_VALUE(r) + (is_jmp << 4));
}
}
#if defined(CONFIG_TCC_BCHECK)
-static void gen_bounds_call(TCCState *S, int v)
+static void gen_bounds_call(int v)
{
- Sym *sym = external_helper_sym(S, v);
- oad(S, 0xe8, 0);
+ Sym *sym = external_helper_sym(v);
+ oad(0xe8, 0);
#ifdef TCC_TARGET_PE
- greloca(S, cur_text_section, sym, S->tccgen_ind-4, R_X86_64_PC32, -4);
+ greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
#else
- greloca(S, cur_text_section, sym, S->tccgen_ind-4, R_X86_64_PLT32, -4);
+ greloca(cur_text_section, sym, ind-4, R_X86_64_PLT32, -4);
#endif
}
@@ -662,51 +675,51 @@ static void gen_bounds_call(TCCState *S, int v)
# define TREG_FASTCALL_1 TREG_RDI
#endif
-static void gen_bounds_prolog(TCCState *S)
+static void gen_bounds_prolog(void)
{
/* leave some room for bound checking code */
- S->func_bound_offset = lbounds_section->data_offset;
- S->func_bound_ind = S->tccgen_ind;
- S->func_bound_add_epilog = 0;
- o(S, 0x0d8d48 + ((TREG_FASTCALL_1 == TREG_RDI) * 0x300000)); /*lbound section pointer */
- gen_le32(S, 0);
- oad(S, 0xb8, 0); /* call to function */
+ func_bound_offset = lbounds_section->data_offset;
+ func_bound_ind = ind;
+ func_bound_add_epilog = 0;
+ o(0x0d8d48 + ((TREG_FASTCALL_1 == TREG_RDI) * 0x300000)); /*lbound section pointer */
+ gen_le32 (0);
+ oad(0xb8, 0); /* call to function */
}
-static void gen_bounds_epilog(TCCState *S)
+static void gen_bounds_epilog(void)
{
addr_t saved_ind;
addr_t *bounds_ptr;
Sym *sym_data;
- int offset_modified = S->func_bound_offset != lbounds_section->data_offset;
+ int offset_modified = func_bound_offset != lbounds_section->data_offset;
- if (!offset_modified && !S->func_bound_add_epilog)
+ if (!offset_modified && !func_bound_add_epilog)
return;
/* add end of table info */
- bounds_ptr = section_ptr_add(S, lbounds_section, sizeof(addr_t));
+ bounds_ptr = section_ptr_add(lbounds_section, sizeof(addr_t));
*bounds_ptr = 0;
- sym_data = get_sym_ref(S, &S->tccgen_char_pointer_type, lbounds_section,
- S->func_bound_offset, lbounds_section->data_offset);
+ sym_data = get_sym_ref(&char_pointer_type, lbounds_section,
+ func_bound_offset, lbounds_section->data_offset);
/* generate bound local allocation */
if (offset_modified) {
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->func_bound_ind;
- greloca(S, cur_text_section, sym_data, S->tccgen_ind + 3, R_X86_64_PC32, -4);
- S->tccgen_ind = S->tccgen_ind + 7;
- gen_bounds_call(S, TOK___bound_local_new);
- S->tccgen_ind = saved_ind;
+ saved_ind = ind;
+ ind = func_bound_ind;
+ greloca(cur_text_section, sym_data, ind + 3, R_X86_64_PC32, -4);
+ ind = ind + 7;
+ gen_bounds_call(TOK___bound_local_new);
+ ind = saved_ind;
}
/* generate bound check local freeing */
- o(S, 0x5250); /* save returned value, if any */
- greloca(S, cur_text_section, sym_data, S->tccgen_ind + 3, R_X86_64_PC32, -4);
- o(S, 0x0d8d48 + ((TREG_FASTCALL_1 == TREG_RDI) * 0x300000)); /* lea xxx(%rip), %rcx/rdi */
- gen_le32(S, 0);
- gen_bounds_call(S, TOK___bound_local_delete);
- o(S, 0x585a); /* restore returned value, if any */
+ o(0x5250); /* save returned value, if any */
+ greloca(cur_text_section, sym_data, ind + 3, R_X86_64_PC32, -4);
+ o(0x0d8d48 + ((TREG_FASTCALL_1 == TREG_RDI) * 0x300000)); /* lea xxx(%rip), %rcx/rdi */
+ gen_le32 (0);
+ gen_bounds_call(TOK___bound_local_delete);
+ o(0x585a); /* restore returned value, if any */
}
#endif
@@ -731,15 +744,15 @@ static int arg_prepare_reg(int idx) {
all the parameters in call order. This functions pops all the
parameters and the function address. */
-static void gen_offs_sp(TCCState* S, int b, int r, int d)
+static void gen_offs_sp(int b, int r, int d)
{
- orex(S, 1,0,r & 0x100 ? 0 : r, b);
+ orex(1,0,r & 0x100 ? 0 : r, b);
if (d == (char)d) {
- o(S, 0x2444 | (REG_VALUE(r) << 3));
- g(S, d);
+ o(0x2444 | (REG_VALUE(r) << 3));
+ g(d);
} else {
- o(S, 0x2484 | (REG_VALUE(r) << 3));
- gen_le32(S, d);
+ o(0x2484 | (REG_VALUE(r) << 3));
+ gen_le32(d);
}
}
@@ -783,14 +796,14 @@ static int gfunc_arg_size(CType *type) {
return type_size(type, &align);
}
-void gfunc_call(TCCState* S, int nb_args)
+void gfunc_call(int nb_args)
{
int size, r, args_size, i, d, bt, struct_size;
int arg;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
args_size = (nb_args < REGN ? REGN : nb_args) * PTR_SIZE;
@@ -804,7 +817,7 @@ void gfunc_call(TCCState* S, int nb_args)
SValue *sv;
--arg;
- sv = &S->tccgen_vtop[-i];
+ sv = &vtop[-i];
bt = (sv->type.t & VT_BTYPE);
size = gfunc_arg_size(&sv->type);
@@ -815,132 +828,132 @@ void gfunc_call(TCCState* S, int nb_args)
/* align to stack align size */
size = (size + 15) & ~15;
/* generate structure store */
- r = get_reg(S, RC_INT);
- gen_offs_sp(S, 0x8d, r, struct_size);
+ r = get_reg(RC_INT);
+ gen_offs_sp(0x8d, r, struct_size);
struct_size += size;
/* generate memcpy call */
- vset(S, &sv->type, r | VT_LVAL, 0);
- vpushv(S, sv);
- vstore(S);
- --S->tccgen_vtop;
+ vset(&sv->type, r | VT_LVAL, 0);
+ vpushv(sv);
+ vstore();
+ --vtop;
} else if (bt == VT_LDOUBLE) {
- gv(S, RC_ST0);
- gen_offs_sp(S, 0xdb, 0x107, struct_size);
+ gv(RC_ST0);
+ gen_offs_sp(0xdb, 0x107, struct_size);
struct_size += 16;
}
}
- if (S->x86_64_gen_func_scratch < struct_size)
- S->x86_64_gen_func_scratch = struct_size;
+ if (func_scratch < struct_size)
+ func_scratch = struct_size;
arg = nb_args;
struct_size = args_size;
for(i = 0; i < nb_args; i++) {
--arg;
- bt = (S->tccgen_vtop->type.t & VT_BTYPE);
+ bt = (vtop->type.t & VT_BTYPE);
- size = gfunc_arg_size(&S->tccgen_vtop->type);
+ size = gfunc_arg_size(&vtop->type);
if (!using_regs(size)) {
/* align to stack align size */
size = (size + 15) & ~15;
if (arg >= REGN) {
- d = get_reg(S, RC_INT);
- gen_offs_sp(S, 0x8d, d, struct_size);
- gen_offs_sp(S, 0x89, d, arg*8);
+ d = get_reg(RC_INT);
+ gen_offs_sp(0x8d, d, struct_size);
+ gen_offs_sp(0x89, d, arg*8);
} else {
d = arg_prepare_reg(arg);
- gen_offs_sp(S, 0x8d, d, struct_size);
+ gen_offs_sp(0x8d, d, struct_size);
}
struct_size += size;
} else {
- if (is_sse_float(S->tccgen_vtop->type.t)) {
- if (S->nosse)
- tcc_error(S, "SSE disabled");
+ if (is_sse_float(vtop->type.t)) {
+ if (tcc_state->nosse)
+ tcc_error("SSE disabled");
if (arg >= REGN) {
- gv(S, RC_XMM0);
+ gv(RC_XMM0);
/* movq %xmm0, j*8(%rsp) */
- gen_offs_sp(S, 0xd60f66, 0x100, arg*8);
+ gen_offs_sp(0xd60f66, 0x100, arg*8);
} else {
/* Load directly to xmmN register */
- gv(S, RC_XMM0 << arg);
+ gv(RC_XMM0 << arg);
d = arg_prepare_reg(arg);
/* mov %xmmN, %rxx */
- o(S, 0x66);
- orex(S, 1,d,0, 0x7e0f);
- o(S, 0xc0 + arg*8 + REG_VALUE(d));
+ o(0x66);
+ orex(1,d,0, 0x7e0f);
+ o(0xc0 + arg*8 + REG_VALUE(d));
}
} else {
if (bt == VT_STRUCT) {
- S->tccgen_vtop->type.ref = NULL;
- S->tccgen_vtop->type.t = size > 4 ? VT_LLONG : size > 2 ? VT_INT
+ vtop->type.ref = NULL;
+ vtop->type.t = size > 4 ? VT_LLONG : size > 2 ? VT_INT
: size > 1 ? VT_SHORT : VT_BYTE;
}
- r = gv(S, RC_INT);
+ r = gv(RC_INT);
if (arg >= REGN) {
- gen_offs_sp(S, 0x89, r, arg*8);
+ gen_offs_sp(0x89, r, arg*8);
} else {
d = arg_prepare_reg(arg);
- orex(S, 1,d,r,0x89); /* mov */
- o(S, 0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d));
+ orex(1,d,r,0x89); /* mov */
+ o(0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d));
}
}
}
- S->tccgen_vtop--;
+ vtop--;
}
- save_regs(S, 0);
+ save_regs(0);
/* Copy R10 and R11 into RCX and RDX, respectively */
if (nb_args > 0) {
- o(S, 0xd1894c); /* mov %r10, %rcx */
+ o(0xd1894c); /* mov %r10, %rcx */
if (nb_args > 1) {
- o(S, 0xda894c); /* mov %r11, %rdx */
+ o(0xda894c); /* mov %r11, %rdx */
}
}
- gcall_or_jmp(S, 0);
+ gcall_or_jmp(0);
- if ((S->tccgen_vtop->r & VT_SYM) && S->tccgen_vtop->sym->v == TOK_alloca) {
+ if ((vtop->r & VT_SYM) && vtop->sym->v == TOK_alloca) {
/* need to add the "func_scratch" area after alloca */
- o(S, 0x48); S->x86_64_gen_func_alloca = oad(S, 0x05, S->x86_64_gen_func_alloca); /* add $NN, %rax */
+ o(0x48); func_alloca = oad(0x05, func_alloca); /* add $NN, %rax */
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_call(S, TOK___bound_alloca_nr); /* new region */
+ if (tcc_state->do_bounds_check)
+ gen_bounds_call(TOK___bound_alloca_nr); /* new region */
#endif
}
- S->tccgen_vtop--;
+ vtop--;
}
#define FUNC_PROLOG_SIZE 11
/* generate function prolog of type 't' */
-void gfunc_prolog(TCCState* S, Sym *func_sym)
+void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
int addr, reg_param_index, bt, size;
Sym *sym;
CType *type;
- S->x86_64_gen_func_ret_sub = 0;
- S->x86_64_gen_func_scratch = 32;
- S->x86_64_gen_func_alloca = 0;
- S->tccgen_loc = 0;
+ func_ret_sub = 0;
+ func_scratch = 32;
+ func_alloca = 0;
+ loc = 0;
addr = PTR_SIZE * 2;
- S->tccgen_ind += FUNC_PROLOG_SIZE;
- S->x86_64_gen_func_sub_sp_offset = S->tccgen_ind;
+ ind += FUNC_PROLOG_SIZE;
+ func_sub_sp_offset = ind;
reg_param_index = 0;
sym = func_type->ref;
/* if the function returns a structure, then add an
implicit pointer parameter */
- size = gfunc_arg_size(&S->tccgen_func_vt);
+ size = gfunc_arg_size(&func_vt);
if (!using_regs(size)) {
- gen_modrm64(S, 0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
- S->tccgen_func_vc = addr;
+ gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
+ func_vc = addr;
reg_param_index++;
addr += 8;
}
@@ -952,23 +965,23 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
size = gfunc_arg_size(type);
if (!using_regs(size)) {
if (reg_param_index < REGN) {
- gen_modrm64(S, 0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
+ gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
}
- sym_push(S, sym->v & ~SYM_FIELD, type,
+ sym_push(sym->v & ~SYM_FIELD, type,
VT_LLOCAL | VT_LVAL, addr);
} else {
if (reg_param_index < REGN) {
/* save arguments passed by register */
if ((bt == VT_FLOAT) || (bt == VT_DOUBLE)) {
- if (S->nosse)
- tcc_error(S, "SSE disabled");
- o(S, 0xd60f66); /* movq */
- gen_modrm(S, reg_param_index, VT_LOCAL, NULL, addr);
+ if (tcc_state->nosse)
+ tcc_error("SSE disabled");
+ o(0xd60f66); /* movq */
+ gen_modrm(reg_param_index, VT_LOCAL, NULL, addr);
} else {
- gen_modrm64(S, 0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
+ gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
}
}
- sym_push(S, sym->v & ~SYM_FIELD, type,
+ sym_push(sym->v & ~SYM_FIELD, type,
VT_LOCAL | VT_LVAL, addr);
}
addr += 8;
@@ -976,74 +989,74 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
}
while (reg_param_index < REGN) {
- if (S->tccgen_func_var) {
- gen_modrm64(S, 0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
+ if (func_var) {
+ gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
addr += 8;
}
reg_param_index++;
}
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
/* generate function epilog */
-void gfunc_epilog(TCCState* S)
+void gfunc_epilog(void)
{
int v, saved_ind;
/* align local size to word & save local variables */
- S->x86_64_gen_func_scratch = (S->x86_64_gen_func_scratch + 15) & -16;
- S->tccgen_loc = (S->tccgen_loc & -16) - S->x86_64_gen_func_scratch;
+ func_scratch = (func_scratch + 15) & -16;
+ loc = (loc & -16) - func_scratch;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
- o(S, 0xc9); /* leave */
- if (S->x86_64_gen_func_ret_sub == 0) {
- o(S, 0xc3); /* ret */
+ o(0xc9); /* leave */
+ if (func_ret_sub == 0) {
+ o(0xc3); /* ret */
} else {
- o(S, 0xc2); /* ret n */
- g(S, S->x86_64_gen_func_ret_sub);
- g(S, S->x86_64_gen_func_ret_sub >> 8);
+ o(0xc2); /* ret n */
+ g(func_ret_sub);
+ g(func_ret_sub >> 8);
}
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->x86_64_gen_func_sub_sp_offset - FUNC_PROLOG_SIZE;
- v = -S->tccgen_loc;
+ saved_ind = ind;
+ ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
+ v = -loc;
if (v >= 4096) {
- Sym *sym = external_helper_sym(S, TOK___chkstk);
- oad(S, 0xb8, v); /* mov stacksize, %eax */
- oad(S, 0xe8, 0); /* call __chkstk, (does the stackframe too) */
- greloca(S, cur_text_section, sym, S->tccgen_ind-4, R_X86_64_PC32, -4);
- o(S, 0x90); /* fill for FUNC_PROLOG_SIZE = 11 bytes */
+ Sym *sym = external_helper_sym(TOK___chkstk);
+ oad(0xb8, v); /* mov stacksize, %eax */
+ oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */
+ greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
+ o(0x90); /* fill for FUNC_PROLOG_SIZE = 11 bytes */
} else {
- o(S, 0xe5894855); /* push %rbp, mov %rsp, %rbp */
- o(S, 0xec8148); /* sub rsp, stacksize */
- gen_le32(S, v);
+ o(0xe5894855); /* push %rbp, mov %rsp, %rbp */
+ o(0xec8148); /* sub rsp, stacksize */
+ gen_le32(v);
}
/* add the "func_scratch" area after each alloca seen */
- gsym_addr(S, S->x86_64_gen_func_alloca, -S->x86_64_gen_func_scratch);
+ gsym_addr(func_alloca, -func_scratch);
cur_text_section->data_offset = saved_ind;
- pe_add_unwind_data(S, S->tccgen_ind, saved_ind, v);
- S->tccgen_ind = cur_text_section->data_offset;
+ pe_add_unwind_data(ind, saved_ind, v);
+ ind = cur_text_section->data_offset;
}
#else
-static void gadd_sp(TCCState* S, int val)
+static void gadd_sp(int val)
{
if (val == (char)val) {
- o(S, 0xc48348);
- g(S, val);
+ o(0xc48348);
+ g(val);
} else {
- oad(S, 0xc48148, val); /* add $xxx, %rsp */
+ oad(0xc48148, val); /* add $xxx, %rsp */
}
}
@@ -1216,7 +1229,7 @@ static int arg_prepare_reg(int idx) {
/* Generate function call. The function address is pushed first, then
all the parameters in call order. This functions pops all the
parameters and the function address. */
-void gfunc_call(TCCState* S, int nb_args)
+void gfunc_call(int nb_args)
{
X86_64_Mode mode;
CType type;
@@ -1224,11 +1237,11 @@ void gfunc_call(TCCState* S, int nb_args)
int nb_reg_args = 0;
int nb_sse_args = 0;
int sse_reg, gen_reg;
- char *onstack = tcc_malloc(S, (nb_args + 1) * sizeof (char));
+ char *onstack = tcc_malloc((nb_args + 1) * sizeof (char));
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gbound_args(S, nb_args);
+ if (tcc_state->do_bounds_check)
+ gbound_args(nb_args);
#endif
/* calculate the number of integer/float register arguments, remember
@@ -1237,7 +1250,7 @@ void gfunc_call(TCCState* S, int nb_args)
to be done in a left-to-right pass over arguments. */
stack_adjust = 0;
for(i = nb_args - 1; i >= 0; i--) {
- mode = classify_x86_64_arg(&S->tccgen_vtop[-i].type, NULL, &size, &align, &reg_count);
+ mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, &reg_count);
if (size == 0) continue;
if (mode == x86_64_mode_sse && nb_sse_args + reg_count <= 8) {
nb_sse_args += reg_count;
@@ -1257,12 +1270,12 @@ void gfunc_call(TCCState* S, int nb_args)
}
}
- if (nb_sse_args && S->nosse)
- tcc_error(S, "SSE disabled but floating point arguments passed");
+ if (nb_sse_args && tcc_state->nosse)
+ tcc_error("SSE disabled but floating point arguments passed");
/* fetch cpu flag before generating any code */
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_CMP)
- gv(S, RC_INT);
+ if ((vtop->r & VT_VALMASK) == VT_CMP)
+ gv(RC_INT);
/* for struct arguments, we need to call memcpy and the function
call breaks register passing arguments we are preparing.
@@ -1272,7 +1285,7 @@ void gfunc_call(TCCState* S, int nb_args)
args_size = 0;
stack_adjust &= 15;
for (i = k = 0; i < nb_args;) {
- mode = classify_x86_64_arg(&S->tccgen_vtop[-i].type, NULL, &size, &align, &reg_count);
+ mode = classify_x86_64_arg(&vtop[-i].type, NULL, &size, &align, &reg_count);
if (size) {
if (!onstack[i + k]) {
++i;
@@ -1283,7 +1296,7 @@ void gfunc_call(TCCState* S, int nb_args)
(stack grows down), so the adjustment needs to happen _after_
an argument that requires it. */
if (stack_adjust) {
- o(S, 0x50); /* push %rax; aka sub $8,%rsp */
+ o(0x50); /* push %rax; aka sub $8,%rsp */
args_size += 8;
stack_adjust = 0;
}
@@ -1291,60 +1304,60 @@ void gfunc_call(TCCState* S, int nb_args)
stack_adjust = 1;
}
- vrotb(S, i+1);
+ vrotb(i+1);
- switch (S->tccgen_vtop->type.t & VT_BTYPE) {
+ switch (vtop->type.t & VT_BTYPE) {
case VT_STRUCT:
/* allocate the necessary size on stack */
- o(S, 0x48);
- oad(S, 0xec81, size); /* sub $xxx, %rsp */
+ o(0x48);
+ oad(0xec81, size); /* sub $xxx, %rsp */
/* generate structure store */
- r = get_reg(S, RC_INT);
- orex(S, 1, r, 0, 0x89); /* mov %rsp, r */
- o(S, 0xe0 + REG_VALUE(r));
- vset(S, &S->tccgen_vtop->type, r | VT_LVAL, 0);
- vswap(S);
- vstore(S);
+ r = get_reg(RC_INT);
+ orex(1, r, 0, 0x89); /* mov %rsp, r */
+ o(0xe0 + REG_VALUE(r));
+ vset(&vtop->type, r | VT_LVAL, 0);
+ vswap();
+ vstore();
break;
case VT_LDOUBLE:
- gv(S, RC_ST0);
- oad(S, 0xec8148, size); /* sub $xxx, %rsp */
- o(S, 0x7cdb); /* fstpt 0(%rsp) */
- g(S, 0x24);
- g(S, 0x00);
+ gv(RC_ST0);
+ oad(0xec8148, size); /* sub $xxx, %rsp */
+ o(0x7cdb); /* fstpt 0(%rsp) */
+ g(0x24);
+ g(0x00);
break;
case VT_FLOAT:
case VT_DOUBLE:
assert(mode == x86_64_mode_sse);
- r = gv(S, RC_FLOAT);
- o(S, 0x50); /* push $rax */
+ r = gv(RC_FLOAT);
+ o(0x50); /* push $rax */
/* movq %xmmN, (%rsp) */
- o(S, 0xd60f66);
- o(S, 0x04 + REG_VALUE(r)*8);
- o(S, 0x24);
+ o(0xd60f66);
+ o(0x04 + REG_VALUE(r)*8);
+ o(0x24);
break;
default:
assert(mode == x86_64_mode_integer);
/* simple type */
/* XXX: implicit cast ? */
- r = gv(S, RC_INT);
- orex(S, 0,r,0,0x50 + REG_VALUE(r)); /* push r */
+ r = gv(RC_INT);
+ orex(0,r,0,0x50 + REG_VALUE(r)); /* push r */
break;
}
args_size += size;
- vpop(S);
+ vpop();
--nb_args;
k++;
}
- tcc_free(S, onstack);
+ tcc_free(onstack);
/* XXX This should be superfluous. */
- save_regs(S, 0); /* save used temporary registers */
+ save_regs(0); /* save used temporary registers */
/* then, we prepare register passing arguments.
Note that we cannot set RDX and RCX in this loop because gv()
@@ -1353,44 +1366,44 @@ void gfunc_call(TCCState* S, int nb_args)
assert(gen_reg <= REGN);
assert(sse_reg <= 8);
for(i = 0; i < nb_args; i++) {
- mode = classify_x86_64_arg(&S->tccgen_vtop->type, &type, &size, &align, &reg_count);
+ mode = classify_x86_64_arg(&vtop->type, &type, &size, &align, &reg_count);
if (size == 0) continue;
/* Alter stack entry type so that gv() knows how to treat it */
- S->tccgen_vtop->type = type;
+ vtop->type = type;
if (mode == x86_64_mode_sse) {
if (reg_count == 2) {
sse_reg -= 2;
- gv(S, RC_FRET); /* Use pair load into xmm0 & xmm1 */
+ gv(RC_FRET); /* Use pair load into xmm0 & xmm1 */
if (sse_reg) { /* avoid redundant movaps %xmm0, %xmm0 */
/* movaps %xmm1, %xmmN */
- o(S, 0x280f);
- o(S, 0xc1 + ((sse_reg+1) << 3));
+ o(0x280f);
+ o(0xc1 + ((sse_reg+1) << 3));
/* movaps %xmm0, %xmmN */
- o(S, 0x280f);
- o(S, 0xc0 + (sse_reg << 3));
+ o(0x280f);
+ o(0xc0 + (sse_reg << 3));
}
} else {
assert(reg_count == 1);
--sse_reg;
/* Load directly to register */
- gv(S, RC_XMM0 << sse_reg);
+ gv(RC_XMM0 << sse_reg);
}
} else if (mode == x86_64_mode_integer) {
/* simple type */
/* XXX: implicit cast ? */
int d;
gen_reg -= reg_count;
- r = gv(S, RC_INT);
+ r = gv(RC_INT);
d = arg_prepare_reg(gen_reg);
- orex(S, 1,d,r,0x89); /* mov */
- o(S, 0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d));
+ orex(1,d,r,0x89); /* mov */
+ o(0xc0 + REG_VALUE(r) * 8 + REG_VALUE(d));
if (reg_count == 2) {
d = arg_prepare_reg(gen_reg+1);
- orex(S, 1,d,S->tccgen_vtop->r2,0x89); /* mov */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r2) * 8 + REG_VALUE(d));
+ orex(1,d,vtop->r2,0x89); /* mov */
+ o(0xc0 + REG_VALUE(vtop->r2) * 8 + REG_VALUE(d));
}
}
- S->tccgen_vtop--;
+ vtop--;
}
assert(gen_reg == 0);
assert(sse_reg == 0);
@@ -1399,33 +1412,33 @@ void gfunc_call(TCCState* S, int nb_args)
call address itself is still there, and it might be in %eax
(or edx/ecx) currently, which the below writes would clobber.
So evict all remaining operands here. */
- save_regs(S, 0);
+ save_regs(0);
/* Copy R10 and R11 into RDX and RCX, respectively */
if (nb_reg_args > 2) {
- o(S, 0xd2894c); /* mov %r10, %rdx */
+ o(0xd2894c); /* mov %r10, %rdx */
if (nb_reg_args > 3) {
- o(S, 0xd9894c); /* mov %r11, %rcx */
+ o(0xd9894c); /* mov %r11, %rcx */
}
}
- if (S->tccgen_vtop->type.ref->f.func_type != FUNC_NEW) /* implies FUNC_OLD or FUNC_ELLIPSIS */
- oad(S, 0xb8, nb_sse_args < 8 ? nb_sse_args : 8); /* mov nb_sse_args, %eax */
- gcall_or_jmp(S, 0);
+ if (vtop->type.ref->f.func_type != FUNC_NEW) /* implies FUNC_OLD or FUNC_ELLIPSIS */
+ oad(0xb8, nb_sse_args < 8 ? nb_sse_args : 8); /* mov nb_sse_args, %eax */
+ gcall_or_jmp(0);
if (args_size)
- gadd_sp(S, args_size);
- S->tccgen_vtop--;
+ gadd_sp(args_size);
+ vtop--;
}
#define FUNC_PROLOG_SIZE 11
-static void push_arg_reg(TCCState* S, int i) {
- S->tccgen_loc -= 8;
- gen_modrm64(S, 0x89, arg_regs[i], VT_LOCAL, NULL, S->tccgen_loc);
+static void push_arg_reg(int i) {
+ loc -= 8;
+ gen_modrm64(0x89, arg_regs[i], VT_LOCAL, NULL, loc);
}
/* generate function prolog of type 't' */
-void gfunc_prolog(TCCState* S, Sym *func_sym)
+void gfunc_prolog(Sym *func_sym)
{
CType *func_type = &func_sym->type;
X86_64_Mode mode, ret_mode;
@@ -1436,13 +1449,13 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
sym = func_type->ref;
addr = PTR_SIZE * 2;
- S->tccgen_loc = 0;
- S->tccgen_ind += FUNC_PROLOG_SIZE;
- S->x86_64_gen_func_sub_sp_offset = S->tccgen_ind;
- S->x86_64_gen_func_ret_sub = 0;
- ret_mode = classify_x86_64_arg(&S->tccgen_func_vt, NULL, &size, &align, &reg_count);
+ loc = 0;
+ ind += FUNC_PROLOG_SIZE;
+ func_sub_sp_offset = ind;
+ func_ret_sub = 0;
+ ret_mode = classify_x86_64_arg(&func_vt, NULL, &size, &align, &reg_count);
- if (S->tccgen_func_var) {
+ if (func_var) {
int seen_reg_num, seen_sse_num, seen_stack_size;
seen_reg_num = ret_mode == x86_64_mode_memory;
seen_sse_num = 0;
@@ -1473,38 +1486,38 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
}
}
- S->tccgen_loc -= 24;
+ loc -= 24;
/* movl $0x????????, -0x18(%rbp) */
- o(S, 0xe845c7);
- gen_le32(S, seen_reg_num * 8);
+ o(0xe845c7);
+ gen_le32(seen_reg_num * 8);
/* movl $0x????????, -0x14(%rbp) */
- o(S, 0xec45c7);
- gen_le32(S, seen_sse_num * 16 + 48);
+ o(0xec45c7);
+ gen_le32(seen_sse_num * 16 + 48);
/* leaq $0x????????, %r11 */
- o(S, 0x9d8d4c);
- gen_le32(S, seen_stack_size);
+ o(0x9d8d4c);
+ gen_le32(seen_stack_size);
/* movq %r11, -0x10(%rbp) */
- o(S, 0xf05d894c);
+ o(0xf05d894c);
/* leaq $-192(%rbp), %r11 */
- o(S, 0x9d8d4c);
- gen_le32(S, -176 - 24);
+ o(0x9d8d4c);
+ gen_le32(-176 - 24);
/* movq %r11, -0x8(%rbp) */
- o(S, 0xf85d894c);
+ o(0xf85d894c);
/* save all register passing arguments */
for (i = 0; i < 8; i++) {
- S->tccgen_loc -= 16;
- if (!S->nosse) {
- o(S, 0xd60f66); /* movq */
- gen_modrm(S, 7 - i, VT_LOCAL, NULL, S->tccgen_loc);
+ loc -= 16;
+ if (!tcc_state->nosse) {
+ o(0xd60f66); /* movq */
+ gen_modrm(7 - i, VT_LOCAL, NULL, loc);
}
/* movq $0, loc+8(%rbp) */
- o(S, 0x85c748);
- gen_le32(S, S->tccgen_loc + 8);
- gen_le32(S, 0);
+ o(0x85c748);
+ gen_le32(loc + 8);
+ gen_le32(0);
}
for (i = 0; i < REGN; i++) {
- push_arg_reg(S, REGN-1-i);
+ push_arg_reg(REGN-1-i);
}
}
@@ -1515,8 +1528,8 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
/* if the function returns a structure, then add an
implicit pointer parameter */
if (ret_mode == x86_64_mode_memory) {
- push_arg_reg(S, reg_param_index);
- S->tccgen_func_vc = S->tccgen_loc;
+ push_arg_reg(reg_param_index);
+ func_vc = loc;
reg_param_index++;
}
/* define parameters */
@@ -1525,15 +1538,15 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
mode = classify_x86_64_arg(type, NULL, &size, &align, &reg_count);
switch (mode) {
case x86_64_mode_sse:
- if (S->nosse)
- tcc_error(S, "SSE disabled but floating point arguments used");
+ if (tcc_state->nosse)
+ tcc_error("SSE disabled but floating point arguments used");
if (sse_param_index + reg_count <= 8) {
/* save arguments passed by register */
- S->tccgen_loc -= reg_count * 8;
- param_addr = S->tccgen_loc;
+ loc -= reg_count * 8;
+ param_addr = loc;
for (i = 0; i < reg_count; ++i) {
- o(S, 0xd60f66); /* movq */
- gen_modrm(S, sse_param_index, VT_LOCAL, NULL, param_addr + i*8);
+ o(0xd60f66); /* movq */
+ gen_modrm(sse_param_index, VT_LOCAL, NULL, param_addr + i*8);
++sse_param_index;
}
} else {
@@ -1553,10 +1566,10 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
case x86_64_mode_integer: {
if (reg_param_index + reg_count <= REGN) {
/* save arguments passed by register */
- S->tccgen_loc -= reg_count * 8;
- param_addr = S->tccgen_loc;
+ loc -= reg_count * 8;
+ param_addr = loc;
for (i = 0; i < reg_count; ++i) {
- gen_modrm64(S, 0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, param_addr + i*8);
+ gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, param_addr + i*8);
++reg_param_index;
}
} else {
@@ -1568,71 +1581,71 @@ void gfunc_prolog(TCCState* S, Sym *func_sym)
}
default: break; /* nothing to be done for x86_64_mode_none */
}
- sym_push(S, sym->v & ~SYM_FIELD, type,
+ sym_push(sym->v & ~SYM_FIELD, type,
VT_LOCAL | VT_LVAL, param_addr);
}
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_prolog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_prolog();
#endif
}
/* generate function epilog */
-void gfunc_epilog(TCCState* S)
+void gfunc_epilog(void)
{
int v, saved_ind;
#ifdef CONFIG_TCC_BCHECK
- if (S->do_bounds_check)
- gen_bounds_epilog(S);
+ if (tcc_state->do_bounds_check)
+ gen_bounds_epilog();
#endif
- o(S, 0xc9); /* leave */
- if (S->x86_64_gen_func_ret_sub == 0) {
- o(S, 0xc3); /* ret */
+ o(0xc9); /* leave */
+ if (func_ret_sub == 0) {
+ o(0xc3); /* ret */
} else {
- o(S, 0xc2); /* ret n */
- g(S, S->x86_64_gen_func_ret_sub);
- g(S, S->x86_64_gen_func_ret_sub >> 8);
+ o(0xc2); /* ret n */
+ g(func_ret_sub);
+ g(func_ret_sub >> 8);
}
/* align local size to word & save local variables */
- v = (-S->tccgen_loc + 15) & -16;
- saved_ind = S->tccgen_ind;
- S->tccgen_ind = S->x86_64_gen_func_sub_sp_offset - FUNC_PROLOG_SIZE;
- o(S, 0xe5894855); /* push %rbp, mov %rsp, %rbp */
- o(S, 0xec8148); /* sub rsp, stacksize */
- gen_le32(S, v);
- S->tccgen_ind = saved_ind;
+ v = (-loc + 15) & -16;
+ saved_ind = ind;
+ ind = func_sub_sp_offset - FUNC_PROLOG_SIZE;
+ o(0xe5894855); /* push %rbp, mov %rsp, %rbp */
+ o(0xec8148); /* sub rsp, stacksize */
+ gen_le32(v);
+ ind = saved_ind;
}
#endif /* not PE */
-ST_FUNC void gen_fill_nops(TCCState* S, int bytes)
+ST_FUNC void gen_fill_nops(int bytes)
{
while (bytes--)
- g(S, 0x90);
+ g(0x90);
}
/* generate a jump to a label */
-int gjmp(TCCState* S, int t)
+int gjmp(int t)
{
- return gjmp2(S, 0xe9, t);
+ return gjmp2(0xe9, t);
}
/* generate a jump to a fixed address */
-void gjmp_addr(TCCState* S, int a)
+void gjmp_addr(int a)
{
int r;
- r = a - S->tccgen_ind - 2;
+ r = a - ind - 2;
if (r == (char)r) {
- g(S, 0xeb);
- g(S, r);
+ g(0xeb);
+ g(r);
} else {
- oad(S, 0xe9, a - S->tccgen_ind - 5);
+ oad(0xe9, a - ind - 5);
}
}
-ST_FUNC int gjmp_append(TCCState *S, int n, int t)
+ST_FUNC int gjmp_append(int n, int t)
{
void *p;
/* insert vtop->c jump list in t */
@@ -1646,7 +1659,7 @@ ST_FUNC int gjmp_append(TCCState *S, int n, int t)
return t;
}
-ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
+ST_FUNC int gjmp_cond(int op, int t)
{
if (op & 0x100)
{
@@ -1657,61 +1670,61 @@ ST_FUNC int gjmp_cond(TCCState* S, int op, int t)
Take care about inverting the test. We need to jump
to our target if the result was unordered and test wasn't NE,
otherwise if unordered we don't want to jump. */
- int v = S->tccgen_vtop->cmp_r;
+ int v = vtop->cmp_r;
op &= ~0x100;
if (op ^ v ^ (v != TOK_NE))
- o(S, 0x067a); /* jp +6 */
+ o(0x067a); /* jp +6 */
else
{
- g(S, 0x0f);
- t = gjmp2(S, 0x8a, t); /* jp t */
+ g(0x0f);
+ t = gjmp2(0x8a, t); /* jp t */
}
}
- g(S, 0x0f);
- t = gjmp2(S, op - 16, t);
+ g(0x0f);
+ t = gjmp2(op - 16, t);
return t;
}
/* generate an integer binary operation */
-void gen_opi(TCCState* S, int op)
+void gen_opi(int op)
{
int r, fr, opc, c;
int ll, uu, cc;
- ll = is64_type(S->tccgen_vtop[-1].type.t);
- uu = (S->tccgen_vtop[-1].type.t & VT_UNSIGNED) != 0;
- cc = (S->tccgen_vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
+ ll = is64_type(vtop[-1].type.t);
+ uu = (vtop[-1].type.t & VT_UNSIGNED) != 0;
+ cc = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
switch(op) {
case '+':
case TOK_ADDC1: /* add with carry generation */
opc = 0;
gen_op8:
- if (cc && (!ll || (int)S->tccgen_vtop->c.i == S->tccgen_vtop->c.i)) {
+ if (cc && (!ll || (int)vtop->c.i == vtop->c.i)) {
/* constant case */
- vswap(S);
- r = gv(S, RC_INT);
- vswap(S);
- c = S->tccgen_vtop->c.i;
+ vswap();
+ r = gv(RC_INT);
+ vswap();
+ c = vtop->c.i;
if (c == (char)c) {
/* XXX: generate inc and dec for smaller code ? */
- orex(S, ll, r, 0, 0x83);
- o(S, 0xc0 | (opc << 3) | REG_VALUE(r));
- g(S, c);
+ orex(ll, r, 0, 0x83);
+ o(0xc0 | (opc << 3) | REG_VALUE(r));
+ g(c);
} else {
- orex(S, ll, r, 0, 0x81);
- oad(S, 0xc0 | (opc << 3) | REG_VALUE(r), c);
+ orex(ll, r, 0, 0x81);
+ oad(0xc0 | (opc << 3) | REG_VALUE(r), c);
}
} else {
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- orex(S, ll, r, fr, (opc << 3) | 0x01);
- o(S, 0xc0 + REG_VALUE(r) + REG_VALUE(fr) * 8);
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ orex(ll, r, fr, (opc << 3) | 0x01);
+ o(0xc0 + REG_VALUE(r) + REG_VALUE(fr) * 8);
}
- S->tccgen_vtop--;
+ vtop--;
if (op >= TOK_ULT && op <= TOK_GT)
- vset_VT_CMP(S, op);
+ vset_VT_CMP(op);
break;
case '-':
case TOK_SUBC1: /* sub with carry generation */
@@ -1733,12 +1746,12 @@ void gen_opi(TCCState* S, int op)
opc = 1;
goto gen_op8;
case '*':
- gv2(S, RC_INT, RC_INT);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- orex(S, ll, fr, r, 0xaf0f); /* imul fr, r */
- o(S, 0xc0 + REG_VALUE(fr) + REG_VALUE(r) * 8);
- S->tccgen_vtop--;
+ gv2(RC_INT, RC_INT);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ orex(ll, fr, r, 0xaf0f); /* imul fr, r */
+ o(0xc0 + REG_VALUE(fr) + REG_VALUE(r) * 8);
+ vtop--;
break;
case TOK_SHL:
opc = 4;
@@ -1752,20 +1765,20 @@ void gen_opi(TCCState* S, int op)
opc = 0xc0 | (opc << 3);
if (cc) {
/* constant case */
- vswap(S);
- r = gv(S, RC_INT);
- vswap(S);
- orex(S, ll, r, 0, 0xc1); /* shl/shr/sar $xxx, r */
- o(S, opc | REG_VALUE(r));
- g(S, S->tccgen_vtop->c.i & (ll ? 63 : 31));
+ vswap();
+ r = gv(RC_INT);
+ vswap();
+ orex(ll, r, 0, 0xc1); /* shl/shr/sar $xxx, r */
+ o(opc | REG_VALUE(r));
+ g(vtop->c.i & (ll ? 63 : 31));
} else {
/* we generate the shift in ecx */
- gv2(S, RC_INT, RC_RCX);
- r = S->tccgen_vtop[-1].r;
- orex(S, ll, r, 0, 0xd3); /* shl/shr/sar %cl, r */
- o(S, opc | REG_VALUE(r));
+ gv2(RC_INT, RC_RCX);
+ r = vtop[-1].r;
+ orex(ll, r, 0, 0xd3); /* shl/shr/sar %cl, r */
+ o(opc | REG_VALUE(r));
}
- S->tccgen_vtop--;
+ vtop--;
break;
case TOK_UDIV:
case TOK_UMOD:
@@ -1778,19 +1791,19 @@ void gen_opi(TCCState* S, int op)
divmod:
/* first operand must be in eax */
/* XXX: need better constraint for second operand */
- gv2(S, RC_RAX, RC_RCX);
- r = S->tccgen_vtop[-1].r;
- fr = S->tccgen_vtop[0].r;
- S->tccgen_vtop--;
- save_reg(S, TREG_RDX);
- orex(S, ll, 0, 0, uu ? 0xd231 : 0x99); /* xor %edx,%edx : cqto */
- orex(S, ll, fr, 0, 0xf7); /* div fr, %eax */
- o(S, (uu ? 0xf0 : 0xf8) + REG_VALUE(fr));
+ gv2(RC_RAX, RC_RCX);
+ r = vtop[-1].r;
+ fr = vtop[0].r;
+ vtop--;
+ save_reg(TREG_RDX);
+ orex(ll, 0, 0, uu ? 0xd231 : 0x99); /* xor %edx,%edx : cqto */
+ orex(ll, fr, 0, 0xf7); /* div fr, %eax */
+ o((uu ? 0xf0 : 0xf8) + REG_VALUE(fr));
if (op == '%' || op == TOK_UMOD)
r = TREG_RDX;
else
r = TREG_RAX;
- S->tccgen_vtop->r = r;
+ vtop->r = r;
break;
default:
opc = 7;
@@ -1798,102 +1811,102 @@ void gen_opi(TCCState* S, int op)
}
}
-void gen_opl(TCCState* S, int op)
+void gen_opl(int op)
{
- gen_opi(S, op);
+ gen_opi(op);
}
-void vpush_const(TCCState* S, int t, int v)
+void vpush_const(int t, int v)
{
CType ctype = { t | VT_CONSTANT, 0 };
- vpushsym(S, &ctype, external_global_sym(S, v, &ctype));
- S->tccgen_vtop->r |= VT_LVAL;
+ vpushsym(&ctype, external_global_sym(v, &ctype));
+ vtop->r |= VT_LVAL;
}
/* generate a floating point operation 'v = t1 op t2' instruction. The
two operands are guaranteed to have the same floating point type */
/* XXX: need to use ST1 too */
-void gen_opf(TCCState* S, int op)
+void gen_opf(int op)
{
int a, ft, fc, swapped, r;
- int bt = S->tccgen_vtop->type.t & VT_BTYPE;
+ int bt = vtop->type.t & VT_BTYPE;
int float_type = bt == VT_LDOUBLE ? RC_ST0 : RC_FLOAT;
if (op == TOK_NEG) { /* unary minus */
- gv(S, float_type);
+ gv(float_type);
if (float_type == RC_ST0) {
- o(S, 0xe0d9); /* fchs */
+ o(0xe0d9); /* fchs */
} else {
/* -0.0, in libtcc1.c */
- vpush_const(S, bt, bt == VT_FLOAT ? TOK___mzerosf : TOK___mzerodf);
- gv(S, RC_FLOAT);
+ vpush_const(bt, bt == VT_FLOAT ? TOK___mzerosf : TOK___mzerodf);
+ gv(RC_FLOAT);
if (bt == VT_DOUBLE)
- o(S, 0x66);
+ o(0x66);
/* xorp[sd] %xmm1, %xmm0 */
- o(S, 0xc0570f | (REG_VALUE(S->tccgen_vtop[0].r) + REG_VALUE(S->tccgen_vtop[-1].r)*8) << 16);
- S->tccgen_vtop--;
+ o(0xc0570f | (REG_VALUE(vtop[0].r) + REG_VALUE(vtop[-1].r)*8) << 16);
+ vtop--;
}
return;
}
/* convert constants to memory references */
- if ((S->tccgen_vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
- vswap(S);
- gv(S, float_type);
- vswap(S);
+ if ((vtop[-1].r & (VT_VALMASK | VT_LVAL)) == VT_CONST) {
+ vswap();
+ gv(float_type);
+ vswap();
}
- if ((S->tccgen_vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
- gv(S, float_type);
+ if ((vtop[0].r & (VT_VALMASK | VT_LVAL)) == VT_CONST)
+ gv(float_type);
/* must put at least one value in the floating point register */
- if ((S->tccgen_vtop[-1].r & VT_LVAL) &&
- (S->tccgen_vtop[0].r & VT_LVAL)) {
- vswap(S);
- gv(S, float_type);
- vswap(S);
+ if ((vtop[-1].r & VT_LVAL) &&
+ (vtop[0].r & VT_LVAL)) {
+ vswap();
+ gv(float_type);
+ vswap();
}
swapped = 0;
/* swap the stack if needed so that t1 is the register and t2 is
the memory reference */
- if (S->tccgen_vtop[-1].r & VT_LVAL) {
- vswap(S);
+ if (vtop[-1].r & VT_LVAL) {
+ vswap();
swapped = 1;
}
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
+ if ((vtop->type.t & VT_BTYPE) == VT_LDOUBLE) {
if (op >= TOK_ULT && op <= TOK_GT) {
/* load on stack second operand */
- load(S, TREG_ST0, S->tccgen_vtop);
- save_reg(S, TREG_RAX); /* eax is used by FP comparison code */
+ load(TREG_ST0, vtop);
+ save_reg(TREG_RAX); /* eax is used by FP comparison code */
if (op == TOK_GE || op == TOK_GT)
swapped = !swapped;
else if (op == TOK_EQ || op == TOK_NE)
swapped = 0;
if (swapped)
- o(S, 0xc9d9); /* fxch %st(1) */
+ o(0xc9d9); /* fxch %st(1) */
if (op == TOK_EQ || op == TOK_NE)
- o(S, 0xe9da); /* fucompp */
+ o(0xe9da); /* fucompp */
else
- o(S, 0xd9de); /* fcompp */
- o(S, 0xe0df); /* fnstsw %ax */
+ o(0xd9de); /* fcompp */
+ o(0xe0df); /* fnstsw %ax */
if (op == TOK_EQ) {
- o(S, 0x45e480); /* and $0x45, %ah */
- o(S, 0x40fC80); /* cmp $0x40, %ah */
+ o(0x45e480); /* and $0x45, %ah */
+ o(0x40fC80); /* cmp $0x40, %ah */
} else if (op == TOK_NE) {
- o(S, 0x45e480); /* and $0x45, %ah */
- o(S, 0x40f480); /* xor $0x40, %ah */
+ o(0x45e480); /* and $0x45, %ah */
+ o(0x40f480); /* xor $0x40, %ah */
op = TOK_NE;
} else if (op == TOK_GE || op == TOK_LE) {
- o(S, 0x05c4f6); /* test $0x05, %ah */
+ o(0x05c4f6); /* test $0x05, %ah */
op = TOK_EQ;
} else {
- o(S, 0x45c4f6); /* test $0x45, %ah */
+ o(0x45c4f6); /* test $0x45, %ah */
op = TOK_EQ;
}
- S->tccgen_vtop--;
- vset_VT_CMP(S, op);
+ vtop--;
+ vset_VT_CMP(op);
} else {
/* no memory reference possible for long double operations */
- load(S, TREG_ST0, S->tccgen_vtop);
+ load(TREG_ST0, vtop);
swapped = !swapped;
switch(op) {
@@ -1915,26 +1928,26 @@ void gen_opf(TCCState* S, int op)
a++;
break;
}
- ft = S->tccgen_vtop->type.t;
- fc = S->tccgen_vtop->c.i;
- o(S, 0xde); /* fxxxp %st, %st(1) */
- o(S, 0xc1 + (a << 3));
- S->tccgen_vtop--;
+ ft = vtop->type.t;
+ fc = vtop->c.i;
+ o(0xde); /* fxxxp %st, %st(1) */
+ o(0xc1 + (a << 3));
+ vtop--;
}
} else {
if (op >= TOK_ULT && op <= TOK_GT) {
/* if saved lvalue, then we must reload it */
- r = S->tccgen_vtop->r;
- fc = S->tccgen_vtop->c.i;
+ r = vtop->r;
+ fc = vtop->c.i;
if ((r & VT_VALMASK) == VT_LLOCAL) {
SValue v1;
- r = get_reg(S, RC_INT);
+ r = get_reg(RC_INT);
v1.type.t = VT_PTR;
v1.r = VT_LOCAL | VT_LVAL;
v1.c.i = fc;
- load(S, r, &v1);
+ load(r, &v1);
fc = 0;
- S->tccgen_vtop->r = r = r | VT_LVAL;
+ vtop->r = r = r | VT_LVAL;
}
if (op == TOK_EQ || op == TOK_NE) {
@@ -1950,29 +1963,29 @@ void gen_opf(TCCState* S, int op)
}
if (swapped) {
- gv(S, RC_FLOAT);
- vswap(S);
+ gv(RC_FLOAT);
+ vswap();
}
- assert(!(S->tccgen_vtop[-1].r & VT_LVAL));
+ assert(!(vtop[-1].r & VT_LVAL));
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_DOUBLE)
- o(S, 0x66);
+ if ((vtop->type.t & VT_BTYPE) == VT_DOUBLE)
+ o(0x66);
if (op == TOK_EQ || op == TOK_NE)
- o(S, 0x2e0f); /* ucomisd */
+ o(0x2e0f); /* ucomisd */
else
- o(S, 0x2f0f); /* comisd */
+ o(0x2f0f); /* comisd */
- if (S->tccgen_vtop->r & VT_LVAL) {
- gen_modrm(S, S->tccgen_vtop[-1].r, r, S->tccgen_vtop->sym, fc);
+ if (vtop->r & VT_LVAL) {
+ gen_modrm(vtop[-1].r, r, vtop->sym, fc);
} else {
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop[0].r) + REG_VALUE(S->tccgen_vtop[-1].r)*8);
+ o(0xc0 + REG_VALUE(vtop[0].r) + REG_VALUE(vtop[-1].r)*8);
}
- S->tccgen_vtop--;
- vset_VT_CMP(S, op | 0x100);
- S->tccgen_vtop->cmp_r = op;
+ vtop--;
+ vset_VT_CMP(op | 0x100);
+ vtop->cmp_r = op;
} else {
- assert((S->tccgen_vtop->type.t & VT_BTYPE) != VT_LDOUBLE);
+ assert((vtop->type.t & VT_BTYPE) != VT_LDOUBLE);
switch(op) {
default:
case '+':
@@ -1988,269 +2001,269 @@ void gen_opf(TCCState* S, int op)
a = 6;
break;
}
- ft = S->tccgen_vtop->type.t;
- fc = S->tccgen_vtop->c.i;
+ ft = vtop->type.t;
+ fc = vtop->c.i;
assert((ft & VT_BTYPE) != VT_LDOUBLE);
- r = S->tccgen_vtop->r;
+ r = vtop->r;
/* if saved lvalue, then we must reload it */
- if ((S->tccgen_vtop->r & VT_VALMASK) == VT_LLOCAL) {
+ if ((vtop->r & VT_VALMASK) == VT_LLOCAL) {
SValue v1;
- r = get_reg(S, RC_INT);
+ r = get_reg(RC_INT);
v1.type.t = VT_PTR;
v1.r = VT_LOCAL | VT_LVAL;
v1.c.i = fc;
- load(S, r, &v1);
+ load(r, &v1);
fc = 0;
- S->tccgen_vtop->r = r = r | VT_LVAL;
+ vtop->r = r = r | VT_LVAL;
}
- assert(!(S->tccgen_vtop[-1].r & VT_LVAL));
+ assert(!(vtop[-1].r & VT_LVAL));
if (swapped) {
- assert(S->tccgen_vtop->r & VT_LVAL);
- gv(S, RC_FLOAT);
- vswap(S);
+ assert(vtop->r & VT_LVAL);
+ gv(RC_FLOAT);
+ vswap();
}
if ((ft & VT_BTYPE) == VT_DOUBLE) {
- o(S, 0xf2);
+ o(0xf2);
} else {
- o(S, 0xf3);
+ o(0xf3);
}
- o(S, 0x0f);
- o(S, 0x58 + a);
+ o(0x0f);
+ o(0x58 + a);
- if (S->tccgen_vtop->r & VT_LVAL) {
- gen_modrm(S, S->tccgen_vtop[-1].r, r, S->tccgen_vtop->sym, fc);
+ if (vtop->r & VT_LVAL) {
+ gen_modrm(vtop[-1].r, r, vtop->sym, fc);
} else {
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop[0].r) + REG_VALUE(S->tccgen_vtop[-1].r)*8);
+ o(0xc0 + REG_VALUE(vtop[0].r) + REG_VALUE(vtop[-1].r)*8);
}
- S->tccgen_vtop--;
+ vtop--;
}
}
}
/* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
and 'long long' cases. */
-void gen_cvt_itof(TCCState* S, int t)
+void gen_cvt_itof(int t)
{
if ((t & VT_BTYPE) == VT_LDOUBLE) {
- save_reg(S, TREG_ST0);
- gv(S, RC_INT);
- if ((S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
+ save_reg(TREG_ST0);
+ gv(RC_INT);
+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG) {
/* signed long long to float/double/long double (unsigned case
is handled generically) */
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x242cdf); /* fildll (%rsp) */
- o(S, 0x08c48348); /* add $8, %rsp */
- } else if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x242cdf); /* fildll (%rsp) */
+ o(0x08c48348); /* add $8, %rsp */
+ } else if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
(VT_INT | VT_UNSIGNED)) {
/* unsigned int to float/double/long double */
- o(S, 0x6a); /* push $0 */
- g(S, 0x00);
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x242cdf); /* fildll (%rsp) */
- o(S, 0x10c48348); /* add $16, %rsp */
+ o(0x6a); /* push $0 */
+ g(0x00);
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x242cdf); /* fildll (%rsp) */
+ o(0x10c48348); /* add $16, %rsp */
} else {
/* int to float/double/long double */
- o(S, 0x50 + (S->tccgen_vtop->r & VT_VALMASK)); /* push r */
- o(S, 0x2404db); /* fildl (%rsp) */
- o(S, 0x08c48348); /* add $8, %rsp */
+ o(0x50 + (vtop->r & VT_VALMASK)); /* push r */
+ o(0x2404db); /* fildl (%rsp) */
+ o(0x08c48348); /* add $8, %rsp */
}
- S->tccgen_vtop->r = TREG_ST0;
+ vtop->r = TREG_ST0;
} else {
- int r = get_reg(S, RC_FLOAT);
- gv(S, RC_INT);
- o(S, 0xf2 + ((t & VT_BTYPE) == VT_FLOAT?1:0));
- if ((S->tccgen_vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
+ int r = get_reg(RC_FLOAT);
+ gv(RC_INT);
+ o(0xf2 + ((t & VT_BTYPE) == VT_FLOAT?1:0));
+ if ((vtop->type.t & (VT_BTYPE | VT_UNSIGNED)) ==
(VT_INT | VT_UNSIGNED) ||
- (S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG) {
- o(S, 0x48); /* REX */
+ (vtop->type.t & VT_BTYPE) == VT_LLONG) {
+ o(0x48); /* REX */
}
- o(S, 0x2a0f);
- o(S, 0xc0 + (S->tccgen_vtop->r & VT_VALMASK) + REG_VALUE(r)*8); /* cvtsi2sd */
- S->tccgen_vtop->r = r;
+ o(0x2a0f);
+ o(0xc0 + (vtop->r & VT_VALMASK) + REG_VALUE(r)*8); /* cvtsi2sd */
+ vtop->r = r;
}
}
/* convert from one floating point type to another */
-void gen_cvt_ftof(TCCState* S, int t)
+void gen_cvt_ftof(int t)
{
int ft, bt, tbt;
- ft = S->tccgen_vtop->type.t;
+ ft = vtop->type.t;
bt = ft & VT_BTYPE;
tbt = t & VT_BTYPE;
if (bt == VT_FLOAT) {
- gv(S, RC_FLOAT);
+ gv(RC_FLOAT);
if (tbt == VT_DOUBLE) {
- o(S, 0x140f); /* unpcklps */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r)*9);
- o(S, 0x5a0f); /* cvtps2pd */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r)*9);
+ o(0x140f); /* unpcklps */
+ o(0xc0 + REG_VALUE(vtop->r)*9);
+ o(0x5a0f); /* cvtps2pd */
+ o(0xc0 + REG_VALUE(vtop->r)*9);
} else if (tbt == VT_LDOUBLE) {
- save_reg(S, RC_ST0);
+ save_reg(RC_ST0);
/* movss %xmm0,-0x10(%rsp) */
- o(S, 0x110ff3);
- o(S, 0x44 + REG_VALUE(S->tccgen_vtop->r)*8);
- o(S, 0xf024);
- o(S, 0xf02444d9); /* flds -0x10(%rsp) */
- S->tccgen_vtop->r = TREG_ST0;
+ o(0x110ff3);
+ o(0x44 + REG_VALUE(vtop->r)*8);
+ o(0xf024);
+ o(0xf02444d9); /* flds -0x10(%rsp) */
+ vtop->r = TREG_ST0;
}
} else if (bt == VT_DOUBLE) {
- gv(S, RC_FLOAT);
+ gv(RC_FLOAT);
if (tbt == VT_FLOAT) {
- o(S, 0x140f66); /* unpcklpd */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r)*9);
- o(S, 0x5a0f66); /* cvtpd2ps */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r)*9);
+ o(0x140f66); /* unpcklpd */
+ o(0xc0 + REG_VALUE(vtop->r)*9);
+ o(0x5a0f66); /* cvtpd2ps */
+ o(0xc0 + REG_VALUE(vtop->r)*9);
} else if (tbt == VT_LDOUBLE) {
- save_reg(S, RC_ST0);
+ save_reg(RC_ST0);
/* movsd %xmm0,-0x10(%rsp) */
- o(S, 0x110ff2);
- o(S, 0x44 + REG_VALUE(S->tccgen_vtop->r)*8);
- o(S, 0xf024);
- o(S, 0xf02444dd); /* fldl -0x10(%rsp) */
- S->tccgen_vtop->r = TREG_ST0;
+ o(0x110ff2);
+ o(0x44 + REG_VALUE(vtop->r)*8);
+ o(0xf024);
+ o(0xf02444dd); /* fldl -0x10(%rsp) */
+ vtop->r = TREG_ST0;
}
} else {
int r;
- gv(S, RC_ST0);
- r = get_reg(S, RC_FLOAT);
+ gv(RC_ST0);
+ r = get_reg(RC_FLOAT);
if (tbt == VT_DOUBLE) {
- o(S, 0xf0245cdd); /* fstpl -0x10(%rsp) */
+ o(0xf0245cdd); /* fstpl -0x10(%rsp) */
/* movsd -0x10(%rsp),%xmm0 */
- o(S, 0x100ff2);
- o(S, 0x44 + REG_VALUE(r)*8);
- o(S, 0xf024);
- S->tccgen_vtop->r = r;
+ o(0x100ff2);
+ o(0x44 + REG_VALUE(r)*8);
+ o(0xf024);
+ vtop->r = r;
} else if (tbt == VT_FLOAT) {
- o(S, 0xf0245cd9); /* fstps -0x10(%rsp) */
+ o(0xf0245cd9); /* fstps -0x10(%rsp) */
/* movss -0x10(%rsp),%xmm0 */
- o(S, 0x100ff3);
- o(S, 0x44 + REG_VALUE(r)*8);
- o(S, 0xf024);
- S->tccgen_vtop->r = r;
+ o(0x100ff3);
+ o(0x44 + REG_VALUE(r)*8);
+ o(0xf024);
+ vtop->r = r;
}
}
}
/* convert fp to int 't' type */
-void gen_cvt_ftoi(TCCState* S, int t)
+void gen_cvt_ftoi(int t)
{
int ft, bt, size, r;
- ft = S->tccgen_vtop->type.t;
+ ft = vtop->type.t;
bt = ft & VT_BTYPE;
if (bt == VT_LDOUBLE) {
- gen_cvt_ftof(S, VT_DOUBLE);
+ gen_cvt_ftof(VT_DOUBLE);
bt = VT_DOUBLE;
}
- gv(S, RC_FLOAT);
+ gv(RC_FLOAT);
if (t != VT_INT)
size = 8;
else
size = 4;
- r = get_reg(S, RC_INT);
+ r = get_reg(RC_INT);
if (bt == VT_FLOAT) {
- o(S, 0xf3);
+ o(0xf3);
} else if (bt == VT_DOUBLE) {
- o(S, 0xf2);
+ o(0xf2);
} else {
assert(0);
}
- orex(S, size == 8, r, 0, 0x2c0f); /* cvttss2si or cvttsd2si */
- o(S, 0xc0 + REG_VALUE(S->tccgen_vtop->r) + REG_VALUE(r)*8);
- S->tccgen_vtop->r = r;
+ orex(size == 8, r, 0, 0x2c0f); /* cvttss2si or cvttsd2si */
+ o(0xc0 + REG_VALUE(vtop->r) + REG_VALUE(r)*8);
+ vtop->r = r;
}
// Generate sign extension from 32 to 64 bits:
-ST_FUNC void gen_cvt_sxtw(TCCState* S)
+ST_FUNC void gen_cvt_sxtw(void)
{
- int r = gv(S, RC_INT);
+ int r = gv(RC_INT);
/* x86_64 specific: movslq */
- o(S, 0x6348);
- o(S, 0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
+ o(0x6348);
+ o(0xc0 + (REG_VALUE(r) << 3) + REG_VALUE(r));
}
/* char/short to int conversion */
-ST_FUNC void gen_cvt_csti(TCCState* S, int t)
+ST_FUNC void gen_cvt_csti(int t)
{
int r, sz, xl, ll;
- r = gv(S, RC_INT);
+ r = gv(RC_INT);
sz = !(t & VT_UNSIGNED);
xl = (t & VT_BTYPE) == VT_SHORT;
- ll = (S->tccgen_vtop->type.t & VT_BTYPE) == VT_LLONG;
- orex(S, ll, r, 0, 0xc0b60f /* mov[sz] %a[xl], %eax */
+ ll = (vtop->type.t & VT_BTYPE) == VT_LLONG;
+ orex(ll, r, 0, 0xc0b60f /* mov[sz] %a[xl], %eax */
| (sz << 3 | xl) << 8
| (REG_VALUE(r) << 3 | REG_VALUE(r)) << 16
);
}
/* increment tcov counter */
-ST_FUNC void gen_increment_tcov (TCCState* S, SValue *sv)
+ST_FUNC void gen_increment_tcov (SValue *sv)
{
- o(S, 0x058348); /* addq $1, xxx(%rip) */
- greloca(S, cur_text_section, sv->sym, S->tccgen_ind, R_X86_64_PC32, -5);
- gen_le32(S, 0);
- o(S, 1);
+ o(0x058348); /* addq $1, xxx(%rip) */
+ greloca(cur_text_section, sv->sym, ind, R_X86_64_PC32, -5);
+ gen_le32(0);
+ o(1);
}
/* computed goto support */
-void ggoto(TCCState* S)
+void ggoto(void)
{
- gcall_or_jmp(S, 1);
- S->tccgen_vtop--;
+ gcall_or_jmp(1);
+ vtop--;
}
/* Save the stack pointer onto the stack and return the location of its address */
-ST_FUNC void gen_vla_sp_save(TCCState* S, int addr) {
+ST_FUNC void gen_vla_sp_save(int addr) {
/* mov %rsp,addr(%rbp)*/
- gen_modrm64(S, 0x89, TREG_RSP, VT_LOCAL, NULL, addr);
+ gen_modrm64(0x89, TREG_RSP, VT_LOCAL, NULL, addr);
}
/* Restore the SP from a location on the stack */
-ST_FUNC void gen_vla_sp_restore(TCCState* S, int addr) {
- gen_modrm64(S, 0x8b, TREG_RSP, VT_LOCAL, NULL, addr);
+ST_FUNC void gen_vla_sp_restore(int addr) {
+ gen_modrm64(0x8b, TREG_RSP, VT_LOCAL, NULL, addr);
}
#ifdef TCC_TARGET_PE
/* Save result of gen_vla_alloc onto the stack */
-ST_FUNC void gen_vla_result(TCCState* S, int addr) {
+ST_FUNC void gen_vla_result(int addr) {
/* mov %rax,addr(%rbp)*/
- gen_modrm64(S, 0x89, TREG_RAX, VT_LOCAL, NULL, addr);
+ gen_modrm64(0x89, TREG_RAX, VT_LOCAL, NULL, addr);
}
#endif
/* Subtract from the stack pointer, and push the resulting value onto the stack */
-ST_FUNC void gen_vla_alloc(TCCState* S, CType *type, int align) {
+ST_FUNC void gen_vla_alloc(CType *type, int align) {
int use_call = 0;
#if defined(CONFIG_TCC_BCHECK)
- use_call = S->do_bounds_check;
+ use_call = tcc_state->do_bounds_check;
#endif
#ifdef TCC_TARGET_PE /* alloca does more than just adjust %rsp on Windows */
use_call = 1;
#endif
if (use_call)
{
- vpush_helper_func(S, TOK_alloca);
- vswap(S); /* Move alloca ref past allocation size */
- gfunc_call(S, 1);
+ vpush_helper_func(TOK_alloca);
+ vswap(); /* Move alloca ref past allocation size */
+ gfunc_call(1);
}
else {
int r;
- r = gv(S, RC_INT); /* allocation size */
+ r = gv(RC_INT); /* allocation size */
/* sub r,%rsp */
- o(S, 0x2b48);
- o(S, 0xe0 | REG_VALUE(r));
+ o(0x2b48);
+ o(0xe0 | REG_VALUE(r));
/* We align to 16 bytes rather than align */
/* and ~15, %rsp */
- o(S, 0xf0e48348);
- vpop(S);
+ o(0xf0e48348);
+ vpop();
}
}
diff --git a/x86_64-link.c b/x86_64-link.c
index eaa7687..83e8f1b 100644
--- a/x86_64-link.c
+++ b/x86_64-link.c
@@ -105,9 +105,9 @@ int gotplt_entry_type (int reloc_type)
}
#if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE
-ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_attr *attr)
+ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{
- Section *plt = S->plt;
+ Section *plt = s1->plt;
uint8_t *p;
int modrm;
unsigned plt_offset, relofs;
@@ -118,7 +118,7 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
(GOT + PTR_SIZE) and jumps to ld.so resolution routine
(GOT + 2 * PTR_SIZE) */
if (plt->data_offset == 0) {
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
p[0] = 0xff; /* pushl got + PTR_SIZE */
p[1] = modrm + 0x10;
write32le(p + 2, PTR_SIZE);
@@ -131,10 +131,10 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* The PLT slot refers to the relocation entry it needs via offset.
The reloc entry is created below, so its offset is the current
data_offset */
- relofs = S->plt->reloc ? S->plt->reloc->data_offset : 0;
+ relofs = s1->plt->reloc ? s1->plt->reloc->data_offset : 0;
/* Jump to GOT entry where ld.so initially put the address of ip + 4 */
- p = section_ptr_add(S, plt, 16);
+ p = section_ptr_add(plt, 16);
p[0] = 0xff; /* jmp *(got + x) */
p[1] = modrm;
write32le(p + 2, got_offset);
@@ -148,32 +148,32 @@ ST_FUNC unsigned create_plt_entry(TCCState *S, unsigned got_offset, struct sym_a
/* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */
-ST_FUNC void relocate_plt(TCCState *S)
+ST_FUNC void relocate_plt(TCCState *s1)
{
uint8_t *p, *p_end;
- if (!S->plt)
+ if (!s1->plt)
return;
- p = S->plt->data;
- p_end = p + S->plt->data_offset;
+ p = s1->plt->data;
+ p_end = p + s1->plt->data_offset;
if (p < p_end) {
- int x = S->got->sh_addr - S->plt->sh_addr - 6;
+ int x = s1->got->sh_addr - s1->plt->sh_addr - 6;
add32le(p + 2, x);
add32le(p + 8, x - 6);
p += 16;
while (p < p_end) {
- add32le(p + 2, x + (S->plt->data - p));
+ add32le(p + 2, x + (s1->plt->data - p));
p += 16;
}
}
- if (S->plt->reloc) {
+ if (s1->plt->reloc) {
ElfW_Rel *rel;
- int x = S->plt->sh_addr + 16 + 6;
- p = S->got->data;
- for_each_elem(S->plt->reloc, 0, rel, ElfW_Rel) {
+ int x = s1->plt->sh_addr + 16 + 6;
+ p = s1->got->data;
+ for_each_elem(s1->plt->reloc, 0, rel, ElfW_Rel) {
write64le(p + rel->r_offset, x);
x += 16;
}
@@ -182,7 +182,7 @@ ST_FUNC void relocate_plt(TCCState *S)
#endif
#endif
-void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index, esym_index;
@@ -190,8 +190,8 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
switch (type) {
case R_X86_64_64:
- if (S->output_type == TCC_OUTPUT_DLL) {
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ if (s1->output_type == TCC_OUTPUT_DLL) {
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
qrel->r_offset = rel->r_offset;
if (esym_index) {
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_64);
@@ -208,7 +208,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
break;
case R_X86_64_32:
case R_X86_64_32S:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* XXX: this logic may depend on TCC's codegen
now TCC uses R_X86_64_32 even for a 64bit pointer */
qrel->r_offset = rel->r_offset;
@@ -221,9 +221,9 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
break;
case R_X86_64_PC32:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC32);
@@ -243,20 +243,20 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
long long diff;
diff = (long long)val - addr;
if (diff < -2147483648LL || diff > 2147483647LL) {
- tcc_error(S, "internal error: relocation failed");
+ tcc_error("internal error: relocation failed");
}
add32le(ptr, diff);
}
break;
case R_X86_64_PLTOFF64:
- add64le(ptr, val - S->got->sh_addr + rel->r_addend);
+ add64le(ptr, val - s1->got->sh_addr + rel->r_addend);
break;
case R_X86_64_PC64:
- if (S->output_type == TCC_OUTPUT_DLL) {
+ if (s1->output_type == TCC_OUTPUT_DLL) {
/* DLL relocation */
- esym_index = get_sym_attr(S, sym_index, 0)->dyn_index;
+ esym_index = get_sym_attr(s1, sym_index, 0)->dyn_index;
if (esym_index) {
qrel->r_offset = rel->r_offset;
qrel->r_info = ELFW(R_INFO)(esym_index, R_X86_64_PC64);
@@ -276,28 +276,28 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
- add32le(ptr, S->got->sh_addr - addr +
- get_sym_attr(S, sym_index, 0)->got_offset - 4);
+ add32le(ptr, s1->got->sh_addr - addr +
+ get_sym_attr(s1, sym_index, 0)->got_offset - 4);
break;
case R_X86_64_GOTPC32:
- add32le(ptr, S->got->sh_addr - addr + rel->r_addend);
+ add32le(ptr, s1->got->sh_addr - addr + rel->r_addend);
break;
case R_X86_64_GOTPC64:
- add64le(ptr, S->got->sh_addr - addr + rel->r_addend);
+ add64le(ptr, s1->got->sh_addr - addr + rel->r_addend);
break;
case R_X86_64_GOTTPOFF:
- add32le(ptr, val - S->got->sh_addr);
+ add32le(ptr, val - s1->got->sh_addr);
break;
case R_X86_64_GOT32:
/* we load the got offset */
- add32le(ptr, get_sym_attr(S, sym_index, 0)->got_offset);
+ add32le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
break;
case R_X86_64_GOT64:
/* we load the got offset */
- add64le(ptr, get_sym_attr(S, sym_index, 0)->got_offset);
+ add64le(ptr, get_sym_attr(s1, sym_index, 0)->got_offset);
break;
case R_X86_64_GOTOFF64:
- add64le(ptr, val - S->got->sh_addr);
+ add64le(ptr, val - s1->got->sh_addr);
break;
case R_X86_64_TLSGD:
{
@@ -320,12 +320,12 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
memcpy(ptr-4, replace, sizeof(replace));
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
- sec = S->sections[sym->st_shndx];
+ sec = s1->sections[sym->st_shndx];
x = sym->st_value - sec->sh_addr - sec->data_offset;
add32le(ptr + 8, x);
}
else
- tcc_error(S, "unexpected R_X86_64_TLSGD pattern");
+ tcc_error("unexpected R_X86_64_TLSGD pattern");
}
break;
case R_X86_64_TLSLD:
@@ -345,7 +345,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
rel[1].r_info = ELFW(R_INFO)(0, R_X86_64_NONE);
}
else
- tcc_error(S, "unexpected R_X86_64_TLSLD pattern");
+ tcc_error("unexpected R_X86_64_TLSLD pattern");
}
break;
case R_X86_64_DTPOFF32:
@@ -356,7 +356,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
int32_t x;
sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
- sec = S->sections[sym->st_shndx];
+ sec = s1->sections[sym->st_shndx];
x = val - sec->sh_addr - sec->data_offset;
add32le(ptr, x);
}
@@ -365,7 +365,7 @@ void relocate(TCCState *S, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t a
break;
case R_X86_64_RELATIVE:
#ifdef TCC_TARGET_PE
- add32le(ptr, val - S->pe_imagebase);
+ add32le(ptr, val - s1->pe_imagebase);
#endif
/* do nothing */
break;