16122f3e6SDimitry Andric //===-- MipsInstPrinter.cpp - Convert Mips MCInst to assembly syntax ------===//
217a519f9SDimitry Andric //
317a519f9SDimitry Andric //                     The LLVM Compiler Infrastructure
417a519f9SDimitry Andric //
517a519f9SDimitry Andric // This file is distributed under the University of Illinois Open Source
617a519f9SDimitry Andric // License. See LICENSE.TXT for details.
717a519f9SDimitry Andric //
817a519f9SDimitry Andric //===----------------------------------------------------------------------===//
917a519f9SDimitry Andric //
1017a519f9SDimitry Andric // This class prints an Mips MCInst to a .s file.
1117a519f9SDimitry Andric //
1217a519f9SDimitry Andric //===----------------------------------------------------------------------===//
1317a519f9SDimitry Andric 
1417a519f9SDimitry Andric #include "MipsInstPrinter.h"
1591bc56edSDimitry Andric #include "MCTargetDesc/MipsMCExpr.h"
167ae0e2c9SDimitry Andric #include "MipsInstrInfo.h"
17dff0c46cSDimitry Andric #include "llvm/ADT/StringExtras.h"
1817a519f9SDimitry Andric #include "llvm/MC/MCExpr.h"
1917a519f9SDimitry Andric #include "llvm/MC/MCInst.h"
20dff0c46cSDimitry Andric #include "llvm/MC/MCInstrInfo.h"
21dff0c46cSDimitry Andric #include "llvm/MC/MCSymbol.h"
2217a519f9SDimitry Andric #include "llvm/Support/ErrorHandling.h"
2317a519f9SDimitry Andric #include "llvm/Support/raw_ostream.h"
2417a519f9SDimitry Andric using namespace llvm;
2517a519f9SDimitry Andric 
2691bc56edSDimitry Andric #define DEBUG_TYPE "asm-printer"
2791bc56edSDimitry Andric 
28139f7f9bSDimitry Andric #define PRINT_ALIAS_INSTR
2917a519f9SDimitry Andric #include "MipsGenAsmWriter.inc"
3017a519f9SDimitry Andric 
31f785676fSDimitry Andric template<unsigned R>
32f785676fSDimitry Andric static bool isReg(const MCInst &MI, unsigned OpNo) {
33f785676fSDimitry Andric   assert(MI.getOperand(OpNo).isReg() && "Register operand expected.");
34f785676fSDimitry Andric   return MI.getOperand(OpNo).getReg() == R;
35f785676fSDimitry Andric }
36f785676fSDimitry Andric 
3717a519f9SDimitry Andric const char* Mips::MipsFCCToString(Mips::CondCode CC) {
3817a519f9SDimitry Andric   switch (CC) {
3917a519f9SDimitry Andric   case FCOND_F:
4017a519f9SDimitry Andric   case FCOND_T:   return "f";
4117a519f9SDimitry Andric   case FCOND_UN:
4217a519f9SDimitry Andric   case FCOND_OR:  return "un";
4317a519f9SDimitry Andric   case FCOND_OEQ:
4417a519f9SDimitry Andric   case FCOND_UNE: return "eq";
4517a519f9SDimitry Andric   case FCOND_UEQ:
4617a519f9SDimitry Andric   case FCOND_ONE: return "ueq";
4717a519f9SDimitry Andric   case FCOND_OLT:
4817a519f9SDimitry Andric   case FCOND_UGE: return "olt";
4917a519f9SDimitry Andric   case FCOND_ULT:
5017a519f9SDimitry Andric   case FCOND_OGE: return "ult";
5117a519f9SDimitry Andric   case FCOND_OLE:
5217a519f9SDimitry Andric   case FCOND_UGT: return "ole";
5317a519f9SDimitry Andric   case FCOND_ULE:
5417a519f9SDimitry Andric   case FCOND_OGT: return "ule";
5517a519f9SDimitry Andric   case FCOND_SF:
5617a519f9SDimitry Andric   case FCOND_ST:  return "sf";
5717a519f9SDimitry Andric   case FCOND_NGLE:
5817a519f9SDimitry Andric   case FCOND_GLE: return "ngle";
5917a519f9SDimitry Andric   case FCOND_SEQ:
6017a519f9SDimitry Andric   case FCOND_SNE: return "seq";
6117a519f9SDimitry Andric   case FCOND_NGL:
6217a519f9SDimitry Andric   case FCOND_GL:  return "ngl";
6317a519f9SDimitry Andric   case FCOND_LT:
6417a519f9SDimitry Andric   case FCOND_NLT: return "lt";
6517a519f9SDimitry Andric   case FCOND_NGE:
6617a519f9SDimitry Andric   case FCOND_GE:  return "nge";
6717a519f9SDimitry Andric   case FCOND_LE:
6817a519f9SDimitry Andric   case FCOND_NLE: return "le";
6917a519f9SDimitry Andric   case FCOND_NGT:
7017a519f9SDimitry Andric   case FCOND_GT:  return "ngt";
7117a519f9SDimitry Andric   }
7217a519f9SDimitry Andric   llvm_unreachable("Impossible condition code!");
7317a519f9SDimitry Andric }
7417a519f9SDimitry Andric 
7517a519f9SDimitry Andric void MipsInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
76dff0c46cSDimitry Andric   OS << '$' << StringRef(getRegisterName(RegNo)).lower();
7717a519f9SDimitry Andric }
7817a519f9SDimitry Andric 
796122f3e6SDimitry Andric void MipsInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
80ff0cc061SDimitry Andric                                 StringRef Annot, const MCSubtargetInfo &STI) {
817ae0e2c9SDimitry Andric   switch (MI->getOpcode()) {
827ae0e2c9SDimitry Andric   default:
837ae0e2c9SDimitry Andric     break;
847ae0e2c9SDimitry Andric   case Mips::RDHWR:
857ae0e2c9SDimitry Andric   case Mips::RDHWR64:
867ae0e2c9SDimitry Andric     O << "\t.set\tpush\n";
877ae0e2c9SDimitry Andric     O << "\t.set\tmips32r2\n";
8891bc56edSDimitry Andric     break;
8991bc56edSDimitry Andric   case Mips::Save16:
9091bc56edSDimitry Andric     O << "\tsave\t";
9191bc56edSDimitry Andric     printSaveRestore(MI, O);
9291bc56edSDimitry Andric     O << " # 16 bit inst\n";
9391bc56edSDimitry Andric     return;
9491bc56edSDimitry Andric   case Mips::SaveX16:
9591bc56edSDimitry Andric     O << "\tsave\t";
9691bc56edSDimitry Andric     printSaveRestore(MI, O);
9791bc56edSDimitry Andric     O << "\n";
9891bc56edSDimitry Andric     return;
9991bc56edSDimitry Andric   case Mips::Restore16:
10091bc56edSDimitry Andric     O << "\trestore\t";
10191bc56edSDimitry Andric     printSaveRestore(MI, O);
10291bc56edSDimitry Andric     O << " # 16 bit inst\n";
10391bc56edSDimitry Andric     return;
10491bc56edSDimitry Andric   case Mips::RestoreX16:
10591bc56edSDimitry Andric     O << "\trestore\t";
10691bc56edSDimitry Andric     printSaveRestore(MI, O);
10791bc56edSDimitry Andric     O << "\n";
10891bc56edSDimitry Andric     return;
1097ae0e2c9SDimitry Andric   }
1107ae0e2c9SDimitry Andric 
111139f7f9bSDimitry Andric   // Try to print any aliases first.
112f785676fSDimitry Andric   if (!printAliasInstr(MI, O) && !printAlias(*MI, O))
11317a519f9SDimitry Andric     printInstruction(MI, O);
1146122f3e6SDimitry Andric   printAnnotation(O, Annot);
1157ae0e2c9SDimitry Andric 
1167ae0e2c9SDimitry Andric   switch (MI->getOpcode()) {
1177ae0e2c9SDimitry Andric   default:
1187ae0e2c9SDimitry Andric     break;
1197ae0e2c9SDimitry Andric   case Mips::RDHWR:
1207ae0e2c9SDimitry Andric   case Mips::RDHWR64:
1217ae0e2c9SDimitry Andric     O << "\n\t.set\tpop";
1227ae0e2c9SDimitry Andric   }
12317a519f9SDimitry Andric }
12417a519f9SDimitry Andric 
125dff0c46cSDimitry Andric static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
126dff0c46cSDimitry Andric   int Offset = 0;
127dff0c46cSDimitry Andric   const MCSymbolRefExpr *SRE;
128dff0c46cSDimitry Andric 
129dff0c46cSDimitry Andric   if (const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(Expr)) {
130dff0c46cSDimitry Andric     SRE = dyn_cast<MCSymbolRefExpr>(BE->getLHS());
131dff0c46cSDimitry Andric     const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(BE->getRHS());
132dff0c46cSDimitry Andric     assert(SRE && CE && "Binary expression must be sym+const.");
133dff0c46cSDimitry Andric     Offset = CE->getValue();
13491bc56edSDimitry Andric   } else if (const MipsMCExpr *ME = dyn_cast<MipsMCExpr>(Expr)) {
13591bc56edSDimitry Andric     ME->print(OS);
13691bc56edSDimitry Andric     return;
13739d628a0SDimitry Andric   } else
13839d628a0SDimitry Andric     SRE = cast<MCSymbolRefExpr>(Expr);
139dff0c46cSDimitry Andric 
140dff0c46cSDimitry Andric   MCSymbolRefExpr::VariantKind Kind = SRE->getKind();
141dff0c46cSDimitry Andric 
142dff0c46cSDimitry Andric   switch (Kind) {
143dff0c46cSDimitry Andric   default:                                 llvm_unreachable("Invalid kind!");
144dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_None:           break;
145dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GPREL:     OS << "%gp_rel("; break;
146dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_CALL:  OS << "%call16("; break;
147dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT16:     OS << "%got(";    break;
148dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT:       OS << "%got(";    break;
149dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_ABS_HI:    OS << "%hi(";     break;
150dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_ABS_LO:    OS << "%lo(";     break;
151dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_TLSGD:     OS << "%tlsgd(";  break;
152dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_TLSLDM:    OS << "%tlsldm(";  break;
153dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_DTPREL_HI: OS << "%dtprel_hi(";  break;
154dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_DTPREL_LO: OS << "%dtprel_lo(";  break;
155dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOTTPREL:  OS << "%gottprel("; break;
156dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_TPREL_HI:  OS << "%tprel_hi("; break;
157dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_TPREL_LO:  OS << "%tprel_lo("; break;
158dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GPOFF_HI:  OS << "%hi(%neg(%gp_rel("; break;
159dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GPOFF_LO:  OS << "%lo(%neg(%gp_rel("; break;
160dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_DISP:  OS << "%got_disp("; break;
161dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_PAGE:  OS << "%got_page("; break;
162dff0c46cSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_OFST:  OS << "%got_ofst("; break;
1637ae0e2c9SDimitry Andric   case MCSymbolRefExpr::VK_Mips_HIGHER:    OS << "%higher("; break;
1647ae0e2c9SDimitry Andric   case MCSymbolRefExpr::VK_Mips_HIGHEST:   OS << "%highest("; break;
165c80e6c4bSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_HI16:  OS << "%got_hi("; break;
166c80e6c4bSDimitry Andric   case MCSymbolRefExpr::VK_Mips_GOT_LO16:  OS << "%got_lo("; break;
167c80e6c4bSDimitry Andric   case MCSymbolRefExpr::VK_Mips_CALL_HI16: OS << "%call_hi("; break;
168c80e6c4bSDimitry Andric   case MCSymbolRefExpr::VK_Mips_CALL_LO16: OS << "%call_lo("; break;
16991bc56edSDimitry Andric   case MCSymbolRefExpr::VK_Mips_PCREL_HI16: OS << "%pcrel_hi("; break;
17091bc56edSDimitry Andric   case MCSymbolRefExpr::VK_Mips_PCREL_LO16: OS << "%pcrel_lo("; break;
171dff0c46cSDimitry Andric   }
172dff0c46cSDimitry Andric 
173dff0c46cSDimitry Andric   OS << SRE->getSymbol();
174dff0c46cSDimitry Andric 
175dff0c46cSDimitry Andric   if (Offset) {
176dff0c46cSDimitry Andric     if (Offset > 0)
177dff0c46cSDimitry Andric       OS << '+';
178dff0c46cSDimitry Andric     OS << Offset;
179dff0c46cSDimitry Andric   }
180dff0c46cSDimitry Andric 
181dff0c46cSDimitry Andric   if ((Kind == MCSymbolRefExpr::VK_Mips_GPOFF_HI) ||
182dff0c46cSDimitry Andric       (Kind == MCSymbolRefExpr::VK_Mips_GPOFF_LO))
183dff0c46cSDimitry Andric     OS << ")))";
184dff0c46cSDimitry Andric   else if (Kind != MCSymbolRefExpr::VK_None)
185dff0c46cSDimitry Andric     OS << ')';
186dff0c46cSDimitry Andric }
187dff0c46cSDimitry Andric 
18817a519f9SDimitry Andric void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
18917a519f9SDimitry Andric                                    raw_ostream &O) {
19017a519f9SDimitry Andric   const MCOperand &Op = MI->getOperand(OpNo);
19117a519f9SDimitry Andric   if (Op.isReg()) {
19217a519f9SDimitry Andric     printRegName(O, Op.getReg());
19317a519f9SDimitry Andric     return;
19417a519f9SDimitry Andric   }
19517a519f9SDimitry Andric 
19617a519f9SDimitry Andric   if (Op.isImm()) {
19717a519f9SDimitry Andric     O << Op.getImm();
19817a519f9SDimitry Andric     return;
19917a519f9SDimitry Andric   }
20017a519f9SDimitry Andric 
20117a519f9SDimitry Andric   assert(Op.isExpr() && "unknown operand kind in printOperand");
202dff0c46cSDimitry Andric   printExpr(Op.getExpr(), O);
20317a519f9SDimitry Andric }
20417a519f9SDimitry Andric 
20517a519f9SDimitry Andric void MipsInstPrinter::printUnsignedImm(const MCInst *MI, int opNum,
20617a519f9SDimitry Andric                                        raw_ostream &O) {
20717a519f9SDimitry Andric   const MCOperand &MO = MI->getOperand(opNum);
20817a519f9SDimitry Andric   if (MO.isImm())
20917a519f9SDimitry Andric     O << (unsigned short int)MO.getImm();
21017a519f9SDimitry Andric   else
21117a519f9SDimitry Andric     printOperand(MI, opNum, O);
21217a519f9SDimitry Andric }
21317a519f9SDimitry Andric 
214f785676fSDimitry Andric void MipsInstPrinter::printUnsignedImm8(const MCInst *MI, int opNum,
215f785676fSDimitry Andric                                         raw_ostream &O) {
216f785676fSDimitry Andric   const MCOperand &MO = MI->getOperand(opNum);
217f785676fSDimitry Andric   if (MO.isImm())
218f785676fSDimitry Andric     O << (unsigned short int)(unsigned char)MO.getImm();
219f785676fSDimitry Andric   else
220f785676fSDimitry Andric     printOperand(MI, opNum, O);
221f785676fSDimitry Andric }
222f785676fSDimitry Andric 
22317a519f9SDimitry Andric void MipsInstPrinter::
22417a519f9SDimitry Andric printMemOperand(const MCInst *MI, int opNum, raw_ostream &O) {
22517a519f9SDimitry Andric   // Load/Store memory operands -- imm($reg)
22617a519f9SDimitry Andric   // If PIC target the target is loaded as the
22717a519f9SDimitry Andric   // pattern lw $25,%call16($28)
22839d628a0SDimitry Andric 
22939d628a0SDimitry Andric   // opNum can be invalid if instruction had reglist as operand.
23039d628a0SDimitry Andric   // MemOperand is always last operand of instruction (base + offset).
23139d628a0SDimitry Andric   switch (MI->getOpcode()) {
23239d628a0SDimitry Andric   default:
23339d628a0SDimitry Andric     break;
23439d628a0SDimitry Andric   case Mips::SWM32_MM:
23539d628a0SDimitry Andric   case Mips::LWM32_MM:
23639d628a0SDimitry Andric   case Mips::SWM16_MM:
23739d628a0SDimitry Andric   case Mips::LWM16_MM:
23839d628a0SDimitry Andric     opNum = MI->getNumOperands() - 2;
23939d628a0SDimitry Andric     break;
24039d628a0SDimitry Andric   }
24139d628a0SDimitry Andric 
24217a519f9SDimitry Andric   printOperand(MI, opNum+1, O);
24317a519f9SDimitry Andric   O << "(";
24417a519f9SDimitry Andric   printOperand(MI, opNum, O);
24517a519f9SDimitry Andric   O << ")";
24617a519f9SDimitry Andric }
24717a519f9SDimitry Andric 
24817a519f9SDimitry Andric void MipsInstPrinter::
24917a519f9SDimitry Andric printMemOperandEA(const MCInst *MI, int opNum, raw_ostream &O) {
25017a519f9SDimitry Andric   // when using stack locations for not load/store instructions
25117a519f9SDimitry Andric   // print the same way as all normal 3 operand instructions.
25217a519f9SDimitry Andric   printOperand(MI, opNum, O);
25317a519f9SDimitry Andric   O << ", ";
25417a519f9SDimitry Andric   printOperand(MI, opNum+1, O);
25517a519f9SDimitry Andric   return;
25617a519f9SDimitry Andric }
25717a519f9SDimitry Andric 
25817a519f9SDimitry Andric void MipsInstPrinter::
25917a519f9SDimitry Andric printFCCOperand(const MCInst *MI, int opNum, raw_ostream &O) {
26017a519f9SDimitry Andric   const MCOperand& MO = MI->getOperand(opNum);
26117a519f9SDimitry Andric   O << MipsFCCToString((Mips::CondCode)MO.getImm());
26217a519f9SDimitry Andric }
263f785676fSDimitry Andric 
264f785676fSDimitry Andric void MipsInstPrinter::
26539d628a0SDimitry Andric printRegisterPair(const MCInst *MI, int opNum, raw_ostream &O) {
26639d628a0SDimitry Andric   printRegName(O, MI->getOperand(opNum).getReg());
26739d628a0SDimitry Andric }
26839d628a0SDimitry Andric 
26939d628a0SDimitry Andric void MipsInstPrinter::
270f785676fSDimitry Andric printSHFMask(const MCInst *MI, int opNum, raw_ostream &O) {
271f785676fSDimitry Andric   llvm_unreachable("TODO");
272f785676fSDimitry Andric }
273f785676fSDimitry Andric 
274f785676fSDimitry Andric bool MipsInstPrinter::printAlias(const char *Str, const MCInst &MI,
275f785676fSDimitry Andric                                  unsigned OpNo, raw_ostream &OS) {
276f785676fSDimitry Andric   OS << "\t" << Str << "\t";
277f785676fSDimitry Andric   printOperand(&MI, OpNo, OS);
278f785676fSDimitry Andric   return true;
279f785676fSDimitry Andric }
280f785676fSDimitry Andric 
281f785676fSDimitry Andric bool MipsInstPrinter::printAlias(const char *Str, const MCInst &MI,
282f785676fSDimitry Andric                                  unsigned OpNo0, unsigned OpNo1,
283f785676fSDimitry Andric                                  raw_ostream &OS) {
284f785676fSDimitry Andric   printAlias(Str, MI, OpNo0, OS);
285f785676fSDimitry Andric   OS << ", ";
286f785676fSDimitry Andric   printOperand(&MI, OpNo1, OS);
287f785676fSDimitry Andric   return true;
288f785676fSDimitry Andric }
289f785676fSDimitry Andric 
290f785676fSDimitry Andric bool MipsInstPrinter::printAlias(const MCInst &MI, raw_ostream &OS) {
291f785676fSDimitry Andric   switch (MI.getOpcode()) {
292f785676fSDimitry Andric   case Mips::BEQ:
293ff0cc061SDimitry Andric   case Mips::BEQ_MM:
294f785676fSDimitry Andric     // beq $zero, $zero, $L2 => b $L2
295f785676fSDimitry Andric     // beq $r0, $zero, $L2 => beqz $r0, $L2
296f785676fSDimitry Andric     return (isReg<Mips::ZERO>(MI, 0) && isReg<Mips::ZERO>(MI, 1) &&
297f785676fSDimitry Andric             printAlias("b", MI, 2, OS)) ||
298f785676fSDimitry Andric            (isReg<Mips::ZERO>(MI, 1) && printAlias("beqz", MI, 0, 2, OS));
299f785676fSDimitry Andric   case Mips::BEQ64:
300f785676fSDimitry Andric     // beq $r0, $zero, $L2 => beqz $r0, $L2
301f785676fSDimitry Andric     return isReg<Mips::ZERO_64>(MI, 1) && printAlias("beqz", MI, 0, 2, OS);
302f785676fSDimitry Andric   case Mips::BNE:
303f785676fSDimitry Andric     // bne $r0, $zero, $L2 => bnez $r0, $L2
304f785676fSDimitry Andric     return isReg<Mips::ZERO>(MI, 1) && printAlias("bnez", MI, 0, 2, OS);
305f785676fSDimitry Andric   case Mips::BNE64:
306f785676fSDimitry Andric     // bne $r0, $zero, $L2 => bnez $r0, $L2
307f785676fSDimitry Andric     return isReg<Mips::ZERO_64>(MI, 1) && printAlias("bnez", MI, 0, 2, OS);
308f785676fSDimitry Andric   case Mips::BGEZAL:
309f785676fSDimitry Andric     // bgezal $zero, $L1 => bal $L1
310f785676fSDimitry Andric     return isReg<Mips::ZERO>(MI, 0) && printAlias("bal", MI, 1, OS);
311f785676fSDimitry Andric   case Mips::BC1T:
312f785676fSDimitry Andric     // bc1t $fcc0, $L1 => bc1t $L1
313f785676fSDimitry Andric     return isReg<Mips::FCC0>(MI, 0) && printAlias("bc1t", MI, 1, OS);
314f785676fSDimitry Andric   case Mips::BC1F:
315f785676fSDimitry Andric     // bc1f $fcc0, $L1 => bc1f $L1
316f785676fSDimitry Andric     return isReg<Mips::FCC0>(MI, 0) && printAlias("bc1f", MI, 1, OS);
317f785676fSDimitry Andric   case Mips::JALR:
318f785676fSDimitry Andric     // jalr $ra, $r1 => jalr $r1
319f785676fSDimitry Andric     return isReg<Mips::RA>(MI, 0) && printAlias("jalr", MI, 1, OS);
320f785676fSDimitry Andric   case Mips::JALR64:
321f785676fSDimitry Andric     // jalr $ra, $r1 => jalr $r1
322f785676fSDimitry Andric     return isReg<Mips::RA_64>(MI, 0) && printAlias("jalr", MI, 1, OS);
323f785676fSDimitry Andric   case Mips::NOR:
324f785676fSDimitry Andric   case Mips::NOR_MM:
325f785676fSDimitry Andric     // nor $r0, $r1, $zero => not $r0, $r1
326f785676fSDimitry Andric     return isReg<Mips::ZERO>(MI, 2) && printAlias("not", MI, 0, 1, OS);
327f785676fSDimitry Andric   case Mips::NOR64:
328f785676fSDimitry Andric     // nor $r0, $r1, $zero => not $r0, $r1
329f785676fSDimitry Andric     return isReg<Mips::ZERO_64>(MI, 2) && printAlias("not", MI, 0, 1, OS);
330f785676fSDimitry Andric   case Mips::OR:
331f785676fSDimitry Andric     // or $r0, $r1, $zero => move $r0, $r1
332f785676fSDimitry Andric     return isReg<Mips::ZERO>(MI, 2) && printAlias("move", MI, 0, 1, OS);
333f785676fSDimitry Andric   default: return false;
334f785676fSDimitry Andric   }
335f785676fSDimitry Andric }
33691bc56edSDimitry Andric 
33791bc56edSDimitry Andric void MipsInstPrinter::printSaveRestore(const MCInst *MI, raw_ostream &O) {
33891bc56edSDimitry Andric   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
33991bc56edSDimitry Andric     if (i != 0) O << ", ";
34091bc56edSDimitry Andric     if (MI->getOperand(i).isReg())
34191bc56edSDimitry Andric       printRegName(O, MI->getOperand(i).getReg());
34291bc56edSDimitry Andric     else
34391bc56edSDimitry Andric       printUnsignedImm(MI, i, O);
34491bc56edSDimitry Andric   }
34591bc56edSDimitry Andric }
34691bc56edSDimitry Andric 
34739d628a0SDimitry Andric void MipsInstPrinter::
34839d628a0SDimitry Andric printRegisterList(const MCInst *MI, int opNum, raw_ostream &O) {
34939d628a0SDimitry Andric   // - 2 because register List is always first operand of instruction and it is
35039d628a0SDimitry Andric   // always followed by memory operand (base + offset).
35139d628a0SDimitry Andric   for (int i = opNum, e = MI->getNumOperands() - 2; i != e; ++i) {
35239d628a0SDimitry Andric     if (i != opNum)
35339d628a0SDimitry Andric       O << ", ";
35439d628a0SDimitry Andric     printRegName(O, MI->getOperand(i).getReg());
35539d628a0SDimitry Andric   }
35639d628a0SDimitry Andric }
357