Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1 | //===-- Core.cpp ----------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the C bindings for libLLVMCore.a, which implements |
| 11 | // the LLVM intermediate representation. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm-c/Core.h" |
| 16 | #include "llvm/Bitcode/ReaderWriter.h" |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 17 | #include "llvm/Constants.h" |
| 18 | #include "llvm/DerivedTypes.h" |
| 19 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 20 | #include "llvm/GlobalAlias.h" |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 21 | #include "llvm/LLVMContext.h" |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 22 | #include "llvm/TypeSymbolTable.h" |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 23 | #include "llvm/ModuleProvider.h" |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 24 | #include "llvm/InlineAsm.h" |
Gordon Henriksen | 2a9c671 | 2008-12-19 18:39:45 +0000 | [diff] [blame] | 25 | #include "llvm/IntrinsicInst.h" |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MemoryBuffer.h" |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CallSite.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 29 | #include <cassert> |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 30 | #include <cstdlib> |
Anton Korobeynikov | ae9f3a3 | 2008-02-20 11:08:44 +0000 | [diff] [blame] | 31 | #include <cstring> |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace llvm; |
| 34 | |
| 35 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 36 | /*===-- Error handling ----------------------------------------------------===*/ |
| 37 | |
| 38 | void LLVMDisposeMessage(char *Message) { |
| 39 | free(Message); |
| 40 | } |
| 41 | |
| 42 | |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 43 | /*===-- Operations on contexts --------------------------------------------===*/ |
| 44 | |
| 45 | LLVMContextRef LLVMContextCreate() { |
| 46 | return wrap(new LLVMContext()); |
| 47 | } |
| 48 | |
Owen Anderson | c70e621 | 2009-07-02 00:16:38 +0000 | [diff] [blame] | 49 | LLVMContextRef LLVMGetGlobalContext() { |
| 50 | return wrap(&getGlobalContext()); |
| 51 | } |
| 52 | |
Owen Anderson | 8b477ed | 2009-07-01 16:58:40 +0000 | [diff] [blame] | 53 | void LLVMContextDispose(LLVMContextRef C) { |
| 54 | delete unwrap(C); |
| 55 | } |
| 56 | |
| 57 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 58 | /*===-- Operations on modules ---------------------------------------------===*/ |
| 59 | |
Owen Anderson | c8897d9 | 2009-07-02 07:17:57 +0000 | [diff] [blame] | 60 | LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) { |
| 61 | return wrap(new Module(ModuleID, getGlobalContext())); |
| 62 | } |
| 63 | |
| 64 | LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, |
| 65 | LLVMContextRef C) { |
Owen Anderson | 31895e7 | 2009-07-01 21:22:36 +0000 | [diff] [blame] | 66 | return wrap(new Module(ModuleID, *unwrap(C))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void LLVMDisposeModule(LLVMModuleRef M) { |
| 70 | delete unwrap(M); |
| 71 | } |
| 72 | |
Gordon Henriksen | a353ffa | 2007-12-27 20:13:47 +0000 | [diff] [blame] | 73 | /*--.. Data layout .........................................................--*/ |
| 74 | const char * LLVMGetDataLayout(LLVMModuleRef M) { |
| 75 | return unwrap(M)->getDataLayout().c_str(); |
| 76 | } |
| 77 | |
| 78 | void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) { |
| 79 | unwrap(M)->setDataLayout(Triple); |
| 80 | } |
| 81 | |
| 82 | /*--.. Target triple .......................................................--*/ |
| 83 | const char * LLVMGetTarget(LLVMModuleRef M) { |
| 84 | return unwrap(M)->getTargetTriple().c_str(); |
| 85 | } |
| 86 | |
| 87 | void LLVMSetTarget(LLVMModuleRef M, const char *Triple) { |
| 88 | unwrap(M)->setTargetTriple(Triple); |
| 89 | } |
| 90 | |
| 91 | /*--.. Type names ..........................................................--*/ |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 92 | int LLVMAddTypeName(LLVMModuleRef M, const char *Name, LLVMTypeRef Ty) { |
| 93 | return unwrap(M)->addTypeName(Name, unwrap(Ty)); |
| 94 | } |
| 95 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 96 | void LLVMDeleteTypeName(LLVMModuleRef M, const char *Name) { |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 97 | TypeSymbolTable &TST = unwrap(M)->getTypeSymbolTable(); |
Daniel Dunbar | 8113c67 | 2009-08-06 06:04:35 +0000 | [diff] [blame] | 98 | |
| 99 | TypeSymbolTable::iterator I = TST.find(Name); |
| 100 | if (I != TST.end()) |
| 101 | TST.remove(I); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 104 | LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) { |
Daniel Dunbar | 8113c67 | 2009-08-06 06:04:35 +0000 | [diff] [blame] | 105 | return wrap(unwrap(M)->getTypeByName(Name)); |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Gordon Henriksen | af59b10 | 2008-03-14 23:58:56 +0000 | [diff] [blame] | 108 | void LLVMDumpModule(LLVMModuleRef M) { |
| 109 | unwrap(M)->dump(); |
| 110 | } |
| 111 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 112 | |
| 113 | /*===-- Operations on types -----------------------------------------------===*/ |
| 114 | |
| 115 | /*--.. Operations on all types (mostly) ....................................--*/ |
| 116 | |
| 117 | LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { |
Chris Lattner | 0df5c8e | 2009-07-15 22:00:31 +0000 | [diff] [blame] | 118 | switch (unwrap(Ty)->getTypeID()) { |
Daniel Dunbar | efd280b | 2009-07-16 22:06:22 +0000 | [diff] [blame] | 119 | default: |
| 120 | assert(false && "Unhandled TypeID."); |
Chris Lattner | 0df5c8e | 2009-07-15 22:00:31 +0000 | [diff] [blame] | 121 | case Type::VoidTyID: |
| 122 | return LLVMVoidTypeKind; |
| 123 | case Type::FloatTyID: |
| 124 | return LLVMFloatTypeKind; |
| 125 | case Type::DoubleTyID: |
| 126 | return LLVMDoubleTypeKind; |
| 127 | case Type::X86_FP80TyID: |
| 128 | return LLVMX86_FP80TypeKind; |
| 129 | case Type::FP128TyID: |
| 130 | return LLVMFP128TypeKind; |
| 131 | case Type::PPC_FP128TyID: |
| 132 | return LLVMPPC_FP128TypeKind; |
| 133 | case Type::LabelTyID: |
| 134 | return LLVMLabelTypeKind; |
| 135 | case Type::MetadataTyID: |
| 136 | return LLVMMetadataTypeKind; |
| 137 | case Type::IntegerTyID: |
| 138 | return LLVMIntegerTypeKind; |
| 139 | case Type::FunctionTyID: |
| 140 | return LLVMFunctionTypeKind; |
| 141 | case Type::StructTyID: |
| 142 | return LLVMStructTypeKind; |
| 143 | case Type::ArrayTyID: |
| 144 | return LLVMArrayTypeKind; |
| 145 | case Type::PointerTyID: |
| 146 | return LLVMPointerTypeKind; |
| 147 | case Type::OpaqueTyID: |
| 148 | return LLVMOpaqueTypeKind; |
| 149 | case Type::VectorTyID: |
| 150 | return LLVMVectorTypeKind; |
Chris Lattner | 0df5c8e | 2009-07-15 22:00:31 +0000 | [diff] [blame] | 151 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 154 | LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) { |
| 155 | return wrap(&unwrap(Ty)->getContext()); |
| 156 | } |
| 157 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 158 | /*--.. Operations on integer types .........................................--*/ |
| 159 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 160 | LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) { |
| 161 | return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C)); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 162 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 163 | LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) { |
| 164 | return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C)); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 165 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 166 | LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) { |
| 167 | return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C)); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 168 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 169 | LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) { |
| 170 | return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C)); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 171 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 172 | LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) { |
| 173 | return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C)); |
| 174 | } |
| 175 | LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) { |
| 176 | return wrap(IntegerType::get(*unwrap(C), NumBits)); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 177 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 178 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 179 | LLVMTypeRef LLVMInt1Type(void) { |
| 180 | return LLVMInt1TypeInContext(LLVMGetGlobalContext()); |
| 181 | } |
| 182 | LLVMTypeRef LLVMInt8Type(void) { |
| 183 | return LLVMInt8TypeInContext(LLVMGetGlobalContext()); |
| 184 | } |
| 185 | LLVMTypeRef LLVMInt16Type(void) { |
| 186 | return LLVMInt16TypeInContext(LLVMGetGlobalContext()); |
| 187 | } |
| 188 | LLVMTypeRef LLVMInt32Type(void) { |
| 189 | return LLVMInt32TypeInContext(LLVMGetGlobalContext()); |
| 190 | } |
| 191 | LLVMTypeRef LLVMInt64Type(void) { |
| 192 | return LLVMInt64TypeInContext(LLVMGetGlobalContext()); |
| 193 | } |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 194 | LLVMTypeRef LLVMIntType(unsigned NumBits) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 195 | return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 198 | unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 199 | return unwrap<IntegerType>(IntegerTy)->getBitWidth(); |
| 200 | } |
| 201 | |
| 202 | /*--.. Operations on real types ............................................--*/ |
| 203 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 204 | LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) { |
| 205 | return (LLVMTypeRef) Type::getFloatTy(*unwrap(C)); |
| 206 | } |
| 207 | LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) { |
| 208 | return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C)); |
| 209 | } |
| 210 | LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) { |
| 211 | return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C)); |
| 212 | } |
| 213 | LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) { |
| 214 | return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C)); |
| 215 | } |
| 216 | LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) { |
| 217 | return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C)); |
| 218 | } |
| 219 | |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 220 | LLVMTypeRef LLVMFloatType(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 221 | return LLVMFloatTypeInContext(LLVMGetGlobalContext()); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 222 | } |
| 223 | LLVMTypeRef LLVMDoubleType(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 224 | return LLVMDoubleTypeInContext(LLVMGetGlobalContext()); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 225 | } |
| 226 | LLVMTypeRef LLVMX86FP80Type(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 227 | return LLVMX86FP80TypeInContext(LLVMGetGlobalContext()); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 228 | } |
| 229 | LLVMTypeRef LLVMFP128Type(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 230 | return LLVMFP128TypeInContext(LLVMGetGlobalContext()); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 231 | } |
| 232 | LLVMTypeRef LLVMPPCFP128Type(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 233 | return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext()); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 234 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 235 | |
| 236 | /*--.. Operations on function types ........................................--*/ |
| 237 | |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 238 | LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, |
| 239 | LLVMTypeRef *ParamTypes, unsigned ParamCount, |
| 240 | int IsVarArg) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 241 | std::vector<const Type*> Tys; |
| 242 | for (LLVMTypeRef *I = ParamTypes, *E = ParamTypes + ParamCount; I != E; ++I) |
| 243 | Tys.push_back(unwrap(*I)); |
| 244 | |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 245 | return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | int LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) { |
| 249 | return unwrap<FunctionType>(FunctionTy)->isVarArg(); |
| 250 | } |
| 251 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 252 | LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 253 | return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType()); |
| 254 | } |
| 255 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 256 | unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 257 | return unwrap<FunctionType>(FunctionTy)->getNumParams(); |
| 258 | } |
| 259 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 260 | void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 261 | FunctionType *Ty = unwrap<FunctionType>(FunctionTy); |
| 262 | for (FunctionType::param_iterator I = Ty->param_begin(), |
| 263 | E = Ty->param_end(); I != E; ++I) |
| 264 | *Dest++ = wrap(*I); |
| 265 | } |
| 266 | |
| 267 | /*--.. Operations on struct types ..........................................--*/ |
| 268 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 269 | LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, |
Gordon Henriksen | 81a7881 | 2007-10-06 16:05:20 +0000 | [diff] [blame] | 270 | unsigned ElementCount, int Packed) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 271 | std::vector<const Type*> Tys; |
| 272 | for (LLVMTypeRef *I = ElementTypes, |
| 273 | *E = ElementTypes + ElementCount; I != E; ++I) |
| 274 | Tys.push_back(unwrap(*I)); |
| 275 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 276 | return wrap(StructType::get(*unwrap(C), Tys, Packed != 0)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 279 | LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, |
| 280 | unsigned ElementCount, int Packed) { |
| 281 | return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes, |
| 282 | ElementCount, Packed); |
| 283 | } |
| 284 | |
| 285 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 286 | unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 287 | return unwrap<StructType>(StructTy)->getNumElements(); |
| 288 | } |
| 289 | |
| 290 | void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) { |
| 291 | StructType *Ty = unwrap<StructType>(StructTy); |
| 292 | for (FunctionType::param_iterator I = Ty->element_begin(), |
| 293 | E = Ty->element_end(); I != E; ++I) |
| 294 | *Dest++ = wrap(*I); |
| 295 | } |
| 296 | |
| 297 | int LLVMIsPackedStruct(LLVMTypeRef StructTy) { |
| 298 | return unwrap<StructType>(StructTy)->isPacked(); |
| 299 | } |
| 300 | |
| 301 | /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/ |
| 302 | |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 303 | LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) { |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 304 | return wrap(ArrayType::get(unwrap(ElementType), ElementCount)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 307 | LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) { |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 308 | return wrap(PointerType::get(unwrap(ElementType), AddressSpace)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 311 | LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) { |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 312 | return wrap(VectorType::get(unwrap(ElementType), ElementCount)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) { |
| 316 | return wrap(unwrap<SequentialType>(Ty)->getElementType()); |
| 317 | } |
| 318 | |
| 319 | unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) { |
| 320 | return unwrap<ArrayType>(ArrayTy)->getNumElements(); |
| 321 | } |
| 322 | |
Gordon Henriksen | 57cebee | 2007-12-17 16:08:32 +0000 | [diff] [blame] | 323 | unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) { |
| 324 | return unwrap<PointerType>(PointerTy)->getAddressSpace(); |
| 325 | } |
| 326 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 327 | unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) { |
| 328 | return unwrap<VectorType>(VectorTy)->getNumElements(); |
| 329 | } |
| 330 | |
| 331 | /*--.. Operations on other types ...........................................--*/ |
| 332 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 333 | LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) { |
| 334 | return wrap(Type::getVoidTy(*unwrap(C))); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 335 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 336 | LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) { |
| 337 | return wrap(Type::getLabelTy(*unwrap(C))); |
| 338 | } |
| 339 | LLVMTypeRef LLVMOpaqueTypeInContext(LLVMContextRef C) { |
| 340 | return wrap(OpaqueType::get(*unwrap(C))); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 341 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 342 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 343 | LLVMTypeRef LLVMVoidType(void) { |
| 344 | return LLVMVoidTypeInContext(LLVMGetGlobalContext()); |
| 345 | } |
| 346 | LLVMTypeRef LLVMLabelType(void) { |
| 347 | return LLVMLabelTypeInContext(LLVMGetGlobalContext()); |
| 348 | } |
Gordon Henriksen | 16c1f44 | 2008-05-04 12:55:34 +0000 | [diff] [blame] | 349 | LLVMTypeRef LLVMOpaqueType(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 350 | return LLVMOpaqueTypeInContext(LLVMGetGlobalContext()); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 353 | /*--.. Operations on type handles ..........................................--*/ |
Gordon Henriksen | 1cf08fd | 2007-10-07 00:13:35 +0000 | [diff] [blame] | 354 | |
| 355 | LLVMTypeHandleRef LLVMCreateTypeHandle(LLVMTypeRef PotentiallyAbstractTy) { |
| 356 | return wrap(new PATypeHolder(unwrap(PotentiallyAbstractTy))); |
| 357 | } |
| 358 | |
| 359 | void LLVMDisposeTypeHandle(LLVMTypeHandleRef TypeHandle) { |
| 360 | delete unwrap(TypeHandle); |
| 361 | } |
| 362 | |
| 363 | LLVMTypeRef LLVMResolveTypeHandle(LLVMTypeHandleRef TypeHandle) { |
| 364 | return wrap(unwrap(TypeHandle)->get()); |
| 365 | } |
| 366 | |
| 367 | void LLVMRefineType(LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy) { |
| 368 | unwrap<DerivedType>(AbstractTy)->refineAbstractTypeTo(unwrap(ConcreteTy)); |
| 369 | } |
| 370 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 371 | |
| 372 | /*===-- Operations on values ----------------------------------------------===*/ |
| 373 | |
| 374 | /*--.. Operations on all values ............................................--*/ |
| 375 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 376 | LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 377 | return wrap(unwrap(Val)->getType()); |
| 378 | } |
| 379 | |
| 380 | const char *LLVMGetValueName(LLVMValueRef Val) { |
Daniel Dunbar | 93b67e4 | 2009-07-26 07:49:05 +0000 | [diff] [blame] | 381 | return unwrap(Val)->getName().data(); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void LLVMSetValueName(LLVMValueRef Val, const char *Name) { |
| 385 | unwrap(Val)->setName(Name); |
| 386 | } |
| 387 | |
Gordon Henriksen | 88cc699 | 2007-10-06 00:08:49 +0000 | [diff] [blame] | 388 | void LLVMDumpValue(LLVMValueRef Val) { |
| 389 | unwrap(Val)->dump(); |
| 390 | } |
| 391 | |
Gordon Henriksen | 2a9c671 | 2008-12-19 18:39:45 +0000 | [diff] [blame] | 392 | |
| 393 | /*--.. Conversion functions ................................................--*/ |
| 394 | |
| 395 | #define LLVM_DEFINE_VALUE_CAST(name) \ |
| 396 | LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \ |
| 397 | return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \ |
| 398 | } |
| 399 | |
| 400 | LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) |
| 401 | |
| 402 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 403 | /*--.. Operations on constants of any type .................................--*/ |
| 404 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 405 | LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) { |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 406 | return wrap(Constant::getNullValue(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 409 | LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) { |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 410 | return wrap(Constant::getAllOnesValue(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) { |
Owen Anderson | 9e9a0d5 | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 414 | return wrap(UndefValue::get(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 417 | int LLVMIsConstant(LLVMValueRef Ty) { |
| 418 | return isa<Constant>(unwrap(Ty)); |
| 419 | } |
| 420 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 421 | int LLVMIsNull(LLVMValueRef Val) { |
| 422 | if (Constant *C = dyn_cast<Constant>(unwrap(Val))) |
| 423 | return C->isNullValue(); |
| 424 | return false; |
| 425 | } |
| 426 | |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 427 | int LLVMIsUndef(LLVMValueRef Val) { |
| 428 | return isa<UndefValue>(unwrap(Val)); |
| 429 | } |
| 430 | |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 431 | LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) { |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 432 | return |
Owen Anderson | 9e9a0d5 | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 433 | wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty))); |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 436 | /*--.. Operations on scalar constants ......................................--*/ |
| 437 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 438 | LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, |
| 439 | int SignExtend) { |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 440 | return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 443 | static const fltSemantics &SemanticsForType(Type *Ty) { |
| 444 | assert(Ty->isFloatingPoint() && "Type is not floating point!"); |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 445 | if (Ty == Type::getFloatTy(Ty->getContext())) |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 446 | return APFloat::IEEEsingle; |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 447 | if (Ty == Type::getDoubleTy(Ty->getContext())) |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 448 | return APFloat::IEEEdouble; |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 449 | if (Ty == Type::getX86_FP80Ty(Ty->getContext())) |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 450 | return APFloat::x87DoubleExtended; |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 451 | if (Ty == Type::getFP128Ty(Ty->getContext())) |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 452 | return APFloat::IEEEquad; |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 453 | if (Ty == Type::getPPC_FP128Ty(Ty->getContext())) |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 454 | return APFloat::PPCDoubleDouble; |
| 455 | return APFloat::Bogus; |
| 456 | } |
| 457 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 458 | LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) { |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 459 | APFloat APN(N); |
Dale Johannesen | 23a9855 | 2008-10-09 23:00:39 +0000 | [diff] [blame] | 460 | bool ignored; |
| 461 | APN.convert(SemanticsForType(unwrap(RealTy)), APFloat::rmNearestTiesToEven, |
| 462 | &ignored); |
Owen Anderson | 6f83c9c | 2009-07-27 20:59:43 +0000 | [diff] [blame] | 463 | return wrap(ConstantFP::get(getGlobalContext(), APN)); |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) { |
Owen Anderson | 6f83c9c | 2009-07-27 20:59:43 +0000 | [diff] [blame] | 467 | return wrap(ConstantFP::get(getGlobalContext(), |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 468 | APFloat(SemanticsForType(unwrap(RealTy)), Text))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /*--.. Operations on composite constants ...................................--*/ |
| 472 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 473 | LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, |
| 474 | unsigned Length, int DontNullTerminate) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 475 | /* Inverted the sense of AddNull because ', 0)' is a |
| 476 | better mnemonic for null termination than ', 1)'. */ |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 477 | return wrap(ConstantArray::get(*unwrap(C), std::string(Str, Length), |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 478 | DontNullTerminate == 0)); |
| 479 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 480 | LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, |
| 481 | LLVMValueRef *ConstantVals, |
| 482 | unsigned Count, int Packed) { |
| 483 | return wrap(ConstantStruct::get(*unwrap(C), |
| 484 | unwrap<Constant>(ConstantVals, Count), |
| 485 | Count, Packed != 0)); |
| 486 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 487 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 488 | LLVMValueRef LLVMConstString(const char *Str, unsigned Length, |
| 489 | int DontNullTerminate) { |
| 490 | return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length, |
| 491 | DontNullTerminate); |
| 492 | } |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 493 | LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, |
| 494 | LLVMValueRef *ConstantVals, unsigned Length) { |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 495 | return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 496 | unwrap<Constant>(ConstantVals, Length), |
| 497 | Length)); |
| 498 | } |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 499 | LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, |
| 500 | int Packed) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 501 | return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count, |
| 502 | Packed); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 505 | LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) { |
Owen Anderson | af7ec97 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 506 | return wrap(ConstantVector::get( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 507 | unwrap<Constant>(ScalarConstantVals, Size), Size)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 510 | /*--.. Constant expressions ................................................--*/ |
| 511 | |
Duncan Sands | ef854af | 2009-05-21 15:52:21 +0000 | [diff] [blame] | 512 | LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 513 | return wrap(ConstantExpr::getAlignOf(unwrap(Ty))); |
Duncan Sands | ef854af | 2009-05-21 15:52:21 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 516 | LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 517 | return wrap(ConstantExpr::getSizeOf(unwrap(Ty))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 521 | return wrap(ConstantExpr::getNeg( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 522 | unwrap<Constant>(ConstantVal))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 526 | return wrap(ConstantExpr::getNot( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 527 | unwrap<Constant>(ConstantVal))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 531 | return wrap(ConstantExpr::getAdd( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 532 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 533 | unwrap<Constant>(RHSConstant))); |
| 534 | } |
| 535 | |
| 536 | LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 537 | return wrap(ConstantExpr::getSub( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 538 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 539 | unwrap<Constant>(RHSConstant))); |
| 540 | } |
| 541 | |
| 542 | LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 543 | return wrap(ConstantExpr::getMul( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 544 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 545 | unwrap<Constant>(RHSConstant))); |
| 546 | } |
| 547 | |
| 548 | LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 549 | return wrap(ConstantExpr::getUDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 550 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 551 | unwrap<Constant>(RHSConstant))); |
| 552 | } |
| 553 | |
| 554 | LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 555 | return wrap(ConstantExpr::getSDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 556 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 557 | unwrap<Constant>(RHSConstant))); |
| 558 | } |
| 559 | |
| 560 | LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 561 | return wrap(ConstantExpr::getFDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 562 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 563 | unwrap<Constant>(RHSConstant))); |
| 564 | } |
| 565 | |
| 566 | LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 567 | return wrap(ConstantExpr::getURem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 568 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 569 | unwrap<Constant>(RHSConstant))); |
| 570 | } |
| 571 | |
| 572 | LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 573 | return wrap(ConstantExpr::getSRem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 574 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 575 | unwrap<Constant>(RHSConstant))); |
| 576 | } |
| 577 | |
| 578 | LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 579 | return wrap(ConstantExpr::getFRem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 580 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 581 | unwrap<Constant>(RHSConstant))); |
| 582 | } |
| 583 | |
| 584 | LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 585 | return wrap(ConstantExpr::getAnd( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 586 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 587 | unwrap<Constant>(RHSConstant))); |
| 588 | } |
| 589 | |
| 590 | LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 591 | return wrap(ConstantExpr::getOr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 592 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 593 | unwrap<Constant>(RHSConstant))); |
| 594 | } |
| 595 | |
| 596 | LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 597 | return wrap(ConstantExpr::getXor( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 598 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 599 | unwrap<Constant>(RHSConstant))); |
| 600 | } |
| 601 | |
| 602 | LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, |
| 603 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 604 | return wrap(ConstantExpr::getICmp(Predicate, |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 605 | unwrap<Constant>(LHSConstant), |
| 606 | unwrap<Constant>(RHSConstant))); |
| 607 | } |
| 608 | |
| 609 | LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, |
| 610 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 611 | return wrap(ConstantExpr::getFCmp(Predicate, |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 612 | unwrap<Constant>(LHSConstant), |
| 613 | unwrap<Constant>(RHSConstant))); |
| 614 | } |
| 615 | |
| 616 | LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 617 | return wrap(ConstantExpr::getShl( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 618 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 619 | unwrap<Constant>(RHSConstant))); |
| 620 | } |
| 621 | |
| 622 | LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 623 | return wrap(ConstantExpr::getLShr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 624 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 625 | unwrap<Constant>(RHSConstant))); |
| 626 | } |
| 627 | |
| 628 | LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 629 | return wrap(ConstantExpr::getAShr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 630 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 631 | unwrap<Constant>(RHSConstant))); |
| 632 | } |
| 633 | |
| 634 | LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, |
| 635 | LLVMValueRef *ConstantIndices, unsigned NumIndices) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 636 | return wrap(ConstantExpr::getGetElementPtr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 637 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 638 | unwrap<Constant>(ConstantIndices, |
| 639 | NumIndices), |
| 640 | NumIndices)); |
| 641 | } |
| 642 | |
| 643 | LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 644 | return wrap(ConstantExpr::getTrunc( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 645 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 646 | unwrap(ToType))); |
| 647 | } |
| 648 | |
| 649 | LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 650 | return wrap(ConstantExpr::getSExt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 651 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 652 | unwrap(ToType))); |
| 653 | } |
| 654 | |
| 655 | LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 656 | return wrap(ConstantExpr::getZExt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 657 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 658 | unwrap(ToType))); |
| 659 | } |
| 660 | |
| 661 | LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 662 | return wrap(ConstantExpr::getFPTrunc( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 663 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 664 | unwrap(ToType))); |
| 665 | } |
| 666 | |
| 667 | LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 668 | return wrap(ConstantExpr::getFPExtend( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 669 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 670 | unwrap(ToType))); |
| 671 | } |
| 672 | |
| 673 | LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 674 | return wrap(ConstantExpr::getUIToFP( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 675 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 676 | unwrap(ToType))); |
| 677 | } |
| 678 | |
| 679 | LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 680 | return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 681 | unwrap(ToType))); |
| 682 | } |
| 683 | |
| 684 | LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 685 | return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 686 | unwrap(ToType))); |
| 687 | } |
| 688 | |
| 689 | LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 690 | return wrap(ConstantExpr::getFPToSI( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 691 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 692 | unwrap(ToType))); |
| 693 | } |
| 694 | |
| 695 | LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 696 | return wrap(ConstantExpr::getPtrToInt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 697 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 698 | unwrap(ToType))); |
| 699 | } |
| 700 | |
| 701 | LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 702 | return wrap(ConstantExpr::getIntToPtr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 703 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 704 | unwrap(ToType))); |
| 705 | } |
| 706 | |
| 707 | LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 708 | return wrap(ConstantExpr::getBitCast( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 709 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 710 | unwrap(ToType))); |
| 711 | } |
| 712 | |
| 713 | LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, |
| 714 | LLVMValueRef ConstantIfTrue, |
| 715 | LLVMValueRef ConstantIfFalse) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 716 | return wrap(ConstantExpr::getSelect( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 717 | unwrap<Constant>(ConstantCondition), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 718 | unwrap<Constant>(ConstantIfTrue), |
| 719 | unwrap<Constant>(ConstantIfFalse))); |
| 720 | } |
| 721 | |
| 722 | LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, |
| 723 | LLVMValueRef IndexConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 724 | return wrap(ConstantExpr::getExtractElement( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 725 | unwrap<Constant>(VectorConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 726 | unwrap<Constant>(IndexConstant))); |
| 727 | } |
| 728 | |
| 729 | LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, |
| 730 | LLVMValueRef ElementValueConstant, |
| 731 | LLVMValueRef IndexConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 732 | return wrap(ConstantExpr::getInsertElement( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 733 | unwrap<Constant>(VectorConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 734 | unwrap<Constant>(ElementValueConstant), |
| 735 | unwrap<Constant>(IndexConstant))); |
| 736 | } |
| 737 | |
| 738 | LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, |
| 739 | LLVMValueRef VectorBConstant, |
| 740 | LLVMValueRef MaskConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 741 | return wrap(ConstantExpr::getShuffleVector( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 742 | unwrap<Constant>(VectorAConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 743 | unwrap<Constant>(VectorBConstant), |
| 744 | unwrap<Constant>(MaskConstant))); |
| 745 | } |
| 746 | |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 747 | LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, |
| 748 | unsigned NumIdx) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 749 | return wrap(ConstantExpr::getExtractValue( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 750 | unwrap<Constant>(AggConstant), |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 751 | IdxList, NumIdx)); |
| 752 | } |
| 753 | |
| 754 | LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, |
| 755 | LLVMValueRef ElementValueConstant, |
| 756 | unsigned *IdxList, unsigned NumIdx) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 757 | return wrap(ConstantExpr::getInsertValue( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 758 | unwrap<Constant>(AggConstant), |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 759 | unwrap<Constant>(ElementValueConstant), |
| 760 | IdxList, NumIdx)); |
| 761 | } |
| 762 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 763 | LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, |
| 764 | const char *Constraints, int HasSideEffects) { |
| 765 | return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString, |
| 766 | Constraints, HasSideEffects)); |
| 767 | } |
| 768 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 769 | /*--.. Operations on global variables, functions, and aliases (globals) ....--*/ |
| 770 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 771 | LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) { |
| 772 | return wrap(unwrap<GlobalValue>(Global)->getParent()); |
| 773 | } |
| 774 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 775 | int LLVMIsDeclaration(LLVMValueRef Global) { |
| 776 | return unwrap<GlobalValue>(Global)->isDeclaration(); |
| 777 | } |
| 778 | |
| 779 | LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { |
Bill Wendling | 4aebcb4 | 2009-07-20 20:34:46 +0000 | [diff] [blame] | 780 | switch (unwrap<GlobalValue>(Global)->getLinkage()) { |
| 781 | default: |
| 782 | assert(false && "Unhandled Linkage Type."); |
| 783 | case GlobalValue::ExternalLinkage: |
| 784 | return LLVMExternalLinkage; |
| 785 | case GlobalValue::AvailableExternallyLinkage: |
| 786 | return LLVMAvailableExternallyLinkage; |
| 787 | case GlobalValue::LinkOnceAnyLinkage: |
| 788 | return LLVMLinkOnceAnyLinkage; |
| 789 | case GlobalValue::LinkOnceODRLinkage: |
| 790 | return LLVMLinkOnceODRLinkage; |
| 791 | case GlobalValue::WeakAnyLinkage: |
| 792 | return LLVMWeakAnyLinkage; |
| 793 | case GlobalValue::WeakODRLinkage: |
| 794 | return LLVMWeakODRLinkage; |
| 795 | case GlobalValue::AppendingLinkage: |
| 796 | return LLVMAppendingLinkage; |
| 797 | case GlobalValue::InternalLinkage: |
| 798 | return LLVMInternalLinkage; |
| 799 | case GlobalValue::PrivateLinkage: |
| 800 | return LLVMPrivateLinkage; |
| 801 | case GlobalValue::LinkerPrivateLinkage: |
| 802 | return LLVMLinkerPrivateLinkage; |
| 803 | case GlobalValue::DLLImportLinkage: |
| 804 | return LLVMDLLImportLinkage; |
| 805 | case GlobalValue::DLLExportLinkage: |
| 806 | return LLVMDLLExportLinkage; |
| 807 | case GlobalValue::ExternalWeakLinkage: |
| 808 | return LLVMExternalWeakLinkage; |
| 809 | case GlobalValue::GhostLinkage: |
| 810 | return LLVMGhostLinkage; |
| 811 | case GlobalValue::CommonLinkage: |
| 812 | return LLVMCommonLinkage; |
| 813 | } |
| 814 | |
| 815 | // Should never get here. |
| 816 | return static_cast<LLVMLinkage>(0); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) { |
Bill Wendling | 4aebcb4 | 2009-07-20 20:34:46 +0000 | [diff] [blame] | 820 | GlobalValue *GV = unwrap<GlobalValue>(Global); |
| 821 | |
| 822 | switch (Linkage) { |
| 823 | default: |
| 824 | assert(false && "Unhandled Linkage Type."); |
| 825 | case LLVMExternalLinkage: |
| 826 | GV->setLinkage(GlobalValue::ExternalLinkage); |
| 827 | break; |
| 828 | case LLVMAvailableExternallyLinkage: |
| 829 | GV->setLinkage(GlobalValue::AvailableExternallyLinkage); |
| 830 | break; |
| 831 | case LLVMLinkOnceAnyLinkage: |
| 832 | GV->setLinkage(GlobalValue::LinkOnceAnyLinkage); |
| 833 | break; |
| 834 | case LLVMLinkOnceODRLinkage: |
| 835 | GV->setLinkage(GlobalValue::LinkOnceODRLinkage); |
| 836 | break; |
| 837 | case LLVMWeakAnyLinkage: |
| 838 | GV->setLinkage(GlobalValue::WeakAnyLinkage); |
| 839 | break; |
| 840 | case LLVMWeakODRLinkage: |
| 841 | GV->setLinkage(GlobalValue::WeakODRLinkage); |
| 842 | break; |
| 843 | case LLVMAppendingLinkage: |
| 844 | GV->setLinkage(GlobalValue::AppendingLinkage); |
| 845 | break; |
| 846 | case LLVMInternalLinkage: |
| 847 | GV->setLinkage(GlobalValue::InternalLinkage); |
| 848 | break; |
| 849 | case LLVMPrivateLinkage: |
| 850 | GV->setLinkage(GlobalValue::PrivateLinkage); |
| 851 | break; |
| 852 | case LLVMLinkerPrivateLinkage: |
| 853 | GV->setLinkage(GlobalValue::LinkerPrivateLinkage); |
| 854 | break; |
| 855 | case LLVMDLLImportLinkage: |
| 856 | GV->setLinkage(GlobalValue::DLLImportLinkage); |
| 857 | break; |
| 858 | case LLVMDLLExportLinkage: |
| 859 | GV->setLinkage(GlobalValue::DLLExportLinkage); |
| 860 | break; |
| 861 | case LLVMExternalWeakLinkage: |
| 862 | GV->setLinkage(GlobalValue::ExternalWeakLinkage); |
| 863 | break; |
| 864 | case LLVMGhostLinkage: |
| 865 | GV->setLinkage(GlobalValue::GhostLinkage); |
| 866 | break; |
| 867 | case LLVMCommonLinkage: |
| 868 | GV->setLinkage(GlobalValue::CommonLinkage); |
| 869 | break; |
| 870 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | const char *LLVMGetSection(LLVMValueRef Global) { |
| 874 | return unwrap<GlobalValue>(Global)->getSection().c_str(); |
| 875 | } |
| 876 | |
| 877 | void LLVMSetSection(LLVMValueRef Global, const char *Section) { |
| 878 | unwrap<GlobalValue>(Global)->setSection(Section); |
| 879 | } |
| 880 | |
| 881 | LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) { |
| 882 | return static_cast<LLVMVisibility>( |
| 883 | unwrap<GlobalValue>(Global)->getVisibility()); |
| 884 | } |
| 885 | |
| 886 | void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) { |
| 887 | unwrap<GlobalValue>(Global) |
| 888 | ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz)); |
| 889 | } |
| 890 | |
| 891 | unsigned LLVMGetAlignment(LLVMValueRef Global) { |
| 892 | return unwrap<GlobalValue>(Global)->getAlignment(); |
| 893 | } |
| 894 | |
| 895 | void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) { |
| 896 | unwrap<GlobalValue>(Global)->setAlignment(Bytes); |
| 897 | } |
| 898 | |
| 899 | /*--.. Operations on global variables ......................................--*/ |
| 900 | |
| 901 | LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 902 | return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false, |
| 903 | GlobalValue::ExternalLinkage, 0, Name)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 906 | LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) { |
| 907 | return wrap(unwrap(M)->getNamedGlobal(Name)); |
| 908 | } |
| 909 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 910 | LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) { |
| 911 | Module *Mod = unwrap(M); |
| 912 | Module::global_iterator I = Mod->global_begin(); |
| 913 | if (I == Mod->global_end()) |
| 914 | return 0; |
| 915 | return wrap(I); |
| 916 | } |
| 917 | |
| 918 | LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) { |
| 919 | Module *Mod = unwrap(M); |
| 920 | Module::global_iterator I = Mod->global_end(); |
| 921 | if (I == Mod->global_begin()) |
| 922 | return 0; |
| 923 | return wrap(--I); |
| 924 | } |
| 925 | |
| 926 | LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) { |
| 927 | GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); |
| 928 | Module::global_iterator I = GV; |
| 929 | if (++I == GV->getParent()->global_end()) |
| 930 | return 0; |
| 931 | return wrap(I); |
| 932 | } |
| 933 | |
| 934 | LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) { |
| 935 | GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); |
| 936 | Module::global_iterator I = GV; |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 937 | if (I == GV->getParent()->global_begin()) |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 938 | return 0; |
| 939 | return wrap(--I); |
| 940 | } |
| 941 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 942 | void LLVMDeleteGlobal(LLVMValueRef GlobalVar) { |
| 943 | unwrap<GlobalVariable>(GlobalVar)->eraseFromParent(); |
| 944 | } |
| 945 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 946 | LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) { |
| 947 | return wrap(unwrap<GlobalVariable>(GlobalVar)->getInitializer()); |
| 948 | } |
| 949 | |
| 950 | void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) { |
| 951 | unwrap<GlobalVariable>(GlobalVar) |
| 952 | ->setInitializer(unwrap<Constant>(ConstantVal)); |
| 953 | } |
| 954 | |
| 955 | int LLVMIsThreadLocal(LLVMValueRef GlobalVar) { |
| 956 | return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal(); |
| 957 | } |
| 958 | |
| 959 | void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) { |
| 960 | unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0); |
| 961 | } |
| 962 | |
Gordon Henriksen | c84c16b | 2007-10-07 17:31:42 +0000 | [diff] [blame] | 963 | int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) { |
Gordon Henriksen | c84c16b | 2007-10-07 17:31:42 +0000 | [diff] [blame] | 964 | return unwrap<GlobalVariable>(GlobalVar)->isConstant(); |
| 965 | } |
| 966 | |
| 967 | void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) { |
| 968 | unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0); |
| 969 | } |
| 970 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 971 | /*--.. Operations on aliases ......................................--*/ |
| 972 | |
| 973 | LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, |
| 974 | const char *Name) { |
| 975 | return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name, |
| 976 | unwrap<Constant>(Aliasee), unwrap (M))); |
| 977 | } |
| 978 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 979 | /*--.. Operations on functions .............................................--*/ |
| 980 | |
| 981 | LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, |
| 982 | LLVMTypeRef FunctionTy) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 983 | return wrap(Function::Create(unwrap<FunctionType>(FunctionTy), |
| 984 | GlobalValue::ExternalLinkage, Name, unwrap(M))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 987 | LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) { |
| 988 | return wrap(unwrap(M)->getFunction(Name)); |
| 989 | } |
| 990 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 991 | LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) { |
| 992 | Module *Mod = unwrap(M); |
| 993 | Module::iterator I = Mod->begin(); |
| 994 | if (I == Mod->end()) |
| 995 | return 0; |
| 996 | return wrap(I); |
| 997 | } |
| 998 | |
| 999 | LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) { |
| 1000 | Module *Mod = unwrap(M); |
| 1001 | Module::iterator I = Mod->end(); |
| 1002 | if (I == Mod->begin()) |
| 1003 | return 0; |
| 1004 | return wrap(--I); |
| 1005 | } |
| 1006 | |
| 1007 | LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) { |
| 1008 | Function *Func = unwrap<Function>(Fn); |
| 1009 | Module::iterator I = Func; |
| 1010 | if (++I == Func->getParent()->end()) |
| 1011 | return 0; |
| 1012 | return wrap(I); |
| 1013 | } |
| 1014 | |
| 1015 | LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) { |
| 1016 | Function *Func = unwrap<Function>(Fn); |
| 1017 | Module::iterator I = Func; |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1018 | if (I == Func->getParent()->begin()) |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1019 | return 0; |
| 1020 | return wrap(--I); |
| 1021 | } |
| 1022 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1023 | void LLVMDeleteFunction(LLVMValueRef Fn) { |
| 1024 | unwrap<Function>(Fn)->eraseFromParent(); |
| 1025 | } |
| 1026 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1027 | unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) { |
| 1028 | if (Function *F = dyn_cast<Function>(unwrap(Fn))) |
| 1029 | return F->getIntrinsicID(); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) { |
| 1034 | return unwrap<Function>(Fn)->getCallingConv(); |
| 1035 | } |
| 1036 | |
| 1037 | void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) { |
| 1038 | return unwrap<Function>(Fn)->setCallingConv(CC); |
| 1039 | } |
| 1040 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1041 | const char *LLVMGetGC(LLVMValueRef Fn) { |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1042 | Function *F = unwrap<Function>(Fn); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1043 | return F->hasGC()? F->getGC() : 0; |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1046 | void LLVMSetGC(LLVMValueRef Fn, const char *GC) { |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1047 | Function *F = unwrap<Function>(Fn); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1048 | if (GC) |
| 1049 | F->setGC(GC); |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1050 | else |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1051 | F->clearGC(); |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Duncan Sands | e149e99 | 2009-05-06 12:21:17 +0000 | [diff] [blame] | 1054 | void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { |
| 1055 | Function *Func = unwrap<Function>(Fn); |
| 1056 | const AttrListPtr PAL = Func->getAttributes(); |
| 1057 | const AttrListPtr PALnew = PAL.addAttr(0, PA); |
| 1058 | Func->setAttributes(PALnew); |
| 1059 | } |
| 1060 | |
| 1061 | void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { |
| 1062 | Function *Func = unwrap<Function>(Fn); |
| 1063 | const AttrListPtr PAL = Func->getAttributes(); |
| 1064 | const AttrListPtr PALnew = PAL.removeAttr(0, PA); |
| 1065 | Func->setAttributes(PALnew); |
| 1066 | } |
| 1067 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1068 | /*--.. Operations on parameters ............................................--*/ |
| 1069 | |
| 1070 | unsigned LLVMCountParams(LLVMValueRef FnRef) { |
| 1071 | // This function is strictly redundant to |
| 1072 | // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef))) |
Dan Gohman | 4d515d0 | 2008-06-21 22:06:54 +0000 | [diff] [blame] | 1073 | return unwrap<Function>(FnRef)->arg_size(); |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) { |
| 1077 | Function *Fn = unwrap<Function>(FnRef); |
| 1078 | for (Function::arg_iterator I = Fn->arg_begin(), |
| 1079 | E = Fn->arg_end(); I != E; I++) |
| 1080 | *ParamRefs++ = wrap(I); |
| 1081 | } |
| 1082 | |
| 1083 | LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) { |
| 1084 | Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin(); |
| 1085 | while (index --> 0) |
| 1086 | AI++; |
| 1087 | return wrap(AI); |
| 1088 | } |
| 1089 | |
| 1090 | LLVMValueRef LLVMGetParamParent(LLVMValueRef V) { |
| 1091 | return wrap(unwrap<Argument>(V)->getParent()); |
| 1092 | } |
| 1093 | |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1094 | LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) { |
| 1095 | Function *Func = unwrap<Function>(Fn); |
| 1096 | Function::arg_iterator I = Func->arg_begin(); |
| 1097 | if (I == Func->arg_end()) |
| 1098 | return 0; |
| 1099 | return wrap(I); |
| 1100 | } |
| 1101 | |
| 1102 | LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) { |
| 1103 | Function *Func = unwrap<Function>(Fn); |
| 1104 | Function::arg_iterator I = Func->arg_end(); |
| 1105 | if (I == Func->arg_begin()) |
| 1106 | return 0; |
| 1107 | return wrap(--I); |
| 1108 | } |
| 1109 | |
| 1110 | LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) { |
| 1111 | Argument *A = unwrap<Argument>(Arg); |
| 1112 | Function::arg_iterator I = A; |
| 1113 | if (++I == A->getParent()->arg_end()) |
| 1114 | return 0; |
| 1115 | return wrap(I); |
| 1116 | } |
| 1117 | |
| 1118 | LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) { |
| 1119 | Argument *A = unwrap<Argument>(Arg); |
| 1120 | Function::arg_iterator I = A; |
| 1121 | if (I == A->getParent()->arg_begin()) |
| 1122 | return 0; |
| 1123 | return wrap(--I); |
| 1124 | } |
| 1125 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1126 | void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1127 | unwrap<Argument>(Arg)->addAttr(PA); |
| 1128 | } |
| 1129 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1130 | void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1131 | unwrap<Argument>(Arg)->removeAttr(PA); |
| 1132 | } |
| 1133 | |
| 1134 | void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) { |
| 1135 | unwrap<Argument>(Arg)->addAttr( |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1136 | Attribute::constructAlignmentFromInt(align)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1139 | /*--.. Operations on basic blocks ..........................................--*/ |
| 1140 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1141 | LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) { |
| 1142 | return wrap(static_cast<Value*>(unwrap(BB))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | int LLVMValueIsBasicBlock(LLVMValueRef Val) { |
| 1146 | return isa<BasicBlock>(unwrap(Val)); |
| 1147 | } |
| 1148 | |
| 1149 | LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) { |
| 1150 | return wrap(unwrap<BasicBlock>(Val)); |
| 1151 | } |
| 1152 | |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1153 | LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) { |
| 1154 | return wrap(unwrap(BB)->getParent()); |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1157 | unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) { |
Dan Gohman | 4d515d0 | 2008-06-21 22:06:54 +0000 | [diff] [blame] | 1158 | return unwrap<Function>(FnRef)->size(); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){ |
| 1162 | Function *Fn = unwrap<Function>(FnRef); |
| 1163 | for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++) |
| 1164 | *BasicBlocksRefs++ = wrap(I); |
| 1165 | } |
| 1166 | |
| 1167 | LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) { |
| 1168 | return wrap(&unwrap<Function>(Fn)->getEntryBlock()); |
| 1169 | } |
| 1170 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1171 | LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) { |
| 1172 | Function *Func = unwrap<Function>(Fn); |
| 1173 | Function::iterator I = Func->begin(); |
| 1174 | if (I == Func->end()) |
| 1175 | return 0; |
| 1176 | return wrap(I); |
| 1177 | } |
| 1178 | |
| 1179 | LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) { |
| 1180 | Function *Func = unwrap<Function>(Fn); |
| 1181 | Function::iterator I = Func->end(); |
| 1182 | if (I == Func->begin()) |
| 1183 | return 0; |
| 1184 | return wrap(--I); |
| 1185 | } |
| 1186 | |
| 1187 | LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) { |
| 1188 | BasicBlock *Block = unwrap(BB); |
| 1189 | Function::iterator I = Block; |
| 1190 | if (++I == Block->getParent()->end()) |
| 1191 | return 0; |
| 1192 | return wrap(I); |
| 1193 | } |
| 1194 | |
| 1195 | LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) { |
| 1196 | BasicBlock *Block = unwrap(BB); |
| 1197 | Function::iterator I = Block; |
| 1198 | if (I == Block->getParent()->begin()) |
| 1199 | return 0; |
| 1200 | return wrap(--I); |
| 1201 | } |
| 1202 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 1203 | LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, |
| 1204 | LLVMValueRef FnRef, |
| 1205 | const char *Name) { |
| 1206 | return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 1209 | LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) { |
| 1210 | return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name); |
| 1211 | } |
| 1212 | |
| 1213 | LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, |
| 1214 | LLVMBasicBlockRef BBRef, |
| 1215 | const char *Name) { |
| 1216 | BasicBlock *BB = unwrap(BBRef); |
| 1217 | return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB)); |
| 1218 | } |
| 1219 | |
| 1220 | LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1221 | const char *Name) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 1222 | return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) { |
| 1226 | unwrap(BBRef)->eraseFromParent(); |
| 1227 | } |
| 1228 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1229 | /*--.. Operations on instructions ..........................................--*/ |
| 1230 | |
| 1231 | LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) { |
| 1232 | return wrap(unwrap<Instruction>(Inst)->getParent()); |
| 1233 | } |
| 1234 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1235 | LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) { |
| 1236 | BasicBlock *Block = unwrap(BB); |
| 1237 | BasicBlock::iterator I = Block->begin(); |
| 1238 | if (I == Block->end()) |
| 1239 | return 0; |
| 1240 | return wrap(I); |
| 1241 | } |
| 1242 | |
| 1243 | LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) { |
| 1244 | BasicBlock *Block = unwrap(BB); |
| 1245 | BasicBlock::iterator I = Block->end(); |
| 1246 | if (I == Block->begin()) |
| 1247 | return 0; |
| 1248 | return wrap(--I); |
| 1249 | } |
| 1250 | |
| 1251 | LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) { |
| 1252 | Instruction *Instr = unwrap<Instruction>(Inst); |
| 1253 | BasicBlock::iterator I = Instr; |
| 1254 | if (++I == Instr->getParent()->end()) |
| 1255 | return 0; |
| 1256 | return wrap(I); |
| 1257 | } |
| 1258 | |
| 1259 | LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) { |
| 1260 | Instruction *Instr = unwrap<Instruction>(Inst); |
| 1261 | BasicBlock::iterator I = Instr; |
| 1262 | if (I == Instr->getParent()->begin()) |
| 1263 | return 0; |
| 1264 | return wrap(--I); |
| 1265 | } |
| 1266 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1267 | /*--.. Call and invoke instructions ........................................--*/ |
| 1268 | |
| 1269 | unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { |
| 1270 | Value *V = unwrap(Instr); |
| 1271 | if (CallInst *CI = dyn_cast<CallInst>(V)) |
| 1272 | return CI->getCallingConv(); |
| 1273 | else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) |
| 1274 | return II->getCallingConv(); |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1275 | llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!"); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { |
| 1280 | Value *V = unwrap(Instr); |
| 1281 | if (CallInst *CI = dyn_cast<CallInst>(V)) |
| 1282 | return CI->setCallingConv(CC); |
| 1283 | else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) |
| 1284 | return II->setCallingConv(CC); |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1285 | llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!"); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1288 | void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, |
| 1289 | LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1290 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1291 | Call.setAttributes( |
| 1292 | Call.getAttributes().addAttr(index, PA)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1295 | void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, |
| 1296 | LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1297 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1298 | Call.setAttributes( |
| 1299 | Call.getAttributes().removeAttr(index, PA)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, |
| 1303 | unsigned align) { |
| 1304 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1305 | Call.setAttributes( |
| 1306 | Call.getAttributes().addAttr(index, |
| 1307 | Attribute::constructAlignmentFromInt(align))); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Gordon Henriksen | 07cabf6 | 2008-08-30 16:34:54 +0000 | [diff] [blame] | 1310 | /*--.. Operations on call instructions (only) ..............................--*/ |
| 1311 | |
| 1312 | int LLVMIsTailCall(LLVMValueRef Call) { |
| 1313 | return unwrap<CallInst>(Call)->isTailCall(); |
| 1314 | } |
| 1315 | |
| 1316 | void LLVMSetTailCall(LLVMValueRef Call, int isTailCall) { |
| 1317 | unwrap<CallInst>(Call)->setTailCall(isTailCall); |
| 1318 | } |
| 1319 | |
Gordon Henriksen | 2618a6c | 2007-10-08 18:14:39 +0000 | [diff] [blame] | 1320 | /*--.. Operations on phi nodes .............................................--*/ |
| 1321 | |
| 1322 | void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, |
| 1323 | LLVMBasicBlockRef *IncomingBlocks, unsigned Count) { |
| 1324 | PHINode *PhiVal = unwrap<PHINode>(PhiNode); |
| 1325 | for (unsigned I = 0; I != Count; ++I) |
| 1326 | PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I])); |
| 1327 | } |
| 1328 | |
| 1329 | unsigned LLVMCountIncoming(LLVMValueRef PhiNode) { |
| 1330 | return unwrap<PHINode>(PhiNode)->getNumIncomingValues(); |
| 1331 | } |
| 1332 | |
| 1333 | LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) { |
| 1334 | return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index)); |
| 1335 | } |
| 1336 | |
| 1337 | LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) { |
| 1338 | return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index)); |
| 1339 | } |
| 1340 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1341 | |
| 1342 | /*===-- Instruction builders ----------------------------------------------===*/ |
| 1343 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 1344 | LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) { |
| 1345 | return wrap(new IRBuilder<>(*unwrap(C))); |
| 1346 | } |
| 1347 | |
Gordon Henriksen | 16c1f44 | 2008-05-04 12:55:34 +0000 | [diff] [blame] | 1348 | LLVMBuilderRef LLVMCreateBuilder(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame^] | 1349 | return LLVMCreateBuilderInContext(LLVMGetGlobalContext()); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1352 | void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, |
| 1353 | LLVMValueRef Instr) { |
| 1354 | BasicBlock *BB = unwrap(Block); |
| 1355 | Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end(); |
| 1356 | unwrap(Builder)->SetInsertPoint(BB, I); |
| 1357 | } |
| 1358 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1359 | void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) { |
| 1360 | Instruction *I = unwrap<Instruction>(Instr); |
| 1361 | unwrap(Builder)->SetInsertPoint(I->getParent(), I); |
| 1362 | } |
| 1363 | |
| 1364 | void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) { |
| 1365 | BasicBlock *BB = unwrap(Block); |
| 1366 | unwrap(Builder)->SetInsertPoint(BB); |
| 1367 | } |
| 1368 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1369 | LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) { |
| 1370 | return wrap(unwrap(Builder)->GetInsertBlock()); |
| 1371 | } |
| 1372 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 1373 | void LLVMClearInsertionPosition(LLVMBuilderRef Builder) { |
| 1374 | unwrap(Builder)->ClearInsertionPoint (); |
| 1375 | } |
| 1376 | |
| 1377 | void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) { |
| 1378 | unwrap(Builder)->Insert(unwrap<Instruction>(Instr)); |
| 1379 | } |
| 1380 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1381 | void LLVMDisposeBuilder(LLVMBuilderRef Builder) { |
| 1382 | delete unwrap(Builder); |
| 1383 | } |
| 1384 | |
| 1385 | /*--.. Instruction builders ................................................--*/ |
| 1386 | |
| 1387 | LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) { |
| 1388 | return wrap(unwrap(B)->CreateRetVoid()); |
| 1389 | } |
| 1390 | |
| 1391 | LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) { |
| 1392 | return wrap(unwrap(B)->CreateRet(unwrap(V))); |
| 1393 | } |
| 1394 | |
| 1395 | LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) { |
| 1396 | return wrap(unwrap(B)->CreateBr(unwrap(Dest))); |
| 1397 | } |
| 1398 | |
| 1399 | LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, |
| 1400 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) { |
| 1401 | return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else))); |
| 1402 | } |
| 1403 | |
| 1404 | LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V, |
| 1405 | LLVMBasicBlockRef Else, unsigned NumCases) { |
| 1406 | return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases)); |
| 1407 | } |
| 1408 | |
| 1409 | LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, |
| 1410 | LLVMValueRef *Args, unsigned NumArgs, |
| 1411 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, |
| 1412 | const char *Name) { |
| 1413 | return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch), |
| 1414 | unwrap(Args), unwrap(Args) + NumArgs, |
| 1415 | Name)); |
| 1416 | } |
| 1417 | |
| 1418 | LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) { |
| 1419 | return wrap(unwrap(B)->CreateUnwind()); |
| 1420 | } |
| 1421 | |
| 1422 | LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) { |
| 1423 | return wrap(unwrap(B)->CreateUnreachable()); |
| 1424 | } |
| 1425 | |
Gordon Henriksen | ab477cc | 2008-01-01 05:50:53 +0000 | [diff] [blame] | 1426 | void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, |
| 1427 | LLVMBasicBlockRef Dest) { |
| 1428 | unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest)); |
| 1429 | } |
| 1430 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1431 | /*--.. Arithmetic ..........................................................--*/ |
| 1432 | |
| 1433 | LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1434 | const char *Name) { |
| 1435 | return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name)); |
| 1436 | } |
| 1437 | |
| 1438 | LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1439 | const char *Name) { |
| 1440 | return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name)); |
| 1441 | } |
| 1442 | |
| 1443 | LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1444 | const char *Name) { |
| 1445 | return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name)); |
| 1446 | } |
| 1447 | |
| 1448 | LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1449 | const char *Name) { |
| 1450 | return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1451 | } |
| 1452 | |
| 1453 | LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1454 | const char *Name) { |
| 1455 | return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1456 | } |
| 1457 | |
| 1458 | LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1459 | const char *Name) { |
| 1460 | return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1461 | } |
| 1462 | |
| 1463 | LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1464 | const char *Name) { |
| 1465 | return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name)); |
| 1466 | } |
| 1467 | |
| 1468 | LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1469 | const char *Name) { |
| 1470 | return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name)); |
| 1471 | } |
| 1472 | |
| 1473 | LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1474 | const char *Name) { |
| 1475 | return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name)); |
| 1476 | } |
| 1477 | |
| 1478 | LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1479 | const char *Name) { |
| 1480 | return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name)); |
| 1481 | } |
| 1482 | |
| 1483 | LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1484 | const char *Name) { |
| 1485 | return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name)); |
| 1486 | } |
| 1487 | |
| 1488 | LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1489 | const char *Name) { |
| 1490 | return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name)); |
| 1491 | } |
| 1492 | |
| 1493 | LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1494 | const char *Name) { |
| 1495 | return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name)); |
| 1496 | } |
| 1497 | |
| 1498 | LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1499 | const char *Name) { |
| 1500 | return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name)); |
| 1501 | } |
| 1502 | |
| 1503 | LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1504 | const char *Name) { |
| 1505 | return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name)); |
| 1506 | } |
| 1507 | |
| 1508 | LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { |
| 1509 | return wrap(unwrap(B)->CreateNeg(unwrap(V), Name)); |
| 1510 | } |
| 1511 | |
| 1512 | LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { |
| 1513 | return wrap(unwrap(B)->CreateNot(unwrap(V), Name)); |
| 1514 | } |
| 1515 | |
| 1516 | /*--.. Memory ..............................................................--*/ |
| 1517 | |
| 1518 | LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1519 | const char *Name) { |
| 1520 | return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name)); |
| 1521 | } |
| 1522 | |
| 1523 | LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1524 | LLVMValueRef Val, const char *Name) { |
| 1525 | return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name)); |
| 1526 | } |
| 1527 | |
| 1528 | LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1529 | const char *Name) { |
| 1530 | return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name)); |
| 1531 | } |
| 1532 | |
| 1533 | LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1534 | LLVMValueRef Val, const char *Name) { |
| 1535 | return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name)); |
| 1536 | } |
| 1537 | |
| 1538 | LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) { |
| 1539 | return wrap(unwrap(B)->CreateFree(unwrap(PointerVal))); |
| 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal, |
| 1544 | const char *Name) { |
| 1545 | return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name)); |
| 1546 | } |
| 1547 | |
| 1548 | LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, |
| 1549 | LLVMValueRef PointerVal) { |
| 1550 | return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal))); |
| 1551 | } |
| 1552 | |
| 1553 | LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 1554 | LLVMValueRef *Indices, unsigned NumIndices, |
| 1555 | const char *Name) { |
| 1556 | return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), unwrap(Indices), |
| 1557 | unwrap(Indices) + NumIndices, Name)); |
| 1558 | } |
| 1559 | |
| 1560 | /*--.. Casts ...............................................................--*/ |
| 1561 | |
| 1562 | LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val, |
| 1563 | LLVMTypeRef DestTy, const char *Name) { |
| 1564 | return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name)); |
| 1565 | } |
| 1566 | |
| 1567 | LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1568 | LLVMTypeRef DestTy, const char *Name) { |
| 1569 | return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1570 | } |
| 1571 | |
| 1572 | LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1573 | LLVMTypeRef DestTy, const char *Name) { |
| 1574 | return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1575 | } |
| 1576 | |
| 1577 | LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, |
| 1578 | LLVMTypeRef DestTy, const char *Name) { |
| 1579 | return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name)); |
| 1580 | } |
| 1581 | |
| 1582 | LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val, |
| 1583 | LLVMTypeRef DestTy, const char *Name) { |
| 1584 | return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name)); |
| 1585 | } |
| 1586 | |
| 1587 | LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val, |
| 1588 | LLVMTypeRef DestTy, const char *Name) { |
| 1589 | return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name)); |
| 1590 | } |
| 1591 | |
| 1592 | LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val, |
| 1593 | LLVMTypeRef DestTy, const char *Name) { |
| 1594 | return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name)); |
| 1595 | } |
| 1596 | |
| 1597 | LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val, |
| 1598 | LLVMTypeRef DestTy, const char *Name) { |
| 1599 | return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name)); |
| 1600 | } |
| 1601 | |
| 1602 | LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1603 | LLVMTypeRef DestTy, const char *Name) { |
| 1604 | return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1605 | } |
| 1606 | |
| 1607 | LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1608 | LLVMTypeRef DestTy, const char *Name) { |
| 1609 | return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name)); |
| 1610 | } |
| 1611 | |
| 1612 | LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val, |
| 1613 | LLVMTypeRef DestTy, const char *Name) { |
| 1614 | return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name)); |
| 1615 | } |
| 1616 | |
| 1617 | LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1618 | LLVMTypeRef DestTy, const char *Name) { |
| 1619 | return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name)); |
| 1620 | } |
| 1621 | |
| 1622 | /*--.. Comparisons .........................................................--*/ |
| 1623 | |
| 1624 | LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, |
| 1625 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 1626 | const char *Name) { |
| 1627 | return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op), |
| 1628 | unwrap(LHS), unwrap(RHS), Name)); |
| 1629 | } |
| 1630 | |
| 1631 | LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op, |
| 1632 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 1633 | const char *Name) { |
| 1634 | return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op), |
| 1635 | unwrap(LHS), unwrap(RHS), Name)); |
| 1636 | } |
| 1637 | |
| 1638 | /*--.. Miscellaneous instructions ..........................................--*/ |
| 1639 | |
| 1640 | LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) { |
| 1641 | return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name)); |
| 1642 | } |
| 1643 | |
| 1644 | LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, |
| 1645 | LLVMValueRef *Args, unsigned NumArgs, |
| 1646 | const char *Name) { |
| 1647 | return wrap(unwrap(B)->CreateCall(unwrap(Fn), unwrap(Args), |
| 1648 | unwrap(Args) + NumArgs, Name)); |
| 1649 | } |
| 1650 | |
| 1651 | LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If, |
| 1652 | LLVMValueRef Then, LLVMValueRef Else, |
| 1653 | const char *Name) { |
| 1654 | return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else), |
| 1655 | Name)); |
| 1656 | } |
| 1657 | |
| 1658 | LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List, |
| 1659 | LLVMTypeRef Ty, const char *Name) { |
| 1660 | return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name)); |
| 1661 | } |
| 1662 | |
| 1663 | LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal, |
| 1664 | LLVMValueRef Index, const char *Name) { |
| 1665 | return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index), |
| 1666 | Name)); |
| 1667 | } |
| 1668 | |
| 1669 | LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal, |
| 1670 | LLVMValueRef EltVal, LLVMValueRef Index, |
| 1671 | const char *Name) { |
| 1672 | return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal), |
| 1673 | unwrap(Index), Name)); |
| 1674 | } |
| 1675 | |
| 1676 | LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1, |
| 1677 | LLVMValueRef V2, LLVMValueRef Mask, |
| 1678 | const char *Name) { |
| 1679 | return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2), |
| 1680 | unwrap(Mask), Name)); |
| 1681 | } |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 1682 | |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 1683 | LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal, |
| 1684 | unsigned Index, const char *Name) { |
| 1685 | return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name)); |
| 1686 | } |
| 1687 | |
| 1688 | LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal, |
| 1689 | LLVMValueRef EltVal, unsigned Index, |
| 1690 | const char *Name) { |
| 1691 | return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal), |
| 1692 | Index, Name)); |
| 1693 | } |
| 1694 | |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 1695 | |
| 1696 | /*===-- Module providers --------------------------------------------------===*/ |
| 1697 | |
| 1698 | LLVMModuleProviderRef |
| 1699 | LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) { |
| 1700 | return wrap(new ExistingModuleProvider(unwrap(M))); |
| 1701 | } |
| 1702 | |
| 1703 | void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) { |
| 1704 | delete unwrap(MP); |
| 1705 | } |
| 1706 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 1707 | |
| 1708 | /*===-- Memory buffers ----------------------------------------------------===*/ |
| 1709 | |
| 1710 | int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, |
| 1711 | LLVMMemoryBufferRef *OutMemBuf, |
| 1712 | char **OutMessage) { |
| 1713 | std::string Error; |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 1714 | if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) { |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 1715 | *OutMemBuf = wrap(MB); |
| 1716 | return 0; |
| 1717 | } |
| 1718 | |
| 1719 | *OutMessage = strdup(Error.c_str()); |
| 1720 | return 1; |
| 1721 | } |
| 1722 | |
| 1723 | int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, |
| 1724 | char **OutMessage) { |
| 1725 | if (MemoryBuffer *MB = MemoryBuffer::getSTDIN()) { |
| 1726 | *OutMemBuf = wrap(MB); |
| 1727 | return 0; |
| 1728 | } |
| 1729 | |
| 1730 | *OutMessage = strdup("stdin is empty."); |
| 1731 | return 1; |
| 1732 | } |
| 1733 | |
| 1734 | void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) { |
| 1735 | delete unwrap(MemBuf); |
| 1736 | } |