Removing the silly CHelpers header by rolling wrap and unwrap into the C
[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 was developed by Gordon Henriksen and is distributed under the   *|
6 |* University of Illinois Open Source 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/LLVMBuilder.h"
42
43 extern "C" {
44 #endif
45
46
47 /* Opaque types. */
48 typedef struct LLVMOpaqueModule *LLVMModuleRef;
49 typedef struct LLVMOpaqueType *LLVMTypeRef;
50 typedef struct LLVMOpaqueValue *LLVMValueRef;
51 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
52 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
53
54 typedef enum {
55   LLVMVoidTypeKind,        /* type with no size */
56   LLVMFloatTypeKind,       /* 32 bit floating point type */
57   LLVMDoubleTypeKind,      /* 64 bit floating point type */
58   LLVMX86_FP80TypeKind,    /* 80 bit floating point type (X87) */
59   LLVMFP128TypeKind,       /* 128 bit floating point type (112-bit mantissa) */
60   LLVMPPC_FP128TypeKind,   /* 128 bit floating point type (two 64-bits) */
61   LLVMLabelTypeKind,       /* Labels */
62   LLVMIntegerTypeKind,     /* Arbitrary bit width integers */
63   LLVMFunctionTypeKind,    /* Functions */
64   LLVMStructTypeKind,      /* Structures */
65   LLVMArrayTypeKind,       /* Arrays */
66   LLVMPointerTypeKind,     /* Pointers */
67   LLVMOpaqueTypeKind,      /* Opaque: type with unknown structure */
68   LLVMVectorTypeKind       /* SIMD 'packed' format, or other vector type */
69 } LLVMTypeKind;
70
71 typedef enum {
72   LLVMExternalLinkage,    /* Externally visible function */
73   LLVMLinkOnceLinkage,    /* Keep one copy of function when linking (inline) */
74   LLVMWeakLinkage,        /* Keep one copy of function when linking (weak) */
75   LLVMAppendingLinkage,   /* Special purpose, only applies to global arrays */
76   LLVMInternalLinkage,    /* Rename collisions when linking (static functions)*/
77   LLVMDLLImportLinkage,   /* Function to be imported from DLL */
78   LLVMDLLExportLinkage,   /* Function to be accessible from DLL */
79   LLVMExternalWeakLinkage,/* ExternalWeak linkage description */
80   LLVMGhostLinkage        /* Stand-in functions for streaming fns from bitcode*/
81 } LLVMLinkage;
82
83 typedef enum {
84   LLVMDefaultVisibility,  /* The GV is visible */
85   LLVMHiddenVisibility,   /* The GV is hidden */
86   LLVMProtectedVisibility /* The GV is protected */
87 } LLVMVisibility;
88
89 typedef enum {
90   LLVMCCallConv           = 0,
91   LLVMFastCallConv        = 8,
92   LLVMColdCallConv        = 9,
93   LLVMX86StdcallCallConv  = 64,
94   LLVMX86FastcallCallConv = 65
95 } LLVMCallConv;
96
97 typedef enum {
98   LLVMIntEQ = 32, /* equal */
99   LLVMIntNE,      /* not equal */
100   LLVMIntUGT,     /* unsigned greater than */
101   LLVMIntUGE,     /* unsigned greater or equal */
102   LLVMIntULT,     /* unsigned less than */
103   LLVMIntULE,     /* unsigned less or equal */
104   LLVMIntSGT,     /* signed greater than */
105   LLVMIntSGE,     /* signed greater or equal */
106   LLVMIntSLT,     /* signed less than */
107   LLVMIntSLE      /* signed less or equal */
108 } LLVMIntPredicate;
109
110 typedef enum {
111   LLVMRealPredicateFalse, /* Always false (always folded) */
112   LLVMRealOEQ,            /* True if ordered and equal */
113   LLVMRealOGT,            /* True if ordered and greater than */
114   LLVMRealOGE,            /* True if ordered and greater than or equal */
115   LLVMRealOLT,            /* True if ordered and less than */
116   LLVMRealOLE,            /* True if ordered and less than or equal */
117   LLVMRealONE,            /* True if ordered and operands are unequal */
118   LLVMRealORD,            /* True if ordered (no nans) */
119   LLVMRealUNO,            /* True if unordered: isnan(X) | isnan(Y) */
120   LLVMRealUEQ,            /* True if unordered or equal */
121   LLVMRealUGT,            /* True if unordered or greater than */
122   LLVMRealUGE,            /* True if unordered, greater than, or equal */
123   LLVMRealULT,            /* True if unordered or less than */
124   LLVMRealULE,            /* True if unordered, less than, or equal */
125   LLVMRealUNE,            /* True if unordered or not equal */
126   LLVMRealPredicateTrue   /* Always true (always folded) */
127 } LLVMRealPredicate;
128
129
130 /*===-- Modules -----------------------------------------------------------===*/
131
132 /* Create and destroy modules. */ 
133 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
134 void LLVMDisposeModule(LLVMModuleRef M);
135
136 /* Same as Module::addTypeName. */
137 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
138 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
139
140
141 /*===-- Types -------------------------------------------------------------===*/
142
143 /* LLVM types conform to the following hierarchy:
144  * 
145  *   types:
146  *     integer type
147  *     real type
148  *     function type
149  *     sequence types:
150  *       array type
151  *       pointer type
152  *       vector type
153  *     void type
154  *     label type
155  *     opaque type
156  */
157
158 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
159 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
160
161 /* Operations on integer types */
162 LLVMTypeRef LLVMInt1Type();
163 LLVMTypeRef LLVMInt8Type();
164 LLVMTypeRef LLVMInt16Type();
165 LLVMTypeRef LLVMInt32Type();
166 LLVMTypeRef LLVMInt64Type();
167 LLVMTypeRef LLVMCreateIntType(unsigned NumBits);
168 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
169
170 /* Operations on real types */
171 LLVMTypeRef LLVMFloatType();
172 LLVMTypeRef LLVMDoubleType();
173 LLVMTypeRef LLVMX86FP80Type();
174 LLVMTypeRef LLVMFP128Type();
175 LLVMTypeRef LLVMPPCFP128Type();
176
177 /* Operations on function types */
178 LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType,
179                                    LLVMTypeRef *ParamTypes, unsigned ParamCount,
180                                    int IsVarArg);
181 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
182 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
183 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
184 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
185
186 /* Operations on struct types */
187 LLVMTypeRef LLVMCreateStructType(LLVMTypeRef *ElementTypes,
188                                  unsigned ElementCount, int Packed);
189 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
190 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
191 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
192
193 /* Operations on array, pointer, and vector types (sequence types) */
194 LLVMTypeRef LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
195 LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType);
196 LLVMTypeRef LLVMCreateVectorType(LLVMTypeRef ElementType,unsigned ElementCount);
197
198 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
199 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
200 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
201
202 /* Operations on other types */
203 LLVMTypeRef LLVMVoidType();
204 LLVMTypeRef LLVMLabelType();
205 LLVMTypeRef LLVMCreateOpaqueType();
206
207
208 /*===-- Values ------------------------------------------------------------===*/
209
210 /* The bulk of LLVM's object model consists of values, which comprise a very
211  * rich type hierarchy.
212  * 
213  *   values:
214  *     constants:
215  *       scalar constants
216  *       composite contants
217  *       globals:
218  *         global variable
219  *         function
220  *         alias
221  *       basic blocks
222  */
223
224 /* Operations on all values */
225 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
226 const char *LLVMGetValueName(LLVMValueRef Val);
227 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
228
229 /* Operations on constants of any type */
230 LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
231 LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
232 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
233 int LLVMIsConstant(LLVMValueRef Val);
234 int LLVMIsNull(LLVMValueRef Val);
235 int LLVMIsUndef(LLVMValueRef Val);
236
237 /* Operations on scalar constants */
238 LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
239                                 int SignExtend);
240 LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N);
241
242 /* Operations on composite constants */
243 LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
244                                    int DontNullTerminate);
245 LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ArrayTy,
246                                   LLVMValueRef *ConstantVals, unsigned Length);
247 LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
248                                    int packed);
249 LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
250                                    unsigned Size);
251
252 /* Operations on global variables, functions, and aliases (globals) */
253 int LLVMIsDeclaration(LLVMValueRef Global);
254 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
255 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
256 const char *LLVMGetSection(LLVMValueRef Global);
257 void LLVMSetSection(LLVMValueRef Global, const char *Section);
258 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
259 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
260 unsigned LLVMGetAlignment(LLVMValueRef Global);
261 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
262
263 /* Operations on global variables */
264 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
265 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
266 int LLVMHasInitializer(LLVMValueRef GlobalVar);
267 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
268 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
269 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
270 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
271
272 /* Operations on functions */
273 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
274                              LLVMTypeRef FunctionTy);
275 void LLVMDeleteFunction(LLVMValueRef Fn);
276 unsigned LLVMCountParams(LLVMValueRef Fn);
277 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
278 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
279 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
280 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
281 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
282
283 /* Operations on basic blocks */
284 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
285 int LLVMValueIsBasicBlock(LLVMValueRef Val);
286 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
287 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
288 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
289 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
290 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
291 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
292                                        const char *Name);
293 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
294
295
296 /*===-- Instruction builders ----------------------------------------------===*/
297
298 /* An instruction builder represents a point within a basic block, and is the
299  * exclusive means of building instructions using the C interface.
300  */
301
302 LLVMBuilderRef LLVMCreateBuilder();
303 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
304 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
305 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
306
307 /* Terminators */
308 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
309 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
310 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
311 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
312                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
313 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
314                              LLVMBasicBlockRef Else, unsigned NumCases);
315 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
316                              LLVMValueRef *Args, unsigned NumArgs,
317                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
318                              const char *Name);
319 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
320 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
321
322 /* Arithmetic */
323 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
324                           const char *Name);
325 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
326                           const char *Name);
327 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
328                           const char *Name);
329 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
330                            const char *Name);
331 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
332                            const char *Name);
333 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
334                            const char *Name);
335 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
336                            const char *Name);
337 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
338                            const char *Name);
339 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
340                            const char *Name);
341 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
342                            const char *Name);
343 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
344                            const char *Name);
345 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
346                            const char *Name);
347 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
348                           const char *Name);
349 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
350                           const char *Name);
351 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
352                           const char *Name);
353 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
354 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
355
356 /* Memory */
357 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
358 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
359                                   LLVMValueRef Val, const char *Name);
360 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
361 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
362                                   LLVMValueRef Val, const char *Name);
363 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
364 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
365                            const char *Name);
366 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
367 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
368                           LLVMValueRef *Indices, unsigned NumIndices,
369                           const char *Name);
370
371 /* Casts */
372 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
373                             LLVMTypeRef DestTy, const char *Name);
374 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
375                            LLVMTypeRef DestTy, const char *Name);
376 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
377                            LLVMTypeRef DestTy, const char *Name);
378 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
379                              LLVMTypeRef DestTy, const char *Name);
380 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
381                              LLVMTypeRef DestTy, const char *Name);
382 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
383                              LLVMTypeRef DestTy, const char *Name);
384 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
385                              LLVMTypeRef DestTy, const char *Name);
386 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
387                               LLVMTypeRef DestTy, const char *Name);
388 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
389                             LLVMTypeRef DestTy, const char *Name);
390 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
391                                LLVMTypeRef DestTy, const char *Name);
392 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
393                                LLVMTypeRef DestTy, const char *Name);
394 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
395                               LLVMTypeRef DestTy, const char *Name);
396
397 /* Comparisons */
398 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
399                            LLVMValueRef LHS, LLVMValueRef RHS,
400                            const char *Name);
401 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
402                            LLVMValueRef LHS, LLVMValueRef RHS,
403                            const char *Name);
404
405 /* Miscellaneous instructions */
406 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
407 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
408                            LLVMValueRef *Args, unsigned NumArgs,
409                            const char *Name);
410 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
411                              LLVMValueRef Then, LLVMValueRef Else,
412                              const char *Name);
413 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
414                             const char *Name);
415 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
416                                      LLVMValueRef Index, const char *Name);
417 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
418                                     LLVMValueRef EltVal, LLVMValueRef Index,
419                                     const char *Name);
420 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
421                                     LLVMValueRef V2, LLVMValueRef Mask,
422                                     const char *Name);
423
424 #ifdef __cplusplus
425 }
426
427 namespace llvm {
428   /* Opaque module conversions
429    */ 
430   inline Module *unwrap(LLVMModuleRef M) {
431     return reinterpret_cast<Module*>(M);
432   }
433   
434   inline LLVMModuleRef wrap(Module *M) {
435     return reinterpret_cast<LLVMModuleRef>(M);
436   }
437   
438   /* Opaque type conversions
439    */ 
440   inline Type *unwrap(LLVMTypeRef Ty) {
441     return reinterpret_cast<Type*>(Ty);
442   }
443   
444   template<typename T>
445   inline T *unwrap(LLVMTypeRef Ty) {
446     return cast<T>(unwrap(Ty));
447   }
448   
449   inline Type **unwrap(LLVMTypeRef* Tys) {
450     return reinterpret_cast<Type**>(Tys);
451   }
452   
453   inline LLVMTypeRef wrap(const Type *Ty) {
454     return reinterpret_cast<LLVMTypeRef>(const_cast<Type*>(Ty));
455   }
456   
457   inline LLVMTypeRef *wrap(const Type **Tys) {
458     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
459   }
460   
461   /* Opaque value conversions
462    */ 
463   inline Value *unwrap(LLVMValueRef Val) {
464     return reinterpret_cast<Value*>(Val);
465   }
466   
467   template<typename T>
468   inline T *unwrap(LLVMValueRef Val) {
469     return cast<T>(unwrap(Val));
470   }
471
472   inline Value **unwrap(LLVMValueRef *Vals) {
473     return reinterpret_cast<Value**>(Vals);
474   }
475   
476   template<typename T>
477   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
478     #if DEBUG
479     for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
480       cast<T>(*I);
481     #endif
482     return reinterpret_cast<T**>(Vals);
483   }
484   
485   inline LLVMValueRef wrap(const Value *Val) {
486     return reinterpret_cast<LLVMValueRef>(const_cast<Value*>(Val));
487   }
488   
489   inline LLVMValueRef *wrap(const Value **Vals) {
490     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
491   }
492   
493   /* Basic block conversions
494    */ 
495   inline BasicBlock *unwrap(LLVMBasicBlockRef BBRef) {
496     return reinterpret_cast<BasicBlock*>(BBRef);
497   }
498   
499   inline LLVMBasicBlockRef wrap(const BasicBlock *BB) {
500     return reinterpret_cast<LLVMBasicBlockRef>(const_cast<BasicBlock*>(BB));
501   }
502   
503   /* Opaque builder conversions.
504    */ 
505   inline LLVMBuilder *unwrap(LLVMBuilderRef B) {
506     return reinterpret_cast<LLVMBuilder*>(B);
507   }
508   
509   inline LLVMBuilderRef wrap(LLVMBuilder *B) {
510     return reinterpret_cast<LLVMBuilderRef>(B);
511   }
512 }
513
514 #endif /* !defined(__cplusplus) */
515
516 #endif /* !defined(LLVM_C_CORE_H) */