mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:17:46 +00:00
LibWasm: Load and instantiate tables
This commit is a fairly large refactor, mainly because it unified the two different ways that existed to represent references. Now Reference values are also a kind of value. It also implements a printer for values/references instead of copying the implementation everywhere.
This commit is contained in:
parent
c392a0cf7f
commit
be62e4d1d7
10 changed files with 350 additions and 192 deletions
|
@ -948,7 +948,7 @@ ParseResult<ElementSection::SegmentType0> ElementSection::SegmentType0::parse(In
|
|||
if (indices.is_error())
|
||||
return indices.error();
|
||||
|
||||
return SegmentType0 { ValueType(ValueType::FunctionReference), indices.release_value(), Active { 0, expression.release_value() } };
|
||||
return SegmentType0 { indices.release_value(), Active { 0, expression.release_value() } };
|
||||
}
|
||||
|
||||
ParseResult<ElementSection::SegmentType1> ElementSection::SegmentType1::parse(InputStream& stream)
|
||||
|
@ -963,7 +963,7 @@ ParseResult<ElementSection::SegmentType1> ElementSection::SegmentType1::parse(In
|
|||
if (indices.is_error())
|
||||
return indices.error();
|
||||
|
||||
return SegmentType1 { ValueType(ValueType::FunctionReference), indices.release_value() };
|
||||
return SegmentType1 { indices.release_value() };
|
||||
}
|
||||
|
||||
ParseResult<ElementSection::SegmentType2> ElementSection::SegmentType2::parse(InputStream& stream)
|
||||
|
@ -1008,7 +1008,7 @@ ParseResult<ElementSection::SegmentType7> ElementSection::SegmentType7::parse(In
|
|||
return ParseError::NotImplemented;
|
||||
}
|
||||
|
||||
ParseResult<ElementSection::AnyElementType> ElementSection::Element::parse(InputStream& stream)
|
||||
ParseResult<ElementSection::Element> ElementSection::Element::parse(InputStream& stream)
|
||||
{
|
||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger("Element");
|
||||
u8 tag;
|
||||
|
@ -1021,49 +1021,55 @@ ParseResult<ElementSection::AnyElementType> ElementSection::Element::parse(Input
|
|||
if (auto result = SegmentType0::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
Vector<Instruction> instructions;
|
||||
for (auto& index : result.value().function_indices)
|
||||
instructions.empend(Instructions::ref_func, index);
|
||||
return Element { ValueType(ValueType::FunctionReference), { Expression { move(instructions) } }, move(result.value().mode) };
|
||||
}
|
||||
case 0x01:
|
||||
if (auto result = SegmentType1::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
Vector<Instruction> instructions;
|
||||
for (auto& index : result.value().function_indices)
|
||||
instructions.empend(Instructions::ref_func, index);
|
||||
return Element { ValueType(ValueType::FunctionReference), { Expression { move(instructions) } }, Passive {} };
|
||||
}
|
||||
case 0x02:
|
||||
if (auto result = SegmentType2::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
case 0x03:
|
||||
if (auto result = SegmentType3::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
case 0x04:
|
||||
if (auto result = SegmentType4::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
case 0x05:
|
||||
if (auto result = SegmentType5::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
case 0x06:
|
||||
if (auto result = SegmentType6::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
case 0x07:
|
||||
if (auto result = SegmentType7::parse(stream); result.is_error()) {
|
||||
return result.error();
|
||||
} else {
|
||||
return AnyElementType { result.release_value() };
|
||||
return ParseError::NotImplemented;
|
||||
}
|
||||
default:
|
||||
return ParseError::InvalidTag;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue