blob: f6d1d3cffca03db261e0df51f31f5a965d275845 [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"
Eugene Zelenkod3a6c892017-02-11 00:27:28 +000013#include "llvm/Support/Compiler.h"
David Greene7b42d702010-01-05 01:28:22 +000014#include "llvm/Support/Debug.h"
Daniel Dunbar212b6d82009-08-27 07:57:12 +000015#include "llvm/Support/raw_ostream.h"
16
17using namespace llvm;
18
Sean Silva0e1fe182015-02-05 00:58:51 +000019void MCOperand::print(raw_ostream &OS) const {
Daniel Dunbar212b6d82009-08-27 07:57:12 +000020 OS << "<MCOperand ";
21 if (!isValid())
22 OS << "INVALID";
23 else if (isReg())
24 OS << "Reg:" << getReg();
25 else if (isImm())
26 OS << "Imm:" << getImm();
Dan Gohman216e0c22015-12-21 16:47:10 +000027 else if (isFPImm())
28 OS << "FPImm:" << getFPImm();
Daniel Dunbar73da11e2009-08-31 08:08:38 +000029 else if (isExpr()) {
Chris Lattnerc8f77172010-01-18 00:37:40 +000030 OS << "Expr:(" << *getExpr() << ")";
Owen Anderson4b53e182012-01-19 19:32:20 +000031 } else if (isInst()) {
32 OS << "Inst:(" << *getInst() << ")";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000033 } else
34 OS << "UNDEFINED";
35 OS << ">";
36}
37
Aaron Ballman615eb472017-10-15 14:32:27 +000038#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +000039LLVM_DUMP_METHOD void MCOperand::dump() const {
Sean Silva32f24c42015-02-05 01:13:47 +000040 print(dbgs());
David Greene7b42d702010-01-05 01:28:22 +000041 dbgs() << "\n";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000042}
Matthias Braun8c209aa2017-01-28 02:02:38 +000043#endif
Daniel Dunbar212b6d82009-08-27 07:57:12 +000044
Sean Silva0e1fe182015-02-05 00:58:51 +000045void MCInst::print(raw_ostream &OS) const {
Daniel Dunbar212b6d82009-08-27 07:57:12 +000046 OS << "<MCInst " << getOpcode();
47 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
48 OS << " ";
Sean Silva0e1fe182015-02-05 00:58:51 +000049 getOperand(i).print(OS);
Daniel Dunbar212b6d82009-08-27 07:57:12 +000050 }
51 OS << ">";
52}
53
Sean Silva0e1fe182015-02-05 00:58:51 +000054void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
Daniel Dunbar04047fb2010-03-22 21:49:34 +000055 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;
Sean Silva0e1fe182015-02-05 00:58:51 +000064 getOperand(i).print(OS);
Daniel Dunbar04047fb2010-03-22 21:49:34 +000065 }
Daniel Dunbar3627af52010-05-26 15:18:13 +000066 OS << ">";
Daniel Dunbar04047fb2010-03-22 21:49:34 +000067}
68
Aaron Ballman615eb472017-10-15 14:32:27 +000069#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +000070LLVM_DUMP_METHOD void MCInst::dump() const {
Sean Silva32f24c42015-02-05 01:13:47 +000071 print(dbgs());
David Greene7b42d702010-01-05 01:28:22 +000072 dbgs() << "\n";
Daniel Dunbar212b6d82009-08-27 07:57:12 +000073}
Matthias Braun8c209aa2017-01-28 02:02:38 +000074#endif