2012-04-12 19:55:53 +02:00
|
|
|
//===- HexagonInstPrinter.cpp - Convert Hexagon MCInst to assembly syntax -===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-04-12 19:55:53 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class prints an Hexagon MCInst to a .s file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-02-20 17:13:27 +01:00
|
|
|
#include "HexagonInstPrinter.h"
|
2015-11-09 05:07:48 +01:00
|
|
|
#include "MCTargetDesc/HexagonBaseInfo.h"
|
2015-02-19 22:10:50 +01:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2012-04-12 19:55:53 +02:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-01-07 12:48:04 +01:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2015-11-09 05:07:48 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-04-12 19:55:53 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:41:26 +02:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2012-04-12 19:55:53 +02:00
|
|
|
#define GET_INSTRUCTION_NAME
|
|
|
|
#include "HexagonGenAsmWriter.inc"
|
|
|
|
|
2015-11-09 05:07:48 +01:00
|
|
|
void HexagonInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
|
2018-08-17 23:12:37 +02:00
|
|
|
O << getRegisterName(RegNo);
|
2015-05-29 16:44:13 +02:00
|
|
|
}
|
2012-04-12 23:06:38 +02:00
|
|
|
|
2020-01-03 19:55:30 +01:00
|
|
|
void HexagonInstPrinter::printInst(const MCInst *MI, uint64_t Address,
|
|
|
|
StringRef Annot, const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &OS) {
|
2015-05-29 16:44:13 +02:00
|
|
|
assert(HexagonMCInstrInfo::isBundle(*MI));
|
|
|
|
assert(HexagonMCInstrInfo::bundleSize(*MI) <= HEXAGON_PACKET_SIZE);
|
2015-11-09 05:07:48 +01:00
|
|
|
assert(HexagonMCInstrInfo::bundleSize(*MI) > 0);
|
2015-05-29 16:44:13 +02:00
|
|
|
HasExtender = false;
|
|
|
|
for (auto const &I : HexagonMCInstrInfo::bundleInstructions(*MI)) {
|
|
|
|
MCInst const &MCI = *I.getInst();
|
2015-06-05 18:00:11 +02:00
|
|
|
if (HexagonMCInstrInfo::isDuplex(MII, MCI)) {
|
2020-01-03 21:02:46 +01:00
|
|
|
printInstruction(MCI.getOperand(1).getInst(), Address, OS);
|
2015-06-05 18:00:11 +02:00
|
|
|
OS << '\v';
|
|
|
|
HasExtender = false;
|
2020-01-03 21:02:46 +01:00
|
|
|
printInstruction(MCI.getOperand(0).getInst(), Address, OS);
|
2015-06-05 18:00:11 +02:00
|
|
|
} else
|
2020-01-03 21:02:46 +01:00
|
|
|
printInstruction(&MCI, Address, OS);
|
2018-08-17 23:12:37 +02:00
|
|
|
HasExtender = HexagonMCInstrInfo::isImmext(MCI);
|
2015-05-29 16:44:13 +02:00
|
|
|
OS << "\n";
|
|
|
|
}
|
2012-05-03 23:52:53 +02:00
|
|
|
|
2018-03-30 21:30:28 +02:00
|
|
|
bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(*MI);
|
|
|
|
bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(*MI);
|
|
|
|
if (IsLoop0) {
|
|
|
|
OS << (IsLoop1 ? " :endloop01" : " :endloop0");
|
|
|
|
} else if (IsLoop1) {
|
|
|
|
OS << " :endloop1";
|
2012-04-12 19:55:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 05:07:48 +01:00
|
|
|
void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
|
2012-04-12 19:55:53 +02:00
|
|
|
raw_ostream &O) const {
|
2015-11-09 05:07:48 +01:00
|
|
|
if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
|
|
|
|
(HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
|
|
|
|
O << "#";
|
|
|
|
MCOperand const &MO = MI->getOperand(OpNo);
|
2012-04-12 19:55:53 +02:00
|
|
|
if (MO.isReg()) {
|
2015-11-09 05:07:48 +01:00
|
|
|
O << getRegisterName(MO.getReg());
|
|
|
|
} else if (MO.isExpr()) {
|
|
|
|
int64_t Value;
|
|
|
|
if (MO.getExpr()->evaluateAsAbsolute(Value))
|
|
|
|
O << formatImm(Value);
|
|
|
|
else
|
|
|
|
O << *MO.getExpr();
|
2012-04-12 19:55:53 +02:00
|
|
|
} else {
|
2012-05-03 23:52:53 +02:00
|
|
|
llvm_unreachable("Unknown operand");
|
2012-04-12 19:55:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 05:07:48 +01:00
|
|
|
void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) const {
|
|
|
|
MCOperand const &MO = MI->getOperand(OpNo);
|
|
|
|
assert (MO.isExpr());
|
|
|
|
MCExpr const &Expr = *MO.getExpr();
|
|
|
|
int64_t Value;
|
|
|
|
if (Expr.evaluateAsAbsolute(Value))
|
|
|
|
O << format("0x%" PRIx64, Value);
|
|
|
|
else {
|
|
|
|
if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
|
|
|
|
if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
|
|
|
|
O << "##";
|
|
|
|
O << Expr;
|
2015-04-27 16:16:43 +02:00
|
|
|
}
|
|
|
|
}
|