Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 1 | // WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*- |
| 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 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 11 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 12 | |
David Blaikie | 75bda30 | 2017-10-24 21:29:15 +0000 | [diff] [blame] | 13 | #include "WebAssemblyMachineFunctionInfo.h" |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 14 | #include "WebAssemblySubtarget.h" |
| 15 | #include "llvm/CodeGen/AsmPrinter.h" |
| 16 | #include "llvm/MC/MCStreamer.h" |
| 17 | #include "llvm/Target/TargetMachine.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | class MCSymbol; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 21 | class WebAssemblyTargetStreamer; |
| 22 | class WebAssemblyMCInstLower; |
| 23 | |
| 24 | class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter { |
| 25 | const WebAssemblySubtarget *Subtarget; |
| 26 | const MachineRegisterInfo *MRI; |
| 27 | WebAssemblyFunctionInfo *MFI; |
| 28 | |
| 29 | public: |
| 30 | explicit WebAssemblyAsmPrinter(TargetMachine &TM, |
| 31 | std::unique_ptr<MCStreamer> Streamer) |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 32 | : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr), |
| 33 | MFI(nullptr) {} |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 34 | |
| 35 | StringRef getPassName() const override { |
| 36 | return "WebAssembly Assembly Printer"; |
| 37 | } |
| 38 | |
| 39 | const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; } |
| 40 | |
| 41 | //===------------------------------------------------------------------===// |
| 42 | // MachineFunctionPass Implementation. |
| 43 | //===------------------------------------------------------------------===// |
| 44 | |
| 45 | bool runOnMachineFunction(MachineFunction &MF) override { |
| 46 | Subtarget = &MF.getSubtarget<WebAssemblySubtarget>(); |
| 47 | MRI = &MF.getRegInfo(); |
| 48 | MFI = MF.getInfo<WebAssemblyFunctionInfo>(); |
| 49 | return AsmPrinter::runOnMachineFunction(MF); |
| 50 | } |
| 51 | |
| 52 | //===------------------------------------------------------------------===// |
| 53 | // AsmPrinter Implementation. |
| 54 | //===------------------------------------------------------------------===// |
| 55 | |
| 56 | void EmitEndOfAsmFile(Module &M) override; |
| 57 | void EmitJumpTableInfo() override; |
| 58 | void EmitConstantPool() override; |
| 59 | void EmitFunctionBodyStart() override; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 60 | void EmitInstruction(const MachineInstr *MI) override; |
| 61 | const MCExpr *lowerConstant(const Constant *CV) override; |
| 62 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 63 | unsigned AsmVariant, const char *ExtraCode, |
| 64 | raw_ostream &OS) override; |
| 65 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 66 | unsigned AsmVariant, const char *ExtraCode, |
| 67 | raw_ostream &OS) override; |
| 68 | |
| 69 | MVT getRegType(unsigned RegNo) const; |
| 70 | std::string regToString(const MachineOperand &MO); |
| 71 | WebAssemblyTargetStreamer *getTargetStreamer(); |
| 72 | }; |
| 73 | |
| 74 | } // end namespace llvm |
| 75 | |
| 76 | #endif |