blob: 7bbfd2efa136676c668873245b87ca971975d1f5 [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
35void MCOperand::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000036 print(dbgs(), 0);
37 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000038}
39
Chris Lattner684c593d2009-09-03 05:46:51 +000040void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
Daniel Dunbar4b770c22009-08-27 07:57:12 +000041 OS << "<MCInst " << getOpcode();
42 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
43 OS << " ";
Chris Lattner684c593d2009-09-03 05:46:51 +000044 getOperand(i).print(OS, MAI);
Daniel Dunbar4b770c22009-08-27 07:57:12 +000045 }
46 OS << ">";
47}
48
Daniel Dunbar67c076c2010-03-22 21:49:34 +000049void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI,
50 const MCInstPrinter *Printer,
51 StringRef Separator) const {
52 OS << "<MCInst #" << getOpcode();
53
54 // Show the instruction opcode name if we have access to a printer.
55 if (Printer)
56 OS << ' ' << Printer->getOpcodeName(getOpcode());
57
58 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
59 OS << Separator;
60 getOperand(i).print(OS, MAI);
61 }
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +000062 OS << ">";
Daniel Dunbar67c076c2010-03-22 21:49:34 +000063}
64
Daniel Dunbar4b770c22009-08-27 07:57:12 +000065void MCInst::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000066 print(dbgs(), 0);
67 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000068}