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) {
73 printInstruction(MI, O);
76 void MipsInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
78 const MCOperand &Op = MI->getOperand(OpNo);
80 printRegName(O, Op.getReg());
89 assert(Op.isExpr() && "unknown operand kind in printOperand");
93 void MipsInstPrinter::printUnsignedImm(const MCInst *MI, int opNum,
95 const MCOperand &MO = MI->getOperand(opNum);
97 O << (unsigned short int)MO.getImm();
99 printOperand(MI, opNum, O);
102 void MipsInstPrinter::
103 printMemOperand(const MCInst *MI, int opNum, raw_ostream &O) {
104 // Load/Store memory operands -- imm($reg)
105 // If PIC target the target is loaded as the
106 // pattern lw $25,%call16($28)
107 printOperand(MI, opNum+1, O);
109 printOperand(MI, opNum, O);
113 void MipsInstPrinter::
114 printMemOperandEA(const MCInst *MI, int opNum, raw_ostream &O) {
115 // when using stack locations for not load/store instructions
116 // print the same way as all normal 3 operand instructions.
117 printOperand(MI, opNum, O);
119 printOperand(MI, opNum+1, O);
123 void MipsInstPrinter::
124 printFCCOperand(const MCInst *MI, int opNum, raw_ostream &O) {
125 const MCOperand& MO = MI->getOperand(opNum);
126 O << MipsFCCToString((Mips::CondCode)MO.getImm());