1 //===-- Core.cpp ----------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the common infrastructure (including the C bindings)
11 // for libLLVMCore.a, which implements the LLVM intermediate representation.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Core.h"
16 #include "llvm/Attributes.h"
17 #include "llvm/Bitcode/ReaderWriter.h"
18 #include "llvm/Constants.h"
19 #include "llvm/DerivedTypes.h"
20 #include "llvm/GlobalAlias.h"
21 #include "llvm/GlobalVariable.h"
22 #include "llvm/InlineAsm.h"
23 #include "llvm/IntrinsicInst.h"
24 #include "llvm/LLVMContext.h"
25 #include "llvm/PassManager.h"
26 #include "llvm/Support/CallSite.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/MemoryBuffer.h"
30 #include "llvm/Support/raw_ostream.h"
31 #include "llvm/Support/system_error.h"
38 void llvm::initializeCore(PassRegistry &Registry) {
39 initializeDominatorTreePass(Registry);
40 initializePrintModulePassPass(Registry);
41 initializePrintFunctionPassPass(Registry);
42 initializeVerifierPass(Registry);
43 initializePreVerifierPass(Registry);
46 void LLVMInitializeCore(LLVMPassRegistryRef R) {
47 initializeCore(*unwrap(R));
50 /*===-- Error handling ----------------------------------------------------===*/
52 void LLVMDisposeMessage(char *Message) {
57 /*===-- Operations on contexts --------------------------------------------===*/
59 LLVMContextRef LLVMContextCreate() {
60 return wrap(new LLVMContext());
63 LLVMContextRef LLVMGetGlobalContext() {
64 return wrap(&getGlobalContext());
67 void LLVMContextDispose(LLVMContextRef C) {
71 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
73 return unwrap(C)->getMDKindID(StringRef(Name, SLen));
76 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
77 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
81 /*===-- Operations on modules ---------------------------------------------===*/
83 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
84 return wrap(new Module(ModuleID, getGlobalContext()));
87 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
89 return wrap(new Module(ModuleID, *unwrap(C)));
92 void LLVMDisposeModule(LLVMModuleRef M) {
96 /*--.. Data layout .........................................................--*/
97 const char * LLVMGetDataLayout(LLVMModuleRef M) {
98 return unwrap(M)->getDataLayout().c_str();
101 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
102 unwrap(M)->setDataLayout(Triple);
105 /*--.. Target triple .......................................................--*/
106 const char * LLVMGetTarget(LLVMModuleRef M) {
107 return unwrap(M)->getTargetTriple().c_str();
110 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
111 unwrap(M)->setTargetTriple(Triple);
114 void LLVMDumpModule(LLVMModuleRef M) {
118 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
119 char **ErrorMessage) {
121 raw_fd_ostream dest(Filename, error);
122 if (!error.empty()) {
123 *ErrorMessage = strdup(error.c_str());
127 unwrap(M)->print(dest, NULL);
129 if (!error.empty()) {
130 *ErrorMessage = strdup(error.c_str());
137 /*--.. Operations on inline assembler ......................................--*/
138 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
139 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
143 /*--.. Operations on module contexts ......................................--*/
144 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) {
145 return wrap(&unwrap(M)->getContext());
149 /*===-- Operations on types -----------------------------------------------===*/
151 /*--.. Operations on all types (mostly) ....................................--*/
153 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
154 switch (unwrap(Ty)->getTypeID()) {
155 default: llvm_unreachable("Unhandled TypeID.");
157 return LLVMVoidTypeKind;
159 return LLVMHalfTypeKind;
160 case Type::FloatTyID:
161 return LLVMFloatTypeKind;
162 case Type::DoubleTyID:
163 return LLVMDoubleTypeKind;
164 case Type::X86_FP80TyID:
165 return LLVMX86_FP80TypeKind;
166 case Type::FP128TyID:
167 return LLVMFP128TypeKind;
168 case Type::PPC_FP128TyID:
169 return LLVMPPC_FP128TypeKind;
170 case Type::LabelTyID:
171 return LLVMLabelTypeKind;
172 case Type::MetadataTyID:
173 return LLVMMetadataTypeKind;
174 case Type::IntegerTyID:
175 return LLVMIntegerTypeKind;
176 case Type::FunctionTyID:
177 return LLVMFunctionTypeKind;
178 case Type::StructTyID:
179 return LLVMStructTypeKind;
180 case Type::ArrayTyID:
181 return LLVMArrayTypeKind;
182 case Type::PointerTyID:
183 return LLVMPointerTypeKind;
184 case Type::VectorTyID:
185 return LLVMVectorTypeKind;
186 case Type::X86_MMXTyID:
187 return LLVMX86_MMXTypeKind;
191 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
193 return unwrap(Ty)->isSized();
196 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
197 return wrap(&unwrap(Ty)->getContext());
200 /*--.. Operations on integer types .........................................--*/
202 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
203 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
205 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
206 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
208 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
209 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
211 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
212 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
214 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
215 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
217 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
218 return wrap(IntegerType::get(*unwrap(C), NumBits));
221 LLVMTypeRef LLVMInt1Type(void) {
222 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
224 LLVMTypeRef LLVMInt8Type(void) {
225 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
227 LLVMTypeRef LLVMInt16Type(void) {
228 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
230 LLVMTypeRef LLVMInt32Type(void) {
231 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
233 LLVMTypeRef LLVMInt64Type(void) {
234 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
236 LLVMTypeRef LLVMIntType(unsigned NumBits) {
237 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
240 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
241 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
244 /*--.. Operations on real types ............................................--*/
246 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) {
247 return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
249 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
250 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
252 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
253 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
255 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
256 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
258 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
259 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
261 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
262 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
264 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
265 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
268 LLVMTypeRef LLVMHalfType(void) {
269 return LLVMHalfTypeInContext(LLVMGetGlobalContext());
271 LLVMTypeRef LLVMFloatType(void) {
272 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
274 LLVMTypeRef LLVMDoubleType(void) {
275 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
277 LLVMTypeRef LLVMX86FP80Type(void) {
278 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
280 LLVMTypeRef LLVMFP128Type(void) {
281 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
283 LLVMTypeRef LLVMPPCFP128Type(void) {
284 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
286 LLVMTypeRef LLVMX86MMXType(void) {
287 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
290 /*--.. Operations on function types ........................................--*/
292 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
293 LLVMTypeRef *ParamTypes, unsigned ParamCount,
295 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
296 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
299 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
300 return unwrap<FunctionType>(FunctionTy)->isVarArg();
303 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
304 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
307 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
308 return unwrap<FunctionType>(FunctionTy)->getNumParams();
311 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
312 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
313 for (FunctionType::param_iterator I = Ty->param_begin(),
314 E = Ty->param_end(); I != E; ++I)
318 /*--.. Operations on struct types ..........................................--*/
320 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
321 unsigned ElementCount, LLVMBool Packed) {
322 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
323 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
326 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
327 unsigned ElementCount, LLVMBool Packed) {
328 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
329 ElementCount, Packed);
332 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
334 return wrap(StructType::create(*unwrap(C), Name));
337 const char *LLVMGetStructName(LLVMTypeRef Ty)
339 StructType *Type = unwrap<StructType>(Ty);
340 if (!Type->hasName())
342 return Type->getName().data();
345 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
346 unsigned ElementCount, LLVMBool Packed) {
347 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
348 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
351 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
352 return unwrap<StructType>(StructTy)->getNumElements();
355 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
356 StructType *Ty = unwrap<StructType>(StructTy);
357 for (StructType::element_iterator I = Ty->element_begin(),
358 E = Ty->element_end(); I != E; ++I)
362 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
363 return unwrap<StructType>(StructTy)->isPacked();
366 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
367 return unwrap<StructType>(StructTy)->isOpaque();
370 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
371 return wrap(unwrap(M)->getTypeByName(Name));
374 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
376 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
377 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
380 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
381 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
384 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
385 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
388 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
389 return wrap(unwrap<SequentialType>(Ty)->getElementType());
392 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
393 return unwrap<ArrayType>(ArrayTy)->getNumElements();
396 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
397 return unwrap<PointerType>(PointerTy)->getAddressSpace();
400 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
401 return unwrap<VectorType>(VectorTy)->getNumElements();
404 /*--.. Operations on other types ...........................................--*/
406 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
407 return wrap(Type::getVoidTy(*unwrap(C)));
409 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
410 return wrap(Type::getLabelTy(*unwrap(C)));
413 LLVMTypeRef LLVMVoidType(void) {
414 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
416 LLVMTypeRef LLVMLabelType(void) {
417 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
420 /*===-- Operations on values ----------------------------------------------===*/
422 /*--.. Operations on all values ............................................--*/
424 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
425 return wrap(unwrap(Val)->getType());
428 const char *LLVMGetValueName(LLVMValueRef Val) {
429 return unwrap(Val)->getName().data();
432 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
433 unwrap(Val)->setName(Name);
436 void LLVMDumpValue(LLVMValueRef Val) {
440 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
441 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
444 int LLVMHasMetadata(LLVMValueRef Inst) {
445 return unwrap<Instruction>(Inst)->hasMetadata();
448 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
449 return wrap(unwrap<Instruction>(Inst)->getMetadata(KindID));
452 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
453 unwrap<Instruction>(Inst)->setMetadata(KindID, MD? unwrap<MDNode>(MD) : NULL);
456 /*--.. Conversion functions ................................................--*/
458 #define LLVM_DEFINE_VALUE_CAST(name) \
459 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
460 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
463 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
465 /*--.. Operations on Uses ..................................................--*/
466 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
467 Value *V = unwrap(Val);
468 Value::use_iterator I = V->use_begin();
469 if (I == V->use_end())
471 return wrap(&(I.getUse()));
474 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
475 Use *Next = unwrap(U)->getNext();
481 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
482 return wrap(unwrap(U)->getUser());
485 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
486 return wrap(unwrap(U)->get());
489 /*--.. Operations on Users .................................................--*/
490 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
491 Value *V = unwrap(Val);
492 if (MDNode *MD = dyn_cast<MDNode>(V))
493 return wrap(MD->getOperand(Index));
494 return wrap(cast<User>(V)->getOperand(Index));
497 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
498 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
501 int LLVMGetNumOperands(LLVMValueRef Val) {
502 Value *V = unwrap(Val);
503 if (MDNode *MD = dyn_cast<MDNode>(V))
504 return MD->getNumOperands();
505 return cast<User>(V)->getNumOperands();
508 /*--.. Operations on constants of any type .................................--*/
510 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
511 return wrap(Constant::getNullValue(unwrap(Ty)));
514 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
515 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
518 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
519 return wrap(UndefValue::get(unwrap(Ty)));
522 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
523 return isa<Constant>(unwrap(Ty));
526 LLVMBool LLVMIsNull(LLVMValueRef Val) {
527 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
528 return C->isNullValue();
532 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
533 return isa<UndefValue>(unwrap(Val));
536 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
538 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
541 /*--.. Operations on metadata nodes ........................................--*/
543 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
545 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
548 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
549 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
552 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
554 return wrap(MDNode::get(*unwrap(C),
555 makeArrayRef(unwrap<Value>(Vals, Count), Count)));
558 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
559 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
562 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
563 if (const MDString *S = dyn_cast<MDString>(unwrap(V))) {
564 *Len = S->getString().size();
565 return S->getString().data();
571 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
573 return cast<MDNode>(unwrap(V))->getNumOperands();
576 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
578 const MDNode *N = cast<MDNode>(unwrap(V));
579 const unsigned numOperands = N->getNumOperands();
580 for (unsigned i = 0; i < numOperands; i++)
581 Dest[i] = wrap(N->getOperand(i));
584 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
586 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
587 return N->getNumOperands();
592 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
594 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
597 for (unsigned i=0;i<N->getNumOperands();i++)
598 Dest[i] = wrap(N->getOperand(i));
601 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
604 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
607 MDNode *Op = Val ? unwrap<MDNode>(Val) : NULL;
612 /*--.. Operations on scalar constants ......................................--*/
614 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
615 LLVMBool SignExtend) {
616 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
619 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
621 const uint64_t Words[]) {
622 IntegerType *Ty = unwrap<IntegerType>(IntTy);
623 return wrap(ConstantInt::get(Ty->getContext(),
624 APInt(Ty->getBitWidth(),
625 makeArrayRef(Words, NumWords))));
628 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
630 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
634 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
635 unsigned SLen, uint8_t Radix) {
636 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
640 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
641 return wrap(ConstantFP::get(unwrap(RealTy), N));
644 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
645 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
648 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
650 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
653 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
654 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
657 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
658 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
661 /*--.. Operations on composite constants ...................................--*/
663 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
665 LLVMBool DontNullTerminate) {
666 /* Inverted the sense of AddNull because ', 0)' is a
667 better mnemonic for null termination than ', 1)'. */
668 return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
669 DontNullTerminate == 0));
671 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
672 LLVMValueRef *ConstantVals,
673 unsigned Count, LLVMBool Packed) {
674 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
675 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
679 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
680 LLVMBool DontNullTerminate) {
681 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
684 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
685 LLVMValueRef *ConstantVals, unsigned Length) {
686 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
687 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
689 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
691 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
695 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
696 LLVMValueRef *ConstantVals,
698 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
699 StructType *Ty = cast<StructType>(unwrap(StructTy));
701 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
704 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
705 return wrap(ConstantVector::get(makeArrayRef(
706 unwrap<Constant>(ScalarConstantVals, Size), Size)));
709 /*-- Opcode mapping */
711 static LLVMOpcode map_to_llvmopcode(int opcode)
714 default: llvm_unreachable("Unhandled Opcode.");
715 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
716 #include "llvm/Instruction.def"
721 static int map_from_llvmopcode(LLVMOpcode code)
724 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
725 #include "llvm/Instruction.def"
728 llvm_unreachable("Unhandled Opcode.");
731 /*--.. Constant expressions ................................................--*/
733 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
734 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
737 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
738 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
741 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
742 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
745 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
746 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
749 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
750 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
753 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
754 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
758 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
759 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
762 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
763 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
766 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
767 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
768 unwrap<Constant>(RHSConstant)));
771 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
772 LLVMValueRef RHSConstant) {
773 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
774 unwrap<Constant>(RHSConstant)));
777 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
778 LLVMValueRef RHSConstant) {
779 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
780 unwrap<Constant>(RHSConstant)));
783 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
784 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
785 unwrap<Constant>(RHSConstant)));
788 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
789 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
790 unwrap<Constant>(RHSConstant)));
793 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
794 LLVMValueRef RHSConstant) {
795 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
796 unwrap<Constant>(RHSConstant)));
799 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
800 LLVMValueRef RHSConstant) {
801 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
802 unwrap<Constant>(RHSConstant)));
805 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
806 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
807 unwrap<Constant>(RHSConstant)));
810 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
811 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
812 unwrap<Constant>(RHSConstant)));
815 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
816 LLVMValueRef RHSConstant) {
817 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
818 unwrap<Constant>(RHSConstant)));
821 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
822 LLVMValueRef RHSConstant) {
823 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
824 unwrap<Constant>(RHSConstant)));
827 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
828 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
829 unwrap<Constant>(RHSConstant)));
832 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
833 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
834 unwrap<Constant>(RHSConstant)));
837 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
838 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
839 unwrap<Constant>(RHSConstant)));
842 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
843 LLVMValueRef RHSConstant) {
844 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
845 unwrap<Constant>(RHSConstant)));
848 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
849 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
850 unwrap<Constant>(RHSConstant)));
853 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
854 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
855 unwrap<Constant>(RHSConstant)));
858 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
859 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
860 unwrap<Constant>(RHSConstant)));
863 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
864 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
865 unwrap<Constant>(RHSConstant)));
868 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
869 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
870 unwrap<Constant>(RHSConstant)));
873 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
874 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
875 unwrap<Constant>(RHSConstant)));
878 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
879 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
880 unwrap<Constant>(RHSConstant)));
883 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
884 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
885 return wrap(ConstantExpr::getICmp(Predicate,
886 unwrap<Constant>(LHSConstant),
887 unwrap<Constant>(RHSConstant)));
890 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
891 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
892 return wrap(ConstantExpr::getFCmp(Predicate,
893 unwrap<Constant>(LHSConstant),
894 unwrap<Constant>(RHSConstant)));
897 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
898 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
899 unwrap<Constant>(RHSConstant)));
902 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
903 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
904 unwrap<Constant>(RHSConstant)));
907 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
908 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
909 unwrap<Constant>(RHSConstant)));
912 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
913 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
914 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
916 return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
920 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
921 LLVMValueRef *ConstantIndices,
922 unsigned NumIndices) {
923 Constant* Val = unwrap<Constant>(ConstantVal);
924 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
926 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
929 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
930 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
934 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
935 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
939 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
940 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
944 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
945 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
949 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
950 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
954 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
955 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
959 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
960 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
964 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
965 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
969 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
970 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
974 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
975 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
979 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
980 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
984 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
985 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
989 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
990 LLVMTypeRef ToType) {
991 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
995 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
996 LLVMTypeRef ToType) {
997 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1001 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1002 LLVMTypeRef ToType) {
1003 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1007 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1008 LLVMTypeRef ToType) {
1009 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1013 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1014 LLVMBool isSigned) {
1015 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1016 unwrap(ToType), isSigned));
1019 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1020 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1024 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1025 LLVMValueRef ConstantIfTrue,
1026 LLVMValueRef ConstantIfFalse) {
1027 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1028 unwrap<Constant>(ConstantIfTrue),
1029 unwrap<Constant>(ConstantIfFalse)));
1032 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1033 LLVMValueRef IndexConstant) {
1034 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1035 unwrap<Constant>(IndexConstant)));
1038 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1039 LLVMValueRef ElementValueConstant,
1040 LLVMValueRef IndexConstant) {
1041 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1042 unwrap<Constant>(ElementValueConstant),
1043 unwrap<Constant>(IndexConstant)));
1046 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1047 LLVMValueRef VectorBConstant,
1048 LLVMValueRef MaskConstant) {
1049 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1050 unwrap<Constant>(VectorBConstant),
1051 unwrap<Constant>(MaskConstant)));
1054 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1056 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1057 makeArrayRef(IdxList, NumIdx)));
1060 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1061 LLVMValueRef ElementValueConstant,
1062 unsigned *IdxList, unsigned NumIdx) {
1063 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1064 unwrap<Constant>(ElementValueConstant),
1065 makeArrayRef(IdxList, NumIdx)));
1068 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1069 const char *Constraints,
1070 LLVMBool HasSideEffects,
1071 LLVMBool IsAlignStack) {
1072 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1073 Constraints, HasSideEffects, IsAlignStack));
1076 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1077 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1080 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1082 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1083 return wrap(unwrap<GlobalValue>(Global)->getParent());
1086 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1087 return unwrap<GlobalValue>(Global)->isDeclaration();
1090 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1091 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1092 case GlobalValue::ExternalLinkage:
1093 return LLVMExternalLinkage;
1094 case GlobalValue::AvailableExternallyLinkage:
1095 return LLVMAvailableExternallyLinkage;
1096 case GlobalValue::LinkOnceAnyLinkage:
1097 return LLVMLinkOnceAnyLinkage;
1098 case GlobalValue::LinkOnceODRLinkage:
1099 return LLVMLinkOnceODRLinkage;
1100 case GlobalValue::LinkOnceODRAutoHideLinkage:
1101 return LLVMLinkOnceODRAutoHideLinkage;
1102 case GlobalValue::WeakAnyLinkage:
1103 return LLVMWeakAnyLinkage;
1104 case GlobalValue::WeakODRLinkage:
1105 return LLVMWeakODRLinkage;
1106 case GlobalValue::AppendingLinkage:
1107 return LLVMAppendingLinkage;
1108 case GlobalValue::InternalLinkage:
1109 return LLVMInternalLinkage;
1110 case GlobalValue::PrivateLinkage:
1111 return LLVMPrivateLinkage;
1112 case GlobalValue::LinkerPrivateLinkage:
1113 return LLVMLinkerPrivateLinkage;
1114 case GlobalValue::LinkerPrivateWeakLinkage:
1115 return LLVMLinkerPrivateWeakLinkage;
1116 case GlobalValue::DLLImportLinkage:
1117 return LLVMDLLImportLinkage;
1118 case GlobalValue::DLLExportLinkage:
1119 return LLVMDLLExportLinkage;
1120 case GlobalValue::ExternalWeakLinkage:
1121 return LLVMExternalWeakLinkage;
1122 case GlobalValue::CommonLinkage:
1123 return LLVMCommonLinkage;
1126 llvm_unreachable("Invalid GlobalValue linkage!");
1129 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1130 GlobalValue *GV = unwrap<GlobalValue>(Global);
1133 case LLVMExternalLinkage:
1134 GV->setLinkage(GlobalValue::ExternalLinkage);
1136 case LLVMAvailableExternallyLinkage:
1137 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1139 case LLVMLinkOnceAnyLinkage:
1140 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1142 case LLVMLinkOnceODRLinkage:
1143 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1145 case LLVMLinkOnceODRAutoHideLinkage:
1146 GV->setLinkage(GlobalValue::LinkOnceODRAutoHideLinkage);
1148 case LLVMWeakAnyLinkage:
1149 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1151 case LLVMWeakODRLinkage:
1152 GV->setLinkage(GlobalValue::WeakODRLinkage);
1154 case LLVMAppendingLinkage:
1155 GV->setLinkage(GlobalValue::AppendingLinkage);
1157 case LLVMInternalLinkage:
1158 GV->setLinkage(GlobalValue::InternalLinkage);
1160 case LLVMPrivateLinkage:
1161 GV->setLinkage(GlobalValue::PrivateLinkage);
1163 case LLVMLinkerPrivateLinkage:
1164 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
1166 case LLVMLinkerPrivateWeakLinkage:
1167 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
1169 case LLVMDLLImportLinkage:
1170 GV->setLinkage(GlobalValue::DLLImportLinkage);
1172 case LLVMDLLExportLinkage:
1173 GV->setLinkage(GlobalValue::DLLExportLinkage);
1175 case LLVMExternalWeakLinkage:
1176 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1178 case LLVMGhostLinkage:
1180 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1182 case LLVMCommonLinkage:
1183 GV->setLinkage(GlobalValue::CommonLinkage);
1188 const char *LLVMGetSection(LLVMValueRef Global) {
1189 return unwrap<GlobalValue>(Global)->getSection().c_str();
1192 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1193 unwrap<GlobalValue>(Global)->setSection(Section);
1196 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1197 return static_cast<LLVMVisibility>(
1198 unwrap<GlobalValue>(Global)->getVisibility());
1201 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1202 unwrap<GlobalValue>(Global)
1203 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1206 unsigned LLVMGetAlignment(LLVMValueRef Global) {
1207 return unwrap<GlobalValue>(Global)->getAlignment();
1210 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
1211 unwrap<GlobalValue>(Global)->setAlignment(Bytes);
1214 /*--.. Operations on global variables ......................................--*/
1216 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1217 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1218 GlobalValue::ExternalLinkage, 0, Name));
1221 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1223 unsigned AddressSpace) {
1224 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1225 GlobalValue::ExternalLinkage, 0, Name, 0,
1226 GlobalVariable::NotThreadLocal, AddressSpace));
1229 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1230 return wrap(unwrap(M)->getNamedGlobal(Name));
1233 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1234 Module *Mod = unwrap(M);
1235 Module::global_iterator I = Mod->global_begin();
1236 if (I == Mod->global_end())
1241 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1242 Module *Mod = unwrap(M);
1243 Module::global_iterator I = Mod->global_end();
1244 if (I == Mod->global_begin())
1249 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1250 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1251 Module::global_iterator I = GV;
1252 if (++I == GV->getParent()->global_end())
1257 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1258 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1259 Module::global_iterator I = GV;
1260 if (I == GV->getParent()->global_begin())
1265 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1266 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1269 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1270 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1271 if ( !GV->hasInitializer() )
1273 return wrap(GV->getInitializer());
1276 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1277 unwrap<GlobalVariable>(GlobalVar)
1278 ->setInitializer(unwrap<Constant>(ConstantVal));
1281 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1282 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1285 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1286 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1289 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1290 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1293 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1294 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1297 /*--.. Operations on aliases ......................................--*/
1299 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1301 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
1302 unwrap<Constant>(Aliasee), unwrap (M)));
1305 /*--.. Operations on functions .............................................--*/
1307 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1308 LLVMTypeRef FunctionTy) {
1309 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1310 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1313 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1314 return wrap(unwrap(M)->getFunction(Name));
1317 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1318 Module *Mod = unwrap(M);
1319 Module::iterator I = Mod->begin();
1320 if (I == Mod->end())
1325 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1326 Module *Mod = unwrap(M);
1327 Module::iterator I = Mod->end();
1328 if (I == Mod->begin())
1333 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1334 Function *Func = unwrap<Function>(Fn);
1335 Module::iterator I = Func;
1336 if (++I == Func->getParent()->end())
1341 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1342 Function *Func = unwrap<Function>(Fn);
1343 Module::iterator I = Func;
1344 if (I == Func->getParent()->begin())
1349 void LLVMDeleteFunction(LLVMValueRef Fn) {
1350 unwrap<Function>(Fn)->eraseFromParent();
1353 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1354 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1355 return F->getIntrinsicID();
1359 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1360 return unwrap<Function>(Fn)->getCallingConv();
1363 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1364 return unwrap<Function>(Fn)->setCallingConv(
1365 static_cast<CallingConv::ID>(CC));
1368 const char *LLVMGetGC(LLVMValueRef Fn) {
1369 Function *F = unwrap<Function>(Fn);
1370 return F->hasGC()? F->getGC() : 0;
1373 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1374 Function *F = unwrap<Function>(Fn);
1381 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1382 Function *Func = unwrap<Function>(Fn);
1383 const AttributeSet PAL = Func->getAttributes();
1385 const AttributeSet PALnew =
1386 PAL.addAttr(Func->getContext(), AttributeSet::FunctionIndex,
1387 Attribute::get(Func->getContext(), B));
1388 Func->setAttributes(PALnew);
1391 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1392 Function *Func = unwrap<Function>(Fn);
1393 const AttributeSet PAL = Func->getAttributes();
1395 const AttributeSet PALnew =
1396 PAL.removeAttr(Func->getContext(), AttributeSet::FunctionIndex,
1397 Attribute::get(Func->getContext(), B));
1398 Func->setAttributes(PALnew);
1401 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1402 Function *Func = unwrap<Function>(Fn);
1403 const AttributeSet PAL = Func->getAttributes();
1404 Attribute attr = PAL.getFnAttributes();
1405 return (LLVMAttribute)attr.Raw();
1408 /*--.. Operations on parameters ............................................--*/
1410 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1411 // This function is strictly redundant to
1412 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1413 return unwrap<Function>(FnRef)->arg_size();
1416 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1417 Function *Fn = unwrap<Function>(FnRef);
1418 for (Function::arg_iterator I = Fn->arg_begin(),
1419 E = Fn->arg_end(); I != E; I++)
1420 *ParamRefs++ = wrap(I);
1423 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1424 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1430 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1431 return wrap(unwrap<Argument>(V)->getParent());
1434 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1435 Function *Func = unwrap<Function>(Fn);
1436 Function::arg_iterator I = Func->arg_begin();
1437 if (I == Func->arg_end())
1442 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1443 Function *Func = unwrap<Function>(Fn);
1444 Function::arg_iterator I = Func->arg_end();
1445 if (I == Func->arg_begin())
1450 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1451 Argument *A = unwrap<Argument>(Arg);
1452 Function::arg_iterator I = A;
1453 if (++I == A->getParent()->arg_end())
1458 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1459 Argument *A = unwrap<Argument>(Arg);
1460 Function::arg_iterator I = A;
1461 if (I == A->getParent()->arg_begin())
1466 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1467 Argument *A = unwrap<Argument>(Arg);
1469 A->addAttr(Attribute::get(A->getContext(), B));
1472 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1473 Argument *A = unwrap<Argument>(Arg);
1475 A->removeAttr(Attribute::get(A->getContext(), B));
1478 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1479 Argument *A = unwrap<Argument>(Arg);
1480 Attribute attr = A->getParent()->getAttributes().getParamAttributes(
1482 return (LLVMAttribute)attr.Raw();
1486 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1488 B.addAlignmentAttr(align);
1489 unwrap<Argument>(Arg)->addAttr(Attribute::
1490 get(unwrap<Argument>(Arg)->getContext(), B));
1493 /*--.. Operations on basic blocks ..........................................--*/
1495 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1496 return wrap(static_cast<Value*>(unwrap(BB)));
1499 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1500 return isa<BasicBlock>(unwrap(Val));
1503 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1504 return wrap(unwrap<BasicBlock>(Val));
1507 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1508 return wrap(unwrap(BB)->getParent());
1511 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1512 return wrap(unwrap(BB)->getTerminator());
1515 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1516 return unwrap<Function>(FnRef)->size();
1519 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1520 Function *Fn = unwrap<Function>(FnRef);
1521 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1522 *BasicBlocksRefs++ = wrap(I);
1525 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1526 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1529 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1530 Function *Func = unwrap<Function>(Fn);
1531 Function::iterator I = Func->begin();
1532 if (I == Func->end())
1537 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1538 Function *Func = unwrap<Function>(Fn);
1539 Function::iterator I = Func->end();
1540 if (I == Func->begin())
1545 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1546 BasicBlock *Block = unwrap(BB);
1547 Function::iterator I = Block;
1548 if (++I == Block->getParent()->end())
1553 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1554 BasicBlock *Block = unwrap(BB);
1555 Function::iterator I = Block;
1556 if (I == Block->getParent()->begin())
1561 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1564 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1567 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1568 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1571 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1572 LLVMBasicBlockRef BBRef,
1574 BasicBlock *BB = unwrap(BBRef);
1575 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1578 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1580 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1583 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1584 unwrap(BBRef)->eraseFromParent();
1587 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1588 unwrap(BBRef)->removeFromParent();
1591 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1592 unwrap(BB)->moveBefore(unwrap(MovePos));
1595 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1596 unwrap(BB)->moveAfter(unwrap(MovePos));
1599 /*--.. Operations on instructions ..........................................--*/
1601 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1602 return wrap(unwrap<Instruction>(Inst)->getParent());
1605 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1606 BasicBlock *Block = unwrap(BB);
1607 BasicBlock::iterator I = Block->begin();
1608 if (I == Block->end())
1613 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1614 BasicBlock *Block = unwrap(BB);
1615 BasicBlock::iterator I = Block->end();
1616 if (I == Block->begin())
1621 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1622 Instruction *Instr = unwrap<Instruction>(Inst);
1623 BasicBlock::iterator I = Instr;
1624 if (++I == Instr->getParent()->end())
1629 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1630 Instruction *Instr = unwrap<Instruction>(Inst);
1631 BasicBlock::iterator I = Instr;
1632 if (I == Instr->getParent()->begin())
1637 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
1638 unwrap<Instruction>(Inst)->eraseFromParent();
1641 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
1642 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
1643 return (LLVMIntPredicate)I->getPredicate();
1644 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
1645 if (CE->getOpcode() == Instruction::ICmp)
1646 return (LLVMIntPredicate)CE->getPredicate();
1647 return (LLVMIntPredicate)0;
1650 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
1651 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
1652 return map_to_llvmopcode(C->getOpcode());
1653 return (LLVMOpcode)0;
1656 /*--.. Call and invoke instructions ........................................--*/
1658 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
1659 Value *V = unwrap(Instr);
1660 if (CallInst *CI = dyn_cast<CallInst>(V))
1661 return CI->getCallingConv();
1662 if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1663 return II->getCallingConv();
1664 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1667 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
1668 Value *V = unwrap(Instr);
1669 if (CallInst *CI = dyn_cast<CallInst>(V))
1670 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
1671 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1672 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
1673 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1676 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
1678 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1681 Call.getAttributes().addAttr(Call->getContext(), index,
1682 Attribute::get(Call->getContext(), B)));
1685 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
1687 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1690 Call.getAttributes().removeAttr(Call->getContext(), index,
1691 Attribute::get(Call->getContext(), B)));
1694 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
1696 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1698 B.addAlignmentAttr(align);
1699 Call.setAttributes(Call.getAttributes().addAttr(Call->getContext(), index,
1700 Attribute::get(Call->getContext(), B)));
1703 /*--.. Operations on call instructions (only) ..............................--*/
1705 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
1706 return unwrap<CallInst>(Call)->isTailCall();
1709 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
1710 unwrap<CallInst>(Call)->setTailCall(isTailCall);
1713 /*--.. Operations on switch instructions (only) ............................--*/
1715 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
1716 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
1719 /*--.. Operations on phi nodes .............................................--*/
1721 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
1722 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
1723 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
1724 for (unsigned I = 0; I != Count; ++I)
1725 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
1728 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
1729 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
1732 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
1733 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
1736 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
1737 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
1741 /*===-- Instruction builders ----------------------------------------------===*/
1743 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
1744 return wrap(new IRBuilder<>(*unwrap(C)));
1747 LLVMBuilderRef LLVMCreateBuilder(void) {
1748 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1751 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
1752 LLVMValueRef Instr) {
1753 BasicBlock *BB = unwrap(Block);
1754 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
1755 unwrap(Builder)->SetInsertPoint(BB, I);
1758 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1759 Instruction *I = unwrap<Instruction>(Instr);
1760 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
1763 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
1764 BasicBlock *BB = unwrap(Block);
1765 unwrap(Builder)->SetInsertPoint(BB);
1768 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
1769 return wrap(unwrap(Builder)->GetInsertBlock());
1772 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
1773 unwrap(Builder)->ClearInsertionPoint();
1776 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1777 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
1780 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
1782 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
1785 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
1786 delete unwrap(Builder);
1789 /*--.. Metadata builders ...................................................--*/
1791 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
1792 MDNode *Loc = L ? unwrap<MDNode>(L) : NULL;
1793 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc));
1796 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
1797 return wrap(unwrap(Builder)->getCurrentDebugLocation()
1798 .getAsMDNode(unwrap(Builder)->getContext()));
1801 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
1802 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
1806 /*--.. Instruction builders ................................................--*/
1808 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
1809 return wrap(unwrap(B)->CreateRetVoid());
1812 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
1813 return wrap(unwrap(B)->CreateRet(unwrap(V)));
1816 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
1818 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
1821 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
1822 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
1825 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
1826 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
1827 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
1830 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
1831 LLVMBasicBlockRef Else, unsigned NumCases) {
1832 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
1835 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
1836 unsigned NumDests) {
1837 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
1840 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
1841 LLVMValueRef *Args, unsigned NumArgs,
1842 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
1844 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
1845 makeArrayRef(unwrap(Args), NumArgs),
1849 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
1850 LLVMValueRef PersFn, unsigned NumClauses,
1852 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty),
1853 cast<Function>(unwrap(PersFn)),
1857 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
1858 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
1861 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
1862 return wrap(unwrap(B)->CreateUnreachable());
1865 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
1866 LLVMBasicBlockRef Dest) {
1867 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
1870 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
1871 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
1874 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
1875 unwrap<LandingPadInst>(LandingPad)->
1876 addClause(cast<Constant>(unwrap(ClauseVal)));
1879 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
1880 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
1883 /*--.. Arithmetic ..........................................................--*/
1885 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1887 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
1890 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1892 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
1895 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1897 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
1900 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1902 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
1905 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1907 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
1910 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1912 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
1915 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1917 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
1920 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1922 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
1925 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1927 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
1930 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1932 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
1935 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1937 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
1940 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1942 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
1945 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1947 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
1950 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1952 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
1955 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
1956 LLVMValueRef RHS, const char *Name) {
1957 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
1960 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1962 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
1965 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1967 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
1970 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1972 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
1975 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1977 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
1980 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1982 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
1985 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1987 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
1990 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1992 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
1995 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1997 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2000 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2002 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2005 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2007 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2010 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2011 LLVMValueRef LHS, LLVMValueRef RHS,
2013 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2014 unwrap(RHS), Name));
2017 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2018 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2021 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2023 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2026 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2028 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2031 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2032 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2035 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2036 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2039 /*--.. Memory ..............................................................--*/
2041 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2043 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2044 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2045 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2046 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2047 ITy, unwrap(Ty), AllocSize,
2049 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2052 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2053 LLVMValueRef Val, const char *Name) {
2054 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2055 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2056 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2057 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2058 ITy, unwrap(Ty), AllocSize,
2059 unwrap(Val), 0, "");
2060 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2063 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2065 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
2068 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2069 LLVMValueRef Val, const char *Name) {
2070 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2073 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2074 return wrap(unwrap(B)->Insert(
2075 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2079 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2081 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2084 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2085 LLVMValueRef PointerVal) {
2086 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2089 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2090 LLVMValueRef *Indices, unsigned NumIndices,
2092 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2093 return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), IdxList, Name));
2096 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2097 LLVMValueRef *Indices, unsigned NumIndices,
2099 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2100 return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), IdxList, Name));
2103 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2104 unsigned Idx, const char *Name) {
2105 return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name));
2108 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2110 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2113 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2115 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2118 LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) {
2119 Value *P = unwrap<Value>(MemAccessInst);
2120 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2121 return LI->isVolatile();
2122 return cast<StoreInst>(P)->isVolatile();
2125 void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) {
2126 Value *P = unwrap<Value>(MemAccessInst);
2127 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2128 return LI->setVolatile(isVolatile);
2129 return cast<StoreInst>(P)->setVolatile(isVolatile);
2132 /*--.. Casts ...............................................................--*/
2134 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2135 LLVMTypeRef DestTy, const char *Name) {
2136 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2139 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2140 LLVMTypeRef DestTy, const char *Name) {
2141 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2144 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2145 LLVMTypeRef DestTy, const char *Name) {
2146 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2149 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2150 LLVMTypeRef DestTy, const char *Name) {
2151 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2154 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2155 LLVMTypeRef DestTy, const char *Name) {
2156 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2159 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2160 LLVMTypeRef DestTy, const char *Name) {
2161 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2164 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2165 LLVMTypeRef DestTy, const char *Name) {
2166 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2169 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2170 LLVMTypeRef DestTy, const char *Name) {
2171 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2174 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2175 LLVMTypeRef DestTy, const char *Name) {
2176 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2179 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2180 LLVMTypeRef DestTy, const char *Name) {
2181 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2184 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2185 LLVMTypeRef DestTy, const char *Name) {
2186 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2189 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2190 LLVMTypeRef DestTy, const char *Name) {
2191 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2194 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2195 LLVMTypeRef DestTy, const char *Name) {
2196 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2200 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2201 LLVMTypeRef DestTy, const char *Name) {
2202 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2206 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2207 LLVMTypeRef DestTy, const char *Name) {
2208 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2212 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2213 LLVMTypeRef DestTy, const char *Name) {
2214 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2215 unwrap(DestTy), Name));
2218 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2219 LLVMTypeRef DestTy, const char *Name) {
2220 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2223 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2224 LLVMTypeRef DestTy, const char *Name) {
2225 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2226 /*isSigned*/true, Name));
2229 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2230 LLVMTypeRef DestTy, const char *Name) {
2231 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2234 /*--.. Comparisons .........................................................--*/
2236 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2237 LLVMValueRef LHS, LLVMValueRef RHS,
2239 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2240 unwrap(LHS), unwrap(RHS), Name));
2243 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2244 LLVMValueRef LHS, LLVMValueRef RHS,
2246 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2247 unwrap(LHS), unwrap(RHS), Name));
2250 /*--.. Miscellaneous instructions ..........................................--*/
2252 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2253 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2256 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2257 LLVMValueRef *Args, unsigned NumArgs,
2259 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2260 makeArrayRef(unwrap(Args), NumArgs),
2264 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2265 LLVMValueRef Then, LLVMValueRef Else,
2267 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2271 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2272 LLVMTypeRef Ty, const char *Name) {
2273 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2276 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2277 LLVMValueRef Index, const char *Name) {
2278 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2282 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2283 LLVMValueRef EltVal, LLVMValueRef Index,
2285 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2286 unwrap(Index), Name));
2289 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2290 LLVMValueRef V2, LLVMValueRef Mask,
2292 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2293 unwrap(Mask), Name));
2296 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2297 unsigned Index, const char *Name) {
2298 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2301 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2302 LLVMValueRef EltVal, unsigned Index,
2304 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2308 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2310 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2313 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2315 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2318 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2319 LLVMValueRef RHS, const char *Name) {
2320 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2324 /*===-- Module providers --------------------------------------------------===*/
2326 LLVMModuleProviderRef
2327 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2328 return reinterpret_cast<LLVMModuleProviderRef>(M);
2331 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2336 /*===-- Memory buffers ----------------------------------------------------===*/
2338 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2340 LLVMMemoryBufferRef *OutMemBuf,
2341 char **OutMessage) {
2343 OwningPtr<MemoryBuffer> MB;
2345 if (!(ec = MemoryBuffer::getFile(Path, MB))) {
2346 *OutMemBuf = wrap(MB.take());
2350 *OutMessage = strdup(ec.message().c_str());
2354 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2355 char **OutMessage) {
2356 OwningPtr<MemoryBuffer> MB;
2358 if (!(ec = MemoryBuffer::getSTDIN(MB))) {
2359 *OutMemBuf = wrap(MB.take());
2363 *OutMessage = strdup(ec.message().c_str());
2367 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2368 delete unwrap(MemBuf);
2371 /*===-- Pass Registry -----------------------------------------------------===*/
2373 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2374 return wrap(PassRegistry::getPassRegistry());
2377 /*===-- Pass Manager ------------------------------------------------------===*/
2379 LLVMPassManagerRef LLVMCreatePassManager() {
2380 return wrap(new PassManager());
2383 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2384 return wrap(new FunctionPassManager(unwrap(M)));
2387 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2388 return LLVMCreateFunctionPassManagerForModule(
2389 reinterpret_cast<LLVMModuleRef>(P));
2392 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2393 return unwrap<PassManager>(PM)->run(*unwrap(M));
2396 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2397 return unwrap<FunctionPassManager>(FPM)->doInitialization();
2400 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2401 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2404 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2405 return unwrap<FunctionPassManager>(FPM)->doFinalization();
2408 void LLVMDisposePassManager(LLVMPassManagerRef PM) {