/src/WasmEdge/include/driver/tool.h
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 | | //===-- wasmedge/driver/tool.h - Tool entrypoint --------------------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contents the entrypoint for the tooling executable. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | #include "plugin/plugin.h" |
16 | | #include "po/argument_parser.h" |
17 | | #include <string_view> |
18 | | |
19 | | namespace WasmEdge { |
20 | | namespace Driver { |
21 | | |
22 | | using namespace std::literals; |
23 | | |
24 | | struct DriverToolOptions { |
25 | | DriverToolOptions() |
26 | 0 | : SoName(PO::Description("Wasm or so file"sv), |
27 | 0 | PO::MetaVar("WASM_OR_SO"sv)), |
28 | 0 | Args(PO::Description("Execution arguments"sv), PO::MetaVar("ARG"sv)), |
29 | 0 | Reactor(PO::Description( |
30 | 0 | "Enable reactor mode. Reactor mode calls `_initialize` if exported."sv)), |
31 | 0 | Dir(PO::Description( |
32 | 0 | "Binding directories into WASI virtual filesystem. Each " |
33 | 0 | "directory " |
34 | 0 | "can be specified as --dir `host_path`. You can also map a " |
35 | 0 | "guest " |
36 | 0 | "directory to a host directory by --dir " |
37 | 0 | "`guest_path:host_path`, " |
38 | 0 | "where `guest_path` specifies the path that will correspond to " |
39 | 0 | "`host_path` for calls like `fopen` in the guest." |
40 | 0 | "The default permission is `readwrite`, however, you can use " |
41 | 0 | "--dir `guest_path:host_path:readonly` to make the mapping " |
42 | 0 | "directory become a read only mode."sv), |
43 | 0 | PO::MetaVar("PREOPEN_DIRS"sv)), |
44 | 0 | Env(PO::Description( |
45 | 0 | "Environ variables. Each variable can be specified as --env `NAME=VALUE`."sv), |
46 | 0 | PO::MetaVar("ENVS"sv)), |
47 | 0 | PropAFUNIX(PO::Description("Enable UNIX domain sockets"sv)), |
48 | 0 | PropMutGlobals(PO::Description( |
49 | 0 | "Disable Import/Export of mutable globals proposal"sv)), |
50 | 0 | PropNonTrapF2IConvs(PO::Description( |
51 | 0 | "Disable Non-trapping float-to-int conversions proposal"sv)), |
52 | 0 | PropSignExtendOps( |
53 | 0 | PO::Description("Disable Sign-extension operators proposal"sv)), |
54 | 0 | PropMultiValue(PO::Description("Disable Multi-value proposal"sv)), |
55 | 0 | PropBulkMemOps( |
56 | 0 | PO::Description("Disable Bulk memory operations proposal"sv)), |
57 | 0 | PropRefTypes(PO::Description("Disable Reference types proposal"sv)), |
58 | 0 | PropSIMD(PO::Description("Disable SIMD proposal"sv)), |
59 | 0 | PropTailCall(PO::Description("Enable Tail-call proposal"sv)), |
60 | 0 | PropExtendConst(PO::Description("Enable Extended-const proposal"sv)), |
61 | 0 | PropFunctionReference( |
62 | 0 | PO::Description("Enable Function Reference proposal"sv)), |
63 | 0 | PropGC(PO::Description("Enable GC proposal, this is experimental"sv)), |
64 | 0 | PropMultiMem(PO::Description("Enable Multiple memories proposal"sv)), |
65 | 0 | PropThreads(PO::Description("Enable Threads proposal"sv)), |
66 | 0 | PropRelaxedSIMD(PO::Description("Enable Relaxed SIMD proposal"sv)), |
67 | 0 | PropExceptionHandling( |
68 | 0 | PO::Description("Enable Exception handling proposal"sv)), |
69 | 0 | PropComponent(PO::Description( |
70 | 0 | "Enable Component Model proposal, this is experimental"sv)), |
71 | 0 | PropAll(PO::Description("Enable all features"sv)), |
72 | 0 | ConfEnableInstructionCounting(PO::Description( |
73 | 0 | "Enable generating code for counting Wasm instructions executed."sv)), |
74 | 0 | ConfEnableGasMeasuring(PO::Description( |
75 | 0 | "Enable generating code for counting gas burned during execution."sv)), |
76 | 0 | ConfEnableTimeMeasuring(PO::Description( |
77 | 0 | "Enable generating code for counting time during execution."sv)), |
78 | 0 | ConfEnableAllStatistics(PO::Description( |
79 | 0 | "Enable generating code for all statistics options include instruction counting, gas measuring, and execution time"sv)), |
80 | 0 | ConfEnableJIT( |
81 | 0 | PO::Description("Enable Just-In-Time compiler for running WASM"sv)), |
82 | 0 | ConfEnableCoredump(PO::Description( |
83 | 0 | "Enable coredump when WebAssembly enters a trap"sv)), |
84 | 0 | ConfCoredumpWasmgdb( |
85 | 0 | PO::Description("Enable coredump for wasm-gdb to debug"sv)), |
86 | 0 | ConfForceInterpreter( |
87 | 0 | PO::Description("Forcibly run WASM in interpreter mode."sv)), |
88 | 0 | TimeLim( |
89 | 0 | PO::Description( |
90 | 0 | "Limitation of maximum time(in milliseconds) for execution, default value is 0 for no limitations"sv), |
91 | 0 | PO::MetaVar("TIMEOUT"sv), PO::DefaultValue<uint64_t>(0)), |
92 | 0 | GasLim( |
93 | 0 | PO::Description( |
94 | 0 | "Limitation of execution gas. Upper bound can be specified as --gas-limit `GAS_LIMIT`."sv), |
95 | 0 | PO::MetaVar("GAS_LIMIT"sv)), |
96 | 0 | MemLim( |
97 | 0 | PO::Description( |
98 | 0 | "Limitation of pages(as size of 64 KiB) in every memory instance. Upper bound can be specified as --memory-page-limit `PAGE_COUNT`."sv), |
99 | 0 | PO::MetaVar("PAGE_COUNT"sv)), |
100 | 0 | ForbiddenPlugins(PO::Description("List of plugins to ignore."sv), |
101 | 0 | PO::MetaVar("NAMES"sv)) {} |
102 | | |
103 | | PO::Option<std::string> SoName; |
104 | | PO::List<std::string> Args; |
105 | | PO::Option<PO::Toggle> Reactor; |
106 | | PO::List<std::string> Dir; |
107 | | PO::List<std::string> Env; |
108 | | PO::Option<PO::Toggle> PropAFUNIX; |
109 | | PO::Option<PO::Toggle> PropMutGlobals; |
110 | | PO::Option<PO::Toggle> PropNonTrapF2IConvs; |
111 | | PO::Option<PO::Toggle> PropSignExtendOps; |
112 | | PO::Option<PO::Toggle> PropMultiValue; |
113 | | PO::Option<PO::Toggle> PropBulkMemOps; |
114 | | PO::Option<PO::Toggle> PropRefTypes; |
115 | | PO::Option<PO::Toggle> PropSIMD; |
116 | | PO::Option<PO::Toggle> PropTailCall; |
117 | | PO::Option<PO::Toggle> PropExtendConst; |
118 | | PO::Option<PO::Toggle> PropFunctionReference; |
119 | | PO::Option<PO::Toggle> PropGC; |
120 | | PO::Option<PO::Toggle> PropMultiMem; |
121 | | PO::Option<PO::Toggle> PropThreads; |
122 | | PO::Option<PO::Toggle> PropRelaxedSIMD; |
123 | | PO::Option<PO::Toggle> PropExceptionHandling; |
124 | | PO::Option<PO::Toggle> PropComponent; |
125 | | PO::Option<PO::Toggle> PropAll; |
126 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
127 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
128 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
129 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
130 | | PO::Option<PO::Toggle> ConfEnableJIT; |
131 | | PO::Option<PO::Toggle> ConfEnableCoredump; |
132 | | PO::Option<PO::Toggle> ConfCoredumpWasmgdb; |
133 | | PO::Option<PO::Toggle> ConfForceInterpreter; |
134 | | PO::Option<uint64_t> TimeLim; |
135 | | PO::List<int> GasLim; |
136 | | PO::List<int> MemLim; |
137 | | PO::List<std::string> ForbiddenPlugins; |
138 | | |
139 | 0 | void add_option(PO::ArgumentParser &Parser) noexcept { |
140 | |
|
141 | 0 | Parser.add_option(SoName) |
142 | 0 | .add_option(Args) |
143 | 0 | .add_option("reactor"sv, Reactor) |
144 | 0 | .add_option("dir"sv, Dir) |
145 | 0 | .add_option("env"sv, Env) |
146 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
147 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
148 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
149 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics) |
150 | 0 | .add_option("enable-jit"sv, ConfEnableJIT) |
151 | 0 | .add_option("enable-coredump"sv, ConfEnableCoredump) |
152 | 0 | .add_option("coredump-for-wasmgdb"sv, ConfCoredumpWasmgdb) |
153 | 0 | .add_option("force-interpreter"sv, ConfForceInterpreter) |
154 | 0 | .add_option("disable-import-export-mut-globals"sv, PropMutGlobals) |
155 | 0 | .add_option("disable-non-trap-float-to-int"sv, PropNonTrapF2IConvs) |
156 | 0 | .add_option("disable-sign-extension-operators"sv, PropSignExtendOps) |
157 | 0 | .add_option("disable-multi-value"sv, PropMultiValue) |
158 | 0 | .add_option("disable-bulk-memory"sv, PropBulkMemOps) |
159 | 0 | .add_option("disable-reference-types"sv, PropRefTypes) |
160 | 0 | .add_option("disable-simd"sv, PropSIMD) |
161 | 0 | .add_option("allow-af-unix"sv, PropAFUNIX) |
162 | 0 | .add_option("enable-tail-call"sv, PropTailCall) |
163 | 0 | .add_option("enable-extended-const"sv, PropExtendConst) |
164 | 0 | .add_option("enable-function-reference"sv, PropFunctionReference) |
165 | 0 | .add_option("enable-gc"sv, PropGC) |
166 | 0 | .add_option("enable-multi-memory"sv, PropMultiMem) |
167 | 0 | .add_option("enable-threads"sv, PropThreads) |
168 | 0 | .add_option("enable-relaxed-simd"sv, PropRelaxedSIMD) |
169 | 0 | .add_option("enable-exception-handling"sv, PropExceptionHandling) |
170 | 0 | .add_option("enable-component"sv, PropComponent) |
171 | 0 | .add_option("enable-all"sv, PropAll) |
172 | 0 | .add_option("time-limit"sv, TimeLim) |
173 | 0 | .add_option("gas-limit"sv, GasLim) |
174 | 0 | .add_option("memory-page-limit"sv, MemLim) |
175 | 0 | .add_option("forbidden-plugin"sv, ForbiddenPlugins); |
176 | |
|
177 | 0 | Plugin::Plugin::loadFromDefaultPaths(); |
178 | 0 | Plugin::Plugin::addPluginOptions(Parser); |
179 | 0 | } |
180 | | }; |
181 | | |
182 | | int Tool(struct DriverToolOptions &Opt) noexcept; |
183 | | |
184 | | } // namespace Driver |
185 | | } // namespace WasmEdge |