blob: 5ecf3ac44320c7065a970caad468a3e92ab79fba [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
30inline DataLayout *unwrap(LLVMTargetDataRef P) {
31 return reinterpret_cast<DataLayout*>(P);
32}
33
34inline LLVMTargetDataRef wrap(const DataLayout *P) {
35 return reinterpret_cast<LLVMTargetDataRef>(const_cast<DataLayout*>(P));
36}
37
38inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) {
39 return reinterpret_cast<TargetLibraryInfo*>(P);
40}
41
42inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) {
43 TargetLibraryInfo *X = const_cast<TargetLibraryInfo*>(P);
44 return reinterpret_cast<LLVMTargetLibraryInfoRef>(X);
45}
46
Juergen Ributzka5fe955c2014-01-23 19:23:28 +000047inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
48 return
49 reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
50}
51
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000052/*===-- Operations on generic values --------------------------------------===*/
53
54LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
55 unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +000056 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000057 GenericValue *GenVal = new GenericValue();
58 GenVal->IntVal = APInt(unwrap<IntegerType>(Ty)->getBitWidth(), N, IsSigned);
59 return wrap(GenVal);
60}
61
62LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P) {
63 GenericValue *GenVal = new GenericValue();
64 GenVal->PointerVal = P;
65 return wrap(GenVal);
66}
67
68LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N) {
69 GenericValue *GenVal = new GenericValue();
70 switch (unwrap(TyRef)->getTypeID()) {
71 case Type::FloatTyID:
72 GenVal->FloatVal = N;
73 break;
74 case Type::DoubleTyID:
75 GenVal->DoubleVal = N;
76 break;
77 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +000078 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000079 }
80 return wrap(GenVal);
81}
82
83unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef) {
84 return unwrap(GenValRef)->IntVal.getBitWidth();
85}
86
87unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef,
Chris Lattner25963c62010-01-09 22:27:07 +000088 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000089 GenericValue *GenVal = unwrap(GenValRef);
90 if (IsSigned)
91 return GenVal->IntVal.getSExtValue();
92 else
93 return GenVal->IntVal.getZExtValue();
94}
95
96void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) {
97 return unwrap(GenVal)->PointerVal;
98}
99
100double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal) {
101 switch (unwrap(TyRef)->getTypeID()) {
102 case Type::FloatTyID:
103 return unwrap(GenVal)->FloatVal;
104 case Type::DoubleTyID:
105 return unwrap(GenVal)->DoubleVal;
106 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000107 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000108 }
109}
110
111void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal) {
112 delete unwrap(GenVal);
113}
114
115/*===-- Operations on execution engines -----------------------------------===*/
116
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000117LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
118 LLVMModuleRef M,
119 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000120 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000121 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000122 builder.setEngineKind(EngineKind::Either)
123 .setErrorStr(&Error);
124 if (ExecutionEngine *EE = builder.create()){
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000125 *OutEE = wrap(EE);
126 return 0;
127 }
128 *OutError = strdup(Error.c_str());
129 return 1;
130}
131
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000132LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
133 LLVMModuleRef M,
134 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000135 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000136 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000137 builder.setEngineKind(EngineKind::Interpreter)
138 .setErrorStr(&Error);
139 if (ExecutionEngine *Interp = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000140 *OutInterp = wrap(Interp);
141 return 0;
142 }
143 *OutError = strdup(Error.c_str());
144 return 1;
145}
146
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000147LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
148 LLVMModuleRef M,
149 unsigned OptLevel,
150 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000151 std::string Error;
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000152 EngineBuilder builder(unwrap(M));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000153 builder.setEngineKind(EngineKind::JIT)
154 .setErrorStr(&Error)
155 .setOptLevel((CodeGenOpt::Level)OptLevel);
156 if (ExecutionEngine *JIT = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000157 *OutJIT = wrap(JIT);
158 return 0;
159 }
160 *OutError = strdup(Error.c_str());
161 return 1;
162}
163
Filip Pizlo85e0d272013-05-01 22:58:00 +0000164void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions,
165 size_t SizeOfPassedOptions) {
166 LLVMMCJITCompilerOptions options;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000167 memset(&options, 0, sizeof(options)); // Most fields are zero by default.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000168 options.CodeModel = LLVMCodeModelJITDefault;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000169
170 memcpy(PassedOptions, &options,
171 std::min(sizeof(options), SizeOfPassedOptions));
172}
173
174LLVMBool LLVMCreateMCJITCompilerForModule(
175 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
176 LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions,
177 char **OutError) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000178 LLVMMCJITCompilerOptions options;
179 // If the user passed a larger sized options struct, then they were compiled
180 // against a newer LLVM. Tell them that something is wrong.
181 if (SizeOfPassedOptions > sizeof(options)) {
182 *OutError = strdup(
Filip Pizlo85e0d272013-05-01 22:58:00 +0000183 "Refusing to use options struct that is larger than my own; assuming "
184 "LLVM library mismatch.");
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000185 return 1;
186 }
187
188 // Defend against the user having an old version of the API by ensuring that
189 // any fields they didn't see are cleared. We must defend against fields being
190 // set to the bitwise equivalent of zero, and assume that this means "do the
191 // default" as if that option hadn't been available.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000192 LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000193 memcpy(&options, PassedOptions, SizeOfPassedOptions);
194
195 TargetOptions targetOptions;
196 targetOptions.NoFramePointerElim = options.NoFramePointerElim;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000197 targetOptions.EnableFastISel = options.EnableFastISel;
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000198
199 std::string Error;
200 EngineBuilder builder(unwrap(M));
201 builder.setEngineKind(EngineKind::JIT)
202 .setErrorStr(&Error)
203 .setUseMCJIT(true)
204 .setOptLevel((CodeGenOpt::Level)options.OptLevel)
Filip Pizlo85e0d272013-05-01 22:58:00 +0000205 .setCodeModel(unwrap(options.CodeModel))
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000206 .setTargetOptions(targetOptions);
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000207 if (options.MCJMM)
208 builder.setMCJITMemoryManager(unwrap(options.MCJMM));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000209 if (ExecutionEngine *JIT = builder.create()) {
210 *OutJIT = wrap(JIT);
211 return 0;
212 }
213 *OutError = strdup(Error.c_str());
214 return 1;
215}
216
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000217LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
218 LLVMModuleProviderRef MP,
219 char **OutError) {
220 /* The module provider is now actually a module. */
221 return LLVMCreateExecutionEngineForModule(OutEE,
222 reinterpret_cast<LLVMModuleRef>(MP),
223 OutError);
224}
225
226LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
227 LLVMModuleProviderRef MP,
228 char **OutError) {
229 /* The module provider is now actually a module. */
230 return LLVMCreateInterpreterForModule(OutInterp,
231 reinterpret_cast<LLVMModuleRef>(MP),
232 OutError);
233}
234
235LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
236 LLVMModuleProviderRef MP,
237 unsigned OptLevel,
238 char **OutError) {
239 /* The module provider is now actually a module. */
240 return LLVMCreateJITCompilerForModule(OutJIT,
241 reinterpret_cast<LLVMModuleRef>(MP),
242 OptLevel, OutError);
243}
244
245
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000246void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) {
247 delete unwrap(EE);
248}
249
250void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE) {
251 unwrap(EE)->runStaticConstructorsDestructors(false);
252}
253
254void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE) {
255 unwrap(EE)->runStaticConstructorsDestructors(true);
256}
257
258int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
259 unsigned ArgC, const char * const *ArgV,
260 const char * const *EnvP) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000261 unwrap(EE)->finalizeObject();
262
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000263 std::vector<std::string> ArgVec;
264 for (unsigned I = 0; I != ArgC; ++I)
265 ArgVec.push_back(ArgV[I]);
266
267 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
268}
269
270LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
271 unsigned NumArgs,
272 LLVMGenericValueRef *Args) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000273 unwrap(EE)->finalizeObject();
274
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000275 std::vector<GenericValue> ArgVec;
276 ArgVec.reserve(NumArgs);
277 for (unsigned I = 0; I != NumArgs; ++I)
278 ArgVec.push_back(*unwrap(Args[I]));
279
280 GenericValue *Result = new GenericValue();
281 *Result = unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
282 return wrap(Result);
283}
284
285void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F) {
286 unwrap(EE)->freeMachineCodeForFunction(unwrap<Function>(F));
287}
288
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000289void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M){
290 unwrap(EE)->addModule(unwrap(M));
291}
292
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000293void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP){
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000294 /* The module provider is now actually a module. */
295 LLVMAddModule(EE, reinterpret_cast<LLVMModuleRef>(MP));
296}
297
298LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
299 LLVMModuleRef *OutMod, char **OutError) {
300 Module *Mod = unwrap(M);
301 unwrap(EE)->removeModule(Mod);
302 *OutMod = wrap(Mod);
303 return 0;
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000304}
305
Chris Lattner25963c62010-01-09 22:27:07 +0000306LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
307 LLVMModuleProviderRef MP,
308 LLVMModuleRef *OutMod, char **OutError) {
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000309 /* The module provider is now actually a module. */
310 return LLVMRemoveModule(EE, reinterpret_cast<LLVMModuleRef>(MP), OutMod,
311 OutError);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000312}
313
Chris Lattner25963c62010-01-09 22:27:07 +0000314LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
315 LLVMValueRef *OutFn) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000316 if (Function *F = unwrap(EE)->FindFunctionNamed(Name)) {
317 *OutFn = wrap(F);
318 return 0;
319 }
320 return 1;
321}
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000322
Filip Pizlo85e0d272013-05-01 22:58:00 +0000323void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
324 LLVMValueRef Fn) {
Duncan Sands953e6172010-07-19 09:36:45 +0000325 return unwrap(EE)->recompileAndRelinkFunction(unwrap<Function>(Fn));
Duncan Sands330134b2010-07-19 09:33:13 +0000326}
327
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000328LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000329 return wrap(unwrap(EE)->getDataLayout());
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000330}
Gordon Henriksen9f337542008-06-20 02:16:11 +0000331
Juergen Ributzka5fe955c2014-01-23 19:23:28 +0000332LLVMTargetMachineRef
333LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
334 return wrap(unwrap(EE)->getTargetMachine());
335}
336
Gordon Henriksen9f337542008-06-20 02:16:11 +0000337void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
338 void* Addr) {
339 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
340}
Chris Lattner41b43da2009-01-21 18:11:10 +0000341
342void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000343 unwrap(EE)->finalizeObject();
344
Chris Lattner41b43da2009-01-21 18:11:10 +0000345 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
346}
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000347
348/*===-- Operations on memory managers -------------------------------------===*/
349
350namespace {
351
352struct SimpleBindingMMFunctions {
Anders Waldenborg9515b312013-09-30 19:11:32 +0000353 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection;
354 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection;
355 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory;
356 LLVMMemoryManagerDestroyCallback Destroy;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000357};
358
359class SimpleBindingMemoryManager : public RTDyldMemoryManager {
360public:
361 SimpleBindingMemoryManager(const SimpleBindingMMFunctions& Functions,
362 void *Opaque);
363 virtual ~SimpleBindingMemoryManager();
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000364
Craig Topperb51ff602014-03-08 07:51:20 +0000365 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
366 unsigned SectionID,
367 StringRef SectionName) override;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000368
Craig Topperb51ff602014-03-08 07:51:20 +0000369 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
370 unsigned SectionID, StringRef SectionName,
371 bool isReadOnly) override;
372
373 bool finalizeMemory(std::string *ErrMsg) override;
374
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000375private:
376 SimpleBindingMMFunctions Functions;
377 void *Opaque;
378};
379
380SimpleBindingMemoryManager::SimpleBindingMemoryManager(
381 const SimpleBindingMMFunctions& Functions,
382 void *Opaque)
383 : Functions(Functions), Opaque(Opaque) {
384 assert(Functions.AllocateCodeSection &&
385 "No AllocateCodeSection function provided!");
386 assert(Functions.AllocateDataSection &&
387 "No AllocateDataSection function provided!");
388 assert(Functions.FinalizeMemory &&
389 "No FinalizeMemory function provided!");
390 assert(Functions.Destroy &&
391 "No Destroy function provided!");
392}
393
394SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
395 Functions.Destroy(Opaque);
396}
397
398uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000399 uintptr_t Size, unsigned Alignment, unsigned SectionID,
400 StringRef SectionName) {
401 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
402 SectionName.str().c_str());
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000403}
404
405uint8_t *SimpleBindingMemoryManager::allocateDataSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000406 uintptr_t Size, unsigned Alignment, unsigned SectionID,
407 StringRef SectionName, bool isReadOnly) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000408 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000409 SectionName.str().c_str(),
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000410 isReadOnly);
411}
412
413bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
Craig Topper2617dcc2014-04-15 06:32:26 +0000414 char *errMsgCString = nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000415 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
416 assert((result || !errMsgCString) &&
417 "Did not expect an error message if FinalizeMemory succeeded");
418 if (errMsgCString) {
419 if (ErrMsg)
420 *ErrMsg = errMsgCString;
421 free(errMsgCString);
422 }
423 return result;
424}
425
426} // anonymous namespace
427
428LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
429 void *Opaque,
Anders Waldenborg9515b312013-09-30 19:11:32 +0000430 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
431 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
432 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
433 LLVMMemoryManagerDestroyCallback Destroy) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000434
435 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
436 !Destroy)
Craig Topper2617dcc2014-04-15 06:32:26 +0000437 return nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000438
439 SimpleBindingMMFunctions functions;
440 functions.AllocateCodeSection = AllocateCodeSection;
441 functions.AllocateDataSection = AllocateDataSection;
442 functions.FinalizeMemory = FinalizeMemory;
443 functions.Destroy = Destroy;
444 return wrap(new SimpleBindingMemoryManager(functions, Opaque));
445}
446
447void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM) {
448 delete unwrap(MM);
449}
450