add '-t' option to generate 3ac code only
authoryu.dongliang <18588496441@163.com>
Sun, 19 Nov 2023 14:07:57 +0000 (22:07 +0800)
committeryu.dongliang <18588496441@163.com>
Sun, 19 Nov 2023 14:07:57 +0000 (22:07 +0800)
core/scf_optimizer_auto_gc_find.c
native/eda/scf_eda_pb.c
parse/main.c
parse/scf_parse.c
parse/scf_parse.h

index f7c9c8bdbceff688f5a055974a46f8595b5b5e73..8db422bf90b4fc3cb27929579ae20dd92a4f7248 100644 (file)
@@ -544,20 +544,6 @@ static int _auto_gc_bb_find(scf_basic_block_t* bb, scf_function_t* f)
                                dn  = src->dag_node;
                                v0  = dn->var;
 
-                               if (v0->nb_pointers + v0->nb_dimentions + (v0->type >= SCF_STRUCT) < 2)
-                                       continue;
-
-                               if (i - 1 >= f2->argv->size)
-                                       continue;
-
-                               scf_variable_t* v1 = f2->argv->data[i - 1];
-
-                               if (!v1->auto_gc_flag)
-                                       continue;
-
-                               scf_logd("f2: %s, v0: %s, v1: %s\n",
-                                               f2->node.w->text->data, v0->w->text->data, v1->w->text->data);
-
                                while (dn) {
                                        if (SCF_OP_TYPE_CAST == dn->type)
                                                dn = dn->childs->data[0];
@@ -568,6 +554,21 @@ static int _auto_gc_bb_find(scf_basic_block_t* bb, scf_function_t* f)
                                                break;
                                }
 
+                               if (v0->nb_pointers + v0->nb_dimentions + (v0->type >= SCF_STRUCT) < 2) {
+                                       continue;
+                               }
+
+                               if (i - 1 >= f2->argv->size)
+                                       continue;
+
+                               scf_variable_t* v1 = f2->argv->data[i - 1];
+
+                               scf_logw("f2: %s, v0: %s, v1: %s\n",
+                                               f2->node.w->text->data, v0->w->text->data, v1->w->text->data);
+
+                               if (!v1->auto_gc_flag)
+                                       continue;
+
                                ds_obj  = NULL;
 
                                int ret;
index d7f0445b97d1ea938ac33d50b188b5b615d59bfa..5433001844e246620f9e9e0a2c16c42e94ff2822 100644 (file)
@@ -21,7 +21,7 @@ static scf_edata_t  component_datas[] =
        {SCF_EDA_Battery,    0, SCF_EDA_Battery_POS,  0, 0,         0, 0,    0,    0, 0},
 
        {SCF_EDA_Resistor,   0,                   0,  0, 0, 10 * 1000, 0,    0,    0, 0},
-       {SCF_EDA_Capacitor,  0,                   0,  0, 0,         0, 0,  0.1,    0, 0},
+       {SCF_EDA_Capacitor,  0,                   0,  0, 0,      1e12, 0,  0.1,    0, 0},
        {SCF_EDA_Inductor,   0,                   0,  0, 0,         0, 0,    0, 1000, 0},
 };
 
index 073045b2c46a76725935a8ec5a27c087eb55d733..753e5b1451a2866d5c341e49aa7433ff02bacdac 100644 (file)
@@ -40,8 +40,9 @@ static char* __arm32_sofiles[] =
 
 void usage(char* path)
 {
-       fprintf(stderr, "Usage: %s [-c] [-a arch] [-o out] src0 [src1]\n\n", path);
-       fprintf(stderr, "-c: only compile, not link\n");
+       fprintf(stderr, "Usage: %s [-c] [-t] [-a arch] [-o out] src0 [src1]\n\n", path);
+       fprintf(stderr, "-c: only compile,  not link\n");
+       fprintf(stderr, "-t: only 3ac code, not compile\n");
        fprintf(stderr, "-a: select cpu arch (x64, arm64, naja, or eda), default is x64\n");
 }
 
@@ -60,6 +61,7 @@ int main(int argc, char* argv[])
        char* out  = NULL;
        char* arch = "x64";
        int   link = 1;
+       int   _3ac = 0;
 
        int   i;
 
@@ -72,6 +74,12 @@ int main(int argc, char* argv[])
                                continue;
                        }
 
