Changes in src/CodeGen/LinkOnce.cc [3cbe320:4bb5d36]
- File:
-
- 1 edited
-
src/CodeGen/LinkOnce.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/LinkOnce.cc
r3cbe320 r4bb5d36 10 10 // Created On : Thur May 13 10:10:00 2021 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Oct 4 10:52:00 202313 // Update Count : 112 // Last Modified On : Thur May 13 14:39:00 2021 13 // Update Count : 0 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"24 20 #include "Common/PassVisitor.h" // for PassVisitor, WithShortCircuiting 25 21 26 22 namespace CodeGen { 27 23 28 namespace { 29 30 bool is_cfa_linkonce_old( Attribute const * attr ) { 24 static bool is_cfa_linkonce( Attribute const * attr ) { 31 25 return std::string("cfa_linkonce") == attr->name; 32 26 } 33 27 34 bool is_section_attribute_old( Attribute const * attr ) {28 static bool is_section_attribute( Attribute const * attr ) { 35 29 return std::string("section") == attr->name; 36 30 } … … 45 39 std::list< Attribute * > & attributes = decl->attributes; 46 40 // See if we can find the element: 47 auto found = std::find_if(attributes.begin(), attributes.end(), is_cfa_linkonce _old);41 auto found = std::find_if(attributes.begin(), attributes.end(), is_cfa_linkonce ); 48 42 if ( attributes.end() != found ) { 49 43 // Remove any other sections: 50 attributes.remove_if( is_section_attribute _old);44 attributes.remove_if( is_section_attribute ); 51 45 // Iterator to the cfa_linkonce attribute should still be valid. 52 46 Attribute * attribute = *found; … … 69 63 }; 70 64 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->mangleName110 )111 );112 113 // Unconditionnaly add "visibility(default)" to anything with114 // .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 } // namespace123 124 65 void translateLinkOnce( std::list< Declaration *> & translationUnit ) { 125 66 PassVisitor<LinkOnceVisitorCore> translator; … … 127 68 } 128 69 129 void translateLinkOnce( ast::TranslationUnit & translationUnit ) {130 ast::Pass<LinkOnceCore>::run( translationUnit );131 70 } 132 133 } // namespace CodeGen
Note:
See TracChangeset
for help on using the changeset viewer.