Changeset 353d168 for src/CodeGen
- Timestamp:
- Aug 19, 2015, 3:59:45 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 830c21a
- Parents:
- 18997b9 (diff), 4aa0858 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/CodeGen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r18997b9 r353d168 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() ); … … 452 472 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 453 473 474 void CodeGenerator::visit( AsmExpr *asmExpr ) { 475 if ( asmExpr->get_inout() ) { 476 output << "[ "; 477 asmExpr->get_inout()->accept( *this ); 478 output << " ] "; 479 } // if 480 asmExpr->get_constraint()->accept( *this ); 481 output << " ( "; 482 asmExpr->get_operand()->accept( *this ); 483 output << " )"; 484 } 485 454 486 //*** Statements 455 487 void CodeGenerator::visit( CompoundStmt *compoundStmt ) { … … 459 491 cur_indent += CodeGenerator::tabsize; 460 492 461 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) {493 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) { 462 494 output << indent << printLabels( (*i)->get_labels() ); 463 (*i)->accept( *this );495 (*i)->accept( *this ); 464 496 465 497 output << endl; … … 485 517 } 486 518 519 void CodeGenerator::visit( AsmStmt *asmStmt ) { 520 output << "asm "; 521 if ( asmStmt->get_voltile() ) output << "volatile "; 522 if ( ! asmStmt->get_gotolabels().empty() ) output << "goto "; 523 output << "( "; 524 if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this ); 525 output << " : "; 526 genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() ); 527 output << " : "; 528 genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() ); 529 output << " : "; 530 genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() ); 531 if ( ! asmStmt->get_gotolabels().empty() ) { 532 output << " : "; 533 for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) { 534 output << *begin++; 535 if ( begin == asmStmt->get_gotolabels().end() ) break; 536 output << ", "; 537 } // for 538 } // if 539 output << " );" ; 540 } 541 487 542 void CodeGenerator::visit( IfStmt *ifStmt ) { 488 output << "if ( ";489 ifStmt->get_condition()->accept( *this );490 output << " ) ";491 492 ifStmt->get_thenPart()->accept( *this );543 output << "if ( "; 544 ifStmt->get_condition()->accept( *this ); 545 output << " ) "; 546 547 ifStmt->get_thenPart()->accept( *this ); 493 548 494 549 if ( ifStmt->get_elsePart() != 0) { 495 550 output << " else "; 496 ifStmt->get_elsePart()->accept( *this );551 ifStmt->get_elsePart()->accept( *this ); 497 552 } // if 498 553 } 499 554 500 555 void CodeGenerator::visit( SwitchStmt *switchStmt ) { 501 output << "switch ( " ;502 switchStmt->get_condition()->accept( *this );503 output << " ) ";556 output << "switch ( " ; 557 switchStmt->get_condition()->accept( *this ); 558 output << " ) "; 504 559 505 560 output << "{" << std::endl; … … 519 574 } else { 520 575 output << "case "; 521 caseStmt->get_condition()->accept( *this );576 caseStmt->get_condition()->accept( *this ); 522 577 } // if 523 578 output << ":\n"; … … 528 583 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 529 584 output << indent << printLabels( (*i)->get_labels() ) ; 530 (*i)->accept( *this );585 (*i)->accept( *this ); 531 586 output << endl; 532 587 } … … 572 627 else { 573 628 output << "while (" ; 574 whileStmt->get_condition()->accept( *this );629 whileStmt->get_condition()->accept( *this ); 575 630 output << ")"; 576 631 } // if … … 584 639 if ( whileStmt->get_isDoWhile() ) { 585 640 output << " while (" ; 586 whileStmt->get_condition()->accept( *this );641 whileStmt->get_condition()->accept( *this ); 587 642 output << ");"; 588 643 } // if -
src/CodeGen/CodeGenerator.h
r18997b9 r353d168 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jun 11 13:24:23201513 // Update Count : 2 312 // Last Modified On : Wed Aug 12 14:27:14 2015 13 // Update Count : 27 14 14 // 15 15 … … 65 65 virtual void visit( TupleExpr *tupleExpr ); 66 66 virtual void visit( TypeExpr *typeExpr ); 67 virtual void visit( AsmExpr * ); 67 68 68 69 //*** Statements 69 70 virtual void visit( CompoundStmt * ); 70 71 virtual void visit( ExprStmt * ); 72 virtual void visit( AsmStmt * ); 71 73 virtual void visit( IfStmt * ); 72 74 virtual void visit( SwitchStmt * ); … … 93 95 std::ostream &output; 94 96 97 void printDesignators( std::list< Expression * > & ); 95 98 static std::string printLabels ( std::list < Label > & ); 96 99 void handleStorageClass( Declaration *decl );
Note:
See TracChangeset
for help on using the changeset viewer.