Change the PointerType api for creating pointer types. The old functionality of Point...
[oota-llvm.git] / lib / VMCore / Core.cpp
1 //===-- Core.cpp ----------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Gordon Henriksen and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the C bindings for libLLVMCore.a, which implements
11 // the LLVM intermediate representation.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm-c/Core.h"
16 #include "llvm/Bitcode/ReaderWriter.h"
17 #include "llvm/Constants.h"
18 #include "llvm/DerivedTypes.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/TypeSymbolTable.h"
21 #include "llvm/ModuleProvider.h"
22 #include <cassert>
23
24 using namespace llvm;
25
26
27 /*===-- Operations on modules ---------------------------------------------===*/
28
29 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
30   return wrap(new Module(ModuleID));
31 }
32
33 void LLVMDisposeModule(LLVMModuleRef M) {
34   delete unwrap(M);
35 }
36
37 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
38   return unwrap(M)->addTypeName(Name, unwrap(Ty));
39 }
40
41 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name) {
42   std::string N(Name);
43   
44   TypeSymbolTable &TST = unwrap(M)->getTypeSymbolTable();
45   for (TypeSymbolTable::iterator I = TST.begin(), E = TST.end(); I != E; ++I)
46     if (I->first == N)
47       TST.remove(I);
48 }
49
50
51 /*===-- Operations on types -----------------------------------------------===*/
52
53 /*--.. Operations on all types (mostly) ....................................--*/
54
55 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
56   return static_cast<LLVMTypeKind>(unwrap(Ty)->getTypeID());
57 }
58
59 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType){
60   DerivedType *Ty = unwrap<DerivedType>(AbstractType);
61   Ty->refineAbstractTypeTo(unwrap(ConcreteType));
62 }
63
64 /*--.. Operations on integer types .........................................--*/
65
66 LLVMTypeRef LLVMInt1Type()  { return (LLVMTypeRef) Type::Int1Ty;  }
67 LLVMTypeRef LLVMInt8Type()  { return (LLVMTypeRef) Type::Int8Ty;  }
68 LLVMTypeRef LLVMInt16Type() { return (LLVMTypeRef) Type::Int16Ty; }
69 LLVMTypeRef LLVMInt32Type() { return (LLVMTypeRef) Type::Int32Ty; }
70 LLVMTypeRef LLVMInt64Type() { return (LLVMTypeRef) Type::Int64Ty; }
71
72 LLVMTypeRef LLVMIntType(unsigned NumBits) {
73   return wrap(IntegerType::get(NumBits));
74 }
75
76 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
77   return unwrap<IntegerType>(IntegerTy)->getBitWidth();
78 }
79
80 /*--.. Operations on real types ............................................--*/
81
82 LLVMTypeRef LLVMFloatType()    { return (LLVMTypeRef) Type::FloatTy;     }
83 LLVMTypeRef LLVMDoubleType()   { return (LLVMTypeRef) Type::DoubleTy;    }
84 LLVMTypeRef LLVMX86FP80Type()  { return (LLVMTypeRef) Type::X86_FP80Ty;  }
85 LLVMTypeRef LLVMFP128Type()    { return (LLVMTypeRef) Type::FP128Ty;     }
86 LLVMTypeRef LLVMPPCFP128Type() { return (LLVMTypeRef) Type::PPC_FP128Ty; }
87
88 /*--.. Operations on function types ........................................--*/
89
90 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
91                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
92                              int IsVarArg) {
93   std::vector<const Type*> Tys;
94   for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
95     Tys.push_back(unwrap(*I));
96   
97   return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
98 }
99
100 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
101   return unwrap<FunctionType>(FunctionTy)->isVarArg();
102 }
103
104 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
105   return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
106 }
107
108 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
109   return unwrap<FunctionType>(FunctionTy)->getNumParams();
110 }
111
112 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
113   FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
114   for (FunctionType::param_iterator I = Ty->param_begin(),
115                                     E = Ty->param_end(); I != E; ++I)
116     *Dest++ = wrap(*I);
117 }
118
119 /*--.. Operations on struct types ..........................................--*/
120
121 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
122                            unsigned ElementCount, int Packed) {
123   std::vector<const Type*> Tys;
124   for (LLVMTypeRef *I = ElementTypes,
125                    *E = ElementTypes + ElementCount; I != E; ++I)
126     Tys.push_back(unwrap(*I));
127   
128   return wrap(StructType::get(Tys, Packed != 0));
129 }
130
131 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
132   return unwrap<StructType>(StructTy)->getNumElements();
133 }
134
135 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
136   StructType *Ty = unwrap<StructType>(StructTy);
137   for (FunctionType::param_iterator I = Ty->element_begin(),
138                                     E = Ty->element_end(); I != E; ++I)
139     *Dest++ = wrap(*I);
140 }
141
142 int LLVMIsPackedStruct(LLVMTypeRef StructTy) {
143   return unwrap<StructType>(StructTy)->isPacked();
144 }
145
146 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
147
148 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount){
149   return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
150 }
151
152 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType) {
153   // FIXME: Needst to handle address spaces
154   return wrap(PointerType::getUnqual(unwrap(ElementType)));
155 }
156
157 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType,unsigned ElementCount){
158   return wrap(VectorType::get(unwrap(ElementType), ElementCount));
159 }
160
161 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
162   return wrap(unwrap<SequentialType>(Ty)->getElementType());
163 }
164
165 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
166   return unwrap<ArrayType>(ArrayTy)->getNumElements();
167 }
168
169 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
170   return unwrap<VectorType>(VectorTy)->getNumElements();
171 }
172
173 /*--.. Operations on other types ...........................................--*/
174
175 LLVMTypeRef LLVMVoidType()  { return (LLVMTypeRef) Type::VoidTy;  }
176 LLVMTypeRef LLVMLabelType() { return (LLVMTypeRef) Type::LabelTy; }
177
178 LLVMTypeRef LLVMOpaqueType() {
179   return wrap(llvm::OpaqueType::get());
180 }
181
182 /* Operations on type handles */
183
184 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy) {
185   return wrap(new PATypeHolder(unwrap(PotentiallyAbstractTy)));
186 }
187
188 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle) {
189   delete unwrap(TypeHandle);
190 }
191
192 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle) {
193   return wrap(unwrap(TypeHandle)->get());
194 }
195
196 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy) {
197   unwrap<DerivedType>(AbstractTy)->refineAbstractTypeTo(unwrap(ConcreteTy));
198 }
199
200
201 /*===-- Operations on values ----------------------------------------------===*/
202
203 /*--.. Operations on all values ............................................--*/
204
205 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
206   return wrap(unwrap(Val)->getType());
207 }
208
209 const char *LLVMGetValueName(LLVMValueRef Val) {
210   return unwrap(Val)->getNameStart();
211 }
212
213 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
214   unwrap(Val)->setName(Name);
215 }
216
217 void LLVMDumpValue(LLVMValueRef Val) {
218   unwrap(Val)->dump();
219 }
220
221 /*--.. Operations on constants of any type .................................--*/
222
223 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
224   return wrap(Constant::getNullValue(unwrap(Ty)));
225 }
226
227 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
228   return wrap(Constant::getAllOnesValue(unwrap(Ty)));
229 }
230
231 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
232   return wrap(UndefValue::get(unwrap(Ty)));
233 }
234
235 int LLVMIsConstant(LLVMValueRef Ty) {
236   return isa<Constant>(unwrap(Ty));
237 }
238
239 int LLVMIsNull(LLVMValueRef Val) {
240   if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
241     return C->isNullValue();
242   return false;
243 }
244
245 int LLVMIsUndef(LLVMValueRef Val) {
246   return isa<UndefValue>(unwrap(Val));
247 }
248
249 /*--.. Operations on scalar constants ......................................--*/
250
251 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
252                           int SignExtend) {
253   return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
254 }
255
256 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
257   return wrap(ConstantFP::get(unwrap(RealTy), APFloat(N)));
258 }
259
260 /*--.. Operations on composite constants ...................................--*/
261
262 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
263                              int DontNullTerminate) {
264   /* Inverted the sense of AddNull because ', 0)' is a
265      better mnemonic for null termination than ', 1)'. */
266   return wrap(ConstantArray::get(std::string(Str, Length),
267                                  DontNullTerminate == 0));
268 }
269
270 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
271                             LLVMValueRef *ConstantVals, unsigned Length) {
272   return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length),
273                                  unwrap<Constant>(ConstantVals, Length),
274                                  Length));
275 }
276
277 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
278                              int Packed) {
279   return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
280                                   Count, Packed != 0));
281 }
282
283 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
284   return wrap(ConstantVector::get(unwrap<Constant>(ScalarConstantVals, Size),
285                                   Size));
286 }
287
288 /*--.. Constant expressions ................................................--*/
289
290 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
291   return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
292 }
293
294 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
295   return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
296 }
297
298 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
299   return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
300 }
301
302 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
303   return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
304                                    unwrap<Constant>(RHSConstant)));
305 }
306
307 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
308   return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
309                                    unwrap<Constant>(RHSConstant)));
310 }
311
312 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
313   return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
314                                    unwrap<Constant>(RHSConstant)));
315 }
316
317 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
318   return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
319                                     unwrap<Constant>(RHSConstant)));
320 }
321
322 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
323   return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
324                                     unwrap<Constant>(RHSConstant)));
325 }
326
327 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
328   return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
329                                     unwrap<Constant>(RHSConstant)));
330 }
331
332 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
333   return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
334                                     unwrap<Constant>(RHSConstant)));
335 }
336
337 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
338   return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
339                                     unwrap<Constant>(RHSConstant)));
340 }
341
342 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
343   return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
344                                     unwrap<Constant>(RHSConstant)));
345 }
346
347 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
348   return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
349                                    unwrap<Constant>(RHSConstant)));
350 }
351
352 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
353   return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
354                                   unwrap<Constant>(RHSConstant)));
355 }
356
357 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
358   return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
359                                    unwrap<Constant>(RHSConstant)));
360 }
361
362 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
363                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
364   return wrap(ConstantExpr::getICmp(Predicate,
365                                     unwrap<Constant>(LHSConstant),
366                                     unwrap<Constant>(RHSConstant)));
367 }
368
369 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
370                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
371   return wrap(ConstantExpr::getFCmp(Predicate,
372                                     unwrap<Constant>(LHSConstant),
373                                     unwrap<Constant>(RHSConstant)));
374 }
375
376 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
377   return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
378                                   unwrap<Constant>(RHSConstant)));
379 }
380
381 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
382   return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
383                                     unwrap<Constant>(RHSConstant)));
384 }
385
386 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
387   return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
388                                     unwrap<Constant>(RHSConstant)));
389 }
390
391 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
392                           LLVMValueRef *ConstantIndices, unsigned NumIndices) {
393   return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
394                                              unwrap<Constant>(ConstantIndices, 
395                                                               NumIndices),
396                                              NumIndices));
397 }
398
399 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
400   return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
401                                      unwrap(ToType)));
402 }
403
404 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
405   return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
406                                     unwrap(ToType)));
407 }
408
409 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
410   return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
411                                     unwrap(ToType)));
412 }
413
414 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
415   return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
416                                        unwrap(ToType)));
417 }
418
419 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
420   return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
421                                         unwrap(ToType)));
422 }
423
424 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
425   return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
426                                       unwrap(ToType)));
427 }
428
429 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
430   return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
431                                       unwrap(ToType)));
432 }
433
434 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
435   return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
436                                       unwrap(ToType)));
437 }
438
439 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
440   return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
441                                       unwrap(ToType)));
442 }
443
444 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
445   return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
446                                         unwrap(ToType)));
447 }
448
449 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
450   return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
451                                         unwrap(ToType)));
452 }
453
454 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
455   return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
456                                        unwrap(ToType)));
457 }
458
459 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
460                              LLVMValueRef ConstantIfTrue,
461                              LLVMValueRef ConstantIfFalse) {
462   return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
463                                       unwrap<Constant>(ConstantIfTrue),
464                                       unwrap<Constant>(ConstantIfFalse)));
465 }
466
467 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
468                                      LLVMValueRef IndexConstant) {
469   return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
470                                               unwrap<Constant>(IndexConstant)));
471 }
472
473 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
474                                     LLVMValueRef ElementValueConstant,
475                                     LLVMValueRef IndexConstant) {
476   return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
477                                          unwrap<Constant>(ElementValueConstant),
478                                              unwrap<Constant>(IndexConstant)));
479 }
480
481 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
482                                     LLVMValueRef VectorBConstant,
483                                     LLVMValueRef MaskConstant) {
484   return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
485                                              unwrap<Constant>(VectorBConstant),
486                                              unwrap<Constant>(MaskConstant)));
487 }
488
489 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
490
491 int LLVMIsDeclaration(LLVMValueRef Global) {
492   return unwrap<GlobalValue>(Global)->isDeclaration();
493 }
494
495 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
496   return static_cast<LLVMLinkage>(unwrap<GlobalValue>(Global)->getLinkage());
497 }
498
499 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
500   unwrap<GlobalValue>(Global)
501     ->setLinkage(static_cast<GlobalValue::LinkageTypes>(Linkage));
502 }
503
504 const char *LLVMGetSection(LLVMValueRef Global) {
505   return unwrap<GlobalValue>(Global)->getSection().c_str();
506 }
507
508 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
509   unwrap<GlobalValue>(Global)->setSection(Section);
510 }
511
512 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
513   return static_cast<LLVMVisibility>(
514     unwrap<GlobalValue>(Global)->getVisibility());
515 }
516
517 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
518   unwrap<GlobalValue>(Global)
519     ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
520 }
521
522 unsigned LLVMGetAlignment(LLVMValueRef Global) {
523   return unwrap<GlobalValue>(Global)->getAlignment();
524 }
525
526 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
527   unwrap<GlobalValue>(Global)->setAlignment(Bytes);
528 }
529
530 /*--.. Operations on global variables ......................................--*/
531
532 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
533   return wrap(new GlobalVariable(unwrap(Ty), false,
534               GlobalValue::ExternalLinkage, 0, Name, unwrap(M)));
535 }
536
537 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
538   return wrap(unwrap(M)->getNamedGlobal(Name));
539 }
540
541 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
542   unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
543 }
544
545 int LLVMHasInitializer(LLVMValueRef GlobalVar) {
546   return unwrap<GlobalVariable>(GlobalVar)->hasInitializer();
547 }
548
549 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
550   return wrap(unwrap<GlobalVariable>(GlobalVar)->getInitializer());
551 }
552
553 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
554   unwrap<GlobalVariable>(GlobalVar)
555     ->setInitializer(unwrap<Constant>(ConstantVal));
556 }
557
558 int LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
559   return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
560 }
561
562 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) {
563   unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
564 }
565
566 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
567   return unwrap<GlobalVariable>(GlobalVar)->isConstant();
568 }
569
570 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
571   unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
572 }
573
574 /*--.. Operations on functions .............................................--*/
575
576 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
577                              LLVMTypeRef FunctionTy) {
578   return wrap(new Function(unwrap<FunctionType>(FunctionTy),
579                            GlobalValue::ExternalLinkage, Name, unwrap(M)));
580 }
581
582 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
583   return wrap(unwrap(M)->getFunction(Name));
584 }
585
586 void LLVMDeleteFunction(LLVMValueRef Fn) {
587   unwrap<Function>(Fn)->eraseFromParent();
588 }
589
590 unsigned LLVMCountParams(LLVMValueRef FnRef) {
591   // This function is strictly redundant to
592   //   LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
593   return unwrap<Function>(FnRef)->getArgumentList().size();
594 }
595
596 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
597   Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
598   while (index --> 0)
599     AI++;
600   return wrap(AI);
601 }
602
603 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
604   Function *Fn = unwrap<Function>(FnRef);
605   for (Function::arg_iterator I = Fn->arg_begin(),
606                               E = Fn->arg_end(); I != E; I++)
607     *ParamRefs++ = wrap(I);
608 }
609
610 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
611   if (Function *F = dyn_cast<Function>(unwrap(Fn)))
612     return F->getIntrinsicID();
613   return 0;
614 }
615
616 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
617   return unwrap<Function>(Fn)->getCallingConv();
618 }
619
620 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
621   return unwrap<Function>(Fn)->setCallingConv(CC);
622 }
623
624 const char *LLVMGetCollector(LLVMValueRef Fn) {
625   Function *F = unwrap<Function>(Fn);
626   return F->hasCollector()? F->getCollector() : 0;
627 }
628
629 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll) {
630   Function *F = unwrap<Function>(Fn);
631   if (Coll)
632     F->setCollector(Coll);
633   else
634     F->clearCollector();
635 }
636
637 /*--.. Operations on basic blocks ..........................................--*/
638
639 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb) {
640   return wrap(static_cast<Value*>(unwrap(Bb)));
641 }
642
643 int LLVMValueIsBasicBlock(LLVMValueRef Val) {
644   return isa<BasicBlock>(unwrap(Val));
645 }
646
647 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
648   return wrap(unwrap<BasicBlock>(Val));
649 }
650
651 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
652   return unwrap<Function>(FnRef)->getBasicBlockList().size();
653 }
654
655 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
656   Function *Fn = unwrap<Function>(FnRef);
657   for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
658     *BasicBlocksRefs++ = wrap(I);
659 }
660
661 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
662   return wrap(&unwrap<Function>(Fn)->getEntryBlock());
663 }
664
665 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
666   return wrap(new BasicBlock(Name, unwrap<Function>(FnRef)));
667 }
668
669 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef,
670                                        const char *Name) {
671   BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef);
672   return wrap(new BasicBlock(Name, InsertBeforeBB->getParent(),
673                              InsertBeforeBB));
674 }
675
676 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
677   unwrap(BBRef)->eraseFromParent();
678 }
679
680 /*--.. Call and invoke instructions ........................................--*/
681
682 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
683   Value *V = unwrap(Instr);
684   if (CallInst *CI = dyn_cast<CallInst>(V))
685     return CI->getCallingConv();
686   else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
687     return II->getCallingConv();
688   assert(0 && "LLVMGetInstructionCallConv applies only to call and invoke!");
689   return 0;
690 }
691
692 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
693   Value *V = unwrap(Instr);
694   if (CallInst *CI = dyn_cast<CallInst>(V))
695     return CI->setCallingConv(CC);
696   else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
697     return II->setCallingConv(CC);
698   assert(0 && "LLVMSetInstructionCallConv applies only to call and invoke!");
699 }
700
701 /*--.. Operations on phi nodes .............................................--*/
702
703 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
704                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
705   PHINode *PhiVal = unwrap<PHINode>(PhiNode);
706   for (unsigned I = 0; I != Count; ++I)
707     PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
708 }
709
710 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
711   return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
712 }
713
714 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
715   return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
716 }
717
718 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
719   return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
720 }
721
722
723 /*===-- Instruction builders ----------------------------------------------===*/
724
725 LLVMBuilderRef LLVMCreateBuilder() {
726   return wrap(new LLVMBuilder());
727 }
728
729 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
730   Instruction *I = unwrap<Instruction>(Instr);
731   unwrap(Builder)->SetInsertPoint(I->getParent(), I);
732 }
733
734 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
735   BasicBlock *BB = unwrap(Block);
736   unwrap(Builder)->SetInsertPoint(BB);
737 }
738
739 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
740   delete unwrap(Builder);
741 }
742
743 /*--.. Instruction builders ................................................--*/
744
745 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
746   return wrap(unwrap(B)->CreateRetVoid());
747 }
748
749 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
750   return wrap(unwrap(B)->CreateRet(unwrap(V)));
751 }
752
753 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
754   return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
755 }
756
757 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
758                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
759   return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
760 }
761
762 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
763                              LLVMBasicBlockRef Else, unsigned NumCases) {
764   return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
765 }
766
767 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
768                              LLVMValueRef *Args, unsigned NumArgs,
769                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
770                              const char *Name) {
771   return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
772                                       unwrap(Args), unwrap(Args) + NumArgs,
773                                       Name));
774 }
775
776 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) {
777   return wrap(unwrap(B)->CreateUnwind());
778 }
779
780 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
781   return wrap(unwrap(B)->CreateUnreachable());
782 }
783
784 /*--.. Arithmetic ..........................................................--*/
785
786 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
787                           const char *Name) {
788   return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
789 }
790
791 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
792                           const char *Name) {
793   return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
794 }
795
796 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
797                           const char *Name) {
798   return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
799 }
800
801 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
802                            const char *Name) {
803   return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
804 }
805
806 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
807                            const char *Name) {
808   return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
809 }
810
811 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
812                            const char *Name) {
813   return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
814 }
815
816 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
817                            const char *Name) {
818   return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
819 }
820
821 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
822                            const char *Name) {
823   return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
824 }
825
826 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
827                            const char *Name) {
828   return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
829 }
830
831 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
832                           const char *Name) {
833   return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
834 }
835
836 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
837                            const char *Name) {
838   return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
839 }
840
841 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
842                            const char *Name) {
843   return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
844 }
845
846 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
847                           const char *Name) {
848   return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
849 }
850
851 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
852                          const char *Name) {
853   return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
854 }
855
856 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
857                           const char *Name) {
858   return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
859 }
860
861 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
862   return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
863 }
864
865 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
866   return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
867 }
868
869 /*--.. Memory ..............................................................--*/
870
871 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
872                              const char *Name) {
873   return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name));
874 }
875
876 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
877                                   LLVMValueRef Val, const char *Name) {
878   return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name));
879 }
880
881 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
882                              const char *Name) {
883   return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
884 }
885
886 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
887                                   LLVMValueRef Val, const char *Name) {
888   return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
889 }
890
891 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
892   return wrap(unwrap(B)->CreateFree(unwrap(PointerVal)));
893 }
894
895
896 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
897                            const char *Name) {
898   return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
899 }
900
901 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, 
902                             LLVMValueRef PointerVal) {
903   return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
904 }
905
906 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
907                           LLVMValueRef *Indices, unsigned NumIndices,
908                           const char *Name) {
909   return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), unwrap(Indices),
910                                    unwrap(Indices) + NumIndices, Name));
911 }
912
913 /*--.. Casts ...............................................................--*/
914
915 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
916                             LLVMTypeRef DestTy, const char *Name) {
917   return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
918 }
919
920 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
921                            LLVMTypeRef DestTy, const char *Name) {
922   return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
923 }
924
925 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
926                            LLVMTypeRef DestTy, const char *Name) {
927   return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
928 }
929
930 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
931                              LLVMTypeRef DestTy, const char *Name) {
932   return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
933 }
934
935 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
936                              LLVMTypeRef DestTy, const char *Name) {
937   return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
938 }
939
940 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
941                              LLVMTypeRef DestTy, const char *Name) {
942   return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
943 }
944
945 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
946                              LLVMTypeRef DestTy, const char *Name) {
947   return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
948 }
949
950 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
951                               LLVMTypeRef DestTy, const char *Name) {
952   return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
953 }
954
955 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
956                             LLVMTypeRef DestTy, const char *Name) {
957   return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
958 }
959
960 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
961                                LLVMTypeRef DestTy, const char *Name) {
962   return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
963 }
964
965 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
966                                LLVMTypeRef DestTy, const char *Name) {
967   return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
968 }
969
970 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
971                               LLVMTypeRef DestTy, const char *Name) {
972   return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
973 }
974
975 /*--.. Comparisons .........................................................--*/
976
977 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
978                            LLVMValueRef LHS, LLVMValueRef RHS,
979                            const char *Name) {
980   return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
981                                     unwrap(LHS), unwrap(RHS), Name));
982 }
983
984 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
985                            LLVMValueRef LHS, LLVMValueRef RHS,
986                            const char *Name) {
987   return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
988                                     unwrap(LHS), unwrap(RHS), Name));
989 }
990
991 /*--.. Miscellaneous instructions ..........................................--*/
992
993 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
994   return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name));
995 }
996
997 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
998                            LLVMValueRef *Args, unsigned NumArgs,
999                            const char *Name) {
1000   return wrap(unwrap(B)->CreateCall(unwrap(Fn), unwrap(Args),
1001                                     unwrap(Args) + NumArgs, Name));
1002 }
1003
1004 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
1005                              LLVMValueRef Then, LLVMValueRef Else,
1006                              const char *Name) {
1007   return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
1008                                       Name));
1009 }
1010
1011 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
1012                             LLVMTypeRef Ty, const char *Name) {
1013   return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
1014 }
1015
1016 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
1017                                       LLVMValueRef Index, const char *Name) {
1018   return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
1019                                               Name));
1020 }
1021
1022 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
1023                                     LLVMValueRef EltVal, LLVMValueRef Index,
1024                                     const char *Name) {
1025   return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
1026                                              unwrap(Index), Name));
1027 }
1028
1029 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
1030                                     LLVMValueRef V2, LLVMValueRef Mask,
1031                                     const char *Name) {
1032   return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
1033                                              unwrap(Mask), Name));
1034 }
1035
1036
1037 /*===-- Module providers --------------------------------------------------===*/
1038
1039 LLVMModuleProviderRef
1040 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
1041   return wrap(new ExistingModuleProvider(unwrap(M)));
1042 }
1043
1044 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
1045   delete unwrap(MP);
1046 }
1047