Commit 15821ebb authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm][refactor] Rename some symbols

- Rename WasmTrapElemSegmentDropped -> WasmTrapElemSegmentOutOfBounds.
- Rename WasmArrayInitFromData -> WasmArrayInitFromSegment, in
  anticipation of array.init_from_elem.
- Rename InitExprInterface::result_ -> computed_value_, to
  distinguish it from the {result} values. Also, rename
  generate_result() -> generate_value().
- Drive-by: Restructure Runtime_WasmArrayInitFromSegment.

Change-Id: Ic372db909847c7a169f3d6732e64e8665f4200fb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3693702Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80991}
parent 4a7b2d47
...@@ -427,7 +427,7 @@ extern enum MessageTemplate { ...@@ -427,7 +427,7 @@ extern enum MessageTemplate {
kWasmTrapFloatUnrepresentable, kWasmTrapFloatUnrepresentable,
kWasmTrapFuncSigMismatch, kWasmTrapFuncSigMismatch,
kWasmTrapDataSegmentOutOfBounds, kWasmTrapDataSegmentOutOfBounds,
kWasmTrapElemSegmentDropped, kWasmTrapElementSegmentOutOfBounds,
kWasmTrapTableOutOfBounds, kWasmTrapTableOutOfBounds,
kWasmTrapRethrowNull, kWasmTrapRethrowNull,
kWasmTrapNullDereference, kWasmTrapNullDereference,
......
...@@ -36,7 +36,7 @@ extern runtime WasmI64AtomicWait( ...@@ -36,7 +36,7 @@ extern runtime WasmI64AtomicWait(
Context, WasmInstanceObject, Number, BigInt, BigInt): Smi; Context, WasmInstanceObject, Number, BigInt, BigInt): Smi;
extern runtime WasmArrayCopy( extern runtime WasmArrayCopy(
Context, WasmArray, Smi, WasmArray, Smi, Smi): JSAny; Context, WasmArray, Smi, WasmArray, Smi, Smi): JSAny;
extern runtime WasmArrayInitFromData( extern runtime WasmArrayInitFromSegment(
Context, WasmInstanceObject, Smi, Smi, Smi, Map): Object; Context, WasmInstanceObject, Smi, Smi, Smi, Map): Object;
extern runtime WasmStringNewWtf8( extern runtime WasmStringNewWtf8(
Context, WasmInstanceObject, Smi, Number, Number): String; Context, WasmInstanceObject, Smi, Number, Number): String;
...@@ -363,10 +363,10 @@ builtin WasmAllocateArray_Uninitialized( ...@@ -363,10 +363,10 @@ builtin WasmAllocateArray_Uninitialized(
return %RawDownCast<WasmArray>(result); return %RawDownCast<WasmArray>(result);
} }
builtin WasmArrayInitFromData( builtin WasmArrayInitFromSegment(
dataSegment: uint32, offset: uint32, length: uint32, rtt: Map): Object { dataSegment: uint32, offset: uint32, length: uint32, rtt: Map): Object {
const instance = LoadInstanceFromFrame(); const instance = LoadInstanceFromFrame();
tail runtime::WasmArrayInitFromData( tail runtime::WasmArrayInitFromSegment(
LoadContextFromInstance(instance), instance, SmiFromUint32(dataSegment), LoadContextFromInstance(instance), instance, SmiFromUint32(dataSegment),
SmiFromUint32(offset), SmiFromUint32(length), rtt); SmiFromUint32(offset), SmiFromUint32(length), rtt);
} }
...@@ -651,8 +651,9 @@ builtin ThrowWasmTrapDataSegmentOutOfBounds(): JSAny { ...@@ -651,8 +651,9 @@ builtin ThrowWasmTrapDataSegmentOutOfBounds(): JSAny {
tail WasmTrap(SmiConstant(MessageTemplate::kWasmTrapDataSegmentOutOfBounds)); tail WasmTrap(SmiConstant(MessageTemplate::kWasmTrapDataSegmentOutOfBounds));
} }
builtin ThrowWasmTrapElemSegmentDropped(): JSAny { builtin ThrowWasmTrapElementSegmentOutOfBounds(): JSAny {
tail WasmTrap(SmiConstant(MessageTemplate::kWasmTrapElemSegmentDropped)); tail WasmTrap(
SmiConstant(MessageTemplate::kWasmTrapElementSegmentOutOfBounds));
} }
builtin ThrowWasmTrapTableOutOfBounds(): JSAny { builtin ThrowWasmTrapTableOutOfBounds(): JSAny {
......
...@@ -1800,7 +1800,7 @@ enum IsolateAddressId { ...@@ -1800,7 +1800,7 @@ enum IsolateAddressId {
V(TrapFloatUnrepresentable) \ V(TrapFloatUnrepresentable) \
V(TrapFuncSigMismatch) \ V(TrapFuncSigMismatch) \
V(TrapDataSegmentOutOfBounds) \ V(TrapDataSegmentOutOfBounds) \
V(TrapElemSegmentDropped) \ V(TrapElementSegmentOutOfBounds) \
V(TrapTableOutOfBounds) \ V(TrapTableOutOfBounds) \
V(TrapRethrowNull) \ V(TrapRethrowNull) \
V(TrapNullDereference) \ V(TrapNullDereference) \
......
...@@ -637,7 +637,7 @@ namespace internal { ...@@ -637,7 +637,7 @@ namespace internal {
T(WasmTrapMultiReturnLengthMismatch, "multi-return length mismatch") \ T(WasmTrapMultiReturnLengthMismatch, "multi-return length mismatch") \
T(WasmTrapJSTypeError, "type incompatibility when transforming from/to JS") \ T(WasmTrapJSTypeError, "type incompatibility when transforming from/to JS") \
T(WasmTrapDataSegmentOutOfBounds, "data segment out of bounds") \ T(WasmTrapDataSegmentOutOfBounds, "data segment out of bounds") \
T(WasmTrapElemSegmentDropped, "element segment has been dropped") \ T(WasmTrapElementSegmentOutOfBounds, "element segment out of bounds") \
T(WasmTrapRethrowNull, "rethrowing null value") \ T(WasmTrapRethrowNull, "rethrowing null value") \
T(WasmTrapNullDereference, "dereferencing a null pointer") \ T(WasmTrapNullDereference, "dereferencing a null pointer") \
T(WasmTrapIllegalCast, "illegal cast") \ T(WasmTrapIllegalCast, "illegal cast") \
......
...@@ -5331,13 +5331,15 @@ Node* WasmGraphBuilder::ArrayInit(const wasm::ArrayType* type, Node* rtt, ...@@ -5331,13 +5331,15 @@ Node* WasmGraphBuilder::ArrayInit(const wasm::ArrayType* type, Node* rtt,
return array; return array;
} }
Node* WasmGraphBuilder::ArrayInitFromData(const wasm::ArrayType* type, Node* WasmGraphBuilder::ArrayInitFromSegment(const wasm::ArrayType* type,
uint32_t data_segment, Node* offset, uint32_t data_segment,
Node* length, Node* rtt, Node* offset, Node* length,
wasm::WasmCodePosition position) { Node* rtt,
return gasm_->CallBuiltin( wasm::WasmCodePosition position) {
Builtin::kWasmArrayInitFromData, Operator::kNoDeopt | Operator::kNoThrow, return gasm_->CallBuiltin(Builtin::kWasmArrayInitFromSegment,
gasm_->Uint32Constant(data_segment), offset, length, rtt); Operator::kNoDeopt | Operator::kNoThrow,
gasm_->Uint32Constant(data_segment), offset, length,
rtt);
} }
Node* WasmGraphBuilder::RttCanon(uint32_t type_index) { Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
......
...@@ -501,9 +501,9 @@ class WasmGraphBuilder { ...@@ -501,9 +501,9 @@ class WasmGraphBuilder {
Node* length, wasm::WasmCodePosition position); Node* length, wasm::WasmCodePosition position);
Node* ArrayInit(const wasm::ArrayType* type, Node* rtt, Node* ArrayInit(const wasm::ArrayType* type, Node* rtt,
base::Vector<Node*> elements); base::Vector<Node*> elements);
Node* ArrayInitFromData(const wasm::ArrayType* type, uint32_t data_segment, Node* ArrayInitFromSegment(const wasm::ArrayType* type, uint32_t data_segment,
Node* offset, Node* length, Node* rtt, Node* offset, Node* length, Node* rtt,
wasm::WasmCodePosition position); wasm::WasmCodePosition position);
Node* I31New(Node* input); Node* I31New(Node* input);
Node* I31GetS(Node* input); Node* I31GetS(Node* input);
Node* I31GetU(Node* input); Node* I31GetU(Node* input);
......
...@@ -712,31 +712,36 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) { ...@@ -712,31 +712,36 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) { RUNTIME_FUNCTION(Runtime_WasmArrayInitFromSegment) {
ClearThreadInWasmScope flag_scope(isolate); ClearThreadInWasmScope flag_scope(isolate);
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(5, args.length()); DCHECK_EQ(5, args.length());
Handle<WasmInstanceObject> instance = args.at<WasmInstanceObject>(0); Handle<WasmInstanceObject> instance = args.at<WasmInstanceObject>(0);
uint32_t data_segment = args.positive_smi_value_at(1); uint32_t segment_index = args.positive_smi_value_at(1);
uint32_t offset = args.positive_smi_value_at(2); uint32_t offset = args.positive_smi_value_at(2);
uint32_t length = args.positive_smi_value_at(3); uint32_t length = args.positive_smi_value_at(3);
Handle<Map> rtt = args.at<Map>(4); Handle<Map> rtt = args.at<Map>(4);
uint32_t element_size = WasmArray::DecodeElementSizeFromMap(*rtt);
uint32_t length_in_bytes = length * element_size;
wasm::ArrayType* type = reinterpret_cast<wasm::ArrayType*>(
rtt->wasm_type_info().foreign_address());
uint32_t element_size = type->element_type().value_kind_size();
// This check also implies no overflow.
if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) { if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) {
return ThrowWasmError(isolate, MessageTemplate::kWasmTrapArrayTooLarge); return ThrowWasmError(isolate, MessageTemplate::kWasmTrapArrayTooLarge);
} }
// The check above implies no overflow.
uint32_t length_in_bytes = length * element_size;
DCHECK_EQ(length_in_bytes / element_size, length); DCHECK_EQ(length_in_bytes / element_size, length);
if (!base::IsInBounds<uint32_t>( if (!base::IsInBounds<uint32_t>(
offset, length_in_bytes, offset, length_in_bytes,
instance->data_segment_sizes()[data_segment])) { instance->data_segment_sizes()[segment_index])) {
return ThrowWasmError(isolate, return ThrowWasmError(isolate,
MessageTemplate::kWasmTrapDataSegmentOutOfBounds); MessageTemplate::kWasmTrapDataSegmentOutOfBounds);
} }
Address source = instance->data_segment_starts()[data_segment] + offset; Address source = instance->data_segment_starts()[segment_index] + offset;
return *isolate->factory()->NewWasmArrayFromMemory(length, rtt, source); return *isolate->factory()->NewWasmArrayFromMemory(length, rtt, source);
} }
......
...@@ -608,7 +608,7 @@ namespace internal { ...@@ -608,7 +608,7 @@ namespace internal {
F(WasmTriggerTierUp, 1, 1) \ F(WasmTriggerTierUp, 1, 1) \
F(WasmDebugBreak, 0, 1) \ F(WasmDebugBreak, 0, 1) \
F(WasmArrayCopy, 5, 1) \ F(WasmArrayCopy, 5, 1) \
F(WasmArrayInitFromData, 5, 1) \ F(WasmArrayInitFromSegment, 5, 1) \
F(WasmAllocateContinuation, 1, 1) \ F(WasmAllocateContinuation, 1, 1) \
F(WasmSyncStackLimit, 0, 1) \ F(WasmSyncStackLimit, 0, 1) \
F(WasmCreateResumePromise, 2, 1) \ F(WasmCreateResumePromise, 2, 1) \
......
...@@ -5581,11 +5581,12 @@ class LiftoffCompiler { ...@@ -5581,11 +5581,12 @@ class LiftoffCompiler {
__ PushRegister(kRef, array); __ PushRegister(kRef, array);
} }
void ArrayInitFromData(FullDecoder* decoder, void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm, const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment, const IndexImmediate<validate>& data_segment,
const Value& /* offset */, const Value& /* length */, const Value& /* offset */,
const Value& /* rtt */, Value* /* result */) { const Value& /* length */, const Value& /* rtt */,
Value* /* result */) {
LiftoffRegList pinned; LiftoffRegList pinned;
LiftoffRegister data_segment_reg = LiftoffRegister data_segment_reg =
pinned.set(__ GetUnusedRegister(kGpReg, pinned)); pinned.set(__ GetUnusedRegister(kGpReg, pinned));
...@@ -5593,7 +5594,7 @@ class LiftoffCompiler { ...@@ -5593,7 +5594,7 @@ class LiftoffCompiler {
WasmValue(static_cast<int32_t>(data_segment.index))); WasmValue(static_cast<int32_t>(data_segment.index)));
LiftoffAssembler::VarState data_segment_var(kI32, data_segment_reg, 0); LiftoffAssembler::VarState data_segment_var(kI32, data_segment_reg, 0);
CallRuntimeStub(WasmCode::kWasmArrayInitFromData, CallRuntimeStub(WasmCode::kWasmArrayInitFromSegment,
MakeSig::Returns(kRef).Params(kI32, kI32, kI32, kRtt), MakeSig::Returns(kRef).Params(kI32, kI32, kI32, kRtt),
{ {
data_segment_var, data_segment_var,
......
...@@ -983,7 +983,7 @@ struct ControlBase : public PcForErrors<validate> { ...@@ -983,7 +983,7 @@ struct ControlBase : public PcForErrors<validate> {
const Value& rtt, Value* result) \ const Value& rtt, Value* result) \
F(ArrayInit, const ArrayIndexImmediate<validate>& imm, \ F(ArrayInit, const ArrayIndexImmediate<validate>& imm, \
const base::Vector<Value>& elements, const Value& rtt, Value* result) \ const base::Vector<Value>& elements, const Value& rtt, Value* result) \
F(ArrayInitFromData, const ArrayIndexImmediate<validate>& array_imm, \ F(ArrayInitFromSegment, const ArrayIndexImmediate<validate>& array_imm, \
const IndexImmediate<validate>& data_segment, const Value& offset, \ const IndexImmediate<validate>& data_segment, const Value& offset, \
const Value& length, const Value& rtt, Value* result) \ const Value& length, const Value& rtt, Value* result) \
F(RttCanon, uint32_t type_index, Value* result) \ F(RttCanon, uint32_t type_index, Value* result) \
...@@ -1979,7 +1979,7 @@ class WasmDecoder : public Decoder { ...@@ -1979,7 +1979,7 @@ class WasmDecoder : public Decoder {
case kExprArrayInitFromDataStatic: { case kExprArrayInitFromDataStatic: {
ArrayIndexImmediate<validate> array_imm(decoder, pc + length); ArrayIndexImmediate<validate> array_imm(decoder, pc + length);
IndexImmediate<validate> data_imm( IndexImmediate<validate> data_imm(
decoder, pc + length + array_imm.length, "data segment index"); decoder, pc + length + array_imm.length, "segment index");
return length + array_imm.length + data_imm.length; return length + array_imm.length + data_imm.length;
} }
case kExprBrOnCast: case kExprBrOnCast:
...@@ -4410,7 +4410,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -4410,7 +4410,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
ValueType element_type = array_imm.array_type->element_type(); ValueType element_type = array_imm.array_type->element_type();
if (element_type.is_reference()) { if (element_type.is_reference()) {
this->DecodeError( this->DecodeError(
"array.init_from_data can only be used with value-type arrays, " "array.init_from_data can only be used with numeric-type arrays, "
"found array type #%d instead", "found array type #%d instead",
array_imm.index); array_imm.index);
return 0; return 0;
...@@ -4443,7 +4443,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -4443,7 +4443,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
Value array = Value array =
CreateValue(ValueType::Ref(array_imm.index, kNonNullable)); CreateValue(ValueType::Ref(array_imm.index, kNonNullable));
CALL_INTERFACE_IF_OK_AND_REACHABLE(ArrayInitFromData, array_imm, CALL_INTERFACE_IF_OK_AND_REACHABLE(ArrayInitFromSegment, array_imm,
data_segment, offset, length, rtt, data_segment, offset, length, rtt,
&array); &array);
Drop(3); // rtt, length, offset Drop(3); // rtt, length, offset
......
...@@ -1193,13 +1193,13 @@ class WasmGraphBuildingInterface { ...@@ -1193,13 +1193,13 @@ class WasmGraphBuildingInterface {
VectorOf(element_nodes))); VectorOf(element_nodes)));
} }
void ArrayInitFromData(FullDecoder* decoder, void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm, const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment, const IndexImmediate<validate>& data_segment,
const Value& offset, const Value& length, const Value& offset, const Value& length,
const Value& rtt, Value* result) { const Value& rtt, Value* result) {
SetAndTypeNode(result, SetAndTypeNode(result,
builder_->ArrayInitFromData( builder_->ArrayInitFromSegment(
array_imm.array_type, data_segment.index, offset.node, array_imm.array_type, data_segment.index, offset.node,
length.node, rtt.node, decoder->position())); length.node, rtt.node, decoder->position()));
} }
......
...@@ -19,35 +19,35 @@ namespace wasm { ...@@ -19,35 +19,35 @@ namespace wasm {
void InitExprInterface::I32Const(FullDecoder* decoder, Value* result, void InitExprInterface::I32Const(FullDecoder* decoder, Value* result,
int32_t value) { int32_t value) {
if (generate_result()) result->runtime_value = WasmValue(value); if (generate_value()) result->runtime_value = WasmValue(value);
} }
void InitExprInterface::I64Const(FullDecoder* decoder, Value* result, void InitExprInterface::I64Const(FullDecoder* decoder, Value* result,
int64_t value) { int64_t value) {
if (generate_result()) result->runtime_value = WasmValue(value); if (generate_value()) result->runtime_value = WasmValue(value);
} }
void InitExprInterface::F32Const(FullDecoder* decoder, Value* result, void InitExprInterface::F32Const(FullDecoder* decoder, Value* result,
float value) { float value) {
if (generate_result()) result->runtime_value = WasmValue(value); if (generate_value()) result->runtime_value = WasmValue(value);
} }
void InitExprInterface::F64Const(FullDecoder* decoder, Value* result, void InitExprInterface::F64Const(FullDecoder* decoder, Value* result,
double value) { double value) {
if (generate_result()) result->runtime_value = WasmValue(value); if (generate_value()) result->runtime_value = WasmValue(value);
} }
void InitExprInterface::S128Const(FullDecoder* decoder, void InitExprInterface::S128Const(FullDecoder* decoder,
Simd128Immediate<validate>& imm, Simd128Immediate<validate>& imm,
Value* result) { Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
result->runtime_value = WasmValue(imm.value, kWasmS128); result->runtime_value = WasmValue(imm.value, kWasmS128);
} }
void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode, void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode,
const Value& lhs, const Value& rhs, const Value& lhs, const Value& rhs,
Value* result) { Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
switch (opcode) { switch (opcode) {
case kExprI32Add: case kExprI32Add:
result->runtime_value = result->runtime_value =
...@@ -80,7 +80,7 @@ void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode, ...@@ -80,7 +80,7 @@ void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode,
void InitExprInterface::RefNull(FullDecoder* decoder, ValueType type, void InitExprInterface::RefNull(FullDecoder* decoder, ValueType type,
Value* result) { Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
result->runtime_value = WasmValue(isolate_->factory()->null_value(), type); result->runtime_value = WasmValue(isolate_->factory()->null_value(), type);
} }
...@@ -90,7 +90,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index, ...@@ -90,7 +90,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index,
outer_module_->functions[function_index].declared = true; outer_module_->functions[function_index].declared = true;
return; return;
} }
if (!generate_result()) return; if (!generate_value()) return;
ValueType type = ValueType::Ref(module_->functions[function_index].sig_index, ValueType type = ValueType::Ref(module_->functions[function_index].sig_index,
kNonNullable); kNonNullable);
Handle<WasmInternalFunction> internal = Handle<WasmInternalFunction> internal =
...@@ -101,7 +101,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index, ...@@ -101,7 +101,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index,
void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result, void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result,
const GlobalIndexImmediate<validate>& imm) { const GlobalIndexImmediate<validate>& imm) {
if (!generate_result()) return; if (!generate_value()) return;
const WasmGlobal& global = module_->globals[imm.index]; const WasmGlobal& global = module_->globals[imm.index];
DCHECK(!global.mutability); DCHECK(!global.mutability);
result->runtime_value = result->runtime_value =
...@@ -120,7 +120,7 @@ void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result, ...@@ -120,7 +120,7 @@ void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result,
void InitExprInterface::StructNewWithRtt( void InitExprInterface::StructNewWithRtt(
FullDecoder* decoder, const StructIndexImmediate<validate>& imm, FullDecoder* decoder, const StructIndexImmediate<validate>& imm,
const Value& rtt, const Value args[], Value* result) { const Value& rtt, const Value args[], Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
std::vector<WasmValue> field_values(imm.struct_type->field_count()); std::vector<WasmValue> field_values(imm.struct_type->field_count());
for (size_t i = 0; i < field_values.size(); i++) { for (size_t i = 0; i < field_values.size(); i++) {
field_values[i] = args[i].runtime_value; field_values[i] = args[i].runtime_value;
...@@ -161,7 +161,7 @@ WasmValue DefaultValueForType(ValueType type, Isolate* isolate) { ...@@ -161,7 +161,7 @@ WasmValue DefaultValueForType(ValueType type, Isolate* isolate) {
void InitExprInterface::StructNewDefault( void InitExprInterface::StructNewDefault(
FullDecoder* decoder, const StructIndexImmediate<validate>& imm, FullDecoder* decoder, const StructIndexImmediate<validate>& imm,
const Value& rtt, Value* result) { const Value& rtt, Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
std::vector<WasmValue> field_values(imm.struct_type->field_count()); std::vector<WasmValue> field_values(imm.struct_type->field_count());
for (uint32_t i = 0; i < field_values.size(); i++) { for (uint32_t i = 0; i < field_values.size(); i++) {
field_values[i] = DefaultValueForType(imm.struct_type->field(i), isolate_); field_values[i] = DefaultValueForType(imm.struct_type->field(i), isolate_);
...@@ -177,7 +177,7 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder, ...@@ -177,7 +177,7 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& imm, const ArrayIndexImmediate<validate>& imm,
const base::Vector<Value>& elements, const base::Vector<Value>& elements,
const Value& rtt, Value* result) { const Value& rtt, Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
std::vector<WasmValue> element_values; std::vector<WasmValue> element_values;
for (Value elem : elements) element_values.push_back(elem.runtime_value); for (Value elem : elements) element_values.push_back(elem.runtime_value);
result->runtime_value = result->runtime_value =
...@@ -187,11 +187,11 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder, ...@@ -187,11 +187,11 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder,
ValueType::Ref(HeapType(imm.index), kNonNullable)); ValueType::Ref(HeapType(imm.index), kNonNullable));
} }
void InitExprInterface::ArrayInitFromData( void InitExprInterface::ArrayInitFromSegment(
FullDecoder* decoder, const ArrayIndexImmediate<validate>& array_imm, FullDecoder* decoder, const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment_imm, const Value& offset_value, const IndexImmediate<validate>& data_segment_imm, const Value& offset_value,
const Value& length_value, const Value& rtt, Value* result) { const Value& length_value, const Value& rtt, Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
uint32_t length = length_value.runtime_value.to_u32(); uint32_t length = length_value.runtime_value.to_u32();
uint32_t offset = offset_value.runtime_value.to_u32(); uint32_t offset = offset_value.runtime_value.to_u32();
...@@ -222,7 +222,7 @@ void InitExprInterface::ArrayInitFromData( ...@@ -222,7 +222,7 @@ void InitExprInterface::ArrayInitFromData(
void InitExprInterface::RttCanon(FullDecoder* decoder, uint32_t type_index, void InitExprInterface::RttCanon(FullDecoder* decoder, uint32_t type_index,
Value* result) { Value* result) {
if (!generate_result()) return; if (!generate_value()) return;
result->runtime_value = WasmValue( result->runtime_value = WasmValue(
handle(instance_->managed_object_maps().get(type_index), isolate_), handle(instance_->managed_object_maps().get(type_index), isolate_),
ValueType::Rtt(type_index)); ValueType::Rtt(type_index));
...@@ -233,7 +233,9 @@ void InitExprInterface::DoReturn(FullDecoder* decoder, ...@@ -233,7 +233,9 @@ void InitExprInterface::DoReturn(FullDecoder* decoder,
end_found_ = true; end_found_ = true;
// End decoding on "end". // End decoding on "end".
decoder->set_end(decoder->pc() + 1); decoder->set_end(decoder->pc() + 1);
if (generate_result()) result_ = decoder->stack_value(1)->runtime_value; if (generate_value()) {
computed_value_ = decoder->stack_value(1)->runtime_value;
}
} }
} // namespace wasm } // namespace wasm
......
...@@ -72,17 +72,17 @@ class InitExprInterface { ...@@ -72,17 +72,17 @@ class InitExprInterface {
WasmValue result() { WasmValue result() {
DCHECK_NOT_NULL(isolate_); DCHECK_NOT_NULL(isolate_);
return result_; return computed_value_;
} }
bool end_found() { return end_found_; } bool end_found() { return end_found_; }
bool runtime_error() { return error_ != nullptr; } bool runtime_error() { return error_ != nullptr; }
const char* runtime_error_msg() { return error_; } const char* runtime_error_msg() { return error_; }
private: private:
bool generate_result() { return isolate_ != nullptr && !runtime_error(); } bool generate_value() { return isolate_ != nullptr && !runtime_error(); }
bool end_found_ = false; bool end_found_ = false;
const char* error_ = nullptr; const char* error_ = nullptr;
WasmValue result_; WasmValue computed_value_;
const WasmModule* module_; const WasmModule* module_;
WasmModule* outer_module_; WasmModule* outer_module_;
Isolate* isolate_; Isolate* isolate_;
......
...@@ -118,7 +118,7 @@ struct WasmModule; ...@@ -118,7 +118,7 @@ struct WasmModule;
V(WasmAllocateArray_Uninitialized) \ V(WasmAllocateArray_Uninitialized) \
V(WasmArrayCopy) \ V(WasmArrayCopy) \
V(WasmArrayCopyWithChecks) \ V(WasmArrayCopyWithChecks) \
V(WasmArrayInitFromData) \ V(WasmArrayInitFromSegment) \
V(WasmAllocateStructWithRtt) \ V(WasmAllocateStructWithRtt) \
V(WasmSubtypeCheck) \ V(WasmSubtypeCheck) \
V(WasmOnStackReplace) \ V(WasmOnStackReplace) \
......
...@@ -402,11 +402,12 @@ class InitExprInterface { ...@@ -402,11 +402,12 @@ class InitExprInterface {
: WasmInitExpr::ArrayInit(imm.index, args); : WasmInitExpr::ArrayInit(imm.index, args);
} }
void ArrayInitFromData(FullDecoder* decoder, void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm, const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment_imm, const IndexImmediate<validate>& data_segment_imm,
const Value& offset_value, const Value& length_value, const Value& offset_value,
const Value& rtt, Value* result) { const Value& length_value, const Value& rtt,
Value* result) {
// TODO(7748): Implement. // TODO(7748): Implement.
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
......
...@@ -905,7 +905,7 @@ let kTrapTableOutOfBounds = 6; ...@@ -905,7 +905,7 @@ let kTrapTableOutOfBounds = 6;
let kTrapFuncSigMismatch = 7; let kTrapFuncSigMismatch = 7;
let kTrapUnalignedAccess = 8; let kTrapUnalignedAccess = 8;
let kTrapDataSegmentOutOfBounds = 9; let kTrapDataSegmentOutOfBounds = 9;
let kTrapElemSegmentDropped = 10; let kTrapElementSegmentOutOfBounds = 10;
let kTrapRethrowNull = 11; let kTrapRethrowNull = 11;
let kTrapArrayTooLarge = 12; let kTrapArrayTooLarge = 12;
...@@ -920,7 +920,7 @@ let kTrapMsgs = [ ...@@ -920,7 +920,7 @@ let kTrapMsgs = [
'null function or function signature mismatch', // -- 'null function or function signature mismatch', // --
'operation does not support unaligned accesses', // -- 'operation does not support unaligned accesses', // --
'data segment out of bounds', // -- 'data segment out of bounds', // --
'element segment has been dropped', // -- 'element segment out of bounds', // --
'rethrowing null value', // -- 'rethrowing null value', // --
'requested new array is too large' // -- 'requested new array is too large' // --
]; ];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment