close some debug logs
authoryu.dongliang <18588496441@163.com>
Tue, 1 Oct 2024 05:26:25 +0000 (13:26 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 1 Oct 2024 05:26:29 +0000 (13:26 +0800)
core/scf_dag.c
core/scf_optimizer_dag.c
core/scf_optimizer_inline.c
core/scf_pointer_alias.c
core/scf_type_cast.c
native/x64/scf_x64_peephole.c
parse/scf_dfa_init_data.c
parse/scf_parse.c

index 88ee109fa8293df90e96afc3a325214cc0cf0736..da9f2bc4f59301b47f35d62338488cac5900fe35 100644 (file)
@@ -108,7 +108,7 @@ scf_dn_status_t* scf_dn_status_alloc(scf_dag_node_t* dn)
 
 int scf_dn_status_copy_dn(scf_dn_status_t* dst, scf_dn_status_t* src)
 {
-       scf_dn_index_t*   di;
+       scf_dn_index_t* di;
        int i;
 
        if (!dst || !src)
@@ -138,7 +138,7 @@ int scf_dn_status_copy_dn(scf_dn_status_t* dst, scf_dn_status_t* src)
 
 int scf_dn_status_copy_alias(scf_dn_status_t* dst, scf_dn_status_t* src)
 {
-       scf_dn_index_t*   di;
+       scf_dn_index_t* di;
        int i;
 
        if (!dst || !src)
@@ -210,16 +210,16 @@ scf_dn_status_t* scf_dn_status_clone(scf_dn_status_t* ds)
                }
        }
 
-       ds2->dag_node     = ds->dag_node;
-       ds2->dereference  = ds->dereference;
+       ds2->dag_node    = ds->dag_node;
+       ds2->dereference = ds->dereference;
 
-       ds2->alias        = ds->alias;
-       ds2->alias_type   = ds->alias_type;
+       ds2->alias       = ds->alias;
+       ds2->alias_type  = ds->alias_type;
 
-       ds2->active       = ds->active;
-       ds2->inited       = ds->inited;
-       ds2->updated      = ds->updated;
-       ds2->ret          = ds->ret;
+       ds2->active      = ds->active;
+       ds2->inited      = ds->inited;
+       ds2->updated     = ds->updated;
+       ds2->ret         = ds->ret;
        return ds2;
 }
 
