dst2->dag_node = dst->dag_node;
dst2->code = dst->code;
dst2->bb = dst->bb;
- dst2->debug_w = dst->debug_w;
}
}
src2->dag_node = src->dag_node;
src2->code = src->code;
src2->bb = src->bb;
- src2->debug_w = src->debug_w;
}
}
node = node->nodes[0];
operand->node = node;
- if (node)
- operand->debug_w = node->debug_w;
- else
- operand->debug_w = NULL;
scf_vector_add(vsrc, operand);
}
node = node->nodes[0];
operand->node = node;
- if (node)
- operand->debug_w = node->debug_w;
- else
- operand->debug_w = NULL;
scf_vector_add(vdst, operand);
}
scf_3ac_code_t* code; // for branch jump
scf_basic_block_t* bb; // dst basic block of jmp
- scf_lex_word_t* debug_w;
void* rabi;
};
return 0;
}
-static int _scf_3ac_call_extern(scf_list_t* h, const char* fname, scf_node_t* d, scf_node_t** nodes, int nb_nodes)
-{
- scf_loge("\n");
- return -1;
-}
-
static int _scf_3ac_code_NN(scf_list_t* h, int op_type, scf_node_t** dsts, int nb_dsts, scf_node_t** srcs, int nb_srcs)
{
- scf_3ac_operator_t* _3ac_op = scf_3ac_find_operator(op_type);
- if (!_3ac_op) {
+ scf_3ac_code_t* c = scf_3ac_code_NN(op_type, dsts, nb_dsts, srcs, nb_srcs);
+ if (!c) {
scf_loge("\n");
return -1;
}
- scf_3ac_operand_t* operand;
- scf_3ac_code_t* c;
- scf_vector_t* vsrc = NULL;
- scf_vector_t* vdst = NULL;
- scf_node_t* node;
-
- int i;
-
- if (srcs) {
- vsrc = scf_vector_alloc();
- for (i = 0; i < nb_srcs; i++) {
-
- operand = scf_3ac_operand_alloc();
-
- node = srcs[i];
-
- while (node && SCF_OP_EXPR == node->type)
- node = node->nodes[0];
-
- operand->node = node;
- if (node)
- operand->debug_w = node->debug_w;
- else
- operand->debug_w = NULL;
-
- scf_vector_add(vsrc, operand);
- }
- }
-
- if (dsts) {
- vdst = scf_vector_alloc();
- for (i = 0; i < nb_dsts; i++) {
-
- operand = scf_3ac_operand_alloc();
-
- node = dsts[i];
-
- while (node && SCF_OP_EXPR == node->type)
- node = node->nodes[0];
-
- operand->node = node;
- if (node)
- operand->debug_w = node->debug_w;
- else
- operand->debug_w = NULL;
-
- scf_vector_add(vdst, operand);
- }
- }
-
- c = scf_3ac_code_alloc();
- c->op = _3ac_op;
- c->dsts = vdst;
- c->srcs = vsrc;
scf_list_add_tail(h, &c->list);
return 0;
}
scf_vector_add(argv, e->nodes[0]);
}
- ret = _scf_3ac_call_extern(d->_3ac_list_head, "printf", parent, (scf_node_t**)argv->data, argv->size);
+ //ret = _scf_3ac_call_extern(d->_3ac_list_head, "printf", parent, (scf_node_t**)argv->data, argv->size);
scf_vector_free(argv);
argv = NULL;
SCF_CHECK_ERROR(ret < 0, ret, "expr calculate failed\n");
scf_vector_add(argv, f);
scf_vector_add(argv, e->nodes[0]);
- ret = _scf_3ac_call_extern(d->_3ac_list_head, "scf_delete", NULL, (scf_node_t**)argv->data, argv->size);
+// ret = _scf_3ac_call_extern(d->_3ac_list_head, "scf_delete", NULL, (scf_node_t**)argv->data, argv->size);
scf_vector_free(argv);
argv = NULL;
SCF_CHECK_ERROR(ret < 0, ret, "call scf_delete failed\n");
}
}
- for (l = scf_list_head(&h); l != scf_list_sentinel(&h); l = scf_list_next(l)) {
-
- c = scf_list_data(l, scf_3ac_code_t, list);
-
- for (l2 = scf_list_head(&bb->code_list_head); l2 != scf_list_sentinel(&bb->code_list_head); l2 = scf_list_next(l2)) {
-
- c2 = scf_list_data(l2, scf_3ac_code_t, list);
-
- if (scf_3ac_code_same(c, c2)) {
-
- if (c->dsts) {
- dst = c ->dsts->data[0];
- dst2 = c2->dsts->data[0];
-
- dst->debug_w = dst2->debug_w;
- }
-
- if (c->srcs) {
- for (i = 0; i < c ->srcs->size; i++) {
- src = c ->srcs->data[i];
- src2 = c2->srcs->data[i];
-
- src->debug_w = src2->debug_w;
- }
- }
- break;
- }
- }
-// assert(l2 != scf_list_sentinel(&bb->code_list_head));
- }
-
scf_list_clear(&bb->code_list_head, scf_3ac_code_t, list, scf_3ac_code_free);
for (l = scf_list_head(&h); l != scf_list_sentinel(&h); ) {
--- /dev/null
+int printf(const char* fmt, ...);
+
+int main()
+{
+ int a[] = {1, 2, 3, 4, 5};
+
+ int i;
+ for (i = 0; i < 5; i++)
+ printf("%d\n", a[i]);
+
+ return 0;
+}
return 0;
}
- if (disp < 127 && disp > -128) {
+ if (disp <= 127 && disp >= -128) {
scf_ModRM_setMod(&ModRM, SCF_X64_MOD_BASE_DISP8);
inst->code[inst->len++] = ModRM;
} else {
inst->code[inst->len++] = SIB;
}
- if (disp < 127 && disp > -128) {
+ if (disp <= 127 && disp >= -128) {
inst->code[inst->len++] = (int8_t)disp;
} else {
uint8_t* p = (uint8_t*)&disp;
if (SCF_X64_RM_EBP != r_base->id && SCF_X64_RM_ESP != r_base->id && 0 == disp)
scf_ModRM_setMod(&ModRM, SCF_X64_MOD_BASE);
else {
- if (disp < 127 && disp > -128)
+ if (disp <= 127 && disp >= -128)
scf_ModRM_setMod(&ModRM, SCF_X64_MOD_BASE_DISP8);
else
scf_ModRM_setMod(&ModRM, SCF_X64_MOD_BASE_DISP32);
if (scf_inst_data_same(&inst->dst, &inst2->dst))
break;
- } else if (SCF_X64_LEA == inst2->OpCode->type) {
+ } else if (SCF_X64_LEA == inst2->OpCode->type
+ || SCF_X64_MOV == inst2->OpCode->type) {
if (inst2->src.base == inst->dst.base)
break;
}
if (!scf_variable_same_type(v0, v1)) {
- if (scf_variable_is_struct_pointer(v0)) {
+ if (scf_variable_is_struct_pointer(v0) && v1->w && strcmp(v1->w->text->data, "NULL")) {
scf_type_t* t = NULL;
int ret = scf_ast_find_type_type(&t, ast, v0->type);
if (!dst->dag_node || !dst->dag_node->node)
continue;
- if (dst->debug_w && line2 < dst->debug_w->line)
- line2 = dst->debug_w->line;
-
node = dst->dag_node->node;
if (node->debug_w) {
+ if (line2 < node->debug_w->line)
+ line2 = node->debug_w->line;
+
if (scf_type_is_var(node->type) && node->var->local_flag) {
ret = _debug_add_var(parse, node);
node = src->dag_node->node;
- if (src->debug_w && line2 < src->debug_w->line)
- line2 = src->debug_w->line;
-
if (node->debug_w) {
+ if (line2 < node->debug_w->line)
+ line2 = node->debug_w->line;
+
if (scf_type_is_var(node->type) && node->var->local_flag) {
ret = _debug_add_var(parse, node);