LLVM API Documentation
00001 //===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===// 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 #include "llvm/MC/MCInst.h" 00011 #include "llvm/MC/MCExpr.h" 00012 #include "llvm/MC/MCInstPrinter.h" 00013 #include "llvm/Support/Debug.h" 00014 #include "llvm/Support/raw_ostream.h" 00015 00016 using namespace llvm; 00017 00018 void MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) const { 00019 OS << "<MCOperand "; 00020 if (!isValid()) 00021 OS << "INVALID"; 00022 else if (isReg()) 00023 OS << "Reg:" << getReg(); 00024 else if (isImm()) 00025 OS << "Imm:" << getImm(); 00026 else if (isExpr()) { 00027 OS << "Expr:(" << *getExpr() << ")"; 00028 } else if (isInst()) { 00029 OS << "Inst:(" << *getInst() << ")"; 00030 } else 00031 OS << "UNDEFINED"; 00032 OS << ">"; 00033 } 00034 00035 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 00036 void MCOperand::dump() const { 00037 print(dbgs(), nullptr); 00038 dbgs() << "\n"; 00039 } 00040 #endif 00041 00042 void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const { 00043 OS << "<MCInst " << getOpcode(); 00044 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 00045 OS << " "; 00046 getOperand(i).print(OS, MAI); 00047 } 00048 OS << ">"; 00049 } 00050 00051 void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI, 00052 const MCInstPrinter *Printer, 00053 StringRef Separator) const { 00054 OS << "<MCInst #" << getOpcode(); 00055 00056 // Show the instruction opcode name if we have access to a printer. 00057 if (Printer) 00058 OS << ' ' << Printer->getOpcodeName(getOpcode()); 00059 00060 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 00061 OS << Separator; 00062 getOperand(i).print(OS, MAI); 00063 } 00064 OS << ">"; 00065 } 00066 00067 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 00068 void MCInst::dump() const { 00069 print(dbgs(), nullptr); 00070 dbgs() << "\n"; 00071 } 00072 #endif