Fixing a bug creating floating point constants of type other
[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/LLVMBuilder.h"
42
43 extern "C" {
44 #endif
45
46
47 /* Opaque types. */
48
49 /**
50  * The top-level container for all other LLVM Intermediate Representation (IR)
51  * objects. See the llvm::Module class.
52  */
53 typedef struct LLVMOpaqueModule *LLVMModuleRef;
54
55 /**
56  * Each value in the LLVM IR has a type, an instance of [lltype]. See the
57  * llvm::Type class.
58  */
59 typedef struct LLVMOpaqueType *LLVMTypeRef;
60
61 /**
62  * When building recursive types using [refine_type], [lltype] values may become
63  * invalid; use [lltypehandle] to resolve this problem. See the
64  * llvm::AbstractTypeHolder] class. 
65  */
66 typedef struct LLVMOpaqueTypeHandle *LLVMTypeHandleRef;
67
68 typedef struct LLVMOpaqueValue *LLVMValueRef;
69 typedef struct LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
70 typedef struct LLVMOpaqueBuilder *LLVMBuilderRef;
71
72 /* Used to provide a module to JIT or interpreter.
73  * See the llvm::ModuleProvider class.
74  */
75 typedef struct LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
76
77 /* Used to provide a module to JIT or interpreter.
78  * See the llvm::MemoryBuffer class.
79  */
80 typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
81
82 typedef enum {
83   LLVMVoidTypeKind,        /**< type with no size */
84   LLVMFloatTypeKind,       /**< 32 bit floating point type */
85   LLVMDoubleTypeKind,      /**< 64 bit floating point type */
86   LLVMX86_FP80TypeKind,    /**< 80 bit floating point type (X87) */
87   LLVMFP128TypeKind,       /**< 128 bit floating point type (112-bit mantissa)*/
88   LLVMPPC_FP128TypeKind,   /**< 128 bit floating point type (two 64-bits) */
89   LLVMLabelTypeKind,       /**< Labels */
90   LLVMIntegerTypeKind,     /**< Arbitrary bit width integers */
91   LLVMFunctionTypeKind,    /**< Functions */
92   LLVMStructTypeKind,      /**< Structures */
93   LLVMArrayTypeKind,       /**< Arrays */
94   LLVMPointerTypeKind,     /**< Pointers */
95   LLVMOpaqueTypeKind,      /**< Opaque: type with unknown structure */
96   LLVMVectorTypeKind       /**< SIMD 'packed' format, or other vector type */
97 } LLVMTypeKind;
98
99 typedef enum {
100   LLVMExternalLinkage,    /**< Externally visible function */
101   LLVMLinkOnceLinkage,    /**< Keep one copy of function when linking (inline)*/
102   LLVMWeakLinkage,        /**< Keep one copy of function when linking (weak) */
103   LLVMAppendingLinkage,   /**< Special purpose, only applies to global arrays */
104   LLVMInternalLinkage,    /**< Rename collisions when linking (static
105                                functions) */
106   LLVMDLLImportLinkage,   /**< Function to be imported from DLL */
107   LLVMDLLExportLinkage,   /**< Function to be accessible from DLL */
108   LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
109   LLVMGhostLinkage        /**< Stand-in functions for streaming fns from
110                                bitcode */
111 } LLVMLinkage;
112
113 typedef enum {
114   LLVMDefaultVisibility,  /**< The GV is visible */
115   LLVMHiddenVisibility,   /**< The GV is hidden */
116   LLVMProtectedVisibility /**< The GV is protected */
117 } LLVMVisibility;
118
119 typedef enum {
120   LLVMCCallConv           = 0,
121   LLVMFastCallConv        = 8,
122   LLVMColdCallConv        = 9,
123   LLVMX86StdcallCallConv  = 64,
124   LLVMX86FastcallCallConv = 65
125 } LLVMCallConv;
126
127 typedef enum {
128   LLVMIntEQ = 32, /**< equal */
129   LLVMIntNE,      /**< not equal */
130   LLVMIntUGT,     /**< unsigned greater than */
131   LLVMIntUGE,     /**< unsigned greater or equal */
132   LLVMIntULT,     /**< unsigned less than */
133   LLVMIntULE,     /**< unsigned less or equal */
134   LLVMIntSGT,     /**< signed greater than */
135   LLVMIntSGE,     /**< signed greater or equal */
136   LLVMIntSLT,     /**< signed less than */
137   LLVMIntSLE      /**< signed less or equal */
138 } LLVMIntPredicate;
139
140 typedef enum {
141   LLVMRealPredicateFalse, /**< Always false (always folded) */
142   LLVMRealOEQ,            /**< True if ordered and equal */
143   LLVMRealOGT,            /**< True if ordered and greater than */
144   LLVMRealOGE,            /**< True if ordered and greater than or equal */
145   LLVMRealOLT,            /**< True if ordered and less than */
146   LLVMRealOLE,            /**< True if ordered and less than or equal */
147   LLVMRealONE,            /**< True if ordered and operands are unequal */
148   LLVMRealORD,            /**< True if ordered (no nans) */
149   LLVMRealUNO,            /**< True if unordered: isnan(X) | isnan(Y) */
150   LLVMRealUEQ,            /**< True if unordered or equal */
151   LLVMRealUGT,            /**< True if unordered or greater than */
152   LLVMRealUGE,            /**< True if unordered, greater than, or equal */
153   LLVMRealULT,            /**< True if unordered or less than */
154   LLVMRealULE,            /**< True if unordered, less than, or equal */
155   LLVMRealUNE,            /**< True if unordered or not equal */
156   LLVMRealPredicateTrue   /**< Always true (always folded) */
157 } LLVMRealPredicate;
158
159
160 /*===-- Error handling ----------------------------------------------------===*/
161
162 void LLVMDisposeMessage(char *Message);
163
164
165 /*===-- Modules -----------------------------------------------------------===*/
166
167 /* Create and destroy modules. */ 
168 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
169 void LLVMDisposeModule(LLVMModuleRef M);
170
171 /* Data layout */
172 const char *LLVMGetDataLayout(LLVMModuleRef M);
173 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple);
174
175 /* Target triple */
176 const char *LLVMGetTarget(LLVMModuleRef M);
177 void LLVMSetTarget(LLVMModuleRef M, const char *Triple);
178
179 /* Same as Module::addTypeName. */
180 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
181 void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
182
183
184 /*===-- Types -------------------------------------------------------------===*/
185
186 /* LLVM types conform to the following hierarchy:
187  * 
188  *   types:
189  *     integer type
190  *     real type
191  *     function type
192  *     sequence types:
193  *       array type
194  *       pointer type
195  *       vector type
196  *     void type
197  *     label type
198  *     opaque type
199  */
200
201 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
202 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
203
204 /* Operations on integer types */
205 LLVMTypeRef LLVMInt1Type();
206 LLVMTypeRef LLVMInt8Type();
207 LLVMTypeRef LLVMInt16Type();
208 LLVMTypeRef LLVMInt32Type();
209 LLVMTypeRef LLVMInt64Type();
210 LLVMTypeRef LLVMIntType(unsigned NumBits);
211 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
212
213 /* Operations on real types */
214 LLVMTypeRef LLVMFloatType();
215 LLVMTypeRef LLVMDoubleType();
216 LLVMTypeRef LLVMX86FP80Type();
217 LLVMTypeRef LLVMFP128Type();
218 LLVMTypeRef LLVMPPCFP128Type();
219
220 /* Operations on function types */
221 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
222                              LLVMTypeRef *ParamTypes, unsigned ParamCount,
223                              int IsVarArg);
224 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
225 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
226 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy);
227 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
228
229 /* Operations on struct types */
230 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
231                            int Packed);
232 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy);
233 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
234 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
235
236 /* Operations on array, pointer, and vector types (sequence types) */
237 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
238 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
239 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
240
241 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
242 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
243 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
244 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
245
246 /* Operations on other types */
247 LLVMTypeRef LLVMVoidType();
248 LLVMTypeRef LLVMLabelType();
249 LLVMTypeRef LLVMOpaqueType();
250
251 /* Operations on type handles */
252 LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy);
253 void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy);
254 LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle);
255 void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle);
256
257
258 /*===-- Values ------------------------------------------------------------===*/
259
260 /* The bulk of LLVM's object model consists of values, which comprise a very
261  * rich type hierarchy.
262  * 
263  *   values:
264  *     constants:
265  *       scalar constants
266  *       composite contants
267  *       globals:
268  *         global variable
269  *         function
270  *         alias
271  *       basic blocks
272  */
273
274 /* Operations on all values */
275 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
276 const char *LLVMGetValueName(LLVMValueRef Val);
277 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
278 void LLVMDumpValue(LLVMValueRef Val);
279
280 /* Operations on constants of any type */
281 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
282 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
283 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
284 int LLVMIsConstant(LLVMValueRef Val);
285 int LLVMIsNull(LLVMValueRef Val);
286 int LLVMIsUndef(LLVMValueRef Val);
287
288 /* Operations on scalar constants */
289 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
290                           int SignExtend);
291 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
292 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text);
293
294 /* Operations on composite constants */
295 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
296                              int DontNullTerminate);
297 LLVMValueRef LLVMConstArray(LLVMTypeRef ArrayTy,
298                             LLVMValueRef *ConstantVals, unsigned Length);
299 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
300                              int packed);
301 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size);
302
303 /* Constant expressions */
304 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty);
305 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal);
306 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal);
307 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
308 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
309 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
310 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
311 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
312 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
313 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
314 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
315 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
316 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
317 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
318 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
319 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
320                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
321 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
322                            LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
323 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
324 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
325 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
326 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
327                           LLVMValueRef *ConstantIndices, unsigned NumIndices);
328 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
329 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
330 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
331 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
332 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
333 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
334 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
335 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
336 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
337 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
338 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
339 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
340 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
341                              LLVMValueRef ConstantIfTrue,
342                              LLVMValueRef ConstantIfFalse);
343 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
344                                      LLVMValueRef IndexConstant);
345 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
346                                     LLVMValueRef ElementValueConstant,
347                                     LLVMValueRef IndexConstant);
348 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
349                                     LLVMValueRef VectorBConstant,
350                                     LLVMValueRef MaskConstant);
351
352 /* Operations on global variables, functions, and aliases (globals) */
353 int LLVMIsDeclaration(LLVMValueRef Global);
354 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
355 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
356 const char *LLVMGetSection(LLVMValueRef Global);
357 void LLVMSetSection(LLVMValueRef Global, const char *Section);
358 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
359 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
360 unsigned LLVMGetAlignment(LLVMValueRef Global);
361 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
362
363 /* Operations on global variables */
364 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
365 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name);
366 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
367 int LLVMHasInitializer(LLVMValueRef GlobalVar);
368 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
369 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
370 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
371 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
372 int LLVMIsGlobalConstant(LLVMValueRef GlobalVar);
373 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant);
374
375 /* Operations on functions */
376 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
377                              LLVMTypeRef FunctionTy);
378 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name);
379 void LLVMDeleteFunction(LLVMValueRef Fn);
380 unsigned LLVMCountParams(LLVMValueRef Fn);
381 void LLVMGetParams(LLVMValueRef Fn, LLVMValueRef *Params);
382 LLVMValueRef LLVMGetParam(LLVMValueRef Fn, unsigned Index);
383 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn);
384 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn);
385 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC);
386 const char *LLVMGetCollector(LLVMValueRef Fn);
387 void LLVMSetCollector(LLVMValueRef Fn, const char *Coll);
388
389 /* Operations on basic blocks */
390 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef Bb);
391 int LLVMValueIsBasicBlock(LLVMValueRef Val);
392 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val);
393 unsigned LLVMCountBasicBlocks(LLVMValueRef Fn);
394 void LLVMGetBasicBlocks(LLVMValueRef Fn, LLVMBasicBlockRef *BasicBlocks);
395 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn);
396 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef Fn, const char *Name);
397 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
398                                        const char *Name);
399 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BB);
400
401 /* Operations on call sites */
402 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC);
403 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
404
405 /* Operations on phi nodes */
406 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
407                      LLVMBasicBlockRef *IncomingBlocks, unsigned Count);
408 unsigned LLVMCountIncoming(LLVMValueRef PhiNode);
409 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index);
410 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index);
411
412 /*===-- Instruction builders ----------------------------------------------===*/
413
414 /* An instruction builder represents a point within a basic block, and is the
415  * exclusive means of building instructions using the C interface.
416  */
417
418 LLVMBuilderRef LLVMCreateBuilder();
419 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr);
420 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block);
421 void LLVMDisposeBuilder(LLVMBuilderRef Builder);
422
423 /* Terminators */
424 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);
425 LLVMValueRef LLVMBuildRet(LLVMBuilderRef, LLVMValueRef V);
426 LLVMValueRef LLVMBuildBr(LLVMBuilderRef, LLVMBasicBlockRef Dest);
427 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef, LLVMValueRef If,
428                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Else);
429 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef, LLVMValueRef V,
430                              LLVMBasicBlockRef Else, unsigned NumCases);
431 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef, LLVMValueRef Fn,
432                              LLVMValueRef *Args, unsigned NumArgs,
433                              LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
434                              const char *Name);
435 LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef);
436 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef);
437
438 /* Add a case to the switch instruction */
439 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
440                  LLVMBasicBlockRef Dest);
441
442 /* Arithmetic */
443 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
444                           const char *Name);
445 LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
446                           const char *Name);
447 LLVMValueRef LLVMBuildMul(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
448                           const char *Name);
449 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
450                            const char *Name);
451 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
452                            const char *Name);
453 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
454                            const char *Name);
455 LLVMValueRef LLVMBuildURem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
456                            const char *Name);
457 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
458                            const char *Name);
459 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
460                            const char *Name);
461 LLVMValueRef LLVMBuildShl(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
462                            const char *Name);
463 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
464                            const char *Name);
465 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
466                            const char *Name);
467 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
468                           const char *Name);
469 LLVMValueRef LLVMBuildOr(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
470                           const char *Name);
471 LLVMValueRef LLVMBuildXor(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
472                           const char *Name);
473 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef, LLVMValueRef V, const char *Name);
474 LLVMValueRef LLVMBuildNot(LLVMBuilderRef, LLVMValueRef V, const char *Name);
475
476 /* Memory */
477 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
478 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef, LLVMTypeRef Ty,
479                                   LLVMValueRef Val, const char *Name);
480 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
481 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef, LLVMTypeRef Ty,
482                                   LLVMValueRef Val, const char *Name);
483 LLVMValueRef LLVMBuildFree(LLVMBuilderRef, LLVMValueRef PointerVal);
484 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef, LLVMValueRef PointerVal,
485                            const char *Name);
486 LLVMValueRef LLVMBuildStore(LLVMBuilderRef, LLVMValueRef Val, LLVMValueRef Ptr);
487 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
488                           LLVMValueRef *Indices, unsigned NumIndices,
489                           const char *Name);
490
491 /* Casts */
492 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef, LLVMValueRef Val,
493                             LLVMTypeRef DestTy, const char *Name);
494 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef, LLVMValueRef Val,
495                            LLVMTypeRef DestTy, const char *Name);
496 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef, LLVMValueRef Val,
497                            LLVMTypeRef DestTy, const char *Name);
498 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef, LLVMValueRef Val,
499                              LLVMTypeRef DestTy, const char *Name);
500 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
501                              LLVMTypeRef DestTy, const char *Name);
502 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
503                              LLVMTypeRef DestTy, const char *Name);
504 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
505                              LLVMTypeRef DestTy, const char *Name);
506 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
507                               LLVMTypeRef DestTy, const char *Name);
508 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
509                             LLVMTypeRef DestTy, const char *Name);
510 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
511                                LLVMTypeRef DestTy, const char *Name);
512 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
513                                LLVMTypeRef DestTy, const char *Name);
514 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
515                               LLVMTypeRef DestTy, const char *Name);
516
517 /* Comparisons */
518 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef, LLVMIntPredicate Op,
519                            LLVMValueRef LHS, LLVMValueRef RHS,
520                            const char *Name);
521 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
522                            LLVMValueRef LHS, LLVMValueRef RHS,
523                            const char *Name);
524
525 /* Miscellaneous instructions */
526 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
527 LLVMValueRef LLVMBuildCall(LLVMBuilderRef, LLVMValueRef Fn,
528                            LLVMValueRef *Args, unsigned NumArgs,
529                            const char *Name);
530 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef, LLVMValueRef If,
531                              LLVMValueRef Then, LLVMValueRef Else,
532                              const char *Name);
533 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
534                             const char *Name);
535 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef, LLVMValueRef VecVal,
536                                      LLVMValueRef Index, const char *Name);
537 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef, LLVMValueRef VecVal,
538                                     LLVMValueRef EltVal, LLVMValueRef Index,
539                                     const char *Name);
540 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef, LLVMValueRef V1,
541                                     LLVMValueRef V2, LLVMValueRef Mask,
542                                     const char *Name);
543
544
545 /*===-- Module providers --------------------------------------------------===*/
546
547 /* Encapsulates the module M in a module provider, taking ownership of the
548  * module.
549  * See the constructor llvm::ExistingModuleProvider::ExistingModuleProvider.
550  */
551 LLVMModuleProviderRef
552 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M);
553
554 /* Destroys the module provider MP as well as the contained module.
555  * See the destructor llvm::ModuleProvider::~ModuleProvider.
556  */
557 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP);
558
559
560 /*===-- Memory buffers ----------------------------------------------------===*/
561
562 int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path,
563                                              LLVMMemoryBufferRef *OutMemBuf,
564                                              char **OutMessage);
565 int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
566                                     char **OutMessage);
567 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
568
569 #ifdef __cplusplus
570 }
571
572 namespace llvm {
573   class ModuleProvider;
574   class MemoryBuffer;
575   
576   #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)   \
577     inline ty *unwrap(ref P) {                          \
578       return reinterpret_cast<ty*>(P);                  \
579     }                                                   \
580                                                         \
581     inline ref wrap(const ty *P) {                      \
582       return reinterpret_cast<ref>(const_cast<ty*>(P)); \
583     }
584   
585   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Type,               LLVMTypeRef          )
586   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Value,              LLVMValueRef         )
587   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module,             LLVMModuleRef        )
588   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(BasicBlock,         LLVMBasicBlockRef    )
589   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMFoldingBuilder, LLVMBuilderRef       )
590   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PATypeHolder,       LLVMTypeHandleRef    )
591   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ModuleProvider,     LLVMModuleProviderRef)
592   DEFINE_SIMPLE_CONVERSION_FUNCTIONS(MemoryBuffer,       LLVMMemoryBufferRef  )
593   
594   #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS
595   
596   /* Specialized opaque type conversions.
597    */
598   template<typename T>
599   inline T *unwrap(LLVMTypeRef Ty) {
600     return cast<T>(unwrap(Ty));
601   }
602   
603   inline Type **unwrap(LLVMTypeRef* Tys) {
604     return reinterpret_cast<Type**>(Tys);
605   }
606   
607   inline LLVMTypeRef *wrap(const Type **Tys) {
608     return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys));
609   }
610   
611   /* Specialized opaque value conversions.
612    */ 
613   template<typename T>
614   inline T *unwrap(LLVMValueRef Val) {
615     return cast<T>(unwrap(Val));
616   }
617
618   inline Value **unwrap(LLVMValueRef *Vals) {
619     return reinterpret_cast<Value**>(Vals);
620   }
621   
622   template<typename T>
623   inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
624     #if DEBUG
625     for (LLVMValueRef *I = Vals, E = Vals + Length; I != E; ++I)
626       cast<T>(*I);
627     #endif
628     return reinterpret_cast<T**>(Vals);
629   }
630   
631   inline LLVMValueRef *wrap(const Value **Vals) {
632     return reinterpret_cast<LLVMValueRef*>(const_cast<Value**>(Vals));
633   }
634 }
635
636 #endif /* !defined(__cplusplus) */
637
638 #endif /* !defined(LLVM_C_CORE_H) */