1 //===- HexagonInstPrinter.cpp - Convert Hexagon MCInst to assembly syntax -===//
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 // This class prints an Hexagon MCInst to a .s file.
11 //===----------------------------------------------------------------------===//
13 #include "HexagonInstPrinter.h"
14 #include "MCTargetDesc/HexagonBaseInfo.h"
15 #include "MCTargetDesc/HexagonMCInstrInfo.h"
16 #include "llvm/MC/MCAsmInfo.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
24 #define DEBUG_TYPE "asm-printer"
26 #define GET_INSTRUCTION_NAME
27 #include "HexagonGenAsmWriter.inc"
29 void HexagonInstPrinter::printRegName(raw_ostream
&O
, MCRegister Reg
) {
30 O
<< getRegisterName(Reg
);
33 void HexagonInstPrinter::printInst(const MCInst
*MI
, uint64_t Address
,
34 StringRef Annot
, const MCSubtargetInfo
&STI
,
36 assert(HexagonMCInstrInfo::isBundle(*MI
));
37 assert(HexagonMCInstrInfo::bundleSize(*MI
) <= HEXAGON_PACKET_SIZE
);
38 assert(HexagonMCInstrInfo::bundleSize(*MI
) > 0);
40 for (auto const &I
: HexagonMCInstrInfo::bundleInstructions(*MI
)) {
41 MCInst
const &MCI
= *I
.getInst();
42 if (HexagonMCInstrInfo::isDuplex(MII
, MCI
)) {
43 printInstruction(MCI
.getOperand(1).getInst(), Address
, OS
);
46 printInstruction(MCI
.getOperand(0).getInst(), Address
, OS
);
48 printInstruction(&MCI
, Address
, OS
);
49 HasExtender
= HexagonMCInstrInfo::isImmext(MCI
);
53 bool IsLoop0
= HexagonMCInstrInfo::isInnerLoop(*MI
);
54 bool IsLoop1
= HexagonMCInstrInfo::isOuterLoop(*MI
);
56 OS
<< (IsLoop1
? " :endloop01" : " :endloop0");
62 void HexagonInstPrinter::printOperand(MCInst
const *MI
, unsigned OpNo
,
63 raw_ostream
&O
) const {
64 if (HexagonMCInstrInfo::getExtendableOp(MII
, *MI
) == OpNo
&&
65 (HasExtender
|| HexagonMCInstrInfo::isConstExtended(MII
, *MI
)))
67 MCOperand
const &MO
= MI
->getOperand(OpNo
);
69 O
<< getRegisterName(MO
.getReg());
70 } else if (MO
.isExpr()) {
72 if (MO
.getExpr()->evaluateAsAbsolute(Value
))
73 O
<< formatImm(Value
);
77 llvm_unreachable("Unknown operand");
81 void HexagonInstPrinter::printBrtarget(MCInst
const *MI
, unsigned OpNo
,
82 raw_ostream
&O
) const {
83 MCOperand
const &MO
= MI
->getOperand(OpNo
);
85 MCExpr
const &Expr
= *MO
.getExpr();
87 if (Expr
.evaluateAsAbsolute(Value
))
88 O
<< format("0x%" PRIx64
, Value
);
90 if (HasExtender
|| HexagonMCInstrInfo::isConstExtended(MII
, *MI
))
91 if (HexagonMCInstrInfo::getExtendableOp(MII
, *MI
) == OpNo
)