LLVM API Documentation

MBlazeInstPrinter.cpp
Go to the documentation of this file.
00001 //===-- MBlazeInstPrinter.cpp - Convert MBlaze MCInst to assembly syntax --===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This class prints an MBlaze MCInst to a .s file.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #define DEBUG_TYPE "asm-printer"
00015 #include "MBlazeInstPrinter.h"
00016 #include "MBlaze.h"
00017 #include "llvm/MC/MCAsmInfo.h"
00018 #include "llvm/MC/MCExpr.h"
00019 #include "llvm/MC/MCInst.h"
00020 #include "llvm/Support/ErrorHandling.h"
00021 #include "llvm/Support/FormattedStream.h"
00022 using namespace llvm;
00023 
00024 
00025 // Include the auto-generated portion of the assembly writer.
00026 #include "MBlazeGenAsmWriter.inc"
00027 
00028 void MBlazeInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
00029                                   StringRef Annot) {
00030   printInstruction(MI, O);
00031   printAnnotation(O, Annot);
00032 }
00033 
00034 void MBlazeInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
00035                                      raw_ostream &O, const char *Modifier) {
00036   assert((Modifier == 0 || Modifier[0] == 0) && "No modifiers supported");
00037   const MCOperand &Op = MI->getOperand(OpNo);
00038   if (Op.isReg()) {
00039     O << getRegisterName(Op.getReg());
00040   } else if (Op.isImm()) {
00041     O << (int32_t)Op.getImm();
00042   } else {
00043     assert(Op.isExpr() && "unknown operand kind in printOperand");
00044     O << *Op.getExpr();
00045   }
00046 }
00047 
00048 void MBlazeInstPrinter::printFSLImm(const MCInst *MI, int OpNo,
00049                                     raw_ostream &O) {
00050   const MCOperand &MO = MI->getOperand(OpNo);
00051   if (MO.isImm())
00052     O << "rfsl" << MO.getImm();
00053   else
00054     printOperand(MI, OpNo, O, NULL);
00055 }
00056 
00057 void MBlazeInstPrinter::printUnsignedImm(const MCInst *MI, int OpNo,
00058                                         raw_ostream &O) {
00059   const MCOperand &MO = MI->getOperand(OpNo);
00060   if (MO.isImm())
00061     O << (uint32_t)MO.getImm();
00062   else
00063     printOperand(MI, OpNo, O, NULL);
00064 }
00065 
00066 void MBlazeInstPrinter::printMemOperand(const MCInst *MI, int OpNo,
00067                                         raw_ostream &O, const char *Modifier) {
00068   printOperand(MI, OpNo, O, NULL);
00069   O << ", ";
00070   printOperand(MI, OpNo+1, O, NULL);
00071 }