blob: 579cc9a493e4dfb57219e0e7f47dbed635c1a6ea [file] [log] [blame]
Dan Gohmand934cb82017-02-24 23:18:00 +00001// WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*-
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gohmand934cb82017-02-24 23:18:00 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
10#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
11
David Blaikie75bda302017-10-24 21:29:15 +000012#include "WebAssemblyMachineFunctionInfo.h"
Dan Gohmand934cb82017-02-24 23:18:00 +000013#include "WebAssemblySubtarget.h"
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/MC/MCStreamer.h"
16#include "llvm/Target/TargetMachine.h"
17
18namespace llvm {
19class MCSymbol;
Dan Gohmand934cb82017-02-24 23:18:00 +000020class WebAssemblyTargetStreamer;
21class WebAssemblyMCInstLower;
22
23class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
24 const WebAssemblySubtarget *Subtarget;
25 const MachineRegisterInfo *MRI;
26 WebAssemblyFunctionInfo *MFI;
Derek Schuff77a7a382018-10-03 22:22:48 +000027 // TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
28 std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
Dan Gohmand934cb82017-02-24 23:18:00 +000029
30public:
31 explicit WebAssemblyAsmPrinter(TargetMachine &TM,
32 std::unique_ptr<MCStreamer> Streamer)
Heejin Ahnf208f632018-09-05 01:27:38 +000033 : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
34 MFI(nullptr) {}
Dan Gohmand934cb82017-02-24 23:18:00 +000035
36 StringRef getPassName() const override {
37 return "WebAssembly Assembly Printer";
38 }
39
40 const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
Derek Schuff77a7a382018-10-03 22:22:48 +000041 void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
42 Signatures.push_back(std::move(Sig));
43 }
Dan Gohmand934cb82017-02-24 23:18:00 +000044
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 Livelyc6795e02019-01-18 02:47:48 +000061 void EmitProducerInfo(Module &M);
Dan Gohmand934cb82017-02-24 23:18:00 +000062 void EmitJumpTableInfo() override;
63 void EmitConstantPool() override;
64 void EmitFunctionBodyStart() override;
Dan Gohmand934cb82017-02-24 23:18:00 +000065 void EmitInstruction(const MachineInstr *MI) override;
Dan Gohmand934cb82017-02-24 23:18:00 +000066 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
67 unsigned AsmVariant, const char *ExtraCode,
68 raw_ostream &OS) override;
69 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
70 unsigned AsmVariant, const char *ExtraCode,
71 raw_ostream &OS) override;
72
73 MVT getRegType(unsigned RegNo) const;
74 std::string regToString(const MachineOperand &MO);
75 WebAssemblyTargetStreamer *getTargetStreamer();
76};
77
78} // end namespace llvm
79
80#endif