Ignore:
Timestamp:
Oct 29, 2021, 4:47:16 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
e58e423
Parents:
0c577f7
Message:

Combined the code in FixMain? so it is all done with one pass.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixMain.cc

    r0c577f7 r8e48fca4  
    3232
    3333namespace CodeGen {
     34
     35namespace {
     36
     37struct 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
    3452        bool FixMain::replace_main = false;
    35         std::unique_ptr<FunctionDecl> FixMain::main_signature = nullptr;
    3653
    3754        template<typename container>
     
    4057        }
    4158
    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;
    4964
    50         void FixMain::fix(std::ostream &os, const char* bootloader_filename) {
    5165                if( main_signature ) {
    5266                        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);
    5468
    5569                        os << main_signature->get_scopedMangleName() << "(";
     
    121135}
    122136
    123 struct FindMainCore {
    124         void previsit( FunctionDecl * decl ) {
    125                 if ( FixMain::isMain( decl ) ) {
    126                         FixMain::registerMain( decl );
    127                 }
    128         }
    129 };
    130 
    131137} // namespace
    132138
     
    145151}
    146152
    147 void FixMain::findMain( std::list< Declaration * > & translationUnit ) {
    148         PassVisitor< FindMainCore > mainFinder;
    149         acceptAll( translationUnit, mainFinder );
    150 }
    151 
    152153};
Note: See TracChangeset for help on using the changeset viewer.