32 #define DEBUG_TYPE "wasm-disassembler" 36 #include "WebAssemblyGenDisassemblerTables.inc" 39 static constexpr
int WebAssemblyInstructionTableSize = 256;
42 std::unique_ptr<const MCInstrInfo> MCII;
51 std::unique_ptr<const MCInstrInfo> MCII)
60 return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
72 if (Size >= Bytes.
size())
82 const char *
Error =
nullptr;
97 if (!
nextLEB(Val, Bytes, Size, Signed))
103 template <
typename T>
105 if (Size +
sizeof(
T) > Bytes.
size())
109 support::endian::byte_swap<T, support::endianness::little>(Val);
111 if (std::is_floating_point<T>::value) {
127 const auto *WasmInst = &InstructionTable0[Opc];
129 if (WasmInst->ET == ET_Prefix) {
132 for (
auto PT = PrefixTable; PT->Table; PT++) {
133 if (PT->Prefix == Opc) {
134 WasmInst = PT->Table;
143 if (PrefixedOpc < 0 || PrefixedOpc >= WebAssemblyInstructionTableSize)
145 WasmInst += PrefixedOpc;
147 if (WasmInst->ET == ET_Unused)
150 assert(WasmInst->ET == ET_Instruction);
153 for (uint8_t OPI = 0; OPI < WasmInst->NumOperands; OPI++) {
154 auto OT = OperandTable[WasmInst->OperandStart + OPI];
178 if (!parseImmediate<uint8_t>(MI,
Size, Bytes))
184 if (!parseImmediate<float>(MI,
Size, Bytes))
189 if (!parseImmediate<double>(MI,
Size, Bytes))
195 if (!parseImmediate<uint8_t>(MI,
Size, Bytes))
200 if (!parseImmediate<uint16_t>(MI,
Size, Bytes))
205 if (!parseImmediate<uint32_t>(MI,
Size, Bytes))
210 if (!parseImmediate<uint64_t>(MI,
Size, Bytes))
215 int64_t TargetTableLen;
218 for (int64_t
I = 0;
I < TargetTableLen;
I++) {
32-bit floating-point immediates.
This class represents lattice values for constants.
void LLVMInitializeWebAssemblyDisassembler()
32-bit integer immediates.
DecodeStatus
Ternary decode status.
16-bit vector lane immediate
Superclass for all disassemblers.
32-bit unsigned memory offsets.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
Basic block label in a branch construct.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
A list of branch targets for br_list.
8-bit vector lane immediate
signature immediate for block/loop.
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.
Context object for machine code objects.
static int nextByte(ArrayRef< uint8_t > Bytes, uint64_t &Size)
Instances of this class represent a single low-level machine instruction.
64-bit integer immediates.
64-bit vector lane immediate
size_t size() const
size - Get the array size.
This file provides WebAssembly-specific target descriptions.
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.
type signature immediate for call_indirect.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setOpcode(unsigned Op)
static MCOperand createFPImm(double Val)
Target - Wrapper for Target specific information.
64-bit floating-point immediates.
32-bit unsigned function indices.
static MCDisassembler * createWebAssemblyDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
p2align immediate for load and store address alignment.
Generic base class for all target subtargets.
static bool parseLEBImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes, bool Signed)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()
static bool nextLEB(int64_t &Val, ArrayRef< uint8_t > Bytes, uint64_t &Size, bool Signed=false)
static MCOperand createImm(int64_t Val)
32-bit vector lane immediate
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)