Changes in src/CodeGen/CodeGenerator.cc [f32c7f4:2794fff]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rf32c7f4 r2794fff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 14:33:52 201513 // Update Count : 22212 // Last Modified On : Wed Jul 15 14:47:42 2015 13 // Update Count : 177 14 14 // 15 15 … … 52 52 } 53 53 54 CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ) { }54 CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { } 55 55 56 56 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) 57 : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {57 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 58 58 //output << std::string( init ); 59 59 } 60 60 61 61 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp ) 62 : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {62 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 63 63 //output << std::string( init ); 64 64 } … … 91 91 // acceptAll( functionDecl->get_oldDecls(), *this ); 92 92 if ( functionDecl->get_statements() ) { 93 functionDecl->get_statements()->accept( *this );93 functionDecl->get_statements()->accept(*this ); 94 94 } // if 95 95 } … … 121 121 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 122 122 output << indent; 123 (*i)->accept( *this );123 (*i)->accept(*this ); 124 124 output << ";" << endl; 125 125 } … … 159 159 if ( obj->get_init() ) { 160 160 output << " = "; 161 obj->get_init()->accept( *this );161 obj->get_init()->accept(*this ); 162 162 } // if 163 163 output << "," << endl; … … 186 186 } 187 187 188 void CodeGenerator::printDesignators( std::list< Expression * > & designators ) {189 typedef std::list< Expression * > DesignatorList;190 if ( designators.size() == 0 ) return;191 for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) {192 if ( NameExpr * nm = dynamic_cast< NameExpr * >( *iter ) ) {193 // if expression is a name, then initializing aggregate member194 output << ".";195 (*iter)->accept( *this );196 } else {197 // if not a simple name, it has to be a constant expression, i.e. an array designator198 output << "[";199 (*iter)->accept( *this );200 output << "]";201 }202 }203 output << " = ";204 }205 206 188 void CodeGenerator::visit( SingleInit *init ) { 207 printDesignators( init->get_designators() );208 189 init->get_value()->accept( *this ); 209 190 } 210 191 211 192 void CodeGenerator::visit( ListInit *init ) { 212 printDesignators( init->get_designators() );213 193 output << "{ "; 214 194 genCommaList( init->begin_initializers(), init->end_initializers() ); … … 258 238 259 239 case OT_CALL: 260 // there are no intrinsic definitions of the function call operator 240 case OT_CTOR: 241 case OT_DTOR: 242 // there are no intrinsic definitions of the function call operator or constructors or destructors 261 243 assert( false ); 262 244 break; … … 470 452 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 471 453 472 void CodeGenerator::visit( AsmExpr *asmExpr ) {473 if ( asmExpr->get_inout() ) {474 output << "[ ";475 asmExpr->get_inout()->accept( *this );476 output << " ] ";477 } // if478 asmExpr->get_constraint()->accept( *this );479 output << " ( ";480 asmExpr->get_operand()->accept( *this );481 output << " )";482 }483 484 454 //*** Statements 485 455 void CodeGenerator::visit( CompoundStmt *compoundStmt ) { … … 489 459 cur_indent += CodeGenerator::tabsize; 490 460 491 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) {461 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 492 462 output << indent << printLabels( (*i)->get_labels() ); 493 (*i)->accept( *this );463 (*i)->accept(*this ); 494 464 495 465 output << endl; … … 515 485 } 516 486 517 void CodeGenerator::visit( AsmStmt *asmStmt ) {518 output << "asm ";519 if ( asmStmt->get_voltile() ) output << "volatile ";520 if ( ! asmStmt->get_gotolabels().empty() ) output << "goto ";521 output << "( ";522 if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this );523 output << " : ";524 genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() );525 output << " : ";526 genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() );527 output << " : ";528 genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() );529 if ( ! asmStmt->get_gotolabels().empty() ) {530 output << " : ";531 for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) {532 output << *begin++;533 if ( begin == asmStmt->get_gotolabels().end() ) break;534 output << ", ";535 } // for536 } // if537 output << " );" ;538 }539 540 487 void CodeGenerator::visit( IfStmt *ifStmt ) { 541 output << "if ( ";542 ifStmt->get_condition()->accept( *this );543 output << " ) ";544 545 ifStmt->get_thenPart()->accept( *this );488 output << "if ("; 489 ifStmt->get_condition()->accept(*this ); 490 output << ") "; 491 492 ifStmt->get_thenPart()->accept(*this ); 546 493 547 494 if ( ifStmt->get_elsePart() != 0) { 548 495 output << " else "; 549 ifStmt->get_elsePart()->accept( *this );496 ifStmt->get_elsePart()->accept(*this ); 550 497 } // if 551 498 } 552 499 553 500 void CodeGenerator::visit( SwitchStmt *switchStmt ) { 554 output << "switch ( " ;555 switchStmt->get_condition()->accept( *this );556 output << " ) ";501 output << "switch (" ; 502 switchStmt->get_condition()->accept(*this ); 503 output << ") "; 557 504 558 505 output << "{" << std::endl; … … 572 519 } else { 573 520 output << "case "; 574 caseStmt->get_condition()->accept( *this );521 caseStmt->get_condition()->accept(*this ); 575 522 } // if 576 523 output << ":\n"; … … 581 528 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 582 529 output << indent << printLabels( (*i)->get_labels() ) ; 583 (*i)->accept( *this );530 (*i)->accept(*this ); 584 531 output << endl; 585 532 } … … 625 572 else { 626 573 output << "while (" ; 627 whileStmt->get_condition()->accept( *this );574 whileStmt->get_condition()->accept(*this ); 628 575 output << ")"; 629 576 } // if … … 637 584 if ( whileStmt->get_isDoWhile() ) { 638 585 output << " while (" ; 639 whileStmt->get_condition()->accept( *this );586 whileStmt->get_condition()->accept(*this ); 640 587 output << ");"; 641 588 } // if
Note:
See TracChangeset
for help on using the changeset viewer.