2, x64/peephole: move some 'code to make instruction' into some little functions, in order to decrease code of key functions.
// mov rd, imm[15:0]
opcode = (0xe3 << 24) | (((imm >> 12 ) & 0xf) << 16) | (rd->id << 12) | (imm & 0xfff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
imm >>= 16;
if (imm & 0xffff) {
// movk rd, imm[31:16]
opcode = (0xe3 << 24) | (0x1 << 22) | (((imm >> 12 ) & 0xf) << 16) | (rd->id << 12) | (imm & 0xfff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else if (vs->global_flag) {
offset = 0;
opcode = (0xe3 << 24) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_ARM_REL32;
opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
scf_loge("temp var should give a register\n");
opcode = (0xe3 << 24) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_ARM_REL32;
opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
rb = rd;
opcode = (0xe0 << 24) | (0x8 << 20) | (r12->id << 16) | (r12->id << 12) | rb->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe8 << 24) | (0xd << 20) | (r12->id << 16) | (1 << rd->id) | (1 << (rd->id + 1));
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe3 << 24) | (rb->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vd, NULL);
rela->type = R_ARM_REL32;
opcode = (0xe3 << 24) | (0x4 << 20) | (rb->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe7 << 24) | (0x9 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
scf_loge("temp var should give a register\n");
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xed << 24) | (0x8 << 20) | (r12->id << 16) | (0x2 << 10) | (SIZE << 8) | 0;
}
opcode |= (D << 22) | (V << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe0 << 24) | (0x8 << 20) | (r12->id << 16) | (r12->id << 12) | rb->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe8 << 24) | (0xc << 20) | (r12->id << 16) | (1 << rs->id) | (1 << (rs->id + 1));
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe3 << 24) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
rela->type = R_ARM_REL32;
opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xed << 24) | (0x8 << 20) | (D << 22) | (r12->id << 16) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | 0;
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rd->id << 12) | (SH << 7) | ri->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return -EINVAL;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0xe3 << 24) | (rb->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_ARM_REL32;
opcode = (0xe3 << 24) | (0x4 << 20) | (rb->id << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe7 << 24) | (0x9 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
scf_loge("temp var should give a register\n");
opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode = (0xed << 24) | (0x9 << 20) | (r12->id << 16) | (0x2 << 10) | (SIZE << 8) | 0;
}
opcode |= (D << 22) | (V << 12);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = 0xeb << 24;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf);
rela->type = R_ARM_CALL;
i0 = (opcode >> 16) & 0xf;
r0 = f->rops->find_register_type_id_bytes(0, i0, 4);
inst = f->iops->MOV_G(c, r12, r0); // use r12 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~(0xf << 16);
opcode |= (0xc << 16);
r0 = f->rops->find_register_type_id_bytes(0, i0, 4);
inst = f->iops->MOV_G(c, r12, r0); // use r16 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
r0 = f->rops->find_register_type_id_bytes(0, i1, 4);
inst = f->iops->MOV_G(c, r14, r0); // use r17 to backup r1
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~(0xf << 16);
opcode |= (0xc << 16);
int offset = bytes - r->inst_offset - 16; // 'pc = current + 8'
inst = risc_make_inst(end, offset - 4);
- RISC_INST_ADD_CHECK(end->instructions, inst);
+ RISC_INST_ADD_CHECK(end, inst);
r->inst_offset = bytes;
r->inst->code[2] |= 0x0f & (offset >> 12);
int j;
- for (j = 0; j < r->code->instructions->size; j++) {
- inst = r->code->instructions->data[j];
+ for (j = 0; j < r->inst->c->instructions->size; j++) {
+ inst = r->inst->c->instructions->data[j];
if (inst == r->inst)
break;
}
- assert(r->code->instructions->size > j + 1);
+ assert(r->inst->c->instructions->size > j + 1);
- inst = r->code->instructions->data[j + 1];
+ inst = r->inst->c->instructions->data[j + 1];
inst->code[0] = 0xff & (offset >> 16);
inst->code[1] &= 0xf0;
.set_jmp_offset = arm32_set_jmp_offset,
.set_rel_veneer = arm32_set_rel_veneer,
};
-
// movn rd, invert[15:0]
opcode = (0x92 << 24) | (0x1 << 23) | ((invert & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (invert >> 16) {
// movk rd, imm[31:16]
opcode = (0xf2 << 24) | (0x1 << 23) | (0x1 << 21) | (((imm >> 16) & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
// mov rd, imm[15:0]
opcode = (0xd2 << 24) | (0x1 << 23) | ((imm & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if ((imm >> 16) & 0xffff) {
// movk rd, imm[31:16]
opcode = (0xf2 << 24) | (0x1 << 23) | (0x1 << 21) | (((imm >> 16) & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
if (8 == bytes) {
// movk rd, imm[47:32]
opcode = (0xf2 << 24) | (0x1 << 23) | (0x2 << 21) | (((imm >> 32) & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
if ((imm >> 48) & 0xffff) {
// movk rd, imm[63:48]
opcode = (0xf2 << 24) | (0x1 << 23) | (0x3 << 21) | (((imm >> 48) & 0xffff) << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
}
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else if (vs->global_flag) {
offset = 0;
opcode = (0x90 << 24) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0x91 << 24) | (rd->id << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode = (0x90 << 24) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0x91 << 24) | (rd->id << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode |= RISC_COLOR_TYPE(rd->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode |= RISC_COLOR_TYPE(rs->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0x90 << 24) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0x91 << 24) | (rd->id << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode |= RISC_COLOR_TYPE(rs->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode |= RISC_COLOR_TYPE(rd->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0x8b << 24) | (ri->id << 16) | (SH << 10) | (rb->id << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode |= RISC_COLOR_TYPE(rd->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode |= RISC_COLOR_TYPE(rs->color) << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0x90 << 24) | rb->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0x91 << 24) | (rb->id << 5) | rb->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode |= (SIZE << 30) | (rb->id << 5) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = 0x25 << 26;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf);
rela->type = R_AARCH64_CALL26;
i0 = (opcode >> 5) & 0x1f;
r0 = f->rops->find_register_type_id_bytes(0, i0, 8);
inst = f->iops->MOV_G(c, r16, r0); // use r16 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~(0x1f << 5);
opcode |= (0x10 << 5);
r0 = f->rops->find_register_type_id_bytes(0, i0, 8);
inst = f->iops->MOV_G(c, r16, r0); // use r16 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
r0 = f->rops->find_register_type_id_bytes(0, i1, 8);
inst = f->iops->MOV_G(c, r17, r0); // use r17 to backup r1
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~(0x1f << 5);
opcode |= (0x10 << 5);
// mvn rd, invert[15:0]
opcode = (0xe << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | (invert & 0xffff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (invert >> 16) {
// movt rd, imm[31:16]
opcode = (0xe << 26) | (rd->id << 21) | (0x1 << 18) | (0x2 << 16)| ((imm >> 16) & 0xffff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
// mov rd, imm[15:0]
inst = naja_inst_MOV_IMM(c, rd, imm & 0xffff);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
imm >>= 16;
if (imm & 0xffff) {
// movt rd, imm[31:16]
opcode = (0xe << 26) | (rd->id << 21) | (1 << 18) | (0x2 << 16) | (imm & 0xffff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
imm >>= 16;
// movk rd, imm[47:32]
opcode = (0xe << 26) | (rd->id << 21) | (2 << 18) | (0x2 << 16) | (imm & 0xffff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
imm >>= 16;
// movk rd, imm[63:48]
opcode = (0xe << 26) | (rd->id << 21) | (3 << 18) | (0x2 << 16) | (imm & 0xffff);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else if (vs->global_flag) {
offset = 0;
inst = __naja_inst_ADRP(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode |= RISC_COLOR_TYPE(rd->color) << 30;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
// opcode |= (1 << 18);
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
uint32_t opcode;
inst = __naja_inst_ADRP(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
rela->type = R_AARCH64_ADR_PREL_PG_HI21;
opcode = (0 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | rd->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
rela->type = R_AARCH64_ADD_ABS_LO12_NC;
opcode |= RISC_COLOR_TYPE(rs->color) << 30;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode |= RISC_COLOR_TYPE(rd->color) << 30;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
}
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
opcode = (0 << 26) | (rd->id << 21) | (3 << 18) | (SH << 16) | (ri->id << 4) | rb->id;
inst = risc_make_inst(c, opcode);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
{
scf_instruction_t* inst = __naja_inst_SIB2G(c, rd, sib);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
{
scf_instruction_t* inst = __naja_inst_G2SIB(c, rs, sib);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = __naja_inst_BL(c, 0);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf);
rela->type = R_AARCH64_CALL26;
i0 = opcode & 0xf;
r0 = f->rops->find_register_type_id_bytes(0, i0, 8);
inst = f->iops->MOV_G(c, r10, r0); // use r10 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~0xf;
opcode |= 0xa;
r0 = f->rops->find_register_type_id_bytes(0, i0, 8);
inst = f->iops->MOV_G(c, r10, r0); // use r10 to backup r0
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
r0 = f->rops->find_register_type_id_bytes(0, i1, 8);
inst = f->iops->MOV_G(c, r11, r0); // use r11 to backup r1
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
opcode &= ~0xf;
opcode |= 0xa;
if (inst) {
inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_ADRP, 8,8, SCF_RISC_E2G);
inst->dst.base = rd;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
}
return inst;
if (f->bp_used_flag) {
inst = ctx->iops->PUSH(NULL, fp);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes = inst->len;
inst = ctx->iops->MOV_SP(NULL, fp, sp);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes += inst->len;
uint32_t local = f->local_vars_size + fp->bytes;
local <<= 12;
}
- inst = ctx->iops->SUB_IMM(f->init_code, f, sp, sp, local);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ inst = ctx->iops->SUB_IMM(f->init_code, f, sp, sp, local);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes += inst->len;
int ret = _risc_save_rabi(f);
for (i = 0; i < relas->size; i++) {
scf_rela_t* rela = relas->data[i];
- scf_3ac_code_t* c = rela->code;
scf_instruction_t* inst = rela->inst;
+ scf_3ac_code_t* c = inst->c;
scf_basic_block_t* cur_bb = c->basic_block;
scf_instruction_t* inst2;
return ret;
if (cmp)
- RISC_INST_ADD_CHECK(c->instructions, cmp);
+ RISC_INST_ADD_CHECK(c, cmp);
return 0;
}
inst = ctx->iops->CVTSS2SD(c, rs, rs);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
if (!rd) {
else
inst = ctx->iops->FMOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
ret = risc_rcg_make(c, c->rcg, NULL, rd);
int valid = _risc_dst_reg_valid(f, rd, updated_regs, nb_updated, idx_int, nb_int);
if (valid) {
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
assert(nb_updated < max_updated);
if (stack_size > 0) {
inst_sp = risc_make_inst(c, 0);
inst_sp2 = risc_make_inst(c, 0);
- RISC_INST_ADD_CHECK(c->instructions, inst_sp);
- RISC_INST_ADD_CHECK(c->instructions, inst_sp2);
+ RISC_INST_ADD_CHECK(c, inst_sp);
+ RISC_INST_ADD_CHECK(c, inst_sp2);
}
ret = _risc_inst_call_argv(ctx, c, f);
}
inst = ctx->iops->BLR(c, r_pf);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
scf_loge("\n");
if (stack_size > 0) {
inst = ctx->iops->ADD_IMM(c, f, sp, sp, stack_size);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
int nb_updated = 0;
inst = ctx->iops->MVN(c, rd, rs);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->ADD_IMM(c, f, rs, rs, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->ADD_IMM(c, f, rs, rs, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->SUB_IMM(c, f, rs, rs, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->SUB_IMM(c, f, rs, rs, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->NEG(c, rd, rs);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0);
inst = ctx->iops->E2G(pxor, rd, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (src->dag_node->color > 0) {
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->E2G(sub, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
scf_rela_t* rela = NULL;
}
inst = ctx->iops->M2G(&rela, sub, rd, NULL, v);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
}
#endif
return ret;
inst = ctx->iops->ADD_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, r, &sib);
return ret;
inst = ctx->iops->SUB_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, r, &sib);
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return ret;
inst = ctx->iops->ADD_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, r, &sib);
return ret;
inst = ctx->iops->SUB_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, r, &sib);
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
#if 0
push = risc_find_OpCode(SCF_RISC_PUSH, 8,8, SCF_RISC_G);
inst = ctx->iops->G(push, rax);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
#endif
return -1;
#if 0
pop = risc_find_OpCode(SCF_RISC_POP, 8,8, SCF_RISC_G);
inst = ctx->iops->G(pop, rax);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
#endif
return -1;
RISC_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0);
inst = ctx->iops->P2G(lea, rptr, rbp, offset_int);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 0, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->P2G(lea, rptr, rbp, offset_float);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 8, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->P2G(lea, rptr, rbp, offset_others);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 16, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
mov = risc_find_OpCode(SCF_RISC_MOV, 4, 8, SCF_RISC_I2E);
inst = ctx->iops->I2P(mov, rap, 24, (uint8_t*)&f->args_int, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->I2P(mov, rap, 32, (uint8_t*)&f->args_float, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
#endif
return -1;
RISC_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0);
inst = ctx->iops->G2E(xor, rptr, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 0, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 8, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 16, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 24, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->G2P(mov, rap, 32, rptr);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
ptr->dag_node->var->tmp_flag = 0;
ptr->dag_node->color = 0;
}
inst = ctx->iops->I2P(cmp, rap, idx_offset, (uint8_t*)&nints, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst_jge = ctx->iops->I(jge, (uint8_t*)&offset, sizeof(offset));
- RISC_INST_ADD_CHECK(c->instructions, inst_jge);
+ RISC_INST_ADD_CHECK(c, inst_jge);
inst = ctx->iops->P2G(mov, rptr, rap, ptr_offset);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
offset += inst->len;
inst = ctx->iops->I2P(sub, rap, ptr_offset, (uint8_t*)&incptr, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
offset += inst->len;
inst_jmp = ctx->iops->I(jmp, (uint8_t*)&offset, sizeof(offset));
- RISC_INST_ADD_CHECK(c->instructions, inst_jmp);
+ RISC_INST_ADD_CHECK(c, inst_jmp);
offset += inst_jmp->len;
uint8_t* p = (uint8_t*)&offset;
offset = 0;
inst = ctx->iops->P2G(mov, rptr, rap, 16);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
offset += inst->len;
inst = ctx->iops->I2P(add, rap, 16, (uint8_t*)&incptr, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
offset += inst->len;
for (i = 0; i < 4; i++)
inst_jmp->code[jmp->nb_OpCodes + i] = p[i];
inst = ctx->iops->P(inc, rap, idx_offset, 8);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (is_float) {
if (4 == size)
mov2 = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_E2G);
inst = ctx->iops->P2G(mov2, rd, rptr, 0);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
#endif
RISC_SELECT_REG_CHECK(&rs1, s1, c, f, 1);
inst = ctx->iops->FDIV(c, rd, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
else
inst = ctx->iops->DIV(c, rd, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->SDIV(c, rd, rs0, rs1);
else
inst = ctx->iops->DIV(c, rd, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->MSUB(c, rd, rs1, rd, rs0);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->FMUL(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->MUL(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s1->color = 0;
s1->loaded = 0;
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->MUL(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->FMUL(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->MUL(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s->color = 0;
s->loaded = 0;
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->MUL(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->FADD(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rn, s0, c, f, 1);
inst = ctx->iops->ADD_IMM(c, f, rd, rn, u);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->ADD_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->FADD(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rd, d, c, f, 0);
inst = ctx->iops->ADD_IMM(c, f, rd, rd, u);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->ADD_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->FSUB(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rd, d, c, f, 0);
inst = ctx->iops->SUB_IMM(c, f, rd, rd, u);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->SUB_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->FSUB(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rn, s0, c, f, 1);
inst = ctx->iops->SUB_IMM(c, f, rd, rn, u);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (neg) {
inst = ctx->iops->NEG(c, rd, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->SUB_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->AND_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s1->color = 0;
s1->loaded = 0;
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->AND_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->OR_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s1->color = 0;
s1->loaded = 0;
RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1);
inst = ctx->iops->OR_G(c, rd, rn, rm);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->AND_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s->color = 0;
s->loaded = 0;
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->AND_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
s->color = 0;
s->loaded = 0;
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = ctx->iops->TEQ(c, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
SET_INIT();
inst = ctx->iops->SETZ(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
{
SET_INIT();
inst = ctx->iops->SETNZ(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
static int _risc_inst_setge_handler(scf_native_t* ctx, scf_3ac_code_t* c)
{
SET_INIT();
inst = ctx->iops->SETGE(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
static int _risc_inst_setgt_handler(scf_native_t* ctx, scf_3ac_code_t* c)
{
SET_INIT();
inst = ctx->iops->SETGT(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
static int _risc_inst_setlt_handler(scf_native_t* ctx, scf_3ac_code_t* c)
{
SET_INIT();
inst = ctx->iops->SETLT(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
static int _risc_inst_setle_handler(scf_native_t* ctx, scf_3ac_code_t* c)
{
SET_INIT();
inst = ctx->iops->SETLE(c, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs1, ds1, c, f, 1);
inst = ctx->iops->FCMP(c, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
assert(0 == scf_vector_del(rs1->dag_nodes, ds1));
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs1, ds1, c, f, 1);
inst = ctx->iops->CMP_G(c, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->CVTF2UI(c, rd, rs);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
} else if (scf_variable_float(vd)) {
else
inst = ctx->iops->CVTUI2F(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
} else
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->FDIV(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
else
inst = ctx->iops->DIV(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->SDIV(c, r, rd, rs);
else
inst = ctx->iops->DIV(c, r, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->MSUB(c, rd, rs, r, rd);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->MOV_G(c, rd, rs);
} else
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
scf_instruction_t* tmp;
int j;
if (0 == dn->color) { \
mov = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_I2G); \
inst = ctx->iops->I2G(mov, r, (uint8_t*)&dn->var->data, size); \
- RISC_INST_ADD_CHECK(c->instructions, inst); \
+ RISC_INST_ADD_CHECK(c, inst); \
\
} else { \
if (dn->color < 0) \
if (!RISC_COLOR_CONFLICT(rd->color, r->color)) { \
mov = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_G2E); \
inst = ctx->iops->G2E(mov, r, rd); \
- RISC_INST_ADD_CHECK(c->instructions, inst); \
+ RISC_INST_ADD_CHECK(c, inst); \
} \
} \
} while (0)
stos = risc_find_OpCode(SCF_RISC_STOS, 1, 8, SCF_RISC_G);
inst = risc_make_inst(stos, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
#endif
return ret;
inst = ctx->iops->MOV_SP(c, sp, fp);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->POP(c, fp);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
inst = ctx->iops->RET(c);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
} \
\
inst = ctx->iops->NAME(c); \
- RISC_INST_ADD_CHECK(c->instructions, inst); \
+ RISC_INST_ADD_CHECK(c, inst); \
return 0;\
}
RISC_SELECT_REG_CHECK(&rs, d, c, f, 1);
inst = ctx->iops->FMOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
RISC_SELECT_REG_CHECK(&rs, s, c, f, 1);
inst = ctx->iops->MOV_G(c, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
} else
inst = ctx->iops->SHL(c, rd, rs0, rs1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
} else
inst = ctx->iops->SHL(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
inst = ctx->iops->ADD_G(c, rd, rd, rs);
else
inst = ctx->iops->FADD(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
inst = ctx->iops->SUB_G(c, rd, rd, rs);
else
inst = ctx->iops->FSUB(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
return ret;
inst = ctx->iops->AND_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
return ret;
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
return ret;
inst = ctx->iops->SUB_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
return ret;
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
return ret;
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size);
}
inst = ctx->iops->ADD_G(c, rd, rd, rs);
else
inst = ctx->iops->FADD(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
inst = ctx->iops->SUB_G(c, rd, rd, rs);
else
inst = ctx->iops->FSUB(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
rs = rd;
return ret;
inst = ctx->iops->AND_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
ret = ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->OR_G(c, rd, rd, rs);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
if (sib.index)
return ctx->iops->G2SIB(c, f, rd, &sib);
return ret;
inst = ctx->iops->SUB_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, r, sib.base, 0, size);
}
return ret;
inst = ctx->iops->ADD_IMM(c, f, r, r, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return ctx->iops->G2P(c, f, r, sib.base, 0, size);
}
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
ret = ctx->iops->G2P(c, f, rd, sib.base, 0, size);
if (ret < 0)
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
return ret;
inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
ret = ctx->iops->G2P(c, f, rd, sib.base, 0, size);
if (ret < 0)
return ret;
inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
return 0;
}
scf_instruction_t* risc_make_inst(scf_3ac_code_t* c, uint32_t opcode);
-#define RISC_INST_ADD_CHECK(vec, inst) \
+#define RISC_INST_ADD_CHECK(_c, _inst) \
do { \
- if (!(inst)) { \
+ if (!(_inst)) { \
scf_loge("\n"); \
return -ENOMEM; \
} \
- int ret = scf_vector_add((vec), (inst)); \
+ int ret = scf_vector_add((_c)->instructions, (_inst)); \
if (ret < 0) { \
- scf_loge("\n"); \
- scf_instruction_free(inst); \
+ scf_instruction_free(_inst); \
return ret; \
} \
+ \
+ (_inst)->c = (_c); \
} while (0)
-#define RISC_RELA_ADD_CHECK(vec, rela, c, v, f) \
+#define RISC_RELA_ADD_CHECK(_vec, _rela, _c, _v, _f) \
do { \
- rela = calloc(1, sizeof(scf_rela_t)); \
- if (!rela) \
+ (_rela) = calloc(1, sizeof(scf_rela_t)); \
+ if (!(_rela)) \
return -ENOMEM; \
+ (_rela)->var = (_v); \
+ (_rela)->func = (_f); \
+ (_rela)->inst = (_c)->instructions->data[(_c)->instructions->size - 1]; \
+ (_rela)->addend = 0; \
\
- (rela)->code = (c); \
- (rela)->var = (v); \
- (rela)->func = (f); \
- (rela)->inst = (c)->instructions->data[(c)->instructions->size - 1]; \
- (rela)->addend = 0; \
- \
- int ret = scf_vector_add((vec), (rela)); \
+ int ret = scf_vector_add((_vec), (_rela)); \
if (ret < 0) { \
- scf_rela_free(rela); \
+ scf_rela_free(_rela); \
return ret; \
} \
+ \
+ (_rela)->inst->rel = (_rela); \
} while (0)
-#define RISC_RELA_ADD_LABEL(vec, rela, _inst, _label) \
+#define RISC_RELA_ADD_LABEL(_vec, _rela, _inst, _label) \
do { \
- rela = calloc(1, sizeof(scf_rela_t)); \
- if (!rela) \
+ (_rela) = calloc(1, sizeof(scf_rela_t)); \
+ if (!(_rela)) \
return -ENOMEM; \
\
- (rela)->inst = (_inst); \
- (rela)->name = scf_string_clone(_label); \
- if (!(rela)->name) { \
- scf_loge("\n"); \
- scf_rela_free(rela); \
+ (_rela)->inst = (_inst); \
+ (_rela)->name = scf_string_clone(_label); \
+ if (!(_rela)->name) { \
+ scf_rela_free(_rela); \
return -ENOMEM; \
} \
- int ret = scf_vector_add((vec), (rela)); \
+ \
+ int ret = scf_vector_add((_vec), (_rela)); \
if (ret < 0) { \
- scf_loge("\n"); \
- scf_rela_free(rela); \
+ scf_rela_free(_rela); \
return ret; \
} \
+ \
+ (_rela)->inst->rel = (_rela); \
} while (0)
#endif
if (scf_variable_signed(index->var)) {
inst = f->iops->MOVSX(c, ri, ri, ri->bytes);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
ri = ri2;
return ret;
inst = f->iops->MUL(c, rs, rs, ri);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
ri = rs;
s = 1;
inst = f->iops->ADD_G(c, rs, rs, rb);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
assert(1 == s);
inst = f->iops->ADD_G(c, rs, rb, rd);
}
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
ri = NULL;
}
return ret;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
if (i == nb_updated) {
inst = f->iops->POP(c, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
inst = f->iops->ADD_IMM(c, f, sp, sp, 4);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
}
return 0;
if (j < N) {
inst = f->iops->PUSH(NULL, r);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes += inst->len;
}
if (j < N) {
inst = f->iops->POP(c, r);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
}
return ret;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
return ret;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
if (i == nb_updated) {
inst = f->iops->POP(c, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
inst = f->iops->ADD_IMM(c, f, sp, sp, 8);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
}
return 0;
}
inst = f->iops->PUSH(NULL, r);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes += inst->len;
}
}
inst = f->iops->POP(c, r);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
return ret;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
return ret;
} else {
inst = f->iops->PUSH(NULL, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
saved_regs[k++] = r2;
if (i == nb_updated) {
inst = f->iops->POP(c, r2);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
} else {
inst = f->iops->ADD_IMM(c, f, sp, sp, 8);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
}
return 0;
}
inst = f->iops->PUSH(NULL, r);
- RISC_INST_ADD_CHECK(f->init_code->instructions, inst);
+ RISC_INST_ADD_CHECK(f->init_code, inst);
f->init_code_bytes += inst->len;
}
}
inst = f->iops->POP(c, r);
- RISC_INST_ADD_CHECK(c->instructions, inst);
+ RISC_INST_ADD_CHECK(c, inst);
}
return 0;
if (rela->name)
scf_string_free(rela->name);
+ rela->inst->rel = NULL;
free(rela);
}
}
if (inst->bin)
scf_string_free(inst->bin);
+ inst->rel = NULL;
free(inst);
}
}
void scf_inst_data_print(scf_inst_data_t* id)
{
- if (1 == id->flag) {
+ if (1 == id->mem_flag) {
if (id->index)
printf("%d(%s, %s, %d)", id->disp, id->base->name, id->index->name, id->scale);
#include"scf_core_types.h"
typedef struct scf_instruction_s scf_instruction_t;
+typedef struct scf_rela_s scf_rela_t;
struct scf_register_s
{
uint64_t imm;
int imm_size;
- uint8_t flag;
+ uint8_t mem_flag:1;
} scf_inst_data_t;
struct scf_instruction_s
{
scf_3ac_code_t* c;
+ scf_rela_t* rel;
+
scf_OpCode_t* OpCode;
scf_instruction_t* next; // only for jcc, jmp, call
int nb_used;
};
-typedef struct {
- scf_3ac_code_t* code; // related 3ac code
+struct scf_rela_s
+{
scf_function_t* func;
scf_variable_t* var;
scf_string_t* name;
int64_t text_offset; // byte offset in .text segment
uint64_t type;
int addend;
-} scf_rela_t;
+};
static inline int scf_inst_data_empty(scf_inst_data_t* id)
{
- return !(id->flag || id->base || id->imm_size);
+ return !(id->mem_flag || id->base || id->imm_size);
}
static inline int scf_inst_data_same(scf_inst_data_t* id0, scf_inst_data_t* id1)
{
// global var, are considered as different.
- if ((id0->flag && !id0->base) || (id1->flag && !id1->base))
+ if ((id0->mem_flag && !id0->base) || (id1->mem_flag && !id1->base))
return 0;
if (id0->scale == id1->scale
&& id0->disp == id1->disp
- && id0->flag == id1->flag
&& id0->imm == id1->imm
- && id0->imm_size == id1->imm_size) {
+ && id0->imm_size == id1->imm_size
+ && id0->mem_flag == id1->mem_flag) {
if (id0->base == id1->base
|| (id0->base && id1->base && SCF_COLOR_CONFLICT(id0->base->color, id1->base->color))) {
#define X64_SAVE_RABI(offset, rabi) \
do { \
inst = x64_make_inst_G2P(mov, rbp, offset, rabi); \
- X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); \
+ X64_INST_ADD_CHECK(f->init_code, inst, NULL); \
f->init_code_bytes += inst->len; \
} while (0)
if (err < 0)
return err;
+ uint32_t local = f->bp_used_flag ? f->local_vars_size : 0;
+
+ if ((f->callee_saved_size + local) & 0xf)
+ local += 8;
+
+ scf_logd("### local: %#x, local_vars_size: %#x, callee_saved_size: %#x\n",
+ local, f->local_vars_size, f->callee_saved_size);
+
if (f->bp_used_flag || f->vla_flag || f->call_flag) {
- inst = x64_make_inst_G2E(mov, rsp, rbp);
- X64_INST_ADD_CHECK(end->instructions, inst, NULL);
- end->inst_bytes += inst->len;
- bb ->code_bytes += inst->len;
+ if (f->bp_used_flag || f->vla_flag) {
+ inst = x64_make_inst_G2E(mov, rsp, rbp);
+ X64_INST_ADD_CHECK(end, inst, NULL);
+ end->inst_bytes += inst->len;
+ bb ->code_bytes += inst->len;
+ }
inst = x64_make_inst_G(pop, rbp);
- X64_INST_ADD_CHECK(end->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(end, inst, NULL);
end->inst_bytes += inst->len;
bb ->code_bytes += inst->len;
}
f->init_code_bytes = 0;
- uint32_t local = f->bp_used_flag ? f->local_vars_size : 0;
if (f->bp_used_flag || f->vla_flag || f->call_flag) {
inst = x64_make_inst_G(push, rbp);
- X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL);
- f->init_code_bytes += inst->len;
-
- inst = x64_make_inst_G2E(mov, rbp, rsp);
- X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(f->init_code, inst, NULL);
f->init_code_bytes += inst->len;
- if ((f->callee_saved_size + local) & 0xf)
- local += 8;
-
- scf_logd("### local: %#x, local_vars_size: %#x, callee_saved_size: %#x\n",
- local, f->local_vars_size, f->callee_saved_size);
+ if (f->bp_used_flag || f->vla_flag) {
+ inst = x64_make_inst_G2E(mov, rbp, rsp);
+ X64_INST_ADD_CHECK(f->init_code, inst, NULL);
+ f->init_code_bytes += inst->len;
+ }
- inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&local, 4);
- X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL);
- f->init_code_bytes += inst->len;
+ if (local > 0) {
+ inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&local, 4);
+ X64_INST_ADD_CHECK(f->init_code, inst, NULL);
+ f->init_code_bytes += inst->len;
+ }
err = _x64_save_rabi(f);
if (err < 0)
return err;
inst = x64_make_inst(ret, 8);
- X64_INST_ADD_CHECK(end->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(end, inst, NULL);
end->inst_bytes += inst->len;
bb ->code_bytes += inst->len;
for (i = 0; i < relas->size; i++) {
scf_rela_t* rela = relas->data[i];
- scf_3ac_code_t* c = rela->code;
scf_instruction_t* inst = rela->inst;
+ scf_3ac_code_t* c = inst->c;
scf_basic_block_t* cur_bb = c->basic_block;
scf_instruction_t* inst2;
if (!rd) {
if (movx) {
inst = x64_make_inst_E2G(movx, rs, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
inst = x64_make_inst_G2P(mov, rsp, v->sp_offset, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
continue;
}
if (!X64_COLOR_CONFLICT(rd->color, rs->color)) {
if (movx) {
inst = x64_make_inst_E2G(movx, rs, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
rd = x64_find_register_color_bytes(rd->color, rs->bytes);
inst = x64_make_inst_G2E(mov, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (movx) {
inst = x64_make_inst_E2G(movx, rs, rs);
}
for (i = 0; i < nb_movx; i++) {
- X64_INST_ADD_CHECK(c->instructions, inst_movx[i], NULL);
+ X64_INST_ADD_CHECK(c, inst_movx[i], NULL);
}
return nb_floats;
int valid = _x64_dst_reg_valid(rd, updated_regs, nb_updated, idx_int, nb_int);
if (valid) {
inst = x64_make_inst_G2E(mov, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
assert(nb_updated < max_updated);
scf_rela_t* rela = NULL;
inst = x64_make_inst_G2M(&rela, mov, dn->var, NULL, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dn->var, NULL);
}
}
if (stack_size > 0) {
sub = x64_find_OpCode(SCF_X64_SUB, 4,4, SCF_X64_I2E);
inst_rsp = x64_make_inst_I2E(sub, rsp, (uint8_t*)&stack_size, 4);
- X64_INST_ADD_CHECK(c->instructions, inst_rsp, NULL);
+ X64_INST_ADD_CHECK(c, inst_rsp, NULL);
}
ret = _x64_inst_call_argv(c, f);
mov = x64_find_OpCode(SCF_X64_MOV, 4,4, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, eax, (uint8_t*)&imm, sizeof(imm));
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
scf_register_t* saved_regs[X64_ABI_CALLER_SAVES_NB];
scf_register_t* drop_regs [X64_ABI_CALLER_SAVES_NB];
int32_t offset = 0;
call = x64_find_OpCode(SCF_X64_CALL, 4,4, SCF_X64_I);
inst = x64_make_inst_I(call, (uint8_t*)&offset, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst->OpCode = (scf_OpCode_t*)call;
}
inst = x64_make_inst_E(call, r_pf);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst->OpCode = (scf_OpCode_t*)call;
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, call, var_pf, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf);
inst->OpCode = (scf_OpCode_t*)call;
if (stack_size > 0) {
add = x64_find_OpCode(SCF_X64_ADD, 4, 4, SCF_X64_I2E);
inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&stack_size, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
x64_drop_regs(drop_regs, n_drops);
}
if (save_size > 0) {
- ret = x64_pop_regs(c->instructions, saved_regs, save_size >> 3, updated_regs, nb_updated);
+ ret = x64_pop_regs(c, saved_regs, save_size >> 3, updated_regs, nb_updated);
if (ret < 0) {
scf_loge("\n");
return ret;
if (dst->dag_node->color > 0) {
X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0);
inst = x64_make_inst_E(OpCode, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, OpCode, var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, var, NULL);
}
if (src->dag_node->color > 0) {
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_E(OpCode, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (0 == src->dag_node->color) {
scf_loge("\n");
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, OpCode, var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, var, NULL);
}
X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0);
inst = x64_make_inst_E2G(pxor, rd, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
if (src->dag_node->color > 0) {
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_E2G(sub, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
v = src->dag_node->var;
scf_rela_t* rela = NULL;
inst = x64_make_inst_M2G(&rela, sub, rd, NULL, v);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
}
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_M2G(&rela, OpCode, rs, NULL, v1);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v1, NULL);
return 0;
}
if (src->dag_node->color > 0) {
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_I2E(OpCode, rs, (uint8_t*)&v->data_size, imm_size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_I2M(&rela, OpCode, v, NULL, (uint8_t*)&v->data_size, imm_size);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
}
if (src->dag_node->color > 0) {
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_E(OpCode, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, OpCode, v, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
}
}
else
inst = x64_make_inst_I2P(OpCode, sib.base, sib.disp, (uint8_t*)&vs->data, size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
if (sib.index) {
inst = x64_make_inst_G2SIB(OpCode, sib.base, sib.index, sib.scale, sib.disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_G2P(OpCode, sib.base, sib.disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
}
if (sib.index) {
inst = x64_make_inst_SIB2G(OpCode, rd, sib.base, sib.index, sib.scale, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_P2G(OpCode, rd, sib.base, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
}
lea = x64_find_OpCode(SCF_X64_LEA, 8,8, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, lea, rd, NULL, src->dag_node->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->dag_node->var, NULL);
return 0;
}
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_G2E(mov, rsi, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
scf_rela_t* rela = NULL;
inst = x64_make_inst_M2G(&rela, lea, rdi, NULL, msg->dag_node->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, msg->dag_node->var, NULL);
inst = x64_make_inst_G2E(xor, rax, rax);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
// call printf() to show msg
uint32_t imm = 0;
inst = x64_make_inst_I(call, (uint8_t*)&imm, sizeof(imm));
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
rela = calloc(1, sizeof(scf_rela_t));
if (!rela)
X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, logf->dag_node->var->func_ptr);
inst = x64_make_inst_G2E(xor, rax, rax);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rax, 0, rax);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
uint32_t imm = 0xf;
inst = x64_make_inst_I2E(add, rs, (uint8_t*)&imm, sizeof(imm));
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
imm = ~0xf;
inst = x64_make_inst_I2E(and, rs, (uint8_t*)&imm, sizeof(imm));
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_E2G(sub, rsp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
int ret = x64_save_var(src->dag_node, c, f);
if (ret < 0)
X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0);
inst = x64_make_inst_G2E(mov, rd, rsp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
inst = x64_make_inst_E2G(add, rsp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2E(xor, rs, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return x64_save_var(src->dag_node, c, f);
}
if (rd->bytes > size) {
inst = x64_make_inst_E2G(mov, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1);
if (!X64_COLOR_CONFLICT(rd->color, rs->color) || rd->bytes > size) {
inst = x64_make_inst_E2G(mov, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
}
} else if (0 == src->dag_node->color) {
mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, rd, (uint8_t*)&v->data, rd->bytes);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_M2G(&rela, mov, rd, NULL, v);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
}
}
if (0 == dn->color) { \
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G); \
inst = x64_make_inst_I2G(mov, r, (uint8_t*)&dn->var->data, size); \
- X64_INST_ADD_CHECK(c->instructions, inst, NULL); \
+ X64_INST_ADD_CHECK(c, inst, NULL); \
\
} else { \
if (dn->color < 0) \
if (!X64_COLOR_CONFLICT(rd->color, r->color)) { \
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_G2E); \
inst = x64_make_inst_G2E(mov, r, rd); \
- X64_INST_ADD_CHECK(c->instructions, inst, NULL); \
+ X64_INST_ADD_CHECK(c, inst, NULL); \
} \
} \
} while (0)
stos = x64_find_OpCode(SCF_X64_STOS, 1, 8, SCF_X64_G);
inst = x64_make_inst(stos, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[i], 8);
inst = x64_make_inst_G(push, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
if (n & 0x1) {
r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[n - 1], 8);
inst = x64_make_inst_G(push, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
}
if (n & 0x1) {
r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[n - 1], 8);
inst = x64_make_inst_G(pop, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
for (i = n - 1; i >= 0; i--) {
r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[i], 8);
inst = x64_make_inst_G(pop, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
X64_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0);
inst = x64_make_inst_P2G(lea, rptr, rbp, offset_int);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 0, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_P2G(lea, rptr, rbp, offset_float);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 8, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_P2G(lea, rptr, rbp, offset_others);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 16, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
mov = x64_find_OpCode(SCF_X64_MOV, 4, 8, SCF_X64_I2E);
inst = x64_make_inst_I2P(mov, rap, 24, (uint8_t*)&f->args_int, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_I2P(mov, rap, 32, (uint8_t*)&f->args_float, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
X64_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0);
inst = x64_make_inst_G2E(xor, rptr, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 0, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 8, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 16, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 24, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(mov, rap, 32, rptr);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
ptr->dag_node->var->tmp_flag = 0;
ptr->dag_node->color = 0;
}
inst = x64_make_inst_I2P(cmp, rap, idx_offset, (uint8_t*)&nints, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst_jge = x64_make_inst_I(jge, (uint8_t*)&offset, sizeof(offset));
- X64_INST_ADD_CHECK(c->instructions, inst_jge, NULL);
+ X64_INST_ADD_CHECK(c, inst_jge, NULL);
inst = x64_make_inst_P2G(mov, rptr, rap, ptr_offset);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
offset += inst->len;
inst = x64_make_inst_I2P(sub, rap, ptr_offset, (uint8_t*)&incptr, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
offset += inst->len;
inst_jmp = x64_make_inst_I(jmp, (uint8_t*)&offset, sizeof(offset));
- X64_INST_ADD_CHECK(c->instructions, inst_jmp, NULL);
+ X64_INST_ADD_CHECK(c, inst_jmp, NULL);
offset += inst_jmp->len;
uint8_t* p = (uint8_t*)&offset;
offset = 0;
inst = x64_make_inst_P2G(mov, rptr, rap, 16);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
offset += inst->len;
inst = x64_make_inst_I2P(add, rap, 16, (uint8_t*)&incptr, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
offset += inst->len;
for (i = 0; i < 4; i++)
inst_jmp->code[jmp->nb_OpCodes + i] = p[i];
inst = x64_make_inst_P(inc, rap, idx_offset, 8);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
if (is_float) {
if (4 == size)
mov2 = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G);
inst = x64_make_inst_P2G(mov2, rd, rptr, 0);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
inst = x64_make_inst_SIB2G(mov, rs, rb, ri, scale, disp);
else
inst = x64_make_inst_P2G(mov, rs, rb, disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
OpCode = x64_find_OpCode(OpCode_type, v->size, v->size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, OpCode, rs, NULL, src->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
end:
inst = x64_make_inst_G2SIB(mov, rb, ri, scale, disp, rs);
else
inst = x64_make_inst_G2P(mov, rb, disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
inst = x64_make_inst_I2SIB(OpCode, rb, ri, scale, disp, (uint8_t*)&v->data, dsize);
else
inst = x64_make_inst_I2P(OpCode, rb, disp, (uint8_t*)&v->data, dsize);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
inst = x64_make_inst_G2SIB(OpCode, rb, ri, scale, disp, rs);
else
inst = x64_make_inst_G2P(OpCode, rb, disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
if (sib.index) {
inst = x64_make_inst_SIB2G(mov, rd, sib.base, sib.index, sib.scale, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_P2G(mov, rd, sib.base, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
}
r = x64_find_register_color_bytes(rs->color, 8);
inst = x64_make_inst_G(push, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_I2G(mov, rs, (uint8_t*)&mask, dsize);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
if (sib.index)
inst = x64_make_inst_G2SIB(and, sib.base, sib.index, sib.scale, sib.disp, rs);
else
inst = x64_make_inst_G2P(and, sib.base, sib.disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G(pop, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
int imm = (rs->bytes << 3) - vm->bit_size;
assert(imm > 0);
shr = x64_find_OpCode(SCF_X64_SHR, 1, rs->bytes, SCF_X64_I2E);
inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&imm, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
imm -= vm->bit_offset;
assert(imm >= 0);
if (imm > 0) {
inst = x64_make_inst_I2E(shr, rs, (uint8_t*)&imm, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
mov = x64_find_OpCode(SCF_X64_OR, dsize, dsize, SCF_X64_G2E);
inst = x64_make_inst_G2SIB(mov, sib.base, sib.index, sib.scale, sib.disp, rs);
else
inst = x64_make_inst_G2P(mov, sib.base, sib.disp, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
if (sib.index) {
inst = x64_make_inst_SIB2G(mov, rd, sib.base, sib.index, sib.scale, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_P2G(mov, rd, sib.base, sib.disp);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
if (vm->bit_size > 0) {
if (imm > 0) {
inst = x64_make_inst_I2E(shl, rd, (uint8_t*)&imm, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
imm += vm->bit_offset;
inst = x64_make_inst_I2E(shr, rd, (uint8_t*)&imm, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
X64_SELECT_REG_CHECK(&rs1, src1, c, f, 1);
inst = x64_make_inst_E2G(cmp, rs0, rs1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
} else {
if (cmp) {
inst = x64_make_inst_I2E(cmp, rs0, (uint8_t*)&src1->var->data, src1_size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
cmp = x64_find_OpCode(SCF_X64_CMP, rs0->bytes, src1_size, SCF_X64_G2E);
inst = x64_make_inst_G2E(cmp, rs0, rs1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
src1->loaded = 0;
src1->color = 0;
if (src1->color > 0) {
X64_SELECT_REG_CHECK(&rs1, src1, c, f, 1);
inst = x64_make_inst_E2G(cmp, rs0, rs1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_M2G(&rela, cmp, rs0, NULL, src1->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src1->var, NULL);
}
mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, rd, (uint8_t*)&imm, rd->bytes);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
rd = x64_find_register_color_bytes(rd->color, 1);
}
inst = x64_make_inst_E(setcc, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
test = x64_find_OpCode(SCF_X64_TEST, v->size, v->size, SCF_X64_G2E);
inst = x64_make_inst_G2E(test, rs, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2G);
if (OpCode) {
inst = x64_make_inst_I2G(OpCode, rd, (uint8_t*)&src->var->data, src_size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2E);
if (OpCode) {
inst = x64_make_inst_I2E(OpCode, rd, (uint8_t*)&src->var->data, src_size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
}
X64_SELECT_REG_CHECK(&rs, src, c, f, 1);
inst = x64_make_inst_G2E(OpCode, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
src->color = 0;
src->loaded = 0;
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2E);
if (OpCode) {
inst = x64_make_inst_I2M(&rela, OpCode, dst->var, NULL, (uint8_t*)&src->var->data, src_size);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
return 0;
}
X64_SELECT_REG_CHECK(&rs, src, c, f, 1);
inst = x64_make_inst_G2M(&rela, OpCode, dst->var, NULL, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
src->color = 0;
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_G2E);
if (OpCode) {
inst = x64_make_inst_G2E(OpCode, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_E2G);
if (!OpCode) {
}
inst = x64_make_inst_E2G(OpCode, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_E2G);
}
inst = x64_make_inst_M2G(&rela, OpCode, rd, NULL, src->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
}
assert(4 == src->var->size);
xor = x64_find_OpCode(SCF_X64_XOR, 8, 8, SCF_X64_G2E);
inst = x64_make_inst_G2E(xor, rd, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
movx = x64_find_OpCode(SCF_X64_MOV, 4, 4, SCF_X64_E2G);
}
if (src->color > 0) {
X64_SELECT_REG_CHECK(&rs, src, c, f, 0);
inst = x64_make_inst_E2G(movx, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (0 == src->color) {
// get the rd's low bits register
mov = x64_find_OpCode(SCF_X64_MOV, src->var->size, src->var->size, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, rs, (uint8_t*)&src->var->data, src->var->size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_E2G(movx, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M2G(&rela, movx, rd, NULL, src->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
}
X64_SELECT_REG_CHECK(&rs, src, c, f, 1);
inst = x64_make_inst_E2G(OpCode, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (src->color > 0) {
X64_SELECT_REG_CHECK(&rs, src, c, f, 1);
inst = x64_make_inst_E2G(OpCode, rd, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M2G(&rela, OpCode, rd, NULL, src->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
}
scf_instruction_t* inst = x64_make_inst_I(jcc, (uint8_t*)&offset, sizeof(offset));
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_G2E);
inst = x64_make_inst_G2E(mov, rl, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
if (rd->id != rh->id) {
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, mov, rl, NULL, dst->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
}
div = x64_find_OpCode(SCF_X64_IDIV, size, size, SCF_X64_E);
cdq = x64_find_OpCode_by_type(SCF_X64_CDQ);
inst = x64_make_inst(cdq, size << 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
div = x64_find_OpCode(SCF_X64_DIV, size, size, SCF_X64_E);
xor = x64_find_OpCode(SCF_X64_XOR, size, size, SCF_X64_G2E);
inst = x64_make_inst_G2E(xor, rh, rh);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
if (src->color > 0) {
X64_SELECT_REG_CHECK(&rs, src, c, f, 1);
inst = x64_make_inst_E(div, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, div, src->var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
}
if (rd->id != result->id) {
mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_G2E);
inst = x64_make_inst_G2E(mov, rd, result);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
scf_rela_t* rela = NULL;
mov = x64_find_OpCode(SCF_X64_MOV, dst->var->size, dst->var->size, SCF_X64_G2E);
inst = x64_make_inst_G2M(&rela, mov, dst->var, NULL, result);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
}
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, rh, (uint8_t*)&src->var->data, size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_E(mul, rh);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
scf_rela_t* rela = NULL;
inst = x64_make_inst_M(&rela, mul, src->var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL);
}
if (rd->id == rl->id) {
inst = x64_make_inst_E(mul, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (rs->id == rl->id) {
inst = x64_make_inst_E(mul, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_G2E(mov, rl, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_E(mul, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
if (rd->id != rl->id) {
inst = x64_make_inst_G2E(mov, rl, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
int ret = _int_mul_src(mul, rh, src, c, f);
if (rs->id != rl->id) {
inst = x64_make_inst_G2E(mov, rl, rs);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
inst = x64_make_inst_M(&rela, mul, dst->var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
} else {
mov2 = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, mov2, rl, NULL, dst->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
int ret = _int_mul_src(mul, rh, src, c, f);
if (rd) {
if (rd->id != rl->id) {
inst = x64_make_inst_G2E(mov, rd, rl);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
inst = x64_make_inst_G2M(&rela, mov, dst->var, NULL, rl);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
}
mov = x64_find_OpCode(SCF_X64_MOV, 1, 1, SCF_X64_G2E);
inst = x64_make_inst_G2E(mov, cl, rc);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else if (count->color < 0) {
ret = x64_overflow_reg(cl, c, f);
mov = x64_find_OpCode(SCF_X64_MOV, 1, 1, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, mov, cl, NULL, count->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, count->var, NULL);
}
if (0 != count->color) {
shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_G2E);
inst = x64_make_inst_E(shift, rd);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_I2E);
inst = x64_make_inst_I2E(shift, rd, (uint8_t*)&count->var->data, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
scf_rela_t* rela = NULL;
if (0 != count->color) {
shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_G2E);
inst = x64_make_inst_M(&rela, shift, dst->var, NULL);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
} else {
shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_I2E);
inst = x64_make_inst_I2M(&rela, shift, dst->var, NULL, (uint8_t*)&count->var->data, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL);
}
}
inst = x64_make_inst_SIB(OpCode, sib->base, sib->index, sib->scale, sib->disp, size);
else
inst = x64_make_inst_P(OpCode, sib->base, sib->disp, size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
return 0;
}
inst->src.base = NULL;
inst->src.disp = 0;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
inst->dst.base = NULL;
inst->dst.disp = 0;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
} else if (SCF_X64_MUL == OpCode->type
|| SCF_X64_DIV == OpCode->type
inst->src.base = NULL;
inst->src.disp = 0;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
}
return inst;
inst->src.base = r_base;
inst->src.disp = offset;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
inst->dst.base = r_base;
inst->dst.disp = offset;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
} else if (SCF_X64_MUL == OpCode->type
|| SCF_X64_DIV == OpCode->type
inst->src.base = r_base;
inst->src.disp = offset;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
}
return inst;
inst->dst.base = NULL;
inst->dst.disp = 0;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
inst->src.imm_size = size;
return inst;
inst->dst.base = r_base;
inst->dst.disp = offset;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
inst->src.imm_size = size;
return inst;
inst->src.base = r_src;
inst->dst.base = NULL;
inst->dst.disp = 0;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return inst;
}
inst->src.base = r_src;
inst->dst.base = r_base;
inst->dst.disp = offset;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return inst;
}
inst->dst.base = r_dst;
inst->src.base = NULL;
inst->src.disp = 0;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
return inst;
}
inst->dst.base = r_dst;
inst->src.base = r_base;
inst->src.disp = offset;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
return inst;
}
inst->dst.base = r_dst;
inst->src.base = r_base;
inst->src.disp = offset;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
return inst;
}
inst->src.base = r_src;
inst->dst.base = r_base;
inst->dst.disp = offset;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return inst;
}
inst->dst.base = r_base;
inst->dst.disp = offset;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return inst;
}
inst->src.index = r_index;
inst->src.scale = scale;
inst->src.disp = disp;
- inst->src.flag = 1;
+ inst->src.mem_flag = 1;
return _x64_make_inst_SIB(inst, OpCode, r_dst->id, r_base, r_index, scale, disp, r_dst->bytes);
}
inst->dst.index = r_index;
inst->dst.scale = scale;
inst->dst.disp = disp;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return _x64_make_inst_SIB(inst, OpCode, r_src->id, r_base, r_index, scale, disp, r_src->bytes);
}
inst->dst.index = r_index;
inst->dst.scale = scale;
inst->dst.disp = disp;
- inst->dst.flag = 1;
+ inst->dst.mem_flag = 1;
return inst;
}
scf_instruction_t* x64_make_inst_G2L(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, scf_register_t* r_src);
scf_instruction_t* x64_make_inst_L2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, scf_register_t* r_dst);
-#define X64_INST_ADD_CHECK(vec, inst, rela) \
+#define X64_INST_ADD_CHECK(_c, _inst, _rela) \
do { \
- if (!(inst)) { \
+ if (!(_inst)) { \
scf_loge("\n"); \
return -ENOMEM; \
} \
- int ret = scf_vector_add((vec), (inst)); \
+ int ret = scf_vector_add((_c)->instructions, (_inst)); \
if (ret < 0) { \
- scf_loge("\n"); \
- scf_instruction_free(inst); \
- scf_rela_free(rela); \
+ scf_instruction_free(_inst); \
+ scf_rela_free(_rela); \
return ret; \
} \
+ \
+ (_inst)->c = (_c); \
} while (0)
-#define X64_RELA_ADD_CHECK(vec, rela, c, v, f) \
+#define X64_RELA_ADD_CHECK(_vec, _rela, _c, _v, _f) \
do { \
- if (rela) { \
- (rela)->code = (c); \
- (rela)->var = (v); \
- (rela)->func = (f); \
- (rela)->inst = (c)->instructions->data[(c)->instructions->size - 1]; \
- (rela)->addend = -4; \
- (rela)->type = R_X86_64_PC32; \
- int ret = scf_vector_add((vec), (rela)); \
+ if (_rela) { \
+ (_rela)->var = (_v); \
+ (_rela)->func = (_f); \
+ (_rela)->inst = (_c)->instructions->data[(_c)->instructions->size - 1]; \
+ (_rela)->addend = -4; \
+ (_rela)->type = R_X86_64_PC32; \
+ \
+ int ret = scf_vector_add((_vec), (_rela)); \
if (ret < 0) { \
- scf_loge("\n"); \
- scf_rela_free(rela); \
+ scf_rela_free(_rela); \
return ret; \
} \
+ \
+ (_rela)->inst->rel = (_rela); \
} \
} while (0)
-#define X64_RELA_ADD_LABEL(vec, rela, _inst, _label) \
+#define X64_RELA_ADD_LABEL(_vec, _rela, _inst, _label) \
do { \
- if (rela) { \
- (rela)->inst = (_inst); \
- (rela)->addend = -4; \
- (rela)->type = R_X86_64_PC32; \
- (rela)->name = scf_string_clone(_label); \
- if (!(rela)->name) { \
- scf_loge("\n"); \
- scf_rela_free(rela); \
+ if (_rela) { \
+ (_rela)->inst = (_inst); \
+ (_rela)->addend = -4; \
+ (_rela)->type = R_X86_64_PC32; \
+ (_rela)->name = scf_string_clone(_label); \
+ if (!(_rela)->name) { \
+ scf_rela_free(_rela); \
return -ENOMEM; \
} \
- int ret = scf_vector_add((vec), (rela)); \
+ \
+ int ret = scf_vector_add((_vec), (_rela)); \
if (ret < 0) { \
- scf_loge("\n"); \
- scf_rela_free(rela); \
+ scf_rela_free(_rela); \
return ret; \
} \
+ \
+ (_rela)->inst->rel = (_rela); \
} \
} while (0)
#include"scf_basic_block.h"
#include"scf_3ac.h"
+static int __x64_peep_mov_by_lea(scf_instruction_t* mov, scf_instruction_t* lea)
+{
+ scf_instruction_t* inst;
+
+ if (lea->src.index)
+ inst = x64_make_inst_SIB2G((scf_x64_OpCode_t*)lea->OpCode,
+ mov->dst.base,
+ lea->src.base, lea->src.index, lea->src.scale, lea->src.disp);
+ else
+ inst = x64_make_inst_P2G((scf_x64_OpCode_t*)lea->OpCode, mov->dst.base, lea->src.base, lea->src.disp);
+
+ if (!inst)
+ return -ENOMEM;
+
+ memcpy(mov->code, inst->code, inst->len);
+ mov->len = inst->len;
+
+ mov->OpCode = lea->OpCode;
+ mov->src.base = lea->src.base;
+ mov->src.index = lea->src.index;
+ mov->src.scale = lea->src.scale;
+ mov->src.disp = lea->src.disp;
+ mov->src.mem_flag = lea->src.mem_flag;
+
+ free(inst);
+ return 0;
+}
+
+static int __x64_peep_src_was_mem(scf_instruction_t* inst, scf_inst_data_t* src)
+{
+ scf_instruction_t* tmp;
+ scf_x64_OpCode_t* OpCode;
+
+ if (src->base)
+ tmp = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, src->base);
+ else {
+ int bytes = inst->dst.base->bytes;
+
+ if (src->imm_size < bytes)
+ src->imm = scf_zero_extend(src->imm, src->imm_size);
+
+ OpCode = x64_find_OpCode(inst->OpCode->type, bytes, bytes, SCF_X64_I2G);
+ if (!OpCode) {
+ OpCode = x64_find_OpCode(inst->OpCode->type, bytes, bytes, SCF_X64_I2E);
+
+ if (!OpCode)
+ return -EINVAL;
+
+ tmp = x64_make_inst_I2E(OpCode, inst->dst.base, (uint8_t*)&src->imm, bytes);
+ } else
+ tmp = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&src->imm, bytes);
+ }
+ if (!tmp)
+ return -ENOMEM;
+
+ memcpy(inst->code, tmp->code, tmp->len);
+ inst->len = tmp->len;
+
+ inst->src.base = src->base;
+ inst->src.index = NULL;
+ inst->src.scale = 0;
+ inst->src.disp = 0;
+ inst->src.mem_flag = 0;
+
+ free(tmp);
+ return 0;
+}
+
+static int __x64_peep_dst_was_mem(scf_instruction_t* inst, scf_inst_data_t* dst)
+{
+ scf_instruction_t* tmp;
+
+ if (inst->src.imm_size > 0)
+ tmp = x64_make_inst_I2E((scf_x64_OpCode_t*)inst->OpCode, dst->base, (uint8_t*)&inst->src.imm, inst->src.imm_size);
+ else
+ tmp = x64_make_inst_G2E((scf_x64_OpCode_t*)inst->OpCode, dst->base, inst->src.base);
+ if (!tmp)
+ return -ENOMEM;
+
+ memcpy(inst->code, tmp->code, tmp->len);
+ inst->len = tmp->len;
+
+ inst->dst.base = dst->base;
+ inst->dst.index = NULL;
+ inst->dst.scale = 0;
+ inst->dst.disp = 0;
+ inst->dst.mem_flag = 0;
+
+ free(tmp);
+ return 0;
+}
+
+static int __x64_peep_mov_to_mem(scf_instruction_t* mov, scf_inst_data_t* src)
+{
+ scf_instruction_t* inst;
+
+ if (!mov->dst.index)
+ inst = x64_make_inst_G2P((scf_x64_OpCode_t*)mov->OpCode,
+ mov->dst.base, mov->dst.disp,
+ src->base);
+ else
+ inst = x64_make_inst_G2SIB((scf_x64_OpCode_t*)mov->OpCode,
+ mov->dst.base,
+ mov->dst.index, mov->dst.scale, mov->dst.disp,
+ src->base);
+ if (!inst)
+ return -ENOMEM;
+
+ memcpy(mov->code, inst->code, inst->len);
+ mov->len = inst->len;
+
+ mov->src.base = src->base;
+ mov->src.index = NULL;
+ mov->src.scale = 0;
+ mov->src.disp = 0;
+ mov->src.mem_flag = 0;
+
+ free(inst);
+ return 0;
+}
+
static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, scf_instruction_t* inst)
{
scf_3ac_code_t* c = inst->c;
int j;
for (j = peep_insts->size - 1; j >= 0; j--) {
std = peep_insts->data[j];
-#if 0
- scf_loge("std j: %d\n", j);
- scf_3ac_code_print(std->c, NULL);
- scf_instruction_print(std);
-
- scf_loge("inst: \n");
- scf_instruction_print(inst);
- printf("\n");
-#endif
+
if (SCF_X64_LEA == std->OpCode->type) {
if (scf_inst_data_same(&std->dst, &inst->src)
&& x64_inst_data_is_reg(&inst->dst)
&& x64_inst_data_is_local(&std->src)) {
- if (std->src.index)
- inst2 = x64_make_inst_SIB2G((scf_x64_OpCode_t*)std->OpCode,
- inst->dst.base,
- std->src.base, std->src.index, std->src.scale, std->src.disp);
- else
- inst2 = x64_make_inst_P2G((scf_x64_OpCode_t*)std->OpCode, inst->dst.base, std->src.base, std->src.disp);
-
- if (!inst2)
- return -ENOMEM;
-
- memcpy(inst->code, inst2->code, inst2->len);
- inst->len = inst2->len;
-
- inst->OpCode = std->OpCode;
- inst->src.base = std->src.base;
- inst->src.index = std->src.index;
- inst->src.scale = std->src.scale;
- inst->src.disp = std->src.disp;
- inst->src.flag = std->src.flag;
-
- free(inst2);
- inst2 = NULL;
+ __x64_peep_mov_by_lea(inst, std);
}
break;
}
} else if (scf_inst_data_same(&std->src, &inst->src)) {
- if (std->src.flag && std->dst.base->bytes == inst->dst.base->bytes) {
-
- inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->dst.base);
- if (!inst2)
- return -ENOMEM;
-
- memcpy(inst->code, inst2->code, inst2->len);
- inst->len = inst2->len;
+ if (std->src.mem_flag && std->dst.base->bytes == inst->dst.base->bytes) {
- inst->src.base = std->dst.base;
- inst->src.index = NULL;
- inst->src.scale = 0;
- inst->src.disp = 0;
- inst->src.flag = 0;
-
- free(inst2);
- inst2 = NULL;
+ __x64_peep_src_was_mem(inst, &std->dst);
}
continue;
return X64_PEEPHOLE_DEL;
}
- if (inst->src.flag) {
- assert(std->dst.flag);
-
- if (std->src.base)
- inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->src.base);
- else {
- OpCode = x64_find_OpCode(inst->OpCode->type, inst->dst.base->bytes, inst->dst.base->bytes, SCF_X64_I2G);
-
- if (std->src.imm_size < inst->dst.base->bytes)
- std->src.imm = scf_zero_extend(std->src.imm, std->src.imm_size);
-
- inst2 = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&std->src.imm, inst->dst.base->bytes);
- }
- if (!inst2)
- return -ENOMEM;
+ if (inst->src.mem_flag) {
+ assert(std->dst.mem_flag);
- memcpy(inst->code, inst2->code, inst2->len);
- inst->len = inst2->len;
-
- inst->src.base = std->src.base;
- inst->src.index = NULL;
- inst->src.scale = 0;
- inst->src.disp = 0;
- inst->src.flag = 0;
-
- free(inst2);
- inst2 = NULL;
+ __x64_peep_src_was_mem(inst, &std->src);
continue;
- } else if (inst->dst.flag) {
-
+ } else if (inst->dst.mem_flag) {
if (x64_inst_data_is_reg(&inst->src)
&& x64_inst_data_is_reg(&std->src)
&& inst->src.base != std->src.base) {
- if (!inst->dst.index)
- inst2 = x64_make_inst_G2P((scf_x64_OpCode_t*)inst->OpCode,
- inst->dst.base, inst->dst.disp,
- std->src.base);
- else
- inst2 = x64_make_inst_G2SIB((scf_x64_OpCode_t*)inst->OpCode,
- inst->dst.base,
- inst->dst.index, inst->dst.scale, inst->dst.disp,
- std->src.base);
- if (!inst2)
- return -ENOMEM;
-
- memcpy(inst->code, inst2->code, inst2->len);
- inst->len = inst2->len;
-
- inst->src.base = std->src.base;
- inst->src.index = NULL;
- inst->src.scale = 0;
- inst->src.disp = 0;
- inst->src.flag = 0;
-
- free(inst2);
- inst2 = NULL;
+ __x64_peep_mov_to_mem(inst, &std->src);
continue;
}
}
for (j = peep_insts->size - 1; j >= 0; j--) {
std = peep_insts->data[j];
- if ((std->src.flag && (std->src.base == r1 || std->src.index == r1))
- || (std->dst.flag && (std->dst.base == r1 || std->dst.index == r1)))
+ if ((std->src.mem_flag && (std->src.base == r1 || std->src.index == r1))
+ || (std->dst.mem_flag && (std->dst.base == r1 || std->dst.index == r1)))
assert(0 == scf_vector_del(peep_insts, std));
}
}
{
scf_3ac_code_t* c = inst->c;
scf_basic_block_t* bb = c->basic_block;
- scf_instruction_t* inst2;
scf_instruction_t* std;
-
+ scf_inst_data_t* id;
int j;
+
for (j = peep_insts->size - 1; j >= 0; j--) {
std = peep_insts->data[j];
if (SCF_X64_LEA == std->OpCode->type)
break;
- if (inst->src.flag) {
+ int ret = 0;
+ if (inst->src.mem_flag) {
if (scf_inst_data_same(&inst->src, &std->src))
- inst->src.base = std->dst.base;
+ id = &std->dst;
else if (scf_inst_data_same(&inst->src, &std->dst))
- inst->src.base = std->src.base;
+ id = &std->src;
else
goto check;
- inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*) inst->OpCode, inst->dst.base, inst->src.base);
- if (!inst2)
- return -ENOMEM;
-
- inst->src.index = NULL;
- inst->src.scale = 0;
- inst->src.disp = 0;
- inst->src.flag = 0;
+ ret = __x64_peep_src_was_mem(inst, id);
- } else if (inst->dst.flag) {
+ } else if (inst->dst.mem_flag) {
if (scf_inst_data_same(&inst->dst, &std->src))
- inst->dst.base = std->dst.base;
+ id = &std->dst;
else if (scf_inst_data_same(&inst->dst, &std->dst))
- inst->dst.base = std->src.base;
+ id = &std->src;
else
goto check;
- if (inst->src.imm_size > 0)
- inst2 = x64_make_inst_I2E((scf_x64_OpCode_t*)inst->OpCode,
- inst->dst.base,
- (uint8_t*)&inst->src.imm, inst->src.imm_size);
- else
- inst2 = x64_make_inst_G2E((scf_x64_OpCode_t*)inst->OpCode,
- inst->dst.base,
- inst->src.base);
- if (!inst2)
- return -ENOMEM;
-
- inst->dst.index = NULL;
- inst->dst.scale = 0;
- inst->dst.disp = 0;
- inst->dst.flag = 0;
- } else
- goto check;
-
- memcpy(inst->code, inst2->code, inst2->len);
- inst->len = inst2->len;
+ ret = __x64_peep_dst_was_mem(inst, id);
+ }
- free(inst2);
- inst2 = NULL;
+ if (ret < 0)
+ return ret;
check:
if (x64_inst_data_is_reg(&std->dst)) {
continue;
assert(0 == scf_vector_del(c->instructions, inst));
- assert(0 == scf_vector_del(save_insts, inst));
+ assert(0 == scf_vector_del(save_insts, inst));
free(inst);
inst = NULL;
inst = x64_make_inst_G2P(movsd, rsp, size + stack_size, r2);
else {
inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&imm, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(movsd, rsp, 0, r2);
}
else
inst = x64_make_inst_G(push, r2);
}
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
saved_regs[n++] = r2;
size += 8;
inst = x64_make_inst_G2P(movsd, rsp, size + stack_size, r2);
else {
inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&imm, 4);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2P(movsd, rsp, 0, r2);
}
else
inst = x64_make_inst_G(push, r2);
}
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
saved_regs[n++] = r2;
size += 8;
return size;
}
-int x64_pop_regs(scf_vector_t* instructions, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated)
+int x64_pop_regs(scf_3ac_code_t* c, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated)
{
scf_register_t* rsp = x64_find_register("rsp");
scf_register_t* r;
if (i == nb_updated) {
if (X64_COLOR_TYPE(r2->color)) {
inst = x64_make_inst_P2G(movsd, r2, rsp, 0);
- X64_INST_ADD_CHECK(instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&imm, 4);
} else
inst = x64_make_inst_G(pop, r2);
- X64_INST_ADD_CHECK(instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&imm, 4);
- X64_INST_ADD_CHECK(instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
}
return 0;
}
inst = x64_make_inst_G2M(&rela, mov, v, NULL, r);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
end:
lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, lea, r, NULL, v);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
} else if (v->nb_dimentions > 0) {
lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, lea, r, NULL, v);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL);
} else if (SCF_FUNCTION_PTR == v->type) {
lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G);
inst = x64_make_inst_M2G(&rela, lea, r, NULL, v);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, v->func_ptr);
} else {
xor = x64_find_OpCode(SCF_X64_XOR, size, size, SCF_X64_G2E);
inst = x64_make_inst_G2E(xor, r, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
} else {
mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G);
inst = x64_make_inst_I2G(mov, r, (uint8_t*)&v->data, size);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
return 0;
}
inst = x64_make_inst_M2G(&rela, mov, r, NULL, dn->var);
- X64_INST_ADD_CHECK(c->instructions, inst, rela);
+ X64_INST_ADD_CHECK(c, inst, rela);
X64_RELA_ADD_CHECK(f->data_relas, rela, c, dn->var, NULL);
dn->loaded = 1;
if (scf_variable_signed(index->var)) {
mov = x64_find_OpCode(SCF_X64_MOVSX, ri->bytes, ri2->bytes, SCF_X64_E2G);
inst = x64_make_inst_E2G(mov, ri2, ri);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else if (ri->bytes <= 2) {
mov = x64_find_OpCode(SCF_X64_MOVZX, ri->bytes, ri2->bytes, SCF_X64_E2G);
inst = x64_make_inst_E2G(mov, ri2, ri);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
} else {
assert(4 == ri->bytes);
/*
xor = x64_find_OpCode(SCF_X64_XOR, 8, 8, SCF_X64_G2E);
inst = x64_make_inst_G2E(xor, ri2, ri2);
- X64_INST_ADD_CHECK(c->instructions, inst);
+ X64_INST_ADD_CHECK(c, inst);
mov = x64_find_OpCode(SCF_X64_MOV, 4, 4, SCF_X64_E2G);
*/
}
mov = x64_find_OpCode(SCF_X64_MOV, 8, 8, SCF_X64_G2E);
inst = x64_make_inst_G2E(mov, rs, ri2);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
shl = x64_find_OpCode(SCF_X64_SHL, 1, 8, SCF_X64_I2E);
add = x64_find_OpCode(SCF_X64_ADD, 8, 8, SCF_X64_G2E);
count -= i;
inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&count, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
inst = x64_make_inst_G2E(add, rs, ri2);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
count = i;
}
if (count > 0) {
inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&count, 1);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
}
ri = rs;
if (j < N) {
inst = x64_make_inst_G(push, r);
- X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(f->init_code, inst, NULL);
f->init_code_bytes += inst->len;
}
if (j < N) {
inst = x64_make_inst_G(pop, r);
- X64_INST_ADD_CHECK(c->instructions, inst, NULL);
+ X64_INST_ADD_CHECK(c, inst, NULL);
bb->code_bytes += inst->len;
f->callee_saved_size += 8;
int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_function_t* f);
-int x64_push_regs(scf_vector_t* instructions, uint32_t* regs, int nb_regs);
-int x64_pop_regs (scf_vector_t* instructions, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated);
+int x64_pop_regs(scf_3ac_code_t* c, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated);
int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int stack_size, scf_register_t** saved_regs, scf_register_t** drop_regs, int* n_drops);
scf_register_t* rsp = x64_find_register("rsp");
scf_register_t* rbp = x64_find_register("rbp");
- if (!id->flag && id->base && id->base != rsp && id->base != rbp && 0 == id->imm_size)
+ if (!id->mem_flag && id->base && id->base != rsp && id->base != rbp && 0 == id->imm_size)
return 1;
return 0;
}
scf_register_t* rbp = x64_find_register("rbp");
scf_register_t* rsp = x64_find_register("rsp");
- if (id->flag && (id->base == rbp || id->base == rsp))
+ if (id->mem_flag && (id->base == rbp || id->base == rsp))
return 1;
return 0;
}
static inline int x64_inst_data_is_global(scf_inst_data_t* id)
{
- if (id->flag && !id->base)
+ if (id->mem_flag && !id->base)
return 1;
return 0;
}
static inline int x64_inst_data_is_const(scf_inst_data_t* id)
{
- if (!id->flag && id->imm_size > 0)
+ if (!id->mem_flag && id->imm_size > 0)
return 1;
return 0;
}
scf_register_t* rbp = x64_find_register("rbp");
scf_register_t* rsp = x64_find_register("rsp");
- if (id->flag && id->base && id->base != rbp && id->base != rsp)
+ if (id->mem_flag && id->base && id->base != rbp && id->base != rsp)
return 1;
return 0;
}