| 1 | // WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*- |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 10 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 11 | |
| 12 | #include "WebAssemblyMachineFunctionInfo.h" |
| 13 | #include "WebAssemblySubtarget.h" |
| 14 | #include "llvm/CodeGen/AsmPrinter.h" |
| 15 | #include "llvm/MC/MCStreamer.h" |
| 16 | #include "llvm/Target/TargetMachine.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | class WebAssemblyTargetStreamer; |
| 20 | |
| 21 | class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter { |
| 22 | public: |
| 23 | static char ID; |
| 24 | |
| 25 | private: |
| 26 | const WebAssemblySubtarget *Subtarget; |
| 27 | const MachineRegisterInfo *MRI; |
| 28 | WebAssemblyFunctionInfo *MFI; |
| 29 | bool signaturesEmitted = false; |
| 30 | |
| 31 | public: |
| 32 | explicit WebAssemblyAsmPrinter(TargetMachine &TM, |
| 33 | std::unique_ptr<MCStreamer> Streamer) |
| 34 | : AsmPrinter(TM, std::move(Streamer), ID), Subtarget(nullptr), |
| 35 | MRI(nullptr), MFI(nullptr) {} |
| 36 | |
| 37 | StringRef getPassName() const override { |
| 38 | return "WebAssembly Assembly Printer" ; |
| 39 | } |
| 40 | |
| 41 | const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; } |
| 42 | |
| 43 | //===------------------------------------------------------------------===// |
| 44 | // MachineFunctionPass Implementation. |
| 45 | //===------------------------------------------------------------------===// |
| 46 | |
| 47 | bool runOnMachineFunction(MachineFunction &MF) override { |
| 48 | Subtarget = &MF.getSubtarget<WebAssemblySubtarget>(); |
| 49 | MRI = &MF.getRegInfo(); |
| 50 | MFI = MF.getInfo<WebAssemblyFunctionInfo>(); |
| 51 | return AsmPrinter::runOnMachineFunction(MF); |
| 52 | } |
| 53 | |
| 54 | //===------------------------------------------------------------------===// |
| 55 | // AsmPrinter Implementation. |
| 56 | //===------------------------------------------------------------------===// |
| 57 | |
| 58 | void emitEndOfAsmFile(Module &M) override; |
| 59 | void EmitProducerInfo(Module &M); |
| 60 | void EmitTargetFeatures(Module &M); |
| 61 | void EmitFunctionAttributes(Module &M); |
| 62 | void emitSymbolType(const MCSymbolWasm *Sym); |
| 63 | void emitGlobalVariable(const GlobalVariable *GV) override; |
| 64 | void emitJumpTableInfo() override; |
| 65 | void emitConstantPool() override; |
| 66 | void emitFunctionBodyStart() override; |
| 67 | void emitInstruction(const MachineInstr *MI) override; |
| 68 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 69 | const char *, raw_ostream &OS) override; |
| 70 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 71 | const char *, raw_ostream &OS) override; |
| 72 | |
| 73 | MVT getRegType(unsigned RegNo) const; |
| 74 | std::string regToString(const MachineOperand &MO); |
| 75 | WebAssemblyTargetStreamer *getTargetStreamer(); |
| 76 | MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH, |
| 77 | wasm::WasmSignature *Sig, |
| 78 | bool &InvokeDetected); |
| 79 | MCSymbol *getOrCreateWasmSymbol(StringRef Name); |
| 80 | void emitDecls(const Module &M); |
| 81 | }; |
| 82 | |
| 83 | } // end namespace llvm |
| 84 | |
| 85 | #endif |
| 86 | |