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 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 392 | void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) { |
| 393 | unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal)); |
| 394 | } |
Gordon Henriksen | 2a9c671 | 2008-12-19 18:39:45 +0000 | [diff] [blame] | 395 | |
| 396 | /*--.. Conversion functions ................................................--*/ |
| 397 | |
| 398 | #define LLVM_DEFINE_VALUE_CAST(name) \ |
| 399 | LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \ |
| 400 | return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \ |
| 401 | } |
| 402 | |
| 403 | LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) |
| 404 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 405 | /*--.. Operations on Uses ..................................................--*/ |
| 406 | LLVMUseIteratorRef LLVMGetFirstUse(LLVMValueRef Val) { |
| 407 | Value *V = unwrap(Val); |
| 408 | Value::use_iterator I = V->use_begin(); |
| 409 | if (I == V->use_end()) |
| 410 | return 0; |
| 411 | return wrap(&(I.getUse())); |
| 412 | } |
| 413 | |
| 414 | LLVMUseIteratorRef LLVMGetNextUse(LLVMUseIteratorRef UR) { |
| 415 | return wrap(unwrap(UR)->getNext()); |
| 416 | } |
| 417 | |
| 418 | LLVMValueRef LLVMGetUser(LLVMUseIteratorRef UR) { |
| 419 | return wrap(unwrap(UR)->getUser()); |
| 420 | } |
| 421 | |
| 422 | LLVMValueRef LLVMGetUsedValue(LLVMUseIteratorRef UR) { |
| 423 | return wrap(unwrap(UR)->get()); |
| 424 | } |
| 425 | |
| 426 | /*--.. Operations on Users .................................................--*/ |
| 427 | LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) { |
| 428 | return wrap(unwrap<User>(Val)->getOperand(Index)); |
| 429 | } |
Gordon Henriksen | 2a9c671 | 2008-12-19 18:39:45 +0000 | [diff] [blame] | 430 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 431 | /*--.. Operations on constants of any type .................................--*/ |
| 432 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 433 | LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) { |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 434 | return wrap(Constant::getNullValue(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 437 | LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) { |
Owen Anderson | a7235ea | 2009-07-31 20:28:14 +0000 | [diff] [blame] | 438 | return wrap(Constant::getAllOnesValue(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) { |
Owen Anderson | 9e9a0d5 | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 442 | return wrap(UndefValue::get(unwrap(Ty))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 445 | int LLVMIsConstant(LLVMValueRef Ty) { |
| 446 | return isa<Constant>(unwrap(Ty)); |
| 447 | } |
| 448 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 449 | int LLVMIsNull(LLVMValueRef Val) { |
| 450 | if (Constant *C = dyn_cast<Constant>(unwrap(Val))) |
| 451 | return C->isNullValue(); |
| 452 | return false; |
| 453 | } |
| 454 | |
Gordon Henriksen | 344be5f | 2007-09-18 18:07:51 +0000 | [diff] [blame] | 455 | int LLVMIsUndef(LLVMValueRef Val) { |
| 456 | return isa<UndefValue>(unwrap(Val)); |
| 457 | } |
| 458 | |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 459 | LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) { |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 460 | return |
Owen Anderson | 9e9a0d5 | 2009-07-30 23:03:37 +0000 | [diff] [blame] | 461 | wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty))); |
Chris Lattner | e4840bc | 2009-07-06 17:29:59 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 464 | /*--.. Operations on scalar constants ......................................--*/ |
| 465 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 466 | LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, |
| 467 | int SignExtend) { |
Owen Anderson | eed707b | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 468 | return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Erick Tryzelaar | e0a1bf6 | 2009-08-16 23:36:46 +0000 | [diff] [blame] | 471 | LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[], |
| 472 | uint8_t Radix) { |
| 473 | return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str), |
| 474 | Radix)); |
| 475 | } |
| 476 | |
| 477 | LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[], |
| 478 | unsigned SLen, uint8_t Radix) { |
| 479 | return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen), |
| 480 | Radix)); |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 483 | LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) { |
Erick Tryzelaar | e0a1bf6 | 2009-08-16 23:36:46 +0000 | [diff] [blame] | 484 | return wrap(ConstantFP::get(unwrap(RealTy), N)); |
Gordon Henriksen | e62a8a3 | 2008-02-02 01:07:50 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) { |
Erick Tryzelaar | e0a1bf6 | 2009-08-16 23:36:46 +0000 | [diff] [blame] | 488 | return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text))); |
| 489 | } |
| 490 | |
| 491 | LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[], |
| 492 | unsigned SLen) { |
| 493 | return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen))); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 496 | unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) { |
| 497 | return unwrap<ConstantInt>(ConstantVal)->getZExtValue(); |
| 498 | } |
| 499 | |
| 500 | long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) { |
| 501 | return unwrap<ConstantInt>(ConstantVal)->getSExtValue(); |
| 502 | } |
| 503 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 504 | /*--.. Operations on composite constants ...................................--*/ |
| 505 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 506 | LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str, |
| 507 | unsigned Length, int DontNullTerminate) { |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 508 | /* Inverted the sense of AddNull because ', 0)' is a |
| 509 | better mnemonic for null termination than ', 1)'. */ |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 510 | return wrap(ConstantArray::get(*unwrap(C), std::string(Str, Length), |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 511 | DontNullTerminate == 0)); |
| 512 | } |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 513 | LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, |
| 514 | LLVMValueRef *ConstantVals, |
| 515 | unsigned Count, int Packed) { |
| 516 | return wrap(ConstantStruct::get(*unwrap(C), |
| 517 | unwrap<Constant>(ConstantVals, Count), |
| 518 | Count, Packed != 0)); |
| 519 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 520 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 521 | LLVMValueRef LLVMConstString(const char *Str, unsigned Length, |
| 522 | int DontNullTerminate) { |
| 523 | return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length, |
| 524 | DontNullTerminate); |
| 525 | } |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 526 | LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy, |
| 527 | LLVMValueRef *ConstantVals, unsigned Length) { |
Owen Anderson | debcb01 | 2009-07-29 22:17:13 +0000 | [diff] [blame] | 528 | return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 529 | unwrap<Constant>(ConstantVals, Length), |
| 530 | Length)); |
| 531 | } |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 532 | LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count, |
| 533 | int Packed) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 534 | return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count, |
| 535 | Packed); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Gordon Henriksen | e3b989d | 2007-10-06 15:11:06 +0000 | [diff] [blame] | 538 | LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) { |
Owen Anderson | af7ec97 | 2009-07-28 21:19:26 +0000 | [diff] [blame] | 539 | return wrap(ConstantVector::get( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 540 | unwrap<Constant>(ScalarConstantVals, Size), Size)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 543 | /*--.. Constant expressions ................................................--*/ |
| 544 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 545 | LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) { |
| 546 | return (LLVMOpcode)unwrap<ConstantExpr>(ConstantVal)->getOpcode(); |
| 547 | } |
| 548 | |
Duncan Sands | ef854af | 2009-05-21 15:52:21 +0000 | [diff] [blame] | 549 | LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 550 | return wrap(ConstantExpr::getAlignOf(unwrap(Ty))); |
Duncan Sands | ef854af | 2009-05-21 15:52:21 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 553 | LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 554 | return wrap(ConstantExpr::getSizeOf(unwrap(Ty))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 558 | return wrap(ConstantExpr::getNeg( |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 559 | unwrap<Constant>(ConstantVal))); |
| 560 | } |
| 561 | |
| 562 | LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) { |
| 563 | return wrap(ConstantExpr::getFNeg( |
| 564 | unwrap<Constant>(ConstantVal))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 568 | return wrap(ConstantExpr::getNot( |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 569 | unwrap<Constant>(ConstantVal))); |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 573 | return wrap(ConstantExpr::getAdd( |
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 | |
Dan Gohman | 6e7ad95 | 2009-09-03 23:34:49 +0000 | [diff] [blame] | 578 | LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, |
| 579 | LLVMValueRef RHSConstant) { |
| 580 | return wrap(ConstantExpr::getNSWAdd( |
| 581 | unwrap<Constant>(LHSConstant), |
| 582 | unwrap<Constant>(RHSConstant))); |
| 583 | } |
| 584 | |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 585 | LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
| 586 | return wrap(ConstantExpr::getFAdd( |
| 587 | unwrap<Constant>(LHSConstant), |
| 588 | unwrap<Constant>(RHSConstant))); |
| 589 | } |
| 590 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 591 | LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 592 | return wrap(ConstantExpr::getSub( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 593 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 594 | unwrap<Constant>(RHSConstant))); |
| 595 | } |
| 596 | |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 597 | LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
| 598 | return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant), |
| 599 | unwrap<Constant>(RHSConstant))); |
| 600 | } |
| 601 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 602 | LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 603 | return wrap(ConstantExpr::getMul( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 604 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 605 | unwrap<Constant>(RHSConstant))); |
| 606 | } |
| 607 | |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 608 | LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
| 609 | return wrap(ConstantExpr::getFMul( |
| 610 | unwrap<Constant>(LHSConstant), |
| 611 | unwrap<Constant>(RHSConstant))); |
| 612 | } |
| 613 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 614 | LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 615 | return wrap(ConstantExpr::getUDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 616 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 617 | unwrap<Constant>(RHSConstant))); |
| 618 | } |
| 619 | |
| 620 | LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 621 | return wrap(ConstantExpr::getSDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 622 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 623 | unwrap<Constant>(RHSConstant))); |
| 624 | } |
| 625 | |
Dan Gohman | 6e7ad95 | 2009-09-03 23:34:49 +0000 | [diff] [blame] | 626 | LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, |
| 627 | LLVMValueRef RHSConstant) { |
| 628 | return wrap(ConstantExpr::getExactSDiv( |
| 629 | unwrap<Constant>(LHSConstant), |
| 630 | unwrap<Constant>(RHSConstant))); |
| 631 | } |
| 632 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 633 | LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 634 | return wrap(ConstantExpr::getFDiv( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 635 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 636 | unwrap<Constant>(RHSConstant))); |
| 637 | } |
| 638 | |
| 639 | LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 640 | return wrap(ConstantExpr::getURem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 641 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 642 | unwrap<Constant>(RHSConstant))); |
| 643 | } |
| 644 | |
| 645 | LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 646 | return wrap(ConstantExpr::getSRem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 647 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 648 | unwrap<Constant>(RHSConstant))); |
| 649 | } |
| 650 | |
| 651 | LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 652 | return wrap(ConstantExpr::getFRem( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 653 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 654 | unwrap<Constant>(RHSConstant))); |
| 655 | } |
| 656 | |
| 657 | LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 658 | return wrap(ConstantExpr::getAnd( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 659 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 660 | unwrap<Constant>(RHSConstant))); |
| 661 | } |
| 662 | |
| 663 | LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 664 | return wrap(ConstantExpr::getOr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 665 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 666 | unwrap<Constant>(RHSConstant))); |
| 667 | } |
| 668 | |
| 669 | LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 670 | return wrap(ConstantExpr::getXor( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 671 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 672 | unwrap<Constant>(RHSConstant))); |
| 673 | } |
| 674 | |
| 675 | LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, |
| 676 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 677 | return wrap(ConstantExpr::getICmp(Predicate, |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 678 | unwrap<Constant>(LHSConstant), |
| 679 | unwrap<Constant>(RHSConstant))); |
| 680 | } |
| 681 | |
| 682 | LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, |
| 683 | LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 684 | return wrap(ConstantExpr::getFCmp(Predicate, |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 685 | unwrap<Constant>(LHSConstant), |
| 686 | unwrap<Constant>(RHSConstant))); |
| 687 | } |
| 688 | |
| 689 | LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 690 | return wrap(ConstantExpr::getShl( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 691 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 692 | unwrap<Constant>(RHSConstant))); |
| 693 | } |
| 694 | |
| 695 | LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 696 | return wrap(ConstantExpr::getLShr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 697 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 698 | unwrap<Constant>(RHSConstant))); |
| 699 | } |
| 700 | |
| 701 | LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 702 | return wrap(ConstantExpr::getAShr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 703 | unwrap<Constant>(LHSConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 704 | unwrap<Constant>(RHSConstant))); |
| 705 | } |
| 706 | |
| 707 | LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal, |
| 708 | LLVMValueRef *ConstantIndices, unsigned NumIndices) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 709 | return wrap(ConstantExpr::getGetElementPtr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 710 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 711 | unwrap<Constant>(ConstantIndices, |
| 712 | NumIndices), |
| 713 | NumIndices)); |
| 714 | } |
| 715 | |
Dan Gohman | 6e7ad95 | 2009-09-03 23:34:49 +0000 | [diff] [blame] | 716 | LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal, |
| 717 | LLVMValueRef *ConstantIndices, |
| 718 | unsigned NumIndices) { |
| 719 | Constant* Val = unwrap<Constant>(ConstantVal); |
| 720 | Constant** Idxs = unwrap<Constant>(ConstantIndices, NumIndices); |
| 721 | return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, Idxs, NumIndices)); |
| 722 | } |
| 723 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 724 | LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 725 | return wrap(ConstantExpr::getTrunc( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 726 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 727 | unwrap(ToType))); |
| 728 | } |
| 729 | |
| 730 | LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 731 | return wrap(ConstantExpr::getSExt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 732 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 733 | unwrap(ToType))); |
| 734 | } |
| 735 | |
| 736 | LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 737 | return wrap(ConstantExpr::getZExt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 738 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 739 | unwrap(ToType))); |
| 740 | } |
| 741 | |
| 742 | LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 743 | return wrap(ConstantExpr::getFPTrunc( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 744 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 745 | unwrap(ToType))); |
| 746 | } |
| 747 | |
| 748 | LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 749 | return wrap(ConstantExpr::getFPExtend( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 750 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 751 | unwrap(ToType))); |
| 752 | } |
| 753 | |
| 754 | LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 755 | return wrap(ConstantExpr::getUIToFP( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 756 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 757 | unwrap(ToType))); |
| 758 | } |
| 759 | |
| 760 | LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 761 | return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 762 | unwrap(ToType))); |
| 763 | } |
| 764 | |
| 765 | LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 766 | return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 767 | unwrap(ToType))); |
| 768 | } |
| 769 | |
| 770 | LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 771 | return wrap(ConstantExpr::getFPToSI( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 772 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 773 | unwrap(ToType))); |
| 774 | } |
| 775 | |
| 776 | LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 777 | return wrap(ConstantExpr::getPtrToInt( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 778 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 779 | unwrap(ToType))); |
| 780 | } |
| 781 | |
| 782 | LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 783 | return wrap(ConstantExpr::getIntToPtr( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 784 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 785 | unwrap(ToType))); |
| 786 | } |
| 787 | |
| 788 | LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 789 | return wrap(ConstantExpr::getBitCast( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 790 | unwrap<Constant>(ConstantVal), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 791 | unwrap(ToType))); |
| 792 | } |
| 793 | |
Erick Tryzelaar | 56b2269 | 2009-08-16 02:20:12 +0000 | [diff] [blame] | 794 | LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal, |
| 795 | LLVMTypeRef ToType) { |
| 796 | return wrap(ConstantExpr::getZExtOrBitCast( |
| 797 | unwrap<Constant>(ConstantVal), |
| 798 | unwrap(ToType))); |
| 799 | } |
| 800 | |
| 801 | LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal, |
| 802 | LLVMTypeRef ToType) { |
| 803 | return wrap(ConstantExpr::getSExtOrBitCast( |
| 804 | unwrap<Constant>(ConstantVal), |
| 805 | unwrap(ToType))); |
| 806 | } |
| 807 | |
| 808 | LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal, |
| 809 | LLVMTypeRef ToType) { |
| 810 | return wrap(ConstantExpr::getTruncOrBitCast( |
| 811 | unwrap<Constant>(ConstantVal), |
| 812 | unwrap(ToType))); |
| 813 | } |
| 814 | |
| 815 | LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, |
| 816 | LLVMTypeRef ToType) { |
| 817 | return wrap(ConstantExpr::getPointerCast( |
| 818 | unwrap<Constant>(ConstantVal), |
| 819 | unwrap(ToType))); |
| 820 | } |
| 821 | |
| 822 | LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType, |
| 823 | unsigned isSigned) { |
| 824 | return wrap(ConstantExpr::getIntegerCast( |
| 825 | unwrap<Constant>(ConstantVal), |
| 826 | unwrap(ToType), |
| 827 | isSigned)); |
| 828 | } |
| 829 | |
| 830 | LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { |
| 831 | return wrap(ConstantExpr::getFPCast( |
| 832 | unwrap<Constant>(ConstantVal), |
| 833 | unwrap(ToType))); |
| 834 | } |
| 835 | |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 836 | LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition, |
| 837 | LLVMValueRef ConstantIfTrue, |
| 838 | LLVMValueRef ConstantIfFalse) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 839 | return wrap(ConstantExpr::getSelect( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 840 | unwrap<Constant>(ConstantCondition), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 841 | unwrap<Constant>(ConstantIfTrue), |
| 842 | unwrap<Constant>(ConstantIfFalse))); |
| 843 | } |
| 844 | |
| 845 | LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, |
| 846 | LLVMValueRef IndexConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 847 | return wrap(ConstantExpr::getExtractElement( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 848 | unwrap<Constant>(VectorConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 849 | unwrap<Constant>(IndexConstant))); |
| 850 | } |
| 851 | |
| 852 | LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant, |
| 853 | LLVMValueRef ElementValueConstant, |
| 854 | LLVMValueRef IndexConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 855 | return wrap(ConstantExpr::getInsertElement( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 856 | unwrap<Constant>(VectorConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 857 | unwrap<Constant>(ElementValueConstant), |
| 858 | unwrap<Constant>(IndexConstant))); |
| 859 | } |
| 860 | |
| 861 | LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, |
| 862 | LLVMValueRef VectorBConstant, |
| 863 | LLVMValueRef MaskConstant) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 864 | return wrap(ConstantExpr::getShuffleVector( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 865 | unwrap<Constant>(VectorAConstant), |
Gordon Henriksen | 4647569 | 2007-10-06 14:29:36 +0000 | [diff] [blame] | 866 | unwrap<Constant>(VectorBConstant), |
| 867 | unwrap<Constant>(MaskConstant))); |
| 868 | } |
| 869 | |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 870 | LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, |
| 871 | unsigned NumIdx) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 872 | return wrap(ConstantExpr::getExtractValue( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 873 | unwrap<Constant>(AggConstant), |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 874 | IdxList, NumIdx)); |
| 875 | } |
| 876 | |
| 877 | LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, |
| 878 | LLVMValueRef ElementValueConstant, |
| 879 | unsigned *IdxList, unsigned NumIdx) { |
Owen Anderson | baf3c40 | 2009-07-29 18:55:55 +0000 | [diff] [blame] | 880 | return wrap(ConstantExpr::getInsertValue( |
Owen Anderson | 62e744b | 2009-07-07 21:33:58 +0000 | [diff] [blame] | 881 | unwrap<Constant>(AggConstant), |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 882 | unwrap<Constant>(ElementValueConstant), |
| 883 | IdxList, NumIdx)); |
| 884 | } |
| 885 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 886 | LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, |
| 887 | const char *Constraints, int HasSideEffects) { |
| 888 | return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString, |
| 889 | Constraints, HasSideEffects)); |
| 890 | } |
| 891 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 892 | /*--.. Operations on global variables, functions, and aliases (globals) ....--*/ |
| 893 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 894 | LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) { |
| 895 | return wrap(unwrap<GlobalValue>(Global)->getParent()); |
| 896 | } |
| 897 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 898 | int LLVMIsDeclaration(LLVMValueRef Global) { |
| 899 | return unwrap<GlobalValue>(Global)->isDeclaration(); |
| 900 | } |
| 901 | |
| 902 | LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) { |
Bill Wendling | 4aebcb4 | 2009-07-20 20:34:46 +0000 | [diff] [blame] | 903 | switch (unwrap<GlobalValue>(Global)->getLinkage()) { |
| 904 | default: |
| 905 | assert(false && "Unhandled Linkage Type."); |
| 906 | case GlobalValue::ExternalLinkage: |
| 907 | return LLVMExternalLinkage; |
| 908 | case GlobalValue::AvailableExternallyLinkage: |
| 909 | return LLVMAvailableExternallyLinkage; |
| 910 | case GlobalValue::LinkOnceAnyLinkage: |
| 911 | return LLVMLinkOnceAnyLinkage; |
| 912 | case GlobalValue::LinkOnceODRLinkage: |
| 913 | return LLVMLinkOnceODRLinkage; |
| 914 | case GlobalValue::WeakAnyLinkage: |
| 915 | return LLVMWeakAnyLinkage; |
| 916 | case GlobalValue::WeakODRLinkage: |
| 917 | return LLVMWeakODRLinkage; |
| 918 | case GlobalValue::AppendingLinkage: |
| 919 | return LLVMAppendingLinkage; |
| 920 | case GlobalValue::InternalLinkage: |
| 921 | return LLVMInternalLinkage; |
| 922 | case GlobalValue::PrivateLinkage: |
| 923 | return LLVMPrivateLinkage; |
| 924 | case GlobalValue::LinkerPrivateLinkage: |
| 925 | return LLVMLinkerPrivateLinkage; |
| 926 | case GlobalValue::DLLImportLinkage: |
| 927 | return LLVMDLLImportLinkage; |
| 928 | case GlobalValue::DLLExportLinkage: |
| 929 | return LLVMDLLExportLinkage; |
| 930 | case GlobalValue::ExternalWeakLinkage: |
| 931 | return LLVMExternalWeakLinkage; |
| 932 | case GlobalValue::GhostLinkage: |
| 933 | return LLVMGhostLinkage; |
| 934 | case GlobalValue::CommonLinkage: |
| 935 | return LLVMCommonLinkage; |
| 936 | } |
| 937 | |
| 938 | // Should never get here. |
| 939 | return static_cast<LLVMLinkage>(0); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) { |
Bill Wendling | 4aebcb4 | 2009-07-20 20:34:46 +0000 | [diff] [blame] | 943 | GlobalValue *GV = unwrap<GlobalValue>(Global); |
| 944 | |
| 945 | switch (Linkage) { |
| 946 | default: |
| 947 | assert(false && "Unhandled Linkage Type."); |
| 948 | case LLVMExternalLinkage: |
| 949 | GV->setLinkage(GlobalValue::ExternalLinkage); |
| 950 | break; |
| 951 | case LLVMAvailableExternallyLinkage: |
| 952 | GV->setLinkage(GlobalValue::AvailableExternallyLinkage); |
| 953 | break; |
| 954 | case LLVMLinkOnceAnyLinkage: |
| 955 | GV->setLinkage(GlobalValue::LinkOnceAnyLinkage); |
| 956 | break; |
| 957 | case LLVMLinkOnceODRLinkage: |
| 958 | GV->setLinkage(GlobalValue::LinkOnceODRLinkage); |
| 959 | break; |
| 960 | case LLVMWeakAnyLinkage: |
| 961 | GV->setLinkage(GlobalValue::WeakAnyLinkage); |
| 962 | break; |
| 963 | case LLVMWeakODRLinkage: |
| 964 | GV->setLinkage(GlobalValue::WeakODRLinkage); |
| 965 | break; |
| 966 | case LLVMAppendingLinkage: |
| 967 | GV->setLinkage(GlobalValue::AppendingLinkage); |
| 968 | break; |
| 969 | case LLVMInternalLinkage: |
| 970 | GV->setLinkage(GlobalValue::InternalLinkage); |
| 971 | break; |
| 972 | case LLVMPrivateLinkage: |
| 973 | GV->setLinkage(GlobalValue::PrivateLinkage); |
| 974 | break; |
| 975 | case LLVMLinkerPrivateLinkage: |
| 976 | GV->setLinkage(GlobalValue::LinkerPrivateLinkage); |
| 977 | break; |
| 978 | case LLVMDLLImportLinkage: |
| 979 | GV->setLinkage(GlobalValue::DLLImportLinkage); |
| 980 | break; |
| 981 | case LLVMDLLExportLinkage: |
| 982 | GV->setLinkage(GlobalValue::DLLExportLinkage); |
| 983 | break; |
| 984 | case LLVMExternalWeakLinkage: |
| 985 | GV->setLinkage(GlobalValue::ExternalWeakLinkage); |
| 986 | break; |
| 987 | case LLVMGhostLinkage: |
| 988 | GV->setLinkage(GlobalValue::GhostLinkage); |
| 989 | break; |
| 990 | case LLVMCommonLinkage: |
| 991 | GV->setLinkage(GlobalValue::CommonLinkage); |
| 992 | break; |
| 993 | } |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | const char *LLVMGetSection(LLVMValueRef Global) { |
| 997 | return unwrap<GlobalValue>(Global)->getSection().c_str(); |
| 998 | } |
| 999 | |
| 1000 | void LLVMSetSection(LLVMValueRef Global, const char *Section) { |
| 1001 | unwrap<GlobalValue>(Global)->setSection(Section); |
| 1002 | } |
| 1003 | |
| 1004 | LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) { |
| 1005 | return static_cast<LLVMVisibility>( |
| 1006 | unwrap<GlobalValue>(Global)->getVisibility()); |
| 1007 | } |
| 1008 | |
| 1009 | void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) { |
| 1010 | unwrap<GlobalValue>(Global) |
| 1011 | ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz)); |
| 1012 | } |
| 1013 | |
| 1014 | unsigned LLVMGetAlignment(LLVMValueRef Global) { |
| 1015 | return unwrap<GlobalValue>(Global)->getAlignment(); |
| 1016 | } |
| 1017 | |
| 1018 | void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) { |
| 1019 | unwrap<GlobalValue>(Global)->setAlignment(Bytes); |
| 1020 | } |
| 1021 | |
| 1022 | /*--.. Operations on global variables ......................................--*/ |
| 1023 | |
| 1024 | LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) { |
Owen Anderson | e9b11b4 | 2009-07-08 19:03:57 +0000 | [diff] [blame] | 1025 | return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false, |
| 1026 | GlobalValue::ExternalLinkage, 0, Name)); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 1029 | LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) { |
| 1030 | return wrap(unwrap(M)->getNamedGlobal(Name)); |
| 1031 | } |
| 1032 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1033 | LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) { |
| 1034 | Module *Mod = unwrap(M); |
| 1035 | Module::global_iterator I = Mod->global_begin(); |
| 1036 | if (I == Mod->global_end()) |
| 1037 | return 0; |
| 1038 | return wrap(I); |
| 1039 | } |
| 1040 | |
| 1041 | LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) { |
| 1042 | Module *Mod = unwrap(M); |
| 1043 | Module::global_iterator I = Mod->global_end(); |
| 1044 | if (I == Mod->global_begin()) |
| 1045 | return 0; |
| 1046 | return wrap(--I); |
| 1047 | } |
| 1048 | |
| 1049 | LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) { |
| 1050 | GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); |
| 1051 | Module::global_iterator I = GV; |
| 1052 | if (++I == GV->getParent()->global_end()) |
| 1053 | return 0; |
| 1054 | return wrap(I); |
| 1055 | } |
| 1056 | |
| 1057 | LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) { |
| 1058 | GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar); |
| 1059 | Module::global_iterator I = GV; |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1060 | if (I == GV->getParent()->global_begin()) |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1061 | return 0; |
| 1062 | return wrap(--I); |
| 1063 | } |
| 1064 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1065 | void LLVMDeleteGlobal(LLVMValueRef GlobalVar) { |
| 1066 | unwrap<GlobalVariable>(GlobalVar)->eraseFromParent(); |
| 1067 | } |
| 1068 | |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1069 | LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) { |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 1070 | GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar); |
| 1071 | if ( !GV->hasInitializer() ) |
| 1072 | return 0; |
| 1073 | return wrap(GV->getInitializer()); |
Gordon Henriksen | 8b94a14 | 2007-09-18 03:18:57 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) { |
| 1077 | unwrap<GlobalVariable>(GlobalVar) |
| 1078 | ->setInitializer(unwrap<Constant>(ConstantVal)); |
| 1079 | } |
| 1080 | |
| 1081 | int LLVMIsThreadLocal(LLVMValueRef GlobalVar) { |
| 1082 | return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal(); |
| 1083 | } |
| 1084 | |
| 1085 | void LLVMSetThreadLocal(LLVMValueRef GlobalVar, int IsThreadLocal) { |
| 1086 | unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0); |
| 1087 | } |
| 1088 | |
Gordon Henriksen | c84c16b | 2007-10-07 17:31:42 +0000 | [diff] [blame] | 1089 | int LLVMIsGlobalConstant(LLVMValueRef GlobalVar) { |
Gordon Henriksen | c84c16b | 2007-10-07 17:31:42 +0000 | [diff] [blame] | 1090 | return unwrap<GlobalVariable>(GlobalVar)->isConstant(); |
| 1091 | } |
| 1092 | |
| 1093 | void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) { |
| 1094 | unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0); |
| 1095 | } |
| 1096 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 1097 | /*--.. Operations on aliases ......................................--*/ |
| 1098 | |
| 1099 | LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee, |
| 1100 | const char *Name) { |
| 1101 | return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name, |
| 1102 | unwrap<Constant>(Aliasee), unwrap (M))); |
| 1103 | } |
| 1104 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1105 | /*--.. Operations on functions .............................................--*/ |
| 1106 | |
| 1107 | LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, |
| 1108 | LLVMTypeRef FunctionTy) { |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 1109 | return wrap(Function::Create(unwrap<FunctionType>(FunctionTy), |
| 1110 | GlobalValue::ExternalLinkage, Name, unwrap(M))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Gordon Henriksen | 6d6203d | 2007-10-08 03:45:09 +0000 | [diff] [blame] | 1113 | LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) { |
| 1114 | return wrap(unwrap(M)->getFunction(Name)); |
| 1115 | } |
| 1116 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1117 | LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) { |
| 1118 | Module *Mod = unwrap(M); |
| 1119 | Module::iterator I = Mod->begin(); |
| 1120 | if (I == Mod->end()) |
| 1121 | return 0; |
| 1122 | return wrap(I); |
| 1123 | } |
| 1124 | |
| 1125 | LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) { |
| 1126 | Module *Mod = unwrap(M); |
| 1127 | Module::iterator I = Mod->end(); |
| 1128 | if (I == Mod->begin()) |
| 1129 | return 0; |
| 1130 | return wrap(--I); |
| 1131 | } |
| 1132 | |
| 1133 | LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) { |
| 1134 | Function *Func = unwrap<Function>(Fn); |
| 1135 | Module::iterator I = Func; |
| 1136 | if (++I == Func->getParent()->end()) |
| 1137 | return 0; |
| 1138 | return wrap(I); |
| 1139 | } |
| 1140 | |
| 1141 | LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) { |
| 1142 | Function *Func = unwrap<Function>(Fn); |
| 1143 | Module::iterator I = Func; |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1144 | if (I == Func->getParent()->begin()) |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1145 | return 0; |
| 1146 | return wrap(--I); |
| 1147 | } |
| 1148 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1149 | void LLVMDeleteFunction(LLVMValueRef Fn) { |
| 1150 | unwrap<Function>(Fn)->eraseFromParent(); |
| 1151 | } |
| 1152 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1153 | unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) { |
| 1154 | if (Function *F = dyn_cast<Function>(unwrap(Fn))) |
| 1155 | return F->getIntrinsicID(); |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) { |
| 1160 | return unwrap<Function>(Fn)->getCallingConv(); |
| 1161 | } |
| 1162 | |
| 1163 | void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) { |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1164 | return unwrap<Function>(Fn)->setCallingConv( |
| 1165 | static_cast<CallingConv::ID>(CC)); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1168 | const char *LLVMGetGC(LLVMValueRef Fn) { |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1169 | Function *F = unwrap<Function>(Fn); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1170 | return F->hasGC()? F->getGC() : 0; |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1173 | void LLVMSetGC(LLVMValueRef Fn, const char *GC) { |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1174 | Function *F = unwrap<Function>(Fn); |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1175 | if (GC) |
| 1176 | F->setGC(GC); |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1177 | else |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1178 | F->clearGC(); |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Duncan Sands | e149e99 | 2009-05-06 12:21:17 +0000 | [diff] [blame] | 1181 | void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { |
| 1182 | Function *Func = unwrap<Function>(Fn); |
| 1183 | const AttrListPtr PAL = Func->getAttributes(); |
| 1184 | const AttrListPtr PALnew = PAL.addAttr(0, PA); |
| 1185 | Func->setAttributes(PALnew); |
| 1186 | } |
| 1187 | |
| 1188 | void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { |
| 1189 | Function *Func = unwrap<Function>(Fn); |
| 1190 | const AttrListPtr PAL = Func->getAttributes(); |
| 1191 | const AttrListPtr PALnew = PAL.removeAttr(0, PA); |
| 1192 | Func->setAttributes(PALnew); |
| 1193 | } |
| 1194 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 1195 | LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) { |
| 1196 | Function *Func = unwrap<Function>(Fn); |
| 1197 | const AttrListPtr PAL = Func->getAttributes(); |
| 1198 | Attributes attr = PAL.getFnAttributes(); |
| 1199 | return (LLVMAttribute)attr; |
| 1200 | } |
| 1201 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1202 | /*--.. Operations on parameters ............................................--*/ |
| 1203 | |
| 1204 | unsigned LLVMCountParams(LLVMValueRef FnRef) { |
| 1205 | // This function is strictly redundant to |
| 1206 | // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef))) |
Dan Gohman | 4d515d0 | 2008-06-21 22:06:54 +0000 | [diff] [blame] | 1207 | return unwrap<Function>(FnRef)->arg_size(); |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) { |
| 1211 | Function *Fn = unwrap<Function>(FnRef); |
| 1212 | for (Function::arg_iterator I = Fn->arg_begin(), |
| 1213 | E = Fn->arg_end(); I != E; I++) |
| 1214 | *ParamRefs++ = wrap(I); |
| 1215 | } |
| 1216 | |
| 1217 | LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) { |
| 1218 | Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin(); |
| 1219 | while (index --> 0) |
| 1220 | AI++; |
| 1221 | return wrap(AI); |
| 1222 | } |
| 1223 | |
| 1224 | LLVMValueRef LLVMGetParamParent(LLVMValueRef V) { |
| 1225 | return wrap(unwrap<Argument>(V)->getParent()); |
| 1226 | } |
| 1227 | |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1228 | LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) { |
| 1229 | Function *Func = unwrap<Function>(Fn); |
| 1230 | Function::arg_iterator I = Func->arg_begin(); |
| 1231 | if (I == Func->arg_end()) |
| 1232 | return 0; |
| 1233 | return wrap(I); |
| 1234 | } |
| 1235 | |
| 1236 | LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) { |
| 1237 | Function *Func = unwrap<Function>(Fn); |
| 1238 | Function::arg_iterator I = Func->arg_end(); |
| 1239 | if (I == Func->arg_begin()) |
| 1240 | return 0; |
| 1241 | return wrap(--I); |
| 1242 | } |
| 1243 | |
| 1244 | LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) { |
| 1245 | Argument *A = unwrap<Argument>(Arg); |
| 1246 | Function::arg_iterator I = A; |
| 1247 | if (++I == A->getParent()->arg_end()) |
| 1248 | return 0; |
| 1249 | return wrap(I); |
| 1250 | } |
| 1251 | |
| 1252 | LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) { |
| 1253 | Argument *A = unwrap<Argument>(Arg); |
| 1254 | Function::arg_iterator I = A; |
| 1255 | if (I == A->getParent()->arg_begin()) |
| 1256 | return 0; |
| 1257 | return wrap(--I); |
| 1258 | } |
| 1259 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1260 | void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1261 | unwrap<Argument>(Arg)->addAttr(PA); |
| 1262 | } |
| 1263 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1264 | void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1265 | unwrap<Argument>(Arg)->removeAttr(PA); |
| 1266 | } |
| 1267 | |
Chris Lattner | 885dffc | 2009-10-12 04:01:02 +0000 | [diff] [blame^] | 1268 | LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) { |
| 1269 | Argument *A = unwrap<Argument>(Arg); |
| 1270 | Attributes attr = A->getParent()->getAttributes().getParamAttributes( |
| 1271 | A->getArgNo()+1); |
| 1272 | return (LLVMAttribute)attr; |
| 1273 | } |
| 1274 | |
| 1275 | |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1276 | void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) { |
| 1277 | unwrap<Argument>(Arg)->addAttr( |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1278 | Attribute::constructAlignmentFromInt(align)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1281 | /*--.. Operations on basic blocks ..........................................--*/ |
| 1282 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1283 | LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) { |
| 1284 | return wrap(static_cast<Value*>(unwrap(BB))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | int LLVMValueIsBasicBlock(LLVMValueRef Val) { |
| 1288 | return isa<BasicBlock>(unwrap(Val)); |
| 1289 | } |
| 1290 | |
| 1291 | LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) { |
| 1292 | return wrap(unwrap<BasicBlock>(Val)); |
| 1293 | } |
| 1294 | |
Gordon Henriksen | 4733be3 | 2008-03-23 22:21:29 +0000 | [diff] [blame] | 1295 | LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) { |
| 1296 | return wrap(unwrap(BB)->getParent()); |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1299 | unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) { |
Dan Gohman | 4d515d0 | 2008-06-21 22:06:54 +0000 | [diff] [blame] | 1300 | return unwrap<Function>(FnRef)->size(); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){ |
| 1304 | Function *Fn = unwrap<Function>(FnRef); |
| 1305 | for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++) |
| 1306 | *BasicBlocksRefs++ = wrap(I); |
| 1307 | } |
| 1308 | |
| 1309 | LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) { |
| 1310 | return wrap(&unwrap<Function>(Fn)->getEntryBlock()); |
| 1311 | } |
| 1312 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1313 | LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) { |
| 1314 | Function *Func = unwrap<Function>(Fn); |
| 1315 | Function::iterator I = Func->begin(); |
| 1316 | if (I == Func->end()) |
| 1317 | return 0; |
| 1318 | return wrap(I); |
| 1319 | } |
| 1320 | |
| 1321 | LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) { |
| 1322 | Function *Func = unwrap<Function>(Fn); |
| 1323 | Function::iterator I = Func->end(); |
| 1324 | if (I == Func->begin()) |
| 1325 | return 0; |
| 1326 | return wrap(--I); |
| 1327 | } |
| 1328 | |
| 1329 | LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) { |
| 1330 | BasicBlock *Block = unwrap(BB); |
| 1331 | Function::iterator I = Block; |
| 1332 | if (++I == Block->getParent()->end()) |
| 1333 | return 0; |
| 1334 | return wrap(I); |
| 1335 | } |
| 1336 | |
| 1337 | LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) { |
| 1338 | BasicBlock *Block = unwrap(BB); |
| 1339 | Function::iterator I = Block; |
| 1340 | if (I == Block->getParent()->begin()) |
| 1341 | return 0; |
| 1342 | return wrap(--I); |
| 1343 | } |
| 1344 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 1345 | LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C, |
| 1346 | LLVMValueRef FnRef, |
| 1347 | const char *Name) { |
| 1348 | return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef))); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 1351 | LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) { |
| 1352 | return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name); |
| 1353 | } |
| 1354 | |
| 1355 | LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C, |
| 1356 | LLVMBasicBlockRef BBRef, |
| 1357 | const char *Name) { |
| 1358 | BasicBlock *BB = unwrap(BBRef); |
| 1359 | return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB)); |
| 1360 | } |
| 1361 | |
| 1362 | LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef, |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1363 | const char *Name) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 1364 | return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) { |
| 1368 | unwrap(BBRef)->eraseFromParent(); |
| 1369 | } |
| 1370 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1371 | /*--.. Operations on instructions ..........................................--*/ |
| 1372 | |
| 1373 | LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) { |
| 1374 | return wrap(unwrap<Instruction>(Inst)->getParent()); |
| 1375 | } |
| 1376 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1377 | LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) { |
| 1378 | BasicBlock *Block = unwrap(BB); |
| 1379 | BasicBlock::iterator I = Block->begin(); |
| 1380 | if (I == Block->end()) |
| 1381 | return 0; |
| 1382 | return wrap(I); |
| 1383 | } |
| 1384 | |
| 1385 | LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) { |
| 1386 | BasicBlock *Block = unwrap(BB); |
| 1387 | BasicBlock::iterator I = Block->end(); |
| 1388 | if (I == Block->begin()) |
| 1389 | return 0; |
| 1390 | return wrap(--I); |
| 1391 | } |
| 1392 | |
| 1393 | LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) { |
| 1394 | Instruction *Instr = unwrap<Instruction>(Inst); |
| 1395 | BasicBlock::iterator I = Instr; |
| 1396 | if (++I == Instr->getParent()->end()) |
| 1397 | return 0; |
| 1398 | return wrap(I); |
| 1399 | } |
| 1400 | |
| 1401 | LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) { |
| 1402 | Instruction *Instr = unwrap<Instruction>(Inst); |
| 1403 | BasicBlock::iterator I = Instr; |
| 1404 | if (I == Instr->getParent()->begin()) |
| 1405 | return 0; |
| 1406 | return wrap(--I); |
| 1407 | } |
| 1408 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1409 | /*--.. Call and invoke instructions ........................................--*/ |
| 1410 | |
| 1411 | unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) { |
| 1412 | Value *V = unwrap(Instr); |
| 1413 | if (CallInst *CI = dyn_cast<CallInst>(V)) |
| 1414 | return CI->getCallingConv(); |
| 1415 | else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) |
| 1416 | return II->getCallingConv(); |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1417 | llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!"); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { |
| 1422 | Value *V = unwrap(Instr); |
| 1423 | if (CallInst *CI = dyn_cast<CallInst>(V)) |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1424 | return CI->setCallingConv(static_cast<CallingConv::ID>(CC)); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1425 | else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1426 | return II->setCallingConv(static_cast<CallingConv::ID>(CC)); |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1427 | llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!"); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1430 | void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, |
| 1431 | LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1432 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1433 | Call.setAttributes( |
| 1434 | Call.getAttributes().addAttr(index, PA)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1437 | void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, |
| 1438 | LLVMAttribute PA) { |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1439 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1440 | Call.setAttributes( |
| 1441 | Call.getAttributes().removeAttr(index, PA)); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, |
| 1445 | unsigned align) { |
| 1446 | CallSite Call = CallSite(unwrap<Instruction>(Instr)); |
Devang Patel | 0598866 | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1447 | Call.setAttributes( |
| 1448 | Call.getAttributes().addAttr(index, |
| 1449 | Attribute::constructAlignmentFromInt(align))); |
Gordon Henriksen | e2435da | 2008-04-28 17:37:06 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Gordon Henriksen | 07cabf6 | 2008-08-30 16:34:54 +0000 | [diff] [blame] | 1452 | /*--.. Operations on call instructions (only) ..............................--*/ |
| 1453 | |
| 1454 | int LLVMIsTailCall(LLVMValueRef Call) { |
| 1455 | return unwrap<CallInst>(Call)->isTailCall(); |
| 1456 | } |
| 1457 | |
| 1458 | void LLVMSetTailCall(LLVMValueRef Call, int isTailCall) { |
| 1459 | unwrap<CallInst>(Call)->setTailCall(isTailCall); |
| 1460 | } |
| 1461 | |
Gordon Henriksen | 2618a6c | 2007-10-08 18:14:39 +0000 | [diff] [blame] | 1462 | /*--.. Operations on phi nodes .............................................--*/ |
| 1463 | |
| 1464 | void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, |
| 1465 | LLVMBasicBlockRef *IncomingBlocks, unsigned Count) { |
| 1466 | PHINode *PhiVal = unwrap<PHINode>(PhiNode); |
| 1467 | for (unsigned I = 0; I != Count; ++I) |
| 1468 | PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I])); |
| 1469 | } |
| 1470 | |
| 1471 | unsigned LLVMCountIncoming(LLVMValueRef PhiNode) { |
| 1472 | return unwrap<PHINode>(PhiNode)->getNumIncomingValues(); |
| 1473 | } |
| 1474 | |
| 1475 | LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) { |
| 1476 | return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index)); |
| 1477 | } |
| 1478 | |
| 1479 | LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) { |
| 1480 | return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index)); |
| 1481 | } |
| 1482 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1483 | |
| 1484 | /*===-- Instruction builders ----------------------------------------------===*/ |
| 1485 | |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 1486 | LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) { |
| 1487 | return wrap(new IRBuilder<>(*unwrap(C))); |
| 1488 | } |
| 1489 | |
Gordon Henriksen | 16c1f44 | 2008-05-04 12:55:34 +0000 | [diff] [blame] | 1490 | LLVMBuilderRef LLVMCreateBuilder(void) { |
Erick Tryzelaar | 22c3f18 | 2009-08-14 00:01:31 +0000 | [diff] [blame] | 1491 | return LLVMCreateBuilderInContext(LLVMGetGlobalContext()); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Gordon Henriksen | 3400097 | 2008-03-19 03:47:18 +0000 | [diff] [blame] | 1494 | void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block, |
| 1495 | LLVMValueRef Instr) { |
| 1496 | BasicBlock *BB = unwrap(Block); |
| 1497 | Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end(); |
| 1498 | unwrap(Builder)->SetInsertPoint(BB, I); |
| 1499 | } |
| 1500 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1501 | void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) { |
| 1502 | Instruction *I = unwrap<Instruction>(Instr); |
| 1503 | unwrap(Builder)->SetInsertPoint(I->getParent(), I); |
| 1504 | } |
| 1505 | |
| 1506 | void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) { |
| 1507 | BasicBlock *BB = unwrap(Block); |
| 1508 | unwrap(Builder)->SetInsertPoint(BB); |
| 1509 | } |
| 1510 | |
Gordon Henriksen | dc1ce7b | 2008-03-19 01:11:35 +0000 | [diff] [blame] | 1511 | LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) { |
| 1512 | return wrap(unwrap(Builder)->GetInsertBlock()); |
| 1513 | } |
| 1514 | |
Chris Lattner | 851ba39 | 2008-12-17 21:39:50 +0000 | [diff] [blame] | 1515 | void LLVMClearInsertionPosition(LLVMBuilderRef Builder) { |
| 1516 | unwrap(Builder)->ClearInsertionPoint (); |
| 1517 | } |
| 1518 | |
| 1519 | void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) { |
| 1520 | unwrap(Builder)->Insert(unwrap<Instruction>(Instr)); |
| 1521 | } |
| 1522 | |
Erick Tryzelaar | 5c1c208 | 2009-08-16 02:20:57 +0000 | [diff] [blame] | 1523 | void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr, |
| 1524 | const char *Name) { |
| 1525 | unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name); |
| 1526 | } |
| 1527 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1528 | void LLVMDisposeBuilder(LLVMBuilderRef Builder) { |
| 1529 | delete unwrap(Builder); |
| 1530 | } |
| 1531 | |
| 1532 | /*--.. Instruction builders ................................................--*/ |
| 1533 | |
| 1534 | LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) { |
| 1535 | return wrap(unwrap(B)->CreateRetVoid()); |
| 1536 | } |
| 1537 | |
| 1538 | LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) { |
| 1539 | return wrap(unwrap(B)->CreateRet(unwrap(V))); |
| 1540 | } |
| 1541 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1542 | LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals, |
| 1543 | unsigned N) { |
| 1544 | return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N)); |
| 1545 | } |
| 1546 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1547 | LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) { |
| 1548 | return wrap(unwrap(B)->CreateBr(unwrap(Dest))); |
| 1549 | } |
| 1550 | |
| 1551 | LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If, |
| 1552 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) { |
| 1553 | return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else))); |
| 1554 | } |
| 1555 | |
| 1556 | LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V, |
| 1557 | LLVMBasicBlockRef Else, unsigned NumCases) { |
| 1558 | return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases)); |
| 1559 | } |
| 1560 | |
| 1561 | LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn, |
| 1562 | LLVMValueRef *Args, unsigned NumArgs, |
| 1563 | LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch, |
| 1564 | const char *Name) { |
| 1565 | return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch), |
| 1566 | unwrap(Args), unwrap(Args) + NumArgs, |
| 1567 | Name)); |
| 1568 | } |
| 1569 | |
| 1570 | LLVMValueRef LLVMBuildUnwind(LLVMBuilderRef B) { |
| 1571 | return wrap(unwrap(B)->CreateUnwind()); |
| 1572 | } |
| 1573 | |
| 1574 | LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) { |
| 1575 | return wrap(unwrap(B)->CreateUnreachable()); |
| 1576 | } |
| 1577 | |
Gordon Henriksen | ab477cc | 2008-01-01 05:50:53 +0000 | [diff] [blame] | 1578 | void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal, |
| 1579 | LLVMBasicBlockRef Dest) { |
| 1580 | unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest)); |
| 1581 | } |
| 1582 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1583 | /*--.. Arithmetic ..........................................................--*/ |
| 1584 | |
| 1585 | LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1586 | const char *Name) { |
| 1587 | return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name)); |
| 1588 | } |
| 1589 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1590 | LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1591 | const char *Name) { |
| 1592 | return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name)); |
| 1593 | } |
| 1594 | |
| 1595 | LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1596 | const char *Name) { |
| 1597 | return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name)); |
| 1598 | } |
| 1599 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1600 | LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1601 | const char *Name) { |
| 1602 | return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name)); |
| 1603 | } |
| 1604 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1605 | LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1606 | const char *Name) { |
| 1607 | return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name)); |
| 1608 | } |
| 1609 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1610 | LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1611 | const char *Name) { |
| 1612 | return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name)); |
| 1613 | } |
| 1614 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1615 | LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1616 | const char *Name) { |
| 1617 | return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name)); |
| 1618 | } |
| 1619 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1620 | LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1621 | const char *Name) { |
| 1622 | return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1623 | } |
| 1624 | |
| 1625 | LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1626 | const char *Name) { |
| 1627 | return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1628 | } |
| 1629 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1630 | LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS, |
| 1631 | LLVMValueRef RHS, const char *Name) { |
| 1632 | return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1633 | } |
| 1634 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1635 | LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1636 | const char *Name) { |
| 1637 | return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name)); |
| 1638 | } |
| 1639 | |
| 1640 | LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1641 | const char *Name) { |
| 1642 | return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name)); |
| 1643 | } |
| 1644 | |
| 1645 | LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1646 | const char *Name) { |
| 1647 | return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name)); |
| 1648 | } |
| 1649 | |
| 1650 | LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1651 | const char *Name) { |
| 1652 | return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name)); |
| 1653 | } |
| 1654 | |
| 1655 | LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1656 | const char *Name) { |
| 1657 | return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name)); |
| 1658 | } |
| 1659 | |
| 1660 | LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1661 | const char *Name) { |
| 1662 | return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name)); |
| 1663 | } |
| 1664 | |
| 1665 | LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1666 | const char *Name) { |
| 1667 | return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name)); |
| 1668 | } |
| 1669 | |
| 1670 | LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1671 | const char *Name) { |
| 1672 | return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name)); |
| 1673 | } |
| 1674 | |
| 1675 | LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1676 | const char *Name) { |
| 1677 | return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name)); |
| 1678 | } |
| 1679 | |
| 1680 | LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, |
| 1681 | const char *Name) { |
| 1682 | return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name)); |
| 1683 | } |
| 1684 | |
| 1685 | LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { |
| 1686 | return wrap(unwrap(B)->CreateNeg(unwrap(V), Name)); |
| 1687 | } |
| 1688 | |
Dan Gohman | d0c5a29 | 2009-09-28 21:51:41 +0000 | [diff] [blame] | 1689 | LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { |
| 1690 | return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name)); |
| 1691 | } |
| 1692 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1693 | LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { |
| 1694 | return wrap(unwrap(B)->CreateNot(unwrap(V), Name)); |
| 1695 | } |
| 1696 | |
| 1697 | /*--.. Memory ..............................................................--*/ |
| 1698 | |
| 1699 | LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1700 | const char *Name) { |
Victor Hernandez | 3e0c99a | 2009-09-25 18:11:52 +0000 | [diff] [blame] | 1701 | return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), 0, Name)); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1705 | LLVMValueRef Val, const char *Name) { |
Victor Hernandez | 3e0c99a | 2009-09-25 18:11:52 +0000 | [diff] [blame] | 1706 | return wrap(unwrap(B)->CreateMalloc(unwrap(Ty), unwrap(Val), Name)); |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1710 | const char *Name) { |
| 1711 | return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name)); |
| 1712 | } |
| 1713 | |
| 1714 | LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, |
| 1715 | LLVMValueRef Val, const char *Name) { |
| 1716 | return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name)); |
| 1717 | } |
| 1718 | |
| 1719 | LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) { |
| 1720 | return wrap(unwrap(B)->CreateFree(unwrap(PointerVal))); |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal, |
| 1725 | const char *Name) { |
| 1726 | return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name)); |
| 1727 | } |
| 1728 | |
| 1729 | LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val, |
| 1730 | LLVMValueRef PointerVal) { |
| 1731 | return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal))); |
| 1732 | } |
| 1733 | |
| 1734 | LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 1735 | LLVMValueRef *Indices, unsigned NumIndices, |
| 1736 | const char *Name) { |
| 1737 | return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), unwrap(Indices), |
| 1738 | unwrap(Indices) + NumIndices, Name)); |
| 1739 | } |
| 1740 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1741 | LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 1742 | LLVMValueRef *Indices, unsigned NumIndices, |
| 1743 | const char *Name) { |
| 1744 | return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), unwrap(Indices), |
| 1745 | unwrap(Indices) + NumIndices, Name)); |
| 1746 | } |
| 1747 | |
| 1748 | LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer, |
| 1749 | unsigned Idx, const char *Name) { |
| 1750 | return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name)); |
| 1751 | } |
| 1752 | |
| 1753 | LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str, |
| 1754 | const char *Name) { |
| 1755 | return wrap(unwrap(B)->CreateGlobalString(Str, Name)); |
| 1756 | } |
| 1757 | |
| 1758 | LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str, |
| 1759 | const char *Name) { |
| 1760 | return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name)); |
| 1761 | } |
| 1762 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1763 | /*--.. Casts ...............................................................--*/ |
| 1764 | |
| 1765 | LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val, |
| 1766 | LLVMTypeRef DestTy, const char *Name) { |
| 1767 | return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name)); |
| 1768 | } |
| 1769 | |
| 1770 | LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1771 | LLVMTypeRef DestTy, const char *Name) { |
| 1772 | return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1773 | } |
| 1774 | |
| 1775 | LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1776 | LLVMTypeRef DestTy, const char *Name) { |
| 1777 | return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1778 | } |
| 1779 | |
| 1780 | LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val, |
| 1781 | LLVMTypeRef DestTy, const char *Name) { |
| 1782 | return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name)); |
| 1783 | } |
| 1784 | |
| 1785 | LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val, |
| 1786 | LLVMTypeRef DestTy, const char *Name) { |
| 1787 | return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name)); |
| 1788 | } |
| 1789 | |
| 1790 | LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val, |
| 1791 | LLVMTypeRef DestTy, const char *Name) { |
| 1792 | return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name)); |
| 1793 | } |
| 1794 | |
| 1795 | LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val, |
| 1796 | LLVMTypeRef DestTy, const char *Name) { |
| 1797 | return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name)); |
| 1798 | } |
| 1799 | |
| 1800 | LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val, |
| 1801 | LLVMTypeRef DestTy, const char *Name) { |
| 1802 | return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name)); |
| 1803 | } |
| 1804 | |
| 1805 | LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1806 | LLVMTypeRef DestTy, const char *Name) { |
| 1807 | return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name)); |
| 1808 | } |
| 1809 | |
| 1810 | LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val, |
| 1811 | LLVMTypeRef DestTy, const char *Name) { |
| 1812 | return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name)); |
| 1813 | } |
| 1814 | |
| 1815 | LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val, |
| 1816 | LLVMTypeRef DestTy, const char *Name) { |
| 1817 | return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name)); |
| 1818 | } |
| 1819 | |
| 1820 | LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1821 | LLVMTypeRef DestTy, const char *Name) { |
| 1822 | return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name)); |
| 1823 | } |
| 1824 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1825 | LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1826 | LLVMTypeRef DestTy, const char *Name) { |
| 1827 | return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy), |
| 1828 | Name)); |
| 1829 | } |
| 1830 | |
| 1831 | LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1832 | LLVMTypeRef DestTy, const char *Name) { |
| 1833 | return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy), |
| 1834 | Name)); |
| 1835 | } |
| 1836 | |
| 1837 | LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1838 | LLVMTypeRef DestTy, const char *Name) { |
| 1839 | return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy), |
| 1840 | Name)); |
| 1841 | } |
| 1842 | |
| 1843 | LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1844 | LLVMTypeRef DestTy, const char *Name) { |
| 1845 | return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name)); |
| 1846 | } |
| 1847 | |
| 1848 | LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1849 | LLVMTypeRef DestTy, const char *Name) { |
| 1850 | return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy), Name)); |
| 1851 | } |
| 1852 | |
| 1853 | LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val, |
| 1854 | LLVMTypeRef DestTy, const char *Name) { |
| 1855 | return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name)); |
| 1856 | } |
| 1857 | |
Gordon Henriksen | 46abf91 | 2007-09-26 20:56:12 +0000 | [diff] [blame] | 1858 | /*--.. Comparisons .........................................................--*/ |
| 1859 | |
| 1860 | LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op, |
| 1861 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 1862 | const char *Name) { |
| 1863 | return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op), |
| 1864 | unwrap(LHS), unwrap(RHS), Name)); |
| 1865 | } |
| 1866 | |
| 1867 | LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op, |
| 1868 | LLVMValueRef LHS, LLVMValueRef RHS, |
| 1869 | const char *Name) { |
| 1870 | return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op), |
| 1871 | unwrap(LHS), unwrap(RHS), Name)); |
| 1872 | } |
| 1873 | |
| 1874 | /*--.. Miscellaneous instructions ..........................................--*/ |
| 1875 | |
| 1876 | LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) { |
| 1877 | return wrap(unwrap(B)->CreatePHI(unwrap(Ty), Name)); |
| 1878 | } |
| 1879 | |
| 1880 | LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, |
| 1881 | LLVMValueRef *Args, unsigned NumArgs, |
| 1882 | const char *Name) { |
| 1883 | return wrap(unwrap(B)->CreateCall(unwrap(Fn), unwrap(Args), |
| 1884 | unwrap(Args) + NumArgs, Name)); |
| 1885 | } |
| 1886 | |
| 1887 | LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If, |
| 1888 | LLVMValueRef Then, LLVMValueRef Else, |
| 1889 | const char *Name) { |
| 1890 | return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else), |
| 1891 | Name)); |
| 1892 | } |
| 1893 | |
| 1894 | LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List, |
| 1895 | LLVMTypeRef Ty, const char *Name) { |
| 1896 | return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name)); |
| 1897 | } |
| 1898 | |
| 1899 | LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal, |
| 1900 | LLVMValueRef Index, const char *Name) { |
| 1901 | return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index), |
| 1902 | Name)); |
| 1903 | } |
| 1904 | |
| 1905 | LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal, |
| 1906 | LLVMValueRef EltVal, LLVMValueRef Index, |
| 1907 | const char *Name) { |
| 1908 | return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal), |
| 1909 | unwrap(Index), Name)); |
| 1910 | } |
| 1911 | |
| 1912 | LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1, |
| 1913 | LLVMValueRef V2, LLVMValueRef Mask, |
| 1914 | const char *Name) { |
| 1915 | return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2), |
| 1916 | unwrap(Mask), Name)); |
| 1917 | } |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 1918 | |
Dan Gohman | b593117 | 2008-11-03 22:55:43 +0000 | [diff] [blame] | 1919 | LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal, |
| 1920 | unsigned Index, const char *Name) { |
| 1921 | return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name)); |
| 1922 | } |
| 1923 | |
| 1924 | LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal, |
| 1925 | LLVMValueRef EltVal, unsigned Index, |
| 1926 | const char *Name) { |
| 1927 | return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal), |
| 1928 | Index, Name)); |
| 1929 | } |
| 1930 | |
Erick Tryzelaar | f72596c | 2009-08-16 02:19:59 +0000 | [diff] [blame] | 1931 | LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val, |
| 1932 | const char *Name) { |
| 1933 | return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name)); |
| 1934 | } |
| 1935 | |
| 1936 | LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val, |
| 1937 | const char *Name) { |
| 1938 | return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name)); |
| 1939 | } |
| 1940 | |
| 1941 | LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS, |
| 1942 | LLVMValueRef RHS, const char *Name) { |
| 1943 | return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name)); |
| 1944 | } |
| 1945 | |
Gordon Henriksen | 1ae6135 | 2007-12-12 01:04:30 +0000 | [diff] [blame] | 1946 | |
| 1947 | /*===-- Module providers --------------------------------------------------===*/ |
| 1948 | |
| 1949 | LLVMModuleProviderRef |
| 1950 | LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) { |
| 1951 | return wrap(new ExistingModuleProvider(unwrap(M))); |
| 1952 | } |
| 1953 | |
| 1954 | void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) { |
| 1955 | delete unwrap(MP); |
| 1956 | } |
| 1957 | |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 1958 | |
| 1959 | /*===-- Memory buffers ----------------------------------------------------===*/ |
| 1960 | |
| 1961 | int LLVMCreateMemoryBufferWithContentsOfFile(const char *Path, |
| 1962 | LLVMMemoryBufferRef *OutMemBuf, |
| 1963 | char **OutMessage) { |
| 1964 | std::string Error; |
Chris Lattner | 038112a | 2008-04-01 18:04:03 +0000 | [diff] [blame] | 1965 | if (MemoryBuffer *MB = MemoryBuffer::getFile(Path, &Error)) { |
Gordon Henriksen | da1435f | 2007-12-19 22:30:40 +0000 | [diff] [blame] | 1966 | *OutMemBuf = wrap(MB); |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | *OutMessage = strdup(Error.c_str()); |
| 1971 | return 1; |
| 1972 | } |
| 1973 | |
| 1974 | int LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf, |
| 1975 | char **OutMessage) { |
| 1976 | if (MemoryBuffer *MB = MemoryBuffer::getSTDIN()) { |
| 1977 | *OutMemBuf = wrap(MB); |
| 1978 | return 0; |
| 1979 | } |
| 1980 | |
| 1981 | *OutMessage = strdup("stdin is empty."); |
| 1982 | return 1; |
| 1983 | } |
| 1984 | |
| 1985 | void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) { |
| 1986 | delete unwrap(MemBuf); |
| 1987 | } |