Skip to content

Commit 6a331eb

Browse files
committed
Feature: ExecutionEngine.addModule - add
Signed-off-by: Dmitry Patsura <talk@dmtry.me>
1 parent 8d39a90 commit 6a331eb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

llvm-node.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,11 @@ declare namespace llvm {
670670
}
671671

672672
class ExecutionEngine {
673+
/**
674+
* Add a Module to the list of modules that we can JIT from.
675+
* @param module
676+
*/
677+
addModule(module: Module);
673678
}
674679

675680
// support

src/execution-engine/execution-engine.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11

22
#include "execution-engine.h"
3-
#include "../ir/data-layout.h"
3+
#include "../ir/module.h"
44

55
Nan::Persistent<v8::ObjectTemplate> ExecutionEngineWrapper::executionEngineTemplate {};
66

77
NAN_MODULE_INIT(ExecutionEngineWrapper::Init) {
88
auto objectTemplate = Nan::New<v8::ObjectTemplate>();
99
objectTemplate->SetInternalFieldCount(1);
1010

11+
Nan::SetMethod(objectTemplate, "addModule", ExecutionEngineWrapper::addModule);
12+
1113
executionEngineTemplate.Reset(objectTemplate);
1214
}
1315

16+
NAN_METHOD(ExecutionEngineWrapper::addModule) {
17+
if (info.Length() != 1 || !ModuleWrapper::isInstance(info[0])) {
18+
return Nan::ThrowTypeError("addModule needs to be called with: mod: Module");
19+
}
20+
21+
auto* module = ModuleWrapper::FromValue(info[0])->getModule();
22+
23+
auto* executionEngine = ExecutionEngineWrapper::FromValue(info.Holder())->executionEngine;
24+
executionEngine->addModule(std::make_unique<llvm::Module*>(module));
25+
}
26+
1427
v8::Local<v8::Object> ExecutionEngineWrapper::of(const llvm::ExecutionEngine *executionEnginePtr) {
1528
Nan::EscapableHandleScope escapeScope {};
1629
v8::Local<v8::ObjectTemplate> tpl = Nan::New(executionEngineTemplate);

src/execution-engine/execution-engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ExecutionEngineWrapper: public Nan::ObjectWrap, public FromValueMixin<Exec
1818
explicit ExecutionEngineWrapper(const llvm::ExecutionEngine* executionEngine): executionEngine { executionEngine } {
1919
assert(executionEngine && "No execute engine passed");
2020
}
21+
22+
static NAN_METHOD(addModule);
2123
};
2224

2325
#endif //LLVM_NODE_EXECUTION_ENGINE_H

0 commit comments

Comments
 (0)