Merge pull request #211 from Daniel-Cortez/emit_op_fixes

Fixes and improvements for emit/__emit
This commit is contained in:
Zeex 2017-12-30 15:00:52 +06:00 committed by GitHub
commit 064d35256b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 928 additions and 630 deletions

View File

@ -46,21 +46,16 @@
#include "../amx/amx.h" #include "../amx/amx.h"
#if defined _MSC_VER #if defined _MSC_VER
#define OPHANDLER_CALL __fastcall #define SC_FASTCALL __fastcall
#elif defined __GNUC__ #elif defined __GNUC__ && (defined __i386__ || defined __x86_64__ || defined __amd64__)
#if defined __clang__ #if !defined __x86_64__ && !defined __amd64__ && (__GNUC__>=4 || __GNUC__==3 && __GNUC_MINOR__>=4)
#define OPHANDLER_CALL __attribute__((fastcall)) #define SC_FASTCALL __attribute__((fastcall))
#elif (defined __i386__ || defined __x86_64__ || defined __amd64__)
#if !defined __x86_64__ && !defined __amd64__ && (__GNUC__>=4 || __GNUC__==3 && __GNUC_MINOR__>=4)
#define OPHANDLER_CALL __attribute__((fastcall))
#else
#define OPHANDLER_CALL __attribute__((regparam(3)))
#endif
#else #else
#define OPHANDLER_CALL #define SC_FASTCALL __attribute__((regparam(3)))
#endif #endif
#else #endif
#define OPHANDLER_CALL #if !defined SC_FASTCALL
#define SC_FASTCALL
#endif #endif
/* Note: the "cell" and "ucell" types are defined in AMX.H */ /* Note: the "cell" and "ucell" types are defined in AMX.H */
@ -407,8 +402,15 @@ typedef struct s_valuepair {
#define tSYMBOL 336 #define tSYMBOL 336
#define tLABEL 337 #define tLABEL 337
#define tSTRING 338 #define tSTRING 338
#define tEXPR 339 /* for assigment to "lastst" only (see SC1.C) */ /* argument types for emit/__emit */
#define tENDLESS 340 /* endless loop, for assigment to "lastst" only */ #define teNUMERIC 339 /* integer/rational number */
#define teDATA 340 /* data (variable name or address) */
#define teLOCAL 341 /* local variable (name or offset) */
#define teFUNCTN 342 /* Pawn function */
#define teNATIVE 343 /* native function */
/* for assigment to "lastst" only (see SC1.C) */
#define tEXPR 344
#define tENDLESS 345 /* endless loop */
/* (reversed) evaluation of staging buffer */ /* (reversed) evaluation of staging buffer */
#define sSTARTREORDER 0x01 #define sSTARTREORDER 0x01
@ -699,7 +701,7 @@ SC_FUNC void dec(value *lval);
SC_FUNC void jmp_ne0(int number); SC_FUNC void jmp_ne0(int number);
SC_FUNC void jmp_eq0(int number); SC_FUNC void jmp_eq0(int number);
SC_FUNC void outval(cell val,int newline); SC_FUNC void outval(cell val,int newline);
SC_FUNC void outinstr(const char *name, int nargs, ucell *args); SC_FUNC void outinstr(const char *name,ucell args[],int numargs);
/* function prototypes in SC5.C */ /* function prototypes in SC5.C */
SC_FUNC int error(int number,...); SC_FUNC int error(int number,...);
@ -868,7 +870,16 @@ SC_VDECL FILE *outf; /* file written to */
SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */ SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */
SC_VDECL int emit_block_parsing; /* Possible entries for "emit_flags"
* Bits: 0 (epmBLOCK) multiline ('{}' block) syntax
* 1 (epmEXPR) used within an expression
* 2 (epmGLOBAL) used outside of a function
*/
#define efBLOCK 1
#define efEXPR 2
#define efGLOBAL 4
SC_VDECL int emit_flags;
SC_VDECL int emit_stgbuf_idx;
#if !defined SC_LIGHT #if !defined SC_LIGHT
SC_VDECL int sc_makereport; /* generate a cross-reference report */ SC_VDECL int sc_makereport; /* generate a cross-reference report */

File diff suppressed because it is too large Load Diff

View File

@ -1368,7 +1368,7 @@ static int command(void)
break; break;
} else if (current_token==tRATIONAL) { } else if (current_token==tRATIONAL) {
/* change the first bit to make float negative value */ /* change the first bit to make float negative value */
outval(val | 0x80000000,FALSE); outval(val|((cell)1 << (PAWN_CELL_SIZE-1)),FALSE);
code_idx+=opargs(1); code_idx+=opargs(1);
break; break;
} else { } else {
@ -2108,7 +2108,9 @@ char *sc_tokens[] = {
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma", "#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
"#tryinclude", "#undef", "#warning", "#tryinclude", "#undef", "#warning",
";", ";", "-integer value-", "-rational value-", "-identifier-", ";", ";", "-integer value-", "-rational value-", "-identifier-",
"-label-", "-string-" "-label-", "-string-",
"-numeric value-", "-data offset-", "-local variable-", "-function-",
"-native function-"
}; };
SC_FUNC int lex(cell *lexvalue,char **lexsym) SC_FUNC int lex(cell *lexvalue,char **lexsym)

