34#define DEBUG_TYPE "m68k-mccodeemitter"
38 M68kMCCodeEmitter(
const M68kMCCodeEmitter &) =
delete;
39 void operator=(
const M68kMCCodeEmitter &) =
delete;
52 template <
unsigned Size>
53 void encodeRelocImm(
const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos,
57 template <
unsigned Size>
58 void encodePCRelImm(
const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos,
64 : MCII(mcii), Ctx(ctx) {}
66 ~M68kMCCodeEmitter()
override {}
75#include "M68kGenMCCodeEmitter.inc"
79 using type =
typename std::conditional<
81 typename std::conditional<
90 return static_cast<unsigned>(BitPos / 8 + ((BitPos & 0b1111) < 8 ? 1 : -1));
92 assert(!(BitPos & 0b1111) &&
"Not aligned to word boundary?");
112template <
unsigned Size>
113void M68kMCCodeEmitter::encodeRelocImm(
const MCInst &
MI,
unsigned OpIdx,
120 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(MCO.
getImm()));
121 }
else if (MCO.
isExpr()) {
126 if (Expr->evaluateAsAbsolute(
Addr)) {
127 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(
Addr));
132 unsigned InsertByte = getBytePosition<Size>(InsertPos);
139template <
unsigned Size>
140void M68kMCCodeEmitter::encodePCRelImm(
const MCInst &
MI,
unsigned OpIdx,
147 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(MCO.
getImm()));
148 }
else if (MCO.
isExpr()) {
150 unsigned InsertByte = getBytePosition<Size>(InsertPos);
158 LabelOffset = InsertByte - 2;
159 else if (InsertByte % 2)
181 unsigned RegNum =
Op.getReg();
182 const auto *RI = Ctx.getRegisterInfo();
183 Value |= RI->getEncodingValue(RegNum);
187 }
else if (
Op.isImm()) {
190 }
else if (
Op.isExpr()) {
193 if (!
Op.getExpr()->evaluateAsAbsolute(
Addr))
195 "can be placed here.");
202void M68kMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
206 unsigned Opcode =
MI.getOpcode();
208 LLVM_DEBUG(
dbgs() <<
"EncodeInstruction: " << MCII.getName(Opcode) <<
"("
212 APInt EncodedInst(16, 0U);
213 APInt Scratch(16, 0U);
214 getBinaryCodeForInstr(
MI, Fixups, EncodedInst, Scratch, STI);
217 int64_t InstSize = EncodedInst.getBitWidth();
219 for (
int i = 0; i < 4 && InstSize > 0; ++i, InstSize -= 16) {
220 support::endian::write<uint16_t>(CB,
static_cast<uint16_t>(Word),
229 return new M68kMCCodeEmitter(MCII, Ctx);
This file contains small standalone helper functions and enum definitions for the M68k target useful ...
This file contains M68k specific fixup entries.
static unsigned getBytePosition(unsigned BitPos)
This file contains the declarations for the code emitter which are useful outside of the emitter itse...
This file provides M68k specific target descriptions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class represents an Operation in the Expression.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
MCCodeEmitter - Generic instruction encoding interface.
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
MCCodeEmitter & operator=(const MCCodeEmitter &)=delete
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Instances of this class represent a single low-level machine instruction.
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
Generic base class for all target subtargets.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool isAddressRegister(unsigned RegNo)
support::ulittle32_t Word
This is an optimization pass for GlobalISel generic memory operations.
static MCFixupKind getFixupForSize(unsigned Size, bool isPCRel)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MCCodeEmitter * createM68kMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
typename std::conditional< Size==8, uint8_t, typename std::conditional< Size==16, uint16_t, typename std::conditional< Size==32, uint32_t, uint64_t >::type >::type >::type type