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,
62 void encodeFPSYSSelect(
const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos,
73 : MCII(mcii), Ctx(ctx) {}
75 ~M68kMCCodeEmitter()
override {}
84#include "M68kGenMCCodeEmitter.inc"
88 using type =
typename std::conditional<
90 typename std::conditional<
99 return static_cast<unsigned>(BitPos / 8 + ((BitPos & 0b1111) < 8 ? 1 : -1));
101 assert(!(BitPos & 0b1111) &&
"Not aligned to word boundary?");
126template <
unsigned Size>
127void M68kMCCodeEmitter::encodeRelocImm(
const MCInst &
MI,
unsigned OpIdx,
134 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(MCO.
getImm()));
135 }
else if (MCO.
isExpr()) {
140 if (Expr->evaluateAsAbsolute(
Addr)) {
141 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(
Addr));
146 unsigned InsertByte = getBytePosition<Size>(InsertPos);
151template <
unsigned Size>
152void M68kMCCodeEmitter::encodePCRelImm(
const MCInst &
MI,
unsigned OpIdx,
159 Value |= M68k::swapWord<value_t>(
static_cast<value_t
>(MCO.
getImm()));
160 }
else if (MCO.
isExpr()) {
162 unsigned InsertByte = getBytePosition<Size>(InsertPos);
170 LabelOffset = InsertByte - 2;
171 else if (InsertByte % 2)
186void M68kMCCodeEmitter::encodeFPSYSSelect(
const MCInst &
MI,
unsigned OpIdx,
206void M68kMCCodeEmitter::encodeInverseMoveMask(
219 unsigned RegNum =
Op.getReg();
220 const auto *RI = Ctx.getRegisterInfo();
221 Value |= RI->getEncodingValue(RegNum);
225 }
else if (
Op.isImm()) {
228 }
else if (
Op.isExpr()) {
231 if (!
Op.getExpr()->evaluateAsAbsolute(
Addr))
233 "can be placed here.");
240void M68kMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
245 <<
"(" <<
MI.getOpcode() <<
")\n");
249 APInt EncodedInst(16, 0U);
250 APInt Scratch(64, 0U);
251 getBinaryCodeForInstr(
MI, Fixups, EncodedInst, Scratch, STI);
253 unsigned InstSize = EncodedInst.getBitWidth();
254 for (
unsigned i = 0; i != InstSize; i += 16)
255 support::endian::write<uint16_t>(
256 CB,
static_cast<uint16_t>(EncodedInst.extractBitsAsZExtValue(16, i)),
262 return new M68kMCCodeEmitter(MCII, Ctx);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind, bool PCRel=false)
This file contains the declarations for the code emitter which are useful outside of the emitter itse...
This file provides M68k specific target descriptions.
MachineInstr unsigned OpIdx
Class for arbitrary precision integers.
This class represents an Operation in the Expression.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
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 LLVM_ABI 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 MCFixupKind getDataKindForSize(unsigned Size)
Return the generic fixup kind for a value with the given size.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
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
Wrapper class representing physical registers. Should be passed by value.
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)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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