1 //===-- MBlazeInstPrinter.cpp - Convert MBlaze MCInst to assembly syntax --===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This class prints an MBlaze MCInst to a .s file. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #define DEBUG_TYPE "asm-printer" 15 #include "MBlazeInstPrinter.h" 16 #include "MBlaze.h" 17 #include "llvm/MC/MCAsmInfo.h" 18 #include "llvm/MC/MCExpr.h" 19 #include "llvm/MC/MCInst.h" 20 #include "llvm/Support/ErrorHandling.h" 21 #include "llvm/Support/FormattedStream.h" 22 using namespace llvm; 23 24 25 // Include the auto-generated portion of the assembly writer. 26 #include "MBlazeGenAsmWriter.inc" 27 28 void MBlazeInstPrinter::printInst(const MCInst *MI, raw_ostream &O, 29 StringRef Annot) { 30 printInstruction(MI, O); 31 printAnnotation(O, Annot); 32 } 33 34 void MBlazeInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, 35 raw_ostream &O, const char *Modifier) { 36 assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported"); 37 const MCOperand &Op = MI->getOperand(OpNo); 38 if (Op.isReg()) { 39 O << getRegisterName(Op.getReg()); 40 } else if (Op.isImm()) { 41 O << (int32_t)Op.getImm(); 42 } else { 43 assert(Op.isExpr() && "unknown operand kind in printOperand"); 44 O << *Op.getExpr(); 45 } 46 } 47 48 void MBlazeInstPrinter::printFSLImm(const MCInst *MI, int OpNo, 49 raw_ostream &O) { 50 const MCOperand &MO = MI->getOperand(OpNo); 51 if (MO.isImm()) 52 O << "rfsl" << MO.getImm(); 53 else 54 printOperand(MI, OpNo, O, NULL); 55 } 56 57 void MBlazeInstPrinter::printUnsignedImm(const MCInst *MI, int OpNo, 58 raw_ostream &O) { 59 const MCOperand &MO = MI->getOperand(OpNo); 60 if (MO.isImm()) 61 O << (uint32_t)MO.getImm(); 62 else 63 printOperand(MI, OpNo, O, NULL); 64 } 65 66 void MBlazeInstPrinter::printMemOperand(const MCInst *MI, int OpNo, 67 raw_ostream &O, const char *Modifier) { 68 printOperand(MI, OpNo, O, NULL); 69 O << ", "; 70 printOperand(MI, OpNo+1, O, NULL); 71 } 72