Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 1 | // WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*- |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 10 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H |
| 11 | |
David Blaikie | 75bda30 | 2017-10-24 21:29:15 +0000 | [diff] [blame] | 12 | #include "WebAssemblyMachineFunctionInfo.h" |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 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 MCSymbol; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 20 | class WebAssemblyTargetStreamer; |
| 21 | class WebAssemblyMCInstLower; |
| 22 | |
| 23 | class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter { |
| 24 | const WebAssemblySubtarget *Subtarget; |
| 25 | const MachineRegisterInfo *MRI; |
| 26 | WebAssemblyFunctionInfo *MFI; |
Derek Schuff | 77a7a38 | 2018-10-03 22:22:48 +0000 | [diff] [blame] | 27 | // TODO: Do the uniquing of Signatures here instead of ObjectFileWriter? |
| 28 | std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 29 | |
| 30 | public: |
| 31 | explicit WebAssemblyAsmPrinter(TargetMachine &TM, |
| 32 | std::unique_ptr<MCStreamer> Streamer) |
Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 33 | : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr), |
| 34 | MFI(nullptr) {} |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 35 | |
| 36 | StringRef getPassName() const override { |
| 37 | return "WebAssembly Assembly Printer"; |
| 38 | } |
| 39 | |
| 40 | const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; } |
Derek Schuff | 77a7a38 | 2018-10-03 22:22:48 +0000 | [diff] [blame] | 41 | void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) { |
| 42 | Signatures.push_back(std::move(Sig)); |
| 43 | } |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 44 | |
| 45 | //===------------------------------------------------------------------===// |
| 46 | // MachineFunctionPass Implementation. |
| 47 | //===------------------------------------------------------------------===// |
| 48 | |
| 49 | bool runOnMachineFunction(MachineFunction &MF) override { |
| 50 | Subtarget = &MF.getSubtarget<WebAssemblySubtarget>(); |
| 51 | MRI = &MF.getRegInfo(); |
| 52 | MFI = MF.getInfo<WebAssemblyFunctionInfo>(); |
| 53 | return AsmPrinter::runOnMachineFunction(MF); |
| 54 | } |
| 55 | |
| 56 | //===------------------------------------------------------------------===// |
| 57 | // AsmPrinter Implementation. |
| 58 | //===------------------------------------------------------------------===// |
| 59 | |
| 60 | void EmitEndOfAsmFile(Module &M) override; |
Thomas Lively | c6795e0 | 2019-01-18 02:47:48 +0000 | [diff] [blame] | 61 | void EmitProducerInfo(Module &M); |
Thomas Lively | 3f34e1b8 | 2019-03-29 00:14:01 +0000 | [diff] [blame] | 62 | void EmitTargetFeatures(Module &M); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 63 | void EmitJumpTableInfo() override; |
| 64 | void EmitConstantPool() override; |
| 65 | void EmitFunctionBodyStart() override; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 66 | void EmitInstruction(const MachineInstr *MI) override; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 67 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Nick Desaulniers | 5277b3f | 2019-04-10 16:38:43 +0000 | [diff] [blame] | 68 | const char *ExtraCode, raw_ostream &OS) override; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 69 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
Nick Desaulniers | 5277b3f | 2019-04-10 16:38:43 +0000 | [diff] [blame] | 70 | const char *ExtraCode, raw_ostream &OS) override; |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 71 | |
| 72 | MVT getRegType(unsigned RegNo) const; |
| 73 | std::string regToString(const MachineOperand &MO); |
| 74 | WebAssemblyTargetStreamer *getTargetStreamer(); |
| 75 | }; |
| 76 | |
| 77 | } // end namespace llvm |
| 78 | |
| 79 | #endif |