1 //===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===// 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 #include "llvm/MC/MCInst.h" 11 #include "llvm/Config/llvm-config.h" 12 #include "llvm/MC/MCExpr.h" 13 #include "llvm/MC/MCInstPrinter.h" 14 #include "llvm/Support/Casting.h" 15 #include "llvm/Support/Compiler.h" 16 #include "llvm/Support/Debug.h" 17 #include "llvm/Support/raw_ostream.h" 18 19 using namespace llvm; 20 print(raw_ostream & OS) const21void MCOperand::print(raw_ostream &OS) const { 22 OS << "<MCOperand "; 23 if (!isValid()) 24 OS << "INVALID"; 25 else if (isReg()) 26 OS << "Reg:" << getReg(); 27 else if (isImm()) 28 OS << "Imm:" << getImm(); 29 else if (isFPImm()) 30 OS << "FPImm:" << getFPImm(); 31 else if (isExpr()) { 32 OS << "Expr:(" << *getExpr() << ")"; 33 } else if (isInst()) { 34 OS << "Inst:(" << *getInst() << ")"; 35 } else 36 OS << "UNDEFINED"; 37 OS << ">"; 38 } 39 evaluateAsConstantImm(int64_t & Imm) const40bool MCOperand::evaluateAsConstantImm(int64_t &Imm) const { 41 if (isImm()) { 42 Imm = getImm(); 43 return true; 44 } 45 return false; 46 } 47 isBareSymbolRef() const48bool MCOperand::isBareSymbolRef() const { 49 assert(isExpr() && 50 "isBareSymbolRef expects only expressions"); 51 const MCExpr *Expr = getExpr(); 52 MCExpr::ExprKind Kind = getExpr()->getKind(); 53 return Kind == MCExpr::SymbolRef && 54 cast<MCSymbolRefExpr>(Expr)->getKind() == MCSymbolRefExpr::VK_None; 55 } 56 57 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) dump() const58LLVM_DUMP_METHOD void MCOperand::dump() const { 59 print(dbgs()); 60 dbgs() << "\n"; 61 } 62 #endif 63 print(raw_ostream & OS) const64void MCInst::print(raw_ostream &OS) const { 65 OS << "<MCInst " << getOpcode(); 66 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 67 OS << " "; 68 getOperand(i).print(OS); 69 } 70 OS << ">"; 71 } 72 dump_pretty(raw_ostream & OS,const MCInstPrinter * Printer,StringRef Separator) const73void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer, 74 StringRef Separator) const { 75 OS << "<MCInst #" << getOpcode(); 76 77 // Show the instruction opcode name if we have access to a printer. 78 if (Printer) 79 OS << ' ' << Printer->getOpcodeName(getOpcode()); 80 81 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 82 OS << Separator; 83 getOperand(i).print(OS); 84 } 85 OS << ">"; 86 } 87 88 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) dump() const89LLVM_DUMP_METHOD void MCInst::dump() const { 90 print(dbgs()); 91 dbgs() << "\n"; 92 } 93 #endif 94