26 #define DEBUG_TYPE "mccodeemitter"
30 BPFMCCodeEmitter(
const BPFMCCodeEmitter &) =
delete;
31 void operator=(
const BPFMCCodeEmitter &) =
delete;
37 : MRI(mri), IsLittleEndian(IsLittleEndian) {}
39 ~BPFMCCodeEmitter() {}
43 uint64_t getBinaryCodeForInstr(
const MCInst &
MI,
53 uint64_t getMemoryOpValue(
const MCInst &MI,
unsigned Op,
66 return new BPFMCCodeEmitter(MRI,
true);
72 return new BPFMCCodeEmitter(MRI,
false);
75 unsigned BPFMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
80 return MRI.getEncodingValue(MO.
getReg());
82 return static_cast<unsigned>(MO.
getImm());
104 return (Val & 0x0F) << 4 | (Val & 0xF0) >> 4;
114 if (Opcode == BPF::LD_imm64 || Opcode == BPF::LD_pseudo) {
115 uint64_t
Value = getBinaryCodeForInstr(MI, Fixups, STI);
116 LE.write<uint8_t>(Value >> 56);
118 LE.write<uint8_t>((Value >> 48) & 0xff);
120 LE.write<uint8_t>(
SwapBits((Value >> 48) & 0xff));
121 LE.write<uint16_t>(0);
123 LE.write<uint32_t>(Value & 0xffffFFFF);
125 BE.write<uint32_t>(Value & 0xffffFFFF);
128 uint64_t Imm = MO.
isImm() ? MO.getImm() : 0;
129 LE.write<uint8_t>(0);
130 LE.write<uint8_t>(0);
131 LE.write<uint16_t>(0);
133 LE.write<uint32_t>(Imm >> 32);
135 BE.write<uint32_t>(Imm >> 32);
138 uint64_t Value = getBinaryCodeForInstr(MI, Fixups, STI);
139 LE.write<uint8_t>(Value >> 56);
140 if (IsLittleEndian) {
141 LE.write<uint8_t>((Value >> 48) & 0xff);
142 LE.write<uint16_t>((Value >> 32) & 0xffff);
143 LE.write<uint32_t>(Value & 0xffffFFFF);
145 LE.write<uint8_t>(
SwapBits((Value >> 48) & 0xff));
146 BE.write<uint16_t>((Value >> 32) & 0xffff);
147 BE.write<uint32_t>(Value & 0xffffFFFF);
153 uint64_t BPFMCCodeEmitter::getMemoryOpValue(
const MCInst &MI,
unsigned Op,
158 assert(Op1.
isReg() &&
"First operand is not register.");
159 Encoding = MRI.getEncodingValue(Op1.
getReg());
162 assert(Op2.
isImm() &&
"Second operand is not immediate.");
163 Encoding |= Op2.
getImm() & 0xffff;
167 #include "BPFGenMCCodeEmitter.inc"
void push_back(const T &Elt)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
A four-byte section relative fixup.
Context object for machine code objects.
MCCodeEmitter * createBPFbeMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
unsigned getReg() const
Returns the register number.
Instances of this class represent a single low-level machine instruction.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MCExpr * getExpr() const
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
static uint8_t SwapBits(uint8_t Val)
A two-byte pc relative fixup.
unsigned getOpcode() const
Adapter to write values to a stream in a particular byte order.
A eight-byte section relative fixup.
MCSubtargetInfo - Generic base class for all target subtargets.
References to labels and assigned expressions.
LLVM Value Representation.
MCCodeEmitter * createBPFMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
This class implements an extremely fast bulk output stream that can only output to a stream...
Instances of this class represent operands of the MCInst class.
const MCOperand & getOperand(unsigned i) const