From 107c3a12d627f12a23f138a00d6aabe9de7402f7 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 3 Nov 2020 10:46:23 -0800 Subject: [WebAssembly] Implement ref.null This patch adds a new "heap type" operand kind to the WebAssembly MC layer, used by ref.null. Currently the possible values are "extern" and "func"; when typed function references come, though, this operand may be a type index. Note that the "heap type" production is still known as "refedtype" in the draft proposal; changing its name in the spec is ongoing (https://github.com/WebAssembly/reference-types/issues/123). The register form of ref.null is still untested. Differential Revision: https://reviews.llvm.org/D90608 --- .../Disassembler/WebAssemblyDisassembler.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp') diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp index 8c93b59..1b7cc09 100644 --- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp +++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp @@ -241,6 +241,28 @@ MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction( } break; } + // heap_type operands, for e.g. ref.null: + case WebAssembly::OPERAND_HEAPTYPE: { + int64_t Val; + uint64_t PrevSize = Size; + if (!nextLEB(Val, Bytes, Size, true)) + return MCDisassembler::Fail; + if (Val < 0 && Size == PrevSize + 1) { + // The HeapType encoding is like BlockType, in that encodings that + // decode as negative values indicate ValTypes. In practice we expect + // either wasm::ValType::EXTERNREF or wasm::ValType::FUNCREF here. + // + // The positive SLEB values are reserved for future expansion and are + // expected to be type indices in the typed function references + // proposal, and should disassemble as MCSymbolRefExpr as in BlockType + // above. + MI.addOperand(MCOperand::createImm(Val & 0x7f)); + } else { + MI.addOperand( + MCOperand::createImm(int64_t(WebAssembly::HeapType::Invalid))); + } + break; + } // FP operands. case WebAssembly::OPERAND_F32IMM: { if (!parseImmediate(MI, Size, Bytes)) -- cgit v1.1