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