1 //===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCInst.h"
11 #include "llvm/Config/llvm-config.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCInstPrinter.h"
14 #include "llvm/Support/Casting.h"
15 #include "llvm/Support/Compiler.h"
16 #include "llvm/Support/Debug.h"
17 #include "llvm/Support/raw_ostream.h"
21 void MCOperand::print(raw_ostream &OS) const {
26 OS << "Reg:" << getReg();
28 OS << "Imm:" << getImm();
30 OS << "FPImm:" << getFPImm();
32 OS << "Expr:(" << *getExpr() << ")";
33 } else if (isInst()) {
34 OS << "Inst:(" << *getInst() << ")";
40 bool MCOperand::evaluateAsConstantImm(int64_t &Imm) const {
48 bool MCOperand::isBareSymbolRef() const {
50 "isBareSymbolRef expects only expressions");
51 const MCExpr *Expr = getExpr();
52 MCExpr::ExprKind Kind = getExpr()->getKind();
53 return Kind == MCExpr::SymbolRef &&
54 cast<MCSymbolRefExpr>(Expr)->getKind() == MCSymbolRefExpr::VK_None;
57 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
58 LLVM_DUMP_METHOD void MCOperand::dump() const {
64 void MCInst::print(raw_ostream &OS) const {
65 OS << "<MCInst " << getOpcode();
66 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
68 getOperand(i).print(OS);
73 void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
74 StringRef Separator) const {
75 StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
76 dump_pretty(OS, InstName, Separator);
79 void MCInst::dump_pretty(raw_ostream &OS, StringRef Name,
80 StringRef Separator) const {
81 OS << "<MCInst #" << getOpcode();
83 // Show the instruction opcode name if we have it.
87 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
89 getOperand(i).print(OS);
94 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
95 LLVM_DUMP_METHOD void MCInst::dump() const {