Ignore:
Timestamp:
Nov 11, 2023, 7:43:14 AM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixMain.cc

    r2da12ae r2174191  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixMain.cc --
     7// FixMain.cc -- Tools to change a Cforall main into a C main.
    88//
    99// Author           : Thierry Delisle
     
    3333namespace {
    3434
    35 struct FindMainCore_new {
     35struct FindMainCore final {
    3636        ast::FunctionDecl const * main_declaration = nullptr;
    3737
    3838        void previsit( ast::FunctionDecl const * decl ) {
    39                 if ( FixMain::isMain( decl ) ) {
     39                if ( isMain( decl ) ) {
    4040                        if ( main_declaration ) {
    4141                                SemanticError( decl, "Multiple definition of main routine\n" );
     
    106106}
    107107
     108struct 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
    108118} // namespace
    109119
    110 bool FixMain::isMain( const ast::FunctionDecl * decl ) {
     120bool isMain( const ast::FunctionDecl * decl ) {
    111121        if ( std::string("main") != decl->name ) {
    112122                return false;
     
    115125}
    116126
    117 void FixMain::fix( ast::TranslationUnit & translationUnit,
     127void 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
     134void fixMainInvoke( ast::TranslationUnit & translationUnit,
    118135                std::ostream &os, const char * bootloader_filename ) {
    119136
    120         ast::Pass<FindMainCore_new> main_finder;
     137        ast::Pass<FindMainCore> main_finder;
    121138        ast::accept_all( translationUnit, main_finder );
    122139        if ( nullptr == main_finder.core.main_declaration ) return;
Note: See TracChangeset for help on using the changeset viewer.