LLVM  4.0.0
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 {
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 
38  print(dbgs());
39  dbgs() << "\n";
40 }
41 
42 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 
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 
67  print(dbgs());
68  dbgs() << "\n";
69 }
bool isValid() const
Definition: MCInst.h:55
double getFPImm() const
Definition: MCInst.h:83
size_t i
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:450
bool isReg() const
Definition: MCInst.h:56
void dump() const
Definition: MCInst.cpp:37
print alias Alias Set Printer
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
Definition: MCInst.cpp:51
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:63
bool isImm() const
Definition: MCInst.h:57
const MCExpr * getExpr() const
Definition: MCInst.h:93
void print(raw_ostream &OS) const
Definition: MCInst.cpp:18
bool isFPImm() const
Definition: MCInst.h:58
StringRef getOpcodeName(unsigned Opcode) const
Return the name of the specified opcode enum (e.g.
bool isExpr() const
Definition: MCInst.h:59
bool isInst() const
Definition: MCInst.h:60
static const char * Separator
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
unsigned getOpcode() const
Definition: MCInst.h:159
int64_t getImm() const
Definition: MCInst.h:74
void print(raw_ostream &OS) const
Definition: MCInst.cpp:42
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
unsigned getNumOperands() const
Definition: MCInst.h:166
const MCInst * getInst() const
Definition: MCInst.h:102
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
void dump() const
Definition: MCInst.cpp:66
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:164