Changeset 8e48fca4 for src/CodeGen/FixMain.cc
- Timestamp:
- Oct 29, 2021, 4:47:16 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- e58e423
- Parents:
- 0c577f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/FixMain.cc
r0c577f7 r8e48fca4 32 32 33 33 namespace CodeGen { 34 35 namespace { 36 37 struct FindMainCore { 38 FunctionDecl * main_signature = nullptr; 39 40 void previsit( FunctionDecl * decl ) { 41 if ( FixMain::isMain( decl ) ) { 42 if ( main_signature ) { 43 SemanticError( decl, "Multiple definition of main routine\n" ); 44 } 45 main_signature = decl; 46 } 47 } 48 }; 49 50 } 51 34 52 bool FixMain::replace_main = false; 35 std::unique_ptr<FunctionDecl> FixMain::main_signature = nullptr;36 53 37 54 template<typename container> … … 40 57 } 41 58 42 void FixMain::registerMain(FunctionDecl* functionDecl) 43 { 44 if(main_signature) { 45 SemanticError(functionDecl, "Multiple definition of main routine\n"); 46 } 47 main_signature.reset( functionDecl->clone() ); 48 } 59 void FixMain::fix( std::list< Declaration * > & translationUnit, 60 std::ostream &os, const char* bootloader_filename ) { 61 PassVisitor< FindMainCore > main_finder; 62 acceptAll( translationUnit, main_finder ); 63 FunctionDecl * main_signature = main_finder.pass.main_signature; 49 64 50 void FixMain::fix(std::ostream &os, const char* bootloader_filename) {51 65 if( main_signature ) { 52 66 os << "static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return "; 53 main_signature->mangleName = SymTab::Mangler::mangle(main_signature .get());67 main_signature->mangleName = SymTab::Mangler::mangle(main_signature); 54 68 55 69 os << main_signature->get_scopedMangleName() << "("; … … 121 135 } 122 136 123 struct FindMainCore {124 void previsit( FunctionDecl * decl ) {125 if ( FixMain::isMain( decl ) ) {126 FixMain::registerMain( decl );127 }128 }129 };130 131 137 } // namespace 132 138 … … 145 151 } 146 152 147 void FixMain::findMain( std::list< Declaration * > & translationUnit ) {148 PassVisitor< FindMainCore > mainFinder;149 acceptAll( translationUnit, mainFinder );150 }151 152 153 };
Note: See TracChangeset
for help on using the changeset viewer.