mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 17:15:08 +00:00

This can currently parse a really simple module. Note that it cannot parse the DataCount section, and it's still missing almost all of the instructions. This commit also adds a 'wasm' test utility that tries to parse a given webassembly binary file. It currently does nothing but exit when the parse fails, but it's a start :^)
34 lines
939 B
C++
34 lines
939 B
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!");
|
|
return 2;
|
|
}
|
|
|
|
return 0;
|
|
}
|