Fix copy & paste errors
[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 } LLVMLinkage;
151
152 typedef enum {
153   LLVMDefaultVisibility,  /**< The GV is visible */
154   LLVMHiddenVisibility,   /**< The GV is hidden */
155   LLVMProtectedVisibility /**< The GV is protected */
156 } LLVMVisibility;
157
158 typedef enum {
159   LLVMCCallConv           = 0,
160   LLVMFastCallConv        = 8,
161   LLVMColdCallConv        = 9,
162   LLVMX86StdcallCallConv  = 64,
163   LLVMX86FastcallCallConv = 65
164 } LLVMCallConv;
165
166 typedef enum {
167   LLVMIntEQ = 32, /**< equal */
168   LLVMIntNE,      /**< not equal */
169   LLVMIntUGT,     /**< unsigned greater than */
170   LLVMIntUGE,     /**< unsigned greater or equal */
171   LLVMIntULT,     /**< unsigned less than */
172   LLVMIntULE,     /**< unsigned less or equal */
173   LLVMIntSGT,     /**< signed greater than */
174   LLVMIntSGE,     /**< signed greater or equal */
175   LLVMIntSLT,     /**< signed less than */
176   LLVMIntSLE      /**< signed less or equal */
177 } LLVMIntPredicate;
178
179 typedef enum {
180   LLVMRealPredicateFalse, /**< Always false (always folded) */
181   LLVMRealOEQ,            /**< True if ordered and equal */
182   LLVMRealOGT,            /**< True if ordered and greater than */
183   LLVMRealOGE,            /**< True if ordered and greater than or equal */
184   LLVMRealOLT,            /**< True if ordered and less than */
185   LLVMRealOLE,            /**< True if ordered and less than or equal */
186   LLVMRealONE,            /**< True if ordered and operands are unequal */
187   LLVMRealORD,            /**< True if ordered (no nans) */
188   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
189   LLVMRealUEQ,            /**< True if unordered or equal */
190   LLVMRealUGT,            /**< True if unordered or greater than */
191   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
192   LLVMRealULT,            /**< True if unordered or less than */
193   LLVMRealULE,            /**< True if unordered, less than, or equal */
194   LLVMRealUNE,            /**< True if unordered or not equal */
195   LLVMRealPredicateTrue   /**< Always true (always folded) */
196 } LLVMRealPredicate;
197
198
199 /*===-- Error handling ----------------------------------------------------===*/
200
201 void LLVMDisposeMessage(char *Message);
202
203
204 /*===-- Modules -----------------------------------------------------------===*/
205
206 /* Create and destroy contexts. */
207 LLVMContextRef LLVMContextCreate();
208 LLVMContextRef LLVMGetGlobalContext();
209 void LLVMContextDispose(LLVMContextRef C);
210
211 /* Create and destroy modules. */ 
212 /** See llvm::Module::Module. */
213 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
214 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
215                                                 LLVMContextRef C);
216
217 /** See llvm::Module::~Module. */
218 void LLVMDisposeModule(LLVMModuleRef M);
219
220 /** Data layout. See Module::getDataLayout. */
221 const char *LLVMGetDataLayout(LLVMModuleRef M);
222 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
223
224 /** Target triple. See Module::getTargetTriple. */
225 const char *LLVMGetTarget(LLVMModuleRef M);
226 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
227
228 /** See Module::addTypeName. */
229 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
230 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
231 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
232
233 /** See Module::dump. */
234 void LLVMDumpModule(LLVMModuleRef M);
235
236
237 /*===-- Types -------------------------------------------------------------===*/
238
239 /* LLVM types conform to the following hierarchy:
240  * 
241  *   types:
242  *     integer type
243  *     real type
244  *     function type
245  *     sequence types:
246  *       array type
247  *       pointer type
248  *       vector type
249  *     void type
250  *     label type
251  *     opaque type
252  */
253
254 /** See llvm::LLVMTypeKind::getTypeID. */
255 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
256
257 /* Operations on integer types */
258 LLVMTypeRef LLVMInt1Type(void);
259 LLVMTypeRef LLVMInt8Type(void);
260 LLVMTypeRef LLVMInt16Type(void);
261 LLVMTypeRef LLVMInt32Type(void);
262 LLVMTypeRef LLVMInt64Type(void);
263 LLVMTypeRef LLVMIntType(unsigned NumBits);
264 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
265
266 /* Operations on real types */
267 LLVMTypeRef LLVMFloatType(void);
268 LLVMTypeRef LLVMDoubleType(void);
269 LLVMTypeRef LLVMX86FP80Type(void);
270 LLVMTypeRef LLVMFP128Type(void);
271 LLVMTypeRef LLVMPPCFP128Type(void);
272
273 /* Operations on function types */
274 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
275                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
276                              int IsVarArg);
277 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
278 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
279 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
280 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
281
282 /* Operations on struct types */
283 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
284                            int Packed);
285 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
286 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
287 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
288
289 /* Operations on array, pointer, and vector types (sequence types) */
290 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
291 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
292 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
293
294 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
295 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
296 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
297 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
298
299 /* Operations on other types */
300 LLVMTypeRef LLVMVoidType(void);
301 LLVMTypeRef LLVMLabelType(void);
302 LLVMTypeRef LLVMOpaqueType(void);
303
304 /* Operations on type handles */
305 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
306 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
307 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
308 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
309
310
311 /*===-- Values ------------------------------------------------------------===*/
312
313 /* The bulk of LLVM's object model consists of values, which comprise a very
314  * rich type hierarchy.
315  */
316
317 #define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
318   macro(Argument)                           \
319   macro(BasicBlock)                         \
320   macro(InlineAsm)                          \
321   macro(User)                               \
322     macro(Constant)                         \
323       macro(ConstantAggregateZero)          \
324       macro(ConstantArray)                  \
325       macro(ConstantExpr)                   \
326       macro(ConstantFP)                     \
327       macro(ConstantInt)                    \
328       macro(ConstantPointerNull)            \
329       macro(ConstantStruct)                 \
330       macro(ConstantVector)                 \
331       macro(GlobalValue)                    \
332         macro(Function)                     \
333         macro(GlobalAlias)                  \
334         macro(GlobalVariable)               \
335       macro(UndefValue)                     \
336     macro(Instruction)                      \
337       macro(BinaryOperator)                 \
338       macro(CallInst)                       \
339         macro(IntrinsicInst)                \
340           macro(DbgInfoIntrinsic)           \
341             macro(DbgDeclareInst)           \
342             macro(DbgFuncStartInst)         \
343             macro(DbgRegionEndInst)         \
344             macro(DbgRegionStartInst)       \
345             macro(DbgStopPointInst)         \
346           macro(EHSelectorInst)             \
347           macro(MemIntrinsic)               \
348             macro(MemCpyInst)               \
349             macro(MemMoveInst)              \
350             macro(MemSetInst)               \
351       macro(CmpInst)                        \
352       macro(FCmpInst)                       \
353       macro(ICmpInst)                       \
354       macro(ExtractElementInst)             \
355       macro(GetElementPtrInst)              \
356       macro(InsertElementInst)              \
357       macro(InsertValueInst)                \
358       macro(PHINode)                        \
359       macro(SelectInst)                     \
360       macro(ShuffleVectorInst)              \
361       macro(StoreInst)                      \
362       macro(TerminatorInst)                 \
363         macro(BranchInst)                   \
364         macro(InvokeInst)                   \
365         macro(ReturnInst)                   \
366         macro(SwitchInst)                   \
367         macro(UnreachableInst)              \
368         macro(UnwindInst)                   \
369     macro(UnaryInstruction)                 \
370       macro(AllocationInst)                 \
371         macro(AllocaInst)                   \
372         macro(MallocInst)                   \
373       macro(CastInst)                       \
374         macro(BitCastInst)                  \
375         macro(FPExtInst)                    \
376         macro(FPToSIInst)                   \
377         macro(FPToUIInst)                   \
378         macro(FPTruncInst)                  \
379         macro(IntToPtrInst)                 \
380         macro(PtrToIntInst)                 \
381         macro(SExtInst)                     \
382         macro(SIToFPInst)                   \
383         macro(TruncInst)                    \
384         macro(UIToFPInst)                   \
385         macro(ZExtInst)                     \
386       macro(ExtractValueInst)               \
387       macro(FreeInst)                       \
388       macro(LoadInst)                       \
389       macro(VAArgInst)
390
391 /* Operations on all values */
392 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
393 const char *LLVMGetValueName(LLVMValueRef Val);
394 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
395 void LLVMDumpValue(LLVMValueRef Val);
396
397 /* Conversion functions. Return the input value if it is an instance of the
398    specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
399 #define LLVM_DECLARE_VALUE_CAST(name) \
400   LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
401 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
402
403 /* Operations on constants of any type */
404 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
405 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
406 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
407 int LLVMIsConstant(LLVMValueRef Val);
408 int LLVMIsNull(LLVMValueRef Val);
409 int LLVMIsUndef(LLVMValueRef Val);
410 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
411
412 /* Operations on scalar constants */
413 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
414                           int SignExtend);
415 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
416 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
417
418 /* Operations on composite constants */
419 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
420                              int DontNullTerminate);
421 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
422                             LLVMValueRef *ConstantVals, unsigned Length);
423 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
424                              int packed);
425 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
426
427 /* Constant expressions */
428 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
429 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
430 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
431 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
432 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
433 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
434 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
435 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
436 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
437 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
438 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
439 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
440 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
441 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
442 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
443 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
444                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
445 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
446                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
447 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
448 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
449 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
450 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
451                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
452 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
453 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
454 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
455 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
456 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
457 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
458 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
459 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
460 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
461 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
462 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
463 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
464 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
465                              LLVMValueRef ConstantIfTrue,
466                              LLVMValueRef ConstantIfFalse);
467 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
468                                      LLVMValueRef IndexConstant);
469 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
470                                     LLVMValueRef ElementValueConstant,
471                                     LLVMValueRef IndexConstant);
472 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
473                                     LLVMValueRef VectorBConstant,
474                                     LLVMValueRef MaskConstant);
475 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
476                                    unsigned NumIdx);
477 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
478                                   LLVMValueRef ElementValueConstant,
479                                   unsigned *IdxList, unsigned NumIdx);
480 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, 
481                                 const char *AsmString, const char *Constraints,
482                                 int HasSideEffects);
483
484 /* Operations on global variables, functions, and aliases (globals) */
485 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
486 int LLVMIsDeclaration(LLVMValueRef Global);
487 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
488 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
489 const char *LLVMGetSection(LLVMValueRef Global);
490 void LLVMSetSection(LLVMValueRef Global, const char *Section);
491 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
492 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
493 unsigned LLVMGetAlignment(LLVMValueRef Global);
494 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
495
496 /* Operations on global variables */
497 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
498 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
499 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
500 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
501 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
502 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
503 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
504 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
505 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
506 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
507 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
508 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
509 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
510
511 /* Operations on aliases */
512 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
513                           const char *Name);
514
515 /* Operations on functions */
516 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
517                              LLVMTypeRef FunctionTy);
518 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
519 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
520 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
521 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
522 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
523 void LLVMDeleteFunction(LLVMValueRef Fn);
524 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
525 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
526 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
527 const char *LLVMGetGC(LLVMValueRef Fn);
528 void LLVMSetGC(LLVMValueRef Fn, const char *Name);
529 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
530 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
531
532 /* Operations on parameters */
533 unsigned LLVMCountParams(LLVMValueRef Fn);
534 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
535 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
536 LLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
537 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
538 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
539 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
540 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
541 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
542 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
543 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
544
545 /* Operations on basic blocks */
546 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
547 int LLVMValueIsBasicBlock(LLVMValueRef Val);
548 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
549 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
550 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
551 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
552 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
553 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
554 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
555 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
556 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
557 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
558 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
559                                        const char *Name);
560 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
561
562 /* Operations on instructions */
563 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
564 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
565 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
566 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
567 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
568
569 /* Operations on call sites */
570 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
571 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
572 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
573 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, 
574                               LLVMAttribute);
575 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 
576                                 unsigned align);
577
578 /* Operations on call instructions (only) */
579 int LLVMIsTailCall(LLVMValueRef CallInst);
580 void LLVMSetTailCall(LLVMValueRef CallInst, int IsTailCall);
581
582 /* Operations on phi nodes */
583 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
584                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
585 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
586 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
587 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
588
589 /*===-- Instruction builders ----------------------------------------------===*/
590
591 /* An instruction builder represents a point within a basic block, and is the
592  * exclusive means of building instructions using the C interface.
593  */
594
595 LLVMBuilderRef LLVMCreateBuilder(void);
596 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
597                          LLVMValueRef Instr);
598 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
599 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
600 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
601 void LLVMClearInsertionPosition(LLVMBuilderRef Builder);
602 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
603 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
604
605 /* Terminators */
606 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
607 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
608 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
609 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
610                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
611 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
612                              LLVMBasicBlockRef Else, unsigned NumCases);
613 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
614                              LLVMValueRef *Args, unsigned NumArgs,
615                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
616                              const char *Name);
617 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
618 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
619
620 /* Add a case to the switch instruction */
621 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
622                  LLVMBasicBlockRef Dest);
623
624 /* Arithmetic */
625 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
626                           const char *Name);
627 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
628                           const char *Name);
629 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
630                           const char *Name);
631 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
632                            const char *Name);
633 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
634                            const char *Name);
635 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
636                            const char *Name);
637 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
638                            const char *Name);
639 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
640                            const char *Name);
641 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
642                            const char *Name);
643 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
644                            const char *Name);
645 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
646                            const char *Name);
647 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
648                            const char *Name);
649 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
650                           const char *Name);
651 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
652                           const char *Name);
653 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
654                           const char *Name);
655 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
656 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
657
658 /* Memory */
659 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
660 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
661                                   LLVMValueRef Val, const char *Name);
662 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
663 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
664                                   LLVMValueRef Val, const char *Name);
665 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
666 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
667                            const char *Name);
668 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
669 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
670                           LLVMValueRef *Indices, unsigned NumIndices,
671                           const char *Name);
672
673 /* Casts */
674 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
675                             LLVMTypeRef DestTy, const char *Name);
676 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
677                            LLVMTypeRef DestTy, const char *Name);
678 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
679                            LLVMTypeRef DestTy, const char *Name);
680 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
681                              LLVMTypeRef DestTy, const char *Name);
682 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
683                              LLVMTypeRef DestTy, const char *Name);
684 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
685                              LLVMTypeRef DestTy, const char *Name);
686 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
687                              LLVMTypeRef DestTy, const char *Name);
688 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
689                               LLVMTypeRef DestTy, const char *Name);
690 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
691                             LLVMTypeRef DestTy, const char *Name);
692 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
693                                LLVMTypeRef DestTy, const char *Name);
694 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
695                                LLVMTypeRef DestTy, const char *Name);
696 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
697                               LLVMTypeRef DestTy, const char *Name);
698
699 /* Comparisons */
700 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
701                            LLVMValueRef LHS, LLVMValueRef RHS,
702                            const char *Name);
703 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
704                            LLVMValueRef LHS, LLVMValueRef RHS,
705                            const char *Name);
706
707 /* Miscellaneous instructions */
708 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
709 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
710                            LLVMValueRef *Args, unsigned NumArgs,
711                            const char *Name);
712 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
713                              LLVMValueRef Then, LLVMValueRef Else,
714                              const char *Name);
715 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
716                             const char *Name);
717 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
718                                      LLVMValueRef Index, const char *Name);
719 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
720                                     LLVMValueRef EltVal, LLVMValueRef Index,
721                                     const char *Name);
722 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
723                                     LLVMValueRef V2, LLVMValueRef Mask,
724                                     const char *Name);
725 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
726                                    unsigned Index, const char *Name);
727 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
728                                   LLVMValueRef EltVal, unsigned Index,
729                                   const char *Name);
730
731
732 /*===-- Module providers --------------------------------------------------===*/
733
734 /* Encapsulates the module M in a module provider, taking ownership of the
735  * module.
736  * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
737  */
738 LLVMModuleProviderRef
739 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
740
741 /* Destroys the module provider MP as well as the contained module.
742  * See the destructor llvm::ModuleProvider::~ModuleProvider.
743  */
744 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
745
746
747 /*===-- Memory buffers ----------------------------------------------------===*/
748
749 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
750                                              LLVMMemoryBufferRef *OutMemBuf,
751                                              char **OutMessage);
752 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
753                                     char **OutMessage);
754 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
755
756
757 /*===-- Pass Managers -----------------------------------------------------===*/
758
759 /** Constructs a new whole-module pass pipeline. This type of pipeline is
760     suitable for link-time optimization and whole-module transformations.
761     See llvm::PassManager::PassManager. */
762 LLVMPassManagerRef LLVMCreatePassManager(void);
763
764 /** Constructs a new function-by-function pass pipeline over the module
765     provider. It does not take ownership of the module provider. This type of
766     pipeline is suitable for code generation and JIT compilation tasks.
767     See llvm::FunctionPassManager::FunctionPassManager. */
768 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
769
770 /** Initializes, executes on the provided module, and finalizes all of the
771     passes scheduled in the pass manager. Returns 1 if any of the passes
772     modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
773 int LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
774
775 /** Initializes all of the function passes scheduled in the function pass
776     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
777     See llvm::FunctionPassManager::doInitialization. */
778 int LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
779
780 /** Executes all of the function passes scheduled in the function pass manager
781     on the provided function. Returns 1 if any of the passes modified the
782     function, false otherwise.
783     See llvm::FunctionPassManager::run(Function&). */
784 int LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
785
786 /** Finalizes all of the function passes scheduled in in the function pass
787     manager. Returns 1 if any of the passes modified the module, 0 otherwise.
788     See llvm::FunctionPassManager::doFinalization. */
789 int LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
790
791 /** Frees the memory of a pass pipeline. For function pipelines, does not free
792     the module provider.
793     See llvm::PassManagerBase::~PassManagerBase. */
794 void LLVMDisposePassManager(LLVMPassManagerRef PM);
795
796
797 #ifdef __cplusplus
798 }
799
800 namespace llvm {
801   class ModuleProvider;
802   class MemoryBuffer;
803   class PassManagerBase;
804   
805   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
806     inline ty *unwrap(ref P) {                          \
807       return reinterpret_cast<ty*>(P);                  \
808     }                                                   \
809                                                         \
810     inline ref wrap(const ty *P) {                      \
811       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
812     }
813   
814   #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
815     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
816                                                         \
817     template<typename T>                                \
818     inline T *unwrap(ref P) {                           \
819       return cast<T>(unwrap(P));                        \
820     }
821   
822   #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
823     DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
824                                                         \
825     template<typename T>                                \
826     inline T *unwrap(ref P) {                           \
827       T *Q = dynamic_cast<T*>(unwrap(P));               \
828       assert(Q && "Invalid cast!");                     \
829       return Q;                                         \
830     }
831   
832   DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
833   DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
834   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
835   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
836   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
837   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
838   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
839   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
840   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
841   DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
842   
843   #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
844   #undef DEFINE_ISA_CONVERSION_FUNCTIONS
845   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
846   
847   /* Specialized opaque type conversions.
848    */
849   inline Type **unwrap(LLVMTypeRef* Tys) {
850     return reinterpret_cast<Type**>(Tys);
851   }
852   
853   inline LLVMTypeRef *wrap(const Type **Tys) {
854     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
855   }
856   
857   /* Specialized opaque value conversions.
858    */ 
859   inline Value **unwrap(LLVMValueRef *Vals) {
860     return reinterpret_cast<Value**>(Vals);
861   }
862   
863   template<typename T>
864   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
865     #if DEBUG
866     for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
867       cast<T>(*I);
868     #endif
869     return reinterpret_cast<T**>(Vals);
870   }
871   
872   inline LLVMValueRef *wrap(const Value **Vals) {
873     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
874   }
875 }
876
877 #endif /* !defined(__cplusplus) */
878
879 #endif /* !defined(LLVM_C_CORE_H) */