LLVM 22.0.0git
HexagonInstPrinter.cpp
Go to the documentation of this file.
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"
16#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCInst.h"
19#include "llvm/Support/Debug.h"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "asm-printer"
25
26#define GET_INSTRUCTION_NAME
27#include "HexagonGenAsmWriter.inc"
28
30 O << getRegisterName(Reg);
31}
32
34 StringRef Annot, const MCSubtargetInfo &STI,
35 raw_ostream &OS) {
37 printInstruction(MI->getOperand(1).getInst(), Address, OS);
38 OS << '\v';
39 HasExtender = false;
40 printInstruction(MI->getOperand(0).getInst(), Address, OS);
41 } else {
43 }
44 HasExtender = HexagonMCInstrInfo::isImmext(*MI);
45 if ((MI->getOpcode() & HexagonII::INST_PARSE_MASK) ==
47 HasExtender = false;
48}
49
50void HexagonInstPrinter::printOperand(MCInst const *MI, unsigned OpNo,
51 raw_ostream &O) const {
52 if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo &&
53 (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI)))
54 O << "#";
55 MCOperand const &MO = MI->getOperand(OpNo);
56 if (MO.isReg()) {
57 O << getRegisterName(MO.getReg());
58 } else if (MO.isExpr()) {
59 int64_t Value;
60 if (MO.getExpr()->evaluateAsAbsolute(Value))
61 O << formatImm(Value);
62 else
63 MAI.printExpr(O, *MO.getExpr());
64 } else {
65 llvm_unreachable("Unknown operand");
66 }
67}
68
69void HexagonInstPrinter::printBrtarget(MCInst const *MI, unsigned OpNo,
70 raw_ostream &O) const {
71 MCOperand const &MO = MI->getOperand(OpNo);
72 assert (MO.isExpr());
73 MCExpr const &Expr = *MO.getExpr();
74 int64_t Value;
75 if (Expr.evaluateAsAbsolute(Value))
76 O << format("0x%" PRIx64, Value);
77 else {
78 if (HasExtender || HexagonMCInstrInfo::isConstExtended(MII, *MI))
79 if (HexagonMCInstrInfo::getExtendableOp(MII, *MI) == OpNo)
80 O << "##";
81 MAI.printExpr(O, Expr);
82 }
83}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IRTranslator LLVM IR MI
raw_pwrite_stream & OS
void printRegName(raw_ostream &O, MCRegister Reg) override
Print the assembler register name.
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O)
void printBrtarget(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
void printOperand(MCInst const *MI, unsigned OpNo, raw_ostream &O) const
void printInst(MCInst const *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &O) override
Print the specified MCInst to the specified raw_ostream.
static char const * getRegisterName(MCRegister Reg)
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
const MCAsmInfo & MAI
Definition: MCInstPrinter.h:52
format_object< int64_t > formatImm(int64_t Value) const
Utility function to print immediates in decimal or hex.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:40
bool isReg() const
Definition: MCInst.h:65
MCRegister getReg() const
Returns the register number.
Definition: MCInst.h:73
const MCExpr * getExpr() const
Definition: MCInst.h:118
bool isExpr() const
Definition: MCInst.h:69
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
bool isImmext(MCInst const &MCI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:126