Dan Gohman | 05ac43f | 2015-12-17 01:39:00 +0000 | [diff] [blame^] | 1 | //=- WebAssemblyMCCodeEmitter.cpp - Convert WebAssembly code to machine code -// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file implements the WebAssemblyMCCodeEmitter class. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" |
| 16 | #include "llvm/ADT/Statistic.h" |
| 17 | #include "llvm/MC/MCCodeEmitter.h" |
| 18 | #include "llvm/MC/MCFixup.h" |
| 19 | #include "llvm/MC/MCInst.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
| 21 | #include "llvm/MC/MCRegisterInfo.h" |
| 22 | #include "llvm/MC/MCSubtargetInfo.h" |
| 23 | #include "llvm/MC/MCSymbol.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | using namespace llvm; |
| 26 | |
| 27 | #define DEBUG_TYPE "mccodeemitter" |
| 28 | |
| 29 | namespace { |
| 30 | class WebAssemblyMCCodeEmitter final : public MCCodeEmitter { |
| 31 | const MCInstrInfo &MCII; |
| 32 | const MCRegisterInfo &MRI; |
| 33 | const MCContext &Ctx; |
| 34 | |
| 35 | public: |
| 36 | WebAssemblyMCCodeEmitter(const MCInstrInfo &mcii, const MCRegisterInfo &mri, |
| 37 | MCContext &ctx) |
| 38 | : MCII(mcii), MRI(mri), Ctx(ctx) {} |
| 39 | |
| 40 | ~WebAssemblyMCCodeEmitter() override {} |
| 41 | |
| 42 | /// TableGen'erated function for getting the binary encoding for an |
| 43 | /// instruction. |
| 44 | uint64_t getBinaryCodeForInstr(const MCInst &MI, |
| 45 | SmallVectorImpl<MCFixup> &Fixups, |
| 46 | const MCSubtargetInfo &STI) const; |
| 47 | |
| 48 | /// Return binary encoding of operand. If the machine operand requires |
| 49 | /// relocation, record the relocation and return zero. |
| 50 | unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, |
| 51 | SmallVectorImpl<MCFixup> &Fixups, |
| 52 | const MCSubtargetInfo &STI) const; |
| 53 | |
| 54 | uint64_t getMemoryOpValue(const MCInst &MI, unsigned Op, |
| 55 | SmallVectorImpl<MCFixup> &Fixups, |
| 56 | const MCSubtargetInfo &STI) const; |
| 57 | |
| 58 | void encodeInstruction(const MCInst &MI, raw_ostream &OS, |
| 59 | SmallVectorImpl<MCFixup> &Fixups, |
| 60 | const MCSubtargetInfo &STI) const override; |
| 61 | }; |
| 62 | } // end anonymous namespace |
| 63 | |
| 64 | MCCodeEmitter *llvm::createWebAssemblyMCCodeEmitter(const MCInstrInfo &MCII, |
| 65 | const MCRegisterInfo &MRI, |
| 66 | MCContext &Ctx) { |
| 67 | return new WebAssemblyMCCodeEmitter(MCII, MRI, Ctx); |
| 68 | } |
| 69 | |
| 70 | unsigned WebAssemblyMCCodeEmitter::getMachineOpValue( |
| 71 | const MCInst &MI, const MCOperand &MO, SmallVectorImpl<MCFixup> &Fixups, |
| 72 | const MCSubtargetInfo &STI) const { |
| 73 | if (MO.isReg()) |
| 74 | return MRI.getEncodingValue(MO.getReg()); |
| 75 | if (MO.isImm()) |
| 76 | return static_cast<unsigned>(MO.getImm()); |
| 77 | |
| 78 | assert(MO.isExpr()); |
| 79 | |
| 80 | const MCExpr *Expr = MO.getExpr(); |
| 81 | |
| 82 | assert(Expr->getKind() == MCExpr::SymbolRef); |
| 83 | |
| 84 | assert(false && "FIXME: not implemented yet"); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | void WebAssemblyMCCodeEmitter::encodeInstruction( |
| 90 | const MCInst &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups, |
| 91 | const MCSubtargetInfo &STI) const { |
| 92 | assert(false && "FIXME: not implemented yet"); |
| 93 | } |
| 94 | |
| 95 | // Encode WebAssembly Memory Operand |
| 96 | uint64_t |
| 97 | WebAssemblyMCCodeEmitter::getMemoryOpValue(const MCInst &MI, unsigned Op, |
| 98 | SmallVectorImpl<MCFixup> &Fixups, |
| 99 | const MCSubtargetInfo &STI) const { |
| 100 | assert(false && "FIXME: not implemented yet"); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | #include "WebAssemblyGenMCCodeEmitter.inc" |