Changes in / [5916272:4cc585b]
- Location:
- src
- Files:
-
- 4 edited
-
CodeGen/CodeGenerator.cc (modified) (10 diffs)
-
CodeGen/CodeGenerator.h (modified) (4 diffs)
-
CodeGen/Generate.cc (modified) (2 diffs)
-
ControlStruct/ForExprMutator.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r5916272 r4cc585b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:34:00 201713 // Update Count : 48 812 // Last Modified On : Tus Jul 25 15:29:00 2017 13 // Update Count : 486 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 81 /* Using updateLocation at the beginning of a node and nextLine 82 * within a node should become the method of formating. 83 */ 84 void CodeGenerator::updateLocation( CodeLocation const & to ) { 85 if ( !lineMarks ) { 86 return; 87 } else if ( currentLocation.followedBy( to, 0 ) ) { 88 return; 89 } else if ( currentLocation.followedBy( to, 1 ) ) { 90 output << "\n" << indent; 91 currentLocation.linenumber += 1; 92 } else if ( currentLocation.followedBy( to, 2 ) ) { 93 output << "\n\n" << indent; 94 currentLocation.linenumber += 2; 95 } else { 96 output << "\n# " << to.linenumber << " \"" << to.filename 97 << "\"\n" << indent; 98 currentLocation = to; 99 } 100 output << std::flush; 101 } 102 103 void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) { 104 updateLocation( to->location ); 105 } 106 107 void CodeGenerator::nextLine() { 108 if ( !lineMarks ) { 109 output << "\n" << indent << std::flush; 81 CodeGenerator::LineMarker::LineMarker( 82 CodeLocation const & loc, bool toPrint) : 83 loc(loc), toPrint(toPrint) 84 {} 85 86 CodeGenerator::LineMarker CodeGenerator::lineDirective( 87 BaseSyntaxNode const * node) { 88 return LineMarker(node->location, lineMarks); 89 } 90 91 std::ostream & operator<<(std::ostream & out, 92 CodeGenerator::LineMarker const & marker) { 93 if (marker.toPrint && marker.loc.isSet()) { 94 return out << "\n# " << marker.loc.linenumber << " \"" 95 << marker.loc.filename << "\"\n"; 96 } else if (marker.toPrint) { 97 return out << "\n/* Missing CodeLocation */\n"; 98 } else { 99 return out; 110 100 } 111 101 } … … 204 194 ++indent; 205 195 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 206 updateLocation( *i );196 output << lineDirective( *i ) << indent; 207 197 (*i)->accept( *this ); 208 198 output << ";" << endl; … … 227 217 void CodeGenerator::visit( EnumDecl * enumDecl ) { 228 218 extension( enumDecl ); 229 updateLocation( enumDecl );219 output << lineDirective ( enumDecl ); 230 220 output << "enum "; 231 221 genAttributes( enumDecl->get_attributes() ); … … 243 233 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 244 234 assert( obj ); 245 updateLocation( obj ); 246 output << mangleName( obj ); 235 output << lineDirective( obj ) << indent << mangleName( obj ); 247 236 if ( obj->get_init() ) { 248 237 output << " = "; … … 262 251 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 263 252 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 264 updateLocation( typeDecl );253 output << lineDirective( typeDecl ); 265 254 output << "typedef "; 266 255 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 763 752 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 764 753 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 765 updateLocation( stmtExpr ); 766 output << "({" << std::endl; 754 output << lineDirective( stmtExpr) << "({" << std::endl; 767 755 ++indent; 768 756 unsigned int numStmts = stmts.size(); 769 757 unsigned int i = 0; 770 758 for ( Statement * stmt : stmts ) { 771 updateLocation( stmt );759 output << lineDirective( stmt ) << indent; 772 760 output << printLabels( stmt->get_labels() ); 773 761 if ( i+1 == numStmts ) { … … 856 844 857 845 void CodeGenerator::visit( IfStmt * ifStmt ) { 858 updateLocation( ifStmt );846 output << lineDirective( ifStmt ); 859 847 output << "if ( "; 860 848 ifStmt->get_condition()->accept( *this ); … … 870 858 871 859 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 872 updateLocation( switchStmt );860 output << lineDirective( switchStmt ); 873 861 output << "switch ( " ; 874 862 switchStmt->get_condition()->accept( *this ); … … 883 871 884 872 void CodeGenerator::visit( CaseStmt * caseStmt ) { 885 updateLocation( caseStmt ); 873 output << lineDirective( caseStmt ); 874 output << indent; 886 875 if ( caseStmt->isDefault()) { 887 876 output << "default"; -
src/CodeGen/CodeGenerator.h
r5916272 r4cc585b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:40:00 201713 // Update Count : 5 612 // Last Modified On : Tus Jul 25 25:30:00 2017 13 // Update Count : 54 14 14 // 15 15 … … 108 108 }; 109 109 110 struct LineMarker { 111 CodeLocation const & loc; 112 bool toPrint; 113 114 LineMarker(CodeLocation const & loc, bool toPrint); 115 }; 116 117 LineMarker lineDirective(BaseSyntaxNode const * node); 118 110 119 void asmName( DeclarationWithType *decl ); 111 120 112 121 void extension( Expression *expr ); 113 122 void extension( Declaration *decl ); 114 115 void updateLocation( BaseSyntaxNode const * to );116 123 private: 117 124 Indenter indent; … … 122 129 bool genC = false; // true if output has to be C code 123 130 bool lineMarks = false; 124 125 CodeLocation currentLocation;126 void updateLocation( CodeLocation const & to );127 void nextLine();128 131 129 132 void handleStorageClass( DeclarationWithType *decl ); … … 152 155 /// returns C-compatible name of declaration 153 156 std::string genName( DeclarationWithType * decl ); 157 158 std::ostream & operator<<(std::ostream &, 159 CodeGenerator::LineMarker const &); 154 160 } // namespace CodeGen 155 161 -
src/CodeGen/Generate.cc
r5916272 r4cc585b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:39:00 201713 // Update Count : 712 // Last Modified On : Wed May 19 13:05:00 2017 13 // Update Count : 6 14 14 // 15 15 #include "Generate.h" … … 33 33 for ( auto & dcl : translationUnit ) { 34 34 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { 35 cgv.updateLocation( dcl);35 os << cgv.lineDirective(dcl); 36 36 dcl->accept(cgv); 37 37 if ( doSemicolon( dcl ) ) { -
src/ControlStruct/ForExprMutator.cc
r5916272 r4cc585b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 18 10:22:00201713 // Update Count : 1 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:32:46 2017 13 // Update Count : 11 14 14 // 15 15 … … 21 21 22 22 namespace ControlStruct { 23 Statement * hoist( Statement *originalStmt, std::list<Statement *> &init ) {24 // If no hoisting is needed, skip:25 if ( 0 == init.size()) {26 return originalStmt;27 } 23 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) { 24 std::list<Statement *> &init = ifStmt->get_initialization(); 25 if ( init.size() == 0 ) { 26 return ifStmt; 27 } // if 28 28 29 // Create compound statement, move initializers outside, 30 // the resut of the original stays as is. 29 // create compound statement, move initializers outside, leave _for_ as-is 31 30 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 31 std::list<Statement *> &stmts = block->get_kids(); 33 32 stmts.splice( stmts.end(), init ); 34 33 35 // Add for to the new block.36 stmts.push_back( originalStmt );34 // add for to the new block 35 stmts.push_back( ifStmt ); 37 36 return block; 38 37 } 39 38 40 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {41 return hoist( ifStmt, ifStmt->initialization );42 }43 39 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 44 40 // hoist any initializer declarations to make them C89 (rather than C99) 45 return hoist( forStmt, forStmt->initialization ); 41 std::list<Statement *> &init = forStmt->get_initialization(); 42 if ( init.size() == 0 ) { 43 return forStmt; 44 } // if 45 46 // create compound statement, move initializers outside, leave _for_ as-is 47 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 48 std::list<Statement *> &stmts = block->get_kids(); 49 stmts.splice( stmts.end(), init ); 50 51 // add for to the new block 52 stmts.push_back( forStmt ); 53 return block; 46 54 } 47 55 } // namespace ControlStruct
Note:
See TracChangeset
for help on using the changeset viewer.