delete 'bb_list_head' in optimizer callback()
authoryu.dongliang <18588496441@163.com>
Tue, 26 Dec 2023 14:00:35 +0000 (22:00 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 26 Dec 2023 14:00:35 +0000 (22:00 +0800)
20 files changed:
core/scf_optimizer.c
core/scf_optimizer.h
core/scf_optimizer_active_vars.c
core/scf_optimizer_auto_gc.c
core/scf_optimizer_auto_gc_find.c
core/scf_optimizer_basic_block.c
core/scf_optimizer_call.c
core/scf_optimizer_const_teq.c
core/scf_optimizer_dag.c
core/scf_optimizer_dominators.c
core/scf_optimizer_dominators_reverse.c
core/scf_optimizer_generate_loads_saves.c
core/scf_optimizer_group.c
core/scf_optimizer_inline.c
core/scf_optimizer_loads_saves.c
core/scf_optimizer_loop.c
core/scf_optimizer_pointer_alias.c
core/scf_optimizer_pointer_aliases.c
parse/scf_operator_handler_const.c
parse/scf_operator_handler_semantic.c

index b5be44936e8a2fb09da9ef8411389a69004b5a4b..7767467e90b6ea15882abdf8f7e2b6aa4f260f7e 100644 (file)
@@ -132,7 +132,7 @@ int scf_optimize(scf_ast_t* ast, scf_vector_t* functions)
 
                if (SCF_OPTIMIZER_GLOBAL == opt->flags) {
 
-                       int ret = opt->optimize(ast, NULL, NULL, functions);
+                       int ret = opt->optimize(ast, NULL, functions);
                        if (ret < 0) {
                                scf_loge("optimizer: %s\n", opt->name);
                                return ret;
@@ -146,7 +146,7 @@ int scf_optimize(scf_ast_t* ast, scf_vector_t* functions)
                        if (!f->node.define_flag)
                                continue;
 
-                       int ret = opt->optimize(ast, f, &f->basic_block_list_head, NULL);
+                       int ret = opt->optimize(ast, f, NULL);
                        if (ret < 0) {
                                scf_loge("optimizer: %s\n", opt->name);
                                return ret;
index cce5482fabd7c1a079ffe4d9b9d96020c4809f94..dbb3f1bca455212d61e49ad7f308e2b16fa4d5e9 100644 (file)
@@ -14,7 +14,7 @@ struct scf_optimizer_s
 {
        const char*  name;
 
-       int        (*optimize)(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions);
+       int        (*optimize)(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions);
        uint32_t     flags;
 };
 
index 087b854e924f761d0c8ad76d74573e221d834697..809db8451f67e92d7d1994c8dc414481a56b56cf 100644 (file)
@@ -62,23 +62,22 @@ static int _bb_prev_find(scf_basic_block_t* bb, void* data, scf_vector_t* queue)
        return count;
 }
 
-static int _optimize_active_vars(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_active_vars(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
        int count;
        int ret;
-       int i;
 
-       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head);
-                       l = scf_list_next(l)) {
+       if (scf_list_empty(bb_list_head))
+               return 0;
+
+       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_next(l)) {
 
                bb  = scf_list_data(l, scf_basic_block_t, list);
 
index e50f87d390343764238f0044e761c4a1d3ce2bac..ef20342ae3ba20464a112145edc69a2b082054ee 100644 (file)
@@ -1795,14 +1795,15 @@ _end:
        return 0;
 }
 
-static int _optimize_auto_gc(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_auto_gc(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!ast || !f || !bb_list_head)
+       if (!ast || !f)
                return -EINVAL;
 
        if (!strcmp(f->node.w->text->data, "scf__auto_malloc"))
                return 0;
 
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
        scf_basic_block_t* bb2;
index 23fb0dadb822a29bba465d6b1e2c29e3e38968fc..7fdf6235a02e0c81b727c3742aee66e179e85421 100644 (file)
@@ -1097,7 +1097,7 @@ static int _auto_gc_global_find(scf_ast_t* ast, scf_vector_t* functions)
        return 0;
 }
 
-static int _optimize_auto_gc_find(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_auto_gc_find(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
        if (!ast || !functions || functions->size <= 0)
                return -EINVAL;
index 6ed586f49f407600b8b051d3947ea61191dfe567..66ad72e11dcdac66b2806e55d15b13ac570c2d73 100644 (file)
@@ -231,26 +231,21 @@ static int __optimize_basic_block(scf_basic_block_t* bb, scf_function_t* f)
        return 0;
 }
 
-static int _optimize_basic_block(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_basic_block(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
-       int count;
-       int ret;
-       int i;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
 //     scf_logi("------- %s() ------\n", f->node.w->text->data);
-//     scf_basic_block_print_list(bb_list_head);
-#if 1
-       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head);
-                       l = scf_list_next(l)) {
+
+       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_next(l)) {
 
                bb  = scf_list_data(l, scf_basic_block_t, list);
 
@@ -264,13 +259,13 @@ static int _optimize_basic_block(scf_ast_t* ast, scf_function_t* f, scf_list_t*
                        continue;
                }
 
-               ret = __optimize_basic_block(bb, f);
+               int ret = __optimize_basic_block(bb, f);
                if (ret < 0) {
                        scf_loge("\n");
                        return ret;
                }
        }
-#endif
+
 //     scf_basic_block_print_list(bb_list_head);
        return 0;
 }
index 06fd0d5f333a8cc655e6a32be4cf20fe0faf0965..77824ad1501aa96037557e001e4d9d567583e45a 100644 (file)
@@ -228,18 +228,17 @@ static int _optimize_call_bb(scf_basic_block_t* bb, scf_list_t* bb_list_head)
        return 0;
 }
 
-static int _optimize_call(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_call(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
-       int ret = 0;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
        for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); ) {
 
@@ -252,14 +251,12 @@ static int _optimize_call(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list
                if (!bb->call_flag)
                        continue;
 
-               ret = _optimize_call_bb(bb, bb_list_head);
+               int ret = _optimize_call_bb(bb, bb_list_head);
                if (ret < 0)
                        return ret;
        }
 
-       ret = 0;
-error:
-       return ret;
+       return 0;
 }
 
 scf_optimizer_t  scf_optimizer_call =
index b8605f3a8a5d0e2362244c82ea11089e6e9bc617..45eaa7e53dc56e82c7cddc077b930d06e1d5939e 100644 (file)
@@ -222,20 +222,17 @@ static int __optimize_const_teq(scf_basic_block_t* bb, scf_function_t* f)
        return 0;
 }
 
-static int _optimize_const_teq(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_const_teq(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
-       int count;
-       int ret;
-       int i;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
        for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head);
                        l = scf_list_next(l)) {
@@ -245,14 +242,13 @@ static int _optimize_const_teq(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb
                if (!bb->cmp_flag)
                        continue;
 
-               ret = __optimize_const_teq(bb, f);
+               int ret = __optimize_const_teq(bb, f);
                if (ret < 0) {
                        scf_loge("\n");
                        return ret;
                }
        }
 
-//     scf_const_teq_print_list(bb_list_head);
        return 0;
 }
 
index cdcf0d50809987419009e05c840a1ad3c72b3b96..84ff383ef82116ad1fc2321d9ecf452ecc341a90 100644 (file)
@@ -1,30 +1,26 @@
 #include"scf_optimizer.h"
 
-static int _optimize_dag(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_dag(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
-       int count;
-       int ret;
-       int i;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
        f->nb_basic_blocks = 0;
 
-       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head);
-                       l = scf_list_next(l)) {
+       for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_next(l)) {
 
-               bb  = scf_list_data(l, scf_basic_block_t, list);
+               bb = scf_list_data(l, scf_basic_block_t, list);
 
                bb->index = f->nb_basic_blocks++;
 
-               ret = scf_basic_block_dag(bb, bb_list_head, &f->dag_list_head);
+               int ret = scf_basic_block_dag(bb, bb_list_head, &f->dag_list_head);
                if (ret < 0) {
                        scf_loge("\n");
                        return ret;
index e5f310ac3b57a00314b54f0d6469f003195c80e4..97dd406673a4bc7d482ce36e1ed71a1f02ad0938 100644 (file)
@@ -293,20 +293,21 @@ error:
        return ret;
 }
 
-static int _optimize_dominators_normal(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_dominators_normal(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
        int ret;
        int i;
 
+       if (scf_list_empty(bb_list_head))
+               return 0;
+
        scf_vector_clear(f->dfs_tree, free);
 
        ret = _bb_dfs_tree(bb_list_head, f);
index fe6cbf03a50310fabedb2077cd7dfb70c39b7cf2..560f4d0d635eab3da17f9d01c914c9260bc6a43c 100644 (file)
@@ -300,20 +300,21 @@ error:
        return ret;
 }
 
-static int _optimize_dominators_reverse(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_dominators_reverse(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
        int ret;
        int i;
 
+       if (scf_list_empty(bb_list_head))
+               return 0;
+
        scf_vector_clear(f->dfs_tree, free);
 
        ret = _bb_dfs_tree(bb_list_head, f);
index 98b8a108940f1fc1dc9ec6f4965b763e4e026fb3..04014b945a6a087b35b85f651b98e61e632e531f 100644 (file)
@@ -13,11 +13,13 @@ static int _bb_index_cmp(const void* p0, const void* p1)
        return 0;
 }
 
-static int _optimize_generate_loads_saves(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_generate_loads_saves(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
+       scf_list_t* bb_list_head = &f->basic_block_list_head;
+
        if (scf_list_empty(bb_list_head))
                return 0;
 
index 8d6aece021ad28556f52cbb283f6b9ba93f66230..75f96984fb67b3114890db98d3025d1ba6f7a402 100644 (file)
@@ -135,11 +135,13 @@ static int _optimize_bbg_loads_saves(scf_function_t* f)
        return 0;
 }
 
-static int _optimize_group(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_group(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
+       scf_list_t* bb_list_head = &f->basic_block_list_head;
+
        if (scf_list_empty(bb_list_head))
                return 0;
 
index f493a69108b26e6c6a65f972f7cd8c6337ddeea7..7eec7f4b049133e73e636cbfdb53ae3c106b3552 100644 (file)
@@ -447,7 +447,7 @@ static int _optimize_inline2(scf_ast_t* ast, scf_function_t* f)
        return 0;
 }
 
-static int _optimize_inline(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_inline(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
        if (!ast || !functions || functions->size <= 0)
                return -EINVAL;
index 61fd0b62e0ae33d7342ca28a6d18f0ab6775bdb9..7c8ee29b382f6b769a268ebd3ba15a96a24ca929 100644 (file)
@@ -1,26 +1,22 @@
 #include"scf_optimizer.h"
 
-static int _optimize_loads_saves(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_loads_saves(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
-       scf_dag_node_t*    dn;
 
-       int count;
-       int ret;
-       int i;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
        for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); l = scf_list_next(l)) {
 
                bb = scf_list_data(l, scf_basic_block_t, list);
 
-               ret = scf_basic_block_loads_saves(bb, bb_list_head);
+               int ret = scf_basic_block_loads_saves(bb, bb_list_head);
                if (ret < 0)
                        return ret;
        }
index 1c2c712664f5c0e41282310808b9c4ebf3aeaa34..08d2e5f4fd3caf5f1c688db2a09338d7c2fd6cfa 100644 (file)
@@ -799,11 +799,13 @@ static int _bb_not_in_loop(scf_function_t* f, scf_list_t* bb_list_head)
        return 0;
 }
 
-static int _optimize_loop(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_loop(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
+       scf_list_t* bb_list_head = &f->basic_block_list_head;
+
        if (scf_list_empty(bb_list_head))
                return 0;
 
index b228c6cae593b8d808164d3d9173728fa4091235..feb5441ab1dd97f007cb72a12c975f80aaa76edf 100644 (file)
@@ -550,18 +550,17 @@ static int _optimize_alias_bb(scf_basic_block_t* bb, scf_list_t* bb_list_head)
        return 0;
 }
 
-static int _optimize_pointer_alias(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_pointer_alias(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* bb;
 
-       int ret = 0;
+       if (scf_list_empty(bb_list_head))
+               return 0;
 
        for (l = scf_list_head(bb_list_head); l != scf_list_sentinel(bb_list_head); ) {
 
@@ -574,15 +573,13 @@ static int _optimize_pointer_alias(scf_ast_t* ast, scf_function_t* f, scf_list_t
                if (!bb->dereference_flag)
                        continue;
 
-               ret = _optimize_alias_bb(bb, bb_list_head);
+               int ret = _optimize_alias_bb(bb, bb_list_head);
                if (ret < 0)
                        return ret;
        }
 
 //     scf_basic_block_print_list(bb_list_head);
-       ret = 0;
-error:
-       return ret;
+       return 0;
 }
 
 scf_optimizer_t  scf_optimizer_pointer_alias =
index 94da27af1cf892df5057b7d3e957d4d74801f5f3..64fe848df06874809e5889cf9187a8ae5b9b47f4 100644 (file)
@@ -128,14 +128,12 @@ static int _bb_next_find_loads(scf_basic_block_t* bb, void* data, scf_vector_t*
        return count;
 }
 
-static int _optimize_pointer_aliases(scf_ast_t* ast, scf_function_t* f, scf_list_t* bb_list_head, scf_vector_t* functions)
+static int _optimize_pointer_aliases(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functions)
 {
-       if (!f || !bb_list_head)
+       if (!f)
                return -EINVAL;
 
-       if (scf_list_empty(bb_list_head))
-               return 0;
-
+       scf_list_t*        bb_list_head = &f->basic_block_list_head;
        scf_list_t*        l;
        scf_basic_block_t* start;
        scf_basic_block_t* end;
@@ -143,6 +141,9 @@ static int _optimize_pointer_aliases(scf_ast_t* ast, scf_function_t* f, scf_list
        int count;
        int ret;
 
+       if (scf_list_empty(bb_list_head))
+               return 0;
+
        l     = scf_list_head(bb_list_head);
        start = scf_list_data(l, scf_basic_block_t, list);
 
index d69fb85a29aa1696045e788d0e643e027c095ed3..ab1c4031230d334cc1cbc90aab97dce95cf4f7a8 100644 (file)
@@ -12,6 +12,25 @@ static scf_handler_data_t* gd = NULL;
 
 static int __scf_op_const_call(scf_ast_t* ast, scf_function_t* f, void* data);
 
+static int _scf_op_const_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data_t* d)
+{
+       scf_operator_t* op = node->op;
+
+       if (!op) {
+               op = scf_find_base_operator_by_type(node->type);
+               if (!op) {
+                       scf_loge("\n");
+                       return -1;
+               }
+       }
+
+       scf_operator_handler_t* h = scf_find_const_operator_handler(op->type);
+       if (!h)
+               return -1;
+
+       return h->func(ast, node->nodes, node->nb_nodes, d);
+}
+
 static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void* data)
 {
        if (!node)
@@ -52,45 +71,42 @@ static int _scf_expr_calculate_internal(scf_ast_t* ast, scf_node_t* node, void*
 
                        if (_scf_expr_calculate_internal(ast, node->nodes[i], d) < 0) {
                                scf_loge("\n");
-                               goto _error;
+                               return -1;
                        }
                }
 
                scf_operator_handler_t* h = scf_find_const_operator_handler(node->op->type);
                if (!h) {
                        scf_loge("\n");
-                       goto _error;
+                       return -1;
                }
 
                if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
                        scf_loge("\n");
-                       goto _error;
+                       return -1;
                }
        } else {
                for (i = node->nb_nodes - 1; i >= 0; i--) {
 
                        if (_scf_expr_calculate_internal(ast, node->nodes[i], d) < 0) {
                                scf_loge("\n");
-                               goto _error;
+                               return -1;
                        }
                }
 
                scf_operator_handler_t* h = scf_find_const_operator_handler(node->op->type);
                if (!h) {
                        scf_loge("\n");
-                       goto _error;
+                       return -1;
                }
 
                if (h->func(ast, node->nodes, node->nb_nodes, d) < 0) {
                        scf_loge("\n");
-                       goto _error;
+                       return -1;
                }
        }
 
        return 0;
-
-_error:
-       return -1;
 }
 
 static int _scf_op_const_create(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
@@ -173,37 +189,19 @@ static int _scf_op_const_block(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes,
 
        scf_handler_data_t* d = data;
 
-       scf_block_t* b = (scf_block_t*)(nodes[0]->parent);
-
        scf_block_t* prev_block = ast->current_block;
-       ast->current_block = b;
+       ast->current_block      = (scf_block_t*)(nodes[0]->parent);
 
        int i = 0;
        while (i < nb_nodes) {
-               scf_node_t*             node = nodes[i];
-               scf_operator_t* op   = node->op;
+               scf_node_t* node = nodes[i];
 
                int ret;
 
                if (SCF_FUNCTION == node->type)
                        ret = __scf_op_const_call(ast, (scf_function_t*)node, data);
-               else {
-                       if (!op) {
-                               op = scf_find_base_operator_by_type(node->type);
-                               if (!op) {
-                                       scf_loge("node->type: %d\n", node->type);
-                                       return -1;
-                               }
-                       }
-
-                       scf_operator_handler_t* h = scf_find_const_operator_handler(op->type);
-                       if (!h) {
-                               scf_loge("\n");
-                               return -1;
-                       }
-
-                       ret = h->func(ast, node->nodes, node->nb_nodes, d);
-               }
+               else
+                       ret = _scf_op_const_node(ast, node, d);
 
                if (ret < 0) {
                        scf_loge("\n");
@@ -282,33 +280,6 @@ static int _scf_op_const_goto(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes,
        return 0;
 }
 
-static int _scf_op_const_node(scf_ast_t* ast, scf_node_t* node, scf_handler_data_t* d)
-{
-       scf_operator_t* op = node->op;
-
-       if (!op) {
-               op = scf_find_base_operator_by_type(node->type);
-               if (!op) {
-                       scf_loge("\n");
-                       return -1;
-               }
-       }
-
-       scf_operator_handler_t* h = scf_find_const_operator_handler(op->type);
-       if (!h) {
-               scf_loge("\n");
-               return -1;
-       }
-
-       int ret = h->func(ast, node->nodes, node->nb_nodes, d);
-       if (ret < 0) {
-               scf_loge("\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 static int _scf_op_const_if(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
 {
        if (nb_nodes < 2) {
@@ -317,13 +288,11 @@ static int _scf_op_const_if(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, vo
        }
 
        scf_handler_data_t* d = data;
+       scf_variable_t*     r = NULL;
+       scf_expr_t*         e = nodes[0];
 
-       scf_expr_t* e = nodes[0];
        assert(SCF_OP_EXPR == e->type);
 
-       scf_block_t* b = (scf_block_t*)(e->parent);
-
-       scf_variable_t* r = NULL;
        if (_scf_expr_calculate_internal(ast, e, &r) < 0) {
                scf_loge("\n");
                return -1;
@@ -331,23 +300,8 @@ static int _scf_op_const_if(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, vo
 
        int i;
        for (i = 1; i < nb_nodes; i++) {
-               scf_node_t*             node = nodes[i];
-               scf_operator_t* op   = node->op;
-
-               if (!op) {
-                       op = scf_find_base_operator_by_type(node->type);
-                       if (!op) {
-                               scf_loge("\n");
-                               return -1;
-                       }
-               }
-
-               scf_operator_handler_t* h = scf_find_const_operator_handler(op->type);
-               if (!h)
-                       return -1;
-
-               int ret = h->func(ast, node->nodes, node->nb_nodes, d);
 
+               int ret = _scf_op_const_node(ast, nodes[i], d);
                if (ret < 0)
                        return -1;
        }
@@ -453,20 +407,6 @@ static int __scf_op_const_call(scf_ast_t* ast, scf_function_t* f, void* data)
        return 0;
 }
 
-int scf_function_const_opt(scf_ast_t* ast, scf_function_t* f)
-{
-       scf_handler_data_t d = {0};
-
-       int ret = __scf_op_const_call(ast, f, &d);
-
-       if (ret < 0) {
-               scf_loge("\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 static int _scf_op_const_call(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, void* data)
 {
        assert(nb_nodes > 0);
@@ -1052,3 +992,17 @@ int scf_const_opt(scf_ast_t* ast)
 
        return 0;
 }
+
+int scf_function_const_opt(scf_ast_t* ast, scf_function_t* f)
+{
+       scf_handler_data_t d = {0};
+
+       int ret = __scf_op_const_call(ast, f, &d);
+
+       if (ret < 0) {
+               scf_loge("\n");
+               return -1;
+       }
+
+       return 0;
+}
index d8b7b57a6c793649fcda26acc90936ab9717d398..cdfcdae89899b49368d0bf8b5d4a5f2f45deafe1 100644 (file)
@@ -368,8 +368,7 @@ static int _semantic_do_overloaded2(scf_ast_t* ast, scf_node_t** nodes, int nb_n
 static int _semantic_do_overloaded(scf_ast_t* ast, scf_node_t** nodes, int nb_nodes, scf_handler_data_t* d)
 {
        scf_function_t* f;
-       scf_variable_t* v0;
-       scf_variable_t* v1;
+       scf_variable_t* v;
        scf_vector_t*   argv;
        scf_vector_t*   fvec   = NULL;
        scf_node_t*     parent = nodes[0]->parent;
@@ -384,18 +383,18 @@ static int _semantic_do_overloaded(scf_ast_t* ast, scf_node_t** nodes, int nb_no
 
        for (i = 0; i < nb_nodes; i++) {
 
-               v0 = _scf_operand_get(nodes[i]);
+               v = _scf_operand_get(nodes[i]);
 
-               if (!t && scf_variable_is_struct_pointer(v0)) {
+               if (!t && scf_variable_is_struct_pointer(v)) {
 
                        t = NULL;
-                       ret = scf_ast_find_type_type(&t, ast, v0->type);
+                       ret = scf_ast_find_type_type(&t, ast, v->type);
                        if (ret < 0)
                                return ret;
                        assert(t->scope);
                }
 
-               ret = scf_vector_add(argv, v0);
+               ret = scf_vector_add(argv, v);
                if (ret < 0) {
                        scf_vector_free(argv);
                        return ret;
@@ -2902,4 +2901,3 @@ int scf_semantic_analysis(scf_ast_t* ast)
 
        return 0;
 }
-