diff options
author | Abbas Mashayekh <martianboy2005@gmail.com> | 2021-02-10 01:17:28 +0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 13:47:28 -0800 |
commit | 3da8b08ecd57f5662bebc69ea73bf59e1928341e (patch) | |
tree | 2902eedc161579eaf37a1aed463de95916eee703 /src/wasm/wasm-validator.cpp | |
parent | a12a8250da24aa5b5787bf89562b243fdc514302 (diff) | |
download | binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.tar.gz binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.tar.bz2 binaryen-3da8b08ecd57f5662bebc69ea73bf59e1928341e.zip |
[reference-types] remove single table restriction in IR (#3517)
Adds support for modules with multiple tables. Adds a field for the table name to `CallIndirect` and updates the C/JS APIs accordingly.
Diffstat (limited to 'src/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index fad78cefd..7e05bd375 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -809,6 +809,12 @@ void FunctionValidator::visitCallIndirect(CallIndirect* curr) { Type(Type::i32), curr, "indirect call target must be an i32"); + + if (curr->target->type != Type::unreachable) { + auto* table = getModule()->getTableOrNull(curr->table); + shouldBeTrue(!!table, curr, "call-indirect table must exist"); + } + validateCallParamsAndResult(curr, curr->sig); } @@ -2667,7 +2673,7 @@ static void validateExports(Module& module, ValidationInfo& info) { name, "module global exports must be found"); } else if (exp->kind == ExternalKind::Table) { - info.shouldBeTrue(name == Name("0") || name == module.table.name, + info.shouldBeTrue(module.getTableOrNull(name), name, "module table exports must be found"); } else if (exp->kind == ExternalKind::Memory) { @@ -2776,22 +2782,28 @@ static void validateMemory(Module& module, ValidationInfo& info) { } } -static void validateTable(Module& module, ValidationInfo& info) { - auto& curr = module.table; - for (auto& segment : curr.segments) { - info.shouldBeEqual(segment.offset->type, - Type(Type::i32), - segment.offset, - "segment offset should be i32"); - info.shouldBeTrue( - checkSegmentOffset(segment.offset, - segment.data.size(), - module.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"); +static void validateTables(Module& module, ValidationInfo& info) { + if (!module.features.hasReferenceTypes()) { + info.shouldBeTrue(module.tables.size() <= 1, + "table", + "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, + Type(Type::i32), + segment.offset, + "segment offset should be i32"); + info.shouldBeTrue(checkSegmentOffset(segment.offset, + segment.data.size(), + curr->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"); + } } } } @@ -2865,7 +2877,7 @@ bool WasmValidator::validate(Module& module, Flags flags) { validateExports(module, info); validateGlobals(module, info); validateMemory(module, info); - validateTable(module, info); + validateTables(module, info); validateEvents(module, info); validateModule(module, info); validateFeatures(module, info); |