0d6e2488c5dc3f18030b3fe19499d1f3d67addfb
[oota-llvm.git] / include / llvm-c / Core.h
1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file is distributed under the University of Illinois Open Source      *|
6 |* License. See LICENSE.TXT for details.                                      *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This header declares the C interface to libLLVMCore.a, which implements    *|
11 |* the LLVM intermediate representation.                                      *|
12 |*                                                                            *|
13 |* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14 |* parameters must be passed as base types. Despite the declared types, most  *|
15 |* of the functions provided operate only on branches of the type hierarchy.  *|
16 |* The declared parameter names are descriptive and specify which type is     *|
17 |* required. Additionally, each type hierarchy is documented along with the   *|
18 |* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19 |* If in doubt, refer to Core.cpp, which performs paramter downcasts in the   *|
20 |* form unwrap<RequiredType>(Param).                                          *|
21 |*                                                                            *|
22 |* Many exotic languages can interoperate with C code but have a harder time  *|
23 |* with C++ due to name mangling. So in addition to C, this interface enables *|
24 |* tools written in such languages.                                           *|
25 |*                                                                            *|
26 |* When included into a C++ source file, also declares 'wrap' and 'unwrap'    *|
27 |* helpers to perform opaque reference<-->pointer conversions. These helpers  *|
28 |* are shorter and more tightly typed than writing the casts by hand when     *|
29 |* authoring bindings. In assert builds, they will do runtime type checking.  *|
30 |*                                                                            *|
31 \*===----------------------------------------------------------------------===*/
32
33 #ifndef LLVM_C_CORE_H
34 #define LLVM_C_CORE_H
35
36 #ifdef __cplusplus
37
38 /* Need these includes to support the LLVM 'cast' template for the C++ 'wrap' 
39    and 'unwrap' conversion functions. */
40 #include "llvm/Module.h"
41 #include "llvm/Support/IRBuilder.h"
42
43 extern "C" {
44 #endif
45
46
47 /* Opaque types. */
48
49 /**
50  * The top-level container for all LLVM global data.  See the LLVMContext class.
51  */
52 typedef struct LLVMCtxt *LLVMContextRef;
53
54 /**
55  * The top-level container for all other LLVM Intermediate Representation (IR)
56  * objects. See the llvm::Module class.
57  */
58 typedef struct LLVMOpaqueModule *LLVMModuleRef;
59
60 /**
61  * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
62  * class.
63  */
64 typedef struct LLVMOpaqueType *LLVMTypeRef;
65
66 /**
67  * When building recursive types using LLVMRefineType, LLVMTypeRef values may
68  * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
69  * llvm::AbstractTypeHolder class.
70  */
71 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
72
73 typedef struct LLVMOpaqueValue *LLVMValueRef;
74 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
75 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
76
77 /* Used to provide a module to JIT or interpreter.
78  * See the llvm::ModuleProvider class.
79  */
80 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
81
82 /* Used to provide a module to JIT or interpreter.
83  * See the llvm::MemoryBuffer class.
84  */
85 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
86
87 /** See the llvm::PassManagerBase class. */
88 typedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
89
90 typedef enum {
91     LLVMZExtAttribute       = 1<<0,
92     LLVMSExtAttribute       = 1<<1,
93     LLVMNoReturnAttribute   = 1<<2,
94     LLVMInRegAttribute      = 1<<3,
95     LLVMStructRetAttribute  = 1<<4,
96     LLVMNoUnwindAttribute   = 1<<5,
97     LLVMNoAliasAttribute    = 1<<6,
98     LLVMByValAttribute      = 1<<7,
99     LLVMNestAttribute       = 1<<8,
100     LLVMReadNoneAttribute   = 1<<9,
101     LLVMReadOnlyAttribute   = 1<<10,
102     LLVMNoInlineAttribute   = 1<<11,
103     LLVMAlwaysInlineAttribute    = 1<<12,
104     LLVMOptimizeForSizeAttribute = 1<<13,
105     LLVMStackProtectAttribute    = 1<<14,
106     LLVMStackProtectReqAttribute = 1<<15,
107     LLVMNoCaptureAttribute  = 1<<21,
108     LLVMNoRedZoneAttribute  = 1<<22,
109     LLVMNoImplicitFloatAttribute = 1<<23,
110     LLVMNakedAttribute      = 1<<24
111 } LLVMAttribute;
112
113 typedef enum {
114   LLVMVoidTypeKind,        /**< type with no size */
115   LLVMFloatTypeKind,       /**< 32 bit floating point type */
116   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
117   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
118   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
119   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
120   LLVMLabelTypeKind,       /**< Labels */
121   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
122   LLVMFunctionTypeKind,    /**< Functions */
123   LLVMStructTypeKind,      /**< Structures */
124   LLVMArrayTypeKind,       /**< Arrays */
125   LLVMPointerTypeKind,     /**< Pointers */
126   LLVMOpaqueTypeKind,      /**< Opaque: type with unknown structure */
127   LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
128   LLVMMetadataTypeKind     /**< Metadata */
129 } LLVMTypeKind;
130
131 typedef enum {
132   LLVMExternalLinkage,    /**< Externally visible function */
133   LLVMAvailableExternallyLinkage,
134   LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
135   LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
136                             equivalent. */
137   LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
138   LLVMWeakODRLinkage,     /**< Same, but only replaced by something
139                             equivalent. */
140   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
141   LLVMInternalLinkage,    /**< Rename collisions when linking (static
142                                functions) */
143   LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
144   LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
145   LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
146   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
147   LLVMGhostLinkage,       /**< Stand-in functions for streaming fns from
148                                bitcode */
149   LLVMCommonLinkage,      /**< Tentative definitions */
150   LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
151 } LLVMLinkage;
152
153 typedef enum {
154   LLVMDefaultVisibility,  /**< The GV is visible */
155   LLVMHiddenVisibility,   /**< The GV is hidden */
156   LLVMProtectedVisibility /**< The GV is protected */
157 } LLVMVisibility;
158
159 typedef enum {
160   LLVMCCallConv           = 0,
161   LLVMFastCallConv        = 8,
162   LLVMColdCallConv        = 9,
163   LLVMX86StdcallCallConv  = 64,
164   LLVMX86FastcallCallConv = 65
165 } LLVMCallConv;
166
167 typedef enum {
168   LLVMIntEQ = 32, /**< equal */
169   LLVMIntNE,      /**< not equal */
170   LLVMIntUGT,     /**< unsigned greater than */
171   LLVMIntUGE,     /**< unsigned greater or equal */
172   LLVMIntULT,     /**< unsigned less than */
173   LLVMIntULE,     /**< unsigned less or equal */
174   LLVMIntSGT,     /**< signed greater than */
175   LLVMIntSGE,     /**< signed greater or equal */
176   LLVMIntSLT,     /**< signed less than */
177   LLVMIntSLE      /**< signed less or equal */
178 } LLVMIntPredicate;
179
180 typedef enum {
181   LLVMRealPredicateFalse, /**< Always false (always folded) */
182   LLVMRealOEQ,            /**< True if ordered and equal */
183   LLVMRealOGT,            /**< True if ordered and greater than */
184   LLVMRealOGE,            /**< True if ordered and greater than or equal */
185   LLVMRealOLT,            /**< True if ordered and less than */
186   LLVMRealOLE,            /**< True if ordered and less than or equal */
187   LLVMRealONE,            /**< True if ordered and operands are unequal */
188   LLVMRealORD,            /**< True if ordered (no nans) */
189   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
190   LLVMRealUEQ,            /**< True if unordered or equal */
191   LLVMRealUGT,            /**< True if unordered or greater than */
192   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
193   LLVMRealULT,            /**< True if unordered or less than */
194   LLVMRealULE,            /**< True if unordered, less than, or equal */
195   LLVMRealUNE,            /**< True if unordered or not equal */
196   LLVMRealPredicateTrue   /**< Always true (always folded) */
197 } LLVMRealPredicate;
198
199
200 /*===-- Error handling ----------------------------------------------------===*/
201
202 void LLVMDisposeMessage(char *Message);
203
204
205 /*===-- Modules -----------------------------------------------------------===*/
206
207 /* Create and destroy contexts. */
208 LLVMContextRef LLVMContextCreate();
209 LLVMContextRef LLVMGetGlobalContext();
210 void LLVMContextDispose(LLVMContextRef C);
211
212 /* Create and destroy modules. */ 
213 /** See llvm::Module::Module. */
214 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
215 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
216                                                 LLVMContextRef C);
217
218 /** See llvm::Module::~Module. */
219 void LLVMDisposeModule(LLVMModuleRef M);
220
221 /** Data layout. See Module::getDataLayout. */
222 const char *LLVMGetDataLayout(LLVMModuleRef M);
223 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
224
225 /** Target triple. See Module::getTargetTriple. */
226 const char *LLVMGetTarget(LLVMModuleRef M);
227 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
228
229 /** See Module::addTypeName. */
230 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
231 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
232 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
233
234 /** See Module::dump. */
235 void LLVMDumpModule(LLVMModuleRef M);
236
237
238 /*===-- Types -------------------------------------------------------------===*/
239
240 /* LLVM types conform to the following hierarchy:
241  * 
242  *   types:
243  *     integer type
244  *     real type
245  *     function type
246  *     sequence types:
247  *       array type
248  *       pointer type
249  *       vector type
250  *     void type
251  *     label type
252  *     opaque type
253  */
254
255 /** See llvm::LLVMTypeKind::getTypeID. */
256 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
257
258 /* Operations on integer types */
259 LLVMTypeRef LLVMInt1Type(void);
260 LLVMTypeRef LLVMInt8Type(void);
261 LLVMTypeRef LLVMInt16Type(void);
262 LLVMTypeRef LLVMInt32Type(void);
263 LLVMTypeRef LLVMInt64Type(void);
264 LLVMTypeRef LLVMIntType(unsigned NumBits);
265 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
266
267 /* Operations on real types */
268 LLVMTypeRef LLVMFloatType(void);
269 LLVMTypeRef LLVMDoubleType(void);
270 LLVMTypeRef LLVMX86FP80Type(void);
271 LLVMTypeRef LLVMFP128Type(void);
272 LLVMTypeRef LLVMPPCFP128Type(void);
273
274 /* Operations on function types */
275 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
276                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
277                              int IsVarArg);
278 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
279 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
280 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
281 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
282
283 /* Operations on struct types */
284 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
285                            int Packed);
286 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
287 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
288 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
289
290 /* Operations on array, pointer, and vector types (sequence types) */
291 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
292 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
293 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
294
295 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
296 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
297 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
298 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
299
300 /* Operations on other types */
301 LLVMTypeRef LLVMVoidType(void);
302 LLVMTypeRef LLVMLabelType(void);
303 LLVMTypeRef LLVMOpaqueType(void);
304
305 /* Operations on type handles */
306 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
307 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
308 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
309 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
310
311
312 /*===-- Values ------------------------------------------------------------===*/
313
314 /* The bulk of LLVM's object model consists of values, which comprise a very
315  * rich type hierarchy.
316  */
317
318 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
319   macro(Argument)                           \
320   macro(BasicBlock)                         \
321   macro(InlineAsm)                          \
322   macro(User)                               \
323     macro(Constant)                         \
324       macro(ConstantAggregateZero)          \
325       macro(ConstantArray)                  \
326       macro(ConstantExpr)                   \
327       macro(ConstantFP)                     \
328       macro(ConstantInt)                    \
329       macro(ConstantPointerNull)            \
330       macro(ConstantStruct)                 \
331       macro(ConstantVector)                 \
332       macro(GlobalValue)                    \
333         macro(Function)                     \
334         macro(GlobalAlias)                  \
335         macro(GlobalVariable)               \
336       macro(UndefValue)                     \
337     macro(Instruction)                      \
338       macro(BinaryOperator)                 \
339       macro(CallInst)                       \
340         macro(IntrinsicInst)                \
341           macro(DbgInfoIntrinsic)           \
342             macro(DbgDeclareInst)           \
343             macro(DbgFuncStartInst)         \
344             macro(DbgRegionEndInst)         \
345             macro(DbgRegionStartInst)       \
346             macro(DbgStopPointInst)         \
347           macro(EHSelectorInst)             \
348           macro(MemIntrinsic)               \
349             macro(MemCpyInst)               \
350             macro(MemMoveInst)              \
351             macro(MemSetInst)               \
352       macro(CmpInst)                        \
353       macro(FCmpInst)                       \
354       macro(ICmpInst)                       \
355       macro(ExtractElementInst)             \
356       macro(GetElementPtrInst)              \
357       macro(InsertElementInst)              \
358       macro(InsertValueInst)                \
359       macro(PHINode)                        \
360       macro(SelectInst)                     \
361       macro(ShuffleVectorInst)              \
362       macro(StoreInst)                      \
363       macro(TerminatorInst)                 \
364         macro(BranchInst)                   \
365         macro(InvokeInst)                   \
366         macro(ReturnInst)                   \
367         macro(SwitchInst)                   \
368         macro(UnreachableInst)              \
369         macro(UnwindInst)                   \
370     macro(UnaryInstruction)                 \
371       macro(AllocationInst)                 \
372         macro(AllocaInst)                   \
373         macro(MallocInst)                   \
374       macro(CastInst)                       \
375         macro(BitCastInst)                  \
376         macro(FPExtInst)                    \
377         macro(FPToSIInst)                   \
378         macro(FPToUIInst)                   \
379         macro(FPTruncInst)                  \
380         macro(IntToPtrInst)                 \
381         macro(PtrToIntInst)                 \
382         macro(SExtInst)                     \
383         macro(SIToFPInst)                   \
384         macro(TruncInst)                    \
385         macro(UIToFPInst)                   \
386         macro(ZExtInst)                     \
387       macro(ExtractValueInst)               \
388       macro(FreeInst)                       \
389       macro(LoadInst)                       \
390       macro(VAArgInst)
391
392 /* Operations on all values */
393 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
394 const char *LLVMGetValueName(LLVMValueRef Val);
395 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
396 void LLVMDumpValue(LLVMValueRef Val);
397
398 /* Conversion functions. Return the input value if it is an instance of the
399    specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
400 #define LLVM_DECLARE_VALUE_CAST(name) \
401   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
402 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
403
404 /* Operations on constants of any type */
405 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
406 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
407 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
408 int LLVMIsConstant(LLVMValueRef Val);
409 int LLVMIsNull(LLVMValueRef Val);
410 int LLVMIsUndef(LLVMValueRef Val);
411 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
412
413 /* Operations on scalar constants */
414 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
415                           int SignExtend);
416 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
417 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
418
419 /* Operations on composite constants */
420 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
421                              int DontNullTerminate);
422 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
423                             LLVMValueRef *ConstantVals, unsigned Length);
424 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
425                              int packed);
426 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
427
428 /* Constant expressions */
429 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
430 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
431 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
432 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
444 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
445                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
446 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
447                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
451 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
452                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
453 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
465 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
466                              LLVMValueRef ConstantIfTrue,
467                              LLVMValueRef ConstantIfFalse);
468 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
469                                      LLVMValueRef IndexConstant);
470 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
471                                     LLVMValueRef ElementValueConstant,
472                                     LLVMValueRef IndexConstant);
473 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
474                                     LLVMValueRef VectorBConstant,
475                                     LLVMValueRef MaskConstant);
476 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
477                                    unsigned NumIdx);
478 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
479                                   LLVMValueRef ElementValueConstant,
480                                   unsigned *IdxList, unsigned NumIdx);
481 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 
482                                 const char *AsmString, const char *Constraints,
483                                 int HasSideEffects);
484
485 /* Operations on global variables, functions, and aliases (globals) */
486 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
487 int LLVMIsDeclaration(LLVMValueRef Global);
488 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
489 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
490 const char *LLVMGetSection(LLVMValueRef Global);
491 void LLVMSetSection(LLVMValueRef Global, const char *Section);
492 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
493 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
494 unsigned LLVMGetAlignment(LLVMValueRef Global);
495 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
496
497 /* Operations on global variables */
498 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
499 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
500 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
501 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
502 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
503 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
504 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
505 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
506 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
507 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
508 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
509 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
510 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
511
512 /* Operations on aliases */
513 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
514                           const char *Name);
515
516 /* Operations on functions */
517 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
518                              LLVMTypeRef FunctionTy);
519 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
520 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
521 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
522 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
523 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
524 void LLVMDeleteFunction(LLVMValueRef Fn);
525 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
526 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
527 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
528 const char *LLVMGetGC(LLVMValueRef Fn);
529 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
530 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
531 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
532
533 /* Operations on parameters */
534 unsigned LLVMCountParams(LLVMValueRef Fn);
535 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
536 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
537 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
538 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
539 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
540 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
541 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
542 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
543 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
544 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
545
546 /* Operations on basic blocks */
547 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
548 int LLVMValueIsBasicBlock(LLVMValueRef Val);
549 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
550 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
551 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
552 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
553 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
554 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
555 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
556 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
557 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
558 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
559 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
560                                        const char *Name);
561 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
562
563 /* Operations on instructions */
564 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
565 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
566 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
567 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
568 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
569
570 /* Operations on call sites */
571 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
572 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
573 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
574 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 
575                               LLVMAttribute);
576 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 
577                                 unsigned align);
578
579 /* Operations on call instructions (only) */
580 int LLVMIsTailCall(LLVMValueRef CallInst);
581 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
582
583 /* Operations on phi nodes */
584 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
585                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
586 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
587 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
588 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
589
590 /*===-- Instruction builders ----------------------------------------------===*/
591
592 /* An instruction builder represents a point within a basic block, and is the
593  * exclusive means of building instructions using the C interface.
594  */
595
596 LLVMBuilderRef LLVMCreateBuilder(void);
597 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
598                          LLVMValueRef Instr);
599 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
600 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
601 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
602 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
603 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
604 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
605
606 /* Terminators */
607 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
608 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
609 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
610 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
611                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
612 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
613                              LLVMBasicBlockRef Else, unsigned NumCases);
614 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
615                              LLVMValueRef *Args, unsigned NumArgs,
616                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
617                              const char *Name);
618 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
619 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
620
621 /* Add a case to the switch instruction */
622 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
623                  LLVMBasicBlockRef Dest);
624
625 /* Arithmetic */
626 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
627                           const char *Name);
628 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
629                           const char *Name);
630 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
631                           const char *Name);
632 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
633                            const char *Name);
634 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
635                            const char *Name);
636 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
637                            const char *Name);
638 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
639                            const char *Name);
640 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
641                            const char *Name);
642 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
643                            const char *Name);
644 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
645                            const char *Name);
646 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
647                            const char *Name);
648 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
649                            const char *Name);
650 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
651                           const char *Name);
652 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
653                           const char *Name);
654 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
655                           const char *Name);
656 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
657 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
658
659 /* Memory */
660 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
661 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
662                                   LLVMValueRef Val, const char *Name);
663 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
664 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
665                                   LLVMValueRef Val, const char *Name);
666 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
667 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
668                            const char *Name);
669 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
670 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
671                           LLVMValueRef *Indices, unsigned NumIndices,
672                           const char *Name);
673
674 /* Casts */
675 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
676                             LLVMTypeRef DestTy, const char *Name);
677 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
678                            LLVMTypeRef DestTy, const char *Name);
679 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
680                            LLVMTypeRef DestTy, const char *Name);
681 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
682                              LLVMTypeRef DestTy, const char *Name);
683 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
684                              LLVMTypeRef DestTy, const char *Name);
685 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
686                              LLVMTypeRef DestTy, const char *Name);
687 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
688                              LLVMTypeRef DestTy, const char *Name);
689 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
690                               LLVMTypeRef DestTy, const char *Name);
691 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
692                             LLVMTypeRef DestTy, const char *Name);
693 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
694                                LLVMTypeRef DestTy, const char *Name);
695 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
696                                LLVMTypeRef DestTy, const char *Name);
697 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
698                               LLVMTypeRef DestTy, const char *Name);
699
700 /* Comparisons */
701 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
702                            LLVMValueRef LHS, LLVMValueRef RHS,
703                            const char *Name);
704 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
705                            LLVMValueRef LHS, LLVMValueRef RHS,
706                            const char *Name);
707
708 /* Miscellaneous instructions */
709 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
710 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
711                            LLVMValueRef *Args, unsigned NumArgs,
712                            const char *Name);
713 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
714                              LLVMValueRef Then, LLVMValueRef Else,
715                              const char *Name);
716 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
717                             const char *Name);
718 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
719                                      LLVMValueRef Index, const char *Name);
720 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
721                                     LLVMValueRef EltVal, LLVMValueRef Index,
722                                     const char *Name);
723 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
724                                     LLVMValueRef V2, LLVMValueRef Mask,
725                                     const char *Name);
726 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
727                                    unsigned Index, const char *Name);
728 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
729                                   LLVMValueRef EltVal, unsigned Index,
730                                   const char *Name);
731
732
733 /*===-- Module providers --------------------------------------------------===*/
734
735 /* Encapsulates the module M in a module provider, taking ownership of the
736  * module.
737  * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
738  */
739 LLVMModuleProviderRef
740 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
741
742 /* Destroys the module provider MP as well as the contained module.
743  * See the destructor llvm::ModuleProvider::~ModuleProvider.
744  */
745 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
746
747
748 /*===-- Memory buffers ----------------------------------------------------===*/
749
750 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
751                                              LLVMMemoryBufferRef *OutMemBuf,
752                                              char **OutMessage);
753 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
754                                     char **OutMessage);
755 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
756
757
758 /*===-- Pass Managers -----------------------------------------------------===*/
759
760 /** Constructs a new whole-module pass pipeline. This type of pipeline is
761     suitable for link-time optimization and whole-module transformations.
762     See llvm::PassManager::PassManager. */
763 LLVMPassManagerRef LLVMCreatePassManager(void);
764
765 /** Constructs a new function-by-function pass pipeline over the module
766     provider. It does not take ownership of the module provider. This type of
767     pipeline is suitable for code generation and JIT compilation tasks.
768     See llvm::FunctionPassManager::FunctionPassManager. */
769 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
770
771 /** Initializes, executes on the provided module, and finalizes all of the
772     passes scheduled in the pass manager. Returns 1 if any of the passes
773     modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
774 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
775
776 /** Initializes all of the function passes scheduled in the function pass
777     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
778     See llvm::FunctionPassManager::doInitialization. */
779 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
780
781 /** Executes all of the function passes scheduled in the function pass manager
782     on the provided function. Returns 1 if any of the passes modified the
783     function, false otherwise.
784     See llvm::FunctionPassManager::run(Function&). */
785 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
786
787 /** Finalizes all of the function passes scheduled in in the function pass
788     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
789     See llvm::FunctionPassManager::doFinalization. */
790 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
791
792 /** Frees the memory of a pass pipeline. For function pipelines, does not free
793     the module provider.
794     See llvm::PassManagerBase::~PassManagerBase. */
795 void LLVMDisposePassManager(LLVMPassManagerRef PM);
796
797
798 #ifdef __cplusplus
799 }
800
801 namespace llvm {
802   class ModuleProvider;
803   class MemoryBuffer;
804   class PassManagerBase;
805   
806   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
807     inline ty *unwrap(ref P) {                          \
808       return reinterpret_cast<ty*>(P);                  \
809     }                                                   \
810                                                         \
811     inline ref wrap(const ty *P) {                      \
812       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
813     }
814   
815   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
816     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
817                                                         \
818     template<typename T>                                \
819     inline T *unwrap(ref P) {                           \
820       return cast<T>(unwrap(P));                        \
821     }
822   
823   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
824     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
825                                                         \
826     template<typename T>                                \
827     inline T *unwrap(ref P) {                           \
828       T *Q = dynamic_cast<T*>(unwrap(P));               \
829       assert(Q && "Invalid cast!");                     \
830       return Q;                                         \
831     }
832   
833   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
834   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
835   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
836   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
837   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
838   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
839   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
840   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
841   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
842   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
843   
844   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
845   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
846   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
847   
848   /* Specialized opaque type conversions.
849    */
850   inline Type **unwrap(LLVMTypeRef* Tys) {
851     return reinterpret_cast<Type**>(Tys);
852   }
853   
854   inline LLVMTypeRef *wrap(const Type **Tys) {
855     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
856   }
857   
858   /* Specialized opaque value conversions.
859    */ 
860   inline Value **unwrap(LLVMValueRef *Vals) {
861     return reinterpret_cast<Value**>(Vals);
862   }
863   
864   template<typename T>
865   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
866     #if DEBUG
867     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
868       cast<T>(*I);
869     #endif
870     return reinterpret_cast<T**>(Vals);
871   }
872   
873   inline LLVMValueRef *wrap(const Value **Vals) {
874     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
875   }
876 }
877
878 #endif /* !defined(__cplusplus) */
879
880 #endif /* !defined(LLVM_C_CORE_H) */