1 /*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
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. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header declares the C interface to libLLVMCore.a, which implements *|
11 |* the LLVM intermediate representation. *|
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). *|
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. *|
26 \*===----------------------------------------------------------------------===*/
37 typedef struct LLVMOpaqueModule *LLVMModuleRef;
38 typedef struct LLVMOpaqueType *LLVMTypeRef;
39 typedef struct LLVMOpaqueValue *LLVMValueRef;
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 */
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*/
71 LLVMDefaultVisibility = 0, /* The GV is visible */
72 LLVMHiddenVisibility, /* The GV is hidden */
73 LLVMProtectedVisibility /* The GV is protected */
77 /*===-- Modules -----------------------------------------------------------===*/
79 /* Create and destroy modules. */
80 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID);
81 void LLVMDisposeModule(LLVMModuleRef M);
83 /* Same as Module::addTypeName. */
84 int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty);
85 int LLVMDeleteTypeName(LLVMModuleRef M, const char *Name);
88 /*===-- Types --------------------------------------------------------------===*/
90 /* LLVM types conform to the following hierarchy:
105 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
106 void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType);
108 /* Operations on integer types */
109 LLVMTypeRef LLVMInt1Type();
110 LLVMTypeRef LLVMInt8Type();
111 LLVMTypeRef LLVMInt16Type();
112 LLVMTypeRef LLVMInt32Type();
113 LLVMTypeRef LLVMInt64Type();
114 LLVMTypeRef LLVMCreateIntegerType(unsigned NumBits);
115 unsigned LLVMGetIntegerTypeWidth(LLVMTypeRef IntegerTy);
117 /* Operations on real types */
118 LLVMTypeRef LLVMFloatType();
119 LLVMTypeRef LLVMDoubleType();
120 LLVMTypeRef LLVMX86FP80Type();
121 LLVMTypeRef LLVMFP128Type();
122 LLVMTypeRef LLVMPPCFP128Type();
124 /* Operations on function types */
125 LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType,
126 LLVMTypeRef *ParamTypes, unsigned ParamCount,
128 int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
129 LLVMTypeRef LLVMGetFunctionReturnType(LLVMTypeRef FunctionTy);
130 unsigned LLVMGetFunctionParamCount(LLVMTypeRef FunctionTy);
131 void LLVMGetFunctionParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
133 /* Operations on struct types */
134 LLVMTypeRef LLVMCreateStructType(LLVMTypeRef *ElementTypes,
135 unsigned ElementCount, int Packed);
136 unsigned LLVMGetStructElementCount(LLVMTypeRef StructTy);
137 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
138 int LLVMIsPackedStruct(LLVMTypeRef StructTy);
140 /* Operations on array, pointer, and vector types (sequence types) */
141 LLVMTypeRef LLVMCreateArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
142 LLVMTypeRef LLVMCreatePointerType(LLVMTypeRef ElementType);
143 LLVMTypeRef LLVMCreateVectorType(LLVMTypeRef ElementType,unsigned ElementCount);
145 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
146 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
147 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
149 /* Operations on other types */
150 LLVMTypeRef LLVMVoidType();
151 LLVMTypeRef LLVMLabelType();
152 LLVMTypeRef LLVMCreateOpaqueType();
155 /*===-- Values ------------------------------------------------------------===*/
157 /* The bulk of LLVM's object model consists of values, which comprise a very
158 * rich type hierarchy.
170 /* Operations on all values */
171 LLVMTypeRef LLVMGetTypeOfValue(LLVMValueRef Val);
172 const char *LLVMGetValueName(LLVMValueRef Val);
173 void LLVMSetValueName(LLVMValueRef Val, const char *Name);
175 /* Operations on constants of any type */
176 LLVMValueRef LLVMGetNull(LLVMTypeRef Ty); /* all zeroes */
177 LLVMValueRef LLVMGetAllOnes(LLVMTypeRef Ty); /* only for int/vector */
178 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
179 int LLVMIsNull(LLVMValueRef Val);
181 /* Operations on scalar constants */
182 LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N,
184 LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N);
186 /* Operations on composite constants */
187 LLVMValueRef LLVMGetStringConstant(const char *Str, unsigned Length,
188 int DontNullTerminate);
189 LLVMValueRef LLVMGetArrayConstant(LLVMTypeRef ArrayTy,
190 LLVMValueRef *ConstantVals, unsigned Length);
191 LLVMValueRef LLVMGetStructConstant(LLVMValueRef *ConstantVals, unsigned Count,
193 LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals,
196 /* Operations on global variables, functions, and aliases (globals) */
197 int LLVMIsDeclaration(LLVMValueRef Global);
198 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global);
199 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage);
200 const char *LLVMGetSection(LLVMValueRef Global);
201 void LLVMSetSection(LLVMValueRef Global, const char *Section);
202 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global);
203 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz);
204 unsigned LLVMGetAlignment(LLVMValueRef Global);
205 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes);
207 /* Operations on global variables */
208 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name);
209 void LLVMDeleteGlobal(LLVMValueRef GlobalVar);
210 int LLVMHasInitializer(LLVMValueRef GlobalVar);
211 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar);
212 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal);
213 int LLVMIsThreadLocal(LLVMValueRef GlobalVar);
214 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal);