| 13 | namespace Driver { |
| 14 | |
| 15 | int FuzzTool(const uint8_t *Data, size_t Size) noexcept { |
| 16 | using namespace std::literals; |
| 17 | std::ios::sync_with_stdio(false); |
| 18 | spdlog::set_level(spdlog::level::critical); |
| 19 | |
| 20 | Configure Conf; |
| 21 | Conf.getRuntimeConfigure().setRunMode(WasmEdge::RunMode::Interpreter); |
| 22 | Loader::Loader Loader(Conf); |
| 23 | |
| 24 | std::unique_ptr<AST::Module> Module; |
| 25 | if (auto Res = Loader.parseModule(Span<const uint8_t>(Data, Size))) { |
| 26 | Module = std::move(*Res); |
| 27 | } else { |
| 28 | const auto Err = static_cast<uint32_t>(Res.error()); |
| 29 | spdlog::error("Parse Module failed. Error code: {}"sv, Err); |
| 30 | return EXIT_FAILURE; |
| 31 | } |
| 32 | |
| 33 | { |
| 34 | Validator::Validator ValidatorEngine(Conf); |
| 35 | if (auto Res = ValidatorEngine.validate(*Module); !Res) { |
| 36 | const auto Err = static_cast<uint32_t>(Res.error()); |
| 37 | spdlog::error("Validate Module failed. Error code: {}"sv, Err); |
| 38 | return EXIT_FAILURE; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | LLVM::Compiler Compiler(Conf); |
| 43 | if (auto Res = Compiler.checkConfigure(); !Res) { |
| 44 | const auto Err = static_cast<uint32_t>(Res.error()); |
| 45 | spdlog::error("Compiler Configure failed. Error code: {}"sv, Err); |
| 46 | } |
| 47 | |
| 48 | LLVM::CodeGen CodeGen(Conf); |
| 49 | if (auto Res = Compiler.compile(*Module); !Res) { |
| 50 | const auto Err = static_cast<uint32_t>(Res.error()); |
| 51 | spdlog::error("Compilation failed. Error code: {}"sv, Err); |
| 52 | return EXIT_FAILURE; |
| 53 | } else if (auto Res2 = CodeGen.codegen(Span<const uint8_t>(Data, Size), |
| 54 | std::move(*Res), "/dev/null"sv); |
| 55 | !Res2) { |
| 56 | const auto Err = static_cast<uint32_t>(Res2.error()); |
| 57 | spdlog::error("Code Generation failed. Error code: {}"sv, Err); |
| 58 | return EXIT_FAILURE; |
| 59 | } |
| 60 | |
| 61 | return EXIT_SUCCESS; |
| 62 | } |
| 63 | |
| 64 | } // namespace Driver |
| 65 | } // namespace WasmEdge |
no test coverage detected