35#define DEBUG_TYPE "wasm-disassembler"
39#include "WebAssemblyGenDisassemblerTables.inc"
42static constexpr int WebAssemblyInstructionTableSize = 256;
45 std::unique_ptr<const MCInstrInfo> MCII;
57 std::unique_ptr<const MCInstrInfo> MCII)
65 std::unique_ptr<const MCInstrInfo> MCII(
T.createMCInstrInfo());
66 return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
89 const char *
Error =
nullptr;
115 support::endian::read<T, llvm::endianness::little>(Bytes.
data() +
Size);
117 if (std::is_floating_point<T>::value) {
133 int64_t FunctionCount;
136 outs() <<
" # " << FunctionCount <<
" functions in section.";
139 int64_t BodySize, LocalEntryCount;
143 if (LocalEntryCount) {
144 outs() <<
" .local ";
145 for (int64_t
I = 0;
I < LocalEntryCount;
I++) {
150 for (int64_t J = 0; J < Count; J++) {
170 const auto *WasmInst = &InstructionTable0[Opc];
172 if (WasmInst->ET == ET_Prefix) {
176 if (PT->Prefix == Opc) {
177 WasmInst = PT->Table;
186 if (PrefixedOpc < 0 || PrefixedOpc >= WebAssemblyInstructionTableSize)
188 WasmInst += PrefixedOpc;
190 if (WasmInst->ET == ET_Unused)
193 assert(WasmInst->ET == ET_Instruction);
194 MI.setOpcode(WasmInst->Opcode);
196 for (uint8_t OPI = 0; OPI < WasmInst->NumOperands; OPI++) {
197 auto OT = OperandTable[WasmInst->OperandStart + OPI];
230 if (
Size != PrevSize + 1) {
238 MCSymbol *
Sym = getContext().createTempSymbol(
"typeindex",
true);
239 auto *WasmSym = cast<MCSymbolWasm>(
Sym);
249 if (!parseImmediate<float>(
MI,
Size, Bytes))
254 if (!parseImmediate<double>(
MI,
Size, Bytes))
260 if (!parseImmediate<uint8_t>(
MI,
Size, Bytes))
265 if (!parseImmediate<uint16_t>(
MI,
Size, Bytes))
270 if (!parseImmediate<uint32_t>(
MI,
Size, Bytes))
275 if (!parseImmediate<uint64_t>(
MI,
Size, Bytes))
280 int64_t TargetTableLen;
283 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.
Tagged union holding either a T or a Error.
Context object for machine code objects.
Superclass for all disassemblers.
virtual Expected< bool > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address) 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_SECTION
@ 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.