2021-04-26 08:18:13 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
|
2021-05-12 09:26:43 +00:00
|
|
|
auto result = Core::File::open(filename, Core::OpenMode::ReadOnly);
|
2021-04-26 08:18:13 +00:00
|
|
|
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!");
|
2021-04-27 11:53:36 +00:00
|
|
|
warnln("The parse error was {}", Wasm::parse_error_to_string(parse_result.error()));
|
2021-04-26 08:18:13 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|