[cfe-commits] r63408 - /cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Jan 30 10:58:59 PST 2009


Author: fjahanian
Date: Fri Jan 30 12:58:59 2009
New Revision: 63408

URL: http://llvm.org/viewvc/llvm-project?rev=63408&view=rev
Log:
Code gen. for @protocol expression in the new nonfragile abi.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=63408&r1=63407&r2=63408&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Fri Jan 30 12:58:59 2009
@@ -638,10 +638,8 @@
   virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
   
   virtual void GenerateClass(const ObjCImplementationDecl *ClassDecl);
-  
   virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
-                                           const ObjCProtocolDecl *PD)
-    { return 0; }
+                                           const ObjCProtocolDecl *PD);
   
   virtual llvm::Function *GetPropertyGetFunction(){ return 0; }
   virtual llvm::Function *GetPropertySetFunction()
@@ -3461,6 +3459,38 @@
   BuildClassMetaData(TClassName, MetaTClass, SuperClassGV, CLASS_RO_GV);
 }
 
+/// GenerateProtocolRef - This routine is called to generate code for
+/// a protocol reference expression; as in:
+/// @code
+///   @protocol(Proto1);
+/// @endcode
+/// It generates a weak reference to l_OBJC_PROTOCOL_REFERENCE_$_Proto1
+/// which will hold address of the protocol meta-data.
+///
+llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CGBuilderTy &Builder,
+                                            const ObjCProtocolDecl *PD) {
+  
+  llvm::Constant *Init =  llvm::ConstantExpr::getBitCast(GetProtocolRef(PD),
+                                        ObjCTypes.ExternalProtocolPtrTy);
+  
+  std::string ProtocolName("\01l_OBJC_PROTOCOL_REFERENCE_$_");
+  ProtocolName += PD->getNameAsCString();
+                            
+  llvm::GlobalVariable *PTGV = CGM.getModule().getGlobalVariable(ProtocolName);
+  if (PTGV)
+    return Builder.CreateLoad(PTGV, false, "tmp");
+  PTGV = new llvm::GlobalVariable(
+                                Init->getType(), false,
+                                llvm::GlobalValue::WeakLinkage,
+                                Init,
+                                ProtocolName,
+                                &CGM.getModule());
+  PTGV->setSection("__DATA, __objc_protorefs, coalesced, no_dead_strip");
+  PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  UsedGlobals.push_back(PTGV);
+  return Builder.CreateLoad(PTGV, false, "tmp");
+}
+
 /// GenerateCategory - Build metadata for a category implementation.
 /// struct _category_t {
 ///   const char * const name;
@@ -3936,7 +3966,7 @@
   Desc[0] = llvm::ConstantExpr::getBitCast(GetMethodVarName(MD->getSelector()),
                                            ObjCTypes.SelectorPtrTy);
   Desc[1] = GetMethodVarType(MD);
-  // FIXME. This is really always NULL?
+  // Protocol methods have no implementation. So, this entry is always NULL.
   Desc[2] = llvm::Constant::getNullValue(ObjCTypes.Int8PtrTy);
   return llvm::ConstantStruct::get(ObjCTypes.MethodTy, Desc);
 }





More information about the cfe-commits mailing list