__emit: Code cleanup
This commit is contained in:
parent
3c1ac1e911
commit
32528e701a
@ -920,9 +920,9 @@ SC_VDECL FILE *outf; /* file written to */
|
||||
SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */
|
||||
|
||||
/* Possible entries for "emit_flags"
|
||||
* Bits: 0 (epmBLOCK) multiline ('{}' block) syntax
|
||||
* 1 (epmEXPR) used within an expression
|
||||
* 2 (epmGLOBAL) used outside of a function
|
||||
* Bits: 0 (efBLOCK) multiline ('()' block) syntax
|
||||
* 1 (efEXPR) used within an expression
|
||||
* 2 (efGLOBAL) used outside of a function
|
||||
*/
|
||||
#define efBLOCK 1
|
||||
#define efEXPR 2
|
||||
|
@ -141,7 +141,6 @@ static int *readwhile(void);
|
||||
|
||||
typedef void (SC_FASTCALL *OPCODE_PROC)(char *name);
|
||||
typedef struct {
|
||||
cell opcode;
|
||||
char *name;
|
||||
OPCODE_PROC func;
|
||||
} EMIT_OPCODE;
|
||||
@ -6036,8 +6035,8 @@ static symbol *fetchlab(char *name)
|
||||
|
||||
static void SC_FASTCALL emit_invalid_token(int expected_token,int found_token)
|
||||
{
|
||||
char s[2];
|
||||
extern char *sc_tokens[];
|
||||
char s[2];
|
||||
|
||||
assert(expected_token>=tFIRST);
|
||||
if (found_token<tFIRST) {
|
||||
@ -6197,20 +6196,25 @@ static void SC_FASTCALL emit_param_nonneg(emit_outval *p)
|
||||
extern char *sc_tokens[];
|
||||
#if PAWN_CELL_SIZE==16
|
||||
char ival[7];
|
||||
sprintf(ival,"%ld",(long)p->value.ucell);
|
||||
#elif PAWN_CELL_SIZE==32
|
||||
char ival[12];
|
||||
sprintf(ival,"%ld",(long)p->value.ucell);
|
||||
#elif PAWN_CELL_SIZE==64
|
||||
char ival[21];
|
||||
sprintf(ival,"%lld",(long long)p->value.ucell);
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#endif
|
||||
sprintf(ival,"%"PRIdC,(cell)p->value.ucell);
|
||||
error(1,sc_tokens[teNONNEG-tFIRST],ival);
|
||||
} /* if */
|
||||
}
|
||||
|
||||
static void SC_FASTCALL emit_param_shift(emit_outval *p)
|
||||
{
|
||||
if (emit_param_any_internal(p,tNUMBER,FALSE,TRUE))
|
||||
if (p->value.ucell>=(sizeof(cell)*8))
|
||||
error(50); /* invalid range */
|
||||
}
|
||||
|
||||
static void SC_FASTCALL emit_param_data(emit_outval *p)
|
||||
{
|
||||
cell val;
|
||||
@ -6445,9 +6449,7 @@ static void SC_FASTCALL emit_parm1_shift(char *name)
|
||||
{
|
||||
emit_outval p[1];
|
||||
|
||||
if (emit_param_any_internal(&p[0],tNUMBER,FALSE,TRUE))
|
||||
if (p->value.ucell>=(sizeof(cell)*8))
|
||||
error(50); /* invalid range */
|
||||
emit_param_shift(&p[0]);
|
||||
outinstr(name,p,(sizeof p / sizeof p[0]));
|
||||
}
|
||||
|
||||
@ -6720,160 +6722,160 @@ static void SC_FASTCALL emit_do_pushn_s_adr(char *name)
|
||||
}
|
||||
|
||||
static EMIT_OPCODE emit_opcodelist[] = {
|
||||
{ 0, NULL, emit_noop },
|
||||
{ 78, "add", emit_parm0 },
|
||||
{ 87, "add.c", emit_parm1_any },
|
||||
{ 14, "addr.alt", emit_parm1_local },
|
||||
{ 13, "addr.pri", emit_parm1_local },
|
||||
{ 30, "align.alt", emit_do_align },
|
||||
{ 29, "align.pri", emit_do_align },
|
||||
{ 81, "and", emit_parm0 },
|
||||
{121, "bounds", emit_parm1_integer },
|
||||
{137, "break", emit_parm0 },
|
||||
{ 49, "call", emit_do_call },
|
||||
{ 50, "call.pri", emit_parm0 },
|
||||
{ 0, "case", emit_do_case },
|
||||
{130, "casetbl", emit_do_casetbl },
|
||||
{118, "cmps", emit_parm1_nonneg },
|
||||
{156, "const", emit_do_const },
|
||||
{ 12, "const.alt", emit_parm1_any },
|
||||
{ 11, "const.pri", emit_parm1_any },
|
||||
{157, "const.s", emit_do_const_s },
|
||||
{114, "dec", emit_parm1_data },
|
||||
{113, "dec.alt", emit_parm0 },
|
||||
{116, "dec.i", emit_parm0 },
|
||||
{112, "dec.pri", emit_parm0 },
|
||||
{115, "dec.s", emit_parm1_local },
|
||||
{ 95, "eq", emit_parm0 },
|
||||
{106, "eq.c.alt", emit_parm1_any },
|
||||
{105, "eq.c.pri", emit_parm1_any },
|
||||
{119, "fill", emit_parm1_nonneg },
|
||||
{100, "geq", emit_parm0 },
|
||||
{ 99, "grtr", emit_parm0 },
|
||||
{120, "halt", emit_parm1_nonneg },
|
||||
{ 45, "heap", emit_parm1_integer },
|
||||
{ 27, "idxaddr", emit_parm0 },
|
||||
{ 28, "idxaddr.b", emit_parm1_shift },
|
||||
{109, "inc", emit_parm1_data },
|
||||
{108, "inc.alt", emit_parm0 },
|
||||
{111, "inc.i", emit_parm0 },
|
||||
{107, "inc.pri", emit_parm0 },
|
||||
{110, "inc.s", emit_parm1_local },
|
||||
{ 86, "invert", emit_parm0 },
|
||||
{ 55, "jeq", emit_parm1_label },
|
||||
{ 60, "jgeq", emit_parm1_label },
|
||||
{ 59, "jgrtr", emit_parm1_label },
|
||||
{ 58, "jleq", emit_parm1_label },
|
||||
{ 57, "jless", emit_parm1_label },
|
||||
{ 56, "jneq", emit_parm1_label },
|
||||
{ 54, "jnz", emit_parm1_label },
|
||||
{ 52, "jrel", emit_parm1_integer },
|
||||
{ 64, "jsgeq", emit_parm1_label },
|
||||
{ 63, "jsgrtr", emit_parm1_label },
|
||||
{ 62, "jsleq", emit_parm1_label },
|
||||
{ 61, "jsless", emit_parm1_label },
|
||||
{ 51, "jump", emit_parm1_label },
|
||||
{128, "jump.pri", emit_parm0 },
|
||||
{ 53, "jzer", emit_parm1_label },
|
||||
{ 31, "lctrl", emit_parm1_integer },
|
||||
{ 98, "leq", emit_parm0 },
|
||||
{ 97, "less", emit_parm0 },
|
||||
{ 25, "lidx", emit_parm0 },
|
||||
{ 26, "lidx.b", emit_parm1_shift },
|
||||
{ 2, "load.alt", emit_parm1_data },
|
||||
{154, "load.both", emit_do_load_both },
|
||||
{ 9, "load.i", emit_parm0 },
|
||||
{ 1, "load.pri", emit_parm1_data },
|
||||
{ 4, "load.s.alt", emit_parm1_local },
|
||||
{155, "load.s.both",emit_do_load_s_both },
|
||||
{ 3, "load.s.pri", emit_parm1_local },
|
||||
{ 10, "lodb.i", emit_do_lodb_strb },
|
||||
{ 6, "lref.alt", emit_parm1_data },
|
||||
{ 5, "lref.pri", emit_parm1_data },
|
||||
{ 8, "lref.s.alt", emit_parm1_local },
|
||||
{ 7, "lref.s.pri", emit_parm1_local },
|
||||
{ 34, "move.alt", emit_parm0 },
|
||||
{ 33, "move.pri", emit_parm0 },
|
||||
{117, "movs", emit_parm1_nonneg },
|
||||
{ 85, "neg", emit_parm0 },
|
||||
{ 96, "neq", emit_parm0 },
|
||||
{134, "nop", emit_parm0 },
|
||||
{ 84, "not", emit_parm0 },
|
||||
{ 82, "or", emit_parm0 },
|
||||
{ 43, "pop.alt", emit_parm0 },
|
||||
{ 42, "pop.pri", emit_parm0 },
|
||||
{ 46, "proc", emit_parm0 },
|
||||
{ 40, "push", emit_parm1_data },
|
||||
{133, "push.adr", emit_parm1_local },
|
||||
{ 37, "push.alt", emit_parm0 },
|
||||
{ 39, "push.c", emit_parm1_any },
|
||||
{ 36, "push.pri", emit_parm0 },
|
||||
{ 38, "push.r", emit_parm1_integer },
|
||||
{ 41, "push.s", emit_parm1_local },
|
||||
{139, "push2", emit_do_pushn },
|
||||
{141, "push2.adr", emit_do_pushn_s_adr },
|
||||
{138, "push2.c", emit_do_pushn_c },
|
||||
{140, "push2.s", emit_do_pushn_s_adr },
|
||||
{143, "push3", emit_do_pushn },
|
||||
{145, "push3.adr", emit_do_pushn_s_adr },
|
||||
{142, "push3.c", emit_do_pushn_c },
|
||||
{144, "push3.s", emit_do_pushn_s_adr },
|
||||
{147, "push4", emit_do_pushn },
|
||||
{149, "push4.adr", emit_do_pushn_s_adr },
|
||||
{146, "push4.c", emit_do_pushn_c },
|
||||
{148, "push4.s", emit_do_pushn_s_adr },
|
||||
{151, "push5", emit_do_pushn },
|
||||
{153, "push5.adr", emit_do_pushn_s_adr },
|
||||
{150, "push5.c", emit_do_pushn_c },
|
||||
{152, "push5.s", emit_do_pushn_s_adr },
|
||||
{ 47, "ret", emit_parm0 },
|
||||
{ 48, "retn", emit_parm0 },
|
||||
{ 32, "sctrl", emit_parm1_integer },
|
||||
{ 73, "sdiv", emit_parm0 },
|
||||
{ 74, "sdiv.alt", emit_parm0 },
|
||||
{104, "sgeq", emit_parm0 },
|
||||
{103, "sgrtr", emit_parm0 },
|
||||
{ 65, "shl", emit_parm0 },
|
||||
{ 69, "shl.c.alt", emit_parm1_shift },
|
||||
{ 68, "shl.c.pri", emit_parm1_shift },
|
||||
{ 66, "shr", emit_parm0 },
|
||||
{ 71, "shr.c.alt", emit_parm1_shift },
|
||||
{ 70, "shr.c.pri", emit_parm1_shift },
|
||||
{ 94, "sign.alt", emit_parm0 },
|
||||
{ 93, "sign.pri", emit_parm0 },
|
||||
{102, "sleq", emit_parm0 },
|
||||
{101, "sless", emit_parm0 },
|
||||
{ 72, "smul", emit_parm0 },
|
||||
{ 88, "smul.c", emit_parm1_integer },
|
||||
{ 20, "sref.alt", emit_parm1_data },
|
||||
{ 19, "sref.pri", emit_parm1_data },
|
||||
{ 22, "sref.s.alt", emit_parm1_local },
|
||||
{ 21, "sref.s.pri", emit_parm1_local },
|
||||
{ 67, "sshr", emit_parm0 },
|
||||
{ 44, "stack", emit_parm1_integer },
|
||||
{ 16, "stor.alt", emit_parm1_data },
|
||||
{ 23, "stor.i", emit_parm0 },
|
||||
{ 15, "stor.pri", emit_parm1_data },
|
||||
{ 18, "stor.s.alt", emit_parm1_local },
|
||||
{ 17, "stor.s.pri", emit_parm1_local },
|
||||
{ 24, "strb.i", emit_do_lodb_strb },
|
||||
{ 79, "sub", emit_parm0 },
|
||||
{ 80, "sub.alt", emit_parm0 },
|
||||
{132, "swap.alt", emit_parm0 },
|
||||
{131, "swap.pri", emit_parm0 },
|
||||
{129, "switch", emit_parm1_label },
|
||||
{123, "sysreq.c", emit_do_sysreq_c },
|
||||
{135, "sysreq.n", emit_do_sysreq_n },
|
||||
{122, "sysreq.pri", emit_parm0 },
|
||||
{ 76, "udiv", emit_parm0 },
|
||||
{ 77, "udiv.alt", emit_parm0 },
|
||||
{ 75, "umul", emit_parm0 },
|
||||
{ 35, "xchg", emit_parm0 },
|
||||
{ 83, "xor", emit_parm0 },
|
||||
{ 91, "zero", emit_parm1_data },
|
||||
{ 90, "zero.alt", emit_parm0 },
|
||||
{ 89, "zero.pri", emit_parm0 },
|
||||
{ 92, "zero.s", emit_parm1_local },
|
||||
{ NULL, emit_noop },
|
||||
{ "add", emit_parm0 },
|
||||
{ "add.c", emit_parm1_any },
|
||||
{ "addr.alt", emit_parm1_local },
|
||||
{ "addr.pri", emit_parm1_local },
|
||||
{ "align.alt", emit_do_align },
|
||||
{ "align.pri", emit_do_align },
|
||||
{ "and", emit_parm0 },
|
||||
{ "bounds", emit_parm1_integer },
|
||||
{ "break", emit_parm0 },
|
||||
{ "call", emit_do_call },
|
||||
{ "call.pri", emit_parm0 },
|
||||
{ "case", emit_do_case },
|
||||
{ "casetbl", emit_do_casetbl },
|
||||
{ "cmps", emit_parm1_nonneg },
|
||||
{ "const", emit_do_const },
|
||||
{ "const.alt", emit_parm1_any },
|
||||
{ "const.pri", emit_parm1_any },
|
||||
{ "const.s", emit_do_const_s },
|
||||
{ "dec", emit_parm1_data },
|
||||
{ "dec.alt", emit_parm0 },
|
||||
{ "dec.i", emit_parm0 },
|
||||
{ "dec.pri", emit_parm0 },
|
||||
{ "dec.s", emit_parm1_local },
|
||||
{ "eq", emit_parm0 },
|
||||
{ "eq.c.alt", emit_parm1_any },
|
||||
{ "eq.c.pri", emit_parm1_any },
|
||||
{ "fill", emit_parm1_nonneg },
|
||||
{ "geq", emit_parm0 },
|
||||
{ "grtr", emit_parm0 },
|
||||
{ "halt", emit_parm1_nonneg },
|
||||
{ "heap", emit_parm1_integer },
|
||||
{ "idxaddr", emit_parm0 },
|
||||
{ "idxaddr.b", emit_parm1_shift },
|
||||
{ "inc", emit_parm1_data },
|
||||
{ "inc.alt", emit_parm0 },
|
||||
{ "inc.i", emit_parm0 },
|
||||
{ "inc.pri", emit_parm0 },
|
||||
{ "inc.s", emit_parm1_local },
|
||||
{ "invert", emit_parm0 },
|
||||
{ "jeq", emit_parm1_label },
|
||||
{ "jgeq", emit_parm1_label },
|
||||
{ "jgrtr", emit_parm1_label },
|
||||
{ "jleq", emit_parm1_label },
|
||||
{ "jless", emit_parm1_label },
|
||||
{ "jneq", emit_parm1_label },
|
||||
{ "jnz", emit_parm1_label },
|
||||
{ "jrel", emit_parm1_integer },
|
||||
{ "jsgeq", emit_parm1_label },
|
||||
{ "jsgrtr", emit_parm1_label },
|
||||
{ "jsleq", emit_parm1_label },
|
||||
{ "jsless", emit_parm1_label },
|
||||
{ "jump", emit_parm1_label },
|
||||
{ "jump.pri", emit_parm0 },
|
||||
{ "jzer", emit_parm1_label },
|
||||
{ "lctrl", emit_parm1_integer },
|
||||
{ "leq", emit_parm0 },
|
||||
{ "less", emit_parm0 },
|
||||
{ "lidx", emit_parm0 },
|
||||
{ "lidx.b", emit_parm1_shift },
|
||||
{ "load.alt", emit_parm1_data },
|
||||
{ "load.both", emit_do_load_both },
|
||||
{ "load.i", emit_parm0 },
|
||||
{ "load.pri", emit_parm1_data },
|
||||
{ "load.s.alt", emit_parm1_local },
|
||||
{ "load.s.both",emit_do_load_s_both },
|
||||
{ "load.s.pri", emit_parm1_local },
|
||||
{ "lodb.i", emit_do_lodb_strb },
|
||||
{ "lref.alt", emit_parm1_data },
|
||||
{ "lref.pri", emit_parm1_data },
|
||||
{ "lref.s.alt", emit_parm1_local },
|
||||
{ "lref.s.pri", emit_parm1_local },
|
||||
{ "move.alt", emit_parm0 },
|
||||
{ "move.pri", emit_parm0 },
|
||||
{ "movs", emit_parm1_nonneg },
|
||||
{ "neg", emit_parm0 },
|
||||
{ "neq", emit_parm0 },
|
||||
{ "nop", emit_parm0 },
|
||||
{ "not", emit_parm0 },
|
||||
{ "or", emit_parm0 },
|
||||
{ "pop.alt", emit_parm0 },
|
||||
{ "pop.pri", emit_parm0 },
|
||||
{ "proc", emit_parm0 },
|
||||
{ "push", emit_parm1_data },
|
||||
{ "push.adr", emit_parm1_local },
|
||||
{ "push.alt", emit_parm0 },
|
||||
{ "push.c", emit_parm1_any },
|
||||
{ "push.pri", emit_parm0 },
|
||||
{ "push.r", emit_parm1_integer },
|
||||
{ "push.s", emit_parm1_local },
|
||||
{ "push2", emit_do_pushn },
|
||||
{ "push2.adr", emit_do_pushn_s_adr },
|
||||
{ "push2.c", emit_do_pushn_c },
|
||||
{ "push2.s", emit_do_pushn_s_adr },
|
||||
{ "push3", emit_do_pushn },
|
||||
{ "push3.adr", emit_do_pushn_s_adr },
|
||||
{ "push3.c", emit_do_pushn_c },
|
||||
{ "push3.s", emit_do_pushn_s_adr },
|
||||
{ "push4", emit_do_pushn },
|
||||
{ "push4.adr", emit_do_pushn_s_adr },
|
||||
{ "push4.c", emit_do_pushn_c },
|
||||
{ "push4.s", emit_do_pushn_s_adr },
|
||||
{ "push5", emit_do_pushn },
|
||||
{ "push5.adr", emit_do_pushn_s_adr },
|
||||
{ "push5.c", emit_do_pushn_c },
|
||||
{ "push5.s", emit_do_pushn_s_adr },
|
||||
{ "ret", emit_parm0 },
|
||||
{ "retn", emit_parm0 },
|
||||
{ "sctrl", emit_parm1_integer },
|
||||
{ "sdiv", emit_parm0 },
|
||||
{ "sdiv.alt", emit_parm0 },
|
||||
{ "sgeq", emit_parm0 },
|
||||
{ "sgrtr", emit_parm0 },
|
||||
{ "shl", emit_parm0 },
|
||||
{ "shl.c.alt", emit_parm1_shift },
|
||||
{ "shl.c.pri", emit_parm1_shift },
|
||||
{ "shr", emit_parm0 },
|
||||
{ "shr.c.alt", emit_parm1_shift },
|
||||
{ "shr.c.pri", emit_parm1_shift },
|
||||
{ "sign.alt", emit_parm0 },
|
||||
{ "sign.pri", emit_parm0 },
|
||||
{ "sleq", emit_parm0 },
|
||||
{ "sless", emit_parm0 },
|
||||
{ "smul", emit_parm0 },
|
||||
{ "smul.c", emit_parm1_integer },
|
||||
{ "sref.alt", emit_parm1_data },
|
||||
{ "sref.pri", emit_parm1_data },
|
||||
{ "sref.s.alt", emit_parm1_local },
|
||||
{ "sref.s.pri", emit_parm1_local },
|
||||
{ "sshr", emit_parm0 },
|
||||
{ "stack", emit_parm1_integer },
|
||||
{ "stor.alt", emit_parm1_data },
|
||||
{ "stor.i", emit_parm0 },
|
||||
{ "stor.pri", emit_parm1_data },
|
||||
{ "stor.s.alt", emit_parm1_local },
|
||||
{ "stor.s.pri", emit_parm1_local },
|
||||
{ "strb.i", emit_do_lodb_strb },
|
||||
{ "sub", emit_parm0 },
|
||||
{ "sub.alt", emit_parm0 },
|
||||
{ "swap.alt", emit_parm0 },
|
||||
{ "swap.pri", emit_parm0 },
|
||||
{ "switch", emit_parm1_label },
|
||||
{ "sysreq.c", emit_do_sysreq_c },
|
||||
{ "sysreq.n", emit_do_sysreq_n },
|
||||
{ "sysreq.pri", emit_parm0 },
|
||||
{ "udiv", emit_parm0 },
|
||||
{ "udiv.alt", emit_parm0 },
|
||||
{ "umul", emit_parm0 },
|
||||
{ "xchg", emit_parm0 },
|
||||
{ "xor", emit_parm0 },
|
||||
{ "zero", emit_parm1_data },
|
||||
{ "zero.alt", emit_parm0 },
|
||||
{ "zero.pri", emit_parm0 },
|
||||
{ "zero.s", emit_parm1_local },
|
||||
};
|
||||
|
||||
static int emit_findopcode(const char *instr,int maxlen)
|
||||
|
Loading…
x
Reference in New Issue
Block a user