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 13 #include "WebAssemblyMachineFunctionInfo.h" 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; 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: WebAssemblyAsmPrinter(TargetMachine & TM,std::unique_ptr<MCStreamer> Streamer)30 explicit WebAssemblyAsmPrinter(TargetMachine &TM, 31 std::unique_ptr<MCStreamer> Streamer) 32 : AsmPrinter(TM, std::move(Streamer)), 33 Subtarget(nullptr), MRI(nullptr), MFI(nullptr) {} 34 getPassName()35 StringRef getPassName() const override { 36 return "WebAssembly Assembly Printer"; 37 } 38 getSubtarget()39 const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; } 40 41 //===------------------------------------------------------------------===// 42 // MachineFunctionPass Implementation. 43 //===------------------------------------------------------------------===// 44 runOnMachineFunction(MachineFunction & MF)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; 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 77