11a427287SDan Gohman //==- WebAssemblyDisassembler.cpp - Disassembler for WebAssembly -*- C++ -*-==//
21a427287SDan Gohman //
31a427287SDan Gohman //                     The LLVM Compiler Infrastructure
41a427287SDan Gohman //
51a427287SDan Gohman // This file is distributed under the University of Illinois Open Source
61a427287SDan Gohman // License. See LICENSE.TXT for details.
71a427287SDan Gohman //
81a427287SDan Gohman //===----------------------------------------------------------------------===//
91a427287SDan Gohman ///
101a427287SDan Gohman /// \file
111a427287SDan Gohman /// \brief This file is part of the WebAssembly Disassembler.
121a427287SDan Gohman ///
131a427287SDan Gohman /// It contains code to translate the data produced by the decoder into
141a427287SDan Gohman /// MCInsts.
151a427287SDan Gohman ///
161a427287SDan Gohman //===----------------------------------------------------------------------===//
171a427287SDan Gohman 
181a427287SDan Gohman #include "WebAssembly.h"
191a427287SDan Gohman #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
201a427287SDan Gohman #include "llvm/MC/MCContext.h"
21c50b8907SBenjamin Kramer #include "llvm/MC/MCDisassembler/MCDisassembler.h"
221a427287SDan Gohman #include "llvm/MC/MCInst.h"
231a427287SDan Gohman #include "llvm/MC/MCInstrInfo.h"
241a427287SDan Gohman #include "llvm/MC/MCSubtargetInfo.h"
251a427287SDan Gohman #include "llvm/MC/MCSymbol.h"
261a427287SDan Gohman #include "llvm/Support/Endian.h"
271a427287SDan Gohman #include "llvm/Support/TargetRegistry.h"
281a427287SDan Gohman using namespace llvm;
291a427287SDan Gohman 
301a427287SDan Gohman #define DEBUG_TYPE "wasm-disassembler"
311a427287SDan Gohman 
321a427287SDan Gohman namespace {
331a427287SDan Gohman class WebAssemblyDisassembler final : public MCDisassembler {
341a427287SDan Gohman   std::unique_ptr<const MCInstrInfo> MCII;
351a427287SDan Gohman 
361a427287SDan Gohman   DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
371a427287SDan Gohman                               ArrayRef<uint8_t> Bytes, uint64_t Address,
381a427287SDan Gohman                               raw_ostream &VStream,
391a427287SDan Gohman                               raw_ostream &CStream) const override;
401a427287SDan Gohman 
411a427287SDan Gohman public:
421a427287SDan Gohman   WebAssemblyDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
431a427287SDan Gohman                           std::unique_ptr<const MCInstrInfo> MCII)
441a427287SDan Gohman       : MCDisassembler(STI, Ctx), MCII(std::move(MCII)) {}
451a427287SDan Gohman };
461a427287SDan Gohman } // end anonymous namespace
471a427287SDan Gohman 
481a427287SDan Gohman static MCDisassembler *createWebAssemblyDisassembler(const Target &T,
491a427287SDan Gohman                                                      const MCSubtargetInfo &STI,
501a427287SDan Gohman                                                      MCContext &Ctx) {
511a427287SDan Gohman   std::unique_ptr<const MCInstrInfo> MCII(T.createMCInstrInfo());
521a427287SDan Gohman   return new WebAssemblyDisassembler(STI, Ctx, std::move(MCII));
531a427287SDan Gohman }
541a427287SDan Gohman 
551a427287SDan Gohman extern "C" void LLVMInitializeWebAssemblyDisassembler() {
561a427287SDan Gohman   // Register the disassembler for each target.
57f42454b9SMehdi Amini   TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget32(),
581a427287SDan Gohman                                          createWebAssemblyDisassembler);
59f42454b9SMehdi Amini   TargetRegistry::RegisterMCDisassembler(getTheWebAssemblyTarget64(),
601a427287SDan Gohman                                          createWebAssemblyDisassembler);
611a427287SDan Gohman }
621a427287SDan Gohman 
631a427287SDan Gohman MCDisassembler::DecodeStatus WebAssemblyDisassembler::getInstruction(
641a427287SDan Gohman     MCInst &MI, uint64_t &Size, ArrayRef<uint8_t> Bytes, uint64_t /*Address*/,
651a427287SDan Gohman     raw_ostream &OS, raw_ostream &CS) const {
661a427287SDan Gohman 
67*dfe6ce7aSDan Gohman   // TODO: Implement disassembly.
681a427287SDan Gohman 
691a427287SDan Gohman   return MCDisassembler::Fail;
701a427287SDan Gohman }
71