emit/__emit: Move the "anti-optimisation" workaround to 'emit_parse_line()'
Conflicts: source/compiler/sc1.c
This commit is contained in:
parent
59428b0c39
commit
d5691209d6
@ -870,15 +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 */
|
||||||
|
|
||||||
|
|
||||||
/* Possible entries for "emit_parsing_mode"
|
/* Possible entries for "emit_parsing_mode"
|
||||||
* Bits: 0 (epmBLOCK) multiline ('{}' block) syntax
|
* Bits: 0 (epmACTIVE) 'emit'/'__emit' parsing is active
|
||||||
* 1 (epmEXPR) used within an expression
|
* 1 (epmBLOCK) multiline ('{}' block) syntax
|
||||||
* 2 (epmGLOBAL) used outside of function
|
* 2 (epmEXPR) used within an expression
|
||||||
|
* 3 (epmGLOBAL) used outside of function
|
||||||
*/
|
*/
|
||||||
#define epmBLOCK 1
|
#define epmACTIVE 1
|
||||||
#define epmEXPR 2
|
#define epmBLOCK 2
|
||||||
#define epmGLOBAL 4
|
#define epmEXPR 4
|
||||||
|
#define epmGLOBAL 8
|
||||||
SC_VDECL int emit_parsing_mode;
|
SC_VDECL int emit_parsing_mode;
|
||||||
|
|
||||||
#if !defined SC_LIGHT
|
#if !defined SC_LIGHT
|
||||||
|
@ -6539,6 +6539,13 @@ SC_FUNC void emit_parse_line(void)
|
|||||||
char name[MAX_INSTR_LEN];
|
char name[MAX_INSTR_LEN];
|
||||||
extern char *sc_tokens[];
|
extern char *sc_tokens[];
|
||||||
|
|
||||||
|
/* write the staging buffer to the output file so instructions
|
||||||
|
* generated by the `emit`/`__emit` operator could be written
|
||||||
|
* separately without getting altered by the optimizer
|
||||||
|
*/
|
||||||
|
stgout(0);
|
||||||
|
emit_parsing_mode |= epmACTIVE;
|
||||||
|
|
||||||
tok=tokeninfo(&val,&st);
|
tok=tokeninfo(&val,&st);
|
||||||
if (tok==tSYMBOL || (tok>tMIDDLE && tok<=tLAST)) {
|
if (tok==tSYMBOL || (tok>tMIDDLE && tok<=tLAST)) {
|
||||||
/* get the token length */
|
/* get the token length */
|
||||||
@ -6580,7 +6587,7 @@ SC_FUNC void emit_parse_line(void)
|
|||||||
} else {
|
} else {
|
||||||
sym=fetchlab(st);
|
sym=fetchlab(st);
|
||||||
if ((sym->usage & uDEFINE)!=0)
|
if ((sym->usage & uDEFINE)!=0)
|
||||||
error(021,st); /* symbol already defined */
|
error(21,st); /* symbol already defined */
|
||||||
setlabel((int)sym->addr);
|
setlabel((int)sym->addr);
|
||||||
sym->usage|=uDEFINE;
|
sym->usage|=uDEFINE;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -6591,6 +6598,10 @@ SC_FUNC void emit_parse_line(void)
|
|||||||
} else if ((emit_parsing_mode & epmEXPR)==0) {
|
} else if ((emit_parsing_mode & epmEXPR)==0) {
|
||||||
matchtoken(';');
|
matchtoken(';');
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
/* write the staging buffer again */
|
||||||
|
stgout(0);
|
||||||
|
emit_parsing_mode &= ~epmACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doemit(void)
|
static void doemit(void)
|
||||||
|
@ -1452,25 +1452,11 @@ static int hier2(value *lval)
|
|||||||
case t__EMIT: {
|
case t__EMIT: {
|
||||||
cell val;
|
cell val;
|
||||||
char* st;
|
char* st;
|
||||||
int opt_bck;
|
|
||||||
|
|
||||||
/* write the staging buffer to the output file and temporarily disable
|
|
||||||
* bytecode optimisation so instructions generated by the `emit`/`__emit`
|
|
||||||
* operator won't get altered by the optimizer
|
|
||||||
*/
|
|
||||||
stgout(0);
|
|
||||||
opt_bck=pc_optimize;
|
|
||||||
pc_optimize=sOPTIMIZE_NONE;
|
|
||||||
|
|
||||||
/* parse the `emit`/`__emit` expression */
|
|
||||||
emit_parsing_mode |= epmEXPR;
|
emit_parsing_mode |= epmEXPR;
|
||||||
lex(&val,&st);
|
lex(&val,&st);
|
||||||
emit_parse_line();
|
emit_parse_line();
|
||||||
emit_parsing_mode &= ~epmEXPR;
|
emit_parsing_mode &= ~epmEXPR;
|
||||||
lval->ident=iEXPRESSION;
|
lval->ident=iEXPRESSION;
|
||||||
|
|
||||||
/* restore the bytecode optimisation level and return */
|
|
||||||
pc_optimize=opt_bck;
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} /* case */
|
} /* case */
|
||||||
default:
|
default:
|
||||||
|
@ -1770,7 +1770,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 && (emit_parsing_mode & epmACTIVE)==0 && sc_status==statWRITE) {
|
||||||
do {
|
do {
|
||||||
matches=0;
|
matches=0;
|
||||||
start=debut;
|
start=debut;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user