From 54fd3aee3a623802c6d7b9b030e4b1186e285b56 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Wed, 6 Dec 2017 22:38:22 +0700 Subject: [PATCH] emit/__emit: Add fallbacks for the other macro opcodes --- source/compiler/sc1.c | 116 +++++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 19 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 8f2fe41..2bd62f4 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -6259,8 +6259,8 @@ static void SC_FASTCALL emit_do_sysreq_c(char *name) emit_param_function(&p[0],TRUE); - /* if macro instructions aren't enabled, output a 'sysreq.c' instruction, - * otherwise generate the following sequence for compatibility: + /* if macro optimisations aren't enabled, output a 'sysreq.c' instruction, + * otherwise generate the following sequence: * const.pri * sysreq.pri */ @@ -6279,8 +6279,8 @@ static void SC_FASTCALL emit_do_sysreq_n(char *name) emit_param_function(&p[0],TRUE); emit_param_any(&p[1]); - /* if macro instructions are enabled, output a 'sysreq.n' instruction, - * otherwise generate the following sequence for compatibility: + /* if macro optimisations are enabled, output a 'sysreq.n' instruction, + * otherwise generate the following sequence: * push * sysreq.c * stack + @@ -6301,7 +6301,22 @@ static void SC_FASTCALL emit_do_const(char *name) emit_param_data(&p[0]); emit_param_any(&p[1]); - outinstr(name,p,(sizeof p / sizeof p[0])); + + /* if macro optimisations are enabled, output a 'const' instruction, + * otherwise generate the following sequence: + * push.pri + * const.pri + * stor.pri + * pop.pri + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,2); + } else { + outinstr("push.pri",NULL,0); + outinstr("const.pri",&p[1],1); + outinstr("stor.pri",&p[0],1); + outinstr("pop.pri",NULL,0); + } /* if */ } static void SC_FASTCALL emit_do_const_s(char *name) @@ -6310,27 +6325,62 @@ static void SC_FASTCALL emit_do_const_s(char *name) emit_param_local(&p[0]); emit_param_any(&p[1]); - outinstr(name,p,(sizeof p / sizeof p[0])); + + /* if macro optimisations are enabled, output a 'const.s' instruction, + * otherwise generate the following sequence: + * push.pri + * const.pri + * stor.s.pri + * pop.pri + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,2); + } else { + outinstr("push.pri",NULL,0); + outinstr("const.pri",&p[1],1); + outinstr("stor.s.pri",&p[0],1); + outinstr("pop.pri",NULL,0); + } /* if */ } static void SC_FASTCALL emit_do_load_both(char *name) { ucell p[2]; - int i; - for (i=0; i<(sizeof p / sizeof p[0]); i++) - emit_param_data(&p[i]); - outinstr(name,p,(sizeof p / sizeof p[0])); + emit_param_data(&p[0]); + emit_param_data(&p[1]); + + /* if macro optimisations are enabled, output a 'load.both' instruction, + * otherwise generate the following sequence: + * load.pri + * load.alt + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,2); + } else { + outinstr("load.pri",&p[0],1); + outinstr("load.alt",&p[1],1); + } /* if */ } static void SC_FASTCALL emit_do_load_s_both(char *name) { ucell p[2]; - int i; - for (i=0; i<(sizeof p / sizeof p[0]); i++) - emit_param_local(&p[i]); - outinstr(name,p,(sizeof p / sizeof p[0])); + emit_param_local(&p[0]); + emit_param_local(&p[1]); + + /* if macro optimisations are enabled, output a 'load.s.both' instruction, + * otherwise generate the following sequence: + * load.s.pri + * load.s.alt + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,2); + } else { + outinstr("load.s.pri",&p[0],1); + outinstr("load.s.alt",&p[1],1); + } /* if */ } static void SC_FASTCALL emit_do_pushn_c(char *name) @@ -6343,7 +6393,16 @@ static void SC_FASTCALL emit_do_pushn_c(char *name) numargs=name[4]-'0'; for (i=0; i.c' instruction, + * otherwise generate a sequence of 'push.c' instructions + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,numargs); + } else { + for (i=0; i' instruction, + * otherwise generate a sequence of 'push' instructions + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,numargs); + } else { + for (i=0; i.s/.adr' instruction, + * otherwise generate a sequence of 'push.s/.adr' instructions + */ + if (pc_optimize>sOPTIMIZE_NOMACRO) { + outinstr(name,p,numargs); + } else { + name=(name[6]=='s') ? "push.s" : "push.adr"; + for (i=0; i