/src/WasmEdge/include/driver/compiler.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | //===-- wasmedge/driver/compiler.h - Compiler entrypoint ------------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contents the entrypoint for the compiler executable. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | #include "po/argument_parser.h" |
16 | | #include <string_view> |
17 | | |
18 | | namespace WasmEdge { |
19 | | namespace Driver { |
20 | | |
21 | | using namespace std::literals; |
22 | | |
23 | | struct DriverCompilerOptions { |
24 | | DriverCompilerOptions() |
25 | 0 | : WasmName(PO::Description("Wasm file"sv), PO::MetaVar("WASM"sv)), |
26 | 0 | SoName(PO::Description("Wasm so file"sv), PO::MetaVar("WASM_SO"sv)), |
27 | 0 | ConfGenericBinary(PO::Description("Generate a generic binary"sv)), |
28 | 0 | ConfDumpIR( |
29 | 0 | PO::Description("Dump LLVM IR to `wasm.ll` and `wasm-opt.ll`."sv)), |
30 | 0 | ConfInterruptible(PO::Description("Generate a interruptible binary"sv)), |
31 | 0 | ConfEnableInstructionCounting(PO::Description( |
32 | 0 | "Enable generating code for counting Wasm instructions executed."sv)), |
33 | 0 | ConfEnableGasMeasuring(PO::Description( |
34 | 0 | "Enable generating code for counting gas burned during execution."sv)), |
35 | 0 | ConfEnableTimeMeasuring(PO::Description( |
36 | 0 | "Enable generating code for counting time during execution."sv)), |
37 | 0 | ConfEnableAllStatistics(PO::Description( |
38 | 0 | "Enable generating code for all statistics options include " |
39 | 0 | "instruction counting, gas measuring, and execution time."sv)), |
40 | 0 | PropWASM1(PO::Description("Set as WASM 1.0 standard."sv)), |
41 | 0 | PropWASM2(PO::Description("Set as WASM 2.0 standard."sv)), |
42 | 0 | PropWASM3(PO::Description("Set as WASM 3.0 standard (default)."sv)), |
43 | 0 | PropMutGlobals(PO::Description( |
44 | 0 | "Disable Import/Export of mutable globals proposal"sv)), |
45 | 0 | PropNonTrapF2IConvs(PO::Description( |
46 | 0 | "Disable Non-trapping float-to-int conversions proposal"sv)), |
47 | 0 | PropSignExtendOps( |
48 | 0 | PO::Description("Disable Sign-extension operators proposal"sv)), |
49 | 0 | PropMultiValue(PO::Description("Disable Multi-value proposal"sv)), |
50 | 0 | PropBulkMemOps( |
51 | 0 | PO::Description("Disable Bulk memory operations proposal"sv)), |
52 | 0 | PropRefTypes(PO::Description("Disable Reference types proposal"sv)), |
53 | 0 | PropSIMD(PO::Description("Disable SIMD proposal"sv)), |
54 | 0 | PropTailCall(PO::Description("Disable Tail-call proposal"sv)), |
55 | 0 | PropExtendConst(PO::Description("Disable Extended-const proposal"sv)), |
56 | 0 | PropFunctionReference( |
57 | 0 | PO::Description("Disable Function Reference proposal"sv)), |
58 | 0 | PropGC(PO::Description("Disable GC proposal"sv)), |
59 | 0 | PropMultiMem(PO::Description("Disable Multiple memories proposal"sv)), |
60 | 0 | PropRelaxedSIMD(PO::Description("Disable Relaxed SIMD proposal"sv)), |
61 | | // TODO: EXCEPTION - enable the option. |
62 | | // PropExceptionHandling( |
63 | | // PO::Description("Disable Exception handling proposal"sv)), |
64 | | // TODO: MEMORY64 - enable the option. |
65 | | // PropMemory64(PO::Description("Disable Memory64 proposal"sv)), |
66 | 0 | PropThreads(PO::Description("Enable Threads proposal"sv)), |
67 | 0 | PropAll(PO::Description("Enable all features"sv)), |
68 | 0 | PropOptimizationLevel( |
69 | 0 | PO::Description("Optimization level, one of 0, 1, 2, 3, s, z."sv), |
70 | 0 | PO::DefaultValue(std::string("2"))) {} |
71 | | |
72 | | PO::Option<std::string> WasmName; |
73 | | PO::Option<std::string> SoName; |
74 | | PO::Option<PO::Toggle> ConfGenericBinary; |
75 | | PO::Option<PO::Toggle> ConfDumpIR; |
76 | | PO::Option<PO::Toggle> ConfInterruptible; |
77 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
78 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
79 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
80 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
81 | | PO::Option<PO::Toggle> PropWASM1; |
82 | | PO::Option<PO::Toggle> PropWASM2; |
83 | | PO::Option<PO::Toggle> PropWASM3; |
84 | | PO::Option<PO::Toggle> PropMutGlobals; |
85 | | PO::Option<PO::Toggle> PropNonTrapF2IConvs; |
86 | | PO::Option<PO::Toggle> PropSignExtendOps; |
87 | | PO::Option<PO::Toggle> PropMultiValue; |
88 | | PO::Option<PO::Toggle> PropBulkMemOps; |
89 | | PO::Option<PO::Toggle> PropRefTypes; |
90 | | PO::Option<PO::Toggle> PropSIMD; |
91 | | PO::Option<PO::Toggle> PropTailCall; |
92 | | PO::Option<PO::Toggle> PropExtendConst; |
93 | | PO::Option<PO::Toggle> PropFunctionReference; |
94 | | PO::Option<PO::Toggle> PropGC; |
95 | | PO::Option<PO::Toggle> PropMultiMem; |
96 | | PO::Option<PO::Toggle> PropRelaxedSIMD; |
97 | | // TODO: EXCEPTION - enable the option. |
98 | | // PO::Option<PO::Toggle> PropExceptionHandling; |
99 | | // TODO: MEMORY64 - enable the option. |
100 | | // PO::Option<PO::Toggle> PropMemory64; |
101 | | PO::Option<PO::Toggle> PropThreads; |
102 | | PO::Option<PO::Toggle> PropAll; |
103 | | PO::Option<std::string> PropOptimizationLevel; |
104 | | |
105 | 0 | void add_option(PO::ArgumentParser &Parser) noexcept { |
106 | 0 | Parser.add_option(WasmName) |
107 | 0 | .add_option(SoName) |
108 | 0 | .add_option("dump"sv, ConfDumpIR) |
109 | 0 | .add_option("interruptible"sv, ConfInterruptible) |
110 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
111 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
112 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
113 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics) |
114 | 0 | .add_option("generic-binary"sv, ConfGenericBinary) |
115 | 0 | .add_option("wasm-1"sv, PropWASM1) |
116 | 0 | .add_option("wasm-2"sv, PropWASM2) |
117 | 0 | .add_option("wasm-3"sv, PropWASM3) |
118 | 0 | .add_option("disable-import-export-mut-globals"sv, PropMutGlobals) |
119 | 0 | .add_option("disable-non-trap-float-to-int"sv, PropNonTrapF2IConvs) |
120 | 0 | .add_option("disable-sign-extension-operators"sv, PropSignExtendOps) |
121 | 0 | .add_option("disable-multi-value"sv, PropMultiValue) |
122 | 0 | .add_option("disable-bulk-memory"sv, PropBulkMemOps) |
123 | 0 | .add_option("disable-reference-types"sv, PropRefTypes) |
124 | 0 | .add_option("disable-simd"sv, PropSIMD) |
125 | 0 | .add_option("disable-tail-call"sv, PropTailCall) |
126 | 0 | .add_option("disable-extended-const"sv, PropExtendConst) |
127 | 0 | .add_option("disable-function-reference"sv, PropFunctionReference) |
128 | 0 | .add_option("disable-gc"sv, PropGC) |
129 | 0 | .add_option("disable-multi-memory"sv, PropMultiMem) |
130 | 0 | .add_option("disable-threads"sv, PropThreads) |
131 | 0 | .add_option("disable-relaxed-simd"sv, PropRelaxedSIMD) |
132 | | // TODO: EXCEPTION - enable the option. |
133 | | // .add_option("disable-exception-handling"sv, PropExceptionHandling) |
134 | | // TODO: MEMORY64 - enable the option. |
135 | | // .add_option("disable-memory64"sv, PropMemory64) |
136 | 0 | .add_option("enable-all"sv, PropAll) |
137 | 0 | .add_option("optimize"sv, PropOptimizationLevel); |
138 | 0 | } |
139 | | }; |
140 | | |
141 | | int Compiler(struct DriverCompilerOptions &Opt) noexcept; |
142 | | |
143 | | } // namespace Driver |
144 | | } // namespace WasmEdge |