mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibWasm: Replace usages of the Endian bytes accessor
This commit is contained in:
parent
e11e7309dd
commit
547a08670e
|
@ -207,10 +207,9 @@ template<>
|
|||
struct ConvertToRaw<float> {
|
||||
u32 operator()(float value)
|
||||
{
|
||||
LittleEndian<u32> res;
|
||||
ReadonlyBytes bytes { &value, sizeof(float) };
|
||||
FixedMemoryStream stream { bytes };
|
||||
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
auto res = stream.read_value<LittleEndian<u32>>().release_value_but_fixme_should_propagate_errors();
|
||||
return static_cast<u32>(res);
|
||||
}
|
||||
};
|
||||
|
@ -219,10 +218,9 @@ template<>
|
|||
struct ConvertToRaw<double> {
|
||||
u64 operator()(double value)
|
||||
{
|
||||
LittleEndian<u64> res;
|
||||
ReadonlyBytes bytes { &value, sizeof(double) };
|
||||
FixedMemoryStream stream { bytes };
|
||||
stream.read_until_filled(res.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
auto res = stream.read_value<LittleEndian<u64>>().release_value_but_fixme_should_propagate_errors();
|
||||
return static_cast<u64>(res);
|
||||
}
|
||||
};
|
||||
|
@ -258,35 +256,34 @@ void BytecodeInterpreter::store_to_memory(Configuration& configuration, Instruct
|
|||
template<typename T>
|
||||
T BytecodeInterpreter::read_value(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<T> value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_until_filled(value.bytes());
|
||||
if (maybe_error.is_error()) {
|
||||
auto value_or_error = stream.read_value<LittleEndian<T>>();
|
||||
if (value_or_error.is_error()) {
|
||||
dbgln("Read from {} failed", data.data());
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
}
|
||||
return value;
|
||||
return value_or_error.release_value();
|
||||
}
|
||||
|
||||
template<>
|
||||
float BytecodeInterpreter::read_value<float>(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<u32> raw_value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_until_filled(raw_value.bytes());
|
||||
if (maybe_error.is_error())
|
||||
auto raw_value_or_error = stream.read_value<LittleEndian<u32>>();
|
||||
if (raw_value_or_error.is_error())
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
auto raw_value = raw_value_or_error.release_value();
|
||||
return bit_cast<float>(static_cast<u32>(raw_value));
|
||||
}
|
||||
|
||||
template<>
|
||||
double BytecodeInterpreter::read_value<double>(ReadonlyBytes data)
|
||||
{
|
||||
LittleEndian<u64> raw_value;
|
||||
FixedMemoryStream stream { data };
|
||||
auto maybe_error = stream.read_until_filled(raw_value.bytes());
|
||||
if (maybe_error.is_error())
|
||||
auto raw_value_or_error = stream.read_value<LittleEndian<u64>>();
|
||||
if (raw_value_or_error.is_error())
|
||||
m_trap = Trap { "Read from memory failed" };
|
||||
auto raw_value = raw_value_or_error.release_value();
|
||||
return bit_cast<double>(static_cast<u64>(raw_value));
|
||||
}
|
||||
|
||||
|
|
|
@ -486,9 +486,10 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
|
|||
}
|
||||
case Instructions::f32_const.value(): {
|
||||
// op literal
|
||||
LittleEndian<u32> value;
|
||||
if (stream.read_until_filled(value.bytes()).is_error())
|
||||
auto value_or_error = stream.read_value<LittleEndian<u32>>();
|
||||
if (value_or_error.is_error())
|
||||
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
|
||||
auto value = value_or_error.release_value();
|
||||
|
||||
auto floating = bit_cast<float>(static_cast<u32>(value));
|
||||
resulting_instructions.append(Instruction { opcode, floating });
|
||||
|
@ -496,9 +497,10 @@ ParseResult<Vector<Instruction>> Instruction::parse(Stream& stream, InstructionP
|
|||
}
|
||||
case Instructions::f64_const.value(): {
|
||||
// op literal
|
||||
LittleEndian<u64> value;
|
||||
if (stream.read_until_filled(value.bytes()).is_error())
|
||||
auto value_or_error = stream.read_value<LittleEndian<u64>>();
|
||||
if (value_or_error.is_error())
|
||||
return with_eof_check(stream, ParseError::ExpectedFloatingImmediate);
|
||||
auto value = value_or_error.release_value();
|
||||
|
||||
auto floating = bit_cast<double>(static_cast<u64>(value));
|
||||
resulting_instructions.append(Instruction { opcode, floating });
|
||||
|
|
Loading…
Reference in a new issue