int scf_basic_block_inited_vars(scf_basic_block_t* bb, scf_list_t* bb_list_head)
{
+ scf_3ac_operand_t* src;
scf_3ac_operand_t* dst;
- scf_3ac_code_t* c;
+ scf_dn_status_t* ds;
scf_dag_node_t* dn;
+ scf_dn_index_t* di;
+ scf_dn_index_t* di2;
+ scf_3ac_code_t* c;
scf_list_t* l;
int ret = 0;
scf_3ac_code_print(c, NULL);
return ret;
}
+
+ } else if (SCF_OP_3AC_INC == c->op->type
+ || SCF_OP_3AC_DEC == c->op->type) {
+
+ src = c->srcs->data[0];
+ dn = src->dag_node;
+
+ if (scf_type_is_var(dn->type)
+ && (dn->var->global_flag || dn->var->local_flag || dn->var->tmp_flag)
+ && dn->var->nb_pointers > 0) {
+
+ scf_variable_t* v = dn->var;
+ scf_logd("++/-- v_%d_%d/%s\n", v->w->line, v->w->pos, v->w->text->data);
+
+ ret = _bb_init_var(dn, c, bb, bb_list_head);
+ if (ret < 0) {
+ scf_loge("\n");
+ return ret;
+ }
+
+ SCF_DN_STATUS_GET(ds, c->dn_status_initeds, dn);
+// scf_dn_status_print(ds);
+
+ if (!ds->alias_indexes) {
+ if (!v->arg_flag && !v->global_flag)
+ scf_logw("++/-- update pointers NOT to an array, v->arg_flag: %d, file: %s, line: %d\n", v->arg_flag, v->w->file->data, v->w->line);
+ continue;
+ }
+
+ assert(ds->alias_indexes->size > 0);
+ di = ds->alias_indexes->data[ds->alias_indexes->size - 1];
+
+ if (di->refs > 1) {
+ di2 = scf_dn_index_clone(di);
+ if (!di2)
+ return -ENOMEM;
+
+ ds->alias_indexes->data[ds->alias_indexes->size - 1] = di2;
+ scf_dn_index_free(di);
+ di = di2;
+ }
+
+ if (di->index >= 0) {
+ if (SCF_OP_3AC_INC == c->op->type)
+ di->index++;
+
+ else if (SCF_OP_3AC_DEC == c->op->type)
+ di->index--;
+ }
+ }
}
}
typedef struct scf_efunction_s ScfEfunction;
typedef struct scf_eboard_s ScfEboard;
-enum scf_core_types {
+enum scf_core_types
+{
SCF_OP_ADD = 0, // +
SCF_OP_SUB, // -
SCF_OP_MUL, // *
SCF_OP_CONTINUE, // continue statement
SCF_OP_ASYNC, // async statement
+ SCF_LABEL, // label
+ SCF_OP_GOTO, // goto statement
+
SCF_N_OPS, // total operators
// 58
SCF_OP_3AC_NOP,
SCF_OP_3AC_END,
- SCF_OP_GOTO, // goto statement
SCF_N_3AC_OPS, // totaol 3ac operators
SCF_VAR_CHAR, // char variable
SCF_VAR_DOUBLE, // double variable
- SCF_LABEL, // label
-
SCF_FUNCTION, // function
SCF_STRUCT, // struct type defined by user
static int scf_type_is_operator(int type)
{
- return type >= SCF_OP_ADD && type <= SCF_OP_GOTO;
+ return type >= SCF_OP_ADD && type < SCF_N_3AC_OPS;
}
static int scf_type_is_cmp_operator(int type)
return di;
}
-scf_dn_index_t* scf_dn_index_clone(scf_dn_index_t* di)
+scf_dn_index_t* scf_dn_index_ref(scf_dn_index_t* di)
{
if (di)
di->refs++;
-
return di;
}
+scf_dn_index_t* scf_dn_index_clone(scf_dn_index_t* di)
+{
+ if (!di)
+ return NULL;
+
+ scf_dn_index_t* di2 = scf_dn_index_alloc();
+ if (!di2)
+ return NULL;
+
+ di2->member = di->member;
+ di2->index = di->index;
+ di2->dn = di->dn;
+ di2->dn_scale = di->dn_scale;
+
+ return di2;
+}
+
void scf_dn_index_free(scf_dn_index_t* di)
{
if (di && 0 == --di->refs)
scf_dn_index_t* scf_dn_index_alloc();
scf_dn_index_t* scf_dn_index_clone(scf_dn_index_t* di);
+scf_dn_index_t* scf_dn_index_ref (scf_dn_index_t* di);
void scf_dn_index_free (scf_dn_index_t* di);
int scf_dn_index_same(const scf_dn_index_t* di0, const scf_dn_index_t* di1);
} while (0)
#endif
-
#include"scf_ast.h"
-typedef struct scf_operator_handler_s scf_operator_handler_t;
-
typedef int (*scf_operator_handler_pt)(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data);
-struct scf_operator_handler_s
-{
- int type;
- scf_operator_handler_pt func;
-};
-
-scf_operator_handler_t* scf_find_3ac_operator_handler(const int type);
+scf_operator_handler_pt scf_find_3ac_operator_handler(const int type);
int scf_function_to_3ac(scf_ast_t* ast, scf_function_t* f, scf_list_t* _3ac_list_head);
return 0;
scf_handler_data_t* d = data;
- scf_operator_handler_t* h;
+ scf_operator_handler_pt h;
int i;
return -1;
}
- return h->func(ast, node->nodes, node->nb_nodes, d);
+ return h(ast, node->nodes, node->nb_nodes, d);
} else {
if (!scf_type_is_assign(node->op->type) && SCF_OP_ADDRESS_OF != node->op->type) {
return -1;
}
- return h->func(ast, node->nodes, node->nb_nodes, d);
+ return h(ast, node->nodes, node->nb_nodes, d);
}
scf_loge("\n");
if (0 == nb_nodes)
return 0;
- scf_operator_handler_t* h;
+ scf_operator_handler_pt h;
scf_operator_t* op;
scf_handler_data_t* d = data;
scf_block_t* b = (scf_block_t*)(nodes[0]->parent);
return -1;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
ast->current_block = up;
return -1;
}
}
- scf_operator_handler_t* h = scf_find_3ac_operator_handler(op->type);
+ scf_operator_handler_pt h = scf_find_3ac_operator_handler(op->type);
if (!h) {
scf_loge("\n");
return -1;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
return -1;
}
SCF_OP_LOGIC(and)
SCF_OP_LOGIC(or)
-scf_operator_handler_t _3ac_operator_handlers[] = {
- {SCF_OP_EXPR, _scf_op_expr},
- {SCF_OP_CALL, _scf_op_call},
- {SCF_OP_CREATE, _scf_op_create},
-
- {SCF_OP_ARRAY_INDEX, _scf_op_array_index},
- {SCF_OP_POINTER, _scf_op_pointer},
-
- {SCF_OP_VA_START, _scf_op_va_start},
- {SCF_OP_VA_ARG, _scf_op_va_arg},
- {SCF_OP_VA_END, _scf_op_va_end},
-
- {SCF_OP_TYPE_CAST, _scf_op_type_cast},
- {SCF_OP_LOGIC_NOT, _scf_op_logic_not},
- {SCF_OP_BIT_NOT, _scf_op_bit_not},
- {SCF_OP_NEG, _scf_op_neg},
- {SCF_OP_POSITIVE, _scf_op_positive},
-
- {SCF_OP_INC, _scf_op_inc},
- {SCF_OP_DEC, _scf_op_dec},
-
- {SCF_OP_INC_POST, _scf_op_inc_post},
- {SCF_OP_DEC_POST, _scf_op_dec_post},
-
- {SCF_OP_DEREFERENCE, _scf_op_dereference},
- {SCF_OP_ADDRESS_OF, _scf_op_address_of},
-
- {SCF_OP_MUL, _scf_op_mul},
- {SCF_OP_DIV, _scf_op_div},
- {SCF_OP_MOD, _scf_op_mod},
-
- {SCF_OP_ADD, _scf_op_add},
- {SCF_OP_SUB, _scf_op_sub},
-
- {SCF_OP_SHL, _scf_op_shl},
- {SCF_OP_SHR, _scf_op_shr},
-
- {SCF_OP_BIT_AND, _scf_op_bit_and},
- {SCF_OP_BIT_OR, _scf_op_bit_or},
-
- {SCF_OP_EQ, _scf_op_eq},
- {SCF_OP_NE, _scf_op_ne},
- {SCF_OP_GT, _scf_op_gt},
- {SCF_OP_LT, _scf_op_lt},
- {SCF_OP_GE, _scf_op_ge},
- {SCF_OP_LE, _scf_op_le},
-
- {SCF_OP_LOGIC_AND, _scf_op_logic_and},
- {SCF_OP_LOGIC_OR, _scf_op_logic_or},
-
- {SCF_OP_ASSIGN, _scf_op_assign},
- {SCF_OP_ADD_ASSIGN, _scf_op_add_assign},
- {SCF_OP_SUB_ASSIGN, _scf_op_sub_assign},
- {SCF_OP_MUL_ASSIGN, _scf_op_mul_assign},
- {SCF_OP_DIV_ASSIGN, _scf_op_div_assign},
- {SCF_OP_MOD_ASSIGN, _scf_op_mod_assign},
- {SCF_OP_SHL_ASSIGN, _scf_op_shl_assign},
- {SCF_OP_SHR_ASSIGN, _scf_op_shr_assign},
- {SCF_OP_AND_ASSIGN, _scf_op_and_assign},
- {SCF_OP_OR_ASSIGN, _scf_op_or_assign},
-
-
- {SCF_OP_BLOCK, _scf_op_block},
- {SCF_OP_RETURN, _scf_op_return},
- {SCF_OP_BREAK, _scf_op_break},
- {SCF_OP_CONTINUE, _scf_op_continue},
- {SCF_OP_GOTO, _scf_op_goto},
- {SCF_LABEL, _scf_op_label},
-
- {SCF_OP_IF, _scf_op_if},
- {SCF_OP_WHILE, _scf_op_while},
- {SCF_OP_DO, _scf_op_do},
- {SCF_OP_FOR, _scf_op_for},
-
- {SCF_OP_SWITCH, _scf_op_switch},
- {SCF_OP_CASE, _scf_op_case},
- {SCF_OP_DEFAULT, _scf_op_default},
+scf_operator_handler_pt __operator_handlers[SCF_N_3AC_OPS] =
+{
+ [SCF_OP_EXPR ] = _scf_op_expr,
+ [SCF_OP_CALL ] = _scf_op_call,
+ [SCF_OP_CREATE] = _scf_op_create,
+
+ [SCF_OP_ARRAY_INDEX] = _scf_op_array_index,
+ [SCF_OP_POINTER ] = _scf_op_pointer,
+
+ [SCF_OP_VA_START] = _scf_op_va_start,
+ [SCF_OP_VA_ARG ] = _scf_op_va_arg,
+ [SCF_OP_VA_END ] = _scf_op_va_end,
+
+ [SCF_OP_TYPE_CAST] = _scf_op_type_cast,
+ [SCF_OP_LOGIC_NOT] = _scf_op_logic_not,
+ [SCF_OP_BIT_NOT ] = _scf_op_bit_not,
+ [SCF_OP_NEG ] = _scf_op_neg,
+ [SCF_OP_POSITIVE ] = _scf_op_positive,
+
+ [SCF_OP_INC] = _scf_op_inc,
+ [SCF_OP_DEC] = _scf_op_dec,
+
+ [SCF_OP_INC_POST] = _scf_op_inc_post,
+ [SCF_OP_DEC_POST] = _scf_op_dec_post,
+
+ [SCF_OP_DEREFERENCE] = _scf_op_dereference,
+ [SCF_OP_ADDRESS_OF ] = _scf_op_address_of,
+
+ [SCF_OP_MUL] = _scf_op_mul,
+ [SCF_OP_DIV] = _scf_op_div,
+ [SCF_OP_MOD] = _scf_op_mod,
+
+ [SCF_OP_ADD] = _scf_op_add,
+ [SCF_OP_SUB] = _scf_op_sub,
+
+ [SCF_OP_SHL] = _scf_op_shl,
+ [SCF_OP_SHR] = _scf_op_shr,
+
+ [SCF_OP_BIT_AND] = _scf_op_bit_and,
+ [SCF_OP_BIT_OR ] = _scf_op_bit_or,
+
+ [SCF_OP_EQ] = _scf_op_eq,
+ [SCF_OP_NE] = _scf_op_ne,
+ [SCF_OP_GT] = _scf_op_gt,
+ [SCF_OP_LT] = _scf_op_lt,
+ [SCF_OP_GE] = _scf_op_ge,
+ [SCF_OP_LE] = _scf_op_le,
+
+ [SCF_OP_LOGIC_AND] = _scf_op_logic_and,
+ [SCF_OP_LOGIC_OR ] = _scf_op_logic_or,
+
+ [SCF_OP_ASSIGN ] = _scf_op_assign,
+ [SCF_OP_ADD_ASSIGN] = _scf_op_add_assign,
+ [SCF_OP_SUB_ASSIGN] = _scf_op_sub_assign,
+ [SCF_OP_MUL_ASSIGN] = _scf_op_mul_assign,
+ [SCF_OP_DIV_ASSIGN] = _scf_op_div_assign,
+ [SCF_OP_MOD_ASSIGN] = _scf_op_mod_assign,
+ [SCF_OP_SHL_ASSIGN] = _scf_op_shl_assign,
+ [SCF_OP_SHR_ASSIGN] = _scf_op_shr_assign,
+ [SCF_OP_AND_ASSIGN] = _scf_op_and_assign,
+ [SCF_OP_OR_ASSIGN ] = _scf_op_or_assign,
+
+
+ [SCF_OP_BLOCK ] = _scf_op_block,
+ [SCF_OP_RETURN ] = _scf_op_return,
+ [SCF_OP_BREAK ] = _scf_op_break,
+ [SCF_OP_CONTINUE] = _scf_op_continue,
+ [SCF_OP_GOTO ] = _scf_op_goto,
+ [SCF_LABEL ] = _scf_op_label,
+
+ [SCF_OP_IF ] = _scf_op_if,
+ [SCF_OP_WHILE] = _scf_op_while,
+ [SCF_OP_DO ] = _scf_op_do,
+ [SCF_OP_FOR ] = _scf_op_for,
+
+ [SCF_OP_SWITCH ] = _scf_op_switch,
+ [SCF_OP_CASE ] = _scf_op_case,
+ [SCF_OP_DEFAULT] = _scf_op_default,
};
-scf_operator_handler_t* scf_find_3ac_operator_handler(const int type)
+scf_operator_handler_pt scf_find_3ac_operator_handler(const int type)
{
- int i;
- for (i = 0; i < sizeof(_3ac_operator_handlers) / sizeof(_3ac_operator_handlers[0]); i++) {
-
- scf_operator_handler_t* h = &_3ac_operator_handlers[i];
-
- if (type == h->type)
- return h;
- }
+ if (type < 0 || type >= SCF_N_3AC_OPS)
+ return NULL;
- return NULL;
+ return __operator_handlers[type];
}
.flags = SCF_OPTIMIZER_LOCAL,
};
-
static int _risc_make_bb_rcg(scf_graph_t* g, scf_basic_block_t* bb, scf_native_t* ctx)
{
- scf_list_t* l;
- scf_3ac_code_t* c;
- risc_rcg_handler_t* h;
+ scf_list_t* l;
+ scf_3ac_code_t* c;
+ risc_rcg_handler_pt h;
for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) {
return -EINVAL;
}
- int ret = h->func(ctx, c, g);
+ int ret = h(ctx, c, g);
if (ret < 0)
return ret;
}
c = scf_list_data(l, scf_3ac_code_t, list);
- risc_inst_handler_t* h = scf_risc_find_inst_handler(c->op->type);
+ risc_inst_handler_pt h = scf_risc_find_inst_handler(c->op->type);
if (!h) {
scf_loge("3ac operator '%s' not supported\n", c->op->name);
return -EINVAL;
}
- int ret = h->func(ctx, c);
+ int ret = h(ctx, c);
if (ret < 0) {
scf_3ac_code_print(c, NULL);
scf_loge("3ac op '%s' make inst failed\n", c->op->name);
} risc_rcg_node_t;
-typedef struct {
- int type;
- int (*func)(scf_native_t* ctx, scf_3ac_code_t* c, scf_graph_t* g);
-} risc_rcg_handler_t;
-
-typedef struct {
- int type;
- int (*func)(scf_native_t* ctx, scf_3ac_code_t* c);
-} risc_inst_handler_t;
+typedef int (*risc_rcg_handler_pt )(scf_native_t* ctx, scf_3ac_code_t* c, scf_graph_t* g);
+typedef int (*risc_inst_handler_pt)(scf_native_t* ctx, scf_3ac_code_t* c);
-risc_rcg_handler_t* scf_risc_find_rcg_handler(const int op_type);
-risc_inst_handler_t* scf_risc_find_inst_handler(const int op_type);
+risc_rcg_handler_pt scf_risc_find_rcg_handler(const int op_type);
+risc_inst_handler_pt scf_risc_find_inst_handler(const int op_type);
int risc_rcg_find_node(scf_graph_node_t** pp, scf_graph_t* g, scf_dag_node_t* dn, scf_register_t* reg);
int _risc_rcg_make_node(scf_graph_node_t** pp, scf_graph_t* g, scf_dag_node_t* dn, scf_register_t* reg);
return 0;
}
-static risc_inst_handler_t risc_inst_handlers[] = {
-
- {SCF_OP_CALL, _risc_inst_call_handler},
- {SCF_OP_ARRAY_INDEX, _risc_inst_array_index_handler},
- {SCF_OP_POINTER, _risc_inst_pointer_handler},
+static risc_inst_handler_pt risc_inst_handlers[SCF_N_3AC_OPS] =
+{
+ [SCF_OP_CALL ] = _risc_inst_call_handler,
+ [SCF_OP_ARRAY_INDEX ] = _risc_inst_array_index_handler,
+ [SCF_OP_POINTER ] = _risc_inst_pointer_handler,
- {SCF_OP_TYPE_CAST, _risc_inst_cast_handler},
- {SCF_OP_LOGIC_NOT, _risc_inst_logic_not_handler},
- {SCF_OP_BIT_NOT, _risc_inst_bit_not_handler},
- {SCF_OP_NEG, _risc_inst_neg_handler},
+ [SCF_OP_TYPE_CAST ] = _risc_inst_cast_handler,
+ [SCF_OP_LOGIC_NOT ] = _risc_inst_logic_not_handler,
+ [SCF_OP_BIT_NOT ] = _risc_inst_bit_not_handler,
+ [SCF_OP_NEG ] = _risc_inst_neg_handler,
- {SCF_OP_VA_START, _risc_inst_va_start_handler},
- {SCF_OP_VA_ARG, _risc_inst_va_arg_handler},
- {SCF_OP_VA_END, _risc_inst_va_end_handler},
+ [SCF_OP_VA_START ] = _risc_inst_va_start_handler,
+ [SCF_OP_VA_ARG ] = _risc_inst_va_arg_handler,
+ [SCF_OP_VA_END ] = _risc_inst_va_end_handler,
- {SCF_OP_INC, _risc_inst_inc_handler},
- {SCF_OP_DEC, _risc_inst_dec_handler},
+ [SCF_OP_INC ] = _risc_inst_inc_handler,
+ [SCF_OP_DEC ] = _risc_inst_dec_handler,
- {SCF_OP_INC_POST, _risc_inst_inc_post_handler},
- {SCF_OP_DEC_POST, _risc_inst_dec_post_handler},
+ [SCF_OP_INC_POST ] = _risc_inst_inc_post_handler,
+ [SCF_OP_DEC_POST ] = _risc_inst_dec_post_handler,
- {SCF_OP_DEREFERENCE, _risc_inst_dereference_handler},
- {SCF_OP_ADDRESS_OF, _risc_inst_address_of_handler},
+ [SCF_OP_DEREFERENCE ] = _risc_inst_dereference_handler,
+ [SCF_OP_ADDRESS_OF ] = _risc_inst_address_of_handler,
- {SCF_OP_MUL, _risc_inst_mul_handler},
- {SCF_OP_DIV, _risc_inst_div_handler},
- {SCF_OP_MOD, _risc_inst_mod_handler},
+ [SCF_OP_MUL ] = _risc_inst_mul_handler,
+ [SCF_OP_DIV ] = _risc_inst_div_handler,
+ [SCF_OP_MOD ] = _risc_inst_mod_handler,
- {SCF_OP_ADD, _risc_inst_add_handler},
- {SCF_OP_SUB, _risc_inst_sub_handler},
+ [SCF_OP_ADD ] = _risc_inst_add_handler,
+ [SCF_OP_SUB ] = _risc_inst_sub_handler,
- {SCF_OP_SHL, _risc_inst_shl_handler},
- {SCF_OP_SHR, _risc_inst_shr_handler},
+ [SCF_OP_SHL ] = _risc_inst_shl_handler,
+ [SCF_OP_SHR ] = _risc_inst_shr_handler,
- {SCF_OP_BIT_AND, _risc_inst_bit_and_handler},
- {SCF_OP_BIT_OR, _risc_inst_bit_or_handler},
+ [SCF_OP_BIT_AND ] = _risc_inst_bit_and_handler,
+ [SCF_OP_BIT_OR ] = _risc_inst_bit_or_handler,
- {SCF_OP_3AC_TEQ, _risc_inst_teq_handler},
- {SCF_OP_3AC_CMP, _risc_inst_cmp_handler},
+ [SCF_OP_3AC_TEQ ] = _risc_inst_teq_handler,
+ [SCF_OP_3AC_CMP ] = _risc_inst_cmp_handler,
- {SCF_OP_3AC_SETZ, _risc_inst_setz_handler},
- {SCF_OP_3AC_SETNZ, _risc_inst_setnz_handler},
- {SCF_OP_3AC_SETGT, _risc_inst_setgt_handler},
- {SCF_OP_3AC_SETGE, _risc_inst_setge_handler},
- {SCF_OP_3AC_SETLT, _risc_inst_setlt_handler},
- {SCF_OP_3AC_SETLE, _risc_inst_setle_handler},
+ [SCF_OP_3AC_SETZ ] = _risc_inst_setz_handler,
+ [SCF_OP_3AC_SETNZ ] = _risc_inst_setnz_handler,
+ [SCF_OP_3AC_SETGT ] = _risc_inst_setgt_handler,
+ [SCF_OP_3AC_SETGE ] = _risc_inst_setge_handler,
+ [SCF_OP_3AC_SETLT ] = _risc_inst_setlt_handler,
+ [SCF_OP_3AC_SETLE ] = _risc_inst_setle_handler,
- {SCF_OP_EQ, _risc_inst_eq_handler},
- {SCF_OP_NE, _risc_inst_ne_handler},
- {SCF_OP_GT, _risc_inst_gt_handler},
- {SCF_OP_GE, _risc_inst_ge_handler},
- {SCF_OP_LT, _risc_inst_lt_handler},
- {SCF_OP_LE, _risc_inst_le_handler},
+ [SCF_OP_EQ ] = _risc_inst_eq_handler,
+ [SCF_OP_NE ] = _risc_inst_ne_handler,
+ [SCF_OP_GT ] = _risc_inst_gt_handler,
+ [SCF_OP_GE ] = _risc_inst_ge_handler,
+ [SCF_OP_LT ] = _risc_inst_lt_handler,
+ [SCF_OP_LE ] = _risc_inst_le_handler,
- {SCF_OP_ASSIGN, _risc_inst_assign_handler},
+ [SCF_OP_ASSIGN ] = _risc_inst_assign_handler,
- {SCF_OP_ADD_ASSIGN, _risc_inst_add_assign_handler},
- {SCF_OP_SUB_ASSIGN, _risc_inst_sub_assign_handler},
+ [SCF_OP_ADD_ASSIGN ] = _risc_inst_add_assign_handler,
+ [SCF_OP_SUB_ASSIGN ] = _risc_inst_sub_assign_handler,
- {SCF_OP_MUL_ASSIGN, _risc_inst_mul_assign_handler},
- {SCF_OP_DIV_ASSIGN, _risc_inst_div_assign_handler},
- {SCF_OP_MOD_ASSIGN, _risc_inst_mod_assign_handler},
+ [SCF_OP_MUL_ASSIGN ] = _risc_inst_mul_assign_handler,
+ [SCF_OP_DIV_ASSIGN ] = _risc_inst_div_assign_handler,
+ [SCF_OP_MOD_ASSIGN ] = _risc_inst_mod_assign_handler,
- {SCF_OP_SHL_ASSIGN, _risc_inst_shl_assign_handler},
- {SCF_OP_SHR_ASSIGN, _risc_inst_shr_assign_handler},
+ [SCF_OP_SHL_ASSIGN ] = _risc_inst_shl_assign_handler,
+ [SCF_OP_SHR_ASSIGN ] = _risc_inst_shr_assign_handler,
- {SCF_OP_AND_ASSIGN, _risc_inst_and_assign_handler},
- {SCF_OP_OR_ASSIGN, _risc_inst_or_assign_handler},
+ [SCF_OP_AND_ASSIGN ] = _risc_inst_and_assign_handler,
+ [SCF_OP_OR_ASSIGN ] = _risc_inst_or_assign_handler,
- {SCF_OP_RETURN, _risc_inst_return_handler},
- {SCF_OP_GOTO, _risc_inst_goto_handler},
+ [SCF_OP_RETURN ] = _risc_inst_return_handler,
+ [SCF_OP_GOTO ] = _risc_inst_goto_handler,
- {SCF_OP_3AC_JZ, _risc_inst_jz_handler},
- {SCF_OP_3AC_JNZ, _risc_inst_jnz_handler},
- {SCF_OP_3AC_JGT, _risc_inst_jgt_handler},
- {SCF_OP_3AC_JGE, _risc_inst_jge_handler},
- {SCF_OP_3AC_JLT, _risc_inst_jlt_handler},
- {SCF_OP_3AC_JLE, _risc_inst_jle_handler},
+ [SCF_OP_3AC_JZ ] = _risc_inst_jz_handler,
+ [SCF_OP_3AC_JNZ ] = _risc_inst_jnz_handler,
+ [SCF_OP_3AC_JGT ] = _risc_inst_jgt_handler,
+ [SCF_OP_3AC_JGE ] = _risc_inst_jge_handler,
+ [SCF_OP_3AC_JLT ] = _risc_inst_jlt_handler,
+ [SCF_OP_3AC_JLE ] = _risc_inst_jle_handler,
- {SCF_OP_3AC_JA, _risc_inst_ja_handler},
- {SCF_OP_3AC_JB, _risc_inst_jb_handler},
- {SCF_OP_3AC_JAE, _risc_inst_jae_handler},
- {SCF_OP_3AC_JBE, _risc_inst_jbe_handler},
+ [SCF_OP_3AC_JA ] = _risc_inst_ja_handler,
+ [SCF_OP_3AC_JB ] = _risc_inst_jb_handler,
+ [SCF_OP_3AC_JAE ] = _risc_inst_jae_handler,
+ [SCF_OP_3AC_JBE ] = _risc_inst_jbe_handler,
- {SCF_OP_3AC_NOP, _risc_inst_nop_handler},
- {SCF_OP_3AC_END, _risc_inst_end_handler},
+ [SCF_OP_3AC_NOP ] = _risc_inst_nop_handler,
+ [SCF_OP_3AC_END ] = _risc_inst_end_handler,
- {SCF_OP_3AC_SAVE, _risc_inst_save_handler},
- {SCF_OP_3AC_LOAD, _risc_inst_load_handler},
+ [SCF_OP_3AC_SAVE ] = _risc_inst_save_handler,
+ [SCF_OP_3AC_LOAD ] = _risc_inst_load_handler,
- {SCF_OP_3AC_RESAVE, _risc_inst_save_handler},
- {SCF_OP_3AC_RELOAD, _risc_inst_reload_handler},
+ [SCF_OP_3AC_RESAVE ] = _risc_inst_save_handler,
+ [SCF_OP_3AC_RELOAD ] = _risc_inst_reload_handler,
- {SCF_OP_3AC_INC, _risc_inst_inc_handler},
- {SCF_OP_3AC_DEC, _risc_inst_dec_handler},
+ [SCF_OP_3AC_INC ] = _risc_inst_inc_handler,
+ [SCF_OP_3AC_DEC ] = _risc_inst_dec_handler,
- {SCF_OP_3AC_PUSH_RAX, _risc_inst_push_rax_handler},
- {SCF_OP_3AC_POP_RAX, _risc_inst_pop_rax_handler},
+ [SCF_OP_3AC_PUSH_RAX] = _risc_inst_push_rax_handler,
+ [SCF_OP_3AC_POP_RAX ] = _risc_inst_pop_rax_handler,
- {SCF_OP_3AC_MEMSET, _risc_inst_memset_handler},
+ [SCF_OP_3AC_MEMSET ] = _risc_inst_memset_handler,
- {SCF_OP_3AC_ASSIGN_DEREFERENCE, _risc_inst_assign_dereference_handler},
- {SCF_OP_3AC_ASSIGN_ARRAY_INDEX, _risc_inst_assign_array_index_handler},
- {SCF_OP_3AC_ASSIGN_POINTER, _risc_inst_assign_pointer_handler},
+ [SCF_OP_3AC_ASSIGN_DEREFERENCE ] = _risc_inst_assign_dereference_handler,
+ [SCF_OP_3AC_ASSIGN_ARRAY_INDEX ] = _risc_inst_assign_array_index_handler,
+ [SCF_OP_3AC_ASSIGN_POINTER ] = _risc_inst_assign_pointer_handler,
- {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE, _risc_inst_add_assign_dereference_handler},
- {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX, _risc_inst_add_assign_array_index_handler},
- {SCF_OP_3AC_ADD_ASSIGN_POINTER, _risc_inst_add_assign_pointer_handler},
+ [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE] = _risc_inst_add_assign_dereference_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX] = _risc_inst_add_assign_array_index_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_POINTER ] = _risc_inst_add_assign_pointer_handler,
- {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE, _risc_inst_sub_assign_dereference_handler},
- {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX, _risc_inst_sub_assign_array_index_handler},
- {SCF_OP_3AC_SUB_ASSIGN_POINTER, _risc_inst_sub_assign_pointer_handler},
+ [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE] = _risc_inst_sub_assign_dereference_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX] = _risc_inst_sub_assign_array_index_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_POINTER ] = _risc_inst_sub_assign_pointer_handler,
- {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE, _risc_inst_and_assign_dereference_handler},
- {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, _risc_inst_and_assign_array_index_handler},
- {SCF_OP_3AC_AND_ASSIGN_POINTER, _risc_inst_and_assign_pointer_handler},
+ [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE] = _risc_inst_and_assign_dereference_handler,
+ [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX] = _risc_inst_and_assign_array_index_handler,
+ [SCF_OP_3AC_AND_ASSIGN_POINTER ] = _risc_inst_and_assign_pointer_handler,
- {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE, _risc_inst_or_assign_dereference_handler},
- {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX, _risc_inst_or_assign_array_index_handler},
- {SCF_OP_3AC_OR_ASSIGN_POINTER, _risc_inst_or_assign_pointer_handler},
+ [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ] = _risc_inst_or_assign_dereference_handler,
+ [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ] = _risc_inst_or_assign_array_index_handler,
+ [SCF_OP_3AC_OR_ASSIGN_POINTER ] = _risc_inst_or_assign_pointer_handler,
- {SCF_OP_3AC_INC_DEREFERENCE, _risc_inst_inc_dereference_handler},
- {SCF_OP_3AC_INC_ARRAY_INDEX, _risc_inst_inc_array_index_handler},
- {SCF_OP_3AC_INC_POINTER, _risc_inst_inc_pointer_handler},
+ [SCF_OP_3AC_INC_DEREFERENCE ] = _risc_inst_inc_dereference_handler,
+ [SCF_OP_3AC_INC_ARRAY_INDEX ] = _risc_inst_inc_array_index_handler,
+ [SCF_OP_3AC_INC_POINTER ] = _risc_inst_inc_pointer_handler,
- {SCF_OP_3AC_INC_POST_DEREFERENCE, _risc_inst_inc_post_dereference_handler},
- {SCF_OP_3AC_INC_POST_ARRAY_INDEX, _risc_inst_inc_post_array_index_handler},
- {SCF_OP_3AC_INC_POST_POINTER, _risc_inst_inc_post_pointer_handler},
+ [SCF_OP_3AC_INC_POST_DEREFERENCE ] = _risc_inst_inc_post_dereference_handler,
+ [SCF_OP_3AC_INC_POST_ARRAY_INDEX ] = _risc_inst_inc_post_array_index_handler,
+ [SCF_OP_3AC_INC_POST_POINTER ] = _risc_inst_inc_post_pointer_handler,
- {SCF_OP_3AC_DEC_DEREFERENCE, _risc_inst_dec_dereference_handler},
- {SCF_OP_3AC_DEC_ARRAY_INDEX, _risc_inst_dec_array_index_handler},
- {SCF_OP_3AC_DEC_POINTER, _risc_inst_dec_pointer_handler},
+ [SCF_OP_3AC_DEC_DEREFERENCE ] = _risc_inst_dec_dereference_handler,
+ [SCF_OP_3AC_DEC_ARRAY_INDEX ] = _risc_inst_dec_array_index_handler,
+ [SCF_OP_3AC_DEC_POINTER ] = _risc_inst_dec_pointer_handler,
- {SCF_OP_3AC_DEC_POST_DEREFERENCE, _risc_inst_dec_post_dereference_handler},
- {SCF_OP_3AC_DEC_POST_ARRAY_INDEX, _risc_inst_dec_post_array_index_handler},
- {SCF_OP_3AC_DEC_POST_POINTER, _risc_inst_dec_post_pointer_handler},
+ [SCF_OP_3AC_DEC_POST_DEREFERENCE ] = _risc_inst_dec_post_dereference_handler,
+ [SCF_OP_3AC_DEC_POST_ARRAY_INDEX ] = _risc_inst_dec_post_array_index_handler,
+ [SCF_OP_3AC_DEC_POST_POINTER ] = _risc_inst_dec_post_pointer_handler,
- {SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX, _risc_inst_address_of_array_index_handler},
- {SCF_OP_3AC_ADDRESS_OF_POINTER, _risc_inst_address_of_pointer_handler},
+ [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX] = _risc_inst_address_of_array_index_handler,
+ [SCF_OP_3AC_ADDRESS_OF_POINTER ] = _risc_inst_address_of_pointer_handler,
};
-risc_inst_handler_t* scf_risc_find_inst_handler(const int op_type)
+risc_inst_handler_pt scf_risc_find_inst_handler(const int op_type)
{
- int i;
- for (i = 0; i < sizeof(risc_inst_handlers) / sizeof(risc_inst_handlers[0]); i++) {
-
- risc_inst_handler_t* h = &(risc_inst_handlers[i]);
+ if (op_type < 0 || op_type >= SCF_N_3AC_OPS)
+ return NULL;
- if (op_type == h->type)
- return h;
- }
- return NULL;
+ return risc_inst_handlers[op_type];
}
scf_instruction_t* risc_make_inst(scf_3ac_code_t* c, uint32_t opcode)
return risc_rcg_make(c, g, dst->dag_node, NULL);
}
-static risc_rcg_handler_t risc_rcg_handlers[] = {
-
- {SCF_OP_CALL, _risc_rcg_call_handler},
- {SCF_OP_ARRAY_INDEX, _risc_rcg_array_index_handler},
+static risc_rcg_handler_pt risc_rcg_handlers[SCF_N_3AC_OPS] =
+{
+ [SCF_OP_CALL ] = _risc_rcg_call_handler,
+ [SCF_OP_ARRAY_INDEX ] = _risc_rcg_array_index_handler,
- {SCF_OP_TYPE_CAST, _risc_rcg_cast_handler},
- {SCF_OP_LOGIC_NOT, _risc_rcg_logic_not_handler},
- {SCF_OP_BIT_NOT, _risc_rcg_bit_not_handler},
- {SCF_OP_NEG, _risc_rcg_neg_handler},
+ [SCF_OP_TYPE_CAST ] = _risc_rcg_cast_handler,
+ [SCF_OP_LOGIC_NOT ] = _risc_rcg_logic_not_handler,
+ [SCF_OP_BIT_NOT ] = _risc_rcg_bit_not_handler,
+ [SCF_OP_NEG ] = _risc_rcg_neg_handler,
- {SCF_OP_VA_START, _risc_rcg_va_start_handler},
- {SCF_OP_VA_ARG, _risc_rcg_va_arg_handler},
- {SCF_OP_VA_END, _risc_rcg_va_end_handler},
+ [SCF_OP_VA_START ] = _risc_rcg_va_start_handler,
+ [SCF_OP_VA_ARG ] = _risc_rcg_va_arg_handler,
+ [SCF_OP_VA_END ] = _risc_rcg_va_end_handler,
- {SCF_OP_INC, _risc_rcg_inc_handler},
- {SCF_OP_DEC, _risc_rcg_dec_handler},
+ [SCF_OP_INC ] = _risc_rcg_inc_handler,
+ [SCF_OP_DEC ] = _risc_rcg_dec_handler,
- {SCF_OP_INC_POST, _risc_rcg_inc_post_handler},
- {SCF_OP_DEC_POST, _risc_rcg_dec_post_handler},
+ [SCF_OP_INC_POST ] = _risc_rcg_inc_post_handler,
+ [SCF_OP_DEC_POST ] = _risc_rcg_dec_post_handler,
- {SCF_OP_DEREFERENCE, _risc_rcg_dereference_handler},
- {SCF_OP_ADDRESS_OF, _risc_rcg_address_of_handler},
- {SCF_OP_POINTER, _risc_rcg_pointer_handler},
+ [SCF_OP_DEREFERENCE ] = _risc_rcg_dereference_handler,
+ [SCF_OP_ADDRESS_OF ] = _risc_rcg_address_of_handler,
+ [SCF_OP_POINTER ] = _risc_rcg_pointer_handler,
- {SCF_OP_MUL, _risc_rcg_mul_handler},
- {SCF_OP_DIV, _risc_rcg_div_handler},
- {SCF_OP_MOD, _risc_rcg_mod_handler},
+ [SCF_OP_MUL ] = _risc_rcg_mul_handler,
+ [SCF_OP_DIV ] = _risc_rcg_div_handler,
+ [SCF_OP_MOD ] = _risc_rcg_mod_handler,
- {SCF_OP_ADD, _risc_rcg_add_handler},
- {SCF_OP_SUB, _risc_rcg_sub_handler},
+ [SCF_OP_ADD ] = _risc_rcg_add_handler,
+ [SCF_OP_SUB ] = _risc_rcg_sub_handler,
- {SCF_OP_SHL, _risc_rcg_shl_handler},
- {SCF_OP_SHR, _risc_rcg_shr_handler},
+ [SCF_OP_SHL ] = _risc_rcg_shl_handler,
+ [SCF_OP_SHR ] = _risc_rcg_shr_handler,
- {SCF_OP_BIT_AND, _risc_rcg_bit_and_handler},
- {SCF_OP_BIT_OR, _risc_rcg_bit_or_handler},
+ [SCF_OP_BIT_AND ] = _risc_rcg_bit_and_handler,
+ [SCF_OP_BIT_OR ] = _risc_rcg_bit_or_handler,
- {SCF_OP_EQ, _risc_rcg_eq_handler},
- {SCF_OP_NE, _risc_rcg_ne_handler},
- {SCF_OP_GT, _risc_rcg_gt_handler},
- {SCF_OP_LT, _risc_rcg_lt_handler},
+ [SCF_OP_EQ ] = _risc_rcg_eq_handler,
+ [SCF_OP_NE ] = _risc_rcg_ne_handler,
+ [SCF_OP_GT ] = _risc_rcg_gt_handler,
+ [SCF_OP_LT ] = _risc_rcg_lt_handler,
- {SCF_OP_ASSIGN, _risc_rcg_assign_handler},
- {SCF_OP_ADD_ASSIGN, _risc_rcg_add_assign_handler},
- {SCF_OP_SUB_ASSIGN, _risc_rcg_sub_assign_handler},
+ [SCF_OP_ASSIGN ] = _risc_rcg_assign_handler,
+ [SCF_OP_ADD_ASSIGN ] = _risc_rcg_add_assign_handler,
+ [SCF_OP_SUB_ASSIGN ] = _risc_rcg_sub_assign_handler,
- {SCF_OP_MUL_ASSIGN, _risc_rcg_mul_assign_handler},
- {SCF_OP_DIV_ASSIGN, _risc_rcg_div_assign_handler},
- {SCF_OP_MOD_ASSIGN, _risc_rcg_mod_assign_handler},
+ [SCF_OP_MUL_ASSIGN ] = _risc_rcg_mul_assign_handler,
+ [SCF_OP_DIV_ASSIGN ] = _risc_rcg_div_assign_handler,
+ [SCF_OP_MOD_ASSIGN ] = _risc_rcg_mod_assign_handler,
- {SCF_OP_SHL_ASSIGN, _risc_rcg_shl_assign_handler},
- {SCF_OP_SHR_ASSIGN, _risc_rcg_shr_assign_handler},
+ [SCF_OP_SHL_ASSIGN ] = _risc_rcg_shl_assign_handler,
+ [SCF_OP_SHR_ASSIGN ] = _risc_rcg_shr_assign_handler,
- {SCF_OP_AND_ASSIGN, _risc_rcg_and_assign_handler},
- {SCF_OP_OR_ASSIGN, _risc_rcg_or_assign_handler},
+ [SCF_OP_AND_ASSIGN ] = _risc_rcg_and_assign_handler,
+ [SCF_OP_OR_ASSIGN ] = _risc_rcg_or_assign_handler,
- {SCF_OP_RETURN, _risc_rcg_return_handler},
+ [SCF_OP_RETURN ] = _risc_rcg_return_handler,
- {SCF_OP_3AC_CMP, _risc_rcg_cmp_handler},
- {SCF_OP_3AC_TEQ, _risc_rcg_teq_handler},
+ [SCF_OP_3AC_CMP ] = _risc_rcg_cmp_handler,
+ [SCF_OP_3AC_TEQ ] = _risc_rcg_teq_handler,
- {SCF_OP_3AC_SETZ, _risc_rcg_setz_handler},
- {SCF_OP_3AC_SETNZ, _risc_rcg_setnz_handler},
- {SCF_OP_3AC_SETGT, _risc_rcg_setgt_handler},
- {SCF_OP_3AC_SETGE, _risc_rcg_setge_handler},
- {SCF_OP_3AC_SETLT, _risc_rcg_setlt_handler},
- {SCF_OP_3AC_SETLE, _risc_rcg_setle_handler},
+ [SCF_OP_3AC_SETZ ] = _risc_rcg_setz_handler,
+ [SCF_OP_3AC_SETNZ ] = _risc_rcg_setnz_handler,
+ [SCF_OP_3AC_SETGT ] = _risc_rcg_setgt_handler,
+ [SCF_OP_3AC_SETGE ] = _risc_rcg_setge_handler,
+ [SCF_OP_3AC_SETLT ] = _risc_rcg_setlt_handler,
+ [SCF_OP_3AC_SETLE ] = _risc_rcg_setle_handler,
- {SCF_OP_GOTO, _risc_rcg_goto_handler},
- {SCF_OP_3AC_JZ, _risc_rcg_jz_handler},
- {SCF_OP_3AC_JNZ, _risc_rcg_jnz_handler},
- {SCF_OP_3AC_JGT, _risc_rcg_jgt_handler},
- {SCF_OP_3AC_JGE, _risc_rcg_jge_handler},
- {SCF_OP_3AC_JLT, _risc_rcg_jlt_handler},
- {SCF_OP_3AC_JLE, _risc_rcg_jle_handler},
+ [SCF_OP_GOTO ] = _risc_rcg_goto_handler,
+ [SCF_OP_3AC_JZ ] = _risc_rcg_jz_handler,
+ [SCF_OP_3AC_JNZ ] = _risc_rcg_jnz_handler,
+ [SCF_OP_3AC_JGT ] = _risc_rcg_jgt_handler,
+ [SCF_OP_3AC_JGE ] = _risc_rcg_jge_handler,
+ [SCF_OP_3AC_JLT ] = _risc_rcg_jlt_handler,
+ [SCF_OP_3AC_JLE ] = _risc_rcg_jle_handler,
- {SCF_OP_3AC_JA, _risc_rcg_ja_handler},
- {SCF_OP_3AC_JAE, _risc_rcg_jae_handler},
- {SCF_OP_3AC_JB, _risc_rcg_jb_handler},
- {SCF_OP_3AC_JBE, _risc_rcg_jbe_handler},
+ [SCF_OP_3AC_JA ] = _risc_rcg_ja_handler,
+ [SCF_OP_3AC_JAE ] = _risc_rcg_jae_handler,
+ [SCF_OP_3AC_JB ] = _risc_rcg_jb_handler,
+ [SCF_OP_3AC_JBE ] = _risc_rcg_jbe_handler,
- {SCF_OP_3AC_SAVE, _risc_rcg_save_handler},
- {SCF_OP_3AC_LOAD, _risc_rcg_load_handler},
+ [SCF_OP_3AC_SAVE ] = _risc_rcg_save_handler,
+ [SCF_OP_3AC_LOAD ] = _risc_rcg_load_handler,
- {SCF_OP_3AC_RESAVE, _risc_rcg_save_handler},
- {SCF_OP_3AC_RELOAD, _risc_rcg_load_handler},
+ [SCF_OP_3AC_RESAVE ] = _risc_rcg_save_handler,
+ [SCF_OP_3AC_RELOAD ] = _risc_rcg_load_handler,
- {SCF_OP_3AC_NOP, _risc_rcg_nop_handler},
- {SCF_OP_3AC_END, _risc_rcg_end_handler},
+ [SCF_OP_3AC_NOP ] = _risc_rcg_nop_handler,
+ [SCF_OP_3AC_END ] = _risc_rcg_end_handler,
- {SCF_OP_3AC_INC, _risc_rcg_inc_handler},
- {SCF_OP_3AC_DEC, _risc_rcg_dec_handler},
+ [SCF_OP_3AC_INC ] = _risc_rcg_inc_handler,
+ [SCF_OP_3AC_DEC ] = _risc_rcg_dec_handler,
- {SCF_OP_3AC_PUSH_RAX, _risc_rcg_push_rax_handler},
- {SCF_OP_3AC_POP_RAX, _risc_rcg_pop_rax_handler},
+ [SCF_OP_3AC_PUSH_RAX] = _risc_rcg_push_rax_handler,
+ [SCF_OP_3AC_POP_RAX ] = _risc_rcg_pop_rax_handler,
- {SCF_OP_3AC_MEMSET, _risc_rcg_memset_handler},
+ [SCF_OP_3AC_MEMSET ] = _risc_rcg_memset_handler,
- {SCF_OP_3AC_ASSIGN_DEREFERENCE, _risc_rcg_assign_dereference_handler},
- {SCF_OP_3AC_ASSIGN_ARRAY_INDEX, _risc_rcg_assign_array_index_handler},
- {SCF_OP_3AC_ASSIGN_POINTER, _risc_rcg_assign_pointer_handler},
+ [SCF_OP_3AC_ASSIGN_DEREFERENCE ] = _risc_rcg_assign_dereference_handler,
+ [SCF_OP_3AC_ASSIGN_ARRAY_INDEX ] = _risc_rcg_assign_array_index_handler,
+ [SCF_OP_3AC_ASSIGN_POINTER ] = _risc_rcg_assign_pointer_handler,
- {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE, _risc_rcg_add_assign_dereference_handler},
- {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX, _risc_rcg_add_assign_array_index_handler},
- {SCF_OP_3AC_ADD_ASSIGN_POINTER, _risc_rcg_add_assign_pointer_handler},
+ [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE] = _risc_rcg_add_assign_dereference_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX] = _risc_rcg_add_assign_array_index_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_POINTER ] = _risc_rcg_add_assign_pointer_handler,
- {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE, _risc_rcg_sub_assign_dereference_handler},
- {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX, _risc_rcg_sub_assign_array_index_handler},
- {SCF_OP_3AC_SUB_ASSIGN_POINTER, _risc_rcg_sub_assign_pointer_handler},
+ [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE] = _risc_rcg_sub_assign_dereference_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX] = _risc_rcg_sub_assign_array_index_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_POINTER ] = _risc_rcg_sub_assign_pointer_handler,
- {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE, _risc_rcg_and_assign_dereference_handler},
- {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, _risc_rcg_and_assign_array_index_handler},
- {SCF_OP_3AC_AND_ASSIGN_POINTER, _risc_rcg_and_assign_pointer_handler},
+ [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE] = _risc_rcg_and_assign_dereference_handler,
+ [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX] = _risc_rcg_and_assign_array_index_handler,
+ [SCF_OP_3AC_AND_ASSIGN_POINTER ] = _risc_rcg_and_assign_pointer_handler,
- {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE, _risc_rcg_or_assign_dereference_handler},
- {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX, _risc_rcg_or_assign_array_index_handler},
- {SCF_OP_3AC_OR_ASSIGN_POINTER, _risc_rcg_or_assign_pointer_handler},
+ [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ] = _risc_rcg_or_assign_dereference_handler,
+ [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ] = _risc_rcg_or_assign_array_index_handler,
+ [SCF_OP_3AC_OR_ASSIGN_POINTER ] = _risc_rcg_or_assign_pointer_handler,
- {SCF_OP_3AC_INC_DEREFERENCE, _risc_rcg_inc_dereference_handler},
- {SCF_OP_3AC_INC_ARRAY_INDEX, _risc_rcg_inc_array_index_handler},
- {SCF_OP_3AC_INC_POINTER, _risc_rcg_inc_pointer_handler},
+ [SCF_OP_3AC_INC_DEREFERENCE ] = _risc_rcg_inc_dereference_handler,
+ [SCF_OP_3AC_INC_ARRAY_INDEX ] = _risc_rcg_inc_array_index_handler,
+ [SCF_OP_3AC_INC_POINTER ] = _risc_rcg_inc_pointer_handler,
- {SCF_OP_3AC_INC_POST_DEREFERENCE, _risc_rcg_inc_post_dereference_handler},
- {SCF_OP_3AC_INC_POST_ARRAY_INDEX, _risc_rcg_inc_post_array_index_handler},
- {SCF_OP_3AC_INC_POST_POINTER, _risc_rcg_inc_post_pointer_handler},
+ [SCF_OP_3AC_INC_POST_DEREFERENCE ] = _risc_rcg_inc_post_dereference_handler,
+ [SCF_OP_3AC_INC_POST_ARRAY_INDEX ] = _risc_rcg_inc_post_array_index_handler,
+ [SCF_OP_3AC_INC_POST_POINTER ] = _risc_rcg_inc_post_pointer_handler,
- {SCF_OP_3AC_DEC_DEREFERENCE, _risc_rcg_dec_dereference_handler},
- {SCF_OP_3AC_DEC_ARRAY_INDEX, _risc_rcg_dec_array_index_handler},
- {SCF_OP_3AC_DEC_POINTER, _risc_rcg_dec_pointer_handler},
+ [SCF_OP_3AC_DEC_DEREFERENCE ] = _risc_rcg_dec_dereference_handler,
+ [SCF_OP_3AC_DEC_ARRAY_INDEX ] = _risc_rcg_dec_array_index_handler,
+ [SCF_OP_3AC_DEC_POINTER ] = _risc_rcg_dec_pointer_handler,
- {SCF_OP_3AC_DEC_POST_DEREFERENCE, _risc_rcg_dec_post_dereference_handler},
- {SCF_OP_3AC_DEC_POST_ARRAY_INDEX, _risc_rcg_dec_post_array_index_handler},
- {SCF_OP_3AC_DEC_POST_POINTER, _risc_rcg_dec_post_pointer_handler},
+ [SCF_OP_3AC_DEC_POST_DEREFERENCE ] = _risc_rcg_dec_post_dereference_handler,
+ [SCF_OP_3AC_DEC_POST_ARRAY_INDEX ] = _risc_rcg_dec_post_array_index_handler,
+ [SCF_OP_3AC_DEC_POST_POINTER ] = _risc_rcg_dec_post_pointer_handler,
- {SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX, _risc_rcg_address_of_array_index_handler},
- {SCF_OP_3AC_ADDRESS_OF_POINTER, _risc_rcg_address_of_pointer_handler},
+ [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX] = _risc_rcg_address_of_array_index_handler,
+ [SCF_OP_3AC_ADDRESS_OF_POINTER ] = _risc_rcg_address_of_pointer_handler,
};
-risc_rcg_handler_t* scf_risc_find_rcg_handler(const int op_type)
+risc_rcg_handler_pt scf_risc_find_rcg_handler(const int op_type)
{
- int i;
- for (i = 0; i < sizeof(risc_rcg_handlers) / sizeof(risc_rcg_handlers[0]); i++) {
+ if (op_type < 0 || op_type >= SCF_N_3AC_OPS)
+ return NULL;
- risc_rcg_handler_t* h = &(risc_rcg_handlers[i]);
-
- if (op_type == h->type)
- return h;
- }
- return NULL;
+ return risc_rcg_handlers[op_type];
}
int scf_native_select_inst(scf_native_t* ctx, scf_function_t* f);
-int scf_native_write_elf(scf_native_t* ctx, const char* path, scf_function_t* f);
-
#endif
-
static int _x64_make_bb_rcg(scf_graph_t* g, scf_basic_block_t* bb, scf_native_t* ctx)
{
- scf_list_t* l;
- scf_3ac_code_t* c;
- x64_rcg_handler_t* h;
+ scf_list_t* l;
+ scf_3ac_code_t* c;
+ x64_rcg_handler_pt h;
for (l = scf_list_head(&bb->code_list_head); l != scf_list_sentinel(&bb->code_list_head); l = scf_list_next(l)) {
return -EINVAL;
}
- int ret = h->func(ctx, c, g);
+ int ret = h(ctx, c, g);
if (ret < 0)
return ret;
}
scf_3ac_code_t* c = scf_list_data(l, scf_3ac_code_t, list);
- x64_inst_handler_t* h = scf_x64_find_inst_handler(c->op->type);
+ x64_inst_handler_pt h = scf_x64_find_inst_handler(c->op->type);
if (!h) {
scf_loge("3ac operator '%s' not supported\n", c->op->name);
return -EINVAL;
}
- ret = h->func(ctx, c);
+ ret = h(ctx, c);
if (ret < 0) {
scf_3ac_code_print(c, NULL);
scf_loge("3ac op '%s' make inst failed\n", c->op->name);
} x64_rcg_node_t;
-typedef struct {
- int type;
- int (*func)(scf_native_t* ctx, scf_3ac_code_t* c, scf_graph_t* g);
-} x64_rcg_handler_t;
-typedef struct {
- int type;
- int (*func)(scf_native_t* ctx, scf_3ac_code_t* c);
-} x64_inst_handler_t;
+typedef int (*x64_rcg_handler_pt )(scf_native_t* ctx, scf_3ac_code_t* c, scf_graph_t* g);
+typedef int (*x64_inst_handler_pt)(scf_native_t* ctx, scf_3ac_code_t* c);
-x64_rcg_handler_t* scf_x64_find_rcg_handler(const int op_type);
-x64_inst_handler_t* scf_x64_find_inst_handler(const int op_type);
+x64_rcg_handler_pt scf_x64_find_rcg_handler (const int op_type);
+x64_inst_handler_pt scf_x64_find_inst_handler(const int op_type);
int x64_rcg_find_node(scf_graph_node_t** pp, scf_graph_t* g, scf_dag_node_t* dn, scf_register_t* reg);
int _x64_rcg_make_node(scf_graph_node_t** pp, scf_graph_t* g, scf_dag_node_t* dn, scf_register_t* reg, scf_x64_OpCode_t* OpCode);
return -ENOMEM;
}
- scf_loge("c->srcs->size: %d\n", c->srcs->size);
assert(3 == c->srcs->size);
scf_register_t* rbp = x64_find_register("rbp");
return 0;
}
-static x64_inst_handler_t x64_inst_handlers[] = {
-
- {SCF_OP_CALL, _x64_inst_call_handler},
- {SCF_OP_ARRAY_INDEX, _x64_inst_array_index_handler},
- {SCF_OP_POINTER, _x64_inst_pointer_handler},
+static x64_inst_handler_pt x64_inst_handlers[] =
+{
+ [SCF_OP_CALL ] = _x64_inst_call_handler,
+ [SCF_OP_ARRAY_INDEX ] = _x64_inst_array_index_handler,
+ [SCF_OP_POINTER ] = _x64_inst_pointer_handler,
- {SCF_OP_TYPE_CAST, _x64_inst_cast_handler},
- {SCF_OP_LOGIC_NOT, _x64_inst_logic_not_handler},
- {SCF_OP_BIT_NOT, _x64_inst_bit_not_handler},
- {SCF_OP_NEG, _x64_inst_neg_handler},
+ [SCF_OP_TYPE_CAST ] = _x64_inst_cast_handler,
+ [SCF_OP_LOGIC_NOT ] = _x64_inst_logic_not_handler,
+ [SCF_OP_BIT_NOT ] = _x64_inst_bit_not_handler,
+ [SCF_OP_NEG ] = _x64_inst_neg_handler,
- {SCF_OP_VA_START, _x64_inst_va_start_handler},
- {SCF_OP_VA_ARG, _x64_inst_va_arg_handler},
- {SCF_OP_VA_END, _x64_inst_va_end_handler},
+ [SCF_OP_VA_START ] = _x64_inst_va_start_handler,
+ [SCF_OP_VA_ARG ] = _x64_inst_va_arg_handler,
+ [SCF_OP_VA_END ] = _x64_inst_va_end_handler,
- {SCF_OP_INC, _x64_inst_inc_handler},
- {SCF_OP_DEC, _x64_inst_dec_handler},
+ [SCF_OP_INC ] = _x64_inst_inc_handler,
+ [SCF_OP_DEC ] = _x64_inst_dec_handler,
- {SCF_OP_DEREFERENCE, _x64_inst_dereference_handler},
- {SCF_OP_ADDRESS_OF, _x64_inst_address_of_handler},
+ [SCF_OP_DEREFERENCE ] = _x64_inst_dereference_handler,
+ [SCF_OP_ADDRESS_OF ] = _x64_inst_address_of_handler,
- {SCF_OP_MUL, _x64_inst_mul_handler},
- {SCF_OP_DIV, _x64_inst_div_handler},
- {SCF_OP_MOD, _x64_inst_mod_handler},
+ [SCF_OP_MUL ] = _x64_inst_mul_handler,
+ [SCF_OP_DIV ] = _x64_inst_div_handler,
+ [SCF_OP_MOD ] = _x64_inst_mod_handler,
- {SCF_OP_ADD, _x64_inst_add_handler},
- {SCF_OP_SUB, _x64_inst_sub_handler},
+ [SCF_OP_ADD ] = _x64_inst_add_handler,
+ [SCF_OP_SUB ] = _x64_inst_sub_handler,
- {SCF_OP_SHL, _x64_inst_shl_handler},
- {SCF_OP_SHR, _x64_inst_shr_handler},
+ [SCF_OP_SHL ] = _x64_inst_shl_handler,
+ [SCF_OP_SHR ] = _x64_inst_shr_handler,
- {SCF_OP_BIT_AND, _x64_inst_bit_and_handler},
- {SCF_OP_BIT_OR, _x64_inst_bit_or_handler},
+ [SCF_OP_BIT_AND ] = _x64_inst_bit_and_handler,
+ [SCF_OP_BIT_OR ] = _x64_inst_bit_or_handler,
- {SCF_OP_3AC_TEQ, _x64_inst_teq_handler},
- {SCF_OP_3AC_CMP, _x64_inst_cmp_handler},
+ [SCF_OP_3AC_TEQ ] = _x64_inst_teq_handler,
+ [SCF_OP_3AC_CMP ] = _x64_inst_cmp_handler,
- {SCF_OP_3AC_SETZ, _x64_inst_setz_handler},
- {SCF_OP_3AC_SETNZ, _x64_inst_setnz_handler},
- {SCF_OP_3AC_SETGT, _x64_inst_setgt_handler},
- {SCF_OP_3AC_SETGE, _x64_inst_setge_handler},
- {SCF_OP_3AC_SETLT, _x64_inst_setlt_handler},
- {SCF_OP_3AC_SETLE, _x64_inst_setle_handler},
+ [SCF_OP_3AC_SETZ ] = _x64_inst_setz_handler,
+ [SCF_OP_3AC_SETNZ ] = _x64_inst_setnz_handler,
+ [SCF_OP_3AC_SETGT ] = _x64_inst_setgt_handler,
+ [SCF_OP_3AC_SETGE ] = _x64_inst_setge_handler,
+ [SCF_OP_3AC_SETLT ] = _x64_inst_setlt_handler,
+ [SCF_OP_3AC_SETLE ] = _x64_inst_setle_handler,
- {SCF_OP_EQ, _x64_inst_eq_handler},
- {SCF_OP_NE, _x64_inst_ne_handler},
- {SCF_OP_GT, _x64_inst_gt_handler},
- {SCF_OP_GE, _x64_inst_ge_handler},
- {SCF_OP_LT, _x64_inst_lt_handler},
- {SCF_OP_LE, _x64_inst_le_handler},
+ [SCF_OP_EQ ] = _x64_inst_eq_handler,
+ [SCF_OP_NE ] = _x64_inst_ne_handler,
+ [SCF_OP_GT ] = _x64_inst_gt_handler,
+ [SCF_OP_GE ] = _x64_inst_ge_handler,
+ [SCF_OP_LT ] = _x64_inst_lt_handler,
+ [SCF_OP_LE ] = _x64_inst_le_handler,
- {SCF_OP_ASSIGN, _x64_inst_assign_handler},
+ [SCF_OP_ASSIGN ] = _x64_inst_assign_handler,
- {SCF_OP_ADD_ASSIGN, _x64_inst_add_assign_handler},
- {SCF_OP_SUB_ASSIGN, _x64_inst_sub_assign_handler},
+ [SCF_OP_ADD_ASSIGN ] = _x64_inst_add_assign_handler,
+ [SCF_OP_SUB_ASSIGN ] = _x64_inst_sub_assign_handler,
- {SCF_OP_MUL_ASSIGN, _x64_inst_mul_assign_handler},
- {SCF_OP_DIV_ASSIGN, _x64_inst_div_assign_handler},
- {SCF_OP_MOD_ASSIGN, _x64_inst_mod_assign_handler},
+ [SCF_OP_MUL_ASSIGN ] = _x64_inst_mul_assign_handler,
+ [SCF_OP_DIV_ASSIGN ] = _x64_inst_div_assign_handler,
+ [SCF_OP_MOD_ASSIGN ] = _x64_inst_mod_assign_handler,
- {SCF_OP_SHL_ASSIGN, _x64_inst_shl_assign_handler},
- {SCF_OP_SHR_ASSIGN, _x64_inst_shr_assign_handler},
+ [SCF_OP_SHL_ASSIGN ] = _x64_inst_shl_assign_handler,
+ [SCF_OP_SHR_ASSIGN ] = _x64_inst_shr_assign_handler,
- {SCF_OP_AND_ASSIGN, _x64_inst_and_assign_handler},
- {SCF_OP_OR_ASSIGN, _x64_inst_or_assign_handler},
+ [SCF_OP_AND_ASSIGN ] = _x64_inst_and_assign_handler,
+ [SCF_OP_OR_ASSIGN ] = _x64_inst_or_assign_handler,
- {SCF_OP_RETURN, _x64_inst_return_handler},
- {SCF_OP_GOTO, _x64_inst_goto_handler},
+ [SCF_OP_RETURN ] = _x64_inst_return_handler,
+ [SCF_OP_GOTO ] = _x64_inst_goto_handler,
- {SCF_OP_3AC_JZ, _x64_inst_jz_handler},
- {SCF_OP_3AC_JNZ, _x64_inst_jnz_handler},
- {SCF_OP_3AC_JGT, _x64_inst_jgt_handler},
- {SCF_OP_3AC_JGE, _x64_inst_jge_handler},
- {SCF_OP_3AC_JLT, _x64_inst_jlt_handler},
- {SCF_OP_3AC_JLE, _x64_inst_jle_handler},
+ [SCF_OP_3AC_JZ ] = _x64_inst_jz_handler,
+ [SCF_OP_3AC_JNZ ] = _x64_inst_jnz_handler,
+ [SCF_OP_3AC_JGT ] = _x64_inst_jgt_handler,
+ [SCF_OP_3AC_JGE ] = _x64_inst_jge_handler,
+ [SCF_OP_3AC_JLT ] = _x64_inst_jlt_handler,
+ [SCF_OP_3AC_JLE ] = _x64_inst_jle_handler,
- {SCF_OP_3AC_JA, _x64_inst_ja_handler},
- {SCF_OP_3AC_JB, _x64_inst_jb_handler},
- {SCF_OP_3AC_JAE, _x64_inst_jae_handler},
- {SCF_OP_3AC_JBE, _x64_inst_jbe_handler},
+ [SCF_OP_3AC_JA ] = _x64_inst_ja_handler,
+ [SCF_OP_3AC_JB ] = _x64_inst_jb_handler,
+ [SCF_OP_3AC_JAE ] = _x64_inst_jae_handler,
+ [SCF_OP_3AC_JBE ] = _x64_inst_jbe_handler,
- {SCF_OP_3AC_NOP, _x64_inst_nop_handler},
- {SCF_OP_3AC_END, _x64_inst_end_handler},
+ [SCF_OP_3AC_NOP ] = _x64_inst_nop_handler,
+ [SCF_OP_3AC_END ] = _x64_inst_end_handler,
- {SCF_OP_3AC_SAVE, _x64_inst_save_handler},
- {SCF_OP_3AC_LOAD, _x64_inst_load_handler},
+ [SCF_OP_3AC_SAVE ] = _x64_inst_save_handler,
+ [SCF_OP_3AC_LOAD ] = _x64_inst_load_handler,
- {SCF_OP_3AC_RESAVE, _x64_inst_save_handler},
- {SCF_OP_3AC_RELOAD, _x64_inst_reload_handler},
+ [SCF_OP_3AC_RESAVE ] = _x64_inst_save_handler,
+ [SCF_OP_3AC_RELOAD ] = _x64_inst_reload_handler,
- {SCF_OP_3AC_INC, _x64_inst_inc_handler},
- {SCF_OP_3AC_DEC, _x64_inst_dec_handler},
+ [SCF_OP_3AC_INC ] = _x64_inst_inc_handler,
+ [SCF_OP_3AC_DEC ] = _x64_inst_dec_handler,
- {SCF_OP_3AC_PUSH_RAX, _x64_inst_push_rax_handler},
- {SCF_OP_3AC_POP_RAX, _x64_inst_pop_rax_handler},
+ [SCF_OP_3AC_PUSH_RAX] = _x64_inst_push_rax_handler,
+ [SCF_OP_3AC_POP_RAX ] = _x64_inst_pop_rax_handler,
- {SCF_OP_3AC_MEMSET, _x64_inst_memset_handler},
+ [SCF_OP_3AC_MEMSET ] = _x64_inst_memset_handler,
- {SCF_OP_3AC_ASSIGN_DEREFERENCE, _x64_inst_assign_dereference_handler},
- {SCF_OP_3AC_ASSIGN_ARRAY_INDEX, _x64_inst_assign_array_index_handler},
- {SCF_OP_3AC_ASSIGN_POINTER, _x64_inst_assign_pointer_handler},
+ [SCF_OP_3AC_ASSIGN_DEREFERENCE ] = _x64_inst_assign_dereference_handler,
+ [SCF_OP_3AC_ASSIGN_ARRAY_INDEX ] = _x64_inst_assign_array_index_handler,
+ [SCF_OP_3AC_ASSIGN_POINTER ] = _x64_inst_assign_pointer_handler,
- {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE, _x64_inst_add_assign_dereference_handler},
- {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX, _x64_inst_add_assign_array_index_handler},
- {SCF_OP_3AC_ADD_ASSIGN_POINTER, _x64_inst_add_assign_pointer_handler},
+ [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE] = _x64_inst_add_assign_dereference_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX] = _x64_inst_add_assign_array_index_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_POINTER ] = _x64_inst_add_assign_pointer_handler,
- {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE, _x64_inst_sub_assign_dereference_handler},
- {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX, _x64_inst_sub_assign_array_index_handler},
- {SCF_OP_3AC_SUB_ASSIGN_POINTER, _x64_inst_sub_assign_pointer_handler},
+ [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE] = _x64_inst_sub_assign_dereference_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX] = _x64_inst_sub_assign_array_index_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_POINTER ] = _x64_inst_sub_assign_pointer_handler,
- {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE, _x64_inst_and_assign_dereference_handler},
- {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, _x64_inst_and_assign_array_index_handler},
- {SCF_OP_3AC_AND_ASSIGN_POINTER, _x64_inst_and_assign_pointer_handler},
+ [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE] = _x64_inst_and_assign_dereference_handler,
+ [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX] = _x64_inst_and_assign_array_index_handler,
+ [SCF_OP_3AC_AND_ASSIGN_POINTER ] = _x64_inst_and_assign_pointer_handler,
- {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE, _x64_inst_or_assign_dereference_handler},
- {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX, _x64_inst_or_assign_array_index_handler},
- {SCF_OP_3AC_OR_ASSIGN_POINTER, _x64_inst_or_assign_pointer_handler},
+ [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ] = _x64_inst_or_assign_dereference_handler,
+ [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ] = _x64_inst_or_assign_array_index_handler,
+ [SCF_OP_3AC_OR_ASSIGN_POINTER ] = _x64_inst_or_assign_pointer_handler,
- {SCF_OP_3AC_INC_DEREFERENCE, _x64_inst_inc_dereference_handler},
- {SCF_OP_3AC_INC_ARRAY_INDEX, _x64_inst_inc_array_index_handler},
- {SCF_OP_3AC_INC_POINTER, _x64_inst_inc_pointer_handler},
+ [SCF_OP_3AC_INC_DEREFERENCE ] = _x64_inst_inc_dereference_handler,
+ [SCF_OP_3AC_INC_ARRAY_INDEX ] = _x64_inst_inc_array_index_handler,
+ [SCF_OP_3AC_INC_POINTER ] = _x64_inst_inc_pointer_handler,
- {SCF_OP_3AC_INC_POST_DEREFERENCE, _x64_inst_inc_post_dereference_handler},
- {SCF_OP_3AC_INC_POST_ARRAY_INDEX, _x64_inst_inc_post_array_index_handler},
- {SCF_OP_3AC_INC_POST_POINTER, _x64_inst_inc_post_pointer_handler},
+ [SCF_OP_3AC_INC_POST_DEREFERENCE ] = _x64_inst_inc_post_dereference_handler,
+ [SCF_OP_3AC_INC_POST_ARRAY_INDEX ] = _x64_inst_inc_post_array_index_handler,
+ [SCF_OP_3AC_INC_POST_POINTER ] = _x64_inst_inc_post_pointer_handler,
- {SCF_OP_3AC_DEC_DEREFERENCE, _x64_inst_dec_dereference_handler},
- {SCF_OP_3AC_DEC_ARRAY_INDEX, _x64_inst_dec_array_index_handler},
- {SCF_OP_3AC_DEC_POINTER, _x64_inst_dec_pointer_handler},
+ [SCF_OP_3AC_DEC_DEREFERENCE ] = _x64_inst_dec_dereference_handler,
+ [SCF_OP_3AC_DEC_ARRAY_INDEX ] = _x64_inst_dec_array_index_handler,
+ [SCF_OP_3AC_DEC_POINTER ] = _x64_inst_dec_pointer_handler,
- {SCF_OP_3AC_DEC_POST_DEREFERENCE, _x64_inst_dec_post_dereference_handler},
- {SCF_OP_3AC_DEC_POST_ARRAY_INDEX, _x64_inst_dec_post_array_index_handler},
- {SCF_OP_3AC_DEC_POST_POINTER, _x64_inst_dec_post_pointer_handler},
+ [SCF_OP_3AC_DEC_POST_DEREFERENCE ] = _x64_inst_dec_post_dereference_handler,
+ [SCF_OP_3AC_DEC_POST_ARRAY_INDEX ] = _x64_inst_dec_post_array_index_handler,
+ [SCF_OP_3AC_DEC_POST_POINTER ] = _x64_inst_dec_post_pointer_handler,
- {SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX, _x64_inst_address_of_array_index_handler},
- {SCF_OP_3AC_ADDRESS_OF_POINTER, _x64_inst_address_of_pointer_handler},
+ [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX] = _x64_inst_address_of_array_index_handler,
+ [SCF_OP_3AC_ADDRESS_OF_POINTER ] = _x64_inst_address_of_pointer_handler,
};
-x64_inst_handler_t* scf_x64_find_inst_handler(const int op_type)
+x64_inst_handler_pt scf_x64_find_inst_handler(const int op_type)
{
- int i;
- for (i = 0; i < sizeof(x64_inst_handlers) / sizeof(x64_inst_handlers[0]); i++) {
+ if (op_type < 0 || op_type >= SCF_N_3AC_OPS)
+ return NULL;
- x64_inst_handler_t* h = &(x64_inst_handlers[i]);
-
- if (op_type == h->type)
- return h;
- }
- return NULL;
+ return x64_inst_handlers[op_type];
}
return _x64_rcg_make(c, g, dst->dag_node, NULL, NULL);
}
-static x64_rcg_handler_t x64_rcg_handlers[] = {
-
- {SCF_OP_CALL, _x64_rcg_call_handler},
- {SCF_OP_ARRAY_INDEX, _x64_rcg_array_index_handler},
-
- {SCF_OP_TYPE_CAST, _x64_rcg_cast_handler},
- {SCF_OP_LOGIC_NOT, _x64_rcg_logic_not_handler},
- {SCF_OP_BIT_NOT, _x64_rcg_bit_not_handler},
- {SCF_OP_NEG, _x64_rcg_neg_handler},
+static x64_rcg_handler_pt x64_rcg_handlers[SCF_N_3AC_OPS] =
+{
+ [SCF_OP_CALL ] = _x64_rcg_call_handler,
+ [SCF_OP_ARRAY_INDEX ] = _x64_rcg_array_index_handler,
- {SCF_OP_VA_START, _x64_rcg_va_start_handler},
- {SCF_OP_VA_ARG, _x64_rcg_va_arg_handler},
- {SCF_OP_VA_END, _x64_rcg_va_end_handler},
+ [SCF_OP_TYPE_CAST ] = _x64_rcg_cast_handler,
+ [SCF_OP_LOGIC_NOT ] = _x64_rcg_logic_not_handler,
+ [SCF_OP_BIT_NOT ] = _x64_rcg_bit_not_handler,
+ [SCF_OP_NEG ] = _x64_rcg_neg_handler,
- {SCF_OP_INC, _x64_rcg_inc_handler},
- {SCF_OP_DEC, _x64_rcg_dec_handler},
+ [SCF_OP_VA_START ] = _x64_rcg_va_start_handler,
+ [SCF_OP_VA_ARG ] = _x64_rcg_va_arg_handler,
+ [SCF_OP_VA_END ] = _x64_rcg_va_end_handler,
- {SCF_OP_INC_POST, _x64_rcg_inc_post_handler},
- {SCF_OP_DEC_POST, _x64_rcg_dec_post_handler},
+ [SCF_OP_INC ] = _x64_rcg_inc_handler,
+ [SCF_OP_DEC ] = _x64_rcg_dec_handler,
- {SCF_OP_DEREFERENCE, _x64_rcg_dereference_handler},
- {SCF_OP_ADDRESS_OF, _x64_rcg_address_of_handler},
- {SCF_OP_POINTER, _x64_rcg_pointer_handler},
+ [SCF_OP_INC_POST ] = _x64_rcg_inc_post_handler,
+ [SCF_OP_DEC_POST ] = _x64_rcg_dec_post_handler,
- {SCF_OP_MUL, _x64_rcg_mul_handler},
- {SCF_OP_DIV, _x64_rcg_div_handler},
- {SCF_OP_MOD, _x64_rcg_mod_handler},
+ [SCF_OP_DEREFERENCE ] = _x64_rcg_dereference_handler,
+ [SCF_OP_ADDRESS_OF ] = _x64_rcg_address_of_handler,
+ [SCF_OP_POINTER ] = _x64_rcg_pointer_handler,
- {SCF_OP_ADD, _x64_rcg_add_handler},
- {SCF_OP_SUB, _x64_rcg_sub_handler},
+ [SCF_OP_MUL ] = _x64_rcg_mul_handler,
+ [SCF_OP_DIV ] = _x64_rcg_div_handler,
+ [SCF_OP_MOD ] = _x64_rcg_mod_handler,
- {SCF_OP_SHL, _x64_rcg_shl_handler},
- {SCF_OP_SHR, _x64_rcg_shr_handler},
+ [SCF_OP_ADD ] = _x64_rcg_add_handler,
+ [SCF_OP_SUB ] = _x64_rcg_sub_handler,
- {SCF_OP_BIT_AND, _x64_rcg_bit_and_handler},
- {SCF_OP_BIT_OR, _x64_rcg_bit_or_handler},
+ [SCF_OP_SHL ] = _x64_rcg_shl_handler,
+ [SCF_OP_SHR ] = _x64_rcg_shr_handler,
- {SCF_OP_EQ, _x64_rcg_eq_handler},
- {SCF_OP_NE, _x64_rcg_ne_handler},
- {SCF_OP_GT, _x64_rcg_gt_handler},
- {SCF_OP_LT, _x64_rcg_lt_handler},
+ [SCF_OP_BIT_AND ] = _x64_rcg_bit_and_handler,
+ [SCF_OP_BIT_OR ] = _x64_rcg_bit_or_handler,
- {SCF_OP_ASSIGN, _x64_rcg_assign_handler},
- {SCF_OP_ADD_ASSIGN, _x64_rcg_add_assign_handler},
- {SCF_OP_SUB_ASSIGN, _x64_rcg_sub_assign_handler},
+ [SCF_OP_EQ ] = _x64_rcg_eq_handler,
+ [SCF_OP_NE ] = _x64_rcg_ne_handler,
+ [SCF_OP_GT ] = _x64_rcg_gt_handler,
+ [SCF_OP_LT ] = _x64_rcg_lt_handler,
- {SCF_OP_MUL_ASSIGN, _x64_rcg_mul_assign_handler},
- {SCF_OP_DIV_ASSIGN, _x64_rcg_div_assign_handler},
- {SCF_OP_MOD_ASSIGN, _x64_rcg_mod_assign_handler},
+ [SCF_OP_ASSIGN ] = _x64_rcg_assign_handler,
+ [SCF_OP_ADD_ASSIGN ] = _x64_rcg_add_assign_handler,
+ [SCF_OP_SUB_ASSIGN ] = _x64_rcg_sub_assign_handler,
- {SCF_OP_SHL_ASSIGN, _x64_rcg_shl_assign_handler},
- {SCF_OP_SHR_ASSIGN, _x64_rcg_shr_assign_handler},
+ [SCF_OP_MUL_ASSIGN ] = _x64_rcg_mul_assign_handler,
+ [SCF_OP_DIV_ASSIGN ] = _x64_rcg_div_assign_handler,
+ [SCF_OP_MOD_ASSIGN ] = _x64_rcg_mod_assign_handler,
- {SCF_OP_AND_ASSIGN, _x64_rcg_and_assign_handler},
- {SCF_OP_OR_ASSIGN, _x64_rcg_or_assign_handler},
+ [SCF_OP_SHL_ASSIGN ] = _x64_rcg_shl_assign_handler,
+ [SCF_OP_SHR_ASSIGN ] = _x64_rcg_shr_assign_handler,
- {SCF_OP_RETURN, _x64_rcg_return_handler},
+ [SCF_OP_AND_ASSIGN ] = _x64_rcg_and_assign_handler,
+ [SCF_OP_OR_ASSIGN ] = _x64_rcg_or_assign_handler,
- {SCF_OP_3AC_CMP, _x64_rcg_cmp_handler},
- {SCF_OP_3AC_TEQ, _x64_rcg_teq_handler},
+ [SCF_OP_RETURN ] = _x64_rcg_return_handler,
- {SCF_OP_3AC_SETZ, _x64_rcg_setz_handler},
- {SCF_OP_3AC_SETNZ, _x64_rcg_setnz_handler},
- {SCF_OP_3AC_SETGT, _x64_rcg_setgt_handler},
- {SCF_OP_3AC_SETGE, _x64_rcg_setge_handler},
- {SCF_OP_3AC_SETLT, _x64_rcg_setlt_handler},
- {SCF_OP_3AC_SETLE, _x64_rcg_setle_handler},
+ [SCF_OP_3AC_CMP ] = _x64_rcg_cmp_handler,
+ [SCF_OP_3AC_TEQ ] = _x64_rcg_teq_handler,
- {SCF_OP_GOTO, _x64_rcg_goto_handler},
- {SCF_OP_3AC_JZ, _x64_rcg_jz_handler},
- {SCF_OP_3AC_JNZ, _x64_rcg_jnz_handler},
- {SCF_OP_3AC_JGT, _x64_rcg_jgt_handler},
- {SCF_OP_3AC_JGE, _x64_rcg_jge_handler},
- {SCF_OP_3AC_JLT, _x64_rcg_jlt_handler},
- {SCF_OP_3AC_JLE, _x64_rcg_jle_handler},
+ [SCF_OP_3AC_SETZ ] = _x64_rcg_setz_handler,
+ [SCF_OP_3AC_SETNZ ] = _x64_rcg_setnz_handler,
+ [SCF_OP_3AC_SETGT ] = _x64_rcg_setgt_handler,
+ [SCF_OP_3AC_SETGE ] = _x64_rcg_setge_handler,
+ [SCF_OP_3AC_SETLT ] = _x64_rcg_setlt_handler,
+ [SCF_OP_3AC_SETLE ] = _x64_rcg_setle_handler,
- {SCF_OP_3AC_JA, _x64_rcg_ja_handler},
- {SCF_OP_3AC_JAE, _x64_rcg_jae_handler},
- {SCF_OP_3AC_JB, _x64_rcg_jb_handler},
- {SCF_OP_3AC_JBE, _x64_rcg_jbe_handler},
+ [SCF_OP_GOTO ] = _x64_rcg_goto_handler,
+ [SCF_OP_3AC_JZ ] = _x64_rcg_jz_handler,
+ [SCF_OP_3AC_JNZ ] = _x64_rcg_jnz_handler,
+ [SCF_OP_3AC_JGT ] = _x64_rcg_jgt_handler,
+ [SCF_OP_3AC_JGE ] = _x64_rcg_jge_handler,
+ [SCF_OP_3AC_JLT ] = _x64_rcg_jlt_handler,
+ [SCF_OP_3AC_JLE ] = _x64_rcg_jle_handler,
- {SCF_OP_3AC_SAVE, _x64_rcg_save_handler},
- {SCF_OP_3AC_LOAD, _x64_rcg_load_handler},
+ [SCF_OP_3AC_JA ] = _x64_rcg_ja_handler,
+ [SCF_OP_3AC_JAE ] = _x64_rcg_jae_handler,
+ [SCF_OP_3AC_JB ] = _x64_rcg_jb_handler,
+ [SCF_OP_3AC_JBE ] = _x64_rcg_jbe_handler,
- {SCF_OP_3AC_RESAVE, _x64_rcg_save_handler},
- {SCF_OP_3AC_RELOAD, _x64_rcg_load_handler},
+ [SCF_OP_3AC_SAVE ] = _x64_rcg_save_handler,
+ [SCF_OP_3AC_LOAD ] = _x64_rcg_load_handler,
- {SCF_OP_3AC_NOP, _x64_rcg_nop_handler},
- {SCF_OP_3AC_END, _x64_rcg_end_handler},
+ [SCF_OP_3AC_RESAVE ] = _x64_rcg_save_handler,
+ [SCF_OP_3AC_RELOAD ] = _x64_rcg_load_handler,
- {SCF_OP_3AC_INC, _x64_rcg_inc_handler},
- {SCF_OP_3AC_DEC, _x64_rcg_dec_handler},
+ [SCF_OP_3AC_NOP ] = _x64_rcg_nop_handler,
+ [SCF_OP_3AC_END ] = _x64_rcg_end_handler,
- {SCF_OP_3AC_PUSH_RAX, _x64_rcg_push_rax_handler},
- {SCF_OP_3AC_POP_RAX, _x64_rcg_pop_rax_handler},
+ [SCF_OP_3AC_INC ] = _x64_rcg_inc_handler,
+ [SCF_OP_3AC_DEC ] = _x64_rcg_dec_handler,
- {SCF_OP_3AC_MEMSET, _x64_rcg_memset_handler},
+ [SCF_OP_3AC_PUSH_RAX] = _x64_rcg_push_rax_handler,
+ [SCF_OP_3AC_POP_RAX ] = _x64_rcg_pop_rax_handler,
+ [SCF_OP_3AC_MEMSET ] = _x64_rcg_memset_handler,
- {SCF_OP_3AC_ASSIGN_DEREFERENCE, _x64_rcg_assign_dereference_handler},
- {SCF_OP_3AC_ASSIGN_ARRAY_INDEX, _x64_rcg_assign_array_index_handler},
- {SCF_OP_3AC_ASSIGN_POINTER, _x64_rcg_assign_pointer_handler},
+ [SCF_OP_3AC_ASSIGN_DEREFERENCE ] = _x64_rcg_assign_dereference_handler,
+ [SCF_OP_3AC_ASSIGN_ARRAY_INDEX ] = _x64_rcg_assign_array_index_handler,
+ [SCF_OP_3AC_ASSIGN_POINTER ] = _x64_rcg_assign_pointer_handler,
- {SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE, _x64_rcg_add_assign_dereference_handler},
- {SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX, _x64_rcg_add_assign_array_index_handler},
- {SCF_OP_3AC_ADD_ASSIGN_POINTER, _x64_rcg_add_assign_pointer_handler},
+ [SCF_OP_3AC_ADD_ASSIGN_DEREFERENCE] = _x64_rcg_add_assign_dereference_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_ARRAY_INDEX] = _x64_rcg_add_assign_array_index_handler,
+ [SCF_OP_3AC_ADD_ASSIGN_POINTER ] = _x64_rcg_add_assign_pointer_handler,
- {SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE, _x64_rcg_sub_assign_dereference_handler},
- {SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX, _x64_rcg_sub_assign_array_index_handler},
- {SCF_OP_3AC_SUB_ASSIGN_POINTER, _x64_rcg_sub_assign_pointer_handler},
+ [SCF_OP_3AC_SUB_ASSIGN_DEREFERENCE] = _x64_rcg_sub_assign_dereference_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_ARRAY_INDEX] = _x64_rcg_sub_assign_array_index_handler,
+ [SCF_OP_3AC_SUB_ASSIGN_POINTER ] = _x64_rcg_sub_assign_pointer_handler,
- {SCF_OP_3AC_AND_ASSIGN_DEREFERENCE, _x64_rcg_and_assign_dereference_handler},
- {SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX, _x64_rcg_and_assign_array_index_handler},
- {SCF_OP_3AC_AND_ASSIGN_POINTER, _x64_rcg_and_assign_pointer_handler},
+ [SCF_OP_3AC_AND_ASSIGN_DEREFERENCE] = _x64_rcg_and_assign_dereference_handler,
+ [SCF_OP_3AC_AND_ASSIGN_ARRAY_INDEX] = _x64_rcg_and_assign_array_index_handler,
+ [SCF_OP_3AC_AND_ASSIGN_POINTER ] = _x64_rcg_and_assign_pointer_handler,
- {SCF_OP_3AC_OR_ASSIGN_DEREFERENCE, _x64_rcg_or_assign_dereference_handler},
- {SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX, _x64_rcg_or_assign_array_index_handler},
- {SCF_OP_3AC_OR_ASSIGN_POINTER, _x64_rcg_or_assign_pointer_handler},
+ [SCF_OP_3AC_OR_ASSIGN_DEREFERENCE ] = _x64_rcg_or_assign_dereference_handler,
+ [SCF_OP_3AC_OR_ASSIGN_ARRAY_INDEX ] = _x64_rcg_or_assign_array_index_handler,
+ [SCF_OP_3AC_OR_ASSIGN_POINTER ] = _x64_rcg_or_assign_pointer_handler,
- {SCF_OP_3AC_INC_DEREFERENCE, _x64_rcg_inc_dereference_handler},
- {SCF_OP_3AC_INC_ARRAY_INDEX, _x64_rcg_inc_array_index_handler},
- {SCF_OP_3AC_INC_POINTER, _x64_rcg_inc_pointer_handler},
+ [SCF_OP_3AC_INC_DEREFERENCE ] = _x64_rcg_inc_dereference_handler,
+ [SCF_OP_3AC_INC_ARRAY_INDEX ] = _x64_rcg_inc_array_index_handler,
+ [SCF_OP_3AC_INC_POINTER ] = _x64_rcg_inc_pointer_handler,
- {SCF_OP_3AC_INC_POST_DEREFERENCE, _x64_rcg_inc_post_dereference_handler},
- {SCF_OP_3AC_INC_POST_ARRAY_INDEX, _x64_rcg_inc_post_array_index_handler},
- {SCF_OP_3AC_INC_POST_POINTER, _x64_rcg_inc_post_pointer_handler},
+ [SCF_OP_3AC_INC_POST_DEREFERENCE ] = _x64_rcg_inc_post_dereference_handler,
+ [SCF_OP_3AC_INC_POST_ARRAY_INDEX ] = _x64_rcg_inc_post_array_index_handler,
+ [SCF_OP_3AC_INC_POST_POINTER ] = _x64_rcg_inc_post_pointer_handler,
- {SCF_OP_3AC_DEC_DEREFERENCE, _x64_rcg_dec_dereference_handler},
- {SCF_OP_3AC_DEC_ARRAY_INDEX, _x64_rcg_dec_array_index_handler},
- {SCF_OP_3AC_DEC_POINTER, _x64_rcg_dec_pointer_handler},
+ [SCF_OP_3AC_DEC_DEREFERENCE ] = _x64_rcg_dec_dereference_handler,
+ [SCF_OP_3AC_DEC_ARRAY_INDEX ] = _x64_rcg_dec_array_index_handler,
+ [SCF_OP_3AC_DEC_POINTER ] = _x64_rcg_dec_pointer_handler,
- {SCF_OP_3AC_DEC_POST_DEREFERENCE, _x64_rcg_dec_post_dereference_handler},
- {SCF_OP_3AC_DEC_POST_ARRAY_INDEX, _x64_rcg_dec_post_array_index_handler},
- {SCF_OP_3AC_DEC_POST_POINTER, _x64_rcg_dec_post_pointer_handler},
+ [SCF_OP_3AC_DEC_POST_DEREFERENCE ] = _x64_rcg_dec_post_dereference_handler,
+ [SCF_OP_3AC_DEC_POST_ARRAY_INDEX ] = _x64_rcg_dec_post_array_index_handler,
+ [SCF_OP_3AC_DEC_POST_POINTER ] = _x64_rcg_dec_post_pointer_handler,
- {SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX, _x64_rcg_address_of_array_index_handler},
- {SCF_OP_3AC_ADDRESS_OF_POINTER, _x64_rcg_address_of_pointer_handler},
+ [SCF_OP_3AC_ADDRESS_OF_ARRAY_INDEX] = _x64_rcg_address_of_array_index_handler,
+ [SCF_OP_3AC_ADDRESS_OF_POINTER ] = _x64_rcg_address_of_pointer_handler,
};
-x64_rcg_handler_t* scf_x64_find_rcg_handler(const int op_type)
+x64_rcg_handler_pt scf_x64_find_rcg_handler(const int op_type)
{
- int i;
- for (i = 0; i < sizeof(x64_rcg_handlers) / sizeof(x64_rcg_handlers[0]); i++) {
-
- x64_rcg_handler_t* h = &(x64_rcg_handlers[i]);
+ if (op_type < 0 || op_type >= SCF_N_3AC_OPS)
+ return NULL;
- if (op_type == h->type)
- return h;
- }
- return NULL;
+ return x64_rcg_handlers[op_type];
}
scf_register_t* rb = NULL;
scf_variable_t* vb = base->var;
- scf_logw("base->color: %ld\n", base->color);
+ scf_logd("base->color: %ld\n", base->color);
int ret = x64_select_reg(&rb, base, c, f, 1);
if (ret < 0) {
scf_loge("\n");
return ret;
}
- scf_logw("base->color: %ld\n", base->color);
+ scf_logd("base->color: %ld\n", base->color);
if (vb->nb_pointers + vb->nb_dimentions > 1 || vb->type >= SCF_STRUCT)
sib->size = 8;
}
}
- scf_operator_handler_t* h = scf_find_const_operator_handler(op->type);
+ scf_operator_handler_pt h = scf_find_const_operator_handler(op->type);
if (!h)
return -1;
- return h->func(ast, node->nodes, node->nb_nodes, d);
+ return h(ast, node->nodes, node->nb_nodes, d);
}
static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void* data)
}
}
- scf_operator_handler_t* h = scf_find_const_operator_handler(node->op->type);
+ scf_operator_handler_pt h = scf_find_const_operator_handler(node->op->type);
if (!h) {
scf_loge("\n");
return -1;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
return -1;
}
}
}
- scf_operator_handler_t* h = scf_find_const_operator_handler(node->op->type);
+ scf_operator_handler_pt h = scf_find_const_operator_handler(node->op->type);
if (!h) {
scf_loge("\n");
return -1;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
return -1;
}
return 0;
}
-scf_operator_handler_t const_operator_handlers[] = {
- {SCF_OP_EXPR, _scf_op_const_expr},
- {SCF_OP_CALL, _scf_op_const_call},
+scf_operator_handler_pt const_operator_handlers[SCF_N_OPS] =
+{
+ [SCF_OP_EXPR ] = _scf_op_const_expr,
+ [SCF_OP_CALL ] = _scf_op_const_call,
- {SCF_OP_ARRAY_INDEX, _scf_op_const_array_index},
- {SCF_OP_POINTER, _scf_op_const_pointer},
- {SCF_OP_CREATE, _scf_op_const_create},
+ [SCF_OP_ARRAY_INDEX] = _scf_op_const_array_index,
+ [SCF_OP_POINTER ] = _scf_op_const_pointer,
+ [SCF_OP_CREATE ] = _scf_op_const_create,
- {SCF_OP_VA_START, _scf_op_const_va_start},
- {SCF_OP_VA_ARG, _scf_op_const_va_arg},
- {SCF_OP_VA_END, _scf_op_const_va_end},
+ [SCF_OP_VA_START ] = _scf_op_const_va_start,
+ [SCF_OP_VA_ARG ] = _scf_op_const_va_arg,
+ [SCF_OP_VA_END ] = _scf_op_const_va_end,
- {SCF_OP_SIZEOF, _scf_op_const_sizeof},
- {SCF_OP_TYPE_CAST, _scf_op_const_type_cast},
- {SCF_OP_LOGIC_NOT, _scf_op_const_logic_not},
- {SCF_OP_BIT_NOT, _scf_op_const_bit_not},
- {SCF_OP_NEG, _scf_op_const_neg},
- {SCF_OP_POSITIVE, _scf_op_const_positive},
+ [SCF_OP_SIZEOF ] = _scf_op_const_sizeof,
+ [SCF_OP_TYPE_CAST ] = _scf_op_const_type_cast,
+ [SCF_OP_LOGIC_NOT ] = _scf_op_const_logic_not,
+ [SCF_OP_BIT_NOT ] = _scf_op_const_bit_not,
+ [SCF_OP_NEG ] = _scf_op_const_neg,
+ [SCF_OP_POSITIVE ] = _scf_op_const_positive,
- {SCF_OP_INC, _scf_op_const_inc},
- {SCF_OP_DEC, _scf_op_const_dec},
+ [SCF_OP_INC ] = _scf_op_const_inc,
+ [SCF_OP_DEC ] = _scf_op_const_dec,
- {SCF_OP_INC_POST, _scf_op_const_inc_post},
- {SCF_OP_DEC_POST, _scf_op_const_dec_post},
+ [SCF_OP_INC_POST ] = _scf_op_const_inc_post,
+ [SCF_OP_DEC_POST ] = _scf_op_const_dec_post,
- {SCF_OP_DEREFERENCE, _scf_op_const_dereference},
- {SCF_OP_ADDRESS_OF, _scf_op_const_address_of},
+ [SCF_OP_DEREFERENCE] = _scf_op_const_dereference,
+ [SCF_OP_ADDRESS_OF ] = _scf_op_const_address_of,
- {SCF_OP_MUL, _scf_op_const_mul},
- {SCF_OP_DIV, _scf_op_const_div},
- {SCF_OP_MOD, _scf_op_const_mod},
+ [SCF_OP_MUL ] = _scf_op_const_mul,
+ [SCF_OP_DIV ] = _scf_op_const_div,
+ [SCF_OP_MOD ] = _scf_op_const_mod,
- {SCF_OP_ADD, _scf_op_const_add},
- {SCF_OP_SUB, _scf_op_const_sub},
+ [SCF_OP_ADD ] = _scf_op_const_add,
+ [SCF_OP_SUB ] = _scf_op_const_sub,
- {SCF_OP_SHL, _scf_op_const_shl},
- {SCF_OP_SHR, _scf_op_const_shr},
+ [SCF_OP_SHL ] = _scf_op_const_shl,
+ [SCF_OP_SHR ] = _scf_op_const_shr,
- {SCF_OP_BIT_AND, _scf_op_const_bit_and},
- {SCF_OP_BIT_OR, _scf_op_const_bit_or},
+ [SCF_OP_BIT_AND ] = _scf_op_const_bit_and,
+ [SCF_OP_BIT_OR ] = _scf_op_const_bit_or,
- {SCF_OP_EQ, _scf_op_const_eq},
- {SCF_OP_NE, _scf_op_const_ne},
- {SCF_OP_GT, _scf_op_const_gt},
- {SCF_OP_LT, _scf_op_const_lt},
- {SCF_OP_GE, _scf_op_const_ge},
- {SCF_OP_LE, _scf_op_const_le},
+ [SCF_OP_EQ ] = _scf_op_const_eq,
+ [SCF_OP_NE ] = _scf_op_const_ne,
+ [SCF_OP_GT ] = _scf_op_const_gt,
+ [SCF_OP_LT ] = _scf_op_const_lt,
+ [SCF_OP_GE ] = _scf_op_const_ge,
+ [SCF_OP_LE ] = _scf_op_const_le,
- {SCF_OP_LOGIC_AND, _scf_op_const_logic_and},
- {SCF_OP_LOGIC_OR, _scf_op_const_logic_or},
+ [SCF_OP_LOGIC_AND ] = _scf_op_const_logic_and,
+ [SCF_OP_LOGIC_OR ] = _scf_op_const_logic_or,
- {SCF_OP_ASSIGN, _scf_op_const_assign},
- {SCF_OP_ADD_ASSIGN, _scf_op_const_add_assign},
- {SCF_OP_SUB_ASSIGN, _scf_op_const_sub_assign},
- {SCF_OP_MUL_ASSIGN, _scf_op_const_mul_assign},
- {SCF_OP_DIV_ASSIGN, _scf_op_const_div_assign},
- {SCF_OP_MOD_ASSIGN, _scf_op_const_mod_assign},
- {SCF_OP_SHL_ASSIGN, _scf_op_const_shl_assign},
- {SCF_OP_SHR_ASSIGN, _scf_op_const_shr_assign},
- {SCF_OP_AND_ASSIGN, _scf_op_const_and_assign},
- {SCF_OP_OR_ASSIGN, _scf_op_const_or_assign},
+ [SCF_OP_ASSIGN ] = _scf_op_const_assign,
+ [SCF_OP_ADD_ASSIGN ] = _scf_op_const_add_assign,
+ [SCF_OP_SUB_ASSIGN ] = _scf_op_const_sub_assign,
+ [SCF_OP_MUL_ASSIGN ] = _scf_op_const_mul_assign,
+ [SCF_OP_DIV_ASSIGN ] = _scf_op_const_div_assign,
+ [SCF_OP_MOD_ASSIGN ] = _scf_op_const_mod_assign,
+ [SCF_OP_SHL_ASSIGN ] = _scf_op_const_shl_assign,
+ [SCF_OP_SHR_ASSIGN ] = _scf_op_const_shr_assign,
+ [SCF_OP_AND_ASSIGN ] = _scf_op_const_and_assign,
+ [SCF_OP_OR_ASSIGN ] = _scf_op_const_or_assign,
- {SCF_OP_BLOCK, _scf_op_const_block},
- {SCF_OP_RETURN, _scf_op_const_return},
- {SCF_OP_BREAK, _scf_op_const_break},
- {SCF_OP_CONTINUE, _scf_op_const_continue},
- {SCF_OP_GOTO, _scf_op_const_goto},
- {SCF_LABEL, _scf_op_const_label},
+ [SCF_OP_BLOCK ] = _scf_op_const_block,
+ [SCF_OP_RETURN ] = _scf_op_const_return,
+ [SCF_OP_BREAK ] = _scf_op_const_break,
+ [SCF_OP_CONTINUE ] = _scf_op_const_continue,
+ [SCF_OP_GOTO ] = _scf_op_const_goto,
+ [SCF_LABEL ] = _scf_op_const_label,
- {SCF_OP_IF, _scf_op_const_if},
- {SCF_OP_WHILE, _scf_op_const_while},
- {SCF_OP_DO, _scf_op_const_do},
- {SCF_OP_FOR, _scf_op_const_for},
+ [SCF_OP_IF ] = _scf_op_const_if,
+ [SCF_OP_WHILE ] = _scf_op_const_while,
+ [SCF_OP_DO ] = _scf_op_const_do,
+ [SCF_OP_FOR ] = _scf_op_const_for,
- {SCF_OP_SWITCH, _scf_op_const_switch},
- {SCF_OP_CASE, _scf_op_const_case},
- {SCF_OP_DEFAULT, _scf_op_const_default},
+ [SCF_OP_SWITCH ] = _scf_op_const_switch,
+ [SCF_OP_CASE ] = _scf_op_const_case,
+ [SCF_OP_DEFAULT ] = _scf_op_const_default,
};
-scf_operator_handler_t* scf_find_const_operator_handler(const int type)
+scf_operator_handler_pt scf_find_const_operator_handler(const int type)
{
- int i;
- for (i = 0; i < sizeof(const_operator_handlers) / sizeof(const_operator_handlers[0]); i++) {
-
- scf_operator_handler_t* h = &const_operator_handlers[i];
-
- if (type == h->type)
- return h;
- }
+ if (type < 0 || type >= SCF_N_OPS)
+ return NULL;
- return NULL;
+ return const_operator_handlers[type];
}
int scf_function_const_opt(scf_ast_t* ast, scf_function_t* f)
#include"scf_operator_handler.h"
-scf_operator_handler_t* scf_find_const_operator_handler(const int type);
+scf_operator_handler_pt scf_find_const_operator_handler(const int type);
int scf_function_const_opt(scf_ast_t* ast, scf_function_t* f);
scf_variable_t** pret;
} scf_handler_data_t;
-scf_operator_handler_t* scf_find_expr_operator_handler(const int type, const int src0_type, const int src1_type, const int ret_type);
+scf_operator_handler_pt scf_find_expr_operator_handler(const int type);
static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void* data)
{
if (0 == node->nb_nodes) {
assert(scf_type_is_var(node->type));
- if (scf_type_is_var(node->type) && node->var->w) {
+ if (scf_type_is_var(node->type) && node->var->w)
scf_logd("w: %s\n", node->var->w->text->data);
- }
+
return 0;
}
}
}
- scf_handler_data_t* d = data;
-
+ scf_handler_data_t* d = data;
int i;
if (SCF_OP_ASSOCIATIVITY_LEFT == node->op->associativity) {
}
}
- scf_operator_handler_t* h = scf_find_expr_operator_handler(node->op->type, -1, -1, -1);
+ scf_operator_handler_pt h = scf_find_expr_operator_handler(node->op->type);
if (!h) {
scf_loge("\n");
goto _error;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
goto _error;
}
}
}
- scf_operator_handler_t* h = scf_find_expr_operator_handler(node->op->type, -1, -1, -1);
+ scf_operator_handler_pt h = scf_find_expr_operator_handler(node->op->type);
if (!h) {
scf_loge("\n");
goto _error;
}
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0) {
scf_loge("\n");
goto _error;
}
return _scf_op_expr_binary(ast, nodes, nb_nodes, data);
}
-scf_operator_handler_t expr_operator_handlers[] = {
-
- {SCF_OP_EXPR, _scf_op_expr_expr},
+scf_operator_handler_pt expr_operator_handlers[SCF_N_OPS] =
+{
+ [SCF_OP_EXPR ] = _scf_op_expr_expr,
- {SCF_OP_ARRAY_INDEX, _scf_op_expr_array_index},
- {SCF_OP_POINTER, _scf_op_expr_pointer},
+ [SCF_OP_ARRAY_INDEX] = _scf_op_expr_array_index,
+ [SCF_OP_POINTER ] = _scf_op_expr_pointer,
- {SCF_OP_SIZEOF, _scf_op_expr_sizeof},
- {SCF_OP_TYPE_CAST, _scf_op_expr_type_cast},
- {SCF_OP_LOGIC_NOT, _scf_op_expr_logic_not},
- {SCF_OP_BIT_NOT, _scf_op_expr_bit_not},
- {SCF_OP_NEG, _scf_op_expr_neg},
+ [SCF_OP_SIZEOF ] = _scf_op_expr_sizeof,
+ [SCF_OP_TYPE_CAST ] = _scf_op_expr_type_cast,
+ [SCF_OP_LOGIC_NOT ] = _scf_op_expr_logic_not,
+ [SCF_OP_BIT_NOT ] = _scf_op_expr_bit_not,
+ [SCF_OP_NEG ] = _scf_op_expr_neg,
- {SCF_OP_ADDRESS_OF, _scf_op_expr_address_of},
+ [SCF_OP_ADDRESS_OF ] = _scf_op_expr_address_of,
- {SCF_OP_MUL, _scf_op_expr_mul},
- {SCF_OP_DIV, _scf_op_expr_div},
- {SCF_OP_MOD, _scf_op_expr_mod},
+ [SCF_OP_MUL ] = _scf_op_expr_mul,
+ [SCF_OP_DIV ] = _scf_op_expr_div,
+ [SCF_OP_MOD ] = _scf_op_expr_mod,
- {SCF_OP_ADD, _scf_op_expr_add},
- {SCF_OP_SUB, _scf_op_expr_sub},
+ [SCF_OP_ADD ] = _scf_op_expr_add,
+ [SCF_OP_SUB ] = _scf_op_expr_sub,
- {SCF_OP_SHL, _scf_op_expr_shl},
- {SCF_OP_SHR, _scf_op_expr_shr},
+ [SCF_OP_SHL ] = _scf_op_expr_shl,
+ [SCF_OP_SHR ] = _scf_op_expr_shr,
- {SCF_OP_BIT_AND, _scf_op_expr_bit_and},
- {SCF_OP_BIT_OR, _scf_op_expr_bit_or},
+ [SCF_OP_BIT_AND ] = _scf_op_expr_bit_and,
+ [SCF_OP_BIT_OR ] = _scf_op_expr_bit_or,
- {SCF_OP_EQ, _scf_op_expr_eq},
- {SCF_OP_NE, _scf_op_expr_ne},
- {SCF_OP_GT, _scf_op_expr_gt},
- {SCF_OP_LT, _scf_op_expr_lt},
- {SCF_OP_GE, _scf_op_expr_ge},
- {SCF_OP_LE, _scf_op_expr_le},
+ [SCF_OP_EQ ] = _scf_op_expr_eq,
+ [SCF_OP_NE ] = _scf_op_expr_ne,
+ [SCF_OP_GT ] = _scf_op_expr_gt,
+ [SCF_OP_LT ] = _scf_op_expr_lt,
+ [SCF_OP_GE ] = _scf_op_expr_ge,
+ [SCF_OP_LE ] = _scf_op_expr_le,
- {SCF_OP_LOGIC_AND, _scf_op_expr_logic_and},
- {SCF_OP_LOGIC_OR, _scf_op_expr_logic_or},
+ [SCF_OP_LOGIC_AND ] = _scf_op_expr_logic_and,
+ [SCF_OP_LOGIC_OR ] = _scf_op_expr_logic_or,
- {SCF_OP_ASSIGN, _scf_op_expr_assign},
+ [SCF_OP_ASSIGN ] = _scf_op_expr_assign,
};
-scf_operator_handler_t* scf_find_expr_operator_handler(const int type, const int src0_type, const int src1_type, const int ret_type)
+scf_operator_handler_pt scf_find_expr_operator_handler(const int type)
{
- int i;
- for (i = 0; i < sizeof(expr_operator_handlers) / sizeof(expr_operator_handlers[0]); i++) {
-
- scf_operator_handler_t* h = &expr_operator_handlers[i];
-
- if (type == h->type)
- return h;
- }
+ if (type < 0 || type >= SCF_N_OPS)
+ return NULL;
- return NULL;
+ return expr_operator_handlers[type];
}
int scf_expr_calculate(scf_ast_t* ast, scf_expr_t* e, scf_variable_t** pret)
}
}
- scf_operator_handler_t* h = scf_find_semantic_operator_handler(op->type);
+ scf_operator_handler_pt h = scf_find_semantic_operator_handler(op->type);
if (!h) {
scf_loge("\n");
return -1;
scf_variable_t** pret = d->pret;
d->pret = &node->result;
- int ret = h->func(ast, node->nodes, node->nb_nodes, d);
+ int ret = h(ast, node->nodes, node->nb_nodes, d);
d->pret = pret;
return ret;
node->result_nodes = NULL;
}
- scf_operator_handler_t* h;
+ scf_operator_handler_pt h;
scf_handler_data_t* d = data;
scf_variable_t** pret = d->pret; // save d->pret, and reload it before return
d->pret = &node->result;
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0)
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0)
goto _error;
} else {
d->pret = &node->result;
- if (h->func(ast, node->nodes, node->nb_nodes, d) < 0)
+ if (h(ast, node->nodes, node->nb_nodes, d) < 0)
goto _error;
}
return 0;
}
-scf_operator_handler_t semantic_operator_handlers[] = {
- {SCF_OP_EXPR, _scf_op_semantic_expr},
- {SCF_OP_CALL, _scf_op_semantic_call},
-
- {SCF_OP_ARRAY_INDEX, _scf_op_semantic_array_index},
- {SCF_OP_POINTER, _scf_op_semantic_pointer},
- {SCF_OP_CREATE, _scf_op_semantic_create},
-
- {SCF_OP_VA_START, _scf_op_semantic_va_start},
- {SCF_OP_VA_ARG, _scf_op_semantic_va_arg},
- {SCF_OP_VA_END, _scf_op_semantic_va_end},
-
- {SCF_OP_CONTAINER, _scf_op_semantic_container},
-
- {SCF_OP_SIZEOF, _scf_op_semantic_sizeof},
- {SCF_OP_TYPE_CAST, _scf_op_semantic_type_cast},
- {SCF_OP_LOGIC_NOT, _scf_op_semantic_logic_not},
- {SCF_OP_BIT_NOT, _scf_op_semantic_bit_not},
- {SCF_OP_NEG, _scf_op_semantic_neg},
- {SCF_OP_POSITIVE, _scf_op_semantic_positive},
-
- {SCF_OP_INC, _scf_op_semantic_inc},
- {SCF_OP_DEC, _scf_op_semantic_dec},
-
- {SCF_OP_INC_POST, _scf_op_semantic_inc_post},
- {SCF_OP_DEC_POST, _scf_op_semantic_dec_post},
-
- {SCF_OP_DEREFERENCE, _scf_op_semantic_dereference},
- {SCF_OP_ADDRESS_OF, _scf_op_semantic_address_of},
-
- {SCF_OP_MUL, _scf_op_semantic_mul},
- {SCF_OP_DIV, _scf_op_semantic_div},
- {SCF_OP_MOD, _scf_op_semantic_mod},
-
- {SCF_OP_ADD, _scf_op_semantic_add},
- {SCF_OP_SUB, _scf_op_semantic_sub},
-
- {SCF_OP_SHL, _scf_op_semantic_shl},
- {SCF_OP_SHR, _scf_op_semantic_shr},
-
- {SCF_OP_BIT_AND, _scf_op_semantic_bit_and},
- {SCF_OP_BIT_OR, _scf_op_semantic_bit_or},
-
- {SCF_OP_EQ, _scf_op_semantic_eq},
- {SCF_OP_NE, _scf_op_semantic_ne},
- {SCF_OP_GT, _scf_op_semantic_gt},
- {SCF_OP_LT, _scf_op_semantic_lt},
- {SCF_OP_GE, _scf_op_semantic_ge},
- {SCF_OP_LE, _scf_op_semantic_le},
-
- {SCF_OP_LOGIC_AND, _scf_op_semantic_logic_and},
- {SCF_OP_LOGIC_OR, _scf_op_semantic_logic_or},
-
- {SCF_OP_ASSIGN, _scf_op_semantic_assign},
- {SCF_OP_ADD_ASSIGN, _scf_op_semantic_add_assign},
- {SCF_OP_SUB_ASSIGN, _scf_op_semantic_sub_assign},
- {SCF_OP_MUL_ASSIGN, _scf_op_semantic_mul_assign},
- {SCF_OP_DIV_ASSIGN, _scf_op_semantic_div_assign},
- {SCF_OP_MOD_ASSIGN, _scf_op_semantic_mod_assign},
- {SCF_OP_SHL_ASSIGN, _scf_op_semantic_shl_assign},
- {SCF_OP_SHR_ASSIGN, _scf_op_semantic_shr_assign},
- {SCF_OP_AND_ASSIGN, _scf_op_semantic_and_assign},
- {SCF_OP_OR_ASSIGN, _scf_op_semantic_or_assign},
-
- {SCF_OP_BLOCK, _scf_op_semantic_block},
- {SCF_OP_RETURN, _scf_op_semantic_return},
- {SCF_OP_BREAK, _scf_op_semantic_break},
- {SCF_OP_CONTINUE, _scf_op_semantic_continue},
- {SCF_OP_GOTO, _scf_op_semantic_goto},
- {SCF_LABEL, _scf_op_semantic_label},
-
- {SCF_OP_IF, _scf_op_semantic_if},
- {SCF_OP_WHILE, _scf_op_semantic_while},
- {SCF_OP_DO, _scf_op_semantic_do},
- {SCF_OP_FOR, _scf_op_semantic_for},
-
- {SCF_OP_SWITCH, _scf_op_semantic_switch},
- {SCF_OP_CASE, _scf_op_semantic_case},
- {SCF_OP_DEFAULT, _scf_op_semantic_default},
-};
-
-scf_operator_handler_t* scf_find_semantic_operator_handler(const int type)
+scf_operator_handler_pt semantic_operator_handlers[SCF_N_OPS] =
{
- int i;
- for (i = 0; i < sizeof(semantic_operator_handlers) / sizeof(semantic_operator_handlers[0]); i++) {
+ [SCF_OP_EXPR ] = _scf_op_semantic_expr,
+ [SCF_OP_CALL ] = _scf_op_semantic_call,
- scf_operator_handler_t* h = &semantic_operator_handlers[i];
+ [SCF_OP_ARRAY_INDEX] = _scf_op_semantic_array_index,
+ [SCF_OP_POINTER ] = _scf_op_semantic_pointer,
+ [SCF_OP_CREATE ] = _scf_op_semantic_create,
- if (type == h->type)
- return h;
- }
+ [SCF_OP_VA_START ] = _scf_op_semantic_va_start,
+ [SCF_OP_VA_ARG ] = _scf_op_semantic_va_arg,
+ [SCF_OP_VA_END ] = _scf_op_semantic_va_end,
+
+ [SCF_OP_CONTAINER ] = _scf_op_semantic_container,
+
+ [SCF_OP_SIZEOF ] = _scf_op_semantic_sizeof,
+ [SCF_OP_TYPE_CAST ] = _scf_op_semantic_type_cast,
+ [SCF_OP_LOGIC_NOT ] = _scf_op_semantic_logic_not,
+ [SCF_OP_BIT_NOT ] = _scf_op_semantic_bit_not,
+ [SCF_OP_NEG ] = _scf_op_semantic_neg,
+ [SCF_OP_POSITIVE ] = _scf_op_semantic_positive,
+
+ [SCF_OP_INC ] = _scf_op_semantic_inc,
+ [SCF_OP_DEC ] = _scf_op_semantic_dec,
+
+ [SCF_OP_INC_POST ] = _scf_op_semantic_inc_post,
+ [SCF_OP_DEC_POST ] = _scf_op_semantic_dec_post,
+
+ [SCF_OP_DEREFERENCE] = _scf_op_semantic_dereference,
+ [SCF_OP_ADDRESS_OF ] = _scf_op_semantic_address_of,
+
+ [SCF_OP_MUL ] = _scf_op_semantic_mul,
+ [SCF_OP_DIV ] = _scf_op_semantic_div,
+ [SCF_OP_MOD ] = _scf_op_semantic_mod,
+
+ [SCF_OP_ADD ] = _scf_op_semantic_add,
+ [SCF_OP_SUB ] = _scf_op_semantic_sub,
+
+ [SCF_OP_SHL ] = _scf_op_semantic_shl,
+ [SCF_OP_SHR ] = _scf_op_semantic_shr,
+
+ [SCF_OP_BIT_AND ] = _scf_op_semantic_bit_and,
+ [SCF_OP_BIT_OR ] = _scf_op_semantic_bit_or,
+
+ [SCF_OP_EQ ] = _scf_op_semantic_eq,
+ [SCF_OP_NE ] = _scf_op_semantic_ne,
+ [SCF_OP_GT ] = _scf_op_semantic_gt,
+ [SCF_OP_LT ] = _scf_op_semantic_lt,
+ [SCF_OP_GE ] = _scf_op_semantic_ge,
+ [SCF_OP_LE ] = _scf_op_semantic_le,
+
+ [SCF_OP_LOGIC_AND ] = _scf_op_semantic_logic_and,
+ [SCF_OP_LOGIC_OR ] = _scf_op_semantic_logic_or,
+
+ [SCF_OP_ASSIGN ] = _scf_op_semantic_assign,
+ [SCF_OP_ADD_ASSIGN ] = _scf_op_semantic_add_assign,
+ [SCF_OP_SUB_ASSIGN ] = _scf_op_semantic_sub_assign,
+ [SCF_OP_MUL_ASSIGN ] = _scf_op_semantic_mul_assign,
+ [SCF_OP_DIV_ASSIGN ] = _scf_op_semantic_div_assign,
+ [SCF_OP_MOD_ASSIGN ] = _scf_op_semantic_mod_assign,
+ [SCF_OP_SHL_ASSIGN ] = _scf_op_semantic_shl_assign,
+ [SCF_OP_SHR_ASSIGN ] = _scf_op_semantic_shr_assign,
+ [SCF_OP_AND_ASSIGN ] = _scf_op_semantic_and_assign,
+ [SCF_OP_OR_ASSIGN ] = _scf_op_semantic_or_assign,
+
+ [SCF_OP_BLOCK ] = _scf_op_semantic_block,
+ [SCF_OP_RETURN ] = _scf_op_semantic_return,
+ [SCF_OP_BREAK ] = _scf_op_semantic_break,
+ [SCF_OP_CONTINUE ] = _scf_op_semantic_continue,
+ [SCF_OP_GOTO ] = _scf_op_semantic_goto,
+ [SCF_LABEL ] = _scf_op_semantic_label,
+
+ [SCF_OP_IF ] = _scf_op_semantic_if,
+ [SCF_OP_WHILE ] = _scf_op_semantic_while,
+ [SCF_OP_DO ] = _scf_op_semantic_do,
+ [SCF_OP_FOR ] = _scf_op_semantic_for,
+
+ [SCF_OP_SWITCH ] = _scf_op_semantic_switch,
+ [SCF_OP_CASE ] = _scf_op_semantic_case,
+ [SCF_OP_DEFAULT ] = _scf_op_semantic_default,
+};
+
+scf_operator_handler_pt scf_find_semantic_operator_handler(const int type)
+{
+ if (type < 0 || type >= SCF_N_OPS)
+ return NULL;
- return NULL;
+ return semantic_operator_handlers[type];
}
int scf_function_semantic_analysis(scf_ast_t* ast, scf_function_t* f)
#include"scf_operator_handler.h"
-scf_operator_handler_t* scf_find_semantic_operator_handler(const int type);
+scf_operator_handler_pt scf_find_semantic_operator_handler(const int type);
int scf_function_semantic_analysis(scf_ast_t* ast, scf_function_t* f);