/src/WasmEdge/include/driver/compiler.h
Line | Count | Source (jump to first uncovered line) |
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( |
38 | 0 | PO::Description("Enable generating code for all statistics options " |
39 | 0 | "include instruction " |
40 | 0 | "counting, gas measuring, and execution time"sv)), |
41 | 0 | PropMutGlobals(PO::Description( |
42 | 0 | "Disable Import/Export of mutable globals proposal"sv)), |
43 | 0 | PropNonTrapF2IConvs(PO::Description( |
44 | 0 | "Disable Non-trapping float-to-int conversions proposal"sv)), |
45 | 0 | PropSignExtendOps( |
46 | 0 | PO::Description("Disable Sign-extension operators proposal"sv)), |
47 | 0 | PropMultiValue(PO::Description("Disable Multi-value proposal"sv)), |
48 | 0 | PropBulkMemOps( |
49 | 0 | PO::Description("Disable Bulk memory operations proposal"sv)), |
50 | 0 | PropRefTypes(PO::Description("Disable Reference types proposal"sv)), |
51 | 0 | PropSIMD(PO::Description("Disable SIMD proposal"sv)), |
52 | 0 | PropTailCall(PO::Description("Enable Tail-call proposal"sv)), |
53 | 0 | PropExtendConst(PO::Description("Enable Extended-const proposal"sv)), |
54 | 0 | PropFunctionReference( |
55 | 0 | PO::Description("Enable Function Reference proposal"sv)), |
56 | 0 | PropMultiMem(PO::Description("Enable Multiple memories proposal"sv)), |
57 | 0 | PropThreads(PO::Description("Enable Threads proposal"sv)), |
58 | 0 | PropRelaxedSIMD(PO::Description("Enable Relaxed SIMD proposal"sv)), |
59 | 0 | PropAll(PO::Description("Enable all features"sv)), |
60 | 0 | PropOptimizationLevel( |
61 | 0 | PO::Description("Optimization level, one of 0, 1, 2, 3, s, z."sv), |
62 | 0 | PO::DefaultValue(std::string("2"))) {} |
63 | | |
64 | | PO::Option<std::string> WasmName; |
65 | | PO::Option<std::string> SoName; |
66 | | PO::Option<PO::Toggle> ConfGenericBinary; |
67 | | PO::Option<PO::Toggle> ConfDumpIR; |
68 | | PO::Option<PO::Toggle> ConfInterruptible; |
69 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
70 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
71 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
72 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
73 | | PO::Option<PO::Toggle> PropMutGlobals; |
74 | | PO::Option<PO::Toggle> PropNonTrapF2IConvs; |
75 | | PO::Option<PO::Toggle> PropSignExtendOps; |
76 | | PO::Option<PO::Toggle> PropMultiValue; |
77 | | PO::Option<PO::Toggle> PropBulkMemOps; |
78 | | PO::Option<PO::Toggle> PropRefTypes; |
79 | | PO::Option<PO::Toggle> PropSIMD; |
80 | | PO::Option<PO::Toggle> PropTailCall; |
81 | | PO::Option<PO::Toggle> PropExtendConst; |
82 | | PO::Option<PO::Toggle> PropFunctionReference; |
83 | | PO::Option<PO::Toggle> PropMultiMem; |
84 | | PO::Option<PO::Toggle> PropThreads; |
85 | | PO::Option<PO::Toggle> PropRelaxedSIMD; |
86 | | PO::Option<PO::Toggle> PropAll; |
87 | | PO::Option<std::string> PropOptimizationLevel; |
88 | | |
89 | 0 | void add_option(PO::ArgumentParser &Parser) noexcept { |
90 | 0 | Parser.add_option(WasmName) |
91 | 0 | .add_option(SoName) |
92 | 0 | .add_option("dump"sv, ConfDumpIR) |
93 | 0 | .add_option("interruptible"sv, ConfInterruptible) |
94 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
95 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
96 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
97 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics) |
98 | 0 | .add_option("generic-binary"sv, ConfGenericBinary) |
99 | 0 | .add_option("disable-import-export-mut-globals"sv, PropMutGlobals) |
100 | 0 | .add_option("disable-non-trap-float-to-int"sv, PropNonTrapF2IConvs) |
101 | 0 | .add_option("disable-sign-extension-operators"sv, PropSignExtendOps) |
102 | 0 | .add_option("disable-multi-value"sv, PropMultiValue) |
103 | 0 | .add_option("disable-bulk-memory"sv, PropBulkMemOps) |
104 | 0 | .add_option("disable-reference-types"sv, PropRefTypes) |
105 | 0 | .add_option("disable-simd"sv, PropSIMD) |
106 | 0 | .add_option("enable-tail-call"sv, PropTailCall) |
107 | 0 | .add_option("enable-extended-const"sv, PropExtendConst) |
108 | 0 | .add_option("enable-function-reference"sv, PropFunctionReference) |
109 | 0 | .add_option("enable-multi-memory"sv, PropMultiMem) |
110 | 0 | .add_option("enable-threads"sv, PropThreads) |
111 | 0 | .add_option("enable-relaxed-simd"sv, PropRelaxedSIMD) |
112 | 0 | .add_option("enable-all"sv, PropAll) |
113 | 0 | .add_option("optimize"sv, PropOptimizationLevel); |
114 | 0 | } |
115 | | }; |
116 | | |
117 | | int Compiler(struct DriverCompilerOptions &Opt) noexcept; |
118 | | |
119 | | } // namespace Driver |
120 | | } // namespace WasmEdge |