Changeset 2174191 for src/CodeGen/FixMain.cc
- Timestamp:
- Nov 11, 2023, 7:43:14 AM (6 months ago)
- Branches:
- master
- Children:
- fc12f05
- Parents:
- 2da12ae (diff), 61efa42 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/FixMain.cc
r2da12ae r2174191 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixMain.cc -- 7 // FixMain.cc -- Tools to change a Cforall main into a C main. 8 8 // 9 9 // Author : Thierry Delisle … … 33 33 namespace { 34 34 35 struct FindMainCore _new{35 struct FindMainCore final { 36 36 ast::FunctionDecl const * main_declaration = nullptr; 37 37 38 38 void previsit( ast::FunctionDecl const * decl ) { 39 if ( FixMain::isMain( decl ) ) {39 if ( isMain( decl ) ) { 40 40 if ( main_declaration ) { 41 41 SemanticError( decl, "Multiple definition of main routine\n" ); … … 106 106 } 107 107 108 struct FixLinkageCore final { 109 ast::Linkage::Spec const spec; 110 FixLinkageCore( ast::Linkage::Spec spec ) : spec( spec ) {} 111 112 ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl ) { 113 if ( decl->name != "main" ) return decl; 114 return ast::mutate_field( decl, &ast::FunctionDecl::linkage, spec ); 115 } 116 }; 117 108 118 } // namespace 109 119 110 bool FixMain::isMain( const ast::FunctionDecl * decl ) {120 bool isMain( const ast::FunctionDecl * decl ) { 111 121 if ( std::string("main") != decl->name ) { 112 122 return false; … … 115 125 } 116 126 117 void FixMain::fix( ast::TranslationUnit & translationUnit, 127 void fixMainLinkage( ast::TranslationUnit & translationUnit, 128 bool replace_main ) { 129 ast::Linkage::Spec const spec = 130 ( replace_main ) ? ast::Linkage::Cforall : ast::Linkage::C; 131 ast::Pass<FixLinkageCore>::run( translationUnit, spec ); 132 } 133 134 void fixMainInvoke( ast::TranslationUnit & translationUnit, 118 135 std::ostream &os, const char * bootloader_filename ) { 119 136 120 ast::Pass<FindMainCore _new> main_finder;137 ast::Pass<FindMainCore> main_finder; 121 138 ast::accept_all( translationUnit, main_finder ); 122 139 if ( nullptr == main_finder.core.main_declaration ) return;
Note: See TracChangeset
for help on using the changeset viewer.