Changeset 2174191
- Timestamp:
- Nov 11, 2023, 7:43:14 AM (12 months ago)
- 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. - Location:
- src
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
r2da12ae r2174191 20 20 #include <unordered_map> 21 21 22 #include "CodeGen/FixMain.h" // for FixMain23 22 #include "Common/Eval.h" // for eval 24 23 … … 76 75 } 77 76 this->type = ftype; 78 // Hack forcing the function "main" to have Cforall linkage to replace79 // main even if it is inside an extern "C", and also makes sure the80 // replacing function is always a C function.81 if ( name == "main" ) {82 this->linkage = CodeGen::FixMain::getMainLinkage();83 }84 77 } 85 78 … … 108 101 } 109 102 this->type = type; 110 // See note above about this hack.111 if ( name == "main" ) {112 this->linkage = CodeGen::FixMain::getMainLinkage();113 }114 103 } 115 104 -
src/AST/Type.hpp
r2da12ae r2174191 34 34 35 35 namespace ast { 36 37 template< typename T > class Pass;38 36 39 37 class Type : public Node { -
src/CodeGen/FixMain.cc
r2da12ae r2174191 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixMain.cc -- 7 // FixMain.cc -- Tools to change a Cforall main into a C main. 8 8 // 9 9 // Author : Thierry Delisle … … 33 33 namespace { 34 34 35 struct FindMainCore _new{35 struct FindMainCore final { 36 36 ast::FunctionDecl const * main_declaration = nullptr; 37 37 38 38 void previsit( ast::FunctionDecl const * decl ) { 39 if ( FixMain::isMain( decl ) ) {39 if ( isMain( decl ) ) { 40 40 if ( main_declaration ) { 41 41 SemanticError( decl, "Multiple definition of main routine\n" ); … … 106 106 } 107 107 108 struct 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 108 118 } // namespace 109 119 110 bool FixMain::isMain( const ast::FunctionDecl * decl ) {120 bool isMain( const ast::FunctionDecl * decl ) { 111 121 if ( std::string("main") != decl->name ) { 112 122 return false; … … 115 125 } 116 126 117 void FixMain::fix( ast::TranslationUnit & translationUnit, 127 void 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 134 void fixMainInvoke( ast::TranslationUnit & translationUnit, 118 135 std::ostream &os, const char * bootloader_filename ) { 119 136 120 ast::Pass<FindMainCore _new> main_finder;137 ast::Pass<FindMainCore> main_finder; 121 138 ast::accept_all( translationUnit, main_finder ); 122 139 if ( nullptr == main_finder.core.main_declaration ) return; -
src/CodeGen/FixMain.h
r2da12ae r2174191 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixMain.h -- 7 // FixMain.h -- Tools to change a Cforall main into a C main. 8 8 // 9 9 // Author : Thierry Delisle … … 17 17 18 18 #include <iosfwd> 19 #include <memory>20 #include <list>21 22 #include "AST/LinkageSpec.hpp"23 19 24 20 namespace ast { … … 29 25 namespace CodeGen { 30 26 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? 28 bool isMain( const ast::FunctionDecl * decl ); 36 29 37 static inline void setReplaceMain(bool val) { 38 replace_main = val; 39 } 30 /// Adjust the linkage of main functions. 31 void fixMainLinkage( ast::TranslationUnit & transUnit, bool replaceMain ); 40 32 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. 34 void fixMainInvoke( ast::TranslationUnit & transUnit, 35 std::ostream & os, const char * bootloaderFilename ); 49 36 50 37 } // namespace CodeGen -
src/CodeGen/FixNames.cc
r2da12ae r2174191 28 28 29 29 namespace CodeGen { 30 31 namespace { 32 30 33 /// Does work with the main function and scopeLevels. 31 class FixNames _newfinal {34 class FixNames final { 32 35 int scopeLevel = 1; 33 36 … … 45 48 46 49 const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) { 47 if ( FixMain::isMain( functionDecl ) ) {50 if ( isMain( functionDecl ) ) { 48 51 auto mutDecl = ast::mutate( functionDecl ); 49 52 … … 80 83 }; 81 84 85 } // namespace 86 82 87 void fixNames( ast::TranslationUnit & translationUnit ) { 83 ast::Pass<FixNames _new>::run( translationUnit );88 ast::Pass<FixNames>::run( translationUnit ); 84 89 } 85 90 -
src/CodeGen/FixNames.h
r2da12ae r2174191 16 16 #pragma once 17 17 18 #include <list> // for list19 20 class Declaration;21 18 namespace ast { 22 19 class TranslationUnit; … … 24 21 25 22 namespace CodeGen { 26 /// mangles object and function names 27 void fixNames( std::list< Declaration* > & translationUnit ); 23 28 24 /// Sets scope levels and fills in main's default return. 29 25 void fixNames( ast::TranslationUnit & translationUnit ); 26 30 27 } // namespace CodeGen 31 28 -
src/CodeGen/module.mk
r2da12ae r2174191 18 18 CodeGen/CodeGeneratorNew.cpp \ 19 19 CodeGen/CodeGeneratorNew.hpp \ 20 CodeGen/FixMain2.cc \21 CodeGen/FixMain.h \22 20 CodeGen/GenType.cc \ 23 21 CodeGen/GenType.h \ … … 29 27 CodeGen/Generate.h \ 30 28 CodeGen/FixMain.cc \ 29 CodeGen/FixMain.h \ 31 30 CodeGen/FixNames.cc \ 32 31 CodeGen/FixNames.h \ -
src/main.cc
r2da12ae r2174191 250 250 251 251 parse_cmdline( argc, argv ); // process command-line arguments 252 CodeGen::FixMain::setReplaceMain( !nomainp );253 252 254 253 if ( waiting_for_gdb ) { … … 394 393 PASS( "Translate Tries", ControlStruct::translateTries, transUnit ); 395 394 PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit ); 395 PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp ); 396 396 397 397 // Needs to happen before tuple types are expanded. … … 421 421 422 422 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 425 425 if ( output != &cout ) { 426 426 delete output;
Note: See TracChangeset
for help on using the changeset viewer.