View File

@ -1452,13 +1452,19 @@ static int hier2(value *lval)
case t__EMIT: { case t__EMIT: {
cell val; cell val;
char* st; char* st;
if (!matchtoken('{')) int block_syntax=matchtoken('(');
error(38); emit_flags |= efEXPR;
lex(&val,&st); if (emit_stgbuf_idx==-1)
emit_stgbuf_idx=stgidx;
do {
lex(&val,&st);
emit_parse_line();
} while ((block_syntax!=0) && matchtoken(','));
if (block_syntax!=0)
needtoken(')');
emit_flags &= ~efEXPR;
lval->ident=iEXPRESSION; lval->ident=iEXPRESSION;
emit_parse_line(); pc_sideeffect=TRUE;
if (!matchtoken('}'))
error(38);
return FALSE; return FALSE;
} /* case */ } /* case */
default: default:

View File

@ -1379,19 +1379,19 @@ SC_FUNC void outval(cell val,int newline)
} }
/* write an instruction with arguments */ /* write an instruction with arguments */
SC_FUNC void outinstr(const char *name, int nargs, ucell *args) SC_FUNC void outinstr(const char *name,ucell args[],int numargs)
{ {
int i; int i;
stgwrite("\t"); stgwrite("\t");
stgwrite(name); stgwrite(name);
for (i=0; i<nargs; i++) { for (i=0; i<numargs; i++) {
stgwrite(" "); stgwrite(" ");
stgwrite(itoh(args[i])); stgwrite(itoh(args[i]));
} /* for */ } /* for */
stgwrite("\n"); stgwrite("\n");
code_idx+=opargs(nargs)+opcodes(1); code_idx+=opargs(numargs)+opcodes(1);
} }

View File

