blob: e6ae6f36b4e131aa541d7a8127b154abec1242fa [file] [log] [blame]
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +00001//===------- CGObjCGNU.cpp - Emit LLVM Code from ASTs for a Module --------===//
Chris Lattnera0fd5ee2008-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 Korobeynikovcd5d08d2008-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 Lattnera0fd5ee2008-03-01 08:50:34 +000014//
15//===----------------------------------------------------------------------===//
16
17#include "CGObjCRuntime.h"
Chris Lattner547907c2008-06-26 04:19:03 +000018#include "CodeGenModule.h"
Daniel Dunbara04840b2008-08-23 03:46:30 +000019#include "CodeGenFunction.h"
Chris Lattner547907c2008-06-26 04:19:03 +000020#include "clang/AST/ASTContext.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000021#include "clang/AST/Decl.h"
Daniel Dunbar84bb85f2008-08-13 00:59:25 +000022#include "clang/AST/DeclObjC.h"
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000023#include "llvm/Module.h"
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000024#include "llvm/ADT/SmallVector.h"
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +000025#include "llvm/ADT/StringMap.h"
Daniel Dunbarac93e472008-08-15 22:20:32 +000026#include "llvm/Support/Compiler.h"
Daniel Dunbarac93e472008-08-15 22:20:32 +000027#include "llvm/Target/TargetData.h"
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +000028#include <map>
Chris Lattner431dc382009-01-27 05:06:01 +000029
30
Chris Lattner547907c2008-06-26 04:19:03 +000031using namespace clang;
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +000032using namespace CodeGen;
Anton Korobeynikovcd5d08d2008-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 Lattnera0fd5ee2008-03-01 08:50:34 +000039
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000040namespace {
Chris Lattner547907c2008-06-26 04:19:03 +000041class CGObjCGNU : public CodeGen::CGObjCRuntime {
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000042private:
Chris Lattner547907c2008-06-26 04:19:03 +000043 CodeGen::CodeGenModule &CGM;
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000044 llvm::Module &TheModule;
Chris Lattner431dc382009-01-27 05:06:01 +000045 const llvm::PointerType *SelectorTy;
46 const llvm::PointerType *PtrToInt8Ty;
Chris Lattnerb326b172008-03-30 23:03:07 +000047 const llvm::Type *IMPTy;
Chris Lattner431dc382009-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 Korobeynikovcd5d08d2008-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 Lattner578279d2008-06-26 05:08:00 +000071 const llvm::SmallVectorImpl<Selector> &MethodSels,
Anton Korobeynikovcd5d08d2008-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 Lattnerad9c3f32008-06-26 04:47:04 +000080 const char *Name,
Anton Korobeynikovcd5d08d2008-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 Lattnera0fd5ee2008-03-01 08:50:34 +000095public:
Chris Lattner547907c2008-06-26 04:19:03 +000096 CGObjCGNU(CodeGen::CodeGenModule &cgm);
Daniel Dunbardaf4ad42008-08-12 00:12:39 +000097 virtual llvm::Constant *GenerateConstantString(const std::string &String);
Daniel Dunbara04840b2008-08-23 03:46:30 +000098 virtual CodeGen::RValue
99 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
Daniel Dunbardd851282008-08-30 05:35:15 +0000100 QualType ResultType,
101 Selector Sel,
Daniel Dunbarb1ee5d62008-08-25 08:19:24 +0000102 llvm::Value *Receiver,
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000103 bool IsClassMessage,
104 const CallArgList &CallArgs);
Daniel Dunbara04840b2008-08-23 03:46:30 +0000105 virtual CodeGen::RValue
106 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
Daniel Dunbardd851282008-08-30 05:35:15 +0000107 QualType ResultType,
108 Selector Sel,
Daniel Dunbarb1ee5d62008-08-25 08:19:24 +0000109 const ObjCInterfaceDecl *Class,
110 llvm::Value *Receiver,
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000111 bool IsClassMessage,
112 const CallArgList &CallArgs);
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000113 virtual llvm::Value *GetClass(CGBuilderTy &Builder,
Daniel Dunbar434627a2008-08-16 00:25:02 +0000114 const ObjCInterfaceDecl *OID);
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000115 virtual llvm::Value *GetSelector(CGBuilderTy &Builder, Selector Sel);
Chris Lattnerd71288e2008-06-26 04:37:12 +0000116
Fariborz Jahanian0adaa8a2009-01-10 21:06:09 +0000117 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
118 const ObjCContainerDecl *CD);
Daniel Dunbarac93e472008-08-15 22:20:32 +0000119 virtual void GenerateCategory(const ObjCCategoryImplDecl *CMD);
120 virtual void GenerateClass(const ObjCImplementationDecl *ClassDecl);
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000121 virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000122 const ObjCProtocolDecl *PD);
123 virtual void GenerateProtocol(const ObjCProtocolDecl *PD);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000124 virtual llvm::Function *ModuleInitFunction();
Daniel Dunbarf7103722008-09-24 03:38:44 +0000125 virtual llvm::Function *GetPropertyGetFunction();
126 virtual llvm::Function *GetPropertySetFunction();
Anders Carlsson58d16242008-08-31 04:05:03 +0000127 virtual llvm::Function *EnumerationMutationFunction();
Anders Carlssonb01a2112008-09-09 10:04:29 +0000128
Fariborz Jahanianfbeda7b2008-11-21 00:49:24 +0000129 virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
130 const Stmt &S);
Anders Carlssonb01a2112008-09-09 10:04:29 +0000131 virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
132 const ObjCAtThrowStmt &S);
Fariborz Jahanian252d87f2008-11-18 22:37:34 +0000133 virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
Fariborz Jahanian3305ad32008-11-18 21:45:40 +0000134 llvm::Value *AddrWeakObj);
Fariborz Jahanian252d87f2008-11-18 22:37:34 +0000135 virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
136 llvm::Value *src, llvm::Value *dst);
Fariborz Jahanian17958902008-11-19 00:59:10 +0000137 virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
138 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanianf310b592008-11-20 19:23:36 +0000139 virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
140 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanian17958902008-11-19 00:59:10 +0000141 virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
142 llvm::Value *src, llvm::Value *dest);
Fariborz Jahanian4337afe2009-02-02 20:02:29 +0000143 virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
144 llvm::Value *BaseValue,
145 const ObjCIvarDecl *Ivar,
146 const FieldDecl *Field,
147 unsigned CVRQualifiers);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000148};
149} // end anonymous namespace
150
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000151
152
153static std::string SymbolNameForClass(const std::string &ClassName) {
154 return ".objc_class_" + ClassName;
155}
156
157static std::string SymbolNameForMethod(const std::string &ClassName, const
158 std::string &CategoryName, const std::string &MethodName, bool isClassMethod)
159{
160 return "._objc_method_" + ClassName +"("+CategoryName+")"+
161 (isClassMethod ? "+" : "-") + MethodName;
162}
163
Chris Lattner547907c2008-06-26 04:19:03 +0000164CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm)
165 : CGM(cgm), TheModule(CGM.getModule()) {
Chris Lattner431dc382009-01-27 05:06:01 +0000166 IntTy = cast<llvm::IntegerType>(
167 CGM.getTypes().ConvertType(CGM.getContext().IntTy));
168 LongTy = cast<llvm::IntegerType>(
169 CGM.getTypes().ConvertType(CGM.getContext().LongTy));
Chris Lattner547907c2008-06-26 04:19:03 +0000170
Sebastian Redle9e21b32008-12-04 00:10:55 +0000171 Zeros[0] = llvm::ConstantInt::get(LongTy, 0);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000172 Zeros[1] = Zeros[0];
173 NULLPtr = llvm::ConstantPointerNull::get(
174 llvm::PointerType::getUnqual(llvm::Type::Int8Ty));
Chris Lattnerb326b172008-03-30 23:03:07 +0000175 // C string type. Used in lots of places.
176 PtrToInt8Ty =
177 llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
178 // Get the selector Type.
Chris Lattner431dc382009-01-27 05:06:01 +0000179 SelectorTy = cast<llvm::PointerType>(
180 CGM.getTypes().ConvertType(CGM.getContext().getObjCSelType()));
181
Chris Lattnerb326b172008-03-30 23:03:07 +0000182 PtrToIntTy = llvm::PointerType::getUnqual(IntTy);
183 PtrTy = PtrToInt8Ty;
184
185 // Object type
186 llvm::PATypeHolder OpaqueObjTy = llvm::OpaqueType::get();
187 llvm::Type *OpaqueIdTy = llvm::PointerType::getUnqual(OpaqueObjTy);
Chris Lattner431dc382009-01-27 05:06:01 +0000188 llvm::Type *ObjectTy = llvm::StructType::get(OpaqueIdTy, NULL);
189 llvm::cast<llvm::OpaqueType>(OpaqueObjTy.get())->refineAbstractTypeTo(
190 ObjectTy);
191 ObjectTy = llvm::cast<llvm::StructType>(OpaqueObjTy.get());
192 IdTy = llvm::PointerType::getUnqual(ObjectTy);
Chris Lattnerb326b172008-03-30 23:03:07 +0000193
194 // IMP type
195 std::vector<const llvm::Type*> IMPArgs;
196 IMPArgs.push_back(IdTy);
197 IMPArgs.push_back(SelectorTy);
198 IMPTy = llvm::FunctionType::get(IdTy, IMPArgs, true);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000199}
200// This has to perform the lookup every time, since posing and related
201// techniques can modify the name -> class mapping.
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000202llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder,
Daniel Dunbar434627a2008-08-16 00:25:02 +0000203 const ObjCInterfaceDecl *OID) {
Chris Lattner271d4c22008-11-24 05:29:24 +0000204 llvm::Value *ClassName = CGM.GetAddrOfConstantCString(OID->getNameAsString());
Daniel Dunbar434627a2008-08-16 00:25:02 +0000205 ClassName = Builder.CreateStructGEP(ClassName, 0);
206
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000207 llvm::Constant *ClassLookupFn =
208 TheModule.getOrInsertFunction("objc_lookup_class", IdTy, PtrToInt8Ty,
209 NULL);
210 return Builder.CreateCall(ClassLookupFn, ClassName);
Chris Lattnerb326b172008-03-30 23:03:07 +0000211}
212
Chris Lattnerd71288e2008-06-26 04:37:12 +0000213/// GetSelector - Return the pointer to the unique'd string for this selector.
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000214llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel) {
Chris Lattnerd71288e2008-06-26 04:37:12 +0000215 // FIXME: uniquing on the string is wasteful, unique on Sel instead!
Chris Lattner3a8f2942008-11-24 03:33:13 +0000216 llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()];
Chris Lattnerd71288e2008-06-26 04:37:12 +0000217 if (US == 0)
218 US = new llvm::GlobalAlias(llvm::PointerType::getUnqual(SelectorTy),
219 llvm::GlobalValue::InternalLinkage,
220 ".objc_untyped_selector_alias",
221 NULL, &TheModule);
222
223 return Builder.CreateLoad(US);
224
225}
226
Chris Lattnera5b18882008-06-26 04:44:19 +0000227llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str,
228 const std::string &Name) {
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000229 llvm::Constant * ConstStr = llvm::ConstantArray::get(Str);
230 ConstStr = new llvm::GlobalVariable(ConstStr->getType(), true,
231 llvm::GlobalValue::InternalLinkage,
232 ConstStr, Name, &TheModule);
233 return llvm::ConstantExpr::getGetElementPtr(ConstStr, Zeros, 2);
234}
235llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::StructType *Ty,
236 std::vector<llvm::Constant*> &V, const std::string &Name) {
237 llvm::Constant *C = llvm::ConstantStruct::get(Ty, V);
238 return new llvm::GlobalVariable(Ty, false,
239 llvm::GlobalValue::InternalLinkage, C, Name, &TheModule);
240}
241llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::ArrayType *Ty,
242 std::vector<llvm::Constant*> &V, const std::string &Name) {
243 llvm::Constant *C = llvm::ConstantArray::get(Ty, V);
244 return new llvm::GlobalVariable(Ty, false,
245 llvm::GlobalValue::InternalLinkage, C, Name, &TheModule);
246}
247
248/// Generate an NSConstantString object.
249//TODO: In case there are any crazy people still using the GNU runtime without
250//an OpenStep implementation, this should let them select their own class for
251//constant strings.
Daniel Dunbardaf4ad42008-08-12 00:12:39 +0000252llvm::Constant *CGObjCGNU::GenerateConstantString(const std::string &Str) {
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000253 std::vector<llvm::Constant*> Ivars;
254 Ivars.push_back(NULLPtr);
Chris Lattnerbac12452008-06-21 21:44:18 +0000255 Ivars.push_back(MakeConstantString(Str));
Daniel Dunbardaf4ad42008-08-12 00:12:39 +0000256 Ivars.push_back(llvm::ConstantInt::get(IntTy, Str.size()));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000257 llvm::Constant *ObjCStr = MakeGlobal(
258 llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, IntTy, NULL),
259 Ivars, ".objc_str");
260 ConstantStrings.push_back(
261 llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty));
262 return ObjCStr;
263}
264
265///Generates a message send where the super is the receiver. This is a message
266///send to self with special delivery semantics indicating which class's method
267///should be called.
Daniel Dunbara04840b2008-08-23 03:46:30 +0000268CodeGen::RValue
269CGObjCGNU::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
Daniel Dunbardd851282008-08-30 05:35:15 +0000270 QualType ResultType,
271 Selector Sel,
Daniel Dunbarb1ee5d62008-08-25 08:19:24 +0000272 const ObjCInterfaceDecl *Class,
273 llvm::Value *Receiver,
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000274 bool IsClassMessage,
275 const CallArgList &CallArgs) {
Daniel Dunbarb1ee5d62008-08-25 08:19:24 +0000276 const ObjCInterfaceDecl *SuperClass = Class->getSuperClass();
Daniel Dunbardd851282008-08-30 05:35:15 +0000277 const llvm::Type *ReturnTy = CGM.getTypes().ConvertType(ResultType);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000278 // TODO: This should be cached, not looked up every time.
Daniel Dunbara04840b2008-08-23 03:46:30 +0000279 llvm::Value *ReceiverClass = GetClass(CGF.Builder, SuperClass);
Daniel Dunbardd851282008-08-30 05:35:15 +0000280 llvm::Value *cmd = GetSelector(CGF.Builder, Sel);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000281 std::vector<const llvm::Type*> impArgTypes;
282 impArgTypes.push_back(Receiver->getType());
Chris Lattnerb326b172008-03-30 23:03:07 +0000283 impArgTypes.push_back(SelectorTy);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000284
285 // Avoid an explicit cast on the IMP by getting a version that has the right
286 // return type.
287 llvm::FunctionType *impType = llvm::FunctionType::get(ReturnTy, impArgTypes,
288 true);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000289 // Construct the structure used to look up the IMP
290 llvm::StructType *ObjCSuperTy = llvm::StructType::get(Receiver->getType(),
291 IdTy, NULL);
Daniel Dunbara04840b2008-08-23 03:46:30 +0000292 llvm::Value *ObjCSuper = CGF.Builder.CreateAlloca(ObjCSuperTy);
Eli Friedman2e630542008-06-13 23:01:12 +0000293 // FIXME: volatility
Daniel Dunbara04840b2008-08-23 03:46:30 +0000294 CGF.Builder.CreateStore(Receiver, CGF.Builder.CreateStructGEP(ObjCSuper, 0));
295 CGF.Builder.CreateStore(ReceiverClass, CGF.Builder.CreateStructGEP(ObjCSuper, 1));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000296
297 // Get the IMP
298 llvm::Constant *lookupFunction =
299 TheModule.getOrInsertFunction("objc_msg_lookup_super",
300 llvm::PointerType::getUnqual(impType),
301 llvm::PointerType::getUnqual(ObjCSuperTy),
302 SelectorTy, NULL);
303 llvm::Value *lookupArgs[] = {ObjCSuper, cmd};
Daniel Dunbara04840b2008-08-23 03:46:30 +0000304 llvm::Value *imp = CGF.Builder.CreateCall(lookupFunction, lookupArgs,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000305 lookupArgs+2);
306
307 // Call the method
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000308 CallArgList ActualArgs;
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +0000309 ActualArgs.push_back(std::make_pair(RValue::get(Receiver),
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000310 CGF.getContext().getObjCIdType()));
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +0000311 ActualArgs.push_back(std::make_pair(RValue::get(cmd),
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000312 CGF.getContext().getObjCSelType()));
313 ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
Daniel Dunbar6ee022b2009-02-02 22:03:45 +0000314 return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000315}
316
317/// Generate code for a message send expression.
Daniel Dunbara04840b2008-08-23 03:46:30 +0000318CodeGen::RValue
319CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
Daniel Dunbardd851282008-08-30 05:35:15 +0000320 QualType ResultType,
321 Selector Sel,
Daniel Dunbarb1ee5d62008-08-25 08:19:24 +0000322 llvm::Value *Receiver,
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000323 bool IsClassMessage,
324 const CallArgList &CallArgs) {
Daniel Dunbardd851282008-08-30 05:35:15 +0000325 const llvm::Type *ReturnTy = CGM.getTypes().ConvertType(ResultType);
326 llvm::Value *cmd = GetSelector(CGF.Builder, Sel);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000327
328 // Look up the method implementation.
329 std::vector<const llvm::Type*> impArgTypes;
330 const llvm::Type *RetTy;
331 //TODO: Revisit this when LLVM supports aggregate return types.
332 if (ReturnTy->isSingleValueType() && ReturnTy != llvm::Type::VoidTy) {
333 RetTy = ReturnTy;
334 } else {
335 // For struct returns allocate the space in the caller and pass it up to
336 // the sender.
337 RetTy = llvm::Type::VoidTy;
338 impArgTypes.push_back(llvm::PointerType::getUnqual(ReturnTy));
339 }
340 impArgTypes.push_back(Receiver->getType());
341 impArgTypes.push_back(SelectorTy);
342
343 // Avoid an explicit cast on the IMP by getting a version that has the right
344 // return type.
345 llvm::FunctionType *impType = llvm::FunctionType::get(RetTy, impArgTypes,
346 true);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000347
348 llvm::Constant *lookupFunction =
349 TheModule.getOrInsertFunction("objc_msg_lookup",
Chris Lattnerb326b172008-03-30 23:03:07 +0000350 llvm::PointerType::getUnqual(impType),
351 Receiver->getType(), SelectorTy, NULL);
Daniel Dunbara04840b2008-08-23 03:46:30 +0000352 llvm::Value *imp = CGF.Builder.CreateCall2(lookupFunction, Receiver, cmd);
Chris Lattner7db5e942008-05-06 00:56:42 +0000353
354 // Call the method.
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000355 CallArgList ActualArgs;
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +0000356 ActualArgs.push_back(std::make_pair(RValue::get(Receiver),
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000357 CGF.getContext().getObjCIdType()));
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +0000358 ActualArgs.push_back(std::make_pair(RValue::get(cmd),
Daniel Dunbar0ed60b02008-08-30 03:02:31 +0000359 CGF.getContext().getObjCSelType()));
360 ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
Daniel Dunbar6ee022b2009-02-02 22:03:45 +0000361 return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000362}
363
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000364/// Generates a MethodList. Used in construction of a objc_class and
365/// objc_category structures.
366llvm::Constant *CGObjCGNU::GenerateMethodList(const std::string &ClassName,
Chris Lattner578279d2008-06-26 05:08:00 +0000367 const std::string &CategoryName,
368 const llvm::SmallVectorImpl<Selector> &MethodSels,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000369 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes,
370 bool isClassMethodList) {
371 // Get the method structure type.
372 llvm::StructType *ObjCMethodTy = llvm::StructType::get(
373 PtrToInt8Ty, // Really a selector, but the runtime creates it us.
374 PtrToInt8Ty, // Method types
375 llvm::PointerType::getUnqual(IMPTy), //Method pointer
376 NULL);
377 std::vector<llvm::Constant*> Methods;
378 std::vector<llvm::Constant*> Elements;
379 for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) {
380 Elements.clear();
Chris Lattner3a8f2942008-11-24 03:33:13 +0000381 llvm::Constant *C =
382 CGM.GetAddrOfConstantCString(MethodSels[i].getAsString());
Chris Lattner578279d2008-06-26 05:08:00 +0000383 Elements.push_back(llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000384 Elements.push_back(
385 llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2));
386 llvm::Constant *Method =
387 TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName,
Chris Lattner3a8f2942008-11-24 03:33:13 +0000388 MethodSels[i].getAsString(),
Chris Lattnere7581092008-06-26 04:05:20 +0000389 isClassMethodList));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000390 Method = llvm::ConstantExpr::getBitCast(Method,
391 llvm::PointerType::getUnqual(IMPTy));
392 Elements.push_back(Method);
393 Methods.push_back(llvm::ConstantStruct::get(ObjCMethodTy, Elements));
394 }
395
396 // Array of method structures
397 llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodTy,
Chris Lattner578279d2008-06-26 05:08:00 +0000398 MethodSels.size());
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000399 llvm::Constant *MethodArray = llvm::ConstantArray::get(ObjCMethodArrayTy,
Chris Lattnerbcb3e862008-06-26 04:52:29 +0000400 Methods);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000401
402 // Structure containing list pointer, array and array count
403 llvm::SmallVector<const llvm::Type*, 16> ObjCMethodListFields;
404 llvm::PATypeHolder OpaqueNextTy = llvm::OpaqueType::get();
405 llvm::Type *NextPtrTy = llvm::PointerType::getUnqual(OpaqueNextTy);
406 llvm::StructType *ObjCMethodListTy = llvm::StructType::get(NextPtrTy,
407 IntTy,
408 ObjCMethodArrayTy,
409 NULL);
410 // Refine next pointer type to concrete type
411 llvm::cast<llvm::OpaqueType>(
412 OpaqueNextTy.get())->refineAbstractTypeTo(ObjCMethodListTy);
413 ObjCMethodListTy = llvm::cast<llvm::StructType>(OpaqueNextTy.get());
414
415 Methods.clear();
416 Methods.push_back(llvm::ConstantPointerNull::get(
417 llvm::PointerType::getUnqual(ObjCMethodListTy)));
418 Methods.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty,
419 MethodTypes.size()));
420 Methods.push_back(MethodArray);
421
422 // Create an instance of the structure
423 return MakeGlobal(ObjCMethodListTy, Methods, ".objc_method_list");
424}
425
426/// Generates an IvarList. Used in construction of a objc_class.
427llvm::Constant *CGObjCGNU::GenerateIvarList(
428 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
429 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
430 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets) {
431 // Get the method structure type.
432 llvm::StructType *ObjCIvarTy = llvm::StructType::get(
433 PtrToInt8Ty,
434 PtrToInt8Ty,
435 IntTy,
436 NULL);
437 std::vector<llvm::Constant*> Ivars;
438 std::vector<llvm::Constant*> Elements;
439 for (unsigned int i = 0, e = IvarNames.size() ; i < e ; i++) {
440 Elements.clear();
441 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(IvarNames[i],
442 Zeros, 2));
443 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(IvarTypes[i],
444 Zeros, 2));
445 Elements.push_back(IvarOffsets[i]);
446 Ivars.push_back(llvm::ConstantStruct::get(ObjCIvarTy, Elements));
447 }
448
449 // Array of method structures
450 llvm::ArrayType *ObjCIvarArrayTy = llvm::ArrayType::get(ObjCIvarTy,
451 IvarNames.size());
452
453
454 Elements.clear();
Chris Lattner431dc382009-01-27 05:06:01 +0000455 Elements.push_back(llvm::ConstantInt::get(IntTy, (int)IvarNames.size()));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000456 Elements.push_back(llvm::ConstantArray::get(ObjCIvarArrayTy, Ivars));
457 // Structure containing array and array count
458 llvm::StructType *ObjCIvarListTy = llvm::StructType::get(IntTy,
459 ObjCIvarArrayTy,
460 NULL);
461
462 // Create an instance of the structure
463 return MakeGlobal(ObjCIvarListTy, Elements, ".objc_ivar_list");
464}
465
466/// Generate a class structure
467llvm::Constant *CGObjCGNU::GenerateClassStructure(
468 llvm::Constant *MetaClass,
469 llvm::Constant *SuperClass,
470 unsigned info,
Chris Lattnerad9c3f32008-06-26 04:47:04 +0000471 const char *Name,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000472 llvm::Constant *Version,
473 llvm::Constant *InstanceSize,
474 llvm::Constant *IVars,
475 llvm::Constant *Methods,
476 llvm::Constant *Protocols) {
477 // Set up the class structure
478 // Note: Several of these are char*s when they should be ids. This is
479 // because the runtime performs this translation on load.
480 llvm::StructType *ClassTy = llvm::StructType::get(
481 PtrToInt8Ty, // class_pointer
482 PtrToInt8Ty, // super_class
483 PtrToInt8Ty, // name
484 LongTy, // version
485 LongTy, // info
486 LongTy, // instance_size
487 IVars->getType(), // ivars
488 Methods->getType(), // methods
489 // These are all filled in by the runtime, so we pretend
490 PtrTy, // dtable
491 PtrTy, // subclass_list
492 PtrTy, // sibling_class
493 PtrTy, // protocols
494 PtrTy, // gc_object_type
495 NULL);
496 llvm::Constant *Zero = llvm::ConstantInt::get(LongTy, 0);
497 llvm::Constant *NullP =
Chris Lattner431dc382009-01-27 05:06:01 +0000498 llvm::ConstantPointerNull::get(PtrTy);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000499 // Fill in the structure
500 std::vector<llvm::Constant*> Elements;
501 Elements.push_back(llvm::ConstantExpr::getBitCast(MetaClass, PtrToInt8Ty));
502 Elements.push_back(SuperClass);
Chris Lattnerad9c3f32008-06-26 04:47:04 +0000503 Elements.push_back(MakeConstantString(Name, ".class_name"));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000504 Elements.push_back(Zero);
505 Elements.push_back(llvm::ConstantInt::get(LongTy, info));
506 Elements.push_back(InstanceSize);
507 Elements.push_back(IVars);
508 Elements.push_back(Methods);
509 Elements.push_back(NullP);
510 Elements.push_back(NullP);
511 Elements.push_back(NullP);
512 Elements.push_back(llvm::ConstantExpr::getBitCast(Protocols, PtrTy));
513 Elements.push_back(NullP);
514 // Create an instance of the structure
Chris Lattner4d018542008-07-21 06:31:05 +0000515 return MakeGlobal(ClassTy, Elements, SymbolNameForClass(Name));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000516}
517
518llvm::Constant *CGObjCGNU::GenerateProtocolMethodList(
519 const llvm::SmallVectorImpl<llvm::Constant *> &MethodNames,
520 const llvm::SmallVectorImpl<llvm::Constant *> &MethodTypes) {
521 // Get the method structure type.
522 llvm::StructType *ObjCMethodDescTy = llvm::StructType::get(
523 PtrToInt8Ty, // Really a selector, but the runtime does the casting for us.
524 PtrToInt8Ty,
525 NULL);
526 std::vector<llvm::Constant*> Methods;
527 std::vector<llvm::Constant*> Elements;
528 for (unsigned int i = 0, e = MethodTypes.size() ; i < e ; i++) {
529 Elements.clear();
530 Elements.push_back( llvm::ConstantExpr::getGetElementPtr(MethodNames[i],
531 Zeros, 2));
532 Elements.push_back(
533 llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2));
534 Methods.push_back(llvm::ConstantStruct::get(ObjCMethodDescTy, Elements));
535 }
536 llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodDescTy,
537 MethodNames.size());
538 llvm::Constant *Array = llvm::ConstantArray::get(ObjCMethodArrayTy, Methods);
539 llvm::StructType *ObjCMethodDescListTy = llvm::StructType::get(
540 IntTy, ObjCMethodArrayTy, NULL);
541 Methods.clear();
542 Methods.push_back(llvm::ConstantInt::get(IntTy, MethodNames.size()));
543 Methods.push_back(Array);
544 return MakeGlobal(ObjCMethodDescListTy, Methods, ".objc_method_list");
545}
546// Create the protocol list structure used in classes, categories and so on
547llvm::Constant *CGObjCGNU::GenerateProtocolList(
548 const llvm::SmallVectorImpl<std::string> &Protocols) {
549 llvm::ArrayType *ProtocolArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
550 Protocols.size());
551 llvm::StructType *ProtocolListTy = llvm::StructType::get(
552 PtrTy, //Should be a recurisve pointer, but it's always NULL here.
553 LongTy,//FIXME: Should be size_t
554 ProtocolArrayTy,
555 NULL);
556 std::vector<llvm::Constant*> Elements;
557 for (const std::string *iter = Protocols.begin(), *endIter = Protocols.end();
558 iter != endIter ; iter++) {
559 llvm::Constant *Ptr =
560 llvm::ConstantExpr::getBitCast(ExistingProtocols[*iter], PtrToInt8Ty);
561 Elements.push_back(Ptr);
562 }
563 llvm::Constant * ProtocolArray = llvm::ConstantArray::get(ProtocolArrayTy,
564 Elements);
565 Elements.clear();
566 Elements.push_back(NULLPtr);
Chris Lattner431dc382009-01-27 05:06:01 +0000567 Elements.push_back(llvm::ConstantInt::get(LongTy, Protocols.size()));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000568 Elements.push_back(ProtocolArray);
569 return MakeGlobal(ProtocolListTy, Elements, ".objc_protocol_list");
570}
571
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000572llvm::Value *CGObjCGNU::GenerateProtocolRef(CGBuilderTy &Builder,
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000573 const ObjCProtocolDecl *PD) {
Chris Lattner271d4c22008-11-24 05:29:24 +0000574 return ExistingProtocols[PD->getNameAsString()];
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000575}
576
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000577void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
578 ASTContext &Context = CGM.getContext();
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000579 std::string ProtocolName = PD->getNameAsString();
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000580 llvm::SmallVector<std::string, 16> Protocols;
581 for (ObjCProtocolDecl::protocol_iterator PI = PD->protocol_begin(),
582 E = PD->protocol_end(); PI != E; ++PI)
Chris Lattner271d4c22008-11-24 05:29:24 +0000583 Protocols.push_back((*PI)->getNameAsString());
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000584 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodNames;
585 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
586 for (ObjCProtocolDecl::instmeth_iterator iter = PD->instmeth_begin(),
587 E = PD->instmeth_end(); iter != E; iter++) {
588 std::string TypeStr;
589 Context.getObjCEncodingForMethodDecl(*iter, TypeStr);
590 InstanceMethodNames.push_back(
Chris Lattner3a8f2942008-11-24 03:33:13 +0000591 CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
Daniel Dunbar31fe9c32008-08-13 23:20:05 +0000592 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000593 }
594 // Collect information about class methods:
595 llvm::SmallVector<llvm::Constant*, 16> ClassMethodNames;
596 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
597 for (ObjCProtocolDecl::classmeth_iterator iter = PD->classmeth_begin(),
598 endIter = PD->classmeth_end() ; iter != endIter ; iter++) {
599 std::string TypeStr;
600 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
601 ClassMethodNames.push_back(
Chris Lattner3a8f2942008-11-24 03:33:13 +0000602 CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString()));
Daniel Dunbar31fe9c32008-08-13 23:20:05 +0000603 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000604 }
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000605
606 llvm::Constant *ProtocolList = GenerateProtocolList(Protocols);
607 llvm::Constant *InstanceMethodList =
608 GenerateProtocolMethodList(InstanceMethodNames, InstanceMethodTypes);
609 llvm::Constant *ClassMethodList =
610 GenerateProtocolMethodList(ClassMethodNames, ClassMethodTypes);
611 // Protocols are objects containing lists of the methods implemented and
612 // protocols adopted.
613 llvm::StructType *ProtocolTy = llvm::StructType::get(IdTy,
614 PtrToInt8Ty,
615 ProtocolList->getType(),
616 InstanceMethodList->getType(),
617 ClassMethodList->getType(),
618 NULL);
619 std::vector<llvm::Constant*> Elements;
620 // The isa pointer must be set to a magic number so the runtime knows it's
621 // the correct layout.
622 Elements.push_back(llvm::ConstantExpr::getIntToPtr(
623 llvm::ConstantInt::get(llvm::Type::Int32Ty, ProtocolVersion), IdTy));
624 Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
625 Elements.push_back(ProtocolList);
626 Elements.push_back(InstanceMethodList);
627 Elements.push_back(ClassMethodList);
628 ExistingProtocols[ProtocolName] =
629 llvm::ConstantExpr::getBitCast(MakeGlobal(ProtocolTy, Elements,
630 ".objc_protocol"), IdTy);
631}
632
Daniel Dunbarac93e472008-08-15 22:20:32 +0000633void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000634 std::string ClassName = OCD->getClassInterface()->getNameAsString();
635 std::string CategoryName = OCD->getNameAsString();
Daniel Dunbarac93e472008-08-15 22:20:32 +0000636 // Collect information about instance methods
637 llvm::SmallVector<Selector, 16> InstanceMethodSels;
638 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
Steve Naroffab63fd62009-01-08 17:28:14 +0000639 for (ObjCCategoryImplDecl::instmeth_iterator iter = OCD->instmeth_begin(),
Daniel Dunbarac93e472008-08-15 22:20:32 +0000640 endIter = OCD->instmeth_end() ; iter != endIter ; iter++) {
641 InstanceMethodSels.push_back((*iter)->getSelector());
642 std::string TypeStr;
643 CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
644 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
645 }
646
647 // Collect information about class methods
648 llvm::SmallVector<Selector, 16> ClassMethodSels;
649 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
Steve Naroffab63fd62009-01-08 17:28:14 +0000650 for (ObjCCategoryImplDecl::classmeth_iterator iter = OCD->classmeth_begin(),
Daniel Dunbarac93e472008-08-15 22:20:32 +0000651 endIter = OCD->classmeth_end() ; iter != endIter ; iter++) {
652 ClassMethodSels.push_back((*iter)->getSelector());
653 std::string TypeStr;
654 CGM.getContext().getObjCEncodingForMethodDecl(*iter,TypeStr);
655 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
656 }
657
658 // Collect the names of referenced protocols
659 llvm::SmallVector<std::string, 16> Protocols;
660 const ObjCInterfaceDecl *ClassDecl = OCD->getClassInterface();
661 const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
662 for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
663 E = Protos.end(); I != E; ++I)
Chris Lattner271d4c22008-11-24 05:29:24 +0000664 Protocols.push_back((*I)->getNameAsString());
Daniel Dunbarac93e472008-08-15 22:20:32 +0000665
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000666 std::vector<llvm::Constant*> Elements;
667 Elements.push_back(MakeConstantString(CategoryName));
668 Elements.push_back(MakeConstantString(ClassName));
669 // Instance method list
670 Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
Chris Lattner578279d2008-06-26 05:08:00 +0000671 ClassName, CategoryName, InstanceMethodSels, InstanceMethodTypes,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000672 false), PtrTy));
673 // Class method list
674 Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList(
Chris Lattner578279d2008-06-26 05:08:00 +0000675 ClassName, CategoryName, ClassMethodSels, ClassMethodTypes, true),
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000676 PtrTy));
677 // Protocol list
678 Elements.push_back(llvm::ConstantExpr::getBitCast(
679 GenerateProtocolList(Protocols), PtrTy));
680 Categories.push_back(llvm::ConstantExpr::getBitCast(
681 MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, PtrTy,
682 PtrTy, PtrTy, NULL), Elements), PtrTy));
683}
Daniel Dunbarac93e472008-08-15 22:20:32 +0000684
685void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
686 ASTContext &Context = CGM.getContext();
687
688 // Get the superclass name.
689 const ObjCInterfaceDecl * SuperClassDecl =
690 OID->getClassInterface()->getSuperClass();
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000691 std::string SuperClassName;
692 if (SuperClassDecl)
693 SuperClassName = SuperClassDecl->getNameAsString();
Daniel Dunbarac93e472008-08-15 22:20:32 +0000694
695 // Get the class name
696 ObjCInterfaceDecl * ClassDecl = (ObjCInterfaceDecl*)OID->getClassInterface();
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000697 std::string ClassName = ClassDecl->getNameAsString();
Daniel Dunbarac93e472008-08-15 22:20:32 +0000698
699 // Get the size of instances. For runtimes that support late-bound instances
700 // this should probably be something different (size just of instance
701 // varaibles in this class, not superclasses?).
702 int instanceSize = 0;
703 const llvm::Type *ObjTy = 0;
704 if (!LateBoundIVars()) {
705 ObjTy = CGM.getTypes().ConvertType(Context.getObjCInterfaceType(ClassDecl));
Daniel Dunbard8439f22009-01-12 21:08:18 +0000706 instanceSize = CGM.getTargetData().getTypePaddedSize(ObjTy);
Daniel Dunbarac93e472008-08-15 22:20:32 +0000707 } else {
708 // This is required by newer ObjC runtimes.
709 assert(0 && "Late-bound instance variables not yet supported");
710 }
711
712 // Collect information about instance variables.
713 llvm::SmallVector<llvm::Constant*, 16> IvarNames;
714 llvm::SmallVector<llvm::Constant*, 16> IvarTypes;
715 llvm::SmallVector<llvm::Constant*, 16> IvarOffsets;
716 const llvm::StructLayout *Layout =
717 CGM.getTargetData().getStructLayout(cast<llvm::StructType>(ObjTy));
718 ObjTy = llvm::PointerType::getUnqual(ObjTy);
719 for (ObjCInterfaceDecl::ivar_iterator iter = ClassDecl->ivar_begin(),
720 endIter = ClassDecl->ivar_end() ; iter != endIter ; iter++) {
721 // Store the name
Chris Lattner271d4c22008-11-24 05:29:24 +0000722 IvarNames.push_back(CGM.GetAddrOfConstantCString((*iter)
723 ->getNameAsString()));
Daniel Dunbarac93e472008-08-15 22:20:32 +0000724 // Get the type encoding for this ivar
725 std::string TypeStr;
Daniel Dunbarc9197cd2008-10-17 20:21:44 +0000726 Context.getObjCEncodingForType((*iter)->getType(), TypeStr);
Daniel Dunbarac93e472008-08-15 22:20:32 +0000727 IvarTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
728 // Get the offset
Fariborz Jahanian86008c02008-12-15 20:35:07 +0000729 FieldDecl *Field = ClassDecl->lookupFieldDeclForIvar(Context, (*iter));
Daniel Dunbarac93e472008-08-15 22:20:32 +0000730 int offset =
Fariborz Jahanian86008c02008-12-15 20:35:07 +0000731 (int)Layout->getElementOffset(CGM.getTypes().getLLVMFieldNo(Field));
Daniel Dunbarac93e472008-08-15 22:20:32 +0000732 IvarOffsets.push_back(
733 llvm::ConstantInt::get(llvm::Type::Int32Ty, offset));
734 }
735
736 // Collect information about instance methods
737 llvm::SmallVector<Selector, 16> InstanceMethodSels;
738 llvm::SmallVector<llvm::Constant*, 16> InstanceMethodTypes;
739 for (ObjCImplementationDecl::instmeth_iterator iter = OID->instmeth_begin(),
740 endIter = OID->instmeth_end() ; iter != endIter ; iter++) {
741 InstanceMethodSels.push_back((*iter)->getSelector());
742 std::string TypeStr;
743 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
744 InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
745 }
746
747 // Collect information about class methods
748 llvm::SmallVector<Selector, 16> ClassMethodSels;
749 llvm::SmallVector<llvm::Constant*, 16> ClassMethodTypes;
750 for (ObjCImplementationDecl::classmeth_iterator iter = OID->classmeth_begin(),
751 endIter = OID->classmeth_end() ; iter != endIter ; iter++) {
752 ClassMethodSels.push_back((*iter)->getSelector());
753 std::string TypeStr;
754 Context.getObjCEncodingForMethodDecl((*iter),TypeStr);
755 ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr));
756 }
757 // Collect the names of referenced protocols
758 llvm::SmallVector<std::string, 16> Protocols;
759 const ObjCList<ObjCProtocolDecl> &Protos =ClassDecl->getReferencedProtocols();
760 for (ObjCList<ObjCProtocolDecl>::iterator I = Protos.begin(),
761 E = Protos.end(); I != E; ++I)
Chris Lattner271d4c22008-11-24 05:29:24 +0000762 Protocols.push_back((*I)->getNameAsString());
Daniel Dunbarac93e472008-08-15 22:20:32 +0000763
764
765
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000766 // Get the superclass pointer.
767 llvm::Constant *SuperClass;
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000768 if (!SuperClassName.empty()) {
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000769 SuperClass = MakeConstantString(SuperClassName, ".super_class_name");
770 } else {
Chris Lattner431dc382009-01-27 05:06:01 +0000771 SuperClass = llvm::ConstantPointerNull::get(PtrToInt8Ty);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000772 }
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000773 // Empty vector used to construct empty method lists
774 llvm::SmallVector<llvm::Constant*, 1> empty;
775 // Generate the method and instance variable lists
776 llvm::Constant *MethodList = GenerateMethodList(ClassName, "",
Chris Lattner578279d2008-06-26 05:08:00 +0000777 InstanceMethodSels, InstanceMethodTypes, false);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000778 llvm::Constant *ClassMethodList = GenerateMethodList(ClassName, "",
Chris Lattner578279d2008-06-26 05:08:00 +0000779 ClassMethodSels, ClassMethodTypes, true);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000780 llvm::Constant *IvarList = GenerateIvarList(IvarNames, IvarTypes,
781 IvarOffsets);
782 //Generate metaclass for class methods
783 llvm::Constant *MetaClassStruct = GenerateClassStructure(NULLPtr,
Chris Lattner4d018542008-07-21 06:31:05 +0000784 NULLPtr, 0x2L, /*name*/"", 0, Zeros[0], GenerateIvarList(
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000785 empty, empty, empty), ClassMethodList, NULLPtr);
786 // Generate the class structure
Chris Lattnerd120b9e2008-11-24 03:54:41 +0000787 llvm::Constant *ClassStruct =
788 GenerateClassStructure(MetaClassStruct, SuperClass, 0x1L,
789 ClassName.c_str(), 0,
Sebastian Redle9e21b32008-12-04 00:10:55 +0000790 llvm::ConstantInt::get(LongTy, instanceSize), IvarList,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000791 MethodList, GenerateProtocolList(Protocols));
792 // Add class structure to list to be added to the symtab later
793 ClassStruct = llvm::ConstantExpr::getBitCast(ClassStruct, PtrToInt8Ty);
794 Classes.push_back(ClassStruct);
795}
796
797llvm::Function *CGObjCGNU::ModuleInitFunction() {
798 // Only emit an ObjC load function if no Objective-C stuff has been called
799 if (Classes.empty() && Categories.empty() && ConstantStrings.empty() &&
800 ExistingProtocols.empty() && TypedSelectors.empty() &&
Anton Korobeynikovb41e4972008-06-01 15:14:46 +0000801 UntypedSelectors.empty())
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000802 return NULL;
Eli Friedman7719bc82008-06-01 16:00:02 +0000803
Chris Lattner431dc382009-01-27 05:06:01 +0000804 const llvm::StructType *SelStructTy = dyn_cast<llvm::StructType>(
805 SelectorTy->getElementType());
806 const llvm::Type *SelStructPtrTy = SelectorTy;
807 bool isSelOpaque = false;
808 if (SelStructTy == 0) {
809 SelStructTy = llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, NULL);
810 SelStructPtrTy = llvm::PointerType::getUnqual(SelStructTy);
811 isSelOpaque = true;
812 }
813
Eli Friedman7719bc82008-06-01 16:00:02 +0000814 // Name the ObjC types to make the IR a bit easier to read
Chris Lattner431dc382009-01-27 05:06:01 +0000815 TheModule.addTypeName(".objc_selector", SelStructPtrTy);
Eli Friedman7719bc82008-06-01 16:00:02 +0000816 TheModule.addTypeName(".objc_id", IdTy);
817 TheModule.addTypeName(".objc_imp", IMPTy);
818
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000819 std::vector<llvm::Constant*> Elements;
820 // Generate statics list:
821 llvm::ArrayType *StaticsArrayTy = llvm::ArrayType::get(PtrToInt8Ty,
822 ConstantStrings.size() + 1);
823 ConstantStrings.push_back(NULLPtr);
824 Elements.push_back(MakeConstantString("NSConstantString",
825 ".objc_static_class_name"));
826 Elements.push_back(llvm::ConstantArray::get(StaticsArrayTy, ConstantStrings));
827 llvm::StructType *StaticsListTy =
828 llvm::StructType::get(PtrToInt8Ty, StaticsArrayTy, NULL);
Chris Lattneref843042008-06-26 04:10:42 +0000829 llvm::Type *StaticsListPtrTy = llvm::PointerType::getUnqual(StaticsListTy);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000830 llvm::Constant *Statics =
831 MakeGlobal(StaticsListTy, Elements, ".objc_statics");
Chris Lattner60eaae82008-06-24 17:01:28 +0000832 llvm::ArrayType *StaticsListArrayTy =
Chris Lattneref843042008-06-26 04:10:42 +0000833 llvm::ArrayType::get(StaticsListPtrTy, 2);
Chris Lattner60eaae82008-06-24 17:01:28 +0000834 Elements.clear();
835 Elements.push_back(Statics);
Chris Lattneref843042008-06-26 04:10:42 +0000836 Elements.push_back(llvm::Constant::getNullValue(StaticsListPtrTy));
Chris Lattner60eaae82008-06-24 17:01:28 +0000837 Statics = MakeGlobal(StaticsListArrayTy, Elements, ".objc_statics_ptr");
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000838 Statics = llvm::ConstantExpr::getBitCast(Statics, PtrTy);
839 // Array of classes, categories, and constant objects
840 llvm::ArrayType *ClassListTy = llvm::ArrayType::get(PtrToInt8Ty,
841 Classes.size() + Categories.size() + 2);
Chris Lattner431dc382009-01-27 05:06:01 +0000842 llvm::StructType *SymTabTy = llvm::StructType::get(LongTy, SelStructPtrTy,
Chris Lattneref843042008-06-26 04:10:42 +0000843 llvm::Type::Int16Ty,
844 llvm::Type::Int16Ty,
845 ClassListTy, NULL);
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000846
847 Elements.clear();
848 // Pointer to an array of selectors used in this module.
849 std::vector<llvm::Constant*> Selectors;
850 for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator
851 iter = TypedSelectors.begin(), iterEnd = TypedSelectors.end();
852 iter != iterEnd ; ++iter) {
Chris Lattneref843042008-06-26 04:10:42 +0000853 Elements.push_back(MakeConstantString(iter->first.first, ".objc_sel_name"));
854 Elements.push_back(MakeConstantString(iter->first.second,
855 ".objc_sel_types"));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000856 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
857 Elements.clear();
858 }
859 for (llvm::StringMap<llvm::GlobalAlias*>::iterator
860 iter = UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
Chris Lattneref843042008-06-26 04:10:42 +0000861 iter != iterEnd; ++iter) {
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000862 Elements.push_back(
Chris Lattneref843042008-06-26 04:10:42 +0000863 MakeConstantString(iter->getKeyData(), ".objc_sel_name"));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000864 Elements.push_back(NULLPtr);
865 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
866 Elements.clear();
867 }
868 Elements.push_back(NULLPtr);
869 Elements.push_back(NULLPtr);
870 Selectors.push_back(llvm::ConstantStruct::get(SelStructTy, Elements));
871 Elements.clear();
872 // Number of static selectors
873 Elements.push_back(llvm::ConstantInt::get(LongTy, Selectors.size() ));
874 llvm::Constant *SelectorList = MakeGlobal(
875 llvm::ArrayType::get(SelStructTy, Selectors.size()), Selectors,
876 ".objc_selector_list");
Chris Lattner431dc382009-01-27 05:06:01 +0000877 Elements.push_back(llvm::ConstantExpr::getBitCast(SelectorList,
878 SelStructPtrTy));
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000879
880 // Now that all of the static selectors exist, create pointers to them.
881 int index = 0;
882 for (std::map<TypedSelector, llvm::GlobalAlias*>::iterator
883 iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end();
884 iter != iterEnd; ++iter) {
885 llvm::Constant *Idxs[] = {Zeros[0],
886 llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
Chris Lattner431dc382009-01-27 05:06:01 +0000887 llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy,
888 true, llvm::GlobalValue::InternalLinkage,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000889 llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
890 ".objc_sel_ptr", &TheModule);
Chris Lattner431dc382009-01-27 05:06:01 +0000891 // If selectors are defined as an opaque type, cast the pointer to this
892 // type.
893 if (isSelOpaque) {
894 SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
895 llvm::PointerType::getUnqual(SelectorTy));
896 }
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000897 (*iter).second->setAliasee(SelPtr);
898 }
899 for (llvm::StringMap<llvm::GlobalAlias*>::iterator
900 iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
901 iter != iterEnd; iter++) {
902 llvm::Constant *Idxs[] = {Zeros[0],
903 llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]};
Chris Lattner431dc382009-01-27 05:06:01 +0000904 llvm::Constant *SelPtr = new llvm::GlobalVariable(SelStructPtrTy, true,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000905 llvm::GlobalValue::InternalLinkage,
906 llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
907 ".objc_sel_ptr", &TheModule);
Chris Lattner431dc382009-01-27 05:06:01 +0000908 // If selectors are defined as an opaque type, cast the pointer to this
909 // type.
910 if (isSelOpaque) {
911 SelPtr = llvm::ConstantExpr::getBitCast(SelPtr,
912 llvm::PointerType::getUnqual(SelectorTy));
913 }
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000914 (*iter).second->setAliasee(SelPtr);
915 }
916 // Number of classes defined.
917 Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty,
918 Classes.size()));
919 // Number of categories defined
920 Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty,
921 Categories.size()));
922 // Create an array of classes, then categories, then static object instances
923 Classes.insert(Classes.end(), Categories.begin(), Categories.end());
924 // NULL-terminated list of static object instances (mainly constant strings)
925 Classes.push_back(Statics);
926 Classes.push_back(NULLPtr);
927 llvm::Constant *ClassList = llvm::ConstantArray::get(ClassListTy, Classes);
928 Elements.push_back(ClassList);
929 // Construct the symbol table
930 llvm::Constant *SymTab= MakeGlobal(SymTabTy, Elements);
931
932 // The symbol table is contained in a module which has some version-checking
933 // constants
934 llvm::StructType * ModuleTy = llvm::StructType::get(LongTy, LongTy,
935 PtrToInt8Ty, llvm::PointerType::getUnqual(SymTabTy), NULL);
936 Elements.clear();
937 // Runtime version used for compatibility checking.
938 Elements.push_back(llvm::ConstantInt::get(LongTy, RuntimeVersion));
939 //FIXME: Should be sizeof(ModuleTy)
940 Elements.push_back(llvm::ConstantInt::get(LongTy, 16));
941 //FIXME: Should be the path to the file where this module was declared
942 Elements.push_back(NULLPtr);
943 Elements.push_back(SymTab);
944 llvm::Value *Module = MakeGlobal(ModuleTy, Elements);
945
946 // Create the load function calling the runtime entry point with the module
947 // structure
948 std::vector<const llvm::Type*> VoidArgs;
949 llvm::Function * LoadFunction = llvm::Function::Create(
950 llvm::FunctionType::get(llvm::Type::VoidTy, VoidArgs, false),
951 llvm::GlobalValue::InternalLinkage, ".objc_load_function",
952 &TheModule);
953 llvm::BasicBlock *EntryBB = llvm::BasicBlock::Create("entry", LoadFunction);
Daniel Dunbard916e6e2008-11-01 01:53:16 +0000954 CGBuilderTy Builder;
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000955 Builder.SetInsertPoint(EntryBB);
956 llvm::Value *Register = TheModule.getOrInsertFunction("__objc_exec_class",
957 llvm::Type::VoidTy, llvm::PointerType::getUnqual(ModuleTy), NULL);
958 Builder.CreateCall(Register, Module);
959 Builder.CreateRetVoid();
960 return LoadFunction;
961}
Daniel Dunbarac93e472008-08-15 22:20:32 +0000962
Fariborz Jahanian0adaa8a2009-01-10 21:06:09 +0000963llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
964 const ObjCContainerDecl *CD) {
Daniel Dunbarac93e472008-08-15 22:20:32 +0000965 const ObjCCategoryImplDecl *OCD =
Steve Naroff438be772009-01-08 19:41:02 +0000966 dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext());
Chris Lattner3a8f2942008-11-24 03:33:13 +0000967 std::string CategoryName = OCD ? OCD->getNameAsString() : "";
968 std::string ClassName = OMD->getClassInterface()->getNameAsString();
969 std::string MethodName = OMD->getSelector().getAsString();
Douglas Gregor5d764842009-01-09 17:18:27 +0000970 bool isClassMethod = !OMD->isInstanceMethod();
Daniel Dunbarac93e472008-08-15 22:20:32 +0000971
Daniel Dunbar3ad1f072008-09-10 04:01:49 +0000972 const llvm::FunctionType *MethodTy =
Daniel Dunbar9fc15a82009-02-02 21:43:58 +0000973 CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()),
974 OMD->isVariadic());
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000975 std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName,
976 MethodName, isClassMethod);
977
Gabor Greif815e2c12008-04-06 20:42:52 +0000978 llvm::Function *Method = llvm::Function::Create(MethodTy,
Chris Lattnerb326b172008-03-30 23:03:07 +0000979 llvm::GlobalValue::InternalLinkage,
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +0000980 FunctionName,
Chris Lattnerb326b172008-03-30 23:03:07 +0000981 &TheModule);
Chris Lattnerb326b172008-03-30 23:03:07 +0000982 return Method;
983}
984
Daniel Dunbarf7103722008-09-24 03:38:44 +0000985llvm::Function *CGObjCGNU::GetPropertyGetFunction() {
986 return 0;
987}
988
989llvm::Function *CGObjCGNU::GetPropertySetFunction() {
990 return 0;
991}
992
993llvm::Function *CGObjCGNU::EnumerationMutationFunction() {
Anders Carlsson58d16242008-08-31 04:05:03 +0000994 return 0;
995}
996
Fariborz Jahanianfbeda7b2008-11-21 00:49:24 +0000997void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
998 const Stmt &S) {
999 CGF.ErrorUnsupported(&S, "@try/@synchronized statement");
Anders Carlssonb01a2112008-09-09 10:04:29 +00001000}
1001
1002void CGObjCGNU::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
Daniel Dunbarf7103722008-09-24 03:38:44 +00001003 const ObjCAtThrowStmt &S) {
Anders Carlssonb01a2112008-09-09 10:04:29 +00001004 CGF.ErrorUnsupported(&S, "@throw statement");
1005}
1006
Fariborz Jahanian252d87f2008-11-18 22:37:34 +00001007llvm::Value * CGObjCGNU::EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
Fariborz Jahanian3305ad32008-11-18 21:45:40 +00001008 llvm::Value *AddrWeakObj)
1009{
1010 return 0;
1011}
1012
Fariborz Jahanian252d87f2008-11-18 22:37:34 +00001013void CGObjCGNU::EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
1014 llvm::Value *src, llvm::Value *dst)
1015{
1016 return;
1017}
1018
Fariborz Jahanian17958902008-11-19 00:59:10 +00001019void CGObjCGNU::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
1020 llvm::Value *src, llvm::Value *dst)
1021{
1022 return;
1023}
1024
Fariborz Jahanianf310b592008-11-20 19:23:36 +00001025void CGObjCGNU::EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
1026 llvm::Value *src, llvm::Value *dst)
1027{
1028 return;
1029}
1030
Fariborz Jahanian17958902008-11-19 00:59:10 +00001031void CGObjCGNU::EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
1032 llvm::Value *src, llvm::Value *dst)
1033{
1034 return;
1035}
1036
Fariborz Jahanian4337afe2009-02-02 20:02:29 +00001037llvm::Value *CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
1038 llvm::Value *BaseValue,
1039 const ObjCIvarDecl *Ivar,
1040 const FieldDecl *Field,
1041 unsigned CVRQualifiers) {
1042 // TODO: Add a special case for isa (index 0)
1043 unsigned Index = CGM.getTypes().getLLVMFieldNo(Field);
1044 llvm::Value *V = CGF.Builder.CreateStructGEP(BaseValue, Index, "tmp");
1045 return V;
1046}
1047
Daniel Dunbar8c85fac2008-08-11 02:45:11 +00001048CodeGen::CGObjCRuntime *CodeGen::CreateGNUObjCRuntime(CodeGen::CodeGenModule &CGM){
Chris Lattner547907c2008-06-26 04:19:03 +00001049 return new CGObjCGNU(CGM);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +00001050}