10b57cec5SDimitry Andric // WebAssemblyInstPrinter.h - Print wasm MCInst to assembly syntax -*- C++ -*-// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric /// 90b57cec5SDimitry Andric /// \file 100b57cec5SDimitry Andric /// This class prints an WebAssembly MCInst to wasm file syntax. 110b57cec5SDimitry Andric /// 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H 150b57cec5SDimitry Andric #define LLVM_LIB_TARGET_WEBASSEMBLY_INSTPRINTER_WEBASSEMBLYINSTPRINTER_H 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 180b57cec5SDimitry Andric #include "llvm/BinaryFormat/Wasm.h" 19*0fca6ea1SDimitry Andric #include "llvm/CodeGenTypes/MachineValueType.h" 200b57cec5SDimitry Andric #include "llvm/MC/MCInstPrinter.h" 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric namespace llvm { 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric class MCSubtargetInfo; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric class WebAssemblyInstPrinter final : public MCInstPrinter { 270b57cec5SDimitry Andric uint64_t ControlFlowCounter = 0; 280b57cec5SDimitry Andric SmallVector<std::pair<uint64_t, bool>, 4> ControlFlowStack; 29fe6060f1SDimitry Andric SmallVector<uint64_t, 4> TryStack; 30fe6060f1SDimitry Andric 31fe6060f1SDimitry Andric enum EHInstKind { TRY, CATCH, CATCH_ALL }; 32fe6060f1SDimitry Andric SmallVector<EHInstKind, 4> EHInstStack; 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric public: 350b57cec5SDimitry Andric WebAssemblyInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, 360b57cec5SDimitry Andric const MCRegisterInfo &MRI); 370b57cec5SDimitry Andric 38bdd1243dSDimitry Andric void printRegName(raw_ostream &OS, MCRegister Reg) const override; 39480093f4SDimitry Andric void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, 40480093f4SDimitry Andric const MCSubtargetInfo &STI, raw_ostream &OS) override; 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric // Used by tblegen code. 435ffd83dbSDimitry Andric void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O, 445ffd83dbSDimitry Andric bool IsVariadicDef = false); 450b57cec5SDimitry Andric void printBrList(const MCInst *MI, unsigned OpNo, raw_ostream &O); 460b57cec5SDimitry Andric void printWebAssemblyP2AlignOperand(const MCInst *MI, unsigned OpNo, 470b57cec5SDimitry Andric raw_ostream &O); 480b57cec5SDimitry Andric void printWebAssemblySignatureOperand(const MCInst *MI, unsigned OpNo, 490b57cec5SDimitry Andric raw_ostream &O); 500b57cec5SDimitry Andric 510b57cec5SDimitry Andric // Autogenerated by tblgen. 52e8d8bef9SDimitry Andric std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override; 53480093f4SDimitry Andric void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O); 54bdd1243dSDimitry Andric static const char *getRegisterName(MCRegister Reg); 550b57cec5SDimitry Andric }; 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric } // end namespace llvm 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric #endif 60