Changeset 3cbe320
- Timestamp:
- Oct 4, 2023, 11:04:22 AM (14 months ago)
- Branches:
- master
- Children:
- 15b5abac
- Parents:
- cf34e82
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/LinkOnce.cc
rcf34e82 r3cbe320 10 10 // Created On : Thur May 13 10:10:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thur May 13 14:39:00 202113 // Update Count : 012 // Last Modified On : Wed Oct 4 10:52:00 2023 13 // Update Count : 1 14 14 // 15 15 … … 18 18 #include <algorithm> 19 19 20 #include "AST/Attribute.hpp" 21 #include "AST/Decl.hpp" 22 #include "AST/Expr.hpp" 23 #include "AST/Pass.hpp" 20 24 #include "Common/PassVisitor.h" // for PassVisitor, WithShortCircuiting 21 25 22 26 namespace CodeGen { 23 27 24 static bool is_cfa_linkonce( Attribute const * attr ) { 28 namespace { 29 30 bool is_cfa_linkonce_old( Attribute const * attr ) { 25 31 return std::string("cfa_linkonce") == attr->name; 26 32 } 27 33 28 static bool is_section_attribute( Attribute const * attr ) {34 bool is_section_attribute_old( Attribute const * attr ) { 29 35 return std::string("section") == attr->name; 30 36 } … … 39 45 std::list< Attribute * > & attributes = decl->attributes; 40 46 // See if we can find the element: 41 auto found = std::find_if(attributes.begin(), attributes.end(), is_cfa_linkonce );47 auto found = std::find_if(attributes.begin(), attributes.end(), is_cfa_linkonce_old ); 42 48 if ( attributes.end() != found ) { 43 49 // Remove any other sections: 44 attributes.remove_if( is_section_attribute );50 attributes.remove_if( is_section_attribute_old ); 45 51 // Iterator to the cfa_linkonce attribute should still be valid. 46 52 Attribute * attribute = *found; … … 63 69 }; 64 70 71 bool is_cfa_linkonce( ast::Attribute const * attr ) { 72 return "cfa_linkonce" == attr->name; 73 } 74 75 bool is_section_attribute( ast::Attribute const * attr ) { 76 return "section" == attr->name; 77 } 78 79 struct LinkOnceCore : public ast::WithShortCircuiting { 80 void previsit( ast::Decl const * ) { 81 visit_children = false; 82 } 83 84 ast::DeclWithType const * postvisit( ast::DeclWithType const * decl ) { 85 // Check to see if we have to mutate, because should be uncommon. 86 { 87 auto & attributes = decl->attributes; 88 auto found = std::find_if( attributes.begin(), attributes.end(), 89 is_cfa_linkonce ); 90 if ( attributes.end() == found ) return decl; 91 } 92 auto mutDecl = mutate( decl ); 93 auto & attributes = mutDecl->attributes; 94 95 // Remove all conflicting section attributes. 96 erase_if( attributes, is_section_attribute ); 97 98 // Get the attribute, and overwrite it as a section attribute. 99 auto found = std::find_if( attributes.begin(), attributes.end(), 100 is_cfa_linkonce ); 101 assert( attributes.end() != found ); 102 ast::Attribute * attribute = found->get_and_mutate(); 103 assert( attribute->params.empty() ); 104 assert( !decl->mangleName.empty() ); 105 106 attribute->name = "section"; 107 attribute->params.push_back( 108 ast::ConstantExpr::from_string( mutDecl->location, 109 ".gnu.linkonce." + decl->mangleName 110 ) 111 ); 112 113 // Unconditionnaly add "visibility(default)" to anything with 114 // .gnu.linkonce visibility is a mess otherwise. 115 attributes.push_back( new ast::Attribute( "visibility", { 116 ast::ConstantExpr::from_string( mutDecl->location, "default" ) 117 } ) ); 118 return mutDecl; 119 } 120 }; 121 122 } // namespace 123 65 124 void translateLinkOnce( std::list< Declaration *> & translationUnit ) { 66 125 PassVisitor<LinkOnceVisitorCore> translator; … … 68 127 } 69 128 129 void translateLinkOnce( ast::TranslationUnit & translationUnit ) { 130 ast::Pass<LinkOnceCore>::run( translationUnit ); 70 131 } 132 133 } // namespace CodeGen -
src/CodeGen/LinkOnce.h
rcf34e82 r3cbe320 10 10 // Created On : Thur May 13 10:06:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thur May 13 14:38:00 202113 // Update Count : 012 // Last Modified On : Wed Oct 4 10:52:00 2023 13 // Update Count : 1 14 14 // 15 15 … … 23 23 24 24 class Declaration; 25 namespace ast { 26 class TranslationUnit; 27 } 25 28 26 29 namespace CodeGen { 27 30 28 31 void translateLinkOnce( std::list< Declaration *> & translationUnit ); 32 void translateLinkOnce( ast::TranslationUnit & translationUnit ); 29 33 /* Convert the cfa_linkonce attribute on top level declaration into 30 34 * a special section declaration (.gnu.linkonce) so that it may be defined -
src/main.cc
rcf34e82 r3cbe320 421 421 DUMP( bboxp, std::move( transUnit ) ); 422 422 PASS( "Box", GenPoly::box, transUnit ); 423 PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit ); 423 424 424 425 translationUnit = convert( std::move( transUnit ) ); 425 426 PASS( "Link-Once", CodeGen::translateLinkOnce, translationUnit );427 426 428 427 // Code has been lowered to C, now we can start generation.
Note: See TracChangeset
for help on using the changeset viewer.