ladybird/Userland/Utilities/wasm.cpp
Ali Mohammad Pur 426878c884 LibWasm: Add some more descriptive parse errors
It's much better to tell the user "hey, the magic numbers don't check
out" than "oh there was a problem with your input" :P
Also refactors some stuff to make it possible to efficiently use the
parser error enum without it getting in the way.
2021-05-08 22:14:39 +02:00

36 lines
1.0 KiB
C++

/*
* Copyright (c) 2021, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/FileStream.h>
#include <LibWasm/Types.h>
int main(int argc, char* argv[])
{
const char* filename = nullptr;
Core::ArgsParser parser;
parser.add_positional_argument(filename, "File name to parse", "file");
parser.parse(argc, argv);
auto result = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly);
if (result.is_error()) {
warnln("Failed to open {}: {}", filename, result.error());
return 1;
}
auto stream = Core::InputFileStream(result.release_value());
auto parse_result = Wasm::Module::parse(stream);
if (parse_result.is_error()) {
warnln("Something went wrong, either the file is invalid, or there's a bug with LibWasm!");
warnln("The parse error was {}", Wasm::parse_error_to_string(parse_result.error()));
return 2;
}
return 0;
}