Uh, Updates?

This commit is contained in:
Michael Fabian Dirks
2016-10-03 17:11:15 +02:00
parent aa3cf453e5
commit 581c640149
62 changed files with 469 additions and 489 deletions
+45 -45
View File
@@ -107,7 +107,7 @@ Tile *Codegen_x86::genCompare( TNode *t,string &func,bool negate ){
}
}
return d_new Tile( q,ql ? munchReg( ql ) : 0,qr ? munchReg( qr ) : 0 );
return new Tile( q,ql ? munchReg( ql ) : 0,qr ? munchReg( qr ) : 0 );
}
////////////////////////////////////////////////
@@ -119,7 +119,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){
case IR_NEG:s="\tneg\t%l\n";break;
default:return 0;
}
return d_new Tile( s,munchReg( t->l ) );
return new Tile( s,munchReg( t->l ) );
}
Tile *Codegen_x86::munchLogical( TNode *t ){
@@ -130,7 +130,7 @@ Tile *Codegen_x86::munchLogical( TNode *t ){
case IR_XOR:s="\txor\t%l,%r\n";break;
default:return 0;
}
return d_new Tile( s,munchReg( t->l ),munchReg( t->r ) );
return new Tile( s,munchReg( t->l ),munchReg( t->r ) );
}
Tile *Codegen_x86::munchArith( TNode *t ){
@@ -139,10 +139,10 @@ Tile *Codegen_x86::munchArith( TNode *t ){
int shift;
if( t->r->op==IR_CONST ){
if( getShift( t->r->iconst,shift ) ){
return d_new Tile( "\tsar\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
return new Tile( "\tsar\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
}
}
Tile *q=d_new Tile( "\tcdq\n\tidiv\tecx\n",munchReg( t->l ),munchReg( t->r ) );
Tile *q=new Tile( "\tcdq\n\tidiv\tecx\n",munchReg( t->l ),munchReg( t->r ) );
q->want_l=EAX;q->want_r=ECX;q->hits=1<<EDX;
return q;
}
@@ -151,11 +151,11 @@ Tile *Codegen_x86::munchArith( TNode *t ){
int shift;
if( t->r->op==IR_CONST ){
if( getShift( t->r->iconst,shift ) ){
return d_new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
return new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->l ) );
}
}else if( t->l->op==IR_CONST ){
if( getShift( t->l->iconst,shift ) ){
return d_new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->r ) );
return new Tile( "\tshl\t%l,byte "+itoa(shift)+"\n",munchReg( t->r ) );
}
}
}
@@ -169,12 +169,12 @@ Tile *Codegen_x86::munchArith( TNode *t ){
}
if( matchMEMCONST( t->r,s ) ){
return d_new Tile( op+"%l,"+s+"\n",munchReg( t->l ) );
return new Tile( op+"%l,"+s+"\n",munchReg( t->l ) );
}
if( t->op!=IR_SUB && matchMEMCONST( t->l,s ) ){
return d_new Tile( op+"%l,"+s+"\n",munchReg( t->r ) );
return new Tile( op+"%l,"+s+"\n",munchReg( t->r ) );
}
return d_new Tile( op+"%l,%r\n",munchReg( t->l ),munchReg( t->r ) );
return new Tile( op+"%l,%r\n",munchReg( t->l ),munchReg( t->r ) );
}
Tile *Codegen_x86::munchShift( TNode *t ){
@@ -187,10 +187,10 @@ Tile *Codegen_x86::munchShift( TNode *t ){
}
if( matchCONST( t->r,s ) ){
return d_new Tile( op+"%l,byte "+s+"\n",munchReg( t->l ) );
return new Tile( op+"%l,byte "+s+"\n",munchReg( t->l ) );
}
Tile *q=d_new Tile( op+"%l,cl\n",munchReg( t->l ),munchReg( t->r ) );
Tile *q=new Tile( op+"%l,cl\n",munchReg( t->l ),munchReg( t->r ) );
q->want_r=ECX;return q;
}
@@ -198,7 +198,7 @@ Tile *Codegen_x86::munchRelop( TNode *t ){
string func;
Tile *q=genCompare( t,func,false );
q=d_new Tile( "\tset"+func+"\tal\n\tmovzx\teax,al\n",q );
q=new Tile( "\tset"+func+"\tal\n\tmovzx\teax,al\n",q );
q->want_l=EAX;
return q;
}
@@ -212,7 +212,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){
case IR_FNEG:s="\tfchs\n";break;
default:return 0;
}
return d_new Tile( s,munchFP( t->l ) );
return new Tile( s,munchFP( t->l ) );
}
Tile *Codegen_x86::munchFPArith( TNode *t ){
@@ -224,7 +224,7 @@ Tile *Codegen_x86::munchFPArith( TNode *t ){
case IR_FDIV:s="\tfdivrp\tst(1)\n";s2="\tfdivp\tst(1)\n";break;
default:return 0;
}
return d_new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
return new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
}
Tile *Codegen_x86::munchFPRelop( TNode *t ){
@@ -240,7 +240,7 @@ Tile *Codegen_x86::munchFPRelop( TNode *t ){
}
s="\tfucompp\n\tfnstsw\tax\n\tsahf\n\tset"+s+"\tal\n\tmovzx\t%l,al\n";
s2="\tfucompp\n\tfnstsw\tax\n\tsahf\n\tset"+s2+"\tal\n\tmovzx\t%l,al\n";
Tile *q=d_new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
Tile *q=new Tile( s,s2,munchFP( t->l ),munchFP( t->r ) );
q->want_l=EAX;
return q;
}
@@ -251,9 +251,9 @@ Tile *Codegen_x86::munchFPRelop( TNode *t ){
Tile *Codegen_x86::munchCall( TNode *t ){
Tile *q;
if( t->l->op==IR_GLOBAL ){
q=d_new Tile( "\tcall\t"+t->l->sconst+"\n",t->r ? munchReg( t->r ) : 0 );
q=new Tile( "\tcall\t"+t->l->sconst+"\n",t->r ? munchReg( t->r ) : 0 );
}else{
q=d_new Tile( "\tcall\t%l\n",munchReg( t->l ),t->r ? munchReg( t->r ) : 0 );
q=new Tile( "\tcall\t%l\n",munchReg( t->l ),t->r ? munchReg( t->r ) : 0 );
}
q->argFrame=t->iconst;
q->want_l=EAX;
@@ -270,26 +270,26 @@ Tile *Codegen_x86::munch( TNode *t ){
string s;
switch( t->op ){
case IR_JSR:
q=d_new Tile( "\tcall\t"+t->sconst+'\n' );
q=new Tile( "\tcall\t"+t->sconst+'\n' );
break;
case IR_RET:
q=d_new Tile( "\tret\n" );
q=new Tile( "\tret\n" );
break;
case IR_RETURN:
q=munchReg( t->l );q->want_l=EAX;
s="\tjmp\t"+t->sconst+'\n';
q=d_new Tile( s,q );
q=new Tile( s,q );
break;
case IR_FRETURN:
q=munchFP( t->l );
s="\tjmp\t"+t->sconst+'\n';
q=d_new Tile( s,q );
q=new Tile( s,q );
break;
case IR_CALL:
q=munchCall( t );
break;
case IR_JUMP:
q=d_new Tile( "\tjmp\t"+t->sconst+'\n' );
q=new Tile( "\tjmp\t"+t->sconst+'\n' );
break;
case IR_JUMPT:
if( TNode *p=t->l ){
@@ -297,7 +297,7 @@ Tile *Codegen_x86::munch( TNode *t ){
if( isRelop( p->op ) ){
string func;
q=genCompare( p,func,neg );
q=d_new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
q=new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
}
}
break;
@@ -307,7 +307,7 @@ Tile *Codegen_x86::munch( TNode *t ){
if( isRelop( p->op ) ){
string func;
q=genCompare( p,func,neg );
q=d_new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
q=new Tile( "\tj"+func+"\t"+t->sconst+"\n",q );
}
}
break;
@@ -315,7 +315,7 @@ Tile *Codegen_x86::munch( TNode *t ){
if( matchMEM( t->r,s ) ){
string c;
if( matchCONST( t->l,c ) ){
q=d_new Tile( "\tmov\t"+s+","+c+"\n" );
q=new Tile( "\tmov\t"+s+","+c+"\n" );
}else if( t->l->op==IR_ADD || t->l->op==IR_SUB ){
TNode *p=0;
if( nodesEqual( t->l->l,t->r ) ) p=t->l->r;
@@ -327,13 +327,13 @@ Tile *Codegen_x86::munch( TNode *t ){
case IR_SUB:op="\tsub\t";break;
}
if( matchCONST( p,c ) ){
q=d_new Tile( op+s+","+c+"\n" );
q=new Tile( op+s+","+c+"\n" );
}else{
q=d_new Tile( op+s+",%l\n",munchReg( p ) );
q=new Tile( op+s+",%l\n",munchReg( p ) );
}
}
}
if( !q ) q=d_new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
if( !q ) q=new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
}
break;
}
@@ -352,13 +352,13 @@ Tile *Codegen_x86::munchReg( TNode *t ){
switch( t->op ){
case IR_JUMPT:
q=d_new Tile( "\tand\t%l,%l\n\tjnz\t"+t->sconst+'\n',munchReg( t->l ) );
q=new Tile( "\tand\t%l,%l\n\tjnz\t"+t->sconst+'\n',munchReg( t->l ) );
break;
case IR_JUMPF:
q=d_new Tile( "\tand\t%l,%l\n\tjz\t"+t->sconst+'\n',munchReg( t->l ) );
q=new Tile( "\tand\t%l,%l\n\tjz\t"+t->sconst+'\n',munchReg( t->l ) );
break;
case IR_JUMPGE:
q=d_new Tile( "\tcmp\t%l,%r\n\tjnc\t"+t->sconst+'\n',munchReg( t->l ),munchReg( t->r ) );
q=new Tile( "\tcmp\t%l,%r\n\tjnc\t"+t->sconst+'\n',munchReg( t->l ),munchReg( t->r ) );
break;
case IR_CALL:
q=munchCall( t );
@@ -366,37 +366,37 @@ Tile *Codegen_x86::munchReg( TNode *t ){
case IR_MOVE:
//MUST BE MOVE TO MEM!
if( matchMEM( t->r,s ) ){
q=d_new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
q=new Tile( "\tmov\t"+s+",%l\n",munchReg( t->l ) );
}else if( t->r->op==IR_MEM ){
q=d_new Tile( "\tmov\t[%r],%l\n",munchReg( t->l ),munchReg( t->r->l ) );
q=new Tile( "\tmov\t[%r],%l\n",munchReg( t->l ),munchReg( t->r->l ) );
}
break;
case IR_MEM:
if( matchMEM( t,s ) ){
q=d_new Tile( "\tmov\t%l,"+s+"\n" );
q=new Tile( "\tmov\t%l,"+s+"\n" );
}else{
q=d_new Tile( "\tmov\t%l,[%l]\n",munchReg( t->l ) );
q=new Tile( "\tmov\t%l,[%l]\n",munchReg( t->l ) );
}
break;
case IR_SEQ:
q=d_new Tile( "",munch(t->l),munch(t->r) );
q=new Tile( "",munch(t->l),munch(t->r) );
break;
case IR_ARG:
q=d_new Tile( "\tlea\t%l,[esp"+itoa_sgn(t->iconst)+"]\n" );
q=new Tile( "\tlea\t%l,[esp"+itoa_sgn(t->iconst)+"]\n" );
break;
case IR_LOCAL:
q=d_new Tile( "\tlea\t%l,[ebp"+itoa_sgn(t->iconst)+"]\n" );
q=new Tile( "\tlea\t%l,[ebp"+itoa_sgn(t->iconst)+"]\n" );
break;
case IR_GLOBAL:
q=d_new Tile( string( "\tmov\t%l," )+t->sconst+'\n' );
q=new Tile( string( "\tmov\t%l," )+t->sconst+'\n' );
break;
case IR_CAST:
q=munchFP( t->l );
s="\tpush\t%l\n\tfistp\t[esp]\n\tpop\t%l\n";
q=d_new Tile( s,q );
q=new Tile( s,q );
break;
case IR_CONST:
q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" );
q=new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" );
break;
case IR_NEG:
q=munchUnary( t );
@@ -419,7 +419,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){
default:
q=munchFP( t );if( !q ) return 0;
s="\tpush\t%l\n\tfstp\t[esp]\n\tpop\t%l\n";
q=d_new Tile( s,q );
q=new Tile( s,q );
}
return q;
}
@@ -439,7 +439,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){
break;
case IR_FCAST:
s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n";
q=d_new Tile( s,munchReg( t->l ) );
q=new Tile( s,munchReg( t->l ) );
break;
case IR_FNEG:
q=munchFPUnary( t );
@@ -450,7 +450,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){
default:
q=munchReg( t );if( !q ) return 0;
s="\tpush\t%l\n\tfld\t[esp]\n\tpop\t%l\n";
q=d_new Tile( s,q );
q=new Tile( s,q );
}
return q;
}