blob: a37f8bcf6ba5965865b715bfbc532a0295344978 [file] [log] [blame]
Dan Gohmand934cb82017-02-24 23:18:00 +00001// 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 Blaikie75bda302017-10-24 21:29:15 +000013#include "WebAssemblyMachineFunctionInfo.h"
Dan Gohmand934cb82017-02-24 23:18:00 +000014#include "WebAssemblySubtarget.h"
15#include "llvm/CodeGen/AsmPrinter.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/Target/TargetMachine.h"
18
19namespace llvm {
20class MCSymbol;
Dan Gohmand934cb82017-02-24 23:18:00 +000021class WebAssemblyTargetStreamer;
22class WebAssemblyMCInstLower;
23
24class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
25 const WebAssemblySubtarget *Subtarget;
26 const MachineRegisterInfo *MRI;
27 WebAssemblyFunctionInfo *MFI;
28
29public:
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
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;
60 void EmitFunctionBodyEnd() override;
61 void EmitInstruction(const MachineInstr *MI) override;
62 const MCExpr *lowerConstant(const Constant *CV) override;
63 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
64 unsigned AsmVariant, const char *ExtraCode,
65 raw_ostream &OS) override;
66 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
67 unsigned AsmVariant, const char *ExtraCode,
68 raw_ostream &OS) override;
69
70 MVT getRegType(unsigned RegNo) const;
71 std::string regToString(const MachineOperand &MO);
72 WebAssemblyTargetStreamer *getTargetStreamer();
73};
74
75} // end namespace llvm
76
77#endif