blob: 1442a237d99d3d2b0188d5ce0653adcf17cd9fd3 [file] [log] [blame]
Gordon Henriksen76a03742007-09-18 03:18:57 +00001/*===-- 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\*===----------------------------------------------------------------------===*/
27
28#ifndef LLVM_C_CORE_H
29#define LLVM_C_CORE_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35
36/* Opaque types. */
37typedef struct LLVMOpaqueModule *LLVMModuleRef;
38typedef struct LLVMOpaqueType *LLVMTypeRef;
39typedef struct LLVMOpaqueValue *LLVMValueRef;
40
41typedef enum {
42 LLVMVoidTypeKind = 0, /* type with no size */
43 LLVMFloatTypeKind, /* 32 bit floating point type */
44 LLVMDoubleTypeKind, /* 64 bit floating point type */
45 LLVMX86_FP80TypeKind, /* 80 bit floating point type (X87) */
46 LLVMFP128TypeKind, /* 128 bit floating point type (112-bit mantissa) */
47 LLVMPPC_FP128TypeKind, /* 128 bit floating point type (two 64-bits) */
48 LLVMLabelTypeKind, /* Labels */
49 LLVMIntegerTypeKind, /* Arbitrary bit width integers */
50 LLVMFunctionTypeKind, /* Functions */
51 LLVMStructTypeKind, /* Structures */
52 LLVMArrayTypeKind, /* Arrays */
53 LLVMPointerTypeKind, /* Pointers */
54 LLVMOpaqueTypeKind, /* Opaque: type with unknown structure */
55 LLVMVectorTypeKind /* SIMD 'packed' format, or other vector type */
56} LLVMTypeKind;
57
58typedef enum {
59 LLVMExternalLinkage = 0,/* Externally visible function */
60 LLVMLinkOnceLinkage, /* Keep one copy of function when linking (inline) */
61 LLVMWeakLinkage, /* Keep one copy of function when linking (weak) */
62 LLVMAppendingLinkage, /* Special purpose, only applies to global arrays */
63 LLVMInternalLinkage, /* Rename collisions when linking (static functions)*/
64 LLVMDLLImportLinkage, /* Function to be imported from DLL */
65 LLVMDLLExportLinkage, /* Function to be accessible from DLL */
66 LLVMExternalWeakLinkage,/* ExternalWeak linkage description */
67 LLVMGhostLinkage /* Stand-in functions for streaming fns from bitcode*/
68} LLVMLinkage;
69
70typedef enum {
71 LLVMDefaultVisibility = 0, /* The GV is visible */
72 LLVMHiddenVisibility, /* The GV is hidden */
73 LLVMProtectedVisibility /* The GV is protected */
74} LLVMVisibility;
75
76
77/*===-- Modules -----------------------------------------------------------===*/
78
79/* Create and destroy modules. */
80LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
81void LLVMDisposeModule(LLVMModuleRef M);
82
83/* Same as Module::addTypeName. */
84int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
85int LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
86
87
88/*===-- Types --------------------------------------------------------------===*/
89
90/* LLVM types conform to the following hierarchy:
91 *
92 * types:
93 * integer type
94 * real type
95 * function type
96 * sequence types:
97 * array type
98 * pointer type
99 * vector type
100 * void type
101 * label type
102 * opaque type
103 */
104
105LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
106void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
107
108/* Operations on integer types */
109LLVMTypeRef LLVMInt1Type();
110LLVMTypeRef LLVMInt8Type();
111LLVMTypeRef LLVMInt16Type();
112LLVMTypeRef LLVMInt32Type();
113LLVMTypeRef LLVMInt64Type();
114LLVMTypeRef LLVMCreateIntegerType(unsigned NumBits);
115unsigned LLVMGetIntegerTypeWidth(LLVMTypeRef IntegerTy);
116
117/* Operations on real types */
118LLVMTypeRef LLVMFloatType();
119LLVMTypeRef LLVMDoubleType();
120LLVMTypeRef LLVMX86FP80Type();
121LLVMTypeRef LLVMFP128Type();
122LLVMTypeRef LLVMPPCFP128Type();
123
124/* Operations on function types */
125LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType,
126 LLVMTypeRef *ParamTypes, unsigned ParamCount,
127 int IsVarArg);
128int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
129LLVMTypeRef LLVMGetFunctionReturnType(LLVMTypeRef FunctionTy);
130unsigned LLVMGetFunctionParamCount(LLVMTypeRef FunctionTy);
131void LLVMGetFunctionParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
132
133/* Operations on struct types */
134LLVMTypeRef LLVMCreateStructType(LLVMTypeRef *ElementTypes,
135 unsigned ElementCount, int Packed);
136unsigned LLVMGetStructElementCount(LLVMTypeRef StructTy);
137void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
138int LLVMIsPackedStruct(LLVMTypeRef StructTy);
139
140/* Operations on array, pointer, and vector types (sequence types) */
141LLVMTypeRef LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
142LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType);
143LLVMTypeRef LLVMCreateVectorType(LLVMTypeRef ElementType,unsigned ElementCount);
144
145LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
146unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
147unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
148
149/* Operations on other types */
150LLVMTypeRef LLVMVoidType();
151LLVMTypeRef LLVMLabelType();
152LLVMTypeRef LLVMCreateOpaqueType();
153
154
155/*===-- Values ------------------------------------------------------------===*/
156
157/* The bulk of LLVM's object model consists of values, which comprise a very
158 * rich type hierarchy.
159 *
160 * values:
161 * constants:
162 * scalar constants
163 * composite contants
164 * globals:
165 * global variable
166 * function
167 * alias
168 */
169
170/* Operations on all values */
171LLVMTypeRef LLVMGetTypeOfValue(LLVMValueRef Val);
172const char *LLVMGetValueName(LLVMValueRef Val);
173void LLVMSetValueName(LLVMValueRef Val, const char *Name);
174
175/* Operations on constants of any type */
176LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
177LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
178LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
179int LLVMIsNull(LLVMValueRef Val);
180
181/* Operations on scalar constants */
182LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
183 int SignExtend);
184LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N);
185
186/* Operations on composite constants */
187LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
188 int DontNullTerminate);
189LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ArrayTy,
190 LLVMValueRef *ConstantVals, unsigned Length);
191LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
192 int packed);
193LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
194 unsigned Size);
195
196/* Operations on global variables, functions, and aliases (globals) */
197int LLVMIsDeclaration(LLVMValueRef Global);
198LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
199void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
200const char *LLVMGetSection(LLVMValueRef Global);
201void LLVMSetSection(LLVMValueRef Global, const char *Section);
202LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
203void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
204unsigned LLVMGetAlignment(LLVMValueRef Global);
205void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
206
207/* Operations on global variables */
208LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
209void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
210int LLVMHasInitializer(LLVMValueRef GlobalVar);
211LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
212void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
213int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
214void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);
215
216
217#ifdef __cplusplus
218}
219#endif
220
221#endif