blob: b41f76db63b9e8a1fdb7bcde933f928068136519 [file] [log] [blame]
Anton Korobeynikov20ff3102008-06-01 14:13:53 +00001//===------- CGObjCGNU.cpp - Emit LLVM Code from ASTs for a Module --------===//
Chris Lattner0f984262008-03-01 08:50:34 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000010// This provides Objective-C code generation targetting the GNU runtime. The
11// class in this file generates structures used by the GNU Objective-C runtime
12// library. These structures are defined in objc/objc.h and objc/objc-api.h in
13// the GNU runtime distribution.
Chris Lattner0f984262008-03-01 08:50:34 +000014//
15//===----------------------------------------------------------------------===//
16
17#include "CGObjCRuntime.h"
Chris Lattnerdce14062008-06-26 04:19:03 +000018#include "CodeGenModule.h"
Daniel Dunbar8f2926b2008-08-23 03:46:30 +000019#include "CodeGenFunction.h"
Chris Lattnerdce14062008-06-26 04:19:03 +000020#include "clang/AST/ASTContext.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000021#include "clang/AST/Decl.h"
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +000022#include "clang/AST/DeclObjC.h"
Chris Lattner0f984262008-03-01 08:50:34 +000023#include "llvm/Module.h"
Chris Lattner0f984262008-03-01 08:50:34 +000024#include "llvm/ADT/SmallVector.h"
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000025#include "llvm/ADT/StringMap.h"
Daniel Dunbar7ded7f42008-08-15 22:20:32 +000026#include "llvm/Support/Compiler.h"
Daniel Dunbar7ded7f42008-08-15 22:20:32 +000027#include "llvm/Target/TargetData.h"
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000028#include <map>
Chris Lattnere160c9b2009-01-27 05:06:01 +000029
30
Chris Lattnerdce14062008-06-26 04:19:03 +000031using namespace clang;
Daniel Dunbar46f45b92008-09-09 01:06:48 +000032using namespace CodeGen;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000033using llvm::dyn_cast;
34
35// The version of the runtime that this class targets. Must match the version
36// in the runtime.
37static const int RuntimeVersion = 8;
38static const int ProtocolVersion = 2;
Chris Lattner0f984262008-03-01 08:50:34 +000039
Chris Lattner0f984262008-03-01 08:50:34 +000040namespace {
Chris Lattnerdce14062008-06-26 04:19:03 +000041class CGObjCGNU : public CodeGen::CGObjCRuntime {
Chris Lattner0f984262008-03-01 08:50:34 +000042private:
Chris Lattnerdce14062008-06-26 04:19:03 +000043 CodeGen::CodeGenModule &CGM;
Chris Lattner0f984262008-03-01 08:50:34 +000044 llvm::Module &TheModule;
Chris Lattnere160c9b2009-01-27 05:06:01 +000045 const llvm::PointerType *SelectorTy;
46 const llvm::PointerType *PtrToInt8Ty;
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +000047 const llvm::FunctionType *IMPTy;
Chris Lattnere160c9b2009-01-27 05:06:01 +000048 const llvm::PointerType *IdTy;
49 const llvm::IntegerType *IntTy;
50 const llvm::PointerType *PtrTy;
51 const llvm::IntegerType *LongTy;
52 const llvm::PointerType *PtrToIntTy;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000053 std::vector<llvm::Constant*> Classes;
54 std::vector<llvm::Constant*> Categories;
55 std::vector<llvm::Constant*> ConstantStrings;
56 llvm::Function *LoadFunction;
57 llvm::StringMap<llvm::Constant*> ExistingProtocols;
58 typedef std::pair<std::string, std::string> TypedSelector;
59 std::map<TypedSelector, llvm::GlobalAlias*> TypedSelectors;
60 llvm::StringMap<llvm::GlobalAlias*> UntypedSelectors;
61 // Some zeros used for GEPs in lots of places.
62 llvm::Constant *Zeros[2];
63 llvm::Constant *NULLPtr;
64private:
65 llvm::Constant *GenerateIvarList(
66 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
67 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
68 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets);
69 llvm::Constant *GenerateMethodList(const std::string &ClassName,
70 const std::string &CategoryName,
Chris Lattnera4210072008-06-26 05:08:00 +000071 const llvm::SmallVectorImpl<Selector> &MethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000072 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes,
73 bool isClassMethodList);
74 llvm::Constant *GenerateProtocolList(
75 const llvm::SmallVectorImpl<std::string> &Protocols);
76 llvm::Constant *GenerateClassStructure(
77 llvm::Constant *MetaClass,
78 llvm::Constant *SuperClass,
79 unsigned info,
Chris Lattnerd002cc62008-06-26 04:47:04 +000080 const char *Name,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000081 llvm::Constant *Version,
82 llvm::Constant *InstanceSize,
83 llvm::Constant *IVars,
84 llvm::Constant *Methods,
85 llvm::Constant *Protocols);
86 llvm::Constant *GenerateProtocolMethodList(
87 const llvm::SmallVectorImpl<llvm::Constant *> &MethodNames,
88 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes);
89 llvm::Constant *MakeConstantString(const std::string &Str, const std::string
90 &Name="");
91 llvm::Constant *MakeGlobal(const llvm::StructType *Ty,
92 std::vector<llvm::Constant*> &V, const std::string &Name="");
93 llvm::Constant *MakeGlobal(const llvm::ArrayType *Ty,
94 std::vector<llvm::Constant*> &V, const std::string &Name="");
Chris Lattner0f984262008-03-01 08:50:34 +000095public:
Chris Lattnerdce14062008-06-26 04:19:03 +000096 CGObjCGNU(CodeGen::CodeGenModule &cgm);
Daniel Dunbarbbce49b2008-08-12 00:12:39 +000097 virtual llvm::Constant *GenerateConstantString(const std::string &String);
Daniel Dunbar8f2926b2008-08-23 03:46:30 +000098 virtual CodeGen::RValue
99 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000100 QualType ResultType,
101 Selector Sel,
Daniel Dunbarf56f1912008-08-25 08:19:24 +0000102 llvm::Value *Receiver,
Daniel Dunbar19cd87e2008-08-30 03:02:31 +0000103 bool IsClassMessage,
104 const CallArgList &CallArgs);
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000105 virtual CodeGen::RValue
106 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000107 QualType ResultType,
108 Selector Sel,
Daniel Dunbarf56f1912008-08-25 08:19:24 +0000109 const ObjCInterfaceDecl *Class,
110 llvm::Value *Receiver,
Daniel Dunbar19cd87e2008-08-30 03:02:31 +0000111 bool IsClassMessage,
112 const CallArgList &CallArgs);
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000113 virtual llvm::Value *GetClass(CGBuilderTy &Builder,
Daniel Dunbarddb2a3d2008-08-16 00:25:02 +0000114 const ObjCInterfaceDecl *OID);
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000115 virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel);
Chris Lattner8e67b632008-06-26 04:37:12 +0000116
Fariborz Jahanian679a5022009-01-10 21:06:09 +0000117 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
118 const ObjCContainerDecl *CD);
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000119 virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
120 virtual void GenerateClass(const ObjCImplementationDecl *ClassDecl);
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000121 virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000122 const ObjCProtocolDecl *PD);
123 virtual void GenerateProtocol(const ObjCProtocolDecl *PD);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000124 virtual llvm::Function *ModuleInitFunction();
Daniel Dunbar49f66022008-09-24 03:38:44 +0000125 virtual llvm::Function *GetPropertyGetFunction();
126 virtual llvm::Function *GetPropertySetFunction();
Anders Carlsson2abd89c2008-08-31 04:05:03 +0000127 virtual llvm::Function *EnumerationMutationFunction();
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000128
Fariborz Jahanianbd71be42008-11-21 00:49:24 +0000129 virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
130 const Stmt &S);
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000131 virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
132 const ObjCAtThrowStmt &S);
Fariborz Jahanian3e283e32008-11-18 22:37:34 +0000133 virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
Fariborz Jahanian6dc23172008-11-18 21:45:40 +0000134 llvm::Value *AddrWeakObj);
Fariborz Jahanian3e283e32008-11-18 22:37:34 +0000135 virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
136 llvm::Value *src, llvm::Value *dst);
Fariborz Jahanian58626502008-11-19 00:59:10 +0000137 virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
138 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanian7eda8362008-11-20 19:23:36 +0000139 virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
140 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanian58626502008-11-19 00:59:10 +0000141 virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
142 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanian598d3f62009-02-03 19:03:09 +0000143 virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
144 QualType ObjectTy,
145 llvm::Value *BaseValue,
146 const ObjCIvarDecl *Ivar,
147 const FieldDecl *Field,
148 unsigned CVRQualifiers);
Fariborz Jahanianf63aa3f2009-02-10 19:02:04 +0000149 virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
150 ObjCInterfaceDecl *Interface,
151 const ObjCIvarDecl *Ivar);
Chris Lattner0f984262008-03-01 08:50:34 +0000152};
153} // end anonymous namespace
154
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000155
156
157static std::string SymbolNameForClass(const std::string &ClassName) {
158 return ".objc_class_" + ClassName;
159}
160
161static std::string SymbolNameForMethod(const std::string &ClassName, const
162 std::string &CategoryName, const std::string &MethodName, bool isClassMethod)
163{
164 return "._objc_method_" + ClassName +"("+CategoryName+")"+
165 (isClassMethod ? "+" : "-") + MethodName;
166}
167
Chris Lattnerdce14062008-06-26 04:19:03 +0000168CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm)
169 : CGM(cgm), TheModule(CGM.getModule()) {
Chris Lattnere160c9b2009-01-27 05:06:01 +0000170 IntTy = cast<llvm::IntegerType>(
171 CGM.getTypes().ConvertType(CGM.getContext().IntTy));
172 LongTy = cast<llvm::IntegerType>(
173 CGM.getTypes().ConvertType(CGM.getContext().LongTy));
Chris Lattnerdce14062008-06-26 04:19:03 +0000174
Sebastian Redl3a5013c2008-12-04 00:10:55 +0000175 Zeros[0] = llvm::ConstantInt::get(LongTy, 0);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000176 Zeros[1] = Zeros[0];
177 NULLPtr = llvm::ConstantPointerNull::get(
178 llvm::PointerType::getUnqual(llvm::Type::Int8Ty));
Chris Lattner391d77a2008-03-30 23:03:07 +0000179 // C string type. Used in lots of places.
180 PtrToInt8Ty =
181 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
182 // Get the selector Type.
Chris Lattnere160c9b2009-01-27 05:06:01 +0000183 SelectorTy = cast<llvm::PointerType>(
184 CGM.getTypes().ConvertType(CGM.getContext().getObjCSelType()));
185
Chris Lattner391d77a2008-03-30 23:03:07 +0000186 PtrToIntTy = llvm::PointerType::getUnqual(IntTy);
187 PtrTy = PtrToInt8Ty;
188
189 // Object type
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000190 IdTy = cast<llvm::PointerType>(
191 CGM.getTypes().ConvertType(CGM.getContext().getObjCIdType()));
Chris Lattner391d77a2008-03-30 23:03:07 +0000192
193 // IMP type
194 std::vector<const llvm::Type*> IMPArgs;
195 IMPArgs.push_back(IdTy);
196 IMPArgs.push_back(SelectorTy);
197 IMPTy = llvm::FunctionType::get(IdTy, IMPArgs, true);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000198}
199// This has to perform the lookup every time, since posing and related
200// techniques can modify the name -> class mapping.
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000201llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder,
Daniel Dunbarddb2a3d2008-08-16 00:25:02 +0000202 const ObjCInterfaceDecl *OID) {
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000203 llvm::Value *ClassName = CGM.GetAddrOfConstantCString(OID->getNameAsString());
Daniel Dunbarddb2a3d2008-08-16 00:25:02 +0000204 ClassName = Builder.CreateStructGEP(ClassName, 0);
205
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000206 llvm::Constant *ClassLookupFn =
207 TheModule.getOrInsertFunction("objc_lookup_class", IdTy, PtrToInt8Ty,
208 NULL);
209 return Builder.CreateCall(ClassLookupFn, ClassName);
Chris Lattner391d77a2008-03-30 23:03:07 +0000210}
211
Chris Lattner8e67b632008-06-26 04:37:12 +0000212/// GetSelector - Return the pointer to the unique'd string for this selector.
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000213llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel) {
Chris Lattner8e67b632008-06-26 04:37:12 +0000214 // FIXME: uniquing on the string is wasteful, unique on Sel instead!
Chris Lattner077bf5e2008-11-24 03:33:13 +0000215 llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()];
Chris Lattner8e67b632008-06-26 04:37:12 +0000216 if (US == 0)
217 US = new llvm::GlobalAlias(llvm::PointerType::getUnqual(SelectorTy),
218 llvm::GlobalValue::InternalLinkage,
219 ".objc_untyped_selector_alias",
220 NULL, &TheModule);
221
222 return Builder.CreateLoad(US);
223
224}
225
Chris Lattner5e7dcc62008-06-26 04:44:19 +0000226llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str,
227 const std::string &Name) {
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000228 llvm::Constant * ConstStr = llvm::ConstantArray::get(Str);
229 ConstStr = new llvm::GlobalVariable(ConstStr->getType(), true,
230 llvm::GlobalValue::InternalLinkage,
231 ConstStr, Name, &TheModule);
232 return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros, 2);
233}
234llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::StructType *Ty,
235 std::vector<llvm::Constant*> &V, const std::string &Name) {
236 llvm::Constant *C = llvm::ConstantStruct::get(Ty, V);
237 return new llvm::GlobalVariable(Ty, false,
238 llvm::GlobalValue::InternalLinkage, C, Name, &TheModule);
239}
240llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::ArrayType *Ty,
241 std::vector<llvm::Constant*> &V, const std::string &Name) {
242 llvm::Constant *C = llvm::ConstantArray::get(Ty, V);
243 return new llvm::GlobalVariable(Ty, false,
244 llvm::GlobalValue::InternalLinkage, C, Name, &TheModule);
245}
246
247/// Generate an NSConstantString object.
248//TODO: In case there are any crazy people still using the GNU runtime without
249//an OpenStep implementation, this should let them select their own class for
250//constant strings.
Daniel Dunbarbbce49b2008-08-12 00:12:39 +0000251llvm::Constant *CGObjCGNU::GenerateConstantString(const std::string &Str) {
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000252 std::vector<llvm::Constant*> Ivars;
253 Ivars.push_back(NULLPtr);
Chris Lattner13fd7e52008-06-21 21:44:18 +0000254 Ivars.push_back(MakeConstantString(Str));
Daniel Dunbarbbce49b2008-08-12 00:12:39 +0000255 Ivars.push_back(llvm::ConstantInt::get(IntTy, Str.size()));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000256 llvm::Constant *ObjCStr = MakeGlobal(
257 llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, IntTy, NULL),
258 Ivars, ".objc_str");
259 ConstantStrings.push_back(
260 llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty));
261 return ObjCStr;
262}
263
264///Generates a message send where the super is the receiver. This is a message
265///send to self with special delivery semantics indicating which class's method
266///should be called.
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000267CodeGen::RValue
268CGObjCGNU::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000269 QualType ResultType,
270 Selector Sel,
Daniel Dunbarf56f1912008-08-25 08:19:24 +0000271 const ObjCInterfaceDecl *Class,
272 llvm::Value *Receiver,
Daniel Dunbar19cd87e2008-08-30 03:02:31 +0000273 bool IsClassMessage,
274 const CallArgList &CallArgs) {
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000275 llvm::Value *cmd = GetSelector(CGF.Builder, Sel);
276
277 CallArgList ActualArgs;
278
279 ActualArgs.push_back(
280 std::make_pair(RValue::get(CGF.Builder.CreateBitCast(Receiver, IdTy)),
281 CGF.getContext().getObjCIdType()));
282 ActualArgs.push_back(std::make_pair(RValue::get(cmd),
283 CGF.getContext().getObjCSelType()));
284 ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
285
286 CodeGenTypes &Types = CGM.getTypes();
287 const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs);
288 const llvm::FunctionType *impType = Types.GetFunctionType(FnInfo, false);
289
290
Daniel Dunbarf56f1912008-08-25 08:19:24 +0000291 const ObjCInterfaceDecl *SuperClass = Class->getSuperClass();
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000292 // TODO: This should be cached, not looked up every time.
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000293 llvm::Value *ReceiverClass = GetClass(CGF.Builder, SuperClass);
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000294
295
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000296 // Construct the structure used to look up the IMP
297 llvm::StructType *ObjCSuperTy = llvm::StructType::get(Receiver->getType(),
298 IdTy, NULL);
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000299 llvm::Value *ObjCSuper = CGF.Builder.CreateAlloca(ObjCSuperTy);
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000300
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000301 CGF.Builder.CreateStore(Receiver, CGF.Builder.CreateStructGEP(ObjCSuper, 0));
302 CGF.Builder.CreateStore(ReceiverClass, CGF.Builder.CreateStructGEP(ObjCSuper, 1));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000303
304 // Get the IMP
305 llvm::Constant *lookupFunction =
306 TheModule.getOrInsertFunction("objc_msg_lookup_super",
307 llvm::PointerType::getUnqual(impType),
308 llvm::PointerType::getUnqual(ObjCSuperTy),
309 SelectorTy, NULL);
310 llvm::Value *lookupArgs[] = {ObjCSuper, cmd};
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000311 llvm::Value *imp = CGF.Builder.CreateCall(lookupFunction, lookupArgs,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000312 lookupArgs+2);
313
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000314 return CGF.EmitCall(FnInfo, imp, ActualArgs);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000315}
316
317/// Generate code for a message send expression.
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000318CodeGen::RValue
319CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000320 QualType ResultType,
321 Selector Sel,
Daniel Dunbarf56f1912008-08-25 08:19:24 +0000322 llvm::Value *Receiver,
Daniel Dunbar19cd87e2008-08-30 03:02:31 +0000323 bool IsClassMessage,
324 const CallArgList &CallArgs) {
Daniel Dunbar7f8ea5c2008-08-30 05:35:15 +0000325 llvm::Value *cmd = GetSelector(CGF.Builder, Sel);
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000326 CallArgList ActualArgs;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000327
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000328 ActualArgs.push_back(
329 std::make_pair(RValue::get(CGF.Builder.CreateBitCast(Receiver, IdTy)),
330 CGF.getContext().getObjCIdType()));
331 ActualArgs.push_back(std::make_pair(RValue::get(cmd),
332 CGF.getContext().getObjCSelType()));
333 ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
334
335 CodeGenTypes &Types = CGM.getTypes();
336 const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs);
337 const llvm::FunctionType *impType = Types.GetFunctionType(FnInfo, false);
338
Chris Lattner0f984262008-03-01 08:50:34 +0000339 llvm::Constant *lookupFunction =
340 TheModule.getOrInsertFunction("objc_msg_lookup",
Chris Lattner391d77a2008-03-30 23:03:07 +0000341 llvm::PointerType::getUnqual(impType),
342 Receiver->getType(), SelectorTy, NULL);
Daniel Dunbar8f2926b2008-08-23 03:46:30 +0000343 llvm::Value *imp = CGF.Builder.CreateCall2(lookupFunction, Receiver, cmd);
Chris Lattner3eae03e2008-05-06 00:56:42 +0000344
Fariborz Jahanianb3716ef2009-02-04 20:31:19 +0000345 return CGF.EmitCall(FnInfo, imp, ActualArgs);
Chris Lattner0f984262008-03-01 08:50:34 +0000346}
347
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000348/// Generates a MethodList. Used in construction of a objc_class and
349/// objc_category structures.
350llvm::Constant *CGObjCGNU::GenerateMethodList(const std::string &ClassName,
Chris Lattnera4210072008-06-26 05:08:00 +0000351 const std::string &CategoryName,
352 const llvm::SmallVectorImpl<Selector> &MethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000353 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes,
354 bool isClassMethodList) {
355 // Get the method structure type.
356 llvm::StructType *ObjCMethodTy = llvm::StructType::get(
357 PtrToInt8Ty, // Really a selector, but the runtime creates it us.
358 PtrToInt8Ty, // Method types
359 llvm::PointerType::getUnqual(IMPTy), //Method pointer
360 NULL);
361 std::vector<llvm::Constant*> Methods;
362 std::vector<llvm::Constant*> Elements;
363 for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
364 Elements.clear();
Chris Lattner077bf5e2008-11-24 03:33:13 +0000365 llvm::Constant *C =
366 CGM.GetAddrOfConstantCString(MethodSels[i].getAsString());
Chris Lattnera4210072008-06-26 05:08:00 +0000367 Elements.push_back(llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000368 Elements.push_back(
369 llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2));
370 llvm::Constant *Method =
371 TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
Chris Lattner077bf5e2008-11-24 03:33:13 +0000372 MethodSels[i].getAsString(),
Chris Lattner550b8db2008-06-26 04:05:20 +0000373 isClassMethodList));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000374 Method = llvm::ConstantExpr::getBitCast(Method,
375 llvm::PointerType::getUnqual(IMPTy));
376 Elements.push_back(Method);
377 Methods.push_back(llvm::ConstantStruct::get(ObjCMethodTy, Elements));
378 }
379
380 // Array of method structures
381 llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodTy,
Chris Lattnera4210072008-06-26 05:08:00 +0000382 MethodSels.size());
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000383 llvm::Constant *MethodArray = llvm::ConstantArray::get(ObjCMethodArrayTy,
Chris Lattnerfba67632008-06-26 04:52:29 +0000384 Methods);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000385
386 // Structure containing list pointer, array and array count
387 llvm::SmallVector<const llvm::Type*, 16> ObjCMethodListFields;
388 llvm::PATypeHolder OpaqueNextTy = llvm::OpaqueType::get();
389 llvm::Type *NextPtrTy = llvm::PointerType::getUnqual(OpaqueNextTy);
390 llvm::StructType *ObjCMethodListTy = llvm::StructType::get(NextPtrTy,
391 IntTy,
392 ObjCMethodArrayTy,
393 NULL);
394 // Refine next pointer type to concrete type
395 llvm::cast<llvm::OpaqueType>(
396 OpaqueNextTy.get())->refineAbstractTypeTo(ObjCMethodListTy);
397 ObjCMethodListTy = llvm::cast<llvm::StructType>(OpaqueNextTy.get());
398
399 Methods.clear();
400 Methods.push_back(llvm::ConstantPointerNull::get(
401 llvm::PointerType::getUnqual(ObjCMethodListTy)));
402 Methods.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty,
403 MethodTypes.size()));
404 Methods.push_back(MethodArray);
405
406 // Create an instance of the structure
407 return MakeGlobal(ObjCMethodListTy, Methods, ".objc_method_list");
408}
409
410/// Generates an IvarList. Used in construction of a objc_class.
411llvm::Constant *CGObjCGNU::GenerateIvarList(
412 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
413 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
414 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets) {
415 // Get the method structure type.
416 llvm::StructType *ObjCIvarTy = llvm::StructType::get(
417 PtrToInt8Ty,
418 PtrToInt8Ty,
419 IntTy,
420 NULL);
421 std::vector<llvm::Constant*> Ivars;
422 std::vector<llvm::Constant*> Elements;
423 for (unsigned int i = 0, e = IvarNames.size() ; i < e ; i++) {
424 Elements.clear();
425 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(IvarNames[i],
426 Zeros, 2));
427 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(IvarTypes[i],
428 Zeros, 2));
429 Elements.push_back(IvarOffsets[i]);
430 Ivars.push_back(llvm::ConstantStruct::get(ObjCIvarTy, Elements));
431 }
432
433 // Array of method structures
434 llvm::ArrayType *ObjCIvarArrayTy = llvm::ArrayType::get(ObjCIvarTy,
435 IvarNames.size());
436
437
438 Elements.clear();
Chris Lattnere160c9b2009-01-27 05:06:01 +0000439 Elements.push_back(llvm::ConstantInt::get(IntTy, (int)IvarNames.size()));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000440 Elements.push_back(llvm::ConstantArray::get(ObjCIvarArrayTy, Ivars));
441 // Structure containing array and array count
442 llvm::StructType *ObjCIvarListTy = llvm::StructType::get(IntTy,
443 ObjCIvarArrayTy,
444 NULL);
445
446 // Create an instance of the structure
447 return MakeGlobal(ObjCIvarListTy, Elements, ".objc_ivar_list");
448}
449
450/// Generate a class structure
451llvm::Constant *CGObjCGNU::GenerateClassStructure(
452 llvm::Constant *MetaClass,
453 llvm::Constant *SuperClass,
454 unsigned info,
Chris Lattnerd002cc62008-06-26 04:47:04 +0000455 const char *Name,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000456 llvm::Constant *Version,
457 llvm::Constant *InstanceSize,
458 llvm::Constant *IVars,
459 llvm::Constant *Methods,
460 llvm::Constant *Protocols) {
461 // Set up the class structure
462 // Note: Several of these are char*s when they should be ids. This is
463 // because the runtime performs this translation on load.
464 llvm::StructType *ClassTy = llvm::StructType::get(
465 PtrToInt8Ty, // class_pointer
466 PtrToInt8Ty, // super_class
467 PtrToInt8Ty, // name
468 LongTy, // version
469 LongTy, // info
470 LongTy, // instance_size
471 IVars->getType(), // ivars
472 Methods->getType(), // methods
473 // These are all filled in by the runtime, so we pretend
474 PtrTy, // dtable
475 PtrTy, // subclass_list
476 PtrTy, // sibling_class
477 PtrTy, // protocols
478 PtrTy, // gc_object_type
479 NULL);
480 llvm::Constant *Zero = llvm::ConstantInt::get(LongTy, 0);
481 llvm::Constant *NullP =
Chris Lattnere160c9b2009-01-27 05:06:01 +0000482 llvm::ConstantPointerNull::get(PtrTy);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000483 // Fill in the structure
484 std::vector<llvm::Constant*> Elements;
485 Elements.push_back(llvm::ConstantExpr::getBitCast(MetaClass, PtrToInt8Ty));
486 Elements.push_back(SuperClass);
Chris Lattnerd002cc62008-06-26 04:47:04 +0000487 Elements.push_back(MakeConstantString(Name, ".class_name"));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000488 Elements.push_back(Zero);
489 Elements.push_back(llvm::ConstantInt::get(LongTy, info));
490 Elements.push_back(InstanceSize);
491 Elements.push_back(IVars);
492 Elements.push_back(Methods);
493 Elements.push_back(NullP);
494 Elements.push_back(NullP);
495 Elements.push_back(NullP);
496 Elements.push_back(llvm::ConstantExpr::getBitCast(Protocols, PtrTy));
497 Elements.push_back(NullP);
498 // Create an instance of the structure
Chris Lattner1565e032008-07-21 06:31:05 +0000499 return MakeGlobal(ClassTy, Elements, SymbolNameForClass(Name));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000500}
501
502llvm::Constant *CGObjCGNU::GenerateProtocolMethodList(
503 const llvm::SmallVectorImpl<llvm::Constant *> &MethodNames,
504 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes) {
505 // Get the method structure type.
506 llvm::StructType *ObjCMethodDescTy = llvm::StructType::get(
507 PtrToInt8Ty, // Really a selector, but the runtime does the casting for us.
508 PtrToInt8Ty,
509 NULL);
510 std::vector<llvm::Constant*> Methods;
511 std::vector<llvm::Constant*> Elements;
512 for (unsigned int i = 0, e = MethodTypes.size() ; i < e ; i++) {
513 Elements.clear();
514 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(MethodNames[i],
515 Zeros, 2));
516 Elements.push_back(
517 llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2));
518 Methods.push_back(llvm::ConstantStruct::get(ObjCMethodDescTy, Elements));
519 }
520 llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodDescTy,
521 MethodNames.size());
522 llvm::Constant *Array = llvm::ConstantArray::get(ObjCMethodArrayTy, Methods);
523 llvm::StructType *ObjCMethodDescListTy = llvm::StructType::get(
524 IntTy, ObjCMethodArrayTy, NULL);
525 Methods.clear();
526 Methods.push_back(llvm::ConstantInt::get(IntTy, MethodNames.size()));
527 Methods.push_back(Array);
528 return MakeGlobal(ObjCMethodDescListTy, Methods, ".objc_method_list");
529}
530// Create the protocol list structure used in classes, categories and so on
531llvm::Constant *CGObjCGNU::GenerateProtocolList(
532 const llvm::SmallVectorImpl<std::string> &Protocols) {
533 llvm::ArrayType *ProtocolArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
534 Protocols.size());
535 llvm::StructType *ProtocolListTy = llvm::StructType::get(
536 PtrTy, //Should be a recurisve pointer, but it's always NULL here.
537 LongTy,//FIXME: Should be size_t
538 ProtocolArrayTy,
539 NULL);
540 std::vector<llvm::Constant*> Elements;
541 for (const std::string *iter = Protocols.begin(), *endIter = Protocols.end();
542 iter != endIter ; iter++) {
543 llvm::Constant *Ptr =
544 llvm::ConstantExpr::getBitCast(ExistingProtocols[*iter], PtrToInt8Ty);
545 Elements.push_back(Ptr);
546 }
547 llvm::Constant * ProtocolArray = llvm::ConstantArray::get(ProtocolArrayTy,
548 Elements);
549 Elements.clear();
550 Elements.push_back(NULLPtr);
Chris Lattnere160c9b2009-01-27 05:06:01 +0000551 Elements.push_back(llvm::ConstantInt::get(LongTy, Protocols.size()));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000552 Elements.push_back(ProtocolArray);
553 return MakeGlobal(ProtocolListTy, Elements, ".objc_protocol_list");
554}
555
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000556llvm::Value *CGObjCGNU::GenerateProtocolRef(CGBuilderTy &Builder,
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000557 const ObjCProtocolDecl *PD) {
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000558 return ExistingProtocols[PD->getNameAsString()];
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000559}
560
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000561void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
562 ASTContext &Context = CGM.getContext();
Chris Lattner8ec03f52008-11-24 03:54:41 +0000563 std::string ProtocolName = PD->getNameAsString();
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000564 llvm::SmallVector<std::string, 16> Protocols;
565 for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
566 E = PD->protocol_end(); PI != E; ++PI)
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000567 Protocols.push_back((*PI)->getNameAsString());
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000568 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodNames;
569 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
570 for (ObjCProtocolDecl::instmeth_iterator iter = PD->instmeth_begin(),
571 E = PD->instmeth_end(); iter != E; iter++) {
572 std::string TypeStr;
573 Context.getObjCEncodingForMethodDecl(*iter, TypeStr);
574 InstanceMethodNames.push_back(
Chris Lattner077bf5e2008-11-24 03:33:13 +0000575 CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
Daniel Dunbar61432932008-08-13 23:20:05 +0000576 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000577 }
578 // Collect information about class methods:
579 llvm::SmallVector<llvm::Constant*, 16> ClassMethodNames;
580 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
581 for (ObjCProtocolDecl::classmeth_iterator iter = PD->classmeth_begin(),
582 endIter = PD->classmeth_end() ; iter != endIter ; iter++) {
583 std::string TypeStr;
584 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
585 ClassMethodNames.push_back(
Chris Lattner077bf5e2008-11-24 03:33:13 +0000586 CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
Daniel Dunbar61432932008-08-13 23:20:05 +0000587 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
Daniel Dunbaraf2f62c2008-08-13 00:59:25 +0000588 }
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000589
590 llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);
591 llvm::Constant *InstanceMethodList =
592 GenerateProtocolMethodList(InstanceMethodNames, InstanceMethodTypes);
593 llvm::Constant *ClassMethodList =
594 GenerateProtocolMethodList(ClassMethodNames, ClassMethodTypes);
595 // Protocols are objects containing lists of the methods implemented and
596 // protocols adopted.
597 llvm::StructType *ProtocolTy = llvm::StructType::get(IdTy,
598 PtrToInt8Ty,
599 ProtocolList->getType(),
600 InstanceMethodList->getType(),
601 ClassMethodList->getType(),
602 NULL);
603 std::vector<llvm::Constant*> Elements;
604 // The isa pointer must be set to a magic number so the runtime knows it's
605 // the correct layout.
606 Elements.push_back(llvm::ConstantExpr::getIntToPtr(
607 llvm::ConstantInt::get(llvm::Type::Int32Ty, ProtocolVersion), IdTy));
608 Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
609 Elements.push_back(ProtocolList);
610 Elements.push_back(InstanceMethodList);
611 Elements.push_back(ClassMethodList);
612 ExistingProtocols[ProtocolName] =
613 llvm::ConstantExpr::getBitCast(MakeGlobal(ProtocolTy, Elements,
614 ".objc_protocol"), IdTy);
615}
616
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000617void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
Chris Lattner8ec03f52008-11-24 03:54:41 +0000618 std::string ClassName = OCD->getClassInterface()->getNameAsString();
619 std::string CategoryName = OCD->getNameAsString();
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000620 // Collect information about instance methods
621 llvm::SmallVector<Selector, 16> InstanceMethodSels;
622 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
Steve Naroff0701bbb2009-01-08 17:28:14 +0000623 for (ObjCCategoryImplDecl::instmeth_iterator iter = OCD->instmeth_begin(),
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000624 endIter = OCD->instmeth_end() ; iter != endIter ; iter++) {
625 InstanceMethodSels.push_back((*iter)->getSelector());
626 std::string TypeStr;
627 CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
628 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
629 }
630
631 // Collect information about class methods
632 llvm::SmallVector<Selector, 16> ClassMethodSels;
633 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
Steve Naroff0701bbb2009-01-08 17:28:14 +0000634 for (ObjCCategoryImplDecl::classmeth_iterator iter = OCD->classmeth_begin(),
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000635 endIter = OCD->classmeth_end() ; iter != endIter ; iter++) {
636 ClassMethodSels.push_back((*iter)->getSelector());
637 std::string TypeStr;
638 CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
639 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
640 }
641
642 // Collect the names of referenced protocols
643 llvm::SmallVector<std::string, 16> Protocols;
644 const ObjCInterfaceDecl *ClassDecl = OCD->getClassInterface();
645 const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
646 for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
647 E = Protos.end(); I != E; ++I)
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000648 Protocols.push_back((*I)->getNameAsString());
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000649
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000650 std::vector<llvm::Constant*> Elements;
651 Elements.push_back(MakeConstantString(CategoryName));
652 Elements.push_back(MakeConstantString(ClassName));
653 // Instance method list
654 Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
Chris Lattnera4210072008-06-26 05:08:00 +0000655 ClassName, CategoryName, InstanceMethodSels, InstanceMethodTypes,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000656 false), PtrTy));
657 // Class method list
658 Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
Chris Lattnera4210072008-06-26 05:08:00 +0000659 ClassName, CategoryName, ClassMethodSels, ClassMethodTypes, true),
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000660 PtrTy));
661 // Protocol list
662 Elements.push_back(llvm::ConstantExpr::getBitCast(
663 GenerateProtocolList(Protocols), PtrTy));
664 Categories.push_back(llvm::ConstantExpr::getBitCast(
665 MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, PtrTy,
666 PtrTy, PtrTy, NULL), Elements), PtrTy));
667}
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000668
669void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
670 ASTContext &Context = CGM.getContext();
671
672 // Get the superclass name.
673 const ObjCInterfaceDecl * SuperClassDecl =
674 OID->getClassInterface()->getSuperClass();
Chris Lattner8ec03f52008-11-24 03:54:41 +0000675 std::string SuperClassName;
676 if (SuperClassDecl)
677 SuperClassName = SuperClassDecl->getNameAsString();
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000678
679 // Get the class name
680 ObjCInterfaceDecl * ClassDecl = (ObjCInterfaceDecl*)OID->getClassInterface();
Chris Lattner8ec03f52008-11-24 03:54:41 +0000681 std::string ClassName = ClassDecl->getNameAsString();
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000682
683 // Get the size of instances. For runtimes that support late-bound instances
684 // this should probably be something different (size just of instance
685 // varaibles in this class, not superclasses?).
686 int instanceSize = 0;
687 const llvm::Type *ObjTy = 0;
688 if (!LateBoundIVars()) {
689 ObjTy = CGM.getTypes().ConvertType(Context.getObjCInterfaceType(ClassDecl));
Daniel Dunbar491c7b72009-01-12 21:08:18 +0000690 instanceSize = CGM.getTargetData().getTypePaddedSize(ObjTy);
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000691 } else {
692 // This is required by newer ObjC runtimes.
693 assert(0 && "Late-bound instance variables not yet supported");
694 }
695
696 // Collect information about instance variables.
697 llvm::SmallVector<llvm::Constant*, 16> IvarNames;
698 llvm::SmallVector<llvm::Constant*, 16> IvarTypes;
699 llvm::SmallVector<llvm::Constant*, 16> IvarOffsets;
700 const llvm::StructLayout *Layout =
701 CGM.getTargetData().getStructLayout(cast<llvm::StructType>(ObjTy));
702 ObjTy = llvm::PointerType::getUnqual(ObjTy);
703 for (ObjCInterfaceDecl::ivar_iterator iter = ClassDecl->ivar_begin(),
704 endIter = ClassDecl->ivar_end() ; iter != endIter ; iter++) {
705 // Store the name
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000706 IvarNames.push_back(CGM.GetAddrOfConstantCString((*iter)
707 ->getNameAsString()));
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000708 // Get the type encoding for this ivar
709 std::string TypeStr;
Daniel Dunbar0d504c12008-10-17 20:21:44 +0000710 Context.getObjCEncodingForType((*iter)->getType(), TypeStr);
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000711 IvarTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
712 // Get the offset
Fariborz Jahanianfd64bb62008-12-15 20:35:07 +0000713 FieldDecl *Field = ClassDecl->lookupFieldDeclForIvar(Context, (*iter));
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000714 int offset =
Fariborz Jahanianfd64bb62008-12-15 20:35:07 +0000715 (int)Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000716 IvarOffsets.push_back(
717 llvm::ConstantInt::get(llvm::Type::Int32Ty, offset));
718 }
719
720 // Collect information about instance methods
721 llvm::SmallVector<Selector, 16> InstanceMethodSels;
722 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
723 for (ObjCImplementationDecl::instmeth_iterator iter = OID->instmeth_begin(),
724 endIter = OID->instmeth_end() ; iter != endIter ; iter++) {
725 InstanceMethodSels.push_back((*iter)->getSelector());
726 std::string TypeStr;
727 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
728 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
729 }
730
731 // Collect information about class methods
732 llvm::SmallVector<Selector, 16> ClassMethodSels;
733 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
734 for (ObjCImplementationDecl::classmeth_iterator iter = OID->classmeth_begin(),
735 endIter = OID->classmeth_end() ; iter != endIter ; iter++) {
736 ClassMethodSels.push_back((*iter)->getSelector());
737 std::string TypeStr;
738 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
739 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
740 }
741 // Collect the names of referenced protocols
742 llvm::SmallVector<std::string, 16> Protocols;
743 const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
744 for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
745 E = Protos.end(); I != E; ++I)
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000746 Protocols.push_back((*I)->getNameAsString());
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000747
748
749
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000750 // Get the superclass pointer.
751 llvm::Constant *SuperClass;
Chris Lattner8ec03f52008-11-24 03:54:41 +0000752 if (!SuperClassName.empty()) {
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000753 SuperClass = MakeConstantString(SuperClassName, ".super_class_name");
754 } else {
Chris Lattnere160c9b2009-01-27 05:06:01 +0000755 SuperClass = llvm::ConstantPointerNull::get(PtrToInt8Ty);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000756 }
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000757 // Empty vector used to construct empty method lists
758 llvm::SmallVector<llvm::Constant*, 1> empty;
759 // Generate the method and instance variable lists
760 llvm::Constant *MethodList = GenerateMethodList(ClassName, "",
Chris Lattnera4210072008-06-26 05:08:00 +0000761 InstanceMethodSels, InstanceMethodTypes, false);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000762 llvm::Constant *ClassMethodList = GenerateMethodList(ClassName, "",
Chris Lattnera4210072008-06-26 05:08:00 +0000763 ClassMethodSels, ClassMethodTypes, true);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000764 llvm::Constant *IvarList = GenerateIvarList(IvarNames, IvarTypes,
765 IvarOffsets);
766 //Generate metaclass for class methods
767 llvm::Constant *MetaClassStruct = GenerateClassStructure(NULLPtr,
Chris Lattner1565e032008-07-21 06:31:05 +0000768 NULLPtr, 0x2L, /*name*/"", 0, Zeros[0], GenerateIvarList(
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000769 empty, empty, empty), ClassMethodList, NULLPtr);
770 // Generate the class structure
Chris Lattner8ec03f52008-11-24 03:54:41 +0000771 llvm::Constant *ClassStruct =
772 GenerateClassStructure(MetaClassStruct, SuperClass, 0x1L,
773 ClassName.c_str(), 0,
Sebastian Redl3a5013c2008-12-04 00:10:55 +0000774 llvm::ConstantInt::get(LongTy, instanceSize), IvarList,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000775 MethodList, GenerateProtocolList(Protocols));
776 // Add class structure to list to be added to the symtab later
777 ClassStruct = llvm::ConstantExpr::getBitCast(ClassStruct, PtrToInt8Ty);
778 Classes.push_back(ClassStruct);
779}
780
781llvm::Function *CGObjCGNU::ModuleInitFunction() {
782 // Only emit an ObjC load function if no Objective-C stuff has been called
783 if (Classes.empty() && Categories.empty() && ConstantStrings.empty() &&
784 ExistingProtocols.empty() && TypedSelectors.empty() &&
Anton Korobeynikov5f58b912008-06-01 15:14:46 +0000785 UntypedSelectors.empty())
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000786 return NULL;
Eli Friedman1b8956e2008-06-01 16:00:02 +0000787
Chris Lattnere160c9b2009-01-27 05:06:01 +0000788 const llvm::StructType *SelStructTy = dyn_cast<llvm::StructType>(
789 SelectorTy->getElementType());
790 const llvm::Type *SelStructPtrTy = SelectorTy;
791 bool isSelOpaque = false;
792 if (SelStructTy == 0) {
793 SelStructTy = llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, NULL);
794 SelStructPtrTy = llvm::PointerType::getUnqual(SelStructTy);
795 isSelOpaque = true;
796 }
797
Eli Friedman1b8956e2008-06-01 16:00:02 +0000798 // Name the ObjC types to make the IR a bit easier to read
Chris Lattnere160c9b2009-01-27 05:06:01 +0000799 TheModule.addTypeName(".objc_selector", SelStructPtrTy);
Eli Friedman1b8956e2008-06-01 16:00:02 +0000800 TheModule.addTypeName(".objc_id", IdTy);
801 TheModule.addTypeName(".objc_imp", IMPTy);
802
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000803 std::vector<llvm::Constant*> Elements;
804 // Generate statics list:
805 llvm::ArrayType *StaticsArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
806 ConstantStrings.size() + 1);
807 ConstantStrings.push_back(NULLPtr);
808 Elements.push_back(MakeConstantString("NSConstantString",
809 ".objc_static_class_name"));
810 Elements.push_back(llvm::ConstantArray::get(StaticsArrayTy, ConstantStrings));
811 llvm::StructType *StaticsListTy =
812 llvm::StructType::get(PtrToInt8Ty, StaticsArrayTy, NULL);
Chris Lattner630404b2008-06-26 04:10:42 +0000813 llvm::Type *StaticsListPtrTy = llvm::PointerType::getUnqual(StaticsListTy);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000814 llvm::Constant *Statics =
815 MakeGlobal(StaticsListTy, Elements, ".objc_statics");
Chris Lattner4e0b2642008-06-24 17:01:28 +0000816 llvm::ArrayType *StaticsListArrayTy =
Chris Lattner630404b2008-06-26 04:10:42 +0000817 llvm::ArrayType::get(StaticsListPtrTy, 2);
Chris Lattner4e0b2642008-06-24 17:01:28 +0000818 Elements.clear();
819 Elements.push_back(Statics);
Chris Lattner630404b2008-06-26 04:10:42 +0000820 Elements.push_back(llvm::Constant::getNullValue(StaticsListPtrTy));
Chris Lattner4e0b2642008-06-24 17:01:28 +0000821 Statics = MakeGlobal(StaticsListArrayTy, Elements, ".objc_statics_ptr");
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000822 Statics = llvm::ConstantExpr::getBitCast(Statics, PtrTy);
823 // Array of classes, categories, and constant objects
824 llvm::ArrayType *ClassListTy = llvm::ArrayType::get(PtrToInt8Ty,
825 Classes.size() + Categories.size() + 2);
Chris Lattnere160c9b2009-01-27 05:06:01 +0000826 llvm::StructType *SymTabTy = llvm::StructType::get(LongTy, SelStructPtrTy,
Chris Lattner630404b2008-06-26 04:10:42 +0000827 llvm::Type::Int16Ty,
828 llvm::Type::Int16Ty,
829 ClassListTy, NULL);
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000830
831 Elements.clear();
832 // Pointer to an array of selectors used in this module.
833 std::vector<llvm::Constant*> Selectors;
834 for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator
835 iter = TypedSelectors.begin(), iterEnd = TypedSelectors.end();
836 iter != iterEnd ; ++iter) {
Chris Lattner630404b2008-06-26 04:10:42 +0000837 Elements.push_back(MakeConstantString(iter->first.first, ".objc_sel_name"));
838 Elements.push_back(MakeConstantString(iter->first.second,
839 ".objc_sel_types"));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000840 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
841 Elements.clear();
842 }
843 for (llvm::StringMap<llvm::GlobalAlias*>::iterator
844 iter = UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
Chris Lattner630404b2008-06-26 04:10:42 +0000845 iter != iterEnd; ++iter) {
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000846 Elements.push_back(
Chris Lattner630404b2008-06-26 04:10:42 +0000847 MakeConstantString(iter->getKeyData(), ".objc_sel_name"));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000848 Elements.push_back(NULLPtr);
849 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
850 Elements.clear();
851 }
852 Elements.push_back(NULLPtr);
853 Elements.push_back(NULLPtr);
854 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
855 Elements.clear();
856 // Number of static selectors
857 Elements.push_back(llvm::ConstantInt::get(LongTy, Selectors.size() ));
858 llvm::Constant *SelectorList = MakeGlobal(
859 llvm::ArrayType::get(SelStructTy, Selectors.size()), Selectors,
860 ".objc_selector_list");
Chris Lattnere160c9b2009-01-27 05:06:01 +0000861 Elements.push_back(llvm::ConstantExpr::getBitCast(SelectorList,
862 SelStructPtrTy));
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000863
864 // Now that all of the static selectors exist, create pointers to them.
865 int index = 0;
866 for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator
867 iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end();
868 iter != iterEnd; ++iter) {
869 llvm::Constant *Idxs[] = {Zeros[0],
870 llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
Chris Lattnere160c9b2009-01-27 05:06:01 +0000871 llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy,
872 true, llvm::GlobalValue::InternalLinkage,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000873 llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
874 ".objc_sel_ptr", &TheModule);
Chris Lattnere160c9b2009-01-27 05:06:01 +0000875 // If selectors are defined as an opaque type, cast the pointer to this
876 // type.
877 if (isSelOpaque) {
878 SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
879 llvm::PointerType::getUnqual(SelectorTy));
880 }
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000881 (*iter).second->setAliasee(SelPtr);
882 }
883 for (llvm::StringMap<llvm::GlobalAlias*>::iterator
884 iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
885 iter != iterEnd; iter++) {
886 llvm::Constant *Idxs[] = {Zeros[0],
887 llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
Chris Lattnere160c9b2009-01-27 05:06:01 +0000888 llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy, true,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000889 llvm::GlobalValue::InternalLinkage,
890 llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
891 ".objc_sel_ptr", &TheModule);
Chris Lattnere160c9b2009-01-27 05:06:01 +0000892 // If selectors are defined as an opaque type, cast the pointer to this
893 // type.
894 if (isSelOpaque) {
895 SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
896 llvm::PointerType::getUnqual(SelectorTy));
897 }
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000898 (*iter).second->setAliasee(SelPtr);
899 }
900 // Number of classes defined.
901 Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty,
902 Classes.size()));
903 // Number of categories defined
904 Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty,
905 Categories.size()));
906 // Create an array of classes, then categories, then static object instances
907 Classes.insert(Classes.end(), Categories.begin(), Categories.end());
908 // NULL-terminated list of static object instances (mainly constant strings)
909 Classes.push_back(Statics);
910 Classes.push_back(NULLPtr);
911 llvm::Constant *ClassList = llvm::ConstantArray::get(ClassListTy, Classes);
912 Elements.push_back(ClassList);
913 // Construct the symbol table
914 llvm::Constant *SymTab= MakeGlobal(SymTabTy, Elements);
915
916 // The symbol table is contained in a module which has some version-checking
917 // constants
918 llvm::StructType * ModuleTy = llvm::StructType::get(LongTy, LongTy,
919 PtrToInt8Ty, llvm::PointerType::getUnqual(SymTabTy), NULL);
920 Elements.clear();
921 // Runtime version used for compatibility checking.
922 Elements.push_back(llvm::ConstantInt::get(LongTy, RuntimeVersion));
923 //FIXME: Should be sizeof(ModuleTy)
924 Elements.push_back(llvm::ConstantInt::get(LongTy, 16));
925 //FIXME: Should be the path to the file where this module was declared
926 Elements.push_back(NULLPtr);
927 Elements.push_back(SymTab);
928 llvm::Value *Module = MakeGlobal(ModuleTy, Elements);
929
930 // Create the load function calling the runtime entry point with the module
931 // structure
932 std::vector<const llvm::Type*> VoidArgs;
933 llvm::Function * LoadFunction = llvm::Function::Create(
934 llvm::FunctionType::get(llvm::Type::VoidTy, VoidArgs, false),
935 llvm::GlobalValue::InternalLinkage, ".objc_load_function",
936 &TheModule);
937 llvm::BasicBlock *EntryBB = llvm::BasicBlock::Create("entry", LoadFunction);
Daniel Dunbar45d196b2008-11-01 01:53:16 +0000938 CGBuilderTy Builder;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000939 Builder.SetInsertPoint(EntryBB);
940 llvm::Value *Register = TheModule.getOrInsertFunction("__objc_exec_class",
941 llvm::Type::VoidTy, llvm::PointerType::getUnqual(ModuleTy), NULL);
942 Builder.CreateCall(Register, Module);
943 Builder.CreateRetVoid();
944 return LoadFunction;
945}
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000946
Fariborz Jahanian679a5022009-01-10 21:06:09 +0000947llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
948 const ObjCContainerDecl *CD) {
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000949 const ObjCCategoryImplDecl *OCD =
Steve Naroff3e0a5402009-01-08 19:41:02 +0000950 dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext());
Chris Lattner077bf5e2008-11-24 03:33:13 +0000951 std::string CategoryName = OCD ? OCD->getNameAsString() : "";
952 std::string ClassName = OMD->getClassInterface()->getNameAsString();
953 std::string MethodName = OMD->getSelector().getAsString();
Douglas Gregorf8d49f62009-01-09 17:18:27 +0000954 bool isClassMethod = !OMD->isInstanceMethod();
Daniel Dunbar7ded7f42008-08-15 22:20:32 +0000955
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000956 CodeGenTypes &Types = CGM.getTypes();
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000957 const llvm::FunctionType *MethodTy =
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000958 Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000959 std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName,
960 MethodName, isClassMethod);
961
Gabor Greif984d0b42008-04-06 20:42:52 +0000962 llvm::Function *Method = llvm::Function::Create(MethodTy,
Chris Lattner391d77a2008-03-30 23:03:07 +0000963 llvm::GlobalValue::InternalLinkage,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000964 FunctionName,
Chris Lattner391d77a2008-03-30 23:03:07 +0000965 &TheModule);
Chris Lattner391d77a2008-03-30 23:03:07 +0000966 return Method;
967}
968
Daniel Dunbar49f66022008-09-24 03:38:44 +0000969llvm::Function *CGObjCGNU::GetPropertyGetFunction() {
970 return 0;
971}
972
973llvm::Function *CGObjCGNU::GetPropertySetFunction() {
974 return 0;
975}
976
977llvm::Function *CGObjCGNU::EnumerationMutationFunction() {
Fariborz Jahanian660af742009-02-03 21:52:35 +0000978return
979 (llvm::Function*)TheModule.getOrInsertFunction(
980 "objc_enumerationMutation", llvm::Type::VoidTy, IdTy, NULL);
Anders Carlsson2abd89c2008-08-31 04:05:03 +0000981}
982
Fariborz Jahanianbd71be42008-11-21 00:49:24 +0000983void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
984 const Stmt &S) {
985 CGF.ErrorUnsupported(&S, "@try/@synchronized statement");
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000986}
987
988void CGObjCGNU::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
Daniel Dunbar49f66022008-09-24 03:38:44 +0000989 const ObjCAtThrowStmt &S) {
Anders Carlsson64d5d6c2008-09-09 10:04:29 +0000990 CGF.ErrorUnsupported(&S, "@throw statement");
991}
992
Fariborz Jahanian3e283e32008-11-18 22:37:34 +0000993llvm::Value * CGObjCGNU::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
Fariborz Jahanian6dc23172008-11-18 21:45:40 +0000994 llvm::Value *AddrWeakObj)
995{
996 return 0;
997}
998
Fariborz Jahanian3e283e32008-11-18 22:37:34 +0000999void CGObjCGNU::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
1000 llvm::Value *src, llvm::Value *dst)
1001{
1002 return;
1003}
1004
Fariborz Jahanian58626502008-11-19 00:59:10 +00001005void CGObjCGNU::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
1006 llvm::Value *src, llvm::Value *dst)
1007{
1008 return;
1009}
1010
Fariborz Jahanian7eda8362008-11-20 19:23:36 +00001011void CGObjCGNU::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
1012 llvm::Value *src, llvm::Value *dst)
1013{
1014 return;
1015}
1016
Fariborz Jahanian58626502008-11-19 00:59:10 +00001017void CGObjCGNU::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
1018 llvm::Value *src, llvm::Value *dst)
1019{
1020 return;
1021}
1022
Fariborz Jahanian598d3f62009-02-03 19:03:09 +00001023LValue CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
1024 QualType ObjectTy,
1025 llvm::Value *BaseValue,
1026 const ObjCIvarDecl *Ivar,
1027 const FieldDecl *Field,
1028 unsigned CVRQualifiers) {
1029 if (Ivar->isBitField())
1030 return CGF.EmitLValueForBitfield(BaseValue, const_cast<FieldDecl *>(Field),
1031 CVRQualifiers);
Fariborz Jahanian0bb20362009-02-02 20:02:29 +00001032 // TODO: Add a special case for isa (index 0)
1033 unsigned Index = CGM.getTypes().getLLVMFieldNo(Field);
1034 llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp");
Fariborz Jahanian598d3f62009-02-03 19:03:09 +00001035 LValue LV = LValue::MakeAddr(V,
1036 Ivar->getType().getCVRQualifiers()|CVRQualifiers);
1037 LValue::SetObjCIvar(LV, true);
1038 return LV;
Fariborz Jahanian0bb20362009-02-02 20:02:29 +00001039}
1040
Fariborz Jahanianf63aa3f2009-02-10 19:02:04 +00001041llvm::Value *CGObjCGNU::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
1042 ObjCInterfaceDecl *Interface,
1043 const ObjCIvarDecl *Ivar) {
1044 const llvm::Type *InterfaceLTy =
1045 CGM.getTypes().ConvertType(
1046 CGM.getContext().getObjCInterfaceType(Interface));
1047 const llvm::StructLayout *Layout =
1048 CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceLTy));
1049 FieldDecl *Field = Interface->lookupFieldDeclForIvar(CGM.getContext(), Ivar);
1050 uint64_t Offset =
1051 Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
1052
1053 return llvm::ConstantInt::get(
1054 CGM.getTypes().ConvertType(CGM.getContext().LongTy),
1055 Offset);
1056}
1057
Daniel Dunbarc17a4d32008-08-11 02:45:11 +00001058CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
Chris Lattnerdce14062008-06-26 04:19:03 +00001059 return new CGObjCGNU(CGM);
Chris Lattner0f984262008-03-01 08:50:34 +00001060}