Core.h revision 202878
1193323Sed/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
2193323Sed|*                                                                            *|
3193323Sed|*                     The LLVM Compiler Infrastructure                       *|
4193323Sed|*                                                                            *|
5193323Sed|* This file is distributed under the University of Illinois Open Source      *|
6193323Sed|* License. See LICENSE.TXT for details.                                      *|
7193323Sed|*                                                                            *|
8193323Sed|*===----------------------------------------------------------------------===*|
9193323Sed|*                                                                            *|
10193323Sed|* This header declares the C interface to libLLVMCore.a, which implements    *|
11193323Sed|* the LLVM intermediate representation.                                      *|
12193323Sed|*                                                                            *|
13193323Sed|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
14193323Sed|* parameters must be passed as base types. Despite the declared types, most  *|
15193323Sed|* of the functions provided operate only on branches of the type hierarchy.  *|
16193323Sed|* The declared parameter names are descriptive and specify which type is     *|
17193323Sed|* required. Additionally, each type hierarchy is documented along with the   *|
18193323Sed|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
19193323Sed|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the   *|
20193323Sed|* form unwrap<RequiredType>(Param).                                          *|
21193323Sed|*                                                                            *|
22193323Sed|* Many exotic languages can interoperate with C code but have a harder time  *|
23193323Sed|* with C++ due to name mangling. So in addition to C, this interface enables *|
24193323Sed|* tools written in such languages.                                           *|
25193323Sed|*                                                                            *|
26193323Sed|* When included into a C++ source file, also declares 'wrap' and 'unwrap'    *|
27193323Sed|* helpers to perform opaque reference<-->pointer conversions. These helpers  *|
28193323Sed|* are shorter and more tightly typed than writing the casts by hand when     *|
29193323Sed|* authoring bindings. In assert builds, they will do runtime type checking.  *|
30193323Sed|*                                                                            *|
31193323Sed\*===----------------------------------------------------------------------===*/
32193323Sed
33193323Sed#ifndef LLVM_C_CORE_H
34193323Sed#define LLVM_C_CORE_H
35193323Sed
36198892Srdivacky#include "llvm/System/DataTypes.h"
37198090Srdivacky
38193323Sed#ifdef __cplusplus
39193323Sed
40193323Sed/* Need these includes to support the LLVM 'cast' template for the C++ 'wrap'
41193323Sed   and 'unwrap' conversion functions. */
42193323Sed#include "llvm/Module.h"
43193323Sed#include "llvm/Support/IRBuilder.h"
44193323Sed
45193323Sedextern "C" {
46193323Sed#endif
47193323Sed
48193323Sed
49202375Srdivackytypedef int LLVMBool;
50202375Srdivacky
51193323Sed/* Opaque types. */
52193323Sed
53193323Sed/**
54195340Sed * The top-level container for all LLVM global data.  See the LLVMContext class.
55195340Sed */
56198090Srdivackytypedef struct LLVMOpaqueContext *LLVMContextRef;
57195340Sed
58195340Sed/**
59193323Sed * The top-level container for all other LLVM Intermediate Representation (IR)
60193323Sed * objects. See the llvm::Module class.
61193323Sed */
62193323Sedtypedef struct LLVMOpaqueModule *LLVMModuleRef;
63193323Sed
64193323Sed/**
65193323Sed * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
66193323Sed * class.
67193323Sed */
68193323Sedtypedef struct LLVMOpaqueType *LLVMTypeRef;
69193323Sed
70193323Sed/**
71193323Sed * When building recursive types using LLVMRefineType, LLVMTypeRef values may
72193323Sed * become invalid; use LLVMTypeHandleRef to resolve this problem. See the
73193323Sed * llvm::AbstractTypeHolder class.
74193323Sed */
75193323Sedtypedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
76193323Sed
77193323Sedtypedef struct LLVMOpaqueValue *LLVMValueRef;
78193323Sedtypedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
79193323Sedtypedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
80193323Sed
81193323Sed/* Used to provide a module to JIT or interpreter.
82193323Sed * See the llvm::ModuleProvider class.
83193323Sed */
84193323Sedtypedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
85193323Sed
86193323Sed/* Used to provide a module to JIT or interpreter.
87193323Sed * See the llvm::MemoryBuffer class.
88193323Sed */
89193323Sedtypedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
90193323Sed
91193323Sed/** See the llvm::PassManagerBase class. */
92193323Sedtypedef struct LLVMOpaquePassManager *LLVMPassManagerRef;
93193323Sed
94198090Srdivacky/**
95198090Srdivacky * Used to iterate through the uses of a Value, allowing access to all Values
96198090Srdivacky * that use this Value.  See the llvm::Use and llvm::value_use_iterator classes.
97198090Srdivacky */
98198090Srdivackytypedef struct LLVMOpaqueUseIterator *LLVMUseIteratorRef;
99198090Srdivacky
100193323Sedtypedef enum {
101193323Sed    LLVMZExtAttribute       = 1<<0,
102193323Sed    LLVMSExtAttribute       = 1<<1,
103193323Sed    LLVMNoReturnAttribute   = 1<<2,
104193323Sed    LLVMInRegAttribute      = 1<<3,
105193323Sed    LLVMStructRetAttribute  = 1<<4,
106193323Sed    LLVMNoUnwindAttribute   = 1<<5,
107193323Sed    LLVMNoAliasAttribute    = 1<<6,
108193323Sed    LLVMByValAttribute      = 1<<7,
109193323Sed    LLVMNestAttribute       = 1<<8,
110193323Sed    LLVMReadNoneAttribute   = 1<<9,
111198090Srdivacky    LLVMReadOnlyAttribute   = 1<<10,
112198090Srdivacky    LLVMNoInlineAttribute   = 1<<11,
113198090Srdivacky    LLVMAlwaysInlineAttribute    = 1<<12,
114198090Srdivacky    LLVMOptimizeForSizeAttribute = 1<<13,
115198090Srdivacky    LLVMStackProtectAttribute    = 1<<14,
116198090Srdivacky    LLVMStackProtectReqAttribute = 1<<15,
117198090Srdivacky    LLVMNoCaptureAttribute  = 1<<21,
118198090Srdivacky    LLVMNoRedZoneAttribute  = 1<<22,
119198090Srdivacky    LLVMNoImplicitFloatAttribute = 1<<23,
120202878Srdivacky    LLVMNakedAttribute      = 1<<24
121193323Sed} LLVMAttribute;
122193323Sed
123193323Sedtypedef enum {
124198090Srdivacky  LLVMRet            = 1,
125198090Srdivacky  LLVMBr             = 2,
126198090Srdivacky  LLVMSwitch         = 3,
127198090Srdivacky  LLVMInvoke         = 4,
128198090Srdivacky  LLVMUnwind         = 5,
129198090Srdivacky  LLVMUnreachable    = 6,
130198090Srdivacky  LLVMAdd            = 7,
131198090Srdivacky  LLVMFAdd           = 8,
132198090Srdivacky  LLVMSub            = 9,
133198090Srdivacky  LLVMFSub           = 10,
134198090Srdivacky  LLVMMul            = 11,
135198090Srdivacky  LLVMFMul           = 12,
136198090Srdivacky  LLVMUDiv           = 13,
137198090Srdivacky  LLVMSDiv           = 14,
138198090Srdivacky  LLVMFDiv           = 15,
139198090Srdivacky  LLVMURem           = 16,
140198090Srdivacky  LLVMSRem           = 17,
141198090Srdivacky  LLVMFRem           = 18,
142198090Srdivacky  LLVMShl            = 19,
143198090Srdivacky  LLVMLShr           = 20,
144198090Srdivacky  LLVMAShr           = 21,
145198090Srdivacky  LLVMAnd            = 22,
146198090Srdivacky  LLVMOr             = 23,
147198090Srdivacky  LLVMXor            = 24,
148198090Srdivacky  LLVMMalloc         = 25,
149198090Srdivacky  LLVMFree           = 26,
150198090Srdivacky  LLVMAlloca         = 27,
151198090Srdivacky  LLVMLoad           = 28,
152198090Srdivacky  LLVMStore          = 29,
153198090Srdivacky  LLVMGetElementPtr  = 30,
154198090Srdivacky  LLVMTrunk          = 31,
155198090Srdivacky  LLVMZExt           = 32,
156198090Srdivacky  LLVMSExt           = 33,
157198090Srdivacky  LLVMFPToUI         = 34,
158198090Srdivacky  LLVMFPToSI         = 35,
159198090Srdivacky  LLVMUIToFP         = 36,
160198090Srdivacky  LLVMSIToFP         = 37,
161198090Srdivacky  LLVMFPTrunc        = 38,
162198090Srdivacky  LLVMFPExt          = 39,
163198090Srdivacky  LLVMPtrToInt       = 40,
164198090Srdivacky  LLVMIntToPtr       = 41,
165198090Srdivacky  LLVMBitCast        = 42,
166198090Srdivacky  LLVMICmp           = 43,
167198090Srdivacky  LLVMFCmp           = 44,
168198090Srdivacky  LLVMPHI            = 45,
169198090Srdivacky  LLVMCall           = 46,
170198090Srdivacky  LLVMSelect         = 47,
171198090Srdivacky  LLVMVAArg          = 50,
172198090Srdivacky  LLVMExtractElement = 51,
173198090Srdivacky  LLVMInsertElement  = 52,
174198090Srdivacky  LLVMShuffleVector  = 53,
175198090Srdivacky  LLVMExtractValue   = 54,
176198090Srdivacky  LLVMInsertValue    = 55
177198090Srdivacky} LLVMOpcode;
178198090Srdivacky
179198090Srdivackytypedef enum {
180193323Sed  LLVMVoidTypeKind,        /**< type with no size */
181193323Sed  LLVMFloatTypeKind,       /**< 32 bit floating point type */
182193323Sed  LLVMDoubleTypeKind,      /**< 64 bit floating point type */
183193323Sed  LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
184193323Sed  LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
185193323Sed  LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
186193323Sed  LLVMLabelTypeKind,       /**< Labels */
187193323Sed  LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
188193323Sed  LLVMFunctionTypeKind,    /**< Functions */
189193323Sed  LLVMStructTypeKind,      /**< Structures */
190193323Sed  LLVMArrayTypeKind,       /**< Arrays */
191193323Sed  LLVMPointerTypeKind,     /**< Pointers */
192193323Sed  LLVMOpaqueTypeKind,      /**< Opaque: type with unknown structure */
193198090Srdivacky  LLVMVectorTypeKind,      /**< SIMD 'packed' format, or other vector type */
194198090Srdivacky  LLVMMetadataTypeKind     /**< Metadata */
195193323Sed} LLVMTypeKind;
196193323Sed
197193323Sedtypedef enum {
198193323Sed  LLVMExternalLinkage,    /**< Externally visible function */
199193323Sed  LLVMAvailableExternallyLinkage,
200193323Sed  LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
201193323Sed  LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
202193323Sed                            equivalent. */
203193323Sed  LLVMWeakAnyLinkage,     /**< Keep one copy of function when linking (weak) */
204193323Sed  LLVMWeakODRLinkage,     /**< Same, but only replaced by something
205193323Sed                            equivalent. */
206193323Sed  LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
207193323Sed  LLVMInternalLinkage,    /**< Rename collisions when linking (static
208193323Sed                               functions) */
209193323Sed  LLVMPrivateLinkage,     /**< Like Internal, but omit from symbol table */
210193323Sed  LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
211193323Sed  LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
212193323Sed  LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
213193323Sed  LLVMGhostLinkage,       /**< Stand-in functions for streaming fns from
214193323Sed                               bitcode */
215198090Srdivacky  LLVMCommonLinkage,      /**< Tentative definitions */
216198090Srdivacky  LLVMLinkerPrivateLinkage /**< Like Private, but linker removes. */
217193323Sed} LLVMLinkage;
218193323Sed
219193323Sedtypedef enum {
220193323Sed  LLVMDefaultVisibility,  /**< The GV is visible */
221193323Sed  LLVMHiddenVisibility,   /**< The GV is hidden */
222193323Sed  LLVMProtectedVisibility /**< The GV is protected */
223193323Sed} LLVMVisibility;
224193323Sed
225193323Sedtypedef enum {
226193323Sed  LLVMCCallConv           = 0,
227193323Sed  LLVMFastCallConv        = 8,
228193323Sed  LLVMColdCallConv        = 9,
229193323Sed  LLVMX86StdcallCallConv  = 64,
230193323Sed  LLVMX86FastcallCallConv = 65
231193323Sed} LLVMCallConv;
232193323Sed
233193323Sedtypedef enum {
234193323Sed  LLVMIntEQ = 32, /**< equal */
235193323Sed  LLVMIntNE,      /**< not equal */
236193323Sed  LLVMIntUGT,     /**< unsigned greater than */
237193323Sed  LLVMIntUGE,     /**< unsigned greater or equal */
238193323Sed  LLVMIntULT,     /**< unsigned less than */
239193323Sed  LLVMIntULE,     /**< unsigned less or equal */
240193323Sed  LLVMIntSGT,     /**< signed greater than */
241193323Sed  LLVMIntSGE,     /**< signed greater or equal */
242193323Sed  LLVMIntSLT,     /**< signed less than */
243193323Sed  LLVMIntSLE      /**< signed less or equal */
244193323Sed} LLVMIntPredicate;
245193323Sed
246193323Sedtypedef enum {
247193323Sed  LLVMRealPredicateFalse, /**< Always false (always folded) */
248193323Sed  LLVMRealOEQ,            /**< True if ordered and equal */
249193323Sed  LLVMRealOGT,            /**< True if ordered and greater than */
250193323Sed  LLVMRealOGE,            /**< True if ordered and greater than or equal */
251193323Sed  LLVMRealOLT,            /**< True if ordered and less than */
252193323Sed  LLVMRealOLE,            /**< True if ordered and less than or equal */
253193323Sed  LLVMRealONE,            /**< True if ordered and operands are unequal */
254193323Sed  LLVMRealORD,            /**< True if ordered (no nans) */
255193323Sed  LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
256193323Sed  LLVMRealUEQ,            /**< True if unordered or equal */
257193323Sed  LLVMRealUGT,            /**< True if unordered or greater than */
258193323Sed  LLVMRealUGE,            /**< True if unordered, greater than, or equal */
259193323Sed  LLVMRealULT,            /**< True if unordered or less than */
260193323Sed  LLVMRealULE,            /**< True if unordered, less than, or equal */
261193323Sed  LLVMRealUNE,            /**< True if unordered or not equal */
262193323Sed  LLVMRealPredicateTrue   /**< Always true (always folded) */
263193323Sed} LLVMRealPredicate;
264193323Sed
265193323Sed
266193323Sed/*===-- Error handling ----------------------------------------------------===*/
267193323Sed
268193323Sedvoid LLVMDisposeMessage(char *Message);
269193323Sed
270193323Sed
271193323Sed/*===-- Modules -----------------------------------------------------------===*/
272193323Sed
273195340Sed/* Create and destroy contexts. */
274198090SrdivackyLLVMContextRef LLVMContextCreate(void);
275198090SrdivackyLLVMContextRef LLVMGetGlobalContext(void);
276195340Sedvoid LLVMContextDispose(LLVMContextRef C);
277195340Sed
278193323Sed/* Create and destroy modules. */
279193323Sed/** See llvm::Module::Module. */
280193323SedLLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
281195340SedLLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
282195340Sed                                                LLVMContextRef C);
283193323Sed
284193323Sed/** See llvm::Module::~Module. */
285193323Sedvoid LLVMDisposeModule(LLVMModuleRef M);
286193323Sed
287193323Sed/** Data layout. See Module::getDataLayout. */
288193323Sedconst char *LLVMGetDataLayout(LLVMModuleRef M);
289193323Sedvoid LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
290193323Sed
291193323Sed/** Target triple. See Module::getTargetTriple. */
292193323Sedconst char *LLVMGetTarget(LLVMModuleRef M);
293193323Sedvoid LLVMSetTarget(LLVMModuleRef M, const char *Triple);
294193323Sed
295193323Sed/** See Module::addTypeName. */
296202375SrdivackyLLVMBool LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
297193323Sedvoid LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
298198090SrdivackyLLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name);
299193323Sed
300193323Sed/** See Module::dump. */
301193323Sedvoid LLVMDumpModule(LLVMModuleRef M);
302193323Sed
303193323Sed
304193323Sed/*===-- Types -------------------------------------------------------------===*/
305193323Sed
306193323Sed/* LLVM types conform to the following hierarchy:
307193323Sed *
308193323Sed *   types:
309193323Sed *     integer type
310193323Sed *     real type
311193323Sed *     function type
312193323Sed *     sequence types:
313193323Sed *       array type
314193323Sed *       pointer type
315193323Sed *       vector type
316193323Sed *     void type
317193323Sed *     label type
318193323Sed *     opaque type
319193323Sed */
320193323Sed
321193323Sed/** See llvm::LLVMTypeKind::getTypeID. */
322193323SedLLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
323193323Sed
324198090Srdivacky/** See llvm::LLVMType::getContext. */
325198090SrdivackyLLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
326198090Srdivacky
327193323Sed/* Operations on integer types */
328198090SrdivackyLLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
329198090SrdivackyLLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
330198090SrdivackyLLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
331198090SrdivackyLLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
332198090SrdivackyLLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
333198090SrdivackyLLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits);
334198090Srdivacky
335193323SedLLVMTypeRef LLVMInt1Type(void);
336193323SedLLVMTypeRef LLVMInt8Type(void);
337193323SedLLVMTypeRef LLVMInt16Type(void);
338193323SedLLVMTypeRef LLVMInt32Type(void);
339193323SedLLVMTypeRef LLVMInt64Type(void);
340193323SedLLVMTypeRef LLVMIntType(unsigned NumBits);
341193323Sedunsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
342193323Sed
343193323Sed/* Operations on real types */
344198090SrdivackyLLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
345198090SrdivackyLLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
346198090SrdivackyLLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
347198090SrdivackyLLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
348198090SrdivackyLLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
349198090Srdivacky
350193323SedLLVMTypeRef LLVMFloatType(void);
351193323SedLLVMTypeRef LLVMDoubleType(void);
352193323SedLLVMTypeRef LLVMX86FP80Type(void);
353193323SedLLVMTypeRef LLVMFP128Type(void);
354193323SedLLVMTypeRef LLVMPPCFP128Type(void);
355193323Sed
356193323Sed/* Operations on function types */
357193323SedLLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
358193323Sed                             LLVMTypeRef *ParamTypes, unsigned ParamCount,
359202375Srdivacky                             LLVMBool IsVarArg);
360202375SrdivackyLLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
361193323SedLLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
362193323Sedunsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
363193323Sedvoid LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
364193323Sed
365193323Sed/* Operations on struct types */
366198090SrdivackyLLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
367202375Srdivacky                                    unsigned ElementCount, LLVMBool Packed);
368193323SedLLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
369202375Srdivacky                           LLVMBool Packed);
370193323Sedunsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
371193323Sedvoid LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
372202375SrdivackyLLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
373193323Sed
374193323Sed/* Operations on array, pointer, and vector types (sequence types) */
375193323SedLLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
376193323SedLLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
377193323SedLLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
378193323Sed
379193323SedLLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
380193323Sedunsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
381193323Sedunsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
382193323Sedunsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
383193323Sed
384193323Sed/* Operations on other types */
385198090SrdivackyLLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
386198090SrdivackyLLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
387198090SrdivackyLLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C);
388198090Srdivacky
389193323SedLLVMTypeRef LLVMVoidType(void);
390193323SedLLVMTypeRef LLVMLabelType(void);
391193323SedLLVMTypeRef LLVMOpaqueType(void);
392193323Sed
393193323Sed/* Operations on type handles */
394193323SedLLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
395193323Sedvoid LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
396193323SedLLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
397193323Sedvoid LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
398193323Sed
399193323Sed
400193323Sed/*===-- Values ------------------------------------------------------------===*/
401193323Sed
402193323Sed/* The bulk of LLVM's object model consists of values, which comprise a very
403193323Sed * rich type hierarchy.
404193323Sed */
405193323Sed
406193323Sed#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
407193323Sed  macro(Argument)                           \
408193323Sed  macro(BasicBlock)                         \
409193323Sed  macro(InlineAsm)                          \
410193323Sed  macro(User)                               \
411193323Sed    macro(Constant)                         \
412193323Sed      macro(ConstantAggregateZero)          \
413193323Sed      macro(ConstantArray)                  \
414193323Sed      macro(ConstantExpr)                   \
415193323Sed      macro(ConstantFP)                     \
416193323Sed      macro(ConstantInt)                    \
417193323Sed      macro(ConstantPointerNull)            \
418193323Sed      macro(ConstantStruct)                 \
419193323Sed      macro(ConstantVector)                 \
420193323Sed      macro(GlobalValue)                    \
421193323Sed        macro(Function)                     \
422193323Sed        macro(GlobalAlias)                  \
423193323Sed        macro(GlobalVariable)               \
424193323Sed      macro(UndefValue)                     \
425193323Sed    macro(Instruction)                      \
426193323Sed      macro(BinaryOperator)                 \
427193323Sed      macro(CallInst)                       \
428193323Sed        macro(IntrinsicInst)                \
429193323Sed          macro(DbgInfoIntrinsic)           \
430193323Sed            macro(DbgDeclareInst)           \
431193323Sed          macro(EHSelectorInst)             \
432193323Sed          macro(MemIntrinsic)               \
433193323Sed            macro(MemCpyInst)               \
434193323Sed            macro(MemMoveInst)              \
435193323Sed            macro(MemSetInst)               \
436193323Sed      macro(CmpInst)                        \
437193323Sed      macro(FCmpInst)                       \
438193323Sed      macro(ICmpInst)                       \
439193323Sed      macro(ExtractElementInst)             \
440193323Sed      macro(GetElementPtrInst)              \
441193323Sed      macro(InsertElementInst)              \
442193323Sed      macro(InsertValueInst)                \
443193323Sed      macro(PHINode)                        \
444193323Sed      macro(SelectInst)                     \
445193323Sed      macro(ShuffleVectorInst)              \
446193323Sed      macro(StoreInst)                      \
447193323Sed      macro(TerminatorInst)                 \
448193323Sed        macro(BranchInst)                   \
449193323Sed        macro(InvokeInst)                   \
450193323Sed        macro(ReturnInst)                   \
451193323Sed        macro(SwitchInst)                   \
452193323Sed        macro(UnreachableInst)              \
453193323Sed        macro(UnwindInst)                   \
454193323Sed    macro(UnaryInstruction)                 \
455198892Srdivacky      macro(AllocaInst)                     \
456193323Sed      macro(CastInst)                       \
457193323Sed        macro(BitCastInst)                  \
458193323Sed        macro(FPExtInst)                    \
459193323Sed        macro(FPToSIInst)                   \
460193323Sed        macro(FPToUIInst)                   \
461193323Sed        macro(FPTruncInst)                  \
462193323Sed        macro(IntToPtrInst)                 \
463193323Sed        macro(PtrToIntInst)                 \
464193323Sed        macro(SExtInst)                     \
465193323Sed        macro(SIToFPInst)                   \
466193323Sed        macro(TruncInst)                    \
467193323Sed        macro(UIToFPInst)                   \
468193323Sed        macro(ZExtInst)                     \
469193323Sed      macro(ExtractValueInst)               \
470193323Sed      macro(LoadInst)                       \
471193323Sed      macro(VAArgInst)
472193323Sed
473193323Sed/* Operations on all values */
474193323SedLLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
475193323Sedconst char *LLVMGetValueName(LLVMValueRef Val);
476193323Sedvoid LLVMSetValueName(LLVMValueRef Val, const char *Name);
477193323Sedvoid LLVMDumpValue(LLVMValueRef Val);
478198090Srdivackyvoid LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
479193323Sed
480193323Sed/* Conversion functions. Return the input value if it is an instance of the
481193323Sed   specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
482193323Sed#define LLVM_DECLARE_VALUE_CAST(name) \
483193323Sed  LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
484193323SedLLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
485193323Sed
486198090Srdivacky/* Operations on Uses */
487198090SrdivackyLLVMUseIteratorRef LLVMGetFirstUse(LLVMValueRef Val);
488198090SrdivackyLLVMUseIteratorRef LLVMGetNextUse(LLVMUseIteratorRef U);
489198090SrdivackyLLVMValueRef LLVMGetUser(LLVMUseIteratorRef U);
490198090SrdivackyLLVMValueRef LLVMGetUsedValue(LLVMUseIteratorRef U);
491198090Srdivacky
492198090Srdivacky/* Operations on Users */
493198090SrdivackyLLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index);
494198090Srdivacky
495193323Sed/* Operations on constants of any type */
496193323SedLLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
497193323SedLLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
498193323SedLLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
499202375SrdivackyLLVMBool LLVMIsConstant(LLVMValueRef Val);
500202375SrdivackyLLVMBool LLVMIsNull(LLVMValueRef Val);
501202375SrdivackyLLVMBool LLVMIsUndef(LLVMValueRef Val);
502198090SrdivackyLLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
503193323Sed
504193323Sed/* Operations on scalar constants */
505193323SedLLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
506202375Srdivacky                          LLVMBool SignExtend);
507198090SrdivackyLLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char *Text,
508198090Srdivacky                                  uint8_t Radix);
509198090SrdivackyLLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char *Text,
510198090Srdivacky                                         unsigned SLen, uint8_t Radix);
511193323SedLLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
512193323SedLLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
513198090SrdivackyLLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char *Text,
514198090Srdivacky                                          unsigned SLen);
515198090Srdivackyunsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal);
516198090Srdivackylong long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal);
517193323Sed
518198090Srdivacky
519193323Sed/* Operations on composite constants */
520198090SrdivackyLLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
521202375Srdivacky                                      unsigned Length, LLVMBool DontNullTerminate);
522198090SrdivackyLLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
523198090Srdivacky                                      LLVMValueRef *ConstantVals,
524202375Srdivacky                                      unsigned Count, LLVMBool Packed);
525198090Srdivacky
526193323SedLLVMValueRef LLVMConstString(const char *Str, unsigned Length,
527202375Srdivacky                             LLVMBool DontNullTerminate);
528193323SedLLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
529193323Sed                            LLVMValueRef *ConstantVals, unsigned Length);
530193323SedLLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
531202375Srdivacky                             LLVMBool Packed);
532193323SedLLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
533193323Sed
534193323Sed/* Constant expressions */
535198090SrdivackyLLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal);
536198090SrdivackyLLVMValueRef LLVMAlignOf(LLVMTypeRef Ty);
537193323SedLLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
538193323SedLLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
539198090SrdivackyLLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal);
540193323SedLLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
541193323SedLLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
542198090SrdivackyLLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
543198090SrdivackyLLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
544193323SedLLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
545198090SrdivackyLLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
546193323SedLLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
547198090SrdivackyLLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
548193323SedLLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
549193323SedLLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
550198090SrdivackyLLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
551193323SedLLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
552193323SedLLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
553193323SedLLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
554193323SedLLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
555193323SedLLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
556193323SedLLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
557193323SedLLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
558193323SedLLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
559193323Sed                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
560193323SedLLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
561193323Sed                           LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
562193323SedLLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
563193323SedLLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
564193323SedLLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
565193323SedLLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
566193323Sed                          LLVMValueRef *ConstantIndices, unsigned NumIndices);
567198090SrdivackyLLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
568198090Srdivacky                                  LLVMValueRef *ConstantIndices,
569198090Srdivacky                                  unsigned NumIndices);
570193323SedLLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
571193323SedLLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
572193323SedLLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
573193323SedLLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
574193323SedLLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
575193323SedLLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
576193323SedLLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
577193323SedLLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
578193323SedLLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
579193323SedLLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
580193323SedLLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
581193323SedLLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
582198090SrdivackyLLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
583198090Srdivacky                                    LLVMTypeRef ToType);
584198090SrdivackyLLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
585198090Srdivacky                                    LLVMTypeRef ToType);
586198090SrdivackyLLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
587198090Srdivacky                                     LLVMTypeRef ToType);
588198090SrdivackyLLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
589198090Srdivacky                                  LLVMTypeRef ToType);
590198090SrdivackyLLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
591202375Srdivacky                              LLVMBool isSigned);
592198090SrdivackyLLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
593193323SedLLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
594193323Sed                             LLVMValueRef ConstantIfTrue,
595193323Sed                             LLVMValueRef ConstantIfFalse);
596193323SedLLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
597193323Sed                                     LLVMValueRef IndexConstant);
598193323SedLLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
599193323Sed                                    LLVMValueRef ElementValueConstant,
600193323Sed                                    LLVMValueRef IndexConstant);
601193323SedLLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
602193323Sed                                    LLVMValueRef VectorBConstant,
603193323Sed                                    LLVMValueRef MaskConstant);
604193323SedLLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
605193323Sed                                   unsigned NumIdx);
606193323SedLLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
607193323Sed                                  LLVMValueRef ElementValueConstant,
608193323Sed                                  unsigned *IdxList, unsigned NumIdx);
609202375SrdivackyLLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty,
610193323Sed                                const char *AsmString, const char *Constraints,
611202375Srdivacky                                LLVMBool HasSideEffects, LLVMBool IsAlignStack);
612193323Sed
613193323Sed/* Operations on global variables, functions, and aliases (globals) */
614193323SedLLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global);
615202375SrdivackyLLVMBool LLVMIsDeclaration(LLVMValueRef Global);
616193323SedLLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
617193323Sedvoid LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
618193323Sedconst char *LLVMGetSection(LLVMValueRef Global);
619193323Sedvoid LLVMSetSection(LLVMValueRef Global, const char *Section);
620193323SedLLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
621193323Sedvoid LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
622193323Sedunsigned LLVMGetAlignment(LLVMValueRef Global);
623193323Sedvoid LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
624193323Sed
625193323Sed/* Operations on global variables */
626193323SedLLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
627193323SedLLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
628193323SedLLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M);
629193323SedLLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M);
630193323SedLLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar);
631193323SedLLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar);
632193323Sedvoid LLVMDeleteGlobal(LLVMValueRef GlobalVar);
633193323SedLLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
634193323Sedvoid LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
635202375SrdivackyLLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar);
636202375Srdivackyvoid LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal);
637202375SrdivackyLLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
638202375Srdivackyvoid LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant);
639193323Sed
640193323Sed/* Operations on aliases */
641193323SedLLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
642193323Sed                          const char *Name);
643193323Sed
644193323Sed/* Operations on functions */
645193323SedLLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
646193323Sed                             LLVMTypeRef FunctionTy);
647193323SedLLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
648193323SedLLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
649193323SedLLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
650193323SedLLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
651193323SedLLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
652193323Sedvoid LLVMDeleteFunction(LLVMValueRef Fn);
653193323Sedunsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
654193323Sedunsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
655193323Sedvoid LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
656193323Sedconst char *LLVMGetGC(LLVMValueRef Fn);
657193323Sedvoid LLVMSetGC(LLVMValueRef Fn, const char *Name);
658193323Sedvoid LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
659198090SrdivackyLLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn);
660193323Sedvoid LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
661193323Sed
662193323Sed/* Operations on parameters */
663193323Sedunsigned LLVMCountParams(LLVMValueRef Fn);
664193323Sedvoid LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
665193323SedLLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
666193323SedLLVMValueRef LLVMGetParamParent(LLVMValueRef Inst);
667193323SedLLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn);
668193323SedLLVMValueRef LLVMGetLastParam(LLVMValueRef Fn);
669193323SedLLVMValueRef LLVMGetNextParam(LLVMValueRef Arg);
670193323SedLLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg);
671193323Sedvoid LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA);
672193323Sedvoid LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA);
673198090SrdivackyLLVMAttribute LLVMGetAttribute(LLVMValueRef Arg);
674193323Sedvoid LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align);
675193323Sed
676193323Sed/* Operations on basic blocks */
677193323SedLLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB);
678202375SrdivackyLLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val);
679193323SedLLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
680193323SedLLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB);
681193323Sedunsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
682193323Sedvoid LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
683193323SedLLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn);
684193323SedLLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn);
685193323SedLLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB);
686193323SedLLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB);
687193323SedLLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
688198090Srdivacky
689198090SrdivackyLLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
690198090Srdivacky                                                LLVMValueRef Fn,
691198090Srdivacky                                                const char *Name);
692198090SrdivackyLLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
693198090Srdivacky                                                LLVMBasicBlockRef BB,
694198090Srdivacky                                                const char *Name);
695198090Srdivacky
696193323SedLLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
697193323SedLLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
698193323Sed                                       const char *Name);
699193323Sedvoid LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
700193323Sed
701193323Sed/* Operations on instructions */
702193323SedLLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst);
703193323SedLLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB);
704193323SedLLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB);
705193323SedLLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst);
706193323SedLLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst);
707193323Sed
708193323Sed/* Operations on call sites */
709193323Sedvoid LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
710193323Sedunsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
711193323Sedvoid LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
712193323Sedvoid LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
713193323Sed                              LLVMAttribute);
714193323Sedvoid LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
715193323Sed                                unsigned align);
716193323Sed
717193323Sed/* Operations on call instructions (only) */
718202375SrdivackyLLVMBool LLVMIsTailCall(LLVMValueRef CallInst);
719202375Srdivackyvoid LLVMSetTailCall(LLVMValueRef CallInst, LLVMBool IsTailCall);
720193323Sed
721193323Sed/* Operations on phi nodes */
722193323Sedvoid LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
723193323Sed                     LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
724193323Sedunsigned LLVMCountIncoming(LLVMValueRef PhiNode);
725193323SedLLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
726193323SedLLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
727193323Sed
728193323Sed/*===-- Instruction builders ----------------------------------------------===*/
729193323Sed
730193323Sed/* An instruction builder represents a point within a basic block, and is the
731193323Sed * exclusive means of building instructions using the C interface.
732193323Sed */
733193323Sed
734198090SrdivackyLLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C);
735193323SedLLVMBuilderRef LLVMCreateBuilder(void);
736193323Sedvoid LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
737193323Sed                         LLVMValueRef Instr);
738193323Sedvoid LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
739193323Sedvoid LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
740193323SedLLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder);
741193323Sedvoid LLVMClearInsertionPosition(LLVMBuilderRef Builder);
742193323Sedvoid LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr);
743198090Srdivackyvoid LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
744198090Srdivacky                                   const char *Name);
745193323Sedvoid LLVMDisposeBuilder(LLVMBuilderRef Builder);
746193323Sed
747193323Sed/* Terminators */
748193323SedLLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
749193323SedLLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
750198090SrdivackyLLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef, LLVMValueRef *RetVals,
751198090Srdivacky                                   unsigned N);
752193323SedLLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
753193323SedLLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
754193323Sed                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
755193323SedLLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
756193323Sed                             LLVMBasicBlockRef Else, unsigned NumCases);
757193323SedLLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
758193323Sed                             LLVMValueRef *Args, unsigned NumArgs,
759193323Sed                             LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
760193323Sed                             const char *Name);
761193323SedLLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
762193323SedLLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
763193323Sed
764193323Sed/* Add a case to the switch instruction */
765193323Sedvoid LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
766193323Sed                 LLVMBasicBlockRef Dest);
767193323Sed
768193323Sed/* Arithmetic */
769193323SedLLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
770193323Sed                          const char *Name);
771198090SrdivackyLLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
772198090Srdivacky                             const char *Name);
773198090SrdivackyLLVMValueRef LLVMBuildFAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
774198090Srdivacky                           const char *Name);
775193323SedLLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
776193323Sed                          const char *Name);
777198090SrdivackyLLVMValueRef LLVMBuildFSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
778198090Srdivacky                           const char *Name);
779193323SedLLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
780193323Sed                          const char *Name);
781198090SrdivackyLLVMValueRef LLVMBuildFMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
782198090Srdivacky                           const char *Name);
783193323SedLLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
784193323Sed                           const char *Name);
785193323SedLLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
786193323Sed                           const char *Name);
787198090SrdivackyLLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
788198090Srdivacky                                const char *Name);
789193323SedLLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
790193323Sed                           const char *Name);
791193323SedLLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
792193323Sed                           const char *Name);
793193323SedLLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
794193323Sed                           const char *Name);
795193323SedLLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
796193323Sed                           const char *Name);
797193323SedLLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
798193323Sed                           const char *Name);
799193323SedLLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
800193323Sed                           const char *Name);
801193323SedLLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
802193323Sed                           const char *Name);
803193323SedLLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
804193323Sed                          const char *Name);
805193323SedLLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
806193323Sed                          const char *Name);
807193323SedLLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
808193323Sed                          const char *Name);
809193323SedLLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
810198090SrdivackyLLVMValueRef LLVMBuildFNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
811193323SedLLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
812193323Sed
813193323Sed/* Memory */
814193323SedLLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
815193323SedLLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
816193323Sed                                  LLVMValueRef Val, const char *Name);
817193323SedLLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
818193323SedLLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
819193323Sed                                  LLVMValueRef Val, const char *Name);
820193323SedLLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
821193323SedLLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
822193323Sed                           const char *Name);
823193323SedLLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
824193323SedLLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
825193323Sed                          LLVMValueRef *Indices, unsigned NumIndices,
826193323Sed                          const char *Name);
827198090SrdivackyLLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
828198090Srdivacky                                  LLVMValueRef *Indices, unsigned NumIndices,
829198090Srdivacky                                  const char *Name);
830198090SrdivackyLLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
831198090Srdivacky                                unsigned Idx, const char *Name);
832198090SrdivackyLLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
833198090Srdivacky                                   const char *Name);
834198090SrdivackyLLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
835198090Srdivacky                                      const char *Name);
836193323Sed
837193323Sed/* Casts */
838193323SedLLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
839193323Sed                            LLVMTypeRef DestTy, const char *Name);
840193323SedLLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
841193323Sed                           LLVMTypeRef DestTy, const char *Name);
842193323SedLLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
843193323Sed                           LLVMTypeRef DestTy, const char *Name);
844193323SedLLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
845193323Sed                             LLVMTypeRef DestTy, const char *Name);
846193323SedLLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
847193323Sed                             LLVMTypeRef DestTy, const char *Name);
848193323SedLLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
849193323Sed                             LLVMTypeRef DestTy, const char *Name);
850193323SedLLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
851193323Sed                             LLVMTypeRef DestTy, const char *Name);
852193323SedLLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
853193323Sed                              LLVMTypeRef DestTy, const char *Name);
854193323SedLLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
855193323Sed                            LLVMTypeRef DestTy, const char *Name);
856193323SedLLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
857193323Sed                               LLVMTypeRef DestTy, const char *Name);
858193323SedLLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
859193323Sed                               LLVMTypeRef DestTy, const char *Name);
860193323SedLLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
861193323Sed                              LLVMTypeRef DestTy, const char *Name);
862198090SrdivackyLLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
863198090Srdivacky                                    LLVMTypeRef DestTy, const char *Name);
864198090SrdivackyLLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
865198090Srdivacky                                    LLVMTypeRef DestTy, const char *Name);
866198090SrdivackyLLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
867198090Srdivacky                                     LLVMTypeRef DestTy, const char *Name);
868198090SrdivackyLLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
869198090Srdivacky                                  LLVMTypeRef DestTy, const char *Name);
870199989SrdivackyLLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val, /*Signed cast!*/
871198090Srdivacky                              LLVMTypeRef DestTy, const char *Name);
872198090SrdivackyLLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
873198090Srdivacky                             LLVMTypeRef DestTy, const char *Name);
874193323Sed
875193323Sed/* Comparisons */
876193323SedLLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
877193323Sed                           LLVMValueRef LHS, LLVMValueRef RHS,
878193323Sed                           const char *Name);
879193323SedLLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
880193323Sed                           LLVMValueRef LHS, LLVMValueRef RHS,
881193323Sed                           const char *Name);
882193323Sed
883193323Sed/* Miscellaneous instructions */
884193323SedLLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
885193323SedLLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
886193323Sed                           LLVMValueRef *Args, unsigned NumArgs,
887193323Sed                           const char *Name);
888193323SedLLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
889193323Sed                             LLVMValueRef Then, LLVMValueRef Else,
890193323Sed                             const char *Name);
891193323SedLLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
892193323Sed                            const char *Name);
893193323SedLLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
894193323Sed                                     LLVMValueRef Index, const char *Name);
895193323SedLLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
896193323Sed                                    LLVMValueRef EltVal, LLVMValueRef Index,
897193323Sed                                    const char *Name);
898193323SedLLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
899193323Sed                                    LLVMValueRef V2, LLVMValueRef Mask,
900193323Sed                                    const char *Name);
901193323SedLLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef, LLVMValueRef AggVal,
902193323Sed                                   unsigned Index, const char *Name);
903193323SedLLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef, LLVMValueRef AggVal,
904193323Sed                                  LLVMValueRef EltVal, unsigned Index,
905193323Sed                                  const char *Name);
906193323Sed
907198090SrdivackyLLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
908198090Srdivacky                             const char *Name);
909198090SrdivackyLLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
910198090Srdivacky                                const char *Name);
911198090SrdivackyLLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
912198090Srdivacky                              LLVMValueRef RHS, const char *Name);
913193323Sed
914198090Srdivacky
915193323Sed/*===-- Module providers --------------------------------------------------===*/
916193323Sed
917193323Sed/* Encapsulates the module M in a module provider, taking ownership of the
918193323Sed * module.
919193323Sed * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
920193323Sed */
921193323SedLLVMModuleProviderRef
922193323SedLLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
923193323Sed
924193323Sed/* Destroys the module provider MP as well as the contained module.
925193323Sed * See the destructor llvm::ModuleProvider::~ModuleProvider.
926193323Sed */
927193323Sedvoid LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
928193323Sed
929193323Sed
930193323Sed/*===-- Memory buffers ----------------------------------------------------===*/
931193323Sed
932202375SrdivackyLLVMBool LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
933202375Srdivacky                                                  LLVMMemoryBufferRef *OutMemBuf,
934202375Srdivacky                                                  char **OutMessage);
935202375SrdivackyLLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
936202375Srdivacky                                         char **OutMessage);
937193323Sedvoid LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
938193323Sed
939193323Sed
940193323Sed/*===-- Pass Managers -----------------------------------------------------===*/
941193323Sed
942193323Sed/** Constructs a new whole-module pass pipeline. This type of pipeline is
943193323Sed    suitable for link-time optimization and whole-module transformations.
944193323Sed    See llvm::PassManager::PassManager. */
945193323SedLLVMPassManagerRef LLVMCreatePassManager(void);
946193323Sed
947193323Sed/** Constructs a new function-by-function pass pipeline over the module
948193323Sed    provider. It does not take ownership of the module provider. This type of
949193323Sed    pipeline is suitable for code generation and JIT compilation tasks.
950193323Sed    See llvm::FunctionPassManager::FunctionPassManager. */
951193323SedLLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef MP);
952193323Sed
953193323Sed/** Initializes, executes on the provided module, and finalizes all of the
954193323Sed    passes scheduled in the pass manager. Returns 1 if any of the passes
955193323Sed    modified the module, 0 otherwise. See llvm::PassManager::run(Module&). */
956202375SrdivackyLLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M);
957193323Sed
958193323Sed/** Initializes all of the function passes scheduled in the function pass
959193323Sed    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
960193323Sed    See llvm::FunctionPassManager::doInitialization. */
961202375SrdivackyLLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM);
962193323Sed
963193323Sed/** Executes all of the function passes scheduled in the function pass manager
964193323Sed    on the provided function. Returns 1 if any of the passes modified the
965193323Sed    function, false otherwise.
966193323Sed    See llvm::FunctionPassManager::run(Function&). */
967202375SrdivackyLLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F);
968193323Sed
969193323Sed/** Finalizes all of the function passes scheduled in in the function pass
970193323Sed    manager. Returns 1 if any of the passes modified the module, 0 otherwise.
971193323Sed    See llvm::FunctionPassManager::doFinalization. */
972202375SrdivackyLLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM);
973193323Sed
974193323Sed/** Frees the memory of a pass pipeline. For function pipelines, does not free
975193323Sed    the module provider.
976193323Sed    See llvm::PassManagerBase::~PassManagerBase. */
977193323Sedvoid LLVMDisposePassManager(LLVMPassManagerRef PM);
978193323Sed
979193323Sed
980193323Sed#ifdef __cplusplus
981193323Sed}
982193323Sed
983193323Sednamespace llvm {
984193323Sed  class ModuleProvider;
985193323Sed  class MemoryBuffer;
986193323Sed  class PassManagerBase;
987193323Sed
988193323Sed  #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
989193323Sed    inline ty *unwrap(ref P) {                          \
990193323Sed      return reinterpret_cast<ty*>(P);                  \
991193323Sed    }                                                   \
992193323Sed                                                        \
993193323Sed    inline ref wrap(const ty *P) {                      \
994193323Sed      return reinterpret_cast<ref>(const_cast<ty*>(P)); \
995193323Sed    }
996193323Sed
997193323Sed  #define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)  \
998193323Sed    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
999193323Sed                                                        \
1000193323Sed    template<typename T>                                \
1001193323Sed    inline T *unwrap(ref P) {                           \
1002193323Sed      return cast<T>(unwrap(P));                        \
1003193323Sed    }
1004193323Sed
1005193323Sed  #define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref)   \
1006193323Sed    DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)         \
1007193323Sed                                                        \
1008193323Sed    template<typename T>                                \
1009193323Sed    inline T *unwrap(ref P) {                           \
1010202878Srdivacky      T *Q = (T*)unwrap(P);                             \
1011193323Sed      assert(Q && "Invalid cast!");                     \
1012193323Sed      return Q;                                         \
1013193323Sed    }
1014193323Sed
1015193323Sed  DEFINE_ISA_CONVERSION_FUNCTIONS   (Type,               LLVMTypeRef          )
1016193323Sed  DEFINE_ISA_CONVERSION_FUNCTIONS   (Value,              LLVMValueRef         )
1017193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
1018193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
1019193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>,        LLVMBuilderRef       )
1020193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
1021193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
1022193323Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
1023195340Sed  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext,        LLVMContextRef       )
1024198090Srdivacky  DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use,                LLVMUseIteratorRef           )
1025193323Sed  DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBase,    LLVMPassManagerRef   )
1026193323Sed
1027193323Sed  #undef DEFINE_STDCXX_CONVERSION_FUNCTIONS
1028193323Sed  #undef DEFINE_ISA_CONVERSION_FUNCTIONS
1029193323Sed  #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
1030198090Srdivacky
1031198090Srdivacky  /* Specialized opaque context conversions.
1032198090Srdivacky   */
1033198090Srdivacky  inline LLVMContext **unwrap(LLVMContextRef* Tys) {
1034198090Srdivacky    return reinterpret_cast<LLVMContext**>(Tys);
1035198090Srdivacky  }
1036193323Sed
1037198090Srdivacky  inline LLVMContextRef *wrap(const LLVMContext **Tys) {
1038198090Srdivacky    return reinterpret_cast<LLVMContextRef*>(const_cast<LLVMContext**>(Tys));
1039198090Srdivacky  }
1040198090Srdivacky
1041193323Sed  /* Specialized opaque type conversions.
1042193323Sed   */
1043193323Sed  inline Type **unwrap(LLVMTypeRef* Tys) {
1044193323Sed    return reinterpret_cast<Type**>(Tys);
1045193323Sed  }
1046193323Sed
1047193323Sed  inline LLVMTypeRef *wrap(const Type **Tys) {
1048193323Sed    return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
1049193323Sed  }
1050193323Sed
1051193323Sed  /* Specialized opaque value conversions.
1052193323Sed   */
1053193323Sed  inline Value **unwrap(LLVMValueRef *Vals) {
1054193323Sed    return reinterpret_cast<Value**>(Vals);
1055193323Sed  }
1056193323Sed
1057193323Sed  template<typename T>
1058193323Sed  inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
1059193323Sed    #if DEBUG
1060198090Srdivacky    for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
1061193323Sed      cast<T>(*I);
1062193323Sed    #endif
1063193323Sed    return reinterpret_cast<T**>(Vals);
1064193323Sed  }
1065193323Sed
1066193323Sed  inline LLVMValueRef *wrap(const Value **Vals) {
1067193323Sed    return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
1068193323Sed  }
1069193323Sed}
1070193323Sed
1071193323Sed#endif /* !defined(__cplusplus) */
1072193323Sed
1073193323Sed#endif /* !defined(LLVM_C_CORE_H) */
1074