From: yu.dongliang <18588496441@163.com> Date: Tue, 26 Dec 2023 14:00:35 +0000 (+0800) Subject: delete 'bb_list_head' in optimizer callback() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=03be44ce12693f5b2843c85ddbba1c9dd0d74b2c;p=scf.git delete 'bb_list_head' in optimizer callback() --- diff --git a/core/scf_optimizer.c b/core/scf_optimizer.c index b5be449..7767467 100644 --- a/core/scf_optimizer.c +++ b/core/scf_optimizer.c @@ -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; diff --git a/core/scf_optimizer.h b/core/scf_optimizer.h index cce5482..dbb3f1b 100644 --- a/core/scf_optimizer.h +++ b/core/scf_optimizer.h @@ -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; }; diff --git a/core/scf_optimizer_active_vars.c b/core/scf_optimizer_active_vars.c index 087b854..809db84 100644 --- a/core/scf_optimizer_active_vars.c +++ b/core/scf_optimizer_active_vars.c @@ -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); diff --git a/core/scf_optimizer_auto_gc.c b/core/scf_optimizer_auto_gc.c index e50f87d..ef20342 100644 --- a/core/scf_optimizer_auto_gc.c +++ b/core/scf_optimizer_auto_gc.c @@ -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; diff --git a/core/scf_optimizer_auto_gc_find.c b/core/scf_optimizer_auto_gc_find.c index 23fb0da..7fdf623 100644 --- a/core/scf_optimizer_auto_gc_find.c +++ b/core/scf_optimizer_auto_gc_find.c @@ -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; diff --git a/core/scf_optimizer_basic_block.c b/core/scf_optimizer_basic_block.c index 6ed586f..66ad72e 100644 --- a/core/scf_optimizer_basic_block.c +++ b/core/scf_optimizer_basic_block.c @@ -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; } diff --git a/core/scf_optimizer_call.c b/core/scf_optimizer_call.c index 06fd0d5..77824ad 100644 --- a/core/scf_optimizer_call.c +++ b/core/scf_optimizer_call.c @@ -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 = diff --git a/core/scf_optimizer_const_teq.c b/core/scf_optimizer_const_teq.c index b8605f3..45eaa7e 100644 --- a/core/scf_optimizer_const_teq.c +++ b/core/scf_optimizer_const_teq.c @@ -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; } diff --git a/core/scf_optimizer_dag.c b/core/scf_optimizer_dag.c index cdcf0d5..84ff383 100644 --- a/core/scf_optimizer_dag.c +++ b/core/scf_optimizer_dag.c @@ -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; diff --git a/core/scf_optimizer_dominators.c b/core/scf_optimizer_dominators.c index e5f310a..97dd406 100644 --- a/core/scf_optimizer_dominators.c +++ b/core/scf_optimizer_dominators.c @@ -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); diff --git a/core/scf_optimizer_dominators_reverse.c b/core/scf_optimizer_dominators_reverse.c index fe6cbf0..560f4d0 100644 --- a/core/scf_optimizer_dominators_reverse.c +++ b/core/scf_optimizer_dominators_reverse.c @@ -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); diff --git a/core/scf_optimizer_generate_loads_saves.c b/core/scf_optimizer_generate_loads_saves.c index 98b8a10..04014b9 100644 --- a/core/scf_optimizer_generate_loads_saves.c +++ b/core/scf_optimizer_generate_loads_saves.c @@ -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; diff --git a/core/scf_optimizer_group.c b/core/scf_optimizer_group.c index 8d6aece..75f9698 100644 --- a/core/scf_optimizer_group.c +++ b/core/scf_optimizer_group.c @@ -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; diff --git a/core/scf_optimizer_inline.c b/core/scf_optimizer_inline.c index f493a69..7eec7f4 100644 --- a/core/scf_optimizer_inline.c +++ b/core/scf_optimizer_inline.c @@ -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; diff --git a/core/scf_optimizer_loads_saves.c b/core/scf_optimizer_loads_saves.c index 61fd0b6..7c8ee29 100644 --- a/core/scf_optimizer_loads_saves.c +++ b/core/scf_optimizer_loads_saves.c @@ -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; } diff --git a/core/scf_optimizer_loop.c b/core/scf_optimizer_loop.c index 1c2c712..08d2e5f 100644 --- a/core/scf_optimizer_loop.c +++ b/core/scf_optimizer_loop.c @@ -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; diff --git a/core/scf_optimizer_pointer_alias.c b/core/scf_optimizer_pointer_alias.c index b228c6c..feb5441 100644 --- a/core/scf_optimizer_pointer_alias.c +++ b/core/scf_optimizer_pointer_alias.c @@ -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 = diff --git a/core/scf_optimizer_pointer_aliases.c b/core/scf_optimizer_pointer_aliases.c index 94da27a..64fe848 100644 --- a/core/scf_optimizer_pointer_aliases.c +++ b/core/scf_optimizer_pointer_aliases.c @@ -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); diff --git a/parse/scf_operator_handler_const.c b/parse/scf_operator_handler_const.c index d69fb85..ab1c403 100644 --- a/parse/scf_operator_handler_const.c +++ b/parse/scf_operator_handler_const.c @@ -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; +} diff --git a/parse/scf_operator_handler_semantic.c b/parse/scf_operator_handler_semantic.c index d8b7b57..cdfcdae 100644 --- a/parse/scf_operator_handler_semantic.c +++ b/parse/scf_operator_handler_semantic.c @@ -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; } -