- 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
- Location:
- src
- Files:
-
- 3 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 }; -
src/CodeGen/FixMain.h
r0c577f7 r8e48fca4 10 10 // Created On : Thr Jan 12 14:11:09 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 29 1 4:49:00 202113 // Update Count : 712 // Last Modified On : Fri Oct 29 16:20:00 2021 13 // Update Count : 8 14 14 // 15 15 … … 29 29 30 30 namespace CodeGen { 31 class FixMain {32 public :33 static inline LinkageSpec::Spec mainLinkage() {34 return replace_main ? LinkageSpec::Cforall : LinkageSpec::C;35 }36 31 37 static inline void setReplaceMain(bool val) { 38 replace_main = val; 39 } 32 class FixMain { 33 public : 34 static inline LinkageSpec::Spec mainLinkage() { 35 return replace_main ? LinkageSpec::Cforall : LinkageSpec::C; 36 } 40 37 41 static void registerMain(FunctionDecl* val);42 static bool isMain(FunctionDecl* decl);43 static bool isMain(const ast::FunctionDecl * decl);38 static inline void setReplaceMain(bool val) { 39 replace_main = val; 40 } 44 41 45 static void fix(std::ostream &os, const char* bootloader_filename); 42 static bool isMain(FunctionDecl* decl); 43 static bool isMain(const ast::FunctionDecl * decl); 46 44 47 static void findMain( std::list< Declaration * > & decls ); 45 static void fix( std::list< Declaration * > & decls, 46 std::ostream &os, const char* bootloader_filename ); 48 47 49 50 51 static std::unique_ptr<FunctionDecl> main_signature;52 }; 48 private: 49 static bool replace_main; 50 }; 51 53 52 } // namespace CodeGen -
src/main.cc
r0c577f7 r8e48fca4 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 29 1 0:10:00 202113 // Update Count : 65 412 // Last Modified On : Fri Oct 29 16:34:00 2021 13 // Update Count : 655 14 14 // 15 15 … … 472 472 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) ); 473 473 474 CodeGen::FixMain::fi ndMain( translationUnit );475 CodeGen::FixMain::fix( *output,(PreludeDirector + "/bootloader.c").c_str() );474 CodeGen::FixMain::fix( translationUnit, *output, 475 (PreludeDirector + "/bootloader.c").c_str() ); 476 476 if ( output != &cout ) { 477 477 delete output;
Note: See TracChangeset
for help on using the changeset viewer.