Changeset d60ccbf for src/CodeGen
- Timestamp:
- Aug 12, 2015, 2:27:31 PM (9 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, string, with_gc
- Children:
- f32c7f4
- Parents:
- e45215c (diff), e869d663 (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:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
re45215c rd60ccbf 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 : Wed Jul 15 14:47:42201513 // Update Count : 17711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jul 27 14:40:06 2015 13 // Update Count : 218 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; … … 478 478 void CodeGenerator::visit( TypeExpr *typeExpr ) {} 479 479 480 void CodeGenerator::visit( AsmExpr *asmExpr ) { 481 if ( asmExpr->get_inout() ) { 482 output << "[ "; 483 asmExpr->get_inout()->accept( *this ); 484 output << " ] "; 485 } // if 486 asmExpr->get_constraint()->accept( *this ); 487 output << " ( "; 488 asmExpr->get_operand()->accept( *this ); 489 output << " )"; 490 } 491 480 492 //*** Statements 481 493 void CodeGenerator::visit( CompoundStmt *compoundStmt ) { … … 485 497 cur_indent += CodeGenerator::tabsize; 486 498 487 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) {499 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++ ) { 488 500 output << indent << printLabels( (*i)->get_labels() ); 489 (*i)->accept( *this );501 (*i)->accept( *this ); 490 502 491 503 output << endl; … … 511 523 } 512 524 525 void CodeGenerator::visit( AsmStmt *asmStmt ) { 526 output << "asm "; 527 if ( asmStmt->get_voltile() ) output << "volatile "; 528 if ( ! asmStmt->get_gotolabels().empty() ) output << "goto "; 529 output << "( "; 530 if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this ); 531 output << " : "; 532 genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() ); 533 output << " : "; 534 genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() ); 535 output << " : "; 536 genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() ); 537 if ( ! asmStmt->get_gotolabels().empty() ) { 538 output << " : "; 539 for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) { 540 output << *begin++; 541 if ( begin == asmStmt->get_gotolabels().end() ) break; 542 output << ", "; 543 } // for 544 } // if 545 output << " );" ; 546 } 547 513 548 void CodeGenerator::visit( IfStmt *ifStmt ) { 514 output << "if ( ";515 ifStmt->get_condition()->accept( *this );516 output << " ) ";517 518 ifStmt->get_thenPart()->accept( *this );549 output << "if ( "; 550 ifStmt->get_condition()->accept( *this ); 551 output << " ) "; 552 553 ifStmt->get_thenPart()->accept( *this ); 519 554 520 555 if ( ifStmt->get_elsePart() != 0) { 521 556 output << " else "; 522 ifStmt->get_elsePart()->accept( *this );557 ifStmt->get_elsePart()->accept( *this ); 523 558 } // if 524 559 } 525 560 526 561 void CodeGenerator::visit( SwitchStmt *switchStmt ) { 527 output << "switch ( " ;528 switchStmt->get_condition()->accept( *this );529 output << " ) ";562 output << "switch ( " ; 563 switchStmt->get_condition()->accept( *this ); 564 output << " ) "; 530 565 531 566 output << "{" << std::endl; … … 545 580 } else { 546 581 output << "case "; 547 caseStmt->get_condition()->accept( *this );582 caseStmt->get_condition()->accept( *this ); 548 583 } // if 549 584 output << ":\n"; … … 554 589 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 555 590 output << indent << printLabels( (*i)->get_labels() ) ; 556 (*i)->accept( *this );591 (*i)->accept( *this ); 557 592 output << endl; 558 593 } … … 598 633 else { 599 634 output << "while (" ; 600 whileStmt->get_condition()->accept( *this );635 whileStmt->get_condition()->accept( *this ); 601 636 output << ")"; 602 637 } // if … … 610 645 if ( whileStmt->get_isDoWhile() ) { 611 646 output << " while (" ; 612 whileStmt->get_condition()->accept( *this );647 whileStmt->get_condition()->accept( *this ); 613 648 output << ");"; 614 649 } // if -
src/CodeGen/CodeGenerator.h
re45215c rd60ccbf 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 17 11:10:58201513 // Update Count : 2 512 // 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 * ); -
src/CodeGen/FixNames.h
re45215c rd60ccbf 20 20 21 21 namespace CodeGen { 22 /// mangles object and function names 22 23 void fixNames( std::list< Declaration* > translationUnit ); 23 24 } // namespace CodeGen -
src/CodeGen/GenType.cc
re45215c rd60ccbf 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 : Wed Jul 08 16:08:24201513 // Update Count : 1 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 9 16:43:52 2015 13 // Update Count : 13 14 14 // 15 15 … … 93 93 os << "_Atomic "; 94 94 } // if 95 if ( qualifiers.isAttribute ) { 96 os << "__attribute(( )) "; 97 } // if 95 98 if ( dimension != 0 ) { 96 99 CodeGenerator cg( os ); 97 100 dimension->accept( cg ); 98 101 } else if ( isVarLen ) { 99 // no dimension expression on a VLA 100 // means it came in with the * token 102 // no dimension expression on a VLA means it came in with the * token 101 103 os << "*"; 102 104 } // if … … 202 204 typeString = "_Atomic " + typeString; 203 205 } // if 206 if ( type->get_isAttribute() ) { 207 typeString = "__attribute(( )) " + typeString; 208 } // if 204 209 } 205 210 } // namespace CodeGen -
src/CodeGen/Generate.h
re45215c rd60ccbf 23 23 24 24 namespace CodeGen { 25 /// Generates code 25 26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics ); 26 27 } // namespace CodeGen
Note: See TracChangeset
for help on using the changeset viewer.