diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h --- a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h +++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.h @@ -14,13 +14,17 @@ #ifndef LLVM_LIB_TARGET_M68K_INSTPRINTER_M68KINSTPRINTER_H #define LLVM_LIB_TARGET_M68K_INSTPRINTER_M68KINSTPRINTER_H +#include "M68kMemOperandPrinter.h" #include "llvm/MC/MCInstPrinter.h" namespace llvm { class TargetMachine; -class M68kInstPrinter : public MCInstPrinter { +class M68kInstPrinter : public MCInstPrinter, + public M68kMemOperandPrinter { + friend class M68kMemOperandPrinter; + public: M68kInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) @@ -48,16 +52,7 @@ /// Print register mask for MOVEM instruction in order A7-A0,D7-D0 void printMoveMaskR(const MCInst *MI, unsigned opNum, raw_ostream &O); void printDisp(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printARIMem(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printARIPIMem(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printARIPDMem(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printARIDMem(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printARIIMem(const MCInst *MI, unsigned opNum, raw_ostream &O); void printAbsMem(const MCInst *MI, unsigned opNum, raw_ostream &O); - void printPCDMem(const MCInst *MI, uint64_t Address, unsigned opNum, - raw_ostream &O); - void printPCIMem(const MCInst *MI, uint64_t Address, unsigned opNum, - raw_ostream &O); //===----------------------------------------------------------------------===// // Specializations diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp --- a/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp +++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kInstPrinter.cpp @@ -147,47 +147,6 @@ Op.getExpr()->print(O, &MAI); } -void M68kInstPrinter::printARIMem(const MCInst *MI, unsigned opNum, - raw_ostream &O) { - O << '('; - printOperand(MI, opNum, O); - O << ')'; -} - -void M68kInstPrinter::printARIPIMem(const MCInst *MI, unsigned opNum, - raw_ostream &O) { - O << "("; - printOperand(MI, opNum, O); - O << ")+"; -} - -void M68kInstPrinter::printARIPDMem(const MCInst *MI, unsigned opNum, - raw_ostream &O) { - O << "-("; - printOperand(MI, opNum, O); - O << ")"; -} - -void M68kInstPrinter::printARIDMem(const MCInst *MI, unsigned opNum, - raw_ostream &O) { - O << '('; - printDisp(MI, opNum + M68k::MemDisp, O); - O << ','; - printOperand(MI, opNum + M68k::MemBase, O); - O << ')'; -} - -void M68kInstPrinter::printARIIMem(const MCInst *MI, unsigned opNum, - raw_ostream &O) { - O << '('; - printDisp(MI, opNum + M68k::MemDisp, O); - O << ','; - printOperand(MI, opNum + M68k::MemBase, O); - O << ','; - printOperand(MI, opNum + M68k::MemIndex, O); - O << ')'; -} - // NOTE forcing (W,L) size available since M68020 only void M68kInstPrinter::printAbsMem(const MCInst *MI, unsigned opNum, raw_ostream &O) { @@ -201,19 +160,3 @@ assert(MO.isImm() && "absolute memory addressing needs an immediate"); O << format("$%0" PRIx64, (uint64_t)MO.getImm()); } - -void M68kInstPrinter::printPCDMem(const MCInst *MI, uint64_t Address, - unsigned opNum, raw_ostream &O) { - O << '('; - printDisp(MI, opNum + M68k::PCRelDisp, O); - O << ",%pc)"; -} - -void M68kInstPrinter::printPCIMem(const MCInst *MI, uint64_t Address, - unsigned opNum, raw_ostream &O) { - O << '('; - printDisp(MI, opNum + M68k::PCRelDisp, O); - O << ",%pc,"; - printOperand(MI, opNum + M68k::PCRelIndex, O); - O << ')'; -} diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kMemOperandPrinter.h b/llvm/lib/Target/M68k/MCTargetDesc/M68kMemOperandPrinter.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kMemOperandPrinter.h @@ -0,0 +1,80 @@ +//===-- M68kMemOperandPrinter.h - Memory operands printing ------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains memory operand printing logics shared between AsmPrinter +// and MCInstPrinter. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_M68K_MEMOPERANDPRINTER_M68KINSTPRINTER_H +#define LLVM_LIB_TARGET_M68K_MEMOPERANDPRINTER_M68KINSTPRINTER_H + +#include "M68kBaseInfo.h" + +#include "llvm/Support/raw_ostream.h" + +namespace llvm { +template class M68kMemOperandPrinter { + Derived &impl() { return *static_cast(this); } + +protected: + void printARIMem(const InstTy *MI, unsigned OpNum, raw_ostream &O) { + O << '('; + impl().printOperand(MI, OpNum, O); + O << ')'; + } + + void printARIPIMem(const InstTy *MI, unsigned OpNum, raw_ostream &O) { + O << "("; + impl().printOperand(MI, OpNum, O); + O << ")+"; + } + + void printARIPDMem(const InstTy *MI, unsigned OpNum, raw_ostream &O) { + O << "-("; + impl().printOperand(MI, OpNum, O); + O << ")"; + } + + void printARIDMem(const InstTy *MI, unsigned OpNum, raw_ostream &O) { + O << '('; + impl().printDisp(MI, OpNum + M68k::MemDisp, O); + O << ','; + impl().printOperand(MI, OpNum + M68k::MemBase, O); + O << ')'; + } + + void printARIIMem(const InstTy *MI, unsigned OpNum, raw_ostream &O) { + O << '('; + impl().printDisp(MI, OpNum + M68k::MemDisp, O); + O << ','; + impl().printOperand(MI, OpNum + M68k::MemBase, O); + O << ','; + impl().printOperand(MI, OpNum + M68k::MemIndex, O); + O << ')'; + } + + void printPCDMem(const InstTy *MI, uint64_t Address, unsigned OpNum, + raw_ostream &O) { + O << '('; + impl().printDisp(MI, OpNum + M68k::PCRelDisp, O); + O << ",%pc)"; + } + + void printPCIMem(const InstTy *MI, uint64_t Address, unsigned OpNum, + raw_ostream &O) { + O << '('; + impl().printDisp(MI, OpNum + M68k::PCRelDisp, O); + O << ",%pc,"; + impl().printOperand(MI, OpNum + M68k::PCRelIndex, O); + O << ')'; + } +}; +} // end namespace llvm +#endif