Changeset 03e5d14


Ignore:
Timestamp:
May 6, 2016, 3:45:23 PM (8 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:
9e2c1f0, af18713, fac84be
Parents:
37024fd
Message:

add support for constructor/destructor attribute priority and set priority for library constructors to high

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r37024fd r03e5d14  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 14:57:16 2016
     12// Last Modified On : Fri May 06 15:40:35 2016
    1313// Update Count     : 243
    1414//
     
    7676        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
    7777                // generalize this
    78                 switch ( functionDecl->get_attribute() ) {
    79                         case FunctionDecl::Constructor:
    80                                 output << "__attribute__ ((constructor)) ";
     78                FunctionDecl::Attribute attr = functionDecl->get_attribute();
     79                switch ( attr.type ) {
     80                        case FunctionDecl::Attribute::Constructor:
     81                                output << "__attribute__ ((constructor";
     82                                if ( attr.priority != FunctionDecl::Attribute::Default ) {
     83                                        output << "(" << attr.priority << ")";
     84                                }
     85                                output << ")) ";
    8186                                break;
    82                         case FunctionDecl::Destructor:
    83                                 output << "__attribute__ ((destructor)) ";
     87                        case FunctionDecl::Attribute::Destructor:
     88                                output << "__attribute__ ((destructor";
     89                                if ( attr.priority != FunctionDecl::Attribute::Default ) {
     90                                        output << "(" << attr.priority << ")";
     91                                }
     92                                output << ")) ";
    8493                                break;
    8594                        default:
  • src/InitTweak/FixGlobalInit.cc

    r37024fd r03e5d14  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 14:59:26 2016
     12// Last Modified On : Fri May 06 15:40:48 2016
    1313// Update Count     : 2
    1414//
     
    3030        class GlobalFixer : public Visitor {
    3131          public:
    32                 GlobalFixer( const std::string & name );
     32                GlobalFixer( const std::string & name, bool inLibrary );
    3333
    3434                virtual void visit( ObjectDecl *objDecl );
     
    8787        }
    8888
    89         void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name ) {
    90                 GlobalFixer fixer( name );
     89        void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
     90                GlobalFixer fixer( name, inLibrary );
    9191                acceptAll( translationUnit, fixer );
    9292                translationUnit.push_back( fixer.initFunction );
     
    102102  }
    103103
    104         GlobalFixer::GlobalFixer( const std::string & name ) : tempNamer( "_global_init" ) {
    105                 initFunction = new FunctionDecl( initName( name ), DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Constructor );
     104        GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) {
     105                initFunction = new FunctionDecl( initName( name ), 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 ) );
    106106        }
    107107
  • src/InitTweak/FixGlobalInit.h

    r37024fd r03e5d14  
    1010// Created On       : Mon May 04 15:14:56 2016
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed May 04 16:35:37 2016
     12// Last Modified On : Fri May 06 15:29:13 2016
    1313// Update Count     : 2
    1414//
     
    2424
    2525namespace InitTweak {
    26   /// Moves global initialization into an _init function that is unique to the translation unit
    27   void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name );
     26  /// Moves global initialization into an _init function that is unique to the translation unit.
     27  /// Sets the priority of the initialization function depending on whether the initialization
     28  /// function is for library code.
     29  void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary );
    2830
    2931  /// Apply transformations to a file name to get a valid C identifier which will be used as
  • src/SynTree/Declaration.h

    r37024fd r03e5d14  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 11:16:45 2016
     12// Last Modified On : Fri May 06 15:39:02 2016
    1313// Update Count     : 33
    1414//
     
    107107  public:
    108108        // temporary - merge this into general GCC attributes
    109         enum Attribute {
    110                 NoAttribute, Constructor, Destructor,
     109        struct Attribute {
     110                enum Type {
     111                        NoAttribute, Constructor, Destructor,
     112                } type;
     113                enum Priority {
     114                        // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case
     115                        Default = 100, High,
     116                } priority;
     117                Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {};
    111118        };
    112119
    113         FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = NoAttribute );
     120        FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() );
    114121        FunctionDecl( const FunctionDecl &other );
    115122        virtual ~FunctionDecl();
  • src/SynTree/FunctionDecl.cc

    r37024fd r03e5d14  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 11:35:09 2016
     12// Last Modified On : Fri May 06 15:41:05 2016
    1313// Update Count     : 19
    1414//
     
    6565                os << "_Noreturn ";
    6666        } // if
    67         switch ( attribute ) {
    68                 case Constructor:
     67        switch ( attribute.type ) {
     68                case Attribute::Constructor:
    6969                        os << "Global Constructor ";
    7070                        break;
    71                 case Destructor:
     71                case Attribute::Destructor:
    7272                        os << "Global Destructor ";
    7373                        break;
    7474                default:
    7575                        break;
     76        }
     77        if ( attribute.priority != Attribute::Default ) {
     78                os << "with priority " << attribute.priority << " ";
    7679        }
    7780        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
     
    114117                os << "_Noreturn ";
    115118        } // if
    116         switch ( attribute ) {
    117                 case Constructor:
     119        switch ( attribute.type ) {
     120                case Attribute::Constructor:
    118121                        os << " Global Constructor ";
    119122                        break;
    120                 case Destructor:
     123                case Attribute::Destructor:
    121124                        os << " Global Destructor ";
    122125                        break;
    123126                default:
    124127                        break;
     128        }
     129        if ( attribute.priority != Attribute::Default ) {
     130                os << "with priority " << attribute.priority << " ";
    125131        }
    126132        if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
  • src/main.cc

    r37024fd r03e5d14  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 06 14:56:40 2016
     12// Last Modified On : Fri May 06 15:29:42 2016
    1313// Update Count     : 203
    1414//
     
    261261                CodeGen::fixNames( translationUnit );
    262262                OPTPRINT( "fixGlobalInit" );
    263                 InitTweak::fixGlobalInit( translationUnit, filename );
     263                InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep );
    264264                OPTPRINT( "tweak" )
    265265                InitTweak::tweak( translationUnit );
Note: See TracChangeset for help on using the changeset viewer.