LLVM 17.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
15#include "llvm/MC/MCStreamer.h"
17
18namespace llvm {
19class WebAssemblyTargetStreamer;
20
22 const WebAssemblySubtarget *Subtarget;
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 bool signaturesEmitted = false;
29
30 StringRef storeName(StringRef Name) {
31 std::unique_ptr<std::string> N = std::make_unique<std::string>(Name);
32 Names.push_back(std::move(N));
33 return *Names.back();
34 }
35
36public:
38 std::unique_ptr<MCStreamer> Streamer)
39 : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
40 MFI(nullptr) {}
41
42 StringRef getPassName() const override {
43 return "WebAssembly Assembly Printer";
44 }
45
46 const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
47 void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
48 Signatures.push_back(std::move(Sig));
49 }
50
51 //===------------------------------------------------------------------===//
52 // MachineFunctionPass Implementation.
53 //===------------------------------------------------------------------===//
54
56 Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
57 MRI = &MF.getRegInfo();
60 }
61
62 //===------------------------------------------------------------------===//
63 // AsmPrinter Implementation.
64 //===------------------------------------------------------------------===//
65
66 void emitEndOfAsmFile(Module &M) override;
67 void EmitProducerInfo(Module &M);
68 void EmitTargetFeatures(Module &M);
69 void emitSymbolType(const MCSymbolWasm *Sym);
70 void emitGlobalVariable(const GlobalVariable *GV) override;
71 void emitJumpTableInfo() override;
72 void emitConstantPool() override;
73 void emitFunctionBodyStart() override;
74 void emitInstruction(const MachineInstr *MI) override;
75 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
76 const char *ExtraCode, raw_ostream &OS) override;
77 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
78 const char *ExtraCode, raw_ostream &OS) override;
79
80 MVT getRegType(unsigned RegNo) const;
81 std::string regToString(const MachineOperand &MO);
82 WebAssemblyTargetStreamer *getTargetStreamer();
83 MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH,
85 bool &InvokeDetected);
86 MCSymbol *getOrCreateWasmSymbol(StringRef Name);
87 void emitDecls(const Module &M);
88};
89
90} // end namespace llvm
91
92#endif
unsigned const MachineRegisterInfo * MRI
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
Definition: Compiler.h:126
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)
std::string Name
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
const char LLVMTargetMachineRef TM
static yaml::StringValue regToString(Register Reg, const TargetRegisterInfo &TRI)
static const FuncProtoTy Signatures[]
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
Definition: AsmPrinter.h:395
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Machine Value Type.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
Definition: MachineInstr.h:68
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
const WebAssemblySubtarget & getSubtarget() const
WebAssemblyAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
void addSignature(std::unique_ptr< wasm::WasmSignature > &&Sig)
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
WebAssembly-specific streamer interface, to implement support WebAssembly-specific assembly directive...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1862
Definition: BitVector.h:851
#define N