Changeset 8135d4c for src/CodeGen
- Timestamp:
- Aug 22, 2017, 7:31:52 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9aaac6e9
- Parents:
- fc56cdbf (diff), b3d413b (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:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rfc56cdbf r8135d4c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 15:29:00 201713 // Update Count : 48 612 // Last Modified On : Fri Aug 18 15:34:00 2017 13 // Update Count : 488 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 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; 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; 100 110 } 101 111 } … … 195 205 ++indent; 196 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 197 output << lineDirective( *i ) << indent;207 updateLocation( *i ); 198 208 (*i)->accept( *this ); 199 209 output << ";" << endl; … … 218 228 void CodeGenerator::visit( EnumDecl * enumDecl ) { 219 229 extension( enumDecl ); 220 output << lineDirective( enumDecl );230 updateLocation( enumDecl ); 221 231 output << "enum "; 222 232 genAttributes( enumDecl->get_attributes() ); … … 234 244 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 235 245 assert( obj ); 236 output << lineDirective( obj ) << indent << mangleName( obj ); 246 updateLocation( obj ); 247 output << mangleName( obj ); 237 248 if ( obj->get_init() ) { 238 249 output << " = "; … … 252 263 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 253 264 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 254 output << lineDirective( typeDecl );265 updateLocation( typeDecl ); 255 266 output << "typedef "; 256 267 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 741 752 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 742 753 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 743 output << lineDirective( stmtExpr) << "({" << std::endl; 754 updateLocation( stmtExpr ); 755 output << "({" << std::endl; 744 756 ++indent; 745 757 unsigned int numStmts = stmts.size(); 746 758 unsigned int i = 0; 747 759 for ( Statement * stmt : stmts ) { 748 output << lineDirective( stmt ) << indent;760 updateLocation( stmt ); 749 761 output << printLabels( stmt->get_labels() ); 750 762 if ( i+1 == numStmts ) { … … 832 844 833 845 void CodeGenerator::visit( IfStmt * ifStmt ) { 834 output << lineDirective( ifStmt );846 updateLocation( ifStmt ); 835 847 output << "if ( "; 836 848 ifStmt->get_condition()->accept( *this ); … … 846 858 847 859 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 848 output << lineDirective( switchStmt );860 updateLocation( switchStmt ); 849 861 output << "switch ( " ; 850 862 switchStmt->get_condition()->accept( *this ); … … 859 871 860 872 void CodeGenerator::visit( CaseStmt * caseStmt ) { 861 output << lineDirective( caseStmt ); 862 output << indent; 873 updateLocation( caseStmt ); 863 874 if ( caseStmt->isDefault()) { 864 875 output << "default"; -
src/CodeGen/CodeGenerator.h
rfc56cdbf r8135d4c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 25:30:00 201713 // Update Count : 5 412 // Last Modified On : Fri Aug 18 15:40:00 2017 13 // Update Count : 56 14 14 // 15 15 … … 21 21 22 22 #include "Common/Indenter.h" // for Indenter 23 24 23 #include "SynTree/Declaration.h" // for DeclarationWithType (ptr only), Fun... 25 24 #include "SynTree/Visitor.h" // for Visitor 26 25 #include "SynTree/SynTree.h" // for Visitor Nodes 27 28 #include "Common/Indenter.h" // for Indenter29 26 30 27 namespace CodeGen { … … 113 110 }; 114 111 115 struct LineMarker {116 CodeLocation const & loc;117 bool toPrint;118 119 LineMarker(CodeLocation const & loc, bool toPrint);120 };121 122 LineMarker lineDirective(BaseSyntaxNode const * node);123 124 112 void asmName( DeclarationWithType *decl ); 125 113 126 114 void extension( Expression *expr ); 127 115 void extension( Declaration *decl ); 116 117 void updateLocation( BaseSyntaxNode const * to ); 128 118 private: 129 119 Indenter indent; … … 134 124 bool genC = false; // true if output has to be C code 135 125 bool lineMarks = false; 126 127 CodeLocation currentLocation; 128 void updateLocation( CodeLocation const & to ); 129 void nextLine(); 136 130 137 131 void handleStorageClass( DeclarationWithType *decl ); … … 160 154 /// returns C-compatible name of declaration 161 155 std::string genName( DeclarationWithType * decl ); 162 163 std::ostream & operator<<(std::ostream &,164 CodeGenerator::LineMarker const &);165 156 } // namespace CodeGen 166 157 -
src/CodeGen/Generate.cc
rfc56cdbf r8135d4c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 19 13:05:00 201713 // Update Count : 612 // Last Modified On : Fri Aug 18 15:39:00 2017 13 // Update Count : 7 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 os << cgv.lineDirective(dcl);35 cgv.updateLocation( dcl ); 36 36 dcl->accept(cgv); 37 37 if ( doSemicolon( dcl ) ) {
Note: See TracChangeset
for help on using the changeset viewer.