Changeset 2174191


Ignore:
Timestamp:
Nov 11, 2023, 7:43:14 AM (12 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

Location:
src
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    r2da12ae r2174191  
    2020#include <unordered_map>
    2121
    22 #include "CodeGen/FixMain.h"   // for FixMain
    2322#include "Common/Eval.h"       // for eval
    2423
     
    7675        }
    7776        this->type = ftype;
    78         // Hack forcing the function "main" to have Cforall linkage to replace
    79         // main even if it is inside an extern "C", and also makes sure the
    80         // replacing function is always a C function.
    81         if ( name == "main" ) {
    82                 this->linkage = CodeGen::FixMain::getMainLinkage();
    83         }
    8477}
    8578
     
    108101        }
    109102        this->type = type;
    110         // See note above about this hack.
    111         if ( name == "main" ) {
    112                 this->linkage = CodeGen::FixMain::getMainLinkage();
    113         }
    114103}
    115104
  • src/AST/Type.hpp

    r2da12ae r2174191  
    3434
    3535namespace ast {
    36 
    37 template< typename T > class Pass;
    3836
    3937class Type : public Node {
  • 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;
  • src/CodeGen/FixMain.h

    r2da12ae r2174191  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // FixMain.h --
     7// FixMain.h -- Tools to change a Cforall main into a C main.
    88//
    99// Author           : Thierry Delisle
     
    1717
    1818#include <iosfwd>
    19 #include <memory>
    20 #include <list>
    21 
    22 #include "AST/LinkageSpec.hpp"
    2319
    2420namespace ast {
     
    2925namespace CodeGen {
    3026
    31 class FixMain {
    32 public :
    33         static inline ast::Linkage::Spec getMainLinkage() {
    34                 return replace_main ? ast::Linkage::Cforall : ast::Linkage::C;
    35         }
     27/// Is this function a program main function?
     28bool isMain( const ast::FunctionDecl * decl );
    3629
    37         static inline void setReplaceMain(bool val) {
    38                 replace_main = val;
    39         }
     30/// Adjust the linkage of main functions.
     31void fixMainLinkage( ast::TranslationUnit & transUnit, bool replaceMain );
    4032
    41         static bool isMain(const ast::FunctionDecl * decl);
    42 
    43         static void fix( ast::TranslationUnit & translationUnit,
    44                         std::ostream &os, const char * bootloader_filename );
    45 
    46 private:
    47         static bool replace_main;
    48 };
     33/// Add a wrapper around to run the Cforall main.
     34void fixMainInvoke( ast::TranslationUnit & transUnit,
     35                std::ostream & os, const char * bootloaderFilename );
    4936
    5037} // namespace CodeGen
  • src/CodeGen/FixNames.cc

    r2da12ae r2174191  
    2828
    2929namespace CodeGen {
     30
     31namespace {
     32
    3033/// Does work with the main function and scopeLevels.
    31 class FixNames_new final {
     34class FixNames final {
    3235        int scopeLevel = 1;
    3336
     
    4548
    4649        const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) {
    47                 if ( FixMain::isMain( functionDecl ) ) {
     50                if ( isMain( functionDecl ) ) {
    4851                        auto mutDecl = ast::mutate( functionDecl );
    4952
     
    8083};
    8184
     85} // namespace
     86
    8287void fixNames( ast::TranslationUnit & translationUnit ) {
    83         ast::Pass<FixNames_new>::run( translationUnit );
     88        ast::Pass<FixNames>::run( translationUnit );
    8489}
    8590
  • src/CodeGen/FixNames.h

    r2da12ae r2174191  
    1616#pragma once
    1717
    18 #include <list>  // for list
    19 
    20 class Declaration;
    2118namespace ast {
    2219        class TranslationUnit;
     
    2421
    2522namespace CodeGen {
    26         /// mangles object and function names
    27         void fixNames( std::list< Declaration* > & translationUnit );
     23
    2824/// Sets scope levels and fills in main's default return.
    2925void fixNames( ast::TranslationUnit & translationUnit );
     26
    3027} // namespace CodeGen
    3128
  • src/CodeGen/module.mk

    r2da12ae r2174191  
    1818        CodeGen/CodeGeneratorNew.cpp \
    1919        CodeGen/CodeGeneratorNew.hpp \
    20         CodeGen/FixMain2.cc \
    21         CodeGen/FixMain.h \
    2220        CodeGen/GenType.cc \
    2321        CodeGen/GenType.h \
     
    2927        CodeGen/Generate.h \
    3028        CodeGen/FixMain.cc \
     29        CodeGen/FixMain.h \
    3130        CodeGen/FixNames.cc \
    3231        CodeGen/FixNames.h \
  • src/main.cc

    r2da12ae r2174191  
    250250
    251251        parse_cmdline( argc, argv );                                            // process command-line arguments
    252         CodeGen::FixMain::setReplaceMain( !nomainp );
    253252
    254253        if ( waiting_for_gdb ) {
     
    394393                PASS( "Translate Tries", ControlStruct::translateTries, transUnit );
    395394                PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit );
     395                PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );
    396396
    397397                // Needs to happen before tuple types are expanded.
     
    421421
    422422                PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false );
    423 
    424                 CodeGen::FixMain::fix( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
     423                CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
     424
    425425                if ( output != &cout ) {
    426426                        delete output;
Note: See TracChangeset for help on using the changeset viewer.