+                       if ('t' == argv[i][1]) {
+                               link = 0;
+                               _3ac = 1;
+                               continue;
+                       }
+
                        if ('a' == argv[i][1]) {
 
                                if (++i >= argc) {
@@ -156,7 +164,7 @@ int main(int argc, char* argv[])
                        exec = out;
        }
 
-       if (scf_parse_compile(parse, obj, arch) < 0) {
+       if (scf_parse_compile(parse, obj, arch, _3ac) < 0) {
                scf_loge("\n");
                return -1;
        }
index bfdc50d498975a4daa9584455eceb3e7d5d7d66a..a3826bf78d8519a97ab453b2485baf8cc3c4c115 100644 (file)
@@ -1855,11 +1855,10 @@ static int _add_debug_sections(scf_parse_t* parse, scf_elf_context_t* elf)
        return 0;
 }
 
-int scf_parse_compile_functions(scf_parse_t* parse, scf_native_t* native, scf_vector_t* functions)
+int scf_parse_compile_functions(scf_parse_t* parse, scf_vector_t* functions)
 {
        scf_function_t* f;
 
-       int64_t tv0 = gettime();
        int i;
        for (i = 0; i < functions->size; i++) {
                f  =        functions->data[i];
@@ -1896,8 +1895,6 @@ int scf_parse_compile_functions(scf_parse_t* parse, scf_native_t* native, scf_ve
                assert(scf_list_empty(&h));
                scf_basic_block_print_list(&f->basic_block_list_head);
        }
-       int64_t tv1 = gettime();
-       scf_logw("tv1 - tv0: %ld\n", tv1 - tv0);
 
        int ret = scf_optimize(parse->ast, functions);
        if (ret < 0) {
@@ -1905,25 +1902,6 @@ int scf_parse_compile_functions(scf_parse_t* parse, scf_native_t* native, scf_ve
                return ret;
        }
 
-       int64_t tv2 = gettime();
-       scf_logw("tv2 - tv1: %ld\n", tv2 - tv1);
-#if 1
-       for (i = 0; i < functions->size; i++) {
-               f  =        functions->data[i];
-
-               if (!f->node.define_flag)
-                       continue;
-
-               int ret = scf_native_select_inst(native, f);
-               if (ret < 0) {
-                       scf_loge("\n");
-                       return ret;
-               }
-       }
-#endif
-
-       int64_t tv3 = gettime();
-       scf_logw("tv3 - tv2: %ld\n", tv3 - tv2);
        return 0;
 }
 
@@ -2113,7 +2091,29 @@ int scf_eda_write_pb(scf_parse_t* parse, const char* out, scf_vector_t* function
        return 0;
 }
 
-int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch)
+int scf_parse_native_functions(scf_parse_t* parse, scf_vector_t* functions, scf_native_t* native)
+{
+       scf_function_t* f;
+
+       int i;
+
+       for (i = 0; i < functions->size; i++) {
+               f  =        functions->data[i];
+
+               if (!f->node.define_flag)
+                       continue;
+
+               int ret = scf_native_select_inst(native, f);
+               if (ret < 0) {
+                       scf_loge("\n");
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
+int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch, int _3ac)
 {
        scf_block_t* b = parse->ast->root_block;
        if (!b)
@@ -2147,7 +2147,16 @@ int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch)
                goto open_native_error;
        }
 
-       ret = scf_parse_compile_functions(parse, native, functions);
+       ret = scf_parse_compile_functions(parse, functions);
+       if (ret < 0) {
+               scf_loge("\n");
+               goto open_native_error;
+       }
+
+       if (_3ac)
+               return 0;
+
+       ret = scf_parse_native_functions(parse, functions, native);
        if (ret < 0) {
                scf_loge("\n");
                goto open_native_error;
index c20bfa53c869099baf17ef62f75fa59c43e8d055..e27ddbf998e1c7800e90650c36cd2b4cf09a9832 100644 (file)
@@ -123,7 +123,7 @@ int scf_parse_close(scf_parse_t* parse);
 
 int scf_parse_file(scf_parse_t* parse, const char* path);
 
-int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch);
+int scf_parse_compile(scf_parse_t* parse, const char* out, const char* arch, int _3ac);
 
 int _find_global_var(scf_node_t* node, void* arg, scf_vector_t* vec);
 int _find_function  (scf_node_t* node, void* arg, scf_vector_t* vec);