mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-29 13:46:31 +00:00
LibWasm: Try to avoid vcalls on very busy stream read functions
This was a bottleneck when parsing, in general.
This commit is contained in:
parent
834fb0be36
commit
3f77aa8521
Notes:
github-actions[bot]
2025-08-08 10:57:01 +00:00
Author: https://github.com/alimpfard
Commit: 3f77aa8521
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5060
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/R-Goc
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gmta
2 changed files with 83 additions and 83 deletions
|
@ -35,7 +35,7 @@ ParseError with_eof_check(Stream const& stream, ParseError error_if_not_eof)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static auto parse_vector(Stream& stream)
|
static auto parse_vector(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
||||||
if constexpr (requires { T::parse(stream); }) {
|
if constexpr (requires { T::parse(stream); }) {
|
||||||
|
@ -88,7 +88,7 @@ static auto parse_vector(Stream& stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParseResult<ByteString> parse_name(Stream& stream)
|
static ParseResult<ByteString> parse_name(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
||||||
auto data = TRY(parse_vector<u8>(stream));
|
auto data = TRY(parse_vector<u8>(stream));
|
||||||
|
@ -123,14 +123,14 @@ ParseResult<ValueType> ValueType::parse(Stream& stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ResultType> ResultType::parse(Stream& stream)
|
ParseResult<ResultType> ResultType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ResultType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ResultType"sv);
|
||||||
auto types = TRY(parse_vector<ValueType>(stream));
|
auto types = TRY(parse_vector<ValueType>(stream));
|
||||||
return ResultType { types };
|
return ResultType { types };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<FunctionType> FunctionType::parse(Stream& stream)
|
ParseResult<FunctionType> FunctionType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionType"sv);
|
||||||
auto tag = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
auto tag = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
||||||
|
@ -146,7 +146,7 @@ ParseResult<FunctionType> FunctionType::parse(Stream& stream)
|
||||||
return FunctionType { parameters_result, results_result };
|
return FunctionType { parameters_result, results_result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<Limits> Limits::parse(Stream& stream)
|
ParseResult<Limits> Limits::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Limits"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Limits"sv);
|
||||||
auto flag = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
auto flag = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
||||||
|
@ -170,14 +170,14 @@ ParseResult<Limits> Limits::parse(Stream& stream)
|
||||||
return Limits { static_cast<u32>(min), move(max) };
|
return Limits { static_cast<u32>(min), move(max) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<MemoryType> MemoryType::parse(Stream& stream)
|
ParseResult<MemoryType> MemoryType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemoryType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemoryType"sv);
|
||||||
auto limits_result = TRY(Limits::parse(stream));
|
auto limits_result = TRY(Limits::parse(stream));
|
||||||
return MemoryType { limits_result };
|
return MemoryType { limits_result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<TableType> TableType::parse(Stream& stream)
|
ParseResult<TableType> TableType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableType"sv);
|
||||||
auto type_result = TRY(ValueType::parse(stream));
|
auto type_result = TRY(ValueType::parse(stream));
|
||||||
|
@ -187,7 +187,7 @@ ParseResult<TableType> TableType::parse(Stream& stream)
|
||||||
return TableType { type_result, limits_result };
|
return TableType { type_result, limits_result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<GlobalType> GlobalType::parse(Stream& stream)
|
ParseResult<GlobalType> GlobalType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalType"sv);
|
||||||
auto type_result = TRY(ValueType::parse(stream));
|
auto type_result = TRY(ValueType::parse(stream));
|
||||||
|
@ -199,7 +199,7 @@ ParseResult<GlobalType> GlobalType::parse(Stream& stream)
|
||||||
return GlobalType { type_result, mutable_ == 0x01 };
|
return GlobalType { type_result, mutable_ == 0x01 };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<BlockType> BlockType::parse(Stream& stream)
|
ParseResult<BlockType> BlockType::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("BlockType"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("BlockType"sv);
|
||||||
auto kind = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
auto kind = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
||||||
|
@ -228,10 +228,12 @@ ParseResult<BlockType> BlockType::parse(Stream& stream)
|
||||||
return BlockType { TypeIndex(index_value) };
|
return BlockType { TypeIndex(index_value) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<Instruction> Instruction::parse(Stream& stream)
|
ParseResult<Instruction> Instruction::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Instruction"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Instruction"sv);
|
||||||
auto byte = TRY_READ(stream, u8, ParseError::ExpectedKindTag);
|
u8 byte;
|
||||||
|
if (auto result = stream.read_some({ &byte, 1 }); result.is_error() || result.value().size() != 1)
|
||||||
|
return ParseError::ExpectedKindTag;
|
||||||
|
|
||||||
OpCode opcode { byte };
|
OpCode opcode { byte };
|
||||||
|
|
||||||
|
@ -858,38 +860,36 @@ ParseResult<Instruction> Instruction::parse(Stream& stream)
|
||||||
return ParseError::UnknownInstruction;
|
return ParseError::UnknownInstruction;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<CustomSection> CustomSection::parse(Stream& stream)
|
ParseResult<CustomSection> CustomSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("CustomSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("CustomSection"sv);
|
||||||
auto name = TRY(parse_name(stream));
|
auto name = TRY(parse_name(stream));
|
||||||
|
auto remaining = stream.remaining();
|
||||||
ByteBuffer data_buffer;
|
auto maybe_data_buffer = ByteBuffer::create_uninitialized(remaining);
|
||||||
if (data_buffer.try_resize(64).is_error())
|
if (maybe_data_buffer.is_error())
|
||||||
return ParseError::OutOfMemory;
|
return ParseError::OutOfMemory;
|
||||||
|
auto data_buffer = maybe_data_buffer.release_value();
|
||||||
|
|
||||||
while (!stream.is_eof()) {
|
size_t nread = 0;
|
||||||
char buf[16];
|
do {
|
||||||
auto span_or_error = stream.read_some({ buf, 16 });
|
auto read = MUST(stream.read_some(data_buffer.bytes().slice(nread)));
|
||||||
if (span_or_error.is_error())
|
nread += read.size();
|
||||||
break;
|
} while (nread != remaining && !stream.is_eof());
|
||||||
auto size = span_or_error.release_value().size();
|
|
||||||
if (size == 0)
|
if (nread != remaining)
|
||||||
break;
|
return ParseError::UnexpectedEof;
|
||||||
if (data_buffer.try_append(buf, size).is_error())
|
|
||||||
return ParseError::HugeAllocationRequested;
|
|
||||||
}
|
|
||||||
|
|
||||||
return CustomSection(name, move(data_buffer));
|
return CustomSection(name, move(data_buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<TypeSection> TypeSection::parse(Stream& stream)
|
ParseResult<TypeSection> TypeSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TypeSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TypeSection"sv);
|
||||||
auto types = TRY(parse_vector<FunctionType>(stream));
|
auto types = TRY(parse_vector<FunctionType>(stream));
|
||||||
return TypeSection { types };
|
return TypeSection { types };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ImportSection::Import> ImportSection::Import::parse(Stream& stream)
|
ParseResult<ImportSection::Import> ImportSection::Import::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Import"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Import"sv);
|
||||||
auto module = TRY(parse_name(stream));
|
auto module = TRY(parse_name(stream));
|
||||||
|
@ -912,14 +912,14 @@ ParseResult<ImportSection::Import> ImportSection::Import::parse(Stream& stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ImportSection> ImportSection::parse(Stream& stream)
|
ParseResult<ImportSection> ImportSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ImportSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ImportSection"sv);
|
||||||
auto imports = TRY(parse_vector<Import>(stream));
|
auto imports = TRY(parse_vector<Import>(stream));
|
||||||
return ImportSection { imports };
|
return ImportSection { imports };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<FunctionSection> FunctionSection::parse(Stream& stream)
|
ParseResult<FunctionSection> FunctionSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("FunctionSection"sv);
|
||||||
auto indices = TRY(parse_vector<u32>(stream));
|
auto indices = TRY(parse_vector<u32>(stream));
|
||||||
|
@ -932,35 +932,35 @@ ParseResult<FunctionSection> FunctionSection::parse(Stream& stream)
|
||||||
return FunctionSection { move(typed_indices) };
|
return FunctionSection { move(typed_indices) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<TableSection::Table> TableSection::Table::parse(Stream& stream)
|
ParseResult<TableSection::Table> TableSection::Table::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Table"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Table"sv);
|
||||||
auto type = TRY(TableType::parse(stream));
|
auto type = TRY(TableType::parse(stream));
|
||||||
return Table { type };
|
return Table { type };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<TableSection> TableSection::parse(Stream& stream)
|
ParseResult<TableSection> TableSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("TableSection"sv);
|
||||||
auto tables = TRY(parse_vector<Table>(stream));
|
auto tables = TRY(parse_vector<Table>(stream));
|
||||||
return TableSection { tables };
|
return TableSection { tables };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<MemorySection::Memory> MemorySection::Memory::parse(Stream& stream)
|
ParseResult<MemorySection::Memory> MemorySection::Memory::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Memory"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Memory"sv);
|
||||||
auto type = TRY(MemoryType::parse(stream));
|
auto type = TRY(MemoryType::parse(stream));
|
||||||
return Memory { type };
|
return Memory { type };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<MemorySection> MemorySection::parse(Stream& stream)
|
ParseResult<MemorySection> MemorySection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemorySection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("MemorySection"sv);
|
||||||
auto memories = TRY(parse_vector<Memory>(stream));
|
auto memories = TRY(parse_vector<Memory>(stream));
|
||||||
return MemorySection { memories };
|
return MemorySection { memories };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<Expression> Expression::parse(Stream& stream, Optional<size_t> size_hint)
|
ParseResult<Expression> Expression::parse(ConstrainedStream& stream, Optional<size_t> size_hint)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Expression"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Expression"sv);
|
||||||
|
|
||||||
|
@ -1002,7 +1002,7 @@ ParseResult<Expression> Expression::parse(Stream& stream, Optional<size_t> size_
|
||||||
return Expression { move(instructions) };
|
return Expression { move(instructions) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<GlobalSection::Global> GlobalSection::Global::parse(Stream& stream)
|
ParseResult<GlobalSection::Global> GlobalSection::Global::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Global"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Global"sv);
|
||||||
auto type = TRY(GlobalType::parse(stream));
|
auto type = TRY(GlobalType::parse(stream));
|
||||||
|
@ -1010,14 +1010,14 @@ ParseResult<GlobalSection::Global> GlobalSection::Global::parse(Stream& stream)
|
||||||
return Global { type, exprs };
|
return Global { type, exprs };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<GlobalSection> GlobalSection::parse(Stream& stream)
|
ParseResult<GlobalSection> GlobalSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("GlobalSection"sv);
|
||||||
auto result = TRY(parse_vector<Global>(stream));
|
auto result = TRY(parse_vector<Global>(stream));
|
||||||
return GlobalSection { result };
|
return GlobalSection { result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ExportSection::Export> ExportSection::Export::parse(Stream& stream)
|
ParseResult<ExportSection::Export> ExportSection::Export::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Export"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Export"sv);
|
||||||
auto name = TRY(parse_name(stream));
|
auto name = TRY(parse_name(stream));
|
||||||
|
@ -1039,28 +1039,28 @@ ParseResult<ExportSection::Export> ExportSection::Export::parse(Stream& stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ExportSection> ExportSection::parse(Stream& stream)
|
ParseResult<ExportSection> ExportSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ExportSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ExportSection"sv);
|
||||||
auto result = TRY(parse_vector<Export>(stream));
|
auto result = TRY(parse_vector<Export>(stream));
|
||||||
return ExportSection { result };
|
return ExportSection { result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<StartSection::StartFunction> StartSection::StartFunction::parse(Stream& stream)
|
ParseResult<StartSection::StartFunction> StartSection::StartFunction::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartFunction"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartFunction"sv);
|
||||||
auto index = TRY(GenericIndexParser<FunctionIndex>::parse(stream));
|
auto index = TRY(GenericIndexParser<FunctionIndex>::parse(stream));
|
||||||
return StartFunction { index };
|
return StartFunction { index };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<StartSection> StartSection::parse(Stream& stream)
|
ParseResult<StartSection> StartSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("StartSection"sv);
|
||||||
auto result = TRY(StartFunction::parse(stream));
|
auto result = TRY(StartFunction::parse(stream));
|
||||||
return StartSection { result };
|
return StartSection { result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ElementSection::Element> ElementSection::Element::parse(Stream& stream)
|
ParseResult<ElementSection::Element> ElementSection::Element::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Element"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Element"sv);
|
||||||
auto tag = TRY_READ(stream, LEB128<u32>, ParseError::ExpectedKindTag);
|
auto tag = TRY_READ(stream, LEB128<u32>, ParseError::ExpectedKindTag);
|
||||||
|
@ -1116,14 +1116,14 @@ ParseResult<ElementSection::Element> ElementSection::Element::parse(Stream& stre
|
||||||
return Element { type, move(items), move(mode) };
|
return Element { type, move(items), move(mode) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<ElementSection> ElementSection::parse(Stream& stream)
|
ParseResult<ElementSection> ElementSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ElementSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("ElementSection"sv);
|
||||||
auto result = TRY(parse_vector<Element>(stream));
|
auto result = TRY(parse_vector<Element>(stream));
|
||||||
return ElementSection { result };
|
return ElementSection { result };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<Locals> Locals::parse(Stream& stream)
|
ParseResult<Locals> Locals::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Locals"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Locals"sv);
|
||||||
auto count = TRY_READ(stream, LEB128<u32>, ParseError::InvalidSize);
|
auto count = TRY_READ(stream, LEB128<u32>, ParseError::InvalidSize);
|
||||||
|
@ -1136,7 +1136,7 @@ ParseResult<Locals> Locals::parse(Stream& stream)
|
||||||
return Locals { count, type };
|
return Locals { count, type };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<CodeSection::Func> CodeSection::Func::parse(Stream& stream, size_t size_hint)
|
ParseResult<CodeSection::Func> CodeSection::Func::parse(ConstrainedStream& stream, size_t size_hint)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Func"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Func"sv);
|
||||||
auto locals = TRY(parse_vector<Locals>(stream));
|
auto locals = TRY(parse_vector<Locals>(stream));
|
||||||
|
@ -1144,7 +1144,7 @@ ParseResult<CodeSection::Func> CodeSection::Func::parse(Stream& stream, size_t s
|
||||||
return Func { move(locals), move(body) };
|
return Func { move(locals), move(body) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<CodeSection::Code> CodeSection::Code::parse(Stream& stream)
|
ParseResult<CodeSection::Code> CodeSection::Code::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Code"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Code"sv);
|
||||||
auto size = TRY_READ(stream, LEB128<u32>, ParseError::InvalidSize);
|
auto size = TRY_READ(stream, LEB128<u32>, ParseError::InvalidSize);
|
||||||
|
@ -1156,14 +1156,14 @@ ParseResult<CodeSection::Code> CodeSection::Code::parse(Stream& stream)
|
||||||
return Code { size, move(func) };
|
return Code { size, move(func) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<CodeSection> CodeSection::parse(Stream& stream)
|
ParseResult<CodeSection> CodeSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("CodeSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("CodeSection"sv);
|
||||||
auto result = TRY(parse_vector<Code>(stream));
|
auto result = TRY(parse_vector<Code>(stream));
|
||||||
return CodeSection { move(result) };
|
return CodeSection { move(result) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<DataSection::Data> DataSection::Data::parse(Stream& stream)
|
ParseResult<DataSection::Data> DataSection::Data::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Data"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Data"sv);
|
||||||
auto tag = TRY_READ(stream, LEB128<u32>, ParseError::ExpectedKindTag);
|
auto tag = TRY_READ(stream, LEB128<u32>, ParseError::ExpectedKindTag);
|
||||||
|
@ -1189,14 +1189,14 @@ ParseResult<DataSection::Data> DataSection::Data::parse(Stream& stream)
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<DataSection> DataSection::parse(Stream& stream)
|
ParseResult<DataSection> DataSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataSection"sv);
|
||||||
auto data = TRY(parse_vector<Data>(stream));
|
auto data = TRY(parse_vector<Data>(stream));
|
||||||
return DataSection { data };
|
return DataSection { data };
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseResult<DataCountSection> DataCountSection::parse([[maybe_unused]] Stream& stream)
|
ParseResult<DataCountSection> DataCountSection::parse(ConstrainedStream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataCountSection"sv);
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger("DataCountSection"sv);
|
||||||
auto value_or_error = stream.read_value<LEB128<u32>>();
|
auto value_or_error = stream.read_value<LEB128<u32>>();
|
||||||
|
|
|
@ -217,7 +217,7 @@ public:
|
||||||
|
|
||||||
auto const& types() const { return m_types; }
|
auto const& types() const { return m_types; }
|
||||||
|
|
||||||
static ParseResult<ResultType> parse(Stream& stream);
|
static ParseResult<ResultType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<ValueType> m_types;
|
Vector<ValueType> m_types;
|
||||||
|
@ -235,7 +235,7 @@ public:
|
||||||
auto& parameters() const { return m_parameters; }
|
auto& parameters() const { return m_parameters; }
|
||||||
auto& results() const { return m_results; }
|
auto& results() const { return m_results; }
|
||||||
|
|
||||||
static ParseResult<FunctionType> parse(Stream& stream);
|
static ParseResult<FunctionType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<ValueType> m_parameters;
|
Vector<ValueType> m_parameters;
|
||||||
|
@ -259,7 +259,7 @@ public:
|
||||||
&& (!other.max().has_value() || (m_max.has_value() && *m_max <= *other.max()));
|
&& (!other.max().has_value() || (m_max.has_value() && *m_max <= *other.max()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParseResult<Limits> parse(Stream& stream);
|
static ParseResult<Limits> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_min { 0 };
|
u32 m_min { 0 };
|
||||||
|
@ -276,7 +276,7 @@ public:
|
||||||
|
|
||||||
auto& limits() const { return m_limits; }
|
auto& limits() const { return m_limits; }
|
||||||
|
|
||||||
static ParseResult<MemoryType> parse(Stream& stream);
|
static ParseResult<MemoryType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Limits m_limits;
|
Limits m_limits;
|
||||||
|
@ -295,7 +295,7 @@ public:
|
||||||
auto& limits() const { return m_limits; }
|
auto& limits() const { return m_limits; }
|
||||||
auto& element_type() const { return m_element_type; }
|
auto& element_type() const { return m_element_type; }
|
||||||
|
|
||||||
static ParseResult<TableType> parse(Stream& stream);
|
static ParseResult<TableType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueType m_element_type;
|
ValueType m_element_type;
|
||||||
|
@ -314,7 +314,7 @@ public:
|
||||||
auto& type() const { return m_type; }
|
auto& type() const { return m_type; }
|
||||||
auto is_mutable() const { return m_is_mutable; }
|
auto is_mutable() const { return m_is_mutable; }
|
||||||
|
|
||||||
static ParseResult<GlobalType> parse(Stream& stream);
|
static ParseResult<GlobalType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ValueType m_type;
|
ValueType m_type;
|
||||||
|
@ -360,7 +360,7 @@ public:
|
||||||
return m_type_index;
|
return m_type_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParseResult<BlockType> parse(Stream& stream);
|
static ParseResult<BlockType> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Kind m_kind { Empty };
|
Kind m_kind { Empty };
|
||||||
|
@ -461,7 +461,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParseResult<Instruction> parse(Stream& stream);
|
static ParseResult<Instruction> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
auto& opcode() const { return m_opcode; }
|
auto& opcode() const { return m_opcode; }
|
||||||
auto& arguments() const { return m_arguments; }
|
auto& arguments() const { return m_arguments; }
|
||||||
|
@ -543,7 +543,7 @@ public:
|
||||||
auto& name() const { return m_name; }
|
auto& name() const { return m_name; }
|
||||||
auto& contents() const { return m_contents; }
|
auto& contents() const { return m_contents; }
|
||||||
|
|
||||||
static ParseResult<CustomSection> parse(Stream& stream);
|
static ParseResult<CustomSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ByteString m_name;
|
ByteString m_name;
|
||||||
|
@ -561,7 +561,7 @@ public:
|
||||||
|
|
||||||
auto& types() const { return m_types; }
|
auto& types() const { return m_types; }
|
||||||
|
|
||||||
static ParseResult<TypeSection> parse(Stream& stream);
|
static ParseResult<TypeSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<FunctionType> m_types;
|
Vector<FunctionType> m_types;
|
||||||
|
@ -583,7 +583,7 @@ public:
|
||||||
auto& name() const { return m_name; }
|
auto& name() const { return m_name; }
|
||||||
auto& description() const { return m_description; }
|
auto& description() const { return m_description; }
|
||||||
|
|
||||||
static ParseResult<Import> parse(Stream& stream);
|
static ParseResult<Import> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -608,7 +608,7 @@ public:
|
||||||
|
|
||||||
auto& imports() const { return m_imports; }
|
auto& imports() const { return m_imports; }
|
||||||
|
|
||||||
static ParseResult<ImportSection> parse(Stream& stream);
|
static ParseResult<ImportSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Import> m_imports;
|
Vector<Import> m_imports;
|
||||||
|
@ -625,7 +625,7 @@ public:
|
||||||
|
|
||||||
auto& types() const { return m_types; }
|
auto& types() const { return m_types; }
|
||||||
|
|
||||||
static ParseResult<FunctionSection> parse(Stream& stream);
|
static ParseResult<FunctionSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<TypeIndex> m_types;
|
Vector<TypeIndex> m_types;
|
||||||
|
@ -642,7 +642,7 @@ public:
|
||||||
|
|
||||||
auto& type() const { return m_type; }
|
auto& type() const { return m_type; }
|
||||||
|
|
||||||
static ParseResult<Table> parse(Stream& stream);
|
static ParseResult<Table> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TableType m_type;
|
TableType m_type;
|
||||||
|
@ -658,7 +658,7 @@ public:
|
||||||
|
|
||||||
auto& tables() const { return m_tables; }
|
auto& tables() const { return m_tables; }
|
||||||
|
|
||||||
static ParseResult<TableSection> parse(Stream& stream);
|
static ParseResult<TableSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Table> m_tables;
|
Vector<Table> m_tables;
|
||||||
|
@ -675,7 +675,7 @@ public:
|
||||||
|
|
||||||
auto& type() const { return m_type; }
|
auto& type() const { return m_type; }
|
||||||
|
|
||||||
static ParseResult<Memory> parse(Stream& stream);
|
static ParseResult<Memory> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MemoryType m_type;
|
MemoryType m_type;
|
||||||
|
@ -691,7 +691,7 @@ public:
|
||||||
|
|
||||||
auto& memories() const { return m_memories; }
|
auto& memories() const { return m_memories; }
|
||||||
|
|
||||||
static ParseResult<MemorySection> parse(Stream& stream);
|
static ParseResult<MemorySection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Memory> m_memories;
|
Vector<Memory> m_memories;
|
||||||
|
@ -706,7 +706,7 @@ public:
|
||||||
|
|
||||||
auto& instructions() const { return m_instructions; }
|
auto& instructions() const { return m_instructions; }
|
||||||
|
|
||||||
static ParseResult<Expression> parse(Stream& stream, Optional<size_t> size_hint = {});
|
static ParseResult<Expression> parse(ConstrainedStream& stream, Optional<size_t> size_hint = {});
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Instruction> m_instructions;
|
Vector<Instruction> m_instructions;
|
||||||
|
@ -725,7 +725,7 @@ public:
|
||||||
auto& type() const { return m_type; }
|
auto& type() const { return m_type; }
|
||||||
auto& expression() const { return m_expression; }
|
auto& expression() const { return m_expression; }
|
||||||
|
|
||||||
static ParseResult<Global> parse(Stream& stream);
|
static ParseResult<Global> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GlobalType m_type;
|
GlobalType m_type;
|
||||||
|
@ -742,7 +742,7 @@ public:
|
||||||
|
|
||||||
auto& entries() const { return m_entries; }
|
auto& entries() const { return m_entries; }
|
||||||
|
|
||||||
static ParseResult<GlobalSection> parse(Stream& stream);
|
static ParseResult<GlobalSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Global> m_entries;
|
Vector<Global> m_entries;
|
||||||
|
@ -764,7 +764,7 @@ public:
|
||||||
auto& name() const { return m_name; }
|
auto& name() const { return m_name; }
|
||||||
auto& description() const { return m_description; }
|
auto& description() const { return m_description; }
|
||||||
|
|
||||||
static ParseResult<Export> parse(Stream& stream);
|
static ParseResult<Export> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ByteString m_name;
|
ByteString m_name;
|
||||||
|
@ -780,7 +780,7 @@ public:
|
||||||
|
|
||||||
auto& entries() const { return m_entries; }
|
auto& entries() const { return m_entries; }
|
||||||
|
|
||||||
static ParseResult<ExportSection> parse(Stream& stream);
|
static ParseResult<ExportSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Export> m_entries;
|
Vector<Export> m_entries;
|
||||||
|
@ -797,7 +797,7 @@ public:
|
||||||
|
|
||||||
auto& index() const { return m_index; }
|
auto& index() const { return m_index; }
|
||||||
|
|
||||||
static ParseResult<StartFunction> parse(Stream& stream);
|
static ParseResult<StartFunction> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FunctionIndex m_index;
|
FunctionIndex m_index;
|
||||||
|
@ -812,7 +812,7 @@ public:
|
||||||
|
|
||||||
auto& function() const { return m_function; }
|
auto& function() const { return m_function; }
|
||||||
|
|
||||||
static ParseResult<StartSection> parse(Stream& stream);
|
static ParseResult<StartSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<StartFunction> m_function;
|
Optional<StartFunction> m_function;
|
||||||
|
@ -830,7 +830,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Element {
|
struct Element {
|
||||||
static ParseResult<Element> parse(Stream&);
|
static ParseResult<Element> parse(ConstrainedStream&);
|
||||||
|
|
||||||
ValueType type;
|
ValueType type;
|
||||||
Vector<Expression> init;
|
Vector<Expression> init;
|
||||||
|
@ -846,7 +846,7 @@ public:
|
||||||
|
|
||||||
auto& segments() const { return m_segments; }
|
auto& segments() const { return m_segments; }
|
||||||
|
|
||||||
static ParseResult<ElementSection> parse(Stream& stream);
|
static ParseResult<ElementSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Element> m_segments;
|
Vector<Element> m_segments;
|
||||||
|
@ -864,7 +864,7 @@ public:
|
||||||
auto n() const { return m_n; }
|
auto n() const { return m_n; }
|
||||||
auto& type() const { return m_type; }
|
auto& type() const { return m_type; }
|
||||||
|
|
||||||
static ParseResult<Locals> parse(Stream& stream);
|
static ParseResult<Locals> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_n { 0 };
|
u32 m_n { 0 };
|
||||||
|
@ -885,7 +885,7 @@ public:
|
||||||
auto& locals() const { return m_locals; }
|
auto& locals() const { return m_locals; }
|
||||||
auto& body() const { return m_body; }
|
auto& body() const { return m_body; }
|
||||||
|
|
||||||
static ParseResult<Func> parse(Stream& stream, size_t size_hint);
|
static ParseResult<Func> parse(ConstrainedStream& stream, size_t size_hint);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Locals> m_locals;
|
Vector<Locals> m_locals;
|
||||||
|
@ -902,7 +902,7 @@ public:
|
||||||
auto size() const { return m_size; }
|
auto size() const { return m_size; }
|
||||||
auto& func() const { return m_func; }
|
auto& func() const { return m_func; }
|
||||||
|
|
||||||
static ParseResult<Code> parse(Stream& stream);
|
static ParseResult<Code> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_size { 0 };
|
u32 m_size { 0 };
|
||||||
|
@ -918,7 +918,7 @@ public:
|
||||||
|
|
||||||
auto& functions() const { return m_functions; }
|
auto& functions() const { return m_functions; }
|
||||||
|
|
||||||
static ParseResult<CodeSection> parse(Stream& stream);
|
static ParseResult<CodeSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Code> m_functions;
|
Vector<Code> m_functions;
|
||||||
|
@ -945,7 +945,7 @@ public:
|
||||||
|
|
||||||
auto& value() const { return m_value; }
|
auto& value() const { return m_value; }
|
||||||
|
|
||||||
static ParseResult<Data> parse(Stream& stream);
|
static ParseResult<Data> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Value m_value;
|
Value m_value;
|
||||||
|
@ -960,7 +960,7 @@ public:
|
||||||
|
|
||||||
auto& data() const { return m_data; }
|
auto& data() const { return m_data; }
|
||||||
|
|
||||||
static ParseResult<DataSection> parse(Stream& stream);
|
static ParseResult<DataSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<Data> m_data;
|
Vector<Data> m_data;
|
||||||
|
@ -977,7 +977,7 @@ public:
|
||||||
|
|
||||||
auto& count() const { return m_count; }
|
auto& count() const { return m_count; }
|
||||||
|
|
||||||
static ParseResult<DataCountSection> parse(Stream& stream);
|
static ParseResult<DataCountSection> parse(ConstrainedStream& stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Optional<u32> m_count;
|
Optional<u32> m_count;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue