This repository was archived by the owner on Dec 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssvmaddon.h
87 lines (80 loc) · 2.63 KB
/
ssvmaddon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef SSVMADDON_H
#define SSVMADDON_H
#include "bytecode.h"
#include "cache.h"
#include "errors.h"
#include "options.h"
#include "vm/configure.h"
#include "vm/vm.h"
#include "host/wasi/wasimodule.h"
#include "common/statistics.h"
#include "storage_module.h"
#include <napi.h>
#include <string>
#include <vector>
#include <unordered_map>
class SSVMAddon : public Napi::ObjectWrap<SSVMAddon> {
public:
static Napi::Object Init(Napi::Env Env, Napi::Object Exports);
SSVMAddon(const Napi::CallbackInfo &Info);
~SSVMAddon(){
if (Configure != nullptr) {
delete Configure;
}
if (VM != nullptr) {
delete VM;
}
};
enum class IntKind {
Default,
SInt32,
UInt32,
SInt64,
UInt64
};
private:
using ErrorType = SSVM::NAPI::ErrorType;
static Napi::FunctionReference Constructor;
SSVM::VM::Configure *Configure;
SSVM::VM::VM *VM;
SSVM::Runtime::Instance::MemoryInstance *MemInst;
SSVM::Statistics::Statistics Stat;
SSVM::Host::SSVMStorageModule StorageMod;
SSVM::Host::WasiModule *WasiMod;
SSVM::NAPI::Bytecode BC;
SSVM::NAPI::SSVMOptions Options;
SSVM::NAPI::SSVMCache Cache;
std::vector<uint8_t> ResultData;
bool Inited;
/// Setup related functions
void InitVM(const Napi::CallbackInfo &Info);
void FiniVM();
void InitWasi(const Napi::CallbackInfo &Info, const std::string &FuncName);
void LoadWasm(const Napi::CallbackInfo &Info);
/// WasmBindgen related functions
void PrepareResource(const Napi::CallbackInfo &Info,
std::vector<SSVM::ValVariant> &Args, IntKind IntT);
void PrepareResource(const Napi::CallbackInfo &Info,
std::vector<SSVM::ValVariant> &Args);
void ReleaseResource(const Napi::CallbackInfo &Info, const uint32_t Offset, const uint32_t Size);
/// Run functions
void Run(const Napi::CallbackInfo &Info);
Napi::Value RunStart(const Napi::CallbackInfo &Info);
Napi::Value RunCompile(const Napi::CallbackInfo &Info);
Napi::Value RunIntImpl(const Napi::CallbackInfo &Info, IntKind IntT);
Napi::Value RunInt(const Napi::CallbackInfo &Info);
Napi::Value RunUInt(const Napi::CallbackInfo &Info);
Napi::Value RunInt64(const Napi::CallbackInfo &Info);
Napi::Value RunUInt64(const Napi::CallbackInfo &Info);
Napi::Value RunString(const Napi::CallbackInfo &Info);
Napi::Value RunUint8Array(const Napi::CallbackInfo &Info);
/// Statistics
Napi::Value GetStatistics(const Napi::CallbackInfo &Info);
/// AoT functions
bool Compile();
bool CompileBytecodeTo(const std::string &Path);
void InitReactor(const Napi::CallbackInfo &Info);
/// Error handling functions
void ThrowNapiError(const Napi::CallbackInfo &Info, ErrorType Type);
};
#endif