Merge pull request #211 from Daniel-Cortez/emit_op_fixes
Fixes and improvements for emit/__emit
This commit is contained in:
commit
064d35256b
@ -46,21 +46,16 @@
|
||||
#include "../amx/amx.h"
|
||||
|
||||
#if defined _MSC_VER
|
||||
#define OPHANDLER_CALL __fastcall
|
||||
#elif defined __GNUC__
|
||||
#if defined __clang__
|
||||
#define OPHANDLER_CALL __attribute__((fastcall))
|
||||
#elif (defined __i386__ || defined __x86_64__ || defined __amd64__)
|
||||
#define SC_FASTCALL __fastcall
|
||||
#elif defined __GNUC__ && (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))
|
||||
#define SC_FASTCALL __attribute__((fastcall))
|
||||
#else
|
||||
#define OPHANDLER_CALL __attribute__((regparam(3)))
|
||||
#define SC_FASTCALL __attribute__((regparam(3)))
|
||||
#endif
|
||||
#else
|
||||
#define OPHANDLER_CALL
|
||||
#endif
|
||||
#else
|
||||
#define OPHANDLER_CALL
|
||||
#endif
|
||||
#if !defined SC_FASTCALL
|
||||
#define SC_FASTCALL
|
||||
#endif
|
||||
|
||||
/* Note: the "cell" and "ucell" types are defined in AMX.H */
|
||||
@ -407,8 +402,15 @@ typedef struct s_valuepair {
|
||||
#define tSYMBOL 336
|
||||
#define tLABEL 337
|
||||
#define tSTRING 338
|
||||
#define tEXPR 339 /* for assigment to "lastst" only (see SC1.C) */
|
||||
#define tENDLESS 340 /* endless loop, for assigment to "lastst" only */
|
||||
/* argument types for emit/__emit */
|
||||
#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 */
|
||||
#define sSTARTREORDER 0x01
|
||||
@ -699,7 +701,7 @@ SC_FUNC void dec(value *lval);
|
||||
SC_FUNC void jmp_ne0(int number);
|
||||
SC_FUNC void jmp_eq0(int number);
|
||||
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 */
|
||||
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 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
|
||||
SC_VDECL int sc_makereport; /* generate a cross-reference report */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1368,7 +1368,7 @@ static int command(void)
|
||||
break;
|
||||
} else if (current_token==tRATIONAL) {
|
||||
/* 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);
|
||||
break;
|
||||
} else {
|
||||
@ -2108,7 +2108,9 @@ char *sc_tokens[] = {
|
||||
"#endscript", "#error", "#file", "#if", "#include", "#line", "#pragma",
|
||||
"#tryinclude", "#undef", "#warning",
|
||||
";", ";", "-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)
|
||||
|
@ -1452,13 +1452,19 @@ static int hier2(value *lval)
|
||||
case t__EMIT: {
|
||||
cell val;
|
||||
char* st;
|
||||
if (!matchtoken('{'))
|
||||
error(38);
|
||||
int block_syntax=matchtoken('(');
|
||||
emit_flags |= efEXPR;
|
||||
if (emit_stgbuf_idx==-1)
|
||||
emit_stgbuf_idx=stgidx;
|
||||
do {
|
||||
lex(&val,&st);
|
||||
lval->ident=iEXPRESSION;
|
||||
emit_parse_line();
|
||||
if (!matchtoken('}'))
|
||||
error(38);
|
||||
} while ((block_syntax!=0) && matchtoken(','));
|
||||
if (block_syntax!=0)
|
||||
needtoken(')');
|
||||
emit_flags &= ~efEXPR;
|
||||
lval->ident=iEXPRESSION;
|
||||
pc_sideeffect=TRUE;
|
||||
return FALSE;
|
||||
} /* case */
|
||||
default:
|
||||
|
@ -1379,19 +1379,19 @@ SC_FUNC void outval(cell val,int newline)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
stgwrite("\t");
|
||||
stgwrite(name);
|
||||
|
||||
for (i=0; i<nargs; i++) {
|
||||
for (i=0; i<numargs; i++) {
|
||||
stgwrite(" ");
|
||||
stgwrite(itoh(args[i]));
|
||||
} /* for */
|
||||
|
||||
stgwrite("\n");
|
||||
|
||||
code_idx+=opargs(nargs)+opcodes(1);
|
||||
code_idx+=opargs(numargs)+opcodes(1);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
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 {
|
||||
cell opcode;
|
||||
@ -282,7 +282,7 @@ static void write_encoded(FILE *fbin,ucell *c,int num)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#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;
|
||||
}
|
||||
@ -290,7 +290,7 @@ static cell OPHANDLER_CALL noop(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#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);
|
||||
return 0;
|
||||
@ -299,14 +299,14 @@ static cell OPHANDLER_CALL set_currentfile(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#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)
|
||||
write_encoded(fbin,(ucell*)&opcode,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);
|
||||
if (fbin!=NULL) {
|
||||
@ -316,7 +316,7 @@ static cell OPHANDLER_CALL parm1(FILE *fbin,char *params,cell opcode)
|
||||
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,¶ms);
|
||||
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);
|
||||
}
|
||||
|
||||
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,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -342,7 +342,7 @@ static cell OPHANDLER_CALL parm3(FILE *fbin,char *params,cell opcode)
|
||||
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,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -358,7 +358,7 @@ static cell OPHANDLER_CALL parm4(FILE *fbin,char *params,cell opcode)
|
||||
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,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -379,7 +379,7 @@ static cell OPHANDLER_CALL parm5(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#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;
|
||||
int num=0;
|
||||
@ -395,7 +395,7 @@ static cell OPHANDLER_CALL do_dump(FILE *fbin,char *params,cell opcode)
|
||||
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;
|
||||
|
||||
@ -408,7 +408,7 @@ static cell OPHANDLER_CALL do_dumpn(FILE *fbin,char *params,cell opcode)
|
||||
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 */
|
||||
int i;
|
||||
@ -449,7 +449,7 @@ static cell OPHANDLER_CALL do_call(FILE *fbin,char *params,cell opcode)
|
||||
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;
|
||||
ucell p;
|
||||
@ -466,7 +466,7 @@ static cell OPHANDLER_CALL do_jump(FILE *fbin,char *params,cell opcode)
|
||||
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;
|
||||
ucell p;
|
||||
@ -486,7 +486,7 @@ static cell OPHANDLER_CALL do_switch(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#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;
|
||||
ucell p,v;
|
||||
|
@ -1437,6 +1437,8 @@ SC_FUNC void stgout(int index)
|
||||
filewrite(stgpipe+idx);
|
||||
} /* if */
|
||||
} /* if */
|
||||
if (stgidx<=emit_stgbuf_idx)
|
||||
emit_stgbuf_idx=-1;
|
||||
pipeidx=0; /* reset second pipe */
|
||||
}
|
||||
|
||||
@ -1770,7 +1772,7 @@ static void stgopt(char *start,char *end,int (*outputfunc)(char *str))
|
||||
|
||||
assert(sequences!=NULL);
|
||||
/* 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 {
|
||||
matches=0;
|
||||
start=debut;
|
||||
|
@ -105,7 +105,8 @@ SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */
|
||||
|
||||
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
|
||||
SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */
|
||||
|
Loading…
x
Reference in New Issue
Block a user