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