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