LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCInst.cpp
Go to the documentation of this file.
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"
15 
16 using namespace llvm;
17 
18 void MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) 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)
36 void MCOperand::dump() const {
37  print(dbgs(), 0);
38  dbgs() << "\n";
39 }
40 #endif
41 
42 void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
43  OS << "<MCInst " << getOpcode();
44  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
45  OS << " ";
46  getOperand(i).print(OS, MAI);
47  }
48  OS << ">";
49 }
50 
52  const MCInstPrinter *Printer,
53  StringRef Separator) const {
54  OS << "<MCInst #" << getOpcode();
55 
56  // Show the instruction opcode name if we have access to a printer.
57  if (Printer)
58  OS << ' ' << Printer->getOpcodeName(getOpcode());
59 
60  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
61  OS << Separator;
62  getOperand(i).print(OS, MAI);
63  }
64  OS << ">";
65 }
66 
67 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
68 void MCInst::dump() const {
69  print(dbgs(), 0);
70  dbgs() << "\n";
71 }
72 #endif
bool isValid() const
Definition: MCInst.h:55
bool isReg() const
Definition: MCInst.h:56
print alias Alias Set Printer
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
Definition: MCInst.cpp:42
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
Definition: MCInst.cpp:18
unsigned getReg() const
getReg - Returns the register number.
Definition: MCInst.h:63
bool isImm() const
Definition: MCInst.h:57
void dump() const
Definition: MCInst.cpp:68
const MCExpr * getExpr() const
Definition: MCInst.h:93
void dump() const
Definition: MCInst.cpp:36
StringRef getOpcodeName(unsigned Opcode) const
bool isExpr() const
Definition: MCInst.h:59
bool isInst() const
Definition: MCInst.h:60
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Definition: Debug.cpp:101
unsigned getOpcode() const
Definition: MCInst.h:158
int64_t getImm() const
Definition: MCInst.h:74
void dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI=0, const MCInstPrinter *Printer=0, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given. Operators are separated by the Separator string.
Definition: MCInst.cpp:51
unsigned getNumOperands() const
Definition: MCInst.h:165
const MCInst * getInst() const
Definition: MCInst.h:102
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:163