blob: 8f3bd6dffe0abeb5453fcdfd5f9d152042a97fa7 [file] [log] [blame]
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
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
Evan Cheng94b95502011-07-26 00:24:13 +000010#include "MCTargetDesc/ARMBaseInfo.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMMCExpr.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000013#include "llvm/MC/MCParser/MCAsmLexer.h"
14#include "llvm/MC/MCParser/MCAsmParser.h"
15#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Rafael Espindola64695402011-05-16 16:17:21 +000016#include "llvm/MC/MCAsmInfo.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000017#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000018#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCInst.h"
Evan Cheng78011362011-08-23 20:15:21 +000021#include "llvm/MC/MCInstrDesc.h"
Evan Cheng94b95502011-07-26 00:24:13 +000022#include "llvm/MC/MCRegisterInfo.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000023#include "llvm/MC/MCSubtargetInfo.h"
Evan Cheng94b95502011-07-26 00:24:13 +000024#include "llvm/MC/MCTargetAsmParser.h"
Jim Grosbach89df9962011-08-26 21:43:41 +000025#include "llvm/Support/MathExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000027#include "llvm/Support/TargetRegistry.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000028#include "llvm/Support/raw_ostream.h"
Jim Grosbach11e03e72011-08-22 18:50:36 +000029#include "llvm/ADT/BitVector.h"
Benjamin Kramer75ca4b92011-07-08 21:06:23 +000030#include "llvm/ADT/OwningPtr.h"
Evan Cheng94b95502011-07-26 00:24:13 +000031#include "llvm/ADT/STLExtras.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000032#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000033#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000034#include "llvm/ADT/Twine.h"
Evan Chengebdeeab2011-07-08 01:53:10 +000035
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000036using namespace llvm;
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Jim Grosbach7636bf62011-12-02 00:35:16 +000042enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbach98b05a52011-11-30 01:09:44 +000043
Evan Cheng94b95502011-07-26 00:24:13 +000044class ARMAsmParser : public MCTargetAsmParser {
Evan Chengffc0e732011-07-09 05:47:46 +000045 MCSubtargetInfo &STI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &Parser;
Jim Grosbach28f08c92012-03-05 19:33:30 +000047 const MCRegisterInfo *MRI;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000048
Jim Grosbacha39cda72011-12-14 02:16:11 +000049 // Map of register aliases registers via the .req directive.
50 StringMap<unsigned> RegisterReqs;
51
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000052 struct {
53 ARMCC::CondCodes Cond; // Condition for IT block.
54 unsigned Mask:4; // Condition mask for instructions.
55 // Starting at first 1 (from lsb).
56 // '1' condition as indicated in IT.
57 // '0' inverse of condition (else).
58 // Count of instructions in IT block is
59 // 4 - trailingzeroes(mask)
60
61 bool FirstCond; // Explicit flag for when we're parsing the
62 // First instruction in the IT block. It's
63 // implied in the mask, so needs special
64 // handling.
65
66 unsigned CurPosition; // Current position in parsing of IT
67 // block. In range [0,3]. Initialized
68 // according to count of instructions in block.
69 // ~0U if no active IT block.
70 } ITState;
71 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha1109882011-09-02 23:22:08 +000072 void forwardITPosition() {
73 if (!inITBlock()) return;
74 // Move to the next instruction in the IT block, if there is one. If not,
75 // mark the block as done.
76 unsigned TZ = CountTrailingZeros_32(ITState.Mask);
77 if (++ITState.CurPosition == 5 - TZ)
78 ITState.CurPosition = ~0U; // Done with the IT block after this.
79 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +000080
81
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000082 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000083 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
84
85 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000086 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
87
Jim Grosbach1355cf12011-07-26 17:10:22 +000088 int tryParseRegister();
89 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d87ec22011-07-26 20:41:24 +000090 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000091 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +000092 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +000093 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
94 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbach7ce05792011-08-03 23:50:40 +000095 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
96 unsigned &ShiftAmount);
Jim Grosbach1355cf12011-07-26 17:10:22 +000097 bool parseDirectiveWord(unsigned Size, SMLoc L);
98 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach9a70df92011-12-07 18:04:19 +000099 bool parseDirectiveARM(SMLoc L);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000100 bool parseDirectiveThumbFunc(SMLoc L);
101 bool parseDirectiveCode(SMLoc L);
102 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbacha39cda72011-12-14 02:16:11 +0000103 bool parseDirectiveReq(StringRef Name, SMLoc L);
104 bool parseDirectiveUnreq(SMLoc L);
Jason W Kimd7c9e082011-12-20 17:38:12 +0000105 bool parseDirectiveArch(SMLoc L);
106 bool parseDirectiveEabiAttr(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +0000107
Jim Grosbach1355cf12011-07-26 17:10:22 +0000108 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach89df9962011-08-26 21:43:41 +0000109 bool &CarrySetting, unsigned &ProcessorIMod,
110 StringRef &ITMask);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000111 void getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +0000112 bool &CanAcceptPredicationCode);
Jim Grosbach16c74252010-10-29 14:46:02 +0000113
Evan Chengebdeeab2011-07-08 01:53:10 +0000114 bool isThumb() const {
115 // FIXME: Can tablegen auto-generate this?
Evan Chengffc0e732011-07-09 05:47:46 +0000116 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000117 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000118 bool isThumbOne() const {
Evan Chengffc0e732011-07-09 05:47:46 +0000119 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Chengebdeeab2011-07-08 01:53:10 +0000120 }
Jim Grosbach47a0d522011-08-16 20:45:50 +0000121 bool isThumbTwo() const {
122 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
123 }
Jim Grosbach194bd892011-08-16 22:20:01 +0000124 bool hasV6Ops() const {
125 return STI.getFeatureBits() & ARM::HasV6Ops;
126 }
James Molloyacad68d2011-09-28 14:21:38 +0000127 bool hasV7Ops() const {
128 return STI.getFeatureBits() & ARM::HasV7Ops;
129 }
Evan Cheng32869202011-07-08 22:36:29 +0000130 void SwitchMode() {
Evan Chengffc0e732011-07-09 05:47:46 +0000131 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
132 setAvailableFeatures(FB);
Evan Cheng32869202011-07-08 22:36:29 +0000133 }
James Molloyacad68d2011-09-28 14:21:38 +0000134 bool isMClass() const {
135 return STI.getFeatureBits() & ARM::FeatureMClass;
136 }
Evan Chengebdeeab2011-07-08 01:53:10 +0000137
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000138 /// @name Auto-generated Match Functions
139 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000140
Chris Lattner0692ee62010-09-06 19:11:01 +0000141#define GET_ASSEMBLER_HEADER
142#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000143
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000144 /// }
145
Jim Grosbach89df9962011-08-26 21:43:41 +0000146 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000147 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000148 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000149 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbachf922c472011-02-12 01:34:40 +0000150 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000151 OperandMatchResultTy parseCoprocOptionOperand(
152 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000153 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000154 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000155 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000156 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach43904292011-07-25 20:14:50 +0000157 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopes8bba1a52011-02-18 19:49:06 +0000158 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachf6c05252011-07-21 17:23:04 +0000159 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
160 StringRef Op, int Low, int High);
161 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
162 return parsePKHImm(O, "lsl", 0, 31);
163 }
164 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
165 return parsePKHImm(O, "asr", 1, 32);
166 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000167 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach580f4a92011-07-25 22:20:28 +0000168 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000169 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000170 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000171 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach251bf252011-08-10 21:56:18 +0000172 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach9d390362011-10-03 23:38:36 +0000173 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach862019c2011-10-18 23:02:30 +0000174 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach7636bf62011-12-02 00:35:16 +0000175 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000176
177 // Asm Match Converter Methods
Jim Grosbacha77295d2011-09-08 22:07:06 +0000178 bool cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
179 const SmallVectorImpl<MCParsedAsmOperand*> &);
180 bool cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
181 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheeec0252011-09-08 00:39:19 +0000182 bool cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
183 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachee2c2a42011-09-16 21:55:56 +0000184 bool cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
185 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000186 bool cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000187 const SmallVectorImpl<MCParsedAsmOperand*> &);
Owen Anderson9ab0f252011-08-26 20:43:14 +0000188 bool cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
189 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach548340c2011-08-11 19:22:40 +0000190 bool cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
191 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000192 bool cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000193 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +0000194 bool cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
195 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach7ce05792011-08-03 23:50:40 +0000196 bool cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
197 const SmallVectorImpl<MCParsedAsmOperand*> &);
198 bool cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
199 const SmallVectorImpl<MCParsedAsmOperand*> &);
200 bool cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
201 const SmallVectorImpl<MCParsedAsmOperand*> &);
202 bool cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
203 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000204 bool cvtLdrdPre(MCInst &Inst, unsigned Opcode,
205 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach14605d12011-08-11 20:28:23 +0000206 bool cvtStrdPre(MCInst &Inst, unsigned Opcode,
207 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach623a4542011-08-10 22:42:16 +0000208 bool cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
209 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +0000210 bool cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
211 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach12431322011-10-24 22:16:58 +0000212 bool cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
213 const SmallVectorImpl<MCParsedAsmOperand*> &);
214 bool cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
215 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach4334e032011-10-31 21:50:31 +0000216 bool cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
217 const SmallVectorImpl<MCParsedAsmOperand*> &);
218 bool cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
219 const SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach189610f2011-07-26 18:25:39 +0000220
221 bool validateInstruction(MCInst &Inst,
222 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach83ec8772011-11-10 23:42:14 +0000223 bool processInstruction(MCInst &Inst,
Jim Grosbachf8fce712011-08-11 17:35:48 +0000224 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachd54b4e62011-08-16 21:12:37 +0000225 bool shouldOmitCCOutOperand(StringRef Mnemonic,
226 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach189610f2011-07-26 18:25:39 +0000227
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000228public:
Jim Grosbach47a0d522011-08-16 20:45:50 +0000229 enum ARMMatchResultTy {
Jim Grosbach194bd892011-08-16 22:20:01 +0000230 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000231 Match_RequiresNotITBlock,
Jim Grosbach194bd892011-08-16 22:20:01 +0000232 Match_RequiresV6,
233 Match_RequiresThumb2
Jim Grosbach47a0d522011-08-16 20:45:50 +0000234 };
235
Evan Chengffc0e732011-07-09 05:47:46 +0000236 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
Evan Cheng94b95502011-07-26 00:24:13 +0000237 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
Evan Chengebdeeab2011-07-08 01:53:10 +0000238 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng32869202011-07-08 22:36:29 +0000239
Jim Grosbach28f08c92012-03-05 19:33:30 +0000240 // Cache the MCRegisterInfo.
241 MRI = &getContext().getRegisterInfo();
242
Evan Chengebdeeab2011-07-08 01:53:10 +0000243 // Initialize the set of available features.
Evan Chengffc0e732011-07-09 05:47:46 +0000244 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +0000245
246 // Not in an ITBlock to start with.
247 ITState.CurPosition = ~0U;
Evan Chengebdeeab2011-07-08 01:53:10 +0000248 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000249
Jim Grosbach1355cf12011-07-26 17:10:22 +0000250 // Implementation of the MCTargetAsmParser interface:
251 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
252 bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Jim Grosbach189610f2011-07-26 18:25:39 +0000253 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbach1355cf12011-07-26 17:10:22 +0000254 bool ParseDirective(AsmToken DirectiveID);
255
Jim Grosbach47a0d522011-08-16 20:45:50 +0000256 unsigned checkTargetMatchPredicate(MCInst &Inst);
257
Jim Grosbach1355cf12011-07-26 17:10:22 +0000258 bool MatchAndEmitInstruction(SMLoc IDLoc,
259 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
260 MCStreamer &Out);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000261};
Jim Grosbach16c74252010-10-29 14:46:02 +0000262} // end anonymous namespace
263
Chris Lattner3a697562010-10-28 17:20:03 +0000264namespace {
265
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000266/// ARMOperand - Instances of this class represent a parsed ARM machine
267/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000268class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000269 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000270 k_CondCode,
271 k_CCOut,
272 k_ITCondMask,
273 k_CoprocNum,
274 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000275 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000276 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000277 k_MemBarrierOpt,
278 k_Memory,
279 k_PostIndexRegister,
280 k_MSRMask,
281 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000282 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000283 k_Register,
284 k_RegisterList,
285 k_DPRRegisterList,
286 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000287 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000288 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000289 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000290 k_ShiftedRegister,
291 k_ShiftedImmediate,
292 k_ShifterImmediate,
293 k_RotateImmediate,
294 k_BitfieldDescriptor,
295 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000296 } Kind;
297
Sean Callanan76264762010-04-02 22:27:05 +0000298 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000299 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000300
301 union {
302 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000303 ARMCC::CondCodes Val;
304 } CC;
305
306 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000307 unsigned Val;
308 } Cop;
309
310 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000311 unsigned Val;
312 } CoprocOption;
313
314 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000315 unsigned Mask:4;
316 } ITMask;
317
318 struct {
319 ARM_MB::MemBOpt Val;
320 } MBOpt;
321
322 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000323 ARM_PROC::IFlags Val;
324 } IFlags;
325
326 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000327 unsigned Val;
328 } MMask;
329
330 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000331 const char *Data;
332 unsigned Length;
333 } Tok;
334
335 struct {
336 unsigned RegNum;
337 } Reg;
338
Jim Grosbach862019c2011-10-18 23:02:30 +0000339 // A vector register list is a sequential list of 1 to 4 registers.
340 struct {
341 unsigned RegNum;
342 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000343 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000344 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000345 } VectorList;
346
Bill Wendling8155e5b2010-11-06 22:19:43 +0000347 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000348 unsigned Val;
349 } VectorIndex;
350
351 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000352 const MCExpr *Val;
353 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000354
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000355 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000356 struct {
357 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000358 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
359 // was specified.
360 const MCConstantExpr *OffsetImm; // Offset immediate value
361 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
362 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000363 unsigned ShiftImm; // shift for OffsetReg.
364 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000365 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000366 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000367 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000368
369 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000370 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000371 bool isAdd;
372 ARM_AM::ShiftOpc ShiftTy;
373 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000374 } PostIdxReg;
375
376 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000377 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000378 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000379 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000380 struct {
381 ARM_AM::ShiftOpc ShiftTy;
382 unsigned SrcReg;
383 unsigned ShiftReg;
384 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000385 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000386 struct {
387 ARM_AM::ShiftOpc ShiftTy;
388 unsigned SrcReg;
389 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000390 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000391 struct {
392 unsigned Imm;
393 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000394 struct {
395 unsigned LSB;
396 unsigned Width;
397 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000398 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000399
Bill Wendling146018f2010-11-06 21:42:12 +0000400 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
401public:
Sean Callanan76264762010-04-02 22:27:05 +0000402 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
403 Kind = o.Kind;
404 StartLoc = o.StartLoc;
405 EndLoc = o.EndLoc;
406 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000407 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000408 CC = o.CC;
409 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000410 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000411 ITMask = o.ITMask;
412 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000413 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000414 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000415 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000416 case k_CCOut:
417 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000418 Reg = o.Reg;
419 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000420 case k_RegisterList:
421 case k_DPRRegisterList:
422 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000423 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000424 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000425 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000426 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000427 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000428 VectorList = o.VectorList;
429 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000430 case k_CoprocNum:
431 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000432 Cop = o.Cop;
433 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000434 case k_CoprocOption:
435 CoprocOption = o.CoprocOption;
436 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000437 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000438 Imm = o.Imm;
439 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000440 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000441 MBOpt = o.MBOpt;
442 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000443 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000444 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000445 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000446 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000447 PostIdxReg = o.PostIdxReg;
448 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000449 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000450 MMask = o.MMask;
451 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000452 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000453 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000454 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000455 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000456 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000457 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000458 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000459 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000460 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000461 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000462 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000463 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000464 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000465 RotImm = o.RotImm;
466 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000467 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000468 Bitfield = o.Bitfield;
469 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000470 case k_VectorIndex:
471 VectorIndex = o.VectorIndex;
472 break;
Sean Callanan76264762010-04-02 22:27:05 +0000473 }
474 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000475
Sean Callanan76264762010-04-02 22:27:05 +0000476 /// getStartLoc - Get the location of the first token of this operand.
477 SMLoc getStartLoc() const { return StartLoc; }
478 /// getEndLoc - Get the location of the last token of this operand.
479 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000480
Daniel Dunbar8462b302010-08-11 06:36:53 +0000481 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000482 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000483 return CC.Val;
484 }
485
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000486 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000487 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000488 return Cop.Val;
489 }
490
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000491 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000492 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000493 return StringRef(Tok.Data, Tok.Length);
494 }
495
496 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000497 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000498 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000499 }
500
Bill Wendling5fa22a12010-11-09 23:28:44 +0000501 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000502 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
503 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000504 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000505 }
506
Kevin Enderbycfe07242009-10-13 22:19:02 +0000507 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000508 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000509 return Imm.Val;
510 }
511
Jim Grosbach460a9052011-10-07 23:56:00 +0000512 unsigned getVectorIndex() const {
513 assert(Kind == k_VectorIndex && "Invalid access!");
514 return VectorIndex.Val;
515 }
516
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000517 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000518 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000519 return MBOpt.Val;
520 }
521
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000522 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000523 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000524 return IFlags.Val;
525 }
526
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000527 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000528 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000529 return MMask.Val;
530 }
531
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000532 bool isCoprocNum() const { return Kind == k_CoprocNum; }
533 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000534 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000535 bool isCondCode() const { return Kind == k_CondCode; }
536 bool isCCOut() const { return Kind == k_CCOut; }
537 bool isITMask() const { return Kind == k_ITCondMask; }
538 bool isITCondCode() const { return Kind == k_CondCode; }
539 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000540 bool isFPImm() const {
541 if (!isImm()) return false;
542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
543 if (!CE) return false;
544 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
545 return Val != -1;
546 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000547 bool isFBits16() const {
548 if (!isImm()) return false;
549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
550 if (!CE) return false;
551 int64_t Value = CE->getValue();
552 return Value >= 0 && Value <= 16;
553 }
554 bool isFBits32() const {
555 if (!isImm()) return false;
556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
557 if (!CE) return false;
558 int64_t Value = CE->getValue();
559 return Value >= 1 && Value <= 32;
560 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000561 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000562 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000563 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
564 if (!CE) return false;
565 int64_t Value = CE->getValue();
566 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
567 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000568 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000569 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
571 if (!CE) return false;
572 int64_t Value = CE->getValue();
573 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
574 }
575 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000576 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000577 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
578 if (!CE) return false;
579 int64_t Value = CE->getValue();
580 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
581 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000582 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000583 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000584 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
585 if (!CE) return false;
586 int64_t Value = CE->getValue();
587 return Value >= 0 && Value < 256;
588 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000589 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000590 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000591 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
592 if (!CE) return false;
593 int64_t Value = CE->getValue();
594 return Value >= 0 && Value < 2;
595 }
596 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000597 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
599 if (!CE) return false;
600 int64_t Value = CE->getValue();
601 return Value >= 0 && Value < 4;
602 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000603 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000604 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000605 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
606 if (!CE) return false;
607 int64_t Value = CE->getValue();
608 return Value >= 0 && Value < 8;
609 }
610 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000611 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000612 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
613 if (!CE) return false;
614 int64_t Value = CE->getValue();
615 return Value >= 0 && Value < 16;
616 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000617 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000618 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000619 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
620 if (!CE) return false;
621 int64_t Value = CE->getValue();
622 return Value >= 0 && Value < 32;
623 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000624 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000625 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
627 if (!CE) return false;
628 int64_t Value = CE->getValue();
629 return Value >= 0 && Value < 64;
630 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000631 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000632 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000633 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
634 if (!CE) return false;
635 int64_t Value = CE->getValue();
636 return Value == 8;
637 }
638 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000639 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
641 if (!CE) return false;
642 int64_t Value = CE->getValue();
643 return Value == 16;
644 }
645 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000646 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000647 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
648 if (!CE) return false;
649 int64_t Value = CE->getValue();
650 return Value == 32;
651 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000652 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000653 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000654 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
655 if (!CE) return false;
656 int64_t Value = CE->getValue();
657 return Value > 0 && Value <= 8;
658 }
659 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000660 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000661 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
662 if (!CE) return false;
663 int64_t Value = CE->getValue();
664 return Value > 0 && Value <= 16;
665 }
666 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000667 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000668 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
669 if (!CE) return false;
670 int64_t Value = CE->getValue();
671 return Value > 0 && Value <= 32;
672 }
673 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000674 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000675 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
676 if (!CE) return false;
677 int64_t Value = CE->getValue();
678 return Value > 0 && Value <= 64;
679 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000680 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000681 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
683 if (!CE) return false;
684 int64_t Value = CE->getValue();
685 return Value > 0 && Value < 8;
686 }
687 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000688 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000689 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
690 if (!CE) return false;
691 int64_t Value = CE->getValue();
692 return Value > 0 && Value < 16;
693 }
694 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000695 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
697 if (!CE) return false;
698 int64_t Value = CE->getValue();
699 return Value > 0 && Value < 32;
700 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000701 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000702 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000703 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
704 if (!CE) return false;
705 int64_t Value = CE->getValue();
706 return Value > 0 && Value < 17;
707 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000708 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000709 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000710 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
711 if (!CE) return false;
712 int64_t Value = CE->getValue();
713 return Value > 0 && Value < 33;
714 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000715 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000716 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
718 if (!CE) return false;
719 int64_t Value = CE->getValue();
720 return Value >= 0 && Value < 33;
721 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000722 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000723 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000724 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
725 if (!CE) return false;
726 int64_t Value = CE->getValue();
727 return Value >= 0 && Value < 65536;
728 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000729 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000730 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
732 // If it's not a constant expression, it'll generate a fixup and be
733 // handled later.
734 if (!CE) return true;
735 int64_t Value = CE->getValue();
736 return Value >= 0 && Value < 65536;
737 }
Jim Grosbached838482011-07-26 16:24:27 +0000738 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000739 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
741 if (!CE) return false;
742 int64_t Value = CE->getValue();
743 return Value >= 0 && Value <= 0xffffff;
744 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000745 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000746 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000747 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
748 if (!CE) return false;
749 int64_t Value = CE->getValue();
750 return Value > 0 && Value < 33;
751 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000752 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000753 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
755 if (!CE) return false;
756 int64_t Value = CE->getValue();
757 return Value >= 0 && Value < 32;
758 }
759 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000760 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000761 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
762 if (!CE) return false;
763 int64_t Value = CE->getValue();
764 return Value > 0 && Value <= 32;
765 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000766 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000767 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000768 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
769 if (!CE) return false;
770 int64_t Value = CE->getValue();
771 return ARM_AM::getSOImmVal(Value) != -1;
772 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000773 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000774 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000775 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
776 if (!CE) return false;
777 int64_t Value = CE->getValue();
778 return ARM_AM::getSOImmVal(~Value) != -1;
779 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000780 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000781 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000782 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
783 if (!CE) return false;
784 int64_t Value = CE->getValue();
785 return ARM_AM::getSOImmVal(-Value) != -1;
786 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000787 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000788 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000789 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
790 if (!CE) return false;
791 int64_t Value = CE->getValue();
792 return ARM_AM::getT2SOImmVal(Value) != -1;
793 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000794 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000795 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return ARM_AM::getT2SOImmVal(~Value) != -1;
800 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000801 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return ARM_AM::getT2SOImmVal(-Value) != -1;
807 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000808 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000809 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value == 1 || Value == 0;
814 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000815 bool isReg() const { return Kind == k_Register; }
816 bool isRegList() const { return Kind == k_RegisterList; }
817 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
818 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
819 bool isToken() const { return Kind == k_Token; }
820 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
821 bool isMemory() const { return Kind == k_Memory; }
822 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
823 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
824 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
825 bool isRotImm() const { return Kind == k_RotateImmediate; }
826 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
827 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000828 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000829 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000830 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000831 bool isMemNoOffset(bool alignOK = false) const {
Jim Grosbachf6c35c52011-10-10 23:06:42 +0000832 if (!isMemory())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000833 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000834 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000835 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
836 (alignOK || Memory.Alignment == 0);
837 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000838 bool isMemPCRelImm12() const {
839 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
840 return false;
841 // Base register must be PC.
842 if (Memory.BaseRegNum != ARM::PC)
843 return false;
844 // Immediate offset in range [-4095, 4095].
845 if (!Memory.OffsetImm) return true;
846 int64_t Val = Memory.OffsetImm->getValue();
847 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
848 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000849 bool isAlignedMemory() const {
850 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000851 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000852 bool isAddrMode2() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000853 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000854 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000855 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000856 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000857 if (!Memory.OffsetImm) return true;
858 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000859 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000860 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000861 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000862 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000863 // Immediate offset in range [-4095, 4095].
864 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
865 if (!CE) return false;
866 int64_t Val = CE->getValue();
867 return Val > -4096 && Val < 4096;
868 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000869 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000870 // If we have an immediate that's not a constant, treat it as a label
871 // reference needing a fixup. If it is a constant, it's something else
872 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000873 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000874 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000875 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000876 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000877 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000878 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000879 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000880 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000881 if (!Memory.OffsetImm) return true;
882 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000883 return Val > -256 && Val < 256;
884 }
885 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000886 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000887 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000888 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000889 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
890 // Immediate offset in range [-255, 255].
891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
892 if (!CE) return false;
893 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000894 // Special case, #-0 is INT32_MIN.
895 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000896 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000897 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000898 // If we have an immediate that's not a constant, treat it as a label
899 // reference needing a fixup. If it is a constant, it's something else
900 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000901 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000902 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000903 if (!isMemory() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000904 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000905 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000906 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000907 if (!Memory.OffsetImm) return true;
908 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000909 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000910 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000911 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000912 bool isMemTBB() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000913 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000914 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000915 return false;
916 return true;
917 }
918 bool isMemTBH() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000919 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000920 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
921 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000922 return false;
923 return true;
924 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000925 bool isMemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000926 if (!isMemory() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000927 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000928 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000929 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000930 bool isT2MemRegOffset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000931 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
932 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000933 return false;
934 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000935 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000936 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000937 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000938 return false;
939 return true;
940 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000941 bool isMemThumbRR() const {
942 // Thumb reg+reg addressing is simple. Just two registers, a base and
943 // an offset. No shifts, negations or any other complicating factors.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000944 if (!isMemory() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000945 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000946 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000947 return isARMLowRegister(Memory.BaseRegNum) &&
948 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +0000949 }
950 bool isMemThumbRIs4() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000951 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000952 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +0000953 return false;
954 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000955 if (!Memory.OffsetImm) return true;
956 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000957 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
958 }
Jim Grosbach38466302011-08-19 18:55:51 +0000959 bool isMemThumbRIs2() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000960 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000961 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +0000962 return false;
963 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000964 if (!Memory.OffsetImm) return true;
965 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +0000966 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
967 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000968 bool isMemThumbRIs1() const {
Jim Grosbache53c87b2011-10-11 15:59:20 +0000969 if (!isMemory() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000970 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000971 return false;
972 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000973 if (!Memory.OffsetImm) return true;
974 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +0000975 return Val >= 0 && Val <= 31;
976 }
Jim Grosbachecd85892011-08-19 18:13:48 +0000977 bool isMemThumbSPI() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +0000978 if (!isMemory() || Memory.OffsetRegNum != 0 ||
979 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +0000980 return false;
981 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000982 if (!Memory.OffsetImm) return true;
983 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +0000984 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000985 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000986 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000987 // If we have an immediate that's not a constant, treat it as a label
988 // reference needing a fixup. If it is a constant, it's something else
989 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000990 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000991 return true;
Jim Grosbach57dcb852011-10-11 17:29:55 +0000992 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +0000993 return false;
994 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000995 if (!Memory.OffsetImm) return true;
996 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha77295d2011-09-08 22:07:06 +0000997 return Val >= -1020 && Val <= 1020 && (Val & 3) == 0;
998 }
Jim Grosbachb6aed502011-09-09 18:37:27 +0000999 bool isMemImm0_1020s4Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001000 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001001 return false;
1002 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001003 if (!Memory.OffsetImm) return true;
1004 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001005 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1006 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001007 bool isMemImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001008 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001009 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001010 // Base reg of PC isn't allowed for these encodings.
1011 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001012 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001013 if (!Memory.OffsetImm) return true;
1014 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001015 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001016 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001017 bool isMemPosImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001018 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001019 return false;
1020 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001021 if (!Memory.OffsetImm) return true;
1022 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001023 return Val >= 0 && Val < 256;
1024 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001025 bool isMemNegImm8Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001026 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001027 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001028 // Base reg of PC isn't allowed for these encodings.
1029 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001030 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001031 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001032 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001033 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001034 }
1035 bool isMemUImm12Offset() const {
Jim Grosbach57dcb852011-10-11 17:29:55 +00001036 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001037 return false;
1038 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001039 if (!Memory.OffsetImm) return true;
1040 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001041 return (Val >= 0 && Val < 4096);
1042 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001043 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001044 // If we have an immediate that's not a constant, treat it as a label
1045 // reference needing a fixup. If it is a constant, it's something else
1046 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001047 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001048 return true;
1049
Jim Grosbach57dcb852011-10-11 17:29:55 +00001050 if (!isMemory() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001051 return false;
1052 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001053 if (!Memory.OffsetImm) return true;
1054 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001055 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001056 }
1057 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001058 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1060 if (!CE) return false;
1061 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001062 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001063 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001064 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001065 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001066 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1067 if (!CE) return false;
1068 int64_t Val = CE->getValue();
1069 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1070 (Val == INT32_MIN);
1071 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001072
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001073 bool isMSRMask() const { return Kind == k_MSRMask; }
1074 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001075
Jim Grosbach0e387b22011-10-17 22:26:03 +00001076 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001077 bool isSingleSpacedVectorList() const {
1078 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1079 }
1080 bool isDoubleSpacedVectorList() const {
1081 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1082 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001083 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001084 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001085 return VectorList.Count == 1;
1086 }
1087
Jim Grosbach28f08c92012-03-05 19:33:30 +00001088 bool isVecListDPair() const {
1089 if (!isSingleSpacedVectorList()) return false;
1090 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1091 .contains(VectorList.RegNum));
1092 }
1093
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001094 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001095 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001096 return VectorList.Count == 3;
1097 }
1098
Jim Grosbachb6310312011-10-21 20:35:01 +00001099 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001100 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001101 return VectorList.Count == 4;
1102 }
1103
Jim Grosbachc3384c92012-03-05 21:43:40 +00001104 bool isVecListDPairSpaced() const {
1105 if (!isSingleSpacedVectorList()) return false;
1106 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1107 .contains(VectorList.RegNum));
1108 }
1109
Jim Grosbachc387fc62012-01-23 23:20:46 +00001110 bool isVecListThreeQ() const {
1111 if (!isDoubleSpacedVectorList()) return false;
1112 return VectorList.Count == 3;
1113 }
1114
Jim Grosbach7945ead2012-01-24 00:43:12 +00001115 bool isVecListFourQ() const {
1116 if (!isDoubleSpacedVectorList()) return false;
1117 return VectorList.Count == 4;
1118 }
1119
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001120 bool isSingleSpacedVectorAllLanes() const {
1121 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1122 }
1123 bool isDoubleSpacedVectorAllLanes() const {
1124 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1125 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001126 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001127 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001128 return VectorList.Count == 1;
1129 }
1130
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001131 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001132 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001133 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1134 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001135 }
1136
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001137 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001138 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001139 return VectorList.Count == 2;
1140 }
1141
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001142 bool isVecListThreeDAllLanes() const {
1143 if (!isSingleSpacedVectorAllLanes()) return false;
1144 return VectorList.Count == 3;
1145 }
1146
1147 bool isVecListThreeQAllLanes() const {
1148 if (!isDoubleSpacedVectorAllLanes()) return false;
1149 return VectorList.Count == 3;
1150 }
1151
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001152 bool isVecListFourDAllLanes() const {
1153 if (!isSingleSpacedVectorAllLanes()) return false;
1154 return VectorList.Count == 4;
1155 }
1156
1157 bool isVecListFourQAllLanes() const {
1158 if (!isDoubleSpacedVectorAllLanes()) return false;
1159 return VectorList.Count == 4;
1160 }
1161
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001162 bool isSingleSpacedVectorIndexed() const {
1163 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1164 }
1165 bool isDoubleSpacedVectorIndexed() const {
1166 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1167 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001168 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001169 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001170 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1171 }
1172
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001173 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001174 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001175 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1176 }
1177
1178 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001179 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001180 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1181 }
1182
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001183 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001184 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001185 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1186 }
1187
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001188 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001189 if (!isSingleSpacedVectorIndexed()) return false;
1190 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1191 }
1192
1193 bool isVecListTwoQWordIndexed() const {
1194 if (!isDoubleSpacedVectorIndexed()) return false;
1195 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1196 }
1197
1198 bool isVecListTwoQHWordIndexed() const {
1199 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001200 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1201 }
1202
1203 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001204 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001205 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1206 }
1207
Jim Grosbach3a678af2012-01-23 21:53:26 +00001208 bool isVecListThreeDByteIndexed() const {
1209 if (!isSingleSpacedVectorIndexed()) return false;
1210 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1211 }
1212
1213 bool isVecListThreeDHWordIndexed() const {
1214 if (!isSingleSpacedVectorIndexed()) return false;
1215 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1216 }
1217
1218 bool isVecListThreeQWordIndexed() const {
1219 if (!isDoubleSpacedVectorIndexed()) return false;
1220 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1221 }
1222
1223 bool isVecListThreeQHWordIndexed() const {
1224 if (!isDoubleSpacedVectorIndexed()) return false;
1225 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1226 }
1227
1228 bool isVecListThreeDWordIndexed() const {
1229 if (!isSingleSpacedVectorIndexed()) return false;
1230 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1231 }
1232
Jim Grosbache983a132012-01-24 18:37:25 +00001233 bool isVecListFourDByteIndexed() const {
1234 if (!isSingleSpacedVectorIndexed()) return false;
1235 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1236 }
1237
1238 bool isVecListFourDHWordIndexed() const {
1239 if (!isSingleSpacedVectorIndexed()) return false;
1240 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1241 }
1242
1243 bool isVecListFourQWordIndexed() const {
1244 if (!isDoubleSpacedVectorIndexed()) return false;
1245 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1246 }
1247
1248 bool isVecListFourQHWordIndexed() const {
1249 if (!isDoubleSpacedVectorIndexed()) return false;
1250 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1251 }
1252
1253 bool isVecListFourDWordIndexed() const {
1254 if (!isSingleSpacedVectorIndexed()) return false;
1255 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1256 }
1257
Jim Grosbach460a9052011-10-07 23:56:00 +00001258 bool isVectorIndex8() const {
1259 if (Kind != k_VectorIndex) return false;
1260 return VectorIndex.Val < 8;
1261 }
1262 bool isVectorIndex16() const {
1263 if (Kind != k_VectorIndex) return false;
1264 return VectorIndex.Val < 4;
1265 }
1266 bool isVectorIndex32() const {
1267 if (Kind != k_VectorIndex) return false;
1268 return VectorIndex.Val < 2;
1269 }
1270
Jim Grosbach0e387b22011-10-17 22:26:03 +00001271 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001272 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001273 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1274 // Must be a constant.
1275 if (!CE) return false;
1276 int64_t Value = CE->getValue();
1277 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1278 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001279 return Value >= 0 && Value < 256;
1280 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001281
Jim Grosbachea461102011-10-17 23:09:09 +00001282 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001283 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001284 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1285 // Must be a constant.
1286 if (!CE) return false;
1287 int64_t Value = CE->getValue();
1288 // i16 value in the range [0,255] or [0x0100, 0xff00]
1289 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1290 }
1291
Jim Grosbach6248a542011-10-18 00:22:00 +00001292 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001293 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001294 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1295 // Must be a constant.
1296 if (!CE) return false;
1297 int64_t Value = CE->getValue();
1298 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1299 return (Value >= 0 && Value < 256) ||
1300 (Value >= 0x0100 && Value <= 0xff00) ||
1301 (Value >= 0x010000 && Value <= 0xff0000) ||
1302 (Value >= 0x01000000 && Value <= 0xff000000);
1303 }
1304
1305 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001306 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001307 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1308 // Must be a constant.
1309 if (!CE) return false;
1310 int64_t Value = CE->getValue();
1311 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1312 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1313 return (Value >= 0 && Value < 256) ||
1314 (Value >= 0x0100 && Value <= 0xff00) ||
1315 (Value >= 0x010000 && Value <= 0xff0000) ||
1316 (Value >= 0x01000000 && Value <= 0xff000000) ||
1317 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1318 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1319 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001320 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001321 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001322 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1323 // Must be a constant.
1324 if (!CE) return false;
1325 int64_t Value = ~CE->getValue();
1326 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1327 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1328 return (Value >= 0 && Value < 256) ||
1329 (Value >= 0x0100 && Value <= 0xff00) ||
1330 (Value >= 0x010000 && Value <= 0xff0000) ||
1331 (Value >= 0x01000000 && Value <= 0xff000000) ||
1332 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1333 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1334 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001335
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001336 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001337 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001338 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1339 // Must be a constant.
1340 if (!CE) return false;
1341 uint64_t Value = CE->getValue();
1342 // i64 value with each byte being either 0 or 0xff.
1343 for (unsigned i = 0; i < 8; ++i)
1344 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1345 return true;
1346 }
1347
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001348 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001349 // Add as immediates when possible. Null MCExpr = 0.
1350 if (Expr == 0)
1351 Inst.addOperand(MCOperand::CreateImm(0));
1352 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001353 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1354 else
1355 Inst.addOperand(MCOperand::CreateExpr(Expr));
1356 }
1357
Daniel Dunbar8462b302010-08-11 06:36:53 +00001358 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001359 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001360 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001361 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1362 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001363 }
1364
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001365 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1366 assert(N == 1 && "Invalid number of operands!");
1367 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1368 }
1369
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001370 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1371 assert(N == 1 && "Invalid number of operands!");
1372 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1373 }
1374
1375 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1376 assert(N == 1 && "Invalid number of operands!");
1377 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1378 }
1379
Jim Grosbach89df9962011-08-26 21:43:41 +00001380 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1381 assert(N == 1 && "Invalid number of operands!");
1382 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1383 }
1384
1385 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1386 assert(N == 1 && "Invalid number of operands!");
1387 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1388 }
1389
Jim Grosbachd67641b2010-12-06 18:21:12 +00001390 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1391 assert(N == 1 && "Invalid number of operands!");
1392 Inst.addOperand(MCOperand::CreateReg(getReg()));
1393 }
1394
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001395 void addRegOperands(MCInst &Inst, unsigned N) const {
1396 assert(N == 1 && "Invalid number of operands!");
1397 Inst.addOperand(MCOperand::CreateReg(getReg()));
1398 }
1399
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001400 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001401 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001402 assert(isRegShiftedReg() &&
1403 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001404 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1405 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001406 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001407 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001408 }
1409
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001410 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001411 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001412 assert(isRegShiftedImm() &&
1413 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001414 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Owen Anderson92a20222011-07-21 18:54:16 +00001415 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001416 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001417 }
1418
Jim Grosbach580f4a92011-07-25 22:20:28 +00001419 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001420 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001421 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1422 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001423 }
1424
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001425 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001426 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001427 const SmallVectorImpl<unsigned> &RegList = getRegList();
1428 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001429 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1430 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001431 }
1432
Bill Wendling0f630752010-11-17 04:32:08 +00001433 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1434 addRegListOperands(Inst, N);
1435 }
1436
1437 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1438 addRegListOperands(Inst, N);
1439 }
1440
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001441 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1442 assert(N == 1 && "Invalid number of operands!");
1443 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1444 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1445 }
1446
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001447 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1448 assert(N == 1 && "Invalid number of operands!");
1449 // Munge the lsb/width into a bitfield mask.
1450 unsigned lsb = Bitfield.LSB;
1451 unsigned width = Bitfield.Width;
1452 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1453 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1454 (32 - (lsb + width)));
1455 Inst.addOperand(MCOperand::CreateImm(Mask));
1456 }
1457
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001458 void addImmOperands(MCInst &Inst, unsigned N) const {
1459 assert(N == 1 && "Invalid number of operands!");
1460 addExpr(Inst, getImm());
1461 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001462
Jim Grosbach4050bc42011-12-22 22:19:05 +00001463 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1464 assert(N == 1 && "Invalid number of operands!");
1465 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1466 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1467 }
1468
1469 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1470 assert(N == 1 && "Invalid number of operands!");
1471 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1472 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1473 }
1474
Jim Grosbach9d390362011-10-03 23:38:36 +00001475 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1476 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001477 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1478 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1479 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001480 }
1481
Jim Grosbacha77295d2011-09-08 22:07:06 +00001482 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1483 assert(N == 1 && "Invalid number of operands!");
1484 // FIXME: We really want to scale the value here, but the LDRD/STRD
1485 // instruction don't encode operands that way yet.
1486 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1487 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1488 }
1489
Jim Grosbach72f39f82011-08-24 21:22:15 +00001490 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1491 assert(N == 1 && "Invalid number of operands!");
1492 // The immediate is scaled by four in the encoding and is stored
1493 // in the MCInst as such. Lop off the low two bits here.
1494 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1495 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1496 }
1497
1498 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1499 assert(N == 1 && "Invalid number of operands!");
1500 // The immediate is scaled by four in the encoding and is stored
1501 // in the MCInst as such. Lop off the low two bits here.
1502 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1503 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1504 }
1505
Jim Grosbachf4943352011-07-25 23:09:14 +00001506 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1507 assert(N == 1 && "Invalid number of operands!");
1508 // The constant encodes as the immediate-1, and we store in the instruction
1509 // the bits as encoded, so subtract off one here.
1510 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1511 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1512 }
1513
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001514 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1515 assert(N == 1 && "Invalid number of operands!");
1516 // The constant encodes as the immediate-1, and we store in the instruction
1517 // the bits as encoded, so subtract off one here.
1518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1519 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1520 }
1521
Jim Grosbach70939ee2011-08-17 21:51:27 +00001522 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1523 assert(N == 1 && "Invalid number of operands!");
1524 // The constant encodes as the immediate, except for 32, which encodes as
1525 // zero.
1526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1527 unsigned Imm = CE->getValue();
1528 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1529 }
1530
Jim Grosbachf6c05252011-07-21 17:23:04 +00001531 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1532 assert(N == 1 && "Invalid number of operands!");
1533 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1534 // the instruction as well.
1535 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1536 int Val = CE->getValue();
1537 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1538 }
1539
Jim Grosbach89a63372011-10-28 22:36:30 +00001540 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1541 assert(N == 1 && "Invalid number of operands!");
1542 // The operand is actually a t2_so_imm, but we have its bitwise
1543 // negation in the assembly source, so twiddle it here.
1544 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1545 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1546 }
1547
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001548 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1549 assert(N == 1 && "Invalid number of operands!");
1550 // The operand is actually a t2_so_imm, but we have its
1551 // negation in the assembly source, so twiddle it here.
1552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1553 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1554 }
1555
Jim Grosbache70ec842011-10-28 22:50:54 +00001556 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1557 assert(N == 1 && "Invalid number of operands!");
1558 // The operand is actually a so_imm, but we have its bitwise
1559 // negation in the assembly source, so twiddle it here.
1560 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1561 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1562 }
1563
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001564 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1565 assert(N == 1 && "Invalid number of operands!");
1566 // The operand is actually a so_imm, but we have its
1567 // negation in the assembly source, so twiddle it here.
1568 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1569 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1570 }
1571
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001572 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1573 assert(N == 1 && "Invalid number of operands!");
1574 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1575 }
1576
Jim Grosbach7ce05792011-08-03 23:50:40 +00001577 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001579 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001580 }
1581
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001582 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1583 assert(N == 1 && "Invalid number of operands!");
1584 int32_t Imm = Memory.OffsetImm->getValue();
1585 // FIXME: Handle #-0
1586 if (Imm == INT32_MIN) Imm = 0;
1587 Inst.addOperand(MCOperand::CreateImm(Imm));
1588 }
1589
Jim Grosbach57dcb852011-10-11 17:29:55 +00001590 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1591 assert(N == 2 && "Invalid number of operands!");
1592 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1593 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1594 }
1595
Jim Grosbach7ce05792011-08-03 23:50:40 +00001596 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1597 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001598 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1599 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001600 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1601 // Special case for #-0
1602 if (Val == INT32_MIN) Val = 0;
1603 if (Val < 0) Val = -Val;
1604 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1605 } else {
1606 // For register offset, we encode the shift type and negation flag
1607 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001608 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1609 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001610 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001611 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1612 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001613 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001614 }
1615
Jim Grosbach039c2e12011-08-04 23:01:30 +00001616 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1617 assert(N == 2 && "Invalid number of operands!");
1618 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1619 assert(CE && "non-constant AM2OffsetImm operand!");
1620 int32_t Val = CE->getValue();
1621 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1622 // Special case for #-0
1623 if (Val == INT32_MIN) Val = 0;
1624 if (Val < 0) Val = -Val;
1625 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1626 Inst.addOperand(MCOperand::CreateReg(0));
1627 Inst.addOperand(MCOperand::CreateImm(Val));
1628 }
1629
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001630 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1631 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001632 // If we have an immediate that's not a constant, treat it as a label
1633 // reference needing a fixup. If it is a constant, it's something else
1634 // and we reject it.
1635 if (isImm()) {
1636 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1637 Inst.addOperand(MCOperand::CreateReg(0));
1638 Inst.addOperand(MCOperand::CreateImm(0));
1639 return;
1640 }
1641
Jim Grosbache53c87b2011-10-11 15:59:20 +00001642 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1643 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001644 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1645 // Special case for #-0
1646 if (Val == INT32_MIN) Val = 0;
1647 if (Val < 0) Val = -Val;
1648 Val = ARM_AM::getAM3Opc(AddSub, Val);
1649 } else {
1650 // For register offset, we encode the shift type and negation flag
1651 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001652 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001653 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001654 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1655 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001656 Inst.addOperand(MCOperand::CreateImm(Val));
1657 }
1658
1659 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1660 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001661 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001662 int32_t Val =
1663 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1664 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1665 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001666 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001667 }
1668
1669 // Constant offset.
1670 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1671 int32_t Val = CE->getValue();
1672 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1673 // Special case for #-0
1674 if (Val == INT32_MIN) Val = 0;
1675 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001676 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001677 Inst.addOperand(MCOperand::CreateReg(0));
1678 Inst.addOperand(MCOperand::CreateImm(Val));
1679 }
1680
Jim Grosbach7ce05792011-08-03 23:50:40 +00001681 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1682 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001683 // If we have an immediate that's not a constant, treat it as a label
1684 // reference needing a fixup. If it is a constant, it's something else
1685 // and we reject it.
1686 if (isImm()) {
1687 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1688 Inst.addOperand(MCOperand::CreateImm(0));
1689 return;
1690 }
1691
Jim Grosbach7ce05792011-08-03 23:50:40 +00001692 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001693 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001694 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1695 // Special case for #-0
1696 if (Val == INT32_MIN) Val = 0;
1697 if (Val < 0) Val = -Val;
1698 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001699 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001700 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001701 }
1702
Jim Grosbacha77295d2011-09-08 22:07:06 +00001703 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001705 // If we have an immediate that's not a constant, treat it as a label
1706 // reference needing a fixup. If it is a constant, it's something else
1707 // and we reject it.
1708 if (isImm()) {
1709 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1710 Inst.addOperand(MCOperand::CreateImm(0));
1711 return;
1712 }
1713
Jim Grosbache53c87b2011-10-11 15:59:20 +00001714 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1715 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001716 Inst.addOperand(MCOperand::CreateImm(Val));
1717 }
1718
Jim Grosbachb6aed502011-09-09 18:37:27 +00001719 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1720 assert(N == 2 && "Invalid number of operands!");
1721 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001722 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1723 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001724 Inst.addOperand(MCOperand::CreateImm(Val));
1725 }
1726
Jim Grosbach7ce05792011-08-03 23:50:40 +00001727 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1728 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001729 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1730 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001731 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001732 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001733
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001734 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1735 addMemImm8OffsetOperands(Inst, N);
1736 }
1737
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001738 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001739 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001740 }
1741
1742 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1743 assert(N == 2 && "Invalid number of operands!");
1744 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001745 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001746 addExpr(Inst, getImm());
1747 Inst.addOperand(MCOperand::CreateImm(0));
1748 return;
1749 }
1750
1751 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001752 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1753 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001754 Inst.addOperand(MCOperand::CreateImm(Val));
1755 }
1756
Jim Grosbach7ce05792011-08-03 23:50:40 +00001757 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1758 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001759 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001760 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001761 addExpr(Inst, getImm());
1762 Inst.addOperand(MCOperand::CreateImm(0));
1763 return;
1764 }
1765
1766 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001767 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1768 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001769 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001770 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001771
Jim Grosbach7f739be2011-09-19 22:21:13 +00001772 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001774 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1775 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001776 }
1777
1778 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1779 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001780 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1781 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001782 }
1783
Jim Grosbach7ce05792011-08-03 23:50:40 +00001784 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1785 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001786 unsigned Val =
1787 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1788 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001789 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1790 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001791 Inst.addOperand(MCOperand::CreateImm(Val));
1792 }
1793
Jim Grosbachab899c12011-09-07 23:10:15 +00001794 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1795 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001796 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1797 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1798 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001799 }
1800
Jim Grosbach7ce05792011-08-03 23:50:40 +00001801 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1802 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001803 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1804 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001805 }
1806
Jim Grosbach60f91a32011-08-19 17:55:24 +00001807 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1808 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001809 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001811 Inst.addOperand(MCOperand::CreateImm(Val));
1812 }
1813
Jim Grosbach38466302011-08-19 18:55:51 +00001814 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1815 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001816 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001818 Inst.addOperand(MCOperand::CreateImm(Val));
1819 }
1820
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001821 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1822 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001823 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1824 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001825 Inst.addOperand(MCOperand::CreateImm(Val));
1826 }
1827
Jim Grosbachecd85892011-08-19 18:13:48 +00001828 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1829 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001830 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1831 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001832 Inst.addOperand(MCOperand::CreateImm(Val));
1833 }
1834
Jim Grosbach7ce05792011-08-03 23:50:40 +00001835 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1836 assert(N == 1 && "Invalid number of operands!");
1837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1838 assert(CE && "non-constant post-idx-imm8 operand!");
1839 int Imm = CE->getValue();
1840 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001841 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001842 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1843 Inst.addOperand(MCOperand::CreateImm(Imm));
1844 }
1845
Jim Grosbach2bd01182011-10-11 21:55:36 +00001846 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1847 assert(N == 1 && "Invalid number of operands!");
1848 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1849 assert(CE && "non-constant post-idx-imm8s4 operand!");
1850 int Imm = CE->getValue();
1851 bool isAdd = Imm >= 0;
1852 if (Imm == INT32_MIN) Imm = 0;
1853 // Immediate is scaled by 4.
1854 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1855 Inst.addOperand(MCOperand::CreateImm(Imm));
1856 }
1857
Jim Grosbach7ce05792011-08-03 23:50:40 +00001858 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1859 assert(N == 2 && "Invalid number of operands!");
1860 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001861 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1862 }
1863
1864 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1865 assert(N == 2 && "Invalid number of operands!");
1866 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1867 // The sign, shift type, and shift amount are encoded in a single operand
1868 // using the AM2 encoding helpers.
1869 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1870 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1871 PostIdxReg.ShiftTy);
1872 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001873 }
1874
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001875 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 1 && "Invalid number of operands!");
1877 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1878 }
1879
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001880 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1881 assert(N == 1 && "Invalid number of operands!");
1882 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1883 }
1884
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001885 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001886 assert(N == 1 && "Invalid number of operands!");
1887 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1888 }
1889
Jim Grosbach7636bf62011-12-02 00:35:16 +00001890 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1891 assert(N == 2 && "Invalid number of operands!");
1892 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1893 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1894 }
1895
Jim Grosbach460a9052011-10-07 23:56:00 +00001896 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1899 }
1900
1901 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 1 && "Invalid number of operands!");
1903 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1904 }
1905
1906 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1907 assert(N == 1 && "Invalid number of operands!");
1908 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1909 }
1910
Jim Grosbach0e387b22011-10-17 22:26:03 +00001911 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1912 assert(N == 1 && "Invalid number of operands!");
1913 // The immediate encodes the type of constant as well as the value.
1914 // Mask in that this is an i8 splat.
1915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1916 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1917 }
1918
Jim Grosbachea461102011-10-17 23:09:09 +00001919 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1920 assert(N == 1 && "Invalid number of operands!");
1921 // The immediate encodes the type of constant as well as the value.
1922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1923 unsigned Value = CE->getValue();
1924 if (Value >= 256)
1925 Value = (Value >> 8) | 0xa00;
1926 else
1927 Value |= 0x800;
1928 Inst.addOperand(MCOperand::CreateImm(Value));
1929 }
1930
Jim Grosbach6248a542011-10-18 00:22:00 +00001931 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1932 assert(N == 1 && "Invalid number of operands!");
1933 // The immediate encodes the type of constant as well as the value.
1934 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1935 unsigned Value = CE->getValue();
1936 if (Value >= 256 && Value <= 0xff00)
1937 Value = (Value >> 8) | 0x200;
1938 else if (Value > 0xffff && Value <= 0xff0000)
1939 Value = (Value >> 16) | 0x400;
1940 else if (Value > 0xffffff)
1941 Value = (Value >> 24) | 0x600;
1942 Inst.addOperand(MCOperand::CreateImm(Value));
1943 }
1944
1945 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 1 && "Invalid number of operands!");
1947 // The immediate encodes the type of constant as well as the value.
1948 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1949 unsigned Value = CE->getValue();
1950 if (Value >= 256 && Value <= 0xffff)
1951 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1952 else if (Value > 0xffff && Value <= 0xffffff)
1953 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1954 else if (Value > 0xffffff)
1955 Value = (Value >> 24) | 0x600;
1956 Inst.addOperand(MCOperand::CreateImm(Value));
1957 }
1958
Jim Grosbach9b087852011-12-19 23:51:07 +00001959 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
1960 assert(N == 1 && "Invalid number of operands!");
1961 // The immediate encodes the type of constant as well as the value.
1962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1963 unsigned Value = ~CE->getValue();
1964 if (Value >= 256 && Value <= 0xffff)
1965 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1966 else if (Value > 0xffff && Value <= 0xffffff)
1967 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1968 else if (Value > 0xffffff)
1969 Value = (Value >> 24) | 0x600;
1970 Inst.addOperand(MCOperand::CreateImm(Value));
1971 }
1972
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001973 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
1974 assert(N == 1 && "Invalid number of operands!");
1975 // The immediate encodes the type of constant as well as the value.
1976 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1977 uint64_t Value = CE->getValue();
1978 unsigned Imm = 0;
1979 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1980 Imm |= (Value & 1) << i;
1981 }
1982 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1983 }
1984
Jim Grosbachb7f689b2011-07-13 15:34:57 +00001985 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00001986
Jim Grosbach89df9962011-08-26 21:43:41 +00001987 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001988 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00001989 Op->ITMask.Mask = Mask;
1990 Op->StartLoc = S;
1991 Op->EndLoc = S;
1992 return Op;
1993 }
1994
Chris Lattner3a697562010-10-28 17:20:03 +00001995 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001996 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001997 Op->CC.Val = CC;
1998 Op->StartLoc = S;
1999 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002000 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002001 }
2002
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002003 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002004 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002005 Op->Cop.Val = CopVal;
2006 Op->StartLoc = S;
2007 Op->EndLoc = S;
2008 return Op;
2009 }
2010
2011 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002012 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002013 Op->Cop.Val = CopVal;
2014 Op->StartLoc = S;
2015 Op->EndLoc = S;
2016 return Op;
2017 }
2018
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002019 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2020 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2021 Op->Cop.Val = Val;
2022 Op->StartLoc = S;
2023 Op->EndLoc = E;
2024 return Op;
2025 }
2026
Jim Grosbachd67641b2010-12-06 18:21:12 +00002027 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002028 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002029 Op->Reg.RegNum = RegNum;
2030 Op->StartLoc = S;
2031 Op->EndLoc = S;
2032 return Op;
2033 }
2034
Chris Lattner3a697562010-10-28 17:20:03 +00002035 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002036 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002037 Op->Tok.Data = Str.data();
2038 Op->Tok.Length = Str.size();
2039 Op->StartLoc = S;
2040 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002041 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002042 }
2043
Bill Wendling50d0f582010-11-18 23:43:05 +00002044 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002045 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002046 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002047 Op->StartLoc = S;
2048 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002049 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002050 }
2051
Jim Grosbache8606dc2011-07-13 17:50:29 +00002052 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2053 unsigned SrcReg,
2054 unsigned ShiftReg,
2055 unsigned ShiftImm,
2056 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002057 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002058 Op->RegShiftedReg.ShiftTy = ShTy;
2059 Op->RegShiftedReg.SrcReg = SrcReg;
2060 Op->RegShiftedReg.ShiftReg = ShiftReg;
2061 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002062 Op->StartLoc = S;
2063 Op->EndLoc = E;
2064 return Op;
2065 }
2066
Owen Anderson92a20222011-07-21 18:54:16 +00002067 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2068 unsigned SrcReg,
2069 unsigned ShiftImm,
2070 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002071 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002072 Op->RegShiftedImm.ShiftTy = ShTy;
2073 Op->RegShiftedImm.SrcReg = SrcReg;
2074 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002075 Op->StartLoc = S;
2076 Op->EndLoc = E;
2077 return Op;
2078 }
2079
Jim Grosbach580f4a92011-07-25 22:20:28 +00002080 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002081 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002082 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002083 Op->ShifterImm.isASR = isASR;
2084 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002085 Op->StartLoc = S;
2086 Op->EndLoc = E;
2087 return Op;
2088 }
2089
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002090 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002091 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002092 Op->RotImm.Imm = Imm;
2093 Op->StartLoc = S;
2094 Op->EndLoc = E;
2095 return Op;
2096 }
2097
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002098 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2099 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002100 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002101 Op->Bitfield.LSB = LSB;
2102 Op->Bitfield.Width = Width;
2103 Op->StartLoc = S;
2104 Op->EndLoc = E;
2105 return Op;
2106 }
2107
Bill Wendling7729e062010-11-09 22:44:22 +00002108 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002109 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002110 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002111 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002112
Jim Grosbachd300b942011-09-13 22:56:44 +00002113 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002114 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002115 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002116 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002117 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002118
2119 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002120 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002121 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002122 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002123 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002124 Op->StartLoc = StartLoc;
2125 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002126 return Op;
2127 }
2128
Jim Grosbach862019c2011-10-18 23:02:30 +00002129 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002130 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002131 ARMOperand *Op = new ARMOperand(k_VectorList);
2132 Op->VectorList.RegNum = RegNum;
2133 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002134 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002135 Op->StartLoc = S;
2136 Op->EndLoc = E;
2137 return Op;
2138 }
2139
Jim Grosbach98b05a52011-11-30 01:09:44 +00002140 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002141 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002142 SMLoc S, SMLoc E) {
2143 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2144 Op->VectorList.RegNum = RegNum;
2145 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002146 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002147 Op->StartLoc = S;
2148 Op->EndLoc = E;
2149 return Op;
2150 }
2151
Jim Grosbach7636bf62011-12-02 00:35:16 +00002152 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002153 unsigned Index,
2154 bool isDoubleSpaced,
2155 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002156 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2157 Op->VectorList.RegNum = RegNum;
2158 Op->VectorList.Count = Count;
2159 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002160 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002161 Op->StartLoc = S;
2162 Op->EndLoc = E;
2163 return Op;
2164 }
2165
Jim Grosbach460a9052011-10-07 23:56:00 +00002166 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2167 MCContext &Ctx) {
2168 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2169 Op->VectorIndex.Val = Idx;
2170 Op->StartLoc = S;
2171 Op->EndLoc = E;
2172 return Op;
2173 }
2174
Chris Lattner3a697562010-10-28 17:20:03 +00002175 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002176 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002177 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002178 Op->StartLoc = S;
2179 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002180 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002181 }
2182
Jim Grosbach7ce05792011-08-03 23:50:40 +00002183 static ARMOperand *CreateMem(unsigned BaseRegNum,
2184 const MCConstantExpr *OffsetImm,
2185 unsigned OffsetRegNum,
2186 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002187 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002188 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002189 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002190 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002191 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002192 Op->Memory.BaseRegNum = BaseRegNum;
2193 Op->Memory.OffsetImm = OffsetImm;
2194 Op->Memory.OffsetRegNum = OffsetRegNum;
2195 Op->Memory.ShiftType = ShiftType;
2196 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002197 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002198 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002199 Op->StartLoc = S;
2200 Op->EndLoc = E;
2201 return Op;
2202 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002203
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002204 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2205 ARM_AM::ShiftOpc ShiftTy,
2206 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002207 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002208 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002209 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002210 Op->PostIdxReg.isAdd = isAdd;
2211 Op->PostIdxReg.ShiftTy = ShiftTy;
2212 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002213 Op->StartLoc = S;
2214 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002215 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002216 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002217
2218 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002219 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002220 Op->MBOpt.Val = Opt;
2221 Op->StartLoc = S;
2222 Op->EndLoc = S;
2223 return Op;
2224 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002225
2226 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002227 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002228 Op->IFlags.Val = IFlags;
2229 Op->StartLoc = S;
2230 Op->EndLoc = S;
2231 return Op;
2232 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002233
2234 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002235 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002236 Op->MMask.Val = MMask;
2237 Op->StartLoc = S;
2238 Op->EndLoc = S;
2239 return Op;
2240 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002241};
2242
2243} // end anonymous namespace.
2244
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002245void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002246 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002247 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002248 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002249 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002250 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002251 OS << "<ccout " << getReg() << ">";
2252 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002253 case k_ITCondMask: {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002254 static const char *MaskStr[] = {
2255 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2256 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2257 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002258 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2259 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2260 break;
2261 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002262 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002263 OS << "<coprocessor number: " << getCoproc() << ">";
2264 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002265 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002266 OS << "<coprocessor register: " << getCoproc() << ">";
2267 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002268 case k_CoprocOption:
2269 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2270 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002271 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002272 OS << "<mask: " << getMSRMask() << ">";
2273 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002274 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002275 getImm()->print(OS);
2276 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002277 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002278 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2279 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002280 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002281 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002282 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002283 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002284 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002285 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002286 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2287 << PostIdxReg.RegNum;
2288 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2289 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2290 << PostIdxReg.ShiftImm;
2291 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002292 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002293 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002294 OS << "<ARM_PROC::";
2295 unsigned IFlags = getProcIFlags();
2296 for (int i=2; i >= 0; --i)
2297 if (IFlags & (1 << i))
2298 OS << ARM_PROC::IFlagsToString(1 << i);
2299 OS << ">";
2300 break;
2301 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002302 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002303 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002304 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002305 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002306 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2307 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002308 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002309 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002310 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002311 << RegShiftedReg.SrcReg << " "
2312 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2313 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002314 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002315 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002316 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002317 << RegShiftedImm.SrcReg << " "
2318 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2319 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002320 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002321 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002322 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2323 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002324 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002325 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2326 << ", width: " << Bitfield.Width << ">";
2327 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002328 case k_RegisterList:
2329 case k_DPRRegisterList:
2330 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002331 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002332
Bill Wendling5fa22a12010-11-09 23:28:44 +00002333 const SmallVectorImpl<unsigned> &RegList = getRegList();
2334 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002335 I = RegList.begin(), E = RegList.end(); I != E; ) {
2336 OS << *I;
2337 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002338 }
2339
2340 OS << ">";
2341 break;
2342 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002343 case k_VectorList:
2344 OS << "<vector_list " << VectorList.Count << " * "
2345 << VectorList.RegNum << ">";
2346 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002347 case k_VectorListAllLanes:
2348 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2349 << VectorList.RegNum << ">";
2350 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002351 case k_VectorListIndexed:
2352 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2353 << VectorList.Count << " * " << VectorList.RegNum << ">";
2354 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002355 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002356 OS << "'" << getToken() << "'";
2357 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002358 case k_VectorIndex:
2359 OS << "<vectorindex " << getVectorIndex() << ">";
2360 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002361 }
2362}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002363
2364/// @name Auto-generated Match Functions
2365/// {
2366
2367static unsigned MatchRegisterName(StringRef Name);
2368
2369/// }
2370
Bob Wilson69df7232011-02-03 21:46:10 +00002371bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2372 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002373 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002374 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002375 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002376
2377 return (RegNo == (unsigned)-1);
2378}
2379
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002380/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002381/// and if it is a register name the token is eaten and the register number is
2382/// returned. Otherwise return -1.
2383///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002384int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002385 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002386 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002387
Benjamin Kramer59085362011-11-06 20:37:06 +00002388 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002389 unsigned RegNum = MatchRegisterName(lowerCase);
2390 if (!RegNum) {
2391 RegNum = StringSwitch<unsigned>(lowerCase)
2392 .Case("r13", ARM::SP)
2393 .Case("r14", ARM::LR)
2394 .Case("r15", ARM::PC)
2395 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002396 // Additional register name aliases for 'gas' compatibility.
2397 .Case("a1", ARM::R0)
2398 .Case("a2", ARM::R1)
2399 .Case("a3", ARM::R2)
2400 .Case("a4", ARM::R3)
2401 .Case("v1", ARM::R4)
2402 .Case("v2", ARM::R5)
2403 .Case("v3", ARM::R6)
2404 .Case("v4", ARM::R7)
2405 .Case("v5", ARM::R8)
2406 .Case("v6", ARM::R9)
2407 .Case("v7", ARM::R10)
2408 .Case("v8", ARM::R11)
2409 .Case("sb", ARM::R9)
2410 .Case("sl", ARM::R10)
2411 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002412 .Default(0);
2413 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002414 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002415 // Check for aliases registered via .req. Canonicalize to lower case.
2416 // That's more consistent since register names are case insensitive, and
2417 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2418 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002419 // If no match, return failure.
2420 if (Entry == RegisterReqs.end())
2421 return -1;
2422 Parser.Lex(); // Eat identifier token.
2423 return Entry->getValue();
2424 }
Bob Wilson69df7232011-02-03 21:46:10 +00002425
Chris Lattnere5658fa2010-10-30 04:09:10 +00002426 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002427
Chris Lattnere5658fa2010-10-30 04:09:10 +00002428 return RegNum;
2429}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002430
Jim Grosbach19906722011-07-13 18:49:30 +00002431// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2432// If a recoverable error occurs, return 1. If an irrecoverable error
2433// occurs, return -1. An irrecoverable error is one where tokens have been
2434// consumed in the process of trying to parse the shifter (i.e., when it is
2435// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002436int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002437 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2438 SMLoc S = Parser.getTok().getLoc();
2439 const AsmToken &Tok = Parser.getTok();
2440 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2441
Benjamin Kramer59085362011-11-06 20:37:06 +00002442 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002443 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002444 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002445 .Case("lsl", ARM_AM::lsl)
2446 .Case("lsr", ARM_AM::lsr)
2447 .Case("asr", ARM_AM::asr)
2448 .Case("ror", ARM_AM::ror)
2449 .Case("rrx", ARM_AM::rrx)
2450 .Default(ARM_AM::no_shift);
2451
2452 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002453 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002454
Jim Grosbache8606dc2011-07-13 17:50:29 +00002455 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002456
Jim Grosbache8606dc2011-07-13 17:50:29 +00002457 // The source register for the shift has already been added to the
2458 // operand list, so we need to pop it off and combine it into the shifted
2459 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002460 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002461 if (!PrevOp->isReg())
2462 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2463 int SrcReg = PrevOp->getReg();
2464 int64_t Imm = 0;
2465 int ShiftReg = 0;
2466 if (ShiftTy == ARM_AM::rrx) {
2467 // RRX Doesn't have an explicit shift amount. The encoder expects
2468 // the shift register to be the same as the source register. Seems odd,
2469 // but OK.
2470 ShiftReg = SrcReg;
2471 } else {
2472 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002473 if (Parser.getTok().is(AsmToken::Hash) ||
2474 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002475 Parser.Lex(); // Eat hash.
2476 SMLoc ImmLoc = Parser.getTok().getLoc();
2477 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002478 if (getParser().ParseExpression(ShiftExpr)) {
2479 Error(ImmLoc, "invalid immediate shift value");
2480 return -1;
2481 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002482 // The expression must be evaluatable as an immediate.
2483 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002484 if (!CE) {
2485 Error(ImmLoc, "invalid immediate shift value");
2486 return -1;
2487 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002488 // Range check the immediate.
2489 // lsl, ror: 0 <= imm <= 31
2490 // lsr, asr: 0 <= imm <= 32
2491 Imm = CE->getValue();
2492 if (Imm < 0 ||
2493 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2494 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002495 Error(ImmLoc, "immediate shift value out of range");
2496 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002497 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002498 // shift by zero is a nop. Always send it through as lsl.
2499 // ('as' compatibility)
2500 if (Imm == 0)
2501 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002502 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002503 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002504 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002505 if (ShiftReg == -1) {
2506 Error (L, "expected immediate or register in shift operand");
2507 return -1;
2508 }
2509 } else {
2510 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002511 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002512 return -1;
2513 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002514 }
2515
Owen Anderson92a20222011-07-21 18:54:16 +00002516 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2517 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002518 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002519 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002520 else
2521 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2522 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002523
Jim Grosbach19906722011-07-13 18:49:30 +00002524 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002525}
2526
2527
Bill Wendling50d0f582010-11-18 23:43:05 +00002528/// Try to parse a register name. The token must be an Identifier when called.
2529/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2530/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002531///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002532/// TODO this is likely to change to allow different register types and or to
2533/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002534bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002535tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002536 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002537 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002538 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002539 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002540
Bill Wendling50d0f582010-11-18 23:43:05 +00002541 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002542
Chris Lattnere5658fa2010-10-30 04:09:10 +00002543 const AsmToken &ExclaimTok = Parser.getTok();
2544 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002545 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2546 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002547 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002548 return false;
2549 }
2550
2551 // Also check for an index operand. This is only legal for vector registers,
2552 // but that'll get caught OK in operand matching, so we don't need to
2553 // explicitly filter everything else out here.
2554 if (Parser.getTok().is(AsmToken::LBrac)) {
2555 SMLoc SIdx = Parser.getTok().getLoc();
2556 Parser.Lex(); // Eat left bracket token.
2557
2558 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002559 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002560 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002561 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002562 if (!MCE)
2563 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002564
2565 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002566 if (Parser.getTok().isNot(AsmToken::RBrac))
2567 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002568
2569 Parser.Lex(); // Eat right bracket token.
2570
2571 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2572 SIdx, E,
2573 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002574 }
2575
Bill Wendling50d0f582010-11-18 23:43:05 +00002576 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002577}
2578
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002579/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2580/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2581/// "c5", ...
2582static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002583 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2584 // but efficient.
2585 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002586 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002587 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002588 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002589 return -1;
2590 switch (Name[1]) {
2591 default: return -1;
2592 case '0': return 0;
2593 case '1': return 1;
2594 case '2': return 2;
2595 case '3': return 3;
2596 case '4': return 4;
2597 case '5': return 5;
2598 case '6': return 6;
2599 case '7': return 7;
2600 case '8': return 8;
2601 case '9': return 9;
2602 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002603 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002604 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002605 return -1;
2606 switch (Name[2]) {
2607 default: return -1;
2608 case '0': return 10;
2609 case '1': return 11;
2610 case '2': return 12;
2611 case '3': return 13;
2612 case '4': return 14;
2613 case '5': return 15;
2614 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002615 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002616}
2617
Jim Grosbach89df9962011-08-26 21:43:41 +00002618/// parseITCondCode - Try to parse a condition code for an IT instruction.
2619ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2620parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2621 SMLoc S = Parser.getTok().getLoc();
2622 const AsmToken &Tok = Parser.getTok();
2623 if (!Tok.is(AsmToken::Identifier))
2624 return MatchOperand_NoMatch;
2625 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2626 .Case("eq", ARMCC::EQ)
2627 .Case("ne", ARMCC::NE)
2628 .Case("hs", ARMCC::HS)
2629 .Case("cs", ARMCC::HS)
2630 .Case("lo", ARMCC::LO)
2631 .Case("cc", ARMCC::LO)
2632 .Case("mi", ARMCC::MI)
2633 .Case("pl", ARMCC::PL)
2634 .Case("vs", ARMCC::VS)
2635 .Case("vc", ARMCC::VC)
2636 .Case("hi", ARMCC::HI)
2637 .Case("ls", ARMCC::LS)
2638 .Case("ge", ARMCC::GE)
2639 .Case("lt", ARMCC::LT)
2640 .Case("gt", ARMCC::GT)
2641 .Case("le", ARMCC::LE)
2642 .Case("al", ARMCC::AL)
2643 .Default(~0U);
2644 if (CC == ~0U)
2645 return MatchOperand_NoMatch;
2646 Parser.Lex(); // Eat the token.
2647
2648 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2649
2650 return MatchOperand_Success;
2651}
2652
Jim Grosbach43904292011-07-25 20:14:50 +00002653/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002654/// token must be an Identifier when called, and if it is a coprocessor
2655/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002656ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002657parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002658 SMLoc S = Parser.getTok().getLoc();
2659 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002660 if (Tok.isNot(AsmToken::Identifier))
2661 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002662
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002663 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002664 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002665 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002666
2667 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002668 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002669 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002670}
2671
Jim Grosbach43904292011-07-25 20:14:50 +00002672/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002673/// token must be an Identifier when called, and if it is a coprocessor
2674/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002675ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002676parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002677 SMLoc S = Parser.getTok().getLoc();
2678 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002679 if (Tok.isNot(AsmToken::Identifier))
2680 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002681
2682 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2683 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002684 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002685
2686 Parser.Lex(); // Eat identifier token.
2687 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002688 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002689}
2690
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002691/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2692/// coproc_option : '{' imm0_255 '}'
2693ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2694parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2695 SMLoc S = Parser.getTok().getLoc();
2696
2697 // If this isn't a '{', this isn't a coprocessor immediate operand.
2698 if (Parser.getTok().isNot(AsmToken::LCurly))
2699 return MatchOperand_NoMatch;
2700 Parser.Lex(); // Eat the '{'
2701
2702 const MCExpr *Expr;
2703 SMLoc Loc = Parser.getTok().getLoc();
2704 if (getParser().ParseExpression(Expr)) {
2705 Error(Loc, "illegal expression");
2706 return MatchOperand_ParseFail;
2707 }
2708 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2709 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2710 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2711 return MatchOperand_ParseFail;
2712 }
2713 int Val = CE->getValue();
2714
2715 // Check for and consume the closing '}'
2716 if (Parser.getTok().isNot(AsmToken::RCurly))
2717 return MatchOperand_ParseFail;
2718 SMLoc E = Parser.getTok().getLoc();
2719 Parser.Lex(); // Eat the '}'
2720
2721 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2722 return MatchOperand_Success;
2723}
2724
Jim Grosbachd0588e22011-09-14 18:08:35 +00002725// For register list parsing, we need to map from raw GPR register numbering
2726// to the enumeration values. The enumeration values aren't sorted by
2727// register number due to our using "sp", "lr" and "pc" as canonical names.
2728static unsigned getNextRegister(unsigned Reg) {
2729 // If this is a GPR, we need to do it manually, otherwise we can rely
2730 // on the sort ordering of the enumeration since the other reg-classes
2731 // are sane.
2732 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2733 return Reg + 1;
2734 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002735 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002736 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2737 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2738 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2739 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2740 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2741 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2742 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2743 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2744 }
2745}
2746
Jim Grosbachce485e72011-11-11 21:27:40 +00002747// Return the low-subreg of a given Q register.
2748static unsigned getDRegFromQReg(unsigned QReg) {
2749 switch (QReg) {
2750 default: llvm_unreachable("expected a Q register!");
2751 case ARM::Q0: return ARM::D0;
2752 case ARM::Q1: return ARM::D2;
2753 case ARM::Q2: return ARM::D4;
2754 case ARM::Q3: return ARM::D6;
2755 case ARM::Q4: return ARM::D8;
2756 case ARM::Q5: return ARM::D10;
2757 case ARM::Q6: return ARM::D12;
2758 case ARM::Q7: return ARM::D14;
2759 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002760 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002761 case ARM::Q10: return ARM::D20;
2762 case ARM::Q11: return ARM::D22;
2763 case ARM::Q12: return ARM::D24;
2764 case ARM::Q13: return ARM::D26;
2765 case ARM::Q14: return ARM::D28;
2766 case ARM::Q15: return ARM::D30;
2767 }
2768}
2769
Jim Grosbachd0588e22011-09-14 18:08:35 +00002770/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002771bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002772parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002773 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002774 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002775 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002776 Parser.Lex(); // Eat '{' token.
2777 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002778
Jim Grosbachd0588e22011-09-14 18:08:35 +00002779 // Check the first register in the list to see what register class
2780 // this is a list of.
2781 int Reg = tryParseRegister();
2782 if (Reg == -1)
2783 return Error(RegLoc, "register expected");
2784
Jim Grosbachce485e72011-11-11 21:27:40 +00002785 // The reglist instructions have at most 16 registers, so reserve
2786 // space for that many.
2787 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2788
2789 // Allow Q regs and just interpret them as the two D sub-registers.
2790 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2791 Reg = getDRegFromQReg(Reg);
2792 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2793 ++Reg;
2794 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002795 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002796 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2797 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2798 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2799 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2800 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2801 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2802 else
2803 return Error(RegLoc, "invalid register in register list");
2804
Jim Grosbachce485e72011-11-11 21:27:40 +00002805 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002806 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002807
Jim Grosbachd0588e22011-09-14 18:08:35 +00002808 // This starts immediately after the first register token in the list,
2809 // so we can see either a comma or a minus (range separator) as a legal
2810 // next token.
2811 while (Parser.getTok().is(AsmToken::Comma) ||
2812 Parser.getTok().is(AsmToken::Minus)) {
2813 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002814 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002815 SMLoc EndLoc = Parser.getTok().getLoc();
2816 int EndReg = tryParseRegister();
2817 if (EndReg == -1)
2818 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002819 // Allow Q regs and just interpret them as the two D sub-registers.
2820 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2821 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002822 // If the register is the same as the start reg, there's nothing
2823 // more to do.
2824 if (Reg == EndReg)
2825 continue;
2826 // The register must be in the same register class as the first.
2827 if (!RC->contains(EndReg))
2828 return Error(EndLoc, "invalid register in register list");
2829 // Ranges must go from low to high.
2830 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2831 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002832
Jim Grosbachd0588e22011-09-14 18:08:35 +00002833 // Add all the registers in the range to the register list.
2834 while (Reg != EndReg) {
2835 Reg = getNextRegister(Reg);
2836 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2837 }
2838 continue;
2839 }
2840 Parser.Lex(); // Eat the comma.
2841 RegLoc = Parser.getTok().getLoc();
2842 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002843 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002844 Reg = tryParseRegister();
2845 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002846 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002847 // Allow Q regs and just interpret them as the two D sub-registers.
2848 bool isQReg = false;
2849 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2850 Reg = getDRegFromQReg(Reg);
2851 isQReg = true;
2852 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002853 // The register must be in the same register class as the first.
2854 if (!RC->contains(Reg))
2855 return Error(RegLoc, "invalid register in register list");
2856 // List must be monotonically increasing.
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002857 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg)) {
2858 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2859 Warning(RegLoc, "register list not in ascending order");
2860 else
2861 return Error(RegLoc, "register list not in ascending order");
2862 }
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002863 if (getARMRegisterNumbering(Reg) == getARMRegisterNumbering(OldReg)) {
2864 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2865 ") in register list");
2866 continue;
2867 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002868 // VFP register lists must also be contiguous.
2869 // It's OK to use the enumeration values directly here rather, as the
2870 // VFP register classes have the enum sorted properly.
2871 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2872 Reg != OldReg + 1)
2873 return Error(RegLoc, "non-contiguous register range");
2874 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002875 if (isQReg)
2876 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002877 }
2878
Jim Grosbachd0588e22011-09-14 18:08:35 +00002879 SMLoc E = Parser.getTok().getLoc();
2880 if (Parser.getTok().isNot(AsmToken::RCurly))
2881 return Error(E, "'}' expected");
2882 Parser.Lex(); // Eat '}' token.
2883
Jim Grosbach27debd62011-12-13 21:48:29 +00002884 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002885 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002886
2887 // The ARM system instruction variants for LDM/STM have a '^' token here.
2888 if (Parser.getTok().is(AsmToken::Caret)) {
2889 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2890 Parser.Lex(); // Eat '^' token.
2891 }
2892
Bill Wendling50d0f582010-11-18 23:43:05 +00002893 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002894}
2895
Jim Grosbach98b05a52011-11-30 01:09:44 +00002896// Helper function to parse the lane index for vector lists.
2897ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002898parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2899 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002900 if (Parser.getTok().is(AsmToken::LBrac)) {
2901 Parser.Lex(); // Eat the '['.
2902 if (Parser.getTok().is(AsmToken::RBrac)) {
2903 // "Dn[]" is the 'all lanes' syntax.
2904 LaneKind = AllLanes;
2905 Parser.Lex(); // Eat the ']'.
2906 return MatchOperand_Success;
2907 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002908 const MCExpr *LaneIndex;
2909 SMLoc Loc = Parser.getTok().getLoc();
2910 if (getParser().ParseExpression(LaneIndex)) {
2911 Error(Loc, "illegal expression");
2912 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002913 }
Jim Grosbachc9313252011-12-21 01:19:23 +00002914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
2915 if (!CE) {
2916 Error(Loc, "lane index must be empty or an integer");
2917 return MatchOperand_ParseFail;
2918 }
2919 if (Parser.getTok().isNot(AsmToken::RBrac)) {
2920 Error(Parser.getTok().getLoc(), "']' expected");
2921 return MatchOperand_ParseFail;
2922 }
2923 Parser.Lex(); // Eat the ']'.
2924 int64_t Val = CE->getValue();
2925
2926 // FIXME: Make this range check context sensitive for .8, .16, .32.
2927 if (Val < 0 || Val > 7) {
2928 Error(Parser.getTok().getLoc(), "lane index out of range");
2929 return MatchOperand_ParseFail;
2930 }
2931 Index = Val;
2932 LaneKind = IndexedLane;
2933 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002934 }
2935 LaneKind = NoLanes;
2936 return MatchOperand_Success;
2937}
2938
Jim Grosbach862019c2011-10-18 23:02:30 +00002939// parse a vector register list
2940ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2941parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002942 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002943 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00002944 SMLoc S = Parser.getTok().getLoc();
2945 // As an extension (to match gas), support a plain D register or Q register
2946 // (without encosing curly braces) as a single or double entry list,
2947 // respectively.
2948 if (Parser.getTok().is(AsmToken::Identifier)) {
2949 int Reg = tryParseRegister();
2950 if (Reg == -1)
2951 return MatchOperand_NoMatch;
2952 SMLoc E = Parser.getTok().getLoc();
2953 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002954 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00002955 if (Res != MatchOperand_Success)
2956 return Res;
2957 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002958 case NoLanes:
2959 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002960 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002961 break;
2962 case AllLanes:
2963 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002964 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
2965 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002966 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002967 case IndexedLane:
2968 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002969 LaneIndex,
2970 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00002971 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002972 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00002973 return MatchOperand_Success;
2974 }
2975 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2976 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00002977 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00002978 if (Res != MatchOperand_Success)
2979 return Res;
2980 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00002981 case NoLanes:
2982 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00002983 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002984 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002985 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002986 break;
2987 case AllLanes:
2988 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002989 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
2990 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002991 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
2992 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002993 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002994 case IndexedLane:
2995 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002996 LaneIndex,
2997 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00002998 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002999 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003000 return MatchOperand_Success;
3001 }
3002 Error(S, "vector register expected");
3003 return MatchOperand_ParseFail;
3004 }
3005
3006 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003007 return MatchOperand_NoMatch;
3008
Jim Grosbach862019c2011-10-18 23:02:30 +00003009 Parser.Lex(); // Eat '{' token.
3010 SMLoc RegLoc = Parser.getTok().getLoc();
3011
3012 int Reg = tryParseRegister();
3013 if (Reg == -1) {
3014 Error(RegLoc, "register expected");
3015 return MatchOperand_ParseFail;
3016 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003017 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003018 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003019 unsigned FirstReg = Reg;
3020 // The list is of D registers, but we also allow Q regs and just interpret
3021 // them as the two D sub-registers.
3022 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3023 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003024 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3025 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003026 ++Reg;
3027 ++Count;
3028 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003029 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003030 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003031
Jim Grosbache43862b2011-11-15 23:19:15 +00003032 while (Parser.getTok().is(AsmToken::Comma) ||
3033 Parser.getTok().is(AsmToken::Minus)) {
3034 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003035 if (!Spacing)
3036 Spacing = 1; // Register range implies a single spaced list.
3037 else if (Spacing == 2) {
3038 Error(Parser.getTok().getLoc(),
3039 "sequential registers in double spaced list");
3040 return MatchOperand_ParseFail;
3041 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003042 Parser.Lex(); // Eat the minus.
3043 SMLoc EndLoc = Parser.getTok().getLoc();
3044 int EndReg = tryParseRegister();
3045 if (EndReg == -1) {
3046 Error(EndLoc, "register expected");
3047 return MatchOperand_ParseFail;
3048 }
3049 // Allow Q regs and just interpret them as the two D sub-registers.
3050 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3051 EndReg = getDRegFromQReg(EndReg) + 1;
3052 // If the register is the same as the start reg, there's nothing
3053 // more to do.
3054 if (Reg == EndReg)
3055 continue;
3056 // The register must be in the same register class as the first.
3057 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3058 Error(EndLoc, "invalid register in register list");
3059 return MatchOperand_ParseFail;
3060 }
3061 // Ranges must go from low to high.
3062 if (Reg > EndReg) {
3063 Error(EndLoc, "bad range in register list");
3064 return MatchOperand_ParseFail;
3065 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003066 // Parse the lane specifier if present.
3067 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003068 unsigned NextLaneIndex;
3069 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003070 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003071 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003072 Error(EndLoc, "mismatched lane index in register list");
3073 return MatchOperand_ParseFail;
3074 }
3075 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003076
3077 // Add all the registers in the range to the register list.
3078 Count += EndReg - Reg;
3079 Reg = EndReg;
3080 continue;
3081 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003082 Parser.Lex(); // Eat the comma.
3083 RegLoc = Parser.getTok().getLoc();
3084 int OldReg = Reg;
3085 Reg = tryParseRegister();
3086 if (Reg == -1) {
3087 Error(RegLoc, "register expected");
3088 return MatchOperand_ParseFail;
3089 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003090 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003091 // It's OK to use the enumeration values directly here rather, as the
3092 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003093 //
3094 // The list is of D registers, but we also allow Q regs and just interpret
3095 // them as the two D sub-registers.
3096 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003097 if (!Spacing)
3098 Spacing = 1; // Register range implies a single spaced list.
3099 else if (Spacing == 2) {
3100 Error(RegLoc,
3101 "invalid register in double-spaced list (must be 'D' register')");
3102 return MatchOperand_ParseFail;
3103 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003104 Reg = getDRegFromQReg(Reg);
3105 if (Reg != OldReg + 1) {
3106 Error(RegLoc, "non-contiguous register range");
3107 return MatchOperand_ParseFail;
3108 }
3109 ++Reg;
3110 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003111 // Parse the lane specifier if present.
3112 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003113 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003114 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003115 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003116 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003117 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003118 Error(EndLoc, "mismatched lane index in register list");
3119 return MatchOperand_ParseFail;
3120 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003121 continue;
3122 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003123 // Normal D register.
3124 // Figure out the register spacing (single or double) of the list if
3125 // we don't know it already.
3126 if (!Spacing)
3127 Spacing = 1 + (Reg == OldReg + 2);
3128
3129 // Just check that it's contiguous and keep going.
3130 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003131 Error(RegLoc, "non-contiguous register range");
3132 return MatchOperand_ParseFail;
3133 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003134 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003135 // Parse the lane specifier if present.
3136 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003137 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003138 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003139 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003140 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003141 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003142 Error(EndLoc, "mismatched lane index in register list");
3143 return MatchOperand_ParseFail;
3144 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003145 }
3146
3147 SMLoc E = Parser.getTok().getLoc();
3148 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3149 Error(E, "'}' expected");
3150 return MatchOperand_ParseFail;
3151 }
3152 Parser.Lex(); // Eat '}' token.
3153
Jim Grosbach98b05a52011-11-30 01:09:44 +00003154 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003155 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003156 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003157 // composite register classes.
3158 if (Count == 2) {
3159 const MCRegisterClass *RC = (Spacing == 1) ?
3160 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3161 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3162 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3163 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003164
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003165 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3166 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003167 break;
3168 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003169 // Two-register operands have been converted to the
3170 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003171 if (Count == 2) {
3172 const MCRegisterClass *RC = (Spacing == 1) ?
3173 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3174 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003175 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3176 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003177 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003178 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003179 S, E));
3180 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003181 case IndexedLane:
3182 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003183 LaneIndex,
3184 (Spacing == 2),
3185 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003186 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003187 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003188 return MatchOperand_Success;
3189}
3190
Jim Grosbach43904292011-07-25 20:14:50 +00003191/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003192ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003193parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003194 SMLoc S = Parser.getTok().getLoc();
3195 const AsmToken &Tok = Parser.getTok();
3196 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3197 StringRef OptStr = Tok.getString();
3198
3199 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3200 .Case("sy", ARM_MB::SY)
3201 .Case("st", ARM_MB::ST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003202 .Case("sh", ARM_MB::ISH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003203 .Case("ish", ARM_MB::ISH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003204 .Case("shst", ARM_MB::ISHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003205 .Case("ishst", ARM_MB::ISHST)
3206 .Case("nsh", ARM_MB::NSH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003207 .Case("un", ARM_MB::NSH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003208 .Case("nshst", ARM_MB::NSHST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003209 .Case("unst", ARM_MB::NSHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003210 .Case("osh", ARM_MB::OSH)
3211 .Case("oshst", ARM_MB::OSHST)
3212 .Default(~0U);
3213
3214 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00003215 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003216
3217 Parser.Lex(); // Eat identifier token.
3218 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003219 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003220}
3221
Jim Grosbach43904292011-07-25 20:14:50 +00003222/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003223ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003224parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003225 SMLoc S = Parser.getTok().getLoc();
3226 const AsmToken &Tok = Parser.getTok();
3227 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3228 StringRef IFlagsStr = Tok.getString();
3229
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003230 // An iflags string of "none" is interpreted to mean that none of the AIF
3231 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003232 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003233 if (IFlagsStr != "none") {
3234 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3235 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3236 .Case("a", ARM_PROC::A)
3237 .Case("i", ARM_PROC::I)
3238 .Case("f", ARM_PROC::F)
3239 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003240
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003241 // If some specific iflag is already set, it means that some letter is
3242 // present more than once, this is not acceptable.
3243 if (Flag == ~0U || (IFlags & Flag))
3244 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003245
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003246 IFlags |= Flag;
3247 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003248 }
3249
3250 Parser.Lex(); // Eat identifier token.
3251 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3252 return MatchOperand_Success;
3253}
3254
Jim Grosbach43904292011-07-25 20:14:50 +00003255/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003256ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003257parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003258 SMLoc S = Parser.getTok().getLoc();
3259 const AsmToken &Tok = Parser.getTok();
3260 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3261 StringRef Mask = Tok.getString();
3262
James Molloyacad68d2011-09-28 14:21:38 +00003263 if (isMClass()) {
3264 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003265 std::string Name = Mask.lower();
3266 unsigned FlagsVal = StringSwitch<unsigned>(Name)
James Molloyacad68d2011-09-28 14:21:38 +00003267 .Case("apsr", 0)
3268 .Case("iapsr", 1)
3269 .Case("eapsr", 2)
3270 .Case("xpsr", 3)
3271 .Case("ipsr", 5)
3272 .Case("epsr", 6)
3273 .Case("iepsr", 7)
3274 .Case("msp", 8)
3275 .Case("psp", 9)
3276 .Case("primask", 16)
3277 .Case("basepri", 17)
3278 .Case("basepri_max", 18)
3279 .Case("faultmask", 19)
3280 .Case("control", 20)
3281 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003282
James Molloyacad68d2011-09-28 14:21:38 +00003283 if (FlagsVal == ~0U)
3284 return MatchOperand_NoMatch;
3285
3286 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3287 // basepri, basepri_max and faultmask only valid for V7m.
3288 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003289
James Molloyacad68d2011-09-28 14:21:38 +00003290 Parser.Lex(); // Eat identifier token.
3291 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3292 return MatchOperand_Success;
3293 }
3294
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003295 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3296 size_t Start = 0, Next = Mask.find('_');
3297 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003298 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003299 if (Next != StringRef::npos)
3300 Flags = Mask.slice(Next+1, Mask.size());
3301
3302 // FlagsVal contains the complete mask:
3303 // 3-0: Mask
3304 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3305 unsigned FlagsVal = 0;
3306
3307 if (SpecReg == "apsr") {
3308 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003309 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003310 .Case("g", 0x4) // same as CPSR_s
3311 .Case("nzcvqg", 0xc) // same as CPSR_fs
3312 .Default(~0U);
3313
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003314 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003315 if (!Flags.empty())
3316 return MatchOperand_NoMatch;
3317 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003318 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003319 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003320 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003321 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
3322 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003323 for (int i = 0, e = Flags.size(); i != e; ++i) {
3324 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3325 .Case("c", 1)
3326 .Case("x", 2)
3327 .Case("s", 4)
3328 .Case("f", 8)
3329 .Default(~0U);
3330
3331 // If some specific flag is already set, it means that some letter is
3332 // present more than once, this is not acceptable.
3333 if (FlagsVal == ~0U || (FlagsVal & Flag))
3334 return MatchOperand_NoMatch;
3335 FlagsVal |= Flag;
3336 }
3337 } else // No match for special register.
3338 return MatchOperand_NoMatch;
3339
Owen Anderson7784f1d2011-10-21 18:43:28 +00003340 // Special register without flags is NOT equivalent to "fc" flags.
3341 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3342 // two lines would enable gas compatibility at the expense of breaking
3343 // round-tripping.
3344 //
3345 // if (!FlagsVal)
3346 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003347
3348 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3349 if (SpecReg == "spsr")
3350 FlagsVal |= 16;
3351
3352 Parser.Lex(); // Eat identifier token.
3353 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3354 return MatchOperand_Success;
3355}
3356
Jim Grosbachf6c05252011-07-21 17:23:04 +00003357ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3358parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3359 int Low, int High) {
3360 const AsmToken &Tok = Parser.getTok();
3361 if (Tok.isNot(AsmToken::Identifier)) {
3362 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3363 return MatchOperand_ParseFail;
3364 }
3365 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003366 std::string LowerOp = Op.lower();
3367 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003368 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3369 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3370 return MatchOperand_ParseFail;
3371 }
3372 Parser.Lex(); // Eat shift type token.
3373
3374 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003375 if (Parser.getTok().isNot(AsmToken::Hash) &&
3376 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003377 Error(Parser.getTok().getLoc(), "'#' expected");
3378 return MatchOperand_ParseFail;
3379 }
3380 Parser.Lex(); // Eat hash token.
3381
3382 const MCExpr *ShiftAmount;
3383 SMLoc Loc = Parser.getTok().getLoc();
3384 if (getParser().ParseExpression(ShiftAmount)) {
3385 Error(Loc, "illegal expression");
3386 return MatchOperand_ParseFail;
3387 }
3388 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3389 if (!CE) {
3390 Error(Loc, "constant expression expected");
3391 return MatchOperand_ParseFail;
3392 }
3393 int Val = CE->getValue();
3394 if (Val < Low || Val > High) {
3395 Error(Loc, "immediate value out of range");
3396 return MatchOperand_ParseFail;
3397 }
3398
3399 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3400
3401 return MatchOperand_Success;
3402}
3403
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003404ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3405parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3406 const AsmToken &Tok = Parser.getTok();
3407 SMLoc S = Tok.getLoc();
3408 if (Tok.isNot(AsmToken::Identifier)) {
3409 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3410 return MatchOperand_ParseFail;
3411 }
3412 int Val = StringSwitch<int>(Tok.getString())
3413 .Case("be", 1)
3414 .Case("le", 0)
3415 .Default(-1);
3416 Parser.Lex(); // Eat the token.
3417
3418 if (Val == -1) {
3419 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3420 return MatchOperand_ParseFail;
3421 }
3422 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3423 getContext()),
3424 S, Parser.getTok().getLoc()));
3425 return MatchOperand_Success;
3426}
3427
Jim Grosbach580f4a92011-07-25 22:20:28 +00003428/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3429/// instructions. Legal values are:
3430/// lsl #n 'n' in [0,31]
3431/// asr #n 'n' in [1,32]
3432/// n == 32 encoded as n == 0.
3433ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3434parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3435 const AsmToken &Tok = Parser.getTok();
3436 SMLoc S = Tok.getLoc();
3437 if (Tok.isNot(AsmToken::Identifier)) {
3438 Error(S, "shift operator 'asr' or 'lsl' expected");
3439 return MatchOperand_ParseFail;
3440 }
3441 StringRef ShiftName = Tok.getString();
3442 bool isASR;
3443 if (ShiftName == "lsl" || ShiftName == "LSL")
3444 isASR = false;
3445 else if (ShiftName == "asr" || ShiftName == "ASR")
3446 isASR = true;
3447 else {
3448 Error(S, "shift operator 'asr' or 'lsl' expected");
3449 return MatchOperand_ParseFail;
3450 }
3451 Parser.Lex(); // Eat the operator.
3452
3453 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003454 if (Parser.getTok().isNot(AsmToken::Hash) &&
3455 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003456 Error(Parser.getTok().getLoc(), "'#' expected");
3457 return MatchOperand_ParseFail;
3458 }
3459 Parser.Lex(); // Eat hash token.
3460
3461 const MCExpr *ShiftAmount;
3462 SMLoc E = Parser.getTok().getLoc();
3463 if (getParser().ParseExpression(ShiftAmount)) {
3464 Error(E, "malformed shift expression");
3465 return MatchOperand_ParseFail;
3466 }
3467 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3468 if (!CE) {
3469 Error(E, "shift amount must be an immediate");
3470 return MatchOperand_ParseFail;
3471 }
3472
3473 int64_t Val = CE->getValue();
3474 if (isASR) {
3475 // Shift amount must be in [1,32]
3476 if (Val < 1 || Val > 32) {
3477 Error(E, "'asr' shift amount must be in range [1,32]");
3478 return MatchOperand_ParseFail;
3479 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003480 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3481 if (isThumb() && Val == 32) {
3482 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3483 return MatchOperand_ParseFail;
3484 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003485 if (Val == 32) Val = 0;
3486 } else {
3487 // Shift amount must be in [1,32]
3488 if (Val < 0 || Val > 31) {
3489 Error(E, "'lsr' shift amount must be in range [0,31]");
3490 return MatchOperand_ParseFail;
3491 }
3492 }
3493
3494 E = Parser.getTok().getLoc();
3495 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3496
3497 return MatchOperand_Success;
3498}
3499
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003500/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3501/// of instructions. Legal values are:
3502/// ror #n 'n' in {0, 8, 16, 24}
3503ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3504parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3505 const AsmToken &Tok = Parser.getTok();
3506 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003507 if (Tok.isNot(AsmToken::Identifier))
3508 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003509 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003510 if (ShiftName != "ror" && ShiftName != "ROR")
3511 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003512 Parser.Lex(); // Eat the operator.
3513
3514 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003515 if (Parser.getTok().isNot(AsmToken::Hash) &&
3516 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003517 Error(Parser.getTok().getLoc(), "'#' expected");
3518 return MatchOperand_ParseFail;
3519 }
3520 Parser.Lex(); // Eat hash token.
3521
3522 const MCExpr *ShiftAmount;
3523 SMLoc E = Parser.getTok().getLoc();
3524 if (getParser().ParseExpression(ShiftAmount)) {
3525 Error(E, "malformed rotate expression");
3526 return MatchOperand_ParseFail;
3527 }
3528 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3529 if (!CE) {
3530 Error(E, "rotate amount must be an immediate");
3531 return MatchOperand_ParseFail;
3532 }
3533
3534 int64_t Val = CE->getValue();
3535 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3536 // normally, zero is represented in asm by omitting the rotate operand
3537 // entirely.
3538 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3539 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3540 return MatchOperand_ParseFail;
3541 }
3542
3543 E = Parser.getTok().getLoc();
3544 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3545
3546 return MatchOperand_Success;
3547}
3548
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003549ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3550parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3551 SMLoc S = Parser.getTok().getLoc();
3552 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003553 if (Parser.getTok().isNot(AsmToken::Hash) &&
3554 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003555 Error(Parser.getTok().getLoc(), "'#' expected");
3556 return MatchOperand_ParseFail;
3557 }
3558 Parser.Lex(); // Eat hash token.
3559
3560 const MCExpr *LSBExpr;
3561 SMLoc E = Parser.getTok().getLoc();
3562 if (getParser().ParseExpression(LSBExpr)) {
3563 Error(E, "malformed immediate expression");
3564 return MatchOperand_ParseFail;
3565 }
3566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3567 if (!CE) {
3568 Error(E, "'lsb' operand must be an immediate");
3569 return MatchOperand_ParseFail;
3570 }
3571
3572 int64_t LSB = CE->getValue();
3573 // The LSB must be in the range [0,31]
3574 if (LSB < 0 || LSB > 31) {
3575 Error(E, "'lsb' operand must be in the range [0,31]");
3576 return MatchOperand_ParseFail;
3577 }
3578 E = Parser.getTok().getLoc();
3579
3580 // Expect another immediate operand.
3581 if (Parser.getTok().isNot(AsmToken::Comma)) {
3582 Error(Parser.getTok().getLoc(), "too few operands");
3583 return MatchOperand_ParseFail;
3584 }
3585 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003586 if (Parser.getTok().isNot(AsmToken::Hash) &&
3587 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003588 Error(Parser.getTok().getLoc(), "'#' expected");
3589 return MatchOperand_ParseFail;
3590 }
3591 Parser.Lex(); // Eat hash token.
3592
3593 const MCExpr *WidthExpr;
3594 if (getParser().ParseExpression(WidthExpr)) {
3595 Error(E, "malformed immediate expression");
3596 return MatchOperand_ParseFail;
3597 }
3598 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3599 if (!CE) {
3600 Error(E, "'width' operand must be an immediate");
3601 return MatchOperand_ParseFail;
3602 }
3603
3604 int64_t Width = CE->getValue();
3605 // The LSB must be in the range [1,32-lsb]
3606 if (Width < 1 || Width > 32 - LSB) {
3607 Error(E, "'width' operand must be in the range [1,32-lsb]");
3608 return MatchOperand_ParseFail;
3609 }
3610 E = Parser.getTok().getLoc();
3611
3612 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3613
3614 return MatchOperand_Success;
3615}
3616
Jim Grosbach7ce05792011-08-03 23:50:40 +00003617ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3618parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3619 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003620 // postidx_reg := '+' register {, shift}
3621 // | '-' register {, shift}
3622 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003623
3624 // This method must return MatchOperand_NoMatch without consuming any tokens
3625 // in the case where there is no match, as other alternatives take other
3626 // parse methods.
3627 AsmToken Tok = Parser.getTok();
3628 SMLoc S = Tok.getLoc();
3629 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003630 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003631 int Reg = -1;
3632 if (Tok.is(AsmToken::Plus)) {
3633 Parser.Lex(); // Eat the '+' token.
3634 haveEaten = true;
3635 } else if (Tok.is(AsmToken::Minus)) {
3636 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003637 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003638 haveEaten = true;
3639 }
3640 if (Parser.getTok().is(AsmToken::Identifier))
3641 Reg = tryParseRegister();
3642 if (Reg == -1) {
3643 if (!haveEaten)
3644 return MatchOperand_NoMatch;
3645 Error(Parser.getTok().getLoc(), "register expected");
3646 return MatchOperand_ParseFail;
3647 }
3648 SMLoc E = Parser.getTok().getLoc();
3649
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003650 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3651 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003652 if (Parser.getTok().is(AsmToken::Comma)) {
3653 Parser.Lex(); // Eat the ','.
3654 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3655 return MatchOperand_ParseFail;
3656 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003657
3658 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3659 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003660
3661 return MatchOperand_Success;
3662}
3663
Jim Grosbach251bf252011-08-10 21:56:18 +00003664ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3665parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3666 // Check for a post-index addressing register operand. Specifically:
3667 // am3offset := '+' register
3668 // | '-' register
3669 // | register
3670 // | # imm
3671 // | # + imm
3672 // | # - imm
3673
3674 // This method must return MatchOperand_NoMatch without consuming any tokens
3675 // in the case where there is no match, as other alternatives take other
3676 // parse methods.
3677 AsmToken Tok = Parser.getTok();
3678 SMLoc S = Tok.getLoc();
3679
3680 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003681 if (Parser.getTok().is(AsmToken::Hash) ||
3682 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003683 Parser.Lex(); // Eat the '#'.
3684 // Explicitly look for a '-', as we need to encode negative zero
3685 // differently.
3686 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3687 const MCExpr *Offset;
3688 if (getParser().ParseExpression(Offset))
3689 return MatchOperand_ParseFail;
3690 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3691 if (!CE) {
3692 Error(S, "constant expression expected");
3693 return MatchOperand_ParseFail;
3694 }
3695 SMLoc E = Tok.getLoc();
3696 // Negative zero is encoded as the flag value INT32_MIN.
3697 int32_t Val = CE->getValue();
3698 if (isNegative && Val == 0)
3699 Val = INT32_MIN;
3700
3701 Operands.push_back(
3702 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3703
3704 return MatchOperand_Success;
3705 }
3706
3707
3708 bool haveEaten = false;
3709 bool isAdd = true;
3710 int Reg = -1;
3711 if (Tok.is(AsmToken::Plus)) {
3712 Parser.Lex(); // Eat the '+' token.
3713 haveEaten = true;
3714 } else if (Tok.is(AsmToken::Minus)) {
3715 Parser.Lex(); // Eat the '-' token.
3716 isAdd = false;
3717 haveEaten = true;
3718 }
3719 if (Parser.getTok().is(AsmToken::Identifier))
3720 Reg = tryParseRegister();
3721 if (Reg == -1) {
3722 if (!haveEaten)
3723 return MatchOperand_NoMatch;
3724 Error(Parser.getTok().getLoc(), "register expected");
3725 return MatchOperand_ParseFail;
3726 }
3727 SMLoc E = Parser.getTok().getLoc();
3728
3729 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3730 0, S, E));
3731
3732 return MatchOperand_Success;
3733}
3734
Jim Grosbacha77295d2011-09-08 22:07:06 +00003735/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3736/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3737/// when they refer multiple MIOperands inside a single one.
3738bool ARMAsmParser::
3739cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3740 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3741 // Rt, Rt2
3742 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3743 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3744 // Create a writeback register dummy placeholder.
3745 Inst.addOperand(MCOperand::CreateReg(0));
3746 // addr
3747 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3748 // pred
3749 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3750 return true;
3751}
3752
3753/// cvtT2StrdPre - Convert parsed operands to MCInst.
3754/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3755/// when they refer multiple MIOperands inside a single one.
3756bool ARMAsmParser::
3757cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3758 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3759 // Create a writeback register dummy placeholder.
3760 Inst.addOperand(MCOperand::CreateReg(0));
3761 // Rt, Rt2
3762 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3763 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3764 // addr
3765 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3766 // pred
3767 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3768 return true;
3769}
3770
Jim Grosbacheeec0252011-09-08 00:39:19 +00003771/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3772/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3773/// when they refer multiple MIOperands inside a single one.
3774bool ARMAsmParser::
3775cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3776 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3777 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3778
3779 // Create a writeback register dummy placeholder.
3780 Inst.addOperand(MCOperand::CreateImm(0));
3781
3782 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3783 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3784 return true;
3785}
3786
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003787/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3788/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3789/// when they refer multiple MIOperands inside a single one.
3790bool ARMAsmParser::
3791cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3792 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3793 // Create a writeback register dummy placeholder.
3794 Inst.addOperand(MCOperand::CreateImm(0));
3795 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3796 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3797 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3798 return true;
3799}
3800
Jim Grosbach1355cf12011-07-26 17:10:22 +00003801/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003802/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3803/// when they refer multiple MIOperands inside a single one.
3804bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003805cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003806 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3807 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3808
3809 // Create a writeback register dummy placeholder.
3810 Inst.addOperand(MCOperand::CreateImm(0));
3811
Jim Grosbach7ce05792011-08-03 23:50:40 +00003812 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003813 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3814 return true;
3815}
3816
Owen Anderson9ab0f252011-08-26 20:43:14 +00003817/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3818/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3819/// when they refer multiple MIOperands inside a single one.
3820bool ARMAsmParser::
3821cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3822 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3823 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3824
3825 // Create a writeback register dummy placeholder.
3826 Inst.addOperand(MCOperand::CreateImm(0));
3827
3828 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3829 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3830 return true;
3831}
3832
3833
Jim Grosbach548340c2011-08-11 19:22:40 +00003834/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3835/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3836/// when they refer multiple MIOperands inside a single one.
3837bool ARMAsmParser::
3838cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3839 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3840 // Create a writeback register dummy placeholder.
3841 Inst.addOperand(MCOperand::CreateImm(0));
3842 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3843 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3844 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3845 return true;
3846}
3847
Jim Grosbach1355cf12011-07-26 17:10:22 +00003848/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003849/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3850/// when they refer multiple MIOperands inside a single one.
3851bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003852cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003853 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3854 // Create a writeback register dummy placeholder.
3855 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003856 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3857 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3858 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003859 return true;
3860}
3861
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003862/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3863/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3864/// when they refer multiple MIOperands inside a single one.
3865bool ARMAsmParser::
3866cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3867 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3868 // Create a writeback register dummy placeholder.
3869 Inst.addOperand(MCOperand::CreateImm(0));
3870 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3871 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3872 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3873 return true;
3874}
3875
Jim Grosbach7ce05792011-08-03 23:50:40 +00003876/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3877/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3878/// when they refer multiple MIOperands inside a single one.
3879bool ARMAsmParser::
3880cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3881 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3882 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003883 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003884 // Create a writeback register dummy placeholder.
3885 Inst.addOperand(MCOperand::CreateImm(0));
3886 // addr
3887 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3888 // offset
3889 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3890 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003891 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3892 return true;
3893}
3894
Jim Grosbach7ce05792011-08-03 23:50:40 +00003895/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003896/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3897/// when they refer multiple MIOperands inside a single one.
3898bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003899cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3900 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3901 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00003902 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003903 // Create a writeback register dummy placeholder.
3904 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003905 // addr
3906 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3907 // offset
3908 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3909 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003910 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3911 return true;
3912}
3913
Jim Grosbach7ce05792011-08-03 23:50:40 +00003914/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003915/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3916/// when they refer multiple MIOperands inside a single one.
3917bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003918cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3919 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003920 // Create a writeback register dummy placeholder.
3921 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003922 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003923 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003924 // addr
3925 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3926 // offset
3927 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3928 // pred
3929 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3930 return true;
3931}
3932
3933/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3934/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3935/// when they refer multiple MIOperands inside a single one.
3936bool ARMAsmParser::
3937cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3938 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3939 // Create a writeback register dummy placeholder.
3940 Inst.addOperand(MCOperand::CreateImm(0));
3941 // Rt
3942 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3943 // addr
3944 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3945 // offset
3946 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3947 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003948 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3949 return true;
3950}
3951
Jim Grosbach2fd2b872011-08-10 20:29:19 +00003952/// cvtLdrdPre - Convert parsed operands to MCInst.
3953/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3954/// when they refer multiple MIOperands inside a single one.
3955bool ARMAsmParser::
3956cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3957 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3958 // Rt, Rt2
3959 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3960 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3961 // Create a writeback register dummy placeholder.
3962 Inst.addOperand(MCOperand::CreateImm(0));
3963 // addr
3964 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3965 // pred
3966 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3967 return true;
3968}
3969
Jim Grosbach14605d12011-08-11 20:28:23 +00003970/// cvtStrdPre - Convert parsed operands to MCInst.
3971/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3972/// when they refer multiple MIOperands inside a single one.
3973bool ARMAsmParser::
3974cvtStrdPre(MCInst &Inst, unsigned Opcode,
3975 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3976 // Create a writeback register dummy placeholder.
3977 Inst.addOperand(MCOperand::CreateImm(0));
3978 // Rt, Rt2
3979 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3980 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3981 // addr
3982 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3983 // pred
3984 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3985 return true;
3986}
3987
Jim Grosbach623a4542011-08-10 22:42:16 +00003988/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3989/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3990/// when they refer multiple MIOperands inside a single one.
3991bool ARMAsmParser::
3992cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3993 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3994 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3995 // Create a writeback register dummy placeholder.
3996 Inst.addOperand(MCOperand::CreateImm(0));
3997 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3998 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3999 return true;
4000}
4001
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004002/// cvtThumbMultiple- Convert parsed operands to MCInst.
4003/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4004/// when they refer multiple MIOperands inside a single one.
4005bool ARMAsmParser::
4006cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
4007 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4008 // The second source operand must be the same register as the destination
4009 // operand.
4010 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00004011 (((ARMOperand*)Operands[3])->getReg() !=
4012 ((ARMOperand*)Operands[5])->getReg()) &&
4013 (((ARMOperand*)Operands[3])->getReg() !=
4014 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004015 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00004016 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004017 return false;
4018 }
4019 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4020 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004021 // If we have a three-operand form, make sure to set Rn to be the operand
4022 // that isn't the same as Rd.
4023 unsigned RegOp = 4;
4024 if (Operands.size() == 6 &&
4025 ((ARMOperand*)Operands[4])->getReg() ==
4026 ((ARMOperand*)Operands[3])->getReg())
4027 RegOp = 5;
4028 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4029 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004030 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4031
4032 return true;
4033}
Jim Grosbach623a4542011-08-10 22:42:16 +00004034
Jim Grosbach12431322011-10-24 22:16:58 +00004035bool ARMAsmParser::
4036cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4037 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4038 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004039 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004040 // Create a writeback register dummy placeholder.
4041 Inst.addOperand(MCOperand::CreateImm(0));
4042 // Vn
4043 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4044 // pred
4045 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4046 return true;
4047}
4048
4049bool ARMAsmParser::
4050cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4051 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4052 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004053 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004054 // Create a writeback register dummy placeholder.
4055 Inst.addOperand(MCOperand::CreateImm(0));
4056 // Vn
4057 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4058 // Vm
4059 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4060 // pred
4061 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4062 return true;
4063}
4064
Jim Grosbach4334e032011-10-31 21:50:31 +00004065bool ARMAsmParser::
4066cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4067 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4068 // Create a writeback register dummy placeholder.
4069 Inst.addOperand(MCOperand::CreateImm(0));
4070 // Vn
4071 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4072 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004073 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004074 // pred
4075 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4076 return true;
4077}
4078
4079bool ARMAsmParser::
4080cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4081 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4082 // Create a writeback register dummy placeholder.
4083 Inst.addOperand(MCOperand::CreateImm(0));
4084 // Vn
4085 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4086 // Vm
4087 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4088 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004089 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004090 // pred
4091 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4092 return true;
4093}
4094
Bill Wendlinge7176102010-11-06 22:36:58 +00004095/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004096/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004097bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004098parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004099 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004100 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004101 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004102 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004103 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004104
Sean Callanan18b83232010-01-19 21:44:56 +00004105 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004106 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004107 if (BaseRegNum == -1)
4108 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004109
Daniel Dunbar05710932011-01-18 05:34:17 +00004110 // The next token must either be a comma or a closing bracket.
4111 const AsmToken &Tok = Parser.getTok();
4112 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004113 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004114
Jim Grosbach7ce05792011-08-03 23:50:40 +00004115 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004116 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004117 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004118
Jim Grosbach7ce05792011-08-03 23:50:40 +00004119 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004120 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004121
Jim Grosbachfb12f352011-09-19 18:42:21 +00004122 // If there's a pre-indexing writeback marker, '!', just add it as a token
4123 // operand. It's rather odd, but syntactically valid.
4124 if (Parser.getTok().is(AsmToken::Exclaim)) {
4125 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4126 Parser.Lex(); // Eat the '!'.
4127 }
4128
Jim Grosbach7ce05792011-08-03 23:50:40 +00004129 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004130 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004131
Jim Grosbach7ce05792011-08-03 23:50:40 +00004132 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4133 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004134
Jim Grosbach57dcb852011-10-11 17:29:55 +00004135 // If we have a ':', it's an alignment specifier.
4136 if (Parser.getTok().is(AsmToken::Colon)) {
4137 Parser.Lex(); // Eat the ':'.
4138 E = Parser.getTok().getLoc();
4139
4140 const MCExpr *Expr;
4141 if (getParser().ParseExpression(Expr))
4142 return true;
4143
4144 // The expression has to be a constant. Memory references with relocations
4145 // don't come through here, as they use the <label> forms of the relevant
4146 // instructions.
4147 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4148 if (!CE)
4149 return Error (E, "constant expression expected");
4150
4151 unsigned Align = 0;
4152 switch (CE->getValue()) {
4153 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004154 return Error(E,
4155 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4156 case 16: Align = 2; break;
4157 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004158 case 64: Align = 8; break;
4159 case 128: Align = 16; break;
4160 case 256: Align = 32; break;
4161 }
4162
4163 // Now we should have the closing ']'
4164 E = Parser.getTok().getLoc();
4165 if (Parser.getTok().isNot(AsmToken::RBrac))
4166 return Error(E, "']' expected");
4167 Parser.Lex(); // Eat right bracket token.
4168
4169 // Don't worry about range checking the value here. That's handled by
4170 // the is*() predicates.
4171 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4172 ARM_AM::no_shift, 0, Align,
4173 false, S, E));
4174
4175 // If there's a pre-indexing writeback marker, '!', just add it as a token
4176 // operand.
4177 if (Parser.getTok().is(AsmToken::Exclaim)) {
4178 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4179 Parser.Lex(); // Eat the '!'.
4180 }
4181
4182 return false;
4183 }
4184
4185 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004186 // offset. Be friendly and also accept a plain integer (without a leading
4187 // hash) for gas compatibility.
4188 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004189 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004190 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004191 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004192 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004193 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004194
Owen Anderson0da10cf2011-08-29 19:36:44 +00004195 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004196 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004197 if (getParser().ParseExpression(Offset))
4198 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004199
4200 // The expression has to be a constant. Memory references with relocations
4201 // don't come through here, as they use the <label> forms of the relevant
4202 // instructions.
4203 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4204 if (!CE)
4205 return Error (E, "constant expression expected");
4206
Owen Anderson0da10cf2011-08-29 19:36:44 +00004207 // If the constant was #-0, represent it as INT32_MIN.
4208 int32_t Val = CE->getValue();
4209 if (isNegative && Val == 0)
4210 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4211
Jim Grosbach7ce05792011-08-03 23:50:40 +00004212 // Now we should have the closing ']'
4213 E = Parser.getTok().getLoc();
4214 if (Parser.getTok().isNot(AsmToken::RBrac))
4215 return Error(E, "']' expected");
4216 Parser.Lex(); // Eat right bracket token.
4217
4218 // Don't worry about range checking the value here. That's handled by
4219 // the is*() predicates.
4220 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004221 ARM_AM::no_shift, 0, 0,
4222 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004223
4224 // If there's a pre-indexing writeback marker, '!', just add it as a token
4225 // operand.
4226 if (Parser.getTok().is(AsmToken::Exclaim)) {
4227 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4228 Parser.Lex(); // Eat the '!'.
4229 }
4230
4231 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004232 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004233
4234 // The register offset is optionally preceded by a '+' or '-'
4235 bool isNegative = false;
4236 if (Parser.getTok().is(AsmToken::Minus)) {
4237 isNegative = true;
4238 Parser.Lex(); // Eat the '-'.
4239 } else if (Parser.getTok().is(AsmToken::Plus)) {
4240 // Nothing to do.
4241 Parser.Lex(); // Eat the '+'.
4242 }
4243
4244 E = Parser.getTok().getLoc();
4245 int OffsetRegNum = tryParseRegister();
4246 if (OffsetRegNum == -1)
4247 return Error(E, "register expected");
4248
4249 // If there's a shift operator, handle it.
4250 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004251 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004252 if (Parser.getTok().is(AsmToken::Comma)) {
4253 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004254 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004255 return true;
4256 }
4257
4258 // Now we should have the closing ']'
4259 E = Parser.getTok().getLoc();
4260 if (Parser.getTok().isNot(AsmToken::RBrac))
4261 return Error(E, "']' expected");
4262 Parser.Lex(); // Eat right bracket token.
4263
4264 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004265 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004266 S, E));
4267
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004268 // If there's a pre-indexing writeback marker, '!', just add it as a token
4269 // operand.
4270 if (Parser.getTok().is(AsmToken::Exclaim)) {
4271 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4272 Parser.Lex(); // Eat the '!'.
4273 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004274
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004275 return false;
4276}
4277
Jim Grosbach7ce05792011-08-03 23:50:40 +00004278/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004279/// ( lsl | lsr | asr | ror ) , # shift_amount
4280/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004281/// return true if it parses a shift otherwise it returns false.
4282bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4283 unsigned &Amount) {
4284 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004285 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004286 if (Tok.isNot(AsmToken::Identifier))
4287 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004288 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004289 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4290 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004291 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004292 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004293 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004294 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004295 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004296 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004297 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004298 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004299 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004300 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004301 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004302 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004303
Jim Grosbach7ce05792011-08-03 23:50:40 +00004304 // rrx stands alone.
4305 Amount = 0;
4306 if (St != ARM_AM::rrx) {
4307 Loc = Parser.getTok().getLoc();
4308 // A '#' and a shift amount.
4309 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004310 if (HashTok.isNot(AsmToken::Hash) &&
4311 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004312 return Error(HashTok.getLoc(), "'#' expected");
4313 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004314
Jim Grosbach7ce05792011-08-03 23:50:40 +00004315 const MCExpr *Expr;
4316 if (getParser().ParseExpression(Expr))
4317 return true;
4318 // Range check the immediate.
4319 // lsl, ror: 0 <= imm <= 31
4320 // lsr, asr: 0 <= imm <= 32
4321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4322 if (!CE)
4323 return Error(Loc, "shift amount must be an immediate");
4324 int64_t Imm = CE->getValue();
4325 if (Imm < 0 ||
4326 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4327 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4328 return Error(Loc, "immediate shift value out of range");
4329 Amount = Imm;
4330 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004331
4332 return false;
4333}
4334
Jim Grosbach9d390362011-10-03 23:38:36 +00004335/// parseFPImm - A floating point immediate expression operand.
4336ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4337parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004338 // Anything that can accept a floating point constant as an operand
4339 // needs to go through here, as the regular ParseExpression is
4340 // integer only.
4341 //
4342 // This routine still creates a generic Immediate operand, containing
4343 // a bitcast of the 64-bit floating point value. The various operands
4344 // that accept floats can check whether the value is valid for them
4345 // via the standard is*() predicates.
4346
Jim Grosbach9d390362011-10-03 23:38:36 +00004347 SMLoc S = Parser.getTok().getLoc();
4348
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004349 if (Parser.getTok().isNot(AsmToken::Hash) &&
4350 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004351 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004352
4353 // Disambiguate the VMOV forms that can accept an FP immediate.
4354 // vmov.f32 <sreg>, #imm
4355 // vmov.f64 <dreg>, #imm
4356 // vmov.f32 <dreg>, #imm @ vector f32x2
4357 // vmov.f32 <qreg>, #imm @ vector f32x4
4358 //
4359 // There are also the NEON VMOV instructions which expect an
4360 // integer constant. Make sure we don't try to parse an FPImm
4361 // for these:
4362 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4363 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4364 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4365 TyOp->getToken() != ".f64"))
4366 return MatchOperand_NoMatch;
4367
Jim Grosbach9d390362011-10-03 23:38:36 +00004368 Parser.Lex(); // Eat the '#'.
4369
4370 // Handle negation, as that still comes through as a separate token.
4371 bool isNegative = false;
4372 if (Parser.getTok().is(AsmToken::Minus)) {
4373 isNegative = true;
4374 Parser.Lex();
4375 }
4376 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004377 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004378 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004379 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004380 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4381 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004382 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004383 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004384 Operands.push_back(ARMOperand::CreateImm(
4385 MCConstantExpr::Create(IntVal, getContext()),
4386 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004387 return MatchOperand_Success;
4388 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004389 // Also handle plain integers. Instructions which allow floating point
4390 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004391 if (Tok.is(AsmToken::Integer)) {
4392 int64_t Val = Tok.getIntVal();
4393 Parser.Lex(); // Eat the token.
4394 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004395 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004396 return MatchOperand_ParseFail;
4397 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004398 double RealVal = ARM_AM::getFPImmFloat(Val);
4399 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4400 Operands.push_back(ARMOperand::CreateImm(
4401 MCConstantExpr::Create(Val, getContext()), S,
4402 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004403 return MatchOperand_Success;
4404 }
4405
Jim Grosbachae69f702012-01-19 02:47:30 +00004406 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004407 return MatchOperand_ParseFail;
4408}
Jim Grosbach51222d12012-01-20 18:09:51 +00004409
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004410/// Parse a arm instruction operand. For now this parses the operand regardless
4411/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004412bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004413 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004414 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004415
4416 // Check if the current operand has a custom associated parser, if so, try to
4417 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004418 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4419 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004420 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004421 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4422 // there was a match, but an error occurred, in which case, just return that
4423 // the operand parsing failed.
4424 if (ResTy == MatchOperand_ParseFail)
4425 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004426
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004427 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004428 default:
4429 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004430 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004431 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004432 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004433 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004434 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004435 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004436 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004437 else if (Res == -1) // irrecoverable error
4438 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004439 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004440 if (Mnemonic == "vmrs" &&
4441 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004442 S = Parser.getTok().getLoc();
4443 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004444 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004445 return false;
4446 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004447
4448 // Fall though for the Identifier case that is not a register or a
4449 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004450 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004451 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004452 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004453 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004454 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004455 // This was not a register so parse other operands that start with an
4456 // identifier (like labels) as expressions and create them as immediates.
4457 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004458 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004459 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004460 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004461 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004462 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4463 return false;
4464 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004465 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004466 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004467 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004468 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004469 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004470 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004471 // #42 -> immediate.
4472 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +00004473 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004474 Parser.Lex();
Owen Anderson63553c72011-08-29 17:17:09 +00004475 bool isNegative = Parser.getTok().is(AsmToken::Minus);
Kevin Enderby515d5092009-10-15 20:48:48 +00004476 const MCExpr *ImmVal;
4477 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004478 return true;
Owen Anderson63553c72011-08-29 17:17:09 +00004479 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbached6a0c52011-11-01 22:37:37 +00004480 if (CE) {
4481 int32_t Val = CE->getValue();
4482 if (isNegative && Val == 0)
4483 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
Owen Anderson63553c72011-08-29 17:17:09 +00004484 }
Sean Callanan76264762010-04-02 22:27:05 +00004485 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004486 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4487 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004488 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004489 case AsmToken::Colon: {
4490 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004491 // FIXME: Check it's an expression prefix,
4492 // e.g. (FOO - :lower16:BAR) isn't legal.
4493 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004494 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004495 return true;
4496
Evan Cheng75972122011-01-13 07:58:56 +00004497 const MCExpr *SubExprVal;
4498 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004499 return true;
4500
Evan Cheng75972122011-01-13 07:58:56 +00004501 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4502 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004503 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004504 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004505 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004506 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004507 }
4508}
4509
Jim Grosbach1355cf12011-07-26 17:10:22 +00004510// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004511// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004512bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004513 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004514
4515 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004516 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004517 Parser.Lex(); // Eat ':'
4518
4519 if (getLexer().isNot(AsmToken::Identifier)) {
4520 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4521 return true;
4522 }
4523
4524 StringRef IDVal = Parser.getTok().getIdentifier();
4525 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004526 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004527 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004528 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004529 } else {
4530 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4531 return true;
4532 }
4533 Parser.Lex();
4534
4535 if (getLexer().isNot(AsmToken::Colon)) {
4536 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4537 return true;
4538 }
4539 Parser.Lex(); // Eat the last ':'
4540 return false;
4541}
4542
Daniel Dunbar352e1482011-01-11 15:59:50 +00004543/// \brief Given a mnemonic, split out possible predication code and carry
4544/// setting letters to form a canonical mnemonic and flags.
4545//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004546// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004547// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004548StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004549 unsigned &PredicationCode,
4550 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004551 unsigned &ProcessorIMod,
4552 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004553 PredicationCode = ARMCC::AL;
4554 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004555 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004556
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004557 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004558 //
4559 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004560 if ((Mnemonic == "movs" && isThumb()) ||
4561 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4562 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4563 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4564 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4565 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4566 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004567 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4568 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004569 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004570
Jim Grosbach3f00e312011-07-11 17:09:57 +00004571 // First, split out any predication code. Ignore mnemonics we know aren't
4572 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004573 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004574 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004575 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004576 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004577 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4578 .Case("eq", ARMCC::EQ)
4579 .Case("ne", ARMCC::NE)
4580 .Case("hs", ARMCC::HS)
4581 .Case("cs", ARMCC::HS)
4582 .Case("lo", ARMCC::LO)
4583 .Case("cc", ARMCC::LO)
4584 .Case("mi", ARMCC::MI)
4585 .Case("pl", ARMCC::PL)
4586 .Case("vs", ARMCC::VS)
4587 .Case("vc", ARMCC::VC)
4588 .Case("hi", ARMCC::HI)
4589 .Case("ls", ARMCC::LS)
4590 .Case("ge", ARMCC::GE)
4591 .Case("lt", ARMCC::LT)
4592 .Case("gt", ARMCC::GT)
4593 .Case("le", ARMCC::LE)
4594 .Case("al", ARMCC::AL)
4595 .Default(~0U);
4596 if (CC != ~0U) {
4597 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4598 PredicationCode = CC;
4599 }
Bill Wendling52925b62010-10-29 23:50:21 +00004600 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004601
Daniel Dunbar352e1482011-01-11 15:59:50 +00004602 // Next, determine if we have a carry setting bit. We explicitly ignore all
4603 // the instructions we know end in 's'.
4604 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004605 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004606 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4607 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4608 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004609 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004610 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004611 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004612 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004613 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004614 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4615 CarrySetting = true;
4616 }
4617
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004618 // The "cps" instruction can have a interrupt mode operand which is glued into
4619 // the mnemonic. Check if this is the case, split it and parse the imod op
4620 if (Mnemonic.startswith("cps")) {
4621 // Split out any imod code.
4622 unsigned IMod =
4623 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4624 .Case("ie", ARM_PROC::IE)
4625 .Case("id", ARM_PROC::ID)
4626 .Default(~0U);
4627 if (IMod != ~0U) {
4628 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4629 ProcessorIMod = IMod;
4630 }
4631 }
4632
Jim Grosbach89df9962011-08-26 21:43:41 +00004633 // The "it" instruction has the condition mask on the end of the mnemonic.
4634 if (Mnemonic.startswith("it")) {
4635 ITMask = Mnemonic.slice(2, Mnemonic.size());
4636 Mnemonic = Mnemonic.slice(0, 2);
4637 }
4638
Daniel Dunbar352e1482011-01-11 15:59:50 +00004639 return Mnemonic;
4640}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004641
4642/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4643/// inclusion of carry set or predication code operands.
4644//
4645// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004646void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004647getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004648 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004649 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4650 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004651 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004652 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004653 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004654 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004655 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004656 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004657 Mnemonic == "mla" || Mnemonic == "smlal" ||
4658 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004659 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004660 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004661 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004662
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004663 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4664 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4665 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4666 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004667 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4668 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004669 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004670 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4671 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4672 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004673 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4674 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004675 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004676 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004677 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004678 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004679
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004680 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004681 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004682 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004683 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004684 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004685}
4686
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004687bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4688 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004689 // FIXME: This is all horribly hacky. We really need a better way to deal
4690 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004691
4692 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4693 // another does not. Specifically, the MOVW instruction does not. So we
4694 // special case it here and remove the defaulted (non-setting) cc_out
4695 // operand if that's the instruction we're trying to match.
4696 //
4697 // We do this as post-processing of the explicit operands rather than just
4698 // conditionally adding the cc_out in the first place because we need
4699 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004700 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004701 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4702 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4703 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4704 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004705
4706 // Register-register 'add' for thumb does not have a cc_out operand
4707 // when there are only two register operands.
4708 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4709 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4710 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4711 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4712 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004713 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004714 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4715 // have to check the immediate range here since Thumb2 has a variant
4716 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004717 if (((isThumb() && Mnemonic == "add") ||
4718 (isThumbTwo() && Mnemonic == "sub")) &&
4719 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004720 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4721 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4722 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004723 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4724 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
4725 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004726 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004727 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4728 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004729 // selecting via the generic "add" mnemonic, so to know that we
4730 // should remove the cc_out operand, we have to explicitly check that
4731 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004732 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4733 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004734 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4735 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4736 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4737 // Nest conditions rather than one big 'if' statement for readability.
4738 //
4739 // If either register is a high reg, it's either one of the SP
4740 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004741 // check against T3. If the second register is the PC, this is an
4742 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004743 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4744 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004745 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004746 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4747 return false;
4748 // If both registers are low, we're in an IT block, and the immediate is
4749 // in range, we should use encoding T1 instead, which has a cc_out.
4750 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004751 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004752 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4753 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4754 return false;
4755
4756 // Otherwise, we use encoding T4, which does not have a cc_out
4757 // operand.
4758 return true;
4759 }
4760
Jim Grosbach64944f42011-09-14 21:00:40 +00004761 // The thumb2 multiply instruction doesn't have a CCOut register, so
4762 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4763 // use the 16-bit encoding or not.
4764 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4765 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4766 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4767 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4768 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4769 // If the registers aren't low regs, the destination reg isn't the
4770 // same as one of the source regs, or the cc_out operand is zero
4771 // outside of an IT block, we have to use the 32-bit encoding, so
4772 // remove the cc_out operand.
4773 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4774 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004775 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004776 !inITBlock() ||
4777 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4778 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4779 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4780 static_cast<ARMOperand*>(Operands[4])->getReg())))
4781 return true;
4782
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004783 // Also check the 'mul' syntax variant that doesn't specify an explicit
4784 // destination register.
4785 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4786 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4787 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4788 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4789 // If the registers aren't low regs or the cc_out operand is zero
4790 // outside of an IT block, we have to use the 32-bit encoding, so
4791 // remove the cc_out operand.
4792 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4793 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4794 !inITBlock()))
4795 return true;
4796
Jim Grosbach64944f42011-09-14 21:00:40 +00004797
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004798
Jim Grosbachf69c8042011-08-24 21:42:27 +00004799 // Register-register 'add/sub' for thumb does not have a cc_out operand
4800 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4801 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4802 // right, this will result in better diagnostics (which operand is off)
4803 // anyway.
4804 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4805 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004806 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4807 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4808 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4809 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004810
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004811 return false;
4812}
4813
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004814static bool isDataTypeToken(StringRef Tok) {
4815 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4816 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4817 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4818 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4819 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4820 Tok == ".f" || Tok == ".d";
4821}
4822
4823// FIXME: This bit should probably be handled via an explicit match class
4824// in the .td files that matches the suffix instead of having it be
4825// a literal string token the way it is now.
4826static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4827 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4828}
4829
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004830static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004831/// Parse an arm instruction mnemonic followed by its operands.
4832bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4833 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004834 // Apply mnemonic aliases before doing anything else, as the destination
4835 // mnemnonic may include suffices and we want to handle them normally.
4836 // The generic tblgen'erated code does this later, at the start of
4837 // MatchInstructionImpl(), but that's too late for aliases that include
4838 // any sort of suffix.
4839 unsigned AvailableFeatures = getAvailableFeatures();
4840 applyMnemonicAliases(Name, AvailableFeatures);
4841
Jim Grosbacha39cda72011-12-14 02:16:11 +00004842 // First check for the ARM-specific .req directive.
4843 if (Parser.getTok().is(AsmToken::Identifier) &&
4844 Parser.getTok().getIdentifier() == ".req") {
4845 parseDirectiveReq(Name, NameLoc);
4846 // We always return 'error' for this, as we're done with this
4847 // statement and don't need to match the 'instruction."
4848 return true;
4849 }
4850
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004851 // Create the leading tokens for the mnemonic, split by '.' characters.
4852 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004853 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004854
Daniel Dunbar352e1482011-01-11 15:59:50 +00004855 // Split out the predication code and carry setting flag from the mnemonic.
4856 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004857 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004858 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004859 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004860 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004861 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004862
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004863 // In Thumb1, only the branch (B) instruction can be predicated.
4864 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4865 Parser.EatToEndOfStatement();
4866 return Error(NameLoc, "conditional execution not supported in Thumb1");
4867 }
4868
Jim Grosbachffa32252011-07-19 19:13:28 +00004869 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4870
Jim Grosbach89df9962011-08-26 21:43:41 +00004871 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4872 // is the mask as it will be for the IT encoding if the conditional
4873 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4874 // where the conditional bit0 is zero, the instruction post-processing
4875 // will adjust the mask accordingly.
4876 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004877 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4878 if (ITMask.size() > 3) {
4879 Parser.EatToEndOfStatement();
4880 return Error(Loc, "too many conditions on IT instruction");
4881 }
Jim Grosbach89df9962011-08-26 21:43:41 +00004882 unsigned Mask = 8;
4883 for (unsigned i = ITMask.size(); i != 0; --i) {
4884 char pos = ITMask[i - 1];
4885 if (pos != 't' && pos != 'e') {
4886 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004887 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00004888 }
4889 Mask >>= 1;
4890 if (ITMask[i - 1] == 't')
4891 Mask |= 8;
4892 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004893 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00004894 }
4895
Jim Grosbachffa32252011-07-19 19:13:28 +00004896 // FIXME: This is all a pretty gross hack. We should automatically handle
4897 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00004898
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004899 // Next, add the CCOut and ConditionCode operands, if needed.
4900 //
4901 // For mnemonics which can ever incorporate a carry setting bit or predication
4902 // code, our matching model involves us always generating CCOut and
4903 // ConditionCode operands to match the mnemonic "as written" and then we let
4904 // the matcher deal with finding the right instruction or generating an
4905 // appropriate error.
4906 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004907 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004908
Jim Grosbach33c16a22011-07-14 22:04:21 +00004909 // If we had a carry-set on an instruction that can't do that, issue an
4910 // error.
4911 if (!CanAcceptCarrySet && CarrySetting) {
4912 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00004913 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00004914 "' can not set flags, but 's' suffix specified");
4915 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00004916 // If we had a predication code on an instruction that can't do that, issue an
4917 // error.
4918 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4919 Parser.EatToEndOfStatement();
4920 return Error(NameLoc, "instruction '" + Mnemonic +
4921 "' is not predicable, but condition code specified");
4922 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00004923
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004924 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004925 if (CanAcceptCarrySet) {
4926 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004927 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004928 Loc));
4929 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004930
4931 // Add the predication code operand, if necessary.
4932 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004933 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4934 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004935 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004936 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004937 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004938
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004939 // Add the processor imod operand, if necessary.
4940 if (ProcessorIMod) {
4941 Operands.push_back(ARMOperand::CreateImm(
4942 MCConstantExpr::Create(ProcessorIMod, getContext()),
4943 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004944 }
4945
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004946 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00004947 while (Next != StringRef::npos) {
4948 Start = Next;
4949 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004950 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004951
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004952 // Some NEON instructions have an optional datatype suffix that is
4953 // completely ignored. Check for that.
4954 if (isDataTypeToken(ExtraToken) &&
4955 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4956 continue;
4957
Jim Grosbach81d2e392011-09-07 16:06:04 +00004958 if (ExtraToken != ".n") {
4959 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4960 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4961 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00004962 }
4963
4964 // Read the remaining operands.
4965 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004966 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004967 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004968 Parser.EatToEndOfStatement();
4969 return true;
4970 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004971
4972 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00004973 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004974
4975 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004976 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004977 Parser.EatToEndOfStatement();
4978 return true;
4979 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004980 }
4981 }
Jim Grosbach16c74252010-10-29 14:46:02 +00004982
Chris Lattnercbf8a982010-09-11 16:18:25 +00004983 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00004984 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00004985 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00004986 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00004987 }
Bill Wendling146018f2010-11-06 21:42:12 +00004988
Chris Lattner34e53142010-09-08 05:10:46 +00004989 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00004990
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004991 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4992 // do and don't have a cc_out optional-def operand. With some spot-checks
4993 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004994 // parse and adjust accordingly before actually matching. We shouldn't ever
4995 // try to remove a cc_out operand that was explicitly set on the the
4996 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4997 // table driven matcher doesn't fit well with the ARM instruction set.
4998 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00004999 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5000 Operands.erase(Operands.begin() + 1);
5001 delete Op;
5002 }
5003
Jim Grosbachcf121c32011-07-28 21:57:55 +00005004 // ARM mode 'blx' need special handling, as the register operand version
5005 // is predicable, but the label operand version is not. So, we can't rely
5006 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005007 // a k_CondCode operand in the list. If we're trying to match the label
5008 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005009 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5010 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5011 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5012 Operands.erase(Operands.begin() + 1);
5013 delete Op;
5014 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005015
5016 // The vector-compare-to-zero instructions have a literal token "#0" at
5017 // the end that comes to here as an immediate operand. Convert it to a
5018 // token to play nicely with the matcher.
5019 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5020 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5021 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5022 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5024 if (CE && CE->getValue() == 0) {
5025 Operands.erase(Operands.begin() + 5);
5026 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5027 delete Op;
5028 }
5029 }
Jim Grosbach68259142011-10-03 22:30:24 +00005030 // VCMP{E} does the same thing, but with a different operand count.
5031 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5032 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5033 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5034 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5035 if (CE && CE->getValue() == 0) {
5036 Operands.erase(Operands.begin() + 4);
5037 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5038 delete Op;
5039 }
5040 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005041 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005042 // end. Convert it to a token here. Take care not to convert those
5043 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005044 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005045 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5046 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005047 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5048 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005050 if (CE && CE->getValue() == 0 &&
5051 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005052 // The cc_out operand matches the IT block.
5053 ((inITBlock() != CarrySetting) &&
5054 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005055 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005056 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005057 Operands.erase(Operands.begin() + 5);
5058 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5059 delete Op;
5060 }
5061 }
5062
Chris Lattner98986712010-01-14 22:21:20 +00005063 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005064}
5065
Jim Grosbach189610f2011-07-26 18:25:39 +00005066// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005067
5068// return 'true' if register list contains non-low GPR registers,
5069// 'false' otherwise. If Reg is in the register list or is HiReg, set
5070// 'containsReg' to true.
5071static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5072 unsigned HiReg, bool &containsReg) {
5073 containsReg = false;
5074 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5075 unsigned OpReg = Inst.getOperand(i).getReg();
5076 if (OpReg == Reg)
5077 containsReg = true;
5078 // Anything other than a low register isn't legal here.
5079 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5080 return true;
5081 }
5082 return false;
5083}
5084
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005085// Check if the specified regisgter is in the register list of the inst,
5086// starting at the indicated operand number.
5087static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5088 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5089 unsigned OpReg = Inst.getOperand(i).getReg();
5090 if (OpReg == Reg)
5091 return true;
5092 }
5093 return false;
5094}
5095
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005096// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5097// the ARMInsts array) instead. Getting that here requires awkward
5098// API changes, though. Better way?
5099namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005100extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005101}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005102static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005103 return ARMInsts[Opcode];
5104}
5105
Jim Grosbach189610f2011-07-26 18:25:39 +00005106// FIXME: We would really like to be able to tablegen'erate this.
5107bool ARMAsmParser::
5108validateInstruction(MCInst &Inst,
5109 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005110 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005111 SMLoc Loc = Operands[0]->getStartLoc();
5112 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005113 // NOTE: BKPT instruction has the interesting property of being
5114 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005115 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005116 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5117 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005118 unsigned bit = 1;
5119 if (ITState.FirstCond)
5120 ITState.FirstCond = false;
5121 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005122 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005123 // The instruction must be predicable.
5124 if (!MCID.isPredicable())
5125 return Error(Loc, "instructions in IT block must be predicable");
5126 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5127 unsigned ITCond = bit ? ITState.Cond :
5128 ARMCC::getOppositeCondition(ITState.Cond);
5129 if (Cond != ITCond) {
5130 // Find the condition code Operand to get its SMLoc information.
5131 SMLoc CondLoc;
5132 for (unsigned i = 1; i < Operands.size(); ++i)
5133 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5134 CondLoc = Operands[i]->getStartLoc();
5135 return Error(CondLoc, "incorrect condition in IT block; got '" +
5136 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5137 "', but expected '" +
5138 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5139 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005140 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005141 } else if (isThumbTwo() && MCID.isPredicable() &&
5142 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005143 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5144 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005145 return Error(Loc, "predicated instructions must be in IT block");
5146
Jim Grosbach189610f2011-07-26 18:25:39 +00005147 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005148 case ARM::LDRD:
5149 case ARM::LDRD_PRE:
5150 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005151 case ARM::LDREXD: {
5152 // Rt2 must be Rt + 1.
5153 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5154 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5155 if (Rt2 != Rt + 1)
5156 return Error(Operands[3]->getStartLoc(),
5157 "destination operands must be sequential");
5158 return false;
5159 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005160 case ARM::STRD: {
5161 // Rt2 must be Rt + 1.
5162 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5163 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5164 if (Rt2 != Rt + 1)
5165 return Error(Operands[3]->getStartLoc(),
5166 "source operands must be sequential");
5167 return false;
5168 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005169 case ARM::STRD_PRE:
5170 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005171 case ARM::STREXD: {
5172 // Rt2 must be Rt + 1.
5173 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5174 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5175 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005176 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005177 "source operands must be sequential");
5178 return false;
5179 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005180 case ARM::SBFX:
5181 case ARM::UBFX: {
5182 // width must be in range [1, 32-lsb]
5183 unsigned lsb = Inst.getOperand(2).getImm();
5184 unsigned widthm1 = Inst.getOperand(3).getImm();
5185 if (widthm1 >= 32 - lsb)
5186 return Error(Operands[5]->getStartLoc(),
5187 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005188 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005189 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005190 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005191 // If we're parsing Thumb2, the .w variant is available and handles
5192 // most cases that are normally illegal for a Thumb1 LDM
5193 // instruction. We'll make the transformation in processInstruction()
5194 // if necessary.
5195 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005196 // Thumb LDM instructions are writeback iff the base register is not
5197 // in the register list.
5198 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005199 bool hasWritebackToken =
5200 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5201 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005202 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005203 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005204 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5205 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005206 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005207 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005208 return Error(Operands[2]->getStartLoc(),
5209 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005210 // If we should not have writeback, there must not be a '!'. This is
5211 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005212 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005213 return Error(Operands[3]->getStartLoc(),
5214 "writeback operator '!' not allowed when base register "
5215 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005216
5217 break;
5218 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005219 case ARM::t2LDMIA_UPD: {
5220 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5221 return Error(Operands[4]->getStartLoc(),
5222 "writeback operator '!' not allowed when base register "
5223 "in register list");
5224 break;
5225 }
Jim Grosbach54026372011-11-10 23:17:11 +00005226 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5227 // so only issue a diagnostic for thumb1. The instructions will be
5228 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005229 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005230 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005231 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5232 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005233 return Error(Operands[2]->getStartLoc(),
5234 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005235 break;
5236 }
5237 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005238 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005239 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5240 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005241 return Error(Operands[2]->getStartLoc(),
5242 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005243 break;
5244 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005245 case ARM::tSTMIA_UPD: {
5246 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005247 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005248 return Error(Operands[4]->getStartLoc(),
5249 "registers must be in range r0-r7");
5250 break;
5251 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005252 }
5253
5254 return false;
5255}
5256
Jim Grosbachd7433e22012-01-23 23:45:44 +00005257static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005258 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005259 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005260 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005261 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5262 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5263 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5264 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5265 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5266 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5267 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5268 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5269 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005270
5271 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005272 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5273 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5274 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5275 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5276 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005277
Jim Grosbach7945ead2012-01-24 00:43:12 +00005278 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5279 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5280 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5281 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5282 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005283
Jim Grosbach7945ead2012-01-24 00:43:12 +00005284 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5285 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5286 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5287 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5288 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005289
Jim Grosbach4adb1822012-01-24 00:07:41 +00005290 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005291 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5292 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5293 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5294 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5295 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5296 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5297 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5298 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5299 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5300 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5301 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5302 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5303 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5304 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5305 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005306
Jim Grosbachd7433e22012-01-23 23:45:44 +00005307 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005308 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5309 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5310 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5311 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5312 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5313 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5314 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5315 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5316 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5317 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5318 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5319 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5320 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5321 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5322 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5323 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5324 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5325 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005326
Jim Grosbach88a54de2012-01-24 18:53:13 +00005327 // VST4LN
5328 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5329 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5330 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5331 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5332 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5333 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5334 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5335 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5336 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5337 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5338 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5339 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5340 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5341 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5342 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5343
Jim Grosbach539aab72012-01-24 00:58:13 +00005344 // VST4
5345 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5346 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5347 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5348 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5349 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5350 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5351 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5352 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5353 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5354 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5355 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5356 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5357 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5358 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5359 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5360 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5361 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5362 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005363 }
5364}
5365
Jim Grosbachd7433e22012-01-23 23:45:44 +00005366static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005367 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005368 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005369 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005370 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5371 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5372 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5373 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5374 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5375 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5376 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5377 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5378 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005379
5380 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005381 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5382 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5383 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5384 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5385 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5386 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5387 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5388 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5389 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5390 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5391 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5392 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5393 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5394 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5395 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005396
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005397 // VLD3DUP
5398 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5399 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5400 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5401 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5402 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5403 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5404 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5405 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5406 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5407 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5408 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5409 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5410 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5411 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5412 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5413 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5414 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5415 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5416
Jim Grosbach3a678af2012-01-23 21:53:26 +00005417 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005418 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5419 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5420 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5421 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5422 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5423 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5424 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5425 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5426 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5427 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5428 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5429 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5430 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5431 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5432 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005433
5434 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005435 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5436 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5437 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5438 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5439 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5440 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5441 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5442 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5443 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5444 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5445 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5446 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5447 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5448 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5449 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5450 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5451 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5452 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005453
Jim Grosbache983a132012-01-24 18:37:25 +00005454 // VLD4LN
5455 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5456 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5457 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5458 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5459 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5460 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5461 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5462 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5463 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5464 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5465 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5466 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5467 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5468 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5469 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5470
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005471 // VLD4DUP
5472 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5473 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5474 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5475 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5476 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5477 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5478 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5479 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5480 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5481 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5482 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5483 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5484 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5485 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5486 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5487 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5488 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5489 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5490
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005491 // VLD4
5492 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5493 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5494 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5495 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5496 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5497 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5498 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5499 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5500 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5501 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5502 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5503 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5504 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5505 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5506 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5507 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5508 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5509 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005510 }
5511}
5512
Jim Grosbach83ec8772011-11-10 23:42:14 +00005513bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005514processInstruction(MCInst &Inst,
5515 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5516 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005517 // Aliases for alternate PC+imm syntax of LDR instructions.
5518 case ARM::t2LDRpcrel:
5519 Inst.setOpcode(ARM::t2LDRpci);
5520 return true;
5521 case ARM::t2LDRBpcrel:
5522 Inst.setOpcode(ARM::t2LDRBpci);
5523 return true;
5524 case ARM::t2LDRHpcrel:
5525 Inst.setOpcode(ARM::t2LDRHpci);
5526 return true;
5527 case ARM::t2LDRSBpcrel:
5528 Inst.setOpcode(ARM::t2LDRSBpci);
5529 return true;
5530 case ARM::t2LDRSHpcrel:
5531 Inst.setOpcode(ARM::t2LDRSHpci);
5532 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005533 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005534 case ARM::VST1LNdWB_register_Asm_8:
5535 case ARM::VST1LNdWB_register_Asm_16:
5536 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005537 MCInst TmpInst;
5538 // Shuffle the operands around so the lane index operand is in the
5539 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005540 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005541 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005542 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5543 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5544 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5545 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5546 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5547 TmpInst.addOperand(Inst.getOperand(1)); // lane
5548 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5549 TmpInst.addOperand(Inst.getOperand(6));
5550 Inst = TmpInst;
5551 return true;
5552 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005553
Jim Grosbach8b31f952012-01-23 19:39:08 +00005554 case ARM::VST2LNdWB_register_Asm_8:
5555 case ARM::VST2LNdWB_register_Asm_16:
5556 case ARM::VST2LNdWB_register_Asm_32:
5557 case ARM::VST2LNqWB_register_Asm_16:
5558 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005559 MCInst TmpInst;
5560 // Shuffle the operands around so the lane index operand is in the
5561 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005562 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005563 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005564 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5565 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5566 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5567 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5568 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5570 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005571 TmpInst.addOperand(Inst.getOperand(1)); // lane
5572 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5573 TmpInst.addOperand(Inst.getOperand(6));
5574 Inst = TmpInst;
5575 return true;
5576 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005577
5578 case ARM::VST3LNdWB_register_Asm_8:
5579 case ARM::VST3LNdWB_register_Asm_16:
5580 case ARM::VST3LNdWB_register_Asm_32:
5581 case ARM::VST3LNqWB_register_Asm_16:
5582 case ARM::VST3LNqWB_register_Asm_32: {
5583 MCInst TmpInst;
5584 // Shuffle the operands around so the lane index operand is in the
5585 // right place.
5586 unsigned Spacing;
5587 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5588 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5589 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5590 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5591 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5592 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5594 Spacing));
5595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5596 Spacing * 2));
5597 TmpInst.addOperand(Inst.getOperand(1)); // lane
5598 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5599 TmpInst.addOperand(Inst.getOperand(6));
5600 Inst = TmpInst;
5601 return true;
5602 }
5603
Jim Grosbach88a54de2012-01-24 18:53:13 +00005604 case ARM::VST4LNdWB_register_Asm_8:
5605 case ARM::VST4LNdWB_register_Asm_16:
5606 case ARM::VST4LNdWB_register_Asm_32:
5607 case ARM::VST4LNqWB_register_Asm_16:
5608 case ARM::VST4LNqWB_register_Asm_32: {
5609 MCInst TmpInst;
5610 // Shuffle the operands around so the lane index operand is in the
5611 // right place.
5612 unsigned Spacing;
5613 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5614 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5615 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5616 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5617 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5618 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5620 Spacing));
5621 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5622 Spacing * 2));
5623 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5624 Spacing * 3));
5625 TmpInst.addOperand(Inst.getOperand(1)); // lane
5626 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5627 TmpInst.addOperand(Inst.getOperand(6));
5628 Inst = TmpInst;
5629 return true;
5630 }
5631
Jim Grosbach8b31f952012-01-23 19:39:08 +00005632 case ARM::VST1LNdWB_fixed_Asm_8:
5633 case ARM::VST1LNdWB_fixed_Asm_16:
5634 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005635 MCInst TmpInst;
5636 // Shuffle the operands around so the lane index operand is in the
5637 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005638 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005639 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005640 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5641 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5642 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5643 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5645 TmpInst.addOperand(Inst.getOperand(1)); // lane
5646 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5647 TmpInst.addOperand(Inst.getOperand(5));
5648 Inst = TmpInst;
5649 return true;
5650 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005651
Jim Grosbach8b31f952012-01-23 19:39:08 +00005652 case ARM::VST2LNdWB_fixed_Asm_8:
5653 case ARM::VST2LNdWB_fixed_Asm_16:
5654 case ARM::VST2LNdWB_fixed_Asm_32:
5655 case ARM::VST2LNqWB_fixed_Asm_16:
5656 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005657 MCInst TmpInst;
5658 // Shuffle the operands around so the lane index operand is in the
5659 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005660 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005661 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005662 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5663 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5664 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5665 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5666 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5668 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005669 TmpInst.addOperand(Inst.getOperand(1)); // lane
5670 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5671 TmpInst.addOperand(Inst.getOperand(5));
5672 Inst = TmpInst;
5673 return true;
5674 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005675
5676 case ARM::VST3LNdWB_fixed_Asm_8:
5677 case ARM::VST3LNdWB_fixed_Asm_16:
5678 case ARM::VST3LNdWB_fixed_Asm_32:
5679 case ARM::VST3LNqWB_fixed_Asm_16:
5680 case ARM::VST3LNqWB_fixed_Asm_32: {
5681 MCInst TmpInst;
5682 // Shuffle the operands around so the lane index operand is in the
5683 // right place.
5684 unsigned Spacing;
5685 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5686 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5687 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5688 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5689 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5690 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5692 Spacing));
5693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5694 Spacing * 2));
5695 TmpInst.addOperand(Inst.getOperand(1)); // lane
5696 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5697 TmpInst.addOperand(Inst.getOperand(5));
5698 Inst = TmpInst;
5699 return true;
5700 }
5701
Jim Grosbach88a54de2012-01-24 18:53:13 +00005702 case ARM::VST4LNdWB_fixed_Asm_8:
5703 case ARM::VST4LNdWB_fixed_Asm_16:
5704 case ARM::VST4LNdWB_fixed_Asm_32:
5705 case ARM::VST4LNqWB_fixed_Asm_16:
5706 case ARM::VST4LNqWB_fixed_Asm_32: {
5707 MCInst TmpInst;
5708 // Shuffle the operands around so the lane index operand is in the
5709 // right place.
5710 unsigned Spacing;
5711 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5712 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5713 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5714 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5715 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5718 Spacing));
5719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5720 Spacing * 2));
5721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5722 Spacing * 3));
5723 TmpInst.addOperand(Inst.getOperand(1)); // lane
5724 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5725 TmpInst.addOperand(Inst.getOperand(5));
5726 Inst = TmpInst;
5727 return true;
5728 }
5729
Jim Grosbach8b31f952012-01-23 19:39:08 +00005730 case ARM::VST1LNdAsm_8:
5731 case ARM::VST1LNdAsm_16:
5732 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005733 MCInst TmpInst;
5734 // Shuffle the operands around so the lane index operand is in the
5735 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005736 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005737 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005738 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5739 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5740 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5741 TmpInst.addOperand(Inst.getOperand(1)); // lane
5742 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5743 TmpInst.addOperand(Inst.getOperand(5));
5744 Inst = TmpInst;
5745 return true;
5746 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005747
Jim Grosbach8b31f952012-01-23 19:39:08 +00005748 case ARM::VST2LNdAsm_8:
5749 case ARM::VST2LNdAsm_16:
5750 case ARM::VST2LNdAsm_32:
5751 case ARM::VST2LNqAsm_16:
5752 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005753 MCInst TmpInst;
5754 // Shuffle the operands around so the lane index operand is in the
5755 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005756 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005757 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005758 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5759 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5760 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5762 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005763 TmpInst.addOperand(Inst.getOperand(1)); // lane
5764 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5765 TmpInst.addOperand(Inst.getOperand(5));
5766 Inst = TmpInst;
5767 return true;
5768 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005769
5770 case ARM::VST3LNdAsm_8:
5771 case ARM::VST3LNdAsm_16:
5772 case ARM::VST3LNdAsm_32:
5773 case ARM::VST3LNqAsm_16:
5774 case ARM::VST3LNqAsm_32: {
5775 MCInst TmpInst;
5776 // Shuffle the operands around so the lane index operand is in the
5777 // right place.
5778 unsigned Spacing;
5779 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5780 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5781 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5784 Spacing));
5785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5786 Spacing * 2));
5787 TmpInst.addOperand(Inst.getOperand(1)); // lane
5788 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5789 TmpInst.addOperand(Inst.getOperand(5));
5790 Inst = TmpInst;
5791 return true;
5792 }
5793
Jim Grosbach88a54de2012-01-24 18:53:13 +00005794 case ARM::VST4LNdAsm_8:
5795 case ARM::VST4LNdAsm_16:
5796 case ARM::VST4LNdAsm_32:
5797 case ARM::VST4LNqAsm_16:
5798 case ARM::VST4LNqAsm_32: {
5799 MCInst TmpInst;
5800 // Shuffle the operands around so the lane index operand is in the
5801 // right place.
5802 unsigned Spacing;
5803 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5804 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5805 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5807 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5808 Spacing));
5809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5810 Spacing * 2));
5811 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5812 Spacing * 3));
5813 TmpInst.addOperand(Inst.getOperand(1)); // lane
5814 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5815 TmpInst.addOperand(Inst.getOperand(5));
5816 Inst = TmpInst;
5817 return true;
5818 }
5819
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005820 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005821 case ARM::VLD1LNdWB_register_Asm_8:
5822 case ARM::VLD1LNdWB_register_Asm_16:
5823 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005824 MCInst TmpInst;
5825 // Shuffle the operands around so the lane index operand is in the
5826 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005827 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005828 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005829 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5830 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5831 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5832 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5833 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5834 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5835 TmpInst.addOperand(Inst.getOperand(1)); // lane
5836 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5837 TmpInst.addOperand(Inst.getOperand(6));
5838 Inst = TmpInst;
5839 return true;
5840 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005841
Jim Grosbach8b31f952012-01-23 19:39:08 +00005842 case ARM::VLD2LNdWB_register_Asm_8:
5843 case ARM::VLD2LNdWB_register_Asm_16:
5844 case ARM::VLD2LNdWB_register_Asm_32:
5845 case ARM::VLD2LNqWB_register_Asm_16:
5846 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005847 MCInst TmpInst;
5848 // Shuffle the operands around so the lane index operand is in the
5849 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005850 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005851 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5854 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005855 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5856 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5857 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5858 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5859 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5861 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005862 TmpInst.addOperand(Inst.getOperand(1)); // lane
5863 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5864 TmpInst.addOperand(Inst.getOperand(6));
5865 Inst = TmpInst;
5866 return true;
5867 }
5868
Jim Grosbach3a678af2012-01-23 21:53:26 +00005869 case ARM::VLD3LNdWB_register_Asm_8:
5870 case ARM::VLD3LNdWB_register_Asm_16:
5871 case ARM::VLD3LNdWB_register_Asm_32:
5872 case ARM::VLD3LNqWB_register_Asm_16:
5873 case ARM::VLD3LNqWB_register_Asm_32: {
5874 MCInst TmpInst;
5875 // Shuffle the operands around so the lane index operand is in the
5876 // right place.
5877 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005878 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005879 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5881 Spacing));
5882 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005883 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005884 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5885 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5886 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5887 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5888 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5889 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5890 Spacing));
5891 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005892 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005893 TmpInst.addOperand(Inst.getOperand(1)); // lane
5894 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5895 TmpInst.addOperand(Inst.getOperand(6));
5896 Inst = TmpInst;
5897 return true;
5898 }
5899
Jim Grosbache983a132012-01-24 18:37:25 +00005900 case ARM::VLD4LNdWB_register_Asm_8:
5901 case ARM::VLD4LNdWB_register_Asm_16:
5902 case ARM::VLD4LNdWB_register_Asm_32:
5903 case ARM::VLD4LNqWB_register_Asm_16:
5904 case ARM::VLD4LNqWB_register_Asm_32: {
5905 MCInst TmpInst;
5906 // Shuffle the operands around so the lane index operand is in the
5907 // right place.
5908 unsigned Spacing;
5909 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5910 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5911 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5912 Spacing));
5913 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5914 Spacing * 2));
5915 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5916 Spacing * 3));
5917 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5918 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5919 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5920 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5921 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5922 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5923 Spacing));
5924 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5925 Spacing * 2));
5926 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5927 Spacing * 3));
5928 TmpInst.addOperand(Inst.getOperand(1)); // lane
5929 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5930 TmpInst.addOperand(Inst.getOperand(6));
5931 Inst = TmpInst;
5932 return true;
5933 }
5934
Jim Grosbach8b31f952012-01-23 19:39:08 +00005935 case ARM::VLD1LNdWB_fixed_Asm_8:
5936 case ARM::VLD1LNdWB_fixed_Asm_16:
5937 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005938 MCInst TmpInst;
5939 // Shuffle the operands around so the lane index operand is in the
5940 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005941 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005942 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005943 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5944 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5945 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5946 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5947 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5948 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5949 TmpInst.addOperand(Inst.getOperand(1)); // lane
5950 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5951 TmpInst.addOperand(Inst.getOperand(5));
5952 Inst = TmpInst;
5953 return true;
5954 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005955
Jim Grosbach8b31f952012-01-23 19:39:08 +00005956 case ARM::VLD2LNdWB_fixed_Asm_8:
5957 case ARM::VLD2LNdWB_fixed_Asm_16:
5958 case ARM::VLD2LNdWB_fixed_Asm_32:
5959 case ARM::VLD2LNqWB_fixed_Asm_16:
5960 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005961 MCInst TmpInst;
5962 // Shuffle the operands around so the lane index operand is in the
5963 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005964 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005965 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005966 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005969 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5970 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5971 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5972 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5973 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5975 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005976 TmpInst.addOperand(Inst.getOperand(1)); // lane
5977 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5978 TmpInst.addOperand(Inst.getOperand(5));
5979 Inst = TmpInst;
5980 return true;
5981 }
5982
Jim Grosbach3a678af2012-01-23 21:53:26 +00005983 case ARM::VLD3LNdWB_fixed_Asm_8:
5984 case ARM::VLD3LNdWB_fixed_Asm_16:
5985 case ARM::VLD3LNdWB_fixed_Asm_32:
5986 case ARM::VLD3LNqWB_fixed_Asm_16:
5987 case ARM::VLD3LNqWB_fixed_Asm_32: {
5988 MCInst TmpInst;
5989 // Shuffle the operands around so the lane index operand is in the
5990 // right place.
5991 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005992 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5995 Spacing));
5996 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005997 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005998 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5999 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6000 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6001 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6002 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6003 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6004 Spacing));
6005 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006006 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006007 TmpInst.addOperand(Inst.getOperand(1)); // lane
6008 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6009 TmpInst.addOperand(Inst.getOperand(5));
6010 Inst = TmpInst;
6011 return true;
6012 }
6013
Jim Grosbache983a132012-01-24 18:37:25 +00006014 case ARM::VLD4LNdWB_fixed_Asm_8:
6015 case ARM::VLD4LNdWB_fixed_Asm_16:
6016 case ARM::VLD4LNdWB_fixed_Asm_32:
6017 case ARM::VLD4LNqWB_fixed_Asm_16:
6018 case ARM::VLD4LNqWB_fixed_Asm_32: {
6019 MCInst TmpInst;
6020 // Shuffle the operands around so the lane index operand is in the
6021 // right place.
6022 unsigned Spacing;
6023 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6024 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6025 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6026 Spacing));
6027 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6028 Spacing * 2));
6029 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6030 Spacing * 3));
6031 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6032 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6033 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6034 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6035 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6037 Spacing));
6038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6039 Spacing * 2));
6040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6041 Spacing * 3));
6042 TmpInst.addOperand(Inst.getOperand(1)); // lane
6043 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6044 TmpInst.addOperand(Inst.getOperand(5));
6045 Inst = TmpInst;
6046 return true;
6047 }
6048
Jim Grosbach8b31f952012-01-23 19:39:08 +00006049 case ARM::VLD1LNdAsm_8:
6050 case ARM::VLD1LNdAsm_16:
6051 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006052 MCInst TmpInst;
6053 // Shuffle the operands around so the lane index operand is in the
6054 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006055 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006056 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006057 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6058 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6059 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6060 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6061 TmpInst.addOperand(Inst.getOperand(1)); // lane
6062 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6063 TmpInst.addOperand(Inst.getOperand(5));
6064 Inst = TmpInst;
6065 return true;
6066 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006067
Jim Grosbach8b31f952012-01-23 19:39:08 +00006068 case ARM::VLD2LNdAsm_8:
6069 case ARM::VLD2LNdAsm_16:
6070 case ARM::VLD2LNdAsm_32:
6071 case ARM::VLD2LNqAsm_16:
6072 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006073 MCInst TmpInst;
6074 // Shuffle the operands around so the lane index operand is in the
6075 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006076 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006077 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006078 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006079 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6080 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006081 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6082 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6083 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006086 TmpInst.addOperand(Inst.getOperand(1)); // lane
6087 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6088 TmpInst.addOperand(Inst.getOperand(5));
6089 Inst = TmpInst;
6090 return true;
6091 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006092
6093 case ARM::VLD3LNdAsm_8:
6094 case ARM::VLD3LNdAsm_16:
6095 case ARM::VLD3LNdAsm_32:
6096 case ARM::VLD3LNqAsm_16:
6097 case ARM::VLD3LNqAsm_32: {
6098 MCInst TmpInst;
6099 // Shuffle the operands around so the lane index operand is in the
6100 // right place.
6101 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006102 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006103 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6104 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6105 Spacing));
6106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006107 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006108 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6109 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6110 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6111 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6112 Spacing));
6113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006114 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006115 TmpInst.addOperand(Inst.getOperand(1)); // lane
6116 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6117 TmpInst.addOperand(Inst.getOperand(5));
6118 Inst = TmpInst;
6119 return true;
6120 }
6121
Jim Grosbache983a132012-01-24 18:37:25 +00006122 case ARM::VLD4LNdAsm_8:
6123 case ARM::VLD4LNdAsm_16:
6124 case ARM::VLD4LNdAsm_32:
6125 case ARM::VLD4LNqAsm_16:
6126 case ARM::VLD4LNqAsm_32: {
6127 MCInst TmpInst;
6128 // Shuffle the operands around so the lane index operand is in the
6129 // right place.
6130 unsigned Spacing;
6131 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6132 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6134 Spacing));
6135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 Spacing * 2));
6137 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6138 Spacing * 3));
6139 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6140 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6141 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 Spacing));
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 Spacing * 2));
6146 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6147 Spacing * 3));
6148 TmpInst.addOperand(Inst.getOperand(1)); // lane
6149 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6150 TmpInst.addOperand(Inst.getOperand(5));
6151 Inst = TmpInst;
6152 return true;
6153 }
6154
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006155 // VLD3DUP single 3-element structure to all lanes instructions.
6156 case ARM::VLD3DUPdAsm_8:
6157 case ARM::VLD3DUPdAsm_16:
6158 case ARM::VLD3DUPdAsm_32:
6159 case ARM::VLD3DUPqAsm_8:
6160 case ARM::VLD3DUPqAsm_16:
6161 case ARM::VLD3DUPqAsm_32: {
6162 MCInst TmpInst;
6163 unsigned Spacing;
6164 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6165 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6167 Spacing));
6168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6169 Spacing * 2));
6170 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6171 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6172 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6173 TmpInst.addOperand(Inst.getOperand(4));
6174 Inst = TmpInst;
6175 return true;
6176 }
6177
6178 case ARM::VLD3DUPdWB_fixed_Asm_8:
6179 case ARM::VLD3DUPdWB_fixed_Asm_16:
6180 case ARM::VLD3DUPdWB_fixed_Asm_32:
6181 case ARM::VLD3DUPqWB_fixed_Asm_8:
6182 case ARM::VLD3DUPqWB_fixed_Asm_16:
6183 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6184 MCInst TmpInst;
6185 unsigned Spacing;
6186 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6187 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6188 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6189 Spacing));
6190 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6191 Spacing * 2));
6192 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6193 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6194 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6195 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6196 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6197 TmpInst.addOperand(Inst.getOperand(4));
6198 Inst = TmpInst;
6199 return true;
6200 }
6201
6202 case ARM::VLD3DUPdWB_register_Asm_8:
6203 case ARM::VLD3DUPdWB_register_Asm_16:
6204 case ARM::VLD3DUPdWB_register_Asm_32:
6205 case ARM::VLD3DUPqWB_register_Asm_8:
6206 case ARM::VLD3DUPqWB_register_Asm_16:
6207 case ARM::VLD3DUPqWB_register_Asm_32: {
6208 MCInst TmpInst;
6209 unsigned Spacing;
6210 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6211 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 Spacing));
6214 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6215 Spacing * 2));
6216 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6217 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6218 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6219 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6220 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6221 TmpInst.addOperand(Inst.getOperand(5));
6222 Inst = TmpInst;
6223 return true;
6224 }
6225
Jim Grosbachc387fc62012-01-23 23:20:46 +00006226 // VLD3 multiple 3-element structure instructions.
6227 case ARM::VLD3dAsm_8:
6228 case ARM::VLD3dAsm_16:
6229 case ARM::VLD3dAsm_32:
6230 case ARM::VLD3qAsm_8:
6231 case ARM::VLD3qAsm_16:
6232 case ARM::VLD3qAsm_32: {
6233 MCInst TmpInst;
6234 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006235 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006236 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6237 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6238 Spacing));
6239 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6240 Spacing * 2));
6241 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6242 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6243 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6244 TmpInst.addOperand(Inst.getOperand(4));
6245 Inst = TmpInst;
6246 return true;
6247 }
6248
6249 case ARM::VLD3dWB_fixed_Asm_8:
6250 case ARM::VLD3dWB_fixed_Asm_16:
6251 case ARM::VLD3dWB_fixed_Asm_32:
6252 case ARM::VLD3qWB_fixed_Asm_8:
6253 case ARM::VLD3qWB_fixed_Asm_16:
6254 case ARM::VLD3qWB_fixed_Asm_32: {
6255 MCInst TmpInst;
6256 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006257 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006258 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6259 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6260 Spacing));
6261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6262 Spacing * 2));
6263 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6264 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6265 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6266 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6267 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6268 TmpInst.addOperand(Inst.getOperand(4));
6269 Inst = TmpInst;
6270 return true;
6271 }
6272
6273 case ARM::VLD3dWB_register_Asm_8:
6274 case ARM::VLD3dWB_register_Asm_16:
6275 case ARM::VLD3dWB_register_Asm_32:
6276 case ARM::VLD3qWB_register_Asm_8:
6277 case ARM::VLD3qWB_register_Asm_16:
6278 case ARM::VLD3qWB_register_Asm_32: {
6279 MCInst TmpInst;
6280 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006281 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006282 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6284 Spacing));
6285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6286 Spacing * 2));
6287 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6288 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6289 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6290 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6291 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6292 TmpInst.addOperand(Inst.getOperand(5));
6293 Inst = TmpInst;
6294 return true;
6295 }
6296
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006297 // VLD4DUP single 3-element structure to all lanes instructions.
6298 case ARM::VLD4DUPdAsm_8:
6299 case ARM::VLD4DUPdAsm_16:
6300 case ARM::VLD4DUPdAsm_32:
6301 case ARM::VLD4DUPqAsm_8:
6302 case ARM::VLD4DUPqAsm_16:
6303 case ARM::VLD4DUPqAsm_32: {
6304 MCInst TmpInst;
6305 unsigned Spacing;
6306 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6307 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6308 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 Spacing));
6310 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6311 Spacing * 2));
6312 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6313 Spacing * 3));
6314 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6315 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6316 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6317 TmpInst.addOperand(Inst.getOperand(4));
6318 Inst = TmpInst;
6319 return true;
6320 }
6321
6322 case ARM::VLD4DUPdWB_fixed_Asm_8:
6323 case ARM::VLD4DUPdWB_fixed_Asm_16:
6324 case ARM::VLD4DUPdWB_fixed_Asm_32:
6325 case ARM::VLD4DUPqWB_fixed_Asm_8:
6326 case ARM::VLD4DUPqWB_fixed_Asm_16:
6327 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6328 MCInst TmpInst;
6329 unsigned Spacing;
6330 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6331 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6333 Spacing));
6334 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6335 Spacing * 2));
6336 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6337 Spacing * 3));
6338 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6339 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6340 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6341 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6342 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6343 TmpInst.addOperand(Inst.getOperand(4));
6344 Inst = TmpInst;
6345 return true;
6346 }
6347
6348 case ARM::VLD4DUPdWB_register_Asm_8:
6349 case ARM::VLD4DUPdWB_register_Asm_16:
6350 case ARM::VLD4DUPdWB_register_Asm_32:
6351 case ARM::VLD4DUPqWB_register_Asm_8:
6352 case ARM::VLD4DUPqWB_register_Asm_16:
6353 case ARM::VLD4DUPqWB_register_Asm_32: {
6354 MCInst TmpInst;
6355 unsigned Spacing;
6356 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6357 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6358 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6359 Spacing));
6360 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6361 Spacing * 2));
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing * 3));
6364 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6365 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6366 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6367 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6368 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6369 TmpInst.addOperand(Inst.getOperand(5));
6370 Inst = TmpInst;
6371 return true;
6372 }
6373
6374 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006375 case ARM::VLD4dAsm_8:
6376 case ARM::VLD4dAsm_16:
6377 case ARM::VLD4dAsm_32:
6378 case ARM::VLD4qAsm_8:
6379 case ARM::VLD4qAsm_16:
6380 case ARM::VLD4qAsm_32: {
6381 MCInst TmpInst;
6382 unsigned Spacing;
6383 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6384 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6385 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6386 Spacing));
6387 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6388 Spacing * 2));
6389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6390 Spacing * 3));
6391 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6392 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6393 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6394 TmpInst.addOperand(Inst.getOperand(4));
6395 Inst = TmpInst;
6396 return true;
6397 }
6398
6399 case ARM::VLD4dWB_fixed_Asm_8:
6400 case ARM::VLD4dWB_fixed_Asm_16:
6401 case ARM::VLD4dWB_fixed_Asm_32:
6402 case ARM::VLD4qWB_fixed_Asm_8:
6403 case ARM::VLD4qWB_fixed_Asm_16:
6404 case ARM::VLD4qWB_fixed_Asm_32: {
6405 MCInst TmpInst;
6406 unsigned Spacing;
6407 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6408 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6409 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6410 Spacing));
6411 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6412 Spacing * 2));
6413 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6414 Spacing * 3));
6415 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6416 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6417 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6418 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6419 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6420 TmpInst.addOperand(Inst.getOperand(4));
6421 Inst = TmpInst;
6422 return true;
6423 }
6424
6425 case ARM::VLD4dWB_register_Asm_8:
6426 case ARM::VLD4dWB_register_Asm_16:
6427 case ARM::VLD4dWB_register_Asm_32:
6428 case ARM::VLD4qWB_register_Asm_8:
6429 case ARM::VLD4qWB_register_Asm_16:
6430 case ARM::VLD4qWB_register_Asm_32: {
6431 MCInst TmpInst;
6432 unsigned Spacing;
6433 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6434 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6435 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6436 Spacing));
6437 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6438 Spacing * 2));
6439 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6440 Spacing * 3));
6441 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6442 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6443 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6444 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6445 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6446 TmpInst.addOperand(Inst.getOperand(5));
6447 Inst = TmpInst;
6448 return true;
6449 }
6450
Jim Grosbachd7433e22012-01-23 23:45:44 +00006451 // VST3 multiple 3-element structure instructions.
6452 case ARM::VST3dAsm_8:
6453 case ARM::VST3dAsm_16:
6454 case ARM::VST3dAsm_32:
6455 case ARM::VST3qAsm_8:
6456 case ARM::VST3qAsm_16:
6457 case ARM::VST3qAsm_32: {
6458 MCInst TmpInst;
6459 unsigned Spacing;
6460 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6461 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6462 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6463 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing));
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing * 2));
6468 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6469 TmpInst.addOperand(Inst.getOperand(4));
6470 Inst = TmpInst;
6471 return true;
6472 }
6473
6474 case ARM::VST3dWB_fixed_Asm_8:
6475 case ARM::VST3dWB_fixed_Asm_16:
6476 case ARM::VST3dWB_fixed_Asm_32:
6477 case ARM::VST3qWB_fixed_Asm_8:
6478 case ARM::VST3qWB_fixed_Asm_16:
6479 case ARM::VST3qWB_fixed_Asm_32: {
6480 MCInst TmpInst;
6481 unsigned Spacing;
6482 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6483 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6485 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6486 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6487 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 Spacing));
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 Spacing * 2));
6492 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6493 TmpInst.addOperand(Inst.getOperand(4));
6494 Inst = TmpInst;
6495 return true;
6496 }
6497
6498 case ARM::VST3dWB_register_Asm_8:
6499 case ARM::VST3dWB_register_Asm_16:
6500 case ARM::VST3dWB_register_Asm_32:
6501 case ARM::VST3qWB_register_Asm_8:
6502 case ARM::VST3qWB_register_Asm_16:
6503 case ARM::VST3qWB_register_Asm_32: {
6504 MCInst TmpInst;
6505 unsigned Spacing;
6506 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6507 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6508 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6509 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6510 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6511 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6513 Spacing));
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing * 2));
6516 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6517 TmpInst.addOperand(Inst.getOperand(5));
6518 Inst = TmpInst;
6519 return true;
6520 }
6521
Jim Grosbach539aab72012-01-24 00:58:13 +00006522 // VST4 multiple 3-element structure instructions.
6523 case ARM::VST4dAsm_8:
6524 case ARM::VST4dAsm_16:
6525 case ARM::VST4dAsm_32:
6526 case ARM::VST4qAsm_8:
6527 case ARM::VST4qAsm_16:
6528 case ARM::VST4qAsm_32: {
6529 MCInst TmpInst;
6530 unsigned Spacing;
6531 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6532 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing));
6537 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6538 Spacing * 2));
6539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6540 Spacing * 3));
6541 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6542 TmpInst.addOperand(Inst.getOperand(4));
6543 Inst = TmpInst;
6544 return true;
6545 }
6546
6547 case ARM::VST4dWB_fixed_Asm_8:
6548 case ARM::VST4dWB_fixed_Asm_16:
6549 case ARM::VST4dWB_fixed_Asm_32:
6550 case ARM::VST4qWB_fixed_Asm_8:
6551 case ARM::VST4qWB_fixed_Asm_16:
6552 case ARM::VST4qWB_fixed_Asm_32: {
6553 MCInst TmpInst;
6554 unsigned Spacing;
6555 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6556 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6557 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6558 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6559 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6562 Spacing));
6563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6564 Spacing * 2));
6565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6566 Spacing * 3));
6567 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6568 TmpInst.addOperand(Inst.getOperand(4));
6569 Inst = TmpInst;
6570 return true;
6571 }
6572
6573 case ARM::VST4dWB_register_Asm_8:
6574 case ARM::VST4dWB_register_Asm_16:
6575 case ARM::VST4dWB_register_Asm_32:
6576 case ARM::VST4qWB_register_Asm_8:
6577 case ARM::VST4qWB_register_Asm_16:
6578 case ARM::VST4qWB_register_Asm_32: {
6579 MCInst TmpInst;
6580 unsigned Spacing;
6581 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6582 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6583 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6584 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6585 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6586 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6588 Spacing));
6589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6590 Spacing * 2));
6591 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6592 Spacing * 3));
6593 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6594 TmpInst.addOperand(Inst.getOperand(5));
6595 Inst = TmpInst;
6596 return true;
6597 }
6598
Jim Grosbach863d2af2011-12-13 22:45:11 +00006599 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006600 case ARM::t2MOVsr:
6601 case ARM::t2MOVSsr: {
6602 // Which instruction to expand to depends on the CCOut operand and
6603 // whether we're in an IT block if the register operands are low
6604 // registers.
6605 bool isNarrow = false;
6606 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6607 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6608 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6609 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6610 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6611 isNarrow = true;
6612 MCInst TmpInst;
6613 unsigned newOpc;
6614 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6615 default: llvm_unreachable("unexpected opcode!");
6616 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6617 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6618 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6619 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6620 }
6621 TmpInst.setOpcode(newOpc);
6622 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6623 if (isNarrow)
6624 TmpInst.addOperand(MCOperand::CreateReg(
6625 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6626 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6627 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6628 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6629 TmpInst.addOperand(Inst.getOperand(5));
6630 if (!isNarrow)
6631 TmpInst.addOperand(MCOperand::CreateReg(
6632 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6633 Inst = TmpInst;
6634 return true;
6635 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006636 case ARM::t2MOVsi:
6637 case ARM::t2MOVSsi: {
6638 // Which instruction to expand to depends on the CCOut operand and
6639 // whether we're in an IT block if the register operands are low
6640 // registers.
6641 bool isNarrow = false;
6642 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6643 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6644 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6645 isNarrow = true;
6646 MCInst TmpInst;
6647 unsigned newOpc;
6648 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6649 default: llvm_unreachable("unexpected opcode!");
6650 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6651 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6652 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6653 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006654 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006655 }
6656 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6657 if (Ammount == 32) Ammount = 0;
6658 TmpInst.setOpcode(newOpc);
6659 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6660 if (isNarrow)
6661 TmpInst.addOperand(MCOperand::CreateReg(
6662 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6663 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006664 if (newOpc != ARM::t2RRX)
6665 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006666 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6667 TmpInst.addOperand(Inst.getOperand(4));
6668 if (!isNarrow)
6669 TmpInst.addOperand(MCOperand::CreateReg(
6670 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6671 Inst = TmpInst;
6672 return true;
6673 }
6674 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006675 case ARM::ASRr:
6676 case ARM::LSRr:
6677 case ARM::LSLr:
6678 case ARM::RORr: {
6679 ARM_AM::ShiftOpc ShiftTy;
6680 switch(Inst.getOpcode()) {
6681 default: llvm_unreachable("unexpected opcode!");
6682 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6683 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6684 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6685 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6686 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006687 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6688 MCInst TmpInst;
6689 TmpInst.setOpcode(ARM::MOVsr);
6690 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6691 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6692 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6693 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6694 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6695 TmpInst.addOperand(Inst.getOperand(4));
6696 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6697 Inst = TmpInst;
6698 return true;
6699 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006700 case ARM::ASRi:
6701 case ARM::LSRi:
6702 case ARM::LSLi:
6703 case ARM::RORi: {
6704 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006705 switch(Inst.getOpcode()) {
6706 default: llvm_unreachable("unexpected opcode!");
6707 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6708 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6709 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6710 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6711 }
6712 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006713 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006714 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6715 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006716 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006717 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006718 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006720 if (Opc == ARM::MOVsi)
6721 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006722 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6723 TmpInst.addOperand(Inst.getOperand(4));
6724 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6725 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006726 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006727 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006728 case ARM::RRXi: {
6729 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6730 MCInst TmpInst;
6731 TmpInst.setOpcode(ARM::MOVsi);
6732 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6733 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6734 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6735 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6736 TmpInst.addOperand(Inst.getOperand(3));
6737 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6738 Inst = TmpInst;
6739 return true;
6740 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006741 case ARM::t2LDMIA_UPD: {
6742 // If this is a load of a single register, then we should use
6743 // a post-indexed LDR instruction instead, per the ARM ARM.
6744 if (Inst.getNumOperands() != 5)
6745 return false;
6746 MCInst TmpInst;
6747 TmpInst.setOpcode(ARM::t2LDR_POST);
6748 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6749 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6750 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6751 TmpInst.addOperand(MCOperand::CreateImm(4));
6752 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6753 TmpInst.addOperand(Inst.getOperand(3));
6754 Inst = TmpInst;
6755 return true;
6756 }
6757 case ARM::t2STMDB_UPD: {
6758 // If this is a store of a single register, then we should use
6759 // a pre-indexed STR instruction instead, per the ARM ARM.
6760 if (Inst.getNumOperands() != 5)
6761 return false;
6762 MCInst TmpInst;
6763 TmpInst.setOpcode(ARM::t2STR_PRE);
6764 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6765 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6766 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6767 TmpInst.addOperand(MCOperand::CreateImm(-4));
6768 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6769 TmpInst.addOperand(Inst.getOperand(3));
6770 Inst = TmpInst;
6771 return true;
6772 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006773 case ARM::LDMIA_UPD:
6774 // If this is a load of a single register via a 'pop', then we should use
6775 // a post-indexed LDR instruction instead, per the ARM ARM.
6776 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6777 Inst.getNumOperands() == 5) {
6778 MCInst TmpInst;
6779 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6780 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6781 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6782 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6783 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6784 TmpInst.addOperand(MCOperand::CreateImm(4));
6785 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6786 TmpInst.addOperand(Inst.getOperand(3));
6787 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006788 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006789 }
6790 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006791 case ARM::STMDB_UPD:
6792 // If this is a store of a single register via a 'push', then we should use
6793 // a pre-indexed STR instruction instead, per the ARM ARM.
6794 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6795 Inst.getNumOperands() == 5) {
6796 MCInst TmpInst;
6797 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6798 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6799 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6800 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6801 TmpInst.addOperand(MCOperand::CreateImm(-4));
6802 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6803 TmpInst.addOperand(Inst.getOperand(3));
6804 Inst = TmpInst;
6805 }
6806 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006807 case ARM::t2ADDri12:
6808 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6809 // mnemonic was used (not "addw"), encoding T3 is preferred.
6810 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6811 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6812 break;
6813 Inst.setOpcode(ARM::t2ADDri);
6814 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6815 break;
6816 case ARM::t2SUBri12:
6817 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6818 // mnemonic was used (not "subw"), encoding T3 is preferred.
6819 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6820 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6821 break;
6822 Inst.setOpcode(ARM::t2SUBri);
6823 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6824 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006825 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00006826 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6827 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6828 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6829 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006830 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006831 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006832 return true;
6833 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006834 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00006835 case ARM::tSUBi8:
6836 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6837 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6838 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6839 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006840 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00006841 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006842 return true;
6843 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00006844 break;
Jim Grosbach927b9df2011-12-05 22:16:39 +00006845 case ARM::t2ADDrr: {
6846 // If the destination and first source operand are the same, and
6847 // there's no setting of the flags, use encoding T2 instead of T3.
6848 // Note that this is only for ADD, not SUB. This mirrors the system
6849 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6850 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6851 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00006852 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6853 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00006854 break;
6855 MCInst TmpInst;
6856 TmpInst.setOpcode(ARM::tADDhirr);
6857 TmpInst.addOperand(Inst.getOperand(0));
6858 TmpInst.addOperand(Inst.getOperand(0));
6859 TmpInst.addOperand(Inst.getOperand(2));
6860 TmpInst.addOperand(Inst.getOperand(3));
6861 TmpInst.addOperand(Inst.getOperand(4));
6862 Inst = TmpInst;
6863 return true;
6864 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006865 case ARM::tB:
6866 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006867 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006868 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006869 return true;
6870 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006871 break;
6872 case ARM::t2B:
6873 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006874 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006875 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006876 return true;
6877 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006878 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00006879 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00006880 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006881 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00006882 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006883 return true;
6884 }
Jim Grosbachc0755102011-08-31 21:17:31 +00006885 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00006886 case ARM::tBcc:
6887 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006888 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00006889 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006890 return true;
6891 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00006892 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006893 case ARM::tLDMIA: {
6894 // If the register list contains any high registers, or if the writeback
6895 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
6896 // instead if we're in Thumb2. Otherwise, this should have generated
6897 // an error in validateInstruction().
6898 unsigned Rn = Inst.getOperand(0).getReg();
6899 bool hasWritebackToken =
6900 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6901 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
6902 bool listContainsBase;
6903 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
6904 (!listContainsBase && !hasWritebackToken) ||
6905 (listContainsBase && hasWritebackToken)) {
6906 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6907 assert (isThumbTwo());
6908 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
6909 // If we're switching to the updating version, we need to insert
6910 // the writeback tied operand.
6911 if (hasWritebackToken)
6912 Inst.insert(Inst.begin(),
6913 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006914 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006915 }
6916 break;
6917 }
Jim Grosbach8213c962011-09-16 20:50:13 +00006918 case ARM::tSTMIA_UPD: {
6919 // If the register list contains any high registers, we need to use
6920 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6921 // should have generated an error in validateInstruction().
6922 unsigned Rn = Inst.getOperand(0).getReg();
6923 bool listContainsBase;
6924 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
6925 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6926 assert (isThumbTwo());
6927 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006928 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00006929 }
6930 break;
6931 }
Jim Grosbach54026372011-11-10 23:17:11 +00006932 case ARM::tPOP: {
6933 bool listContainsBase;
6934 // If the register list contains any high registers, we need to use
6935 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6936 // should have generated an error in validateInstruction().
6937 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00006938 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00006939 assert (isThumbTwo());
6940 Inst.setOpcode(ARM::t2LDMIA_UPD);
6941 // Add the base register and writeback operands.
6942 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6943 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006944 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00006945 }
6946 case ARM::tPUSH: {
6947 bool listContainsBase;
6948 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00006949 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00006950 assert (isThumbTwo());
6951 Inst.setOpcode(ARM::t2STMDB_UPD);
6952 // Add the base register and writeback operands.
6953 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6954 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006955 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00006956 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006957 case ARM::t2MOVi: {
6958 // If we can use the 16-bit encoding and the user didn't explicitly
6959 // request the 32-bit variant, transform it here.
6960 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6961 Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00006962 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
6963 Inst.getOperand(4).getReg() == ARM::CPSR) ||
6964 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006965 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6966 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6967 // The operands aren't in the same order for tMOVi8...
6968 MCInst TmpInst;
6969 TmpInst.setOpcode(ARM::tMOVi8);
6970 TmpInst.addOperand(Inst.getOperand(0));
6971 TmpInst.addOperand(Inst.getOperand(4));
6972 TmpInst.addOperand(Inst.getOperand(1));
6973 TmpInst.addOperand(Inst.getOperand(2));
6974 TmpInst.addOperand(Inst.getOperand(3));
6975 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006976 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006977 }
6978 break;
6979 }
6980 case ARM::t2MOVr: {
6981 // If we can use the 16-bit encoding and the user didn't explicitly
6982 // request the 32-bit variant, transform it here.
6983 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6984 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6985 Inst.getOperand(2).getImm() == ARMCC::AL &&
6986 Inst.getOperand(4).getReg() == ARM::CPSR &&
6987 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6988 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6989 // The operands aren't the same for tMOV[S]r... (no cc_out)
6990 MCInst TmpInst;
6991 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
6992 TmpInst.addOperand(Inst.getOperand(0));
6993 TmpInst.addOperand(Inst.getOperand(1));
6994 TmpInst.addOperand(Inst.getOperand(2));
6995 TmpInst.addOperand(Inst.getOperand(3));
6996 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006997 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006998 }
6999 break;
7000 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007001 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007002 case ARM::t2SXTB:
7003 case ARM::t2UXTH:
7004 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007005 // If we can use the 16-bit encoding and the user didn't explicitly
7006 // request the 32-bit variant, transform it here.
7007 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7008 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7009 Inst.getOperand(2).getImm() == 0 &&
7010 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7011 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007012 unsigned NewOpc;
7013 switch (Inst.getOpcode()) {
7014 default: llvm_unreachable("Illegal opcode!");
7015 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7016 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7017 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7018 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7019 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007020 // The operands aren't the same for thumb1 (no rotate operand).
7021 MCInst TmpInst;
7022 TmpInst.setOpcode(NewOpc);
7023 TmpInst.addOperand(Inst.getOperand(0));
7024 TmpInst.addOperand(Inst.getOperand(1));
7025 TmpInst.addOperand(Inst.getOperand(3));
7026 TmpInst.addOperand(Inst.getOperand(4));
7027 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007028 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007029 }
7030 break;
7031 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007032 case ARM::MOVsi: {
7033 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7034 if (SOpc == ARM_AM::rrx) return false;
7035 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7036 // Shifting by zero is accepted as a vanilla 'MOVr'
7037 MCInst TmpInst;
7038 TmpInst.setOpcode(ARM::MOVr);
7039 TmpInst.addOperand(Inst.getOperand(0));
7040 TmpInst.addOperand(Inst.getOperand(1));
7041 TmpInst.addOperand(Inst.getOperand(3));
7042 TmpInst.addOperand(Inst.getOperand(4));
7043 TmpInst.addOperand(Inst.getOperand(5));
7044 Inst = TmpInst;
7045 return true;
7046 }
7047 return false;
7048 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007049 case ARM::ANDrsi:
7050 case ARM::ORRrsi:
7051 case ARM::EORrsi:
7052 case ARM::BICrsi:
7053 case ARM::SUBrsi:
7054 case ARM::ADDrsi: {
7055 unsigned newOpc;
7056 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7057 if (SOpc == ARM_AM::rrx) return false;
7058 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007059 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007060 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7061 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7062 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7063 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7064 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7065 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7066 }
7067 // If the shift is by zero, use the non-shifted instruction definition.
7068 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7069 MCInst TmpInst;
7070 TmpInst.setOpcode(newOpc);
7071 TmpInst.addOperand(Inst.getOperand(0));
7072 TmpInst.addOperand(Inst.getOperand(1));
7073 TmpInst.addOperand(Inst.getOperand(2));
7074 TmpInst.addOperand(Inst.getOperand(4));
7075 TmpInst.addOperand(Inst.getOperand(5));
7076 TmpInst.addOperand(Inst.getOperand(6));
7077 Inst = TmpInst;
7078 return true;
7079 }
7080 return false;
7081 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007082 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007083 case ARM::t2IT: {
7084 // The mask bits for all but the first condition are represented as
7085 // the low bit of the condition code value implies 't'. We currently
7086 // always have 1 implies 't', so XOR toggle the bits if the low bit
7087 // of the condition code is zero. The encoding also expects the low
7088 // bit of the condition to be encoded as bit 4 of the mask operand,
7089 // so mask that in if needed
7090 MCOperand &MO = Inst.getOperand(1);
7091 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007092 unsigned OrigMask = Mask;
7093 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007094 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007095 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7096 for (unsigned i = 3; i != TZ; --i)
7097 Mask ^= 1 << i;
7098 } else
7099 Mask |= 0x10;
7100 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007101
7102 // Set up the IT block state according to the IT instruction we just
7103 // matched.
7104 assert(!inITBlock() && "nested IT blocks?!");
7105 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7106 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7107 ITState.CurPosition = 0;
7108 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007109 break;
7110 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007111 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007112 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007113}
7114
Jim Grosbach47a0d522011-08-16 20:45:50 +00007115unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7116 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7117 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007118 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007119 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007120 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7121 assert(MCID.hasOptionalDef() &&
7122 "optionally flag setting instruction missing optional def operand");
7123 assert(MCID.NumOperands == Inst.getNumOperands() &&
7124 "operand count mismatch!");
7125 // Find the optional-def operand (cc_out).
7126 unsigned OpNo;
7127 for (OpNo = 0;
7128 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7129 ++OpNo)
7130 ;
7131 // If we're parsing Thumb1, reject it completely.
7132 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7133 return Match_MnemonicFail;
7134 // If we're parsing Thumb2, which form is legal depends on whether we're
7135 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007136 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7137 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007138 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007139 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7140 inITBlock())
7141 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007142 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007143 // Some high-register supporting Thumb1 encodings only allow both registers
7144 // to be from r0-r7 when in Thumb2.
7145 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7146 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7147 isARMLowRegister(Inst.getOperand(2).getReg()))
7148 return Match_RequiresThumb2;
7149 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007150 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007151 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7152 isARMLowRegister(Inst.getOperand(1).getReg()))
7153 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007154 return Match_Success;
7155}
7156
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007157bool ARMAsmParser::
7158MatchAndEmitInstruction(SMLoc IDLoc,
7159 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7160 MCStreamer &Out) {
7161 MCInst Inst;
7162 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007163 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007164 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007165 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007166 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007167 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007168 // Context sensitive operand constraints aren't handled by the matcher,
7169 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007170 if (validateInstruction(Inst, Operands)) {
7171 // Still progress the IT block, otherwise one wrong condition causes
7172 // nasty cascading errors.
7173 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007174 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007175 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007176
Jim Grosbachf8fce712011-08-11 17:35:48 +00007177 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007178 // encoding is selected. Loop on it while changes happen so the
7179 // individual transformations can chain off each other. E.g.,
7180 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7181 while (processInstruction(Inst, Operands))
7182 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007183
Jim Grosbacha1109882011-09-02 23:22:08 +00007184 // Only move forward at the very end so that everything in validate
7185 // and process gets a consistent answer about whether we're in an IT
7186 // block.
7187 forwardITPosition();
7188
Jim Grosbach74423e32012-01-25 19:52:01 +00007189 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7190 // doesn't actually encode.
7191 if (Inst.getOpcode() == ARM::ITasm)
7192 return false;
7193
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007194 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007195 Out.EmitInstruction(Inst);
7196 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007197 case Match_MissingFeature:
7198 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
7199 return true;
7200 case Match_InvalidOperand: {
7201 SMLoc ErrorLoc = IDLoc;
7202 if (ErrorInfo != ~0U) {
7203 if (ErrorInfo >= Operands.size())
7204 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007205
Chris Lattnere73d4f82010-10-28 21:41:58 +00007206 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7207 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7208 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007209
Chris Lattnere73d4f82010-10-28 21:41:58 +00007210 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007211 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007212 case Match_MnemonicFail:
Jim Grosbach47a0d522011-08-16 20:45:50 +00007213 return Error(IDLoc, "invalid instruction");
Daniel Dunbarb4129152011-02-04 17:12:23 +00007214 case Match_ConversionFail:
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007215 // The converter function will have already emited a diagnostic.
7216 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007217 case Match_RequiresNotITBlock:
7218 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007219 case Match_RequiresITBlock:
7220 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007221 case Match_RequiresV6:
7222 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7223 case Match_RequiresThumb2:
7224 return Error(IDLoc, "instruction variant requires Thumb2");
Chris Lattnere73d4f82010-10-28 21:41:58 +00007225 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007226
Eric Christopherc223e2b2010-10-29 09:26:59 +00007227 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007228}
7229
Jim Grosbach1355cf12011-07-26 17:10:22 +00007230/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007231bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7232 StringRef IDVal = DirectiveID.getIdentifier();
7233 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007234 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007235 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007236 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007237 else if (IDVal == ".arm")
7238 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007239 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007240 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007241 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007242 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007243 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007244 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007245 else if (IDVal == ".unreq")
7246 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007247 else if (IDVal == ".arch")
7248 return parseDirectiveArch(DirectiveID.getLoc());
7249 else if (IDVal == ".eabi_attribute")
7250 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007251 return true;
7252}
7253
Jim Grosbach1355cf12011-07-26 17:10:22 +00007254/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007255/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007256bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007257 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7258 for (;;) {
7259 const MCExpr *Value;
7260 if (getParser().ParseExpression(Value))
7261 return true;
7262
Chris Lattneraaec2052010-01-19 19:46:13 +00007263 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007264
7265 if (getLexer().is(AsmToken::EndOfStatement))
7266 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007267
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007268 // FIXME: Improve diagnostic.
7269 if (getLexer().isNot(AsmToken::Comma))
7270 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007271 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007272 }
7273 }
7274
Sean Callananb9a25b72010-01-19 20:27:46 +00007275 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007276 return false;
7277}
7278
Jim Grosbach1355cf12011-07-26 17:10:22 +00007279/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007280/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007281bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007282 if (getLexer().isNot(AsmToken::EndOfStatement))
7283 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007284 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007285
Jim Grosbach9a70df92011-12-07 18:04:19 +00007286 if (!isThumb())
7287 SwitchMode();
7288 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7289 return false;
7290}
7291
7292/// parseDirectiveARM
7293/// ::= .arm
7294bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7295 if (getLexer().isNot(AsmToken::EndOfStatement))
7296 return Error(L, "unexpected token in directive");
7297 Parser.Lex();
7298
7299 if (isThumb())
7300 SwitchMode();
7301 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007302 return false;
7303}
7304
Jim Grosbach1355cf12011-07-26 17:10:22 +00007305/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007306/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007307bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007308 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7309 bool isMachO = MAI.hasSubsectionsViaSymbols();
7310 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007311 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007312
Jim Grosbachde4d8392011-12-21 22:30:16 +00007313 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007314 // ELF doesn't
7315 if (isMachO) {
7316 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007317 if (Tok.isNot(AsmToken::EndOfStatement)) {
7318 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7319 return Error(L, "unexpected token in .thumb_func directive");
7320 Name = Tok.getIdentifier();
7321 Parser.Lex(); // Consume the identifier token.
7322 needFuncName = false;
7323 }
Rafael Espindola64695402011-05-16 16:17:21 +00007324 }
7325
Jim Grosbachde4d8392011-12-21 22:30:16 +00007326 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007327 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007328
7329 // Eat the end of statement and any blank lines that follow.
7330 while (getLexer().is(AsmToken::EndOfStatement))
7331 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007332
Rafael Espindola64695402011-05-16 16:17:21 +00007333 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007334 // We really should be checking the next symbol definition even if there's
7335 // stuff in between.
7336 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007337 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007338 }
7339
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007340 // Mark symbol as a thumb symbol.
7341 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7342 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007343 return false;
7344}
7345
Jim Grosbach1355cf12011-07-26 17:10:22 +00007346/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007347/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007348bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007349 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007350 if (Tok.isNot(AsmToken::Identifier))
7351 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007352 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007353 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007354 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007355 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007356 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007357 else
7358 return Error(L, "unrecognized syntax mode in .syntax directive");
7359
7360 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007361 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007362 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007363
7364 // TODO tell the MC streamer the mode
7365 // getParser().getStreamer().Emit???();
7366 return false;
7367}
7368
Jim Grosbach1355cf12011-07-26 17:10:22 +00007369/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007370/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007371bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007372 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007373 if (Tok.isNot(AsmToken::Integer))
7374 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007375 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007376 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007377 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007378 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007379 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007380 else
7381 return Error(L, "invalid operand to .code directive");
7382
7383 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007384 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007385 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007386
Evan Cheng32869202011-07-08 22:36:29 +00007387 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007388 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007389 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007390 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007391 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007392 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007393 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007394 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007395 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007396
Kevin Enderby515d5092009-10-15 20:48:48 +00007397 return false;
7398}
7399
Jim Grosbacha39cda72011-12-14 02:16:11 +00007400/// parseDirectiveReq
7401/// ::= name .req registername
7402bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7403 Parser.Lex(); // Eat the '.req' token.
7404 unsigned Reg;
7405 SMLoc SRegLoc, ERegLoc;
7406 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7407 Parser.EatToEndOfStatement();
7408 return Error(SRegLoc, "register name expected");
7409 }
7410
7411 // Shouldn't be anything else.
7412 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7413 Parser.EatToEndOfStatement();
7414 return Error(Parser.getTok().getLoc(),
7415 "unexpected input in .req directive.");
7416 }
7417
7418 Parser.Lex(); // Consume the EndOfStatement
7419
7420 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7421 return Error(SRegLoc, "redefinition of '" + Name +
7422 "' does not match original.");
7423
7424 return false;
7425}
7426
7427/// parseDirectiveUneq
7428/// ::= .unreq registername
7429bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7430 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7431 Parser.EatToEndOfStatement();
7432 return Error(L, "unexpected input in .unreq directive.");
7433 }
7434 RegisterReqs.erase(Parser.getTok().getIdentifier());
7435 Parser.Lex(); // Eat the identifier.
7436 return false;
7437}
7438
Jason W Kimd7c9e082011-12-20 17:38:12 +00007439/// parseDirectiveArch
7440/// ::= .arch token
7441bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7442 return true;
7443}
7444
7445/// parseDirectiveEabiAttr
7446/// ::= .eabi_attribute int, int
7447bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7448 return true;
7449}
7450
Sean Callanan90b70972010-04-07 20:29:34 +00007451extern "C" void LLVMInitializeARMAsmLexer();
7452
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007453/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007454extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007455 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7456 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007457 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007458}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007459
Chris Lattner0692ee62010-09-06 19:11:01 +00007460#define GET_REGISTER_MATCHER
7461#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007462#include "ARMGenAsmMatcher.inc"