From 5d174babf99161623c05ccd01f4419bba14488fb Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 19 Nov 2023 22:07:57 +0800 Subject: [PATCH] add '-t' option to generate 3ac code only --- core/scf_optimizer_auto_gc_find.c | 29 +++++++-------- native/eda/scf_eda_pb.c | 2 +- parse/main.c | 14 ++++++-- parse/scf_parse.c | 59 ++++++++++++++++++------------- parse/scf_parse.h | 2 +- 5 files changed, 62 insertions(+), 44 deletions(-) diff --git a/core/scf_optimizer_auto_gc_find.c b/core/scf_optimizer_auto_gc_find.c index f7c9c8b..8db422b 100644 --- a/core/scf_optimizer_auto_gc_find.c +++ b/core/scf_optimizer_auto_gc_find.c @@ -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; diff --git a/native/eda/scf_eda_pb.c b/native/eda/scf_eda_pb.c index d7f0445..5433001 100644 --- a/native/eda/scf_eda_pb.c +++ b/native/eda/scf_eda_pb.c @@ -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}, }; diff --git a/parse/main.c b/parse/main.c index 073045b..753e5b1 100644 --- a/parse/main.c +++ b/parse/main.c @@ -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; } diff --git a/parse/scf_parse.c b/parse/scf_parse.c index bfdc50d..a3826bf 100644 --- a/parse/scf_parse.c +++ b/parse/scf_parse.c @@ -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; diff --git a/parse/scf_parse.h b/parse/scf_parse.h index c20bfa5..e27ddbf 100644 --- a/parse/scf_parse.h +++ b/parse/scf_parse.h @@ -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); -- 2.25.1