Skip to content

Commit

Permalink
simplify translate_sig
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 31, 2020
1 parent 7e9502f commit 5481fe7
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions test/utils/fizzy_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,26 @@ bytes_view FizzyEngine::get_memory() const

namespace
{
ValType translate_valtype(char input)
{
if (input == 'i')
return fizzy::ValType::i32;
else if (input == 'I')
return fizzy::ValType::i64;
else
throw std::runtime_error{"invalid type"};
}

FuncType translate_signature(std::string_view signature)
{
std::string_view inputs(signature.begin(), signature.find(":"));
std::string_view outputs(inputs.end() + 1); // Is this a terrible hack?

FuncType func_type;
for (const auto input : inputs)
{
if (input == 'i')
func_type.inputs.push_back(fizzy::ValType::i32);
else if (input == 'I')
func_type.inputs.push_back(fizzy::ValType::i64);
else
throw std::runtime_error{"invalid type"};
}
func_type.inputs.push_back(translate_valtype(input));
for (const auto output : outputs)
{
if (output == 'i')
func_type.outputs.push_back(fizzy::ValType::i32);
else if (output == 'I')
func_type.outputs.push_back(fizzy::ValType::i64);
else
throw std::runtime_error{"invalid type"};
}

func_type.outputs.push_back(translate_valtype(output));
return func_type;
}
} // namespace
Expand Down

0 comments on commit 5481fe7

Please sign in to comment.