Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/driver/uniTool.cpp
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "driver/unitool.h"
5
#include "common/spdlog.h"
6
#include "driver/compiler.h"
7
#include "driver/tool.h"
8
#include "po/argument_parser.h"
9
10
#include <string_view>
11
12
namespace WasmEdge {
13
namespace Driver {
14
15
0
int UniTool(int Argc, const char *Argv[], const ToolType ToolSelect) noexcept {
16
0
  using namespace std::literals;
17
18
0
  std::ios::sync_with_stdio(false);
19
0
  Log::setInfoLoggingLevel();
20
21
0
  auto Parser = PO::ArgumentParser();
22
23
0
  PO::SubCommand ToolSubCommand(
24
0
      PO::Description("Wasmedge runtime tool subcommand"sv));
25
0
  PO::SubCommand CompilerSubCommand(
26
0
      PO::Description("Wasmedge compiler subcommand"sv));
27
0
  struct DriverToolOptions ToolOptions;
28
0
  struct DriverCompilerOptions CompilerOptions;
29
30
  // Construct Parser Subcommands and Options
31
0
  if (ToolSelect == ToolType::All) {
32
0
    ToolOptions.add_option(Parser);
33
34
0
    Parser.begin_subcommand(CompilerSubCommand, "compile"sv);
35
0
    CompilerOptions.add_option(Parser);
36
0
    Parser.end_subcommand();
37
38
0
    Parser.begin_subcommand(ToolSubCommand, "run"sv);
39
0
    ToolOptions.add_option(Parser);
40
0
    Parser.end_subcommand();
41
0
  } else if (ToolSelect == ToolType::Tool) {
42
0
    ToolOptions.add_option(Parser);
43
0
  } else if (ToolSelect == ToolType::Compiler) {
44
0
    CompilerOptions.add_option(Parser);
45
0
  } else {
46
0
    return EXIT_FAILURE;
47
0
  }
48
49
  // Parse
50
0
  if (!Parser.parse(stdout, Argc, Argv)) {
51
0
    return EXIT_FAILURE;
52
0
  }
53
0
  if (Parser.isVersion()) {
54
0
    fmt::print("{} version {}\n"sv, Argv[0], kVersionString);
55
0
    for (const auto &Plugin : Plugin::Plugin::plugins()) {
56
0
      auto PluginVersion = Plugin.version();
57
0
      fmt::print("{} (plugin \"{}\") version {}.{}.{}.{}\n"sv,
58
0
                 Plugin.path().string(), Plugin.name(), PluginVersion.Major,
59
0
                 PluginVersion.Minor, PluginVersion.Patch, PluginVersion.Build);
60
0
    }
61
0
    return EXIT_SUCCESS;
62
0
  }
63
0
  if (Parser.isHelp()) {
64
0
    return EXIT_SUCCESS;
65
0
  }
66
67
  // Forward Results
68
0
  if (ToolSubCommand.is_selected() || ToolSelect == ToolType::Tool) {
69
0
    return Tool(ToolOptions);
70
0
  } else if (CompilerSubCommand.is_selected() ||
71
0
             ToolSelect == ToolType::Compiler) {
72
0
    return Compiler(CompilerOptions);
73
0
  } else {
74
0
    return Tool(ToolOptions);
75
0
  }
76
0
}
77
} // namespace Driver
78
} // namespace WasmEdge