diff options
author | Max Graey <maxgraey@gmail.com> | 2021-10-18 22:48:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-18 12:48:50 -0700 |
commit | f0a8de302b85441deb8864c9e20c561c934e27b8 (patch) | |
tree | b71e540462b865891a0b63d25b0b16b9653fd04a /src/wasm/wasm-binary.cpp | |
parent | 0bec0a4bbaf4859bb4c7a2f1c4ecda60ccab72f2 (diff) | |
download | binaryen-f0a8de302b85441deb8864c9e20c561c934e27b8.tar.gz binaryen-f0a8de302b85441deb8864c9e20c561c934e27b8.tar.bz2 binaryen-f0a8de302b85441deb8864c9e20c561c934e27b8.zip |
Add table.grow operation (#4245)
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index e2dacdf70..9c8b83325 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2798,6 +2798,8 @@ void WasmBinaryBuilder::processNames() { set->table = getTableName(index); } else if (auto* size = ref->dynCast<TableSize>()) { size->table = getTableName(index); + } else if (auto* grow = ref->dynCast<TableGrow>()) { + grow->table = getTableName(index); } else { WASM_UNREACHABLE("Invalid type in table references"); } @@ -3621,6 +3623,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { if (maybeVisitTableSize(curr, opcode)) { break; } + if (maybeVisitTableGrow(curr, opcode)) { + break; + } throwError("invalid code after misc prefix: " + std::to_string(opcode)); break; } @@ -4941,6 +4946,24 @@ bool WasmBinaryBuilder::maybeVisitTableSize(Expression*& out, uint32_t code) { return true; } +bool WasmBinaryBuilder::maybeVisitTableGrow(Expression*& out, uint32_t code) { + if (code != BinaryConsts::TableGrow) { + return false; + } + Index tableIdx = getU32LEB(); + if (tableIdx >= tables.size()) { + throwError("bad table index"); + } + auto* curr = allocator.alloc<TableGrow>(); + curr->delta = popNonVoidExpression(); + curr->value = popNonVoidExpression(); + curr->finalize(); + // Defer setting the table name for later, when we know it. + tableRefs[tableIdx].push_back(curr); + out = curr; + return true; +} + bool WasmBinaryBuilder::maybeVisitBinary(Expression*& out, uint8_t code) { Binary* curr; #define INT_TYPED_CODE(code) \ |