blob: fa2f23809a8a81ea92c09db5dc02b5fc7a140167 [file] [log] [blame]
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00001//===-- ExecutionEngineBindings.cpp - C bindings for EEs ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the C bindings for the ExecutionEngine library.
11//
12//===----------------------------------------------------------------------===//
13
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000014#include "llvm-c/ExecutionEngine.h"
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000015#include "llvm/ExecutionEngine/ExecutionEngine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/ExecutionEngine/GenericValue.h"
Filip Pizlo3fdbaff2013-05-22 02:46:43 +000017#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
Filip Pizlodec20e42013-05-01 20:59:00 +000018#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/Module.h"
Torok Edwin56d06592009-07-11 20:10:48 +000020#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikov579f0712008-02-20 11:08:44 +000021#include <cstring>
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000022
23using namespace llvm;
24
Chandler Carruthf58e3762014-04-22 03:04:17 +000025#define DEBUG_TYPE "jit"
26
Eric Christopher04d4e932013-04-22 22:47:22 +000027// Wrapping the C bindings types.
Filip Pizlodec20e42013-05-01 20:59:00 +000028DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef)
Eric Christopher04d4e932013-04-22 22:47:22 +000029
Eric Christopher04d4e932013-04-22 22:47:22 +000030inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
31 return reinterpret_cast<TargetLibraryInfo*>(P);
32}
33
34inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
35 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
36 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
37}
38
Juergen Ributzka5fe955c2014-01-23 19:23:28 +000039inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
40 return
41 reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
42}
43
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000044/*===-- Operations on generic values --------------------------------------===*/
45
46LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
47 unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +000048 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000049 GenericValue *GenVal = new GenericValue();
50 GenVal->IntVal = APInt(unwrap<IntegerType>(Ty)->getBitWidth(), N, IsSigned);
51 return wrap(GenVal);
52}
53
54LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P) {
55 GenericValue *GenVal = new GenericValue();
56 GenVal->PointerVal = P;
57 return wrap(GenVal);
58}
59
60LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N) {
61 GenericValue *GenVal = new GenericValue();
62 switch (unwrap(TyRef)->getTypeID()) {
63 case Type::FloatTyID:
64 GenVal->FloatVal = N;
65 break;
66 case Type::DoubleTyID:
67 GenVal->DoubleVal = N;
68 break;
69 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +000070 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000071 }
72 return wrap(GenVal);
73}
74
75unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef) {
76 return unwrap(GenValRef)->IntVal.getBitWidth();
77}
78
79unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef,
Chris Lattner25963c62010-01-09 22:27:07 +000080 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000081 GenericValue *GenVal = unwrap(GenValRef);
82 if (IsSigned)
83 return GenVal->IntVal.getSExtValue();
84 else
85 return GenVal->IntVal.getZExtValue();
86}
87
88void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) {
89 return unwrap(GenVal)->PointerVal;
90}
91
92double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal) {
93 switch (unwrap(TyRef)->getTypeID()) {
94 case Type::FloatTyID:
95 return unwrap(GenVal)->FloatVal;
96 case Type::DoubleTyID:
97 return unwrap(GenVal)->DoubleVal;
98 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +000099 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000100 }
101}
102
103void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal) {
104 delete unwrap(GenVal);
105}
106
107/*===-- Operations on execution engines -----------------------------------===*/
108
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000109LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
110 LLVMModuleRef M,
111 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000112 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000113 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000114 builder.setEngineKind(EngineKind::Either)
115 .setErrorStr(&Error);
116 if (ExecutionEngine *EE = builder.create()){
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000117 *OutEE = wrap(EE);
118 return 0;
119 }
120 *OutError = strdup(Error.c_str());
121 return 1;
122}
123
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000124LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
125 LLVMModuleRef M,
126 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000127 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000128 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000129 builder.setEngineKind(EngineKind::Interpreter)
130 .setErrorStr(&Error);
131 if (ExecutionEngine *Interp = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000132 *OutInterp = wrap(Interp);
133 return 0;
134 }
135 *OutError = strdup(Error.c_str());
136 return 1;
137}
138
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000139LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
140 LLVMModuleRef M,
141 unsigned OptLevel,
142 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000143 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000144 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000145 builder.setEngineKind(EngineKind::JIT)
146 .setErrorStr(&Error)
147 .setOptLevel((CodeGenOpt::Level)OptLevel);
148 if (ExecutionEngine *JIT = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000149 *OutJIT = wrap(JIT);
150 return 0;
151 }
152 *OutError = strdup(Error.c_str());
153 return 1;
154}
155
Filip Pizlo85e0d272013-05-01 22:58:00 +0000156void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions,
157 size_t SizeOfPassedOptions) {
158 LLVMMCJITCompilerOptions options;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000159 memset(&options, 0, sizeof(options)); // Most fields are zero by default.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000160 options.CodeModel = LLVMCodeModelJITDefault;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000161
162 memcpy(PassedOptions, &options,
163 std::min(sizeof(options), SizeOfPassedOptions));
164}
165
166LLVMBool LLVMCreateMCJITCompilerForModule(
167 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
168 LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions,
169 char **OutError) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000170 LLVMMCJITCompilerOptions options;
171 // If the user passed a larger sized options struct, then they were compiled
172 // against a newer LLVM. Tell them that something is wrong.
173 if (SizeOfPassedOptions > sizeof(options)) {
174 *OutError = strdup(
Filip Pizlo85e0d272013-05-01 22:58:00 +0000175 "Refusing to use options struct that is larger than my own; assuming "
176 "LLVM library mismatch.");
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000177 return 1;
178 }
179
180 // Defend against the user having an old version of the API by ensuring that
181 // any fields they didn't see are cleared. We must defend against fields being
182 // set to the bitwise equivalent of zero, and assume that this means "do the
183 // default" as if that option hadn't been available.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000184 LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000185 memcpy(&options, PassedOptions, SizeOfPassedOptions);
186
187 TargetOptions targetOptions;
188 targetOptions.NoFramePointerElim = options.NoFramePointerElim;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000189 targetOptions.EnableFastISel = options.EnableFastISel;
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000190
191 std::string Error;
192 EngineBuilder builder(unwrap(M));
193 builder.setEngineKind(EngineKind::JIT)
194 .setErrorStr(&Error)
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000195 .setOptLevel((CodeGenOpt::Level)options.OptLevel)
Filip Pizlo85e0d272013-05-01 22:58:00 +0000196 .setCodeModel(unwrap(options.CodeModel))
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000197 .setTargetOptions(targetOptions);
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000198 if (options.MCJMM)
199 builder.setMCJITMemoryManager(unwrap(options.MCJMM));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000200 if (ExecutionEngine *JIT = builder.create()) {
201 *OutJIT = wrap(JIT);
202 return 0;
203 }
204 *OutError = strdup(Error.c_str());
205 return 1;
206}
207
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000208LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
209 LLVMModuleProviderRef MP,
210 char **OutError) {
211 /* The module provider is now actually a module. */
212 return LLVMCreateExecutionEngineForModule(OutEE,
213 reinterpret_cast<LLVMModuleRef>(MP),
214 OutError);
215}
216
217LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
218 LLVMModuleProviderRef MP,
219 char **OutError) {
220 /* The module provider is now actually a module. */
221 return LLVMCreateInterpreterForModule(OutInterp,
222 reinterpret_cast<LLVMModuleRef>(MP),
223 OutError);
224}
225
226LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
227 LLVMModuleProviderRef MP,
228 unsigned OptLevel,
229 char **OutError) {
230 /* The module provider is now actually a module. */
231 return LLVMCreateJITCompilerForModule(OutJIT,
232 reinterpret_cast<LLVMModuleRef>(MP),
233 OptLevel, OutError);
234}
235
236
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000237void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) {
238 delete unwrap(EE);
239}
240
241void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE) {
242 unwrap(EE)->runStaticConstructorsDestructors(false);
243}
244
245void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE) {
246 unwrap(EE)->runStaticConstructorsDestructors(true);
247}
248
249int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
250 unsigned ArgC, const char * const *ArgV,
251 const char * const *EnvP) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000252 unwrap(EE)->finalizeObject();
253
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000254 std::vector<std::string> ArgVec;
255 for (unsigned I = 0; I != ArgC; ++I)
256 ArgVec.push_back(ArgV[I]);
257
258 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
259}
260
261LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
262 unsigned NumArgs,
263 LLVMGenericValueRef *Args) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000264 unwrap(EE)->finalizeObject();
265
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000266 std::vector<GenericValue> ArgVec;
267 ArgVec.reserve(NumArgs);
268 for (unsigned I = 0; I != NumArgs; ++I)
269 ArgVec.push_back(*unwrap(Args[I]));
270
271 GenericValue *Result = new GenericValue();
272 *Result = unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
273 return wrap(Result);
274}
275
276void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000277}
278
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000279void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M){
280 unwrap(EE)->addModule(unwrap(M));
281}
282
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000283void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP){
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000284 /* The module provider is now actually a module. */
285 LLVMAddModule(EE, reinterpret_cast<LLVMModuleRef>(MP));
286}
287
288LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
289 LLVMModuleRef *OutMod, char **OutError) {
290 Module *Mod = unwrap(M);
291 unwrap(EE)->removeModule(Mod);
292 *OutMod = wrap(Mod);
293 return 0;
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000294}
295
Chris Lattner25963c62010-01-09 22:27:07 +0000296LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
297 LLVMModuleProviderRef MP,
298 LLVMModuleRef *OutMod, char **OutError) {
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000299 /* The module provider is now actually a module. */
300 return LLVMRemoveModule(EE, reinterpret_cast<LLVMModuleRef>(MP), OutMod,
301 OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000302}
303
Chris Lattner25963c62010-01-09 22:27:07 +0000304LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
305 LLVMValueRef *OutFn) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000306 if (Function *F = unwrap(EE)->FindFunctionNamed(Name)) {
307 *OutFn = wrap(F);
308 return 0;
309 }
310 return 1;
311}
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000312
Filip Pizlo85e0d272013-05-01 22:58:00 +0000313void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
314 LLVMValueRef Fn) {
Rafael Espindolaf8b27c42014-08-07 14:21:18 +0000315 return nullptr;
Duncan Sands330134b2010-07-19 09:33:13 +0000316}
317
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000318LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000319 return wrap(unwrap(EE)->getDataLayout());
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000320}
Gordon Henriksen9f337542008-06-20 02:16:11 +0000321
Juergen Ributzka5fe955c2014-01-23 19:23:28 +0000322LLVMTargetMachineRef
323LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
324 return wrap(unwrap(EE)->getTargetMachine());
325}
326
Gordon Henriksen9f337542008-06-20 02:16:11 +0000327void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
328 void* Addr) {
329 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
330}
Chris Lattner41b43da2009-01-21 18:11:10 +0000331
332void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000333 unwrap(EE)->finalizeObject();
334
Chris Lattner41b43da2009-01-21 18:11:10 +0000335 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
336}
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000337
338/*===-- Operations on memory managers -------------------------------------===*/
339
340namespace {
341
342struct SimpleBindingMMFunctions {
Anders Waldenborg9515b312013-09-30 19:11:32 +0000343 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection;
344 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection;
345 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory;
346 LLVMMemoryManagerDestroyCallback Destroy;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000347};
348
349class SimpleBindingMemoryManager : public RTDyldMemoryManager {
350public:
351 SimpleBindingMemoryManager(const SimpleBindingMMFunctions& Functions,
352 void *Opaque);
353 virtual ~SimpleBindingMemoryManager();
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000354
Craig Topperb51ff602014-03-08 07:51:20 +0000355 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
356 unsigned SectionID,
357 StringRef SectionName) override;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000358
Craig Topperb51ff602014-03-08 07:51:20 +0000359 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
360 unsigned SectionID, StringRef SectionName,
361 bool isReadOnly) override;
362
363 bool finalizeMemory(std::string *ErrMsg) override;
364
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000365private:
366 SimpleBindingMMFunctions Functions;
367 void *Opaque;
368};
369
370SimpleBindingMemoryManager::SimpleBindingMemoryManager(
371 const SimpleBindingMMFunctions& Functions,
372 void *Opaque)
373 : Functions(Functions), Opaque(Opaque) {
374 assert(Functions.AllocateCodeSection &&
375 "No AllocateCodeSection function provided!");
376 assert(Functions.AllocateDataSection &&
377 "No AllocateDataSection function provided!");
378 assert(Functions.FinalizeMemory &&
379 "No FinalizeMemory function provided!");
380 assert(Functions.Destroy &&
381 "No Destroy function provided!");
382}
383
384SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
385 Functions.Destroy(Opaque);
386}
387
388uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000389 uintptr_t Size, unsigned Alignment, unsigned SectionID,
390 StringRef SectionName) {
391 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
392 SectionName.str().c_str());
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000393}
394
395uint8_t *SimpleBindingMemoryManager::allocateDataSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000396 uintptr_t Size, unsigned Alignment, unsigned SectionID,
397 StringRef SectionName, bool isReadOnly) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000398 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000399 SectionName.str().c_str(),
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000400 isReadOnly);
401}
402
403bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
Craig Topper2617dcc2014-04-15 06:32:26 +0000404 char *errMsgCString = nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000405 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
406 assert((result || !errMsgCString) &&
407 "Did not expect an error message if FinalizeMemory succeeded");
408 if (errMsgCString) {
409 if (ErrMsg)
410 *ErrMsg = errMsgCString;
411 free(errMsgCString);
412 }
413 return result;
414}
415
416} // anonymous namespace
417
418LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
419 void *Opaque,
Anders Waldenborg9515b312013-09-30 19:11:32 +0000420 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
421 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
422 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
423 LLVMMemoryManagerDestroyCallback Destroy) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000424
425 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
426 !Destroy)
Craig Topper2617dcc2014-04-15 06:32:26 +0000427 return nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000428
429 SimpleBindingMMFunctions functions;
430 functions.AllocateCodeSection = AllocateCodeSection;
431 functions.AllocateDataSection = AllocateDataSection;
432 functions.FinalizeMemory = FinalizeMemory;
433 functions.Destroy = Destroy;
434 return wrap(new SimpleBindingMemoryManager(functions, Opaque));
435}
436
437void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM) {
438 delete unwrap(MM);
439}
440