Skip to content

Commit ffe5499

Browse files
committed
Simplify endianness conversions for wasmtime
Signed-off-by: Matt Leon <mattleon@google.com>
1 parent 8df1995 commit ffe5499

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/wasmtime/wasmtime.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ template <typename Arg, typename... Args> std::string printValues(Arg arg, Args.
7070
return printValue(arg) + ((", " + printValue(args)) + ... + "");
7171
}
7272

73-
template <typename... Args> void InPlaceConvertWasmToHostEndianness(Args &...args) {
74-
(void(args = wasmtoh(convertWordToUint32(args), true)), ...);
73+
auto ConvertWasmToHostEndianness(const auto &arg) {
74+
return wasmtoh(convertWordToUint32(arg), true);
7575
}
76-
proxy_wasm::Word ConvertWasmToHostEndianness(const proxy_wasm::Word &arg) {
77-
return proxy_wasm::Word(wasmtoh(convertWordToUint32(arg), true));
76+
void InPlaceConvertWasmToHostEndianness(auto &...args) {
77+
(void(args = ConvertWasmToHostEndianness(args)), ...);
7878
}
79-
template <typename... Args> void InPlaceConvertHostToWasmEndianness(Args &...args) {
80-
(void(args = htowasm(convertWordToUint32(args), true)), ...);
79+
auto ConvertHostToWasmEndianness(const auto &arg) {
80+
return htowasm(convertWordToUint32(arg), true);
8181
}
82-
template <typename... Args> auto ConvertHostToWasmEndianness(const Args &...args) {
83-
return std::make_tuple((htowasm(convertWordToUint32(args), true))...);
82+
void InPlaceConvertHostToWasmEndianness(auto &...args) {
83+
(void(args = ConvertHostToWasmEndianness(args)), ...);
8484
}
8585

8686
} // namespace
@@ -387,18 +387,18 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
387387
")");
388388
}
389389
InPlaceConvertHostToWasmEndianness(args...);
390-
TrapResult<R> result = func.call(store_->context(), {args...});
391-
if (!result) {
390+
TrapResult<R> result_wasm = func.call(store_->context(), {args...});
391+
if (!result_wasm) {
392392
fail(FailState::RuntimeError,
393-
"Function: " + std::string(function_name) + " failed: " + result.err().message());
393+
"Function: " + std::string(function_name) + " failed: " + result_wasm.err().message());
394394
return R{};
395395
}
396-
R result_host = ConvertWasmToHostEndianness(result.ok());
396+
R result = ConvertWasmToHostEndianness(result_wasm.ok());
397397
if (log) {
398398
integration()->trace("[host<-vm] " + std::string(function_name) +
399-
" return: " + printValue(result_host));
399+
" return: " + printValue(result));
400400
}
401-
return result_host;
401+
return result;
402402
};
403403
};
404404

0 commit comments

Comments
 (0)