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,
71 void encodeScale(
const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos,
75 void encodeIndexSuppress(
const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos,
81 : MCII(mcii), Ctx(ctx) {}
83 ~M68kMCCodeEmitter()
override {}
92#include "M68kGenMCCodeEmitter.inc"
96 using type =
typename std::conditional<
98 typename std::conditional<
107 return static_cast<unsigned>(BitPos / 8 + ((BitPos & 0b1111) < 8 ? 1 : -1));
109 assert(!(BitPos & 0b1111) &&
"Not aligned to word boundary?");
134template <
unsigned Size>
135void M68kMCCodeEmitter::encodeRelocImm(
const MCInst &
MI,
unsigned OpIdx,
140 const MCOperand &MCO =
MI.getOperand(
OpIdx);
143 }
else if (MCO.
isExpr()) {
144 const MCExpr *Expr = MCO.
getExpr();
148 if (Expr->evaluateAsAbsolute(Addr)) {
159template <
unsigned Size>
160void M68kMCCodeEmitter::encodePCRelImm(
const MCInst &
MI,
unsigned OpIdx,
161 unsigned InsertPos, APInt &
Value,
162 SmallVectorImpl<MCFixup> &Fixups,
163 const MCSubtargetInfo &STI)
const {
164 const MCOperand &MCO =
MI.getOperand(
OpIdx);
168 }
else if (MCO.
isExpr()) {
169 const MCExpr *Expr = MCO.
getExpr();
178 LabelOffset = InsertByte - 2;
179 else if (InsertByte % 2)
194void M68kMCCodeEmitter::encodeFPSYSSelect(
const MCInst &
MI,
unsigned OpIdx,
195 unsigned InsertPos, APInt &
Value,
196 SmallVectorImpl<MCFixup> &Fixups,
197 const MCSubtargetInfo &STI)
const {
198 MCRegister FPSysReg =
MI.getOperand(
OpIdx).getReg();
214void M68kMCCodeEmitter::encodeInverseMoveMask(
215 const MCInst &
MI,
unsigned OpIdx,
unsigned InsertPos, APInt &
Value,
216 SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI)
const {
217 const MCOperand &
Op =
MI.getOperand(
OpIdx);
221void M68kMCCodeEmitter::encodeScale(
const MCInst &
MI,
unsigned OpIdx,
222 unsigned InsertPos, APInt &
Value,
223 SmallVectorImpl<MCFixup> &Fixups,
224 const MCSubtargetInfo &STI)
const {
225 const MCOperand &
Op =
MI.getOperand(
OpIdx);
226 int64_t ScaleImm =
Op.getImm();
228 Value.clearAllBits();
232void M68kMCCodeEmitter::encodeIndexSuppress(
const MCInst &
MI,
unsigned OpIdx,
233 unsigned InsertPos, APInt &
Value,
234 SmallVectorImpl<MCFixup> &Fixups,
235 const MCSubtargetInfo &STI)
const {
237 const MCOperand &
Op =
MI.getOperand(
OpIdx);
238 MCRegister IndexReg =
Op.getReg();
242void M68kMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
const MCOperand &
Op,
243 unsigned InsertPos, APInt &
Value,
244 SmallVectorImpl<MCFixup> &Fixups,
245 const MCSubtargetInfo &STI)
const {
248 MCRegister
Reg =
Op.getReg();
257 }
else if (
Op.isImm()) {
259 Value |=
static_cast<uint64_t
>(
Op.getImm());
260 }
else if (
Op.isExpr()) {
263 if (!
Op.getExpr()->evaluateAsAbsolute(Addr))
265 "can be placed here.");
266 Value |=
static_cast<uint64_t
>(Addr);
272void M68kMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
273 SmallVectorImpl<char> &CB,
274 SmallVectorImpl<MCFixup> &Fixups,
275 const MCSubtargetInfo &STI)
const {
277 <<
"(" <<
MI.getOpcode() <<
")\n");
281 APInt EncodedInst(16, 0U);
282 APInt Scratch(64, 0U);
283 getBinaryCodeForInstr(
MI, Fixups, EncodedInst, Scratch, STI);
285 unsigned InstSize = EncodedInst.getBitWidth();
286 for (
unsigned i = 0; i != InstSize; i += 16)
288 CB,
static_cast<uint16_t
>(EncodedInst.extractBitsAsZExtValue(16, i)),
294 return new M68kMCCodeEmitter(MCII, Ctx);
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind, bool PCRel=false)
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)
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.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
MCCodeEmitter - Generic instruction encoding interface.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCRegisterInfo * getRegisterInfo() const
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.
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Instances of this class represent operands of the MCInst class.
const MCExpr * getExpr() const
constexpr bool isValid() const
Generic base class for all target subtargets.
constexpr bool isValid() const
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)
value_t swapWord(value_t Val)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
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)
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
DWARFExpression::Operation Op
constexpr T reverseBits(T Val)
Reverse the bits in Val.
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