LLVM  6.0.0svn
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/Compiler.h"
14 #include "llvm/Support/Debug.h"
16 
17 using namespace llvm;
18 
19 void MCOperand::print(raw_ostream &OS) const {
20  OS << "<MCOperand ";
21  if (!isValid())
22  OS << "INVALID";
23  else if (isReg())
24  OS << "Reg:" << getReg();
25  else if (isImm())
26  OS << "Imm:" << getImm();
27  else if (isFPImm())
28  OS << "FPImm:" << getFPImm();
29  else if (isExpr()) {
30  OS << "Expr:(" << *getExpr() << ")";
31  } else if (isInst()) {
32  OS << "Inst:(" << *getInst() << ")";
33  } else
34  OS << "UNDEFINED";
35  OS << ">";
36 }
37 
38 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
40  print(dbgs());
41  dbgs() << "\n";
42 }
43 #endif
44 
45 void MCInst::print(raw_ostream &OS) const {
46  OS << "<MCInst " << getOpcode();
47  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
48  OS << " ";
49  getOperand(i).print(OS);
50  }
51  OS << ">";
52 }
53 
55  StringRef Separator) const {
56  OS << "<MCInst #" << getOpcode();
57 
58  // Show the instruction opcode name if we have access to a printer.
59  if (Printer)
60  OS << ' ' << Printer->getOpcodeName(getOpcode());
61 
62  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
63  OS << Separator;
64  getOperand(i).print(OS);
65  }
66  OS << ">";
67 }
68 
69 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
71  print(dbgs());
72  dbgs() << "\n";
73 }
74 #endif
bool isImm() const
Definition: MCInst.h:59
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
void print(raw_ostream &OS) const
Definition: MCInst.cpp:19
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:54
bool isReg() const
Definition: MCInst.h:58
print alias Alias Set Printer
void dump() const
Definition: MCInst.cpp:39
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
const MCInst * getInst() const
Definition: MCInst.h:106
const MCExpr * getExpr() const
Definition: MCInst.h:96
int64_t getImm() const
Definition: MCInst.h:76
bool isInst() const
Definition: MCInst.h:62
bool isFPImm() const
Definition: MCInst.h:60
bool isExpr() const
Definition: MCInst.h:61
void print(raw_ostream &OS) const
Definition: MCInst.cpp:45
void dump() const
Definition: MCInst.cpp:70
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
StringRef getOpcodeName(unsigned Opcode) const
Return the name of the specified opcode enum (e.g.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isValid() const
Definition: MCInst.h:57
double getFPImm() const
Definition: MCInst.h:86