1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:37:36 +00:00

LibWasm: Implement parsing of the DataCount section

With this, the parser should technically be able to parse all wasm
modules. Any parse failure on correct modules should henceforth be
labelled a bug :^)
This commit is contained in:
Ali Mohammad Pur 2021-04-28 07:02:37 +04:30 committed by Linus Groh
parent bd8dac111c
commit 6e891822c5
3 changed files with 22 additions and 3 deletions

View file

@ -1066,8 +1066,16 @@ ParseResult<DataSection> DataSection::parse(InputStream& stream)
ParseResult<DataCountSection> DataCountSection::parse([[maybe_unused]] InputStream& stream)
{
ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataCountSection");
// FIXME: Implement parsing optional values!
return with_eof_check(stream, ParseError::NotImplemented);
u32 value;
if (!LEB128::read_unsigned(stream, value)) {
if (stream.unreliable_eof()) {
// The section simply didn't contain anything.
return DataCountSection { {} };
}
return ParseError::ExpectedSize;
}
return DataCountSection { value };
}
ParseResult<Module> Module::parse(InputStream& stream)
@ -1203,6 +1211,14 @@ ParseResult<Module> Module::parse(InputStream& stream)
return section.error();
}
}
case DataCountSection::section_id: {
if (auto section = DataCountSection::parse(section_stream); !section.is_error()) {
sections.append(section.release_value());
continue;
} else {
return section.error();
}
}
default:
return with_eof_check(stream, ParseError::InvalidIndex);
}

View file

@ -783,4 +783,6 @@ HashMap<Wasm::OpCode, String> Wasm::Names::instruction_names {
{ Instructions::table_grow, "table.grow" },
{ Instructions::table_size, "table.size" },
{ Instructions::table_fill, "table.fill" },
{ Instructions::structured_else, "synthetic:else" },
{ Instructions::structured_end, "synthetic:end" },
};

View file

@ -945,7 +945,8 @@ public:
StartSection,
ElementSection,
CodeSection,
DataSection>;
DataSection,
DataCountSection>;
static constexpr Array<u8, 4> wasm_magic { 0, 'a', 's', 'm' };
static constexpr Array<u8, 4> wasm_version { 1, 0, 0, 0 };