LLVM  13.0.0git
WebAssemblyAsmPrinter.h
Go to the documentation of this file.
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 
13 #include "WebAssemblySubtarget.h"
15 #include "llvm/MC/MCStreamer.h"
17 
18 namespace llvm {
19 class WebAssemblyTargetStreamer;
20 
22  const WebAssemblySubtarget *Subtarget;
23  const MachineRegisterInfo *MRI;
25  // TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?
26  std::vector<std::unique_ptr<wasm::WasmSignature>> Signatures;
27  std::vector<std::unique_ptr<std::string>> Names;
28 
29  StringRef storeName(StringRef Name) {
30  std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
31  Names.push_back(std::move(N));
32  return *Names.back();
33  }
34 
35 public:
37  std::unique_ptr<MCStreamer> Streamer)
38  : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
39  MFI(nullptr) {}
40 
41  StringRef getPassName() const override {
42  return "WebAssembly Assembly Printer";
43  }
44 
45  const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
46  void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
47  Signatures.push_back(std::move(Sig));
48  }
49 
50  //===------------------------------------------------------------------===//
51  // MachineFunctionPass Implementation.
52  //===------------------------------------------------------------------===//
53 
55  Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
56  MRI = &MF.getRegInfo();
57  MFI = MF.getInfo<WebAssemblyFunctionInfo>();
59  }
60 
61  //===------------------------------------------------------------------===//
62  // AsmPrinter Implementation.
63  //===------------------------------------------------------------------===//
64 
65  void emitEndOfAsmFile(Module &M) override;
66  void EmitProducerInfo(Module &M);
67  void EmitTargetFeatures(Module &M);
68  void emitJumpTableInfo() override;
69  void emitConstantPool() override;
70  void emitFunctionBodyStart() override;
71  void emitInstruction(const MachineInstr *MI) override;
72  bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
73  const char *ExtraCode, raw_ostream &OS) override;
74  bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
75  const char *ExtraCode, raw_ostream &OS) override;
76 
77  MVT getRegType(unsigned RegNo) const;
78  std::string regToString(const MachineOperand &MO);
79  WebAssemblyTargetStreamer *getTargetStreamer();
80  MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH,
82  bool &InvokeDetected);
83 };
84 
85 } // end namespace llvm
86 
87 #endif
AsmPrinter.h
regToString
static yaml::StringValue regToString(Register Reg, const TargetRegisterInfo &TRI)
Definition: SIMachineFunctionInfo.cpp:488
llvm::WebAssemblyAsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: WebAssemblyAsmPrinter.h:54
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
llvm
Definition: AllocatorList.h:23
llvm::WebAssemblyTargetStreamer
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
Definition: WebAssemblyTargetStreamer.h:29
llvm::SystemZISD::TM
@ TM
Definition: SystemZISelLowering.h:65
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::Function
Definition: Function.h:61
llvm::WebAssemblyAsmPrinter::getSubtarget
const WebAssemblySubtarget & getSubtarget() const
Definition: WebAssemblyAsmPrinter.h:45
emitConstantPool
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)
Definition: ConstantPools.cpp:79
llvm::WebAssemblyAsmPrinter::getPassName
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: WebAssemblyAsmPrinter.h:41
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:565
TargetMachine.h
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:653
llvm::WebAssemblyAsmPrinter::addSignature
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
Definition: WebAssemblyAsmPrinter.h:46
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:555
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1563
llvm::WebAssemblyFunctionInfo
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Definition: WebAssemblyMachineFunctionInfo.h:33
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:30
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::WebAssemblyAsmPrinter
Definition: WebAssemblyAsmPrinter.h:21
WebAssemblyMachineFunctionInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:227
llvm::AsmPrinter::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:331
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
LLVM_LIBRARY_VISIBILITY
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
Definition: Compiler.h:131
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
WebAssemblySubtarget.h
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
N
#define N
MCStreamer.h
llvm::wasm::WasmSignature
Definition: Wasm.h:397
llvm::WebAssemblyAsmPrinter::WebAssemblyAsmPrinter
WebAssemblyAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
Definition: WebAssemblyAsmPrinter.h:36