evalop: addressing mode
This commit is contained in:
parent
9323ccd77e
commit
468a4232af
24
gen.c
24
gen.c
@ -819,6 +819,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
eval_elem tmpelem={0};
|
||||
size_t opos=0;
|
||||
uint32_t res=0;
|
||||
uint32_t addrmode=0;
|
||||
|
||||
// TODO: refactor this function to be smarter,
|
||||
// removing special cases and pendantic-ness
|
||||
@ -881,6 +882,10 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
}
|
||||
|
||||
// Set up addressing mode
|
||||
addrmode=AM(elem[0].type,elem[1].type);
|
||||
/* printf("addrmode: %x (%x) (%x)\n",addrmode,elem[0].type,elem[1].type); */
|
||||
|
||||
// UNARY OPS
|
||||
if(nops==1)
|
||||
{
|
||||
@ -920,7 +925,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// INT OP INT
|
||||
else if(elem[0].type==EE_I32&&elem[1].type==EE_I32)
|
||||
else if(addrmode==AM(EE_I32,EE_I32))
|
||||
{
|
||||
switch(curtok->subtype)
|
||||
{
|
||||
@ -937,10 +942,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
|
||||
// INT OP ACC
|
||||
// ACC OP INT
|
||||
else if(
|
||||
(elem[0].type==EE_ACC && elem[1].type==EE_I32) ||
|
||||
(elem[0].type==EE_I32 && elem[1].type==EE_ACC)
|
||||
)
|
||||
else if(addrmode==AM(EE_I32,EE_ACC)||addrmode==AM(EE_ACC,EE_I32))
|
||||
{
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
|
||||
@ -980,7 +982,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// INT OP IDENT
|
||||
else if(elem[0].type==EE_VAR && elem[1].type==EE_I32)
|
||||
else if(addrmode==AM(EE_VAR,EE_I32))
|
||||
{
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
|
||||
@ -1010,7 +1012,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// IDENT OP INT
|
||||
else if(elem[0].type==EE_I32 && elem[1].type==EE_VAR)
|
||||
else if(addrmode==AM(EE_I32,EE_VAR))
|
||||
{
|
||||
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
@ -1043,7 +1045,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// IDENT OP IDENT
|
||||
else if(elem[0].type==EE_VAR && elem[1].type==EE_VAR)
|
||||
else if(addrmode==AM(EE_VAR,EE_VAR))
|
||||
{
|
||||
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
@ -1076,7 +1078,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// IDENT OP ACC
|
||||
else if(elem[1].type==EE_ACC && elem[0].type==EE_VAR)
|
||||
else if(addrmode==AM(EE_VAR,EE_ACC))
|
||||
{
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
|
||||
@ -1101,7 +1103,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// I32 OP ACC
|
||||
else if(elem[1].type==EE_ACC && elem[0].type==EE_I32)
|
||||
else if(addrmode==AM(EE_ACC,EE_I32))
|
||||
{
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
|
||||
@ -1130,7 +1132,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
|
||||
// ACC OP IDENT
|
||||
else if(elem[1].type==EE_VAR && elem[0].type==EE_ACC)
|
||||
else if(addrmode==AM(EE_ACC,EE_VAR))
|
||||
{
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
|
||||
|
6
gen.h
6
gen.h
@ -11,7 +11,7 @@
|
||||
#include"x86_64.h"
|
||||
|
||||
// Build architecture types
|
||||
enum {M_I386,M_IR,M_RUN,M_X86_64};
|
||||
enum {M_I386=1,M_IR,M_RUN,M_X86_64};
|
||||
|
||||
typedef struct Gen
|
||||
{
|
||||
@ -23,8 +23,8 @@ typedef struct Gen
|
||||
bool showeval;
|
||||
} Gen;
|
||||
|
||||
// Type of elements in evaluation of RPN Vec
|
||||
enum EVAL_ELEM_TYPE {EE_I32,EE_IDENT,EE_VAR,EE_FUNC,EE_ACC};
|
||||
#define AM(x,y) ((((uint32_t)(x&0xff))<<8)|(y&0xff))
|
||||
enum EVAL_ELEM_TYPE {EE_I32=1,EE_IDENT,EE_VAR,EE_FUNC,EE_ACC};
|
||||
typedef struct eval_elem
|
||||
{
|
||||
size_t type;
|
||||
|
Loading…
Reference in New Issue
Block a user