@@ -235,7 +235,6 @@ void scf_dn_status_free(scf_dn_status_t* ds)
        int i;
 
        if (ds) {
-
                assert(ds->refs > 0);
 
                if (--ds->refs > 0)
@@ -266,7 +265,6 @@ void scf_dn_status_print(scf_dn_status_t* ds)
        int i;
 
        if (ds->dag_node) {
-
                v = ds->dag_node->var;
                printf("dn: v_%d_%d/%s ", v->w->line, v->w->pos, v->w->text->data);
 
@@ -315,7 +313,7 @@ scf_dag_node_t* scf_dag_node_alloc(int type, scf_variable_t* var, const scf_node
 
        dn->node = (scf_node_t*)node;
 
-#if 1
+#if 0
        if (SCF_OP_CALL == type) {
                scf_logw("dn: %#lx, dn->type: %d", 0xffff & (uintptr_t)dn, dn->type);
                if (var) {
@@ -392,11 +390,13 @@ static int _dn_status_cmp_dn_indexes(const void* p0, const void* p1,
                if (ds0->dn_indexes->size != ds1->dn_indexes->size)
                        return -1;
 
+               scf_dn_index_t* di0;
+               scf_dn_index_t* di1;
                int i;
-               for (i = 0; i < ds0->dn_indexes->size; i++) {
 
-                       scf_dn_index_t* di0 = ds0->dn_indexes->data[i];
-                       scf_dn_index_t* di1 = ds1->dn_indexes->data[i];
+               for (i = 0; i < ds0->dn_indexes->size; i++) {
+                       di0       = ds0->dn_indexes->data[i];
+                       di1       = ds1->dn_indexes->data[i];
 
                        if (!cmp(di0, di1))
                                return -1;
@@ -449,11 +449,13 @@ int scf_dn_status_cmp_alias(const void* p0, const void* p1)
                                if (v0->alias_indexes->size != v1->alias_indexes->size)
                                        return -1;
 
+                               scf_dn_index_t* di0;
+                               scf_dn_index_t* di1;
                                int i;
-                               for (i = 0; i < v0->alias_indexes->size; i++) {
 
-                                       scf_dn_index_t* di0 = v0->alias_indexes->data[i];
-                                       scf_dn_index_t* di1 = v1->alias_indexes->data[i];
+                               for (i = 0; i < v0->alias_indexes->size; i++) {
+                                       di0       = v0->alias_indexes->data[i];
+                                       di1       = v1->alias_indexes->data[i];
 
                                        if (!scf_dn_index_like(di0, di1))
                                                return -1;
@@ -473,11 +475,11 @@ int scf_dn_status_cmp_alias(const void* p0, const void* p1)
 
 void scf_dag_node_free_list(scf_list_t* dag_list_head)
 {
-       scf_list_t* l;
+       scf_dag_node_t* dn;
+       scf_list_t*     l;
 
        for (l = scf_list_head(dag_list_head); l != scf_list_sentinel(dag_list_head); ) {
-
-               scf_dag_node_t* dn = scf_list_data(l, scf_dag_node_t, list);
+               dn = scf_list_data(l, scf_dag_node_t, list);
 
                l = scf_list_next(l);
 
@@ -510,9 +512,8 @@ int scf_dag_node_same(scf_dag_node_t* dn, const scf_node_t* node)
        if (dn->type != node->type)
                return 0;
 
-       if (SCF_OP_ADDRESS_OF == node->type) {
+       if (SCF_OP_ADDRESS_OF == node->type)
                scf_logd("type: %d, %d, node: %#lx, %#lx, ", dn->type, node->type, 0xffff & (uintptr_t)dn, 0xffff & (uintptr_t)node);
-       }
 
        if (scf_type_is_var(node->type)) {
                if (dn->var == node->var)
@@ -642,8 +643,8 @@ cmp_childs:
 
                if (v0 && v0->w && v1 && v1->w) {
                        if (v0->type != v1->type) {
-                               scf_loge("v0: %d/%s_%#lx, split_flag: %d\n", v0->w->line, v0->w->text->data, 0xffff & (uintptr_t)v0, node->split_flag);
-                               scf_loge("v1: %d/%s_%#lx\n", v1->w->line, v1->w->text->data, 0xffff & (uintptr_t)v1);
+                               scf_logd("v0: %d/%s_%#lx, split_flag: %d\n", v0->w->line, v0->w->text->data, 0xffff & (uintptr_t)v0, node->split_flag);
+                               scf_logd("v1: %d/%s_%#lx\n", v1->w->line, v1->w->text->data, 0xffff & (uintptr_t)v1);
                        }
                }
 
@@ -655,15 +656,15 @@ cmp_childs:
 
 scf_dag_node_t* scf_dag_find_node(scf_list_t* h, const scf_node_t* node)
 {
-       scf_list_t* l;
-       scf_node_t* origin = (scf_node_t*)node;
+       scf_dag_node_t* dn;
+       scf_list_t*     l;
+       scf_node_t*     origin = (scf_node_t*)node;
 
        while (SCF_OP_EXPR == origin->type)
                origin = origin->nodes[0];
 
        for (l = scf_list_tail(h); l != scf_list_sentinel(h); l = scf_list_prev(l)) {
-
-               scf_dag_node_t* dn = scf_list_data(l, scf_dag_node_t, list);
+               dn = scf_list_data(l, scf_dag_node_t, list);
 
                if (scf_dag_node_same(dn, origin))
                        return dn;
@@ -752,13 +753,14 @@ int scf_dag_dn_same(scf_dag_node_t* dn0, scf_dag_node_t* dn1)
 
 int scf_dag_find_roots(scf_list_t* h, scf_vector_t* roots)
 {
-       scf_list_t* l;
-       for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) {
+       scf_dag_node_t* dn;
+       scf_list_t*     l;
 
-               scf_dag_node_t* dag_node = scf_list_data(l, scf_dag_node_t, list);
+       for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) {
+               dn = scf_list_data(l, scf_dag_node_t, list);
 
-               if (!dag_node->parents) {
-                       int ret = scf_vector_add(roots, dag_node);
+               if (!dn->parents) {
+                       int ret = scf_vector_add(roots, dn);
                        if (ret < 0)
                                return ret;
                }
@@ -768,10 +770,11 @@ int scf_dag_find_roots(scf_list_t* h, scf_vector_t* roots)
 
 int scf_dag_find_leafs(scf_list_t* h, scf_vector_t* leafs)
 {
-       scf_list_t* l;
-       for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) {
+       scf_dag_node_t* dn;
+       scf_list_t*     l;
 
-               scf_dag_node_t* dn = scf_list_data(l, scf_dag_node_t, list);
+       for (l = scf_list_head(h); l != scf_list_sentinel(h); l = scf_list_next(l)) {
+               dn = scf_list_data(l, scf_dag_node_t, list);
 
                if (!dn->childs) {
                        int ret = scf_vector_add_unique(leafs, dn);
@@ -787,12 +790,13 @@ int scf_dag_root_find_leafs(scf_dag_node_t* root, scf_vector_t* leafs)
        if (!root->childs)
                return scf_vector_add_unique(leafs, root);
 
+       scf_dag_node_t* dn;
        int i;
-       for (i = 0; i < root->childs->size; i++) {
 
-               scf_dag_node_t* child = root->childs->data[i];
+       for (i = 0; i < root->childs->size; i++) {
+               dn =        root->childs->data[i];
 
-               int ret = scf_dag_root_find_leafs(child, leafs);
+               int ret = scf_dag_root_find_leafs(dn, leafs);
                if (ret < 0)
                        return ret;
        }
@@ -801,10 +805,11 @@ int scf_dag_root_find_leafs(scf_dag_node_t* root, scf_vector_t* leafs)
 
 int scf_dag_vector_find_leafs(scf_vector_t* roots, scf_vector_t* leafs)
 {
+       scf_dag_node_t* root;
        int i;
-       for (i = 0; i < roots->size; i++) {
 
-               scf_dag_node_t* root = roots->data[i];
+       for (i = 0; i < roots->size; i++) {
+               root      = roots->data[i];
 
                int ret = scf_dag_root_find_leafs(root, leafs);
                if (ret < 0)
@@ -824,7 +829,6 @@ static int _dn_status_index(scf_vector_t* indexes, scf_dag_node_t* dn_index, int
        if (SCF_OP_ARRAY_INDEX == type) {
 
                if (scf_variable_const(dn_index->var))
-
                        di->index = dn_index->var->data.i;
                else
                        di->index = -1;
@@ -882,9 +886,9 @@ void scf_dn_status_vector_clear_by_dn(scf_vector_t* vec, scf_dag_node_t* dn)
 
 static int __ds_for_dn(scf_dn_status_t* ds, scf_dag_node_t* dn_base)
 {
-       scf_dag_node_t*   dn_index;
-       scf_dag_node_t*   dn_scale;
-       scf_dn_index_t*   di;
+       scf_dag_node_t*  dn_index;
+       scf_dag_node_t*  dn_scale;
+       scf_dn_index_t*  di;
 
        int ret;
 
index 84ff383ef82116ad1fc2321d9ecf452ecc341a90..767f4dcbe4b6bc463f625bacd6f4d64dcf44b858 100644 (file)
@@ -27,7 +27,7 @@ static int _optimize_dag(scf_ast_t* ast, scf_function_t* f, scf_vector_t* functi
                }
        }
 
-       scf_basic_block_print_list(bb_list_head);
+//     scf_basic_block_print_list(bb_list_head);
        return 0;
 }
 
@@ -39,4 +39,3 @@ scf_optimizer_t  scf_optimizer_dag =
 
        .flags    = SCF_OPTIMIZER_LOCAL,
 };
-
index 7eec7f4b049133e73e636cbfdb53ae3c106b3552..eb0606525a0ca5f572d5006fee473025991d74cb 100644 (file)
@@ -473,4 +473,3 @@ scf_optimizer_t  scf_optimizer_inline =
 
        .flags    = SCF_OPTIMIZER_GLOBAL,
 };
-
index 731c3bb5b067cf1748af5b8c353b45d5d54a3bac..4015977fbebbcbafed1397956d631d378c309366 100644 (file)
@@ -149,7 +149,8 @@ static int _bb_pointer_initeds(scf_vector_t* initeds, scf_list_t* bb_list_head,
                        return 0;
 
                if (v->global_flag) {
-                       scf_loge("bb: %p, index: %d, global pointer v_%d_%d/%s is not inited\n", bb, bb->index, v->w->line, v->w->pos, v->w->text->data);
+                       if (v->nb_pointers > 0)
+                               scf_logw("global pointer '%s' is not inited, file: %s, line: %d\n", v->w->text->data, v->w->file->data, v->w->line);
                        return 0;
                }
 
@@ -157,18 +158,17 @@ static int _bb_pointer_initeds(scf_vector_t* initeds, scf_list_t* bb_list_head,
                        return 0;
 
                if (dn->node->split_flag) {
-                       scf_loge("dn->node->split_parent: %d, %p\n", dn->node->split_parent->type, dn->node->split_parent);
-                       assert(dn->node->split_parent->type == SCF_OP_CALL
-                                       || dn->node->split_parent->type == SCF_OP_CREATE);
+                       scf_logd("dn->node->split_parent: %d, %p\n", dn->node->split_parent->type, dn->node->split_parent);
 
+                       assert(dn->node->split_parent->type == SCF_OP_CALL
+                               || dn->node->split_parent->type == SCF_OP_CREATE);
                        return 0;
                }
 
                if (ds->dn_indexes)
                        return 0;
 
-               scf_loge("bb: %p, index: %d, pointer v_%d_%d/%s is not inited\n", bb, bb->index, v->w->line, v->w->pos, v->w->text->data);
-
+               scf_loge("pointer '%s' is not inited, file: %s, line: %d\n", v->w->text->data, v->w->file->data, v->w->line);
                return SCF_POINTER_NOT_INIT;
        }
 
@@ -204,12 +204,12 @@ static int _bb_pointer_initeds(scf_vector_t* initeds, scf_list_t* bb_list_head,
                }
        }
 
-       scf_loge("initeds->size: %d\n", initeds->size);
+       scf_logd("initeds->size: %d\n", initeds->size);
        int i;
        for (i = 0; i < initeds->size; i++) {
                scf_basic_block_t* bb2 = initeds->data[i];
 
-               scf_loge("bb2: %p, %d\n", bb2, bb2->index);
+               scf_logd("bb2: %p, %d\n", bb2, bb2->index);
        }
 
        ret = _bb_dfs_check_initeds(bb_list_head, bb, initeds);
@@ -218,9 +218,7 @@ static int _bb_pointer_initeds(scf_vector_t* initeds, scf_list_t* bb_list_head,
                v  = dn->var;
 
                if (!v->arg_flag && !v->global_flag) {
-                       scf_loge("in bb: %p, index: %d, pointer v_%d_%d/%s may not be inited\n",
-                                       bb, bb->index, v->w->line, v->w->pos, v->w->text->data);
-
+                       scf_loge("pointer '%s' is not inited, file: %s, line: %d\n", v->w->text->data, v->w->file->data, v->w->line);
                        return SCF_POINTER_NOT_INIT;
                }
                return 0;
@@ -248,7 +246,8 @@ static int _bb_pointer_initeds_leak(scf_vector_t* initeds, scf_list_t* bb_list_h
                        return 0;
 
                if (v->global_flag) {
-                       scf_loge("bb: %p, index: %d, global pointer v_%d_%d/%s is not inited\n", bb, bb->index, v->w->line, v->w->pos, v->w->text->data);
+                       if (v->nb_pointers > 0)
+                               scf_logw("global pointer '%s' is not inited, file: %s, line: %d\n", v->w->text->data, v->w->file->data, v->w->line);
                        return 0;
                }
 
@@ -256,18 +255,15 @@ static int _bb_pointer_initeds_leak(scf_vector_t* initeds, scf_list_t* bb_list_h
                        return 0;
 
                if (dn->node->split_flag) {
-                       scf_loge("dn->node->split_parent: %d, %p\n", dn->node->split_parent->type, dn->node->split_parent);
                        assert(dn->node->split_parent->type == SCF_OP_CALL
-                                       || dn->node->split_parent->type == SCF_OP_CREATE);
-
+                               || dn->node->split_parent->type == SCF_OP_CREATE);
                        return 0;
                }
 
                if (ds->dn_indexes)
                        return 0;
 
-               scf_loge("bb: %p, index: %d, pointer v_%d_%d/%s is not inited\n", bb, bb->index, v->w->line, v->w->pos, v->w->text->data);
-
+               scf_loge("pointer '%s' is not inited, file: %s, line: %d\n", v->w->text->data, v->w->file->data, v->w->line);
                return SCF_POINTER_NOT_INIT;
        }
 
@@ -1646,4 +1642,3 @@ int scf_pointer_alias(scf_vector_t* aliases, scf_dag_node_t* dn_alias, scf_3ac_c
        }
        return 0;
 }
-
index 32797389445f7b82e0fa9a6149831e9a47bdadfa..be31fb6c300cd605fa23bb59f4c3d9be5116987f 100644 (file)
@@ -95,7 +95,7 @@ scf_type_cast_t* scf_find_base_type_cast(int src_type, int dst_type)
 
 int scf_type_cast_check(scf_ast_t* ast, scf_variable_t* dst, scf_variable_t* src)
 {
-       if (!dst->const_flag && src->const_flag) {
+       if (!dst->const_flag && src->const_flag && !src->const_literal_flag) {
                scf_logw("type cast %s -> %s discard 'const'\n", src->w->text->data, dst->w->text->data);
        }
 
@@ -186,4 +186,3 @@ failed:
        scf_string_free(src_type);
        return -1;
 }
-
index 784fefd5299ecdd13d76322b09a710fe1b2303c4..91d0545f07c2779591572ee10a5e48c65160d409 100644 (file)
@@ -393,8 +393,8 @@ static void _x64_peephole_function(scf_vector_t* tmp_insts, scf_function_t* f, i
                assert(0 == scf_vector_del(c->instructions,  inst));
                assert(0 == scf_vector_del(tmp_insts,        inst));
 
-               scf_logw("del: \n");
-               scf_instruction_print(inst);
+//             scf_logd("del: \n");
+//             scf_instruction_print(inst);
 
                free(inst);
                inst = NULL;
index 861ce9f82a9ff55292012990c4ec1556f4442c84..29f8ca9478b0d2795cb9197e50535eb9fb58f5b8 100644 (file)
@@ -10,15 +10,15 @@ int scf_struct_init(scf_ast_t* ast, scf_lex_word_t* w, scf_variable_t* var, scf_
 int _expr_add_var(scf_parse_t* parse, dfa_data_t* d);
 
 typedef struct {
-       scf_vector_t*  init_exprs;
+       scf_lex_word_t*  assign;
+       scf_vector_t*    init_exprs;
 
-       dfa_index_t*   current_index;
-       int            current_n;
+       dfa_index_t*     current_index;
+       int              current_n;
+       int              current_dim;
 
-       int            current_dim;
-
-       int            nb_lbs;
-       int            nb_rbs;
+       int              nb_lbs;
+       int              nb_rbs;
 } init_module_data_t;
 
 static int _do_data_init(scf_dfa_t* dfa, scf_vector_t* words, dfa_data_t* d)
@@ -33,10 +33,10 @@ static int _do_data_init(scf_dfa_t* dfa, scf_vector_t* words, dfa_data_t* d)
        int i   = 0;
 
        if (d->current_var->nb_dimentions > 0)
-               ret = scf_array_init(parse->ast, w, d->current_var, md->init_exprs);
+               ret = scf_array_init(parse->ast, md->assign, d->current_var, md->init_exprs);
 
        else if (d->current_var->type >=  SCF_STRUCT)
-               ret = scf_struct_init(parse->ast, w, d->current_var, md->init_exprs);
+               ret = scf_struct_init(parse->ast, md->assign, d->current_var, md->init_exprs);
 
        if (ret < 0)
                goto error;
@@ -73,6 +73,8 @@ error:
                ie = NULL;
        }
 
+       md->assign = NULL;
+
        scf_vector_free(md->init_exprs);
        md->init_exprs = NULL;
 
@@ -143,11 +145,16 @@ static int _data_action_comma(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 
 static int _data_action_entry(scf_dfa_t* dfa, scf_vector_t* words, void* data)
 {
+       assert(words->size >= 2);
+
        scf_parse_t*        parse = dfa->priv;
        dfa_data_t*         d     = data;
-       scf_lex_word_t*     w     = words->data[words->size - 1];
+       scf_lex_word_t*     w     = words->data[words->size - 2];
        init_module_data_t* md    = d->module_datas[dfa_module_init_data.index];
 
+       assert(SCF_LEX_WORD_ASSIGN == w->type);
+
+       md->assign = w;
        md->nb_lbs = 0;
        md->nb_rbs = 0;
 
index e7059b6c9e10dd4426094a6b1e7bb27a4ad3c1ad..e0f889d159240573e96b8f7b7a356d0d33004367 100644 (file)
@@ -1897,7 +1897,7 @@ int scf_parse_compile_functions(scf_parse_t* parse, scf_vector_t* functions)
                }
 
                assert(scf_list_empty(&h));
-               scf_basic_block_print_list(&f->basic_block_list_head);
+//             scf_basic_block_print_list(&f->basic_block_list_head);
        }
 
        int ret = scf_optimize(parse->ast, functions);