#include "cgstd.h" #include "cgdebug.h" #include "cgmodule_ppc.h" CGModule_PPC::CGModule_PPC( ostream &o ):CGModule(o),fp_const(0){ } void CGModule_PPC::setSeg( string t ){ if( t==seg ) return; seg=t; out<<"\t."<(f); assert(frame); setSeg( "text" ); //find callee-save regs int k,max_int=12,max_flt=13; for( k=64;kregs.size();++k ){ CGReg *r=frame->regs[k]; if( r->isfloat() ){ if( r->color>=14 && r->color<=31 && r->color>max_flt ) max_flt=r->color; }else{ if( r->color>=13 && r->color<=31 && r->color>max_int ) max_int=r->color; } } int int_save=max_int-12; int flt_save=max_flt-13; int save_sz=int_save*4+flt_save*8; int stack_sz=24+frame->param_sz+frame->local_sz+save_sz; stack_sz=(stack_sz+15)&~15; //emit label out<fun->sym->value<<":\n"; //setup frames out<<"__LOCAL="<<(24+frame->param_sz)<<'\n'; out<<"__FRAME="<assem.begin;as!=frame->assem.end;as=as->succ ){ if( as->stm->ret() ){ out<<"\tlwz\tr1,0(r1)\n"; out<<"\tlwz\tr0,8(r1)\n"; out<<"\tmtlr\tr0\n"; //restore int regs if( int_save ){ out<<"\tlmw\tr"<<(32-int_save)<<","<<(-save_sz)<<"(r1)\n"; } //restore float regs for( int k=flt_save-1;k>=0;--k ){ out<<"\tlfd\tf"<<(k+14)<<","<<(-save_sz+int_save*4+k*8)<<"(r1)\n"; } } const char *p=as->assem; if( !p ) continue; out<value<<":\n"; for( int k=0;kexps.size();++k ){ CGExp *e=d->exps[k]; if( CGLit *t=e->lit() ){ if( t->type==CG_INT8 ){ out<<"\t.byte\t"<int_value)<<'\n'; }else if( t->type==CG_INT16 ){ out<<"\t.short\t"<int_value)<<'\n'; }else if( t->type==CG_INT32 ){ out<<"\t.long\t"<int_value)<<'\n'; }else if( t->type==CG_INT64 ){ out<<"\t.long\t"<int_value>>int64(32))<<','<int_value)<<'\n'; }else if( t->type==CG_FLOAT32 ){ float f=t->float_value; out<<"\t.long\t0x"<type==CG_FLOAT64 ){ double f=t->float_value; out<<"\t.long\t0x"<type==CG_CSTRING ){ bstring s=t->string_value; out<<"\t.asciz\t\""; for( int k=0;ktype==CG_BSTRING ){ bstring s=t->string_value; out<<"\t.long\t"<type==CG_BINFILE ){ string file=tostring(t->string_value); ifstream is( file.c_str() ); if( !is.good() ) fail( "Unable to read from file '%s'",file.c_str() ); for(;;){ char buf[16]; is.read( buf,16 ); int n=is.gcount(); if( !n ) break; out<<"\t.byte\t"; for( int k=0;ktype==CG_LABEL ){ out<string_value)<<":\n"; }else{ assert(0); } }else if( CGSym *t=e->sym() ){ out<<"\t.long\t"<value<<'\n'; }else if( CGLea *t=e->lea() ){ CGMem *m=t->exp->mem(); assert(m); if( m->flags==1 ){ //PARAM }else if( m->flags==2 ){ //LOCAL out<<"\t.long\t"<offset<<'\n'; }else if( CGSym *t=m->exp->sym() ){ assert(t); if( m->offset ){ out<<"\t.long\t"<value<<'+'<offset<<'\n'; }else{ out<<"\t.long\t"<value<<'\n'; } }else{ assert(0); } }else{ cout<value<<":\n"; out<<"\t.double\t0r4.50360177485414400000e15\n"; } }