@@ -468,15 +468,16 @@ void Wamr::registerHostFunctionImpl(std::string_view module_name, std::string_vi
468
468
store_.get (), type.get (),
469
469
[](void *data, const wasm_val_t params[], wasm_val_t results[]) -> wasm_trap_t * {
470
470
auto func_data = reinterpret_cast <HostFuncData *>(data);
471
- if (func_data->vm_ ->cmpLogLevel (LogLevel::trace)) {
471
+ const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
472
+ if (log) {
472
473
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->name_ + " (" +
473
474
printValues (params, sizeof ...(Args)) + " )" );
474
475
}
475
476
auto args_tuple = convertValTypesToArgsTuple<std::tuple<Args...>>(params);
476
477
auto args = std::tuple_cat (std::make_tuple (current_context_), args_tuple);
477
478
auto fn = reinterpret_cast <void (*)(void *, Args...)>(func_data->raw_func_ );
478
479
std::apply (fn, args);
479
- if (func_data-> vm_ -> cmpLogLevel (LogLevel::trace) ) {
480
+ if (log ) {
480
481
func_data->vm_ ->integration ()->trace (" [vm<-host] " + func_data->name_ + " return: void" );
481
482
}
482
483
return nullptr ;
@@ -500,7 +501,8 @@ void Wamr::registerHostFunctionImpl(std::string_view module_name, std::string_vi
500
501
store_.get (), type.get (),
501
502
[](void *data, const wasm_val_t params[], wasm_val_t results[]) -> wasm_trap_t * {
502
503
auto func_data = reinterpret_cast <HostFuncData *>(data);
503
- if (func_data->vm_ ->cmpLogLevel (LogLevel::trace)) {
504
+ const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
505
+ if (log) {
504
506
func_data->vm_ ->integration ()->trace (" [vm->host] " + func_data->name_ + " (" +
505
507
printValues (params, sizeof ...(Args)) + " )" );
506
508
}
@@ -509,7 +511,7 @@ void Wamr::registerHostFunctionImpl(std::string_view module_name, std::string_vi
509
511
auto fn = reinterpret_cast <R (*)(void *, Args...)>(func_data->raw_func_ );
510
512
R res = std::apply (fn, args);
511
513
assignVal<R>(res, results[0 ]);
512
- if (func_data-> vm_ -> cmpLogLevel (LogLevel::trace) ) {
514
+ if (log ) {
513
515
func_data->vm_ ->integration ()->trace (" [vm<-host] " + func_data->name_ +
514
516
" return: " + std::to_string (res));
515
517
}
@@ -552,11 +554,12 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
552
554
553
555
*function = [func, function_name, this ](ContextBase *context, Args... args) -> void {
554
556
wasm_val_t params[] = {makeVal (args)...};
555
- SaveRestoreContext saved_context (context );
556
- if (cmpLogLevel (LogLevel::trace) ) {
557
+ const bool log = cmpLogLevel (LogLevel::trace );
558
+ if (log ) {
557
559
integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
558
560
printValues (params, sizeof ...(Args)) + " )" );
559
561
}
562
+ SaveRestoreContext saved_context (context);
560
563
WasmTrapPtr trap{wasm_func_call (func, params, nullptr )};
561
564
if (trap) {
562
565
WasmByteVec error_message;
@@ -566,7 +569,7 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
566
569
std::string (error_message.get ()->data , error_message.get ()->size ));
567
570
return ;
568
571
}
569
- if (cmpLogLevel (LogLevel::trace) ) {
572
+ if (log ) {
570
573
integration ()->trace (" [host<-vm] " + std::string (function_name) + " return: void" );
571
574
}
572
575
};
@@ -598,11 +601,12 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
598
601
*function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
599
602
wasm_val_t params[] = {makeVal (args)...};
600
603
wasm_val_t results[1 ];
601
- SaveRestoreContext saved_context (context );
602
- if (cmpLogLevel (LogLevel::trace) ) {
604
+ const bool log = cmpLogLevel (LogLevel::trace );
605
+ if (log ) {
603
606
integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
604
607
printValues (params, sizeof ...(Args)) + " )" );
605
608
}
609
+ SaveRestoreContext saved_context (context);
606
610
WasmTrapPtr trap{wasm_func_call (func, params, results)};
607
611
if (trap) {
608
612
WasmByteVec error_message;
@@ -613,7 +617,7 @@ void Wamr::getModuleFunctionImpl(std::string_view function_name,
613
617
return R{};
614
618
}
615
619
R ret = convertValueTypeToArg<R>(results[0 ]);
616
- if (cmpLogLevel (LogLevel::trace) ) {
620
+ if (log ) {
617
621
integration ()->trace (" [host<-vm] " + std::string (function_name) +
618
622
" return: " + std::to_string (ret));
619
623
}
0 commit comments