optimize operator handlers
authoryu.dongliang <18588496441@163.com>
Mon, 7 Oct 2024 05:08:08 +0000 (13:08 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 7 Oct 2024 05:08:08 +0000 (13:08 +0800)
22 files changed:
core/scf_basic_block.c
core/scf_core_types.h
core/scf_dag.c
core/scf_dag.h
core/scf_operator_handler.h
core/scf_operator_handler_3ac.c
core/scf_optimizer_pointer_alias.c
native/risc/scf_risc.c
native/risc/scf_risc.h
native/risc/scf_risc_inst.c
native/risc/scf_risc_rcg.c
native/scf_native.h
native/x64/scf_x64.c
native/x64/scf_x64.h
native/x64/scf_x64_inst.c
native/x64/scf_x64_rcg.c
native/x64/scf_x64_reg.c
parse/scf_operator_handler_const.c
parse/scf_operator_handler_const.h
parse/scf_operator_handler_expr.c
parse/scf_operator_handler_semantic.c
parse/scf_operator_handler_semantic.h

index d0ac7abe308c7df422088c2d70d34583705b9675..b207148b98bc045dc217a1b436cf3c2d2577b8f5 100644 (file)
@@ -852,9 +852,13 @@ static int _bb_init_array_index(scf_3ac_code_t* c, scf_basic_block_t* bb, scf_li
 
 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;
@@ -894,6 +898,56 @@ int scf_basic_block_inited_vars(scf_basic_block_t* bb, scf_list_t* bb_list_head)
                                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--;
+                               }
+                       }
                }
        }
 
index 005222e90ce736eef985e1dee87d072b35fe7e15..956acab6772ab0321114c4bd84ebdb0fb4a0a246 100644 (file)
@@ -28,7 +28,8 @@ typedef struct scf_ecomponent_s  ScfEcomponent;
 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,         // *
@@ -115,6 +116,9 @@ enum scf_core_types {
        SCF_OP_CONTINUE,        // continue statement
        SCF_OP_ASYNC,       // async statement
 
+       SCF_LABEL,          // label
+       SCF_OP_GOTO,        // goto statement
+
        SCF_N_OPS, // total operators
 
        // 58
@@ -202,7 +206,6 @@ enum scf_core_types {
        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
@@ -232,8 +235,6 @@ enum scf_core_types {
        SCF_VAR_DOUBLE,         // double variable
 
 
-       SCF_LABEL,                      // label
-
        SCF_FUNCTION,           // function
 
        SCF_STRUCT,                     // struct type defined by user
@@ -296,7 +297,7 @@ static int scf_type_is_var(int type)
 
 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)
index 209d8ece7a637a150cd5692bfd88e5c0cba95ae3..3b3c273af04a9eecd53333aee829524772da2481 100644 (file)
@@ -11,14 +11,30 @@ scf_dn_index_t* scf_dn_index_alloc()
        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)
index 90e6443fc511ffed45f0eadd0ec14c2e1e3c3ecc..c2674a8bf165a20c31a396bf07b82852240f3519 100644 (file)
@@ -81,6 +81,7 @@ struct scf_dn_status_s {
 
 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);
@@ -240,4 +241,3 @@ static inline int scf_ds_nb_pointers(scf_dn_status_t* ds)
        } while (0)
 
 #endif
-
index a545e41d73ad2de7a5ebaf377c4f988bc984691e..97c64c93e20cc60a388e9e27fab845e94649f71b 100644 (file)
@@ -3,17 +3,9 @@
 
 #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);
 
index 6aa7db5b0bb376e6e0174450c64a939b4ab5bdc7..297aaeeeb30153e7d3d23d00aac2c8ad8517de20 100644 (file)
@@ -51,7 +51,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                return 0;
 
        scf_handler_data_t*     d = data;
-       scf_operator_handler_t* h;
+       scf_operator_handler_pt h;
 
        int i;
 
@@ -93,7 +93,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        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) {
@@ -112,7 +112,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        return -1;
                }
 
-               return h->func(ast, node->nodes, node->nb_nodes, d);
+               return h(ast, node->nodes, node->nb_nodes, d);
        }
 
        scf_loge("\n");
@@ -371,7 +371,7 @@ static int _scf_op_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void*
        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);
@@ -405,7 +405,7 @@ static int _scf_op_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void*
                        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;
@@ -704,13 +704,13 @@ static int _scf_op_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data_t* d)
                }
        }
 
-       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;
        }
@@ -2362,95 +2362,90 @@ static int _scf_op_logic_##name(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes
 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];
 }
index 93a9a74c85fb4266592d618ea0d6436a2c58eb10..dd836fd898c14308700353d1663fac8dc9f0e441 100644 (file)
@@ -590,4 +590,3 @@ scf_optimizer_t  scf_optimizer_pointer_alias =
 
        .flags    = SCF_OPTIMIZER_LOCAL,
 };
-
index 0a4c4dd213ff96ea0294a6a75420e9806f2dc3f3..d3481a336fdca44be13f5e47d7ff2e1871c0faec 100644 (file)
@@ -441,9 +441,9 @@ static int _risc_argv_save(scf_basic_block_t* bb, scf_function_t* f)
 
 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)) {
 
@@ -455,7 +455,7 @@ static int _risc_make_bb_rcg(scf_graph_t* g, scf_basic_block_t* bb, scf_native_t
                        return -EINVAL;
                }
 
-               int ret = h->func(ctx, c, g);
+               int ret = h(ctx, c, g);
                if (ret < 0)
                        return ret;
        }
@@ -606,13 +606,13 @@ static int _risc_make_insts_for_list(scf_native_t* ctx, scf_basic_block_t* bb, i
 
                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);
