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/Support/Casting.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/Support/Debug.h"
16 #include "llvm/Support/raw_ostream.h"
20 void MCOperand::print(raw_ostream
&OS
) const {
25 OS
<< "Reg:" << getReg();
27 OS
<< "Imm:" << getImm();
29 OS
<< "FPImm:" << getFPImm();
31 OS
<< "Expr:(" << *getExpr() << ")";
32 } else if (isInst()) {
33 OS
<< "Inst:(" << *getInst() << ")";
39 bool MCOperand::evaluateAsConstantImm(int64_t &Imm
) const {
47 bool MCOperand::isBareSymbolRef() const {
49 "isBareSymbolRef expects only expressions");
50 const MCExpr
*Expr
= getExpr();
51 MCExpr::ExprKind Kind
= getExpr()->getKind();
52 return Kind
== MCExpr::SymbolRef
&&
53 cast
<MCSymbolRefExpr
>(Expr
)->getKind() == MCSymbolRefExpr::VK_None
;
56 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
57 LLVM_DUMP_METHOD
void MCOperand::dump() const {
63 void MCInst::print(raw_ostream
&OS
) const {
64 OS
<< "<MCInst " << getOpcode();
65 for (unsigned i
= 0, e
= getNumOperands(); i
!= e
; ++i
) {
67 getOperand(i
).print(OS
);
72 void MCInst::dump_pretty(raw_ostream
&OS
, const MCInstPrinter
*Printer
,
73 StringRef Separator
) const {
74 StringRef InstName
= Printer
? Printer
->getOpcodeName(getOpcode()) : "";
75 dump_pretty(OS
, InstName
, Separator
);
78 void MCInst::dump_pretty(raw_ostream
&OS
, StringRef Name
,
79 StringRef Separator
) const {
80 OS
<< "<MCInst #" << getOpcode();
82 // Show the instruction opcode name if we have it.
86 for (unsigned i
= 0, e
= getNumOperands(); i
!= e
; ++i
) {
88 getOperand(i
).print(OS
);
93 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
94 LLVM_DUMP_METHOD
void MCInst::dump() const {