1 //=== MipsInstPrinter.h - Convert Mips MCInst to assembly syntax -*- 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 // This class prints a Mips MCInst to a .s file. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSINSTPRINTER_H 14 #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSINSTPRINTER_H 15 #include "llvm/MC/MCInstPrinter.h" 16 17 namespace llvm { 18 // These enumeration declarations were originally in MipsInstrInfo.h but 19 // had to be moved here to avoid circular dependencies between 20 // LLVMMipsCodeGen and LLVMMipsAsmPrinter. 21 namespace Mips { 22 // Mips Branch Codes 23 enum FPBranchCode { 24 BRANCH_F, 25 BRANCH_T, 26 BRANCH_FL, 27 BRANCH_TL, 28 BRANCH_INVALID 29 }; 30 31 // Mips Condition Codes 32 enum CondCode { 33 // To be used with float branch True 34 FCOND_F, 35 FCOND_UN, 36 FCOND_OEQ, 37 FCOND_UEQ, 38 FCOND_OLT, 39 FCOND_ULT, 40 FCOND_OLE, 41 FCOND_ULE, 42 FCOND_SF, 43 FCOND_NGLE, 44 FCOND_SEQ, 45 FCOND_NGL, 46 FCOND_LT, 47 FCOND_NGE, 48 FCOND_LE, 49 FCOND_NGT, 50 51 // To be used with float branch False 52 // This conditions have the same mnemonic as the 53 // above ones, but are used with a branch False; 54 FCOND_T, 55 FCOND_OR, 56 FCOND_UNE, 57 FCOND_ONE, 58 FCOND_UGE, 59 FCOND_OGE, 60 FCOND_UGT, 61 FCOND_OGT, 62 FCOND_ST, 63 FCOND_GLE, 64 FCOND_SNE, 65 FCOND_GL, 66 FCOND_NLT, 67 FCOND_GE, 68 FCOND_NLE, 69 FCOND_GT 70 }; 71 72 const char *MipsFCCToString(Mips::CondCode CC); 73 } // end namespace Mips 74 75 class MipsInstPrinter : public MCInstPrinter { 76 public: MipsInstPrinter(const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)77 MipsInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, 78 const MCRegisterInfo &MRI) 79 : MCInstPrinter(MAI, MII, MRI) {} 80 81 // Autogenerated by tblgen. 82 std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override; 83 void printInstruction(const MCInst *MI, uint64_t Address, 84 const MCSubtargetInfo &STI, raw_ostream &O); 85 static const char *getRegisterName(MCRegister Reg); 86 87 void printRegName(raw_ostream &OS, MCRegister Reg) const override; 88 void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, 89 const MCSubtargetInfo &STI, raw_ostream &O) override; 90 91 bool printAliasInstr(const MCInst *MI, uint64_t Address, 92 const MCSubtargetInfo &STI, raw_ostream &OS); 93 void printCustomAliasOperand(const MCInst *MI, uint64_t Address, 94 unsigned OpIdx, unsigned PrintMethodIdx, 95 const MCSubtargetInfo &STI, raw_ostream &O); 96 97 private: 98 void printOperand(const MCInst *MI, unsigned OpNo, const MCSubtargetInfo &STI, 99 raw_ostream &O); 100 void printJumpOperand(const MCInst *MI, unsigned OpNo, 101 const MCSubtargetInfo &STI, raw_ostream &O); 102 void printBranchOperand(const MCInst *MI, uint64_t Address, unsigned OpNo, 103 const MCSubtargetInfo &STI, raw_ostream &O); 104 template <unsigned Bits, unsigned Offset = 0> 105 void printUImm(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, 106 raw_ostream &O); 107 void printMemOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, 108 raw_ostream &O); 109 void printMemOperandEA(const MCInst *MI, int opNum, 110 const MCSubtargetInfo &STI, raw_ostream &O); 111 void printFCCOperand(const MCInst *MI, int opNum, const MCSubtargetInfo &STI, 112 raw_ostream &O); 113 void printSHFMask(const MCInst *MI, int opNum, raw_ostream &O); 114 115 bool printAlias(const char *Str, const MCInst &MI, uint64_t Address, 116 unsigned OpNo, const MCSubtargetInfo &STI, raw_ostream &OS, 117 bool IsBranch = false); 118 bool printAlias(const char *Str, const MCInst &MI, uint64_t Address, 119 unsigned OpNo0, unsigned OpNo1, const MCSubtargetInfo &STI, 120 raw_ostream &OS, bool IsBranch = false); 121 bool printAlias(const MCInst &MI, uint64_t Address, 122 const MCSubtargetInfo &STI, raw_ostream &OS); 123 void printSaveRestore(const MCInst *MI, const MCSubtargetInfo &STI, 124 raw_ostream &O); 125 void printRegisterList(const MCInst *MI, int opNum, 126 const MCSubtargetInfo &STI, raw_ostream &O); 127 }; 128 } // end namespace llvm 129 130 #endif 131