Coverage Report

Created: 2026-11-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/lib/driver/runtimeTool.cpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
#include "common/configure.h"
5
#include "common/filesystem.h"
6
#include "common/spdlog.h"
7
#include "common/types.h"
8
#include "common/version.h"
9
#include "driver/tool.h"
10
#include "host/wasi/wasimodule.h"
11
#include "vm/vm.h"
12
13
#include <algorithm>
14
#include <cctype>
15
#include <chrono>
16
#include <cstddef>
17
#include <cstdint>
18
#include <cstdlib>
19
#include <limits>
20
#include <optional>
21
#include <stdexcept>
22
#include <string>
23
#include <string_view>
24
#include <vector>
25
26
using namespace std::literals;
27
28
namespace WasmEdge {
29
namespace Driver {
30
31
0
std::optional<RunMode> parseRunModeArg(std::string_view S) noexcept {
32
0
  std::string Lower(S);
33
0
  std::transform(Lower.begin(), Lower.end(), Lower.begin(),
34
0
                 [](unsigned char C) -> char {
35
0
                   return static_cast<char>(std::tolower(C));
36
0
                 });
37
0
  if (Lower == "interpreter") {
38
0
    return RunMode::Interpreter;
39
0
  }
40
0
  if (Lower == "jit") {
41
0
    return RunMode::JIT;
42
0
  }
43
0
  if (Lower == "aot") {
44
0
    return RunMode::AOT;
45
0
  }
46
0
  if (Lower == "lazyjit") {
47
0
    return RunMode::LazyJIT;
48
0
  }
49
0
  return std::nullopt;
50
0
}
51
52
namespace {
53
54
// Helper template to parse numeric arguments and catch conversion exceptions
55
template <typename Converter, typename ValVec, typename TypeVec, typename TC>
56
bool parseNumericArg(const std::string &Value, size_t ParamIndex,
57
                     std::string_view TypeName, Converter Conv,
58
0
                     ValVec &FuncArgs, TypeVec &FuncArgTypes, TC TCode) {
59
0
  try {
60
0
    auto Out = Conv(Value);
61
0
    FuncArgs.emplace_back(Out);
62
0
    FuncArgTypes.emplace_back(TCode);
63
0
    return true;
64
0
  } catch (const std::invalid_argument &) {
65
0
    spdlog::error("Invalid argument '{}' for parameter {}: expected {}"sv,
66
0
                  Value, ParamIndex + 1, TypeName);
67
0
    return false;
68
0
  } catch (const std::out_of_range &) {
69
0
    spdlog::error("Argument '{}' for parameter {}: {} out of range"sv, Value,
70
0
                  ParamIndex + 1, TypeName);
71
0
    return false;
72
0
  }
73
0
}
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >, WasmEdge::TypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >&, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >&, WasmEdge::TypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >, WasmEdge::TypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >&, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >&, WasmEdge::TypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<float (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >, WasmEdge::TypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, float (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >&, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >&, WasmEdge::TypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<double (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >, WasmEdge::TypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, double (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >&, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >&, WasmEdge::TypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<unsigned int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned int (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<unsigned long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<float (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, float (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseNumericArg<double (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, double (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
74
75
// Helpers to convert the numeric arguments. The whole string must be a number
76
// in the range of the type.
77
0
int64_t toS64(const std::string &S) {
78
0
  std::size_t Pos = 0;
79
0
  const auto Val = std::stoll(S, &Pos);
80
0
  if (Pos != S.size()) {
81
0
    throw std::invalid_argument(S);
82
0
  }
83
0
  return Val;
84
0
}
85
86
0
uint64_t toU64(const std::string &S) {
87
0
  if (S.find('-') != std::string::npos) {
88
0
    throw std::out_of_range(S);
89
0
  }
90
0
  std::size_t Pos = 0;
91
0
  const auto Val = std::stoull(S, &Pos);
92
0
  if (Pos != S.size()) {
93
0
    throw std::invalid_argument(S);
94
0
  }
95
0
  return Val;
96
0
}
97
98
// The i32 and i64 parameters take both the signed and the unsigned ranges.
99
0
int64_t toI64(const std::string &S) {
100
0
  try {
101
0
    return toS64(S);
102
0
  } catch (const std::out_of_range &) {
103
0
    return static_cast<int64_t>(toU64(S));
104
0
  }
105
0
}
106
107
0
int32_t toI32(const std::string &S) {
108
0
  const auto Val = toS64(S);
109
0
  if (Val < std::numeric_limits<int32_t>::min() ||
110
0
      Val > std::numeric_limits<uint32_t>::max()) {
111
0
    throw std::out_of_range(S);
112
0
  }
113
0
  return static_cast<int32_t>(static_cast<uint32_t>(Val));
114
0
}
115
116
0
int32_t toS32(const std::string &S) {
117
0
  const auto Val = toS64(S);
118
0
  if (Val < std::numeric_limits<int32_t>::min() ||
119
0
      Val > std::numeric_limits<int32_t>::max()) {
120
0
    throw std::out_of_range(S);
121
0
  }
122
0
  return static_cast<int32_t>(Val);
123
0
}
124
125
0
uint32_t toU32(const std::string &S) {
126
0
  const auto Val = toU64(S);
127
0
  if (Val > std::numeric_limits<uint32_t>::max()) {
128
0
    throw std::out_of_range(S);
129
0
  }
130
0
  return static_cast<uint32_t>(Val);
131
0
}
132
133
0
float toF32(const std::string &S) {
134
0
  std::size_t Pos = 0;
135
0
  const auto Val = std::stof(S, &Pos);
136
0
  if (Pos != S.size()) {
137
0
    throw std::invalid_argument(S);
138
0
  }
139
0
  return Val;
140
0
}
141
142
0
double toF64(const std::string &S) {
143
0
  std::size_t Pos = 0;
144
0
  const auto Val = std::stod(S, &Pos);
145
0
  if (Pos != S.size()) {
146
0
    throw std::invalid_argument(S);
147
0
  }
148
0
  return Val;
149
0
}
150
151
// Helper to parse the arguments beyond the function parameters.
152
template <typename Converter, typename ValVec, typename TypeVec, typename TC>
153
bool parseExtraArgs(const std::vector<std::string> &Args, size_t ParamCount,
154
                    std::string_view TypeName, Converter Conv, ValVec &FuncArgs,
155
0
                    TypeVec &FuncArgTypes, TC TCode) {
156
0
  for (size_t I = ParamCount + 1; I < Args.size(); ++I) {
157
0
    if (!parseNumericArg(Args[I], I, TypeName, Conv, FuncArgs, FuncArgTypes,
158
0
                         TCode)) {
159
0
      return false;
160
0
    }
161
0
  }
162
0
  return true;
163
0
}
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseExtraArgs<long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >, WasmEdge::TypeCode>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, std::__1::allocator<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant> > >&, std::__1::vector<WasmEdge::ValType, std::__1::allocator<WasmEdge::ValType> >&, WasmEdge::TypeCode)
Unexecuted instantiation: runtimeTool.cpp:bool WasmEdge::Driver::(anonymous namespace)::parseExtraArgs<unsigned long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >, WasmEdge::ComponentTypeCode>(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, unsigned long, std::__1::basic_string_view<char, std::__1::char_traits<char> >, unsigned long (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&), std::__1::vector<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, std::__1::allocator<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> > > >&, std::__1::vector<WasmEdge::ComponentValType, std::__1::allocator<WasmEdge::ComponentValType> >&, WasmEdge::ComponentTypeCode)
164
165
bool checkArgCount(const std::string &FuncName, size_t Expected,
166
0
                   const std::vector<std::string> &Args) {
167
0
  const size_t Got = Args.size() - 1;
168
0
  if (Got < Expected) {
169
0
    spdlog::error("function `{}` expects {} argument(s), got {}"sv, FuncName,
170
0
                  Expected, Got);
171
0
    return false;
172
0
  }
173
0
  return true;
174
0
}
175
176
// Helper to wait for the async execution until the timeout and get the result.
177
template <typename AsyncT>
178
auto getAsyncResult(
179
    AsyncT &&AsyncResult,
180
0
    const std::optional<std::chrono::system_clock::time_point> &Timeout) {
181
0
  if (Timeout.has_value()) {
182
0
    if (!AsyncResult.waitUntil(*Timeout)) {
183
0
      AsyncResult.cancel();
184
0
    }
185
0
  }
186
0
  return AsyncResult.get();
187
0
}
Unexecuted instantiation: runtimeTool.cpp:auto WasmEdge::Driver::(anonymous namespace)::getAsyncResult<WasmEdge::Async<cxx20::expected<std::__1::vector<std::__1::pair<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, WasmEdge::ValType>, std::__1::allocator<std::__1::pair<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, WasmEdge::ValType> > >, WasmEdge::ErrCode> > >(WasmEdge::Async<cxx20::expected<std::__1::vector<std::__1::pair<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, WasmEdge::ValType>, std::__1::allocator<std::__1::pair<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, cxx26::simd::basic_vec<unsigned long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<long, cxx26::simd::detail::vector_ext_abi<2> >, cxx26::simd::basic_vec<unsigned int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<int, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<unsigned short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<short, cxx26::simd::detail::vector_ext_abi<8> >, cxx26::simd::basic_vec<unsigned char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<signed char, cxx26::simd::detail::vector_ext_abi<16> >, cxx26::simd::basic_vec<float, cxx26::simd::detail::vector_ext_abi<4> >, cxx26::simd::basic_vec<double, cxx26::simd::detail::vector_ext_abi<2> >, WasmEdge::RefVariant>, WasmEdge::ValType> > >, WasmEdge::ErrCode> >&&, std::__1::optional<std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > > > const&)
Unexecuted instantiation: runtimeTool.cpp:auto WasmEdge::Driver::(anonymous namespace)::getAsyncResult<WasmEdge::Async<cxx20::expected<std::__1::vector<std::__1::pair<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, WasmEdge::ComponentValType>, std::__1::allocator<std::__1::pair<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, WasmEdge::ComponentValType> > >, WasmEdge::ErrCode> > >(WasmEdge::Async<cxx20::expected<std::__1::vector<std::__1::pair<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, WasmEdge::ComponentValType>, std::__1::allocator<std::__1::pair<std::__1::variant<unsigned char, unsigned short, unsigned int, unsigned long, signed char, short, int, long, float, double, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<WasmEdge::ValComp> >, WasmEdge::ComponentValType> > >, WasmEdge::ErrCode> >&&, std::__1::optional<std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l> > > > const&)
188
} // namespace
189
190
static int
191
ToolOnModule(WasmEdge::VM::VM &VM, const std::string &FuncName,
192
             std::optional<std::chrono::system_clock::time_point> Timeout,
193
             struct DriverToolOptions &Opt,
194
0
             const AST::FunctionType &FuncType) noexcept {
195
0
  std::vector<ValVariant> FuncArgs;
196
0
  std::vector<ValType> FuncArgTypes;
197
198
0
  if (!checkArgCount(FuncName, FuncType.getParamTypes().size(),
199
0
                     Opt.Args.value())) {
200
0
    return EXIT_FAILURE;
201
0
  }
202
203
0
  for (size_t I = 0;
204
0
       I < FuncType.getParamTypes().size() && I + 1 < Opt.Args.value().size();
205
0
       ++I) {
206
0
    const auto TCode = FuncType.getParamTypes()[I].getCode();
207
0
    const auto &ArgValue = Opt.Args.value()[I + 1];
208
209
0
    switch (TCode) {
210
0
    case TypeCode::I32: {
211
0
      if (!parseNumericArg(ArgValue, I, "i32"sv, toI32, FuncArgs, FuncArgTypes,
212
0
                           TCode)) {
213
0
        return EXIT_FAILURE;
214
0
      }
215
0
      break;
216
0
    }
217
0
    case TypeCode::I64: {
218
0
      if (!parseNumericArg(ArgValue, I, "i64"sv, toI64, FuncArgs, FuncArgTypes,
219
0
                           TCode)) {
220
0
        return EXIT_FAILURE;
221
0
      }
222
0
      break;
223
0
    }
224
0
    case TypeCode::F32: {
225
0
      if (!parseNumericArg(ArgValue, I, "f32"sv, toF32, FuncArgs, FuncArgTypes,
226
0
                           TCode)) {
227
0
        return EXIT_FAILURE;
228
0
      }
229
0
      break;
230
0
    }
231
0
    case TypeCode::F64: {
232
0
      if (!parseNumericArg(ArgValue, I, "f64"sv, toF64, FuncArgs, FuncArgTypes,
233
0
                           TCode)) {
234
0
        return EXIT_FAILURE;
235
0
      }
236
0
      break;
237
0
    }
238
    // TODO: FuncRef and ExternRef
239
0
    default:
240
0
      break;
241
0
    }
242
0
  }
243
0
  if (!parseExtraArgs(Opt.Args.value(), FuncType.getParamTypes().size(),
244
0
                      "i64"sv, toI64, FuncArgs, FuncArgTypes, TypeCode::I64)) {
245
0
    return EXIT_FAILURE;
246
0
  }
247
248
0
  if (auto Result = getAsyncResult(
249
0
          VM.asyncExecute(FuncName, FuncArgs, FuncArgTypes), Timeout)) {
250
    // Print results.
251
0
    for (size_t I = 0; I < Result->size(); ++I) {
252
0
      switch ((*Result)[I].second.getCode()) {
253
0
      case TypeCode::I32:
254
0
        fmt::print("{}\n"sv, (*Result)[I].first.get<int32_t>());
255
0
        break;
256
0
      case TypeCode::I64:
257
0
        fmt::print("{}\n"sv, (*Result)[I].first.get<int64_t>());
258
0
        break;
259
0
      case TypeCode::F32:
260
0
        fmt::print("{}\n"sv, (*Result)[I].first.get<float>());
261
0
        break;
262
0
      case TypeCode::F64:
263
0
        fmt::print("{}\n"sv, (*Result)[I].first.get<double>());
264
0
        break;
265
0
      case TypeCode::V128:
266
0
        fmt::print("{}\n"sv, uint128((*Result)[I].first.get<uint128_t>()));
267
0
        break;
268
0
      case TypeCode::Ref: {
269
0
        if ((*Result)[I].second.isFuncRefType()) {
270
0
          fmt::print("<funcref>\n"sv);
271
0
        } else if ((*Result)[I].second.isExternRefType()) {
272
0
          fmt::print("<externref>\n"sv);
273
0
        } else {
274
0
          fmt::print("<anyref>\n"sv);
275
0
        }
276
0
        break;
277
0
      }
278
0
      case TypeCode::RefNull: {
279
0
        if ((*Result)[I].second.isFuncRefType()) {
280
0
          fmt::print("<null funcref>\n"sv);
281
0
        } else if ((*Result)[I].second.isExternRefType()) {
282
0
          fmt::print("<null externref>\n"sv);
283
0
        } else {
284
0
          fmt::print("<null anyref>\n"sv);
285
0
        }
286
0
        break;
287
0
      }
288
0
      default:
289
0
        break;
290
0
      }
291
0
    }
292
0
    return EXIT_SUCCESS;
293
0
  } else {
294
    // It indicates that the execution of wasm has been aborted.
295
0
    return 128 + SIGABRT;
296
0
  }
297
0
}
298
299
static int
300
ToolOnComponent(WasmEdge::VM::VM &VM, const std::string &FuncName,
301
                std::optional<std::chrono::system_clock::time_point> Timeout,
302
                struct DriverToolOptions &Opt,
303
0
                const AST::Component::FuncType &FuncType) noexcept {
304
0
  std::vector<ComponentValVariant> FuncArgs;
305
0
  std::vector<ComponentValType> FuncArgTypes;
306
307
0
  if (!checkArgCount(FuncName, FuncType.getParamList().size(),
308
0
                     Opt.Args.value())) {
309
0
    return EXIT_FAILURE;
310
0
  }
311
312
0
  for (size_t I = 0;
313
0
       I < FuncType.getParamList().size() && I + 1 < Opt.Args.value().size();
314
0
       ++I) {
315
0
    const auto TCode = FuncType.getParamList()[I].getValType().getCode();
316
0
    const auto &ArgValue = Opt.Args.value()[I + 1];
317
318
0
    switch (TCode) {
319
0
    case ComponentTypeCode::S32: {
320
0
      if (!parseNumericArg(ArgValue, I, "s32"sv, toS32, FuncArgs, FuncArgTypes,
321
0
                           TCode)) {
322
0
        return EXIT_FAILURE;
323
0
      }
324
0
      break;
325
0
    }
326
0
    case ComponentTypeCode::U32: {
327
0
      if (!parseNumericArg(ArgValue, I, "u32"sv, toU32, FuncArgs, FuncArgTypes,
328
0
                           TCode)) {
329
0
        return EXIT_FAILURE;
330
0
      }
331
0
      break;
332
0
    }
333
0
    case ComponentTypeCode::S64: {
334
0
      if (!parseNumericArg(ArgValue, I, "s64"sv, toS64, FuncArgs, FuncArgTypes,
335
0
                           TCode)) {
336
0
        return EXIT_FAILURE;
337
0
      }
338
0
      break;
339
0
    }
340
0
    case ComponentTypeCode::U64: {
341
0
      if (!parseNumericArg(ArgValue, I, "u64"sv, toU64, FuncArgs, FuncArgTypes,
342
0
                           TCode)) {
343
0
        return EXIT_FAILURE;
344
0
      }
345
0
      break;
346
0
    }
347
0
    case ComponentTypeCode::F32: {
348
0
      if (!parseNumericArg(ArgValue, I, "f32"sv, toF32, FuncArgs, FuncArgTypes,
349
0
                           TCode)) {
350
0
        return EXIT_FAILURE;
351
0
      }
352
0
      break;
353
0
    }
354
0
    case ComponentTypeCode::F64: {
355
0
      if (!parseNumericArg(ArgValue, I, "f64"sv, toF64, FuncArgs, FuncArgTypes,
356
0
                           TCode)) {
357
0
        return EXIT_FAILURE;
358
0
      }
359
0
      break;
360
0
    }
361
0
    case ComponentTypeCode::String: {
362
0
      const std::string Value = Opt.Args.value()[I + 1];
363
0
      FuncArgs.emplace_back(Value);
364
0
      FuncArgTypes.emplace_back(TCode);
365
0
      break;
366
0
    }
367
    // TODO: COMPONENT - other types.
368
0
    default:
369
0
      break;
370
0
    }
371
0
  }
372
0
  if (!parseExtraArgs(Opt.Args.value(), FuncType.getParamList().size(), "u64"sv,
373
0
                      toU64, FuncArgs, FuncArgTypes, ComponentTypeCode::U64)) {
374
0
    return EXIT_FAILURE;
375
0
  }
376
377
0
  if (auto Result = getAsyncResult(
378
0
          VM.asyncExecuteComponent(FuncName, FuncArgs, FuncArgTypes),
379
0
          Timeout)) {
380
    // Print results.
381
0
    for (auto &&Val : *Result) {
382
0
      switch (Val.second.getCode()) {
383
0
      case ComponentTypeCode::S32:
384
0
        fmt::print("{}\n"sv, std::get<int32_t>(Val.first));
385
0
        break;
386
0
      case ComponentTypeCode::U32:
387
0
        fmt::print("{}\n"sv, std::get<uint32_t>(Val.first));
388
0
        break;
389
0
      case ComponentTypeCode::S64:
390
0
        fmt::print("{}\n"sv, std::get<int64_t>(Val.first));
391
0
        break;
392
0
      case ComponentTypeCode::U64:
393
0
        fmt::print("{}\n"sv, std::get<uint64_t>(Val.first));
394
0
        break;
395
0
      case ComponentTypeCode::F32:
396
0
        fmt::print("{}\n"sv, std::get<float>(Val.first));
397
0
        break;
398
0
      case ComponentTypeCode::F64:
399
0
        fmt::print("{}\n"sv, std::get<double>(Val.first));
400
0
        break;
401
0
      case ComponentTypeCode::String:
402
0
        fmt::print("{}\n"sv, std::get<std::string>(Val.first));
403
0
        break;
404
0
      default:
405
0
        break;
406
0
      }
407
0
    }
408
409
0
    return EXIT_SUCCESS;
410
0
  } else {
411
    // It indicates that the execution of wasm has been aborted.
412
0
    return 128 + SIGABRT;
413
0
  }
414
0
}
415
416
0
int Tool(struct DriverToolOptions &Opt) noexcept {
417
0
  std::ios::sync_with_stdio(false);
418
419
0
  Configure Conf = createConfigure(Opt);
420
421
0
  std::optional<std::chrono::system_clock::time_point> Timeout;
422
0
  if (Opt.TimeLim.value() > 0) {
423
    // A limit beyond the range of the clock never expires.
424
0
    const auto Now = std::chrono::system_clock::now();
425
0
    const auto Remain = std::chrono::duration_cast<std::chrono::milliseconds>(
426
0
        std::chrono::system_clock::time_point::max() - Now);
427
0
    if (Opt.TimeLim.value() < static_cast<uint64_t>(Remain.count())) {
428
0
      Timeout = Now + std::chrono::milliseconds(Opt.TimeLim.value());
429
0
    }
430
0
  }
431
0
  if (Opt.GasLim.value().size() > 0) {
432
0
    Conf.getStatisticsConfigure().setCostMeasuring(true);
433
0
    Conf.getStatisticsConfigure().setCostLimit(Opt.GasLim.value().back());
434
0
  }
435
0
  setMemoryPageLimit(Opt, Conf);
436
0
  Conf.getRuntimeConfigure().setMaxStackSize(Opt.StackLim.value());
437
0
  setStatisticsConfigure(Opt, Conf);
438
  // Determine the effective run mode.
439
  // Precedence: --run-mode > deprecated --enable-jit / --force-interpreter.
440
0
  RunMode RunModeFromFlag = RunMode::Interpreter;
441
0
  if (!Opt.ConfRunMode.value().empty()) {
442
0
    if (Opt.ConfEnableJIT.value() || Opt.ConfForceInterpreter.value()) {
443
0
      spdlog::warn("--run-mode overrides deprecated --enable-jit / "
444
0
                   "--force-interpreter."sv);
445
0
    }
446
0
    if (auto Mode = parseRunModeArg(Opt.ConfRunMode.value())) {
447
0
      RunModeFromFlag = *Mode;
448
0
    } else {
449
0
      spdlog::warn("Unknown --run-mode value: \"{}\"; using interpreter. "
450
0
                   "Valid values: interpreter, jit, aot, lazyjit."sv,
451
0
                   Opt.ConfRunMode.value());
452
0
      RunModeFromFlag = RunMode::Interpreter;
453
0
    }
454
0
  } else if (Opt.ConfEnableJIT.value()) {
455
0
    spdlog::warn("--enable-jit is deprecated, use --run-mode=jit instead."sv);
456
0
    RunModeFromFlag = RunMode::JIT;
457
0
  } else if (Opt.ConfForceInterpreter.value()) {
458
0
    spdlog::warn("--force-interpreter is deprecated, use "
459
0
                 "--run-mode=interpreter instead."sv);
460
0
    RunModeFromFlag = RunMode::Interpreter;
461
0
  }
462
0
  Conf.getRuntimeConfigure().setRunMode(RunModeFromFlag);
463
0
  if (RunModeFromFlag == RunMode::JIT || RunModeFromFlag == RunMode::LazyJIT) {
464
0
    Conf.getCompilerConfigure().setOptimizationLevel(
465
0
        WasmEdge::CompilerConfigure::OptimizationLevel::O1);
466
0
  }
467
0
  bool IsCoredumpEnabled =
468
0
      Opt.ConfEnableCoredump.value() || Opt.ConfCoredumpWasmgdb.value();
469
0
  if (IsCoredumpEnabled && RunModeFromFlag != RunMode::Interpreter) {
470
0
    spdlog::warn("The coredump generation is supported by the interpreter "
471
0
                 "only; the coredump is disabled. Use --run-mode=interpreter "
472
0
                 "to generate a coredump."sv);
473
0
    IsCoredumpEnabled = false;
474
0
  }
475
0
  if (IsCoredumpEnabled) {
476
0
    Conf.getRuntimeConfigure().setEnableCoredump(true);
477
0
    if (Opt.ConfCoredumpWasmgdb.value()) {
478
0
      Conf.getRuntimeConfigure().setCoredumpWasmgdb(true);
479
0
    }
480
0
  }
481
0
  if (Opt.ConfAFUNIX.value()) {
482
0
    Conf.getRuntimeConfigure().setAllowAFUNIX(true);
483
0
  }
484
485
0
  Conf.addHostRegistration(HostRegistration::Wasi);
486
0
  const auto InputPath = getInputPath(Opt);
487
0
  if (!InputPath) {
488
0
    return EXIT_FAILURE;
489
0
  }
490
491
  // Create VM and get WASI module instance.
492
0
  VM::VM VM(Conf);
493
0
  Host::WasiModule *WasiMod = dynamic_cast<Host::WasiModule *>(
494
0
      VM.getImportModule(HostRegistration::Wasi));
495
496
0
  if (!registerLinkedModules(Opt, VM)) {
497
0
    return EXIT_FAILURE;
498
0
  }
499
500
  // Load, validate, and instantiate WASM or Component.
501
0
  if (auto Result = VM.loadWasm(u8string(*InputPath)); !Result) {
502
0
    return EXIT_FAILURE;
503
0
  }
504
0
  if (auto Result = VM.validate(); !Result) {
505
0
    return EXIT_FAILURE;
506
0
  }
507
0
  if (auto Result = VM.instantiate(); !Result) {
508
0
    return EXIT_FAILURE;
509
0
  }
510
511
0
  auto HasValidCommandModStartFunc = [&]() {
512
0
    bool HasStart = false;
513
0
    bool Valid = false;
514
515
0
    auto Functions = VM.getFunctionList();
516
0
    for (auto &[FuncName, Type] : Functions) {
517
0
      if (FuncName == "_start") {
518
0
        HasStart = true;
519
0
        if (Type.getReturnTypes().size() == 0 &&
520
0
            Type.getParamTypes().size() == 0) {
521
0
          Valid = true;
522
0
          break;
523
0
        }
524
0
      }
525
0
    }
526
527
    // If HasStart is true but Valid is false, insert _start to enter reactor
528
    // mode.
529
0
    if (HasStart && !Valid) {
530
0
      Opt.Args.value().insert(Opt.Args.value().begin(), "_start");
531
0
    }
532
533
0
    return HasStart && Valid;
534
0
  };
535
536
  // TODO: COMPONENT - does component start function named as "_start"?
537
0
  bool EnterCommandMode = !Opt.Reactor.value() && HasValidCommandModStartFunc();
538
539
  // Initialize WASI module.
540
0
  WasiMod->init(
541
0
      Opt.Dir.value(),
542
0
      u8string(InputPath->filename().replace_extension(u8path("wasm"sv))),
543
0
      Opt.Args.value(), Opt.Env.value());
544
545
0
  if (EnterCommandMode) {
546
    // command mode
547
548
    // TODO: COMPONENT - currently not supported.
549
0
    if (auto Result = getAsyncResult(VM.asyncExecute("_start"sv), Timeout);
550
0
        Result || Result.error() == ErrCode::Value::Terminated) {
551
0
      return static_cast<int>(WasiMod->getExitCode());
552
0
    } else {
553
      // It indicates that the execution of wasm has been aborted.
554
0
      return 128 + SIGABRT;
555
0
    }
556
0
  } else {
557
    // reactor mode
558
559
    // Get the function name to invoke.
560
0
    if (Opt.Args.value().empty()) {
561
0
      fmt::print(
562
0
          stderr,
563
0
          "A function name is required when reactor mode is enabled.\n"sv);
564
0
      return EXIT_FAILURE;
565
0
    }
566
0
    const auto &FuncName = Opt.Args.value().front();
567
568
0
    if (VM.holdsModule()) {
569
      // WASM case.
570
571
      // Check the exported function name and function type first.
572
0
      const auto InitFunc = "_initialize"s;
573
0
      bool HasInit = false;
574
0
      const AST::FunctionType *FuncType = nullptr;
575
0
      for (const auto &Func : VM.getFunctionList()) {
576
0
        if (Func.first == InitFunc) {
577
          // Found the init function.
578
0
          HasInit = true;
579
0
        }
580
0
        if (Func.first == FuncName) {
581
          // Found the function to invoke.
582
0
          FuncType = &Func.second;
583
0
        }
584
0
      }
585
586
0
      if (FuncType == nullptr) {
587
0
        fmt::print(stderr,
588
0
                   "Function \"{}\" not found in the module export list.\n"sv,
589
0
                   FuncName);
590
0
        return EXIT_FAILURE;
591
0
      }
592
593
      // If the initialize function was found and is not being called
594
      // explicitly, invoke it first.
595
0
      if (HasInit && FuncName != InitFunc) {
596
0
        if (auto Result = getAsyncResult(VM.asyncExecute(InitFunc), Timeout);
597
0
            unlikely(!Result)) {
598
          // It indicates that the execution of wasm has been aborted.
599
0
          return 128 + SIGABRT;
600
0
        }
601
0
      }
602
0
      return ToolOnModule(VM, FuncName, Timeout, Opt, *FuncType);
603
0
    } else if (VM.holdsComponent()) {
604
      // Component case.
605
606
      // Check the exported function name and function type first.
607
0
      const AST::Component::FuncType *FuncType = nullptr;
608
0
      for (const auto &Func : VM.getComponentFunctionList()) {
609
0
        if (Func.first == FuncName) {
610
          // Found the function to invoke.
611
0
          FuncType = &Func.second;
612
0
        }
613
0
      }
614
0
      if (FuncType == nullptr) {
615
0
        fmt::print(
616
0
            stderr,
617
0
            "Function \"{}\" not found in the component export list.\n"sv,
618
0
            FuncName);
619
0
        return EXIT_FAILURE;
620
0
      }
621
0
      return ToolOnComponent(VM, FuncName, Timeout, Opt, *FuncType);
622
0
    } else {
623
      // which means VM has neither instantiated module nor instantiated
624
      // component
625
      return 128 + SIGABRT;
626
0
    }
627
0
  }
628
0
}
629
630
} // namespace Driver
631
} // namespace WasmEdge