Changeset 61efa42 for src/CodeGen
- Timestamp:
- Nov 10, 2023, 5:04:30 PM (23 months ago)
- Branches:
- master
- Children:
- 2174191
- Parents:
- f5ec35a
- Location:
- src/CodeGen
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/FixMain.cc
rf5ec35a r61efa42 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
rf5ec35a r61efa42 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
rf5ec35a r61efa42 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
rf5ec35a r61efa42 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
rf5ec35a r61efa42 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 \
Note:
See TracChangeset
for help on using the changeset viewer.