blob: 7ef69be66df64e07dd2f6ad20174b0ffd62d23fe [file] [log] [blame]
Daniel Dunbar212b6d82009-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 Dunbar73da11e2009-08-31 08:08:38 +000011#include "llvm/MC/MCExpr.h"
Daniel Dunbar04047fb2010-03-22 21:49:34 +000012#include "llvm/MC/MCInstPrinter.h"
David Greene7b42d702010-01-05 01:28:22 +000013#include "llvm/Support/Debug.h"
Daniel Dunbar212b6d82009-08-27 07:57:12 +000014#include "llvm/Support/raw_ostream.h"
15
16using namespace llvm;
17
Sean Silva0e1fe182015-02-05 00:58:51 +000018void MCOperand::print(raw_ostream &OS) const {
Daniel Dunbar212b6d82009-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 Dunbar73da11e2009-08-31 08:08:38 +000026 else if (isExpr()) {
Chris Lattnerc8f77172010-01-18 00:37:40 +000027 OS << "Expr:(" << *getExpr() << ")";
Owen Anderson4b53e182012-01-19 19:32:20 +000028 } else if (isInst()) {
29 OS << "Inst:(" << *getInst() << ")";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000030 } else
31 OS << "UNDEFINED";
32 OS << ">";
33}
34
Manman Ren49d684e2012-09-12 05:06:18 +000035#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Daniel Dunbar212b6d82009-08-27 07:57:12 +000036void MCOperand::dump() const {
Sean Silva32f24c42015-02-05 01:13:47 +000037 print(dbgs());
David Greene7b42d702010-01-05 01:28:22 +000038 dbgs() << "\n";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000039}
Manman Renc3366cc2012-09-06 19:55:56 +000040#endif
Daniel Dunbar212b6d82009-08-27 07:57:12 +000041
Sean Silva0e1fe182015-02-05 00:58:51 +000042void MCInst::print(raw_ostream &OS) const {
Daniel Dunbar212b6d82009-08-27 07:57:12 +000043 OS << "<MCInst " << getOpcode();
44 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
45 OS << " ";
Sean Silva0e1fe182015-02-05 00:58:51 +000046 getOperand(i).print(OS);
Daniel Dunbar212b6d82009-08-27 07:57:12 +000047 }
48 OS << ">";
49}
50
Sean Silva0e1fe182015-02-05 00:58:51 +000051void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
Daniel Dunbar04047fb2010-03-22 21:49:34 +000052 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;
Sean Silva0e1fe182015-02-05 00:58:51 +000061 getOperand(i).print(OS);
Daniel Dunbar04047fb2010-03-22 21:49:34 +000062 }
Daniel Dunbar3627af52010-05-26 15:18:13 +000063 OS << ">";
Daniel Dunbar04047fb2010-03-22 21:49:34 +000064}
65
Manman Ren49d684e2012-09-12 05:06:18 +000066#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Daniel Dunbar212b6d82009-08-27 07:57:12 +000067void MCInst::dump() const {
Sean Silva32f24c42015-02-05 01:13:47 +000068 print(dbgs());
David Greene7b42d702010-01-05 01:28:22 +000069 dbgs() << "\n";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000070}
Manman Renc3366cc2012-09-06 19:55:56 +000071#endif