Skip to content

Commit

Permalink
simplify wasm3_engine
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 25, 2021
1 parent db65a24 commit a2a1601
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions test/utils/wasm3_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,6 @@ class Wasm3Engine final : public WasmEngine

namespace
{
M3ValueType translate_valtype(char input)
{
if (input == 'i')
return M3ValueType::c_m3Type_i32;
else if (input == 'I')
return M3ValueType::c_m3Type_i64;
else
throw std::runtime_error{"invalid type"};
}

std::pair<std::vector<M3ValueType>, std::vector<M3ValueType>> translate_signature(
std::string_view signature)
{
const auto delimiter_pos = signature.find(':');
assert(delimiter_pos != std::string_view::npos);
const auto inputs = signature.substr(0, delimiter_pos);
const auto outputs = signature.substr(delimiter_pos + 1);

std::vector<M3ValueType> input_types;
std::vector<M3ValueType> output_types;
std::transform(
std::begin(inputs), std::end(inputs), std::back_inserter(input_types), translate_valtype);
std::transform(std::begin(outputs), std::end(outputs), std::back_inserter(output_types),
translate_valtype);
return {std::move(input_types), std::move(output_types)};
}

const void* env_adler32(
IM3Runtime /*runtime*/, IM3ImportContext /*context*/, uint64_t* stack, void* mem)
{
Expand Down Expand Up @@ -152,7 +125,8 @@ std::optional<WasmEngine::FuncRef> Wasm3Engine::find_function(

std::vector<M3ValueType> inputs;
std::vector<M3ValueType> outputs;
std::tie(inputs, outputs) = translate_signature(signature);
std::tie(inputs, outputs) = translate_function_signature<M3ValueType, M3ValueType::c_m3Type_i32,
M3ValueType::c_m3Type_i64>(signature);

if (inputs.size() != m3_GetArgCount(function))
return std::nullopt;
Expand Down

0 comments on commit a2a1601

Please sign in to comment.