/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 "common/configure.h" |
16 | | #include "common/span.h" |
17 | | #include "common/types.h" |
18 | | #include "driver/options.h" |
19 | | #include "po/argument_parser.h" |
20 | | #include <filesystem> |
21 | | #include <string_view> |
22 | | |
23 | | namespace WasmEdge { |
24 | | namespace Driver { |
25 | | |
26 | | using namespace std::literals; |
27 | | |
28 | | struct DriverCompilerOptions : public DriverProposalOptions, |
29 | | public DriverStatisticsOptions, |
30 | | public DriverLoggingOptions { |
31 | | DriverCompilerOptions() |
32 | 0 | : WasmName(PO::Description("Wasm file"sv), PO::MetaVar("WASM"sv)), |
33 | 0 | SoName(PO::Description("Wasm so file"sv), PO::MetaVar("WASM_SO"sv)), |
34 | 0 | ConfGenericBinary(PO::Description("Generate a generic binary"sv)), |
35 | 0 | ConfDumpIR( |
36 | 0 | PO::Description("Dump LLVM IR to `wasm.ll` and `wasm-opt.ll`."sv)), |
37 | 0 | ConfInterruptible(PO::Description("Generate a interruptible binary"sv)), |
38 | 0 | PropOptimizationLevel( |
39 | 0 | PO::Description("Optimization level, one of 0, 1, 2, 3, s, z."sv), |
40 | 0 | PO::DefaultValue(std::string("2"))) {} |
41 | | |
42 | | PO::Option<std::string> WasmName; |
43 | | PO::Option<std::string> SoName; |
44 | | PO::Option<PO::Toggle> ConfGenericBinary; |
45 | | PO::Option<PO::Toggle> ConfDumpIR; |
46 | | PO::Option<PO::Toggle> ConfInterruptible; |
47 | | PO::Option<std::string> PropOptimizationLevel; |
48 | | |
49 | 0 | void addOptions(PO::ArgumentParser &Parser) noexcept { |
50 | 0 | addLoggingOptions(Parser); |
51 | 0 | Parser.add_option(WasmName) |
52 | 0 | .add_option(SoName) |
53 | 0 | .add_option("dump"sv, ConfDumpIR) |
54 | 0 | .add_option("interruptible"sv, ConfInterruptible); |
55 | 0 | addStatisticsOptions(Parser); |
56 | 0 | Parser.add_option("generic-binary"sv, ConfGenericBinary); |
57 | 0 | addProposalOptions(Parser); |
58 | 0 | Parser.add_option("optimize"sv, PropOptimizationLevel); |
59 | 0 | } |
60 | | }; |
61 | | |
62 | | int compileModule(const Configure &Conf, Span<const Byte> Data, |
63 | | const std::filesystem::path &OutputPath) noexcept; |
64 | | |
65 | | int Compiler(struct DriverCompilerOptions &Opt) noexcept; |
66 | | |
67 | | } // namespace Driver |
68 | | } // namespace WasmEdge |