LLVM 19.0.0git
Go to the documentation of this file.
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
15#include "llvm/MC/MCStreamer.h"
18namespace llvm {
19class WebAssemblyTargetStreamer;
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;
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 }
38 std::unique_ptr<MCStreamer> Streamer)
39 : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), MRI(nullptr),
40 MFI(nullptr) {}
42 StringRef getPassName() const override {
43 return "WebAssembly Assembly Printer";
44 }
46 const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }
47 void addSignature(std::unique_ptr<wasm::WasmSignature> &&Sig) {
48 Signatures.push_back(std::move(Sig));
49 }
51 //===------------------------------------------------------------------===//
52 // MachineFunctionPass Implementation.
53 //===------------------------------------------------------------------===//
56 Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();
57 MRI = &MF.getRegInfo();
59 return AsmPrinter::runOnMachineFunction(MF);
60 }
62 //===------------------------------------------------------------------===//
63 // AsmPrinter Implementation.
64 //===------------------------------------------------------------------===//
66 void emitEndOfAsmFile(Module &M) override;
67 void EmitProducerInfo(Module &M);
68 void EmitTargetFeatures(Module &M);
69 void EmitFunctionAttributes(Module &M);
70 void emitSymbolType(const MCSymbolWasm *Sym);
71 void emitGlobalVariable(const GlobalVariable *GV) override;
72 void emitJumpTableInfo() override;
73 void emitConstantPool() override;
74 void emitFunctionBodyStart() override;
75 void emitInstruction(const MachineInstr *MI) override;
76 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
77 const char *ExtraCode, raw_ostream &OS) override;
78 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
79 const char *ExtraCode, raw_ostream &OS) override;
81 MVT getRegType(unsigned RegNo) const;
82 std::string regToString(const MachineOperand &MO);
83 WebAssemblyTargetStreamer *getTargetStreamer();
84 MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH,
86 bool &InvokeDetected);
87 MCSymbol *getOrCreateWasmSymbol(StringRef Name);
88 void emitDecls(const Module &M);
91} // end namespace llvm
unsigned const MachineRegisterInfo * MRI
Definition: Compiler.h:131
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section, ConstantPool &CP)
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
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)
raw_pwrite_stream & OS
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
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
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:76
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:1858
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N