Wrapping Value::dump.
[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 LLVMCreateIntType(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 LLVMCreateFunctionType(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 LLVMCreateStructType(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 LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount){
148   return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
149 }
150
151 LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType) {
152   return wrap(PointerType::get(unwrap(ElementType)));
153 }
154
155 LLVMTypeRef LLVMCreateVectorType(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 LLVMCreateOpaqueType() {
177   return wrap(llvm::OpaqueType::get());
178 }
179
180
181 /*===-- Operations on values ----------------------------------------------===*/
182
183 /*--.. Operations on all values ............................................--*/
184
185 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
186   return wrap(unwrap(Val)->getType());
187 }
188
189 const char *LLVMGetValueName(LLVMValueRef Val) {
190   return unwrap(Val)->getNameStart();
191 }
192
193 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
194   unwrap(Val)->setName(Name);
195 }
196
197 void LLVMDumpValue(LLVMValueRef Val) {
198   unwrap(Val)->dump();
199 }
200
201 /*--.. Operations on constants of any type .................................--*/
202
203 LLVMValueRef LLVMGetNull(LLVMTypeRef Ty) {
204   return wrap(Constant::getNullValue(unwrap(Ty)));
205 }
206
207 LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty) {
208   return wrap(Constant::getAllOnesValue(unwrap(Ty)));
209 }
210
211 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
212   return wrap(UndefValue::get(unwrap(Ty)));
213 }
214
215 int LLVMIsConstant(LLVMValueRef Ty) {
216   return isa<Constant>(unwrap(Ty));
217 }
218
219 int LLVMIsNull(LLVMValueRef Val) {
220   if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
221     return C->isNullValue();
222   return false;
223 }
224
225 int LLVMIsUndef(LLVMValueRef Val) {
226   return isa<UndefValue>(unwrap(Val));
227 }
228
229 /*--.. Operations on scalar constants ......................................--*/
230
231 LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
232                                 int SignExtend) {
233   return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
234 }
235
236 LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N) {
237   return wrap(ConstantFP::get(unwrap(RealTy), APFloat(N)));
238 }
239
240 /*--.. Operations on composite constants ...................................--*/
241
242 LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
243                                    int DontNullTerminate) {
244   /* Inverted the sense of AddNull because ', 0)' is a
245      better mnemonic for null termination than ', 1)'. */
246   return wrap(ConstantArray::get(std::string(Str, Length),
247                                  DontNullTerminate == 0));
248 }
249
250 LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ElementTy,
251                                   LLVMValueRef *ConstantVals, unsigned Length) {
252   return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length),
253                                  unwrap<Constant>(ConstantVals, Length),
254                                  Length));
255 }
256
257 LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
258                                    int Packed) {
259   return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
260                                   Count, Packed != 0));
261 }
262
263 LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
264                                    unsigned Size) {
265   return wrap(ConstantVector::get(unwrap<Constant>(ScalarConstantVals, Size),
266                                   Size));
267 }
268
269 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
270
271 int LLVMIsDeclaration(LLVMValueRef Global) {
272   return unwrap<GlobalValue>(Global)->isDeclaration();
273 }
274
275 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
276   return static_cast<LLVMLinkage>(unwrap<GlobalValue>(Global)->getLinkage());
277 }
278
279 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
280   unwrap<GlobalValue>(Global)
281     ->setLinkage(static_cast<GlobalValue::LinkageTypes>(Linkage));
282 }
283
284 const char *LLVMGetSection(LLVMValueRef Global) {
285   return unwrap<GlobalValue>(Global)->getSection().c_str();
286 }
287
288 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
289   unwrap<GlobalValue>(Global)->setSection(Section);
290 }
291
292 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
293   return static_cast<LLVMVisibility>(
294     unwrap<GlobalValue>(Global)->getVisibility());
295 }
296
297 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
298   unwrap<GlobalValue>(Global)
299     ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
300 }
301
302 unsigned LLVMGetAlignment(LLVMValueRef Global) {
303   return unwrap<GlobalValue>(Global)->getAlignment();
304 }
305
306 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
307   unwrap<GlobalValue>(Global)->setAlignment(Bytes);
308 }
309
310 /*--.. Operations on global variables ......................................--*/
311
312 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
313   return wrap(new GlobalVariable(unwrap(Ty), false,
314               GlobalValue::ExternalLinkage, 0, Name, unwrap(M)));
315 }
316
317 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
318   unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
319 }
320
321 int LLVMHasInitializer(LLVMValueRef GlobalVar) {
322   return unwrap<GlobalVariable>(GlobalVar)->hasInitializer();
323 }
324
325 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
326   return wrap(unwrap<GlobalVariable>(GlobalVar)->getInitializer());
327 }
328
329 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
330   unwrap<GlobalVariable>(GlobalVar)
331     ->setInitializer(unwrap<Constant>(ConstantVal));
332 }
333
334 int LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
335   return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
336 }
337
338 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) {
339   unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
340 }
341
342 /*--.. Operations on functions .............................................--*/
343
344 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
345                              LLVMTypeRef FunctionTy) {
346   return wrap(new Function(unwrap<FunctionType>(FunctionTy),
347                            GlobalValue::ExternalLinkage, Name, unwrap(M)));
348 }
349
350 void LLVMDeleteFunction(LLVMValueRef Fn) {
351   unwrap<Function>(Fn)->eraseFromParent();
352 }
353
354 unsigned LLVMCountParams(LLVMValueRef FnRef) {
355   // This function is strictly redundant to
356   //   LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
357   return unwrap<Function>(FnRef)->getArgumentList().size();
358 }
359
360 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
361   Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
362   while (index --> 0)
363     AI++;
364   return wrap(AI);
365 }
366
367 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
368   Function *Fn = unwrap<Function>(FnRef);
369   for (Function::arg_iterator I = Fn->arg_begin(),
370                               E = Fn->arg_end(); I != E; I++)
371     *ParamRefs++ = wrap(I);
372 }
373
374 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
375   if (Function *F = dyn_cast<Function>(unwrap(Fn)))
376     return F->getIntrinsicID();
377   return 0;
378 }
379
380 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
381   return unwrap<Function>(Fn)->getCallingConv();
382 }
383
384 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
385   return unwrap<Function>(Fn)->setCallingConv(CC);
386 }
387
388 /*--.. Operations on basic blocks ..........................................--*/
389
390 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb) {
391   return wrap(static_cast<Value*>(unwrap(Bb)));
392 }
393
394 int LLVMValueIsBasicBlock(LLVMValueRef Val) {
395   return isa<BasicBlock>(unwrap(Val));
396 }
397
398 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
399   return wrap(unwrap<BasicBlock>(Val));
400 }
401
402 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
403   return unwrap<Function>(FnRef)->getBasicBlockList().size();
404 }
405
406 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
407   Function *Fn = unwrap<Function>(FnRef);
408   for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
409     *BasicBlocksRefs++ = wrap(I);
410 }
411
412 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
413   return wrap(&unwrap<Function>(Fn)->getEntryBlock());
414 }
415
416 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
417   return wrap(new BasicBlock(Name, unwrap<Function>(FnRef)));
418 }
419
420 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef,
421                                        const char *Name) {
422   BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef);
423   return wrap(new BasicBlock(Name, InsertBeforeBB->getParent(),
424                              InsertBeforeBB));
425 }
426
427 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
428   unwrap(BBRef)->eraseFromParent();
429 }
430
431 /*--.. Call and invoke instructions ........................................--*/
432
433 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
434   Value *V = unwrap(Instr);
435   if (CallInst *CI = dyn_cast<CallInst>(V))
436     return CI->getCallingConv();
437   else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
438     return II->getCallingConv();
439   assert(0 && "LLVMGetInstructionCallConv applies only to call and invoke!");
440   return 0;
441 }
442
443 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
444   Value *V = unwrap(Instr);
445   if (CallInst *CI = dyn_cast<CallInst>(V))
446     return CI->setCallingConv(CC);
447   else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
448     return II->setCallingConv(CC);
449   assert(0 && "LLVMSetInstructionCallConv applies only to call and invoke!");
450 }
451
452
453 /*===-- Instruction builders ----------------------------------------------===*/
454
455 LLVMBuilderRef LLVMCreateBuilder() {
456   return wrap(new LLVMBuilder());
457 }
458
459 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
460   Instruction *I = unwrap<Instruction>(Instr);
461   unwrap(Builder)->SetInsertPoint(I->getParent(), I);
462 }
463
464 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
465   BasicBlock *BB = unwrap(Block);
466   unwrap(Builder)->SetInsertPoint(BB);
467 }
468
469 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
470   delete unwrap(Builder);
471 }
472
473 /*--.. Instruction builders ................................................--*/
474
475 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
476   return wrap(unwrap(B)->CreateRetVoid());
477 }
478
479 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
480   return wrap(unwrap(B)->CreateRet(unwrap(V)));
481 }
482
483 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
484   return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
485 }
486
487 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
488                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
489   return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
490 }
491
492 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
493                              LLVMBasicBlockRef Else, unsigned NumCases) {
494   return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
495 }
496
497 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
498                              LLVMValueRef *Args, unsigned NumArgs,
499                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
500                              const char *Name) {
501   return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
502                                       unwrap(Args), unwrap(Args) + NumArgs,
503                                       Name));
504 }
505
506 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) {
507   return wrap(unwrap(B)->CreateUnwind());
508 }
509
510 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
511   return wrap(unwrap(B)->CreateUnreachable());
512 }
513
514 /*--.. Arithmetic ..........................................................--*/
515
516 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
517                           const char *Name) {
518   return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
519 }
520
521 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
522                           const char *Name) {
523   return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
524 }
525
526 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
527                           const char *Name) {
528   return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
529 }
530
531 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
532                            const char *Name) {
533   return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
534 }
535
536 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
537                            const char *Name) {
538   return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
539 }
540
541 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
542                            const char *Name) {
543   return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
544 }
545
546 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
547                            const char *Name) {
548   return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
549 }
550
551 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
552                            const char *Name) {
553   return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
554 }
555
556 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
557                            const char *Name) {
558   return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
559 }
560
561 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
562                           const char *Name) {
563   return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
564 }
565
566 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
567                            const char *Name) {
568   return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
569 }
570
571 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
572                            const char *Name) {
573   return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
574 }
575
576 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
577                           const char *Name) {
578   return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
579 }
580
581 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
582                          const char *Name) {
583   return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
584 }
585
586 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
587                           const char *Name) {
588   return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
589 }
590
591 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
592   return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
593 }
594
595 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
596   return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
597 }
598
599 /*--.. Memory ..............................................................--*/
600
601 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
602                              const char *Name) {
603   return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name));
604 }
605
606 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
607                                   LLVMValueRef Val, const char *Name) {
608   return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name));
609 }
610
611 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
612                              const char *Name) {
613   return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
614 }
615
616 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
617                                   LLVMValueRef Val, const char *Name) {
618   return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
619 }
620
621 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
622   return wrap(unwrap(B)->CreateFree(unwrap(PointerVal)));
623 }
624
625
626 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
627                            const char *Name) {
628   return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
629 }
630
631 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, 
632                             LLVMValueRef PointerVal) {
633   return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
634 }
635
636 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
637                           LLVMValueRef *Indices, unsigned NumIndices,
638                           const char *Name) {
639   return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), unwrap(Indices),
640                                    unwrap(Indices) + NumIndices, Name));
641 }
642
643 /*--.. Casts ...............................................................--*/
644
645 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
646                             LLVMTypeRef DestTy, const char *Name) {
647   return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
648 }
649
650 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
651                            LLVMTypeRef DestTy, const char *Name) {
652   return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
653 }
654
655 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
656                            LLVMTypeRef DestTy, const char *Name) {
657   return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
658 }
659
660 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
661                              LLVMTypeRef DestTy, const char *Name) {
662   return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
663 }
664
665 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
666                              LLVMTypeRef DestTy, const char *Name) {
667   return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
668 }
669
670 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
671                              LLVMTypeRef DestTy, const char *Name) {
672   return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
673 }
674
675 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
676                              LLVMTypeRef DestTy, const char *Name) {
677   return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
678 }
679
680 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
681                               LLVMTypeRef DestTy, const char *Name) {
682   return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
683 }
684
685 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
686                             LLVMTypeRef DestTy, const char *Name) {
687   return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
688 }
689
690 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
691                                LLVMTypeRef DestTy, const char *Name) {
692   return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
693 }
694
695 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
696                                LLVMTypeRef DestTy, const char *Name) {
697   return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
698 }
699
700 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
701                               LLVMTypeRef DestTy, const char *Name) {
702   return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
703 }
704
705 /*--.. Comparisons .........................................................--*/
706
707 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
708                            LLVMValueRef LHS, LLVMValueRef RHS,
709                            const char *Name) {
710   return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
711                                     unwrap(LHS), unwrap(RHS), Name));
712 }
713
714 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
715                            LLVMValueRef LHS, LLVMValueRef RHS,
716                            const char *Name) {
717   return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
718                                     unwrap(LHS), unwrap(RHS), Name));
719 }
720
721 /*--.. Miscellaneous instructions ..........................................--*/
722
723 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
724   return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name));
725 }
726
727 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
728                            LLVMValueRef *Args, unsigned NumArgs,
729                            const char *Name) {
730   return wrap(unwrap(B)->CreateCall(unwrap(Fn), unwrap(Args),
731                                     unwrap(Args) + NumArgs, Name));
732 }
733
734 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
735                              LLVMValueRef Then, LLVMValueRef Else,
736                              const char *Name) {
737   return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
738                                       Name));
739 }
740
741 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
742                             LLVMTypeRef Ty, const char *Name) {
743   return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
744 }
745
746 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
747                                       LLVMValueRef Index, const char *Name) {
748   return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
749                                               Name));
750 }
751
752 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
753                                     LLVMValueRef EltVal, LLVMValueRef Index,
754                                     const char *Name) {
755   return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
756                                              unwrap(Index), Name));
757 }
758
759 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
760                                     LLVMValueRef V2, LLVMValueRef Mask,
761                                     const char *Name) {
762   return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
763                                              unwrap(Mask), Name));
764 }