1 //===-- MipsInstPrinter.cpp - Convert Mips MCInst to assembly syntax ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class prints an Mips MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "MipsInstPrinter.h"
16 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCInst.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/ADT/StringExtras.h"
23 #define GET_INSTRUCTION_NAME
24 #include "MipsGenAsmWriter.inc"
26 const char* Mips::MipsFCCToString(Mips::CondCode CC) {
29 case FCOND_T: return "f";
31 case FCOND_OR: return "un";
33 case FCOND_UNE: return "eq";
35 case FCOND_ONE: return "ueq";
37 case FCOND_UGE: return "olt";
39 case FCOND_OGE: return "ult";
41 case FCOND_UGT: return "ole";
43 case FCOND_OGT: return "ule";
45 case FCOND_ST: return "sf";
47 case FCOND_GLE: return "ngle";
49 case FCOND_SNE: return "seq";
51 case FCOND_GL: return "ngl";
53 case FCOND_NLT: return "lt";
55 case FCOND_GE: return "nge";
57 case FCOND_NLE: return "le";
59 case FCOND_GT: return "ngt";
61 llvm_unreachable("Impossible condition code!");
64 StringRef MipsInstPrinter::getOpcodeName(unsigned Opcode) const {
65 return getInstructionName(Opcode);
68 void MipsInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
69 OS << '$' << LowercaseString(getRegisterName(RegNo));
72 void MipsInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
74 printInstruction(MI, O);
75 printAnnotation(O, Annot);
78 void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
80 const MCOperand &Op = MI->getOperand(OpNo);
82 printRegName(O, Op.getReg());
91 assert(Op.isExpr() && "unknown operand kind in printOperand");
95 void MipsInstPrinter::printUnsignedImm(const MCInst *MI, int opNum,
97 const MCOperand &MO = MI->getOperand(opNum);
99 O << (unsigned short int)MO.getImm();
101 printOperand(MI, opNum, O);
104 void MipsInstPrinter::
105 printMemOperand(const MCInst *MI, int opNum, raw_ostream &O) {
106 // Load/Store memory operands -- imm($reg)
107 // If PIC target the target is loaded as the
108 // pattern lw $25,%call16($28)
109 printOperand(MI, opNum+1, O);
111 printOperand(MI, opNum, O);
115 void MipsInstPrinter::
116 printMemOperandEA(const MCInst *MI, int opNum, raw_ostream &O) {
117 // when using stack locations for not load/store instructions
118 // print the same way as all normal 3 operand instructions.
119 printOperand(MI, opNum, O);
121 printOperand(MI, opNum+1, O);
125 void MipsInstPrinter::
126 printFCCOperand(const MCInst *MI, int opNum, raw_ostream &O) {
127 const MCOperand& MO = MI->getOperand(opNum);
128 O << MipsFCCToString((Mips::CondCode)MO.getImm());