From 2dff27c086e8f2a9913096ebf3dc93e97051d85a Mon Sep 17 00:00:00 2001 From: Max Graey Date: Thu, 7 Oct 2021 22:43:30 +0300 Subject: Add table.set operation (#4215) --- src/wasm/wasm-validator.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index fae95980f..0e362df9c 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -365,6 +365,7 @@ public: void visitRefFunc(RefFunc* curr); void visitRefEq(RefEq* curr); void visitTableGet(TableGet* curr); + void visitTableSet(TableSet* curr); void noteDelegate(Name name, Expression* curr); void noteRethrow(Name name, Expression* curr); void visitTry(Try* curr); @@ -2046,6 +2047,22 @@ void FunctionValidator::visitTableGet(TableGet* curr) { } } +void FunctionValidator::visitTableSet(TableSet* curr) { + shouldBeTrue(getModule()->features.hasReferenceTypes(), + curr, + "table.set requires reference types to be enabled"); + shouldBeEqualOrFirstIsUnreachable( + curr->index->type, Type(Type::i32), curr, "table.set index must be an i32"); + auto* table = getModule()->getTableOrNull(curr->table); + if (shouldBeTrue(!!table, curr, "table.set table must exist") && + curr->type != Type::unreachable) { + shouldBeSubType(curr->value->type, + table->type, + curr, + "table.set value must have right type"); + } +} + void FunctionValidator::noteDelegate(Name name, Expression* curr) { if (name != DELEGATE_CALLER_TARGET) { shouldBeTrue(delegateTargetNames.count(name) != 0, -- cgit v1.2.3