diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-09 20:09:19 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-09 20:09:19 +0000 |
commit | fd65d370b14209e35cdbf7bb3b899b60ef207eab (patch) | |
tree | ad88d5c5d6d6fab7dfdc25e558bef849a0fe0999 /lib/CodeGen/CGObjCMac.cpp | |
parent | 8d21721fe9672a6742ad5430f48ea3aa4518528a (diff) |
NeXT: Add CreateMetadataVar utility method to encapsulate creation of
Obj-C metadata variables (which generally should be handled the same,
although they aren't currently).
- No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66432 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 44d56b5a60..ffc40b943b 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -430,6 +430,18 @@ protected: uint64_t GetIvarBaseOffset(const llvm::StructLayout *Layout, FieldDecl *Field); + /// CreateMetadataVar - Create a global variable with internal + /// linkage for use by the Objective-C runtime. + /// + /// This is a convenience wrapper which not only creates the + /// variable, but also sets the section and alignment and adds the + /// global to the UsedGlobals list. + llvm::GlobalVariable *CreateMetadataVar(const std::string &Name, + llvm::Constant *Init, + const char *Section, + bool SetAlignment, + bool IsUsed); + public: CGObjCCommonMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) { } @@ -1836,6 +1848,28 @@ uint64_t CGObjCCommonMac::GetIvarBaseOffset(const llvm::StructLayout *Layout, CGM.getTypes().getLLVMFieldNo(Field)); } +llvm::GlobalVariable * +CGObjCCommonMac::CreateMetadataVar(const std::string &Name, + llvm::Constant *Init, + const char *Section, + bool SetAlignment, + bool IsUsed) { + const llvm::Type *Ty = Init->getType(); + llvm::GlobalVariable *GV = + new llvm::GlobalVariable(Ty, false, + llvm::GlobalValue::InternalLinkage, + Init, + Name, + &CGM.getModule()); + if (Section) + GV->setSection(Section); + if (SetAlignment) + GV->setAlignment(CGM.getTargetData().getPreferredAlignment(Ty)); + if (IsUsed) + UsedGlobals.push_back(GV); + return GV; +} + llvm::Function *CGObjCMac::ModuleInitFunction() { // Abuse this interface function as a place to finalize. FinishModule(); |