Source code

Revision control

Copy as Markdown

Other Tools

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
*
* Copyright 2016 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wasm/WasmValidate.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Utf8.h"
#include "js/Printf.h"
#include "js/String.h" // JS::MaxStringLength
#include "vm/JSContext.h"
#include "vm/Realm.h"
#include "wasm/WasmOpIter.h"
using namespace js;
using namespace js::jit;
using namespace js::wasm;
using mozilla::AsChars;
using mozilla::CheckedInt;
using mozilla::CheckedInt32;
using mozilla::IsUtf8;
using mozilla::Span;
// Misc helpers.
bool wasm::EncodeLocalEntries(Encoder& e, const ValTypeVector& locals) {
if (locals.length() > MaxLocals) {
return false;
}
uint32_t numLocalEntries = 0;
if (locals.length()) {
ValType prev = locals[0];
numLocalEntries++;
for (ValType t : locals) {
if (t != prev) {
numLocalEntries++;
prev = t;
}
}
}
if (!e.writeVarU32(numLocalEntries)) {
return false;
}
if (numLocalEntries) {
ValType prev = locals[0];
uint32_t count = 1;
for (uint32_t i = 1; i < locals.length(); i++, count++) {
if (prev != locals[i]) {
if (!e.writeVarU32(count)) {
return false;
}
if (!e.writeValType(prev)) {
return false;
}
prev = locals[i];
count = 0;
}
}
if (!e.writeVarU32(count)) {
return false;
}
if (!e.writeValType(prev)) {
return false;
}
}
return true;
}
bool wasm::DecodeLocalEntries(Decoder& d, const TypeContext& types,
const FeatureArgs& features,
ValTypeVector* locals) {
uint32_t numLocalEntries;
if (!d.readVarU32(&numLocalEntries)) {
return d.fail("failed to read number of local entries");
}
for (uint32_t i = 0; i < numLocalEntries; i++) {
uint32_t count;
if (!d.readVarU32(&count)) {
return d.fail("failed to read local entry count");
}
if (MaxLocals - locals->length() < count) {
return d.fail("too many locals");
}
ValType type;
if (!d.readValType(types, features, &type)) {
return false;
}
if (!type.isDefaultable()) {
return d.fail("cannot have a non-defaultable local");
}
if (!locals->appendN(type, count)) {
return false;
}
}
return true;
}
bool wasm::DecodeValidatedLocalEntries(Decoder& d, ValTypeVector* locals) {
uint32_t numLocalEntries;
MOZ_ALWAYS_TRUE(d.readVarU32(&numLocalEntries));
for (uint32_t i = 0; i < numLocalEntries; i++) {
uint32_t count = d.uncheckedReadVarU32();
MOZ_ASSERT(MaxLocals - locals->length() >= count);
if (!locals->appendN(d.uncheckedReadValType(), count)) {
return false;
}
}
return true;
}
bool wasm::CheckIsSubtypeOf(Decoder& d, const ModuleEnvironment& env,
size_t opcodeOffset, ValType actual,
ValType expected, TypeCache* cache) {
switch (env.types->isSubtypeOf(actual, expected, cache)) {
case TypeResult::OOM:
return false;
case TypeResult::True:
return true;
case TypeResult::False: {
UniqueChars actualText = ToString(actual);
if (!actualText) {
return false;
}
UniqueChars expectedText = ToString(expected);
if (!expectedText) {
return false;
}
UniqueChars error(
JS_smprintf("type mismatch: expression has type %s but expected %s",
actualText.get(), expectedText.get()));
if (!error) {
return false;
}
return d.fail(opcodeOffset, error.get());
}
default:
MOZ_CRASH();
}
}
// Function body validation.
static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env,
uint32_t funcIndex,
const ValTypeVector& locals,
const uint8_t* bodyEnd, Decoder* d) {
ValidatingOpIter iter(env, *d);
if (!iter.startFunction(funcIndex)) {
return false;
}
#define CHECK(c) \
if (!(c)) return false; \
break
while (true) {
OpBytes op;
if (!iter.readOp(&op)) {
return false;
}
Nothing nothing;
NothingVector nothings{};
ResultType unusedType;
switch (op.b0) {
case uint16_t(Op::End): {
LabelKind unusedKind;
if (!iter.readEnd(&unusedKind, &unusedType, &nothings, &nothings)) {
return false;
}
iter.popEnd();
if (iter.controlStackEmpty()) {
return iter.endFunction(bodyEnd);
}
break;
}
case uint16_t(Op::Nop):
CHECK(iter.readNop());
case uint16_t(Op::Drop):
CHECK(iter.readDrop());
case uint16_t(Op::Call): {
uint32_t unusedIndex;
NothingVector unusedArgs{};
CHECK(iter.readCall(&unusedIndex, &unusedArgs));
}
case uint16_t(Op::CallIndirect): {
uint32_t unusedIndex, unusedIndex2;
NothingVector unusedArgs{};
CHECK(iter.readCallIndirect(&unusedIndex, &unusedIndex2, &nothing,
&unusedArgs));
}
case uint16_t(Op::I32Const): {
int32_t unused;
CHECK(iter.readI32Const(&unused));
}
case uint16_t(Op::I64Const): {
int64_t unused;
CHECK(iter.readI64Const(&unused));
}
case uint16_t(Op::F32Const): {
float unused;
CHECK(iter.readF32Const(&unused));
}
case uint16_t(Op::F64Const): {
double unused;
CHECK(iter.readF64Const(&unused));
}
case uint16_t(Op::LocalGet): {
uint32_t unused;
CHECK(iter.readGetLocal(locals, &unused));
}
case uint16_t(Op::LocalSet): {
uint32_t unused;
CHECK(iter.readSetLocal(locals, &unused, &nothing));
}
case uint16_t(Op::LocalTee): {
uint32_t unused;
CHECK(iter.readTeeLocal(locals, &unused, &nothing));
}
case uint16_t(Op::GlobalGet): {
uint32_t unused;
CHECK(iter.readGetGlobal(&unused));
}
case uint16_t(Op::GlobalSet): {
uint32_t unused;
CHECK(iter.readSetGlobal(&unused, &nothing));
}
case uint16_t(Op::TableGet): {
uint32_t unusedTableIndex;
CHECK(iter.readTableGet(&unusedTableIndex, &nothing));
}
case uint16_t(Op::TableSet): {
uint32_t unusedTableIndex;
CHECK(iter.readTableSet(&unusedTableIndex, &nothing, &nothing));
}
case uint16_t(Op::SelectNumeric): {
StackType unused;
CHECK(iter.readSelect(/*typed*/ false, &unused, &nothing, &nothing,
&nothing));
}
case uint16_t(Op::SelectTyped): {
StackType unused;
CHECK(iter.readSelect(/*typed*/ true, &unused, &nothing, &nothing,
&nothing));
}
case uint16_t(Op::Block):
CHECK(iter.readBlock(&unusedType));
case uint16_t(Op::Loop):
CHECK(iter.readLoop(&unusedType));
case uint16_t(Op::If):
CHECK(iter.readIf(&unusedType, &nothing));
case uint16_t(Op::Else):
CHECK(iter.readElse(&unusedType, &unusedType, &nothings));
case uint16_t(Op::I32Clz):
case uint16_t(Op::I32Ctz):
case uint16_t(Op::I32Popcnt):
CHECK(iter.readUnary(ValType::I32, &nothing));
case uint16_t(Op::I64Clz):
case uint16_t(Op::I64Ctz):
case uint16_t(Op::I64Popcnt):
CHECK(iter.readUnary(ValType::I64, &nothing));
case uint16_t(Op::F32Abs):
case uint16_t(Op::F32Neg):
case uint16_t(Op::F32Ceil):
case uint16_t(Op::F32Floor):
case uint16_t(Op::F32Sqrt):
case uint16_t(Op::F32Trunc):
case uint16_t(Op::F32Nearest):
CHECK(iter.readUnary(ValType::F32, &nothing));
case uint16_t(Op::F64Abs):
case uint16_t(Op::F64Neg):
case uint16_t(Op::F64Ceil):
case uint16_t(Op::F64Floor):
case uint16_t(Op::F64Sqrt):
case uint16_t(Op::F64Trunc):
case uint16_t(Op::F64Nearest):
CHECK(iter.readUnary(ValType::F64, &nothing));
case uint16_t(Op::I32Add):
case uint16_t(Op::I32Sub):
case uint16_t(Op::I32Mul):
case uint16_t(Op::I32DivS):
case uint16_t(Op::I32DivU):
case uint16_t(Op::I32RemS):
case uint16_t(Op::I32RemU):
case uint16_t(Op::I32And):
case uint16_t(Op::I32Or):
case uint16_t(Op::I32Xor):
case uint16_t(Op::I32Shl):
case uint16_t(Op::I32ShrS):
case uint16_t(Op::I32ShrU):
case uint16_t(Op::I32Rotl):
case uint16_t(Op::I32Rotr):
CHECK(iter.readBinary(ValType::I32, &nothing, &nothing));
case uint16_t(Op::I64Add):
case uint16_t(Op::I64Sub):
case uint16_t(Op::I64Mul):
case uint16_t(Op::I64DivS):
case uint16_t(Op::I64DivU):
case uint16_t(Op::I64RemS):
case uint16_t(Op::I64RemU):
case uint16_t(Op::I64And):
case uint16_t(Op::I64Or):
case uint16_t(Op::I64Xor):
case uint16_t(Op::I64Shl):
case uint16_t(Op::I64ShrS):
case uint16_t(Op::I64ShrU):
case uint16_t(Op::I64Rotl):
case uint16_t(Op::I64Rotr):
CHECK(iter.readBinary(ValType::I64, &nothing, &nothing));
case uint16_t(Op::F32Add):
case uint16_t(Op::F32Sub):
case uint16_t(Op::F32Mul):
case uint16_t(Op::F32Div):
case uint16_t(Op::F32Min):
case uint16_t(Op::F32Max):
case uint16_t(Op::F32CopySign):
CHECK(iter.readBinary(ValType::F32, &nothing, &nothing));
case uint16_t(Op::F64Add):
case uint16_t(Op::F64Sub):
case uint16_t(Op::F64Mul):
case uint16_t(Op::F64Div):
case uint16_t(Op::F64Min):
case uint16_t(Op::F64Max):
case uint16_t(Op::F64CopySign):
CHECK(iter.readBinary(ValType::F64, &nothing, &nothing));
case uint16_t(Op::I32Eq):
case uint16_t(Op::I32Ne):
case uint16_t(Op::I32LtS):
case uint16_t(Op::I32LtU):
case uint16_t(Op::I32LeS):
case uint16_t(Op::I32LeU):
case uint16_t(Op::I32GtS):
case uint16_t(Op::I32GtU):
case uint16_t(Op::I32GeS):
case uint16_t(Op::I32GeU):
CHECK(iter.readComparison(ValType::I32, &nothing, &nothing));
case uint16_t(Op::I64Eq):
case uint16_t(Op::I64Ne):
case uint16_t(Op::I64LtS):
case uint16_t(Op::I64LtU):
case uint16_t(Op::I64LeS):
case uint16_t(Op::I64LeU):
case uint16_t(Op::I64GtS):
case uint16_t(Op::I64GtU):
case uint16_t(Op::I64GeS):
case uint16_t(Op::I64GeU):
CHECK(iter.readComparison(ValType::I64, &nothing, &nothing));
case uint16_t(Op::F32Eq):
case uint16_t(Op::F32Ne):
case uint16_t(Op::F32Lt):
case uint16_t(Op::F32Le):
case uint16_t(Op::F32Gt):
case uint16_t(Op::F32Ge):
CHECK(iter.readComparison(ValType::F32, &nothing, &nothing));
case uint16_t(Op::F64Eq):
case uint16_t(Op::F64Ne):
case uint16_t(Op::F64Lt):
case uint16_t(Op::F64Le):
case uint16_t(Op::F64Gt):
case uint16_t(Op::F64Ge):
CHECK(iter.readComparison(ValType::F64, &nothing, &nothing));
case uint16_t(Op::I32Eqz):
CHECK(iter.readConversion(ValType::I32, ValType::I32, &nothing));
case uint16_t(Op::I64Eqz):
case uint16_t(Op::I32WrapI64):
CHECK(iter.readConversion(ValType::I64, ValType::I32, &nothing));
case uint16_t(Op::I32TruncF32S):
case uint16_t(Op::I32TruncF32U):
case uint16_t(Op::I32ReinterpretF32):
CHECK(iter.readConversion(ValType::F32, ValType::I32, &nothing));
case uint16_t(Op::I32TruncF64S):
case uint16_t(Op::I32TruncF64U):
CHECK(iter.readConversion(ValType::F64, ValType::I32, &nothing));
case uint16_t(Op::I64ExtendI32S):
case uint16_t(Op::I64ExtendI32U):
CHECK(iter.readConversion(ValType::I32, ValType::I64, &nothing));
case uint16_t(Op::I64TruncF32S):
case uint16_t(Op::I64TruncF32U):
CHECK(iter.readConversion(ValType::F32, ValType::I64, &nothing));
case uint16_t(Op::I64TruncF64S):
case uint16_t(Op::I64TruncF64U):
case uint16_t(Op::I64ReinterpretF64):
CHECK(iter.readConversion(ValType::F64, ValType::I64, &nothing));
case uint16_t(Op::F32ConvertI32S):
case uint16_t(Op::F32ConvertI32U):
case uint16_t(Op::F32ReinterpretI32):
CHECK(iter.readConversion(ValType::I32, ValType::F32, &nothing));
case uint16_t(Op::F32ConvertI64S):
case uint16_t(Op::F32ConvertI64U):
CHECK(iter.readConversion(ValType::I64, ValType::F32, &nothing));
case uint16_t(Op::F32DemoteF64):
CHECK(iter.readConversion(ValType::F64, ValType::F32, &nothing));
case uint16_t(Op::F64ConvertI32S):
case uint16_t(Op::F64ConvertI32U):
CHECK(iter.readConversion(ValType::I32, ValType::F64, &nothing));
case uint16_t(Op::F64ConvertI64S):
case uint16_t(Op::F64ConvertI64U):
case uint16_t(Op::F64ReinterpretI64):
CHECK(iter.readConversion(ValType::I64, ValType::F64, &nothing));
case uint16_t(Op::F64PromoteF32):
CHECK(iter.readConversion(ValType::F32, ValType::F64, &nothing));
case uint16_t(Op::I32Extend8S):
case uint16_t(Op::I32Extend16S):
CHECK(iter.readConversion(ValType::I32, ValType::I32, &nothing));
case uint16_t(Op::I64Extend8S):
case uint16_t(Op::I64Extend16S):
case uint16_t(Op::I64Extend32S):
CHECK(iter.readConversion(ValType::I64, ValType::I64, &nothing));
case uint16_t(Op::I32Load8S):
case uint16_t(Op::I32Load8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I32, 1, &addr));
}
case uint16_t(Op::I32Load16S):
case uint16_t(Op::I32Load16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I32, 2, &addr));
}
case uint16_t(Op::I32Load): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I32, 4, &addr));
}
case uint16_t(Op::I64Load8S):
case uint16_t(Op::I64Load8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I64, 1, &addr));
}
case uint16_t(Op::I64Load16S):
case uint16_t(Op::I64Load16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I64, 2, &addr));
}
case uint16_t(Op::I64Load32S):
case uint16_t(Op::I64Load32U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I64, 4, &addr));
}
case uint16_t(Op::I64Load): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::I64, 8, &addr));
}
case uint16_t(Op::F32Load): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::F32, 4, &addr));
}
case uint16_t(Op::F64Load): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::F64, 8, &addr));
}
case uint16_t(Op::I32Store8): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I32, 1, &addr, &nothing));
}
case uint16_t(Op::I32Store16): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I32, 2, &addr, &nothing));
}
case uint16_t(Op::I32Store): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I32, 4, &addr, &nothing));
}
case uint16_t(Op::I64Store8): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I64, 1, &addr, &nothing));
}
case uint16_t(Op::I64Store16): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I64, 2, &addr, &nothing));
}
case uint16_t(Op::I64Store32): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I64, 4, &addr, &nothing));
}
case uint16_t(Op::I64Store): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::I64, 8, &addr, &nothing));
}
case uint16_t(Op::F32Store): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::F32, 4, &addr, &nothing));
}
case uint16_t(Op::F64Store): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::F64, 8, &addr, &nothing));
}
case uint16_t(Op::MemoryGrow):
CHECK(iter.readMemoryGrow(&nothing));
case uint16_t(Op::MemorySize):
CHECK(iter.readMemorySize());
case uint16_t(Op::Br): {
uint32_t unusedDepth;
CHECK(iter.readBr(&unusedDepth, &unusedType, &nothings));
}
case uint16_t(Op::BrIf): {
uint32_t unusedDepth;
CHECK(iter.readBrIf(&unusedDepth, &unusedType, &nothings, &nothing));
}
case uint16_t(Op::BrTable): {
Uint32Vector unusedDepths;
uint32_t unusedDefault;
CHECK(iter.readBrTable(&unusedDepths, &unusedDefault, &unusedType,
&nothings, &nothing));
}
case uint16_t(Op::Return):
CHECK(iter.readReturn(&nothings));
case uint16_t(Op::Unreachable):
CHECK(iter.readUnreachable());
#ifdef ENABLE_WASM_GC
case uint16_t(Op::GcPrefix): {
if (!env.gcEnabled()) {
return iter.unrecognizedOpcode(&op);
}
switch (op.b1) {
case uint32_t(GcOp::StructNewWithRtt): {
uint32_t unusedUint;
NothingVector unusedArgs{};
CHECK(
iter.readStructNewWithRtt(&unusedUint, &nothing, &unusedArgs));
}
case uint32_t(GcOp::StructNewDefaultWithRtt): {
uint32_t unusedUint;
CHECK(iter.readStructNewDefaultWithRtt(&unusedUint, &nothing));
}
case uint32_t(GcOp::StructGet): {
uint32_t unusedUint1, unusedUint2;
CHECK(iter.readStructGet(&unusedUint1, &unusedUint2,
FieldExtension::None, &nothing));
}
case uint32_t(GcOp::StructGetS): {
uint32_t unusedUint1, unusedUint2;
CHECK(iter.readStructGet(&unusedUint1, &unusedUint2,
FieldExtension::Signed, &nothing));
}
case uint32_t(GcOp::StructGetU): {
uint32_t unusedUint1, unusedUint2;
CHECK(iter.readStructGet(&unusedUint1, &unusedUint2,
FieldExtension::Unsigned, &nothing));
}
case uint32_t(GcOp::StructSet): {
uint32_t unusedUint1, unusedUint2;
CHECK(iter.readStructSet(&unusedUint1, &unusedUint2, &nothing,
&nothing));
}
case uint32_t(GcOp::ArrayNewWithRtt): {
uint32_t unusedUint;
CHECK(iter.readArrayNewWithRtt(&unusedUint, &nothing, &nothing,
&nothing));
}
case uint32_t(GcOp::ArrayNewDefaultWithRtt): {
uint32_t unusedUint;
CHECK(iter.readArrayNewDefaultWithRtt(&unusedUint, &nothing,
&nothing));
}
case uint32_t(GcOp::ArrayGet): {
uint32_t unusedUint1;
CHECK(iter.readArrayGet(&unusedUint1, FieldExtension::None,
&nothing, &nothing));
}
case uint32_t(GcOp::ArrayGetS): {
uint32_t unusedUint1;
CHECK(iter.readArrayGet(&unusedUint1, FieldExtension::Signed,
&nothing, &nothing));
}
case uint32_t(GcOp::ArrayGetU): {
uint32_t unusedUint1;
CHECK(iter.readArrayGet(&unusedUint1, FieldExtension::Unsigned,
&nothing, &nothing));
}
case uint32_t(GcOp::ArraySet): {
uint32_t unusedUint1;
CHECK(
iter.readArraySet(&unusedUint1, &nothing, &nothing, &nothing));
}
case uint32_t(GcOp::ArrayLen): {
uint32_t unusedUint1;
CHECK(iter.readArrayLen(&unusedUint1, &nothing));
}
case uint16_t(GcOp::RttCanon): {
ValType unusedTy;
CHECK(iter.readRttCanon(&unusedTy));
}
case uint16_t(GcOp::RttSub): {
uint32_t unusedRttTypeIndex;
CHECK(iter.readRttSub(&nothing, &unusedRttTypeIndex));
}
case uint16_t(GcOp::RefTest): {
uint32_t unusedRttTypeIndex;
uint32_t unusedRttDepth;
CHECK(iter.readRefTest(&nothing, &unusedRttTypeIndex,
&unusedRttDepth, &nothing));
}
case uint16_t(GcOp::RefCast): {
uint32_t unusedRttTypeIndex;
uint32_t unusedRttDepth;
CHECK(iter.readRefCast(&nothing, &unusedRttTypeIndex,
&unusedRttDepth, &nothing));
}
case uint16_t(GcOp::BrOnCast): {
uint32_t unusedRelativeDepth;
uint32_t unusedRttTypeIndex;
uint32_t unusedRttDepth;
CHECK(iter.readBrOnCast(&unusedRelativeDepth, &nothing,
&unusedRttTypeIndex, &unusedRttDepth,
&unusedType, &nothings));
}
default:
return iter.unrecognizedOpcode(&op);
}
break;
}
#endif
#ifdef ENABLE_WASM_SIMD
case uint16_t(Op::SimdPrefix): {
if (!env.v128Enabled()) {
return iter.unrecognizedOpcode(&op);
}
uint32_t noIndex;
switch (op.b1) {
case uint32_t(SimdOp::I8x16ExtractLaneS):
case uint32_t(SimdOp::I8x16ExtractLaneU):
CHECK(iter.readExtractLane(ValType::I32, 16, &noIndex, &nothing));
case uint32_t(SimdOp::I16x8ExtractLaneS):
case uint32_t(SimdOp::I16x8ExtractLaneU):
CHECK(iter.readExtractLane(ValType::I32, 8, &noIndex, &nothing));
case uint32_t(SimdOp::I32x4ExtractLane):
CHECK(iter.readExtractLane(ValType::I32, 4, &noIndex, &nothing));
case uint32_t(SimdOp::I64x2ExtractLane):
CHECK(iter.readExtractLane(ValType::I64, 2, &noIndex, &nothing));
case uint32_t(SimdOp::F32x4ExtractLane):
CHECK(iter.readExtractLane(ValType::F32, 4, &noIndex, &nothing));
case uint32_t(SimdOp::F64x2ExtractLane):
CHECK(iter.readExtractLane(ValType::F64, 2, &noIndex, &nothing));
case uint32_t(SimdOp::I8x16Splat):
case uint32_t(SimdOp::I16x8Splat):
case uint32_t(SimdOp::I32x4Splat):
CHECK(iter.readConversion(ValType::I32, ValType::V128, &nothing));
case uint32_t(SimdOp::I64x2Splat):
CHECK(iter.readConversion(ValType::I64, ValType::V128, &nothing));
case uint32_t(SimdOp::F32x4Splat):
CHECK(iter.readConversion(ValType::F32, ValType::V128, &nothing));
case uint32_t(SimdOp::F64x2Splat):
CHECK(iter.readConversion(ValType::F64, ValType::V128, &nothing));
case uint32_t(SimdOp::V128AnyTrue):
case uint32_t(SimdOp::I8x16AllTrue):
case uint32_t(SimdOp::I16x8AllTrue):
case uint32_t(SimdOp::I32x4AllTrue):
case uint32_t(SimdOp::I64x2AllTrue):
case uint32_t(SimdOp::I8x16Bitmask):
case uint32_t(SimdOp::I16x8Bitmask):
case uint32_t(SimdOp::I32x4Bitmask):
case uint32_t(SimdOp::I64x2Bitmask):
CHECK(iter.readConversion(ValType::V128, ValType::I32, &nothing));
case uint32_t(SimdOp::I8x16ReplaceLane):
CHECK(iter.readReplaceLane(ValType::I32, 16, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::I16x8ReplaceLane):
CHECK(iter.readReplaceLane(ValType::I32, 8, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::I32x4ReplaceLane):
CHECK(iter.readReplaceLane(ValType::I32, 4, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::I64x2ReplaceLane):
CHECK(iter.readReplaceLane(ValType::I64, 2, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::F32x4ReplaceLane):
CHECK(iter.readReplaceLane(ValType::F32, 4, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::F64x2ReplaceLane):
CHECK(iter.readReplaceLane(ValType::F64, 2, &noIndex, &nothing,
&nothing));
case uint32_t(SimdOp::I8x16Eq):
case uint32_t(SimdOp::I8x16Ne):
case uint32_t(SimdOp::I8x16LtS):
case uint32_t(SimdOp::I8x16LtU):
case uint32_t(SimdOp::I8x16GtS):
case uint32_t(SimdOp::I8x16GtU):
case uint32_t(SimdOp::I8x16LeS):
case uint32_t(SimdOp::I8x16LeU):
case uint32_t(SimdOp::I8x16GeS):
case uint32_t(SimdOp::I8x16GeU):
case uint32_t(SimdOp::I16x8Eq):
case uint32_t(SimdOp::I16x8Ne):
case uint32_t(SimdOp::I16x8LtS):
case uint32_t(SimdOp::I16x8LtU):
case uint32_t(SimdOp::I16x8GtS):
case uint32_t(SimdOp::I16x8GtU):
case uint32_t(SimdOp::I16x8LeS):
case uint32_t(SimdOp::I16x8LeU):
case uint32_t(SimdOp::I16x8GeS):
case uint32_t(SimdOp::I16x8GeU):
case uint32_t(SimdOp::I32x4Eq):
case uint32_t(SimdOp::I32x4Ne):
case uint32_t(SimdOp::I32x4LtS):
case uint32_t(SimdOp::I32x4LtU):
case uint32_t(SimdOp::I32x4GtS):
case uint32_t(SimdOp::I32x4GtU):
case uint32_t(SimdOp::I32x4LeS):
case uint32_t(SimdOp::I32x4LeU):
case uint32_t(SimdOp::I32x4GeS):
case uint32_t(SimdOp::I32x4GeU):
case uint32_t(SimdOp::I64x2Eq):
case uint32_t(SimdOp::I64x2Ne):
case uint32_t(SimdOp::I64x2LtS):
case uint32_t(SimdOp::I64x2GtS):
case uint32_t(SimdOp::I64x2LeS):
case uint32_t(SimdOp::I64x2GeS):
case uint32_t(SimdOp::F32x4Eq):
case uint32_t(SimdOp::F32x4Ne):
case uint32_t(SimdOp::F32x4Lt):
case uint32_t(SimdOp::F32x4Gt):
case uint32_t(SimdOp::F32x4Le):
case uint32_t(SimdOp::F32x4Ge):
case uint32_t(SimdOp::F64x2Eq):
case uint32_t(SimdOp::F64x2Ne):
case uint32_t(SimdOp::F64x2Lt):
case uint32_t(SimdOp::F64x2Gt):
case uint32_t(SimdOp::F64x2Le):
case uint32_t(SimdOp::F64x2Ge):
case uint32_t(SimdOp::V128And):
case uint32_t(SimdOp::V128Or):
case uint32_t(SimdOp::V128Xor):
case uint32_t(SimdOp::V128AndNot):
case uint32_t(SimdOp::I8x16AvgrU):
case uint32_t(SimdOp::I16x8AvgrU):
case uint32_t(SimdOp::I8x16Add):
case uint32_t(SimdOp::I8x16AddSatS):
case uint32_t(SimdOp::I8x16AddSatU):
case uint32_t(SimdOp::I8x16Sub):
case uint32_t(SimdOp::I8x16SubSatS):
case uint32_t(SimdOp::I8x16SubSatU):
case uint32_t(SimdOp::I8x16MinS):
case uint32_t(SimdOp::I8x16MinU):
case uint32_t(SimdOp::I8x16MaxS):
case uint32_t(SimdOp::I8x16MaxU):
case uint32_t(SimdOp::I16x8Add):
case uint32_t(SimdOp::I16x8AddSatS):
case uint32_t(SimdOp::I16x8AddSatU):
case uint32_t(SimdOp::I16x8Sub):
case uint32_t(SimdOp::I16x8SubSatS):
case uint32_t(SimdOp::I16x8SubSatU):
case uint32_t(SimdOp::I16x8Mul):
case uint32_t(SimdOp::I16x8MinS):
case uint32_t(SimdOp::I16x8MinU):
case uint32_t(SimdOp::I16x8MaxS):
case uint32_t(SimdOp::I16x8MaxU):
case uint32_t(SimdOp::I32x4Add):
case uint32_t(SimdOp::I32x4Sub):
case uint32_t(SimdOp::I32x4Mul):
case uint32_t(SimdOp::I32x4MinS):
case uint32_t(SimdOp::I32x4MinU):
case uint32_t(SimdOp::I32x4MaxS):
case uint32_t(SimdOp::I32x4MaxU):
case uint32_t(SimdOp::I64x2Add):
case uint32_t(SimdOp::I64x2Sub):
case uint32_t(SimdOp::I64x2Mul):
case uint32_t(SimdOp::F32x4Add):
case uint32_t(SimdOp::F32x4Sub):
case uint32_t(SimdOp::F32x4Mul):
case uint32_t(SimdOp::F32x4Div):
case uint32_t(SimdOp::F32x4Min):
case uint32_t(SimdOp::F32x4Max):
case uint32_t(SimdOp::F64x2Add):
case uint32_t(SimdOp::F64x2Sub):
case uint32_t(SimdOp::F64x2Mul):
case uint32_t(SimdOp::F64x2Div):
case uint32_t(SimdOp::F64x2Min):
case uint32_t(SimdOp::F64x2Max):
case uint32_t(SimdOp::I8x16NarrowI16x8S):
case uint32_t(SimdOp::I8x16NarrowI16x8U):
case uint32_t(SimdOp::I16x8NarrowI32x4S):
case uint32_t(SimdOp::I16x8NarrowI32x4U):
case uint32_t(SimdOp::I8x16Swizzle):
case uint32_t(SimdOp::F32x4PMax):
case uint32_t(SimdOp::F32x4PMin):
case uint32_t(SimdOp::F64x2PMax):
case uint32_t(SimdOp::F64x2PMin):
case uint32_t(SimdOp::I32x4DotI16x8S):
case uint32_t(SimdOp::I16x8ExtmulLowI8x16S):
case uint32_t(SimdOp::I16x8ExtmulHighI8x16S):
case uint32_t(SimdOp::I16x8ExtmulLowI8x16U):
case uint32_t(SimdOp::I16x8ExtmulHighI8x16U):
case uint32_t(SimdOp::I32x4ExtmulLowI16x8S):
case uint32_t(SimdOp::I32x4ExtmulHighI16x8S):
case uint32_t(SimdOp::I32x4ExtmulLowI16x8U):
case uint32_t(SimdOp::I32x4ExtmulHighI16x8U):
case uint32_t(SimdOp::I64x2ExtmulLowI32x4S):
case uint32_t(SimdOp::I64x2ExtmulHighI32x4S):
case uint32_t(SimdOp::I64x2ExtmulLowI32x4U):
case uint32_t(SimdOp::I64x2ExtmulHighI32x4U):
case uint32_t(SimdOp::I16x8Q15MulrSatS):
CHECK(iter.readBinary(ValType::V128, &nothing, &nothing));
case uint32_t(SimdOp::I8x16Neg):
case uint32_t(SimdOp::I16x8Neg):
case uint32_t(SimdOp::I16x8ExtendLowI8x16S):
case uint32_t(SimdOp::I16x8ExtendHighI8x16S):
case uint32_t(SimdOp::I16x8ExtendLowI8x16U):
case uint32_t(SimdOp::I16x8ExtendHighI8x16U):
case uint32_t(SimdOp::I32x4Neg):
case uint32_t(SimdOp::I32x4ExtendLowI16x8S):
case uint32_t(SimdOp::I32x4ExtendHighI16x8S):
case uint32_t(SimdOp::I32x4ExtendLowI16x8U):
case uint32_t(SimdOp::I32x4ExtendHighI16x8U):
case uint32_t(SimdOp::I32x4TruncSatF32x4S):
case uint32_t(SimdOp::I32x4TruncSatF32x4U):
case uint32_t(SimdOp::I64x2Neg):
case uint32_t(SimdOp::I64x2ExtendLowI32x4S):
case uint32_t(SimdOp::I64x2ExtendHighI32x4S):
case uint32_t(SimdOp::I64x2ExtendLowI32x4U):
case uint32_t(SimdOp::I64x2ExtendHighI32x4U):
case uint32_t(SimdOp::F32x4Abs):
case uint32_t(SimdOp::F32x4Neg):
case uint32_t(SimdOp::F32x4Sqrt):
case uint32_t(SimdOp::F32x4ConvertI32x4S):
case uint32_t(SimdOp::F32x4ConvertI32x4U):
case uint32_t(SimdOp::F64x2Abs):
case uint32_t(SimdOp::F64x2Neg):
case uint32_t(SimdOp::F64x2Sqrt):
case uint32_t(SimdOp::V128Not):
case uint32_t(SimdOp::I8x16Popcnt):
case uint32_t(SimdOp::I8x16Abs):
case uint32_t(SimdOp::I16x8Abs):
case uint32_t(SimdOp::I32x4Abs):
case uint32_t(SimdOp::I64x2Abs):
case uint32_t(SimdOp::F32x4Ceil):
case uint32_t(SimdOp::F32x4Floor):
case uint32_t(SimdOp::F32x4Trunc):
case uint32_t(SimdOp::F32x4Nearest):
case uint32_t(SimdOp::F64x2Ceil):
case uint32_t(SimdOp::F64x2Floor):
case uint32_t(SimdOp::F64x2Trunc):
case uint32_t(SimdOp::F64x2Nearest):
case uint32_t(SimdOp::F32x4DemoteF64x2Zero):
case uint32_t(SimdOp::F64x2PromoteLowF32x4):
case uint32_t(SimdOp::F64x2ConvertLowI32x4S):
case uint32_t(SimdOp::F64x2ConvertLowI32x4U):
case uint32_t(SimdOp::I32x4TruncSatF64x2SZero):
case uint32_t(SimdOp::I32x4TruncSatF64x2UZero):
case uint32_t(SimdOp::I16x8ExtaddPairwiseI8x16S):
case uint32_t(SimdOp::I16x8ExtaddPairwiseI8x16U):
case uint32_t(SimdOp::I32x4ExtaddPairwiseI16x8S):
case uint32_t(SimdOp::I32x4ExtaddPairwiseI16x8U):
CHECK(iter.readUnary(ValType::V128, &nothing));
case uint32_t(SimdOp::I8x16Shl):
case uint32_t(SimdOp::I8x16ShrS):
case uint32_t(SimdOp::I8x16ShrU):
case uint32_t(SimdOp::I16x8Shl):
case uint32_t(SimdOp::I16x8ShrS):
case uint32_t(SimdOp::I16x8ShrU):
case uint32_t(SimdOp::I32x4Shl):
case uint32_t(SimdOp::I32x4ShrS):
case uint32_t(SimdOp::I32x4ShrU):
case uint32_t(SimdOp::I64x2Shl):
case uint32_t(SimdOp::I64x2ShrS):
case uint32_t(SimdOp::I64x2ShrU):
CHECK(iter.readVectorShift(&nothing, &nothing));
case uint32_t(SimdOp::V128Bitselect):
CHECK(
iter.readTernary(ValType::V128, &nothing, &nothing, &nothing));
case uint32_t(SimdOp::I8x16Shuffle): {
V128 mask;
CHECK(iter.readVectorShuffle(&nothing, &nothing, &mask));
}
case uint32_t(SimdOp::V128Const): {
V128 noVector;
CHECK(iter.readV128Const(&noVector));
}
case uint32_t(SimdOp::V128Load): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoad(ValType::V128, 16, &addr));
}
case uint32_t(SimdOp::V128Load8Splat): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(1, &addr));
}
case uint32_t(SimdOp::V128Load16Splat): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(2, &addr));
}
case uint32_t(SimdOp::V128Load32Splat): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(4, &addr));
}
case uint32_t(SimdOp::V128Load64Splat): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(8, &addr));
}
case uint32_t(SimdOp::V128Load8x8S):
case uint32_t(SimdOp::V128Load8x8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadExtend(&addr));
}
case uint32_t(SimdOp::V128Load16x4S):
case uint32_t(SimdOp::V128Load16x4U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadExtend(&addr));
}
case uint32_t(SimdOp::V128Load32x2S):
case uint32_t(SimdOp::V128Load32x2U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadExtend(&addr));
}
case uint32_t(SimdOp::V128Store): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStore(ValType::V128, 16, &addr, &nothing));
}
case uint32_t(SimdOp::V128Load32Zero): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(4, &addr));
}
case uint32_t(SimdOp::V128Load64Zero): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadSplat(8, &addr));
}
case uint32_t(SimdOp::V128Load8Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadLane(1, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Load16Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadLane(2, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Load32Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadLane(4, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Load64Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readLoadLane(8, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Store8Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStoreLane(1, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Store16Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStoreLane(2, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Store32Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStoreLane(4, &addr, &noIndex, &nothing));
}
case uint32_t(SimdOp::V128Store64Lane): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readStoreLane(8, &addr, &noIndex, &nothing));
}
# ifdef ENABLE_WASM_RELAXED_SIMD
case uint32_t(SimdOp::F32x4RelaxedFma):
case uint32_t(SimdOp::F32x4RelaxedFms):
case uint32_t(SimdOp::F64x2RelaxedFma):
case uint32_t(SimdOp::F64x2RelaxedFms):
case uint32_t(SimdOp::I8x16RelaxedLaneSelect):
case uint32_t(SimdOp::I16x8RelaxedLaneSelect):
case uint32_t(SimdOp::I32x4RelaxedLaneSelect):
case uint32_t(SimdOp::I64x2RelaxedLaneSelect):
case uint32_t(SimdOp::I32x4DotI8x16I7x16AddS): {
if (!env.v128RelaxedEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(
iter.readTernary(ValType::V128, &nothing, &nothing, &nothing));
}
case uint32_t(SimdOp::F32x4RelaxedMin):
case uint32_t(SimdOp::F32x4RelaxedMax):
case uint32_t(SimdOp::F64x2RelaxedMin):
case uint32_t(SimdOp::F64x2RelaxedMax):
case uint32_t(SimdOp::I16x8RelaxedQ15MulrS):
case uint32_t(SimdOp::I16x8DotI8x16I7x16S): {
if (!env.v128RelaxedEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readBinary(ValType::V128, &nothing, &nothing));
}
case uint32_t(SimdOp::I32x4RelaxedTruncSSatF32x4):
case uint32_t(SimdOp::I32x4RelaxedTruncUSatF32x4):
case uint32_t(SimdOp::I32x4RelaxedTruncSatF64x2SZero):
case uint32_t(SimdOp::I32x4RelaxedTruncSatF64x2UZero): {
if (!env.v128RelaxedEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readUnary(ValType::V128, &nothing));
}
case uint32_t(SimdOp::I8x16RelaxedSwizzle): {
if (!env.v128RelaxedEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readBinary(ValType::V128, &nothing, &nothing));
}
# endif
default:
return iter.unrecognizedOpcode(&op);
}
break;
}
#endif // ENABLE_WASM_SIMD
case uint16_t(Op::MiscPrefix): {
switch (op.b1) {
case uint32_t(MiscOp::I32TruncSatF32S):
case uint32_t(MiscOp::I32TruncSatF32U):
CHECK(iter.readConversion(ValType::F32, ValType::I32, &nothing));
case uint32_t(MiscOp::I32TruncSatF64S):
case uint32_t(MiscOp::I32TruncSatF64U):
CHECK(iter.readConversion(ValType::F64, ValType::I32, &nothing));
case uint32_t(MiscOp::I64TruncSatF32S):
case uint32_t(MiscOp::I64TruncSatF32U):
CHECK(iter.readConversion(ValType::F32, ValType::I64, &nothing));
case uint32_t(MiscOp::I64TruncSatF64S):
case uint32_t(MiscOp::I64TruncSatF64U):
CHECK(iter.readConversion(ValType::F64, ValType::I64, &nothing));
case uint32_t(MiscOp::MemoryCopy): {
uint32_t unusedDestMemIndex;
uint32_t unusedSrcMemIndex;
CHECK(iter.readMemOrTableCopy(/*isMem=*/true, &unusedDestMemIndex,
&nothing, &unusedSrcMemIndex,
&nothing, &nothing));
}
case uint32_t(MiscOp::DataDrop): {
uint32_t unusedSegIndex;
CHECK(iter.readDataOrElemDrop(/*isData=*/true, &unusedSegIndex));
}
case uint32_t(MiscOp::MemoryFill):
CHECK(iter.readMemFill(&nothing, &nothing, &nothing));
case uint32_t(MiscOp::MemoryInit): {
uint32_t unusedSegIndex;
uint32_t unusedTableIndex;
CHECK(iter.readMemOrTableInit(/*isMem=*/true, &unusedSegIndex,
&unusedTableIndex, &nothing, &nothing,
&nothing));
}
case uint32_t(MiscOp::TableCopy): {
uint32_t unusedDestTableIndex;
uint32_t unusedSrcTableIndex;
CHECK(iter.readMemOrTableCopy(
/*isMem=*/false, &unusedDestTableIndex, &nothing,
&unusedSrcTableIndex, &nothing, &nothing));
}
case uint32_t(MiscOp::ElemDrop): {
uint32_t unusedSegIndex;
CHECK(iter.readDataOrElemDrop(/*isData=*/false, &unusedSegIndex));
}
case uint32_t(MiscOp::TableInit): {
uint32_t unusedSegIndex;
uint32_t unusedTableIndex;
CHECK(iter.readMemOrTableInit(/*isMem=*/false, &unusedSegIndex,
&unusedTableIndex, &nothing, &nothing,
&nothing));
}
case uint32_t(MiscOp::TableFill): {
uint32_t unusedTableIndex;
CHECK(iter.readTableFill(&unusedTableIndex, &nothing, &nothing,
&nothing));
}
case uint32_t(MiscOp::TableGrow): {
uint32_t unusedTableIndex;
CHECK(iter.readTableGrow(&unusedTableIndex, &nothing, &nothing));
}
case uint32_t(MiscOp::TableSize): {
uint32_t unusedTableIndex;
CHECK(iter.readTableSize(&unusedTableIndex));
}
default:
return iter.unrecognizedOpcode(&op);
}
break;
}
#ifdef ENABLE_WASM_FUNCTION_REFERENCES
case uint16_t(Op::RefAsNonNull): {
if (!env.functionReferencesEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readRefAsNonNull(&nothing));
}
case uint16_t(Op::BrOnNull): {
if (!env.functionReferencesEnabled()) {
return iter.unrecognizedOpcode(&op);
}
uint32_t unusedDepth;
CHECK(
iter.readBrOnNull(&unusedDepth, &unusedType, &nothings, &nothing));
}
#endif
#ifdef ENABLE_WASM_GC
case uint16_t(Op::RefEq): {
if (!env.gcEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readComparison(RefType::eq(), &nothing, &nothing));
}
#endif
case uint16_t(Op::RefFunc): {
uint32_t unusedIndex;
CHECK(iter.readRefFunc(&unusedIndex));
}
case uint16_t(Op::RefNull): {
RefType type;
CHECK(iter.readRefNull(&type));
}
case uint16_t(Op::RefIsNull): {
Nothing nothing;
CHECK(iter.readRefIsNull(&nothing));
}
case uint16_t(Op::Try):
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
CHECK(iter.readTry(&unusedType));
case uint16_t(Op::Catch): {
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
LabelKind unusedKind;
uint32_t unusedIndex;
CHECK(iter.readCatch(&unusedKind, &unusedIndex, &unusedType,
&unusedType, &nothings));
}
case uint16_t(Op::CatchAll): {
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
LabelKind unusedKind;
CHECK(iter.readCatchAll(&unusedKind, &unusedType, &unusedType,
&nothings));
}
case uint16_t(Op::Delegate): {
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
uint32_t unusedDepth;
if (!iter.readDelegate(&unusedDepth, &unusedType, &nothings)) {
return false;
}
iter.popDelegate();
break;
}
case uint16_t(Op::Throw): {
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
uint32_t unusedIndex;
CHECK(iter.readThrow(&unusedIndex, &nothings));
}
case uint16_t(Op::Rethrow): {
if (!env.exceptionsEnabled()) {
return iter.unrecognizedOpcode(&op);
}
uint32_t unusedDepth;
CHECK(iter.readRethrow(&unusedDepth));
}
case uint16_t(Op::ThreadPrefix): {
// Though thread ops can be used on nonshared memories, we make them
// unavailable if shared memory has been disabled in the prefs, for
// maximum predictability and safety and consistency with JS.
if (env.sharedMemoryEnabled() == Shareable::False) {
return iter.unrecognizedOpcode(&op);
}
switch (op.b1) {
case uint32_t(ThreadOp::Wake): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readWake(&addr, &nothing));
}
case uint32_t(ThreadOp::I32Wait): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readWait(&addr, ValType::I32, 4, &nothing, &nothing));
}
case uint32_t(ThreadOp::I64Wait): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readWait(&addr, ValType::I64, 8, &nothing, &nothing));
}
case uint32_t(ThreadOp::Fence): {
CHECK(iter.readFence());
}
case uint32_t(ThreadOp::I32AtomicLoad): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I32, 4));
}
case uint32_t(ThreadOp::I64AtomicLoad): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I64, 8));
}
case uint32_t(ThreadOp::I32AtomicLoad8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I32, 1));
}
case uint32_t(ThreadOp::I32AtomicLoad16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I32, 2));
}
case uint32_t(ThreadOp::I64AtomicLoad8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I64, 1));
}
case uint32_t(ThreadOp::I64AtomicLoad16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I64, 2));
}
case uint32_t(ThreadOp::I64AtomicLoad32U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicLoad(&addr, ValType::I64, 4));
}
case uint32_t(ThreadOp::I32AtomicStore): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I32, 4, &nothing));
}
case uint32_t(ThreadOp::I64AtomicStore): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I64, 8, &nothing));
}
case uint32_t(ThreadOp::I32AtomicStore8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I32, 1, &nothing));
}
case uint32_t(ThreadOp::I32AtomicStore16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I32, 2, &nothing));
}
case uint32_t(ThreadOp::I64AtomicStore8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I64, 1, &nothing));
}
case uint32_t(ThreadOp::I64AtomicStore16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I64, 2, &nothing));
}
case uint32_t(ThreadOp::I64AtomicStore32U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicStore(&addr, ValType::I64, 4, &nothing));
}
case uint32_t(ThreadOp::I32AtomicAdd):
case uint32_t(ThreadOp::I32AtomicSub):
case uint32_t(ThreadOp::I32AtomicAnd):
case uint32_t(ThreadOp::I32AtomicOr):
case uint32_t(ThreadOp::I32AtomicXor):
case uint32_t(ThreadOp::I32AtomicXchg): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I32, 4, &nothing));
}
case uint32_t(ThreadOp::I64AtomicAdd):
case uint32_t(ThreadOp::I64AtomicSub):
case uint32_t(ThreadOp::I64AtomicAnd):
case uint32_t(ThreadOp::I64AtomicOr):
case uint32_t(ThreadOp::I64AtomicXor):
case uint32_t(ThreadOp::I64AtomicXchg): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I64, 8, &nothing));
}
case uint32_t(ThreadOp::I32AtomicAdd8U):
case uint32_t(ThreadOp::I32AtomicSub8U):
case uint32_t(ThreadOp::I32AtomicAnd8U):
case uint32_t(ThreadOp::I32AtomicOr8U):
case uint32_t(ThreadOp::I32AtomicXor8U):
case uint32_t(ThreadOp::I32AtomicXchg8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I32, 1, &nothing));
}
case uint32_t(ThreadOp::I32AtomicAdd16U):
case uint32_t(ThreadOp::I32AtomicSub16U):
case uint32_t(ThreadOp::I32AtomicAnd16U):
case uint32_t(ThreadOp::I32AtomicOr16U):
case uint32_t(ThreadOp::I32AtomicXor16U):
case uint32_t(ThreadOp::I32AtomicXchg16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I32, 2, &nothing));
}
case uint32_t(ThreadOp::I64AtomicAdd8U):
case uint32_t(ThreadOp::I64AtomicSub8U):
case uint32_t(ThreadOp::I64AtomicAnd8U):
case uint32_t(ThreadOp::I64AtomicOr8U):
case uint32_t(ThreadOp::I64AtomicXor8U):
case uint32_t(ThreadOp::I64AtomicXchg8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I64, 1, &nothing));
}
case uint32_t(ThreadOp::I64AtomicAdd16U):
case uint32_t(ThreadOp::I64AtomicSub16U):
case uint32_t(ThreadOp::I64AtomicAnd16U):
case uint32_t(ThreadOp::I64AtomicOr16U):
case uint32_t(ThreadOp::I64AtomicXor16U):
case uint32_t(ThreadOp::I64AtomicXchg16U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I64, 2, &nothing));
}
case uint32_t(ThreadOp::I64AtomicAdd32U):
case uint32_t(ThreadOp::I64AtomicSub32U):
case uint32_t(ThreadOp::I64AtomicAnd32U):
case uint32_t(ThreadOp::I64AtomicOr32U):
case uint32_t(ThreadOp::I64AtomicXor32U):
case uint32_t(ThreadOp::I64AtomicXchg32U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicRMW(&addr, ValType::I64, 4, &nothing));
}
case uint32_t(ThreadOp::I32AtomicCmpXchg): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicCmpXchg(&addr, ValType::I32, 4, &nothing,
&nothing));
}
case uint32_t(ThreadOp::I64AtomicCmpXchg): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicCmpXchg(&addr, ValType::I64, 8, &nothing,
&nothing));
}
case uint32_t(ThreadOp::I32AtomicCmpXchg8U): {
LinearMemoryAddress<Nothing> addr;
CHECK(iter.readAtomicCmpXchg(&addr, ValType::I32, 1, &nothing,