35#define DEBUG_TYPE "wasm-disassembler"
39#include "WebAssemblyGenDisassemblerTables.inc"
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;
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++) {
163 MCInst &
MI, uint64_t &
Size, ArrayRef<uint8_t> Bytes, uint64_t ,
164 raw_ostream &CS)
const {
170 const auto *WasmInst = &InstructionTable0[
Opc];
172 if (WasmInst->ET == ET_Prefix) {
175 for (
const auto &[Prefix, Table] : PrefixTable) {
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];
225 uint64_t PrevSize =
Size;
230 if (
Size != PrevSize + 1) {
239 auto *WasmSym =
static_cast<MCSymbolWasm *
>(Sym);
280 int64_t TargetTableLen;
283 for (int64_t
I = 0;
I < TargetTableLen;
I++) {
295 int64_t NumCatches =
MI.getOperand(
MI.getNumOperands() - 1).getImm();
296 for (int64_t
I = 0;
I < NumCatches;
I++) {
299 int64_t CatchOpcode =
MI.getOperand(
MI.getNumOperands() - 1).getImm();
MCDisassembler::DecodeStatus DecodeStatus
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_EXTERNAL_VISIBILITY
static constexpr int WebAssemblyInstructionTableSize
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)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyDisassembler()
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 WebAssemblyMCAsmInfo class.
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.
DecodeStatus
Ternary decode status.
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, SMLoc Loc=SMLoc())
Target - Wrapper for Target specific information.
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_CATCH_LIST
A list of catch clauses for try_table.
@ 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)
Context & getContext() const
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
@ WASM_SYMBOL_TYPE_SECTION
@ WASM_SYMBOL_TYPE_FUNCTION
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI 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()
FunctionAddr VTableAddr Count
Target & getTheWebAssemblyTarget64()
To bit_cast(const From &from) noexcept
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.