Changeset 1be845b
- Timestamp:
- Jul 30, 2018, 4:43:47 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- f072892
- Parents:
- c198b69
- git-author:
- Rob Schluntz <rschlunt@…> (07/26/18 13:54:40)
- git-committer:
- Rob Schluntz <rschlunt@…> (07/30/18 16:43:47)
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
rc198b69 r1be845b 37 37 class GlobalFixer : public WithShortCircuiting { 38 38 public: 39 GlobalFixer( const std::string & name,bool inLibrary );39 GlobalFixer( bool inLibrary ); 40 40 41 41 void previsit( ObjectDecl *objDecl ); … … 52 52 }; 53 53 54 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name,bool inLibrary ) {55 PassVisitor<GlobalFixer> visitor( name,inLibrary );54 void fixGlobalInit( std::list< Declaration * > & translationUnit, bool inLibrary ) { 55 PassVisitor<GlobalFixer> visitor( inLibrary ); 56 56 acceptAll( translationUnit, visitor ); 57 57 GlobalFixer & fixer = visitor.pass; … … 70 70 } 71 71 72 std::string globalFunctionName( const std::string & name ) { 73 // get basename 74 std::string ret = name.substr( 0, name.find( '.' ) ); 75 // replace invalid characters with _ 76 static std::string invalid = "/-@"; 77 replace_if( ret.begin(), ret.end(), []( char c ) { return invalid.find(c) != std::string::npos; }, '_' ); 78 return ret; 79 } 80 81 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 82 std::string fixedName = globalFunctionName( name ); 72 GlobalFixer::GlobalFixer( bool inLibrary ) : tempNamer( "_global_init" ) { 83 73 std::list< Expression * > ctorParameters; 84 74 std::list< Expression * > dtorParameters; … … 90 80 // for library code are run before constructors and destructors for user code, 91 81 // specify a priority when building the library. Priorities 0-100 are reserved by gcc. 92 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 93 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 82 // Priorities 101-200 are reserved by cfa, so use priority 200 for CFA library globals, 83 // allowing room for overriding with a higher priority. 84 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) ); 85 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) ); 94 86 } 95 initFunction = new FunctionDecl( "_ init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );87 initFunction = new FunctionDecl( "__global_init__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 96 88 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 97 destroyFunction = new FunctionDecl( "_ destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );89 destroyFunction = new FunctionDecl( "__global_destroy__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 98 90 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 99 91 } -
src/InitTweak/FixGlobalInit.h
rc198b69 r1be845b 22 22 23 23 namespace InitTweak { 24 /// Moves global initialization into an _init function that is unique to the translation unit. 25 /// Sets the priority of the initialization function depending on whether the initialization 26 /// function is for library code. 27 void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ); 28 29 /// Apply transformations to a file name to get a valid C identifier which will be used as 30 /// the name of the generated initializer function. 31 std::string globalFunctionName( const std::string & name ); 24 /// Moves global initialization into an _init function that is unique to the translation unit. 25 /// Sets the priority of the initialization function depending on whether the initialization 26 /// function is for library code. 27 void fixGlobalInit( std::list< Declaration * > & translationUnit, bool inLibrary ); 32 28 } // namespace 33 29 -
src/InitTweak/FixInit.cc
rc198b69 r1be845b 238 238 } // namespace 239 239 240 void fix( std::list< Declaration * > & translationUnit, const std::string & filename,bool inLibrary ) {240 void fix( std::list< Declaration * > & translationUnit, bool inLibrary ) { 241 241 PassVisitor<SelfAssignChecker> checker; 242 242 acceptAll( translationUnit, checker ); 243 243 244 244 // fixes ConstructorInit for global variables. should happen before fixInitializers. 245 InitTweak::fixGlobalInit( translationUnit, filename,inLibrary );245 InitTweak::fixGlobalInit( translationUnit, inLibrary ); 246 246 247 247 UnqCount unqCount; -
src/InitTweak/FixInit.h
rc198b69 r1be845b 24 24 /// replace constructor initializers with expression statements 25 25 /// and unwrap basic C-style initializers 26 void fix( std::list< Declaration * > & translationUnit, const std::string & name,bool inLibrary );26 void fix( std::list< Declaration * > & translationUnit, bool inLibrary ); 27 27 } // namespace 28 28 -
src/main.cc
rc198b69 r1be845b 299 299 300 300 // fix ObjectDecl - replaces ConstructorInit nodes 301 PASS( "fixInit", InitTweak::fix( translationUnit, filename,libcfap || treep ) );301 PASS( "fixInit", InitTweak::fix( translationUnit, libcfap || treep ) ); 302 302 if ( ctorinitp ) { 303 303 dump ( translationUnit );
Note: See TracChangeset
for help on using the changeset viewer.