86 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H10#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYASMPRINTER_H11 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"17 18namespace llvm {19class WebAssemblyTargetStreamer;20 21class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {22public:23 static char ID;24 25private:26 const WebAssemblySubtarget *Subtarget;27 const MachineRegisterInfo *MRI;28 WebAssemblyFunctionInfo *MFI;29 bool signaturesEmitted = false;30 31public:32 explicit WebAssemblyAsmPrinter(TargetMachine &TM,33 std::unique_ptr<MCStreamer> Streamer)34 : AsmPrinter(TM, std::move(Streamer), ID), Subtarget(nullptr),35 MRI(nullptr), MFI(nullptr) {}36 37 StringRef getPassName() const override {38 return "WebAssembly Assembly Printer";39 }40 41 const WebAssemblySubtarget &getSubtarget() const { return *Subtarget; }42 43 //===------------------------------------------------------------------===//44 // MachineFunctionPass Implementation.45 //===------------------------------------------------------------------===//46 47 bool runOnMachineFunction(MachineFunction &MF) override {48 Subtarget = &MF.getSubtarget<WebAssemblySubtarget>();49 MRI = &MF.getRegInfo();50 MFI = MF.getInfo<WebAssemblyFunctionInfo>();51 return AsmPrinter::runOnMachineFunction(MF);52 }53 54 //===------------------------------------------------------------------===//55 // AsmPrinter Implementation.56 //===------------------------------------------------------------------===//57 58 void emitEndOfAsmFile(Module &M) override;59 void EmitProducerInfo(Module &M);60 void EmitTargetFeatures(Module &M);61 void EmitFunctionAttributes(Module &M);62 void emitSymbolType(const MCSymbolWasm *Sym);63 void emitGlobalVariable(const GlobalVariable *GV) override;64 void emitJumpTableInfo() override;65 void emitConstantPool() override;66 void emitFunctionBodyStart() override;67 void emitInstruction(const MachineInstr *MI) override;68 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,69 const char *ExtraCode, raw_ostream &OS) override;70 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,71 const char *ExtraCode, raw_ostream &OS) override;72 73 MVT getRegType(unsigned RegNo) const;74 std::string regToString(const MachineOperand &MO);75 WebAssemblyTargetStreamer *getTargetStreamer();76 MCSymbolWasm *getMCSymbolForFunction(const Function *F,77 wasm::WasmSignature *Sig,78 bool &InvokeDetected);79 MCSymbol *getOrCreateWasmSymbol(StringRef Name);80 void emitDecls(const Module &M);81};82 83} // end namespace llvm84 85#endif86