combine similar eval ops
This commit is contained in:
parent
b7f2655916
commit
9323ccd77e
93
gen.c
93
gen.c
@ -867,7 +867,7 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
|
||||
// Move result to accumulator
|
||||
if(elem[1].type!=EE_ACC)
|
||||
printf("%s %s, %%eax\n",ld.mov_32,operands[0]);
|
||||
printf("%s %s, %s\n",ld.mov_32,operands[0],operands[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -887,17 +887,17 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
switch(curtok->subtype)
|
||||
{
|
||||
case LSNOT:
|
||||
if(elem[0].type==EE_VAR)
|
||||
switch(elem[0].type)
|
||||
case EE_VAR:
|
||||
{
|
||||
opos+=sprintf(output_buffer+opos,"\tcmpl $0,%s\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\tsete %%al\n");
|
||||
opos+=sprintf(output_buffer+opos,"\tmovzbl %%al,%%eax\n");
|
||||
/* opos+=sprintf(output_buffer+opos,"\tmovl %%eax,-%lu(%%%s)\n",elem[0].vstackloc,ld.bp); */
|
||||
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
vec_push(stack,&tmpelem);
|
||||
}
|
||||
else if(elem[0].type==EE_I32)
|
||||
break;
|
||||
case EE_I32:
|
||||
{
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl $%s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\tcmpl $0,%%eax\n");
|
||||
@ -906,12 +906,12 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
vec_push(stack,&tmpelem);
|
||||
}
|
||||
else if(elem[0].type==EE_ACC)
|
||||
break;
|
||||
case EE_ACC:
|
||||
{
|
||||
opos+=sprintf(output_buffer+opos,"\tcmpl $0,%%eax\n");
|
||||
opos+=sprintf(output_buffer+opos,"\tsete %%al\n");
|
||||
opos+=sprintf(output_buffer+opos,"\tmovzbl %%al,%%eax\n");
|
||||
//opos+=sprintf(output_buffer+opos,"\tmovl %%eax,-%lu(%%%s)\n",elem[0].vstackloc,ld.bp);
|
||||
tmpelem=(eval_elem){.type=EE_ACC,.val={0}};
|
||||
vec_push(stack,&tmpelem);
|
||||
}
|
||||
@ -964,21 +964,12 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[1],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%%s\n",operator,ld.scratch1);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[1],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%%s\n",operator,ld.scratch1);
|
||||
@ -1001,11 +992,6 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
@ -1013,12 +999,6 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[1],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%%s\n",operator,ld.scratch1);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[1],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[0]);
|
||||
@ -1045,11 +1025,6 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
@ -1057,12 +1032,6 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[0],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\timul %%%s\n",ld.scratch1);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[0],ld.scratch1);
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
@ -1084,16 +1053,11 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
|
||||
case LASSIGN:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %%eax,%s\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%eax,%s\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
@ -1101,11 +1065,6 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
@ -1125,25 +1084,13 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
{
|
||||
|
||||
case LASSIGN:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %%eax,%s\n",operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%s\n",operator,operands[0],operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
@ -1167,20 +1114,12 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%s\n",operator,operands[0],operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
@ -1199,25 +1138,17 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
{
|
||||
|
||||
case LASSIGN:
|
||||
opos+=sprintf(output_buffer+opos,"\tmovl %%eax,%s\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%s\n",operator,operands[0],operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LADD:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMINUS:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%%eax\n",operator,operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s,%s\n",operator,operands[1],operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSMUL:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
|
Loading…
Reference in New Issue
Block a user