1 //==- WebAssemblyDisassembler.cpp - Disassembler for WebAssembly -*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file is part of the WebAssembly Disassembler.
13 /// It contains code to translate the data produced by the decoder into
16 //===----------------------------------------------------------------------===//
18 #include "WebAssembly.h"
19 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstrInfo.h"
24 #include "llvm/MC/MCSubtargetInfo.h"
25 #include "llvm/MC/MCSymbol.h"
26 #include "llvm/Support/Endian.h"
27 #include "llvm/Support/TargetRegistry.h"
30 #define DEBUG_TYPE "wasm-disassembler"
33 class WebAssemblyDisassembler final : public MCDisassembler {
34 std::unique_ptr<const MCInstrInfo> MCII;
36 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
37 ArrayRef<uint8_t> Bytes, uint64_t Address,
39 raw_ostream &CStream) const override;
42 WebAssemblyDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
43 std::unique_ptr<const MCInstrInfo> MCII)
44 : MCDisassembler(STI, Ctx), MCII(std::move(MCII)) {}
46 } // end anonymous namespace
48 static MCDisassembler *createWebAssemblyDisassembler(const Target &T,
49 const MCSubtargetInfo &STI,
51 std::unique_ptr<const MCInstrInfo> MCII(T.createMCInstrInfo());
52 return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
55 extern "C" void LLVMInitializeWebAssemblyDisassembler() {
56 // Register the disassembler for each target.
57 TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget32(),
58 createWebAssemblyDisassembler);
59 TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget64(),
60 createWebAssemblyDisassembler);
63 MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
64 MCInst &MI, uint64_t &Size, ArrayRef<uint8_t> Bytes, uint64_t /*Address*/,
65 raw_ostream &OS, raw_ostream &CS) const {
67 // TODO: Implement disassembly.
69 return MCDisassembler::Fail;