33#define DEBUG_TYPE "wasm-disassembler"
37#include "WebAssemblyGenDisassemblerTables.inc"
40static constexpr int WebAssemblyInstructionTableSize = 256;
43 std::unique_ptr<const MCInstrInfo> MCII;
48 std::optional<DecodeStatus>
54 std::unique_ptr<const MCInstrInfo> MCII)
62 std::unique_ptr<const MCInstrInfo> MCII(
T.createMCInstrInfo());
63 return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
86 const char *
Error =
nullptr;
111 T Val = support::endian::read<T, support::endianness::little, 1>(
114 if (std::is_floating_point<T>::value) {
123std::optional<MCDisassembler::DecodeStatus>
131 int64_t FunctionCount;
134 outs() <<
" # " << FunctionCount <<
" functions in section.";
137 int64_t BodySize, LocalEntryCount;
141 if (LocalEntryCount) {
142 outs() <<
" .local ";
143 for (int64_t
I = 0;
I < LocalEntryCount;
I++) {
148 for (int64_t J = 0; J < Count; J++) {
168 const auto *WasmInst = &InstructionTable0[Opc];
170 if (WasmInst->ET == ET_Prefix) {
174 if (PT->Prefix == Opc) {
175 WasmInst = PT->Table;
184 if (PrefixedOpc < 0 || PrefixedOpc >= WebAssemblyInstructionTableSize)
186 WasmInst += PrefixedOpc;
188 if (WasmInst->ET == ET_Unused)
191 assert(WasmInst->ET == ET_Instruction);
192 MI.setOpcode(WasmInst->Opcode);
194 for (uint8_t OPI = 0; OPI < WasmInst->NumOperands; OPI++) {
195 auto OT = OperandTable[WasmInst->OperandStart + OPI];
228 if (
Size != PrevSize + 1) {
236 MCSymbol *Sym = getContext().createTempSymbol(
"typeindex",
true);
237 auto *WasmSym = cast<MCSymbolWasm>(Sym);
247 if (!parseImmediate<float>(
MI,
Size, Bytes))
252 if (!parseImmediate<double>(
MI,
Size, Bytes))
258 if (!parseImmediate<uint8_t>(
MI,
Size, Bytes))
263 if (!parseImmediate<uint16_t>(
MI,
Size, Bytes))
268 if (!parseImmediate<uint32_t>(
MI,
Size, Bytes))
273 if (!parseImmediate<uint64_t>(
MI,
Size, Bytes))
278 int64_t TargetTableLen;
281 for (int64_t
I = 0;
I < TargetTableLen;
I++) {
static constexpr const ArrayRef< StringLiteral > PrefixTable(PrefixTable_init, std::size(PrefixTable_init) - 1)
#define LLVM_EXTERNAL_VISIBILITY
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyDisassembler()
static int nextByte(ArrayRef< uint8_t > Bytes, uint64_t &Size)
static bool nextLEB(int64_t &Val, ArrayRef< uint8_t > Bytes, uint64_t &Size, bool Signed)
static MCDisassembler * createWebAssemblyDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)
static bool parseLEBImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes, bool Signed)
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file registers the WebAssembly target.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
Context object for machine code objects.
Superclass for all disassemblers.
virtual std::optional< DecodeStatus > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const
Used to perform separate target specific disassembly for a particular symbol.
DecodeStatus
Ternary decode status.
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a single low-level machine instruction.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createImm(int64_t Val)
static MCOperand createDFPImm(uint64_t Val)
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ OPERAND_GLOBAL
Global index.
@ OPERAND_OFFSET64
64-bit unsigned memory offsets.
@ OPERAND_I32IMM
32-bit integer immediates.
@ OPERAND_P2ALIGN
p2align immediate for load and store address alignment.
@ OPERAND_TABLE
32-bit unsigned table number.
@ OPERAND_LOCAL
Local index.
@ OPERAND_VEC_I64IMM
64-bit vector lane immediate
@ OPERAND_VEC_I16IMM
16-bit vector lane immediate
@ OPERAND_TYPEINDEX
type signature immediate for call_indirect.
@ OPERAND_FUNCTION32
32-bit unsigned function indices.
@ OPERAND_F32IMM
32-bit floating-point immediates.
@ OPERAND_BASIC_BLOCK
Basic block label in a branch construct.
@ OPERAND_VEC_I32IMM
32-bit vector lane immediate
@ OPERAND_BRLIST
A list of branch targets for br_list.
@ OPERAND_F64IMM
64-bit floating-point immediates.
@ OPERAND_VEC_I8IMM
8-bit vector lane immediate
@ OPERAND_SIGNATURE
signature immediate for block/loop.
@ OPERAND_I64IMM
64-bit integer immediates.
@ OPERAND_OFFSET32
32-bit unsigned memory offsets.
const char * anyTypeToString(unsigned Type)
@ WASM_SYMBOL_TYPE_FUNCTION
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.