emit/__emit: Verify the arguments for 'sysreq.c' and 'sysreq.n'
This commit is contained in:
parent
bd01c04def
commit
c77b0f1bdd
@ -5868,7 +5868,7 @@ static void emit_invalid_token(int expected_token,int found_token)
|
|||||||
} /* if */
|
} /* if */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emit_param_any(ucell *p,int size)
|
static void emit_param_any(ucell *p,int numargs)
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
cell val,cidx;
|
cell val,cidx;
|
||||||
@ -5877,17 +5877,17 @@ static void emit_param_any(ucell *p,int size)
|
|||||||
int curp=0;
|
int curp=0;
|
||||||
int tok,neg,ident,index;
|
int tok,neg,ident,index;
|
||||||
|
|
||||||
assert(size>0);
|
assert(numargs>0);
|
||||||
do {
|
do {
|
||||||
neg=FALSE;
|
neg=FALSE;
|
||||||
fetchtok:
|
fetchtok:
|
||||||
tok=lex(&val,&str);
|
tok=lex(&val,&str);
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
case tNUMBER:
|
case tNUMBER:
|
||||||
p[curp]=(neg==TRUE) ? -val : val;
|
p[curp]=(neg!=FALSE) ? -val : val;
|
||||||
break;
|
break;
|
||||||
case tRATIONAL:
|
case tRATIONAL:
|
||||||
p[curp]=(neg==TRUE) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val;
|
p[curp]=(neg!=FALSE) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val;
|
||||||
break;
|
break;
|
||||||
case tSYMBOL:
|
case tSYMBOL:
|
||||||
sym=findloc(str);
|
sym=findloc(str);
|
||||||
@ -5908,7 +5908,7 @@ static void emit_param_any(ucell *p,int size)
|
|||||||
} else {
|
} else {
|
||||||
markusage(sym,uREAD|uWRITTEN);
|
markusage(sym,uREAD|uWRITTEN);
|
||||||
} /* if */
|
} /* if */
|
||||||
p[curp]=(neg==TRUE) ? -sym->addr : sym->addr;
|
p[curp]=(neg!=FALSE) ? -sym->addr : sym->addr;
|
||||||
break;
|
break;
|
||||||
case '(':
|
case '(':
|
||||||
if ((emit_parsing_mode & epmEXPR)==0)
|
if ((emit_parsing_mode & epmEXPR)==0)
|
||||||
@ -5923,24 +5923,25 @@ static void emit_param_any(ucell *p,int size)
|
|||||||
if ((emit_parsing_mode & epmEXPR)==0)
|
if ((emit_parsing_mode & epmEXPR)==0)
|
||||||
stgset(FALSE);
|
stgset(FALSE);
|
||||||
needtoken(')');
|
needtoken(')');
|
||||||
p[curp]=(neg==TRUE) ? -val : val;
|
p[curp]=(neg!=FALSE) ? -val : val;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
if (neg==FALSE) {
|
if (neg==FALSE) {
|
||||||
neg=TRUE;
|
neg=TRUE;
|
||||||
goto fetchtok;
|
goto fetchtok;
|
||||||
|
} else {
|
||||||
|
char ival[sNAMEMAX+2]="-";
|
||||||
|
strcpy(ival+1,str);
|
||||||
|
error(1,sc_tokens[tSYMBOL-tFIRST],ival);
|
||||||
|
break;
|
||||||
} /* if */
|
} /* if */
|
||||||
char ival[sNAMEMAX+2]="-";
|
|
||||||
strcpy(ival+1,str);
|
|
||||||
error(1,sc_tokens[tSYMBOL-tFIRST],ival);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
emit_invalid_token(teNUMBER,tok);
|
emit_invalid_token(teNUMBER,tok);
|
||||||
} /* switch */
|
} /* switch */
|
||||||
} while (++curp<size);
|
} while (++curp<numargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emit_param_data(ucell *p,int size)
|
static void emit_param_data(ucell *p,int numargs)
|
||||||
{
|
{
|
||||||
cell val;
|
cell val;
|
||||||
char *str;
|
char *str;
|
||||||
@ -5948,7 +5949,7 @@ static void emit_param_data(ucell *p,int size)
|
|||||||
int curp=0;
|
int curp=0;
|
||||||
int tok;
|
int tok;
|
||||||
|
|
||||||
assert(size>0);
|
assert(numargs>0);
|
||||||
do {
|
do {
|
||||||
tok=lex(&val,&str);
|
tok=lex(&val,&str);
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
@ -5983,10 +5984,10 @@ static void emit_param_data(ucell *p,int size)
|
|||||||
default:
|
default:
|
||||||
emit_invalid_token(teDATA,tok);
|
emit_invalid_token(teDATA,tok);
|
||||||
} /* switch */
|
} /* switch */
|
||||||
} while (++curp<size);
|
} while (++curp<numargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emit_param_local(ucell *p,int size)
|
static void emit_param_local(ucell *p,int numargs)
|
||||||
{
|
{
|
||||||
cell val;
|
cell val;
|
||||||
char *str;
|
char *str;
|
||||||
@ -5994,7 +5995,7 @@ static void emit_param_local(ucell *p,int size)
|
|||||||
int curp=0;
|
int curp=0;
|
||||||
int tok;
|
int tok;
|
||||||
|
|
||||||
assert(size>0);
|
assert(numargs>0);
|
||||||
do {
|
do {
|
||||||
tok=lex(&val,&str);
|
tok=lex(&val,&str);
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
@ -6025,10 +6026,10 @@ static void emit_param_local(ucell *p,int size)
|
|||||||
default:
|
default:
|
||||||
emit_invalid_token(tSYMBOL,tok);
|
emit_invalid_token(tSYMBOL,tok);
|
||||||
} /* switch */
|
} /* switch */
|
||||||
} while (++curp<size);
|
} while (++curp<numargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void emit_param_index(ucell *p,const cell *valid_values,int size)
|
static void emit_param_index(ucell *p,const cell *valid_values,int numvalues)
|
||||||
{
|
{
|
||||||
cell val;
|
cell val;
|
||||||
char *str;
|
char *str;
|
||||||
@ -6036,16 +6037,16 @@ static void emit_param_index(ucell *p,const cell *valid_values,int size)
|
|||||||
int tok,i,global;
|
int tok,i,global;
|
||||||
int neg=FALSE;
|
int neg=FALSE;
|
||||||
|
|
||||||
assert(size>0);
|
assert(numvalues>0);
|
||||||
fetchtok:
|
fetchtok:
|
||||||
tok=lex(&val,&str);
|
tok=lex(&val,&str);
|
||||||
switch (tok) {
|
switch (tok) {
|
||||||
case tNUMBER:
|
case tNUMBER:
|
||||||
if (neg==TRUE)
|
if (neg!=FALSE)
|
||||||
val=-val;
|
val=-val;
|
||||||
break;
|
break;
|
||||||
case tRATIONAL:
|
case tRATIONAL:
|
||||||
if (neg==TRUE)
|
if (neg!=FALSE)
|
||||||
val=val|((cell)1 << (PAWN_CELL_SIZE-1));
|
val=val|((cell)1 << (PAWN_CELL_SIZE-1));
|
||||||
break;
|
break;
|
||||||
case tSYMBOL:
|
case tSYMBOL:
|
||||||
@ -6076,7 +6077,7 @@ fetchtok:
|
|||||||
return;
|
return;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
markusage(sym,uREAD);
|
markusage(sym,uREAD);
|
||||||
val=(neg==TRUE) ? -sym->addr : sym->addr;
|
val=(neg!=FALSE) ? -sym->addr : sym->addr;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
if (neg==FALSE) {
|
if (neg==FALSE) {
|
||||||
@ -6090,7 +6091,7 @@ fetchtok:
|
|||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
||||||
*p=val;
|
*p=val;
|
||||||
for (i=0; i<size; i++)
|
for (i=0; i<numvalues; i++)
|
||||||
if (val==valid_values[i])
|
if (val==valid_values[i])
|
||||||
return;
|
return;
|
||||||
error(50); /* invalid range */
|
error(50); /* invalid range */
|
||||||
@ -6111,6 +6112,45 @@ static void emit_param_label(ucell *p)
|
|||||||
*p=*(ucell *)&sym->addr;
|
*p=*(ucell *)&sym->addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void emit_param_function(ucell *p,int isnative)
|
||||||
|
{
|
||||||
|
cell val;
|
||||||
|
char *str;
|
||||||
|
symbol *sym;
|
||||||
|
int tok;
|
||||||
|
|
||||||
|
tok=lex(&val,&str);
|
||||||
|
switch (tok)
|
||||||
|
{
|
||||||
|
case tSYMBOL:
|
||||||
|
sym=findglb(str,sSTATEVAR);
|
||||||
|
if (sym==NULL) {
|
||||||
|
error(17,str); /* undefined symbol */
|
||||||
|
return;
|
||||||
|
} /* if */
|
||||||
|
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
|
||||||
|
if (!!(sym->usage & uNATIVE)==isnative)
|
||||||
|
break;
|
||||||
|
tok=(isnative!=FALSE) ? teFUNCTN : teNATIVE;
|
||||||
|
} else {
|
||||||
|
tok=(sym->ident==iCONSTEXPR) ? teNUMBER : teDATA;
|
||||||
|
} /* if */
|
||||||
|
/* drop through */
|
||||||
|
default:
|
||||||
|
emit_invalid_token((isnative!=FALSE) ? teNATIVE : teFUNCTN,tok);
|
||||||
|
return;
|
||||||
|
} /* switch */
|
||||||
|
|
||||||
|
if (isnative!=FALSE) {
|
||||||
|
if ((sym->usage & uREAD)==0 && sym->addr>=0)
|
||||||
|
sym->addr=ntv_funcid++;
|
||||||
|
*p=sym->addr;
|
||||||
|
} else {
|
||||||
|
*(char **)p=str;
|
||||||
|
} /* if */
|
||||||
|
markusage(sym,uREAD);
|
||||||
|
}
|
||||||
|
|
||||||
static void OPHANDLER_CALL emit_noop(char *name)
|
static void OPHANDLER_CALL emit_noop(char *name)
|
||||||
{
|
{
|
||||||
(void)name;
|
(void)name;
|
||||||
@ -6324,36 +6364,34 @@ static void OPHANDLER_CALL emit_do_sctrl(char *name)
|
|||||||
|
|
||||||
static void OPHANDLER_CALL emit_do_call(char *name)
|
static void OPHANDLER_CALL emit_do_call(char *name)
|
||||||
{
|
{
|
||||||
cell val;
|
char *funcname=NULL;
|
||||||
char *str;
|
|
||||||
symbol *sym;
|
|
||||||
int tok;
|
|
||||||
|
|
||||||
tok=lex(&val,&str);
|
emit_param_function((ucell *)&funcname,FALSE);
|
||||||
if (tok!=tSYMBOL) {
|
|
||||||
emit_invalid_token(tSYMBOL,tok);
|
|
||||||
return;
|
|
||||||
} /* if */
|
|
||||||
sym=findglb(str,sGLOBAL);
|
|
||||||
if (sym==NULL) {
|
|
||||||
error(17,str); /* undefined symbol */
|
|
||||||
return;
|
|
||||||
} /* if */
|
|
||||||
if (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC) {
|
|
||||||
emit_invalid_token(teFUNCTN,(sym->ident==iCONSTEXPR) ? teNUMBER : teDATA);
|
|
||||||
return;
|
|
||||||
} /* if */
|
|
||||||
if ((sym->usage & uNATIVE)!=0) {
|
|
||||||
emit_invalid_token(teFUNCTN,teNATIVE);
|
|
||||||
return;
|
|
||||||
} /* if */
|
|
||||||
stgwrite("\t");
|
stgwrite("\t");
|
||||||
stgwrite(name);
|
stgwrite(name);
|
||||||
stgwrite(" .");
|
if (funcname!=NULL) {
|
||||||
stgwrite(str);
|
stgwrite(" .");
|
||||||
|
stgwrite(funcname);
|
||||||
|
} /* if */
|
||||||
stgwrite("\n");
|
stgwrite("\n");
|
||||||
code_idx+=opcodes(1)+opargs(1);
|
code_idx+=opcodes(1)+opargs(1);
|
||||||
markusage(sym,uREAD);
|
}
|
||||||
|
|
||||||
|
static void OPHANDLER_CALL emit_do_sysreq_c(char *name)
|
||||||
|
{
|
||||||
|
ucell p[1];
|
||||||
|
|
||||||
|
emit_param_function(&p[0],TRUE);
|
||||||
|
outinstr(name,p,(sizeof p / sizeof p[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void OPHANDLER_CALL emit_do_sysreq_n(char *name)
|
||||||
|
{
|
||||||
|
ucell p[2];
|
||||||
|
|
||||||
|
emit_param_function(&p[0],TRUE);
|
||||||
|
emit_param_any(&p[1],1);
|
||||||
|
outinstr(name,p,(sizeof p / sizeof p[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static EMIT_OPCODE emit_opcodelist[] = {
|
static EMIT_OPCODE emit_opcodelist[] = {
|
||||||
@ -6504,8 +6542,8 @@ static EMIT_OPCODE emit_opcodelist[] = {
|
|||||||
{129, "switch", emit_parm1_label },
|
{129, "switch", emit_parm1_label },
|
||||||
/*{126, "symbol", do_symbol }, */
|
/*{126, "symbol", do_symbol }, */
|
||||||
/*{136, "symtag", emit_parm1_any }, */
|
/*{136, "symtag", emit_parm1_any }, */
|
||||||
{123, "sysreq.c", emit_parm1_any },
|
{123, "sysreq.c", emit_do_sysreq_c },
|
||||||
{135, "sysreq.n", emit_parm2_any },
|
{135, "sysreq.n", emit_do_sysreq_n },
|
||||||
{122, "sysreq.pri", emit_parm0 },
|
{122, "sysreq.pri", emit_parm0 },
|
||||||
{ 76, "udiv", emit_parm0 },
|
{ 76, "udiv", emit_parm0 },
|
||||||
{ 77, "udiv.alt", emit_parm0 },
|
{ 77, "udiv.alt", emit_parm0 },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user