/src/WasmEdge/include/driver/options.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/driver/options.h - Shared option definitions -------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the shared proposal, statistics, and logging options |
12 | | /// base structs used by both the runtime tool and the compiler tool. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | #pragma once |
16 | | #include "common/configure.h" |
17 | | #include "po/argument_parser.h" |
18 | | #include <filesystem> |
19 | | #include <optional> |
20 | | #include <string> |
21 | | #include <string_view> |
22 | | |
23 | | namespace WasmEdge { |
24 | | namespace Driver { |
25 | | |
26 | | using namespace std::literals; |
27 | | |
28 | | struct DriverProposalOptions { |
29 | | DriverProposalOptions() |
30 | 0 | : PropWASM1(PO::Description("Set as WASM 1.0 standard."sv)), |
31 | 0 | PropWASM2(PO::Description("Set as WASM 2.0 standard."sv)), |
32 | 0 | PropWASM3(PO::Description("Set as WASM 3.0 standard (default)."sv)), |
33 | 0 | PropMutGlobals(PO::Description( |
34 | 0 | "Disable Import/Export of mutable globals proposal"sv)), |
35 | 0 | PropNonTrapF2IConvs(PO::Description( |
36 | 0 | "Disable Non-trapping float-to-int conversions proposal"sv)), |
37 | 0 | PropSignExtendOps( |
38 | 0 | PO::Description("Disable Sign-extension operators proposal"sv)), |
39 | 0 | PropMultiValue(PO::Description("Disable Multi-value proposal"sv)), |
40 | 0 | PropBulkMemOps( |
41 | 0 | PO::Description("Disable Bulk memory operations proposal"sv)), |
42 | 0 | PropRefTypes(PO::Description("Disable Reference types proposal"sv)), |
43 | 0 | PropSIMD(PO::Description("Disable SIMD proposal"sv)), |
44 | 0 | PropTailCall(PO::Description("Disable Tail-call proposal"sv)), |
45 | 0 | PropExtendConst(PO::Description("Disable Extended-const proposal"sv)), |
46 | 0 | PropFunctionReference( |
47 | 0 | PO::Description("Disable Function Reference proposal"sv)), |
48 | 0 | PropGC(PO::Description("Disable GC proposal"sv)), |
49 | 0 | PropMultiMem(PO::Description("Disable Multiple memories proposal"sv)), |
50 | 0 | PropRelaxedSIMD(PO::Description("Disable Relaxed SIMD proposal"sv)), |
51 | 0 | PropExceptionHandling( |
52 | 0 | PO::Description("Disable Exception handling proposal"sv)), |
53 | 0 | PropMemory64(PO::Description("Disable Memory64 proposal"sv)), |
54 | 0 | PropThreads(PO::Description("Enable Threads proposal"sv)), |
55 | 0 | PropAll(PO::Description("Enable all features"sv)) {} |
56 | | |
57 | | PO::Option<PO::Toggle> PropWASM1; |
58 | | PO::Option<PO::Toggle> PropWASM2; |
59 | | PO::Option<PO::Toggle> PropWASM3; |
60 | | PO::Option<PO::Toggle> PropMutGlobals; |
61 | | PO::Option<PO::Toggle> PropNonTrapF2IConvs; |
62 | | PO::Option<PO::Toggle> PropSignExtendOps; |
63 | | PO::Option<PO::Toggle> PropMultiValue; |
64 | | PO::Option<PO::Toggle> PropBulkMemOps; |
65 | | PO::Option<PO::Toggle> PropRefTypes; |
66 | | PO::Option<PO::Toggle> PropSIMD; |
67 | | PO::Option<PO::Toggle> PropTailCall; |
68 | | PO::Option<PO::Toggle> PropExtendConst; |
69 | | PO::Option<PO::Toggle> PropFunctionReference; |
70 | | PO::Option<PO::Toggle> PropGC; |
71 | | PO::Option<PO::Toggle> PropMultiMem; |
72 | | PO::Option<PO::Toggle> PropRelaxedSIMD; |
73 | | PO::Option<PO::Toggle> PropExceptionHandling; |
74 | | PO::Option<PO::Toggle> PropMemory64; |
75 | | PO::Option<PO::Toggle> PropThreads; |
76 | | PO::Option<PO::Toggle> PropAll; |
77 | | |
78 | 0 | void addProposalOptions(PO::ArgumentParser &Parser) noexcept { |
79 | 0 | Parser.add_option("wasm-1"sv, PropWASM1) |
80 | 0 | .add_option("wasm-2"sv, PropWASM2) |
81 | 0 | .add_option("wasm-3"sv, PropWASM3) |
82 | 0 | .add_option("disable-import-export-mut-globals"sv, PropMutGlobals) |
83 | 0 | .add_option("disable-non-trap-float-to-int"sv, PropNonTrapF2IConvs) |
84 | 0 | .add_option("disable-sign-extension-operators"sv, PropSignExtendOps) |
85 | 0 | .add_option("disable-multi-value"sv, PropMultiValue) |
86 | 0 | .add_option("disable-bulk-memory"sv, PropBulkMemOps) |
87 | 0 | .add_option("disable-reference-types"sv, PropRefTypes) |
88 | 0 | .add_option("disable-simd"sv, PropSIMD) |
89 | 0 | .add_option("disable-tail-call"sv, PropTailCall) |
90 | 0 | .add_option("disable-extended-const"sv, PropExtendConst) |
91 | 0 | .add_option("disable-function-reference"sv, PropFunctionReference) |
92 | 0 | .add_option("disable-gc"sv, PropGC) |
93 | 0 | .add_option("disable-multi-memory"sv, PropMultiMem) |
94 | 0 | .add_option("disable-relaxed-simd"sv, PropRelaxedSIMD) |
95 | 0 | .add_option("disable-exception-handling"sv, PropExceptionHandling) |
96 | 0 | .add_option("disable-memory64"sv, PropMemory64) |
97 | 0 | .add_option("enable-threads"sv, PropThreads) |
98 | 0 | .add_option("enable-all"sv, PropAll); |
99 | 0 | } |
100 | | }; |
101 | | |
102 | | struct DriverStatisticsOptions { |
103 | | DriverStatisticsOptions() |
104 | 0 | : ConfEnableInstructionCounting(PO::Description( |
105 | 0 | "Enable generating code for counting Wasm instructions executed."sv)), |
106 | 0 | ConfEnableGasMeasuring(PO::Description( |
107 | 0 | "Enable generating code for counting gas burned during execution."sv)), |
108 | 0 | ConfEnableTimeMeasuring(PO::Description( |
109 | 0 | "Enable generating code for counting time during execution."sv)), |
110 | 0 | ConfEnableAllStatistics(PO::Description( |
111 | 0 | "Enable generating code for all statistics options include " |
112 | 0 | "instruction counting, gas measuring, and execution time."sv)) {} |
113 | | |
114 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
115 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
116 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
117 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
118 | | |
119 | 0 | void addStatisticsOptions(PO::ArgumentParser &Parser) noexcept { |
120 | 0 | Parser |
121 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
122 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
123 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
124 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics); |
125 | 0 | } |
126 | | }; |
127 | | |
128 | | struct DriverLoggingOptions { |
129 | | DriverLoggingOptions() |
130 | 0 | : LogLevel( |
131 | 0 | PO::Description( |
132 | 0 | "Set logging level. Valid values: off, trace, debug, info, " |
133 | 0 | "warning, error, fatal. Default is info."sv), |
134 | 0 | PO::MetaVar("LEVEL"sv), PO::DefaultValue(std::string())) {} |
135 | | |
136 | | PO::Option<std::string> LogLevel; |
137 | | |
138 | 0 | void addLoggingOptions(PO::ArgumentParser &Parser) noexcept { |
139 | 0 | Parser.add_option("log-level"sv, LogLevel); |
140 | 0 | } |
141 | | |
142 | | /// Take the options given before the subcommand when not set again. |
143 | 0 | void inheritLoggingOptions(const DriverLoggingOptions &Parent) noexcept { |
144 | 0 | if (LogLevel.value().empty()) { |
145 | 0 | LogLevel.value() = Parent.LogLevel.value(); |
146 | 0 | } |
147 | 0 | } |
148 | | }; |
149 | | |
150 | | Configure |
151 | | createProposalConfigure(const struct DriverProposalOptions &Opt) noexcept; |
152 | | void setLoggingLevel(const struct DriverLoggingOptions &Opt) noexcept; |
153 | | std::optional<std::filesystem::path> |
154 | | getAbsolutePath(const std::string &Name, std::string_view Kind) noexcept; |
155 | | void setStatisticsConfigure(const struct DriverStatisticsOptions &Opt, |
156 | | Configure &Conf) noexcept; |
157 | | |
158 | | } // namespace Driver |
159 | | } // namespace WasmEdge |