Changes in / [2174191:2da12ae]
- Location:
- src
- Files:
-
- 1 added
- 8 edited
-
AST/Decl.cpp (modified) (3 diffs)
-
AST/Type.hpp (modified) (1 diff)
-
CodeGen/FixMain.cc (modified) (4 diffs)
-
CodeGen/FixMain.h (modified) (3 diffs)
-
CodeGen/FixMain2.cc (added)
-
CodeGen/FixNames.cc (modified) (3 diffs)
-
CodeGen/FixNames.h (modified) (2 diffs)
-
CodeGen/module.mk (modified) (2 diffs)
-
main.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Decl.cpp
r2174191 r2da12ae 20 20 #include <unordered_map> 21 21 22 #include "CodeGen/FixMain.h" // for FixMain 22 23 #include "Common/Eval.h" // for eval 23 24 … … 75 76 } 76 77 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 } 77 84 } 78 85 … … 101 108 } 102 109 this->type = type; 110 // See note above about this hack. 111 if ( name == "main" ) { 112 this->linkage = CodeGen::FixMain::getMainLinkage(); 113 } 103 114 } 104 115 -
src/AST/Type.hpp
r2174191 r2da12ae 34 34 35 35 namespace ast { 36 37 template< typename T > class Pass; 36 38 37 39 class Type : public Node { -
src/CodeGen/FixMain.cc
r2174191 r2da12ae 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixMain.cc -- Tools to change a Cforall main into a C main.7 // FixMain.cc -- 8 8 // 9 9 // Author : Thierry Delisle … … 33 33 namespace { 34 34 35 struct FindMainCore final{35 struct FindMainCore_new { 36 36 ast::FunctionDecl const * main_declaration = nullptr; 37 37 38 38 void previsit( ast::FunctionDecl const * decl ) { 39 if ( isMain( decl ) ) {39 if ( FixMain::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 118 108 } // namespace 119 109 120 bool isMain( const ast::FunctionDecl * decl ) {110 bool FixMain::isMain( const ast::FunctionDecl * decl ) { 121 111 if ( std::string("main") != decl->name ) { 122 112 return false; … … 125 115 } 126 116 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, 117 void FixMain::fix( ast::TranslationUnit & translationUnit, 135 118 std::ostream &os, const char * bootloader_filename ) { 136 119 137 ast::Pass<FindMainCore > main_finder;120 ast::Pass<FindMainCore_new> main_finder; 138 121 ast::accept_all( translationUnit, main_finder ); 139 122 if ( nullptr == main_finder.core.main_declaration ) return; -
src/CodeGen/FixMain.h
r2174191 r2da12ae 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FixMain.h -- Tools to change a Cforall main into a C main.7 // FixMain.h -- 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" 19 23 20 24 namespace ast { … … 25 29 namespace CodeGen { 26 30 27 /// Is this function a program main function? 28 bool isMain( const ast::FunctionDecl * decl ); 31 class FixMain { 32 public : 33 static inline ast::Linkage::Spec getMainLinkage() { 34 return replace_main ? ast::Linkage::Cforall : ast::Linkage::C; 35 } 29 36 30 /// Adjust the linkage of main functions. 31 void fixMainLinkage( ast::TranslationUnit & transUnit, bool replaceMain ); 37 static inline void setReplaceMain(bool val) { 38 replace_main = val; 39 } 32 40 33 /// Add a wrapper around to run the Cforall main. 34 void fixMainInvoke( ast::TranslationUnit & transUnit, 35 std::ostream & os, const char * bootloaderFilename ); 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 }; 36 49 37 50 } // namespace CodeGen -
src/CodeGen/FixNames.cc
r2174191 r2da12ae 28 28 29 29 namespace CodeGen { 30 31 namespace {32 33 30 /// Does work with the main function and scopeLevels. 34 class FixNames final {31 class FixNames_new final { 35 32 int scopeLevel = 1; 36 33 … … 48 45 49 46 const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) { 50 if ( isMain( functionDecl ) ) {47 if ( FixMain::isMain( functionDecl ) ) { 51 48 auto mutDecl = ast::mutate( functionDecl ); 52 49 … … 83 80 }; 84 81 85 } // namespace86 87 82 void fixNames( ast::TranslationUnit & translationUnit ) { 88 ast::Pass<FixNames >::run( translationUnit );83 ast::Pass<FixNames_new>::run( translationUnit ); 89 84 } 90 85 -
src/CodeGen/FixNames.h
r2174191 r2da12ae 16 16 #pragma once 17 17 18 #include <list> // for list 19 20 class Declaration; 18 21 namespace ast { 19 22 class TranslationUnit; … … 21 24 22 25 namespace CodeGen { 23 26 /// mangles object and function names 27 void fixNames( std::list< Declaration* > & translationUnit ); 24 28 /// Sets scope levels and fills in main's default return. 25 29 void fixNames( ast::TranslationUnit & translationUnit ); 26 27 30 } // namespace CodeGen 28 31 -
src/CodeGen/module.mk
r2174191 r2da12ae 18 18 CodeGen/CodeGeneratorNew.cpp \ 19 19 CodeGen/CodeGeneratorNew.hpp \ 20 CodeGen/FixMain2.cc \ 21 CodeGen/FixMain.h \ 20 22 CodeGen/GenType.cc \ 21 23 CodeGen/GenType.h \ … … 27 29 CodeGen/Generate.h \ 28 30 CodeGen/FixMain.cc \ 29 CodeGen/FixMain.h \30 31 CodeGen/FixNames.cc \ 31 32 CodeGen/FixNames.h \ -
src/main.cc
r2174191 r2da12ae 250 250 251 251 parse_cmdline( argc, argv ); // process command-line arguments 252 CodeGen::FixMain::setReplaceMain( !nomainp ); 252 253 253 254 if ( waiting_for_gdb ) { … … 393 394 PASS( "Translate Tries", ControlStruct::translateTries, transUnit ); 394 395 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 CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() ); 424 423 424 CodeGen::FixMain::fix( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() ); 425 425 if ( output != &cout ) { 426 426 delete output;
Note:
See TracChangeset
for help on using the changeset viewer.