diff options
author | Alon Zakai <azakai@google.com> | 2023-11-06 12:29:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-06 12:29:19 -0800 |
commit | e3d27166370da202bef6c012014604beac41d43f (patch) | |
tree | f9e0515c0c6044e6c9b12f6d5d83f8ba99ab0fc3 /src/wasm/wasm-binary.cpp | |
parent | 4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96 (diff) | |
download | binaryen-e3d27166370da202bef6c012014604beac41d43f.tar.gz binaryen-e3d27166370da202bef6c012014604beac41d43f.tar.bz2 binaryen-e3d27166370da202bef6c012014604beac41d43f.zip |
Implement table.copy (#6078)
Helps #5951
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 6b74f2597..3c01e5df5 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -4062,6 +4062,9 @@ BinaryConsts::ASTNodes WasmBinaryReader::readExpression(Expression*& curr) { if (maybeVisitTableFill(curr, opcode)) { break; } + if (maybeVisitTableCopy(curr, opcode)) { + break; + } throwError("invalid code after misc prefix: " + std::to_string(opcode)); break; } @@ -5436,6 +5439,28 @@ bool WasmBinaryReader::maybeVisitTableFill(Expression*& out, uint32_t code) { return true; } +bool WasmBinaryReader::maybeVisitTableCopy(Expression*& out, uint32_t code) { + if (code != BinaryConsts::TableCopy) { + return false; + } + Index destTableIdx = getU32LEB(); + if (destTableIdx >= wasm.tables.size()) { + throwError("bad table index"); + } + Index sourceTableIdx = getU32LEB(); + if (sourceTableIdx >= wasm.tables.size()) { + throwError("bad table index"); + } + auto* size = popNonVoidExpression(); + auto* source = popNonVoidExpression(); + auto* dest = popNonVoidExpression(); + auto* ret = Builder(wasm).makeTableCopy(dest, source, size, Name(), Name()); + tableRefs[destTableIdx].push_back(&ret->destTable); + tableRefs[sourceTableIdx].push_back(&ret->sourceTable); + out = ret; + return true; +} + bool WasmBinaryReader::maybeVisitBinary(Expression*& out, uint8_t code) { Binary* curr; #define INT_TYPED_CODE(code) \ |