1 //===- lib/MC/MCInst.cpp - MCInst implementation --------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCInst.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCInstPrinter.h"
13 #include "llvm/MC/MCRegisterInfo.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 MCRegisterInfo
*RegInfo
) const {
28 OS
<< RegInfo
->getName(getReg());
32 OS
<< "Imm:" << getImm();
34 OS
<< "SFPImm:" << bit_cast
<float>(getSFPImm());
36 OS
<< "DFPImm:" << bit_cast
<double>(getDFPImm());
38 OS
<< "Expr:(" << *getExpr() << ")";
39 } else if (isInst()) {
41 if (const auto *Inst
= getInst())
42 Inst
->print(OS
, RegInfo
);
51 bool MCOperand::evaluateAsConstantImm(int64_t &Imm
) const {
59 bool MCOperand::isBareSymbolRef() const {
61 "isBareSymbolRef expects only expressions");
62 const MCExpr
*Expr
= getExpr();
63 MCExpr::ExprKind Kind
= getExpr()->getKind();
64 return Kind
== MCExpr::SymbolRef
&&
65 cast
<MCSymbolRefExpr
>(Expr
)->getKind() == MCSymbolRefExpr::VK_None
;
68 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
69 LLVM_DUMP_METHOD
void MCOperand::dump() const {
75 void MCInst::print(raw_ostream
&OS
, const MCRegisterInfo
*RegInfo
) const {
76 OS
<< "<MCInst " << getOpcode();
77 for (unsigned i
= 0, e
= getNumOperands(); i
!= e
; ++i
) {
79 getOperand(i
).print(OS
, RegInfo
);
84 void MCInst::dump_pretty(raw_ostream
&OS
, const MCInstPrinter
*Printer
,
86 const MCRegisterInfo
*RegInfo
) const {
87 StringRef InstName
= Printer
? Printer
->getOpcodeName(getOpcode()) : "";
88 dump_pretty(OS
, InstName
, Separator
, RegInfo
);
91 void MCInst::dump_pretty(raw_ostream
&OS
, StringRef Name
, StringRef Separator
,
92 const MCRegisterInfo
*RegInfo
) const {
93 OS
<< "<MCInst #" << getOpcode();
95 // Show the instruction opcode name if we have it.
99 for (unsigned i
= 0, e
= getNumOperands(); i
!= e
; ++i
) {
101 getOperand(i
).print(OS
, RegInfo
);
106 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
107 LLVM_DUMP_METHOD
void MCInst::dump() const {