Changeset 87b5bf0 for src/CodeGen
- Timestamp:
- Jun 29, 2016, 2:30:12 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, with_gc
- Children:
- e64365c
- Parents:
- 7305915 (diff), 2fb2ad5 (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
-
CodeGenerator.cc (modified) (3 diffs)
-
CodeGenerator.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r7305915 r87b5bf0 48 48 } 49 49 50 ostream & CodeGenerator::Indenter::operator()( ostream & output ) {50 ostream & CodeGenerator::Indenter::operator()( ostream & output ) const { 51 51 return output << string( cg.cur_indent, ' ' ); 52 52 } 53 53 54 ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) {54 ostream & operator<<( ostream & output, const CodeGenerator::Indenter &indent ) { 55 55 return indent( output ); 56 56 } 57 57 58 CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ) { } 58 CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()( std::list< Label > & l ) { 59 labels = &l; 60 return *this; 61 } 62 63 ostream & operator<<( ostream & output, CodeGenerator::LabelPrinter &printLabels ) { 64 std::list< Label > & labs = *printLabels.labels; 65 // l.unique(); // assumes a sorted list. Why not use set? Does order matter? 66 for ( Label & l : labs ) { 67 output << l.get_name() + ": "; 68 printLabels.cg.genAttributes( l.get_attributes() ); 69 } 70 return output; 71 } 72 73 CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ) { } 59 74 60 75 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) 61 : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {76 : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) { 62 77 //output << std::string( init ); 63 78 } 64 79 65 80 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp ) 66 : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ) {81 : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ), printLabels( *this ) { 67 82 //output << std::string( init ); 68 83 } … … 735 750 void CodeGenerator::visit( ReturnStmt *returnStmt ) { 736 751 output << "return "; 737 738 // xxx -- check for null expression; 739 if ( returnStmt->get_expr() ) { 740 returnStmt->get_expr()->accept( *this ); 741 } // if 752 maybeAccept( returnStmt->get_expr(), *this ); 742 753 output << ";"; 743 754 } … … 799 810 output << ";"; 800 811 } // if 801 }802 803 std::string CodeGenerator::printLabels( std::list< Label > &l ) {804 std::string str( "" );805 l.unique(); // assumes a sorted list. Why not use set?806 807 for ( std::list< Label >::iterator i = l.begin(); i != l.end(); i++ )808 str += *i + ": ";809 810 return str;811 812 } 812 813 -
src/CodeGen/CodeGenerator.h
r7305915 r87b5bf0 94 94 Indenter(CodeGenerator &cg) : cg(cg) {} 95 95 CodeGenerator & cg; 96 std::ostream& operator()(std::ostream & os); 96 std::ostream& operator()(std::ostream & os) const; 97 }; 98 99 struct LabelPrinter { 100 LabelPrinter(CodeGenerator &cg) : cg(cg), labels( 0 ) {} 101 LabelPrinter & operator()( std::list< Label > & l ); 102 CodeGenerator & cg; 103 std::list< Label > * labels; 97 104 }; 98 105 … … 108 115 bool insideFunction; 109 116 std::ostream &output; 117 LabelPrinter printLabels; 110 118 111 119 void printDesignators( std::list< Expression * > & ); 112 static std::string printLabels ( std::list < Label > & );113 120 void handleStorageClass( Declaration *decl ); 114 121 void handleAggregate( AggregateDecl *aggDecl );
Note:
See TracChangeset
for help on using the changeset viewer.