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/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/InlineAsm.h"
23 #include "llvm/IntrinsicInst.h"
24 #include "llvm/PassManager.h"
25 #include "llvm/Support/CallSite.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/system_error.h"
37 void llvm::initializeCore(PassRegistry &Registry) {
38 initializeDominatorTreePass(Registry);
39 initializePrintModulePassPass(Registry);
40 initializePrintFunctionPassPass(Registry);
41 initializeVerifierPass(Registry);
42 initializePreVerifierPass(Registry);
45 void LLVMInitializeCore(LLVMPassRegistryRef R) {
46 initializeCore(*unwrap(R));
49 /*===-- Error handling ----------------------------------------------------===*/
51 void LLVMDisposeMessage(char *Message) {
56 /*===-- Operations on contexts --------------------------------------------===*/
58 LLVMContextRef LLVMContextCreate() {
59 return wrap(new LLVMContext());
62 LLVMContextRef LLVMGetGlobalContext() {
63 return wrap(&getGlobalContext());
66 void LLVMContextDispose(LLVMContextRef C) {
70 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
72 return unwrap(C)->getMDKindID(StringRef(Name, SLen));
75 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
76 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
80 /*===-- Operations on modules ---------------------------------------------===*/
82 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
83 return wrap(new Module(ModuleID, getGlobalContext()));
86 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
88 return wrap(new Module(ModuleID, *unwrap(C)));
91 void LLVMDisposeModule(LLVMModuleRef M) {
95 /*--.. Data layout .........................................................--*/
96 const char * LLVMGetDataLayout(LLVMModuleRef M) {
97 return unwrap(M)->getDataLayout().c_str();
100 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
101 unwrap(M)->setDataLayout(Triple);
104 /*--.. Target triple .......................................................--*/
105 const char * LLVMGetTarget(LLVMModuleRef M) {
106 return unwrap(M)->getTargetTriple().c_str();
109 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
110 unwrap(M)->setTargetTriple(Triple);
113 void LLVMDumpModule(LLVMModuleRef M) {
117 /*--.. Operations on inline assembler ......................................--*/
118 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
119 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
123 /*--.. Operations on module contexts ......................................--*/
124 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) {
125 return wrap(&unwrap(M)->getContext());
129 /*===-- Operations on types -----------------------------------------------===*/
131 /*--.. Operations on all types (mostly) ....................................--*/
133 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
134 switch (unwrap(Ty)->getTypeID()) {
136 assert(false && "Unhandled TypeID.");
138 return LLVMVoidTypeKind;
140 return LLVMHalfTypeKind;
141 case Type::FloatTyID:
142 return LLVMFloatTypeKind;
143 case Type::DoubleTyID:
144 return LLVMDoubleTypeKind;
145 case Type::X86_FP80TyID:
146 return LLVMX86_FP80TypeKind;
147 case Type::FP128TyID:
148 return LLVMFP128TypeKind;
149 case Type::PPC_FP128TyID:
150 return LLVMPPC_FP128TypeKind;
151 case Type::LabelTyID:
152 return LLVMLabelTypeKind;
153 case Type::MetadataTyID:
154 return LLVMMetadataTypeKind;
155 case Type::IntegerTyID:
156 return LLVMIntegerTypeKind;
157 case Type::FunctionTyID:
158 return LLVMFunctionTypeKind;
159 case Type::StructTyID:
160 return LLVMStructTypeKind;
161 case Type::ArrayTyID:
162 return LLVMArrayTypeKind;
163 case Type::PointerTyID:
164 return LLVMPointerTypeKind;
165 case Type::VectorTyID:
166 return LLVMVectorTypeKind;
167 case Type::X86_MMXTyID:
168 return LLVMX86_MMXTypeKind;
172 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
174 return unwrap(Ty)->isSized();
177 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
178 return wrap(&unwrap(Ty)->getContext());
181 /*--.. Operations on integer types .........................................--*/
183 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
184 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
186 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
187 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
189 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
190 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
192 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
193 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
195 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
196 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
198 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
199 return wrap(IntegerType::get(*unwrap(C), NumBits));
202 LLVMTypeRef LLVMInt1Type(void) {
203 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
205 LLVMTypeRef LLVMInt8Type(void) {
206 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
208 LLVMTypeRef LLVMInt16Type(void) {
209 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
211 LLVMTypeRef LLVMInt32Type(void) {
212 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
214 LLVMTypeRef LLVMInt64Type(void) {
215 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
217 LLVMTypeRef LLVMIntType(unsigned NumBits) {
218 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
221 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
222 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
225 /*--.. Operations on real types ............................................--*/
227 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) {
228 return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
230 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
231 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
233 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
234 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
236 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
237 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
239 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
240 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
242 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
243 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
245 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
246 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
249 LLVMTypeRef LLVMHalfType(void) {
250 return LLVMHalfTypeInContext(LLVMGetGlobalContext());
252 LLVMTypeRef LLVMFloatType(void) {
253 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
255 LLVMTypeRef LLVMDoubleType(void) {
256 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
258 LLVMTypeRef LLVMX86FP80Type(void) {
259 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
261 LLVMTypeRef LLVMFP128Type(void) {
262 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
264 LLVMTypeRef LLVMPPCFP128Type(void) {
265 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
267 LLVMTypeRef LLVMX86MMXType(void) {
268 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
271 /*--.. Operations on function types ........................................--*/
273 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
274 LLVMTypeRef *ParamTypes, unsigned ParamCount,
276 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
277 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
280 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
281 return unwrap<FunctionType>(FunctionTy)->isVarArg();
284 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
285 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
288 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
289 return unwrap<FunctionType>(FunctionTy)->getNumParams();
292 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
293 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
294 for (FunctionType::param_iterator I = Ty->param_begin(),
295 E = Ty->param_end(); I != E; ++I)
299 /*--.. Operations on struct types ..........................................--*/
301 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
302 unsigned ElementCount, LLVMBool Packed) {
303 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
304 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
307 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
308 unsigned ElementCount, LLVMBool Packed) {
309 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
310 ElementCount, Packed);
313 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
315 return wrap(StructType::create(*unwrap(C), Name));
318 const char *LLVMGetStructName(LLVMTypeRef Ty)
320 StructType *Type = unwrap<StructType>(Ty);
321 if (!Type->hasName())
323 return Type->getName().data();
326 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
327 unsigned ElementCount, LLVMBool Packed) {
328 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
329 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
332 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
333 return unwrap<StructType>(StructTy)->getNumElements();
336 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
337 StructType *Ty = unwrap<StructType>(StructTy);
338 for (StructType::element_iterator I = Ty->element_begin(),
339 E = Ty->element_end(); I != E; ++I)
343 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
344 return unwrap<StructType>(StructTy)->isPacked();
347 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
348 return unwrap<StructType>(StructTy)->isOpaque();
351 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
352 return wrap(unwrap(M)->getTypeByName(Name));
355 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
357 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
358 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
361 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
362 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
365 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
366 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
369 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
370 return wrap(unwrap<SequentialType>(Ty)->getElementType());
373 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
374 return unwrap<ArrayType>(ArrayTy)->getNumElements();
377 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
378 return unwrap<PointerType>(PointerTy)->getAddressSpace();
381 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
382 return unwrap<VectorType>(VectorTy)->getNumElements();
385 /*--.. Operations on other types ...........................................--*/
387 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
388 return wrap(Type::getVoidTy(*unwrap(C)));
390 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
391 return wrap(Type::getLabelTy(*unwrap(C)));
394 LLVMTypeRef LLVMVoidType(void) {
395 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
397 LLVMTypeRef LLVMLabelType(void) {
398 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
401 /*===-- Operations on values ----------------------------------------------===*/
403 /*--.. Operations on all values ............................................--*/
405 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
406 return wrap(unwrap(Val)->getType());
409 const char *LLVMGetValueName(LLVMValueRef Val) {
410 return unwrap(Val)->getName().data();
413 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
414 unwrap(Val)->setName(Name);
417 void LLVMDumpValue(LLVMValueRef Val) {
421 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
422 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
425 int LLVMHasMetadata(LLVMValueRef Inst) {
426 return unwrap<Instruction>(Inst)->hasMetadata();
429 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
430 return wrap(unwrap<Instruction>(Inst)->getMetadata(KindID));
433 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
434 unwrap<Instruction>(Inst)->setMetadata(KindID, MD? unwrap<MDNode>(MD) : NULL);
437 /*--.. Conversion functions ................................................--*/
439 #define LLVM_DEFINE_VALUE_CAST(name) \
440 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
441 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
444 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
446 /*--.. Operations on Uses ..................................................--*/
447 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
448 Value *V = unwrap(Val);
449 Value::use_iterator I = V->use_begin();
450 if (I == V->use_end())
452 return wrap(&(I.getUse()));
455 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
456 Use *Next = unwrap(U)->getNext();
462 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
463 return wrap(unwrap(U)->getUser());
466 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
467 return wrap(unwrap(U)->get());
470 /*--.. Operations on Users .................................................--*/
471 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
472 Value *V = unwrap(Val);
473 if (MDNode *MD = dyn_cast<MDNode>(V))
474 return wrap(MD->getOperand(Index));
475 return wrap(cast<User>(V)->getOperand(Index));
478 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
479 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
482 int LLVMGetNumOperands(LLVMValueRef Val) {
483 Value *V = unwrap(Val);
484 if (MDNode *MD = dyn_cast<MDNode>(V))
485 return MD->getNumOperands();
486 return cast<User>(V)->getNumOperands();
489 /*--.. Operations on constants of any type .................................--*/
491 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
492 return wrap(Constant::getNullValue(unwrap(Ty)));
495 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
496 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
499 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
500 return wrap(UndefValue::get(unwrap(Ty)));
503 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
504 return isa<Constant>(unwrap(Ty));
507 LLVMBool LLVMIsNull(LLVMValueRef Val) {
508 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
509 return C->isNullValue();
513 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
514 return isa<UndefValue>(unwrap(Val));
517 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
519 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
522 /*--.. Operations on metadata nodes ........................................--*/
524 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
526 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
529 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
530 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
533 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
535 return wrap(MDNode::get(*unwrap(C),
536 makeArrayRef(unwrap<Value>(Vals, Count), Count)));
539 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
540 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
543 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
544 if (const MDString *S = dyn_cast<MDString>(unwrap(V))) {
545 *Len = S->getString().size();
546 return S->getString().data();
552 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
554 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
555 return N->getNumOperands();
560 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
562 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
565 for (unsigned i=0;i<N->getNumOperands();i++)
566 Dest[i] = wrap(N->getOperand(i));
569 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
572 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
575 MDNode *Op = Val ? unwrap<MDNode>(Val) : NULL;
580 /*--.. Operations on scalar constants ......................................--*/
582 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
583 LLVMBool SignExtend) {
584 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
587 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
589 const uint64_t Words[]) {
590 IntegerType *Ty = unwrap<IntegerType>(IntTy);
591 return wrap(ConstantInt::get(Ty->getContext(),
592 APInt(Ty->getBitWidth(),
593 makeArrayRef(Words, NumWords))));
596 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
598 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
602 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
603 unsigned SLen, uint8_t Radix) {
604 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
608 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
609 return wrap(ConstantFP::get(unwrap(RealTy), N));
612 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
613 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
616 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
618 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
621 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
622 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
625 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
626 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
629 /*--.. Operations on composite constants ...................................--*/
631 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
633 LLVMBool DontNullTerminate) {
634 /* Inverted the sense of AddNull because ', 0)' is a
635 better mnemonic for null termination than ', 1)'. */
636 return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length),
637 DontNullTerminate == 0));
639 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
640 LLVMValueRef *ConstantVals,
641 unsigned Count, LLVMBool Packed) {
642 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
643 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
647 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
648 LLVMBool DontNullTerminate) {
649 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
652 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
653 LLVMValueRef *ConstantVals, unsigned Length) {
654 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
655 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
657 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
659 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
663 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
664 LLVMValueRef *ConstantVals,
666 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
667 StructType *Ty = cast<StructType>(unwrap(StructTy));
669 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
672 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
673 return wrap(ConstantVector::get(makeArrayRef(
674 unwrap<Constant>(ScalarConstantVals, Size), Size)));
677 /*-- Opcode mapping */
679 static LLVMOpcode map_to_llvmopcode(int opcode)
683 assert(0 && "Unhandled Opcode.");
684 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
685 #include "llvm/Instruction.def"
690 static int map_from_llvmopcode(LLVMOpcode code)
694 assert(0 && "Unhandled Opcode.");
695 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
696 #include "llvm/Instruction.def"
701 /*--.. Constant expressions ................................................--*/
703 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
704 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
707 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
708 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
711 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
712 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
715 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
716 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
719 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
720 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
723 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
724 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
728 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
729 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
732 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
733 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
736 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
737 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
738 unwrap<Constant>(RHSConstant)));
741 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
742 LLVMValueRef RHSConstant) {
743 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
744 unwrap<Constant>(RHSConstant)));
747 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
748 LLVMValueRef RHSConstant) {
749 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
750 unwrap<Constant>(RHSConstant)));
753 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
754 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
755 unwrap<Constant>(RHSConstant)));
758 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
759 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
760 unwrap<Constant>(RHSConstant)));
763 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
764 LLVMValueRef RHSConstant) {
765 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
766 unwrap<Constant>(RHSConstant)));
769 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
770 LLVMValueRef RHSConstant) {
771 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
772 unwrap<Constant>(RHSConstant)));
775 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
776 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
777 unwrap<Constant>(RHSConstant)));
780 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
781 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
782 unwrap<Constant>(RHSConstant)));
785 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
786 LLVMValueRef RHSConstant) {
787 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
788 unwrap<Constant>(RHSConstant)));
791 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
792 LLVMValueRef RHSConstant) {
793 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
794 unwrap<Constant>(RHSConstant)));
797 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
798 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
799 unwrap<Constant>(RHSConstant)));
802 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
803 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
804 unwrap<Constant>(RHSConstant)));
807 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
808 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
809 unwrap<Constant>(RHSConstant)));
812 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
813 LLVMValueRef RHSConstant) {
814 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
815 unwrap<Constant>(RHSConstant)));
818 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
819 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
820 unwrap<Constant>(RHSConstant)));
823 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
824 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
825 unwrap<Constant>(RHSConstant)));
828 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
829 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
830 unwrap<Constant>(RHSConstant)));
833 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
834 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
835 unwrap<Constant>(RHSConstant)));
838 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
839 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
840 unwrap<Constant>(RHSConstant)));
843 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
844 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
845 unwrap<Constant>(RHSConstant)));
848 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
849 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
850 unwrap<Constant>(RHSConstant)));
853 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
854 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
855 return wrap(ConstantExpr::getICmp(Predicate,
856 unwrap<Constant>(LHSConstant),
857 unwrap<Constant>(RHSConstant)));
860 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
861 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
862 return wrap(ConstantExpr::getFCmp(Predicate,
863 unwrap<Constant>(LHSConstant),
864 unwrap<Constant>(RHSConstant)));
867 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
868 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
869 unwrap<Constant>(RHSConstant)));
872 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
873 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
874 unwrap<Constant>(RHSConstant)));
877 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
878 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
879 unwrap<Constant>(RHSConstant)));
882 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
883 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
884 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
886 return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
890 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
891 LLVMValueRef *ConstantIndices,
892 unsigned NumIndices) {
893 Constant* Val = unwrap<Constant>(ConstantVal);
894 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
896 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
899 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
900 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
904 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
905 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
909 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
910 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
914 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
915 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
919 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
920 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
924 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
925 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
929 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
930 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
934 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
935 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
939 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
940 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
944 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
945 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
949 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
950 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
954 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
955 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
959 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
960 LLVMTypeRef ToType) {
961 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
965 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
966 LLVMTypeRef ToType) {
967 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
971 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
972 LLVMTypeRef ToType) {
973 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
977 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
978 LLVMTypeRef ToType) {
979 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
983 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
985 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
986 unwrap(ToType), isSigned));
989 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
990 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
994 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
995 LLVMValueRef ConstantIfTrue,
996 LLVMValueRef ConstantIfFalse) {
997 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
998 unwrap<Constant>(ConstantIfTrue),
999 unwrap<Constant>(ConstantIfFalse)));
1002 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1003 LLVMValueRef IndexConstant) {
1004 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1005 unwrap<Constant>(IndexConstant)));
1008 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1009 LLVMValueRef ElementValueConstant,
1010 LLVMValueRef IndexConstant) {
1011 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1012 unwrap<Constant>(ElementValueConstant),
1013 unwrap<Constant>(IndexConstant)));
1016 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1017 LLVMValueRef VectorBConstant,
1018 LLVMValueRef MaskConstant) {
1019 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1020 unwrap<Constant>(VectorBConstant),
1021 unwrap<Constant>(MaskConstant)));
1024 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1026 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1027 makeArrayRef(IdxList, NumIdx)));
1030 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1031 LLVMValueRef ElementValueConstant,
1032 unsigned *IdxList, unsigned NumIdx) {
1033 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1034 unwrap<Constant>(ElementValueConstant),
1035 makeArrayRef(IdxList, NumIdx)));
1038 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1039 const char *Constraints,
1040 LLVMBool HasSideEffects,
1041 LLVMBool IsAlignStack) {
1042 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1043 Constraints, HasSideEffects, IsAlignStack));
1046 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1047 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1050 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1052 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1053 return wrap(unwrap<GlobalValue>(Global)->getParent());
1056 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1057 return unwrap<GlobalValue>(Global)->isDeclaration();
1060 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1061 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1063 assert(false && "Unhandled Linkage Type.");
1064 case GlobalValue::ExternalLinkage:
1065 return LLVMExternalLinkage;
1066 case GlobalValue::AvailableExternallyLinkage:
1067 return LLVMAvailableExternallyLinkage;
1068 case GlobalValue::LinkOnceAnyLinkage:
1069 return LLVMLinkOnceAnyLinkage;
1070 case GlobalValue::LinkOnceODRLinkage:
1071 return LLVMLinkOnceODRLinkage;
1072 case GlobalValue::WeakAnyLinkage:
1073 return LLVMWeakAnyLinkage;
1074 case GlobalValue::WeakODRLinkage:
1075 return LLVMWeakODRLinkage;
1076 case GlobalValue::AppendingLinkage:
1077 return LLVMAppendingLinkage;
1078 case GlobalValue::InternalLinkage:
1079 return LLVMInternalLinkage;
1080 case GlobalValue::PrivateLinkage:
1081 return LLVMPrivateLinkage;
1082 case GlobalValue::LinkerPrivateLinkage:
1083 return LLVMLinkerPrivateLinkage;
1084 case GlobalValue::LinkerPrivateWeakLinkage:
1085 return LLVMLinkerPrivateWeakLinkage;
1086 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
1087 return LLVMLinkerPrivateWeakDefAutoLinkage;
1088 case GlobalValue::DLLImportLinkage:
1089 return LLVMDLLImportLinkage;
1090 case GlobalValue::DLLExportLinkage:
1091 return LLVMDLLExportLinkage;
1092 case GlobalValue::ExternalWeakLinkage:
1093 return LLVMExternalWeakLinkage;
1094 case GlobalValue::CommonLinkage:
1095 return LLVMCommonLinkage;
1098 // Should never get here.
1099 return static_cast<LLVMLinkage>(0);
1102 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1103 GlobalValue *GV = unwrap<GlobalValue>(Global);
1107 assert(false && "Unhandled Linkage Type.");
1108 case LLVMExternalLinkage:
1109 GV->setLinkage(GlobalValue::ExternalLinkage);
1111 case LLVMAvailableExternallyLinkage:
1112 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1114 case LLVMLinkOnceAnyLinkage:
1115 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1117 case LLVMLinkOnceODRLinkage:
1118 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1120 case LLVMWeakAnyLinkage:
1121 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1123 case LLVMWeakODRLinkage:
1124 GV->setLinkage(GlobalValue::WeakODRLinkage);
1126 case LLVMAppendingLinkage:
1127 GV->setLinkage(GlobalValue::AppendingLinkage);
1129 case LLVMInternalLinkage:
1130 GV->setLinkage(GlobalValue::InternalLinkage);
1132 case LLVMPrivateLinkage:
1133 GV->setLinkage(GlobalValue::PrivateLinkage);
1135 case LLVMLinkerPrivateLinkage:
1136 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
1138 case LLVMLinkerPrivateWeakLinkage:
1139 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
1141 case LLVMLinkerPrivateWeakDefAutoLinkage:
1142 GV->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage);
1144 case LLVMDLLImportLinkage:
1145 GV->setLinkage(GlobalValue::DLLImportLinkage);
1147 case LLVMDLLExportLinkage:
1148 GV->setLinkage(GlobalValue::DLLExportLinkage);
1150 case LLVMExternalWeakLinkage:
1151 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1153 case LLVMGhostLinkage:
1155 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1157 case LLVMCommonLinkage:
1158 GV->setLinkage(GlobalValue::CommonLinkage);
1163 const char *LLVMGetSection(LLVMValueRef Global) {
1164 return unwrap<GlobalValue>(Global)->getSection().c_str();
1167 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1168 unwrap<GlobalValue>(Global)->setSection(Section);
1171 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1172 return static_cast<LLVMVisibility>(
1173 unwrap<GlobalValue>(Global)->getVisibility());
1176 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1177 unwrap<GlobalValue>(Global)
1178 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1181 unsigned LLVMGetAlignment(LLVMValueRef Global) {
1182 return unwrap<GlobalValue>(Global)->getAlignment();
1185 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
1186 unwrap<GlobalValue>(Global)->setAlignment(Bytes);
1189 /*--.. Operations on global variables ......................................--*/
1191 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1192 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1193 GlobalValue::ExternalLinkage, 0, Name));
1196 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1198 unsigned AddressSpace) {
1199 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1200 GlobalValue::ExternalLinkage, 0, Name, 0,
1201 false, AddressSpace));
1204 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1205 return wrap(unwrap(M)->getNamedGlobal(Name));
1208 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1209 Module *Mod = unwrap(M);
1210 Module::global_iterator I = Mod->global_begin();
1211 if (I == Mod->global_end())
1216 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1217 Module *Mod = unwrap(M);
1218 Module::global_iterator I = Mod->global_end();
1219 if (I == Mod->global_begin())
1224 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1225 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1226 Module::global_iterator I = GV;
1227 if (++I == GV->getParent()->global_end())
1232 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1233 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1234 Module::global_iterator I = GV;
1235 if (I == GV->getParent()->global_begin())
1240 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1241 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1244 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1245 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1246 if ( !GV->hasInitializer() )
1248 return wrap(GV->getInitializer());
1251 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1252 unwrap<GlobalVariable>(GlobalVar)
1253 ->setInitializer(unwrap<Constant>(ConstantVal));
1256 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1257 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1260 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1261 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1264 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1265 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1268 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1269 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1272 /*--.. Operations on aliases ......................................--*/
1274 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1276 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
1277 unwrap<Constant>(Aliasee), unwrap (M)));
1280 /*--.. Operations on functions .............................................--*/
1282 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1283 LLVMTypeRef FunctionTy) {
1284 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1285 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1288 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1289 return wrap(unwrap(M)->getFunction(Name));
1292 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1293 Module *Mod = unwrap(M);
1294 Module::iterator I = Mod->begin();
1295 if (I == Mod->end())
1300 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1301 Module *Mod = unwrap(M);
1302 Module::iterator I = Mod->end();
1303 if (I == Mod->begin())
1308 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1309 Function *Func = unwrap<Function>(Fn);
1310 Module::iterator I = Func;
1311 if (++I == Func->getParent()->end())
1316 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1317 Function *Func = unwrap<Function>(Fn);
1318 Module::iterator I = Func;
1319 if (I == Func->getParent()->begin())
1324 void LLVMDeleteFunction(LLVMValueRef Fn) {
1325 unwrap<Function>(Fn)->eraseFromParent();
1328 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1329 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1330 return F->getIntrinsicID();
1334 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1335 return unwrap<Function>(Fn)->getCallingConv();
1338 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1339 return unwrap<Function>(Fn)->setCallingConv(
1340 static_cast<CallingConv::ID>(CC));
1343 const char *LLVMGetGC(LLVMValueRef Fn) {
1344 Function *F = unwrap<Function>(Fn);
1345 return F->hasGC()? F->getGC() : 0;
1348 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1349 Function *F = unwrap<Function>(Fn);
1356 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1357 Function *Func = unwrap<Function>(Fn);
1358 const AttrListPtr PAL = Func->getAttributes();
1359 const AttrListPtr PALnew = PAL.addAttr(~0U, PA);
1360 Func->setAttributes(PALnew);
1363 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1364 Function *Func = unwrap<Function>(Fn);
1365 const AttrListPtr PAL = Func->getAttributes();
1366 const AttrListPtr PALnew = PAL.removeAttr(~0U, PA);
1367 Func->setAttributes(PALnew);
1370 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1371 Function *Func = unwrap<Function>(Fn);
1372 const AttrListPtr PAL = Func->getAttributes();
1373 Attributes attr = PAL.getFnAttributes();
1374 return (LLVMAttribute)attr;
1377 /*--.. Operations on parameters ............................................--*/
1379 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1380 // This function is strictly redundant to
1381 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1382 return unwrap<Function>(FnRef)->arg_size();
1385 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1386 Function *Fn = unwrap<Function>(FnRef);
1387 for (Function::arg_iterator I = Fn->arg_begin(),
1388 E = Fn->arg_end(); I != E; I++)
1389 *ParamRefs++ = wrap(I);
1392 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1393 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1399 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1400 return wrap(unwrap<Argument>(V)->getParent());
1403 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1404 Function *Func = unwrap<Function>(Fn);
1405 Function::arg_iterator I = Func->arg_begin();
1406 if (I == Func->arg_end())
1411 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1412 Function *Func = unwrap<Function>(Fn);
1413 Function::arg_iterator I = Func->arg_end();
1414 if (I == Func->arg_begin())
1419 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1420 Argument *A = unwrap<Argument>(Arg);
1421 Function::arg_iterator I = A;
1422 if (++I == A->getParent()->arg_end())
1427 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1428 Argument *A = unwrap<Argument>(Arg);
1429 Function::arg_iterator I = A;
1430 if (I == A->getParent()->arg_begin())
1435 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1436 unwrap<Argument>(Arg)->addAttr(PA);
1439 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1440 unwrap<Argument>(Arg)->removeAttr(PA);
1443 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1444 Argument *A = unwrap<Argument>(Arg);
1445 Attributes attr = A->getParent()->getAttributes().getParamAttributes(
1447 return (LLVMAttribute)attr;
1451 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1452 unwrap<Argument>(Arg)->addAttr(
1453 Attribute::constructAlignmentFromInt(align));
1456 /*--.. Operations on basic blocks ..........................................--*/
1458 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1459 return wrap(static_cast<Value*>(unwrap(BB)));
1462 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1463 return isa<BasicBlock>(unwrap(Val));
1466 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1467 return wrap(unwrap<BasicBlock>(Val));
1470 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1471 return wrap(unwrap(BB)->getParent());
1474 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1475 return wrap(unwrap(BB)->getTerminator());
1478 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1479 return unwrap<Function>(FnRef)->size();
1482 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1483 Function *Fn = unwrap<Function>(FnRef);
1484 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1485 *BasicBlocksRefs++ = wrap(I);
1488 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1489 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1492 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1493 Function *Func = unwrap<Function>(Fn);
1494 Function::iterator I = Func->begin();
1495 if (I == Func->end())
1500 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1501 Function *Func = unwrap<Function>(Fn);
1502 Function::iterator I = Func->end();
1503 if (I == Func->begin())
1508 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1509 BasicBlock *Block = unwrap(BB);
1510 Function::iterator I = Block;
1511 if (++I == Block->getParent()->end())
1516 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1517 BasicBlock *Block = unwrap(BB);
1518 Function::iterator I = Block;
1519 if (I == Block->getParent()->begin())
1524 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1527 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1530 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1531 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1534 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1535 LLVMBasicBlockRef BBRef,
1537 BasicBlock *BB = unwrap(BBRef);
1538 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1541 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1543 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1546 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1547 unwrap(BBRef)->eraseFromParent();
1550 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1551 unwrap(BBRef)->removeFromParent();
1554 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1555 unwrap(BB)->moveBefore(unwrap(MovePos));
1558 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1559 unwrap(BB)->moveAfter(unwrap(MovePos));
1562 /*--.. Operations on instructions ..........................................--*/
1564 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1565 return wrap(unwrap<Instruction>(Inst)->getParent());
1568 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1569 BasicBlock *Block = unwrap(BB);
1570 BasicBlock::iterator I = Block->begin();
1571 if (I == Block->end())
1576 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1577 BasicBlock *Block = unwrap(BB);
1578 BasicBlock::iterator I = Block->end();
1579 if (I == Block->begin())
1584 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1585 Instruction *Instr = unwrap<Instruction>(Inst);
1586 BasicBlock::iterator I = Instr;
1587 if (++I == Instr->getParent()->end())
1592 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1593 Instruction *Instr = unwrap<Instruction>(Inst);
1594 BasicBlock::iterator I = Instr;
1595 if (I == Instr->getParent()->begin())
1600 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
1601 unwrap<Instruction>(Inst)->eraseFromParent();
1604 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
1605 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
1606 return (LLVMIntPredicate)I->getPredicate();
1607 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
1608 if (CE->getOpcode() == Instruction::ICmp)
1609 return (LLVMIntPredicate)CE->getPredicate();
1610 return (LLVMIntPredicate)0;
1613 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
1614 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
1615 return map_to_llvmopcode(C->getOpcode());
1616 return (LLVMOpcode)0;
1619 /*--.. Call and invoke instructions ........................................--*/
1621 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
1622 Value *V = unwrap(Instr);
1623 if (CallInst *CI = dyn_cast<CallInst>(V))
1624 return CI->getCallingConv();
1625 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1626 return II->getCallingConv();
1627 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1631 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
1632 Value *V = unwrap(Instr);
1633 if (CallInst *CI = dyn_cast<CallInst>(V))
1634 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
1635 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1636 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
1637 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1640 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
1642 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1644 Call.getAttributes().addAttr(index, PA));
1647 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
1649 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1651 Call.getAttributes().removeAttr(index, PA));
1654 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
1656 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1658 Call.getAttributes().addAttr(index,
1659 Attribute::constructAlignmentFromInt(align)));
1662 /*--.. Operations on call instructions (only) ..............................--*/
1664 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
1665 return unwrap<CallInst>(Call)->isTailCall();
1668 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
1669 unwrap<CallInst>(Call)->setTailCall(isTailCall);
1672 /*--.. Operations on switch instructions (only) ............................--*/
1674 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
1675 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
1678 /*--.. Operations on phi nodes .............................................--*/
1680 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
1681 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
1682 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
1683 for (unsigned I = 0; I != Count; ++I)
1684 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
1687 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
1688 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
1691 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
1692 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
1695 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
1696 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
1700 /*===-- Instruction builders ----------------------------------------------===*/
1702 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
1703 return wrap(new IRBuilder<>(*unwrap(C)));
1706 LLVMBuilderRef LLVMCreateBuilder(void) {
1707 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1710 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
1711 LLVMValueRef Instr) {
1712 BasicBlock *BB = unwrap(Block);
1713 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
1714 unwrap(Builder)->SetInsertPoint(BB, I);
1717 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1718 Instruction *I = unwrap<Instruction>(Instr);
1719 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
1722 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
1723 BasicBlock *BB = unwrap(Block);
1724 unwrap(Builder)->SetInsertPoint(BB);
1727 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
1728 return wrap(unwrap(Builder)->GetInsertBlock());
1731 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
1732 unwrap(Builder)->ClearInsertionPoint();
1735 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1736 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
1739 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
1741 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
1744 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
1745 delete unwrap(Builder);
1748 /*--.. Metadata builders ...................................................--*/
1750 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
1751 MDNode *Loc = L ? unwrap<MDNode>(L) : NULL;
1752 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc));
1755 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
1756 return wrap(unwrap(Builder)->getCurrentDebugLocation()
1757 .getAsMDNode(unwrap(Builder)->getContext()));
1760 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
1761 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
1765 /*--.. Instruction builders ................................................--*/
1767 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
1768 return wrap(unwrap(B)->CreateRetVoid());
1771 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
1772 return wrap(unwrap(B)->CreateRet(unwrap(V)));
1775 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
1777 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
1780 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
1781 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
1784 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
1785 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
1786 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
1789 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
1790 LLVMBasicBlockRef Else, unsigned NumCases) {
1791 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
1794 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
1795 unsigned NumDests) {
1796 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
1799 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
1800 LLVMValueRef *Args, unsigned NumArgs,
1801 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
1803 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
1804 makeArrayRef(unwrap(Args), NumArgs),
1808 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
1809 LLVMValueRef PersFn, unsigned NumClauses,
1811 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty),
1812 cast<Function>(unwrap(PersFn)),
1816 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
1817 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
1820 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
1821 return wrap(unwrap(B)->CreateUnreachable());
1824 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
1825 LLVMBasicBlockRef Dest) {
1826 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
1829 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
1830 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
1833 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
1834 unwrap<LandingPadInst>(LandingPad)->
1835 addClause(cast<Constant>(unwrap(ClauseVal)));
1838 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
1839 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
1842 /*--.. Arithmetic ..........................................................--*/
1844 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1846 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
1849 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1851 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
1854 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1856 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
1859 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1861 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
1864 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1866 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
1869 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1871 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
1874 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1876 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
1879 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1881 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
1884 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1886 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
1889 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1891 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
1894 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1896 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
1899 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1901 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
1904 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1906 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
1909 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1911 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
1914 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
1915 LLVMValueRef RHS, const char *Name) {
1916 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
1919 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1921 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
1924 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1926 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
1929 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1931 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
1934 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1936 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
1939 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1941 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
1944 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1946 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
1949 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1951 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
1954 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1956 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
1959 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1961 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
1964 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1966 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
1969 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
1970 LLVMValueRef LHS, LLVMValueRef RHS,
1972 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
1973 unwrap(RHS), Name));
1976 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1977 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
1980 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
1982 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
1985 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
1987 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
1990 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1991 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
1994 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1995 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
1998 /*--.. Memory ..............................................................--*/
2000 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2002 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2003 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2004 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2005 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2006 ITy, unwrap(Ty), AllocSize,
2008 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2011 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2012 LLVMValueRef Val, const char *Name) {
2013 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2014 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2015 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2016 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2017 ITy, unwrap(Ty), AllocSize,
2018 unwrap(Val), 0, "");
2019 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2022 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2024 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
2027 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2028 LLVMValueRef Val, const char *Name) {
2029 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2032 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2033 return wrap(unwrap(B)->Insert(
2034 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2038 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2040 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2043 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2044 LLVMValueRef PointerVal) {
2045 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2048 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2049 LLVMValueRef *Indices, unsigned NumIndices,
2051 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2052 return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), IdxList, Name));
2055 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2056 LLVMValueRef *Indices, unsigned NumIndices,
2058 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2059 return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), IdxList, Name));
2062 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2063 unsigned Idx, const char *Name) {
2064 return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name));
2067 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2069 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2072 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2074 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2077 /*--.. Casts ...............................................................--*/
2079 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2080 LLVMTypeRef DestTy, const char *Name) {
2081 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2084 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2085 LLVMTypeRef DestTy, const char *Name) {
2086 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2089 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2090 LLVMTypeRef DestTy, const char *Name) {
2091 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2094 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2095 LLVMTypeRef DestTy, const char *Name) {
2096 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2099 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2100 LLVMTypeRef DestTy, const char *Name) {
2101 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2104 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2105 LLVMTypeRef DestTy, const char *Name) {
2106 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2109 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2110 LLVMTypeRef DestTy, const char *Name) {
2111 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2114 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2115 LLVMTypeRef DestTy, const char *Name) {
2116 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2119 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2120 LLVMTypeRef DestTy, const char *Name) {
2121 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2124 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2125 LLVMTypeRef DestTy, const char *Name) {
2126 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2129 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2130 LLVMTypeRef DestTy, const char *Name) {
2131 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2134 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2135 LLVMTypeRef DestTy, const char *Name) {
2136 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2139 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2140 LLVMTypeRef DestTy, const char *Name) {
2141 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2145 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2146 LLVMTypeRef DestTy, const char *Name) {
2147 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2151 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2152 LLVMTypeRef DestTy, const char *Name) {
2153 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2157 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2158 LLVMTypeRef DestTy, const char *Name) {
2159 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2160 unwrap(DestTy), Name));
2163 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2164 LLVMTypeRef DestTy, const char *Name) {
2165 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2168 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2169 LLVMTypeRef DestTy, const char *Name) {
2170 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2171 /*isSigned*/true, Name));
2174 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2175 LLVMTypeRef DestTy, const char *Name) {
2176 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2179 /*--.. Comparisons .........................................................--*/
2181 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2182 LLVMValueRef LHS, LLVMValueRef RHS,
2184 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2185 unwrap(LHS), unwrap(RHS), Name));
2188 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2189 LLVMValueRef LHS, LLVMValueRef RHS,
2191 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2192 unwrap(LHS), unwrap(RHS), Name));
2195 /*--.. Miscellaneous instructions ..........................................--*/
2197 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2198 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2201 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2202 LLVMValueRef *Args, unsigned NumArgs,
2204 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2205 makeArrayRef(unwrap(Args), NumArgs),
2209 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2210 LLVMValueRef Then, LLVMValueRef Else,
2212 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2216 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2217 LLVMTypeRef Ty, const char *Name) {
2218 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2221 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2222 LLVMValueRef Index, const char *Name) {
2223 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2227 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2228 LLVMValueRef EltVal, LLVMValueRef Index,
2230 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2231 unwrap(Index), Name));
2234 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2235 LLVMValueRef V2, LLVMValueRef Mask,
2237 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2238 unwrap(Mask), Name));
2241 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2242 unsigned Index, const char *Name) {
2243 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2246 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2247 LLVMValueRef EltVal, unsigned Index,
2249 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2253 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2255 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2258 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2260 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2263 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2264 LLVMValueRef RHS, const char *Name) {
2265 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2269 /*===-- Module providers --------------------------------------------------===*/
2271 LLVMModuleProviderRef
2272 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2273 return reinterpret_cast<LLVMModuleProviderRef>(M);
2276 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2281 /*===-- Memory buffers ----------------------------------------------------===*/
2283 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2285 LLVMMemoryBufferRef *OutMemBuf,
2286 char **OutMessage) {
2288 OwningPtr<MemoryBuffer> MB;
2290 if (!(ec = MemoryBuffer::getFile(Path, MB))) {
2291 *OutMemBuf = wrap(MB.take());
2295 *OutMessage = strdup(ec.message().c_str());
2299 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2300 char **OutMessage) {
2301 OwningPtr<MemoryBuffer> MB;
2303 if (!(ec = MemoryBuffer::getSTDIN(MB))) {
2304 *OutMemBuf = wrap(MB.take());
2308 *OutMessage = strdup(ec.message().c_str());
2312 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2313 delete unwrap(MemBuf);
2316 /*===-- Pass Registry -----------------------------------------------------===*/
2318 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2319 return wrap(PassRegistry::getPassRegistry());
2322 /*===-- Pass Manager ------------------------------------------------------===*/
2324 LLVMPassManagerRef LLVMCreatePassManager() {
2325 return wrap(new PassManager());
2328 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2329 return wrap(new FunctionPassManager(unwrap(M)));
2332 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2333 return LLVMCreateFunctionPassManagerForModule(
2334 reinterpret_cast<LLVMModuleRef>(P));
2337 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2338 return unwrap<PassManager>(PM)->run(*unwrap(M));
2341 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2342 return unwrap<FunctionPassManager>(FPM)->doInitialization();
2345 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2346 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2349 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2350 return unwrap<FunctionPassManager>(FPM)->doFinalization();
2353 void LLVMDisposePassManager(LLVMPassManagerRef PM) {