/src/WasmEdge/include/driver/compiler.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright The WasmEdge Authors |
3 | | |
4 | | //===-- wasmedge/driver/compiler.h - Compiler entry point -----------------===// |
5 | | // |
6 | | // Part of the WasmEdge Project. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// This file contains the entry point for the compiler executable. |
12 | | /// |
13 | | //===----------------------------------------------------------------------===// |
14 | | #pragma once |
15 | | #include "driver/options.h" |
16 | | #include "po/argument_parser.h" |
17 | | #include <string_view> |
18 | | |
19 | | namespace WasmEdge { |
20 | | namespace Driver { |
21 | | |
22 | | using namespace std::literals; |
23 | | |
24 | | struct DriverCompilerOptions : public DriverProposalOptions { |
25 | | DriverCompilerOptions() |
26 | 0 | : WasmName(PO::Description("Wasm file"sv), PO::MetaVar("WASM"sv)), |
27 | 0 | SoName(PO::Description("Wasm so file"sv), PO::MetaVar("WASM_SO"sv)), |
28 | 0 | ConfGenericBinary(PO::Description("Generate a generic binary"sv)), |
29 | 0 | ConfDumpIR( |
30 | 0 | PO::Description("Dump LLVM IR to `wasm.ll` and `wasm-opt.ll`."sv)), |
31 | 0 | ConfInterruptible(PO::Description("Generate a interruptible binary"sv)), |
32 | 0 | ConfEnableInstructionCounting(PO::Description( |
33 | 0 | "Enable generating code for counting Wasm instructions executed."sv)), |
34 | 0 | ConfEnableGasMeasuring(PO::Description( |
35 | 0 | "Enable generating code for counting gas burned during execution."sv)), |
36 | 0 | ConfEnableTimeMeasuring(PO::Description( |
37 | 0 | "Enable generating code for counting time during execution."sv)), |
38 | 0 | ConfEnableAllStatistics(PO::Description( |
39 | 0 | "Enable generating code for all statistics options include " |
40 | 0 | "instruction counting, gas measuring, and execution time."sv)), |
41 | 0 | PropOptimizationLevel( |
42 | 0 | PO::Description("Optimization level, one of 0, 1, 2, 3, s, z."sv), |
43 | 0 | PO::DefaultValue(std::string("2"))) {} |
44 | | |
45 | | PO::Option<std::string> WasmName; |
46 | | PO::Option<std::string> SoName; |
47 | | PO::Option<PO::Toggle> ConfGenericBinary; |
48 | | PO::Option<PO::Toggle> ConfDumpIR; |
49 | | PO::Option<PO::Toggle> ConfInterruptible; |
50 | | PO::Option<PO::Toggle> ConfEnableInstructionCounting; |
51 | | PO::Option<PO::Toggle> ConfEnableGasMeasuring; |
52 | | PO::Option<PO::Toggle> ConfEnableTimeMeasuring; |
53 | | PO::Option<PO::Toggle> ConfEnableAllStatistics; |
54 | | PO::Option<std::string> PropOptimizationLevel; |
55 | | |
56 | 0 | void addOptions(PO::ArgumentParser &Parser) noexcept { |
57 | 0 | Parser.add_option(WasmName) |
58 | 0 | .add_option(SoName) |
59 | 0 | .add_option("dump"sv, ConfDumpIR) |
60 | 0 | .add_option("interruptible"sv, ConfInterruptible) |
61 | 0 | .add_option("enable-instruction-count"sv, ConfEnableInstructionCounting) |
62 | 0 | .add_option("enable-gas-measuring"sv, ConfEnableGasMeasuring) |
63 | 0 | .add_option("enable-time-measuring"sv, ConfEnableTimeMeasuring) |
64 | 0 | .add_option("enable-all-statistics"sv, ConfEnableAllStatistics) |
65 | 0 | .add_option("generic-binary"sv, ConfGenericBinary); |
66 | 0 | addProposalOptions(Parser); |
67 | | // TODO: Move exception handling option into addProposalOptions after |
68 | | // AOT mode of exception handling proposal is ready. |
69 | | // Parser.add_option("disable-exception-handling"sv, PropExceptionHandling) |
70 | 0 | Parser.add_option("optimize"sv, PropOptimizationLevel); |
71 | 0 | } |
72 | | }; |
73 | | |
74 | | int Compiler(struct DriverCompilerOptions &Opt) noexcept; |
75 | | |
76 | | } // namespace Driver |
77 | | } // namespace WasmEdge |