blob: efa9677194b081552d79ee63e434db8207a5f47d [file] [log] [blame]
Jim Grosbach568eeed2010-09-17 18:46:17 +00001//===-- ARM/ARMMCCodeEmitter.cpp - Convert ARM code to machine code -------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARMMCCodeEmitter class.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "arm-emitter"
15#include "ARM.h"
Jim Grosbach42fac8e2010-10-11 23:16:21 +000016#include "ARMAddressingModes.h"
Jim Grosbachd6d4b422010-10-07 22:12:50 +000017#include "ARMInstrInfo.h"
Jim Grosbach568eeed2010-09-17 18:46:17 +000018#include "llvm/MC/MCCodeEmitter.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Jim Grosbachd6d4b422010-10-07 22:12:50 +000021#include "llvm/ADT/Statistic.h"
Jim Grosbach568eeed2010-09-17 18:46:17 +000022#include "llvm/Support/raw_ostream.h"
23using namespace llvm;
24
Jim Grosbachd6d4b422010-10-07 22:12:50 +000025STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
26
Jim Grosbach568eeed2010-09-17 18:46:17 +000027namespace {
28class ARMMCCodeEmitter : public MCCodeEmitter {
29 ARMMCCodeEmitter(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
30 void operator=(const ARMMCCodeEmitter &); // DO NOT IMPLEMENT
31 const TargetMachine &TM;
32 const TargetInstrInfo &TII;
33 MCContext &Ctx;
34
35public:
36 ARMMCCodeEmitter(TargetMachine &tm, MCContext &ctx)
37 : TM(tm), TII(*TM.getInstrInfo()), Ctx(ctx) {
Jim Grosbach568eeed2010-09-17 18:46:17 +000038 }
39
40 ~ARMMCCodeEmitter() {}
41
Jim Grosbach0de6ab32010-10-12 17:11:26 +000042 unsigned getMachineSoImmOpValue(unsigned SoImm) const;
43
Jim Grosbach9af82ba2010-10-07 21:57:55 +000044 // getBinaryCodeForInstr - TableGen'erated function for getting the
45 // binary encoding for an instruction.
Jim Grosbach806e80e2010-11-03 23:52:49 +000046 unsigned getBinaryCodeForInstr(const MCInst &MI,
47 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach9af82ba2010-10-07 21:57:55 +000048
49 /// getMachineOpValue - Return binary encoding of operand. If the machine
50 /// operand requires relocation, record the relocation and return zero.
Jim Grosbach806e80e2010-11-03 23:52:49 +000051 unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO,
52 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach9af82ba2010-10-07 21:57:55 +000053
Bill Wendling92b5a2e2010-11-03 01:49:29 +000054 bool EncodeAddrModeOpValues(const MCInst &MI, unsigned OpIdx,
Jim Grosbach806e80e2010-11-03 23:52:49 +000055 unsigned &Reg, unsigned &Imm,
56 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendling92b5a2e2010-11-03 01:49:29 +000057
58 /// getAddrModeImm12OpValue - Return encoding info for 'reg +/- imm12'
59 /// operand.
Jim Grosbach806e80e2010-11-03 23:52:49 +000060 uint32_t getAddrModeImm12OpValue(const MCInst &MI, unsigned OpIdx,
61 SmallVectorImpl<MCFixup> &Fixups) const;
Bill Wendling92b5a2e2010-11-03 01:49:29 +000062
63 /// getAddrMode5OpValue - Return encoding info for 'reg +/- imm8' operand.
Jim Grosbach806e80e2010-11-03 23:52:49 +000064 uint32_t getAddrMode5OpValue(const MCInst &MI, unsigned OpIdx,
65 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach3e556122010-10-26 22:37:02 +000066
Jim Grosbach08bd5492010-10-12 23:00:24 +000067 /// getCCOutOpValue - Return encoding of the 's' bit.
Jim Grosbach806e80e2010-11-03 23:52:49 +000068 unsigned getCCOutOpValue(const MCInst &MI, unsigned Op,
69 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach08bd5492010-10-12 23:00:24 +000070 // The operand is either reg0 or CPSR. The 's' bit is encoded as '0' or
71 // '1' respectively.
72 return MI.getOperand(Op).getReg() == ARM::CPSR;
73 }
Jim Grosbachef324d72010-10-12 23:53:58 +000074
Jim Grosbach2a6a93d2010-10-12 23:18:08 +000075 /// getSOImmOpValue - Return an encoded 12-bit shifted-immediate value.
Jim Grosbach806e80e2010-11-03 23:52:49 +000076 unsigned getSOImmOpValue(const MCInst &MI, unsigned Op,
77 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach2a6a93d2010-10-12 23:18:08 +000078 unsigned SoImm = MI.getOperand(Op).getImm();
79 int SoImmVal = ARM_AM::getSOImmVal(SoImm);
80 assert(SoImmVal != -1 && "Not a valid so_imm value!");
81
82 // Encode rotate_imm.
83 unsigned Binary = (ARM_AM::getSOImmValRot((unsigned)SoImmVal) >> 1)
84 << ARMII::SoRotImmShift;
85
86 // Encode immed_8.
87 Binary |= ARM_AM::getSOImmValImm((unsigned)SoImmVal);
88 return Binary;
89 }
Jim Grosbach08bd5492010-10-12 23:00:24 +000090
Jim Grosbachef324d72010-10-12 23:53:58 +000091 /// getSORegOpValue - Return an encoded so_reg shifted register value.
Jim Grosbach806e80e2010-11-03 23:52:49 +000092 unsigned getSORegOpValue(const MCInst &MI, unsigned Op,
93 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbachef324d72010-10-12 23:53:58 +000094
Jim Grosbach806e80e2010-11-03 23:52:49 +000095 unsigned getRotImmOpValue(const MCInst &MI, unsigned Op,
96 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbachb35ad412010-10-13 19:56:10 +000097 switch (MI.getOperand(Op).getImm()) {
98 default: assert (0 && "Not a valid rot_imm value!");
99 case 0: return 0;
100 case 8: return 1;
101 case 16: return 2;
102 case 24: return 3;
103 }
104 }
105
Jim Grosbach806e80e2010-11-03 23:52:49 +0000106 unsigned getImmMinusOneOpValue(const MCInst &MI, unsigned Op,
107 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach8abe32a2010-10-15 17:15:16 +0000108 return MI.getOperand(Op).getImm() - 1;
109 }
Jim Grosbachd8a11c22010-10-29 23:21:03 +0000110
Jim Grosbach806e80e2010-11-03 23:52:49 +0000111 unsigned getNEONVcvtImm32OpValue(const MCInst &MI, unsigned Op,
112 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Anderson498ec202010-10-27 22:49:00 +0000113 return 64 - MI.getOperand(Op).getImm();
114 }
Jim Grosbach8abe32a2010-10-15 17:15:16 +0000115
Jim Grosbach806e80e2010-11-03 23:52:49 +0000116 unsigned getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
117 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach3fea191052010-10-21 22:03:21 +0000118
Jim Grosbach806e80e2010-11-03 23:52:49 +0000119 unsigned getRegisterListOpValue(const MCInst &MI, unsigned Op,
120 SmallVectorImpl<MCFixup> &Fixups) const;
121 unsigned getAddrMode6AddressOpValue(const MCInst &MI, unsigned Op,
122 SmallVectorImpl<MCFixup> &Fixups) const;
123 unsigned getAddrMode6OffsetOpValue(const MCInst &MI, unsigned Op,
124 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach6b5252d2010-10-30 00:37:59 +0000125
Jim Grosbach568eeed2010-09-17 18:46:17 +0000126 unsigned getNumFixupKinds() const {
127 assert(0 && "ARMMCCodeEmitter::getNumFixupKinds() not yet implemented.");
Michael J. Spencer895dda62010-09-18 17:54:37 +0000128 return 0;
Jim Grosbach568eeed2010-09-17 18:46:17 +0000129 }
130
131 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
132 static MCFixupKindInfo rtn;
133 assert(0 && "ARMMCCodeEmitter::getFixupKindInfo() not yet implemented.");
134 return rtn;
135 }
136
Jim Grosbach568eeed2010-09-17 18:46:17 +0000137 void EmitByte(unsigned char C, unsigned &CurByte, raw_ostream &OS) const {
138 OS << (char)C;
139 ++CurByte;
140 }
141
142 void EmitConstant(uint64_t Val, unsigned Size, unsigned &CurByte,
143 raw_ostream &OS) const {
144 // Output the constant in little endian byte order.
145 for (unsigned i = 0; i != Size; ++i) {
146 EmitByte(Val & 255, CurByte, OS);
147 Val >>= 8;
148 }
149 }
150
Jim Grosbach568eeed2010-09-17 18:46:17 +0000151 void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
152 SmallVectorImpl<MCFixup> &Fixups) const;
Jim Grosbach568eeed2010-09-17 18:46:17 +0000153};
154
155} // end anonymous namespace
156
Bill Wendling0800ce72010-11-02 22:53:11 +0000157MCCodeEmitter *llvm::createARMMCCodeEmitter(const Target &, TargetMachine &TM,
158 MCContext &Ctx) {
Jim Grosbach568eeed2010-09-17 18:46:17 +0000159 return new ARMMCCodeEmitter(TM, Ctx);
160}
161
Jim Grosbach56ac9072010-10-08 21:45:55 +0000162/// getMachineOpValue - Return binary encoding of operand. If the machine
163/// operand requires relocation, record the relocation and return zero.
Jim Grosbach806e80e2010-11-03 23:52:49 +0000164unsigned ARMMCCodeEmitter::
165getMachineOpValue(const MCInst &MI, const MCOperand &MO,
166 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendlingbbbdcd42010-10-14 02:33:26 +0000167 if (MO.isReg()) {
Bill Wendling0800ce72010-11-02 22:53:11 +0000168 unsigned Reg = MO.getReg();
169 unsigned RegNo = getARMRegisterNumbering(Reg);
Jim Grosbachd8a11c22010-10-29 23:21:03 +0000170
Owen Anderson90d4cf92010-10-21 20:49:13 +0000171 // Q registers are encodes as 2x their register number.
Bill Wendling0800ce72010-11-02 22:53:11 +0000172 switch (Reg) {
173 default:
174 return RegNo;
175 case ARM::Q0: case ARM::Q1: case ARM::Q2: case ARM::Q3:
176 case ARM::Q4: case ARM::Q5: case ARM::Q6: case ARM::Q7:
177 case ARM::Q8: case ARM::Q9: case ARM::Q10: case ARM::Q11:
178 case ARM::Q12: case ARM::Q13: case ARM::Q14: case ARM::Q15:
179 return 2 * RegNo;
Owen Anderson90d4cf92010-10-21 20:49:13 +0000180 }
Bill Wendlingbbbdcd42010-10-14 02:33:26 +0000181 } else if (MO.isImm()) {
Jim Grosbach56ac9072010-10-08 21:45:55 +0000182 return static_cast<unsigned>(MO.getImm());
Bill Wendlingbbbdcd42010-10-14 02:33:26 +0000183 } else if (MO.isFPImm()) {
184 return static_cast<unsigned>(APFloat(MO.getFPImm())
185 .bitcastToAPInt().getHiBits(32).getLimitedValue());
Jim Grosbach56ac9072010-10-08 21:45:55 +0000186 }
Bill Wendling0800ce72010-11-02 22:53:11 +0000187
188#ifndef NDEBUG
189 errs() << MO;
190#endif
191 llvm_unreachable(0);
Jim Grosbach56ac9072010-10-08 21:45:55 +0000192 return 0;
193}
194
Bill Wendling5df0e0a2010-11-02 22:31:46 +0000195/// getAddrModeImmOpValue - Return encoding info for 'reg +/- imm' operand.
Jim Grosbach806e80e2010-11-03 23:52:49 +0000196bool ARMMCCodeEmitter::
197EncodeAddrModeOpValues(const MCInst &MI, unsigned OpIdx, unsigned &Reg,
198 unsigned &Imm, SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach3e556122010-10-26 22:37:02 +0000199 const MCOperand &MO = MI.getOperand(OpIdx);
200 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
Jim Grosbach9af3d1c2010-11-01 23:45:50 +0000201
202 // If The first operand isn't a register, we have a label reference.
203 if (!MO.isReg()) {
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000204 Reg = ARM::PC; // Rn is PC.
205 Imm = 0;
Jim Grosbach9af3d1c2010-11-01 23:45:50 +0000206 // FIXME: Add a fixup referencing the label.
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000207 return true;
Jim Grosbach9af3d1c2010-11-01 23:45:50 +0000208 }
209
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000210 Reg = getARMRegisterNumbering(MO.getReg());
211
212 int32_t SImm = MO1.getImm();
213 bool isAdd = true;
Bill Wendling5df0e0a2010-11-02 22:31:46 +0000214
Jim Grosbachab682a22010-10-28 18:34:10 +0000215 // Special value for #-0
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000216 if (SImm == INT32_MIN)
217 SImm = 0;
Bill Wendling5df0e0a2010-11-02 22:31:46 +0000218
Jim Grosbachab682a22010-10-28 18:34:10 +0000219 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000220 if (SImm < 0) {
221 SImm = -SImm;
222 isAdd = false;
223 }
Bill Wendling5df0e0a2010-11-02 22:31:46 +0000224
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000225 Imm = SImm;
226 return isAdd;
227}
228
229/// getAddrModeImm12OpValue - Return encoding info for 'reg +/- imm12' operand.
Jim Grosbach806e80e2010-11-03 23:52:49 +0000230uint32_t ARMMCCodeEmitter::
231getAddrModeImm12OpValue(const MCInst &MI, unsigned OpIdx,
232 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000233 // {17-13} = reg
234 // {12} = (U)nsigned (add == '1', sub == '0')
235 // {11-0} = imm12
236 unsigned Reg, Imm12;
Jim Grosbach806e80e2010-11-03 23:52:49 +0000237 bool isAdd = EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm12, Fixups);
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000238
239 if (Reg == ARM::PC)
240 return ARM::PC << 13; // Rn is PC;
241
242 uint32_t Binary = Imm12 & 0xfff;
243 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
Jim Grosbachab682a22010-10-28 18:34:10 +0000244 if (isAdd)
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000245 Binary |= (1 << 12);
246 Binary |= (Reg << 13);
247 return Binary;
248}
249
250/// getAddrMode5OpValue - Return encoding info for 'reg +/- imm12' operand.
Jim Grosbach806e80e2010-11-03 23:52:49 +0000251uint32_t ARMMCCodeEmitter::
252getAddrMode5OpValue(const MCInst &MI, unsigned OpIdx,
253 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000254 // {12-9} = reg
255 // {8} = (U)nsigned (add == '1', sub == '0')
256 // {7-0} = imm8
257 unsigned Reg, Imm8;
Jim Grosbach806e80e2010-11-03 23:52:49 +0000258 EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm8, Fixups);
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000259
260 if (Reg == ARM::PC)
Bill Wendlingcdbbec42010-11-03 04:57:44 +0000261 return ARM::PC << 9; // Rn is PC;
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000262
263 uint32_t Binary = ARM_AM::getAM5Offset(Imm8);
264 // Immediate is always encoded as positive. The 'U' bit controls add vs sub.
265 if (ARM_AM::getAM5Op(Imm8) == ARM_AM::add)
266 Binary |= (1 << 8);
267 Binary |= (Reg << 9);
Jim Grosbach3e556122010-10-26 22:37:02 +0000268 return Binary;
269}
270
Jim Grosbach806e80e2010-11-03 23:52:49 +0000271unsigned ARMMCCodeEmitter::
272getSORegOpValue(const MCInst &MI, unsigned OpIdx,
273 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling0800ce72010-11-02 22:53:11 +0000274 // Sub-operands are [reg, reg, imm]. The first register is Rm, the reg to be
275 // shifted. The second is either Rs, the amount to shift by, or reg0 in which
276 // case the imm contains the amount to shift by.
Jim Grosbach35b2de02010-11-03 22:03:20 +0000277 //
Jim Grosbachef324d72010-10-12 23:53:58 +0000278 // {3-0} = Rm.
Bill Wendling0800ce72010-11-02 22:53:11 +0000279 // {4} = 1 if reg shift, 0 if imm shift
Jim Grosbachef324d72010-10-12 23:53:58 +0000280 // {6-5} = type
281 // If reg shift:
Jim Grosbachef324d72010-10-12 23:53:58 +0000282 // {11-8} = Rs
Bill Wendling0800ce72010-11-02 22:53:11 +0000283 // {7} = 0
Jim Grosbachef324d72010-10-12 23:53:58 +0000284 // else (imm shift)
285 // {11-7} = imm
286
287 const MCOperand &MO = MI.getOperand(OpIdx);
288 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
289 const MCOperand &MO2 = MI.getOperand(OpIdx + 2);
290 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(MO2.getImm());
291
292 // Encode Rm.
293 unsigned Binary = getARMRegisterNumbering(MO.getReg());
294
295 // Encode the shift opcode.
296 unsigned SBits = 0;
297 unsigned Rs = MO1.getReg();
298 if (Rs) {
299 // Set shift operand (bit[7:4]).
300 // LSL - 0001
301 // LSR - 0011
302 // ASR - 0101
303 // ROR - 0111
304 // RRX - 0110 and bit[11:8] clear.
305 switch (SOpc) {
306 default: llvm_unreachable("Unknown shift opc!");
307 case ARM_AM::lsl: SBits = 0x1; break;
308 case ARM_AM::lsr: SBits = 0x3; break;
309 case ARM_AM::asr: SBits = 0x5; break;
310 case ARM_AM::ror: SBits = 0x7; break;
311 case ARM_AM::rrx: SBits = 0x6; break;
312 }
313 } else {
314 // Set shift operand (bit[6:4]).
315 // LSL - 000
316 // LSR - 010
317 // ASR - 100
318 // ROR - 110
319 switch (SOpc) {
320 default: llvm_unreachable("Unknown shift opc!");
321 case ARM_AM::lsl: SBits = 0x0; break;
322 case ARM_AM::lsr: SBits = 0x2; break;
323 case ARM_AM::asr: SBits = 0x4; break;
324 case ARM_AM::ror: SBits = 0x6; break;
325 }
326 }
Bill Wendling0800ce72010-11-02 22:53:11 +0000327
Jim Grosbachef324d72010-10-12 23:53:58 +0000328 Binary |= SBits << 4;
329 if (SOpc == ARM_AM::rrx)
330 return Binary;
331
332 // Encode the shift operation Rs or shift_imm (except rrx).
333 if (Rs) {
334 // Encode Rs bit[11:8].
335 assert(ARM_AM::getSORegOffset(MO2.getImm()) == 0);
336 return Binary | (getARMRegisterNumbering(Rs) << ARMII::RegRsShift);
337 }
338
339 // Encode shift_imm bit[11:7].
340 return Binary | ARM_AM::getSORegOffset(MO2.getImm()) << 7;
341}
342
Jim Grosbach806e80e2010-11-03 23:52:49 +0000343unsigned ARMMCCodeEmitter::
344getBitfieldInvertedMaskOpValue(const MCInst &MI, unsigned Op,
345 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach3fea191052010-10-21 22:03:21 +0000346 // 10 bits. lower 5 bits are are the lsb of the mask, high five bits are the
347 // msb of the mask.
348 const MCOperand &MO = MI.getOperand(Op);
349 uint32_t v = ~MO.getImm();
350 uint32_t lsb = CountTrailingZeros_32(v);
351 uint32_t msb = (32 - CountLeadingZeros_32 (v)) - 1;
352 assert (v != 0 && lsb < 32 && msb < 32 && "Illegal bitfield mask!");
353 return lsb | (msb << 5);
354}
355
Jim Grosbach806e80e2010-11-03 23:52:49 +0000356unsigned ARMMCCodeEmitter::
357getRegisterListOpValue(const MCInst &MI, unsigned Op,
358 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbach6b5252d2010-10-30 00:37:59 +0000359 // Convert a list of GPRs into a bitfield (R0 -> bit 0). For each
360 // register in the list, set the corresponding bit.
361 unsigned Binary = 0;
Jim Grosbach4b5236c2010-10-30 01:40:16 +0000362 for (unsigned i = Op, e = MI.getNumOperands(); i < e; ++i) {
Jim Grosbach6b5252d2010-10-30 00:37:59 +0000363 unsigned regno = getARMRegisterNumbering(MI.getOperand(i).getReg());
364 Binary |= 1 << regno;
365 }
366 return Binary;
367}
368
Jim Grosbach806e80e2010-11-03 23:52:49 +0000369unsigned ARMMCCodeEmitter::
370getAddrMode6AddressOpValue(const MCInst &MI, unsigned Op,
371 SmallVectorImpl<MCFixup> &Fixups) const {
Owen Andersond9aa7d32010-11-02 00:05:05 +0000372 const MCOperand &Reg = MI.getOperand(Op);
Bill Wendling0800ce72010-11-02 22:53:11 +0000373 const MCOperand &Imm = MI.getOperand(Op + 1);
Jim Grosbach35b2de02010-11-03 22:03:20 +0000374
Owen Andersond9aa7d32010-11-02 00:05:05 +0000375 unsigned RegNo = getARMRegisterNumbering(Reg.getReg());
Bill Wendling0800ce72010-11-02 22:53:11 +0000376 unsigned Align = 0;
377
378 switch (Imm.getImm()) {
379 default: break;
380 case 2:
381 case 4:
382 case 8: Align = 0x01; break;
383 case 16: Align = 0x02; break;
384 case 32: Align = 0x03; break;
Owen Andersond9aa7d32010-11-02 00:05:05 +0000385 }
Bill Wendling0800ce72010-11-02 22:53:11 +0000386
Owen Andersond9aa7d32010-11-02 00:05:05 +0000387 return RegNo | (Align << 4);
388}
389
Jim Grosbach806e80e2010-11-03 23:52:49 +0000390unsigned ARMMCCodeEmitter::
391getAddrMode6OffsetOpValue(const MCInst &MI, unsigned Op,
392 SmallVectorImpl<MCFixup> &Fixups) const {
Bill Wendling0800ce72010-11-02 22:53:11 +0000393 const MCOperand &MO = MI.getOperand(Op);
394 if (MO.getReg() == 0) return 0x0D;
395 return MO.getReg();
Owen Andersoncf667be2010-11-02 01:24:55 +0000396}
397
Jim Grosbach568eeed2010-09-17 18:46:17 +0000398void ARMMCCodeEmitter::
399EncodeInstruction(const MCInst &MI, raw_ostream &OS,
Jim Grosbach806e80e2010-11-03 23:52:49 +0000400 SmallVectorImpl<MCFixup> &Fixups) const {
Jim Grosbachd6d4b422010-10-07 22:12:50 +0000401 // Pseudo instructions don't get encoded.
Bill Wendling7292e0a2010-11-02 22:44:12 +0000402 const TargetInstrDesc &Desc = TII.get(MI.getOpcode());
403 if ((Desc.TSFlags & ARMII::FormMask) == ARMII::Pseudo)
Jim Grosbachd6d4b422010-10-07 22:12:50 +0000404 return;
405
Bill Wendling7292e0a2010-11-02 22:44:12 +0000406 // Keep track of the current byte being emitted.
407 unsigned CurByte = 0;
Jim Grosbach806e80e2010-11-03 23:52:49 +0000408 EmitConstant(getBinaryCodeForInstr(MI, Fixups), 4, CurByte, OS);
Bill Wendling7292e0a2010-11-02 22:44:12 +0000409 ++MCNumEmitted; // Keep track of the # of mi's emitted.
Jim Grosbach568eeed2010-09-17 18:46:17 +0000410}
Jim Grosbach9af82ba2010-10-07 21:57:55 +0000411
Jim Grosbach806e80e2010-11-03 23:52:49 +0000412#include "ARMGenMCCodeEmitter.inc"