Skip to content

Commit 8d39a90

Browse files
committed
Feature: ExecutionEngine - initial
Signed-off-by: Dmitry Patsura <talk@dmtry.me>
1 parent 77afa2f commit 8d39a90

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ file(GLOB SOURCE_FILES
2222
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
2323
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
2424

25-
llvm_map_components_to_libnames(llvm_libs ${LLVM_TARGETS_TO_BUILD} bitwriter codegen core support tablegen target)
25+
llvm_map_components_to_libnames(llvm_libs ${LLVM_TARGETS_TO_BUILD} bitwriter codegen core support tablegen target executionengine)
2626

2727
# Link against LLVM libraries
2828
target_link_libraries(${PROJECT_NAME} ${llvm_libs} ${CMAKE_JS_LIB} )

llvm-node.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ declare namespace llvm {
669669
getTypeByName(name: string): StructType | null;
670670
}
671671

672+
class ExecutionEngine {
673+
}
674+
672675
// support
673676
class TargetRegistry {
674677
private constructor();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#ifndef LLVM_NODE_EXECUTION_ENGINE_MODULE_H
3+
#define LLVM_NODE_EXECUTION_ENGINE_MODULE_H
4+
5+
#include <nan.h>
6+
#include "execution-engine.h"
7+
8+
NAN_MODULE_INIT(InitExecutionEngine) {
9+
ExecutionEngineWrapper::Init(target);
10+
}
11+
12+
#endif //LLVM_NODE_EXECUTION_ENGINE_MODULE_H
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#include "execution-engine.h"
3+
#include "../ir/data-layout.h"
4+
5+
Nan::Persistent<v8::ObjectTemplate> ExecutionEngineWrapper::executionEngineTemplate {};
6+
7+
NAN_MODULE_INIT(ExecutionEngineWrapper::Init) {
8+
auto objectTemplate = Nan::New<v8::ObjectTemplate>();
9+
objectTemplate->SetInternalFieldCount(1);
10+
11+
executionEngineTemplate.Reset(objectTemplate);
12+
}
13+
14+
v8::Local<v8::Object> ExecutionEngineWrapper::of(const llvm::ExecutionEngine *executionEnginePtr) {
15+
Nan::EscapableHandleScope escapeScope {};
16+
v8::Local<v8::ObjectTemplate> tpl = Nan::New(executionEngineTemplate);
17+
18+
auto object = Nan::NewInstance(tpl).ToLocalChecked();
19+
auto* wrapper = new ExecutionEngineWrapper { executionEnginePtr };
20+
wrapper->Wrap(object);
21+
22+
return escapeScope.Escape(object);
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#ifndef LLVM_NODE_EXECUTION_ENGINE_H
3+
#define LLVM_NODE_EXECUTION_ENGINE_H
4+
5+
#include <nan.h>
6+
#include <llvm/ExecutionEngine/ExecutionEngine.h>
7+
#include "../util/from-value-mixin.h"
8+
9+
class ExecutionEngineWrapper: public Nan::ObjectWrap, public FromValueMixin<ExecutionEngineWrapper> {
10+
public:
11+
static NAN_MODULE_INIT(Init);
12+
static v8::Local<v8::Object> of(const llvm::ExecutionEngine *ptr);
13+
14+
private:
15+
const llvm::ExecutionEngine* executionEngine;
16+
static Nan::Persistent<v8::ObjectTemplate> executionEngineTemplate;
17+
18+
explicit ExecutionEngineWrapper(const llvm::ExecutionEngine* executionEngine): executionEngine { executionEngine } {
19+
assert(executionEngine && "No execute engine passed");
20+
}
21+
};
22+
23+
#endif //LLVM_NODE_EXECUTION_ENGINE_H

src/llvm-node.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include "config/config.h"
66
#include "support/support.h"
77
#include "target/target.h"
8+
#include "execution-engine/execution-engine-module.h"
89

910
NAN_MODULE_INIT(InitAll) {
1011
InitBitCode(target);
1112
InitConfig(target);
1213
InitIR(target);
1314
InitSupport(target);
14-
InitTarget(target);
15+
InitExecutionEngine(target);
1516
}
1617

1718
NODE_MODULE(llvm, InitAll)

0 commit comments

Comments
 (0)