diff options
author | Andy Wingo <wingo@igalia.com> | 2020-11-03 10:46:23 -0800 |
---|---|---|
committer | Thomas Lively <tlively@google.com> | 2020-11-03 10:46:23 -0800 |
commit | 107c3a12d627f12a23f138a00d6aabe9de7402f7 (patch) | |
tree | 956497feb7d3fde2dd7af347b539891e618f2f93 /llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp | |
parent | ca5b31502c828f8e7160a77f54a5a131dc298005 (diff) | |
download | llvm-107c3a12d627f12a23f138a00d6aabe9de7402f7.zip llvm-107c3a12d627f12a23f138a00d6aabe9de7402f7.tar.gz llvm-107c3a12d627f12a23f138a00d6aabe9de7402f7.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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<float>(MI, Size, Bytes)) |