mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:17:34 +00:00
LibWasm+LibWeb: Parse and validate all Wasm SIMD instructions
This commit is contained in:
parent
b005691497
commit
2462064fcd
13 changed files with 2474 additions and 78 deletions
|
@ -330,6 +330,7 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
|
|||
size_t offset = 0;
|
||||
result.values().first().value().visit(
|
||||
[&](auto const& value) { offset = value; },
|
||||
[&](u128 const&) { instantiation_result = InstantiationError { "Data segment offset returned a vector type"sv }; },
|
||||
[&](Reference const&) { instantiation_result = InstantiationError { "Data segment offset returned a reference"sv }; });
|
||||
if (instantiation_result.has_value() && instantiation_result->is_error())
|
||||
return;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Result.h>
|
||||
#include <AK/StackInfo.h>
|
||||
#include <AK/UFixedBigInt.h>
|
||||
#include <LibWasm/Types.h>
|
||||
|
||||
// NOTE: Special case for Wasm::Result.
|
||||
|
@ -74,7 +75,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
using AnyValueType = Variant<i32, i64, float, double, Reference>;
|
||||
using AnyValueType = Variant<i32, i64, float, double, u128, Reference>;
|
||||
explicit Value(AnyValueType value)
|
||||
: m_value(move(value))
|
||||
{
|
||||
|
@ -111,11 +112,20 @@ public:
|
|||
VERIFY(raw_value == 0);
|
||||
m_value = Reference { Reference::Null { ValueType(ValueType::Kind::ExternReference) } };
|
||||
break;
|
||||
case ValueType::Kind::V128:
|
||||
m_value = u128(0ull, bit_cast<u64>(raw_value));
|
||||
break;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
template<SameAs<u128> T>
|
||||
explicit Value(T raw_value)
|
||||
: m_value(raw_value)
|
||||
{
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Value(Value const& value) = default;
|
||||
ALWAYS_INLINE Value(Value&& value) = default;
|
||||
ALWAYS_INLINE Value& operator=(Value&& value) = default;
|
||||
|
@ -158,6 +168,7 @@ public:
|
|||
[](i64) { return ValueType::Kind::I64; },
|
||||
[](float) { return ValueType::Kind::F32; },
|
||||
[](double) { return ValueType::Kind::F64; },
|
||||
[](u128) { return ValueType::Kind::V128; },
|
||||
[&](Reference const& type) {
|
||||
return type.ref().visit(
|
||||
[](Reference::Func const&) { return ValueType::Kind::FunctionReference; },
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -221,6 +221,17 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
template<auto... kinds>
|
||||
ErrorOr<void, ValidationError> take_and_put(Wasm::ValueType::Kind kind, SourceLocation location = SourceLocation::current())
|
||||
{
|
||||
ErrorOr<void, ValidationError> result;
|
||||
if (((result = take(Wasm::ValueType(kinds), location)).is_error(), ...)) {
|
||||
return result;
|
||||
}
|
||||
append(Wasm::ValueType(kind));
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t actual_size() const { return Vector<StackEntry>::size(); }
|
||||
size_t size() const { return m_did_insert_unknown_entry ? static_cast<size_t>(-1) : actual_size(); }
|
||||
|
||||
|
@ -238,7 +249,7 @@ public:
|
|||
};
|
||||
ErrorOr<ExpressionTypeResult, ValidationError> validate(Expression const&, Vector<ValueType> const&);
|
||||
ErrorOr<void, ValidationError> validate(Instruction const& instruction, Stack& stack, bool& is_constant);
|
||||
template<u32 opcode>
|
||||
template<u64 opcode>
|
||||
ErrorOr<void, ValidationError> validate_instruction(Instruction const&, Stack& stack, bool& is_constant);
|
||||
|
||||
// Types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue