From e0856058944c47b07ae124540c8bac1c7acbf04d Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sun, 21 Jun 2026 14:21:55 +0800 Subject: [PATCH] sync from scf, the most code is for native/x64 & elf --- html/Makefile | 1 + js/abc_libjs.so | Bin 136824 -> 137328 bytes js/core/scf_ast.h | 26 - js/core/scf_lex_word.h | 7 + js/elf/scf_elf.h | 39 +- js/elf/scf_elf_arm32.c | 11 +- js/elf/scf_elf_arm64.c | 11 +- js/elf/scf_elf_naja.c | 11 +- js/elf/scf_elf_x64.c | 1 + js/lex/scf_lex.c | 530 +--------------- js/lex/scf_lex.h | 6 + js/lex/scf_macro.c | 756 +++++++++++++++++++++++ js/native/risc/scf_arm32.c | 97 ++- js/native/risc/scf_arm64.c | 56 +- js/native/risc/scf_naja.c | 822 +------------------------ js/native/risc/scf_naja_inst.c | 911 ++++++++++++++++++++++++++++ js/native/risc/scf_naja_reg.c | 285 +++++++++ js/native/risc/scf_risc.c | 15 +- js/native/risc/scf_risc.h | 36 -- js/native/risc/scf_risc_bb_color.c | 2 +- js/native/risc/scf_risc_inst.c | 282 ++++----- js/native/risc/scf_risc_opcode.c | 54 +- js/native/risc/scf_risc_opcode.h | 63 +- js/native/risc/scf_risc_reg.c | 8 +- js/native/risc/scf_risc_reg_arm32.c | 12 +- js/native/risc/scf_risc_reg_arm64.c | 12 +- js/native/risc/scf_risc_reg_naja.c | 297 +-------- js/native/risc/scf_risc_util.h | 2 + js/native/scf_instruction.c | 71 ++- js/native/scf_instruction.h | 29 +- js/native/x64/scf_x64.c | 51 +- js/native/x64/scf_x64_inst.c | 156 ++--- js/native/x64/scf_x64_inst_binary.c | 36 +- js/native/x64/scf_x64_inst_cmp.c | 16 +- js/native/x64/scf_x64_inst_common.c | 34 +- js/native/x64/scf_x64_inst_div.c | 16 +- js/native/x64/scf_x64_inst_mul.c | 26 +- js/native/x64/scf_x64_inst_shift.c | 12 +- js/native/x64/scf_x64_inst_unary.c | 2 +- js/native/x64/scf_x64_inst_util.c | 36 +- js/native/x64/scf_x64_opcode.h | 61 +- js/native/x64/scf_x64_peephole.c | 286 ++++----- js/native/x64/scf_x64_reg.c | 48 +- js/native/x64/scf_x64_reg.h | 3 +- js/native/x64/scf_x64_reg_util.h | 10 +- js/util/scf_string.c | 34 ++ js/util/scf_string.h | 2 + ui/Makefile | 1 + 48 files changed, 2890 insertions(+), 2393 deletions(-) create mode 100644 js/lex/scf_macro.c create mode 100644 js/native/risc/scf_naja_inst.c create mode 100644 js/native/risc/scf_naja_reg.c diff --git a/html/Makefile b/html/Makefile index b11e664..cf65d8a 100644 --- a/html/Makefile +++ b/html/Makefile @@ -18,6 +18,7 @@ CFILES += ../js/util/scf_string.c CFILES += ../js/util/scf_graph.c CFILES += ../js/lex/scf_lex.c CFILES += ../js/lex/scf_lex_util.c +CFILES += ../js/lex/scf_macro.c CFILES += ../js/parse/main.c CFILES += ../js/parse/scf_parse.c diff --git a/js/abc_libjs.so b/js/abc_libjs.so index e9b31a886e3576a056b32783adc71d35b296fc91..41cb04229299873b80d908997fabfdbde5a3b993 100755 GIT binary patch delta 26970 zcma)lcX$=W_xGH=xh?gk-rV#;LPB~%3M7zF0-<-L6MAn_1OzT!st^WP(4c@7DS|;z z1O*jE=^_Z&z>25{f{GyK{hZxR|_p10@lE4e-ZTimX@@*qfmY z{N*r!t0DgK@Ye``jqz8Azb5!A#$Pl1wZtD^rFvGImH}#mzqUq6dl_p=@!0uS-@&rI zX|ud(%A~$(?0s@p#dsW6XokFMak_%jbnYdF(C;KffbbUkq`%eano^_}Z$~L#-C+O+ zs710FsFMs!wbzN_ByyHrEhkx>ZrMREzHU&z@z7;Q4>k&nY@JD$I@ww;=wp<306%Lh z?W`9pHQF%GC?C;RFTZS*{|1!#H|afci!2|VVTd8Hy{nEJazZid4VqG?L1jjRmbKLR z(~JtFp{H4Yy?m{niNyy0Bdzp;X&QewA)Ye?&Km;54MkrX0&NY$jWHBGYVcbi%U4Z9 zj~M)WY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?&_u{x$!rhMP_^ByORE9d*jE;F=o4-oGS%TAf`9ls5zH`>l4RJ?-!BqiA?64N!*B zbghR|DaDIAHBKcfu;B+h8|qHlS#ECYG?ZzmS8IWRN|w)Mv-z@9>lmmM*s}u-wrp)l zpwc|3;deY6>YEnrT%htW?bdn(DOvV2@do!9ZAp;QT$>-H;IAc0v~xj9rq6dn4I1LH zPq6YR4bp0Yp~sn7W*4&_zyEA7l&3NK14B{!y}!<&>!tQns1mGAb}3=X-#OY7E~O;& zy&{}<__RfybN6HL-2|UKppQY{sRg=~=E}hzw2p42M49r7_5^DC`dcurrent_block, (scf_node_t*)b); - ast->current_block = b; -} - -static inline void scf_ast_pop_block(scf_ast_t* ast) -{ - ast->current_block = (scf_block_t*)(ast->current_block->node.parent); -} - -static inline scf_block_t* scf_ast_parent_block(scf_ast_t* ast) -{ - scf_node_t* parent = ast->current_block->node.parent; - - while (parent && parent->type != SCF_OP_BLOCK && parent->type != SCF_FUNCTION) - parent = parent->parent; - - return (scf_block_t*)parent; -} - -static inline scf_scope_t* scf_ast_current_scope(scf_ast_t* ast) -{ - return ast->current_block->scope; -} - int scf_ast_find_proper_function (scf_function_t** pf, scf_ast_t* ast, scf_vector_t* fvec, scf_vector_t* argv); int scf_ast_find_global_function (scf_function_t** pf, scf_ast_t* ast, char* name); int scf_ast_find_global_variable (scf_variable_t** pv, scf_ast_t* ast, char* name); diff --git a/js/core/scf_lex_word.h b/js/core/scf_lex_word.h index 17ac40d..e97b625 100644 --- a/js/core/scf_lex_word.h +++ b/js/core/scf_lex_word.h @@ -111,6 +111,11 @@ enum scf_lex_words SCF_LEX_WORD_KEY_INCLUDE, // #include SCF_LEX_WORD_KEY_DEFINE, // #define + SCF_LEX_WORD_KEY_UNDEF, // #undef + + SCF_LEX_WORD_KEY_IFDEF, // #ifdef + SCF_LEX_WORD_KEY_IFNDEF, // #ifndef + SCF_LEX_WORD_KEY_ELIF, // #elif SCF_LEX_WORD_KEY_ENDIF, // #endif // data types @@ -189,6 +194,8 @@ struct scf_macro_s { int refs; + uint8_t def_flag:1; + scf_lex_word_t* w; scf_vector_t* argv; diff --git a/js/elf/scf_elf.h b/js/elf/scf_elf.h index b3599aa..0a40786 100644 --- a/js/elf/scf_elf.h +++ b/js/elf/scf_elf.h @@ -8,6 +8,16 @@ typedef struct scf_elf_context_s scf_elf_context_t; typedef struct scf_elf_ops_s scf_elf_ops_t; +enum scf_elf_archs +{ + SCF_ELF_X64, + SCF_ELF_ARM64, + SCF_ELF_ARM32, + SCF_ELF_NAJA, + + SCF_ELF_N_ARCHS, +}; + typedef struct { char* name; uint64_t st_size; @@ -52,27 +62,28 @@ typedef struct { struct scf_elf_ops_s { - const char* machine; + const char* machine; + int arch; - int (*open )(scf_elf_context_t* elf); - int (*close)(scf_elf_context_t* elf); + int (*open )(scf_elf_context_t* elf); + int (*close)(scf_elf_context_t* elf); - int (*add_sym )(scf_elf_context_t* elf, const scf_elf_sym_t* sym, const char* sh_name); - int (*read_syms )(scf_elf_context_t* elf, scf_vector_t* syms, const char* sh_name); - int (*read_relas)(scf_elf_context_t* elf, scf_vector_t* relas, const char* sh_name); - int (*read_phdrs)(scf_elf_context_t* elf, scf_vector_t* phdrs); + int (*add_sym )(scf_elf_context_t* elf, const scf_elf_sym_t* sym, const char* sh_name); + int (*read_syms )(scf_elf_context_t* elf, scf_vector_t* syms, const char* sh_name); + int (*read_relas)(scf_elf_context_t* elf, scf_vector_t* relas, const char* sh_name); + int (*read_phdrs)(scf_elf_context_t* elf, scf_vector_t* phdrs); - int (*add_section )(scf_elf_context_t* elf, const scf_elf_section_t* section); - int (*read_section)(scf_elf_context_t* elf, scf_elf_section_t** psection, const char* name); + int (*add_section )(scf_elf_context_t* elf, const scf_elf_section_t* section); + int (*read_section)(scf_elf_context_t* elf, scf_elf_section_t** psection, const char* name); - int (*add_rela_section)(scf_elf_context_t* elf, const scf_elf_section_t* section, scf_vector_t* relas); + int (*add_rela_section)(scf_elf_context_t* elf, const scf_elf_section_t* section, scf_vector_t* relas); - int (*add_dyn_need)(scf_elf_context_t* elf, const char* soname); + int (*add_dyn_need)(scf_elf_context_t* elf, const char* soname); int (*add_dyn_rela)(scf_elf_context_t* elf, const scf_elf_rela_t* rela); - int (*write_rel )(scf_elf_context_t* elf); - int (*write_dyn )(scf_elf_context_t* elf, const char* sysroot); - int (*write_exec)(scf_elf_context_t* elf, const char* sysroot); + int (*write_rel )(scf_elf_context_t* elf); + int (*write_dyn )(scf_elf_context_t* elf, const char* sysroot); + int (*write_exec)(scf_elf_context_t* elf, const char* sysroot); }; struct scf_elf_context_s { diff --git a/js/elf/scf_elf_arm32.c b/js/elf/scf_elf_arm32.c index 6c85c87..6e66b0f 100644 --- a/js/elf/scf_elf_arm32.c +++ b/js/elf/scf_elf_arm32.c @@ -440,12 +440,13 @@ static int _arm32_elf_write_exec(scf_elf_context_t* elf, const char* sysroot) scf_elf_ops_t elf_ops_arm32 = { - .machine = "arm32", + .machine = "arm32", + .arch = SCF_ELF_ARM32, - .open = elf32_open, - .close = elf32_close, + .open = elf32_open, + .close = elf32_close, - .add_sym = elf32_add_sym, + .add_sym = elf32_add_sym, .add_section = elf32_add_section, .add_rela_section = elf32_add_rela_section, @@ -457,6 +458,6 @@ scf_elf_ops_t elf_ops_arm32 = .read_relas = elf32_read_relas, .read_section = elf32_read_section, - .write_rel = _arm32_elf_write_rel, + .write_rel = _arm32_elf_write_rel, .write_exec = _arm32_elf_write_exec, }; diff --git a/js/elf/scf_elf_arm64.c b/js/elf/scf_elf_arm64.c index 318ee2e..3cfe50e 100644 --- a/js/elf/scf_elf_arm64.c +++ b/js/elf/scf_elf_arm64.c @@ -452,12 +452,13 @@ static int _arm64_elf_write_exec(scf_elf_context_t* elf, const char* sysroot) scf_elf_ops_t elf_ops_arm64 = { - .machine = "arm64", + .machine = "arm64", + .arch = SCF_ELF_ARM64, - .open = elf_open, - .close = elf_close, + .open = elf_open, + .close = elf_close, - .add_sym = elf_add_sym, + .add_sym = elf_add_sym, .add_section = elf_add_section, .add_rela_section = elf_add_rela_section, @@ -469,6 +470,6 @@ scf_elf_ops_t elf_ops_arm64 = .read_relas = elf_read_relas, .read_section = elf_read_section, - .write_rel = _arm64_elf_write_rel, + .write_rel = _arm64_elf_write_rel, .write_exec = _arm64_elf_write_exec, }; diff --git a/js/elf/scf_elf_naja.c b/js/elf/scf_elf_naja.c index d399243..513910a 100644 --- a/js/elf/scf_elf_naja.c +++ b/js/elf/scf_elf_naja.c @@ -452,12 +452,13 @@ static int _naja_elf_write_exec(scf_elf_context_t* elf, const char* sysroot) scf_elf_ops_t elf_ops_naja = { - .machine = "naja", + .machine = "naja", + .arch = SCF_ELF_NAJA, - .open = elf_open, - .close = elf_close, + .open = elf_open, + .close = elf_close, - .add_sym = elf_add_sym, + .add_sym = elf_add_sym, .add_section = elf_add_section, .add_rela_section = elf_add_rela_section, @@ -470,6 +471,6 @@ scf_elf_ops_t elf_ops_naja = .read_section = elf_read_section, .read_phdrs = elf_read_phdrs, - .write_rel = _naja_elf_write_rel, + .write_rel = _naja_elf_write_rel, .write_exec = _naja_elf_write_exec, }; diff --git a/js/elf/scf_elf_x64.c b/js/elf/scf_elf_x64.c index 4d28fac..147d1e0 100644 --- a/js/elf/scf_elf_x64.c +++ b/js/elf/scf_elf_x64.c @@ -653,6 +653,7 @@ static int _x64_elf_write_dyn(scf_elf_context_t* elf, const char* sysroot) scf_elf_ops_t elf_ops_x64 = { .machine = "x64", + .arch = SCF_ELF_X64, .open = elf_open, .close = elf_close, diff --git a/js/lex/scf_lex.c b/js/lex/scf_lex.c index a090615..19a7780 100644 --- a/js/lex/scf_lex.c +++ b/js/lex/scf_lex.c @@ -905,522 +905,6 @@ int __lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) return -1; } -static int __parse_macro_argv(scf_lex_t* lex, scf_macro_t* m) -{ - scf_lex_word_t* w = NULL; - scf_lex_word_t* w2; - - int comma = 0; - int id = 0; - - while (1) { - int ret = __lex_pop_word(lex, &w); - if (ret < 0) - return ret; - - if (!comma) { - if (SCF_LEX_WORD_RP == w->type) { - scf_lex_word_free(w); - break; - } - - if (SCF_LEX_WORD_COMMA == w->type) { - scf_lex_word_free(w); - w = NULL; - - if (!id) { - scf_loge("an identity is needed before ',' in file: %s, line: %d\n", w->file->data, w->line); - return -1; - } - - id = 0; - comma = 1; - continue; - } - } - - if (!scf_lex_is_identity(w)) { - scf_loge("macro arg '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line); - scf_lex_word_free(w); - return -1; - } - - if (id) { - scf_loge("',' is needed before macro arg '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line); - scf_lex_word_free(w); - return -1; - } - - int i; - for (i = 0; i < m->argv->size; i++) { - w2 = m->argv->data[i]; - - if (!scf_string_cmp(w2->text, w->text)) { - scf_loge("macro has same args '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line); - scf_lex_word_free(w); - return -1; - } - } - - scf_logw("macro '%s' arg: %s\n", m->w->text->data, w->text->data); - - ret = scf_vector_add(m->argv, w); - if (ret < 0) { - scf_lex_word_free(w); - return ret; - } - w = NULL; - - id = 1; - comma = 0; - } - - return 0; -} - -static int __parse_macro_define(scf_lex_t* lex) -{ - scf_lex_word_t** pp; - scf_lex_word_t* w = NULL; - scf_macro_t* m; - scf_macro_t* m0; - - int ret = __lex_pop_word(lex, &w); - if (ret < 0) - return ret; - - if (!scf_lex_is_identity(w)) { - scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line); - scf_lex_word_free(w); - return -1; - } - - m = scf_macro_alloc(w); - if (!m) { - scf_lex_word_free(w); - return -ENOMEM; - } - - w = NULL; - ret = __lex_pop_word(lex, &w); - if (ret < 0) { - scf_macro_free(m); - return ret; - } - - pp = &m->text_list; - - if (SCF_LEX_WORD_LP == w->type) { - scf_lex_word_free(w); - w = NULL; - - m->argv = scf_vector_alloc(); - if (!m->argv) { - scf_macro_free(m); - return -ENOMEM; - } - - ret = __parse_macro_argv(lex, m); - if (ret < 0) { - scf_macro_free(m); - return ret; - } - } else { - *pp = w; - pp = &w->next; - w = NULL; - } - - while (1) { - ret = __lex_pop_word(lex, &w); - if (ret < 0) { - scf_macro_free(m); - return ret; - } - - if (SCF_LEX_WORD_LF == w->type) { - scf_lex_word_free(w); - w = NULL; - break; - } - - *pp = w; - pp = &w->next; - w = NULL; - } - - if (!lex->macros) { - lex->macros = scf_vector_alloc(); - if (!lex->macros) - return -ENOMEM; - - } else { - int i; - for (i = lex->macros->size - 1; i >= 0; i--) { - m0 = lex->macros->data[i]; - - if (!scf_string_cmp(m->w->text, m0->w->text)) { - scf_logw("macro '%s' defined before in file: %s, line: %d\n", - m0->w->text->data, m0->w->file->data, m0->w->line); - break; - } - } - } - - ret = scf_vector_add(lex->macros, m); - if (ret < 0) { - scf_macro_free(m); - return ret; - } - - return 0; -} - -static int __fill_macro_argv(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use, scf_vector_t* argv) -{ - scf_lex_word_t** pp; - scf_lex_word_t* w = NULL; - - int ret = __lex_pop_word(lex, &w); - if (ret < 0) - return ret; - - if (SCF_LEX_WORD_LP != w->type) { - scf_loge("macro '%s' needs args, file: %s, line: %d\n", m->w->text->data, w->file->data, w->line); - scf_lex_word_free(w); - return -1; - } - - scf_lex_word_free(w); - w = NULL; - - int n_lps = 0; - int n_rps = 0; - int i; - - pp = NULL; - - while (1) { - ret = __lex_pop_word(lex, &w); - if (ret < 0) - return ret; - - if (SCF_LEX_WORD_COMMA == w->type) { - if (!pp) { - scf_loge("unexpected ',' in macro '%s', file: %s, line: %d\n", m->w->text->data, w->file->data, w->line); - - scf_lex_word_free(w); - ret = -1; - goto error; - } - - scf_lex_word_free(w); - w = NULL; - - if (n_rps == n_lps) - pp = NULL; - continue; - - } else if (SCF_LEX_WORD_LP == w->type) - n_lps++; - else if (SCF_LEX_WORD_RP == w->type) { - n_rps++; - - if (n_rps > n_lps) { - scf_lex_word_free(w); - w = NULL; - break; - } - } - - w->next = NULL; - - if (pp) - *pp = w; - else { - ret = scf_vector_add(argv, w); - if (ret < 0) { - scf_lex_word_free(w); - goto error; - } - } - - pp = &w->next; - w = NULL; - } - - if (m->argv->size != argv->size) { - scf_loge("macro '%s' needs %d args, but in fact give %d args, file: %s, line: %d\n", - m->w->text->data, m->argv->size, argv->size, use->file->data, use->line); - ret = -1; - goto error; - } - - return 0; - -error: - for (i = 0; i < argv->size; i++) { - w = argv->data[i]; - scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free); - } - - argv->size = 0; - return ret; -} - -static int __convert_str(scf_lex_word_t* h) -{ - scf_lex_word_t* w; - scf_string_t* s; - - if (h->type != SCF_LEX_WORD_CONST_STRING) { - h->type = SCF_LEX_WORD_CONST_STRING; - - h->data.s = scf_string_clone(h->text); - if (!h->data.s) - return -ENOMEM; - } - - while ( h->next) { - w = h->next; - - if (SCF_LEX_WORD_CONST_STRING != w->type) - s = w->text; - else - s = w->data.s; - - int ret = scf_string_cat(h->data.s, s); - if (ret < 0) - return ret; - - ret = scf_string_cat(h->text, w->text); - if (ret < 0) - return ret; - - h->next = w->next; - - scf_lex_word_free(w); - w = NULL; - } - - scf_logw("h: '%s', file: %s, line: %d\n", h->data.s->data, h->file->data, h->line); - return 0; -} - -static scf_macro_t* __find_macro(scf_lex_t* lex, scf_lex_word_t* w) -{ - if (!lex->macros) - return NULL; - - scf_macro_t* m; - int i; - - for (i = lex->macros->size - 1; i >= 0; i--) { - m = lex->macros->data[i]; - - if (!scf_string_cmp(m->w->text, w->text)) - return m; - } - - return NULL; -} - -static int __use_macro(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use) -{ - scf_lex_word_t** pp; - scf_lex_word_t* p; - scf_lex_word_t* h; - scf_lex_word_t* w; - scf_lex_word_t* prev; - scf_vector_t* argv = NULL; - - if (m->argv) { - argv = scf_vector_alloc(); - if (!argv) - return -ENOMEM; - - int ret = __fill_macro_argv(lex, m, use, argv); - if (ret < 0) { - scf_vector_free(argv); - return ret; - } - } - - h = NULL; - pp = &h; - - int ret = 0; - int hash = 0; - int i; - - for (p = m->text_list; p; p = p->next) { - - if (SCF_LEX_WORD_HASH == p->type) { - hash = 1; - continue; - } - - scf_logd("p: '%s', line: %d, hash: %d\n", p->text->data, p->line, hash); - - if (m->argv) { - assert(argv); - assert(argv->size >= m->argv->size); - - for (i = 0; i < m->argv->size; i++) { - w = m->argv->data[i]; - - if (!scf_string_cmp(w->text, p->text)) - break; - } - - if (i < m->argv->size) { - scf_lex_word_t** tmp = pp; - - for (w = argv->data[i]; w; w = w->next) { - - *pp = scf_lex_word_clone(w); - if (!*pp) { - ret = -ENOMEM; - goto error; - } - - if (!strcmp((*pp)->text->data, "__LINE__")) - (*pp)->data.u64 = use->line; - - pp = &(*pp)->next; - } - - if (1 == hash) { - ret = __convert_str(*tmp); - if (ret < 0) - goto error; - - pp = &(*tmp)->next; - } - - hash = 0; - continue; - } - } - - *pp = scf_lex_word_clone(p); - if (!*pp) { - ret = -ENOMEM; - goto error; - } - - if (!strcmp((*pp)->text->data, "__LINE__")) - (*pp)->data.u64 = use->line; - - pp = &(*pp)->next; - - hash = 0; - } - -error: - if (argv) { - for (i = 0; i < argv->size; i++) { - w = argv->data[i]; - - if (w) - scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free); - } - - scf_vector_free(argv); - argv = NULL; - } - - if (ret < 0) { - scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free); - return ret; - } - -#if 0 - w = h; - while (w) { - scf_logi("---------- %s, line: %d\n", w->text->data, w->line); - w = w->next; - } -#endif - *pp = lex->word_list; - lex->word_list = h; - return 0; -} - -static int __use_hash2(scf_lex_t* lex, scf_lex_word_t* prev) -{ - scf_lex_word_t* after = NULL; - - int ret = __lex_pop_word(lex, &after); - if (ret < 0) - return ret; - - switch (after->type) { - - case SCF_LEX_WORD_ID: - ret = scf_string_cat(prev->text, after->text); - break; - - default: - ret = -1; - scf_loge("needs identity after '##', file: %s, line: %d\n", after->file->data, after->line); - break; - }; - - scf_lex_word_free(after); - return ret; -} - -int __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp) -{ - scf_lex_word_t* w1 = NULL; - scf_lex_word_t* w = *pp; - scf_macro_t* m; - - *pp = NULL; - - while (SCF_LEX_WORD_ID == w->type) { - - m = __find_macro(lex, w); - if (m) { - int ret = __use_macro(lex, m, w); - - scf_lex_word_free(w); - w = NULL; - if (ret < 0) - return ret; - - ret = __lex_pop_word(lex, &w); - if (ret < 0) - return ret; - continue; - } - - int ret = __lex_pop_word(lex, &w1); - if (ret < 0) { - scf_lex_word_free(w); - return ret; - } - - if (SCF_LEX_WORD_HASH2 != w1->type) { - scf_lex_push_word(lex, w1); - break; - } - - scf_lex_word_free(w1); - w1 = NULL; - - ret = __use_hash2(lex, w); - if (ret < 0) { - scf_lex_word_free(w); - return ret; - } - } - - *pp = w; - return 0; -} - static int __lex_math(scf_lex_t* lex, scf_lex_word_t* w) { scf_lex_word_t* w1 = NULL; @@ -1502,9 +986,21 @@ int scf_lex_pop_word(scf_lex_t* lex, scf_lex_word_t** pword) return 0; break; + case SCF_LEX_WORD_KEY_IFNDEF: + ret = __parse_macro_ifdef(lex, 0); + break; + case SCF_LEX_WORD_KEY_IFDEF: + ret = __parse_macro_ifdef(lex, 1); + break; + case SCF_LEX_WORD_KEY_DEFINE: - ret = __parse_macro_define(lex); + ret = __parse_macro_define(lex, 1); + break; + + case SCF_LEX_WORD_KEY_UNDEF: + ret = __parse_macro_define(lex, 0); break; + default: scf_loge("unknown macro '%s', file: %s, line: %d\n", w1->text->data, w1->file->data, w1->line); ret = -1; diff --git a/js/lex/scf_lex.h b/js/lex/scf_lex.h index f66d8e5..386ab3a 100644 --- a/js/lex/scf_lex.h +++ b/js/lex/scf_lex.h @@ -45,6 +45,8 @@ struct scf_lex_s scf_string_t* file; // original code file name int nb_lines; int pos; + + uint8_t asm_flag:1; }; @@ -59,6 +61,10 @@ void scf_lex_push_word(scf_lex_t* lex, scf_lex_word_t* word); int scf_lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword); int __lex_pop_word (scf_lex_t* lex, scf_lex_word_t** pword); +int __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp); + +int __parse_macro_define(scf_lex_t* lex, int def_flag); +int __parse_macro_ifdef (scf_lex_t* lex, int def_flag); int _lex_number_base_16(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s); int _lex_number_base_10(scf_lex_t* lex, scf_lex_word_t** pword, scf_string_t* s); diff --git a/js/lex/scf_macro.c b/js/lex/scf_macro.c new file mode 100644 index 0000000..b8c1a71 --- /dev/null +++ b/js/lex/scf_macro.c @@ -0,0 +1,756 @@ +#include"scf_lex.h" + +static int __macro_drop_to_LF(scf_lex_t* lex) +{ + scf_lex_word_t* w = NULL; + int type; + + do { + int ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + type = w->type; + scf_lex_word_free(w); + w = NULL; + + } while (SCF_LEX_WORD_LF != type); + + return 0; +} + +static int __macro_drop_to(scf_lex_t* lex, scf_lex_word_t** pw1, scf_lex_word_t** pw2) +{ + scf_lex_word_t* w1 = NULL; + scf_lex_word_t* w2 = NULL; + + int n_if = 1; + + while (1) { + if (!w1) { + int ret = __lex_pop_word(lex, &w1); + if (ret < 0) + return ret; + } + + if (SCF_LEX_WORD_HASH != w1->type) { + scf_lex_word_free(w1); + w1 = NULL; + continue; + } + + int ret = __lex_pop_word(lex, &w2); + if (ret < 0) { + scf_lex_word_free(w1); + return ret; + } + + switch (w2->type) + { + case SCF_LEX_WORD_KEY_IF: + case SCF_LEX_WORD_KEY_IFDEF: + case SCF_LEX_WORD_KEY_IFNDEF: + n_if++; + break; + + case SCF_LEX_WORD_KEY_ELIF: + case SCF_LEX_WORD_KEY_ELSE: + if (n_if <= 1) + goto end; + break; + + case SCF_LEX_WORD_KEY_ENDIF: + if (0 == --n_if) + goto end; + break; + }; + + scf_lex_word_free(w1); + w1 = w2; + } + +end: + *pw1 = w1; + *pw2 = w2; + return 0; +} + +static int __macro_pop_to(scf_lex_t* lex, scf_lex_word_t** h, scf_lex_word_t** pw1, scf_lex_word_t** pw2) +{ + scf_lex_word_t* w1 = NULL; + scf_lex_word_t* w2 = NULL; + + int n_if = 1; + + while (1) { + if (!w1) { + int ret = __lex_pop_word(lex, &w1); + if (ret < 0) + return ret; + } + + if (SCF_LEX_WORD_HASH != w1->type) { + w1->next = *h; + *h = w1; + w1 = NULL; + continue; + } + + int ret = __lex_pop_word(lex, &w2); + if (ret < 0) { + scf_lex_word_free(w1); + return ret; + } + + switch (w2->type) + { + case SCF_LEX_WORD_KEY_IF: + case SCF_LEX_WORD_KEY_IFDEF: + case SCF_LEX_WORD_KEY_IFNDEF: + n_if++; + break; + + case SCF_LEX_WORD_KEY_ELIF: + case SCF_LEX_WORD_KEY_ELSE: + if (n_if <= 1) + goto end; + break; + + case SCF_LEX_WORD_KEY_ENDIF: + if (0 == --n_if) + goto end; + break; + }; + + w1->next = *h; + *h = w1; + w1 = w2; + } + +end: + *pw1 = w1; + *pw2 = w2; + return 0; +} + +static int __parse_macro_argv(scf_lex_t* lex, scf_macro_t* m) +{ + scf_lex_word_t* w = NULL; + scf_lex_word_t* w2; + + int comma = 0; + int id = 0; + + while (1) { + int ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + if (!comma) { + if (SCF_LEX_WORD_RP == w->type) { + scf_lex_word_free(w); + break; + } + + if (SCF_LEX_WORD_COMMA == w->type) { + scf_lex_word_free(w); + w = NULL; + + if (!id) { + scf_loge("an identity is needed before ',' in file: %s, line: %d\n", w->file->data, w->line); + return -EINVAL; + } + + id = 0; + comma = 1; + continue; + } + } + + if (!scf_lex_is_identity(w)) { + scf_loge("macro arg '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -EINVAL; + } + + if (id) { + scf_loge("',' is needed before macro arg '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -EINVAL; + } + + int i; + for (i = 0; i < m->argv->size; i++) { + w2 = m->argv->data[i]; + + if (!scf_string_cmp(w2->text, w->text)) { + scf_loge("macro has same args '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -EINVAL; + } + } + + scf_logw("macro '%s' arg: %s\n", m->w->text->data, w->text->data); + + ret = scf_vector_add(m->argv, w); + if (ret < 0) { + scf_lex_word_free(w); + return ret; + } + w = NULL; + + id = 1; + comma = 0; + } + + return 0; +} + +int __parse_macro_define(scf_lex_t* lex, int def_flag) +{ + scf_lex_word_t** pp; + scf_lex_word_t* w = NULL; + scf_macro_t* m; + scf_macro_t* m0; + + int ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + if (!scf_lex_is_identity(w)) { + scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -EINVAL; + } + + m = scf_macro_alloc(w); + if (!m) { + scf_lex_word_free(w); + return -ENOMEM; + } + + w = NULL; + ret = __lex_pop_word(lex, &w); + if (ret < 0) { + scf_macro_free(m); + return ret; + } + + if (SCF_LEX_WORD_LP == w->type) { + scf_lex_word_free(w); + w = NULL; + + m->argv = scf_vector_alloc(); + if (!m->argv) { + scf_macro_free(m); + return -ENOMEM; + } + + ret = __parse_macro_argv(lex, m); + if (ret < 0) { + scf_macro_free(m); + return ret; + } + } + + pp = &m->text_list; + + while (1) { + if (w) { + scf_logw("w: '%s', file: %s, line: %d\n", w->text->data, w->file->data, w->line); + + if (SCF_LEX_WORD_LF == w->type) { + scf_lex_word_free(w); + w = NULL; + break; + } + + *pp = w; + pp = &w->next; + w = NULL; + } + + ret = __lex_pop_word(lex, &w); + if (ret < 0) { + scf_macro_free(m); + return ret; + } + } + + if (lex->macros) { + int i; + for (i = lex->macros->size - 1; i >= 0; i--) { + m0 = lex->macros->data[i]; + + if (!scf_string_cmp(m->w->text, m0->w->text)) { + scf_logw("macro '%s' defined before in file: %s, line: %d\n", + m0->w->text->data, m0->w->file->data, m0->w->line); + break; + } + } + } else { + lex->macros = scf_vector_alloc(); + if (!lex->macros) + return -ENOMEM; + } + + ret = scf_vector_add(lex->macros, m); + if (ret < 0) { + scf_macro_free(m); + return ret; + } + + m->def_flag = def_flag; + + scf_logw("macro '%s', def_flag: %d, file: %s, line: %d\n", + m->w->text->data, m->def_flag, m->w->file->data, m->w->line); + return 0; +} + +int __parse_macro_ifdef(scf_lex_t* lex, int def_flag) +{ + scf_lex_word_t** pp; + scf_lex_word_t* w = NULL; + scf_macro_t* m; + + int ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + if (!scf_lex_is_identity(w)) { + scf_loge("macro '%s' should be an identity, file: %s, line: %d\n", w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -EINVAL; + } + + ret = __macro_drop_to_LF(lex); + if (ret < 0) + return ret; + + int found = 0; + int i; + + if (lex->macros) { + for (i = lex->macros->size - 1; i >= 0; i--) { + m = lex->macros->data[i]; + + if (m->def_flag && !scf_string_cmp(m->w->text, w->text)) { + found = 1; + break; + } + } + } + + scf_logw("macro '%s', found: %d, def_flag: %d, file: %s, line: %d\n", + w->text->data, found, def_flag, w->file->data, w->line); + + scf_lex_word_t* h = NULL; + scf_lex_word_t* w1 = NULL; + scf_lex_word_t* w2 = NULL; + + if (found != def_flag) { + ret = __macro_drop_to(lex, &w1, &w2); + if (ret < 0) + return ret; + + if (SCF_LEX_WORD_KEY_ENDIF == w2->type) { + scf_lex_word_free(w2); + scf_lex_word_free(w1); + + return __macro_drop_to_LF(lex); + } + + scf_lex_push_word(lex, w2); + scf_lex_push_word(lex, w1); + return 0; + } + + ret = __macro_pop_to(lex, &h, &w1, &w2); + if (ret < 0) { + scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free); + return ret; + } + + int type = w2->type; + + scf_lex_word_free(w2); + scf_lex_word_free(w1); + w1 = NULL; + w2 = NULL; + + while (SCF_LEX_WORD_KEY_ENDIF != type) { + + ret = __macro_drop_to(lex, &w1, &w2); + if (ret < 0) { + scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free); + return ret; + } + + type = w2->type; + + scf_lex_word_free(w2); + scf_lex_word_free(w1); + w1 = NULL; + w2 = NULL; + } + + ret = __macro_drop_to_LF(lex); + if (ret < 0) { + scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free); + return ret; + } + + while (h) { + w1 = h; + h = h->next; + + scf_lex_push_word(lex, w1); + } + + return 0; +} + +static int __fill_macro_argv(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use, scf_vector_t* argv) +{ + scf_lex_word_t** pp; + scf_lex_word_t* w = NULL; + + int ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + if (SCF_LEX_WORD_LP != w->type) { + scf_loge("macro '%s' needs args, file: %s, line: %d\n", m->w->text->data, w->file->data, w->line); + scf_lex_word_free(w); + return -1; + } + + scf_lex_word_free(w); + w = NULL; + + int n_lps = 0; + int n_rps = 0; + int i; + + pp = NULL; + + while (1) { + ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + + if (SCF_LEX_WORD_COMMA == w->type) { + if (!pp) { + scf_loge("unexpected ',' in macro '%s', file: %s, line: %d\n", m->w->text->data, w->file->data, w->line); + + scf_lex_word_free(w); + ret = -1; + goto error; + } + + scf_lex_word_free(w); + w = NULL; + + if (n_rps == n_lps) + pp = NULL; + continue; + + } else if (SCF_LEX_WORD_LP == w->type) + n_lps++; + else if (SCF_LEX_WORD_RP == w->type) { + n_rps++; + + if (n_rps > n_lps) { + scf_lex_word_free(w); + w = NULL; + break; + } + } + + w->next = NULL; + + if (pp) + *pp = w; + else { + ret = scf_vector_add(argv, w); + if (ret < 0) { + scf_lex_word_free(w); + goto error; + } + } + + pp = &w->next; + w = NULL; + } + + if (m->argv->size != argv->size) { + scf_loge("macro '%s' needs %d args, but in fact give %d args, file: %s, line: %d\n", + m->w->text->data, m->argv->size, argv->size, use->file->data, use->line); + ret = -1; + goto error; + } + + return 0; + +error: + for (i = 0; i < argv->size; i++) { + w = argv->data[i]; + scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free); + } + + argv->size = 0; + return ret; +} + +static int __convert_str(scf_lex_word_t* h) +{ + scf_lex_word_t* w; + scf_string_t* s; + + if (h->type != SCF_LEX_WORD_CONST_STRING) { + h->type = SCF_LEX_WORD_CONST_STRING; + + h->data.s = scf_string_clone(h->text); + if (!h->data.s) + return -ENOMEM; + } + + while ( h->next) { + w = h->next; + + if (SCF_LEX_WORD_CONST_STRING != w->type) + s = w->text; + else + s = w->data.s; + + int ret = scf_string_cat(h->data.s, s); + if (ret < 0) + return ret; + + ret = scf_string_cat(h->text, w->text); + if (ret < 0) + return ret; + + h->next = w->next; + + scf_lex_word_free(w); + w = NULL; + } + + scf_logw("h: '%s', file: %s, line: %d\n", h->data.s->data, h->file->data, h->line); + return 0; +} + +static scf_macro_t* __find_macro(scf_lex_t* lex, scf_lex_word_t* w) +{ + if (!lex->macros) + return NULL; + + scf_macro_t* m; + int i; + + for (i = lex->macros->size - 1; i >= 0; i--) { + m = lex->macros->data[i]; + + if (!scf_string_cmp(m->w->text, w->text)) + return m; + } + + return NULL; +} + +static int __use_macro(scf_lex_t* lex, scf_macro_t* m, scf_lex_word_t* use) +{ + scf_lex_word_t** pp; + scf_lex_word_t* p; + scf_lex_word_t* h; + scf_lex_word_t* w; + scf_lex_word_t* prev; + scf_vector_t* argv = NULL; + + if (m->argv) { + argv = scf_vector_alloc(); + if (!argv) + return -ENOMEM; + + int ret = __fill_macro_argv(lex, m, use, argv); + if (ret < 0) { + scf_vector_free(argv); + return ret; + } + } + + h = NULL; + pp = &h; + + int ret = 0; + int hash = 0; + int i; + + for (p = m->text_list; p; p = p->next) { + + if (SCF_LEX_WORD_HASH == p->type) { + hash = 1; + continue; + } + + scf_logd("p: '%s', line: %d, hash: %d\n", p->text->data, p->line, hash); + + if (m->argv) { + assert(argv); + assert(argv->size >= m->argv->size); + + for (i = 0; i < m->argv->size; i++) { + w = m->argv->data[i]; + + if (!scf_string_cmp(w->text, p->text)) + break; + } + + if (i < m->argv->size) { + scf_lex_word_t** tmp = pp; + + for (w = argv->data[i]; w; w = w->next) { + + *pp = scf_lex_word_clone(w); + if (!*pp) { + ret = -ENOMEM; + goto error; + } + + if (!strcmp((*pp)->text->data, "__LINE__")) + (*pp)->data.u64 = use->line; + + pp = &(*pp)->next; + } + + if (1 == hash) { + ret = __convert_str(*tmp); + if (ret < 0) + goto error; + + pp = &(*tmp)->next; + } + + hash = 0; + continue; + } + } + + *pp = scf_lex_word_clone(p); + if (!*pp) { + ret = -ENOMEM; + goto error; + } + + if (!strcmp((*pp)->text->data, "__LINE__")) + (*pp)->data.u64 = use->line; + + pp = &(*pp)->next; + + hash = 0; + } + +error: + if (argv) { + for (i = 0; i < argv->size; i++) { + w = argv->data[i]; + + if (w) + scf_slist_clear(w, scf_lex_word_t, next, scf_lex_word_free); + } + + scf_vector_free(argv); + argv = NULL; + } + + if (ret < 0) { + scf_slist_clear(h, scf_lex_word_t, next, scf_lex_word_free); + return ret; + } + +#if 0 + w = h; + while (w) { + scf_logi("---------- %s, line: %d\n", w->text->data, w->line); + w = w->next; + } +#endif + *pp = lex->word_list; + lex->word_list = h; + return 0; +} + +static int __use_hash2(scf_lex_t* lex, scf_lex_word_t* prev) +{ + scf_lex_word_t* after = NULL; + + int ret = __lex_pop_word(lex, &after); + if (ret < 0) + return ret; + + switch (after->type) { + + case SCF_LEX_WORD_ID: + ret = scf_string_cat(prev->text, after->text); + break; + + default: + ret = -1; + scf_loge("needs identity after '##', file: %s, line: %d\n", after->file->data, after->line); + break; + }; + + scf_lex_word_free(after); + return ret; +} + +int __lex_use_macro(scf_lex_t* lex, scf_lex_word_t** pp) +{ + scf_lex_word_t* w1 = NULL; + scf_lex_word_t* w = *pp; + scf_macro_t* m; + + *pp = NULL; + + while (SCF_LEX_WORD_ID == w->type) { + + m = __find_macro(lex, w); + if (m) { + int ret = __use_macro(lex, m, w); + + scf_lex_word_free(w); + w = NULL; + if (ret < 0) + return ret; + + ret = __lex_pop_word(lex, &w); + if (ret < 0) + return ret; + continue; + } + + int ret = __lex_pop_word(lex, &w1); + if (ret < 0) { + scf_lex_word_free(w); + return ret; + } + + if (SCF_LEX_WORD_HASH2 != w1->type) { + scf_lex_push_word(lex, w1); + break; + } + + scf_lex_word_free(w1); + w1 = NULL; + + ret = __use_hash2(lex, w); + if (ret < 0) { + scf_lex_word_free(w); + return ret; + } + } + + *pp = w; + return 0; +} diff --git a/js/native/risc/scf_arm32.c b/js/native/risc/scf_arm32.c index b3193be..dbb7cf3 100644 --- a/js/native/risc/scf_arm32.c +++ b/js/native/risc/scf_arm32.c @@ -22,7 +22,7 @@ int arm32_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // mov rd, imm[15:0] opcode = (0xe3 << 24) | (((imm >> 12 ) & 0xf) << 16) | (rd->id << 12) | (imm & 0xfff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); imm >>= 16; if (imm & 0xffff) { @@ -30,7 +30,7 @@ int arm32_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // movk rd, imm[31:16] opcode = (0xe3 << 24) | (0x1 << 22) | (((imm >> 12 ) & 0xf) << 16) | (rd->id << 12) | (imm & 0xfff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; @@ -70,28 +70,28 @@ int arm32_inst_ADR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else if (vs->global_flag) { offset = 0; opcode = (0xe3 << 24) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_ARM_REL32; opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { scf_loge("temp var should give a register\n"); @@ -126,21 +126,21 @@ int arm32_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf opcode = (0xe3 << 24) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_ARM_REL32; opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); rb = rd; @@ -255,7 +255,7 @@ int arm32_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf opcode = (0xe0 << 24) | (0x8 << 20) | (r12->id << 16) | (r12->id << 12) | rb->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe8 << 24) | (0xd << 20) | (r12->id << 16) | (1 << rd->id) | (1 << (rd->id + 1)); } @@ -263,7 +263,7 @@ int arm32_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -296,21 +296,21 @@ int arm32_inst_G2MF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, sc opcode = (0xe3 << 24) | (rb->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vd, NULL); rela->type = R_ARM_REL32; opcode = (0xe3 << 24) | (0x4 << 20) | (rb->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe7 << 24) | (0x9 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { scf_loge("temp var should give a register\n"); @@ -364,14 +364,14 @@ int arm32_inst_G2MF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, sc opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xed << 24) | (0x8 << 20) | (r12->id << 16) | (0x2 << 10) | (SIZE << 8) | 0; } opcode |= (D << 22) | (V << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -497,7 +497,7 @@ int arm32_inst_G2M(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf opcode = (0xe0 << 24) | (0x8 << 20) | (r12->id << 16) | (r12->id << 12) | rb->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe8 << 24) | (0xc << 20) | (r12->id << 16) | (1 << rs->id) | (1 << (rs->id + 1)); } @@ -505,7 +505,7 @@ int arm32_inst_G2M(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -528,21 +528,21 @@ int arm32_inst_ISTR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, opcode = (0xe3 << 24) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); rela->type = R_ARM_REL32; opcode = (0xe3 << 24) | (0x4 << 20) | (rd->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe7 << 24) | (0x9 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe0 << 24) | (0x8 << 20) | (rd->id << 16) | (rd->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -593,13 +593,13 @@ int arm32_inst_G2PF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, sc opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xed << 24) | (0x8 << 20) | (D << 22) | (r12->id << 16) | (Vd << 12) | (0x2 << 10) | (SIZE << 8) | 0; } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -684,7 +684,7 @@ int arm32_inst_G2P(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -768,7 +768,7 @@ int arm32_inst_P2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -795,7 +795,7 @@ int arm32_inst_ADRP2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -826,7 +826,7 @@ int arm32_inst_ADRSIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rd->id << 12) | (SH << 7) | ri->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -858,7 +858,7 @@ int arm32_inst_SIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -891,7 +891,7 @@ int arm32_inst_G2SIB(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, s return -EINVAL; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -923,21 +923,21 @@ int arm32_inst_M2GF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc opcode = (0xe3 << 24) | (rb->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_ARM_REL32; opcode = (0xe3 << 24) | (0x4 << 20) | (rb->id << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe7 << 24) | (0x9 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (rb->id << 12) | 0xf; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { scf_loge("temp var should give a register\n"); @@ -992,14 +992,14 @@ int arm32_inst_M2GF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc opcode = (0xe0 << 24) | (0x8 << 20) | (rb->id << 16) | (r12->id << 12) | (0x2 << 7) | r12->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode = (0xed << 24) | (0x9 << 20) | (r12->id << 16) | (0x2 << 10) | (SIZE << 8) | 0; } opcode |= (D << 22) | (V << 12); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1937,7 +1937,7 @@ int arm32_inst_BL(scf_3ac_code_t* c, scf_function_t* f, scf_function_t* pf) opcode = 0xeb << 24; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf); rela->type = R_ARM_CALL; @@ -2151,7 +2151,7 @@ int arm32_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cm i0 = (opcode >> 16) & 0xf; r0 = f->rops->find_register_type_id_bytes(0, i0, 4); inst = f->iops->MOV_G(c, r12, r0); // use r12 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~(0xf << 16); opcode |= (0xc << 16); @@ -2163,11 +2163,11 @@ int arm32_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cm r0 = f->rops->find_register_type_id_bytes(0, i0, 4); inst = f->iops->MOV_G(c, r12, r0); // use r16 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); r0 = f->rops->find_register_type_id_bytes(0, i1, 4); inst = f->iops->MOV_G(c, r14, r0); // use r17 to backup r1 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~(0xf << 16); opcode |= (0xc << 16); @@ -2215,7 +2215,7 @@ int arm32_set_rel_veneer(scf_function_t* f) int offset = bytes - r->inst_offset - 16; // 'pc = current + 8' inst = risc_make_inst(end, offset - 4); - RISC_INST_ADD_CHECK(end->instructions, inst); + RISC_INST_ADD_CHECK(end, inst); r->inst_offset = bytes; @@ -2230,16 +2230,16 @@ int arm32_set_rel_veneer(scf_function_t* f) r->inst->code[2] |= 0x0f & (offset >> 12); int j; - for (j = 0; j < r->code->instructions->size; j++) { - inst = r->code->instructions->data[j]; + for (j = 0; j < r->inst->c->instructions->size; j++) { + inst = r->inst->c->instructions->data[j]; if (inst == r->inst) break; } - assert(r->code->instructions->size > j + 1); + assert(r->inst->c->instructions->size > j + 1); - inst = r->code->instructions->data[j + 1]; + inst = r->inst->c->instructions->data[j + 1]; inst->code[0] = 0xff & (offset >> 16); inst->code[1] &= 0xf0; @@ -2337,4 +2337,3 @@ scf_inst_ops_t inst_ops_arm32 = .set_jmp_offset = arm32_set_jmp_offset, .set_rel_veneer = arm32_set_rel_veneer, }; - diff --git a/js/native/risc/scf_arm64.c b/js/native/risc/scf_arm64.c index 618e909..ae8711d 100644 --- a/js/native/risc/scf_arm64.c +++ b/js/native/risc/scf_arm64.c @@ -12,13 +12,13 @@ int arm64_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // movn rd, invert[15:0] opcode = (0x92 << 24) | (0x1 << 23) | ((invert & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (invert >> 16) { // movk rd, imm[31:16] opcode = (0xf2 << 24) | (0x1 << 23) | (0x1 << 21) | (((imm >> 16) & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; @@ -27,14 +27,14 @@ int arm64_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // mov rd, imm[15:0] opcode = (0xd2 << 24) | (0x1 << 23) | ((imm & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if ((imm >> 16) & 0xffff) { // movk rd, imm[31:16] opcode = (0xf2 << 24) | (0x1 << 23) | (0x1 << 21) | (((imm >> 16) & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } if (8 == bytes) { @@ -44,7 +44,7 @@ int arm64_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // movk rd, imm[47:32] opcode = (0xf2 << 24) | (0x1 << 23) | (0x2 << 21) | (((imm >> 32) & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } if ((imm >> 48) & 0xffff) { @@ -52,7 +52,7 @@ int arm64_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int byte // movk rd, imm[63:48] opcode = (0xf2 << 24) | (0x1 << 23) | (0x3 << 21) | (((imm >> 48) & 0xffff) << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } } @@ -93,20 +93,20 @@ int arm64_inst_ADR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else if (vs->global_flag) { offset = 0; opcode = (0x90 << 24) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0x91 << 24) | (rd->id << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -143,13 +143,13 @@ int arm64_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf opcode = (0x90 << 24) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0x91 << 24) | (rd->id << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -234,7 +234,7 @@ int arm64_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf opcode |= RISC_COLOR_TYPE(rd->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -346,7 +346,7 @@ int arm64_inst_G2M(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf opcode |= RISC_COLOR_TYPE(rs->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -369,13 +369,13 @@ int arm64_inst_ISTR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, opcode = (0x90 << 24) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0x91 << 24) | (rd->id << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -456,7 +456,7 @@ int arm64_inst_G2P(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf opcode |= RISC_COLOR_TYPE(rs->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -535,7 +535,7 @@ int arm64_inst_P2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf opcode |= RISC_COLOR_TYPE(rd->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -574,7 +574,7 @@ int arm64_inst_ADRP2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -608,7 +608,7 @@ int arm64_inst_ADRSIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd opcode = (0x8b << 24) | (ri->id << 16) | (SH << 10) | (rb->id << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -653,7 +653,7 @@ int arm64_inst_SIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s opcode |= RISC_COLOR_TYPE(rd->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -699,7 +699,7 @@ int arm64_inst_G2SIB(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, s opcode |= RISC_COLOR_TYPE(rs->color) << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -733,13 +733,13 @@ int arm64_inst_M2GF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc opcode = (0x90 << 24) | rb->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0x91 << 24) | (rb->id << 5) | rb->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -812,7 +812,7 @@ int arm64_inst_M2GF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc opcode |= (SIZE << 30) | (rb->id << 5) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1314,7 +1314,7 @@ int arm64_inst_BL(scf_3ac_code_t* c, scf_function_t* f, scf_function_t* pf) opcode = 0x25 << 26; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf); rela->type = R_AARCH64_CALL26; @@ -1550,7 +1550,7 @@ int arm64_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cm i0 = (opcode >> 5) & 0x1f; r0 = f->rops->find_register_type_id_bytes(0, i0, 8); inst = f->iops->MOV_G(c, r16, r0); // use r16 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~(0x1f << 5); opcode |= (0x10 << 5); @@ -1562,11 +1562,11 @@ int arm64_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cm r0 = f->rops->find_register_type_id_bytes(0, i0, 8); inst = f->iops->MOV_G(c, r16, r0); // use r16 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); r0 = f->rops->find_register_type_id_bytes(0, i1, 8); inst = f->iops->MOV_G(c, r17, r0); // use r17 to backup r1 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~(0x1f << 5); opcode |= (0x10 << 5); diff --git a/js/native/risc/scf_naja.c b/js/native/risc/scf_naja.c index ef56dff..6042b04 100644 --- a/js/native/risc/scf_naja.c +++ b/js/native/risc/scf_naja.c @@ -1,15 +1,5 @@ #include"scf_risc.h" - -static uint32_t naja_shift(int bytes) -{ - if (bytes <= 1) - return 0; - else if (bytes <= 2) - return 1; - else if (bytes <= 4) - return 2; - return 3; -} +#include"scf_naja_inst.c" int naja_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int bytes) { @@ -23,22 +13,21 @@ int naja_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int bytes // mvn rd, invert[15:0] opcode = (0xe << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | (invert & 0xffff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (invert >> 16) { // movt rd, imm[31:16] opcode = (0xe << 26) | (rd->id << 21) | (0x1 << 18) | (0x2 << 16)| ((imm >> 16) & 0xffff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; } // mov rd, imm[15:0] - opcode = (0xe << 26) | (rd->id << 21) | (0x2 << 16) | (imm & 0xffff); - inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + inst = naja_inst_MOV_IMM(c, rd, imm & 0xffff); + RISC_INST_ADD_CHECK(c, inst); imm >>= 16; if (imm & 0xffff) { @@ -46,7 +35,7 @@ int naja_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int bytes // movt rd, imm[31:16] opcode = (0xe << 26) | (rd->id << 21) | (1 << 18) | (0x2 << 16) | (imm & 0xffff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } imm >>= 16; @@ -55,7 +44,7 @@ int naja_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int bytes // movk rd, imm[47:32] opcode = (0xe << 26) | (rd->id << 21) | (2 << 18) | (0x2 << 16) | (imm & 0xffff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } imm >>= 16; @@ -64,7 +53,7 @@ int naja_inst_I2G(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm, int bytes // movk rd, imm[63:48] opcode = (0xe << 26) | (rd->id << 21) | (3 << 18) | (0x2 << 16) | (imm & 0xffff); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; @@ -91,7 +80,7 @@ int naja_inst_ADR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc opcode = (0 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | (offset << 4) | fp->id; - else if (offset < 0 && -offset <= 0x3fff) + else if (offset < 0 && -offset <= 0xfff) opcode = (1 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | ((-offset) << 4) | fp->id; @@ -104,20 +93,19 @@ int naja_inst_ADR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, sc } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else if (vs->global_flag) { offset = 0; - opcode = (0x35 << 26) | (rd->id << 21); - inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + inst = __naja_inst_ADRP(c, rd); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, vs, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -232,7 +220,7 @@ int naja_inst_M2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_ opcode |= RISC_COLOR_TYPE(rd->color) << 30; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -341,7 +329,7 @@ int naja_inst_G2M(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf_ // opcode |= (1 << 18); inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -362,15 +350,14 @@ int naja_inst_ISTR2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s uint32_t opcode; - opcode = (0x35 << 26) | (rd->id << 21); - inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + inst = __naja_inst_ADRP(c, rd); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); rela->type = R_AARCH64_ADR_PREL_PG_HI21; opcode = (0 << 26) | (rd->id << 21) | (0x3 << 18) | (0x3 << 16) | rd->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); rela->type = R_AARCH64_ADD_ABS_LO12_NC; @@ -443,7 +430,7 @@ int naja_inst_G2P(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf_ opcode |= RISC_COLOR_TYPE(rs->color) << 30; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -514,7 +501,7 @@ int naja_inst_P2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_ opcode |= RISC_COLOR_TYPE(rd->color) << 30; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -544,7 +531,7 @@ int naja_inst_ADRP2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, s } inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -578,89 +565,23 @@ int naja_inst_ADRSIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, opcode = (0 << 26) | (rd->id << 21) | (3 << 18) | (SH << 16) | (ri->id << 4) | rb->id; inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } int naja_inst_SIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_sib_t* sib) { - scf_register_t* rb = sib->base; - scf_register_t* ri = sib->index; - scf_instruction_t* inst = NULL; - - assert(0 == sib->disp); - - if (!rb || !ri) - return -EINVAL; - - int scale = sib->scale; - int size = sib->size; - - uint32_t opcode; - uint32_t SIZE = 0; - - if (1 == size) - SIZE = 0; - - else if (2 == size) - SIZE = 1; - - else if (4 == size) - SIZE = 2; - - else if (8 == size) - SIZE = 3; - else - return -EINVAL; - - opcode = (0xa << 26) | (rd->id << 21) | (SIZE << 10) | (ri->id << 4) | rb->id; - opcode |= SIZE << 18; - opcode |= RISC_COLOR_TYPE(rd->color) << 30; - - inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + scf_instruction_t* inst = __naja_inst_SIB2G(c, rd, sib); + RISC_INST_ADD_CHECK(c, inst); return 0; } int naja_inst_G2SIB(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, scf_sib_t* sib) { - scf_register_t* rb = sib->base; - scf_register_t* ri = sib->index; - scf_instruction_t* inst = NULL; - - assert(0 == sib->disp); - - if (!rb || !ri) - return -EINVAL; - - int scale = sib->scale; - int size = sib->size; - - uint32_t opcode; - uint32_t SIZE = 0; - - if (1 == size) - SIZE = 0; - - else if (2 == size) - SIZE = 1; - - else if (4 == size) - SIZE = 2; - - else if (8 == size) - SIZE = 3; - else - return -EINVAL; - - opcode = (0xb << 26) | (rs->id << 21) | (SIZE << 10) | (ri->id << 4) | rb->id; - opcode |= SIZE << 18; - opcode |= RISC_COLOR_TYPE(rs->color) << 16; - - inst = risc_make_inst(c, opcode); - RISC_INST_ADD_CHECK(c->instructions, inst); + scf_instruction_t* inst = __naja_inst_G2SIB(c, rs, sib); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -669,701 +590,20 @@ int naja_inst_M2GF(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf return naja_inst_M2G(c, f, rd, rb, vs); } -scf_instruction_t* naja_inst_PUSH(scf_3ac_code_t* c, scf_register_t* r) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x9 << 26) | (r->id << 21) | (3 << 18) | 0xe; - opcode |= RISC_COLOR_TYPE(r->color) << 17; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_POP(scf_3ac_code_t* c, scf_register_t* r) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x8 << 26) | (r->id << 21) | (3 << 18) | 0xe; - opcode |= RISC_COLOR_TYPE(r->color) << 17; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_RET(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = 0x36 << 26; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MOV_SP(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xc << 26) | (rd->id << 21) | (3 << 18) | (0xf << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MOV_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MVN(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xe << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FMOV_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x1c << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MOVSX(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs, int size) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (1 == size) - SH = 0; - else if (2 == size) - SH = 1; - else if (4 == size) - SH = 2; - else - return NULL; - - opcode = (0xd << 26) | (rd->id << 21) | (SH << 18) | (1 << 17) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MOVZX(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs, int size) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (1 == size) - SH = 0; - else if (2 == size) - SH = 1; - else if (4 == size) - SH = 2; - else - return NULL; - - opcode = (0xd << 26) | (rd->id << 21) | (SH << 18) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTSS2SD(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t S; - - opcode = (0x1d << 26) | (rd->id << 21) | (3 << 18) | (1 << 12) | (1 << 6) | (2 << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTSD2SS(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x1d << 26) | (rd->id << 21) | (2 << 18) | (1 << 12) | (1 << 6) | (3 << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTF2SI(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (4 == rd->bytes) - SH = 2; - else - SH = 3; - - opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (3 << 12) | (1 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTF2UI(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (4 == rd->bytes) - SH = 2; - else - SH = 3; - - opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (2 << 12) | (1 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTSI2F(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (4 == rd->bytes) - SH = 2; - else - SH = 3; - - opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (1 << 12) | (3 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CVTUI2F(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t SH; - - if (4 == rd->bytes) - SH = 2; - else - SH = 3; - - opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (1 << 12) | (2 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SUB_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_register_t* rs, uint64_t imm) -{ - scf_instruction_t* inst; - uint32_t opcode; - - if (imm > 0xfff) { - scf_loge("NOT support too big imm: %#lx\n", imm); - return NULL; - } - - opcode = (1 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CMP_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, uint64_t imm) -{ - scf_instruction_t* inst; - uint32_t opcode; - - if (imm > 0xfff) { - scf_loge("NOT support too big imm: %#lx\n", imm); - return NULL; - } - - opcode = (1 << 26) | (0xf << 21) | (naja_shift(rs->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_ADD_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_register_t* rs, uint64_t imm) -{ - scf_instruction_t* inst; - uint32_t opcode; - - if (imm > 0xfff) { - scf_loge("NOT support too big imm: %#lx\n", imm); - return NULL; - } - - opcode = (0 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_ADD_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SHL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SHR(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_ASR(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (2 << 16) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_AND_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x5 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_OR_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x7 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SUB_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (1 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_CMP_G(scf_3ac_code_t* c, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (1 << 26) | (0xf << 21) | (naja_shift(rs0->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FCMP(scf_3ac_code_t* c, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x11 << 26) | (0xf << 21) | (naja_shift(rs0->bytes) << 18) | (1 << 16) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_NEG(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0xe << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_TEQ(scf_3ac_code_t* c, scf_register_t* rs) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x5 << 26) | (0xf << 21) | (naja_shift(rs->bytes) << 18) | (rs->id << 4) | rs->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FADD(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x10 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FSUB(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x11 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MUL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (2 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 12) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FMUL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x12 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 12) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_FDIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x13 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_DIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (3 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SDIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (3 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 17) | (rs1->id << 4) | rs0->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_MSUB(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rm, scf_register_t* rn, scf_register_t* ra) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (2 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | (ra->id << 12) | (rm->id << 4) | rn->id; - inst = risc_make_inst(c, opcode); - - return inst; -} - int naja_inst_BL(scf_3ac_code_t* c, scf_function_t* f, scf_function_t* pf) { scf_instruction_t* inst; scf_rela_t* rela; - uint32_t opcode; - opcode = (0x31 << 26); - inst = risc_make_inst(c, opcode); + inst = __naja_inst_BL(c, 0); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf); rela->type = R_AARCH64_CALL26; return 0; } -scf_instruction_t* naja_inst_BLR(scf_3ac_code_t* c, scf_register_t* r) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x33 << 26) | (r->id << 21); - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_SETZ(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t cc = 1; - - opcode = (0x34 << 26) | (rd->id << 21); - inst = risc_make_inst(c, opcode); - - return inst; -} -scf_instruction_t* naja_inst_SETNZ(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - uint32_t cc = 0; - - opcode = (0x34 << 26) | (rd->id << 21) | (1 << 1); - inst = risc_make_inst(c, opcode); - - return inst; -} -scf_instruction_t* naja_inst_SETGT(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x34 << 26) | (rd->id << 21) | (3 << 1); - inst = risc_make_inst(c, opcode); - - return inst; -} -scf_instruction_t* naja_inst_SETGE(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x34 << 26) | (rd->id << 21) | (2 << 1); - inst = risc_make_inst(c, opcode); - - return inst; -} -scf_instruction_t* naja_inst_SETLT(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x34 << 26) | (rd->id << 21) | (5 << 1); - inst = risc_make_inst(c, opcode); - - return inst; -} -scf_instruction_t* naja_inst_SETLE(scf_3ac_code_t* c, scf_register_t* rd) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x34 << 26) | (rd->id << 21) | (4 << 1); - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JMP(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = 0x30 << 26; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JZ(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JNZ(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | (1 << 1) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JGT(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | (3 << 1) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JGE(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | (2 << 1) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JLT(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | (5 << 1) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JLE(scf_3ac_code_t* c) -{ - scf_instruction_t* inst; - uint32_t opcode; - - opcode = (0x32 << 26) | (4 << 1) | 1; - inst = risc_make_inst(c, opcode); - - return inst; -} - -scf_instruction_t* naja_inst_JA(scf_3ac_code_t* c) -{ - return NULL; -} -scf_instruction_t* naja_inst_JB(scf_3ac_code_t* c) -{ - return NULL; -} -scf_instruction_t* naja_inst_JAE(scf_3ac_code_t* c) -{ - return NULL; -} -scf_instruction_t* naja_inst_JBE(scf_3ac_code_t* c) -{ - return NULL; -} - -void naja_set_jmp_offset(scf_instruction_t* inst, int32_t bytes) -{ - uint32_t opcode; - - opcode = inst->code[0]; - opcode |= inst->code[1] << 8; - opcode |= inst->code[2] << 16; - opcode |= inst->code[3] << 24; - - if (0x32 == (opcode >> 26) && 1 == (opcode & 1)) { - - if (bytes >= 0 && bytes < (0x1 << 20)) { - bytes >>= 2; - bytes <<= 5; - - } else if (bytes < 0 && bytes > -(0x1 << 20)) { - - bytes >>= 2; - bytes &= 0x1fffff; - bytes <<= 5; - } else - assert(0); - - inst->code[0] |= 0xff & bytes; - inst->code[1] |= 0xff & (bytes >> 8); - inst->code[2] |= 0xff & (bytes >> 16); - inst->code[3] |= 0x3 & (bytes >> 24); - - } else { - assert(0x30 == (opcode >> 26)); - - bytes >>= 2; - - assert(bytes < (0x1 << 26) && bytes > -(0x1 << 26)); - - inst->code[0] |= 0xff & bytes; - inst->code[1] |= 0xff & (bytes >> 8); - inst->code[2] |= 0xff & (bytes >> 16); - inst->code[3] |= 0x3 & (bytes >> 24); - } -} - int naja_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cmp) { scf_instruction_t* inst; @@ -1391,7 +631,7 @@ int naja_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cmp i0 = opcode & 0xf; r0 = f->rops->find_register_type_id_bytes(0, i0, 8); inst = f->iops->MOV_G(c, r10, r0); // use r10 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~0xf; opcode |= 0xa; @@ -1401,11 +641,11 @@ int naja_cmp_update(scf_3ac_code_t* c, scf_function_t* f, scf_instruction_t* cmp r0 = f->rops->find_register_type_id_bytes(0, i0, 8); inst = f->iops->MOV_G(c, r10, r0); // use r10 to backup r0 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); r0 = f->rops->find_register_type_id_bytes(0, i1, 8); inst = f->iops->MOV_G(c, r11, r0); // use r11 to backup r1 - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); opcode &= ~0xf; opcode |= 0xa; diff --git a/js/native/risc/scf_naja_inst.c b/js/native/risc/scf_naja_inst.c new file mode 100644 index 0000000..57bdf09 --- /dev/null +++ b/js/native/risc/scf_naja_inst.c @@ -0,0 +1,911 @@ +#include"scf_risc.h" + +static uint32_t naja_shift(int bytes) +{ + if (bytes <= 1) + return 0; + else if (bytes <= 2) + return 1; + else if (bytes <= 4) + return 2; + return 3; +} + +scf_instruction_t* __naja_inst_ADRP(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x35 << 26) | (rd->id << 21); + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_ADRP, 8,8, SCF_RISC_E2G); + inst->dst.base = rd; + inst->src.mem_flag = 1; + } + + return inst; +} + +scf_instruction_t* __naja_inst_SIB2G(scf_3ac_code_t* c, scf_register_t* rd, scf_sib_t* sib) +{ + scf_register_t* rb = sib->base; + scf_register_t* ri = sib->index; + scf_instruction_t* inst = NULL; + + assert(0 == sib->disp); + + if (!rb || !ri) + return NULL; + + int scale = sib->scale; + int size = sib->size; + + uint32_t opcode; + uint32_t SIZE = 0; + + if (1 == size) + SIZE = 0; + + else if (2 == size) + SIZE = 1; + + else if (4 == size) + SIZE = 2; + + else if (8 == size) + SIZE = 3; + else + return NULL; + + opcode = (0xa << 26) | (rd->id << 21) | (SIZE << 10) | (ri->id << 4) | rb->id; + opcode |= SIZE << 18; + opcode |= RISC_COLOR_TYPE(rd->color) << 30; + + inst = risc_make_inst(c, opcode); + return inst; +} + +scf_instruction_t* __naja_inst_G2SIB(scf_3ac_code_t* c, scf_register_t* rs, scf_sib_t* sib) +{ + scf_register_t* rb = sib->base; + scf_register_t* ri = sib->index; + scf_instruction_t* inst = NULL; + + assert(0 == sib->disp); + + if (!rb || !ri) + return NULL; + + int scale = sib->scale; + int size = sib->size; + + uint32_t opcode; + uint32_t SIZE = 0; + + if (1 == size) + SIZE = 0; + + else if (2 == size) + SIZE = 1; + + else if (4 == size) + SIZE = 2; + + else if (8 == size) + SIZE = 3; + else + return NULL; + + opcode = (0xb << 26) | (rs->id << 21) | (SIZE << 10) | (ri->id << 4) | rb->id; + opcode |= SIZE << 18; + opcode |= RISC_COLOR_TYPE(rs->color) << 16; + + inst = risc_make_inst(c, opcode); + return inst; +} + +scf_instruction_t* naja_inst_PUSH(scf_3ac_code_t* c, scf_register_t* r) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x9 << 26) | (r->id << 21) | (3 << 18) | 0xe; + opcode |= RISC_COLOR_TYPE(r->color) << 17; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_PUSH, 8,8, SCF_RISC_G); + inst->src.base = r; + } + + return inst; +} + +scf_instruction_t* naja_inst_POP(scf_3ac_code_t* c, scf_register_t* r) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x8 << 26) | (r->id << 21) | (3 << 18) | 0xe; + opcode |= RISC_COLOR_TYPE(r->color) << 17; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_POP, 8,8, SCF_RISC_G); + inst->dst.base = r; + } + + return inst; +} + +scf_instruction_t* naja_inst_RET(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = 0x36 << 26; + + inst = risc_make_inst(c, opcode); + if (inst) + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_RET, 8,8, SCF_RISC_G); + + return inst; +} + +scf_instruction_t* naja_inst_MOV_SP(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xc << 26) | (rd->id << 21) | (3 << 18) | (0xf << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_MOV_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 4) | rs->id; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_MOV, 8,8, SCF_RISC_G2E); + inst->dst.base = rd; + inst->src.base = rs; + } + + return inst; +} + +scf_instruction_t* naja_inst_MOV_IMM(scf_3ac_code_t* c, scf_register_t* rd, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0xffff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = (0xe << 26) | (rd->id << 21) | (0x2 << 16) | (imm & 0xffff); + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_MOV, 2,2, SCF_RISC_I2G); + inst->dst.base = rd; + inst->src.imm = imm; + inst->src.imm_size = 2; + } + + return inst; +} + +scf_instruction_t* naja_inst_MVN(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xe << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FMOV_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x1c << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_MOVSX(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs, int size) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (1 == size) + SH = 0; + else if (2 == size) + SH = 1; + else if (4 == size) + SH = 2; + else + return NULL; + + opcode = (0xd << 26) | (rd->id << 21) | (SH << 18) | (1 << 17) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_MOVZX(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs, int size) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (1 == size) + SH = 0; + else if (2 == size) + SH = 1; + else if (4 == size) + SH = 2; + else + return NULL; + + opcode = (0xd << 26) | (rd->id << 21) | (SH << 18) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTSS2SD(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t S; + + opcode = (0x1d << 26) | (rd->id << 21) | (3 << 18) | (1 << 12) | (1 << 6) | (2 << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTSD2SS(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x1d << 26) | (rd->id << 21) | (2 << 18) | (1 << 12) | (1 << 6) | (3 << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTF2SI(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (4 == rd->bytes) + SH = 2; + else + SH = 3; + + opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (3 << 12) | (1 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTF2UI(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (4 == rd->bytes) + SH = 2; + else + SH = 3; + + opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (2 << 12) | (1 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTSI2F(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (4 == rd->bytes) + SH = 2; + else + SH = 3; + + opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (1 << 12) | (3 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CVTUI2F(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t SH; + + if (4 == rd->bytes) + SH = 2; + else + SH = 3; + + opcode = (0x1d << 26) | (rd->id << 21) | (SH << 18) | (1 << 12) | (2 << 6) | (naja_shift(rs->bytes) << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_SUB_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_register_t* rs, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0xfff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = (1 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CMP_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rs, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0xfff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = (1 << 26) | (0xf << 21) | (naja_shift(rs->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_ADD_IMM(scf_3ac_code_t* c, scf_function_t* f, scf_register_t* rd, scf_register_t* rs, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0xfff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = (0 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (3 << 16) | (imm << 4) | rs->id; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_ADD, 8,8, SCF_RISC_E2G); + inst->dst.base = rd; + inst->src.base = rs; + + inst->srcs[0].imm = imm; + inst->srcs[0].imm_size = 2; + } + + return inst; +} + +scf_instruction_t* naja_inst_ADD_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_ADD, 8,8, SCF_RISC_E2G); + inst->dst.base = rd; + inst->src.base = rs0; + + inst->srcs[0].base = rs1; + } + + return inst; +} + +scf_instruction_t* naja_inst_SHL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_SHR(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_ASR(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xc << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (2 << 16) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_AND_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x5 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_OR_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x7 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_SUB_G(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (1 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_CMP_G(scf_3ac_code_t* c, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (1 << 26) | (0xf << 21) | (naja_shift(rs0->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FCMP(scf_3ac_code_t* c, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x11 << 26) | (0xf << 21) | (naja_shift(rs0->bytes) << 18) | (1 << 16) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_NEG(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0xe << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_TEQ(scf_3ac_code_t* c, scf_register_t* rs) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x5 << 26) | (0xf << 21) | (naja_shift(rs->bytes) << 18) | (rs->id << 4) | rs->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FADD(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x10 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FSUB(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x11 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_MUL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (2 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 12) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FMUL(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x12 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (0xf << 12) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_FDIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x13 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_DIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (3 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_SDIV(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rs0, scf_register_t* rs1) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (3 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 17) | (rs1->id << 4) | rs0->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_MSUB(scf_3ac_code_t* c, scf_register_t* rd, scf_register_t* rm, scf_register_t* rn, scf_register_t* ra) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (2 << 26) | (rd->id << 21) | (naja_shift(rd->bytes) << 18) | (1 << 16) | (ra->id << 12) | (rm->id << 4) | rn->id; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_BR(scf_3ac_code_t* c, scf_register_t* r) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (r->id << 21); + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_JMP, 8,8, SCF_RISC_E); + inst->dst.base = r; + } + + return inst; +} + +scf_instruction_t* naja_inst_BLR(scf_3ac_code_t* c, scf_register_t* r) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x33 << 26) | (r->id << 21); + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_CALL, 8,8, SCF_RISC_E); + inst->dst.base = r; + } + + return inst; +} + +scf_instruction_t* __naja_inst_BL(scf_3ac_code_t* c, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0x3ffffff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = (0x31 << 26) | imm; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_CALL, 4,4, SCF_RISC_I); + inst->dst.imm = imm; + inst->dst.imm_size = 4; + } + + return inst; +} + +scf_instruction_t* __naja_inst_JMP(scf_3ac_code_t* c, uint64_t imm) +{ + scf_instruction_t* inst; + uint32_t opcode; + + if (imm > 0x3ffffff) { + scf_loge("NOT support too big imm: %#lx\n", imm); + return NULL; + } + + opcode = 0x30 << 26 | imm; + + inst = risc_make_inst(c, opcode); + if (inst) { + inst->OpCode = (scf_OpCode_t*)risc_find_OpCode(SCF_RISC_JMP, 4,4, SCF_RISC_I); + inst->dst.imm = imm; + inst->dst.imm_size = 4; + } + + return inst; +} + +scf_instruction_t* naja_inst_SETZ(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t cc = 1; + + opcode = (0x34 << 26) | (rd->id << 21); + inst = risc_make_inst(c, opcode); + + return inst; +} +scf_instruction_t* naja_inst_SETNZ(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + uint32_t cc = 0; + + opcode = (0x34 << 26) | (rd->id << 21) | (1 << 1); + inst = risc_make_inst(c, opcode); + + return inst; +} +scf_instruction_t* naja_inst_SETGT(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x34 << 26) | (rd->id << 21) | (3 << 1); + inst = risc_make_inst(c, opcode); + + return inst; +} +scf_instruction_t* naja_inst_SETGE(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x34 << 26) | (rd->id << 21) | (2 << 1); + inst = risc_make_inst(c, opcode); + + return inst; +} +scf_instruction_t* naja_inst_SETLT(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x34 << 26) | (rd->id << 21) | (5 << 1); + inst = risc_make_inst(c, opcode); + + return inst; +} +scf_instruction_t* naja_inst_SETLE(scf_3ac_code_t* c, scf_register_t* rd) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x34 << 26) | (rd->id << 21) | (4 << 1); + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JMP(scf_3ac_code_t* c) +{ + return __naja_inst_JMP(c, 0); +} + +scf_instruction_t* naja_inst_JZ(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JNZ(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (1 << 1) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JGT(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (3 << 1) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JGE(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (2 << 1) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JLT(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (5 << 1) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JLE(scf_3ac_code_t* c) +{ + scf_instruction_t* inst; + uint32_t opcode; + + opcode = (0x32 << 26) | (4 << 1) | 1; + inst = risc_make_inst(c, opcode); + + return inst; +} + +scf_instruction_t* naja_inst_JA(scf_3ac_code_t* c) +{ + return NULL; +} +scf_instruction_t* naja_inst_JB(scf_3ac_code_t* c) +{ + return NULL; +} +scf_instruction_t* naja_inst_JAE(scf_3ac_code_t* c) +{ + return NULL; +} +scf_instruction_t* naja_inst_JBE(scf_3ac_code_t* c) +{ + return NULL; +} + +void naja_set_jmp_offset(scf_instruction_t* inst, int32_t bytes) +{ + uint32_t opcode; + + opcode = inst->code[0]; + opcode |= inst->code[1] << 8; + opcode |= inst->code[2] << 16; + opcode |= inst->code[3] << 24; + + if (0x32 == (opcode >> 26) && 1 == (opcode & 1)) { + + if (bytes >= 0 && bytes < (0x1 << 20)) { + bytes >>= 2; + bytes <<= 5; + + } else if (bytes < 0 && bytes > -(0x1 << 20)) { + + bytes >>= 2; + bytes &= 0x1fffff; + bytes <<= 5; + } else + assert(0); + + opcode &= ~0x1ffffe0; + opcode |= bytes; + + inst->code[0] = 0xff & opcode; + inst->code[1] = 0xff & (opcode >> 8); + inst->code[2] = 0xff & (opcode >> 16); + inst->code[3] = 0xff & (opcode >> 24); + + } else if (0x30 == (opcode >> 26) + || 0x31 == (opcode >> 26)) { + + bytes >>= 2; + + assert(bytes < (0x1 << 26) && bytes > -(0x1 << 26)); + + bytes &= 0x3ffffff; + opcode &= ~0x3ffffff; + opcode |= bytes; + + inst->code[0] = 0xff & opcode; + inst->code[1] = 0xff & (opcode >> 8); + inst->code[2] = 0xff & (opcode >> 16); + inst->code[3] = 0xff & (opcode >> 24); + } +} diff --git a/js/native/risc/scf_naja_reg.c b/js/native/risc/scf_naja_reg.c new file mode 100644 index 0000000..cfa2532 --- /dev/null +++ b/js/native/risc/scf_naja_reg.c @@ -0,0 +1,285 @@ +#include"scf_risc.h" + +#define SCF_RISC_REG_FP 12 +#define SCF_RISC_REG_LR 13 +#define SCF_RISC_REG_SP 14 +#define SCF_RISC_REG_NULL 15 + +scf_register_t naja_registers[] = +{ + {0, 1, "r0b", RISC_COLOR(0, 0, 0x1), NULL, 0, 0}, + {0, 2, "r0w", RISC_COLOR(0, 0, 0x3), NULL, 0, 0}, + {0, 4, "r0d", RISC_COLOR(0, 0, 0xf), NULL, 0, 0}, + {0, 8, "r0", RISC_COLOR(0, 0, 0xff), NULL, 0, 0}, + + {1, 1, "r1b", RISC_COLOR(0, 1, 0x1), NULL, 0, 0}, + {1, 2, "r1w", RISC_COLOR(0, 1, 0x3), NULL, 0, 0}, + {1, 4, "r1d", RISC_COLOR(0, 1, 0xf), NULL, 0, 0}, + {1, 8, "r1", RISC_COLOR(0, 1, 0xff), NULL, 0, 0}, + + {2, 1, "r2b", RISC_COLOR(0, 2, 0x1), NULL, 0, 0}, + {2, 2, "r2w", RISC_COLOR(0, 2, 0x3), NULL, 0, 0}, + {2, 4, "r2d", RISC_COLOR(0, 2, 0xf), NULL, 0, 0}, + {2, 8, "r2", RISC_COLOR(0, 2, 0xff), NULL, 0, 0}, + + {3, 1, "r3b", RISC_COLOR(0, 3, 0x1), NULL, 0, 0}, + {3, 2, "r3w", RISC_COLOR(0, 3, 0x3), NULL, 0, 0}, + {3, 4, "r3d", RISC_COLOR(0, 3, 0xf), NULL, 0, 0}, + {3, 8, "r3", RISC_COLOR(0, 3, 0xff), NULL, 0, 0}, + + {4, 1, "r4b", RISC_COLOR(0, 4, 0x1), NULL, 0, 0}, + {4, 2, "r4w", RISC_COLOR(0, 4, 0x3), NULL, 0, 0}, + {4, 4, "r4d", RISC_COLOR(0, 4, 0xf), NULL, 0, 0}, + {4, 8, "r4", RISC_COLOR(0, 4, 0xff), NULL, 0, 0}, + + {5, 1, "r5b", RISC_COLOR(0, 5, 0x1), NULL, 0, 0}, + {5, 2, "r5w", RISC_COLOR(0, 5, 0x3), NULL, 0, 0}, + {5, 4, "r5d", RISC_COLOR(0, 5, 0xf), NULL, 0, 0}, + {5, 8, "r5", RISC_COLOR(0, 5, 0xff), NULL, 0, 0}, + + {6, 1, "r6b", RISC_COLOR(0, 6, 0x1), NULL, 0, 0}, + {6, 2, "r6w", RISC_COLOR(0, 6, 0x3), NULL, 0, 0}, + {6, 4, "r6d", RISC_COLOR(0, 6, 0xf), NULL, 0, 0}, + {6, 8, "r6", RISC_COLOR(0, 6, 0xff), NULL, 0, 0}, + + {7, 1, "r7b", RISC_COLOR(0, 7, 0x1), NULL, 0, 0}, + {7, 2, "r7w", RISC_COLOR(0, 7, 0x3), NULL, 0, 0}, + {7, 4, "r7d", RISC_COLOR(0, 7, 0xf), NULL, 0, 0}, + {7, 8, "r7", RISC_COLOR(0, 7, 0xff), NULL, 0, 0}, + + {8, 1, "r8b", RISC_COLOR(0, 8, 0x1), NULL, 0, 0}, + {8, 2, "r8w", RISC_COLOR(0, 8, 0x3), NULL, 0, 0}, + {8, 4, "r8d", RISC_COLOR(0, 8, 0xf), NULL, 0, 0}, + {8, 8, "r8", RISC_COLOR(0, 8, 0xff), NULL, 0, 0}, + + {9, 1, "r9b", RISC_COLOR(0, 9, 0x1), NULL, 0, 0}, + {9, 2, "r9w", RISC_COLOR(0, 9, 0x3), NULL, 0, 0}, + {9, 4, "r9d", RISC_COLOR(0, 9, 0xf), NULL, 0, 0}, + {9, 8, "r9", RISC_COLOR(0, 9, 0xff), NULL, 0, 0}, + +// not use r10, r11 + {10, 1, "r10b", RISC_COLOR(0, 10, 0x1), NULL, 0, 0}, + {10, 2, "r10w", RISC_COLOR(0, 10, 0x3), NULL, 0, 0}, + {10, 4, "r10d", RISC_COLOR(0, 10, 0xf), NULL, 0, 0}, + {10, 8, "r10", RISC_COLOR(0, 10, 0xff), NULL, 0, 0}, + + {11, 1, "r11b", RISC_COLOR(0, 11, 0x1), NULL, 0, 0}, + {11, 2, "r11w", RISC_COLOR(0, 11, 0x3), NULL, 0, 0}, + {11, 4, "r11d", RISC_COLOR(0, 11, 0xf), NULL, 0, 0}, + {11, 8, "r11", RISC_COLOR(0, 11, 0xff), NULL, 0, 0}, + + {12, 1, "r12b", RISC_COLOR(0, 12, 0x1), NULL, 0, 0}, + {12, 2, "r12w", RISC_COLOR(0, 12, 0x3), NULL, 0, 0}, + {12, 4, "r12d", RISC_COLOR(0, 12, 0xf), NULL, 0, 0}, + {12, 8, "fp", RISC_COLOR(0, 12, 0xff), NULL, 0, 0}, + + {13, 1, "r13b", RISC_COLOR(0, 13, 0x1), NULL, 0, 0}, + {13, 2, "r13w", RISC_COLOR(0, 13, 0x3), NULL, 0, 0}, + {13, 4, "r13d", RISC_COLOR(0, 13, 0xf), NULL, 0, 0}, + {13, 8, "lr", RISC_COLOR(0, 13, 0xff), NULL, 0, 0}, + + {14, 8, "sp", RISC_COLOR(0, 14, 0xff), NULL, 0, 0}, +// {15, 8, "null", RISC_COLOR(0, 15, 0xff), NULL, 0, 0}, + + + {0, 1, "b0", RISC_COLOR(1, 0, 0x1), NULL, 0, 0}, + {0, 2, "h0", RISC_COLOR(1, 0, 0x3), NULL, 0, 0}, + {0, 4, "s0", RISC_COLOR(1, 0, 0xf), NULL, 0, 0}, + {0, 8, "d0", RISC_COLOR(1, 0, 0xff), NULL, 0, 0}, + + {1, 1, "b1", RISC_COLOR(1, 1, 0x1), NULL, 0, 0}, + {1, 2, "h1", RISC_COLOR(1, 1, 0x3), NULL, 0, 0}, + {1, 4, "s1", RISC_COLOR(1, 1, 0xf), NULL, 0, 0}, + {1, 8, "d1", RISC_COLOR(1, 1, 0xff), NULL, 0, 0}, + + {2, 1, "b2", RISC_COLOR(1, 2, 0x1), NULL, 0, 0}, + {2, 2, "h2", RISC_COLOR(1, 2, 0x3), NULL, 0, 0}, + {2, 4, "s2", RISC_COLOR(1, 2, 0xf), NULL, 0, 0}, + {2, 8, "d2", RISC_COLOR(1, 2, 0xff), NULL, 0, 0}, + + {3, 1, "b3", RISC_COLOR(1, 3, 0x1), NULL, 0, 0}, + {3, 2, "h3", RISC_COLOR(1, 3, 0x3), NULL, 0, 0}, + {3, 4, "s3", RISC_COLOR(1, 3, 0xf), NULL, 0, 0}, + {3, 8, "d3", RISC_COLOR(1, 3, 0xff), NULL, 0, 0}, + + {4, 1, "b4", RISC_COLOR(1, 4, 0x1), NULL, 0, 0}, + {4, 2, "h4", RISC_COLOR(1, 4, 0x3), NULL, 0, 0}, + {4, 4, "s4", RISC_COLOR(1, 4, 0xf), NULL, 0, 0}, + {4, 8, "d4", RISC_COLOR(1, 4, 0xff), NULL, 0, 0}, + + {5, 1, "b5", RISC_COLOR(1, 5, 0x1), NULL, 0, 0}, + {5, 2, "h5", RISC_COLOR(1, 5, 0x3), NULL, 0, 0}, + {5, 4, "s5", RISC_COLOR(1, 5, 0xf), NULL, 0, 0}, + {5, 8, "d5", RISC_COLOR(1, 5, 0xff), NULL, 0, 0}, + + {6, 1, "b6", RISC_COLOR(1, 6, 0x1), NULL, 0, 0}, + {6, 2, "h6", RISC_COLOR(1, 6, 0x3), NULL, 0, 0}, + {6, 4, "s6", RISC_COLOR(1, 6, 0xf), NULL, 0, 0}, + {6, 8, "d6", RISC_COLOR(1, 6, 0xff), NULL, 0, 0}, + + {7, 1, "b7", RISC_COLOR(1, 7, 0x1), NULL, 0, 0}, + {7, 2, "h7", RISC_COLOR(1, 7, 0x3), NULL, 0, 0}, + {7, 4, "s7", RISC_COLOR(1, 7, 0xf), NULL, 0, 0}, + {7, 8, "d7", RISC_COLOR(1, 7, 0xff), NULL, 0, 0}, + + {8, 1, "b8", RISC_COLOR(1, 8, 0x1), NULL, 0, 0}, + {8, 2, "h8", RISC_COLOR(1, 8, 0x3), NULL, 0, 0}, + {8, 4, "s8", RISC_COLOR(1, 8, 0xf), NULL, 0, 0}, + {8, 8, "d8", RISC_COLOR(1, 8, 0xff), NULL, 0, 0}, + + {9, 1, "b9", RISC_COLOR(1, 9, 0x1), NULL, 0, 0}, + {9, 2, "h9", RISC_COLOR(1, 9, 0x3), NULL, 0, 0}, + {9, 4, "s9", RISC_COLOR(1, 9, 0xf), NULL, 0, 0}, + {9, 8, "d9", RISC_COLOR(1, 9, 0xff), NULL, 0, 0}, + + {10, 1, "b10", RISC_COLOR(1, 10, 0x1), NULL, 0, 0}, + {10, 2, "h10", RISC_COLOR(1, 10, 0x3), NULL, 0, 0}, + {10, 4, "s10", RISC_COLOR(1, 10, 0xf), NULL, 0, 0}, + {10, 8, "d10", RISC_COLOR(1, 10, 0xff), NULL, 0, 0}, + + {11, 1, "b11", RISC_COLOR(1, 11, 0x1), NULL, 0, 0}, + {11, 2, "h11", RISC_COLOR(1, 11, 0x3), NULL, 0, 0}, + {11, 4, "s11", RISC_COLOR(1, 11, 0xf), NULL, 0, 0}, + {11, 8, "d11", RISC_COLOR(1, 11, 0xff), NULL, 0, 0}, + + {12, 1, "b12", RISC_COLOR(1, 12, 0x1), NULL, 0, 0}, + {12, 2, "h12", RISC_COLOR(1, 12, 0x3), NULL, 0, 0}, + {12, 4, "s12", RISC_COLOR(1, 12, 0xf), NULL, 0, 0}, + {12, 8, "d12", RISC_COLOR(1, 12, 0xff), NULL, 0, 0}, + + {13, 1, "b13", RISC_COLOR(1, 13, 0x1), NULL, 0, 0}, + {13, 2, "h13", RISC_COLOR(1, 13, 0x3), NULL, 0, 0}, + {13, 4, "s13", RISC_COLOR(1, 13, 0xf), NULL, 0, 0}, + {13, 8, "d13", RISC_COLOR(1, 13, 0xff), NULL, 0, 0}, + + {14, 1, "b14", RISC_COLOR(1, 14, 0x1), NULL, 0, 0}, + {14, 2, "h14", RISC_COLOR(1, 14, 0x3), NULL, 0, 0}, + {14, 4, "s14", RISC_COLOR(1, 14, 0xf), NULL, 0, 0}, + {14, 8, "d14", RISC_COLOR(1, 14, 0xff), NULL, 0, 0}, + + {15, 1, "b15", RISC_COLOR(1, 15, 0x1), NULL, 0, 0}, + {15, 2, "h15", RISC_COLOR(1, 15, 0x3), NULL, 0, 0}, + {15, 4, "s15", RISC_COLOR(1, 15, 0xf), NULL, 0, 0}, + {15, 8, "d15", RISC_COLOR(1, 15, 0xff), NULL, 0, 0}, +}; + +static uint32_t naja_abi_regs[] = +{ + SCF_RISC_REG_X0, + SCF_RISC_REG_X1, + SCF_RISC_REG_X2, + SCF_RISC_REG_X3, + SCF_RISC_REG_X4, + SCF_RISC_REG_X5, +}; + +static uint32_t naja_abi_float_regs[] = +{ + SCF_RISC_REG_D0, + SCF_RISC_REG_D1, + SCF_RISC_REG_D2, + SCF_RISC_REG_D3, + SCF_RISC_REG_D4, + SCF_RISC_REG_D5, + SCF_RISC_REG_D6, + SCF_RISC_REG_D7, +}; + +static uint32_t naja_abi_ret_regs[] = +{ + SCF_RISC_REG_X0, + SCF_RISC_REG_X1, + SCF_RISC_REG_X2, + SCF_RISC_REG_X3, +}; + +static uint32_t naja_abi_caller_saves[] = +{ + SCF_RISC_REG_X0, + SCF_RISC_REG_X1, + SCF_RISC_REG_X2, + SCF_RISC_REG_X3, + SCF_RISC_REG_X4, + SCF_RISC_REG_X5, +}; + +static uint32_t naja_abi_callee_saves[] = +{ + SCF_RISC_REG_X6, + SCF_RISC_REG_X7, + SCF_RISC_REG_X8, + SCF_RISC_REG_X9, + SCF_RISC_REG_FP, + SCF_RISC_REG_LR, +}; + +static int naja_color_conflict(intptr_t c0, intptr_t c1) +{ + intptr_t id0 = c0 >> 16; + intptr_t id1 = c1 >> 16; + + return id0 == id1 && (c0 & c1 & 0xffff); +} + +static int naja_variable_size(scf_variable_t* v) +{ + if (v->nb_dimentions > 0) + return 8; + + if (v->type >= SCF_STRUCT && 0 == v->nb_pointers) + return 8; + + return v->size; +} + +scf_register_t* naja_find_register(const char* name) +{ + int i; + for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { + + scf_register_t* r = &(naja_registers[i]); + + if (!strcmp(r->name, name)) + return r; + } + return NULL; +} + +scf_register_t* naja_find_register_type_id_bytes(uint32_t type, uint32_t id, int bytes) +{ + int i; + for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { + + scf_register_t* r = &(naja_registers[i]); + + if (RISC_COLOR_TYPE(r->color) == type && r->id == id && r->bytes == bytes) + return r; + } + return NULL; +} + +scf_register_t* naja_find_register_color(intptr_t color) +{ + int i; + for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { + + scf_register_t* r = &(naja_registers[i]); + + if (r->color == color) + return r; + } + return NULL; +} + +scf_register_t* naja_find_register_color_bytes(intptr_t color, int bytes) +{ + int i; + for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { + + scf_register_t* r = &(naja_registers[i]); + + if (naja_color_conflict(r->color, color) && r->bytes == bytes) + return r; + } + return NULL; +} diff --git a/js/native/risc/scf_risc.c b/js/native/risc/scf_risc.c index d0b71d8..b38529e 100644 --- a/js/native/risc/scf_risc.c +++ b/js/native/risc/scf_risc.c @@ -207,11 +207,11 @@ static int _risc_function_finish(scf_native_t* ctx, scf_function_t* f) if (f->bp_used_flag) { inst = ctx->iops->PUSH(NULL, fp); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes = inst->len; inst = ctx->iops->MOV_SP(NULL, fp, sp); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes += inst->len; uint32_t local = f->local_vars_size + fp->bytes; @@ -231,8 +231,8 @@ static int _risc_function_finish(scf_native_t* ctx, scf_function_t* f) local <<= 12; } - inst = ctx->iops->SUB_IMM(f->init_code, f, sp, sp, local); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + inst = ctx->iops->SUB_IMM(f->init_code, f, sp, sp, local); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes += inst->len; int ret = _risc_save_rabi(f); @@ -631,10 +631,11 @@ static int _risc_make_insts_for_list(scf_native_t* ctx, scf_basic_block_t* bb, i static void _risc_set_offset_for_jmps(scf_native_t* ctx, scf_function_t* f) { + scf_3ac_code_t* c; int i; for (i = 0; i < f->jmps->size; i++) { - scf_3ac_code_t* c = f->jmps->data[i]; + c = f->jmps->data[i]; assert(c->instructions && 1 == c->instructions->size); @@ -651,14 +652,12 @@ static void _risc_set_offset_for_jmps(scf_native_t* ctx, scf_function_t* f) for (l = &cur_bb->list; l != &dst_bb->list; l = scf_list_next(l)) { bb = scf_list_data(l, scf_basic_block_t, list); - bytes += bb->code_bytes; } } else { for (l = &dst_bb->list; l != &cur_bb->list; l = scf_list_next(l)) { bb = scf_list_data(l, scf_basic_block_t, list); - bytes -= bb->code_bytes; } } @@ -675,8 +674,8 @@ static void _risc_set_offset_for_relas(scf_native_t* ctx, scf_function_t* f, scf for (i = 0; i < relas->size; i++) { scf_rela_t* rela = relas->data[i]; - scf_3ac_code_t* c = rela->code; scf_instruction_t* inst = rela->inst; + scf_3ac_code_t* c = inst->c; scf_basic_block_t* cur_bb = c->basic_block; scf_instruction_t* inst2; diff --git a/js/native/risc/scf_risc.h b/js/native/risc/scf_risc.h index 40930d2..41847cb 100644 --- a/js/native/risc/scf_risc.h +++ b/js/native/risc/scf_risc.h @@ -8,40 +8,6 @@ #include"scf_graph.h" #include"scf_elf.h" -#define RISC_INST_ADD_CHECK(vec, inst) \ - do { \ - if (!(inst)) { \ - scf_loge("\n"); \ - return -ENOMEM; \ - } \ - int ret = scf_vector_add((vec), (inst)); \ - if (ret < 0) { \ - scf_loge("\n"); \ - free(inst); \ - return ret; \ - } \ - } while (0) - -#define RISC_RELA_ADD_CHECK(vec, rela, c, v, f) \ - do { \ - rela = calloc(1, sizeof(scf_rela_t)); \ - if (!rela) \ - return -ENOMEM; \ - \ - (rela)->code = (c); \ - (rela)->var = (v); \ - (rela)->func = (f); \ - (rela)->inst = (c)->instructions->data[(c)->instructions->size - 1]; \ - (rela)->addend = 0; \ - \ - int ret = scf_vector_add((vec), (rela)); \ - if (ret < 0) { \ - free(rela); \ - rela = NULL; \ - return ret; \ - } \ - } while (0) - #define RISC_PEEPHOLE_DEL 1 #define RISC_PEEPHOLE_OK 0 @@ -92,7 +58,6 @@ int risc_load_bb_colors2(scf_basic_block_t* bb, scf_bb_group_t* bbg, scf_functi void risc_init_bb_colors (scf_basic_block_t* bb, scf_function_t* f); -scf_instruction_t* risc_make_inst (scf_3ac_code_t* c, uint32_t opcode); scf_instruction_t* risc_make_inst_BL (scf_3ac_code_t* c); scf_instruction_t* risc_make_inst_BLR (scf_3ac_code_t* c, scf_register_t* r); scf_instruction_t* risc_make_inst_PUSH (scf_3ac_code_t* c, scf_register_t* r); @@ -172,4 +137,3 @@ int risc_make_inst_ADRSIB2G(scf_3ac_code_t* c, scf_function_t* f, scf_register_t int risc_rcg_make(scf_3ac_code_t* c, scf_graph_t* g, scf_dag_node_t* dn, scf_register_t* reg); #endif - diff --git a/js/native/risc/scf_risc_bb_color.c b/js/native/risc/scf_risc_bb_color.c index ee58d60..fe97d37 100644 --- a/js/native/risc/scf_risc_bb_color.c +++ b/js/native/risc/scf_risc_bb_color.c @@ -204,7 +204,7 @@ int risc_bb_load_dn2(intptr_t color, scf_dag_node_t* dn, scf_basic_block_t* bb, return ret; if (cmp) - RISC_INST_ADD_CHECK(c->instructions, cmp); + RISC_INST_ADD_CHECK(c, cmp); return 0; } diff --git a/js/native/risc/scf_risc_inst.c b/js/native/risc/scf_risc_inst.c index 2d64b8d..7f13d91 100644 --- a/js/native/risc/scf_risc_inst.c +++ b/js/native/risc/scf_risc_inst.c @@ -177,7 +177,7 @@ static int _risc_inst_call_argv(scf_native_t* ctx, scf_3ac_code_t* c, scf_functi inst = ctx->iops->CVTSS2SD(c, rs, rs); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } if (!rd) { @@ -205,7 +205,7 @@ static int _risc_inst_call_argv(scf_native_t* ctx, scf_3ac_code_t* c, scf_functi else inst = ctx->iops->FMOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } ret = risc_rcg_make(c, c->rcg, NULL, rd); @@ -373,7 +373,7 @@ static int _risc_call_update_dsts(scf_native_t* ctx, scf_3ac_code_t* c, scf_func int valid = _risc_dst_reg_valid(f, rd, updated_regs, nb_updated, idx_int, nb_int); if (valid) { inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); assert(nb_updated < max_updated); @@ -479,8 +479,8 @@ static int _risc_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (stack_size > 0) { inst_sp = risc_make_inst(c, 0); inst_sp2 = risc_make_inst(c, 0); - RISC_INST_ADD_CHECK(c->instructions, inst_sp); - RISC_INST_ADD_CHECK(c->instructions, inst_sp2); + RISC_INST_ADD_CHECK(c, inst_sp); + RISC_INST_ADD_CHECK(c, inst_sp2); } ret = _risc_inst_call_argv(ctx, c, f); @@ -576,7 +576,7 @@ static int _risc_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) } inst = ctx->iops->BLR(c, r_pf); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { scf_loge("\n"); @@ -586,7 +586,7 @@ static int _risc_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (stack_size > 0) { inst = ctx->iops->ADD_IMM(c, f, sp, sp, stack_size); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } int nb_updated = 0; @@ -663,7 +663,7 @@ static int _risc_inst_bit_not_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->MVN(c, rd, rs); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -695,7 +695,7 @@ static int _risc_inst_inc_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->ADD_IMM(c, f, rs, rs, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -737,10 +737,10 @@ static int _risc_inst_inc_post_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->ADD_IMM(c, f, rs, rs, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -772,7 +772,7 @@ static int _risc_inst_dec_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->SUB_IMM(c, f, rs, rs, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -814,10 +814,10 @@ static int _risc_inst_dec_post_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->SUB_IMM(c, f, rs, rs, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -879,7 +879,7 @@ static int _risc_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->NEG(c, rd, rs); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -892,13 +892,13 @@ static int _risc_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0); inst = ctx->iops->E2G(pxor, rd, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (src->dag_node->color > 0) { RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->E2G(sub, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { scf_rela_t* rela = NULL; @@ -912,7 +912,7 @@ static int _risc_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c) } inst = ctx->iops->M2G(&rela, sub, rd, NULL, v); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); RISC_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } #endif @@ -1038,7 +1038,7 @@ static int _risc_inst_inc_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c) return ret; inst = ctx->iops->ADD_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, r, &sib); @@ -1105,7 +1105,7 @@ static int _risc_inst_dec_pointer_handler(scf_native_t* ctx, scf_3ac_code_t* c) return ret; inst = ctx->iops->SUB_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, r, &sib); @@ -1178,7 +1178,7 @@ static int _risc_inst_inc_post_pointer_handler(scf_native_t* ctx, scf_3ac_code_t return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -1188,7 +1188,7 @@ static int _risc_inst_inc_post_pointer_handler(scf_native_t* ctx, scf_3ac_code_t return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1256,7 +1256,7 @@ static int _risc_inst_dec_post_pointer_handler(scf_native_t* ctx, scf_3ac_code_t return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -1266,7 +1266,7 @@ static int _risc_inst_dec_post_pointer_handler(scf_native_t* ctx, scf_3ac_code_t return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1377,7 +1377,7 @@ static int _risc_inst_inc_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* return ret; inst = ctx->iops->ADD_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, r, &sib); @@ -1444,7 +1444,7 @@ static int _risc_inst_dec_array_index_handler(scf_native_t* ctx, scf_3ac_code_t* return ret; inst = ctx->iops->SUB_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, r, &sib); @@ -1515,7 +1515,7 @@ static int _risc_inst_inc_post_array_index_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -1525,7 +1525,7 @@ static int _risc_inst_inc_post_array_index_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1591,7 +1591,7 @@ static int _risc_inst_dec_post_array_index_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -1601,7 +1601,7 @@ static int _risc_inst_dec_post_array_index_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -1779,7 +1779,7 @@ static int _risc_inst_push_rax_handler(scf_native_t* ctx, scf_3ac_code_t* c) #if 0 push = risc_find_OpCode(SCF_RISC_PUSH, 8,8, SCF_RISC_G); inst = ctx->iops->G(push, rax); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; #endif return -1; @@ -1801,7 +1801,7 @@ static int _risc_inst_pop_rax_handler(scf_native_t* ctx, scf_3ac_code_t* c) #if 0 pop = risc_find_OpCode(SCF_RISC_POP, 8,8, SCF_RISC_G); inst = ctx->iops->G(pop, rax); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; #endif return -1; @@ -1857,33 +1857,33 @@ static int _risc_inst_va_start_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0); inst = ctx->iops->P2G(lea, rptr, rbp, offset_int); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 0, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->P2G(lea, rptr, rbp, offset_float); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 8, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->P2G(lea, rptr, rbp, offset_others); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 16, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); mov = risc_find_OpCode(SCF_RISC_MOV, 4, 8, SCF_RISC_I2E); inst = ctx->iops->I2P(mov, rap, 24, (uint8_t*)&f->args_int, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->I2P(mov, rap, 32, (uint8_t*)&f->args_float, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; #endif return -1; @@ -1924,22 +1924,22 @@ static int _risc_inst_va_end_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0); inst = ctx->iops->G2E(xor, rptr, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 0, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 8, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 16, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 24, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->G2P(mov, rap, 32, rptr); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); ptr->dag_node->var->tmp_flag = 0; ptr->dag_node->color = 0; @@ -2010,22 +2010,22 @@ static int _risc_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) } inst = ctx->iops->I2P(cmp, rap, idx_offset, (uint8_t*)&nints, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst_jge = ctx->iops->I(jge, (uint8_t*)&offset, sizeof(offset)); - RISC_INST_ADD_CHECK(c->instructions, inst_jge); + RISC_INST_ADD_CHECK(c, inst_jge); inst = ctx->iops->P2G(mov, rptr, rap, ptr_offset); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); offset += inst->len; inst = ctx->iops->I2P(sub, rap, ptr_offset, (uint8_t*)&incptr, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); offset += inst->len; inst_jmp = ctx->iops->I(jmp, (uint8_t*)&offset, sizeof(offset)); - RISC_INST_ADD_CHECK(c->instructions, inst_jmp); + RISC_INST_ADD_CHECK(c, inst_jmp); offset += inst_jmp->len; uint8_t* p = (uint8_t*)&offset; @@ -2035,18 +2035,18 @@ static int _risc_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) offset = 0; inst = ctx->iops->P2G(mov, rptr, rap, 16); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); offset += inst->len; inst = ctx->iops->I2P(add, rap, 16, (uint8_t*)&incptr, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); offset += inst->len; for (i = 0; i < 4; i++) inst_jmp->code[jmp->nb_OpCodes + i] = p[i]; inst = ctx->iops->P(inc, rap, idx_offset, 8); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (is_float) { if (4 == size) @@ -2059,7 +2059,7 @@ static int _risc_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) mov2 = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_E2G); inst = ctx->iops->P2G(mov2, rd, rptr, 0); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; #endif @@ -2153,7 +2153,7 @@ static int _risc_inst_div_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs1, s1, c, f, 1); inst = ctx->iops->FDIV(c, rd, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2203,7 +2203,7 @@ static int _risc_inst_div_handler(scf_native_t* ctx, scf_3ac_code_t* c) else inst = ctx->iops->DIV(c, rd, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2282,10 +2282,10 @@ static int _risc_inst_mod_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->SDIV(c, rd, rs0, rs1); else inst = ctx->iops->DIV(c, rd, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->MSUB(c, rd, rs1, rd, rs0); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2331,7 +2331,7 @@ static int _risc_inst_mul_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->FMUL(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2350,7 +2350,7 @@ static int _risc_inst_mul_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->MUL(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s1->color = 0; s1->loaded = 0; @@ -2362,7 +2362,7 @@ static int _risc_inst_mul_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->MUL(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2416,7 +2416,7 @@ static int _risc_inst_mul_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->FMUL(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2434,7 +2434,7 @@ static int _risc_inst_mul_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->MUL(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s->color = 0; s->loaded = 0; @@ -2446,7 +2446,7 @@ static int _risc_inst_mul_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->MUL(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2488,7 +2488,7 @@ static int _risc_inst_add_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->FADD(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2510,7 +2510,7 @@ static int _risc_inst_add_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rn, s0, c, f, 1); inst = ctx->iops->ADD_IMM(c, f, rd, rn, u); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2519,7 +2519,7 @@ static int _risc_inst_add_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->ADD_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2578,7 +2578,7 @@ static int _risc_inst_add_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->FADD(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2599,7 +2599,7 @@ static int _risc_inst_add_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rd, d, c, f, 0); inst = ctx->iops->ADD_IMM(c, f, rd, rd, u); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2607,7 +2607,7 @@ static int _risc_inst_add_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->ADD_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2666,7 +2666,7 @@ static int _risc_inst_sub_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->FSUB(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2687,7 +2687,7 @@ static int _risc_inst_sub_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rd, d, c, f, 0); inst = ctx->iops->SUB_IMM(c, f, rd, rd, u); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2695,7 +2695,7 @@ static int _risc_inst_sub_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->SUB_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2738,7 +2738,7 @@ static int _risc_inst_sub_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->FSUB(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2767,11 +2767,11 @@ static int _risc_inst_sub_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rn, s0, c, f, 1); inst = ctx->iops->SUB_IMM(c, f, rd, rn, u); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (neg) { inst = ctx->iops->NEG(c, rd, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; } @@ -2781,7 +2781,7 @@ static int _risc_inst_sub_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->SUB_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2837,7 +2837,7 @@ static int _risc_inst_bit_and_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->AND_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s1->color = 0; s1->loaded = 0; @@ -2849,7 +2849,7 @@ static int _risc_inst_bit_and_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->AND_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2901,7 +2901,7 @@ static int _risc_inst_bit_or_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->OR_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s1->color = 0; s1->loaded = 0; @@ -2913,7 +2913,7 @@ static int _risc_inst_bit_or_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rm, s1, c, f, 1); inst = ctx->iops->OR_G(c, rd, rn, rm); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -2976,7 +2976,7 @@ static int _risc_inst_and_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->AND_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s->color = 0; s->loaded = 0; @@ -2988,7 +2988,7 @@ static int _risc_inst_and_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->AND_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3051,7 +3051,7 @@ static int _risc_inst_or_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); s->color = 0; s->loaded = 0; @@ -3063,7 +3063,7 @@ static int _risc_inst_or_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3098,7 +3098,7 @@ static int _risc_inst_teq_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = ctx->iops->TEQ(c, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3128,7 +3128,7 @@ static int _risc_inst_setz_handler(scf_native_t* ctx, scf_3ac_code_t* c) SET_INIT(); inst = ctx->iops->SETZ(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3136,35 +3136,35 @@ static int _risc_inst_setnz_handler(scf_native_t* ctx, scf_3ac_code_t* c) { SET_INIT(); inst = ctx->iops->SETNZ(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } static int _risc_inst_setge_handler(scf_native_t* ctx, scf_3ac_code_t* c) { SET_INIT(); inst = ctx->iops->SETGE(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } static int _risc_inst_setgt_handler(scf_native_t* ctx, scf_3ac_code_t* c) { SET_INIT(); inst = ctx->iops->SETGT(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } static int _risc_inst_setlt_handler(scf_native_t* ctx, scf_3ac_code_t* c) { SET_INIT(); inst = ctx->iops->SETLT(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } static int _risc_inst_setle_handler(scf_native_t* ctx, scf_3ac_code_t* c) { SET_INIT(); inst = ctx->iops->SETLE(c, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3233,7 +3233,7 @@ static int _risc_inst_cmp_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs1, ds1, c, f, 1); inst = ctx->iops->FCMP(c, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3259,14 +3259,14 @@ static int _risc_inst_cmp_handler(scf_native_t* ctx, scf_3ac_code_t* c) assert(0 == scf_vector_del(rs1->dag_nodes, ds1)); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } RISC_SELECT_REG_CHECK(&rs1, ds1, c, f, 1); inst = ctx->iops->CMP_G(c, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3355,7 +3355,7 @@ static int _risc_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->CVTF2UI(c, rd, rs); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } else if (scf_variable_float(vd)) { @@ -3384,7 +3384,7 @@ static int _risc_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) else inst = ctx->iops->CVTUI2F(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3415,7 +3415,7 @@ static int _risc_inst_cast_handler(scf_native_t* ctx, scf_3ac_code_t* c) } else inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3469,7 +3469,7 @@ static int _risc_inst_div_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->FDIV(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3498,7 +3498,7 @@ static int _risc_inst_div_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) else inst = ctx->iops->DIV(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3576,10 +3576,10 @@ static int _risc_inst_mod_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->SDIV(c, r, rd, rs); else inst = ctx->iops->DIV(c, r, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->MSUB(c, rd, rs, r, rd); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3675,7 +3675,7 @@ static int _risc_inst_return_handler(scf_native_t* ctx, scf_3ac_code_t* c) inst = ctx->iops->MOV_G(c, rd, rs); } else inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); scf_instruction_t* tmp; int j; @@ -3748,7 +3748,7 @@ static int _risc_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (0 == dn->color) { \ mov = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_I2G); \ inst = ctx->iops->I2G(mov, r, (uint8_t*)&dn->var->data, size); \ - RISC_INST_ADD_CHECK(c->instructions, inst); \ + RISC_INST_ADD_CHECK(c, inst); \ \ } else { \ if (dn->color < 0) \ @@ -3758,7 +3758,7 @@ static int _risc_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (!RISC_COLOR_CONFLICT(rd->color, r->color)) { \ mov = risc_find_OpCode(SCF_RISC_MOV, size, size, SCF_RISC_G2E); \ inst = ctx->iops->G2E(mov, r, rd); \ - RISC_INST_ADD_CHECK(c->instructions, inst); \ + RISC_INST_ADD_CHECK(c, inst); \ } \ } \ } while (0) @@ -3768,7 +3768,7 @@ static int _risc_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) stos = risc_find_OpCode(SCF_RISC_STOS, 1, 8, SCF_RISC_G); inst = risc_make_inst(stos, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; #endif @@ -3800,13 +3800,13 @@ static int _risc_inst_end_handler(scf_native_t* ctx, scf_3ac_code_t* c) return ret; inst = ctx->iops->MOV_SP(c, sp, fp); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->POP(c, fp); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); inst = ctx->iops->RET(c); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -3829,7 +3829,7 @@ static int _risc_inst_##name##_handler(scf_native_t* ctx, scf_3ac_code_t* c) \ } \ \ inst = ctx->iops->NAME(c); \ - RISC_INST_ADD_CHECK(c->instructions, inst); \ + RISC_INST_ADD_CHECK(c, inst); \ return 0;\ } @@ -4030,7 +4030,7 @@ static int _risc_inst_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, d, c, f, 1); inst = ctx->iops->FMOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -4053,7 +4053,7 @@ static int _risc_inst_assign_handler(scf_native_t* ctx, scf_3ac_code_t* c) RISC_SELECT_REG_CHECK(&rs, s, c, f, 1); inst = ctx->iops->MOV_G(c, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -4135,7 +4135,7 @@ static int _risc_inst_shift(scf_native_t* ctx, scf_3ac_code_t* c) } else inst = ctx->iops->SHL(c, rd, rs0, rs1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -4195,7 +4195,7 @@ static int _risc_inst_shift_assign(scf_native_t* ctx, scf_3ac_code_t* c) } else inst = ctx->iops->SHL(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -4357,7 +4357,7 @@ static int _risc_inst_add_assign_dereference_handler(scf_native_t* ctx, scf_3ac_ inst = ctx->iops->ADD_G(c, rd, rd, rs); else inst = ctx->iops->FADD(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4436,7 +4436,7 @@ static int _risc_inst_sub_assign_dereference_handler(scf_native_t* ctx, scf_3ac_ inst = ctx->iops->SUB_G(c, rd, rd, rs); else inst = ctx->iops->FSUB(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4505,7 +4505,7 @@ static int _risc_inst_and_assign_dereference_handler(scf_native_t* ctx, scf_3ac_ return ret; inst = ctx->iops->AND_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4582,7 +4582,7 @@ static int _risc_inst_or_assign_dereference_handler(scf_native_t* ctx, scf_3ac_c return ret; inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4816,7 +4816,7 @@ static int _risc_inst_sub_assign_pointer_handler(scf_native_t* ctx, scf_3ac_code return ret; inst = ctx->iops->SUB_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4898,7 +4898,7 @@ static int _risc_inst_and_assign_pointer_handler(scf_native_t* ctx, scf_3ac_code return ret; inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -4980,7 +4980,7 @@ static int _risc_inst_or_assign_pointer_handler(scf_native_t* ctx, scf_3ac_code_ return ret; inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, rd, sib.base, sib.disp, sib.size); } @@ -5157,7 +5157,7 @@ static int _risc_inst_add_assign_array_index_handler(scf_native_t* ctx, scf_3ac_ inst = ctx->iops->ADD_G(c, rd, rd, rs); else inst = ctx->iops->FADD(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -5256,7 +5256,7 @@ static int _risc_inst_sub_assign_array_index_handler(scf_native_t* ctx, scf_3ac_ inst = ctx->iops->SUB_G(c, rd, rd, rs); else inst = ctx->iops->FSUB(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); rs = rd; @@ -5348,7 +5348,7 @@ static int _risc_inst_and_assign_array_index_handler(scf_native_t* ctx, scf_3ac_ return ret; inst = ctx->iops->AND_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) ret = ctx->iops->G2SIB(c, f, rd, &sib); @@ -5438,7 +5438,7 @@ static int _risc_inst_or_assign_array_index_handler(scf_native_t* ctx, scf_3ac_c return ret; inst = ctx->iops->OR_G(c, rd, rd, rs); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); if (sib.index) return ctx->iops->G2SIB(c, f, rd, &sib); @@ -5486,7 +5486,7 @@ static int _risc_inst_dec_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* return ret; inst = ctx->iops->SUB_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, r, sib.base, 0, size); } @@ -5531,7 +5531,7 @@ static int _risc_inst_inc_dereference_handler(scf_native_t* ctx, scf_3ac_code_t* return ret; inst = ctx->iops->ADD_IMM(c, f, r, r, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return ctx->iops->G2P(c, f, r, sib.base, 0, size); } @@ -5575,14 +5575,14 @@ static int _risc_inst_dec_post_dereference_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); ret = ctx->iops->G2P(c, f, rd, sib.base, 0, size); if (ret < 0) return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -5625,14 +5625,14 @@ static int _risc_inst_inc_post_dereference_handler(scf_native_t* ctx, scf_3ac_co return ret; inst = ctx->iops->ADD_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); ret = ctx->iops->G2P(c, f, rd, sib.base, 0, size); if (ret < 0) return ret; inst = ctx->iops->SUB_IMM(c, f, rd, rd, 1); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); return 0; } @@ -5752,21 +5752,3 @@ risc_inst_handler_pt scf_risc_find_inst_handler(const int op_type) return risc_inst_handlers[op_type]; } - -scf_instruction_t* risc_make_inst(scf_3ac_code_t* c, uint32_t opcode) -{ - scf_instruction_t* inst; - - inst = calloc(1, sizeof(scf_instruction_t)); - if (!inst) - return NULL; - - inst->c = c; - inst->code[0] = opcode & 0xff; - inst->code[1] = (opcode >> 8) & 0xff; - inst->code[2] = (opcode >> 16) & 0xff; - inst->code[3] = (opcode >> 24) & 0xff; - inst->len = 4; - - return inst; -} diff --git a/js/native/risc/scf_risc_opcode.c b/js/native/risc/scf_risc_opcode.c index b12e502..d4a9141 100644 --- a/js/native/risc/scf_risc_opcode.c +++ b/js/native/risc/scf_risc_opcode.c @@ -1,6 +1,7 @@ #include"scf_risc.h" -scf_risc_OpCode_t risc_OpCodes[] = { +scf_risc_OpCode_t risc_OpCodes[] = +{ {SCF_RISC_PUSH, "push", 1, {0x50, 0x0, 0x0},1, 8,8, SCF_RISC_G, 0,0, 0,{0,0}}, {SCF_RISC_POP, "pop", 1, {0x58, 0x0, 0x0},1, 8,8, SCF_RISC_G, 0,0, 0,{0,0}}, @@ -59,6 +60,11 @@ scf_risc_OpCode_t risc_OpCodes[] = { {SCF_RISC_RET, "ret", 1, {0xc3, 0x0, 0x0},1, 8,8, SCF_RISC_G, 0,0, 0,{0,0}}, + {SCF_RISC_ADD, "addb", 2, {0x00, 0x0, 0x0},1, 1,1, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_ADD, "addw", 2, {0x01, 0x0, 0x0},1, 2,2, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_ADD, "addl", 2, {0x01, 0x0, 0x0},1, 4,4, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_ADD, "addq", 2, {0x01, 0x0, 0x0},1, 8,8, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_ADD, "add", 2, {0x00, 0x0, 0x0},1, 1,1, SCF_RISC_G2E, 0,0, 0,{0,0}}, {SCF_RISC_ADD, "add", 2, {0x01, 0x0, 0x0},1, 2,2, SCF_RISC_G2E, 0,0, 0,{0,0}}, {SCF_RISC_ADD, "add", 2, {0x01, 0x0, 0x0},1, 4,4, SCF_RISC_G2E, 0,0, 0,{0,0}}, @@ -162,6 +168,11 @@ scf_risc_OpCode_t risc_OpCodes[] = { {SCF_RISC_LEA, "lea", 1, {0x8d, 0x0, 0x0},1, 8,8, SCF_RISC_E2G, 0,0, 0,{0,0}}, + {SCF_RISC_MOV, "movb", 2, {0x88, 0x0, 0x0},1, 1,1, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_MOV, "movw", 2, {0x89, 0x0, 0x0},1, 2,2, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_MOV, "movl", 2, {0x89, 0x0, 0x0},1, 4,4, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_MOV, "movq", 2, {0x89, 0x0, 0x0},1, 8,8, SCF_RISC_G2E, 0,0, 0,{0,0}}, + {SCF_RISC_MOV, "mov", 2, {0x88, 0x0, 0x0},1, 1,1, SCF_RISC_G2E, 0,0, 0,{0,0}}, {SCF_RISC_MOV, "mov", 2, {0x89, 0x0, 0x0},1, 2,2, SCF_RISC_G2E, 0,0, 0,{0,0}}, {SCF_RISC_MOV, "mov", 2, {0x89, 0x0, 0x0},1, 4,4, SCF_RISC_G2E, 0,0, 0,{0,0}}, @@ -310,9 +321,11 @@ scf_risc_OpCode_t risc_OpCodes[] = { {SCF_RISC_JMP, "jmp", 2, {0xeb, 0x0, 0x0},1, 1,1, SCF_RISC_I, 0,0, 0,{0,0}}, {SCF_RISC_JMP, "jmp", 5, {0xe9, 0x0, 0x0},1, 4,4, SCF_RISC_I, 0,0, 0,{0,0}}, {SCF_RISC_JMP, "jmp", 2, {0xff, 0x0, 0x0},1, 8,8, SCF_RISC_E, 4,1, 0,{0,0}}, + + {SCF_RISC_ADRP, "adrp", 1, {0xff, 0x0, 0x0},1, 8,8, SCF_RISC_E2G, 0,0, 0,{0,0}}, }; -scf_risc_OpCode_t* risc_find_OpCode_by_type(const int type) +scf_risc_OpCode_t* risc_find_OpCode_by_type(const int type) { int i; for (i = 0; i < sizeof(risc_OpCodes) / sizeof(risc_OpCodes[0]); i++) { @@ -324,23 +337,19 @@ scf_risc_OpCode_t* risc_find_OpCode_by_type(const int type) return NULL; } -scf_risc_OpCode_t* risc_find_OpCode(const int type, const int OpBytes, const int RegBytes, const int EG) +scf_risc_OpCode_t* risc_find_OpCode_by_name(const char* name) { int i; for (i = 0; i < sizeof(risc_OpCodes) / sizeof(risc_OpCodes[0]); i++) { scf_risc_OpCode_t* OpCode = &(risc_OpCodes[i]); - - if (type == OpCode->type - && OpBytes == OpCode->OpBytes - && RegBytes == OpCode->RegBytes - && EG == OpCode->EG) + if (!strcmp(OpCode->name, name)) return OpCode; } return NULL; } -int risc_find_OpCodes(scf_vector_t* results, const int type, const int OpBytes, const int RegBytes, const int EG) +scf_risc_OpCode_t* risc_find_OpCode(const int type, const int OpBytes, const int RegBytes, const int EG) { int i; for (i = 0; i < sizeof(risc_OpCodes) / sizeof(risc_OpCodes[0]); i++) { @@ -350,13 +359,26 @@ int risc_find_OpCodes(scf_vector_t* results, const int type, const int OpBytes, if (type == OpCode->type && OpBytes == OpCode->OpBytes && RegBytes == OpCode->RegBytes - && EG == OpCode->EG) { - - int ret = scf_vector_add(results, OpCode); - if (ret < 0) - return ret; - } + && EG == OpCode->EG) + return OpCode; } - return 0; + return NULL; } +scf_instruction_t* risc_make_inst(scf_3ac_code_t* c, uint32_t opcode) +{ + scf_instruction_t* inst; + + inst = calloc(1, sizeof(scf_instruction_t)); + if (!inst) + return NULL; + + inst->c = c; + inst->code[0] = opcode & 0xff; + inst->code[1] = (opcode >> 8) & 0xff; + inst->code[2] = (opcode >> 16) & 0xff; + inst->code[3] = (opcode >> 24) & 0xff; + inst->len = 4; + + return inst; +} diff --git a/js/native/risc/scf_risc_opcode.h b/js/native/risc/scf_risc_opcode.h index 0f7286a..d11bce9 100644 --- a/js/native/risc/scf_risc_opcode.h +++ b/js/native/risc/scf_risc_opcode.h @@ -27,11 +27,66 @@ typedef struct { uint32_t regs[2]; } scf_risc_OpCode_t; -scf_risc_OpCode_t* risc_find_OpCode_by_type(const int type); +scf_risc_OpCode_t* risc_find_OpCode_by_name(const char* name); +scf_risc_OpCode_t* risc_find_OpCode_by_type(const int type); +scf_risc_OpCode_t* risc_find_OpCode (const int type, const int OpBytes, const int RegBytes, const int EG); -scf_risc_OpCode_t* risc_find_OpCode(const int type, const int OpBytes, const int RegBytes, const int EG); +scf_instruction_t* risc_make_inst(scf_3ac_code_t* c, uint32_t opcode); -int risc_find_OpCodes(scf_vector_t* results, const int type, const int OpBytes, const int RegBytes, const int EG); +#define RISC_INST_ADD_CHECK(_c, _inst) \ + do { \ + if (!(_inst)) { \ + scf_loge("\n"); \ + return -ENOMEM; \ + } \ + int ret = scf_vector_add((_c)->instructions, (_inst)); \ + if (ret < 0) { \ + scf_instruction_free(_inst); \ + return ret; \ + } \ + \ + (_inst)->c = (_c); \ + } while (0) -#endif +#define RISC_RELA_ADD_CHECK(_vec, _rela, _c, _v, _f) \ + do { \ + (_rela) = calloc(1, sizeof(scf_rela_t)); \ + if (!(_rela)) \ + return -ENOMEM; \ + (_rela)->var = (_v); \ + (_rela)->func = (_f); \ + (_rela)->inst = (_c)->instructions->data[(_c)->instructions->size - 1]; \ + (_rela)->addend = 0; \ + \ + int ret = scf_vector_add((_vec), (_rela)); \ + if (ret < 0) { \ + scf_rela_free(_rela); \ + return ret; \ + } \ + \ + (_rela)->inst->rel = (_rela); \ + } while (0) + +#define RISC_RELA_ADD_LABEL(_vec, _rela, _inst, _label) \ + do { \ + (_rela) = calloc(1, sizeof(scf_rela_t)); \ + if (!(_rela)) \ + return -ENOMEM; \ + \ + (_rela)->inst = (_inst); \ + (_rela)->name = scf_string_clone(_label); \ + if (!(_rela)->name) { \ + scf_rela_free(_rela); \ + return -ENOMEM; \ + } \ + \ + int ret = scf_vector_add((_vec), (_rela)); \ + if (ret < 0) { \ + scf_rela_free(_rela); \ + return ret; \ + } \ + \ + (_rela)->inst->rel = (_rela); \ + } while (0) +#endif diff --git a/js/native/risc/scf_risc_reg.c b/js/native/risc/scf_risc_reg.c index 23383a9..2f75ea9 100644 --- a/js/native/risc/scf_risc_reg.c +++ b/js/native/risc/scf_risc_reg.c @@ -472,7 +472,7 @@ int risc_array_index_reg(scf_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* i if (scf_variable_signed(index->var)) { inst = f->iops->MOVSX(c, ri, ri, ri->bytes); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } ri = ri2; @@ -494,7 +494,7 @@ int risc_array_index_reg(scf_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* i return ret; inst = f->iops->MUL(c, rs, rs, ri); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); ri = rs; s = 1; @@ -523,7 +523,7 @@ int risc_array_index_reg(scf_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* i inst = f->iops->ADD_G(c, rs, rs, rb); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { assert(1 == s); @@ -546,7 +546,7 @@ int risc_array_index_reg(scf_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* i inst = f->iops->ADD_G(c, rs, rb, rd); } - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); ri = NULL; } diff --git a/js/native/risc/scf_risc_reg_arm32.c b/js/native/risc/scf_risc_reg_arm32.c index ef69b29..d7499ec 100644 --- a/js/native/risc/scf_risc_reg_arm32.c +++ b/js/native/risc/scf_risc_reg_arm32.c @@ -471,7 +471,7 @@ int arm32_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, return ret; } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -488,7 +488,7 @@ int arm32_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -548,10 +548,10 @@ int arm32_pop_regs(scf_3ac_code_t* c, scf_function_t* f, scf_register_t** regs, if (i == nb_updated) { inst = f->iops->POP(c, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { inst = f->iops->ADD_IMM(c, f, sp, sp, 4); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } } return 0; @@ -1104,7 +1104,7 @@ int arm32_push_callee_regs(scf_3ac_code_t* c, scf_function_t* f) if (j < N) { inst = f->iops->PUSH(NULL, r); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes += inst->len; } @@ -1137,7 +1137,7 @@ int arm32_pop_callee_regs(scf_3ac_code_t* c, scf_function_t* f) if (j < N) { inst = f->iops->POP(c, r); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } } diff --git a/js/native/risc/scf_risc_reg_arm64.c b/js/native/risc/scf_risc_reg_arm64.c index 158b409..6fa6d9d 100644 --- a/js/native/risc/scf_risc_reg_arm64.c +++ b/js/native/risc/scf_risc_reg_arm64.c @@ -556,7 +556,7 @@ int arm64_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, return ret; } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -572,7 +572,7 @@ int arm64_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, return ret; } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -633,10 +633,10 @@ int arm64_pop_regs(scf_3ac_code_t* c, scf_function_t* f, scf_register_t** regs, if (i == nb_updated) { inst = f->iops->POP(c, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { inst = f->iops->ADD_IMM(c, f, sp, sp, 8); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } } return 0; @@ -1069,7 +1069,7 @@ int arm64_push_callee_regs(scf_3ac_code_t* c, scf_function_t* f) } inst = f->iops->PUSH(NULL, r); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes += inst->len; } @@ -1095,7 +1095,7 @@ int arm64_pop_callee_regs(scf_3ac_code_t* c, scf_function_t* f) } inst = f->iops->POP(c, r); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; diff --git a/js/native/risc/scf_risc_reg_naja.c b/js/native/risc/scf_risc_reg_naja.c index 9b6ff13..fa795a5 100644 --- a/js/native/risc/scf_risc_reg_naja.c +++ b/js/native/risc/scf_risc_reg_naja.c @@ -1,288 +1,5 @@ #include"scf_risc.h" - -#define SCF_RISC_REG_FP 12 -#define SCF_RISC_REG_LR 13 -#define SCF_RISC_REG_SP 14 -#define SCF_RISC_REG_NULL 15 - -scf_register_t naja_registers[] = -{ - {0, 1, "r0b", RISC_COLOR(0, 0, 0x1), NULL, 0, 0}, - {0, 2, "r0w", RISC_COLOR(0, 0, 0x3), NULL, 0, 0}, - {0, 4, "r0d", RISC_COLOR(0, 0, 0xf), NULL, 0, 0}, - {0, 8, "r0", RISC_COLOR(0, 0, 0xff), NULL, 0, 0}, - - {1, 1, "r1b", RISC_COLOR(0, 1, 0x1), NULL, 0, 0}, - {1, 2, "r1w", RISC_COLOR(0, 1, 0x3), NULL, 0, 0}, - {1, 4, "r1d", RISC_COLOR(0, 1, 0xf), NULL, 0, 0}, - {1, 8, "r1", RISC_COLOR(0, 1, 0xff), NULL, 0, 0}, - - {2, 1, "r2b", RISC_COLOR(0, 2, 0x1), NULL, 0, 0}, - {2, 2, "r2w", RISC_COLOR(0, 2, 0x3), NULL, 0, 0}, - {2, 4, "r2d", RISC_COLOR(0, 2, 0xf), NULL, 0, 0}, - {2, 8, "r2", RISC_COLOR(0, 2, 0xff), NULL, 0, 0}, - - {3, 1, "r3b", RISC_COLOR(0, 3, 0x1), NULL, 0, 0}, - {3, 2, "r3w", RISC_COLOR(0, 3, 0x3), NULL, 0, 0}, - {3, 4, "r3d", RISC_COLOR(0, 3, 0xf), NULL, 0, 0}, - {3, 8, "r3", RISC_COLOR(0, 3, 0xff), NULL, 0, 0}, - - {4, 1, "r4b", RISC_COLOR(0, 4, 0x1), NULL, 0, 0}, - {4, 2, "r4w", RISC_COLOR(0, 4, 0x3), NULL, 0, 0}, - {4, 4, "r4d", RISC_COLOR(0, 4, 0xf), NULL, 0, 0}, - {4, 8, "r4", RISC_COLOR(0, 4, 0xff), NULL, 0, 0}, - - {5, 1, "r5b", RISC_COLOR(0, 5, 0x1), NULL, 0, 0}, - {5, 2, "r5w", RISC_COLOR(0, 5, 0x3), NULL, 0, 0}, - {5, 4, "r5d", RISC_COLOR(0, 5, 0xf), NULL, 0, 0}, - {5, 8, "r5", RISC_COLOR(0, 5, 0xff), NULL, 0, 0}, - - {6, 1, "r6b", RISC_COLOR(0, 6, 0x1), NULL, 0, 0}, - {6, 2, "r6w", RISC_COLOR(0, 6, 0x3), NULL, 0, 0}, - {6, 4, "r6d", RISC_COLOR(0, 6, 0xf), NULL, 0, 0}, - {6, 8, "r6", RISC_COLOR(0, 6, 0xff), NULL, 0, 0}, - - {7, 1, "r7b", RISC_COLOR(0, 7, 0x1), NULL, 0, 0}, - {7, 2, "r7w", RISC_COLOR(0, 7, 0x3), NULL, 0, 0}, - {7, 4, "r7d", RISC_COLOR(0, 7, 0xf), NULL, 0, 0}, - {7, 8, "r7", RISC_COLOR(0, 7, 0xff), NULL, 0, 0}, - - {8, 1, "r8b", RISC_COLOR(0, 8, 0x1), NULL, 0, 0}, - {8, 2, "r8w", RISC_COLOR(0, 8, 0x3), NULL, 0, 0}, - {8, 4, "r8d", RISC_COLOR(0, 8, 0xf), NULL, 0, 0}, - {8, 8, "r8", RISC_COLOR(0, 8, 0xff), NULL, 0, 0}, - - {9, 1, "r9b", RISC_COLOR(0, 9, 0x1), NULL, 0, 0}, - {9, 2, "r9w", RISC_COLOR(0, 9, 0x3), NULL, 0, 0}, - {9, 4, "r9d", RISC_COLOR(0, 9, 0xf), NULL, 0, 0}, - {9, 8, "r9", RISC_COLOR(0, 9, 0xff), NULL, 0, 0}, - -// not use r10, r11 - {10, 1, "r10b", RISC_COLOR(0, 10, 0x1), NULL, 0, 0}, - {10, 2, "r10w", RISC_COLOR(0, 10, 0x3), NULL, 0, 0}, - {10, 4, "r10d", RISC_COLOR(0, 10, 0xf), NULL, 0, 0}, - {10, 8, "r10", RISC_COLOR(0, 10, 0xff), NULL, 0, 0}, - - {11, 1, "r11b", RISC_COLOR(0, 11, 0x1), NULL, 0, 0}, - {11, 2, "r11w", RISC_COLOR(0, 11, 0x3), NULL, 0, 0}, - {11, 4, "r11d", RISC_COLOR(0, 11, 0xf), NULL, 0, 0}, - {11, 8, "r11", RISC_COLOR(0, 11, 0xff), NULL, 0, 0}, - - {12, 1, "r12b", RISC_COLOR(0, 12, 0x1), NULL, 0, 0}, - {12, 2, "r12w", RISC_COLOR(0, 12, 0x3), NULL, 0, 0}, - {12, 4, "r12d", RISC_COLOR(0, 12, 0xf), NULL, 0, 0}, - {12, 8, "fp", RISC_COLOR(0, 12, 0xff), NULL, 0, 0}, - - {13, 1, "r13b", RISC_COLOR(0, 13, 0x1), NULL, 0, 0}, - {13, 2, "r13w", RISC_COLOR(0, 13, 0x3), NULL, 0, 0}, - {13, 4, "r13d", RISC_COLOR(0, 13, 0xf), NULL, 0, 0}, - {13, 8, "lr", RISC_COLOR(0, 13, 0xff), NULL, 0, 0}, - - {14, 8, "sp", RISC_COLOR(0, 14, 0xff), NULL, 0, 0}, -// {15, 8, "null", RISC_COLOR(0, 15, 0xff), NULL, 0, 0}, - - - {0, 1, "b0", RISC_COLOR(1, 0, 0x1), NULL, 0, 0}, - {0, 2, "h0", RISC_COLOR(1, 0, 0x3), NULL, 0, 0}, - {0, 4, "s0", RISC_COLOR(1, 0, 0xf), NULL, 0, 0}, - {0, 8, "d0", RISC_COLOR(1, 0, 0xff), NULL, 0, 0}, - - {1, 1, "b1", RISC_COLOR(1, 1, 0x1), NULL, 0, 0}, - {1, 2, "h1", RISC_COLOR(1, 1, 0x3), NULL, 0, 0}, - {1, 4, "s1", RISC_COLOR(1, 1, 0xf), NULL, 0, 0}, - {1, 8, "d1", RISC_COLOR(1, 1, 0xff), NULL, 0, 0}, - - {2, 1, "b2", RISC_COLOR(1, 2, 0x1), NULL, 0, 0}, - {2, 2, "h2", RISC_COLOR(1, 2, 0x3), NULL, 0, 0}, - {2, 4, "s2", RISC_COLOR(1, 2, 0xf), NULL, 0, 0}, - {2, 8, "d2", RISC_COLOR(1, 2, 0xff), NULL, 0, 0}, - - {3, 1, "b3", RISC_COLOR(1, 3, 0x1), NULL, 0, 0}, - {3, 2, "h3", RISC_COLOR(1, 3, 0x3), NULL, 0, 0}, - {3, 4, "s3", RISC_COLOR(1, 3, 0xf), NULL, 0, 0}, - {3, 8, "d3", RISC_COLOR(1, 3, 0xff), NULL, 0, 0}, - - {4, 1, "b4", RISC_COLOR(1, 4, 0x1), NULL, 0, 0}, - {4, 2, "h4", RISC_COLOR(1, 4, 0x3), NULL, 0, 0}, - {4, 4, "s4", RISC_COLOR(1, 4, 0xf), NULL, 0, 0}, - {4, 8, "d4", RISC_COLOR(1, 4, 0xff), NULL, 0, 0}, - - {5, 1, "b5", RISC_COLOR(1, 5, 0x1), NULL, 0, 0}, - {5, 2, "h5", RISC_COLOR(1, 5, 0x3), NULL, 0, 0}, - {5, 4, "s5", RISC_COLOR(1, 5, 0xf), NULL, 0, 0}, - {5, 8, "d5", RISC_COLOR(1, 5, 0xff), NULL, 0, 0}, - - {6, 1, "b6", RISC_COLOR(1, 6, 0x1), NULL, 0, 0}, - {6, 2, "h6", RISC_COLOR(1, 6, 0x3), NULL, 0, 0}, - {6, 4, "s6", RISC_COLOR(1, 6, 0xf), NULL, 0, 0}, - {6, 8, "d6", RISC_COLOR(1, 6, 0xff), NULL, 0, 0}, - - {7, 1, "b7", RISC_COLOR(1, 7, 0x1), NULL, 0, 0}, - {7, 2, "h7", RISC_COLOR(1, 7, 0x3), NULL, 0, 0}, - {7, 4, "s7", RISC_COLOR(1, 7, 0xf), NULL, 0, 0}, - {7, 8, "d7", RISC_COLOR(1, 7, 0xff), NULL, 0, 0}, - - {8, 1, "b8", RISC_COLOR(1, 8, 0x1), NULL, 0, 0}, - {8, 2, "h8", RISC_COLOR(1, 8, 0x3), NULL, 0, 0}, - {8, 4, "s8", RISC_COLOR(1, 8, 0xf), NULL, 0, 0}, - {8, 8, "d8", RISC_COLOR(1, 8, 0xff), NULL, 0, 0}, - - {9, 1, "b9", RISC_COLOR(1, 9, 0x1), NULL, 0, 0}, - {9, 2, "h9", RISC_COLOR(1, 9, 0x3), NULL, 0, 0}, - {9, 4, "s9", RISC_COLOR(1, 9, 0xf), NULL, 0, 0}, - {9, 8, "d9", RISC_COLOR(1, 9, 0xff), NULL, 0, 0}, - - {10, 1, "b10", RISC_COLOR(1, 10, 0x1), NULL, 0, 0}, - {10, 2, "h10", RISC_COLOR(1, 10, 0x3), NULL, 0, 0}, - {10, 4, "s10", RISC_COLOR(1, 10, 0xf), NULL, 0, 0}, - {10, 8, "d10", RISC_COLOR(1, 10, 0xff), NULL, 0, 0}, - - {11, 1, "b11", RISC_COLOR(1, 11, 0x1), NULL, 0, 0}, - {11, 2, "h11", RISC_COLOR(1, 11, 0x3), NULL, 0, 0}, - {11, 4, "s11", RISC_COLOR(1, 11, 0xf), NULL, 0, 0}, - {11, 8, "d11", RISC_COLOR(1, 11, 0xff), NULL, 0, 0}, - - {12, 1, "b12", RISC_COLOR(1, 12, 0x1), NULL, 0, 0}, - {12, 2, "h12", RISC_COLOR(1, 12, 0x3), NULL, 0, 0}, - {12, 4, "s12", RISC_COLOR(1, 12, 0xf), NULL, 0, 0}, - {12, 8, "d12", RISC_COLOR(1, 12, 0xff), NULL, 0, 0}, - - {13, 1, "b13", RISC_COLOR(1, 13, 0x1), NULL, 0, 0}, - {13, 2, "h13", RISC_COLOR(1, 13, 0x3), NULL, 0, 0}, - {13, 4, "s13", RISC_COLOR(1, 13, 0xf), NULL, 0, 0}, - {13, 8, "d13", RISC_COLOR(1, 13, 0xff), NULL, 0, 0}, - - {14, 1, "b14", RISC_COLOR(1, 14, 0x1), NULL, 0, 0}, - {14, 2, "h14", RISC_COLOR(1, 14, 0x3), NULL, 0, 0}, - {14, 4, "s14", RISC_COLOR(1, 14, 0xf), NULL, 0, 0}, - {14, 8, "d14", RISC_COLOR(1, 14, 0xff), NULL, 0, 0}, - - {15, 1, "b15", RISC_COLOR(1, 15, 0x1), NULL, 0, 0}, - {15, 2, "h15", RISC_COLOR(1, 15, 0x3), NULL, 0, 0}, - {15, 4, "s15", RISC_COLOR(1, 15, 0xf), NULL, 0, 0}, - {15, 8, "d15", RISC_COLOR(1, 15, 0xff), NULL, 0, 0}, -}; - -static uint32_t naja_abi_regs[] = -{ - SCF_RISC_REG_X0, - SCF_RISC_REG_X1, - SCF_RISC_REG_X2, - SCF_RISC_REG_X3, - SCF_RISC_REG_X4, - SCF_RISC_REG_X5, -}; - -static uint32_t naja_abi_float_regs[] = -{ - SCF_RISC_REG_D0, - SCF_RISC_REG_D1, - SCF_RISC_REG_D2, - SCF_RISC_REG_D3, - SCF_RISC_REG_D4, - SCF_RISC_REG_D5, - SCF_RISC_REG_D6, - SCF_RISC_REG_D7, -}; - -static uint32_t naja_abi_ret_regs[] = -{ - SCF_RISC_REG_X0, - SCF_RISC_REG_X1, - SCF_RISC_REG_X2, - SCF_RISC_REG_X3, -}; - -static uint32_t naja_abi_caller_saves[] = -{ - SCF_RISC_REG_X0, - SCF_RISC_REG_X1, - SCF_RISC_REG_X2, - SCF_RISC_REG_X3, - SCF_RISC_REG_X4, - SCF_RISC_REG_X5, -}; - -static uint32_t naja_abi_callee_saves[] = -{ - SCF_RISC_REG_X6, - SCF_RISC_REG_X7, - SCF_RISC_REG_X8, - SCF_RISC_REG_X9, - SCF_RISC_REG_FP, - SCF_RISC_REG_LR, -}; - -static int naja_color_conflict(intptr_t c0, intptr_t c1) -{ - intptr_t id0 = c0 >> 16; - intptr_t id1 = c1 >> 16; - - return id0 == id1 && (c0 & c1 & 0xffff); -} - -static int naja_variable_size(scf_variable_t* v) -{ - if (v->nb_dimentions > 0) - return 8; - - if (v->type >= SCF_STRUCT && 0 == v->nb_pointers) - return 8; - - return v->size; -} - -scf_register_t* naja_find_register(const char* name) -{ - int i; - for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { - - scf_register_t* r = &(naja_registers[i]); - - if (!strcmp(r->name, name)) - return r; - } - return NULL; -} - -scf_register_t* naja_find_register_type_id_bytes(uint32_t type, uint32_t id, int bytes) -{ - int i; - for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { - - scf_register_t* r = &(naja_registers[i]); - - if (RISC_COLOR_TYPE(r->color) == type && r->id == id && r->bytes == bytes) - return r; - } - return NULL; -} - -scf_register_t* naja_find_register_color(intptr_t color) -{ - int i; - for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { - - scf_register_t* r = &(naja_registers[i]); - - if (r->color == color) - return r; - } - return NULL; -} - -scf_register_t* naja_find_register_color_bytes(intptr_t color, int bytes) -{ - int i; - for (i = 0; i < sizeof(naja_registers) / sizeof(naja_registers[0]); i++) { - - scf_register_t* r = &(naja_registers[i]); - - if (naja_color_conflict(r->color, color) && r->bytes == bytes) - return r; - } - return NULL; -} +#include"scf_naja_reg.c" scf_vector_t* naja_register_colors() { @@ -466,7 +183,7 @@ int naja_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, return ret; } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -482,7 +199,7 @@ int naja_caller_save_regs(scf_3ac_code_t* c, scf_function_t* f, uint32_t* regs, return ret; } else { inst = f->iops->PUSH(NULL, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } saved_regs[k++] = r2; @@ -543,10 +260,10 @@ int naja_pop_regs(scf_3ac_code_t* c, scf_function_t* f, scf_register_t** regs, i if (i == nb_updated) { inst = f->iops->POP(c, r2); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } else { inst = f->iops->ADD_IMM(c, f, sp, sp, 8); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } } return 0; @@ -980,7 +697,7 @@ int naja_push_callee_regs(scf_3ac_code_t* c, scf_function_t* f) } inst = f->iops->PUSH(NULL, r); - RISC_INST_ADD_CHECK(f->init_code->instructions, inst); + RISC_INST_ADD_CHECK(f->init_code, inst); f->init_code_bytes += inst->len; } @@ -1008,7 +725,7 @@ int naja_pop_callee_regs(scf_3ac_code_t* c, scf_function_t* f) } inst = f->iops->POP(c, r); - RISC_INST_ADD_CHECK(c->instructions, inst); + RISC_INST_ADD_CHECK(c, inst); } return 0; diff --git a/js/native/risc/scf_risc_util.h b/js/native/risc/scf_risc_util.h index d8209eb..e92c843 100644 --- a/js/native/risc/scf_risc_util.h +++ b/js/native/risc/scf_risc_util.h @@ -115,6 +115,8 @@ enum scf_risc_OpCode_types SCF_RISC_JMP, + SCF_RISC_ADRP, + SCF_RISC_NB }; diff --git a/js/native/scf_instruction.c b/js/native/scf_instruction.c index 92519a8..fc9e4e1 100644 --- a/js/native/scf_instruction.c +++ b/js/native/scf_instruction.c @@ -6,6 +6,7 @@ void scf_rela_free(scf_rela_t* rela) if (rela->name) scf_string_free(rela->name); + rela->inst->rel = NULL; free(rela); } } @@ -19,10 +20,31 @@ void scf_instruction_free(scf_instruction_t* inst) if (inst->bin) scf_string_free(inst->bin); + inst->rel = NULL; free(inst); } } +void scf_inst_data_print(scf_inst_data_t* id) +{ + if (1 == id->mem_flag) { + if (id->index) + printf("%d(%s, %s, %d)", id->disp, id->base->name, id->index->name, id->scale); + + else if (id->base) { + if (id->disp < 0) + printf("-%#x(%s)", -id->disp, id->base->name); + else + printf("%#x(%s)", id->disp, id->base->name); + } else + printf("%d(rip)", id->disp); + + } else if (id->base) + printf("%s", id->base->name); + else if (id->imm_size > 0) + printf("%d", (int)id->imm); +} + void scf_instruction_print(scf_instruction_t* inst) { if (inst->label) @@ -31,46 +53,23 @@ void scf_instruction_print(scf_instruction_t* inst) if (inst->OpCode) printf("%s ", inst->OpCode->name); - if (1 == inst->src.flag) { - if (inst->src.index) - printf("%d(%s, %s, %d), ", inst->src.disp, inst->src.base->name, - inst->src.index->name, inst->src.scale); - - else if (inst->src.base) { - if (inst->src.disp < 0) - printf("-%#x(%s), ", -inst->src.disp, inst->src.base->name); - else - printf("%#x(%s), ", inst->src.disp, inst->src.base->name); - } else - printf("%d(rip), ", inst->dst.disp); - - } else if (inst->src.base) - printf("%s, ", inst->src.base->name); - - else if (inst->src.imm_size > 0) - printf("%d, ", (int)inst->src.imm); + scf_inst_data_print(&inst->dst); - if (1 == inst->dst.flag) { - if (inst->dst.index) - printf("%d(%s, %s, %d)", inst->dst.disp, inst->dst.base->name, - inst->dst.index->name, inst->dst.scale); + if (!scf_inst_data_empty(&inst->dst) && !scf_inst_data_empty(&inst->src)) + printf(", "); + scf_inst_data_print(&inst->src); - else if (inst->dst.base) { - if (inst->dst.disp < 0) - printf("-%#x(%s)", -inst->dst.disp, inst->dst.base->name); - else - printf("%#x(%s)", inst->dst.disp, inst->dst.base->name); - } else - printf("%d(rip)", inst->dst.disp); + if (!scf_inst_data_empty(&inst->srcs[0])) + printf(", "); + scf_inst_data_print(&inst->srcs[0]); - } else if (inst->dst.base) - printf("%s", inst->dst.base->name); + if (!scf_inst_data_empty(&inst->srcs[1])) + printf(", "); + scf_inst_data_print(&inst->srcs[1]); - else if (inst->dst.imm_size > 0) - printf("%d", (int)inst->dst.imm); - - int i; - for (i = 0; i < inst->len; i++) + printf(" |"); + for (int i = 0; i < inst->len; i++) printf(" %#x", inst->code[i]); + printf("\n"); } diff --git a/js/native/scf_instruction.h b/js/native/scf_instruction.h index 37c0b0e..004018e 100644 --- a/js/native/scf_instruction.h +++ b/js/native/scf_instruction.h @@ -5,6 +5,7 @@ #include"scf_core_types.h" typedef struct scf_instruction_s scf_instruction_t; +typedef struct scf_rela_s scf_rela_t; struct scf_register_s { @@ -46,23 +47,29 @@ typedef struct { uint64_t imm; int imm_size; - uint8_t flag; + uint8_t mem_flag:1; } scf_inst_data_t; struct scf_instruction_s { scf_3ac_code_t* c; + scf_rela_t* rel; + scf_OpCode_t* OpCode; scf_instruction_t* next; // only for jcc, jmp, call - scf_inst_data_t src; scf_inst_data_t dst; + scf_inst_data_t src; + scf_inst_data_t srcs[2]; scf_lex_word_t* label; // asm label scf_string_t* bin; // asm binary data, maybe in .text or .data int offset; // asm offset, maybe in .text or .data + int align; // asm .align + int org; // asm .org + int len; uint8_t code[32]; @@ -70,8 +77,8 @@ struct scf_instruction_s int nb_used; }; -typedef struct { - scf_3ac_code_t* code; // related 3ac code +struct scf_rela_s +{ scf_function_t* func; scf_variable_t* var; scf_string_t* name; @@ -81,19 +88,25 @@ typedef struct { int64_t text_offset; // byte offset in .text segment uint64_t type; int addend; -} scf_rela_t; +}; + + +static inline int scf_inst_data_empty(scf_inst_data_t* id) +{ + return !(id->mem_flag || id->base || id->imm_size); +} static inline int scf_inst_data_same(scf_inst_data_t* id0, scf_inst_data_t* id1) { // global var, are considered as different. - if ((id0->flag && !id0->base) || (id1->flag && !id1->base)) + if ((id0->mem_flag && !id0->base) || (id1->mem_flag && !id1->base)) return 0; if (id0->scale == id1->scale && id0->disp == id1->disp - && id0->flag == id1->flag && id0->imm == id1->imm - && id0->imm_size == id1->imm_size) { + && id0->imm_size == id1->imm_size + && id0->mem_flag == id1->mem_flag) { if (id0->base == id1->base || (id0->base && id1->base && SCF_COLOR_CONFLICT(id0->base->color, id1->base->color))) { diff --git a/js/native/x64/scf_x64.c b/js/native/x64/scf_x64.c index 300b9dc..903fa68 100644 --- a/js/native/x64/scf_x64.c +++ b/js/native/x64/scf_x64.c @@ -159,7 +159,7 @@ static int _x64_save_rabi(scf_function_t* f) #define X64_SAVE_RABI(offset, rabi) \ do { \ inst = x64_make_inst_G2P(mov, rbp, offset, rabi); \ - X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); \ + X64_INST_ADD_CHECK(f->init_code, inst, NULL); \ f->init_code_bytes += inst->len; \ } while (0) @@ -234,42 +234,49 @@ static int _x64_function_finish(scf_function_t* f) if (err < 0) return err; + uint32_t local = f->bp_used_flag ? f->local_vars_size : 0; + + if ((f->callee_saved_size + local) & 0xf) + local += 8; + + scf_logd("### local: %#x, local_vars_size: %#x, callee_saved_size: %#x\n", + local, f->local_vars_size, f->callee_saved_size); + if (f->bp_used_flag || f->vla_flag || f->call_flag) { - inst = x64_make_inst_G2E(mov, rsp, rbp); - X64_INST_ADD_CHECK(end->instructions, inst, NULL); - end->inst_bytes += inst->len; - bb ->code_bytes += inst->len; + if (f->bp_used_flag || f->vla_flag) { + inst = x64_make_inst_G2E(mov, rsp, rbp); + X64_INST_ADD_CHECK(end, inst, NULL); + end->inst_bytes += inst->len; + bb ->code_bytes += inst->len; + } inst = x64_make_inst_G(pop, rbp); - X64_INST_ADD_CHECK(end->instructions, inst, NULL); + X64_INST_ADD_CHECK(end, inst, NULL); end->inst_bytes += inst->len; bb ->code_bytes += inst->len; } f->init_code_bytes = 0; - uint32_t local = f->bp_used_flag ? f->local_vars_size : 0; if (f->bp_used_flag || f->vla_flag || f->call_flag) { inst = x64_make_inst_G(push, rbp); - X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); - f->init_code_bytes += inst->len; - - inst = x64_make_inst_G2E(mov, rbp, rsp); - X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); + X64_INST_ADD_CHECK(f->init_code, inst, NULL); f->init_code_bytes += inst->len; - if ((f->callee_saved_size + local) & 0xf) - local += 8; - - scf_logd("### local: %#x, local_vars_size: %#x, callee_saved_size: %#x\n", - local, f->local_vars_size, f->callee_saved_size); + if (f->bp_used_flag || f->vla_flag) { + inst = x64_make_inst_G2E(mov, rbp, rsp); + X64_INST_ADD_CHECK(f->init_code, inst, NULL); + f->init_code_bytes += inst->len; + } - inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&local, 4); - X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); - f->init_code_bytes += inst->len; + if (local > 0) { + inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&local, 4); + X64_INST_ADD_CHECK(f->init_code, inst, NULL); + f->init_code_bytes += inst->len; + } err = _x64_save_rabi(f); if (err < 0) @@ -281,7 +288,7 @@ static int _x64_function_finish(scf_function_t* f) return err; inst = x64_make_inst(ret, 8); - X64_INST_ADD_CHECK(end->instructions, inst, NULL); + X64_INST_ADD_CHECK(end, inst, NULL); end->inst_bytes += inst->len; bb ->code_bytes += inst->len; @@ -731,8 +738,8 @@ static void _x64_set_offset_for_relas(scf_native_t* ctx, scf_function_t* f, scf_ for (i = 0; i < relas->size; i++) { scf_rela_t* rela = relas->data[i]; - scf_3ac_code_t* c = rela->code; scf_instruction_t* inst = rela->inst; + scf_3ac_code_t* c = inst->c; scf_basic_block_t* cur_bb = c->basic_block; scf_instruction_t* inst2; diff --git a/js/native/x64/scf_x64_inst.c b/js/native/x64/scf_x64_inst.c index 9921814..89147f9 100644 --- a/js/native/x64/scf_x64_inst.c +++ b/js/native/x64/scf_x64_inst.c @@ -204,11 +204,11 @@ static int _x64_inst_call_argv(scf_3ac_code_t* c, scf_function_t* f) if (!rd) { if (movx) { inst = x64_make_inst_E2G(movx, rs, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } inst = x64_make_inst_G2P(mov, rsp, v->sp_offset, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); continue; } @@ -221,12 +221,12 @@ static int _x64_inst_call_argv(scf_3ac_code_t* c, scf_function_t* f) if (!X64_COLOR_CONFLICT(rd->color, rs->color)) { if (movx) { inst = x64_make_inst_E2G(movx, rs, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } rd = x64_find_register_color_bytes(rd->color, rs->bytes); inst = x64_make_inst_G2E(mov, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (movx) { inst = x64_make_inst_E2G(movx, rs, rs); @@ -240,7 +240,7 @@ static int _x64_inst_call_argv(scf_3ac_code_t* c, scf_function_t* f) } for (i = 0; i < nb_movx; i++) { - X64_INST_ADD_CHECK(c->instructions, inst_movx[i], NULL); + X64_INST_ADD_CHECK(c, inst_movx[i], NULL); } return nb_floats; @@ -399,7 +399,7 @@ static int _x64_call_update_dsts(scf_3ac_code_t* c, scf_function_t* f, scf_regis int valid = _x64_dst_reg_valid(rd, updated_regs, nb_updated, idx_int, nb_int); if (valid) { inst = x64_make_inst_G2E(mov, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); assert(nb_updated < max_updated); @@ -444,7 +444,7 @@ static int _x64_call_update_dsts(scf_3ac_code_t* c, scf_function_t* f, scf_regis scf_rela_t* rela = NULL; inst = x64_make_inst_G2M(&rela, mov, dn->var, NULL, rs); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dn->var, NULL); } } @@ -513,7 +513,7 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (stack_size > 0) { sub = x64_find_OpCode(SCF_X64_SUB, 4,4, SCF_X64_I2E); inst_rsp = x64_make_inst_I2E(sub, rsp, (uint8_t*)&stack_size, 4); - X64_INST_ADD_CHECK(c->instructions, inst_rsp, NULL); + X64_INST_ADD_CHECK(c, inst_rsp, NULL); } ret = _x64_inst_call_argv(c, f); @@ -525,7 +525,7 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) mov = x64_find_OpCode(SCF_X64_MOV, 4,4, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, eax, (uint8_t*)&imm, sizeof(imm)); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); scf_register_t* saved_regs[X64_ABI_CALLER_SAVES_NB]; scf_register_t* drop_regs [X64_ABI_CALLER_SAVES_NB]; @@ -549,7 +549,7 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) int32_t offset = 0; call = x64_find_OpCode(SCF_X64_CALL, 4,4, SCF_X64_I); inst = x64_make_inst_I(call, (uint8_t*)&offset, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst->OpCode = (scf_OpCode_t*)call; @@ -575,14 +575,14 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) } inst = x64_make_inst_E(call, r_pf); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst->OpCode = (scf_OpCode_t*)call; } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, call, var_pf, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, pf); inst->OpCode = (scf_OpCode_t*)call; @@ -592,7 +592,7 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (stack_size > 0) { add = x64_find_OpCode(SCF_X64_ADD, 4, 4, SCF_X64_I2E); inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&stack_size, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } x64_drop_regs(drop_regs, n_drops); @@ -610,7 +610,7 @@ static int _x64_inst_call_handler(scf_native_t* ctx, scf_3ac_code_t* c) } if (save_size > 0) { - ret = x64_pop_regs(c->instructions, saved_regs, save_size >> 3, updated_regs, nb_updated); + ret = x64_pop_regs(c, saved_regs, save_size >> 3, updated_regs, nb_updated); if (ret < 0) { scf_loge("\n"); return ret; @@ -665,12 +665,12 @@ static int _x64_inst_unary(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type if (dst->dag_node->color > 0) { X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0); inst = x64_make_inst_E(OpCode, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, OpCode, var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, var, NULL); } @@ -708,7 +708,7 @@ static int _x64_inst_unary_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCo if (src->dag_node->color > 0) { X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_E(OpCode, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (0 == src->dag_node->color) { scf_loge("\n"); @@ -717,7 +717,7 @@ static int _x64_inst_unary_assign(scf_native_t* ctx, scf_3ac_code_t* c, int OpCo scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, OpCode, var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, var, NULL); } @@ -776,13 +776,13 @@ static int _x64_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0); inst = x64_make_inst_E2G(pxor, rd, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); if (src->dag_node->color > 0) { X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_E2G(sub, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { v = src->dag_node->var; @@ -795,7 +795,7 @@ static int _x64_inst_neg_handler(scf_native_t* ctx, scf_3ac_code_t* c) scf_rela_t* rela = NULL; inst = x64_make_inst_M2G(&rela, sub, rd, NULL, v); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } @@ -850,7 +850,7 @@ static int _x64_inst_inc_float(scf_function_t* f, scf_3ac_code_t* c, int INC) X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_M2G(&rela, OpCode, rs, NULL, v1); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v1, NULL); return 0; } @@ -902,12 +902,12 @@ static int _x64_inst_inc(scf_native_t* ctx, scf_3ac_code_t* c, int INC, int ADD) if (src->dag_node->color > 0) { X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_I2E(OpCode, rs, (uint8_t*)&v->data_size, imm_size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_I2M(&rela, OpCode, v, NULL, (uint8_t*)&v->data_size, imm_size); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } @@ -915,12 +915,12 @@ static int _x64_inst_inc(scf_native_t* ctx, scf_3ac_code_t* c, int INC, int ADD) if (src->dag_node->color > 0) { X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_E(OpCode, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, OpCode, v, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } } @@ -1016,7 +1016,7 @@ static int _x64_inst_assign_array_index(scf_native_t* ctx, scf_3ac_code_t* c, in else inst = x64_make_inst_I2P(OpCode, sib.base, sib.disp, (uint8_t*)&vs->data, size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -1042,10 +1042,10 @@ static int _x64_inst_assign_array_index(scf_native_t* ctx, scf_3ac_code_t* c, in if (sib.index) { inst = x64_make_inst_G2SIB(OpCode, sib.base, sib.index, sib.scale, sib.disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_G2P(OpCode, sib.base, sib.disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; } @@ -1125,10 +1125,10 @@ static int _x64_inst_array_index(scf_native_t* ctx, scf_3ac_code_t* c, int lea_f if (sib.index) { inst = x64_make_inst_SIB2G(OpCode, rd, sib.base, sib.index, sib.scale, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_P2G(OpCode, rd, sib.base, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; } @@ -1193,7 +1193,7 @@ static int _x64_inst_address_of_handler(scf_native_t* ctx, scf_3ac_code_t* c) lea = x64_find_OpCode(SCF_X64_LEA, 8,8, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, lea, rd, NULL, src->dag_node->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->dag_node->var, NULL); return 0; } @@ -1532,21 +1532,21 @@ static int _x64_inst_dump_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_G2E(mov, rsi, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); scf_rela_t* rela = NULL; inst = x64_make_inst_M2G(&rela, lea, rdi, NULL, msg->dag_node->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, msg->dag_node->var, NULL); inst = x64_make_inst_G2E(xor, rax, rax); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); // call printf() to show msg uint32_t imm = 0; inst = x64_make_inst_I(call, (uint8_t*)&imm, sizeof(imm)); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); rela = calloc(1, sizeof(scf_rela_t)); if (!rela) @@ -1555,10 +1555,10 @@ static int _x64_inst_dump_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, logf->dag_node->var->func_ptr); inst = x64_make_inst_G2E(xor, rax, rax); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rax, 0, rax); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -1601,14 +1601,14 @@ static int _x64_inst_vla_alloc_handler(scf_native_t* ctx, scf_3ac_code_t* c) uint32_t imm = 0xf; inst = x64_make_inst_I2E(add, rs, (uint8_t*)&imm, sizeof(imm)); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); imm = ~0xf; inst = x64_make_inst_I2E(and, rs, (uint8_t*)&imm, sizeof(imm)); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_E2G(sub, rsp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); int ret = x64_save_var(src->dag_node, c, f); if (ret < 0) @@ -1617,7 +1617,7 @@ static int _x64_inst_vla_alloc_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rd, dst->dag_node, c, f, 0); inst = x64_make_inst_G2E(mov, rd, rsp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -1651,10 +1651,10 @@ static int _x64_inst_vla_free_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); inst = x64_make_inst_E2G(add, rsp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2E(xor, rs, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return x64_save_var(src->dag_node, c, f); } @@ -1755,14 +1755,14 @@ static int _x64_inst_return_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (rd->bytes > size) { inst = x64_make_inst_E2G(mov, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { X64_SELECT_REG_CHECK(&rs, src->dag_node, c, f, 1); if (!X64_COLOR_CONFLICT(rd->color, rs->color) || rd->bytes > size) { inst = x64_make_inst_E2G(mov, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } } else if (0 == src->dag_node->color) { @@ -1773,10 +1773,10 @@ static int _x64_inst_return_handler(scf_native_t* ctx, scf_3ac_code_t* c) mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, rd, (uint8_t*)&v->data, rd->bytes); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_M2G(&rela, mov, rd, NULL, v); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } } @@ -1828,7 +1828,7 @@ static int _x64_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (0 == dn->color) { \ mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G); \ inst = x64_make_inst_I2G(mov, r, (uint8_t*)&dn->var->data, size); \ - X64_INST_ADD_CHECK(c->instructions, inst, NULL); \ + X64_INST_ADD_CHECK(c, inst, NULL); \ \ } else { \ if (dn->color < 0) \ @@ -1838,7 +1838,7 @@ static int _x64_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (!X64_COLOR_CONFLICT(rd->color, r->color)) { \ mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_G2E); \ inst = x64_make_inst_G2E(mov, r, rd); \ - X64_INST_ADD_CHECK(c->instructions, inst, NULL); \ + X64_INST_ADD_CHECK(c, inst, NULL); \ } \ } \ } while (0) @@ -1849,7 +1849,7 @@ static int _x64_inst_memset_handler(scf_native_t* ctx, scf_3ac_code_t* c) stos = x64_find_OpCode(SCF_X64_STOS, 1, 8, SCF_X64_G); inst = x64_make_inst(stos, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -2093,13 +2093,13 @@ static int _x64_inst_push_rets_handler(scf_native_t* ctx, scf_3ac_code_t* c) r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[i], 8); inst = x64_make_inst_G(push, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } if (n & 0x1) { r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[n - 1], 8); inst = x64_make_inst_G(push, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; } @@ -2131,14 +2131,14 @@ static int _x64_inst_pop_rets_handler(scf_native_t* ctx, scf_3ac_code_t* c) if (n & 0x1) { r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[n - 1], 8); inst = x64_make_inst_G(pop, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } for (i = n - 1; i >= 0; i--) { r = x64_find_register_type_id_bytes(0, x64_abi_ret_regs[i], 8); inst = x64_make_inst_G(pop, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; @@ -2193,32 +2193,32 @@ static int _x64_inst_va_start_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0); inst = x64_make_inst_P2G(lea, rptr, rbp, offset_int); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 0, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_P2G(lea, rptr, rbp, offset_float); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 8, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_P2G(lea, rptr, rbp, offset_others); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 16, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); mov = x64_find_OpCode(SCF_X64_MOV, 4, 8, SCF_X64_I2E); inst = x64_make_inst_I2P(mov, rap, 24, (uint8_t*)&f->args_int, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_I2P(mov, rap, 32, (uint8_t*)&f->args_float, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -2257,22 +2257,22 @@ static int _x64_inst_va_end_handler(scf_native_t* ctx, scf_3ac_code_t* c) X64_SELECT_REG_CHECK(&rptr, ptr->dag_node, c, f, 0); inst = x64_make_inst_G2E(xor, rptr, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 0, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 8, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 16, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 24, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(mov, rap, 32, rptr); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); ptr->dag_node->var->tmp_flag = 0; ptr->dag_node->color = 0; @@ -2340,22 +2340,22 @@ static int _x64_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) } inst = x64_make_inst_I2P(cmp, rap, idx_offset, (uint8_t*)&nints, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst_jge = x64_make_inst_I(jge, (uint8_t*)&offset, sizeof(offset)); - X64_INST_ADD_CHECK(c->instructions, inst_jge, NULL); + X64_INST_ADD_CHECK(c, inst_jge, NULL); inst = x64_make_inst_P2G(mov, rptr, rap, ptr_offset); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); offset += inst->len; inst = x64_make_inst_I2P(sub, rap, ptr_offset, (uint8_t*)&incptr, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); offset += inst->len; inst_jmp = x64_make_inst_I(jmp, (uint8_t*)&offset, sizeof(offset)); - X64_INST_ADD_CHECK(c->instructions, inst_jmp, NULL); + X64_INST_ADD_CHECK(c, inst_jmp, NULL); offset += inst_jmp->len; uint8_t* p = (uint8_t*)&offset; @@ -2365,18 +2365,18 @@ static int _x64_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) offset = 0; inst = x64_make_inst_P2G(mov, rptr, rap, 16); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); offset += inst->len; inst = x64_make_inst_I2P(add, rap, 16, (uint8_t*)&incptr, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); offset += inst->len; for (i = 0; i < 4; i++) inst_jmp->code[jmp->nb_OpCodes + i] = p[i]; inst = x64_make_inst_P(inc, rap, idx_offset, 8); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); if (is_float) { if (4 == size) @@ -2389,7 +2389,7 @@ static int _x64_inst_va_arg_handler(scf_native_t* ctx, scf_3ac_code_t* c) mov2 = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G); inst = x64_make_inst_P2G(mov2, rd, rptr, 0); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } diff --git a/js/native/x64/scf_x64_inst_binary.c b/js/native/x64/scf_x64_inst_binary.c index a292950..ec83545 100644 --- a/js/native/x64/scf_x64_inst_binary.c +++ b/js/native/x64/scf_x64_inst_binary.c @@ -41,11 +41,11 @@ static int _binary_assign_sib_float(scf_register_t* rb, scf_register_t* ri, int3 inst = x64_make_inst_SIB2G(mov, rs, rb, ri, scale, disp); else inst = x64_make_inst_P2G(mov, rs, rb, disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); OpCode = x64_find_OpCode(OpCode_type, v->size, v->size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, OpCode, rs, NULL, src->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); end: @@ -54,7 +54,7 @@ end: inst = x64_make_inst_G2SIB(mov, rb, ri, scale, disp, rs); else inst = x64_make_inst_G2P(mov, rb, disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -82,7 +82,7 @@ static int _binary_assign_sib_int(x64_sib_t* sib, scf_dag_node_t* src, scf_3ac_c inst = x64_make_inst_I2SIB(OpCode, rb, ri, scale, disp, (uint8_t*)&v->data, dsize); else inst = x64_make_inst_I2P(OpCode, rb, disp, (uint8_t*)&v->data, dsize); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -108,7 +108,7 @@ static int _binary_assign_sib_int(x64_sib_t* sib, scf_dag_node_t* src, scf_3ac_c inst = x64_make_inst_G2SIB(OpCode, rb, ri, scale, disp, rs); else inst = x64_make_inst_G2P(OpCode, rb, disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -171,10 +171,10 @@ static int _binary_SIB2G(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type, if (sib.index) { inst = x64_make_inst_SIB2G(mov, rd, sib.base, sib.index, sib.scale, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_P2G(mov, rd, sib.base, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; } @@ -332,19 +332,19 @@ int x64_assign_pointer(scf_native_t* ctx, scf_3ac_code_t* c) r = x64_find_register_color_bytes(rs->color, 8); inst = x64_make_inst_G(push, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_I2G(mov, rs, (uint8_t*)&mask, dsize); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); if (sib.index) inst = x64_make_inst_G2SIB(and, sib.base, sib.index, sib.scale, sib.disp, rs); else inst = x64_make_inst_G2P(and, sib.base, sib.disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G(pop, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); int imm = (rs->bytes << 3) - vm->bit_size; assert(imm > 0); @@ -353,14 +353,14 @@ int x64_assign_pointer(scf_native_t* ctx, scf_3ac_code_t* c) shr = x64_find_OpCode(SCF_X64_SHR, 1, rs->bytes, SCF_X64_I2E); inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&imm, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); imm -= vm->bit_offset; assert(imm >= 0); if (imm > 0) { inst = x64_make_inst_I2E(shr, rs, (uint8_t*)&imm, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } mov = x64_find_OpCode(SCF_X64_OR, dsize, dsize, SCF_X64_G2E); @@ -375,7 +375,7 @@ int x64_assign_pointer(scf_native_t* ctx, scf_3ac_code_t* c) inst = x64_make_inst_G2SIB(mov, sib.base, sib.index, sib.scale, sib.disp, rs); else inst = x64_make_inst_G2P(mov, sib.base, sib.disp, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -452,10 +452,10 @@ int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag) if (sib.index) { inst = x64_make_inst_SIB2G(mov, rd, sib.base, sib.index, sib.scale, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_P2G(mov, rd, sib.base, sib.disp); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } if (vm->bit_size > 0) { @@ -467,12 +467,12 @@ int x64_inst_pointer(scf_native_t* ctx, scf_3ac_code_t* c, int lea_flag) if (imm > 0) { inst = x64_make_inst_I2E(shl, rd, (uint8_t*)&imm, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } imm += vm->bit_offset; inst = x64_make_inst_I2E(shr, rd, (uint8_t*)&imm, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; diff --git a/js/native/x64/scf_x64_inst_cmp.c b/js/native/x64/scf_x64_inst_cmp.c index 55d8711..2230212 100644 --- a/js/native/x64/scf_x64_inst_cmp.c +++ b/js/native/x64/scf_x64_inst_cmp.c @@ -35,7 +35,7 @@ static int _inst_cmp(scf_dag_node_t* src0, scf_dag_node_t* src1, scf_3ac_code_t* X64_SELECT_REG_CHECK(&rs1, src1, c, f, 1); inst = x64_make_inst_E2G(cmp, rs0, rs1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } } else { @@ -44,7 +44,7 @@ static int _inst_cmp(scf_dag_node_t* src0, scf_dag_node_t* src1, scf_3ac_code_t* if (cmp) { inst = x64_make_inst_I2E(cmp, rs0, (uint8_t*)&src1->var->data, src1_size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -54,7 +54,7 @@ static int _inst_cmp(scf_dag_node_t* src0, scf_dag_node_t* src1, scf_3ac_code_t* cmp = x64_find_OpCode(SCF_X64_CMP, rs0->bytes, src1_size, SCF_X64_G2E); inst = x64_make_inst_G2E(cmp, rs0, rs1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); src1->loaded = 0; src1->color = 0; @@ -68,10 +68,10 @@ static int _inst_cmp(scf_dag_node_t* src0, scf_dag_node_t* src1, scf_3ac_code_t* if (src1->color > 0) { X64_SELECT_REG_CHECK(&rs1, src1, c, f, 1); inst = x64_make_inst_E2G(cmp, rs0, rs1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_M2G(&rela, cmp, rs0, NULL, src1->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src1->var, NULL); } @@ -98,13 +98,13 @@ static int _inst_set(int setcc_type, scf_dag_node_t* dst, scf_3ac_code_t* c, scf mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, rd, (uint8_t*)&imm, rd->bytes); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); rd = x64_find_register_color_bytes(rd->color, 1); } inst = x64_make_inst_E(setcc, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } @@ -141,7 +141,7 @@ int x64_inst_teq(scf_native_t* ctx, scf_3ac_code_t* c) test = x64_find_OpCode(SCF_X64_TEST, v->size, v->size, SCF_X64_G2E); inst = x64_make_inst_G2E(test, rs, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } diff --git a/js/native/x64/scf_x64_inst_common.c b/js/native/x64/scf_x64_inst_common.c index 1d9eba7..52e7b00 100644 --- a/js/native/x64/scf_x64_inst_common.c +++ b/js/native/x64/scf_x64_inst_common.c @@ -91,14 +91,14 @@ static int _x64_inst_op2_imm(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_ OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2G); if (OpCode) { inst = x64_make_inst_I2G(OpCode, rd, (uint8_t*)&src->var->data, src_size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2E); if (OpCode) { inst = x64_make_inst_I2E(OpCode, rd, (uint8_t*)&src->var->data, src_size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } } @@ -114,7 +114,7 @@ static int _x64_inst_op2_imm(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_ X64_SELECT_REG_CHECK(&rs, src, c, f, 1); inst = x64_make_inst_G2E(OpCode, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); src->color = 0; src->loaded = 0; @@ -128,7 +128,7 @@ static int _x64_inst_op2_imm(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_ OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_I2E); if (OpCode) { inst = x64_make_inst_I2M(&rela, OpCode, dst->var, NULL, (uint8_t*)&src->var->data, src_size); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); return 0; } @@ -145,7 +145,7 @@ static int _x64_inst_op2_imm(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_ X64_SELECT_REG_CHECK(&rs, src, c, f, 1); inst = x64_make_inst_G2M(&rela, OpCode, dst->var, NULL, rs); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); src->color = 0; @@ -202,7 +202,7 @@ int x64_inst_op2(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_t* src, scf_ OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_G2E); if (OpCode) { inst = x64_make_inst_G2E(OpCode, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_E2G); if (!OpCode) { @@ -211,7 +211,7 @@ int x64_inst_op2(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_t* src, scf_ } inst = x64_make_inst_E2G(OpCode, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { OpCode = x64_find_OpCode(OpCode_type, src_size, dst_size, SCF_X64_E2G); @@ -221,7 +221,7 @@ int x64_inst_op2(int OpCode_type, scf_dag_node_t* dst, scf_dag_node_t* src, scf_ } inst = x64_make_inst_M2G(&rela, OpCode, rd, NULL, src->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); } @@ -252,7 +252,7 @@ int x64_inst_movx(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c, s assert(4 == src->var->size); xor = x64_find_OpCode(SCF_X64_XOR, 8, 8, SCF_X64_G2E); inst = x64_make_inst_G2E(xor, rd, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); movx = x64_find_OpCode(SCF_X64_MOV, 4, 4, SCF_X64_E2G); } @@ -260,7 +260,7 @@ int x64_inst_movx(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c, s if (src->color > 0) { X64_SELECT_REG_CHECK(&rs, src, c, f, 0); inst = x64_make_inst_E2G(movx, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (0 == src->color) { // get the rd's low bits register @@ -268,16 +268,16 @@ int x64_inst_movx(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c, s mov = x64_find_OpCode(SCF_X64_MOV, src->var->size, src->var->size, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, rs, (uint8_t*)&src->var->data, src->var->size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_E2G(movx, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M2G(&rela, movx, rd, NULL, src->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); } @@ -329,18 +329,18 @@ int x64_inst_float_cast(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t X64_SELECT_REG_CHECK(&rs, src, c, f, 1); inst = x64_make_inst_E2G(OpCode, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (src->color > 0) { X64_SELECT_REG_CHECK(&rs, src, c, f, 1); inst = x64_make_inst_E2G(OpCode, rd, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M2G(&rela, OpCode, rd, NULL, src->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); } @@ -369,6 +369,6 @@ int x64_inst_jmp(scf_native_t* ctx, scf_3ac_code_t* c, int OpCode_type) scf_instruction_t* inst = x64_make_inst_I(jcc, (uint8_t*)&offset, sizeof(offset)); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } diff --git a/js/native/x64/scf_x64_inst_div.c b/js/native/x64/scf_x64_inst_div.c index 9de5722..eebb869 100644 --- a/js/native/x64/scf_x64_inst_div.c +++ b/js/native/x64/scf_x64_inst_div.c @@ -44,7 +44,7 @@ int x64_inst_int_div(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_G2E); inst = x64_make_inst_G2E(mov, rl, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } if (rd->id != rh->id) { @@ -65,7 +65,7 @@ int x64_inst_int_div(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, mov, rl, NULL, dst->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } @@ -73,23 +73,23 @@ int x64_inst_int_div(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c div = x64_find_OpCode(SCF_X64_IDIV, size, size, SCF_X64_E); cdq = x64_find_OpCode_by_type(SCF_X64_CDQ); inst = x64_make_inst(cdq, size << 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { div = x64_find_OpCode(SCF_X64_DIV, size, size, SCF_X64_E); xor = x64_find_OpCode(SCF_X64_XOR, size, size, SCF_X64_G2E); inst = x64_make_inst_G2E(xor, rh, rh); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } if (src->color > 0) { X64_SELECT_REG_CHECK(&rs, src, c, f, 1); inst = x64_make_inst_E(div, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, div, src->var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); } @@ -103,14 +103,14 @@ int x64_inst_int_div(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c if (rd->id != result->id) { mov = x64_find_OpCode(SCF_X64_MOV, rd->bytes, rd->bytes, SCF_X64_G2E); inst = x64_make_inst_G2E(mov, rd, result); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { scf_rela_t* rela = NULL; mov = x64_find_OpCode(SCF_X64_MOV, dst->var->size, dst->var->size, SCF_X64_G2E); inst = x64_make_inst_G2M(&rela, mov, dst->var, NULL, result); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } diff --git a/js/native/x64/scf_x64_inst_mul.c b/js/native/x64/scf_x64_inst_mul.c index 6e20ce8..7fcc0db 100644 --- a/js/native/x64/scf_x64_inst_mul.c +++ b/js/native/x64/scf_x64_inst_mul.c @@ -12,15 +12,15 @@ static int _int_mul_src(scf_x64_OpCode_t* mul, scf_register_t* rh, scf_dag_node_ mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, rh, (uint8_t*)&src->var->data, size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_E(mul, rh); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { scf_rela_t* rela = NULL; inst = x64_make_inst_M(&rela, mul, src->var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, src->var, NULL); } @@ -87,23 +87,23 @@ int x64_inst_int_mul(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c if (rd->id == rl->id) { inst = x64_make_inst_E(mul, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (rs->id == rl->id) { inst = x64_make_inst_E(mul, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_G2E(mov, rl, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_E(mul, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { if (rd->id != rl->id) { inst = x64_make_inst_G2E(mov, rl, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } int ret = _int_mul_src(mul, rh, src, c, f); @@ -116,18 +116,18 @@ int x64_inst_int_mul(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c if (rs->id != rl->id) { inst = x64_make_inst_G2E(mov, rl, rs); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } inst = x64_make_inst_M(&rela, mul, dst->var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } else { mov2 = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, mov2, rl, NULL, dst->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); int ret = _int_mul_src(mul, rh, src, c, f); @@ -139,11 +139,11 @@ int x64_inst_int_mul(scf_dag_node_t* dst, scf_dag_node_t* src, scf_3ac_code_t* c if (rd) { if (rd->id != rl->id) { inst = x64_make_inst_G2E(mov, rd, rl); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { inst = x64_make_inst_G2M(&rela, mov, dst->var, NULL, rl); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } diff --git a/js/native/x64/scf_x64_inst_shift.c b/js/native/x64/scf_x64_inst_shift.c index 855ad92..9444828 100644 --- a/js/native/x64/scf_x64_inst_shift.c +++ b/js/native/x64/scf_x64_inst_shift.c @@ -25,7 +25,7 @@ static int _shift_count(scf_dag_node_t* count, scf_3ac_code_t* c, scf_function_t mov = x64_find_OpCode(SCF_X64_MOV, 1, 1, SCF_X64_G2E); inst = x64_make_inst_G2E(mov, cl, rc); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else if (count->color < 0) { ret = x64_overflow_reg(cl, c, f); @@ -38,7 +38,7 @@ static int _shift_count(scf_dag_node_t* count, scf_3ac_code_t* c, scf_function_t mov = x64_find_OpCode(SCF_X64_MOV, 1, 1, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, mov, cl, NULL, count->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, count->var, NULL); } @@ -76,11 +76,11 @@ static int _x64_shift(scf_native_t* ctx, scf_3ac_code_t* c, scf_dag_node_t* dst, if (0 != count->color) { shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_G2E); inst = x64_make_inst_E(shift, rd); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_I2E); inst = x64_make_inst_I2E(shift, rd, (uint8_t*)&count->var->data, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { scf_rela_t* rela = NULL; @@ -88,12 +88,12 @@ static int _x64_shift(scf_native_t* ctx, scf_3ac_code_t* c, scf_dag_node_t* dst, if (0 != count->color) { shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_G2E); inst = x64_make_inst_M(&rela, shift, dst->var, NULL); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } else { shift = x64_find_OpCode(OpCode_type, 1, dst->var->size, SCF_X64_I2E); inst = x64_make_inst_I2M(&rela, shift, dst->var, NULL, (uint8_t*)&count->var->data, 1); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dst->var, NULL); } } diff --git a/js/native/x64/scf_x64_inst_unary.c b/js/native/x64/scf_x64_inst_unary.c index 8ee5358..260463e 100644 --- a/js/native/x64/scf_x64_inst_unary.c +++ b/js/native/x64/scf_x64_inst_unary.c @@ -15,7 +15,7 @@ static int _unary_assign_sib(x64_sib_t* sib, int size, scf_3ac_code_t* c, scf_fu inst = x64_make_inst_SIB(OpCode, sib->base, sib->index, sib->scale, sib->disp, size); else inst = x64_make_inst_P(OpCode, sib->base, sib->disp, size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); return 0; } diff --git a/js/native/x64/scf_x64_inst_util.c b/js/native/x64/scf_x64_inst_util.c index 1c3f461..d475604 100644 --- a/js/native/x64/scf_x64_inst_util.c +++ b/js/native/x64/scf_x64_inst_util.c @@ -345,11 +345,11 @@ scf_instruction_t* x64_make_inst_L(scf_rela_t** prela, scf_x64_OpCode_t* OpCode) inst->src.base = NULL; inst->src.disp = 0; - inst->src.flag = 1; + inst->src.mem_flag = 1; inst->dst.base = NULL; inst->dst.disp = 0; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; } else if (SCF_X64_MUL == OpCode->type || SCF_X64_DIV == OpCode->type @@ -359,7 +359,7 @@ scf_instruction_t* x64_make_inst_L(scf_rela_t** prela, scf_x64_OpCode_t* OpCode) inst->src.base = NULL; inst->src.disp = 0; - inst->src.flag = 1; + inst->src.mem_flag = 1; } return inst; @@ -412,11 +412,11 @@ scf_instruction_t* x64_make_inst_M(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, inst->src.base = r_base; inst->src.disp = offset; - inst->src.flag = 1; + inst->src.mem_flag = 1; inst->dst.base = r_base; inst->dst.disp = offset; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; } else if (SCF_X64_MUL == OpCode->type || SCF_X64_DIV == OpCode->type @@ -426,7 +426,7 @@ scf_instruction_t* x64_make_inst_M(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, inst->src.base = r_base; inst->src.disp = offset; - inst->src.flag = 1; + inst->src.mem_flag = 1; } return inst; @@ -462,7 +462,7 @@ scf_instruction_t* x64_make_inst_I2L(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->dst.base = NULL; inst->dst.disp = 0; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; inst->src.imm_size = size; return inst; @@ -525,7 +525,7 @@ scf_instruction_t* x64_make_inst_I2M(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->dst.base = r_base; inst->dst.disp = offset; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; inst->src.imm_size = size; return inst; @@ -550,7 +550,7 @@ scf_instruction_t* x64_make_inst_G2L(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->src.base = r_src; inst->dst.base = NULL; inst->dst.disp = 0; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return inst; } @@ -604,7 +604,7 @@ scf_instruction_t* x64_make_inst_G2M(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->src.base = r_src; inst->dst.base = r_base; inst->dst.disp = offset; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return inst; } @@ -628,7 +628,7 @@ scf_instruction_t* x64_make_inst_L2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->dst.base = r_dst; inst->src.base = NULL; inst->src.disp = 0; - inst->src.flag = 1; + inst->src.mem_flag = 1; return inst; } @@ -681,7 +681,7 @@ scf_instruction_t* x64_make_inst_M2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCod inst->dst.base = r_dst; inst->src.base = r_base; inst->src.disp = offset; - inst->src.flag = 1; + inst->src.mem_flag = 1; return inst; } @@ -716,7 +716,7 @@ scf_instruction_t* x64_make_inst_P2G(scf_x64_OpCode_t* OpCode, scf_register_t* r inst->dst.base = r_dst; inst->src.base = r_base; inst->src.disp = offset; - inst->src.flag = 1; + inst->src.mem_flag = 1; return inst; } @@ -751,7 +751,7 @@ scf_instruction_t* x64_make_inst_G2P(scf_x64_OpCode_t* OpCode, scf_register_t* r inst->src.base = r_src; inst->dst.base = r_base; inst->dst.disp = offset; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return inst; } @@ -795,7 +795,7 @@ scf_instruction_t* x64_make_inst_I2P(scf_x64_OpCode_t* OpCode, scf_register_t* r inst->dst.base = r_base; inst->dst.disp = offset; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return inst; } @@ -939,7 +939,7 @@ scf_instruction_t* x64_make_inst_SIB2G(scf_x64_OpCode_t* OpCode, scf_register_t* inst->src.index = r_index; inst->src.scale = scale; inst->src.disp = disp; - inst->src.flag = 1; + inst->src.mem_flag = 1; return _x64_make_inst_SIB(inst, OpCode, r_dst->id, r_base, r_index, scale, disp, r_dst->bytes); } @@ -961,7 +961,7 @@ scf_instruction_t* x64_make_inst_G2SIB(scf_x64_OpCode_t* OpCode, scf_register_t* inst->dst.index = r_index; inst->dst.scale = scale; inst->dst.disp = disp; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return _x64_make_inst_SIB(inst, OpCode, r_src->id, r_base, r_index, scale, disp, r_src->bytes); } @@ -996,7 +996,7 @@ scf_instruction_t* x64_make_inst_I2SIB(scf_x64_OpCode_t* OpCode, scf_register_t* inst->dst.index = r_index; inst->dst.scale = scale; inst->dst.disp = disp; - inst->dst.flag = 1; + inst->dst.mem_flag = 1; return inst; } diff --git a/js/native/x64/scf_x64_opcode.h b/js/native/x64/scf_x64_opcode.h index 0e45f98..1abe401 100644 --- a/js/native/x64/scf_x64_opcode.h +++ b/js/native/x64/scf_x64_opcode.h @@ -61,57 +61,60 @@ scf_instruction_t* x64_make_inst_I2L(scf_rela_t** prela, scf_x64_OpCode_t* OpCo scf_instruction_t* x64_make_inst_G2L(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, scf_register_t* r_src); scf_instruction_t* x64_make_inst_L2G(scf_rela_t** prela, scf_x64_OpCode_t* OpCode, scf_register_t* r_dst); -#define X64_INST_ADD_CHECK(vec, inst, rela) \ +#define X64_INST_ADD_CHECK(_c, _inst, _rela) \ do { \ - if (!(inst)) { \ + if (!(_inst)) { \ scf_loge("\n"); \ return -ENOMEM; \ } \ - int ret = scf_vector_add((vec), (inst)); \ + int ret = scf_vector_add((_c)->instructions, (_inst)); \ if (ret < 0) { \ - scf_loge("\n"); \ - scf_instruction_free(inst); \ - scf_rela_free(rela); \ + scf_instruction_free(_inst); \ + scf_rela_free(_rela); \ return ret; \ } \ + \ + (_inst)->c = (_c); \ } while (0) -#define X64_RELA_ADD_CHECK(vec, rela, c, v, f) \ +#define X64_RELA_ADD_CHECK(_vec, _rela, _c, _v, _f) \ do { \ - if (rela) { \ - (rela)->code = (c); \ - (rela)->var = (v); \ - (rela)->func = (f); \ - (rela)->inst = (c)->instructions->data[(c)->instructions->size - 1]; \ - (rela)->addend = -4; \ - (rela)->type = R_X86_64_PC32; \ - int ret = scf_vector_add((vec), (rela)); \ + if (_rela) { \ + (_rela)->var = (_v); \ + (_rela)->func = (_f); \ + (_rela)->inst = (_c)->instructions->data[(_c)->instructions->size - 1]; \ + (_rela)->addend = -4; \ + (_rela)->type = R_X86_64_PC32; \ + \ + int ret = scf_vector_add((_vec), (_rela)); \ if (ret < 0) { \ - scf_loge("\n"); \ - scf_rela_free(rela); \ + scf_rela_free(_rela); \ return ret; \ } \ + \ + (_rela)->inst->rel = (_rela); \ } \ } while (0) -#define X64_RELA_ADD_LABEL(vec, rela, _inst, _label) \ +#define X64_RELA_ADD_LABEL(_vec, _rela, _inst, _label) \ do { \ - if (rela) { \ - (rela)->inst = (_inst); \ - (rela)->addend = -4; \ - (rela)->type = R_X86_64_PC32; \ - (rela)->name = scf_string_clone(_label); \ - if (!(rela)->name) { \ - scf_loge("\n"); \ - scf_rela_free(rela); \ + if (_rela) { \ + (_rela)->inst = (_inst); \ + (_rela)->addend = -4; \ + (_rela)->type = R_X86_64_PC32; \ + (_rela)->name = scf_string_clone(_label); \ + if (!(_rela)->name) { \ + scf_rela_free(_rela); \ return -ENOMEM; \ } \ - int ret = scf_vector_add((vec), (rela)); \ + \ + int ret = scf_vector_add((_vec), (_rela)); \ if (ret < 0) { \ - scf_loge("\n"); \ - scf_rela_free(rela); \ + scf_rela_free(_rela); \ return ret; \ } \ + \ + (_rela)->inst->rel = (_rela); \ } \ } while (0) diff --git a/js/native/x64/scf_x64_peephole.c b/js/native/x64/scf_x64_peephole.c index 147a303..cb3d512 100644 --- a/js/native/x64/scf_x64_peephole.c +++ b/js/native/x64/scf_x64_peephole.c @@ -3,6 +3,127 @@ #include"scf_basic_block.h" #include"scf_3ac.h" +static int __x64_peep_mov_by_lea(scf_instruction_t* mov, scf_instruction_t* lea) +{ + scf_instruction_t* inst; + + if (lea->src.index) + inst = x64_make_inst_SIB2G((scf_x64_OpCode_t*)lea->OpCode, + mov->dst.base, + lea->src.base, lea->src.index, lea->src.scale, lea->src.disp); + else + inst = x64_make_inst_P2G((scf_x64_OpCode_t*)lea->OpCode, mov->dst.base, lea->src.base, lea->src.disp); + + if (!inst) + return -ENOMEM; + + memcpy(mov->code, inst->code, inst->len); + mov->len = inst->len; + + mov->OpCode = lea->OpCode; + mov->src.base = lea->src.base; + mov->src.index = lea->src.index; + mov->src.scale = lea->src.scale; + mov->src.disp = lea->src.disp; + mov->src.mem_flag = lea->src.mem_flag; + + free(inst); + return 0; +} + +static int __x64_peep_src_was_mem(scf_instruction_t* inst, scf_inst_data_t* src) +{ + scf_instruction_t* tmp; + scf_x64_OpCode_t* OpCode; + + if (src->base) + tmp = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, src->base); + else { + int bytes = inst->dst.base->bytes; + + if (src->imm_size < bytes) + src->imm = scf_zero_extend(src->imm, src->imm_size); + + OpCode = x64_find_OpCode(inst->OpCode->type, bytes, bytes, SCF_X64_I2G); + if (!OpCode) { + OpCode = x64_find_OpCode(inst->OpCode->type, bytes, bytes, SCF_X64_I2E); + + if (!OpCode) + return -EINVAL; + + tmp = x64_make_inst_I2E(OpCode, inst->dst.base, (uint8_t*)&src->imm, bytes); + } else + tmp = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&src->imm, bytes); + } + if (!tmp) + return -ENOMEM; + + memcpy(inst->code, tmp->code, tmp->len); + inst->len = tmp->len; + + inst->src.base = src->base; + inst->src.index = NULL; + inst->src.scale = 0; + inst->src.disp = 0; + inst->src.mem_flag = 0; + + free(tmp); + return 0; +} + +static int __x64_peep_dst_was_mem(scf_instruction_t* inst, scf_inst_data_t* dst) +{ + scf_instruction_t* tmp; + + if (inst->src.imm_size > 0) + tmp = x64_make_inst_I2E((scf_x64_OpCode_t*)inst->OpCode, dst->base, (uint8_t*)&inst->src.imm, inst->src.imm_size); + else + tmp = x64_make_inst_G2E((scf_x64_OpCode_t*)inst->OpCode, dst->base, inst->src.base); + if (!tmp) + return -ENOMEM; + + memcpy(inst->code, tmp->code, tmp->len); + inst->len = tmp->len; + + inst->dst.base = dst->base; + inst->dst.index = NULL; + inst->dst.scale = 0; + inst->dst.disp = 0; + inst->dst.mem_flag = 0; + + free(tmp); + return 0; +} + +static int __x64_peep_mov_to_mem(scf_instruction_t* mov, scf_inst_data_t* src) +{ + scf_instruction_t* inst; + + if (!mov->dst.index) + inst = x64_make_inst_G2P((scf_x64_OpCode_t*)mov->OpCode, + mov->dst.base, mov->dst.disp, + src->base); + else + inst = x64_make_inst_G2SIB((scf_x64_OpCode_t*)mov->OpCode, + mov->dst.base, + mov->dst.index, mov->dst.scale, mov->dst.disp, + src->base); + if (!inst) + return -ENOMEM; + + memcpy(mov->code, inst->code, inst->len); + mov->len = inst->len; + + mov->src.base = src->base; + mov->src.index = NULL; + mov->src.scale = 0; + mov->src.disp = 0; + mov->src.mem_flag = 0; + + free(inst); + return 0; +} + static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, scf_instruction_t* inst) { scf_3ac_code_t* c = inst->c; @@ -17,43 +138,14 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, int j; for (j = peep_insts->size - 1; j >= 0; j--) { std = peep_insts->data[j]; -#if 0 - scf_loge("std j: %d\n", j); - scf_3ac_code_print(std->c, NULL); - scf_instruction_print(std); - - scf_loge("inst: \n"); - scf_instruction_print(inst); - printf("\n"); -#endif + if (SCF_X64_LEA == std->OpCode->type) { if (scf_inst_data_same(&std->dst, &inst->src) && x64_inst_data_is_reg(&inst->dst) && x64_inst_data_is_local(&std->src)) { - if (std->src.index) - inst2 = x64_make_inst_SIB2G((scf_x64_OpCode_t*)std->OpCode, - inst->dst.base, - std->src.base, std->src.index, std->src.scale, std->src.disp); - else - inst2 = x64_make_inst_P2G((scf_x64_OpCode_t*)std->OpCode, inst->dst.base, std->src.base, std->src.disp); - - if (!inst2) - return -ENOMEM; - - memcpy(inst->code, inst2->code, inst2->len); - inst->len = inst2->len; - - inst->OpCode = std->OpCode; - inst->src.base = std->src.base; - inst->src.index = std->src.index; - inst->src.scale = std->src.scale; - inst->src.disp = std->src.disp; - inst->src.flag = std->src.flag; - - free(inst2); - inst2 = NULL; + __x64_peep_mov_by_lea(inst, std); } break; } @@ -83,23 +175,9 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, } else if (scf_inst_data_same(&std->src, &inst->src)) { - if (std->src.flag && std->dst.base->bytes == inst->dst.base->bytes) { - - inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->dst.base); - if (!inst2) - return -ENOMEM; - - memcpy(inst->code, inst2->code, inst2->len); - inst->len = inst2->len; + if (std->src.mem_flag && std->dst.base->bytes == inst->dst.base->bytes) { - inst->src.base = std->dst.base; - inst->src.index = NULL; - inst->src.scale = 0; - inst->src.disp = 0; - inst->src.flag = 0; - - free(inst2); - inst2 = NULL; + __x64_peep_src_was_mem(inst, &std->dst); } continue; @@ -115,64 +193,18 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, return X64_PEEPHOLE_DEL; } - if (inst->src.flag) { - assert(std->dst.flag); - - if (std->src.base) - inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*)inst->OpCode, inst->dst.base, std->src.base); - else { - OpCode = x64_find_OpCode(inst->OpCode->type, inst->dst.base->bytes, inst->dst.base->bytes, SCF_X64_I2G); - - if (std->src.imm_size < inst->dst.base->bytes) - std->src.imm = scf_zero_extend(std->src.imm, std->src.imm_size); - - inst2 = x64_make_inst_I2G(OpCode, inst->dst.base, (uint8_t*)&std->src.imm, inst->dst.base->bytes); - } - if (!inst2) - return -ENOMEM; + if (inst->src.mem_flag) { + assert(std->dst.mem_flag); - memcpy(inst->code, inst2->code, inst2->len); - inst->len = inst2->len; - - inst->src.base = std->src.base; - inst->src.index = NULL; - inst->src.scale = 0; - inst->src.disp = 0; - inst->src.flag = 0; - - free(inst2); - inst2 = NULL; + __x64_peep_src_was_mem(inst, &std->src); continue; - } else if (inst->dst.flag) { - + } else if (inst->dst.mem_flag) { if (x64_inst_data_is_reg(&inst->src) && x64_inst_data_is_reg(&std->src) && inst->src.base != std->src.base) { - if (!inst->dst.index) - inst2 = x64_make_inst_G2P((scf_x64_OpCode_t*)inst->OpCode, - inst->dst.base, inst->dst.disp, - std->src.base); - else - inst2 = x64_make_inst_G2SIB((scf_x64_OpCode_t*)inst->OpCode, - inst->dst.base, - inst->dst.index, inst->dst.scale, inst->dst.disp, - std->src.base); - if (!inst2) - return -ENOMEM; - - memcpy(inst->code, inst2->code, inst2->len); - inst->len = inst2->len; - - inst->src.base = std->src.base; - inst->src.index = NULL; - inst->src.scale = 0; - inst->src.disp = 0; - inst->src.flag = 0; - - free(inst2); - inst2 = NULL; + __x64_peep_mov_to_mem(inst, &std->src); continue; } } @@ -206,8 +238,8 @@ static int _x64_peephole_mov(scf_vector_t* save_insts, scf_vector_t* peep_insts, for (j = peep_insts->size - 1; j >= 0; j--) { std = peep_insts->data[j]; - if ((std->src.flag && (std->src.base == r1 || std->src.index == r1)) - || (std->dst.flag && (std->dst.base == r1 || std->dst.index == r1))) + if ((std->src.mem_flag && (std->src.base == r1 || std->src.index == r1)) + || (std->dst.mem_flag && (std->dst.base == r1 || std->dst.index == r1))) assert(0 == scf_vector_del(peep_insts, std)); } } @@ -220,67 +252,43 @@ static int _x64_peephole_cmp(scf_vector_t* save_insts, scf_vector_t* peep_insts, { scf_3ac_code_t* c = inst->c; scf_basic_block_t* bb = c->basic_block; - scf_instruction_t* inst2; scf_instruction_t* std; - + scf_inst_data_t* id; int j; + for (j = peep_insts->size - 1; j >= 0; j--) { std = peep_insts->data[j]; if (SCF_X64_LEA == std->OpCode->type) break; - if (inst->src.flag) { + int ret = 0; + if (inst->src.mem_flag) { if (scf_inst_data_same(&inst->src, &std->src)) - inst->src.base = std->dst.base; + id = &std->dst; else if (scf_inst_data_same(&inst->src, &std->dst)) - inst->src.base = std->src.base; + id = &std->src; else goto check; - inst2 = x64_make_inst_E2G((scf_x64_OpCode_t*) inst->OpCode, inst->dst.base, inst->src.base); - if (!inst2) - return -ENOMEM; - - inst->src.index = NULL; - inst->src.scale = 0; - inst->src.disp = 0; - inst->src.flag = 0; + ret = __x64_peep_src_was_mem(inst, id); - } else if (inst->dst.flag) { + } else if (inst->dst.mem_flag) { if (scf_inst_data_same(&inst->dst, &std->src)) - inst->dst.base = std->dst.base; + id = &std->dst; else if (scf_inst_data_same(&inst->dst, &std->dst)) - inst->dst.base = std->src.base; + id = &std->src; else goto check; - if (inst->src.imm_size > 0) - inst2 = x64_make_inst_I2E((scf_x64_OpCode_t*)inst->OpCode, - inst->dst.base, - (uint8_t*)&inst->src.imm, inst->src.imm_size); - else - inst2 = x64_make_inst_G2E((scf_x64_OpCode_t*)inst->OpCode, - inst->dst.base, - inst->src.base); - if (!inst2) - return -ENOMEM; - - inst->dst.index = NULL; - inst->dst.scale = 0; - inst->dst.disp = 0; - inst->dst.flag = 0; - } else - goto check; - - memcpy(inst->code, inst2->code, inst2->len); - inst->len = inst2->len; + ret = __x64_peep_dst_was_mem(inst, id); + } - free(inst2); - inst2 = NULL; + if (ret < 0) + return ret; check: if (x64_inst_data_is_reg(&std->dst)) { @@ -479,7 +487,7 @@ static int _x64_peephole_function(scf_vector_t* save_insts, scf_function_t* f) continue; assert(0 == scf_vector_del(c->instructions, inst)); - assert(0 == scf_vector_del(save_insts, inst)); + assert(0 == scf_vector_del(save_insts, inst)); free(inst); inst = NULL; diff --git a/js/native/x64/scf_x64_reg.c b/js/native/x64/scf_x64_reg.c index 9374eed..38505ce 100644 --- a/js/native/x64/scf_x64_reg.c +++ b/js/native/x64/scf_x64_reg.c @@ -165,7 +165,7 @@ int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int inst = x64_make_inst_G2P(movsd, rsp, size + stack_size, r2); else { inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&imm, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(movsd, rsp, 0, r2); } @@ -175,7 +175,7 @@ int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int else inst = x64_make_inst_G(push, r2); } - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); saved_regs[n++] = r2; size += 8; @@ -189,7 +189,7 @@ int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int inst = x64_make_inst_G2P(movsd, rsp, size + stack_size, r2); else { inst = x64_make_inst_I2E(sub, rsp, (uint8_t*)&imm, 4); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2P(movsd, rsp, 0, r2); } @@ -199,7 +199,7 @@ int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int else inst = x64_make_inst_G(push, r2); } - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); saved_regs[n++] = r2; size += 8; @@ -216,7 +216,7 @@ int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int return size; } -int x64_pop_regs(scf_vector_t* instructions, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated) +int x64_pop_regs(scf_3ac_code_t* c, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated) { scf_register_t* rsp = x64_find_register("rsp"); scf_register_t* r; @@ -260,15 +260,15 @@ int x64_pop_regs(scf_vector_t* instructions, scf_register_t** regs, int nb_regs, if (i == nb_updated) { if (X64_COLOR_TYPE(r2->color)) { inst = x64_make_inst_P2G(movsd, r2, rsp, 0); - X64_INST_ADD_CHECK(instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&imm, 4); } else inst = x64_make_inst_G(pop, r2); - X64_INST_ADD_CHECK(instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { inst = x64_make_inst_I2E(add, rsp, (uint8_t*)&imm, 4); - X64_INST_ADD_CHECK(instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } return 0; @@ -414,7 +414,7 @@ int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_ } inst = x64_make_inst_G2M(&rela, mov, v, NULL, r); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); end: @@ -718,7 +718,7 @@ int x64_load_const(scf_register_t* r, scf_dag_node_t* dn, scf_3ac_code_t* c, scf lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, lea, r, NULL, v); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } else if (v->nb_dimentions > 0) { @@ -727,7 +727,7 @@ int x64_load_const(scf_register_t* r, scf_dag_node_t* dn, scf_3ac_code_t* c, scf lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, lea, r, NULL, v); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, v, NULL); } else if (SCF_FUNCTION_PTR == v->type) { @@ -740,17 +740,17 @@ int x64_load_const(scf_register_t* r, scf_dag_node_t* dn, scf_3ac_code_t* c, scf lea = x64_find_OpCode(SCF_X64_LEA, size, size, SCF_X64_E2G); inst = x64_make_inst_M2G(&rela, lea, r, NULL, v); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->text_relas, rela, c, NULL, v->func_ptr); } else { xor = x64_find_OpCode(SCF_X64_XOR, size, size, SCF_X64_G2E); inst = x64_make_inst_G2E(xor, r, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } } else { mov = x64_find_OpCode(SCF_X64_MOV, size, size, SCF_X64_I2G); inst = x64_make_inst_I2G(mov, r, (uint8_t*)&v->data, size); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } return 0; @@ -826,7 +826,7 @@ int x64_load_reg(scf_register_t* r, scf_dag_node_t* dn, scf_3ac_code_t* c, scf_f } inst = x64_make_inst_M2G(&rela, mov, r, NULL, dn->var); - X64_INST_ADD_CHECK(c->instructions, inst, rela); + X64_INST_ADD_CHECK(c, inst, rela); X64_RELA_ADD_CHECK(f->data_relas, rela, c, dn->var, NULL); dn->loaded = 1; @@ -1056,19 +1056,19 @@ int x64_array_index_reg(x64_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* in if (scf_variable_signed(index->var)) { mov = x64_find_OpCode(SCF_X64_MOVSX, ri->bytes, ri2->bytes, SCF_X64_E2G); inst = x64_make_inst_E2G(mov, ri2, ri); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else if (ri->bytes <= 2) { mov = x64_find_OpCode(SCF_X64_MOVZX, ri->bytes, ri2->bytes, SCF_X64_E2G); inst = x64_make_inst_E2G(mov, ri2, ri); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } else { assert(4 == ri->bytes); /* xor = x64_find_OpCode(SCF_X64_XOR, 8, 8, SCF_X64_G2E); inst = x64_make_inst_G2E(xor, ri2, ri2); - X64_INST_ADD_CHECK(c->instructions, inst); + X64_INST_ADD_CHECK(c, inst); mov = x64_find_OpCode(SCF_X64_MOV, 4, 4, SCF_X64_E2G); */ } @@ -1093,7 +1093,7 @@ int x64_array_index_reg(x64_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* in mov = x64_find_OpCode(SCF_X64_MOV, 8, 8, SCF_X64_G2E); inst = x64_make_inst_G2E(mov, rs, ri2); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); shl = x64_find_OpCode(SCF_X64_SHL, 1, 8, SCF_X64_I2E); add = x64_find_OpCode(SCF_X64_ADD, 8, 8, SCF_X64_G2E); @@ -1116,17 +1116,17 @@ int x64_array_index_reg(x64_sib_t* sib, scf_dag_node_t* base, scf_dag_node_t* in count -= i; inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&count, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); inst = x64_make_inst_G2E(add, rs, ri2); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); count = i; } if (count > 0) { inst = x64_make_inst_I2E(shl, rs, (uint8_t*)&count, 1); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); } ri = rs; @@ -1242,7 +1242,7 @@ int x64_push_callee_regs(scf_3ac_code_t* c, scf_function_t* f) if (j < N) { inst = x64_make_inst_G(push, r); - X64_INST_ADD_CHECK(f->init_code->instructions, inst, NULL); + X64_INST_ADD_CHECK(f->init_code, inst, NULL); f->init_code_bytes += inst->len; } @@ -1278,7 +1278,7 @@ int x64_pop_callee_regs(scf_3ac_code_t* c, scf_function_t* f) if (j < N) { inst = x64_make_inst_G(pop, r); - X64_INST_ADD_CHECK(c->instructions, inst, NULL); + X64_INST_ADD_CHECK(c, inst, NULL); bb->code_bytes += inst->len; f->callee_saved_size += 8; diff --git a/js/native/x64/scf_x64_reg.h b/js/native/x64/scf_x64_reg.h index 9be5f65..23bf2d1 100644 --- a/js/native/x64/scf_x64_reg.h +++ b/js/native/x64/scf_x64_reg.h @@ -109,8 +109,7 @@ int x64_save_var(scf_dag_node_t* dn, scf_3ac_code_t* c, scf_func int x64_save_var2(scf_dag_node_t* dn, scf_register_t* r, scf_3ac_code_t* c, scf_function_t* f); -int x64_push_regs(scf_vector_t* instructions, uint32_t* regs, int nb_regs); -int x64_pop_regs (scf_vector_t* instructions, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated); +int x64_pop_regs(scf_3ac_code_t* c, scf_register_t** regs, int nb_regs, scf_register_t** updated_regs, int nb_updated); int x64_caller_save_regs(scf_3ac_code_t* c, const char* regs[], int nb_regs, int stack_size, scf_register_t** saved_regs, scf_register_t** drop_regs, int* n_drops); diff --git a/js/native/x64/scf_x64_reg_util.h b/js/native/x64/scf_x64_reg_util.h index 1f23aaf..c05dd14 100644 --- a/js/native/x64/scf_x64_reg_util.h +++ b/js/native/x64/scf_x64_reg_util.h @@ -43,7 +43,7 @@ static inline int x64_inst_data_is_reg(scf_inst_data_t* id) scf_register_t* rsp = x64_find_register("rsp"); scf_register_t* rbp = x64_find_register("rbp"); - if (!id->flag && id->base && id->base != rsp && id->base != rbp && 0 == id->imm_size) + if (!id->mem_flag && id->base && id->base != rsp && id->base != rbp && 0 == id->imm_size) return 1; return 0; } @@ -53,21 +53,21 @@ static inline int x64_inst_data_is_local(scf_inst_data_t* id) scf_register_t* rbp = x64_find_register("rbp"); scf_register_t* rsp = x64_find_register("rsp"); - if (id->flag && (id->base == rbp || id->base == rsp)) + if (id->mem_flag && (id->base == rbp || id->base == rsp)) return 1; return 0; } static inline int x64_inst_data_is_global(scf_inst_data_t* id) { - if (id->flag && !id->base) + if (id->mem_flag && !id->base) return 1; return 0; } static inline int x64_inst_data_is_const(scf_inst_data_t* id) { - if (!id->flag && id->imm_size > 0) + if (!id->mem_flag && id->imm_size > 0) return 1; return 0; } @@ -77,7 +77,7 @@ static inline int x64_inst_data_is_pointer(scf_inst_data_t* id) scf_register_t* rbp = x64_find_register("rbp"); scf_register_t* rsp = x64_find_register("rsp"); - if (id->flag && id->base && id->base != rbp && id->base != rsp) + if (id->mem_flag && id->base && id->base != rbp && id->base != rsp) return 1; return 0; } diff --git a/js/util/scf_string.c b/js/util/scf_string.c index 83c8197..a1afd01 100644 --- a/js/util/scf_string.c +++ b/js/util/scf_string.c @@ -397,6 +397,40 @@ int scf_utf8_len(const uint8_t* str, size_t* len) return c; } +int scf_file_path(uint8_t** path, const scf_string_t* base, const scf_string_t* file) +{ + if ('/' == file->data[0] || '~' == file->data[0]) + return 0; + + int i; + int j; + for (i = base->len - 1; i >= 0; i--) { + if ('/' == base->data[i]) + break; + } + + if (i < 0) + return 0; + + for (j = file->len - 1; j >= 0; j--) { + if ('/' == file->data[j]) + break; + } + + if (j == i && (j <= 0 || !strncmp(base->data, file->data, j))) + return 0; + + uint8_t* p = malloc(i + 1 + file->len + 1); + if (!p) + return -ENOMEM; + + memcpy(p, base->data, i + 1); + memcpy(p + i + 1, file->data, file->len + 1); + + *path = p; + return 0; +} + #if 0 int main(int argc, char* argv[]) { diff --git a/js/util/scf_string.h b/js/util/scf_string.h index 16b07a8..dcf1af4 100644 --- a/js/util/scf_string.h +++ b/js/util/scf_string.h @@ -46,4 +46,6 @@ int scf_string_match_kmp_cstr_len(const scf_string_t* T, const uint8 int scf_string_get_offset(scf_string_t* str, const char* data, size_t len); int scf_utf8_len(const uint8_t* str, size_t* len); + +int scf_file_path(uint8_t** path, const scf_string_t* base, const scf_string_t* file); #endif diff --git a/ui/Makefile b/ui/Makefile index a56faec..6d63133 100644 --- a/ui/Makefile +++ b/ui/Makefile @@ -73,6 +73,7 @@ CFILES += ../js/util/scf_rbtree.c CFILES += ../js/util/scf_graph.c CFILES += ../js/lex/scf_lex.c CFILES += ../js/lex/scf_lex_util.c +CFILES += ../js/lex/scf_macro.c CFILES += ../js/parse/main.c CFILES += ../js/parse/scf_parse_util.c -- 2.25.1