Gordon Henriksen | 76a0374 | 2007-09-18 03:18:57 +0000 | [diff] [blame^] | 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 | \*===----------------------------------------------------------------------===*/ |
| 27 | |
| 28 | #ifndef LLVM_C_CORE_H |
| 29 | #define LLVM_C_CORE_H |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | |
| 36 | /* Opaque types. */ |
| 37 | typedef struct LLVMOpaqueModule *LLVMModuleRef; |
| 38 | typedef struct LLVMOpaqueType *LLVMTypeRef; |
| 39 | typedef struct LLVMOpaqueValue *LLVMValueRef; |
| 40 | |
| 41 | typedef 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 | |
| 58 | typedef 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 | |
| 70 | typedef 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. */ |
| 80 | LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID); |
| 81 | void LLVMDisposeModule(LLVMModuleRef M); |
| 82 | |
| 83 | /* Same as Module::addTypeName. */ |
| 84 | int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty); |
| 85 | int 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 | |
| 105 | LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); |
| 106 | void LLVMRefineAbstractType(LLVMTypeRef AbstractType, LLVMTypeRef ConcreteType); |
| 107 | |
| 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); |
| 116 | |
| 117 | /* Operations on real types */ |
| 118 | LLVMTypeRef LLVMFloatType(); |
| 119 | LLVMTypeRef LLVMDoubleType(); |
| 120 | LLVMTypeRef LLVMX86FP80Type(); |
| 121 | LLVMTypeRef LLVMFP128Type(); |
| 122 | LLVMTypeRef LLVMPPCFP128Type(); |
| 123 | |
| 124 | /* Operations on function types */ |
| 125 | LLVMTypeRef LLVMCreateFunctionType(LLVMTypeRef ReturnType, |
| 126 | LLVMTypeRef *ParamTypes, unsigned ParamCount, |
| 127 | int IsVarArg); |
| 128 | int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy); |
| 129 | LLVMTypeRef LLVMGetFunctionReturnType(LLVMTypeRef FunctionTy); |
| 130 | unsigned LLVMGetFunctionParamCount(LLVMTypeRef FunctionTy); |
| 131 | void LLVMGetFunctionParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest); |
| 132 | |
| 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); |
| 139 | |
| 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); |
| 144 | |
| 145 | LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); |
| 146 | unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy); |
| 147 | unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy); |
| 148 | |
| 149 | /* Operations on other types */ |
| 150 | LLVMTypeRef LLVMVoidType(); |
| 151 | LLVMTypeRef LLVMLabelType(); |
| 152 | LLVMTypeRef 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 */ |
| 171 | LLVMTypeRef LLVMGetTypeOfValue(LLVMValueRef Val); |
| 172 | const char *LLVMGetValueName(LLVMValueRef Val); |
| 173 | void LLVMSetValueName(LLVMValueRef Val, const char *Name); |
| 174 | |
| 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); |
| 180 | |
| 181 | /* Operations on scalar constants */ |
| 182 | LLVMValueRef LLVMGetIntConstant(LLVMTypeRef IntTy, unsigned long long N, |
| 183 | int SignExtend); |
| 184 | LLVMValueRef LLVMGetRealConstant(LLVMTypeRef RealTy, double N); |
| 185 | |
| 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, |
| 192 | int packed); |
| 193 | LLVMValueRef LLVMGetVectorConstant(LLVMValueRef *ScalarConstantVals, |
| 194 | unsigned Size); |
| 195 | |
| 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); |
| 206 | |
| 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); |
| 215 | |
| 216 | |
| 217 | #ifdef __cplusplus |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | #endif |