From 89b8af006bc56cb4bf68f12a80b1cfe8e7a353d4 Mon Sep 17 00:00:00 2001 From: Abbas Mashayekh Date: Sat, 6 Mar 2021 03:08:51 +0330 Subject: [reference-types] Support passive elem segments (#3572) Passive element segments do not belong to any table, so the link between Table and elem needs to be weaker; i.e. an elem may have a table in case of active segments, or simply be a collection of function references in case of passive/declarative segments. This PR takes Table::Segment out and turns it into a first class module element just like tables and functions. It also implements early support for parsing, printing, encoding and decoding passive/declarative elem segments. --- src/wasm/wasm-validator.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index e95950bb5..656c5e832 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2882,21 +2882,25 @@ static void validateTables(Module& module, ValidationInfo& info) { "Only 1 table definition allowed in MVP (requires " "--enable-reference-types)"); } - for (auto& curr : module.tables) { - for (auto& segment : curr->segments) { - info.shouldBeEqual(segment.offset->type, + + for (auto& segment : module.elementSegments) { + if (segment->table.is()) { + auto table = module.getTableOrNull(segment->table); + info.shouldBeTrue( + table != nullptr, "elem", "elem segment must have a valid table name"); + info.shouldBeEqual(segment->offset->type, Type(Type::i32), - segment.offset, - "segment offset should be i32"); - info.shouldBeTrue(checkSegmentOffset(segment.offset, - segment.data.size(), - curr->initial * Table::kPageSize), - segment.offset, + segment->offset, + "elem segment offset should be i32"); + info.shouldBeTrue(checkSegmentOffset(segment->offset, + segment->data.size(), + table->initial * Table::kPageSize), + segment->offset, "table segment offset should be reasonable"); - for (auto name : segment.data) { - info.shouldBeTrue( - module.getFunctionOrNull(name), name, "segment name should be valid"); - } + } + for (auto name : segment->data) { + info.shouldBeTrue( + module.getFunctionOrNull(name), name, "segment name should be valid"); } } } -- cgit v1.2.3