/src/llvm-project/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- HexagonInstPrinter.cpp - Convert Hexagon MCInst to assembly syntax -===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This class prints an Hexagon MCInst to a .s file. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
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" |
21 | | |
22 | | using namespace llvm; |
23 | | |
24 | | #define DEBUG_TYPE "asm-printer" |
25 | | |
26 | | #define GET_INSTRUCTION_NAME |
27 | | #include "HexagonGenAsmWriter.inc" |
28 | | |
29 | 0 | void HexagonInstPrinter::printRegName(raw_ostream &O, MCRegister Reg) const { |
30 | 0 | O << getRegisterName(Reg); |
31 | 0 | } |
32 | | |
33 | | void HexagonInstPrinter::printInst(const MCInst *MI, uint64_t Address, |
34 | | StringRef Annot, const MCSubtargetInfo &STI, |
35 | 0 | raw_ostream &OS) { |
36 | 0 | assert(HexagonMCInstrInfo::isBundle(*MI)); |
37 | 0 | assert(HexagonMCInstrInfo::bundleSize(*MI) <= HEXAGON_PACKET_SIZE); |
38 | 0 | assert(HexagonMCInstrInfo::bundleSize(*MI) > 0); |
39 | 0 | HasExtender = false; |
40 | 0 | for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) { |
41 | 0 | MCInst const &MCI = *I.getInst(); |
42 | 0 | if (HexagonMCInstrInfo::isDuplex(MII, MCI)) { |
43 | 0 | printInstruction(MCI.getOperand(1).getInst(), Address, OS); |
44 | 0 | OS << '\v'; |
45 | 0 | HasExtender = false; |
46 | 0 | printInstruction(MCI.getOperand(0).getInst(), Address, OS); |
47 | 0 | } else |
48 | 0 | printInstruction(&MCI, Address, OS); |
49 | 0 | HasExtender = HexagonMCInstrInfo::isImmext(MCI); |
50 | 0 | OS << "\n"; |
51 | 0 | } |
52 | |
|
53 | 0 | bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(*MI); |
54 | 0 | bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(*MI); |
55 | 0 | if (IsLoop0) { |
56 | 0 | OS << (IsLoop1 ? " :endloop01" : " :endloop0"); |
57 | 0 | } else if (IsLoop1) { |
58 | 0 | OS << " :endloop1"; |
59 | 0 | } |
60 | 0 | } |
61 | | |
62 | | void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo, |
63 | 0 | raw_ostream &O) const { |
64 | 0 | if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo && |
65 | 0 | (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))) |
66 | 0 | O << "#"; |
67 | 0 | MCOperand const &MO = MI->getOperand(OpNo); |
68 | 0 | if (MO.isReg()) { |
69 | 0 | O << getRegisterName(MO.getReg()); |
70 | 0 | } else if (MO.isExpr()) { |
71 | 0 | int64_t Value; |
72 | 0 | if (MO.getExpr()->evaluateAsAbsolute(Value)) |
73 | 0 | O << formatImm(Value); |
74 | 0 | else |
75 | 0 | O << *MO.getExpr(); |
76 | 0 | } else { |
77 | 0 | llvm_unreachable("Unknown operand"); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | | void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo, |
82 | 0 | raw_ostream &O) const { |
83 | 0 | MCOperand const &MO = MI->getOperand(OpNo); |
84 | 0 | assert (MO.isExpr()); |
85 | 0 | MCExpr const &Expr = *MO.getExpr(); |
86 | 0 | int64_t Value; |
87 | 0 | if (Expr.evaluateAsAbsolute(Value)) |
88 | 0 | O << format("0x%" PRIx64, Value); |
89 | 0 | else { |
90 | 0 | if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)) |
91 | 0 | if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo) |
92 | 0 | O << "##"; |
93 | 0 | O << Expr; |
94 | 0 | } |
95 | 0 | } |