34 #define DEBUG_TYPE "wasm-disassembler" 38 #include "WebAssemblyGenDisassemblerTables.inc" 41 static constexpr
int WebAssemblyInstructionTableSize = 256;
44 std::unique_ptr<const MCInstrInfo> MCII;
55 std::unique_ptr<const MCInstrInfo> MCII)
64 return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
77 if (Size >= Bytes.
size())
87 const char *
Error =
nullptr;
102 if (!
nextLEB(Val, Bytes, Size, Signed))
108 template <
typename T>
110 if (Size +
sizeof(
T) > Bytes.
size())
112 T Val = support::endian::read<T, support::endianness::little, 1>(
115 if (std::is_floating_point<T>::value) {
129 int64_t FunctionCount;
132 outs() <<
" # " << FunctionCount <<
" functions in section.";
135 int64_t BodySize, LocalEntryCount;
139 if (LocalEntryCount) {
140 outs() <<
" .local ";
141 for (int64_t
I = 0;
I < LocalEntryCount;
I++) {
146 for (int64_t J = 0; J < Count; J++) {
166 const auto *WasmInst = &InstructionTable0[Opc];
168 if (WasmInst->ET == ET_Prefix) {
171 for (
auto PT = PrefixTable; PT->Table; PT++) {
172 if (PT->Prefix == Opc) {
173 WasmInst = PT->Table;
182 if (PrefixedOpc < 0 || PrefixedOpc >= WebAssemblyInstructionTableSize)
184 WasmInst += PrefixedOpc;
186 if (WasmInst->ET == ET_Unused)
189 assert(WasmInst->ET == ET_Instruction);
192 for (uint8_t OPI = 0; OPI < WasmInst->NumOperands; OPI++) {
193 auto OT = OperandTable[WasmInst->OperandStart + OPI];
219 uint64_t PrevSize =
Size;
224 if (
Size != PrevSize + 1) {
232 MCSymbol *Sym = getContext().createTempSymbol(
"typeindex",
true);
233 auto *WasmSym = cast<MCSymbolWasm>(Sym);
243 if (!parseImmediate<float>(MI,
Size, Bytes))
248 if (!parseImmediate<double>(MI,
Size, Bytes))
254 if (!parseImmediate<uint8_t>(MI,
Size, Bytes))
259 if (!parseImmediate<uint16_t>(MI,
Size, Bytes))
264 if (!parseImmediate<uint32_t>(MI,
Size, Bytes))
269 if (!parseImmediate<uint64_t>(MI,
Size, Bytes))
274 int64_t TargetTableLen;
277 for (int64_t
I = 0;
I < TargetTableLen;
I++) {
32-bit floating-point immediates.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
This class represents lattice values for constants.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
32-bit integer immediates.
DecodeStatus
Ternary decode status.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
16-bit vector lane immediate
static MCOperand createExpr(const MCExpr *Val)
Superclass for all disassemblers.
This class prints an WebAssembly MCInst to wasm file syntax.
32-bit unsigned memory offsets.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
Basic block label in a branch construct.
const char * anyTypeToString(unsigned Ty)
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
This file registers the WebAssembly target.
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.
Base class for the full range of assembler expressions which are needed for parsing.
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.
raw_ostream & outs()
This returns a reference to a raw_ostream for standard output.
64-bit integer immediates.
The instances of the Type class are immutable: once they are created, they are never changed...
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.
static bool nextLEB(int64_t &Val, ArrayRef< uint8_t > Bytes, uint64_t &Size, bool Signed)
void setOpcode(unsigned Op)
#define LLVM_EXTERNAL_VISIBILITY
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.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyDisassembler()
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)
StringRef - Represent a constant reference to a string, i.e.
Target & getTheWebAssemblyTarget32()
Target & getTheWebAssemblyTarget64()
static MCOperand createImm(int64_t Val)
32-bit vector lane immediate
bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes)