1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/MC/MCInst.h" 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/MC/MCExpr.h" 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/MC/MCInstPrinter.h" 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/Debug.h" 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/raw_ostream.h" 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanusing namespace llvm; 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) const { 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "<MCOperand "; 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (!isValid()) 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "INVALID"; 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else if (isReg()) 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "Reg:" << getReg(); 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else if (isImm()) 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "Imm:" << getImm(); 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else if (isExpr()) { 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "Expr:(" << *getExpr() << ")"; 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } else 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "UNDEFINED"; 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << ">"; 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid MCOperand::dump() const { 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman print(dbgs(), 0); 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman dbgs() << "\n"; 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const { 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "<MCInst " << getOpcode(); 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << " "; 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman getOperand(i).print(OS, MAI); 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << ">"; 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI, 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const MCInstPrinter *Printer, 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman StringRef Separator) const { 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << "<MCInst #" << getOpcode(); 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Show the instruction opcode name if we have access to a printer. 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (Printer) 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << ' ' << Printer->getOpcodeName(getOpcode()); 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << Separator; 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman getOperand(i).print(OS, MAI); 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman OS << ">"; 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanvoid MCInst::dump() const { 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman print(dbgs(), 0); 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman dbgs() << "\n"; 66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 67