blob: faf6fa94fcf72beb3ab7b04aa9a36c554ff2aad4 [file] [log] [blame]
Daniel Dunbar8c85fac2008-08-11 02:45:11 +00001//===------- CGObjCMac.cpp - Interface to Apple Objective-C Runtime -------===//
2//
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//
10// This provides Objective-C code generation targetting the Apple runtime.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CGObjCRuntime.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000015#include "clang/AST/Decl.h"
Daniel Dunbar8c85fac2008-08-11 02:45:11 +000016#include "llvm/Support/IRBuilder.h"
Daniel Dunbar8c85fac2008-08-11 02:45:11 +000017
18using namespace clang;
19
20namespace {
21class CGObjCMac : public CodeGen::CGObjCRuntime {
22private:
23 CodeGen::CodeGenModule &CGM;
24
25public:
26 CGObjCMac(CodeGen::CodeGenModule &cgm);
27 virtual llvm::Constant *GenerateConstantString(const char *String,
28 const size_t length);
29
30 virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder<> &Builder,
31 const llvm::Type *ReturnTy,
32 llvm::Value *Sender,
33 llvm::Value *Receiver,
34 Selector Sel,
35 llvm::Value** ArgV,
36 unsigned ArgC);
37
38 virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
39 const llvm::Type *ReturnTy,
40 llvm::Value *Sender,
41 const char *SuperClassName,
42 llvm::Value *Receiver,
43 Selector Sel,
44 llvm::Value** ArgV,
45 unsigned ArgC);
46
47 virtual llvm::Value *LookupClass(llvm::IRBuilder<> &Builder,
48 llvm::Value *ClassName);
49
50 virtual llvm::Value *GetSelector(llvm::IRBuilder<> &Builder, Selector Sel);
51
52 virtual llvm::Function *MethodPreamble(const std::string &ClassName,
53 const std::string &CategoryName,
54 const std::string &MethodName,
55 const llvm::Type *ReturnTy,
56 const llvm::Type *SelfTy,
57 const llvm::Type **ArgTy,
58 unsigned ArgC,
59 bool isClassMethod,
60 bool isVarArg);
61
62 virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
63 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
64 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
65 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
66 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
67 const llvm::SmallVectorImpl<std::string> &Protocols);
68
69 virtual void GenerateClass(
70 const char *ClassName,
71 const char *SuperClassName,
72 const int instanceSize,
73 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
74 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
75 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
76 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
77 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
78 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
79 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
80 const llvm::SmallVectorImpl<std::string> &Protocols);
81
82 virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<> &Builder,
83 const char *ProtocolName);
84
85 virtual void GenerateProtocol(const char *ProtocolName,
86 const llvm::SmallVectorImpl<std::string> &Protocols,
87 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
88 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
89 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
90 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes);
91
92 virtual llvm::Function *ModuleInitFunction();
93};
94} // end anonymous namespace
95
96CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) {
97}
98
99// This has to perform the lookup every time, since posing and related
100// techniques can modify the name -> class mapping.
101llvm::Value *CGObjCMac::LookupClass(llvm::IRBuilder<> &Builder,
102 llvm::Value *ClassName) {
103 assert(0 && "Cannot lookup classes on Mac runtime.");
104 return 0;
105}
106
107/// GetSelector - Return the pointer to the unique'd string for this selector.
108llvm::Value *CGObjCMac::GetSelector(llvm::IRBuilder<> &Builder, Selector Sel) {
109 assert(0 && "Cannot get selector on Mac runtime.");
110 return 0;
111}
112
113/// Generate an NSConstantString object.
114llvm::Constant *CGObjCMac::GenerateConstantString(const char *String,
115 const size_t length) {
116 assert(0 && "Cannot generate constant string for Mac runtime.");
117 return 0;
118}
119
120/// Generates a message send where the super is the receiver. This is
121/// a message send to self with special delivery semantics indicating
122/// which class's method should be called.
123llvm::Value *CGObjCMac::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
124 const llvm::Type *ReturnTy,
125 llvm::Value *Sender,
126 const char *SuperClassName,
127 llvm::Value *Receiver,
128 Selector Sel,
129 llvm::Value** ArgV,
130 unsigned ArgC) {
131 assert(0 && "Cannot generate message send to super for Mac runtime.");
132 return 0;
133}
134
135/// Generate code for a message send expression.
136llvm::Value *CGObjCMac::GenerateMessageSend(llvm::IRBuilder<> &Builder,
137 const llvm::Type *ReturnTy,
138 llvm::Value *Sender,
139 llvm::Value *Receiver,
140 Selector Sel,
141 llvm::Value** ArgV,
142 unsigned ArgC) {
143 assert(0 && "Cannot generate message send for Mac runtime.");
144 return 0;
145}
146
147llvm::Value *CGObjCMac::GenerateProtocolRef(llvm::IRBuilder<> &Builder,
148 const char *ProtocolName) {
149 assert(0 && "Cannot get protocol reference on Mac runtime.");
150 return 0;
151}
152
153void CGObjCMac::GenerateProtocol(const char *ProtocolName,
154 const llvm::SmallVectorImpl<std::string> &Protocols,
155 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
156 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
157 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
158 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes) {
159 assert(0 && "Cannot generate protocol for Mac runtime.");
160}
161
162void CGObjCMac::GenerateCategory(
163 const char *ClassName,
164 const char *CategoryName,
165 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
166 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
167 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
168 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
169 const llvm::SmallVectorImpl<std::string> &Protocols) {
170 assert(0 && "Cannot generate category for Mac runtime.");
171}
172
173void CGObjCMac::GenerateClass(
174 const char *ClassName,
175 const char *SuperClassName,
176 const int instanceSize,
177 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
178 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
179 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
180 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
181 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
182 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
183 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
184 const llvm::SmallVectorImpl<std::string> &Protocols) {
185 assert(0 && "Cannot generate class for Mac runtime.");
186}
187
188llvm::Function *CGObjCMac::ModuleInitFunction() {
189 return NULL;
190}
191
192llvm::Function *CGObjCMac::MethodPreamble(
193 const std::string &ClassName,
194 const std::string &CategoryName,
195 const std::string &MethodName,
196 const llvm::Type *ReturnTy,
197 const llvm::Type *SelfTy,
198 const llvm::Type **ArgTy,
199 unsigned ArgC,
200 bool isClassMethod,
201 bool isVarArg) {
202 assert(0 && "Cannot generate method preamble for Mac runtime.");
203 return 0;
204}
205
206CodeGen::CGObjCRuntime *CodeGen::CreateMacObjCRuntime(CodeGen::CodeGenModule &CGM){
207 return new CGObjCMac(CGM);
208}