diff options
author | Max Graey <maxgraey@gmail.com> | 2021-10-09 05:26:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 19:26:08 -0700 |
commit | ef686a4d932b9b86edc34a3b9b15926f943f6f7b (patch) | |
tree | 38a89d5b555d4501b7d504a66c7aec409e45e9b1 /src/wasm/wasm-binary.cpp | |
parent | 53c5e3e62db25fe3522a1fa615a1f53c4cefdf06 (diff) | |
download | binaryen-ef686a4d932b9b86edc34a3b9b15926f943f6f7b.tar.gz binaryen-ef686a4d932b9b86edc34a3b9b15926f943f6f7b.tar.bz2 binaryen-ef686a4d932b9b86edc34a3b9b15926f943f6f7b.zip |
Add table.size operation (#4224)
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 7e72b056f..9aa18f270 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -2793,6 +2793,8 @@ void WasmBinaryBuilder::processNames() { get->table = getTableName(index); } else if (auto* set = ref->dynCast<TableSet>()) { set->table = getTableName(index); + } else if (auto* size = ref->dynCast<TableSize>()) { + size->table = getTableName(index); } else { WASM_UNREACHABLE("Invalid type in table references"); } @@ -3613,8 +3615,10 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { if (maybeVisitMemoryFill(curr, opcode)) { break; } - throwError("invalid code after nontrapping float-to-int prefix: " + - std::to_string(opcode)); + if (maybeVisitTableSize(curr, opcode)) { + break; + } + throwError("invalid code after misc prefix: " + std::to_string(opcode)); break; } case BinaryConsts::SIMDPrefix: { @@ -4918,6 +4922,22 @@ bool WasmBinaryBuilder::maybeVisitMemoryFill(Expression*& out, uint32_t code) { return true; } +bool WasmBinaryBuilder::maybeVisitTableSize(Expression*& out, uint32_t code) { + if (code != BinaryConsts::TableSize) { + return false; + } + Index tableIdx = getU32LEB(); + if (tableIdx >= tables.size()) { + throwError("bad table index"); + } + auto* curr = allocator.alloc<TableSize>(); + 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) \ |