]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCInst.cpp
Upgrade Unbound to 1.6.2. More to follow.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCInst.cpp
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"
15 #include "llvm/Support/raw_ostream.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)
39 LLVM_DUMP_METHOD void MCOperand::dump() const {
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
54 void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
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)
70 LLVM_DUMP_METHOD void MCInst::dump() const {
71   print(dbgs());
72   dbgs() << "\n";
73 }
74 #endif