Commit f6e39938 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][anyref] Change element segment encoding

The proposal is changing accordingly, see
https://github.com/WebAssembly/reference-types/issues/36.

In our tests we were already using the new format implicitly, because
bulk-memory-operations are enabled by default. I noticed the missing
implementation when I executed spec tests with
--no-experimental-wasm-bulk-memory.

R=mstarzinger@chromium.org

Bug: v8:7581
Change-Id: I13aaba9a8d60e8542245aac7f0a072da1be357dc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1631591Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61913}
parent b114cb4c
......@@ -1680,45 +1680,41 @@ class ModuleDecoderImpl : public Decoder {
void consume_segment_header(const char* name, bool* is_active,
uint32_t* index, WasmInitExpr* offset) {
const byte* pos = pc();
// In the MVP, this is a table or memory index field that must be 0, but
// we've repurposed it as a flags field in the bulk memory proposal.
uint32_t flags;
if (enabled_features_.bulk_memory) {
flags = consume_u32v("flags");
if (failed()) return;
} else {
// Without the bulk memory proposal, we should still read the table
// index. This is the same as reading the `ActiveWithIndex` flag with
// the bulk memory proposal.
flags = SegmentFlags::kActiveWithIndex;
uint32_t flag = consume_u32v("flag");
// Some flag values are only valid for specific proposals.
if (flag == SegmentFlags::kPassive) {
if (!enabled_features_.bulk_memory) {
error(
"Passive element segments require --experimental-wasm-bulk-memory");
return;
}
} else if (flag == SegmentFlags::kActiveWithIndex) {
if (!(enabled_features_.bulk_memory || enabled_features_.anyref)) {
error(
"Element segments with table indices require "
"--experimental-wasm-bulk-memory or --experimental-wasm-anyref");
return;
}
} else if (flag != SegmentFlags::kActiveNoIndex) {
errorf(pos, "illegal flag value %u. Must be 0, 1, or 2", flag);
return;
}
bool read_index;
bool read_offset;
if (flags == SegmentFlags::kActiveNoIndex) {
// We know now that the flag is valid. Time to read the rest.
if (flag == SegmentFlags::kActiveNoIndex) {
*is_active = true;
read_index = false;
read_offset = true;
} else if (flags == SegmentFlags::kPassive) {
*index = 0;
*offset = consume_init_expr(module_.get(), kWasmI32);
return;
}
if (flag == SegmentFlags::kPassive) {
*is_active = false;
read_index = false;
read_offset = false;
} else if (flags == SegmentFlags::kActiveWithIndex) {
*is_active = true;
read_index = true;
read_offset = true;
} else {
errorf(pos, "illegal flag value %u. Must be 0, 1, or 2", flags);
return;
}
if (read_index) {
if (flag == SegmentFlags::kActiveWithIndex) {
*is_active = true;
*index = consume_u32v(name);
} else {
*index = 0;
}
if (read_offset) {
*offset = consume_init_expr(module_.get(), kWasmI32);
}
}
......
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