Changes in src/CodeGen/CodeGenerator.cc [2794fff:f32c7f4]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r2794fff rf32c7f4 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jul 15 14:47:42 201513 // Update Count : 17712 // Last Modified On : Wed Aug 12 14:33:52 2015 13 // Update Count : 222 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 member 194 output << "."; 195 (*iter)->accept( *this ); 196 } else { 197 // if not a simple name, it has to be a constant expression, i.e. an array designator 198 output << "["; 199 (*iter)->accept( *this ); 200 output << "]"; 201 } 202 } 203 output << " = "; 204 } 205 188 206 void CodeGenerator::visit( SingleInit *init ) { 207 printDesignators( init->get_designators() ); 189 208 init->get_value()->accept( *this ); 190 209 } 191 210 192 211 void CodeGenerator::visit( ListInit *init ) { 212 printDesignators( init->get_designators() ); 193 213 output << "{ "; 194 214 genCommaList( init->begin_initializers(), init->end_initializers() ); … … 238 258 239 259 case OT_CALL: 240 case OT_CTOR: 241 case OT_DTOR: 242 // there are no intrinsic definitions of the function call operator or constructors or destructors 260 // there are no intrinsic definitions of the function call operator 243 261 assert( false ); 244 262 break; … … 452 470 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 453 471 472 void CodeGenerator::visit( AsmExpr *asmExpr ) { 473 if ( asmExpr->get_inout() ) { 474 output << "[ "; 475 asmExpr->get_inout()->accept( *this ); 476 output << " ] "; 477 } // if 478 asmExpr->get_constraint()->accept( *this ); 479 output << " ( "; 480 asmExpr->get_operand()->accept( *this ); 481 output << " )"; 482 } 483 454 484 //*** Statements 455 485 void CodeGenerator::visit( CompoundStmt *compoundStmt ) { … … 459 489 cur_indent += CodeGenerator::tabsize; 460 490 461 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) {491 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) { 462 492 output << indent << printLabels( (*i)->get_labels() ); 463 (*i)->accept( *this );493 (*i)->accept( *this ); 464 494 465 495 output << endl; … … 485 515 } 486 516 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 } // for 536 } // if 537 output << " );" ; 538 } 539 487 540 void CodeGenerator::visit( IfStmt *ifStmt ) { 488 output << "if ( ";489 ifStmt->get_condition()->accept( *this );490 output << " ) ";491 492 ifStmt->get_thenPart()->accept( *this );541 output << "if ( "; 542 ifStmt->get_condition()->accept( *this ); 543 output << " ) "; 544 545 ifStmt->get_thenPart()->accept( *this ); 493 546 494 547 if ( ifStmt->get_elsePart() != 0) { 495 548 output << " else "; 496 ifStmt->get_elsePart()->accept( *this );549 ifStmt->get_elsePart()->accept( *this ); 497 550 } // if 498 551 } 499 552 500 553 void CodeGenerator::visit( SwitchStmt *switchStmt ) { 501 output << "switch ( " ;502 switchStmt->get_condition()->accept( *this );503 output << " ) ";554 output << "switch ( " ; 555 switchStmt->get_condition()->accept( *this ); 556 output << " ) "; 504 557 505 558 output << "{" << std::endl; … … 519 572 } else { 520 573 output << "case "; 521 caseStmt->get_condition()->accept( *this );574 caseStmt->get_condition()->accept( *this ); 522 575 } // if 523 576 output << ":\n"; … … 528 581 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 529 582 output << indent << printLabels( (*i)->get_labels() ) ; 530 (*i)->accept( *this );583 (*i)->accept( *this ); 531 584 output << endl; 532 585 } … … 572 625 else { 573 626 output << "while (" ; 574 whileStmt->get_condition()->accept( *this );627 whileStmt->get_condition()->accept( *this ); 575 628 output << ")"; 576 629 } // if … … 584 637 if ( whileStmt->get_isDoWhile() ) { 585 638 output << " while (" ; 586 whileStmt->get_condition()->accept( *this );639 whileStmt->get_condition()->accept( *this ); 587 640 output << ");"; 588 641 } // if
Note:
See TracChangeset
for help on using the changeset viewer.