Fill in a few more missing accessors.
[oota-llvm.git] / lib / VMCore / LLVMContext.cpp
1 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
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 file implements LLVMContext, as a wrapper around the opaque
11 // class LLVMContextImpl.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/LLVMContext.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/MDNode.h"
19 #include "llvm/Support/ManagedStatic.h"
20 #include "LLVMContextImpl.h"
21
22 using namespace llvm;
23
24 static ManagedStatic<LLVMContext> GlobalContext;
25
26 LLVMContext& llvm::getGlobalContext() {
27   return *GlobalContext;
28 }
29
30 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
31 LLVMContext::~LLVMContext() { delete pImpl; }
32
33 // Constant accessors
34 Constant* LLVMContext::getNullValue(const Type* Ty) {
35   return Constant::getNullValue(Ty);
36 }
37
38 Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
39   return Constant::getAllOnesValue(Ty);
40 }
41
42 // UndefValue accessors.
43 UndefValue* LLVMContext::getUndef(const Type* Ty) {
44   return UndefValue::get(Ty);
45 }
46
47 // ConstantInt accessors.
48 ConstantInt* LLVMContext::getConstantIntTrue() {
49   return ConstantInt::getTrue();
50 }
51
52 ConstantInt* LLVMContext::getConstantIntFalse() {
53   return ConstantInt::getFalse();
54 }
55
56 Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
57                                          bool isSigned) {
58   return ConstantInt::get(Ty, V, isSigned);
59 }
60
61
62 ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
63                                          bool isSigned) {
64   return ConstantInt::get(Ty, V, isSigned);
65 }
66
67 ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
68                                                int64_t V) {
69   return ConstantInt::getSigned(Ty, V);
70 }
71
72 ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
73   return ConstantInt::get(V);
74 }
75
76 Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
77   return ConstantInt::get(Ty, V);
78 }
79
80 ConstantInt* LLVMContext::getConstantIntAllOnesValue(const Type* Ty) {
81   return ConstantInt::getAllOnesValue(Ty);
82 }
83
84
85 // ConstantPointerNull accessors.
86 ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
87   return ConstantPointerNull::get(T);
88 }
89
90
91 // ConstantStruct accessors.
92 Constant* LLVMContext::getConstantStruct(const StructType* T,
93                                          const std::vector<Constant*>& V) {
94   return ConstantStruct::get(T, V);
95 }
96
97 Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
98                                          bool Packed) {
99   return ConstantStruct::get(V, Packed);
100 }
101
102 Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
103                                          unsigned NumVals, bool Packed) {
104   return ConstantStruct::get(Vals, NumVals, Packed);
105 }
106
107
108 // ConstantAggregateZero accessors.
109 ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
110   return ConstantAggregateZero::get(Ty);
111 }
112
113
114 // ConstantArray accessors.
115 Constant* LLVMContext::getConstantArray(const ArrayType* T,
116                                         const std::vector<Constant*>& V) {
117   return ConstantArray::get(T, V);
118 }
119
120 Constant* LLVMContext::getConstantArray(const ArrayType* T,
121                                         Constant* const* Vals,
122                                         unsigned NumVals) {
123   return ConstantArray::get(T, Vals, NumVals);
124 }
125
126 Constant* LLVMContext::getConstantArray(const std::string& Initializer,
127                                         bool AddNull) {
128   return ConstantArray::get(Initializer, AddNull);
129 }
130
131
132 // ConstantExpr accessors.
133 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
134                                        Constant* C2) {
135   return ConstantExpr::get(Opcode, C1, C2);
136 }
137
138 Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
139   return ConstantExpr::getTrunc(C, Ty);
140 }
141
142 Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
143   return ConstantExpr::getSExt(C, Ty);
144 }
145
146 Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
147   return ConstantExpr::getZExt(C, Ty);  
148 }
149
150 Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
151   return ConstantExpr::getFPTrunc(C, Ty);
152 }
153
154 Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
155   return ConstantExpr::getFPExtend(C, Ty);
156 }
157
158 Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
159   return ConstantExpr::getUIToFP(C, Ty);
160 }
161
162 Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
163   return ConstantExpr::getSIToFP(C, Ty);
164 }
165
166 Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
167   return ConstantExpr::getFPToUI(C, Ty);
168 }
169
170 Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
171   return ConstantExpr::getFPToSI(C, Ty);
172 }
173
174 Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
175   return ConstantExpr::getPtrToInt(C, Ty);
176 }
177
178 Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
179   return ConstantExpr::getIntToPtr(C, Ty);
180 }
181
182 Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
183   return ConstantExpr::getBitCast(C, Ty);
184 }
185
186 Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
187                                            const Type* Ty) {
188   return ConstantExpr::getCast(ops, C, Ty);
189 }
190
191 Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
192                                                     const Type* Ty) {
193   return ConstantExpr::getZExtOrBitCast(C, Ty);
194 }
195
196 Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
197                                                     const Type* Ty) {
198   return ConstantExpr::getSExtOrBitCast(C, Ty);
199 }
200
201 Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
202                                                      const Type* Ty) {
203   return ConstantExpr::getTruncOrBitCast(C, Ty);  
204 }
205
206 Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
207   return ConstantExpr::getPointerCast(C, Ty);
208 }
209
210 Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
211                                                   bool isSigned) {
212   return ConstantExpr::getIntegerCast(C, Ty, isSigned);
213 }
214
215 Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
216   return ConstantExpr::getFPCast(C, Ty);
217 }
218
219 Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
220                                              Constant* V2) {
221   return ConstantExpr::getSelect(C, V1, V2);
222 }
223
224 Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
225   return ConstantExpr::getAlignOf(Ty);
226 }
227
228 Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
229                                  Constant* C1, Constant* C2) {
230   return ConstantExpr::getCompare(pred, C1, C2);
231 }
232
233 Constant* LLVMContext::getConstantExprNeg(Constant* C) {
234   return ConstantExpr::getNeg(C);
235 }
236
237 Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
238   return ConstantExpr::getFNeg(C);
239 }
240
241 Constant* LLVMContext::getConstantExprNot(Constant* C) {
242   return ConstantExpr::getNot(C);
243 }
244
245 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
246   return ConstantExpr::getAdd(C1, C2);
247 }
248
249 Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
250   return ConstantExpr::getFAdd(C1, C2);
251 }
252
253 Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
254   return ConstantExpr::getSub(C1, C2);
255 }
256
257 Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
258   return ConstantExpr::getFSub(C1, C2);
259 }
260
261 Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
262   return ConstantExpr::getMul(C1, C2);
263 }
264
265 Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
266   return ConstantExpr::getFMul(C1, C2);
267 }
268
269 Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
270   return ConstantExpr::getUDiv(C1, C2);
271 }
272
273 Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
274   return ConstantExpr::getSDiv(C1, C2);
275 }
276
277 Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
278   return ConstantExpr::getFDiv(C1, C2);
279 }
280
281 Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
282   return ConstantExpr::getURem(C1, C2);
283 }
284
285 Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
286   return ConstantExpr::getSRem(C1, C2);
287 }
288
289 Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
290   return ConstantExpr::getFRem(C1, C2);
291 }
292
293 Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
294   return ConstantExpr::getAnd(C1, C2);
295 }
296
297 Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
298   return ConstantExpr::getOr(C1, C2);
299 }
300
301 Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
302   return ConstantExpr::getXor(C1, C2);
303 }
304
305 Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
306                               Constant* RHS) {
307   return ConstantExpr::getICmp(pred, LHS, RHS);
308 }
309
310 Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
311                               Constant* RHS) {
312   return ConstantExpr::getFCmp(pred, LHS, RHS);
313 }
314
315 Constant* LLVMContext::getConstantExprVICmp(unsigned short pred, Constant* LHS,
316                                Constant* RHS) {
317   return ConstantExpr::getVICmp(pred, LHS, RHS);
318 }
319
320 Constant* LLVMContext::getConstantExprVFCmp(unsigned short pred, Constant* LHS,
321                                Constant* RHS) {
322   return ConstantExpr::getVFCmp(pred, LHS, RHS);
323 }
324
325 Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
326   return ConstantExpr::getShl(C1, C2);
327 }
328
329 Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
330   return ConstantExpr::getLShr(C1, C2);
331 }
332
333 Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
334   return ConstantExpr::getAShr(C1, C2);
335 }
336
337 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
338                                                     Constant* const* IdxList, 
339                                                     unsigned NumIdx) {
340   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
341 }
342
343 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
344                                                     Value* const* IdxList, 
345                                                     unsigned NumIdx) {
346   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
347 }
348
349 Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
350                                                      Constant* Idx) {
351   return ConstantExpr::getExtractElement(Vec, Idx);
352 }
353
354 Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
355                                                     Constant* Elt,
356                                                     Constant* Idx) {
357   return ConstantExpr::getInsertElement(Vec, Elt, Idx);
358 }
359
360 Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
361                                                     Constant* Mask) {
362   return ConstantExpr::getShuffleVector(V1, V2, Mask);
363 }
364
365 Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
366                                                    const unsigned* IdxList, 
367                                                    unsigned NumIdx) {
368   return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
369 }
370
371 Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
372                                                   const unsigned* IdxList,
373                                                   unsigned NumIdx) {
374   return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
375 }
376
377 Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
378   return ConstantExpr::getZeroValueForNegationExpr(Ty);
379 }
380
381
382 // ConstantFP accessors.
383 ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
384   return ConstantFP::get(V);
385 }
386
387 Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
388   return ConstantFP::get(Ty, V);
389 }
390
391 ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
392   return ConstantFP::getNegativeZero(Ty);
393 }
394
395
396 // ConstantVector accessors.
397 Constant* LLVMContext::getConstantVector(const VectorType* T,
398                             const std::vector<Constant*>& V) {
399   return ConstantVector::get(T, V);
400 }
401
402 Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
403   return ConstantVector::get(V);
404 }
405
406 Constant* LLVMContext::getConstantVector(Constant* const* Vals,
407                                          unsigned NumVals) {
408   return ConstantVector::get(Vals, NumVals);
409 }
410
411 ConstantVector* LLVMContext::getConstantVectorAllOnes(const VectorType* Ty) {
412   return ConstantVector::getAllOnesValue(Ty);
413 }
414
415 // MDNode accessors
416 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
417   return MDNode::get(Vals, NumVals);
418 }
419
420 // MDString accessors
421 MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
422   return MDString::get(StrBegin, StrEnd);
423 }
424
425 MDString* LLVMContext::getMDString(const std::string &Str) {
426   return MDString::get(Str);
427 }
428
429 // FunctionType accessors
430 FunctionType* LLVMContext::getFunctionType(const Type* Result,
431                                          const std::vector<const Type*>& Params,
432                                          bool isVarArg) {
433   return FunctionType::get(Result, Params, isVarArg);
434 }
435                                 
436 // IntegerType accessors
437 const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
438   return IntegerType::get(NumBits);
439 }
440   
441 // OpaqueType accessors
442 OpaqueType* LLVMContext::getOpaqueType() {
443   return OpaqueType::get();
444 }
445
446 // StructType accessors
447 StructType* LLVMContext::getStructType(bool isPacked) {
448   return StructType::get(isPacked);
449 }
450
451 StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
452                                        bool isPacked) {
453   return StructType::get(Params, isPacked);
454 }
455
456 // ArrayType accessors
457 ArrayType* LLVMContext::getArrayType(const Type* ElementType,
458                                      uint64_t NumElements) {
459   return ArrayType::get(ElementType, NumElements);
460 }
461   
462 // PointerType accessors
463 PointerType* LLVMContext::getPointerType(const Type* ElementType,
464                                          unsigned AddressSpace) {
465   return PointerType::get(ElementType, AddressSpace);
466 }
467
468 PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
469   return PointerType::getUnqual(ElementType);
470 }
471   
472 // VectorType accessors
473 VectorType* LLVMContext::getVectorType(const Type* ElementType,
474                                        unsigned NumElements) {
475   return VectorType::get(ElementType, NumElements);
476 }
477
478 VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
479   return VectorType::getInteger(VTy);  
480 }
481
482 VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
483   return VectorType::getExtendedElementVectorType(VTy);
484 }
485
486 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
487   return VectorType::getTruncatedElementVectorType(VTy);
488 }