/src/WasmEdge/lib/driver/toolConfig.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/spdlog.h" |
6 | | #include "driver/options.h" |
7 | | #include "driver/tool.h" |
8 | | |
9 | | #include <string_view> |
10 | | |
11 | | using namespace std::literals; |
12 | | |
13 | | namespace WasmEdge { |
14 | | namespace Driver { |
15 | | |
16 | | Configure |
17 | 0 | createProposalConfigure(const struct DriverProposalOptions &Opt) noexcept { |
18 | 0 | Configure Conf; |
19 | | // WASM standard configuration has the highest priority. |
20 | 0 | if (Opt.PropWASM1.value()) { |
21 | 0 | Conf.setWASMStandard(Standard::WASM_1); |
22 | 0 | } |
23 | 0 | if (Opt.PropWASM2.value()) { |
24 | 0 | Conf.setWASMStandard(Standard::WASM_2); |
25 | 0 | } |
26 | 0 | if (Opt.PropWASM3.value()) { |
27 | 0 | Conf.setWASMStandard(Standard::WASM_3); |
28 | 0 | } |
29 | | |
30 | | // Proposals adjustment. |
31 | 0 | if (Opt.PropMutGlobals.value()) { |
32 | 0 | Conf.removeProposal(Proposal::ImportExportMutGlobals); |
33 | 0 | } |
34 | 0 | if (Opt.PropNonTrapF2IConvs.value()) { |
35 | 0 | Conf.removeProposal(Proposal::NonTrapFloatToIntConversions); |
36 | 0 | } |
37 | 0 | if (Opt.PropSignExtendOps.value()) { |
38 | 0 | Conf.removeProposal(Proposal::SignExtensionOperators); |
39 | 0 | } |
40 | 0 | if (Opt.PropMultiValue.value()) { |
41 | 0 | Conf.removeProposal(Proposal::MultiValue); |
42 | 0 | } |
43 | 0 | if (Opt.PropBulkMemOps.value()) { |
44 | 0 | Conf.removeProposal(Proposal::BulkMemoryOperations); |
45 | 0 | } |
46 | 0 | if (Opt.PropSIMD.value()) { |
47 | 0 | Conf.removeProposal(Proposal::SIMD); |
48 | 0 | } |
49 | 0 | if (Opt.PropTailCall.value()) { |
50 | 0 | Conf.removeProposal(Proposal::TailCall); |
51 | 0 | } |
52 | 0 | if (Opt.PropExtendConst.value()) { |
53 | 0 | Conf.removeProposal(Proposal::ExtendedConst); |
54 | 0 | } |
55 | 0 | if (Opt.PropMultiMem.value()) { |
56 | 0 | Conf.removeProposal(Proposal::MultiMemories); |
57 | 0 | } |
58 | 0 | if (Opt.PropRelaxedSIMD.value()) { |
59 | 0 | Conf.removeProposal(Proposal::RelaxSIMD); |
60 | 0 | } |
61 | 0 | if (Opt.PropMemory64.value()) { |
62 | 0 | Conf.removeProposal(Proposal::Memory64); |
63 | 0 | } |
64 | 0 | if (Opt.PropTailCallDeprecated.value()) { |
65 | 0 | Conf.addProposal(Proposal::TailCall); |
66 | 0 | } |
67 | 0 | if (Opt.PropExtendConstDeprecated.value()) { |
68 | 0 | Conf.addProposal(Proposal::ExtendedConst); |
69 | 0 | } |
70 | 0 | if (Opt.PropMultiMemDeprecated.value()) { |
71 | 0 | Conf.addProposal(Proposal::MultiMemories); |
72 | 0 | } |
73 | 0 | if (Opt.PropRelaxedSIMDDeprecated.value()) { |
74 | 0 | Conf.addProposal(Proposal::RelaxSIMD); |
75 | 0 | } |
76 | | |
77 | | // Handle the proposal removal which has dependency. |
78 | | // The GC proposal depends on the func-ref proposal, and the func-ref proposal |
79 | | // depends on the ref-types proposal. |
80 | 0 | if (Opt.PropGC.value()) { |
81 | 0 | Conf.removeProposal(Proposal::GC); |
82 | 0 | } |
83 | 0 | if (Opt.PropFunctionReference.value()) { |
84 | | // This will automatically not work if the GC proposal not disabled. |
85 | 0 | Conf.removeProposal(Proposal::FunctionReferences); |
86 | 0 | } |
87 | 0 | if (Opt.PropRefTypes.value()) { |
88 | | // This will automatically not work if the GC or func-ref proposal not |
89 | | // disabled. |
90 | 0 | Conf.removeProposal(Proposal::ReferenceTypes); |
91 | 0 | } |
92 | 0 | if (Opt.PropFunctionReferenceDeprecated.value()) { |
93 | 0 | Conf.addProposal(Proposal::FunctionReferences); |
94 | 0 | } |
95 | 0 | if (Opt.PropGCDeprecated.value()) { |
96 | 0 | Conf.addProposal(Proposal::GC); |
97 | 0 | } |
98 | |
|
99 | 0 | if (Opt.PropThreads.value()) { |
100 | 0 | Conf.addProposal(Proposal::Threads); |
101 | 0 | } |
102 | 0 | if (Opt.PropAll.value()) { |
103 | 0 | Conf.setWASMStandard(Standard::WASM_3); |
104 | 0 | Conf.addProposal(Proposal::Threads); |
105 | 0 | } |
106 | |
|
107 | 0 | return Conf; |
108 | 0 | } |
109 | | |
110 | 0 | Configure createConfigure(const struct DriverToolOptions &Opt) noexcept { |
111 | | // Setup logging |
112 | 0 | const std::string &Level = |
113 | 0 | Opt.LogLevel.value().empty() ? "info" : Opt.LogLevel.value(); |
114 | 0 | if (!Log::setLoggingLevelFromString(Level)) { |
115 | 0 | spdlog::warn("Invalid log level: {}. Valid values are: off, trace, debug, " |
116 | 0 | "info, warning, error, fatal. Falling back to info level."sv, |
117 | 0 | Level); |
118 | 0 | Log::setInfoLoggingLevel(); |
119 | 0 | } |
120 | |
|
121 | 0 | Configure Conf = createProposalConfigure(Opt); |
122 | |
|
123 | 0 | if (Opt.PropExceptionHandling.value()) { |
124 | 0 | Conf.removeProposal(Proposal::ExceptionHandling); |
125 | 0 | } |
126 | 0 | if (Opt.PropExceptionHandlingDeprecated.value()) { |
127 | 0 | Conf.addProposal(Proposal::ExceptionHandling); |
128 | 0 | } |
129 | 0 | if (Opt.PropComponent.value()) { |
130 | 0 | Conf.addProposal(Proposal::Component); |
131 | 0 | spdlog::warn("component model is enabled, this is experimental."sv); |
132 | 0 | } |
133 | 0 | if (Opt.PropAll.value()) { |
134 | 0 | spdlog::warn("component model is enabled, this is experimental."sv); |
135 | 0 | Conf.addProposal(Proposal::Component); |
136 | 0 | } |
137 | |
|
138 | 0 | for (const auto &Name : Opt.ForbiddenPlugins.value()) { |
139 | 0 | Conf.addForbiddenPlugins(Name); |
140 | 0 | } |
141 | |
|
142 | 0 | return Conf; |
143 | 0 | } |
144 | | |
145 | | } // namespace Driver |
146 | | } // namespace WasmEdge |