Squashed commit of the following:
commit 448aa3b0517a48bf1eb23e143716a1d2543f0ee2 Author: Daniel_Cortez <gromovstanislav@yandex.ru> Date: Fri Jul 5 19:10:25 2019 +0700 Update tests for __emit commit b7fd80382a3481acfcb4e1335cee7071fda064f3 Author: Daniel_Cortez <gromovstanislav@yandex.ru> Date: Fri Jul 5 19:10:09 2019 +0700 __emit: Do not allow pseudo-opcodes to modify constant variables/arrays
This commit is contained in:
parent
8d8b104f38
commit
fc7156241f
@ -6091,8 +6091,9 @@ static regid SC_FASTCALL emit_findreg(char *opname)
|
|||||||
* Looks for an lvalue and generates code to get cell address in PRI
|
* Looks for an lvalue and generates code to get cell address in PRI
|
||||||
* if the lvalue is an array element (iARRAYCELL or iARRAYCHAR).
|
* if the lvalue is an array element (iARRAYCELL or iARRAYCHAR).
|
||||||
*/
|
*/
|
||||||
static int SC_FASTCALL emit_getlval(int *identptr,emit_outval *p,int *islocal, regid reg,
|
static int SC_FASTCALL emit_getlval(int *identptr,emit_outval *p,int *islocal,
|
||||||
int allow_char, int store_pri,int store_alt,int *ispushed)
|
regid reg,int allow_char,int allow_const,
|
||||||
|
int store_pri,int store_alt,int *ispushed)
|
||||||
{
|
{
|
||||||
int tok,index,ident,close;
|
int tok,index,ident,close;
|
||||||
cell cidx,val,length;
|
cell cidx,val,length;
|
||||||
@ -6123,6 +6124,8 @@ invalid_lvalue:
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
} /* if */
|
} /* if */
|
||||||
markusage(sym,uREAD | uWRITTEN);
|
markusage(sym,uREAD | uWRITTEN);
|
||||||
|
if (!allow_const && (sym->usage & uCONST)!=0)
|
||||||
|
goto invalid_lvalue;
|
||||||
|
|
||||||
p->type=eotNUMBER;
|
p->type=eotNUMBER;
|
||||||
switch (sym->ident)
|
switch (sym->ident)
|
||||||
@ -6458,7 +6461,8 @@ static void SC_FASTCALL emit_param_integer(emit_outval *p)
|
|||||||
emit_param_any_internal(p,tNUMBER,FALSE,TRUE);
|
emit_param_any_internal(p,tNUMBER,FALSE,TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SC_FASTCALL emit_param_index(emit_outval *p,int isrange,const cell *valid_values,int numvalues)
|
static void SC_FASTCALL emit_param_index(emit_outval *p,int isrange,
|
||||||
|
const cell *valid_values,int numvalues)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
cell val;
|
cell val;
|
||||||
@ -7097,7 +7101,7 @@ static void SC_FASTCALL emit_do_stor_u_pri_alt(char *name)
|
|||||||
int ident,islocal,ispushed;
|
int ident,islocal,ispushed;
|
||||||
|
|
||||||
reg=emit_findreg(name);
|
reg=emit_findreg(name);
|
||||||
if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,(reg==sPRI),(reg==sALT),&ispushed))
|
if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,(reg==sPRI),(reg==sALT),&ispushed))
|
||||||
return;
|
return;
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
case iVARIABLE:
|
case iVARIABLE:
|
||||||
@ -7133,7 +7137,7 @@ static void SC_FASTCALL emit_do_addr_u_pri_alt(char *name)
|
|||||||
int ident,islocal;
|
int ident,islocal;
|
||||||
|
|
||||||
reg=emit_findreg(name);
|
reg=emit_findreg(name);
|
||||||
if (!emit_getlval(&ident,&p[0],&islocal,reg,TRUE,FALSE,FALSE,NULL))
|
if (!emit_getlval(&ident,&p[0],&islocal,reg,TRUE,TRUE,FALSE,FALSE,NULL))
|
||||||
return;
|
return;
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
case iVARIABLE:
|
case iVARIABLE:
|
||||||
@ -7184,7 +7188,7 @@ static void SC_FASTCALL emit_do_push_u_adr(char *name)
|
|||||||
emit_outval p[1];
|
emit_outval p[1];
|
||||||
int ident,islocal;
|
int ident,islocal;
|
||||||
|
|
||||||
if (!emit_getlval(&ident,&p[0],&islocal,sPRI,FALSE,FALSE,FALSE,NULL))
|
if (!emit_getlval(&ident,&p[0],&islocal,sPRI,FALSE,TRUE,FALSE,FALSE,NULL))
|
||||||
return;
|
return;
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
case iVARIABLE:
|
case iVARIABLE:
|
||||||
@ -7208,7 +7212,7 @@ static void SC_FASTCALL emit_do_zero_u(char *name)
|
|||||||
emit_outval p[1];
|
emit_outval p[1];
|
||||||
int ident,islocal;
|
int ident,islocal;
|
||||||
|
|
||||||
if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,FALSE,NULL))
|
if (!emit_getlval(&ident,&p[0],&islocal,sALT,TRUE,FALSE,FALSE,FALSE,NULL))
|
||||||
return;
|
return;
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
case iVARIABLE:
|
case iVARIABLE:
|
||||||
@ -7240,7 +7244,7 @@ static void SC_FASTCALL emit_do_inc_dec_u(char *name)
|
|||||||
|
|
||||||
assert(strcmp(name,"inc.u")==0 || strcmp(name,"dec.u")==0);
|
assert(strcmp(name,"inc.u")==0 || strcmp(name,"dec.u")==0);
|
||||||
|
|
||||||
if (!emit_getlval(&ident,&p[0],&islocal,sPRI,TRUE,FALSE,FALSE,NULL))
|
if (!emit_getlval(&ident,&p[0],&islocal,sPRI,TRUE,FALSE,FALSE,FALSE,NULL))
|
||||||
return;
|
return;
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
case iVARIABLE:
|
case iVARIABLE:
|
||||||
@ -7445,7 +7449,6 @@ static int emit_findopcode(const char *instr)
|
|||||||
high=(sizeof emit_opcodelist / sizeof emit_opcodelist[0])-1;
|
high=(sizeof emit_opcodelist / sizeof emit_opcodelist[0])-1;
|
||||||
while (low<high) {
|
while (low<high) {
|
||||||
mid=(low+high)/2;
|
mid=(low+high)/2;
|
||||||
assert(emit_opcodelist[mid].name!=NULL);
|
|
||||||
cmp=strcmp(instr,emit_opcodelist[mid].name);
|
cmp=strcmp(instr,emit_opcodelist[mid].name);
|
||||||
if (cmp>0)
|
if (cmp>0)
|
||||||
low=mid+1;
|
low=mid+1;
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
const global_const = 0;
|
const global_const = 0;
|
||||||
new stock global_var = 0;
|
new stock global_var = 0;
|
||||||
new stock global_array[2];
|
new stock global_array[2];
|
||||||
|
new stock const global_const_var = 0;
|
||||||
forward global_func(); public global_func() { return 0; }
|
forward global_func(); public global_func() { return 0; }
|
||||||
native global_native(const string[]) = print;
|
native global_native(const string[]) = print;
|
||||||
|
@ -9,17 +9,18 @@ __emit_p6.pwn(45) : error 022: must be lvalue (non-constant)
|
|||||||
__emit_p6.pwn(46) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(46) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(47) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(47) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(48) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(48) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(49) : error 033: array must be indexed (variable "local_array")
|
__emit_p6.pwn(49) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(50) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p6.pwn(50) : error 033: array must be indexed (variable "local_array")
|
||||||
__emit_p6.pwn(69) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(51) : error 033: array must be indexed (variable "local_refarray")
|
||||||
__emit_p6.pwn(70) : error 022: must be lvalue (non-constant)
|
|
||||||
__emit_p6.pwn(71) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(71) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(72) : error 022: must be lvalue (non-constant)
|
__emit_p6.pwn(72) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(73) : error 033: array must be indexed (variable "local_array")
|
__emit_p6.pwn(73) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(74) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p6.pwn(74) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p6.pwn(96) : error 076: syntax error in the expression, or invalid function call
|
__emit_p6.pwn(75) : error 033: array must be indexed (variable "local_array")
|
||||||
__emit_p6.pwn(97) : error 076: syntax error in the expression, or invalid function call
|
__emit_p6.pwn(76) : error 033: array must be indexed (variable "local_refarray")
|
||||||
__emit_p6.pwn(98) : error 033: array must be indexed (variable "local_array")
|
__emit_p6.pwn(98) : error 076: syntax error in the expression, or invalid function call
|
||||||
__emit_p6.pwn(99) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p6.pwn(99) : error 076: syntax error in the expression, or invalid function call
|
||||||
|
__emit_p6.pwn(100) : error 033: array must be indexed (variable "local_array")
|
||||||
|
__emit_p6.pwn(101) : error 033: array must be indexed (variable "local_refarray")
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ stock test__op_stor_u_pri_alt(&local_refvar, local_refarray[])
|
|||||||
emit stor.u.pri global_const;
|
emit stor.u.pri global_const;
|
||||||
emit stor.u.pri global_func;
|
emit stor.u.pri global_func;
|
||||||
emit stor.u.pri global_native;
|
emit stor.u.pri global_native;
|
||||||
|
emit stor.u.pri global_const_var;
|
||||||
emit stor.u.pri local_const;
|
emit stor.u.pri local_const;
|
||||||
emit stor.u.pri local_array;
|
emit stor.u.pri local_array;
|
||||||
emit stor.u.pri local_refarray;
|
emit stor.u.pri local_refarray;
|
||||||
@ -59,6 +60,7 @@ stock test__op_addr_u_pri_alt(&local_refvar, local_refarray[])
|
|||||||
|
|
||||||
// ok
|
// ok
|
||||||
emit addr.u.pri global_var;
|
emit addr.u.pri global_var;
|
||||||
|
emit addr.u.pri global_const_var;
|
||||||
emit addr.u.pri local_var;
|
emit addr.u.pri local_var;
|
||||||
emit addr.u.pri local_static_var;
|
emit addr.u.pri local_static_var;
|
||||||
emit addr.u.pri local_refvar;
|
emit addr.u.pri local_refvar;
|
||||||
@ -104,7 +106,7 @@ main()
|
|||||||
{
|
{
|
||||||
new t, a[2];
|
new t, a[2];
|
||||||
test__op_load_u_pri_alt(t, a); // 4
|
test__op_load_u_pri_alt(t, a); // 4
|
||||||
test__op_stor_u_pri_alt(t, a); // 6
|
test__op_stor_u_pri_alt(t, a); // 7
|
||||||
test__op_addr_u_pri_alt(t, a); // 6
|
test__op_addr_u_pri_alt(t, a); // 6
|
||||||
test__push_u(t, a); // 4
|
test__push_u(t, a); // 4
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
{
|
{
|
||||||
'test_type': 'output_check',
|
'test_type': 'output_check',
|
||||||
'errors': """
|
'errors': """
|
||||||
__emit_p7.pwn(20) : error 022: must be lvalue (non-constant)
|
|
||||||
__emit_p7.pwn(21) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(21) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(22) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(22) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(23) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(23) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(24) : error 033: array must be indexed (variable "local_array")
|
__emit_p7.pwn(24) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(25) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p7.pwn(25) : error 033: array must be indexed (variable "local_array")
|
||||||
__emit_p7.pwn(26) : error 035: argument type mismatch (argument 1)
|
__emit_p7.pwn(26) : error 033: array must be indexed (variable "local_refarray")
|
||||||
__emit_p7.pwn(27) : error 035: argument type mismatch (argument 1)
|
__emit_p7.pwn(27) : error 035: argument type mismatch (argument 1)
|
||||||
__emit_p7.pwn(46) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(28) : error 035: argument type mismatch (argument 1)
|
||||||
__emit_p7.pwn(47) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(47) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(48) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(48) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(49) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(49) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(50) : error 033: array must be indexed (variable "local_array")
|
__emit_p7.pwn(50) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(51) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p7.pwn(51) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(70) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(52) : error 033: array must be indexed (variable "local_array")
|
||||||
__emit_p7.pwn(71) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(53) : error 033: array must be indexed (variable "local_refarray")
|
||||||
__emit_p7.pwn(72) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(72) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(73) : error 022: must be lvalue (non-constant)
|
__emit_p7.pwn(73) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(74) : error 033: array must be indexed (variable "local_array")
|
__emit_p7.pwn(74) : error 022: must be lvalue (non-constant)
|
||||||
__emit_p7.pwn(75) : error 033: array must be indexed (variable "local_refarray")
|
__emit_p7.pwn(75) : error 022: must be lvalue (non-constant)
|
||||||
|
__emit_p7.pwn(76) : error 022: must be lvalue (non-constant)
|
||||||
|
__emit_p7.pwn(77) : error 033: array must be indexed (variable "local_array")
|
||||||
|
__emit_p7.pwn(78) : error 033: array must be indexed (variable "local_refarray")
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ stock test__push_u_adr(&local_refvar, local_refarray[])
|
|||||||
|
|
||||||
// ok
|
// ok
|
||||||
emit push.u.adr global_var;
|
emit push.u.adr global_var;
|
||||||
|
emit push.u.adr global_const_var;
|
||||||
emit push.u.adr local_refvar;
|
emit push.u.adr local_refvar;
|
||||||
emit push.u.adr local_var;
|
emit push.u.adr local_var;
|
||||||
emit push.u.adr local_static_var;
|
emit push.u.adr local_static_var;
|
||||||
@ -46,6 +47,7 @@ stock test__zero_u(&local_refvar, local_refarray[])
|
|||||||
emit zero.u global_const;
|
emit zero.u global_const;
|
||||||
emit zero.u global_func;
|
emit zero.u global_func;
|
||||||
emit zero.u global_native;
|
emit zero.u global_native;
|
||||||
|
emit zero.u global_const_var;
|
||||||
emit zero.u local_const;
|
emit zero.u local_const;
|
||||||
emit zero.u local_array;
|
emit zero.u local_array;
|
||||||
emit zero.u local_refarray;
|
emit zero.u local_refarray;
|
||||||
@ -70,6 +72,7 @@ stock test__inc_dec_u(&local_refvar, local_refarray[])
|
|||||||
emit inc.u global_const;
|
emit inc.u global_const;
|
||||||
emit inc.u global_func;
|
emit inc.u global_func;
|
||||||
emit inc.u global_native;
|
emit inc.u global_native;
|
||||||
|
emit inc.u global_const_var;
|
||||||
emit inc.u local_const;
|
emit inc.u local_const;
|
||||||
emit inc.u local_array;
|
emit inc.u local_array;
|
||||||
emit inc.u local_refarray;
|
emit inc.u local_refarray;
|
||||||
@ -80,6 +83,6 @@ main()
|
|||||||
{
|
{
|
||||||
new t, a[2];
|
new t, a[2];
|
||||||
test__push_u_adr(t, a); // 8
|
test__push_u_adr(t, a); // 8
|
||||||
test__zero_u(t, a); // 6
|
test__zero_u(t, a); // 7
|
||||||
test__inc_dec_u(t, a); // 6
|
test__inc_dec_u(t, a); // 7
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user