Changes in src/CodeGen/CodeGenerator.cc [de62360d:94b4364]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rde62360d r94b4364 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jun 23 16:16:57201513 // Update Count : 1 3311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jun 15 12:47:16 2015 13 // Update Count : 142 14 14 // 15 15 … … 44 44 } 45 45 46 CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { } 47 48 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indent, bool infunp ) 49 : cur_indent( indent ), insideFunction( infunp ), output( os ) { 46 ostream & CodeGenerator::Indenter::operator()( ostream & output ) { 47 return output << string( cg.cur_indent, ' ' ); 48 } 49 50 ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) { 51 return indent( output ); 52 } 53 54 CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { } 55 56 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) 57 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 50 58 //output << std::string( init ); 51 59 } 52 60 53 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent , bool infunp )54 : cur_indent( indent), insideFunction( infunp ), output( os ) {61 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp ) 62 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 55 63 //output << std::string( init ); 56 64 } … … 63 71 } // if 64 72 } 65 73 66 74 //*** Declarations 67 75 void CodeGenerator::visit( FunctionDecl *functionDecl ) { … … 69 77 if ( functionDecl->get_isInline() ) { 70 78 output << "inline "; 71 } // if72 if ( functionDecl->get_isNoreturn() ) {73 output << "_Noreturn ";74 79 } // if 75 80 output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) ); … … 108 113 109 114 if ( ! memb.empty() ) { 110 output << endl << string( cur_indent, ' ' ) << "{" << endl;115 output << " {" << endl; 111 116 112 117 cur_indent += CodeGenerator::tabsize; 113 118 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 114 output << string( cur_indent, ' ' );119 output << indent; 115 120 (*i)->accept(*this ); 116 121 output << ";" << endl; … … 119 124 cur_indent -= CodeGenerator::tabsize; 120 125 121 output << string( cur_indent, ' ' )<< "}";126 output << indent << "}"; 122 127 } // if 123 128 } … … 142 147 143 148 if ( ! memb.empty() ) { 144 output << endl << "{" << endl;149 output << " {" << endl; 145 150 146 151 cur_indent += CodeGenerator::tabsize; … … 148 153 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 149 154 assert( obj ); 150 output << string( cur_indent, ' ' )<< mangleName( obj );155 output << indent << mangleName( obj ); 151 156 if ( obj->get_init() ) { 152 157 output << " = "; … … 158 163 cur_indent -= CodeGenerator::tabsize; 159 164 160 output << "}" << endl;165 output << indent << "}"; 161 166 } // if 162 167 } … … 298 303 case OT_PREFIX: 299 304 case OT_PREFIXASSIGN: 300 case OT_LABELADDRESS:301 305 assert( untypedExpr->get_args().size() == 1 ); 302 306 output << "("; … … 322 326 output << ")"; 323 327 break; 324 328 325 329 case OT_CONSTANT: 326 330 // there are no intrinsic definitions of 0 or 1 as functions … … 449 453 450 454 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 451 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() );455 output << indent << printLabels( (*i)->get_labels() ); 452 456 (*i)->accept(*this ); 453 457 … … 459 463 cur_indent -= CodeGenerator::tabsize; 460 464 461 output << string( cur_indent, ' ' )<< "}";465 output << indent << "}"; 462 466 } 463 467 … … 499 503 cur_indent -= CodeGenerator::tabsize; 500 504 501 output << string( cur_indent, ' ' )<< "}";505 output << indent << "}"; 502 506 } 503 507 504 508 void CodeGenerator::visit( CaseStmt *caseStmt ) { 505 output << string( cur_indent, ' ' );509 output << indent; 506 510 if ( caseStmt->isDefault()) { 507 511 output << "default"; … … 516 520 cur_indent += CodeGenerator::tabsize; 517 521 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 518 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() ) ;522 output << indent << printLabels( (*i)->get_labels() ) ; 519 523 (*i)->accept(*this ); 520 524 output << endl; … … 569 573 whileStmt->get_body()->accept( *this ); 570 574 571 output << string( cur_indent, ' ' );575 output << indent; 572 576 573 577 if ( whileStmt->get_isDoWhile() ) { … … 601 605 602 606 void CodeGenerator::visit( NullStmt *nullStmt ) { 603 //output << string( cur_indent, ' ' )<< CodeGenerator::printLabels( nullStmt->get_labels() );607 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() ); 604 608 output << "/* null statement */ ;"; 605 609 } … … 638 642 break; 639 643 case DeclarationNode::Inline: 640 output << "inline ";644 // handled as special via isInline flag (FIX) 641 645 break; 642 646 case DeclarationNode::Fortran: 647 // not handled 643 648 output << "fortran "; 644 649 break; 645 650 case DeclarationNode::Noreturn: 651 // not handled 646 652 output << "_Noreturn "; 647 653 break; 648 654 case DeclarationNode::Threadlocal: 655 // not handled 649 656 output << "_Thread_local "; 650 657 break;
Note:
See TracChangeset
for help on using the changeset viewer.