Changeset 7baed7d for src/InitTweak


Ignore:
Timestamp:
Jun 6, 2016, 5:46:09 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
64a32c6
Parents:
64071c2
Message:

generalize notion of a GCC attribute

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r64071c2 r7baed7d  
    2222#include "SynTree/Initializer.h"
    2323#include "SynTree/Visitor.h"
     24#include "SynTree/Attribute.h"
    2425#include <algorithm>
    2526
     
    116117        GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) {
    117118                std::string fixedName = globalFunctionName( name );
    118                 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Constructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) );
    119 
    120                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Destructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) );
     119                std::list< Expression * > ctorParameters;
     120                std::list< Expression * > dtorParameters;
     121                if ( inLibrary ) {
     122                        // Constructor/destructor attributes take a single parameter which
     123                        // is the priority, with lower numbers meaning higher priority.
     124                        // Functions specified with priority are guaranteed to run before
     125                        // functions without a priority. To ensure that constructors and destructors
     126                        // for library code are run before constructors and destructors for user code,
     127                        // specify a priority when building the library. Priorities 0-100 are reserved by gcc.
     128                        ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
     129                        dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
     130                }
     131                initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
     132                initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
     133                destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
     134                destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
    121135        }
    122136
Note: See TracChangeset for help on using the changeset viewer.