diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index dffb721b75..934b947782 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -703,9 +703,6 @@ struct MemoryAccessImmediate { pc + alignment_length, &offset_length, "offset"); length = alignment_length + offset_length; } - // Defined below, after the definition of WasmDecoder. - inline MemoryAccessImmediate(WasmDecoder* decoder, const byte* pc, - uint32_t max_alignment); }; // Immediate for SIMD lane operations. @@ -2080,12 +2077,6 @@ class WasmDecoder : public Decoder { const FunctionSig* sig_; }; -template -MemoryAccessImmediate::MemoryAccessImmediate( - WasmDecoder* decoder, const byte* pc, uint32_t max_alignment) - : MemoryAccessImmediate(decoder, pc, max_alignment, - decoder->module_->is_memory64) {} - // Only call this in contexts where {current_code_reachable_and_ok_} is known to // hold. #define CALL_INTERFACE(name, ...) \ @@ -2282,6 +2273,12 @@ class WasmFullDecoder : public WasmDecoder { return true; } + MemoryAccessImmediate MakeMemoryAccessImmediate( + uint32_t pc_offset, uint32_t max_alignment) { + return MemoryAccessImmediate( + this, this->pc_ + pc_offset, max_alignment, this->module_->is_memory64); + } + #ifdef DEBUG class TraceLine { public: @@ -3610,8 +3607,8 @@ class WasmFullDecoder : public WasmDecoder { } int DecodeLoadMem(LoadType type, int prefix_len = 1) { - MemoryAccessImmediate imm(this, this->pc_ + prefix_len, - type.size_log_2()); + MemoryAccessImmediate imm = + MakeMemoryAccessImmediate(prefix_len, type.size_log_2()); if (!this->Validate(this->pc_ + prefix_len, imm)) return 0; ValueType index_type = this->module_->is_memory64 ? kWasmI64 : kWasmI32; Value index = Peek(0, 0, index_type); @@ -3627,8 +3624,8 @@ class WasmFullDecoder : public WasmDecoder { // Load extends always load 64-bits. uint32_t max_alignment = transform == LoadTransformationKind::kExtend ? 3 : type.size_log_2(); - MemoryAccessImmediate imm(this, this->pc_ + opcode_length, - max_alignment); + MemoryAccessImmediate imm = + MakeMemoryAccessImmediate(opcode_length, max_alignment); if (!this->Validate(this->pc_ + opcode_length, imm)) return 0; ValueType index_type = this->module_->is_memory64 ? kWasmI64 : kWasmI32; Value index = Peek(0, 0, index_type); @@ -3641,8 +3638,8 @@ class WasmFullDecoder : public WasmDecoder { } int DecodeLoadLane(WasmOpcode opcode, LoadType type, uint32_t opcode_length) { - MemoryAccessImmediate mem_imm(this, this->pc_ + opcode_length, - type.size_log_2()); + MemoryAccessImmediate mem_imm = + MakeMemoryAccessImmediate(opcode_length, type.size_log_2()); if (!this->Validate(this->pc_ + opcode_length, mem_imm)) return 0; SimdLaneImmediate lane_imm( this, this->pc_ + opcode_length + mem_imm.length); @@ -3660,8 +3657,8 @@ class WasmFullDecoder : public WasmDecoder { int DecodeStoreLane(WasmOpcode opcode, StoreType type, uint32_t opcode_length) { - MemoryAccessImmediate mem_imm(this, this->pc_ + opcode_length, - type.size_log_2()); + MemoryAccessImmediate mem_imm = + MakeMemoryAccessImmediate(opcode_length, type.size_log_2()); if (!this->Validate(this->pc_ + opcode_length, mem_imm)) return 0; SimdLaneImmediate lane_imm( this, this->pc_ + opcode_length + mem_imm.length); @@ -3676,8 +3673,8 @@ class WasmFullDecoder : public WasmDecoder { } int DecodeStoreMem(StoreType store, int prefix_len = 1) { - MemoryAccessImmediate imm(this, this->pc_ + prefix_len, - store.size_log_2()); + MemoryAccessImmediate imm = + MakeMemoryAccessImmediate(prefix_len, store.size_log_2()); if (!this->Validate(this->pc_ + prefix_len, imm)) return 0; Value value = Peek(0, 1, store.value_type()); ValueType index_type = this->module_->is_memory64 ? kWasmI64 : kWasmI32; @@ -4591,9 +4588,8 @@ class WasmFullDecoder : public WasmDecoder { return 0; } - MemoryAccessImmediate imm( - this, this->pc_ + opcode_length, - ElementSizeLog2Of(memtype.representation())); + MemoryAccessImmediate imm = MakeMemoryAccessImmediate( + opcode_length, ElementSizeLog2Of(memtype.representation())); if (!this->Validate(this->pc_ + opcode_length, imm)) return false; // TODO(10949): Fix this for memory64 (index type should be kWasmI64