From e3d27166370da202bef6c012014604beac41d43f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 6 Nov 2023 12:29:19 -0800 Subject: Implement table.copy (#6078) Helps #5951 --- src/wasm/wasm-validator.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index cd90e767e..68d1f786d 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -441,6 +441,7 @@ public: void visitTableSize(TableSize* curr); void visitTableGrow(TableGrow* curr); void visitTableFill(TableFill* curr); + void visitTableCopy(TableCopy* curr); void noteDelegate(Name name, Expression* curr); void noteRethrow(Name name, Expression* curr); void visitTry(Try* curr); @@ -2315,6 +2316,27 @@ void FunctionValidator::visitTableFill(TableFill* curr) { curr->size->type, Type(Type::i32), curr, "table.fill size must be i32"); } +void FunctionValidator::visitTableCopy(TableCopy* curr) { + shouldBeTrue(getModule()->features.hasBulkMemory(), + curr, + "table.copy requires bulk-memory [--enable-bulk-memory]"); + auto* sourceTable = getModule()->getTableOrNull(curr->sourceTable); + auto* destTable = getModule()->getTableOrNull(curr->destTable); + if (shouldBeTrue(!!sourceTable, curr, "table.copy source table must exist") && + shouldBeTrue(!!destTable, curr, "table.copy dest table must exist")) { + shouldBeSubType(sourceTable->type, + destTable->type, + curr, + "table.copy source must have right type for dest"); + } + shouldBeEqualOrFirstIsUnreachable( + curr->dest->type, Type(Type::i32), curr, "table.copy dest must be i32"); + shouldBeEqualOrFirstIsUnreachable( + curr->source->type, Type(Type::i32), curr, "table.copy source must be i32"); + shouldBeEqualOrFirstIsUnreachable( + curr->size->type, Type(Type::i32), curr, "table.copy size must be i32"); +} + void FunctionValidator::noteDelegate(Name name, Expression* curr) { if (name != DELEGATE_CALLER_TARGET) { shouldBeTrue(delegateTargetNames.count(name) != 0, -- cgit v1.2.3