#include "cgstd.h" #include "cgdebug.h" #include static const char *ccSym( int cc ){ switch( cc ){ case CG_EQ:return "EQ"; case CG_NE:return "NE"; case CG_LT:return "LT"; case CG_GT:return "GT"; case CG_LE:return "LE"; case CG_GE:return "GE"; case CG_LTU:return "LTU"; case CG_GTU:return "GTU"; case CG_LEU:return "LEU"; case CG_GEU:return "GEU"; } assert(0); return 0; } static const char *uopSym( int op ){ return "UOP"; } static const char *bopSym( int op ){ switch( op ){ case CG_ADD:return "add"; case CG_SUB:return "sub"; case CG_MUL:return "mul"; case CG_DIV:return "div"; case CG_MOD:return "mod"; case CG_AND:return "and"; case CG_ORL:return "orl"; case CG_XOR:return "xor"; case CG_SHL:return "shl"; case CG_SHR:return "shr"; case CG_SAR:return "sar"; } assert(0); return 0; } static const char *typeSym( int ty ){ switch( ty ){ case CG_PTR:return "PTR"; case CG_VOID:return "VOID"; case CG_INT8:return "INT8"; case CG_INT16:return "INT16"; case CG_INT32:return "INT32"; case CG_INT64:return "INT64"; case CG_FLOAT32:return "FLOAT32"; case CG_FLOAT64:return "FLOAT64"; case CG_CSTRING:return "CSTRING"; case CG_BSTRING:return "BSTRING"; } assert(0); return 0; } ostream &operator<<( ostream &o,CGStm *stm ){ if( !stm ) return o; if( CGNop *t=stm->nop() ){ o<<"nop"; }else if( CGMov *t=stm->mov() ){ o<<"mov "<lhs<<','<rhs; }else if( CGLab *t=stm->lab() ){ o<<"lab "<sym; }else if( CGBra *t=stm->bra() ){ o<<"bra "<sym; }else if( CGBcc *t=stm->bcc() ){ o<<"bcc "<cc)<<','<lhs<<','<rhs<<","<sym; }else if( CGRet *t=stm->ret() ){ o<<"ret ";if( t->exp ) o<exp; }else if( CGSeq *t=stm->seq() ){ int i; o<<"seq "; for( i=0;istms.size();++i ){ if( i ) o<<','; o<stms[i]; } }else if( CGXop *t=stm->xop() ){ o<<"xop "<op<<','<exp; }else if( CGRem *t=stm->rem() ){ o<<"rem "<comment; }else if( CGEva *t=stm->eva() ){ o<<"eva "<exp; }else if( CGAti *t=stm->ati() ){ o<<"ati "<mem; }else if( CGAtd *t=stm->atd() ){ o<<"atd "<mem<<","<sym; }else{ o<<"STM: "<type); if( CGMem *t=exp->mem() ){ o<<"mem("<exp<<','<offset<<')'; }else if( CGLea *t=exp->lea() ){ o<<"lea("<exp<<')'; }else if( CGCvt *t=exp->cvt() ){ o<<"cvt("<exp<<')'; }else if( CGUop *t=exp->uop() ){ o<op)<<'('<exp<<')'; }else if( CGBop *t=exp->bop() ){ o<op)<<'('<lhs<<','<rhs<<')'; }else if( CGJsr *t=exp->jsr() ){ o<<"jsr("<exp; for( int k=0;kargs.size();++k ) o<<','<args[k]; o<<')'; }else if( CGVfn *t=exp->vfn() ){ o<<"vfn("<exp<<','<self<<')'; }else if( CGScc *t=exp->scc() ){ o<<"scc("<lhs<<','<rhs<<')'; }else if( CGEsq *t=exp->esq() ){ o<<"esq("<lhs<<','<rhs<<')'; }else if( CGReg *t=exp->reg() ){ o<<"reg("<id<<')'; }else if( CGTmp *t=exp->tmp() ){ o<<"tmp("<ident<<')'; }else if( CGLit *t=exp->lit() ){ if( t->isfloat() ) o<float_value; else o<int_value); }else if( CGSym *t=exp->sym() ){ o<<"sym("<value<<")"; }else if( CGFrm *t=exp->frm() ){ o<<"frm"; }else{ assert(0); } return o; } ostream &operator<<( ostream &o,const CGStmSeq &seq ){ for( int k=0;ksucc ){ if( as->stm ) o<<"\t;"<stm<assem ) o<assem; } return o; } ostream &operator<<( ostream &o,const CGIntSet &t ){ CGIntSet::const_iterator it; for( it=t.begin();it!=t.end();++it ) o<<' '<<*it; return o; } ostream &operator<<( ostream &o,CGFlow *flow ){ CGBlockSeq &seq=flow->blocks; CGBlockCIter it; //enumerate blocks map blk_map; for( it=seq.begin();it!=seq.end();++it ){ blk_map[*it]=blk_map.size(); } for( it=seq.begin();it!=seq.end();++it ){ CGBlock *blk=*it; CGBlockCIter t_it; o<<"\t;---block "<use<def<live_in<live_out<succ.begin();t_it!=blk->succ.end();++t_it ) o<<' '<pred.begin();t_it!=blk->pred.end();++t_it ) o<<' '<::iterator d_it; o<<"\t;dom:"; for( d_it=blk->dom.begin();d_it!=blk->dom.end();++d_it ){ o<<' '<loops.begin();d_it!=blk->loops.end();++d_it ){ o<<' '<loop_level<begin; while( as!=blk->end ){ if( as->stm ) o<<"\t;"<stm<def.size() ) o<<"\t;def="<def<use.size() ) o<<"\t;use="<use<assem ) o<assem; as=as->succ; } o<stms.size();++k ){ o<stms[k]<