• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (isFPImm())
27      OS << "FPImm:" << getFPImm();
28    else if (isExpr()) {
29      OS << "Expr:(" << *getExpr() << ")";
30    } else if (isInst()) {
31      OS << "Inst:(" << *getInst() << ")";
32    } else
33      OS << "UNDEFINED";
34    OS << ">";
35  }
36  
37  #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const38  LLVM_DUMP_METHOD void MCOperand::dump() const {
39    print(dbgs());
40    dbgs() << "\n";
41  }
42  #endif
43  
print(raw_ostream & OS) const44  void MCInst::print(raw_ostream &OS) const {
45    OS << "<MCInst " << getOpcode();
46    for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
47      OS << " ";
48      getOperand(i).print(OS);
49    }
50    OS << ">";
51  }
52  
dump_pretty(raw_ostream & OS,const MCInstPrinter * Printer,StringRef Separator) const53  void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
54                           StringRef Separator) const {
55    OS << "<MCInst #" << getOpcode();
56  
57    // Show the instruction opcode name if we have access to a printer.
58    if (Printer)
59      OS << ' ' << Printer->getOpcodeName(getOpcode());
60  
61    for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
62      OS << Separator;
63      getOperand(i).print(OS);
64    }
65    OS << ">";
66  }
67  
68  #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
dump() const69  LLVM_DUMP_METHOD void MCInst::dump() const {
70    print(dbgs());
71    dbgs() << "\n";
72  }
73  #endif
74