/src/WasmEdge/include/driver/tool.h
Line | Count | Source |
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 can be specified as --dir `host_path`. You can also " |
34 | 0 | "map a guest directory to a host directory by --dir " |
35 | 0 | "`guest_path:host_path`, where `guest_path` specifies the path " |
36 | 0 | "that will correspond to `host_path` for calls like `fopen` in " |
37 | 0 | "the guest. The default permission is `readwrite`, however, " |
38 | 0 | "you can use --dir `guest_path:host_path:readonly` to make the " |
39 | 0 | "mapping directory become a read only mode."sv), |
40 | 0 | PO::MetaVar("PREOPEN_DIRS"sv)), |
41 | 0 | Env(PO::Description( |
42 | 0 | "Environ variables. Each variable can be specified as --env " |
43 | 0 | "`NAME=VALUE`."sv), |
44 | 0 | PO::MetaVar("ENVS"sv)), |
45 | 0 | PropWASM1(PO::Description("Set as WASM 1.0 standard."sv)), |
46 | 0 | PropWASM2(PO::Description("Set as WASM 2.0 standard."sv)), |
47 | 0 | PropWASM3(PO::Description("Set as WASM 3.0 standard (default)."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("Disable Tail-call proposal"sv)), |
60 | 0 | PropExtendConst(PO::Description("Disable Extended-const proposal"sv)), |
61 | 0 | PropFunctionReference( |
62 | 0 | PO::Description("Disable Function Reference proposal"sv)), |
63 | 0 | PropGC(PO::Description("Disable GC proposal"sv)), |
64 | 0 | PropMultiMem(PO::Description("Disable Multiple memories proposal"sv)), |
65 | 0 | PropRelaxedSIMD(PO::Description("Disable Relaxed SIMD proposal"sv)), |
66 | 0 | PropExceptionHandling( |
67 | 0 | PO::Description("Disable Exception handling proposal"sv)), |
68 | | // TODO: MEMORY64 - enable the option. |
69 | | // PropMemory64(PO::Description("Disable Memory64 proposal"sv)), |
70 | 0 | PropThreads(PO::Description("Disable Threads proposal"sv)), |
71 | 0 | PropComponent(PO::Description( |
72 | 0 | "Enable Component Model proposal, this is experimental"sv)), |
73 | 0 | PropAll(PO::Description("Enable all features"sv)), |
74 | 0 | ConfEnableInstructionCounting(PO::Description( |
75 | 0 | "Enable generating code for counting Wasm instructions executed."sv)), |
76 | 0 | ConfEnableGasMeasuring(PO::Description( |
77 | 0 | "Enable generating code for counting gas burned during execution."sv)), |
78 | 0 | ConfEnableTimeMeasuring(PO::Description( |
79 | 0 | "Enable generating code for counting time during execution."sv)), |
80 | 0 | ConfEnableAllStatistics(PO::Description( |
81 | 0 | "Enable generating code for all statistics options include " |
82 | 0 | "instruction counting, gas measuring, and execution time"sv)), |
83 | 0 | ConfEnableJIT( |
84 | 0 | PO::Description("Enable Just-In-Time compiler for running WASM"sv)), |
85 | 0 | ConfEnableCoredump(PO::Description( |
86 | 0 | "Enable coredump when WebAssembly enters a trap"sv)), |
87 | 0 | ConfCoredumpWasmgdb( |
88 | 0 | PO::Description("Enable coredump for wasm-gdb to debug"sv)), |
89 | 0 | ConfForceInterpreter( |
90 | 0 | PO::Description("Forcibly run WASM in interpreter mode."sv)), |
91 | 0 | ConfAFUNIX(PO::Description("Enable UNIX domain sockets"sv)), |
92 | 0 | TimeLim( |
93 | 0 | PO::Description( |
94 | 0 | "Limitation of maximum time(in milliseconds) for execution, " |
95 | 0 | "default value is 0 for no limitations"sv), |
96 | 0 | PO::MetaVar("TIMEOUT"sv), PO::DefaultValue<uint64_t>(0)), |
97 | 0 | GasLim( |
98 | 0 | PO::Description( |
99 | 0 | "Limitation of execution gas. Upper bound can be specified as " |
100 | 0 | "--gas-limit `GAS_LIMIT`."sv), |
101 | 0 | PO::MetaVar("GAS_LIMIT"sv)), |
102 | 0 | MemLim( |
103 | 0 | PO::Description( |
104 | 0 | "Limitation of pages(as size of 64 KiB) in every memory " |
105 | 0 | "instance. Upper bound can be specified as --memory-page-limit " |
106 | 0 | "`PAGE_COUNT`."sv), |
107 | 0 | PO::MetaVar("PAGE_COUNT"sv)), |
108 | 0 | ForbiddenPlugins(PO::Description("List of plugins to ignore."sv), |
109 | 0 | PO::MetaVar("NAMES"sv)) {} |
110 | | |
111 | | PO::Option<std::string> SoName; |
112 | | PO::List<std::string> Args; |
113 | | PO::Option<PO::Toggle> Reactor; |
114 | | PO::List<std::string> Dir; |
115 | | PO::List<std::string> Env; |
116 | | PO::Option<PO::Toggle> PropWASM1; |
117 | | PO::Option<PO::Toggle> PropWASM2; |
118 | | PO::Option<PO::Toggle> PropWASM3; |
119 | | PO::Option<PO::Toggle> PropMutGlobals; |
120 | | PO::Option<PO::Toggle> PropNonTrapF2IConvs; |
121 | | PO::Option<PO::Toggle> PropSignExtendOps; |
122 | | PO::Option<PO::Toggle> PropMultiValue; |
123 | | PO::Option<PO::Toggle> PropBulkMemOps; |
124 | | PO::Option<PO::Toggle> PropRefTypes; |
125 | | PO::Option<PO::Toggle> PropSIMD; |
126 | | PO::Option<PO::Toggle> PropTailCall; |
127 | | PO::Option<PO::Toggle> PropExtendConst; |
128 | | PO::Option<PO::Toggle> PropFunctionReference; |
129 | | PO::Option<PO::Toggle> PropGC; |
130 | | PO::Option<PO::Toggle> PropMultiMem; |
131 | | PO::Option<PO::Toggle> PropRelaxedSIMD; |
132 | | PO::Option<PO::Toggle> PropExceptionHandling; |
133 | | // TODO: MEMORY64 - enable the option. |
134 | | // PO::Option<PO::Toggle> PropMemory64; |
135 | | PO::Option<PO::Toggle> PropThreads; |
136 | | PO::Option<PO::Toggle> PropComponent; |
137 | | PO::Option<PO::Toggle> PropAll; |
138 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
139 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
140 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
141 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
142 | | PO::Option<PO::Toggle> ConfEnableJIT; |
143 | | PO::Option<PO::Toggle> ConfEnableCoredump; |
144 | | PO::Option<PO::Toggle> ConfCoredumpWasmgdb; |
145 | | PO::Option<PO::Toggle> ConfForceInterpreter; |
146 | | PO::Option<PO::Toggle> ConfAFUNIX; |
147 | | PO::Option<uint64_t> TimeLim; |
148 | | PO::List<int> GasLim; |
149 | | PO::List<int> MemLim; |
150 | | PO::List<std::string> ForbiddenPlugins; |
151 | | |
152 | 0 | void add_option(PO::ArgumentParser &Parser) noexcept { |
153 | |
|
154 | 0 | Parser.add_option(SoName) |
155 | 0 | .add_option(Args) |
156 | 0 | .add_option("reactor"sv, Reactor) |
157 | 0 | .add_option("dir"sv, Dir) |
158 | 0 | .add_option("env"sv, Env) |
159 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
160 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
161 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
162 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics) |
163 | 0 | .add_option("enable-jit"sv, ConfEnableJIT) |
164 | 0 | .add_option("enable-coredump"sv, ConfEnableCoredump) |
165 | 0 | .add_option("coredump-for-wasmgdb"sv, ConfCoredumpWasmgdb) |
166 | 0 | .add_option("force-interpreter"sv, ConfForceInterpreter) |
167 | 0 | .add_option("allow-af-unix"sv, ConfAFUNIX) |
168 | 0 | .add_option("wasm-1"sv, PropWASM1) |
169 | 0 | .add_option("wasm-2"sv, PropWASM2) |
170 | 0 | .add_option("wasm-3"sv, PropWASM3) |
171 | 0 | .add_option("disable-import-export-mut-globals"sv, PropMutGlobals) |
172 | 0 | .add_option("disable-non-trap-float-to-int"sv, PropNonTrapF2IConvs) |
173 | 0 | .add_option("disable-sign-extension-operators"sv, PropSignExtendOps) |
174 | 0 | .add_option("disable-multi-value"sv, PropMultiValue) |
175 | 0 | .add_option("disable-bulk-memory"sv, PropBulkMemOps) |
176 | 0 | .add_option("disable-reference-types"sv, PropRefTypes) |
177 | 0 | .add_option("disable-simd"sv, PropSIMD) |
178 | 0 | .add_option("disable-tail-call"sv, PropTailCall) |
179 | 0 | .add_option("disable-extended-const"sv, PropExtendConst) |
180 | 0 | .add_option("disable-function-reference"sv, PropFunctionReference) |
181 | 0 | .add_option("disable-gc"sv, PropGC) |
182 | 0 | .add_option("disable-multi-memory"sv, PropMultiMem) |
183 | 0 | .add_option("disable-relaxed-simd"sv, PropRelaxedSIMD) |
184 | 0 | .add_option("disable-exception-handling"sv, PropExceptionHandling) |
185 | | // TODO: MEMORY64 - enable the option. |
186 | | // .add_option("disable-memory64"sv, PropMemory64) |
187 | 0 | .add_option("disable-threads"sv, PropThreads) |
188 | 0 | .add_option("enable-component"sv, PropComponent) |
189 | 0 | .add_option("enable-all"sv, PropAll) |
190 | 0 | .add_option("time-limit"sv, TimeLim) |
191 | 0 | .add_option("gas-limit"sv, GasLim) |
192 | 0 | .add_option("memory-page-limit"sv, MemLim) |
193 | 0 | .add_option("forbidden-plugin"sv, ForbiddenPlugins); |
194 | |
|
195 | 0 | Plugin::Plugin::loadFromDefaultPaths(); |
196 | 0 | Plugin::Plugin::addPluginOptions(Parser); |
197 | 0 | } |
198 | | }; |
199 | | |
200 | | int Tool(struct DriverToolOptions &Opt) noexcept; |
201 | | |
202 | | } // namespace Driver |
203 | | } // namespace WasmEdge |