diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-stack.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 24 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index b74b73ba1..8f6581956 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -81,10 +81,10 @@ void BinaryInstWriter::visitCall(Call* curr) { void BinaryInstWriter::visitCallIndirect(CallIndirect* curr) { Index tableIdx = parent.getTableIndex(curr->table); - int8_t op = curr->isReturn ? BinaryConsts::RetCallIndirect : BinaryConsts::CallIndirect; - o << op << U32LEB(parent.getTypeIndex(curr->sig)) << U32LEB(tableIdx); + o << op << U32LEB(parent.getTypeIndex(curr->getHeapType(parent.getModule()))) + << U32LEB(tableIdx); } void BinaryInstWriter::visitLocalGet(LocalGet* curr) { diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 26e6b369b..4975f4597 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -300,6 +300,30 @@ void CallIndirect::finalize() { } } +HeapType CallIndirect::getHeapType(Module* module) { + auto heapType = HeapType(sig); + // See comment in wasm.h + if (module) { + // The table may not yet exist if the wasm module is still being + // constructed. This should perhaps be an error, but as this is a hack for + // the time being, handle this the same as the case where module is null. + // Note: table_ (with underscore) is needed as |table| is a field on |this|. + if (auto* table_ = module->getTableOrNull(table)) { + // The wasm spec may allow more things eventually, and if so we'd need to + // add more checking here. + assert(table_->type.isRef()); + auto tableHeapType = table_->type.getHeapType(); + if (tableHeapType.isSignature()) { + auto tableSig = tableHeapType.getSignature(); + if (sig == tableSig) { + heapType = tableHeapType; + } + } + } + } + return heapType; +} + bool LocalSet::isTee() const { return type != Type::none; } // Changes to local.tee. The type of the local should be given. |