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