index 3821c12f41a650ce0cca6b53a6d338a0ddd5fa84..40930d26f1b34109d94187bf0a2f512c8f23ecf7 100644 (file)
@@ -60,18 +60,11 @@ typedef struct {
 
 } 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);
index 1f3a94aff7fc2c4c50ebc88f758a8ec0fb24dd0f..fd0c4fd6cd3fcdebf6fd738480358e6ec7545f48 100644 (file)
@@ -5633,158 +5633,153 @@ static int _risc_inst_inc_post_dereference_handler(scf_native_t* ctx, scf_3ac_co
        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)
index f92ca675084445b82a8d52e737e3dcefcf1ca4cd..82eb8e4f744a21db5b484a4688bda86a22ab9c05 100644 (file)
@@ -1127,154 +1127,149 @@ static int _risc_rcg_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c, scf_gr
        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];
 }
index dee18f68a385ee453092914c8cf3407c1bc4f91b..74f68ae9676efc870bc9be9ce55abc18a163d9e0 100644 (file)
@@ -262,7 +262,4 @@ int scf_native_close(scf_native_t* ctx);
 
 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
-
index a010c8f98e5d55d60ec9a2d2d6e27006d79aba82..ed48bea2fdef3b6f30e995e71f435367b3b7e608 100644 (file)
@@ -475,9 +475,9 @@ static int _x64_argv_save(scf_basic_block_t* bb, scf_function_t* f)
 
 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)) {
 
@@ -489,7 +489,7 @@ static int _x64_make_bb_rcg(scf_graph_t* g, scf_basic_block_t* bb, scf_native_t*
                        return -EINVAL;
                }
 
-               int ret = h->func(ctx, c, g);
+               int ret = h(ctx, c, g);
                if (ret < 0)
                        return ret;
        }
@@ -638,13 +638,13 @@ static int _x64_make_insts_for_list(scf_native_t* ctx, scf_list_t* h, int bb_off
 
                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);
index e5ede88a829388366ea72bf10838dfb73788757e..377a9105034193da0513373874bf5bbb7b651293 100644 (file)
@@ -58,18 +58,12 @@ typedef struct {
 
 } 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);
index 05d3e13ba3595f1eaaece22591608fd869ea037a..be0cd86be4a0bbcca2f0edacf913237a3b176ffb 100644 (file)
@@ -1908,7 +1908,6 @@ static int _x64_inst_va_start_handler(scf_native_t* ctx, scf_3ac_code_t* c)
                        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");
@@ -2136,153 +2135,148 @@ static int _x64_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c)
        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];
 }
index 2738ccb2987e10df0950970fed1a44805d01775f..63a6b512fcb5fc4a2d108a1c7b6a3e16af960f1f 100644 (file)
@@ -1229,154 +1229,148 @@ static int _x64_rcg_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c, scf_gra
        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];
 }
index 7494a9bc889e69526027ef319aa5d3e3660b642f..9cde4703dc10406465db767182985002a9c5a8b6 100644 (file)
@@ -1098,14 +1098,14 @@ int x64_dereference_reg(x64_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* me
        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;
index 0d53b21e728e3f5649184baf943cda38cb63bf7a..eba7be0e852baff955c4ec45c0bb7f04992bf8b4 100644 (file)
@@ -24,11 +24,11 @@ static int _scf_op_const_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data
                }
        }
 
-       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)
@@ -75,13 +75,13 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        }
                }
 
-               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;
                }
@@ -94,13 +94,13 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        }
                }
 
-               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;
                }
@@ -902,97 +902,92 @@ static int _scf_op_const_va_end(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes
        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)
index e040bb2a33f4d8dd1dcf162bd27b288d70a7f419..c45143b920d52f5c6d724df4fffd669b871fafc1 100644 (file)
@@ -3,7 +3,7 @@
 
 #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);
 
index 1e42350a8e2186ca1f9e323927adeed717937a5a..edef075f7f90694b0ec94e92eea11fb582d0a562 100644 (file)
@@ -8,7 +8,7 @@ typedef struct {
        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)
 {
@@ -18,9 +18,9 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
        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;
        }
 
@@ -35,8 +35,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                }
        }
 
-       scf_handler_data_t* d    = data;
-
+       scf_handler_data_t* d = data;
        int i;
 
        if (SCF_OP_ASSOCIATIVITY_LEFT == node->op->associativity) {
@@ -49,13 +48,13 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        }
                }
 
-               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;
                }
@@ -68,13 +67,13 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                        }
                }
 
-               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;
                }
@@ -658,59 +657,53 @@ static int _scf_op_expr_bit_or(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes,
        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)
index 182d52f49fcc699f732414b1e06050cd14426a51..7a1294a0e95c267cbc9bc7a4c18fc0e22061fa20 100644 (file)
@@ -23,7 +23,7 @@ static int _scf_op_semantic_node(scf_ast_t* ast, scf_node_t* node, scf_handler_d
                }
        }
 
-       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;
@@ -32,7 +32,7 @@ static int _scf_op_semantic_node(scf_ast_t* ast, scf_node_t* node, scf_handler_d
        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;
@@ -585,7 +585,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
                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
 
@@ -612,7 +612,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
 
                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 {
@@ -636,7 +636,7 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
 
                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;
        }
 
@@ -3082,99 +3082,94 @@ static int _scf_op_semantic_va_end(scf_ast_t* ast, scf_node_t** nodes, int nb_no
        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)
index d35e0a81a2f59dd3a8b61944b829cec61c380420..92ab2e8c12f7db51f3b1a1d6f2bdae4031704540 100644 (file)
@@ -3,7 +3,7 @@
 
 #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);