summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp24
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) \