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/MC/MCExpr.h"
12 #include "llvm/MC/MCInstPrinter.h"
13 #include "llvm/Support/Debug.h"
14 #include "llvm/Support/raw_ostream.h"
15 
16 using namespace llvm;
17 
print(raw_ostream & OS) const18 void MCOperand::print(raw_ostream &OS) const {
19   OS << "<MCOperand ";
20   if (!isValid())
21     OS << "INVALID";
22   else if (isReg())
23     OS << "Reg:" << getReg();
24   else if (isImm())
25     OS << "Imm:" << getImm();
26   else if (isExpr()) {
27     OS << "Expr:(" << *getExpr() << ")";
28   } else if (isInst()) {
29     OS << "Inst:(" << *getInst() << ")";
30   } else
31     OS << "UNDEFINED";
32   OS << ">";
33 }
34 
35 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const36 void MCOperand::dump() const {
37   print(dbgs());
38   dbgs() << "\n";
39 }
40 #endif
41 
print(raw_ostream & OS) const42 void MCInst::print(raw_ostream &OS) const {
43   OS << "<MCInst " << getOpcode();
44   for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
45     OS << " ";
46     getOperand(i).print(OS);
47   }
48   OS << ">";
49 }
50 
dump_pretty(raw_ostream & OS,const MCInstPrinter * Printer,StringRef Separator) const51 void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
52                          StringRef Separator) const {
53   OS << "<MCInst #" << getOpcode();
54 
55   // Show the instruction opcode name if we have access to a printer.
56   if (Printer)
57     OS << ' ' << Printer->getOpcodeName(getOpcode());
58 
59   for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
60     OS << Separator;
61     getOperand(i).print(OS);
62   }
63   OS << ">";
64 }
65 
66 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const67 void MCInst::dump() const {
68   print(dbgs());
69   dbgs() << "\n";
70 }
71 #endif
72