blob: e96010bd5c860dc898d453436318242be244ce3c [file] [log] [blame]
Daniel Dunbar4b770c22009-08-27 07:57:12 +00001//===- 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"
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000011#include "llvm/MC/MCExpr.h"
Daniel Dunbar67c076c2010-03-22 21:49:34 +000012#include "llvm/MC/MCInstPrinter.h"
David Greene593b6e42010-01-05 01:28:22 +000013#include "llvm/Support/Debug.h"
Daniel Dunbar4b770c22009-08-27 07:57:12 +000014#include "llvm/Support/raw_ostream.h"
15
16using namespace llvm;
17
Chris Lattner684c593d2009-09-03 05:46:51 +000018void MCOperand::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
Daniel Dunbar4b770c22009-08-27 07:57:12 +000019 OS << "<MCOperand ";
20 if (!isValid())
21 OS << "INVALID";
22 else if (isReg())
23 OS << "Reg:" << getReg();
24 else if (isImm())
25 OS << "Imm:" << getImm();
Daniel Dunbar8c2eebe2009-08-31 08:08:38 +000026 else if (isExpr()) {
Chris Lattner8cb9a3b2010-01-18 00:37:40 +000027 OS << "Expr:(" << *getExpr() << ")";
Owen Anderson27ff6b52012-01-19 19:32:20 +000028 } else if (isInst()) {
29 OS << "Inst:(" << *getInst() << ")";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000030 } else
31 OS << "UNDEFINED";
32 OS << ">";
33}
34
Manman Rencc77eec2012-09-06 19:55:56 +000035#ifndef NDEBUG
Daniel Dunbar4b770c22009-08-27 07:57:12 +000036void MCOperand::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000037 print(dbgs(), 0);
38 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000039}
Manman Rencc77eec2012-09-06 19:55:56 +000040#endif
Daniel Dunbar4b770c22009-08-27 07:57:12 +000041
Chris Lattner684c593d2009-09-03 05:46:51 +000042void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
Daniel Dunbar4b770c22009-08-27 07:57:12 +000043 OS << "<MCInst " << getOpcode();
44 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
45 OS << " ";
Chris Lattner684c593d2009-09-03 05:46:51 +000046 getOperand(i).print(OS, MAI);
Daniel Dunbar4b770c22009-08-27 07:57:12 +000047 }
48 OS << ">";
49}
50
Daniel Dunbar67c076c2010-03-22 21:49:34 +000051void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI,
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 }
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +000064 OS << ">";
Daniel Dunbar67c076c2010-03-22 21:49:34 +000065}
66
Manman Rencc77eec2012-09-06 19:55:56 +000067#ifndef NDEBUG
Daniel Dunbar4b770c22009-08-27 07:57:12 +000068void MCInst::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000069 print(dbgs(), 0);
70 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000071}
Manman Rencc77eec2012-09-06 19:55:56 +000072#endif