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