evalop: set up for mul, div operations
This commit is contained in:
parent
f479dcb5b5
commit
b7f2655916
39
gen.c
39
gen.c
@ -846,15 +846,15 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
/* printf("[[[%d+%d=%d]]]\n",elem[1].val.i32,elem[0].val.i32,elem[1].val.i32+elem[0].val.i32); */
|
||||
|
||||
// Convert operator name to instruction name
|
||||
if(strcmp("+",curtok->str.buffer)==0)
|
||||
if(curtok->subtype==LADD)
|
||||
sprintf(operator,"addl");
|
||||
else if(strcmp("-",curtok->str.buffer)==0)
|
||||
else if(curtok->subtype==LSMINUS)
|
||||
sprintf(operator,"subl");
|
||||
else if(strcmp("*",curtok->str.buffer)==0)
|
||||
else if(curtok->subtype==LSMUL)
|
||||
sprintf(operator,"imull");
|
||||
else if(strcmp("/",curtok->str.buffer)==0)
|
||||
else if(curtok->subtype==LSDIV)
|
||||
sprintf(operator,"idivl");
|
||||
else if(strcmp("=",curtok->str.buffer)==0)
|
||||
else if(curtok->subtype==LASSIGN)
|
||||
sprintf(operator,"movl");
|
||||
|
||||
// Print output
|
||||
@ -871,6 +871,16 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
}
|
||||
}
|
||||
|
||||
// Set up for multiply/divide instructions
|
||||
if(curtok->subtype==LSDIV||curtok->subtype==LSMUL)
|
||||
{
|
||||
if(!(elem[0].type==EE_I32&&elem[0].type==EE_I32))
|
||||
{
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
/* opos+=sprintf(output_buffer+opos,"\tmovl %s,%%%s\n",operands[1],ld.scratch1); */
|
||||
}
|
||||
}
|
||||
|
||||
// UNARY OPS
|
||||
if(nops==1)
|
||||
{
|
||||
@ -926,6 +936,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)
|
||||
@ -963,14 +974,12 @@ 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,"\txorl %%edx,%%edx\n");
|
||||
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,"\txorl %%edx,%%edx\n");
|
||||
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);
|
||||
@ -1004,7 +1013,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,"\txorl %%edx,%%edx\n");
|
||||
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);
|
||||
@ -1012,9 +1020,8 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
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,"\tmovl %s,%%eax\n",operands[0]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%%s\n",operator,ld.scratch1);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
@ -1050,7 +1057,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,"\txorl %%edx,%%edx\n");
|
||||
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);
|
||||
@ -1058,9 +1064,8 @@ void gen_evalop(Gen*gen,PNode*pn,eval_elem*elem,size_t nops,Tok*curtok,FILE*file
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
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,"\tmovl %s,%%eax\n",operands[1]);
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %%%s\n",operator,ld.scratch1);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
@ -1096,14 +1101,12 @@ 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,"\txorl %%edx,%%edx\n");
|
||||
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,"\txorl %%edx,%%edx\n");
|
||||
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);
|
||||
@ -1137,13 +1140,11 @@ 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,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
@ -1176,13 +1177,11 @@ 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,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[0]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
@ -1215,13 +1214,11 @@ 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,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
||||
case LSDIV:
|
||||
opos+=sprintf(output_buffer+opos,"\txorl %%edx,%%edx\n");
|
||||
opos+=sprintf(output_buffer+opos,"\t%s %s\n",operator,operands[1]);
|
||||
vec_push(stack,&tmpelem);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user