mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +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:
parent
bd8dac111c
commit
6e891822c5
3 changed files with 22 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue