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 C bindings for libLLVMCore.a, which implements
11 // the LLVM intermediate representation.
13 //===----------------------------------------------------------------------===//
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/GlobalAlias.h"
21 #include "llvm/LLVMContext.h"
22 #include "llvm/TypeSymbolTable.h"
23 #include "llvm/ModuleProvider.h"
24 #include "llvm/InlineAsm.h"
25 #include "llvm/IntrinsicInst.h"
26 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/CallSite.h"
28 #include "llvm/Support/ErrorHandling.h"
36 /*===-- Error handling ----------------------------------------------------===*/
38 void LLVMDisposeMessage(char *Message) {
43 /*===-- Operations on contexts --------------------------------------------===*/
45 LLVMContextRef LLVMContextCreate() {
46 return wrap(new LLVMContext());
49 LLVMContextRef LLVMGetGlobalContext() {
50 return wrap(&getGlobalContext());
53 void LLVMContextDispose(LLVMContextRef C) {
58 /*===-- Operations on modules ---------------------------------------------===*/
60 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
61 return wrap(new Module(ModuleID, getGlobalContext()));
64 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
66 return wrap(new Module(ModuleID, *unwrap(C)));
69 void LLVMDisposeModule(LLVMModuleRef M) {
73 /*--.. Data layout .........................................................--*/
74 const char * LLVMGetDataLayout(LLVMModuleRef M) {
75 return unwrap(M)->getDataLayout().c_str();
78 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
79 unwrap(M)->setDataLayout(Triple);
82 /*--.. Target triple .......................................................--*/
83 const char * LLVMGetTarget(LLVMModuleRef M) {
84 return unwrap(M)->getTargetTriple().c_str();
87 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
88 unwrap(M)->setTargetTriple(Triple);
91 /*--.. Type names ..........................................................--*/
92 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) {
93 return unwrap(M)->addTypeName(Name, unwrap(Ty));
96 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name) {
97 TypeSymbolTable &TST = unwrap(M)->getTypeSymbolTable();
99 TypeSymbolTable::iterator I = TST.find(Name);
104 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
105 return wrap(unwrap(M)->getTypeByName(Name));
108 void LLVMDumpModule(LLVMModuleRef M) {
113 /*===-- Operations on types -----------------------------------------------===*/
115 /*--.. Operations on all types (mostly) ....................................--*/
117 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
118 switch (unwrap(Ty)->getTypeID()) {
120 assert(false && "Unhandled TypeID.");
122 return LLVMVoidTypeKind;
123 case Type::FloatTyID:
124 return LLVMFloatTypeKind;
125 case Type::DoubleTyID:
126 return LLVMDoubleTypeKind;
127 case Type::X86_FP80TyID:
128 return LLVMX86_FP80TypeKind;
129 case Type::FP128TyID:
130 return LLVMFP128TypeKind;
131 case Type::PPC_FP128TyID:
132 return LLVMPPC_FP128TypeKind;
133 case Type::LabelTyID:
134 return LLVMLabelTypeKind;
135 case Type::MetadataTyID:
136 return LLVMMetadataTypeKind;
137 case Type::IntegerTyID:
138 return LLVMIntegerTypeKind;
139 case Type::FunctionTyID:
140 return LLVMFunctionTypeKind;
141 case Type::StructTyID:
142 return LLVMStructTypeKind;
143 case Type::ArrayTyID:
144 return LLVMArrayTypeKind;
145 case Type::PointerTyID:
146 return LLVMPointerTypeKind;
147 case Type::OpaqueTyID:
148 return LLVMOpaqueTypeKind;
149 case Type::VectorTyID:
150 return LLVMVectorTypeKind;
154 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
155 return wrap(&unwrap(Ty)->getContext());
158 /*--.. Operations on integer types .........................................--*/
160 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
161 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
163 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
164 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
166 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
167 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
169 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
170 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
172 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
173 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
175 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
176 return wrap(IntegerType::get(*unwrap(C), NumBits));
179 LLVMTypeRef LLVMInt1Type(void) {
180 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
182 LLVMTypeRef LLVMInt8Type(void) {
183 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
185 LLVMTypeRef LLVMInt16Type(void) {
186 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
188 LLVMTypeRef LLVMInt32Type(void) {
189 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
191 LLVMTypeRef LLVMInt64Type(void) {
192 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
194 LLVMTypeRef LLVMIntType(unsigned NumBits) {
195 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
198 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
199 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
202 /*--.. Operations on real types ............................................--*/
204 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
205 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
207 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
208 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
210 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
211 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
213 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
214 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
216 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
217 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
220 LLVMTypeRef LLVMFloatType(void) {
221 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
223 LLVMTypeRef LLVMDoubleType(void) {
224 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
226 LLVMTypeRef LLVMX86FP80Type(void) {
227 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
229 LLVMTypeRef LLVMFP128Type(void) {
230 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
232 LLVMTypeRef LLVMPPCFP128Type(void) {
233 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
236 /*--.. Operations on function types ........................................--*/
238 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
239 LLVMTypeRef *ParamTypes, unsigned ParamCount,
241 std::vector<const Type*> Tys;
242 for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I)
243 Tys.push_back(unwrap(*I));
245 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
248 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
249 return unwrap<FunctionType>(FunctionTy)->isVarArg();
252 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
253 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
256 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
257 return unwrap<FunctionType>(FunctionTy)->getNumParams();
260 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
261 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
262 for (FunctionType::param_iterator I = Ty->param_begin(),
263 E = Ty->param_end(); I != E; ++I)
267 /*--.. Operations on struct types ..........................................--*/
269 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
270 unsigned ElementCount, int Packed) {
271 std::vector<const Type*> Tys;
272 for (LLVMTypeRef *I = ElementTypes,
273 *E = ElementTypes + ElementCount; I != E; ++I)
274 Tys.push_back(unwrap(*I));
276 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
279 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
280 unsigned ElementCount, int Packed) {
281 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
282 ElementCount, Packed);
286 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
287 return unwrap<StructType>(StructTy)->getNumElements();
290 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
291 StructType *Ty = unwrap<StructType>(StructTy);
292 for (FunctionType::param_iterator I = Ty->element_begin(),
293 E = Ty->element_end(); I != E; ++I)
297 int LLVMIsPackedStruct(LLVMTypeRef StructTy) {
298 return unwrap<StructType>(StructTy)->isPacked();
301 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
303 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
304 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
307 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
308 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
311 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
312 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
315 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
316 return wrap(unwrap<SequentialType>(Ty)->getElementType());
319 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
320 return unwrap<ArrayType>(ArrayTy)->getNumElements();
323 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
324 return unwrap<PointerType>(PointerTy)->getAddressSpace();
327 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
328 return unwrap<VectorType>(VectorTy)->getNumElements();
331 /*--.. Operations on other types ...........................................--*/
333 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
334 return wrap(Type::getVoidTy(*unwrap(C)));
336 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
337 return wrap(Type::getLabelTy(*unwrap(C)));
339 LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C) {
340 return wrap(OpaqueType::get(*unwrap(C)));
343 LLVMTypeRef LLVMVoidType(void) {
344 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
346 LLVMTypeRef LLVMLabelType(void) {
347 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
349 LLVMTypeRef LLVMOpaqueType(void) {
350 return LLVMOpaqueTypeInContext(LLVMGetGlobalContext());
353 /*--.. Operations on type handles ..........................................--*/
355 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy) {
356 return wrap(new PATypeHolder(unwrap(PotentiallyAbstractTy)));
359 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle) {
360 delete unwrap(TypeHandle);
363 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle) {
364 return wrap(unwrap(TypeHandle)->get());
367 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy) {
368 unwrap<DerivedType>(AbstractTy)->refineAbstractTypeTo(unwrap(ConcreteTy));
372 /*===-- Operations on values ----------------------------------------------===*/
374 /*--.. Operations on all values ............................................--*/
376 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
377 return wrap(unwrap(Val)->getType());
380 const char *LLVMGetValueName(LLVMValueRef Val) {
381 return unwrap(Val)->getName().data();
384 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
385 unwrap(Val)->setName(Name);
388 void LLVMDumpValue(LLVMValueRef Val) {
393 /*--.. Conversion functions ................................................--*/
395 #define LLVM_DEFINE_VALUE_CAST(name) \
396 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
397 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
400 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
403 /*--.. Operations on constants of any type .................................--*/
405 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
406 return wrap(Constant::getNullValue(unwrap(Ty)));
409 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
410 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
413 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
414 return wrap(UndefValue::get(unwrap(Ty)));
417 int LLVMIsConstant(LLVMValueRef Ty) {
418 return isa<Constant>(unwrap(Ty));
421 int LLVMIsNull(LLVMValueRef Val) {
422 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
423 return C->isNullValue();
427 int LLVMIsUndef(LLVMValueRef Val) {
428 return isa<UndefValue>(unwrap(Val));
431 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
433 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
436 /*--.. Operations on scalar constants ......................................--*/
438 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
440 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
443 static const fltSemantics &SemanticsForType(Type *Ty) {
444 assert(Ty->isFloatingPoint() && "Type is not floating point!");
445 if (Ty == Type::getFloatTy(Ty->getContext()))
446 return APFloat::IEEEsingle;
447 if (Ty == Type::getDoubleTy(Ty->getContext()))
448 return APFloat::IEEEdouble;
449 if (Ty == Type::getX86_FP80Ty(Ty->getContext()))
450 return APFloat::x87DoubleExtended;
451 if (Ty == Type::getFP128Ty(Ty->getContext()))
452 return APFloat::IEEEquad;
453 if (Ty == Type::getPPC_FP128Ty(Ty->getContext()))
454 return APFloat::PPCDoubleDouble;
455 return APFloat::Bogus;
458 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
461 APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven,
463 return wrap(ConstantFP::get(getGlobalContext(), APN));
466 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
467 return wrap(ConstantFP::get(getGlobalContext(),
468 APFloat(SemanticsForType(unwrap(RealTy)), Text)));
471 /*--.. Operations on composite constants ...................................--*/
473 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
474 unsigned Length, int DontNullTerminate) {
475 /* Inverted the sense of AddNull because ', 0)' is a
476 better mnemonic for null termination than ', 1)'. */
477 return wrap(ConstantArray::get(*unwrap(C), std::string(Str, Length),
478 DontNullTerminate == 0));
480 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
481 LLVMValueRef *ConstantVals,
482 unsigned Count, int Packed) {
483 return wrap(ConstantStruct::get(*unwrap(C),
484 unwrap<Constant>(ConstantVals, Count),
485 Count, Packed != 0));
488 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
489 int DontNullTerminate) {
490 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
493 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
494 LLVMValueRef *ConstantVals, unsigned Length) {
495 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length),
496 unwrap<Constant>(ConstantVals, Length),
499 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
501 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
505 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
506 return wrap(ConstantVector::get(
507 unwrap<Constant>(ScalarConstantVals, Size), Size));
510 /*--.. Constant expressions ................................................--*/
512 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
513 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
516 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
517 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
520 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
521 return wrap(ConstantExpr::getNeg(
522 unwrap<Constant>(ConstantVal)));
525 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
526 return wrap(ConstantExpr::getNot(
527 unwrap<Constant>(ConstantVal)));
530 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
531 return wrap(ConstantExpr::getAdd(
532 unwrap<Constant>(LHSConstant),
533 unwrap<Constant>(RHSConstant)));
536 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
537 return wrap(ConstantExpr::getSub(
538 unwrap<Constant>(LHSConstant),
539 unwrap<Constant>(RHSConstant)));
542 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
543 return wrap(ConstantExpr::getMul(
544 unwrap<Constant>(LHSConstant),
545 unwrap<Constant>(RHSConstant)));
548 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
549 return wrap(ConstantExpr::getUDiv(
550 unwrap<Constant>(LHSConstant),
551 unwrap<Constant>(RHSConstant)));
554 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
555 return wrap(ConstantExpr::getSDiv(
556 unwrap<Constant>(LHSConstant),
557 unwrap<Constant>(RHSConstant)));
560 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
561 return wrap(ConstantExpr::getFDiv(
562 unwrap<Constant>(LHSConstant),
563 unwrap<Constant>(RHSConstant)));
566 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
567 return wrap(ConstantExpr::getURem(
568 unwrap<Constant>(LHSConstant),
569 unwrap<Constant>(RHSConstant)));
572 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
573 return wrap(ConstantExpr::getSRem(
574 unwrap<Constant>(LHSConstant),
575 unwrap<Constant>(RHSConstant)));
578 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
579 return wrap(ConstantExpr::getFRem(
580 unwrap<Constant>(LHSConstant),
581 unwrap<Constant>(RHSConstant)));
584 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
585 return wrap(ConstantExpr::getAnd(
586 unwrap<Constant>(LHSConstant),
587 unwrap<Constant>(RHSConstant)));
590 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
591 return wrap(ConstantExpr::getOr(
592 unwrap<Constant>(LHSConstant),
593 unwrap<Constant>(RHSConstant)));
596 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
597 return wrap(ConstantExpr::getXor(
598 unwrap<Constant>(LHSConstant),
599 unwrap<Constant>(RHSConstant)));
602 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
603 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
604 return wrap(ConstantExpr::getICmp(Predicate,
605 unwrap<Constant>(LHSConstant),
606 unwrap<Constant>(RHSConstant)));
609 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
610 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
611 return wrap(ConstantExpr::getFCmp(Predicate,
612 unwrap<Constant>(LHSConstant),
613 unwrap<Constant>(RHSConstant)));
616 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
617 return wrap(ConstantExpr::getShl(
618 unwrap<Constant>(LHSConstant),
619 unwrap<Constant>(RHSConstant)));
622 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
623 return wrap(ConstantExpr::getLShr(
624 unwrap<Constant>(LHSConstant),
625 unwrap<Constant>(RHSConstant)));
628 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
629 return wrap(ConstantExpr::getAShr(
630 unwrap<Constant>(LHSConstant),
631 unwrap<Constant>(RHSConstant)));
634 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
635 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
636 return wrap(ConstantExpr::getGetElementPtr(
637 unwrap<Constant>(ConstantVal),
638 unwrap<Constant>(ConstantIndices,
643 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
644 return wrap(ConstantExpr::getTrunc(
645 unwrap<Constant>(ConstantVal),
649 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
650 return wrap(ConstantExpr::getSExt(
651 unwrap<Constant>(ConstantVal),
655 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
656 return wrap(ConstantExpr::getZExt(
657 unwrap<Constant>(ConstantVal),
661 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
662 return wrap(ConstantExpr::getFPTrunc(
663 unwrap<Constant>(ConstantVal),
667 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
668 return wrap(ConstantExpr::getFPExtend(
669 unwrap<Constant>(ConstantVal),
673 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
674 return wrap(ConstantExpr::getUIToFP(
675 unwrap<Constant>(ConstantVal),
679 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
680 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
684 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
685 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
689 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
690 return wrap(ConstantExpr::getFPToSI(
691 unwrap<Constant>(ConstantVal),
695 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
696 return wrap(ConstantExpr::getPtrToInt(
697 unwrap<Constant>(ConstantVal),
701 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
702 return wrap(ConstantExpr::getIntToPtr(
703 unwrap<Constant>(ConstantVal),
707 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
708 return wrap(ConstantExpr::getBitCast(
709 unwrap<Constant>(ConstantVal),
713 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
714 LLVMValueRef ConstantIfTrue,
715 LLVMValueRef ConstantIfFalse) {
716 return wrap(ConstantExpr::getSelect(
717 unwrap<Constant>(ConstantCondition),
718 unwrap<Constant>(ConstantIfTrue),
719 unwrap<Constant>(ConstantIfFalse)));
722 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
723 LLVMValueRef IndexConstant) {
724 return wrap(ConstantExpr::getExtractElement(
725 unwrap<Constant>(VectorConstant),
726 unwrap<Constant>(IndexConstant)));
729 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
730 LLVMValueRef ElementValueConstant,
731 LLVMValueRef IndexConstant) {
732 return wrap(ConstantExpr::getInsertElement(
733 unwrap<Constant>(VectorConstant),
734 unwrap<Constant>(ElementValueConstant),
735 unwrap<Constant>(IndexConstant)));
738 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
739 LLVMValueRef VectorBConstant,
740 LLVMValueRef MaskConstant) {
741 return wrap(ConstantExpr::getShuffleVector(
742 unwrap<Constant>(VectorAConstant),
743 unwrap<Constant>(VectorBConstant),
744 unwrap<Constant>(MaskConstant)));
747 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
749 return wrap(ConstantExpr::getExtractValue(
750 unwrap<Constant>(AggConstant),
754 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
755 LLVMValueRef ElementValueConstant,
756 unsigned *IdxList, unsigned NumIdx) {
757 return wrap(ConstantExpr::getInsertValue(
758 unwrap<Constant>(AggConstant),
759 unwrap<Constant>(ElementValueConstant),
763 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
764 const char *Constraints, int HasSideEffects) {
765 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
766 Constraints, HasSideEffects));
769 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
771 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
772 return wrap(unwrap<GlobalValue>(Global)->getParent());
775 int LLVMIsDeclaration(LLVMValueRef Global) {
776 return unwrap<GlobalValue>(Global)->isDeclaration();
779 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
780 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
782 assert(false && "Unhandled Linkage Type.");
783 case GlobalValue::ExternalLinkage:
784 return LLVMExternalLinkage;
785 case GlobalValue::AvailableExternallyLinkage:
786 return LLVMAvailableExternallyLinkage;
787 case GlobalValue::LinkOnceAnyLinkage:
788 return LLVMLinkOnceAnyLinkage;
789 case GlobalValue::LinkOnceODRLinkage:
790 return LLVMLinkOnceODRLinkage;
791 case GlobalValue::WeakAnyLinkage:
792 return LLVMWeakAnyLinkage;
793 case GlobalValue::WeakODRLinkage:
794 return LLVMWeakODRLinkage;
795 case GlobalValue::AppendingLinkage:
796 return LLVMAppendingLinkage;
797 case GlobalValue::InternalLinkage:
798 return LLVMInternalLinkage;
799 case GlobalValue::PrivateLinkage:
800 return LLVMPrivateLinkage;
801 case GlobalValue::LinkerPrivateLinkage:
802 return LLVMLinkerPrivateLinkage;
803 case GlobalValue::DLLImportLinkage:
804 return LLVMDLLImportLinkage;
805 case GlobalValue::DLLExportLinkage:
806 return LLVMDLLExportLinkage;
807 case GlobalValue::ExternalWeakLinkage:
808 return LLVMExternalWeakLinkage;
809 case GlobalValue::GhostLinkage:
810 return LLVMGhostLinkage;
811 case GlobalValue::CommonLinkage:
812 return LLVMCommonLinkage;
815 // Should never get here.
816 return static_cast<LLVMLinkage>(0);
819 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
820 GlobalValue *GV = unwrap<GlobalValue>(Global);
824 assert(false && "Unhandled Linkage Type.");
825 case LLVMExternalLinkage:
826 GV->setLinkage(GlobalValue::ExternalLinkage);
828 case LLVMAvailableExternallyLinkage:
829 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
831 case LLVMLinkOnceAnyLinkage:
832 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
834 case LLVMLinkOnceODRLinkage:
835 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
837 case LLVMWeakAnyLinkage:
838 GV->setLinkage(GlobalValue::WeakAnyLinkage);
840 case LLVMWeakODRLinkage:
841 GV->setLinkage(GlobalValue::WeakODRLinkage);
843 case LLVMAppendingLinkage:
844 GV->setLinkage(GlobalValue::AppendingLinkage);
846 case LLVMInternalLinkage:
847 GV->setLinkage(GlobalValue::InternalLinkage);
849 case LLVMPrivateLinkage:
850 GV->setLinkage(GlobalValue::PrivateLinkage);
852 case LLVMLinkerPrivateLinkage:
853 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
855 case LLVMDLLImportLinkage:
856 GV->setLinkage(GlobalValue::DLLImportLinkage);
858 case LLVMDLLExportLinkage:
859 GV->setLinkage(GlobalValue::DLLExportLinkage);
861 case LLVMExternalWeakLinkage:
862 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
864 case LLVMGhostLinkage:
865 GV->setLinkage(GlobalValue::GhostLinkage);
867 case LLVMCommonLinkage:
868 GV->setLinkage(GlobalValue::CommonLinkage);
873 const char *LLVMGetSection(LLVMValueRef Global) {
874 return unwrap<GlobalValue>(Global)->getSection().c_str();
877 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
878 unwrap<GlobalValue>(Global)->setSection(Section);
881 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
882 return static_cast<LLVMVisibility>(
883 unwrap<GlobalValue>(Global)->getVisibility());
886 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
887 unwrap<GlobalValue>(Global)
888 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
891 unsigned LLVMGetAlignment(LLVMValueRef Global) {
892 return unwrap<GlobalValue>(Global)->getAlignment();
895 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
896 unwrap<GlobalValue>(Global)->setAlignment(Bytes);
899 /*--.. Operations on global variables ......................................--*/
901 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
902 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
903 GlobalValue::ExternalLinkage, 0, Name));
906 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
907 return wrap(unwrap(M)->getNamedGlobal(Name));
910 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
911 Module *Mod = unwrap(M);
912 Module::global_iterator I = Mod->global_begin();
913 if (I == Mod->global_end())
918 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
919 Module *Mod = unwrap(M);
920 Module::global_iterator I = Mod->global_end();
921 if (I == Mod->global_begin())
926 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
927 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
928 Module::global_iterator I = GV;
929 if (++I == GV->getParent()->global_end())
934 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
935 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
936 Module::global_iterator I = GV;
937 if (I == GV->getParent()->global_begin())
942 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
943 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
946 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
947 return wrap(unwrap<GlobalVariable>(GlobalVar)->getInitializer());
950 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
951 unwrap<GlobalVariable>(GlobalVar)
952 ->setInitializer(unwrap<Constant>(ConstantVal));
955 int LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
956 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
959 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) {
960 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
963 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
964 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
967 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
968 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
971 /*--.. Operations on aliases ......................................--*/
973 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
975 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
976 unwrap<Constant>(Aliasee), unwrap (M)));
979 /*--.. Operations on functions .............................................--*/
981 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
982 LLVMTypeRef FunctionTy) {
983 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
984 GlobalValue::ExternalLinkage, Name, unwrap(M)));
987 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
988 return wrap(unwrap(M)->getFunction(Name));
991 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
992 Module *Mod = unwrap(M);
993 Module::iterator I = Mod->begin();
999 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1000 Module *Mod = unwrap(M);
1001 Module::iterator I = Mod->end();
1002 if (I == Mod->begin())
1007 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1008 Function *Func = unwrap<Function>(Fn);
1009 Module::iterator I = Func;
1010 if (++I == Func->getParent()->end())
1015 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1016 Function *Func = unwrap<Function>(Fn);
1017 Module::iterator I = Func;
1018 if (I == Func->getParent()->begin())
1023 void LLVMDeleteFunction(LLVMValueRef Fn) {
1024 unwrap<Function>(Fn)->eraseFromParent();
1027 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1028 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1029 return F->getIntrinsicID();
1033 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1034 return unwrap<Function>(Fn)->getCallingConv();
1037 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1038 return unwrap<Function>(Fn)->setCallingConv(CC);
1041 const char *LLVMGetGC(LLVMValueRef Fn) {
1042 Function *F = unwrap<Function>(Fn);
1043 return F->hasGC()? F->getGC() : 0;
1046 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1047 Function *F = unwrap<Function>(Fn);
1054 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1055 Function *Func = unwrap<Function>(Fn);
1056 const AttrListPtr PAL = Func->getAttributes();
1057 const AttrListPtr PALnew = PAL.addAttr(0, PA);
1058 Func->setAttributes(PALnew);
1061 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1062 Function *Func = unwrap<Function>(Fn);
1063 const AttrListPtr PAL = Func->getAttributes();
1064 const AttrListPtr PALnew = PAL.removeAttr(0, PA);
1065 Func->setAttributes(PALnew);
1068 /*--.. Operations on parameters ............................................--*/
1070 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1071 // This function is strictly redundant to
1072 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1073 return unwrap<Function>(FnRef)->arg_size();
1076 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1077 Function *Fn = unwrap<Function>(FnRef);
1078 for (Function::arg_iterator I = Fn->arg_begin(),
1079 E = Fn->arg_end(); I != E; I++)
1080 *ParamRefs++ = wrap(I);
1083 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1084 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1090 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1091 return wrap(unwrap<Argument>(V)->getParent());
1094 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1095 Function *Func = unwrap<Function>(Fn);
1096 Function::arg_iterator I = Func->arg_begin();
1097 if (I == Func->arg_end())
1102 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1103 Function *Func = unwrap<Function>(Fn);
1104 Function::arg_iterator I = Func->arg_end();
1105 if (I == Func->arg_begin())
1110 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1111 Argument *A = unwrap<Argument>(Arg);
1112 Function::arg_iterator I = A;
1113 if (++I == A->getParent()->arg_end())
1118 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1119 Argument *A = unwrap<Argument>(Arg);
1120 Function::arg_iterator I = A;
1121 if (I == A->getParent()->arg_begin())
1126 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1127 unwrap<Argument>(Arg)->addAttr(PA);
1130 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1131 unwrap<Argument>(Arg)->removeAttr(PA);
1134 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1135 unwrap<Argument>(Arg)->addAttr(
1136 Attribute::constructAlignmentFromInt(align));
1139 /*--.. Operations on basic blocks ..........................................--*/
1141 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1142 return wrap(static_cast<Value*>(unwrap(BB)));
1145 int LLVMValueIsBasicBlock(LLVMValueRef Val) {
1146 return isa<BasicBlock>(unwrap(Val));
1149 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1150 return wrap(unwrap<BasicBlock>(Val));
1153 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1154 return wrap(unwrap(BB)->getParent());
1157 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1158 return unwrap<Function>(FnRef)->size();
1161 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1162 Function *Fn = unwrap<Function>(FnRef);
1163 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1164 *BasicBlocksRefs++ = wrap(I);
1167 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1168 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1171 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1172 Function *Func = unwrap<Function>(Fn);
1173 Function::iterator I = Func->begin();
1174 if (I == Func->end())
1179 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1180 Function *Func = unwrap<Function>(Fn);
1181 Function::iterator I = Func->end();
1182 if (I == Func->begin())
1187 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1188 BasicBlock *Block = unwrap(BB);
1189 Function::iterator I = Block;
1190 if (++I == Block->getParent()->end())
1195 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1196 BasicBlock *Block = unwrap(BB);
1197 Function::iterator I = Block;
1198 if (I == Block->getParent()->begin())
1203 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1206 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1209 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1210 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1213 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1214 LLVMBasicBlockRef BBRef,
1216 BasicBlock *BB = unwrap(BBRef);
1217 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1220 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1222 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1225 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1226 unwrap(BBRef)->eraseFromParent();
1229 /*--.. Operations on instructions ..........................................--*/
1231 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1232 return wrap(unwrap<Instruction>(Inst)->getParent());
1235 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1236 BasicBlock *Block = unwrap(BB);
1237 BasicBlock::iterator I = Block->begin();
1238 if (I == Block->end())
1243 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1244 BasicBlock *Block = unwrap(BB);
1245 BasicBlock::iterator I = Block->end();
1246 if (I == Block->begin())
1251 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1252 Instruction *Instr = unwrap<Instruction>(Inst);
1253 BasicBlock::iterator I = Instr;
1254 if (++I == Instr->getParent()->end())
1259 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1260 Instruction *Instr = unwrap<Instruction>(Inst);
1261 BasicBlock::iterator I = Instr;
1262 if (I == Instr->getParent()->begin())
1267 /*--.. Call and invoke instructions ........................................--*/
1269 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
1270 Value *V = unwrap(Instr);
1271 if (CallInst *CI = dyn_cast<CallInst>(V))
1272 return CI->getCallingConv();
1273 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1274 return II->getCallingConv();
1275 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1279 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
1280 Value *V = unwrap(Instr);
1281 if (CallInst *CI = dyn_cast<CallInst>(V))
1282 return CI->setCallingConv(CC);
1283 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1284 return II->setCallingConv(CC);
1285 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1288 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
1290 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1292 Call.getAttributes().addAttr(index, PA));
1295 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
1297 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1299 Call.getAttributes().removeAttr(index, PA));
1302 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
1304 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1306 Call.getAttributes().addAttr(index,
1307 Attribute::constructAlignmentFromInt(align)));
1310 /*--.. Operations on call instructions (only) ..............................--*/
1312 int LLVMIsTailCall(LLVMValueRef Call) {
1313 return unwrap<CallInst>(Call)->isTailCall();
1316 void LLVMSetTailCall(LLVMValueRef Call, int isTailCall) {
1317 unwrap<CallInst>(Call)->setTailCall(isTailCall);
1320 /*--.. Operations on phi nodes .............................................--*/
1322 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
1323 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
1324 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
1325 for (unsigned I = 0; I != Count; ++I)
1326 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
1329 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
1330 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
1333 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
1334 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
1337 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
1338 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
1342 /*===-- Instruction builders ----------------------------------------------===*/
1344 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
1345 return wrap(new IRBuilder<>(*unwrap(C)));
1348 LLVMBuilderRef LLVMCreateBuilder(void) {
1349 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1352 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
1353 LLVMValueRef Instr) {
1354 BasicBlock *BB = unwrap(Block);
1355 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
1356 unwrap(Builder)->SetInsertPoint(BB, I);
1359 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1360 Instruction *I = unwrap<Instruction>(Instr);
1361 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
1364 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
1365 BasicBlock *BB = unwrap(Block);
1366 unwrap(Builder)->SetInsertPoint(BB);
1369 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
1370 return wrap(unwrap(Builder)->GetInsertBlock());
1373 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
1374 unwrap(Builder)->ClearInsertionPoint ();
1377 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1378 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
1381 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
1382 delete unwrap(Builder);
1385 /*--.. Instruction builders ................................................--*/
1387 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
1388 return wrap(unwrap(B)->CreateRetVoid());
1391 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
1392 return wrap(unwrap(B)->CreateRet(unwrap(V)));
1395 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
1397 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
1400 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
1401 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
1404 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
1405 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
1406 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
1409 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
1410 LLVMBasicBlockRef Else, unsigned NumCases) {
1411 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
1414 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
1415 LLVMValueRef *Args, unsigned NumArgs,
1416 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
1418 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
1419 unwrap(Args), unwrap(Args) + NumArgs,
1423 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) {
1424 return wrap(unwrap(B)->CreateUnwind());
1427 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
1428 return wrap(unwrap(B)->CreateUnreachable());
1431 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
1432 LLVMBasicBlockRef Dest) {
1433 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
1436 /*--.. Arithmetic ..........................................................--*/
1438 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1440 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
1443 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1445 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
1448 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1450 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
1453 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1455 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
1458 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1460 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
1463 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1465 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
1468 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1470 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
1473 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1475 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
1478 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1480 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
1483 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
1484 LLVMValueRef RHS, const char *Name) {
1485 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
1488 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1490 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
1493 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1495 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
1498 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1500 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
1503 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1505 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
1508 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1510 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
1513 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1515 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
1518 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1520 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
1523 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1525 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
1528 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1530 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
1533 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1535 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
1538 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1539 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
1542 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1543 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
1546 /*--.. Memory ..............................................................--*/
1548 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
1550 return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name));
1553 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
1554 LLVMValueRef Val, const char *Name) {
1555 return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name));
1558 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
1560 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
1563 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
1564 LLVMValueRef Val, const char *Name) {
1565 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
1568 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
1569 return wrap(unwrap(B)->CreateFree(unwrap(PointerVal)));
1573 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
1575 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
1578 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
1579 LLVMValueRef PointerVal) {
1580 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
1583 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
1584 LLVMValueRef *Indices, unsigned NumIndices,
1586 return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), unwrap(Indices),
1587 unwrap(Indices) + NumIndices, Name));
1590 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
1591 LLVMValueRef *Indices, unsigned NumIndices,
1593 return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), unwrap(Indices),
1594 unwrap(Indices) + NumIndices, Name));
1597 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
1598 unsigned Idx, const char *Name) {
1599 return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name));
1602 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
1604 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
1607 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
1609 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
1612 /*--.. Casts ...............................................................--*/
1614 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
1615 LLVMTypeRef DestTy, const char *Name) {
1616 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
1619 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
1620 LLVMTypeRef DestTy, const char *Name) {
1621 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
1624 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
1625 LLVMTypeRef DestTy, const char *Name) {
1626 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
1629 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
1630 LLVMTypeRef DestTy, const char *Name) {
1631 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
1634 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
1635 LLVMTypeRef DestTy, const char *Name) {
1636 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
1639 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
1640 LLVMTypeRef DestTy, const char *Name) {
1641 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
1644 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
1645 LLVMTypeRef DestTy, const char *Name) {
1646 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
1649 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
1650 LLVMTypeRef DestTy, const char *Name) {
1651 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
1654 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
1655 LLVMTypeRef DestTy, const char *Name) {
1656 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
1659 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
1660 LLVMTypeRef DestTy, const char *Name) {
1661 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
1664 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
1665 LLVMTypeRef DestTy, const char *Name) {
1666 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
1669 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
1670 LLVMTypeRef DestTy, const char *Name) {
1671 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
1674 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
1675 LLVMTypeRef DestTy, const char *Name) {
1676 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
1680 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
1681 LLVMTypeRef DestTy, const char *Name) {
1682 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
1686 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
1687 LLVMTypeRef DestTy, const char *Name) {
1688 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
1692 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
1693 LLVMTypeRef DestTy, const char *Name) {
1694 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
1697 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
1698 LLVMTypeRef DestTy, const char *Name) {
1699 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), Name));
1702 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
1703 LLVMTypeRef DestTy, const char *Name) {
1704 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
1707 /*--.. Comparisons .........................................................--*/
1709 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
1710 LLVMValueRef LHS, LLVMValueRef RHS,
1712 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
1713 unwrap(LHS), unwrap(RHS), Name));
1716 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
1717 LLVMValueRef LHS, LLVMValueRef RHS,
1719 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
1720 unwrap(LHS), unwrap(RHS), Name));
1723 /*--.. Miscellaneous instructions ..........................................--*/
1725 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
1726 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name));
1729 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
1730 LLVMValueRef *Args, unsigned NumArgs,
1732 return wrap(unwrap(B)->CreateCall(unwrap(Fn), unwrap(Args),
1733 unwrap(Args) + NumArgs, Name));
1736 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
1737 LLVMValueRef Then, LLVMValueRef Else,
1739 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
1743 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
1744 LLVMTypeRef Ty, const char *Name) {
1745 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
1748 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
1749 LLVMValueRef Index, const char *Name) {
1750 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
1754 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
1755 LLVMValueRef EltVal, LLVMValueRef Index,
1757 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
1758 unwrap(Index), Name));
1761 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
1762 LLVMValueRef V2, LLVMValueRef Mask,
1764 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
1765 unwrap(Mask), Name));
1768 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
1769 unsigned Index, const char *Name) {
1770 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
1773 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
1774 LLVMValueRef EltVal, unsigned Index,
1776 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
1780 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
1782 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
1785 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
1787 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
1790 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
1791 LLVMValueRef RHS, const char *Name) {
1792 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
1796 /*===-- Module providers --------------------------------------------------===*/
1798 LLVMModuleProviderRef
1799 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
1800 return wrap(new ExistingModuleProvider(unwrap(M)));
1803 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
1808 /*===-- Memory buffers ----------------------------------------------------===*/
1810 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
1811 LLVMMemoryBufferRef *OutMemBuf,
1812 char **OutMessage) {
1814 if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) {
1815 *OutMemBuf = wrap(MB);
1819 *OutMessage = strdup(Error.c_str());
1823 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
1824 char **OutMessage) {
1825 if (MemoryBuffer *MB = MemoryBuffer::getSTDIN()) {
1826 *OutMemBuf = wrap(MB);
1830 *OutMessage = strdup("stdin is empty.");
1834 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
1835 delete unwrap(MemBuf);