Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/LinkOnce.cc

    r3cbe320 r4bb5d36  
    1010// Created On       : Thur May 13 10:10:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Oct  4 10:52:00 2023
    13 // Update Count     : 1
     12// Last Modified On : Thur May 13 14:39:00 2021
     13// Update Count     : 0
    1414//
    1515
     
    1818#include <algorithm>
    1919
    20 #include "AST/Attribute.hpp"
    21 #include "AST/Decl.hpp"
    22 #include "AST/Expr.hpp"
    23 #include "AST/Pass.hpp"
    2420#include "Common/PassVisitor.h"       // for PassVisitor, WithShortCircuiting
    2521
    2622namespace CodeGen {
    2723
    28 namespace {
    29 
    30 bool is_cfa_linkonce_old( Attribute const * attr ) {
     24static bool is_cfa_linkonce( Attribute const * attr ) {
    3125        return std::string("cfa_linkonce") == attr->name;
    3226}
    3327
    34 bool is_section_attribute_old( Attribute const * attr ) {
     28static bool is_section_attribute( Attribute const * attr ) {
    3529        return std::string("section") == attr->name;
    3630}
     
    4539                std::list< Attribute * > & attributes = decl->attributes;
    4640                // 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 );
    4842                if ( attributes.end() != found ) {
    4943                        // Remove any other sections:
    50                         attributes.remove_if( is_section_attribute_old );
     44                        attributes.remove_if( is_section_attribute );
    5145                        // Iterator to the cfa_linkonce attribute should still be valid.
    5246                        Attribute * attribute = *found;
     
    6963};
    7064
    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 
    12465void translateLinkOnce( std::list< Declaration *> & translationUnit ) {
    12566        PassVisitor<LinkOnceVisitorCore> translator;
     
    12768}
    12869
    129 void translateLinkOnce( ast::TranslationUnit & translationUnit ) {
    130         ast::Pass<LinkOnceCore>::run( translationUnit );
    13170}
    132 
    133 } // namespace CodeGen
Note: See TracChangeset for help on using the changeset viewer.