blob: 4cb628b395c3fba2ca0a61d26fa32499f235d217 [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() << ")";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000028 } else
29 OS << "UNDEFINED";
30 OS << ">";
31}
32
33void MCOperand::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000034 print(dbgs(), 0);
35 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000036}
37
Chris Lattner684c593d2009-09-03 05:46:51 +000038void MCInst::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
Daniel Dunbar4b770c22009-08-27 07:57:12 +000039 OS << "<MCInst " << getOpcode();
40 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
41 OS << " ";
Chris Lattner684c593d2009-09-03 05:46:51 +000042 getOperand(i).print(OS, MAI);
Daniel Dunbar4b770c22009-08-27 07:57:12 +000043 }
44 OS << ">";
45}
46
Daniel Dunbar67c076c2010-03-22 21:49:34 +000047void MCInst::dump_pretty(raw_ostream &OS, const MCAsmInfo *MAI,
48 const MCInstPrinter *Printer,
49 StringRef Separator) const {
50 OS << "<MCInst #" << getOpcode();
51
52 // Show the instruction opcode name if we have access to a printer.
53 if (Printer)
54 OS << ' ' << Printer->getOpcodeName(getOpcode());
55
56 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
57 OS << Separator;
58 getOperand(i).print(OS, MAI);
59 }
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +000060 OS << ">";
Daniel Dunbar67c076c2010-03-22 21:49:34 +000061}
62
Daniel Dunbar4b770c22009-08-27 07:57:12 +000063void MCInst::dump() const {
David Greene593b6e42010-01-05 01:28:22 +000064 print(dbgs(), 0);
65 dbgs() << "\n";
Daniel Dunbar4b770c22009-08-27 07:57:12 +000066}