@ -42,7 +42,7 @@
static void append_dbginfo(FILE *fout); static void append_dbginfo(FILE *fout);
typedef cell (OPHANDLER_CALL *OPCODE_PROC)(FILE *fbin,char *params,cell opcode); typedef cell (SC_FASTCALL *OPCODE_PROC)(FILE *fbin,char *params,cell opcode);
typedef struct { typedef struct {
cell opcode; cell opcode;
@ -282,7 +282,7 @@ static void write_encoded(FILE *fbin,ucell *c,int num)
#if defined __BORLANDC__ || defined __WATCOMC__ #if defined __BORLANDC__ || defined __WATCOMC__
#pragma argsused #pragma argsused
#endif #endif
static cell OPHANDLER_CALL noop(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL noop(FILE *fbin,char *params,cell opcode)
{ {
return 0; return 0;
} }
@ -290,7 +290,7 @@ static cell OPHANDLER_CALL noop(FILE *fbin,char *params,cell opcode)
#if defined __BORLANDC__ || defined __WATCOMC__ #if defined __BORLANDC__ || defined __WATCOMC__
#pragma argsused #pragma argsused
#endif #endif
static cell OPHANDLER_CALL set_currentfile(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL set_currentfile(FILE *fbin,char *params,cell opcode)
{ {
fcurrent=(short)getparam(params,NULL); fcurrent=(short)getparam(params,NULL);
return 0; return 0;
@ -299,14 +299,14 @@ static cell OPHANDLER_CALL set_currentfile(FILE *fbin,char *params,cell opcode)
#if defined __BORLANDC__ || defined __WATCOMC__ #if defined __BORLANDC__ || defined __WATCOMC__
#pragma argsused #pragma argsused
#endif #endif
static cell OPHANDLER_CALL parm0(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm0(FILE *fbin,char *params,cell opcode)
{ {
if (fbin!=NULL) if (fbin!=NULL)
write_encoded(fbin,(ucell*)&opcode,1); write_encoded(fbin,(ucell*)&opcode,1);
return opcodes(1); return opcodes(1);
} }
static cell OPHANDLER_CALL parm1(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm1(FILE *fbin,char *params,cell opcode)
{ {
ucell p=getparam(params,NULL); ucell p=getparam(params,NULL);
if (fbin!=NULL) { if (fbin!=NULL) {
@ -316,7 +316,7 @@ static cell OPHANDLER_CALL parm1(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(1); return opcodes(1)+opargs(1);
} }
static cell OPHANDLER_CALL parm2(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm2(FILE *fbin,char *params,cell opcode)
{ {
ucell p1=getparam(params,&params); ucell p1=getparam(params,&params);
ucell p2=getparam(params,NULL); ucell p2=getparam(params,NULL);
@ -328,7 +328,7 @@ static cell OPHANDLER_CALL parm2(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(2); return opcodes(1)+opargs(2);
} }
static cell OPHANDLER_CALL parm3(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm3(FILE *fbin,char *params,cell opcode)
{ {
ucell p1=getparam(params,&params); ucell p1=getparam(params,&params);
ucell p2=getparam(params,&params); ucell p2=getparam(params,&params);
@ -342,7 +342,7 @@ static cell OPHANDLER_CALL parm3(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(3); return opcodes(1)+opargs(3);
} }
static cell OPHANDLER_CALL parm4(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm4(FILE *fbin,char *params,cell opcode)
{ {
ucell p1=getparam(params,&params); ucell p1=getparam(params,&params);
ucell p2=getparam(params,&params); ucell p2=getparam(params,&params);
@ -358,7 +358,7 @@ static cell OPHANDLER_CALL parm4(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(4); return opcodes(1)+opargs(4);
} }
static cell OPHANDLER_CALL parm5(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL parm5(FILE *fbin,char *params,cell opcode)
{ {
ucell p1=getparam(params,&params); ucell p1=getparam(params,&params);
ucell p2=getparam(params,&params); ucell p2=getparam(params,&params);
@ -379,7 +379,7 @@ static cell OPHANDLER_CALL parm5(FILE *fbin,char *params,cell opcode)
#if defined __BORLANDC__ || defined __WATCOMC__ #if defined __BORLANDC__ || defined __WATCOMC__
#pragma argsused #pragma argsused
#endif #endif
static cell OPHANDLER_CALL do_dump(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_dump(FILE *fbin,char *params,cell opcode)
{ {
ucell p; ucell p;
int num=0; int num=0;
@ -395,7 +395,7 @@ static cell OPHANDLER_CALL do_dump(FILE *fbin,char *params,cell opcode)
return num*sizeof(cell); return num*sizeof(cell);
} }
static cell OPHANDLER_CALL do_dumpn(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_dumpn(FILE *fbin,char *params,cell opcode)
{ {
ucell value,num,i; ucell value,num,i;
@ -408,7 +408,7 @@ static cell OPHANDLER_CALL do_dumpn(FILE *fbin,char *params,cell opcode)
return num*sizeof(cell); return num*sizeof(cell);
} }
static cell OPHANDLER_CALL do_call(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_call(FILE *fbin,char *params,cell opcode)
{ {
char name[sNAMEMAX+2]; /* +1 for a possible leading dot */ char name[sNAMEMAX+2]; /* +1 for a possible leading dot */
int i; int i;
@ -449,7 +449,7 @@ static cell OPHANDLER_CALL do_call(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(1); return opcodes(1)+opargs(1);
} }
static cell OPHANDLER_CALL do_jump(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_jump(FILE *fbin,char *params,cell opcode)
{ {
int i; int i;
ucell p; ucell p;
@ -466,7 +466,7 @@ static cell OPHANDLER_CALL do_jump(FILE *fbin,char *params,cell opcode)
return opcodes(1)+opargs(1); return opcodes(1)+opargs(1);
} }
static cell OPHANDLER_CALL do_switch(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_switch(FILE *fbin,char *params,cell opcode)
{ {
int i; int i;
ucell p; ucell p;
@ -486,7 +486,7 @@ static cell OPHANDLER_CALL do_switch(FILE *fbin,char *params,cell opcode)
#if defined __BORLANDC__ || defined __WATCOMC__ #if defined __BORLANDC__ || defined __WATCOMC__
#pragma argsused #pragma argsused
#endif #endif
static cell OPHANDLER_CALL do_case(FILE *fbin,char *params,cell opcode) static cell SC_FASTCALL do_case(FILE *fbin,char *params,cell opcode)
{ {
int i; int i;
ucell p,v; ucell p,v;

View File

@ -1437,6 +1437,8 @@ SC_FUNC void stgout(int index)
filewrite(stgpipe+idx); filewrite(stgpipe+idx);
} /* if */ } /* if */
} /* if */ } /* if */
if (stgidx<=emit_stgbuf_idx)
emit_stgbuf_idx=-1;
pipeidx=0; /* reset second pipe */ pipeidx=0; /* reset second pipe */
} }
@ -1770,7 +1772,7 @@ static void stgopt(char *start,char *end,int (*outputfunc)(char *str))
assert(sequences!=NULL); assert(sequences!=NULL);
/* do not match anything if debug-level is maximum */ /* do not match anything if debug-level is maximum */
if (pc_optimize>sOPTIMIZE_NONE && sc_status==statWRITE) { if (pc_optimize>sOPTIMIZE_NONE && sc_status==statWRITE && emit_stgbuf_idx==-1) {
do { do {
matches=0; matches=0;
start=debut; start=debut;

View File

@ -105,7 +105,8 @@ SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */
SC_VDEFINE jmp_buf errbuf; SC_VDEFINE jmp_buf errbuf;
SC_VDEFINE int emit_block_parsing=FALSE; SC_VDEFINE int emit_flags;
SC_VDEFINE int emit_stgbuf_idx;
#if !defined SC_LIGHT #if !defined SC_LIGHT
SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */ SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */