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/TypeSymbolTable.h"
23 #include "llvm/InlineAsm.h"
24 #include "llvm/IntrinsicInst.h"
25 #include "llvm/PassManager.h"
26 #include "llvm/Support/CallSite.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/MemoryBuffer.h"
30 #include "llvm/Support/raw_ostream.h"
37 void llvm::initializeCore(PassRegistry
&Registry
) {
38 initializeDominatorTreePass(Registry
);
39 initializeDominanceFrontierPass(Registry
);
40 initializePrintModulePassPass(Registry
);
41 initializePrintFunctionPassPass(Registry
);
42 initializeVerifierPass(Registry
);
43 initializePreVerifierPass(Registry
);
46 void LLVMInitializeCore(LLVMPassRegistryRef R
) {
47 initializeCore(*unwrap(R
));
50 /*===-- Error handling ----------------------------------------------------===*/
52 void LLVMDisposeMessage(char *Message
) {
57 /*===-- Operations on contexts --------------------------------------------===*/
59 LLVMContextRef
LLVMContextCreate() {
60 return wrap(new LLVMContext());
63 LLVMContextRef
LLVMGetGlobalContext() {
64 return wrap(&getGlobalContext());
67 void LLVMContextDispose(LLVMContextRef C
) {
71 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C
, const char* Name
,
73 return unwrap(C
)->getMDKindID(StringRef(Name
, SLen
));
76 unsigned LLVMGetMDKindID(const char* Name
, unsigned SLen
) {
77 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name
, SLen
);
81 /*===-- Operations on modules ---------------------------------------------===*/
83 LLVMModuleRef
LLVMModuleCreateWithName(const char *ModuleID
) {
84 return wrap(new Module(ModuleID
, getGlobalContext()));
87 LLVMModuleRef
LLVMModuleCreateWithNameInContext(const char *ModuleID
,
89 return wrap(new Module(ModuleID
, *unwrap(C
)));
92 void LLVMDisposeModule(LLVMModuleRef M
) {
96 /*--.. Data layout .........................................................--*/
97 const char * LLVMGetDataLayout(LLVMModuleRef M
) {
98 return unwrap(M
)->getDataLayout().c_str();
101 void LLVMSetDataLayout(LLVMModuleRef M
, const char *Triple
) {
102 unwrap(M
)->setDataLayout(Triple
);
105 /*--.. Target triple .......................................................--*/
106 const char * LLVMGetTarget(LLVMModuleRef M
) {
107 return unwrap(M
)->getTargetTriple().c_str();
110 void LLVMSetTarget(LLVMModuleRef M
, const char *Triple
) {
111 unwrap(M
)->setTargetTriple(Triple
);
114 /*--.. Type names ..........................................................--*/
115 LLVMBool
LLVMAddTypeName(LLVMModuleRef M
, const char *Name
, LLVMTypeRef Ty
) {
116 return unwrap(M
)->addTypeName(Name
, unwrap(Ty
));
119 void LLVMDeleteTypeName(LLVMModuleRef M
, const char *Name
) {
120 TypeSymbolTable
&TST
= unwrap(M
)->getTypeSymbolTable();
122 TypeSymbolTable::iterator I
= TST
.find(Name
);
127 LLVMTypeRef
LLVMGetTypeByName(LLVMModuleRef M
, const char *Name
) {
128 return wrap(unwrap(M
)->getTypeByName(Name
));
131 void LLVMDumpModule(LLVMModuleRef M
) {
135 /*--.. Operations on inline assembler ......................................--*/
136 void LLVMSetModuleInlineAsm(LLVMModuleRef M
, const char *Asm
) {
137 unwrap(M
)->setModuleInlineAsm(StringRef(Asm
));
141 /*===-- Operations on types -----------------------------------------------===*/
143 /*--.. Operations on all types (mostly) ....................................--*/
145 LLVMTypeKind
LLVMGetTypeKind(LLVMTypeRef Ty
) {
146 switch (unwrap(Ty
)->getTypeID()) {
148 assert(false && "Unhandled TypeID.");
150 return LLVMVoidTypeKind
;
151 case Type::FloatTyID
:
152 return LLVMFloatTypeKind
;
153 case Type::DoubleTyID
:
154 return LLVMDoubleTypeKind
;
155 case Type::X86_FP80TyID
:
156 return LLVMX86_FP80TypeKind
;
157 case Type::FP128TyID
:
158 return LLVMFP128TypeKind
;
159 case Type::PPC_FP128TyID
:
160 return LLVMPPC_FP128TypeKind
;
161 case Type::LabelTyID
:
162 return LLVMLabelTypeKind
;
163 case Type::MetadataTyID
:
164 return LLVMMetadataTypeKind
;
165 case Type::IntegerTyID
:
166 return LLVMIntegerTypeKind
;
167 case Type::FunctionTyID
:
168 return LLVMFunctionTypeKind
;
169 case Type::StructTyID
:
170 return LLVMStructTypeKind
;
171 case Type::ArrayTyID
:
172 return LLVMArrayTypeKind
;
173 case Type::PointerTyID
:
174 return LLVMPointerTypeKind
;
175 case Type::OpaqueTyID
:
176 return LLVMOpaqueTypeKind
;
177 case Type::VectorTyID
:
178 return LLVMVectorTypeKind
;
179 case Type::X86_MMXTyID
:
180 return LLVMX86_MMXTypeKind
;
184 LLVMContextRef
LLVMGetTypeContext(LLVMTypeRef Ty
) {
185 return wrap(&unwrap(Ty
)->getContext());
188 /*--.. Operations on integer types .........................................--*/
190 LLVMTypeRef
LLVMInt1TypeInContext(LLVMContextRef C
) {
191 return (LLVMTypeRef
) Type::getInt1Ty(*unwrap(C
));
193 LLVMTypeRef
LLVMInt8TypeInContext(LLVMContextRef C
) {
194 return (LLVMTypeRef
) Type::getInt8Ty(*unwrap(C
));
196 LLVMTypeRef
LLVMInt16TypeInContext(LLVMContextRef C
) {
197 return (LLVMTypeRef
) Type::getInt16Ty(*unwrap(C
));
199 LLVMTypeRef
LLVMInt32TypeInContext(LLVMContextRef C
) {
200 return (LLVMTypeRef
) Type::getInt32Ty(*unwrap(C
));
202 LLVMTypeRef
LLVMInt64TypeInContext(LLVMContextRef C
) {
203 return (LLVMTypeRef
) Type::getInt64Ty(*unwrap(C
));
205 LLVMTypeRef
LLVMIntTypeInContext(LLVMContextRef C
, unsigned NumBits
) {
206 return wrap(IntegerType::get(*unwrap(C
), NumBits
));
209 LLVMTypeRef
LLVMInt1Type(void) {
210 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
212 LLVMTypeRef
LLVMInt8Type(void) {
213 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
215 LLVMTypeRef
LLVMInt16Type(void) {
216 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
218 LLVMTypeRef
LLVMInt32Type(void) {
219 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
221 LLVMTypeRef
LLVMInt64Type(void) {
222 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
224 LLVMTypeRef
LLVMIntType(unsigned NumBits
) {
225 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits
);
228 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy
) {
229 return unwrap
<IntegerType
>(IntegerTy
)->getBitWidth();
232 /*--.. Operations on real types ............................................--*/
234 LLVMTypeRef
LLVMFloatTypeInContext(LLVMContextRef C
) {
235 return (LLVMTypeRef
) Type::getFloatTy(*unwrap(C
));
237 LLVMTypeRef
LLVMDoubleTypeInContext(LLVMContextRef C
) {
238 return (LLVMTypeRef
) Type::getDoubleTy(*unwrap(C
));
240 LLVMTypeRef
LLVMX86FP80TypeInContext(LLVMContextRef C
) {
241 return (LLVMTypeRef
) Type::getX86_FP80Ty(*unwrap(C
));
243 LLVMTypeRef
LLVMFP128TypeInContext(LLVMContextRef C
) {
244 return (LLVMTypeRef
) Type::getFP128Ty(*unwrap(C
));
246 LLVMTypeRef
LLVMPPCFP128TypeInContext(LLVMContextRef C
) {
247 return (LLVMTypeRef
) Type::getPPC_FP128Ty(*unwrap(C
));
249 LLVMTypeRef
LLVMX86MMXTypeInContext(LLVMContextRef C
) {
250 return (LLVMTypeRef
) Type::getX86_MMXTy(*unwrap(C
));
253 LLVMTypeRef
LLVMFloatType(void) {
254 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
256 LLVMTypeRef
LLVMDoubleType(void) {
257 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
259 LLVMTypeRef
LLVMX86FP80Type(void) {
260 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
262 LLVMTypeRef
LLVMFP128Type(void) {
263 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
265 LLVMTypeRef
LLVMPPCFP128Type(void) {
266 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
268 LLVMTypeRef
LLVMX86MMXType(void) {
269 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
272 /*--.. Operations on function types ........................................--*/
274 LLVMTypeRef
LLVMFunctionType(LLVMTypeRef ReturnType
,
275 LLVMTypeRef
*ParamTypes
, unsigned ParamCount
,
277 std::vector
<const Type
*> Tys
;
278 for (LLVMTypeRef
*I
= ParamTypes
, *E
= ParamTypes
+ ParamCount
; I
!= E
; ++I
)
279 Tys
.push_back(unwrap(*I
));
281 return wrap(FunctionType::get(unwrap(ReturnType
), Tys
, IsVarArg
!= 0));
284 LLVMBool
LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy
) {
285 return unwrap
<FunctionType
>(FunctionTy
)->isVarArg();
288 LLVMTypeRef
LLVMGetReturnType(LLVMTypeRef FunctionTy
) {
289 return wrap(unwrap
<FunctionType
>(FunctionTy
)->getReturnType());
292 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy
) {
293 return unwrap
<FunctionType
>(FunctionTy
)->getNumParams();
296 void LLVMGetParamTypes(LLVMTypeRef FunctionTy
, LLVMTypeRef
*Dest
) {
297 FunctionType
*Ty
= unwrap
<FunctionType
>(FunctionTy
);
298 for (FunctionType::param_iterator I
= Ty
->param_begin(),
299 E
= Ty
->param_end(); I
!= E
; ++I
)
303 /*--.. Operations on struct types ..........................................--*/
305 LLVMTypeRef
LLVMStructTypeInContext(LLVMContextRef C
, LLVMTypeRef
*ElementTypes
,
306 unsigned ElementCount
, LLVMBool Packed
) {
307 std::vector
<const Type
*> Tys
;
308 for (LLVMTypeRef
*I
= ElementTypes
,
309 *E
= ElementTypes
+ ElementCount
; I
!= E
; ++I
)
310 Tys
.push_back(unwrap(*I
));
312 return wrap(StructType::get(*unwrap(C
), Tys
, Packed
!= 0));
315 LLVMTypeRef
LLVMStructType(LLVMTypeRef
*ElementTypes
,
316 unsigned ElementCount
, LLVMBool Packed
) {
317 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes
,
318 ElementCount
, Packed
);
322 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy
) {
323 return unwrap
<StructType
>(StructTy
)->getNumElements();
326 void LLVMGetStructElementTypes(LLVMTypeRef StructTy
, LLVMTypeRef
*Dest
) {
327 StructType
*Ty
= unwrap
<StructType
>(StructTy
);
328 for (FunctionType::param_iterator I
= Ty
->element_begin(),
329 E
= Ty
->element_end(); I
!= E
; ++I
)
333 LLVMBool
LLVMIsPackedStruct(LLVMTypeRef StructTy
) {
334 return unwrap
<StructType
>(StructTy
)->isPacked();
337 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
339 LLVMTypeRef
LLVMArrayType(LLVMTypeRef ElementType
, unsigned ElementCount
) {
340 return wrap(ArrayType::get(unwrap(ElementType
), ElementCount
));
343 LLVMTypeRef
LLVMPointerType(LLVMTypeRef ElementType
, unsigned AddressSpace
) {
344 return wrap(PointerType::get(unwrap(ElementType
), AddressSpace
));
347 LLVMTypeRef
LLVMVectorType(LLVMTypeRef ElementType
, unsigned ElementCount
) {
348 return wrap(VectorType::get(unwrap(ElementType
), ElementCount
));
351 LLVMTypeRef
LLVMGetElementType(LLVMTypeRef Ty
) {
352 return wrap(unwrap
<SequentialType
>(Ty
)->getElementType());
355 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy
) {
356 return unwrap
<ArrayType
>(ArrayTy
)->getNumElements();
359 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy
) {
360 return unwrap
<PointerType
>(PointerTy
)->getAddressSpace();
363 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy
) {
364 return unwrap
<VectorType
>(VectorTy
)->getNumElements();
367 /*--.. Operations on other types ...........................................--*/
369 LLVMTypeRef
LLVMVoidTypeInContext(LLVMContextRef C
) {
370 return wrap(Type::getVoidTy(*unwrap(C
)));
372 LLVMTypeRef
LLVMLabelTypeInContext(LLVMContextRef C
) {
373 return wrap(Type::getLabelTy(*unwrap(C
)));
375 LLVMTypeRef
LLVMOpaqueTypeInContext(LLVMContextRef C
) {
376 return wrap(OpaqueType::get(*unwrap(C
)));
379 LLVMTypeRef
LLVMVoidType(void) {
380 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
382 LLVMTypeRef
LLVMLabelType(void) {
383 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
385 LLVMTypeRef
LLVMOpaqueType(void) {
386 return LLVMOpaqueTypeInContext(LLVMGetGlobalContext());
389 /*--.. Operations on type handles ..........................................--*/
391 LLVMTypeHandleRef
LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy
) {
392 return wrap(new PATypeHolder(unwrap(PotentiallyAbstractTy
)));
395 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle
) {
396 delete unwrap(TypeHandle
);
399 LLVMTypeRef
LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle
) {
400 return wrap(unwrap(TypeHandle
)->get());
403 void LLVMRefineType(LLVMTypeRef AbstractTy
, LLVMTypeRef ConcreteTy
) {
404 unwrap
<DerivedType
>(AbstractTy
)->refineAbstractTypeTo(unwrap(ConcreteTy
));
408 /*===-- Operations on values ----------------------------------------------===*/
410 /*--.. Operations on all values ............................................--*/
412 LLVMTypeRef
LLVMTypeOf(LLVMValueRef Val
) {
413 return wrap(unwrap(Val
)->getType());
416 const char *LLVMGetValueName(LLVMValueRef Val
) {
417 return unwrap(Val
)->getName().data();
420 void LLVMSetValueName(LLVMValueRef Val
, const char *Name
) {
421 unwrap(Val
)->setName(Name
);
424 void LLVMDumpValue(LLVMValueRef Val
) {
428 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal
, LLVMValueRef NewVal
) {
429 unwrap(OldVal
)->replaceAllUsesWith(unwrap(NewVal
));
432 int LLVMHasMetadata(LLVMValueRef Inst
) {
433 return unwrap
<Instruction
>(Inst
)->hasMetadata();
436 LLVMValueRef
LLVMGetMetadata(LLVMValueRef Inst
, unsigned KindID
) {
437 return wrap(unwrap
<Instruction
>(Inst
)->getMetadata(KindID
));
440 void LLVMSetMetadata(LLVMValueRef Inst
, unsigned KindID
, LLVMValueRef MD
) {
441 unwrap
<Instruction
>(Inst
)->setMetadata(KindID
, MD
? unwrap
<MDNode
>(MD
) : NULL
);
444 /*--.. Conversion functions ................................................--*/
446 #define LLVM_DEFINE_VALUE_CAST(name) \
447 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
448 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
451 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST
)
453 /*--.. Operations on Uses ..................................................--*/
454 LLVMUseRef
LLVMGetFirstUse(LLVMValueRef Val
) {
455 Value
*V
= unwrap(Val
);
456 Value::use_iterator I
= V
->use_begin();
457 if (I
== V
->use_end())
459 return wrap(&(I
.getUse()));
462 LLVMUseRef
LLVMGetNextUse(LLVMUseRef U
) {
463 Use
*Next
= unwrap(U
)->getNext();
469 LLVMValueRef
LLVMGetUser(LLVMUseRef U
) {
470 return wrap(unwrap(U
)->getUser());
473 LLVMValueRef
LLVMGetUsedValue(LLVMUseRef U
) {
474 return wrap(unwrap(U
)->get());
477 /*--.. Operations on Users .................................................--*/
478 LLVMValueRef
LLVMGetOperand(LLVMValueRef Val
, unsigned Index
) {
479 return wrap(unwrap
<User
>(Val
)->getOperand(Index
));
482 void LLVMSetOperand(LLVMValueRef Val
, unsigned Index
, LLVMValueRef Op
) {
483 unwrap
<User
>(Val
)->setOperand(Index
, unwrap(Op
));
486 int LLVMGetNumOperands(LLVMValueRef Val
) {
487 return unwrap
<User
>(Val
)->getNumOperands();
490 /*--.. Operations on constants of any type .................................--*/
492 LLVMValueRef
LLVMConstNull(LLVMTypeRef Ty
) {
493 return wrap(Constant::getNullValue(unwrap(Ty
)));
496 LLVMValueRef
LLVMConstAllOnes(LLVMTypeRef Ty
) {
497 return wrap(Constant::getAllOnesValue(unwrap(Ty
)));
500 LLVMValueRef
LLVMGetUndef(LLVMTypeRef Ty
) {
501 return wrap(UndefValue::get(unwrap(Ty
)));
504 LLVMBool
LLVMIsConstant(LLVMValueRef Ty
) {
505 return isa
<Constant
>(unwrap(Ty
));
508 LLVMBool
LLVMIsNull(LLVMValueRef Val
) {
509 if (Constant
*C
= dyn_cast
<Constant
>(unwrap(Val
)))
510 return C
->isNullValue();
514 LLVMBool
LLVMIsUndef(LLVMValueRef Val
) {
515 return isa
<UndefValue
>(unwrap(Val
));
518 LLVMValueRef
LLVMConstPointerNull(LLVMTypeRef Ty
) {
520 wrap(ConstantPointerNull::get(unwrap
<PointerType
>(Ty
)));
523 /*--.. Operations on metadata nodes ........................................--*/
525 LLVMValueRef
LLVMMDStringInContext(LLVMContextRef C
, const char *Str
,
527 return wrap(MDString::get(*unwrap(C
), StringRef(Str
, SLen
)));
530 LLVMValueRef
LLVMMDString(const char *Str
, unsigned SLen
) {
531 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str
, SLen
);
534 LLVMValueRef
LLVMMDNodeInContext(LLVMContextRef C
, LLVMValueRef
*Vals
,
536 return wrap(MDNode::get(*unwrap(C
), unwrap
<Value
>(Vals
, Count
), Count
));
539 LLVMValueRef
LLVMMDNode(LLVMValueRef
*Vals
, unsigned Count
) {
540 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals
, Count
);
543 /*--.. Operations on scalar constants ......................................--*/
545 LLVMValueRef
LLVMConstInt(LLVMTypeRef IntTy
, unsigned long long N
,
546 LLVMBool SignExtend
) {
547 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), N
, SignExtend
!= 0));
550 LLVMValueRef
LLVMConstIntOfString(LLVMTypeRef IntTy
, const char Str
[],
552 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), StringRef(Str
),
556 LLVMValueRef
LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy
, const char Str
[],
557 unsigned SLen
, uint8_t Radix
) {
558 return wrap(ConstantInt::get(unwrap
<IntegerType
>(IntTy
), StringRef(Str
, SLen
),
562 LLVMValueRef
LLVMConstReal(LLVMTypeRef RealTy
, double N
) {
563 return wrap(ConstantFP::get(unwrap(RealTy
), N
));
566 LLVMValueRef
LLVMConstRealOfString(LLVMTypeRef RealTy
, const char *Text
) {
567 return wrap(ConstantFP::get(unwrap(RealTy
), StringRef(Text
)));
570 LLVMValueRef
LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy
, const char Str
[],
572 return wrap(ConstantFP::get(unwrap(RealTy
), StringRef(Str
, SLen
)));
575 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal
) {
576 return unwrap
<ConstantInt
>(ConstantVal
)->getZExtValue();
579 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal
) {
580 return unwrap
<ConstantInt
>(ConstantVal
)->getSExtValue();
583 /*--.. Operations on composite constants ...................................--*/
585 LLVMValueRef
LLVMConstStringInContext(LLVMContextRef C
, const char *Str
,
587 LLVMBool DontNullTerminate
) {
588 /* Inverted the sense of AddNull because ', 0)' is a
589 better mnemonic for null termination than ', 1)'. */
590 return wrap(ConstantArray::get(*unwrap(C
), StringRef(Str
, Length
),
591 DontNullTerminate
== 0));
593 LLVMValueRef
LLVMConstStructInContext(LLVMContextRef C
,
594 LLVMValueRef
*ConstantVals
,
595 unsigned Count
, LLVMBool Packed
) {
596 return wrap(ConstantStruct::get(*unwrap(C
),
597 unwrap
<Constant
>(ConstantVals
, Count
),
598 Count
, Packed
!= 0));
601 LLVMValueRef
LLVMConstString(const char *Str
, unsigned Length
,
602 LLVMBool DontNullTerminate
) {
603 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str
, Length
,
606 LLVMValueRef
LLVMConstArray(LLVMTypeRef ElementTy
,
607 LLVMValueRef
*ConstantVals
, unsigned Length
) {
608 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy
), Length
),
609 unwrap
<Constant
>(ConstantVals
, Length
),
612 LLVMValueRef
LLVMConstStruct(LLVMValueRef
*ConstantVals
, unsigned Count
,
614 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals
, Count
,
617 LLVMValueRef
LLVMConstVector(LLVMValueRef
*ScalarConstantVals
, unsigned Size
) {
618 return wrap(ConstantVector::get(
619 unwrap
<Constant
>(ScalarConstantVals
, Size
), Size
));
621 /*--.. Constant expressions ................................................--*/
623 LLVMOpcode
LLVMGetConstOpcode(LLVMValueRef ConstantVal
) {
624 return (LLVMOpcode
)unwrap
<ConstantExpr
>(ConstantVal
)->getOpcode();
627 LLVMValueRef
LLVMAlignOf(LLVMTypeRef Ty
) {
628 return wrap(ConstantExpr::getAlignOf(unwrap(Ty
)));
631 LLVMValueRef
LLVMSizeOf(LLVMTypeRef Ty
) {
632 return wrap(ConstantExpr::getSizeOf(unwrap(Ty
)));
635 LLVMValueRef
LLVMConstNeg(LLVMValueRef ConstantVal
) {
636 return wrap(ConstantExpr::getNeg(
637 unwrap
<Constant
>(ConstantVal
)));
640 LLVMValueRef
LLVMConstNSWNeg(LLVMValueRef ConstantVal
) {
641 return wrap(ConstantExpr::getNSWNeg(
642 unwrap
<Constant
>(ConstantVal
)));
645 LLVMValueRef
LLVMConstNUWNeg(LLVMValueRef ConstantVal
) {
646 return wrap(ConstantExpr::getNUWNeg(
647 unwrap
<Constant
>(ConstantVal
)));
651 LLVMValueRef
LLVMConstFNeg(LLVMValueRef ConstantVal
) {
652 return wrap(ConstantExpr::getFNeg(
653 unwrap
<Constant
>(ConstantVal
)));
656 LLVMValueRef
LLVMConstNot(LLVMValueRef ConstantVal
) {
657 return wrap(ConstantExpr::getNot(
658 unwrap
<Constant
>(ConstantVal
)));
661 LLVMValueRef
LLVMConstAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
662 return wrap(ConstantExpr::getAdd(
663 unwrap
<Constant
>(LHSConstant
),
664 unwrap
<Constant
>(RHSConstant
)));
667 LLVMValueRef
LLVMConstNSWAdd(LLVMValueRef LHSConstant
,
668 LLVMValueRef RHSConstant
) {
669 return wrap(ConstantExpr::getNSWAdd(
670 unwrap
<Constant
>(LHSConstant
),
671 unwrap
<Constant
>(RHSConstant
)));
674 LLVMValueRef
LLVMConstNUWAdd(LLVMValueRef LHSConstant
,
675 LLVMValueRef RHSConstant
) {
676 return wrap(ConstantExpr::getNUWAdd(
677 unwrap
<Constant
>(LHSConstant
),
678 unwrap
<Constant
>(RHSConstant
)));
681 LLVMValueRef
LLVMConstFAdd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
682 return wrap(ConstantExpr::getFAdd(
683 unwrap
<Constant
>(LHSConstant
),
684 unwrap
<Constant
>(RHSConstant
)));
687 LLVMValueRef
LLVMConstSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
688 return wrap(ConstantExpr::getSub(
689 unwrap
<Constant
>(LHSConstant
),
690 unwrap
<Constant
>(RHSConstant
)));
693 LLVMValueRef
LLVMConstNSWSub(LLVMValueRef LHSConstant
,
694 LLVMValueRef RHSConstant
) {
695 return wrap(ConstantExpr::getNSWSub(
696 unwrap
<Constant
>(LHSConstant
),
697 unwrap
<Constant
>(RHSConstant
)));
700 LLVMValueRef
LLVMConstNUWSub(LLVMValueRef LHSConstant
,
701 LLVMValueRef RHSConstant
) {
702 return wrap(ConstantExpr::getNUWSub(
703 unwrap
<Constant
>(LHSConstant
),
704 unwrap
<Constant
>(RHSConstant
)));
707 LLVMValueRef
LLVMConstFSub(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
708 return wrap(ConstantExpr::getFSub(unwrap
<Constant
>(LHSConstant
),
709 unwrap
<Constant
>(RHSConstant
)));
712 LLVMValueRef
LLVMConstMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
713 return wrap(ConstantExpr::getMul(
714 unwrap
<Constant
>(LHSConstant
),
715 unwrap
<Constant
>(RHSConstant
)));
718 LLVMValueRef
LLVMConstNSWMul(LLVMValueRef LHSConstant
,
719 LLVMValueRef RHSConstant
) {
720 return wrap(ConstantExpr::getNSWMul(
721 unwrap
<Constant
>(LHSConstant
),
722 unwrap
<Constant
>(RHSConstant
)));
725 LLVMValueRef
LLVMConstNUWMul(LLVMValueRef LHSConstant
,
726 LLVMValueRef RHSConstant
) {
727 return wrap(ConstantExpr::getNUWMul(
728 unwrap
<Constant
>(LHSConstant
),
729 unwrap
<Constant
>(RHSConstant
)));
732 LLVMValueRef
LLVMConstFMul(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
733 return wrap(ConstantExpr::getFMul(
734 unwrap
<Constant
>(LHSConstant
),
735 unwrap
<Constant
>(RHSConstant
)));
738 LLVMValueRef
LLVMConstUDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
739 return wrap(ConstantExpr::getUDiv(
740 unwrap
<Constant
>(LHSConstant
),
741 unwrap
<Constant
>(RHSConstant
)));
744 LLVMValueRef
LLVMConstSDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
745 return wrap(ConstantExpr::getSDiv(
746 unwrap
<Constant
>(LHSConstant
),
747 unwrap
<Constant
>(RHSConstant
)));
750 LLVMValueRef
LLVMConstExactSDiv(LLVMValueRef LHSConstant
,
751 LLVMValueRef RHSConstant
) {
752 return wrap(ConstantExpr::getExactSDiv(
753 unwrap
<Constant
>(LHSConstant
),
754 unwrap
<Constant
>(RHSConstant
)));
757 LLVMValueRef
LLVMConstFDiv(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
758 return wrap(ConstantExpr::getFDiv(
759 unwrap
<Constant
>(LHSConstant
),
760 unwrap
<Constant
>(RHSConstant
)));
763 LLVMValueRef
LLVMConstURem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
764 return wrap(ConstantExpr::getURem(
765 unwrap
<Constant
>(LHSConstant
),
766 unwrap
<Constant
>(RHSConstant
)));
769 LLVMValueRef
LLVMConstSRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
770 return wrap(ConstantExpr::getSRem(
771 unwrap
<Constant
>(LHSConstant
),
772 unwrap
<Constant
>(RHSConstant
)));
775 LLVMValueRef
LLVMConstFRem(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
776 return wrap(ConstantExpr::getFRem(
777 unwrap
<Constant
>(LHSConstant
),
778 unwrap
<Constant
>(RHSConstant
)));
781 LLVMValueRef
LLVMConstAnd(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
782 return wrap(ConstantExpr::getAnd(
783 unwrap
<Constant
>(LHSConstant
),
784 unwrap
<Constant
>(RHSConstant
)));
787 LLVMValueRef
LLVMConstOr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
788 return wrap(ConstantExpr::getOr(
789 unwrap
<Constant
>(LHSConstant
),
790 unwrap
<Constant
>(RHSConstant
)));
793 LLVMValueRef
LLVMConstXor(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
794 return wrap(ConstantExpr::getXor(
795 unwrap
<Constant
>(LHSConstant
),
796 unwrap
<Constant
>(RHSConstant
)));
799 LLVMValueRef
LLVMConstICmp(LLVMIntPredicate Predicate
,
800 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
801 return wrap(ConstantExpr::getICmp(Predicate
,
802 unwrap
<Constant
>(LHSConstant
),
803 unwrap
<Constant
>(RHSConstant
)));
806 LLVMValueRef
LLVMConstFCmp(LLVMRealPredicate Predicate
,
807 LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
808 return wrap(ConstantExpr::getFCmp(Predicate
,
809 unwrap
<Constant
>(LHSConstant
),
810 unwrap
<Constant
>(RHSConstant
)));
813 LLVMValueRef
LLVMConstShl(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
814 return wrap(ConstantExpr::getShl(
815 unwrap
<Constant
>(LHSConstant
),
816 unwrap
<Constant
>(RHSConstant
)));
819 LLVMValueRef
LLVMConstLShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
820 return wrap(ConstantExpr::getLShr(
821 unwrap
<Constant
>(LHSConstant
),
822 unwrap
<Constant
>(RHSConstant
)));
825 LLVMValueRef
LLVMConstAShr(LLVMValueRef LHSConstant
, LLVMValueRef RHSConstant
) {
826 return wrap(ConstantExpr::getAShr(
827 unwrap
<Constant
>(LHSConstant
),
828 unwrap
<Constant
>(RHSConstant
)));
831 LLVMValueRef
LLVMConstGEP(LLVMValueRef ConstantVal
,
832 LLVMValueRef
*ConstantIndices
, unsigned NumIndices
) {
833 return wrap(ConstantExpr::getGetElementPtr(
834 unwrap
<Constant
>(ConstantVal
),
835 unwrap
<Constant
>(ConstantIndices
,
840 LLVMValueRef
LLVMConstInBoundsGEP(LLVMValueRef ConstantVal
,
841 LLVMValueRef
*ConstantIndices
,
842 unsigned NumIndices
) {
843 Constant
* Val
= unwrap
<Constant
>(ConstantVal
);
844 Constant
** Idxs
= unwrap
<Constant
>(ConstantIndices
, NumIndices
);
845 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val
, Idxs
, NumIndices
));
848 LLVMValueRef
LLVMConstTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
849 return wrap(ConstantExpr::getTrunc(
850 unwrap
<Constant
>(ConstantVal
),
854 LLVMValueRef
LLVMConstSExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
855 return wrap(ConstantExpr::getSExt(
856 unwrap
<Constant
>(ConstantVal
),
860 LLVMValueRef
LLVMConstZExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
861 return wrap(ConstantExpr::getZExt(
862 unwrap
<Constant
>(ConstantVal
),
866 LLVMValueRef
LLVMConstFPTrunc(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
867 return wrap(ConstantExpr::getFPTrunc(
868 unwrap
<Constant
>(ConstantVal
),
872 LLVMValueRef
LLVMConstFPExt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
873 return wrap(ConstantExpr::getFPExtend(
874 unwrap
<Constant
>(ConstantVal
),
878 LLVMValueRef
LLVMConstUIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
879 return wrap(ConstantExpr::getUIToFP(
880 unwrap
<Constant
>(ConstantVal
),
884 LLVMValueRef
LLVMConstSIToFP(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
885 return wrap(ConstantExpr::getSIToFP(unwrap
<Constant
>(ConstantVal
),
889 LLVMValueRef
LLVMConstFPToUI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
890 return wrap(ConstantExpr::getFPToUI(unwrap
<Constant
>(ConstantVal
),
894 LLVMValueRef
LLVMConstFPToSI(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
895 return wrap(ConstantExpr::getFPToSI(
896 unwrap
<Constant
>(ConstantVal
),
900 LLVMValueRef
LLVMConstPtrToInt(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
901 return wrap(ConstantExpr::getPtrToInt(
902 unwrap
<Constant
>(ConstantVal
),
906 LLVMValueRef
LLVMConstIntToPtr(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
907 return wrap(ConstantExpr::getIntToPtr(
908 unwrap
<Constant
>(ConstantVal
),
912 LLVMValueRef
LLVMConstBitCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
913 return wrap(ConstantExpr::getBitCast(
914 unwrap
<Constant
>(ConstantVal
),
918 LLVMValueRef
LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal
,
919 LLVMTypeRef ToType
) {
920 return wrap(ConstantExpr::getZExtOrBitCast(
921 unwrap
<Constant
>(ConstantVal
),
925 LLVMValueRef
LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal
,
926 LLVMTypeRef ToType
) {
927 return wrap(ConstantExpr::getSExtOrBitCast(
928 unwrap
<Constant
>(ConstantVal
),
932 LLVMValueRef
LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal
,
933 LLVMTypeRef ToType
) {
934 return wrap(ConstantExpr::getTruncOrBitCast(
935 unwrap
<Constant
>(ConstantVal
),
939 LLVMValueRef
LLVMConstPointerCast(LLVMValueRef ConstantVal
,
940 LLVMTypeRef ToType
) {
941 return wrap(ConstantExpr::getPointerCast(
942 unwrap
<Constant
>(ConstantVal
),
946 LLVMValueRef
LLVMConstIntCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
,
948 return wrap(ConstantExpr::getIntegerCast(
949 unwrap
<Constant
>(ConstantVal
),
954 LLVMValueRef
LLVMConstFPCast(LLVMValueRef ConstantVal
, LLVMTypeRef ToType
) {
955 return wrap(ConstantExpr::getFPCast(
956 unwrap
<Constant
>(ConstantVal
),
960 LLVMValueRef
LLVMConstSelect(LLVMValueRef ConstantCondition
,
961 LLVMValueRef ConstantIfTrue
,
962 LLVMValueRef ConstantIfFalse
) {
963 return wrap(ConstantExpr::getSelect(
964 unwrap
<Constant
>(ConstantCondition
),
965 unwrap
<Constant
>(ConstantIfTrue
),
966 unwrap
<Constant
>(ConstantIfFalse
)));
969 LLVMValueRef
LLVMConstExtractElement(LLVMValueRef VectorConstant
,
970 LLVMValueRef IndexConstant
) {
971 return wrap(ConstantExpr::getExtractElement(
972 unwrap
<Constant
>(VectorConstant
),
973 unwrap
<Constant
>(IndexConstant
)));
976 LLVMValueRef
LLVMConstInsertElement(LLVMValueRef VectorConstant
,
977 LLVMValueRef ElementValueConstant
,
978 LLVMValueRef IndexConstant
) {
979 return wrap(ConstantExpr::getInsertElement(
980 unwrap
<Constant
>(VectorConstant
),
981 unwrap
<Constant
>(ElementValueConstant
),
982 unwrap
<Constant
>(IndexConstant
)));
985 LLVMValueRef
LLVMConstShuffleVector(LLVMValueRef VectorAConstant
,
986 LLVMValueRef VectorBConstant
,
987 LLVMValueRef MaskConstant
) {
988 return wrap(ConstantExpr::getShuffleVector(
989 unwrap
<Constant
>(VectorAConstant
),
990 unwrap
<Constant
>(VectorBConstant
),
991 unwrap
<Constant
>(MaskConstant
)));
994 LLVMValueRef
LLVMConstExtractValue(LLVMValueRef AggConstant
, unsigned *IdxList
,
996 return wrap(ConstantExpr::getExtractValue(
997 unwrap
<Constant
>(AggConstant
),
1001 LLVMValueRef
LLVMConstInsertValue(LLVMValueRef AggConstant
,
1002 LLVMValueRef ElementValueConstant
,
1003 unsigned *IdxList
, unsigned NumIdx
) {
1004 return wrap(ConstantExpr::getInsertValue(
1005 unwrap
<Constant
>(AggConstant
),
1006 unwrap
<Constant
>(ElementValueConstant
),
1010 LLVMValueRef
LLVMConstInlineAsm(LLVMTypeRef Ty
, const char *AsmString
,
1011 const char *Constraints
,
1012 LLVMBool HasSideEffects
,
1013 LLVMBool IsAlignStack
) {
1014 return wrap(InlineAsm::get(dyn_cast
<FunctionType
>(unwrap(Ty
)), AsmString
,
1015 Constraints
, HasSideEffects
, IsAlignStack
));
1018 LLVMValueRef
LLVMBlockAddress(LLVMValueRef F
, LLVMBasicBlockRef BB
) {
1019 return wrap(BlockAddress::get(unwrap
<Function
>(F
), unwrap(BB
)));
1022 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1024 LLVMModuleRef
LLVMGetGlobalParent(LLVMValueRef Global
) {
1025 return wrap(unwrap
<GlobalValue
>(Global
)->getParent());
1028 LLVMBool
LLVMIsDeclaration(LLVMValueRef Global
) {
1029 return unwrap
<GlobalValue
>(Global
)->isDeclaration();
1032 LLVMLinkage
LLVMGetLinkage(LLVMValueRef Global
) {
1033 switch (unwrap
<GlobalValue
>(Global
)->getLinkage()) {
1035 assert(false && "Unhandled Linkage Type.");
1036 case GlobalValue::ExternalLinkage
:
1037 return LLVMExternalLinkage
;
1038 case GlobalValue::AvailableExternallyLinkage
:
1039 return LLVMAvailableExternallyLinkage
;
1040 case GlobalValue::LinkOnceAnyLinkage
:
1041 return LLVMLinkOnceAnyLinkage
;
1042 case GlobalValue::LinkOnceODRLinkage
:
1043 return LLVMLinkOnceODRLinkage
;
1044 case GlobalValue::WeakAnyLinkage
:
1045 return LLVMWeakAnyLinkage
;
1046 case GlobalValue::WeakODRLinkage
:
1047 return LLVMWeakODRLinkage
;
1048 case GlobalValue::AppendingLinkage
:
1049 return LLVMAppendingLinkage
;
1050 case GlobalValue::InternalLinkage
:
1051 return LLVMInternalLinkage
;
1052 case GlobalValue::PrivateLinkage
:
1053 return LLVMPrivateLinkage
;
1054 case GlobalValue::LinkerPrivateLinkage
:
1055 return LLVMLinkerPrivateLinkage
;
1056 case GlobalValue::LinkerPrivateWeakLinkage
:
1057 return LLVMLinkerPrivateWeakLinkage
;
1058 case GlobalValue::LinkerPrivateWeakDefAutoLinkage
:
1059 return LLVMLinkerPrivateWeakDefAutoLinkage
;
1060 case GlobalValue::DLLImportLinkage
:
1061 return LLVMDLLImportLinkage
;
1062 case GlobalValue::DLLExportLinkage
:
1063 return LLVMDLLExportLinkage
;
1064 case GlobalValue::ExternalWeakLinkage
:
1065 return LLVMExternalWeakLinkage
;
1066 case GlobalValue::CommonLinkage
:
1067 return LLVMCommonLinkage
;
1070 // Should never get here.
1071 return static_cast<LLVMLinkage
>(0);
1074 void LLVMSetLinkage(LLVMValueRef Global
, LLVMLinkage Linkage
) {
1075 GlobalValue
*GV
= unwrap
<GlobalValue
>(Global
);
1079 assert(false && "Unhandled Linkage Type.");
1080 case LLVMExternalLinkage
:
1081 GV
->setLinkage(GlobalValue::ExternalLinkage
);
1083 case LLVMAvailableExternallyLinkage
:
1084 GV
->setLinkage(GlobalValue::AvailableExternallyLinkage
);
1086 case LLVMLinkOnceAnyLinkage
:
1087 GV
->setLinkage(GlobalValue::LinkOnceAnyLinkage
);
1089 case LLVMLinkOnceODRLinkage
:
1090 GV
->setLinkage(GlobalValue::LinkOnceODRLinkage
);
1092 case LLVMWeakAnyLinkage
:
1093 GV
->setLinkage(GlobalValue::WeakAnyLinkage
);
1095 case LLVMWeakODRLinkage
:
1096 GV
->setLinkage(GlobalValue::WeakODRLinkage
);
1098 case LLVMAppendingLinkage
:
1099 GV
->setLinkage(GlobalValue::AppendingLinkage
);
1101 case LLVMInternalLinkage
:
1102 GV
->setLinkage(GlobalValue::InternalLinkage
);
1104 case LLVMPrivateLinkage
:
1105 GV
->setLinkage(GlobalValue::PrivateLinkage
);
1107 case LLVMLinkerPrivateLinkage
:
1108 GV
->setLinkage(GlobalValue::LinkerPrivateLinkage
);
1110 case LLVMLinkerPrivateWeakLinkage
:
1111 GV
->setLinkage(GlobalValue::LinkerPrivateWeakLinkage
);
1113 case LLVMLinkerPrivateWeakDefAutoLinkage
:
1114 GV
->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage
);
1116 case LLVMDLLImportLinkage
:
1117 GV
->setLinkage(GlobalValue::DLLImportLinkage
);
1119 case LLVMDLLExportLinkage
:
1120 GV
->setLinkage(GlobalValue::DLLExportLinkage
);
1122 case LLVMExternalWeakLinkage
:
1123 GV
->setLinkage(GlobalValue::ExternalWeakLinkage
);
1125 case LLVMGhostLinkage
:
1127 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1129 case LLVMCommonLinkage
:
1130 GV
->setLinkage(GlobalValue::CommonLinkage
);
1135 const char *LLVMGetSection(LLVMValueRef Global
) {
1136 return unwrap
<GlobalValue
>(Global
)->getSection().c_str();
1139 void LLVMSetSection(LLVMValueRef Global
, const char *Section
) {
1140 unwrap
<GlobalValue
>(Global
)->setSection(Section
);
1143 LLVMVisibility
LLVMGetVisibility(LLVMValueRef Global
) {
1144 return static_cast<LLVMVisibility
>(
1145 unwrap
<GlobalValue
>(Global
)->getVisibility());
1148 void LLVMSetVisibility(LLVMValueRef Global
, LLVMVisibility Viz
) {
1149 unwrap
<GlobalValue
>(Global
)
1150 ->setVisibility(static_cast<GlobalValue::VisibilityTypes
>(Viz
));
1153 unsigned LLVMGetAlignment(LLVMValueRef Global
) {
1154 return unwrap
<GlobalValue
>(Global
)->getAlignment();
1157 void LLVMSetAlignment(LLVMValueRef Global
, unsigned Bytes
) {
1158 unwrap
<GlobalValue
>(Global
)->setAlignment(Bytes
);
1161 /*--.. Operations on global variables ......................................--*/
1163 LLVMValueRef
LLVMAddGlobal(LLVMModuleRef M
, LLVMTypeRef Ty
, const char *Name
) {
1164 return wrap(new GlobalVariable(*unwrap(M
), unwrap(Ty
), false,
1165 GlobalValue::ExternalLinkage
, 0, Name
));
1168 LLVMValueRef
LLVMAddGlobalInAddressSpace(LLVMModuleRef M
, LLVMTypeRef Ty
,
1170 unsigned AddressSpace
) {
1171 return wrap(new GlobalVariable(*unwrap(M
), unwrap(Ty
), false,
1172 GlobalValue::ExternalLinkage
, 0, Name
, 0,
1173 false, AddressSpace
));
1176 LLVMValueRef
LLVMGetNamedGlobal(LLVMModuleRef M
, const char *Name
) {
1177 return wrap(unwrap(M
)->getNamedGlobal(Name
));
1180 LLVMValueRef
LLVMGetFirstGlobal(LLVMModuleRef M
) {
1181 Module
*Mod
= unwrap(M
);
1182 Module::global_iterator I
= Mod
->global_begin();
1183 if (I
== Mod
->global_end())
1188 LLVMValueRef
LLVMGetLastGlobal(LLVMModuleRef M
) {
1189 Module
*Mod
= unwrap(M
);
1190 Module::global_iterator I
= Mod
->global_end();
1191 if (I
== Mod
->global_begin())
1196 LLVMValueRef
LLVMGetNextGlobal(LLVMValueRef GlobalVar
) {
1197 GlobalVariable
*GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1198 Module::global_iterator I
= GV
;
1199 if (++I
== GV
->getParent()->global_end())
1204 LLVMValueRef
LLVMGetPreviousGlobal(LLVMValueRef GlobalVar
) {
1205 GlobalVariable
*GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1206 Module::global_iterator I
= GV
;
1207 if (I
== GV
->getParent()->global_begin())
1212 void LLVMDeleteGlobal(LLVMValueRef GlobalVar
) {
1213 unwrap
<GlobalVariable
>(GlobalVar
)->eraseFromParent();
1216 LLVMValueRef
LLVMGetInitializer(LLVMValueRef GlobalVar
) {
1217 GlobalVariable
* GV
= unwrap
<GlobalVariable
>(GlobalVar
);
1218 if ( !GV
->hasInitializer() )
1220 return wrap(GV
->getInitializer());
1223 void LLVMSetInitializer(LLVMValueRef GlobalVar
, LLVMValueRef ConstantVal
) {
1224 unwrap
<GlobalVariable
>(GlobalVar
)
1225 ->setInitializer(unwrap
<Constant
>(ConstantVal
));
1228 LLVMBool
LLVMIsThreadLocal(LLVMValueRef GlobalVar
) {
1229 return unwrap
<GlobalVariable
>(GlobalVar
)->isThreadLocal();
1232 void LLVMSetThreadLocal(LLVMValueRef GlobalVar
, LLVMBool IsThreadLocal
) {
1233 unwrap
<GlobalVariable
>(GlobalVar
)->setThreadLocal(IsThreadLocal
!= 0);
1236 LLVMBool
LLVMIsGlobalConstant(LLVMValueRef GlobalVar
) {
1237 return unwrap
<GlobalVariable
>(GlobalVar
)->isConstant();
1240 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar
, LLVMBool IsConstant
) {
1241 unwrap
<GlobalVariable
>(GlobalVar
)->setConstant(IsConstant
!= 0);
1244 /*--.. Operations on aliases ......................................--*/
1246 LLVMValueRef
LLVMAddAlias(LLVMModuleRef M
, LLVMTypeRef Ty
, LLVMValueRef Aliasee
,
1248 return wrap(new GlobalAlias(unwrap(Ty
), GlobalValue::ExternalLinkage
, Name
,
1249 unwrap
<Constant
>(Aliasee
), unwrap (M
)));
1252 /*--.. Operations on functions .............................................--*/
1254 LLVMValueRef
LLVMAddFunction(LLVMModuleRef M
, const char *Name
,
1255 LLVMTypeRef FunctionTy
) {
1256 return wrap(Function::Create(unwrap
<FunctionType
>(FunctionTy
),
1257 GlobalValue::ExternalLinkage
, Name
, unwrap(M
)));
1260 LLVMValueRef
LLVMGetNamedFunction(LLVMModuleRef M
, const char *Name
) {
1261 return wrap(unwrap(M
)->getFunction(Name
));
1264 LLVMValueRef
LLVMGetFirstFunction(LLVMModuleRef M
) {
1265 Module
*Mod
= unwrap(M
);
1266 Module::iterator I
= Mod
->begin();
1267 if (I
== Mod
->end())
1272 LLVMValueRef
LLVMGetLastFunction(LLVMModuleRef M
) {
1273 Module
*Mod
= unwrap(M
);
1274 Module::iterator I
= Mod
->end();
1275 if (I
== Mod
->begin())
1280 LLVMValueRef
LLVMGetNextFunction(LLVMValueRef Fn
) {
1281 Function
*Func
= unwrap
<Function
>(Fn
);
1282 Module::iterator I
= Func
;
1283 if (++I
== Func
->getParent()->end())
1288 LLVMValueRef
LLVMGetPreviousFunction(LLVMValueRef Fn
) {
1289 Function
*Func
= unwrap
<Function
>(Fn
);
1290 Module::iterator I
= Func
;
1291 if (I
== Func
->getParent()->begin())
1296 void LLVMDeleteFunction(LLVMValueRef Fn
) {
1297 unwrap
<Function
>(Fn
)->eraseFromParent();
1300 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn
) {
1301 if (Function
*F
= dyn_cast
<Function
>(unwrap(Fn
)))
1302 return F
->getIntrinsicID();
1306 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn
) {
1307 return unwrap
<Function
>(Fn
)->getCallingConv();
1310 void LLVMSetFunctionCallConv(LLVMValueRef Fn
, unsigned CC
) {
1311 return unwrap
<Function
>(Fn
)->setCallingConv(
1312 static_cast<CallingConv::ID
>(CC
));
1315 const char *LLVMGetGC(LLVMValueRef Fn
) {
1316 Function
*F
= unwrap
<Function
>(Fn
);
1317 return F
->hasGC()? F
->getGC() : 0;
1320 void LLVMSetGC(LLVMValueRef Fn
, const char *GC
) {
1321 Function
*F
= unwrap
<Function
>(Fn
);
1328 void LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
1329 Function
*Func
= unwrap
<Function
>(Fn
);
1330 const AttrListPtr PAL
= Func
->getAttributes();
1331 const AttrListPtr PALnew
= PAL
.addAttr(~0U, PA
);
1332 Func
->setAttributes(PALnew
);
1335 void LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
1336 Function
*Func
= unwrap
<Function
>(Fn
);
1337 const AttrListPtr PAL
= Func
->getAttributes();
1338 const AttrListPtr PALnew
= PAL
.removeAttr(~0U, PA
);
1339 Func
->setAttributes(PALnew
);
1342 LLVMAttribute
LLVMGetFunctionAttr(LLVMValueRef Fn
) {
1343 Function
*Func
= unwrap
<Function
>(Fn
);
1344 const AttrListPtr PAL
= Func
->getAttributes();
1345 Attributes attr
= PAL
.getFnAttributes();
1346 return (LLVMAttribute
)attr
;
1349 /*--.. Operations on parameters ............................................--*/
1351 unsigned LLVMCountParams(LLVMValueRef FnRef
) {
1352 // This function is strictly redundant to
1353 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1354 return unwrap
<Function
>(FnRef
)->arg_size();
1357 void LLVMGetParams(LLVMValueRef FnRef
, LLVMValueRef
*ParamRefs
) {
1358 Function
*Fn
= unwrap
<Function
>(FnRef
);
1359 for (Function::arg_iterator I
= Fn
->arg_begin(),
1360 E
= Fn
->arg_end(); I
!= E
; I
++)
1361 *ParamRefs
++ = wrap(I
);
1364 LLVMValueRef
LLVMGetParam(LLVMValueRef FnRef
, unsigned index
) {
1365 Function::arg_iterator AI
= unwrap
<Function
>(FnRef
)->arg_begin();
1371 LLVMValueRef
LLVMGetParamParent(LLVMValueRef V
) {
1372 return wrap(unwrap
<Argument
>(V
)->getParent());
1375 LLVMValueRef
LLVMGetFirstParam(LLVMValueRef Fn
) {
1376 Function
*Func
= unwrap
<Function
>(Fn
);
1377 Function::arg_iterator I
= Func
->arg_begin();
1378 if (I
== Func
->arg_end())
1383 LLVMValueRef
LLVMGetLastParam(LLVMValueRef Fn
) {
1384 Function
*Func
= unwrap
<Function
>(Fn
);
1385 Function::arg_iterator I
= Func
->arg_end();
1386 if (I
== Func
->arg_begin())
1391 LLVMValueRef
LLVMGetNextParam(LLVMValueRef Arg
) {
1392 Argument
*A
= unwrap
<Argument
>(Arg
);
1393 Function::arg_iterator I
= A
;
1394 if (++I
== A
->getParent()->arg_end())
1399 LLVMValueRef
LLVMGetPreviousParam(LLVMValueRef Arg
) {
1400 Argument
*A
= unwrap
<Argument
>(Arg
);
1401 Function::arg_iterator I
= A
;
1402 if (I
== A
->getParent()->arg_begin())
1407 void LLVMAddAttribute(LLVMValueRef Arg
, LLVMAttribute PA
) {
1408 unwrap
<Argument
>(Arg
)->addAttr(PA
);
1411 void LLVMRemoveAttribute(LLVMValueRef Arg
, LLVMAttribute PA
) {
1412 unwrap
<Argument
>(Arg
)->removeAttr(PA
);
1415 LLVMAttribute
LLVMGetAttribute(LLVMValueRef Arg
) {
1416 Argument
*A
= unwrap
<Argument
>(Arg
);
1417 Attributes attr
= A
->getParent()->getAttributes().getParamAttributes(
1419 return (LLVMAttribute
)attr
;
1423 void LLVMSetParamAlignment(LLVMValueRef Arg
, unsigned align
) {
1424 unwrap
<Argument
>(Arg
)->addAttr(
1425 Attribute::constructAlignmentFromInt(align
));
1428 /*--.. Operations on basic blocks ..........................................--*/
1430 LLVMValueRef
LLVMBasicBlockAsValue(LLVMBasicBlockRef BB
) {
1431 return wrap(static_cast<Value
*>(unwrap(BB
)));
1434 LLVMBool
LLVMValueIsBasicBlock(LLVMValueRef Val
) {
1435 return isa
<BasicBlock
>(unwrap(Val
));
1438 LLVMBasicBlockRef
LLVMValueAsBasicBlock(LLVMValueRef Val
) {
1439 return wrap(unwrap
<BasicBlock
>(Val
));
1442 LLVMValueRef
LLVMGetBasicBlockParent(LLVMBasicBlockRef BB
) {
1443 return wrap(unwrap(BB
)->getParent());
1446 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef
) {
1447 return unwrap
<Function
>(FnRef
)->size();
1450 void LLVMGetBasicBlocks(LLVMValueRef FnRef
, LLVMBasicBlockRef
*BasicBlocksRefs
){
1451 Function
*Fn
= unwrap
<Function
>(FnRef
);
1452 for (Function::iterator I
= Fn
->begin(), E
= Fn
->end(); I
!= E
; I
++)
1453 *BasicBlocksRefs
++ = wrap(I
);
1456 LLVMBasicBlockRef
LLVMGetEntryBasicBlock(LLVMValueRef Fn
) {
1457 return wrap(&unwrap
<Function
>(Fn
)->getEntryBlock());
1460 LLVMBasicBlockRef
LLVMGetFirstBasicBlock(LLVMValueRef Fn
) {
1461 Function
*Func
= unwrap
<Function
>(Fn
);
1462 Function::iterator I
= Func
->begin();
1463 if (I
== Func
->end())
1468 LLVMBasicBlockRef
LLVMGetLastBasicBlock(LLVMValueRef Fn
) {
1469 Function
*Func
= unwrap
<Function
>(Fn
);
1470 Function::iterator I
= Func
->end();
1471 if (I
== Func
->begin())
1476 LLVMBasicBlockRef
LLVMGetNextBasicBlock(LLVMBasicBlockRef BB
) {
1477 BasicBlock
*Block
= unwrap(BB
);
1478 Function::iterator I
= Block
;
1479 if (++I
== Block
->getParent()->end())
1484 LLVMBasicBlockRef
LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB
) {
1485 BasicBlock
*Block
= unwrap(BB
);
1486 Function::iterator I
= Block
;
1487 if (I
== Block
->getParent()->begin())
1492 LLVMBasicBlockRef
LLVMAppendBasicBlockInContext(LLVMContextRef C
,
1495 return wrap(BasicBlock::Create(*unwrap(C
), Name
, unwrap
<Function
>(FnRef
)));
1498 LLVMBasicBlockRef
LLVMAppendBasicBlock(LLVMValueRef FnRef
, const char *Name
) {
1499 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef
, Name
);
1502 LLVMBasicBlockRef
LLVMInsertBasicBlockInContext(LLVMContextRef C
,
1503 LLVMBasicBlockRef BBRef
,
1505 BasicBlock
*BB
= unwrap(BBRef
);
1506 return wrap(BasicBlock::Create(*unwrap(C
), Name
, BB
->getParent(), BB
));
1509 LLVMBasicBlockRef
LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef
,
1511 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef
, Name
);
1514 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef
) {
1515 unwrap(BBRef
)->eraseFromParent();
1518 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
) {
1519 unwrap(BB
)->moveBefore(unwrap(MovePos
));
1522 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB
, LLVMBasicBlockRef MovePos
) {
1523 unwrap(BB
)->moveAfter(unwrap(MovePos
));
1526 /*--.. Operations on instructions ..........................................--*/
1528 LLVMBasicBlockRef
LLVMGetInstructionParent(LLVMValueRef Inst
) {
1529 return wrap(unwrap
<Instruction
>(Inst
)->getParent());
1532 LLVMValueRef
LLVMGetFirstInstruction(LLVMBasicBlockRef BB
) {
1533 BasicBlock
*Block
= unwrap(BB
);
1534 BasicBlock::iterator I
= Block
->begin();
1535 if (I
== Block
->end())
1540 LLVMValueRef
LLVMGetLastInstruction(LLVMBasicBlockRef BB
) {
1541 BasicBlock
*Block
= unwrap(BB
);
1542 BasicBlock::iterator I
= Block
->end();
1543 if (I
== Block
->begin())
1548 LLVMValueRef
LLVMGetNextInstruction(LLVMValueRef Inst
) {
1549 Instruction
*Instr
= unwrap
<Instruction
>(Inst
);
1550 BasicBlock::iterator I
= Instr
;
1551 if (++I
== Instr
->getParent()->end())
1556 LLVMValueRef
LLVMGetPreviousInstruction(LLVMValueRef Inst
) {
1557 Instruction
*Instr
= unwrap
<Instruction
>(Inst
);
1558 BasicBlock::iterator I
= Instr
;
1559 if (I
== Instr
->getParent()->begin())
1564 /*--.. Call and invoke instructions ........................................--*/
1566 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr
) {
1567 Value
*V
= unwrap(Instr
);
1568 if (CallInst
*CI
= dyn_cast
<CallInst
>(V
))
1569 return CI
->getCallingConv();
1570 else if (InvokeInst
*II
= dyn_cast
<InvokeInst
>(V
))
1571 return II
->getCallingConv();
1572 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1576 void LLVMSetInstructionCallConv(LLVMValueRef Instr
, unsigned CC
) {
1577 Value
*V
= unwrap(Instr
);
1578 if (CallInst
*CI
= dyn_cast
<CallInst
>(V
))
1579 return CI
->setCallingConv(static_cast<CallingConv::ID
>(CC
));
1580 else if (InvokeInst
*II
= dyn_cast
<InvokeInst
>(V
))
1581 return II
->setCallingConv(static_cast<CallingConv::ID
>(CC
));
1582 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1585 void LLVMAddInstrAttribute(LLVMValueRef Instr
, unsigned index
,
1587 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1589 Call
.getAttributes().addAttr(index
, PA
));
1592 void LLVMRemoveInstrAttribute(LLVMValueRef Instr
, unsigned index
,
1594 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1596 Call
.getAttributes().removeAttr(index
, PA
));
1599 void LLVMSetInstrParamAlignment(LLVMValueRef Instr
, unsigned index
,
1601 CallSite Call
= CallSite(unwrap
<Instruction
>(Instr
));
1603 Call
.getAttributes().addAttr(index
,
1604 Attribute::constructAlignmentFromInt(align
)));
1607 /*--.. Operations on call instructions (only) ..............................--*/
1609 LLVMBool
LLVMIsTailCall(LLVMValueRef Call
) {
1610 return unwrap
<CallInst
>(Call
)->isTailCall();
1613 void LLVMSetTailCall(LLVMValueRef Call
, LLVMBool isTailCall
) {
1614 unwrap
<CallInst
>(Call
)->setTailCall(isTailCall
);
1617 /*--.. Operations on phi nodes .............................................--*/
1619 void LLVMAddIncoming(LLVMValueRef PhiNode
, LLVMValueRef
*IncomingValues
,
1620 LLVMBasicBlockRef
*IncomingBlocks
, unsigned Count
) {
1621 PHINode
*PhiVal
= unwrap
<PHINode
>(PhiNode
);
1622 for (unsigned I
= 0; I
!= Count
; ++I
)
1623 PhiVal
->addIncoming(unwrap(IncomingValues
[I
]), unwrap(IncomingBlocks
[I
]));
1626 unsigned LLVMCountIncoming(LLVMValueRef PhiNode
) {
1627 return unwrap
<PHINode
>(PhiNode
)->getNumIncomingValues();
1630 LLVMValueRef
LLVMGetIncomingValue(LLVMValueRef PhiNode
, unsigned Index
) {
1631 return wrap(unwrap
<PHINode
>(PhiNode
)->getIncomingValue(Index
));
1634 LLVMBasicBlockRef
LLVMGetIncomingBlock(LLVMValueRef PhiNode
, unsigned Index
) {
1635 return wrap(unwrap
<PHINode
>(PhiNode
)->getIncomingBlock(Index
));
1639 /*===-- Instruction builders ----------------------------------------------===*/
1641 LLVMBuilderRef
LLVMCreateBuilderInContext(LLVMContextRef C
) {
1642 return wrap(new IRBuilder
<>(*unwrap(C
)));
1645 LLVMBuilderRef
LLVMCreateBuilder(void) {
1646 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1649 void LLVMPositionBuilder(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
,
1650 LLVMValueRef Instr
) {
1651 BasicBlock
*BB
= unwrap(Block
);
1652 Instruction
*I
= Instr
? unwrap
<Instruction
>(Instr
) : (Instruction
*) BB
->end();
1653 unwrap(Builder
)->SetInsertPoint(BB
, I
);
1656 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder
, LLVMValueRef Instr
) {
1657 Instruction
*I
= unwrap
<Instruction
>(Instr
);
1658 unwrap(Builder
)->SetInsertPoint(I
->getParent(), I
);
1661 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder
, LLVMBasicBlockRef Block
) {
1662 BasicBlock
*BB
= unwrap(Block
);
1663 unwrap(Builder
)->SetInsertPoint(BB
);
1666 LLVMBasicBlockRef
LLVMGetInsertBlock(LLVMBuilderRef Builder
) {
1667 return wrap(unwrap(Builder
)->GetInsertBlock());
1670 void LLVMClearInsertionPosition(LLVMBuilderRef Builder
) {
1671 unwrap(Builder
)->ClearInsertionPoint();
1674 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder
, LLVMValueRef Instr
) {
1675 unwrap(Builder
)->Insert(unwrap
<Instruction
>(Instr
));
1678 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder
, LLVMValueRef Instr
,
1680 unwrap(Builder
)->Insert(unwrap
<Instruction
>(Instr
), Name
);
1683 void LLVMDisposeBuilder(LLVMBuilderRef Builder
) {
1684 delete unwrap(Builder
);
1687 /*--.. Metadata builders ...................................................--*/
1689 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef L
) {
1690 MDNode
*Loc
= L
? unwrap
<MDNode
>(L
) : NULL
;
1691 unwrap(Builder
)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc
));
1694 LLVMValueRef
LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder
) {
1695 return wrap(unwrap(Builder
)->getCurrentDebugLocation()
1696 .getAsMDNode(unwrap(Builder
)->getContext()));
1699 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder
, LLVMValueRef Inst
) {
1700 unwrap(Builder
)->SetInstDebugLocation(unwrap
<Instruction
>(Inst
));
1704 /*--.. Instruction builders ................................................--*/
1706 LLVMValueRef
LLVMBuildRetVoid(LLVMBuilderRef B
) {
1707 return wrap(unwrap(B
)->CreateRetVoid());
1710 LLVMValueRef
LLVMBuildRet(LLVMBuilderRef B
, LLVMValueRef V
) {
1711 return wrap(unwrap(B
)->CreateRet(unwrap(V
)));
1714 LLVMValueRef
LLVMBuildAggregateRet(LLVMBuilderRef B
, LLVMValueRef
*RetVals
,
1716 return wrap(unwrap(B
)->CreateAggregateRet(unwrap(RetVals
), N
));
1719 LLVMValueRef
LLVMBuildBr(LLVMBuilderRef B
, LLVMBasicBlockRef Dest
) {
1720 return wrap(unwrap(B
)->CreateBr(unwrap(Dest
)));
1723 LLVMValueRef
LLVMBuildCondBr(LLVMBuilderRef B
, LLVMValueRef If
,
1724 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Else
) {
1725 return wrap(unwrap(B
)->CreateCondBr(unwrap(If
), unwrap(Then
), unwrap(Else
)));
1728 LLVMValueRef
LLVMBuildSwitch(LLVMBuilderRef B
, LLVMValueRef V
,
1729 LLVMBasicBlockRef Else
, unsigned NumCases
) {
1730 return wrap(unwrap(B
)->CreateSwitch(unwrap(V
), unwrap(Else
), NumCases
));
1733 LLVMValueRef
LLVMBuildIndirectBr(LLVMBuilderRef B
, LLVMValueRef Addr
,
1734 unsigned NumDests
) {
1735 return wrap(unwrap(B
)->CreateIndirectBr(unwrap(Addr
), NumDests
));
1738 LLVMValueRef
LLVMBuildInvoke(LLVMBuilderRef B
, LLVMValueRef Fn
,
1739 LLVMValueRef
*Args
, unsigned NumArgs
,
1740 LLVMBasicBlockRef Then
, LLVMBasicBlockRef Catch
,
1742 return wrap(unwrap(B
)->CreateInvoke(unwrap(Fn
), unwrap(Then
), unwrap(Catch
),
1743 unwrap(Args
), unwrap(Args
) + NumArgs
,
1747 LLVMValueRef
LLVMBuildUnwind(LLVMBuilderRef B
) {
1748 return wrap(unwrap(B
)->CreateUnwind());
1751 LLVMValueRef
LLVMBuildUnreachable(LLVMBuilderRef B
) {
1752 return wrap(unwrap(B
)->CreateUnreachable());
1755 void LLVMAddCase(LLVMValueRef Switch
, LLVMValueRef OnVal
,
1756 LLVMBasicBlockRef Dest
) {
1757 unwrap
<SwitchInst
>(Switch
)->addCase(unwrap
<ConstantInt
>(OnVal
), unwrap(Dest
));
1760 void LLVMAddDestination(LLVMValueRef IndirectBr
, LLVMBasicBlockRef Dest
) {
1761 unwrap
<IndirectBrInst
>(IndirectBr
)->addDestination(unwrap(Dest
));
1764 /*--.. Arithmetic ..........................................................--*/
1766 LLVMValueRef
LLVMBuildAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1768 return wrap(unwrap(B
)->CreateAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1771 LLVMValueRef
LLVMBuildNSWAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1773 return wrap(unwrap(B
)->CreateNSWAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1776 LLVMValueRef
LLVMBuildNUWAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1778 return wrap(unwrap(B
)->CreateNUWAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1781 LLVMValueRef
LLVMBuildFAdd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1783 return wrap(unwrap(B
)->CreateFAdd(unwrap(LHS
), unwrap(RHS
), Name
));
1786 LLVMValueRef
LLVMBuildSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1788 return wrap(unwrap(B
)->CreateSub(unwrap(LHS
), unwrap(RHS
), Name
));
1791 LLVMValueRef
LLVMBuildNSWSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1793 return wrap(unwrap(B
)->CreateNSWSub(unwrap(LHS
), unwrap(RHS
), Name
));
1796 LLVMValueRef
LLVMBuildNUWSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1798 return wrap(unwrap(B
)->CreateNUWSub(unwrap(LHS
), unwrap(RHS
), Name
));
1801 LLVMValueRef
LLVMBuildFSub(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1803 return wrap(unwrap(B
)->CreateFSub(unwrap(LHS
), unwrap(RHS
), Name
));
1806 LLVMValueRef
LLVMBuildMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1808 return wrap(unwrap(B
)->CreateMul(unwrap(LHS
), unwrap(RHS
), Name
));
1811 LLVMValueRef
LLVMBuildNSWMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1813 return wrap(unwrap(B
)->CreateNSWMul(unwrap(LHS
), unwrap(RHS
), Name
));
1816 LLVMValueRef
LLVMBuildNUWMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1818 return wrap(unwrap(B
)->CreateNUWMul(unwrap(LHS
), unwrap(RHS
), Name
));
1821 LLVMValueRef
LLVMBuildFMul(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1823 return wrap(unwrap(B
)->CreateFMul(unwrap(LHS
), unwrap(RHS
), Name
));
1826 LLVMValueRef
LLVMBuildUDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1828 return wrap(unwrap(B
)->CreateUDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1831 LLVMValueRef
LLVMBuildSDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1833 return wrap(unwrap(B
)->CreateSDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1836 LLVMValueRef
LLVMBuildExactSDiv(LLVMBuilderRef B
, LLVMValueRef LHS
,
1837 LLVMValueRef RHS
, const char *Name
) {
1838 return wrap(unwrap(B
)->CreateExactSDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1841 LLVMValueRef
LLVMBuildFDiv(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1843 return wrap(unwrap(B
)->CreateFDiv(unwrap(LHS
), unwrap(RHS
), Name
));
1846 LLVMValueRef
LLVMBuildURem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1848 return wrap(unwrap(B
)->CreateURem(unwrap(LHS
), unwrap(RHS
), Name
));
1851 LLVMValueRef
LLVMBuildSRem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1853 return wrap(unwrap(B
)->CreateSRem(unwrap(LHS
), unwrap(RHS
), Name
));
1856 LLVMValueRef
LLVMBuildFRem(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1858 return wrap(unwrap(B
)->CreateFRem(unwrap(LHS
), unwrap(RHS
), Name
));
1861 LLVMValueRef
LLVMBuildShl(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1863 return wrap(unwrap(B
)->CreateShl(unwrap(LHS
), unwrap(RHS
), Name
));
1866 LLVMValueRef
LLVMBuildLShr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1868 return wrap(unwrap(B
)->CreateLShr(unwrap(LHS
), unwrap(RHS
), Name
));
1871 LLVMValueRef
LLVMBuildAShr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1873 return wrap(unwrap(B
)->CreateAShr(unwrap(LHS
), unwrap(RHS
), Name
));
1876 LLVMValueRef
LLVMBuildAnd(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1878 return wrap(unwrap(B
)->CreateAnd(unwrap(LHS
), unwrap(RHS
), Name
));
1881 LLVMValueRef
LLVMBuildOr(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1883 return wrap(unwrap(B
)->CreateOr(unwrap(LHS
), unwrap(RHS
), Name
));
1886 LLVMValueRef
LLVMBuildXor(LLVMBuilderRef B
, LLVMValueRef LHS
, LLVMValueRef RHS
,
1888 return wrap(unwrap(B
)->CreateXor(unwrap(LHS
), unwrap(RHS
), Name
));
1891 LLVMValueRef
LLVMBuildBinOp(LLVMBuilderRef B
, LLVMOpcode Op
,
1892 LLVMValueRef LHS
, LLVMValueRef RHS
,
1894 return wrap(unwrap(B
)->CreateBinOp(Instruction::BinaryOps(Op
), unwrap(LHS
),
1895 unwrap(RHS
), Name
));
1898 LLVMValueRef
LLVMBuildNeg(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1899 return wrap(unwrap(B
)->CreateNeg(unwrap(V
), Name
));
1902 LLVMValueRef
LLVMBuildNSWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
1904 return wrap(unwrap(B
)->CreateNSWNeg(unwrap(V
), Name
));
1907 LLVMValueRef
LLVMBuildNUWNeg(LLVMBuilderRef B
, LLVMValueRef V
,
1909 return wrap(unwrap(B
)->CreateNUWNeg(unwrap(V
), Name
));
1912 LLVMValueRef
LLVMBuildFNeg(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1913 return wrap(unwrap(B
)->CreateFNeg(unwrap(V
), Name
));
1916 LLVMValueRef
LLVMBuildNot(LLVMBuilderRef B
, LLVMValueRef V
, const char *Name
) {
1917 return wrap(unwrap(B
)->CreateNot(unwrap(V
), Name
));
1920 /*--.. Memory ..............................................................--*/
1922 LLVMValueRef
LLVMBuildMalloc(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1924 const Type
* ITy
= Type::getInt32Ty(unwrap(B
)->GetInsertBlock()->getContext());
1925 Constant
* AllocSize
= ConstantExpr::getSizeOf(unwrap(Ty
));
1926 AllocSize
= ConstantExpr::getTruncOrBitCast(AllocSize
, ITy
);
1927 Instruction
* Malloc
= CallInst::CreateMalloc(unwrap(B
)->GetInsertBlock(),
1928 ITy
, unwrap(Ty
), AllocSize
,
1930 return wrap(unwrap(B
)->Insert(Malloc
, Twine(Name
)));
1933 LLVMValueRef
LLVMBuildArrayMalloc(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1934 LLVMValueRef Val
, const char *Name
) {
1935 const Type
* ITy
= Type::getInt32Ty(unwrap(B
)->GetInsertBlock()->getContext());
1936 Constant
* AllocSize
= ConstantExpr::getSizeOf(unwrap(Ty
));
1937 AllocSize
= ConstantExpr::getTruncOrBitCast(AllocSize
, ITy
);
1938 Instruction
* Malloc
= CallInst::CreateMalloc(unwrap(B
)->GetInsertBlock(),
1939 ITy
, unwrap(Ty
), AllocSize
,
1940 unwrap(Val
), 0, "");
1941 return wrap(unwrap(B
)->Insert(Malloc
, Twine(Name
)));
1944 LLVMValueRef
LLVMBuildAlloca(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1946 return wrap(unwrap(B
)->CreateAlloca(unwrap(Ty
), 0, Name
));
1949 LLVMValueRef
LLVMBuildArrayAlloca(LLVMBuilderRef B
, LLVMTypeRef Ty
,
1950 LLVMValueRef Val
, const char *Name
) {
1951 return wrap(unwrap(B
)->CreateAlloca(unwrap(Ty
), unwrap(Val
), Name
));
1954 LLVMValueRef
LLVMBuildFree(LLVMBuilderRef B
, LLVMValueRef PointerVal
) {
1955 return wrap(unwrap(B
)->Insert(
1956 CallInst::CreateFree(unwrap(PointerVal
), unwrap(B
)->GetInsertBlock())));
1960 LLVMValueRef
LLVMBuildLoad(LLVMBuilderRef B
, LLVMValueRef PointerVal
,
1962 return wrap(unwrap(B
)->CreateLoad(unwrap(PointerVal
), Name
));
1965 LLVMValueRef
LLVMBuildStore(LLVMBuilderRef B
, LLVMValueRef Val
,
1966 LLVMValueRef PointerVal
) {
1967 return wrap(unwrap(B
)->CreateStore(unwrap(Val
), unwrap(PointerVal
)));
1970 LLVMValueRef
LLVMBuildGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1971 LLVMValueRef
*Indices
, unsigned NumIndices
,
1973 return wrap(unwrap(B
)->CreateGEP(unwrap(Pointer
), unwrap(Indices
),
1974 unwrap(Indices
) + NumIndices
, Name
));
1977 LLVMValueRef
LLVMBuildInBoundsGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1978 LLVMValueRef
*Indices
, unsigned NumIndices
,
1980 return wrap(unwrap(B
)->CreateInBoundsGEP(unwrap(Pointer
), unwrap(Indices
),
1981 unwrap(Indices
) + NumIndices
, Name
));
1984 LLVMValueRef
LLVMBuildStructGEP(LLVMBuilderRef B
, LLVMValueRef Pointer
,
1985 unsigned Idx
, const char *Name
) {
1986 return wrap(unwrap(B
)->CreateStructGEP(unwrap(Pointer
), Idx
, Name
));
1989 LLVMValueRef
LLVMBuildGlobalString(LLVMBuilderRef B
, const char *Str
,
1991 return wrap(unwrap(B
)->CreateGlobalString(Str
, Name
));
1994 LLVMValueRef
LLVMBuildGlobalStringPtr(LLVMBuilderRef B
, const char *Str
,
1996 return wrap(unwrap(B
)->CreateGlobalStringPtr(Str
, Name
));
1999 /*--.. Casts ...............................................................--*/
2001 LLVMValueRef
LLVMBuildTrunc(LLVMBuilderRef B
, LLVMValueRef Val
,
2002 LLVMTypeRef DestTy
, const char *Name
) {
2003 return wrap(unwrap(B
)->CreateTrunc(unwrap(Val
), unwrap(DestTy
), Name
));
2006 LLVMValueRef
LLVMBuildZExt(LLVMBuilderRef B
, LLVMValueRef Val
,
2007 LLVMTypeRef DestTy
, const char *Name
) {
2008 return wrap(unwrap(B
)->CreateZExt(unwrap(Val
), unwrap(DestTy
), Name
));
2011 LLVMValueRef
LLVMBuildSExt(LLVMBuilderRef B
, LLVMValueRef Val
,
2012 LLVMTypeRef DestTy
, const char *Name
) {
2013 return wrap(unwrap(B
)->CreateSExt(unwrap(Val
), unwrap(DestTy
), Name
));
2016 LLVMValueRef
LLVMBuildFPToUI(LLVMBuilderRef B
, LLVMValueRef Val
,
2017 LLVMTypeRef DestTy
, const char *Name
) {
2018 return wrap(unwrap(B
)->CreateFPToUI(unwrap(Val
), unwrap(DestTy
), Name
));
2021 LLVMValueRef
LLVMBuildFPToSI(LLVMBuilderRef B
, LLVMValueRef Val
,
2022 LLVMTypeRef DestTy
, const char *Name
) {
2023 return wrap(unwrap(B
)->CreateFPToSI(unwrap(Val
), unwrap(DestTy
), Name
));
2026 LLVMValueRef
LLVMBuildUIToFP(LLVMBuilderRef B
, LLVMValueRef Val
,
2027 LLVMTypeRef DestTy
, const char *Name
) {
2028 return wrap(unwrap(B
)->CreateUIToFP(unwrap(Val
), unwrap(DestTy
), Name
));
2031 LLVMValueRef
LLVMBuildSIToFP(LLVMBuilderRef B
, LLVMValueRef Val
,
2032 LLVMTypeRef DestTy
, const char *Name
) {
2033 return wrap(unwrap(B
)->CreateSIToFP(unwrap(Val
), unwrap(DestTy
), Name
));
2036 LLVMValueRef
LLVMBuildFPTrunc(LLVMBuilderRef B
, LLVMValueRef Val
,
2037 LLVMTypeRef DestTy
, const char *Name
) {
2038 return wrap(unwrap(B
)->CreateFPTrunc(unwrap(Val
), unwrap(DestTy
), Name
));
2041 LLVMValueRef
LLVMBuildFPExt(LLVMBuilderRef B
, LLVMValueRef Val
,
2042 LLVMTypeRef DestTy
, const char *Name
) {
2043 return wrap(unwrap(B
)->CreateFPExt(unwrap(Val
), unwrap(DestTy
), Name
));
2046 LLVMValueRef
LLVMBuildPtrToInt(LLVMBuilderRef B
, LLVMValueRef Val
,
2047 LLVMTypeRef DestTy
, const char *Name
) {
2048 return wrap(unwrap(B
)->CreatePtrToInt(unwrap(Val
), unwrap(DestTy
), Name
));
2051 LLVMValueRef
LLVMBuildIntToPtr(LLVMBuilderRef B
, LLVMValueRef Val
,
2052 LLVMTypeRef DestTy
, const char *Name
) {
2053 return wrap(unwrap(B
)->CreateIntToPtr(unwrap(Val
), unwrap(DestTy
), Name
));
2056 LLVMValueRef
LLVMBuildBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2057 LLVMTypeRef DestTy
, const char *Name
) {
2058 return wrap(unwrap(B
)->CreateBitCast(unwrap(Val
), unwrap(DestTy
), Name
));
2061 LLVMValueRef
LLVMBuildZExtOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2062 LLVMTypeRef DestTy
, const char *Name
) {
2063 return wrap(unwrap(B
)->CreateZExtOrBitCast(unwrap(Val
), unwrap(DestTy
),
2067 LLVMValueRef
LLVMBuildSExtOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2068 LLVMTypeRef DestTy
, const char *Name
) {
2069 return wrap(unwrap(B
)->CreateSExtOrBitCast(unwrap(Val
), unwrap(DestTy
),
2073 LLVMValueRef
LLVMBuildTruncOrBitCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2074 LLVMTypeRef DestTy
, const char *Name
) {
2075 return wrap(unwrap(B
)->CreateTruncOrBitCast(unwrap(Val
), unwrap(DestTy
),
2079 LLVMValueRef
LLVMBuildCast(LLVMBuilderRef B
, LLVMOpcode Op
, LLVMValueRef Val
,
2080 LLVMTypeRef DestTy
, const char *Name
) {
2081 return wrap(unwrap(B
)->CreateCast(Instruction::CastOps(Op
), unwrap(Val
),
2082 unwrap(DestTy
), Name
));
2085 LLVMValueRef
LLVMBuildPointerCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2086 LLVMTypeRef DestTy
, const char *Name
) {
2087 return wrap(unwrap(B
)->CreatePointerCast(unwrap(Val
), unwrap(DestTy
), Name
));
2090 LLVMValueRef
LLVMBuildIntCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2091 LLVMTypeRef DestTy
, const char *Name
) {
2092 return wrap(unwrap(B
)->CreateIntCast(unwrap(Val
), unwrap(DestTy
),
2093 /*isSigned*/true, Name
));
2096 LLVMValueRef
LLVMBuildFPCast(LLVMBuilderRef B
, LLVMValueRef Val
,
2097 LLVMTypeRef DestTy
, const char *Name
) {
2098 return wrap(unwrap(B
)->CreateFPCast(unwrap(Val
), unwrap(DestTy
), Name
));
2101 /*--.. Comparisons .........................................................--*/
2103 LLVMValueRef
LLVMBuildICmp(LLVMBuilderRef B
, LLVMIntPredicate Op
,
2104 LLVMValueRef LHS
, LLVMValueRef RHS
,
2106 return wrap(unwrap(B
)->CreateICmp(static_cast<ICmpInst::Predicate
>(Op
),
2107 unwrap(LHS
), unwrap(RHS
), Name
));
2110 LLVMValueRef
LLVMBuildFCmp(LLVMBuilderRef B
, LLVMRealPredicate Op
,
2111 LLVMValueRef LHS
, LLVMValueRef RHS
,
2113 return wrap(unwrap(B
)->CreateFCmp(static_cast<FCmpInst::Predicate
>(Op
),
2114 unwrap(LHS
), unwrap(RHS
), Name
));
2117 /*--.. Miscellaneous instructions ..........................................--*/
2119 LLVMValueRef
LLVMBuildPhi(LLVMBuilderRef B
, LLVMTypeRef Ty
, const char *Name
) {
2120 return wrap(unwrap(B
)->CreatePHI(unwrap(Ty
), Name
));
2123 LLVMValueRef
LLVMBuildCall(LLVMBuilderRef B
, LLVMValueRef Fn
,
2124 LLVMValueRef
*Args
, unsigned NumArgs
,
2126 return wrap(unwrap(B
)->CreateCall(unwrap(Fn
), unwrap(Args
),
2127 unwrap(Args
) + NumArgs
, Name
));
2130 LLVMValueRef
LLVMBuildSelect(LLVMBuilderRef B
, LLVMValueRef If
,
2131 LLVMValueRef Then
, LLVMValueRef Else
,
2133 return wrap(unwrap(B
)->CreateSelect(unwrap(If
), unwrap(Then
), unwrap(Else
),
2137 LLVMValueRef
LLVMBuildVAArg(LLVMBuilderRef B
, LLVMValueRef List
,
2138 LLVMTypeRef Ty
, const char *Name
) {
2139 return wrap(unwrap(B
)->CreateVAArg(unwrap(List
), unwrap(Ty
), Name
));
2142 LLVMValueRef
LLVMBuildExtractElement(LLVMBuilderRef B
, LLVMValueRef VecVal
,
2143 LLVMValueRef Index
, const char *Name
) {
2144 return wrap(unwrap(B
)->CreateExtractElement(unwrap(VecVal
), unwrap(Index
),
2148 LLVMValueRef
LLVMBuildInsertElement(LLVMBuilderRef B
, LLVMValueRef VecVal
,
2149 LLVMValueRef EltVal
, LLVMValueRef Index
,
2151 return wrap(unwrap(B
)->CreateInsertElement(unwrap(VecVal
), unwrap(EltVal
),
2152 unwrap(Index
), Name
));
2155 LLVMValueRef
LLVMBuildShuffleVector(LLVMBuilderRef B
, LLVMValueRef V1
,
2156 LLVMValueRef V2
, LLVMValueRef Mask
,
2158 return wrap(unwrap(B
)->CreateShuffleVector(unwrap(V1
), unwrap(V2
),
2159 unwrap(Mask
), Name
));
2162 LLVMValueRef
LLVMBuildExtractValue(LLVMBuilderRef B
, LLVMValueRef AggVal
,
2163 unsigned Index
, const char *Name
) {
2164 return wrap(unwrap(B
)->CreateExtractValue(unwrap(AggVal
), Index
, Name
));
2167 LLVMValueRef
LLVMBuildInsertValue(LLVMBuilderRef B
, LLVMValueRef AggVal
,
2168 LLVMValueRef EltVal
, unsigned Index
,
2170 return wrap(unwrap(B
)->CreateInsertValue(unwrap(AggVal
), unwrap(EltVal
),
2174 LLVMValueRef
LLVMBuildIsNull(LLVMBuilderRef B
, LLVMValueRef Val
,
2176 return wrap(unwrap(B
)->CreateIsNull(unwrap(Val
), Name
));
2179 LLVMValueRef
LLVMBuildIsNotNull(LLVMBuilderRef B
, LLVMValueRef Val
,
2181 return wrap(unwrap(B
)->CreateIsNotNull(unwrap(Val
), Name
));
2184 LLVMValueRef
LLVMBuildPtrDiff(LLVMBuilderRef B
, LLVMValueRef LHS
,
2185 LLVMValueRef RHS
, const char *Name
) {
2186 return wrap(unwrap(B
)->CreatePtrDiff(unwrap(LHS
), unwrap(RHS
), Name
));
2190 /*===-- Module providers --------------------------------------------------===*/
2192 LLVMModuleProviderRef
2193 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M
) {
2194 return reinterpret_cast<LLVMModuleProviderRef
>(M
);
2197 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP
) {
2202 /*===-- Memory buffers ----------------------------------------------------===*/
2204 LLVMBool
LLVMCreateMemoryBufferWithContentsOfFile(
2206 LLVMMemoryBufferRef
*OutMemBuf
,
2207 char **OutMessage
) {
2210 if (MemoryBuffer
*MB
= MemoryBuffer::getFile(Path
, &Error
)) {
2211 *OutMemBuf
= wrap(MB
);
2215 *OutMessage
= strdup(Error
.c_str());
2219 LLVMBool
LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef
*OutMemBuf
,
2220 char **OutMessage
) {
2222 if (MemoryBuffer
*MB
= MemoryBuffer::getSTDIN(&Error
)) {
2223 *OutMemBuf
= wrap(MB
);
2227 *OutMessage
= strdup(Error
.c_str());
2231 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf
) {
2232 delete unwrap(MemBuf
);
2235 /*===-- Pass Registry -----------------------------------------------------===*/
2237 LLVMPassRegistryRef
LLVMGetGlobalPassRegistry(void) {
2238 return wrap(PassRegistry::getPassRegistry());
2241 /*===-- Pass Manager ------------------------------------------------------===*/
2243 LLVMPassManagerRef
LLVMCreatePassManager() {
2244 return wrap(new PassManager());
2247 LLVMPassManagerRef
LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M
) {
2248 return wrap(new FunctionPassManager(unwrap(M
)));
2251 LLVMPassManagerRef
LLVMCreateFunctionPassManager(LLVMModuleProviderRef P
) {
2252 return LLVMCreateFunctionPassManagerForModule(
2253 reinterpret_cast<LLVMModuleRef
>(P
));
2256 LLVMBool
LLVMRunPassManager(LLVMPassManagerRef PM
, LLVMModuleRef M
) {
2257 return unwrap
<PassManager
>(PM
)->run(*unwrap(M
));
2260 LLVMBool
LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM
) {
2261 return unwrap
<FunctionPassManager
>(FPM
)->doInitialization();
2264 LLVMBool
LLVMRunFunctionPassManager(LLVMPassManagerRef FPM
, LLVMValueRef F
) {
2265 return unwrap
<FunctionPassManager
>(FPM
)->run(*unwrap
<Function
>(F
));
2268 LLVMBool
LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM
) {
2269 return unwrap
<FunctionPassManager
>(FPM
)->doFinalization();
2272 void LLVMDisposePassManager(LLVMPassManagerRef PM
) {