1 // WebAssemblyAsmPrinter.h - WebAssembly implementation of AsmPrinter-*- C++ -*-
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
10 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H
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"
19 class WebAssemblyTargetStreamer
;
21 class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final
: public AsmPrinter
{
22 const WebAssemblySubtarget
*Subtarget
;
23 const MachineRegisterInfo
*MRI
;
24 WebAssemblyFunctionInfo
*MFI
;
25 bool signaturesEmitted
= false;
28 explicit WebAssemblyAsmPrinter(TargetMachine
&TM
,
29 std::unique_ptr
<MCStreamer
> Streamer
)
30 : AsmPrinter(TM
, std::move(Streamer
)), Subtarget(nullptr), MRI(nullptr),
33 StringRef
getPassName() const override
{
34 return "WebAssembly Assembly Printer";
37 const WebAssemblySubtarget
&getSubtarget() const { return *Subtarget
; }
39 //===------------------------------------------------------------------===//
40 // MachineFunctionPass Implementation.
41 //===------------------------------------------------------------------===//
43 bool runOnMachineFunction(MachineFunction
&MF
) override
{
44 Subtarget
= &MF
.getSubtarget
<WebAssemblySubtarget
>();
45 MRI
= &MF
.getRegInfo();
46 MFI
= MF
.getInfo
<WebAssemblyFunctionInfo
>();
47 return AsmPrinter::runOnMachineFunction(MF
);
50 //===------------------------------------------------------------------===//
51 // AsmPrinter Implementation.
52 //===------------------------------------------------------------------===//
54 void emitEndOfAsmFile(Module
&M
) override
;
55 void EmitProducerInfo(Module
&M
);
56 void EmitTargetFeatures(Module
&M
);
57 void EmitFunctionAttributes(Module
&M
);
58 void emitSymbolType(const MCSymbolWasm
*Sym
);
59 void emitGlobalVariable(const GlobalVariable
*GV
) override
;
60 void emitJumpTableInfo() override
;
61 void emitConstantPool() override
;
62 void emitFunctionBodyStart() override
;
63 void emitInstruction(const MachineInstr
*MI
) override
;
64 bool PrintAsmOperand(const MachineInstr
*MI
, unsigned OpNo
,
65 const char *ExtraCode
, raw_ostream
&OS
) override
;
66 bool PrintAsmMemoryOperand(const MachineInstr
*MI
, unsigned OpNo
,
67 const char *ExtraCode
, raw_ostream
&OS
) override
;
69 MVT
getRegType(unsigned RegNo
) const;
70 std::string
regToString(const MachineOperand
&MO
);
71 WebAssemblyTargetStreamer
*getTargetStreamer();
72 MCSymbolWasm
*getMCSymbolForFunction(const Function
*F
, bool EnableEmEH
,
73 wasm::WasmSignature
*Sig
,
74 bool &InvokeDetected
);
75 MCSymbol
*getOrCreateWasmSymbol(StringRef Name
);
76 void emitDecls(const Module
&M
);
79 } // end namespace llvm