2016-09-30 22:01:50 +08:00
|
|
|
//===- AVRInstPrinter.h - Convert AVR MCInst to assembly syntax -*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2016-09-30 22:01:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class prints an AVR MCInst to a .s file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_AVR_INST_PRINTER_H
|
|
|
|
#define LLVM_AVR_INST_PRINTER_H
|
|
|
|
|
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
|
|
|
|
|
|
|
#include "MCTargetDesc/AVRMCTargetDesc.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// Prints AVR instructions to a textual stream.
|
|
|
|
class AVRInstPrinter : public MCInstPrinter {
|
|
|
|
public:
|
|
|
|
AVRInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
|
|
|
|
const MCRegisterInfo &MRI)
|
|
|
|
: MCInstPrinter(MAI, MII, MRI) {}
|
|
|
|
|
|
|
|
static const char *getPrettyRegisterName(unsigned RegNo,
|
|
|
|
MCRegisterInfo const &MRI);
|
|
|
|
|
2020-01-04 02:55:30 +08:00
|
|
|
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
|
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) override;
|
2016-09-30 22:01:50 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const char *getRegisterName(unsigned RegNo,
|
|
|
|
unsigned AltIdx = AVR::NoRegAltName);
|
|
|
|
|
|
|
|
void printOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
|
|
|
void printPCRelImm(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
[MCInstPrinter] Pass `Address` parameter to MCOI::OPERAND_PCREL typed operands. NFC
Follow-up of D72172 and D72180
This patch passes `uint64_t Address` to print methods of PC-relative
operands so that subsequent target specific patches can change
`*InstPrinter::print{Operand,PCRelImm,...}` to customize the output.
Add MCInstPrinter::PrintBranchImmAsAddress which is set to true by
llvm-objdump.
```
// Current llvm-objdump -d output
aarch64: 20000: bl #0
ppc: 20000: bl .+4
x86: 20000: callq 0
// Ideal output
aarch64: 20000: bl 0x20000
ppc: 20000: bl 0x20004
x86: 20000: callq 0x20005
// GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled
aarch64: 20000: bl 20000
ppc: 20000: bl 0x20004
x86: 20000: callq 20005
```
In `lib/Target/X86/X86GenAsmWriter1.inc` (generated by `llvm-tblgen -gen-asm-writer`):
```
case 12:
// CALL64pcrel32, CALLpcrel16, CALLpcrel32, EH_SjLj_Setup, JCXZ, JECXZ, J...
- printPCRelImm(MI, 0, O);
+ printPCRelImm(MI, Address, 0, O);
return;
```
Some targets have 2 `printOperand` overloads, one without `Address` and
one with `Address`. They should annotate derived `Operand` properly with
`let OperandType = "OPERAND_PCREL"`.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D76574
2020-03-23 03:32:27 +08:00
|
|
|
void printPCRelImm(const MCInst *MI, uint64_t /*Address*/, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
printPCRelImm(MI, OpNo, O);
|
|
|
|
}
|
2016-09-30 22:01:50 +08:00
|
|
|
void printMemri(const MCInst *MI, unsigned OpNo, raw_ostream &O);
|
|
|
|
|
|
|
|
// Autogenerated by TableGen.
|
2020-11-17 17:38:17 +08:00
|
|
|
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
|
2020-01-04 04:02:46 +08:00
|
|
|
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
|
2020-03-27 14:55:43 +08:00
|
|
|
bool printAliasInstr(const MCInst *MI, uint64_t Address, raw_ostream &O);
|
2020-03-27 15:17:56 +08:00
|
|
|
void printCustomAliasOperand(const MCInst *MI, uint64_t Address,
|
|
|
|
unsigned OpIdx, unsigned PrintMethodIdx,
|
|
|
|
raw_ostream &O);
|
2016-09-30 22:01:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_AVR_INST_PRINTER_H
|
|
|
|
|