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