1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
//===------- CGObjCMac.cpp - Interface to Apple Objective-C Runtime -------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This provides Objective-C code generation targetting the Apple runtime.
//
//===----------------------------------------------------------------------===//
#include "CGObjCRuntime.h"
#include "CodeGenModule.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/LangOptions.h"
#include "llvm/Support/IRBuilder.h"
using namespace clang;
namespace {
class CGObjCMac : public CodeGen::CGObjCRuntime {
private:
CodeGen::CodeGenModule &CGM;
/// UsedGlobals - list of globals to pack into the llvm.used metadata
/// to prevent them from being clobbered.
std::vector<llvm::GlobalValue*> UsedGlobals;
/// EmitImageInfo - Emit the image info marker used to encode some module
/// level information.
void EmitImageInfo();
/// FinishModule - Write out global data structures at the end of
/// processing a translation unit.
void FinishModule();
public:
CGObjCMac(CodeGen::CodeGenModule &cgm);
virtual llvm::Constant *GenerateConstantString(const char *String,
const size_t length);
virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
llvm::Value *Sender,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC);
virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
llvm::Value *Sender,
const char *SuperClassName,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC);
virtual llvm::Value *LookupClass(llvm::IRBuilder<> &Builder,
llvm::Value *ClassName);
virtual llvm::Value *GetSelector(llvm::IRBuilder<> &Builder, Selector Sel);
virtual llvm::Function *MethodPreamble(const std::string &ClassName,
const std::string &CategoryName,
const std::string &MethodName,
const llvm::Type *ReturnTy,
const llvm::Type *SelfTy,
const llvm::Type **ArgTy,
unsigned ArgC,
bool isClassMethod,
bool isVarArg);
virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
const llvm::SmallVectorImpl<std::string> &Protocols);
virtual void GenerateClass(
const char *ClassName,
const char *SuperClassName,
const int instanceSize,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
const llvm::SmallVectorImpl<std::string> &Protocols);
virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<> &Builder,
const char *ProtocolName);
virtual void GenerateProtocol(const char *ProtocolName,
const llvm::SmallVectorImpl<std::string> &Protocols,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes);
virtual llvm::Function *ModuleInitFunction();
};
} // end anonymous namespace
CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGM(cgm) {
EmitImageInfo();
}
// This has to perform the lookup every time, since posing and related
// techniques can modify the name -> class mapping.
llvm::Value *CGObjCMac::LookupClass(llvm::IRBuilder<> &Builder,
llvm::Value *ClassName) {
assert(0 && "Cannot lookup classes on Mac runtime.");
return 0;
}
/// GetSelector - Return the pointer to the unique'd string for this selector.
llvm::Value *CGObjCMac::GetSelector(llvm::IRBuilder<> &Builder, Selector Sel) {
assert(0 && "Cannot get selector on Mac runtime.");
return 0;
}
/// Generate an NSConstantString object.
llvm::Constant *CGObjCMac::GenerateConstantString(const char *String,
const size_t length) {
assert(0 && "Cannot generate constant string for Mac runtime.");
return 0;
}
/// Generates a message send where the super is the receiver. This is
/// a message send to self with special delivery semantics indicating
/// which class's method should be called.
llvm::Value *CGObjCMac::GenerateMessageSendSuper(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
llvm::Value *Sender,
const char *SuperClassName,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC) {
assert(0 && "Cannot generate message send to super for Mac runtime.");
return 0;
}
/// Generate code for a message send expression.
llvm::Value *CGObjCMac::GenerateMessageSend(llvm::IRBuilder<> &Builder,
const llvm::Type *ReturnTy,
llvm::Value *Sender,
llvm::Value *Receiver,
Selector Sel,
llvm::Value** ArgV,
unsigned ArgC) {
assert(0 && "Cannot generate message send for Mac runtime.");
return 0;
}
llvm::Value *CGObjCMac::GenerateProtocolRef(llvm::IRBuilder<> &Builder,
const char *ProtocolName) {
assert(0 && "Cannot get protocol reference on Mac runtime.");
return 0;
}
void CGObjCMac::GenerateProtocol(const char *ProtocolName,
const llvm::SmallVectorImpl<std::string> &Protocols,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes) {
assert(0 && "Cannot generate protocol for Mac runtime.");
}
void CGObjCMac::GenerateCategory(
const char *ClassName,
const char *CategoryName,
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
const llvm::SmallVectorImpl<std::string> &Protocols) {
assert(0 && "Cannot generate category for Mac runtime.");
}
void CGObjCMac::GenerateClass(
const char *ClassName,
const char *SuperClassName,
const int instanceSize,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
const llvm::SmallVectorImpl<std::string> &Protocols) {
assert(0 && "Cannot generate class for Mac runtime.");
}
llvm::Function *CGObjCMac::ModuleInitFunction() {
// Abuse this interface function as a place to finalize.
FinishModule();
return NULL;
}
llvm::Function *CGObjCMac::MethodPreamble(
const std::string &ClassName,
const std::string &CategoryName,
const std::string &MethodName,
const llvm::Type *ReturnTy,
|