17
17
#include " include/proxy-wasm/wasm_vm.h"
18
18
#include " src/wasmedge/types.h"
19
19
20
- #include " wasmedge.h"
20
+ #include " wasmedge/wasmedge .h"
21
21
22
22
#include < array>
23
23
#include < cassert>
@@ -206,11 +206,10 @@ namespace WasmEdge {
206
206
struct HostFuncData {
207
207
HostFuncData (const std::string_view modname, const std::string_view name)
208
208
: modname_(modname), name_(name) {}
209
- ~HostFuncData () { WasmEdge_FunctionTypeDelete (functype_); }
209
+ ~HostFuncData () {}
210
210
211
211
std::string modname_, name_;
212
- WasmEdge_WrapFunc_t callback_;
213
- WasmEdge_FunctionTypeContext *functype_;
212
+ WasmEdge_HostFunc_t callback_;
214
213
void *raw_func_;
215
214
WasmVm *vm_;
216
215
};
@@ -219,8 +218,7 @@ using HostFuncDataPtr = std::unique_ptr<HostFuncData>;
219
218
220
219
struct HostModuleData {
221
220
HostModuleData (const std::string_view modname) {
222
- cxt_ =
223
- WasmEdge_ImportObjectCreate (WasmEdge_StringWrap (modname.data (), modname.length ()), nullptr );
221
+ cxt_ = WasmEdge_ImportObjectCreate (WasmEdge_StringWrap (modname.data (), modname.length ()));
224
222
}
225
223
~HostModuleData () { WasmEdge_ImportObjectDelete (cxt_); }
226
224
@@ -234,7 +232,7 @@ class WasmEdge : public WasmVm {
234
232
WasmEdge () {
235
233
loader_ = WasmEdge_LoaderCreate (nullptr );
236
234
validator_ = WasmEdge_ValidatorCreate (nullptr );
237
- interpreter_ = WasmEdge_InterpreterCreate (nullptr , nullptr );
235
+ executor_ = WasmEdge_ExecutorCreate (nullptr , nullptr );
238
236
store_ = nullptr ;
239
237
module_ = nullptr ;
240
238
memory_ = nullptr ;
@@ -289,7 +287,7 @@ class WasmEdge : public WasmVm {
289
287
290
288
WasmEdgeLoaderPtr loader_;
291
289
WasmEdgeValidatorPtr validator_;
292
- WasmEdgeInterpreterPtr interpreter_ ;
290
+ WasmEdgeExecutorPtr executor_ ;
293
291
WasmEdgeStorePtr store_;
294
292
WasmEdgeASTModulePtr module_;
295
293
WasmEdge_MemoryInstanceContext *memory_;
@@ -319,16 +317,15 @@ bool WasmEdge::link(std::string_view debug_name) {
319
317
// Create store and register imports.
320
318
store_ = WasmEdge_StoreCreate ();
321
319
for (auto &&it : import_objects_) {
322
- auto res =
323
- WasmEdge_InterpreterRegisterImport (interpreter_.get (), store_.get (), it.second ->cxt_ );
320
+ auto res = WasmEdge_ExecutorRegisterImport (executor_.get (), store_.get (), it.second ->cxt_ );
324
321
if (!WasmEdge_ResultOK (res)) {
325
322
fail (FailState::UnableToInitializeCode,
326
323
std::string (" Failed to link Wasm module due to import: " ) + it.first );
327
324
return false ;
328
325
}
329
326
}
330
327
// Instantiate module.
331
- if (auto res = WasmEdge_InterpreterInstantiate (interpreter_ .get (), store_.get (), module_.get ());
328
+ if (auto res = WasmEdge_ExecutorInstantiate (executor_ .get (), store_.get (), module_.get ());
332
329
!WasmEdge_ResultOK (res)) {
333
330
fail (FailState::UnableToInitializeCode,
334
331
std::string (" Failed to link Wasm module: " ) + std::string (WasmEdge_ResultGetMessage (res)));
@@ -345,7 +342,6 @@ bool WasmEdge::link(std::string_view debug_name) {
345
342
WasmEdge_StoreListFunction (store_.get (), &names[0 ], num);
346
343
for (auto i = 0 ; i < num; i++) {
347
344
module_functions_.insert (std::string (names[i].Buf , names[i].Length ));
348
- WasmEdge_StringDelete (names[i]);
349
345
}
350
346
}
351
347
return true ;
@@ -402,13 +398,12 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
402
398
}
403
399
404
400
auto data = std::make_unique<HostFuncData>(module_name, function_name);
401
+ auto *func_type = newWasmEdgeFuncType<std::tuple<Args...>>();
405
402
data->vm_ = this ;
406
- data->functype_ = newWasmEdgeFuncType<std::tuple<Args...>>();
407
403
data->raw_func_ = reinterpret_cast <void *>(function);
408
- data->callback_ = [](void *func, void *data, WasmEdge_MemoryInstanceContext *MemCxt,
409
- const WasmEdge_Value *Params, const uint32_t ParamLen,
410
- WasmEdge_Value *Returns, const uint32_t ReturnLen) -> WasmEdge_Result {
411
- auto func_data = reinterpret_cast <HostFuncData *>(func);
404
+ data->callback_ = [](void *data, WasmEdge_MemoryInstanceContext *MemCxt,
405
+ const WasmEdge_Value *Params, WasmEdge_Value *Returns) -> WasmEdge_Result {
406
+ auto func_data = reinterpret_cast <HostFuncData *>(data);
412
407
const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
413
408
if (log) {
414
409
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->modname_ + " ." +
@@ -425,10 +420,10 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
425
420
return WasmEdge_Result_Success;
426
421
};
427
422
428
- auto *hostfunc_cxt =
429
- WasmEdge_HostFunctionCreateBinding (data-> functype_ , data-> callback_ , data. get (), 0 );
423
+ auto *hostfunc_cxt = WasmEdge_FunctionInstanceCreate (func_type, data-> callback_ , data. get (), 0 );
424
+ WasmEdge_FunctionTypeDelete (func_type );
430
425
431
- WasmEdge_ImportObjectAddHostFunction (
426
+ WasmEdge_ImportObjectAddFunction (
432
427
it->second ->cxt_ , WasmEdge_StringWrap (function_name.data (), function_name.length ()),
433
428
hostfunc_cxt);
434
429
host_functions_.insert_or_assign (std::string (module_name) + " ." + std::string (function_name),
@@ -445,13 +440,12 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
445
440
}
446
441
447
442
auto data = std::make_unique<HostFuncData>(module_name, function_name);
443
+ auto *func_type = newWasmEdgeFuncType<R, std::tuple<Args...>>();
448
444
data->vm_ = this ;
449
- data->functype_ = newWasmEdgeFuncType<R, std::tuple<Args...>>();
450
445
data->raw_func_ = reinterpret_cast <void *>(function);
451
- data->callback_ = [](void *func, void *data, WasmEdge_MemoryInstanceContext *MemCxt,
452
- const WasmEdge_Value *Params, const uint32_t ParamLen,
453
- WasmEdge_Value *Returns, const uint32_t ReturnLen) -> WasmEdge_Result {
454
- auto func_data = reinterpret_cast <HostFuncData *>(func);
446
+ data->callback_ = [](void *data, WasmEdge_MemoryInstanceContext *MemCxt,
447
+ const WasmEdge_Value *Params, WasmEdge_Value *Returns) -> WasmEdge_Result {
448
+ auto func_data = reinterpret_cast <HostFuncData *>(data);
455
449
const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
456
450
if (log) {
457
451
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->modname_ + " ." +
@@ -469,10 +463,10 @@ void WasmEdge::registerHostFunctionImpl(std::string_view module_name,
469
463
return WasmEdge_Result_Success;
470
464
};
471
465
472
- auto *hostfunc_cxt =
473
- WasmEdge_HostFunctionCreateBinding (data-> functype_ , data-> callback_ , data. get (), 0 );
466
+ auto *hostfunc_cxt = WasmEdge_FunctionInstanceCreate (func_type, data-> callback_ , data. get (), 0 );
467
+ WasmEdge_FunctionTypeDelete (func_type );
474
468
475
- WasmEdge_ImportObjectAddHostFunction (
469
+ WasmEdge_ImportObjectAddFunction (
476
470
it->second ->cxt_ , WasmEdge_StringWrap (function_name.data (), function_name.length ()),
477
471
hostfunc_cxt);
478
472
host_functions_.insert_or_assign (std::string (module_name) + " ." + std::string (function_name),
@@ -518,10 +512,10 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name,
518
512
printValues (params, sizeof ...(Args)) + " )" );
519
513
}
520
514
SaveRestoreContext saved_context (context);
521
- WasmEdge_Result res = WasmEdge_InterpreterInvoke (
522
- interpreter_ .get (), store_.get (),
523
- WasmEdge_StringWrap (function_name.data (), function_name.length ()), params, sizeof ...(Args ),
524
- nullptr , 0 );
515
+ WasmEdge_Result res =
516
+ WasmEdge_ExecutorInvoke (executor_ .get (), store_.get (),
517
+ WasmEdge_StringWrap (function_name.data (), function_name.length ()),
518
+ params, sizeof ...(Args), nullptr , 0 );
525
519
if (!WasmEdge_ResultOK (res)) {
526
520
fail (FailState::RuntimeError, " Function: " + std::string (function_name) + " failed:\n " +
527
521
WasmEdge_ResultGetMessage (res));
@@ -573,10 +567,10 @@ void WasmEdge::getModuleFunctionImpl(std::string_view function_name,
573
567
printValues (params, sizeof ...(Args)) + " )" );
574
568
}
575
569
SaveRestoreContext saved_context (context);
576
- WasmEdge_Result res = WasmEdge_InterpreterInvoke (
577
- interpreter_ .get (), store_.get (),
578
- WasmEdge_StringWrap (function_name.data (), function_name.length ()), params, sizeof ...(Args ),
579
- results, 1 );
570
+ WasmEdge_Result res =
571
+ WasmEdge_ExecutorInvoke (executor_ .get (), store_.get (),
572
+ WasmEdge_StringWrap (function_name.data (), function_name.length ()),
573
+ params, sizeof ...(Args), results, 1 );
580
574
if (!WasmEdge_ResultOK (res)) {
581
575
fail (FailState::RuntimeError, " Function: " + std::string (function_name) + " failed:\n " +
582
576
WasmEdge_ResultGetMessage (res));
0 commit comments