/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.PropExceptionHandling.value()) { |
62 | 0 | Conf.removeProposal(Proposal::ExceptionHandling); |
63 | 0 | } |
64 | 0 | if (Opt.PropMemory64.value()) { |
65 | 0 | Conf.removeProposal(Proposal::Memory64); |
66 | 0 | } |
67 | | |
68 | | // Handle the proposal removal which has dependency. |
69 | | // The GC proposal depends on the func-ref proposal, and the func-ref proposal |
70 | | // depends on the ref-types proposal. |
71 | 0 | if (Opt.PropGC.value()) { |
72 | 0 | Conf.removeProposal(Proposal::GC); |
73 | 0 | } |
74 | 0 | if (Opt.PropFunctionReference.value()) { |
75 | | // This will automatically not work if the GC proposal not disabled. |
76 | 0 | Conf.removeProposal(Proposal::FunctionReferences); |
77 | 0 | } |
78 | 0 | if (Opt.PropRefTypes.value()) { |
79 | | // This will automatically not work if the GC or func-ref proposal not |
80 | | // disabled. |
81 | 0 | Conf.removeProposal(Proposal::ReferenceTypes); |
82 | 0 | } |
83 | |
|
84 | 0 | if (Opt.PropThreads.value()) { |
85 | 0 | Conf.addProposal(Proposal::Threads); |
86 | 0 | } |
87 | 0 | if (Opt.PropAll.value()) { |
88 | 0 | Conf.setWASMStandard(Standard::WASM_3); |
89 | 0 | Conf.addProposal(Proposal::Threads); |
90 | 0 | } |
91 | |
|
92 | 0 | return Conf; |
93 | 0 | } |
94 | | |
95 | 0 | Configure createConfigure(const struct DriverToolOptions &Opt) noexcept { |
96 | | // Setup logging |
97 | 0 | const std::string &Level = |
98 | 0 | Opt.LogLevel.value().empty() ? "info" : Opt.LogLevel.value(); |
99 | 0 | if (!Log::setLoggingLevelFromString(Level)) { |
100 | 0 | spdlog::warn("Invalid log level: {}. Valid values are: off, trace, debug, " |
101 | 0 | "info, warning, error, fatal. Falling back to info level."sv, |
102 | 0 | Level); |
103 | 0 | Log::setInfoLoggingLevel(); |
104 | 0 | } |
105 | |
|
106 | 0 | Configure Conf = createProposalConfigure(Opt); |
107 | |
|
108 | 0 | if (Opt.PropComponent.value()) { |
109 | 0 | Conf.addProposal(Proposal::Component); |
110 | 0 | spdlog::warn("component model is enabled, this is experimental."sv); |
111 | 0 | } |
112 | 0 | if (Opt.PropAll.value()) { |
113 | 0 | spdlog::warn("component model is enabled, this is experimental."sv); |
114 | 0 | Conf.addProposal(Proposal::Component); |
115 | 0 | } |
116 | |
|
117 | 0 | for (const auto &Name : Opt.ForbiddenPlugins.value()) { |
118 | 0 | Conf.addForbiddenPlugins(Name); |
119 | 0 | } |
120 | |
|
121 | 0 | return Conf; |
122 | 0 | } |
123 | | |
124 | | } // namespace Driver |
125 | | } // namespace WasmEdge |