blob: 20454821569d0be4019e1df810bad6bb6cecfa75 [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 Grosbach4661d4c2011-10-21 22:21:10 +00001104 bool isVecListTwoQ() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001105 if (!isDoubleSpacedVectorList()) return false;
1106 return VectorList.Count == 2;
Jim Grosbach4661d4c2011-10-21 22:21:10 +00001107 }
1108
Jim Grosbachc3384c92012-03-05 21:43:40 +00001109 bool isVecListDPairSpaced() const {
1110 if (!isSingleSpacedVectorList()) return false;
1111 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1112 .contains(VectorList.RegNum));
1113 }
1114
Jim Grosbachc387fc62012-01-23 23:20:46 +00001115 bool isVecListThreeQ() const {
1116 if (!isDoubleSpacedVectorList()) return false;
1117 return VectorList.Count == 3;
1118 }
1119
Jim Grosbach7945ead2012-01-24 00:43:12 +00001120 bool isVecListFourQ() const {
1121 if (!isDoubleSpacedVectorList()) return false;
1122 return VectorList.Count == 4;
1123 }
1124
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001125 bool isSingleSpacedVectorAllLanes() const {
1126 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1127 }
1128 bool isDoubleSpacedVectorAllLanes() const {
1129 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1130 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001131 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001132 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001133 return VectorList.Count == 1;
1134 }
1135
Jim Grosbach13af2222011-11-30 18:21:25 +00001136 bool isVecListTwoDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001137 if (!isSingleSpacedVectorAllLanes()) return false;
1138 return VectorList.Count == 2;
1139 }
1140
1141 bool isVecListTwoQAllLanes() const {
1142 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001143 return VectorList.Count == 2;
1144 }
1145
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001146 bool isVecListThreeDAllLanes() const {
1147 if (!isSingleSpacedVectorAllLanes()) return false;
1148 return VectorList.Count == 3;
1149 }
1150
1151 bool isVecListThreeQAllLanes() const {
1152 if (!isDoubleSpacedVectorAllLanes()) return false;
1153 return VectorList.Count == 3;
1154 }
1155
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001156 bool isVecListFourDAllLanes() const {
1157 if (!isSingleSpacedVectorAllLanes()) return false;
1158 return VectorList.Count == 4;
1159 }
1160
1161 bool isVecListFourQAllLanes() const {
1162 if (!isDoubleSpacedVectorAllLanes()) return false;
1163 return VectorList.Count == 4;
1164 }
1165
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001166 bool isSingleSpacedVectorIndexed() const {
1167 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1168 }
1169 bool isDoubleSpacedVectorIndexed() const {
1170 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1171 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001172 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001173 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001174 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1175 }
1176
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001177 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001178 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001179 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1180 }
1181
1182 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001183 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001184 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1185 }
1186
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001187 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001188 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001189 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1190 }
1191
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001192 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001193 if (!isSingleSpacedVectorIndexed()) return false;
1194 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1195 }
1196
1197 bool isVecListTwoQWordIndexed() const {
1198 if (!isDoubleSpacedVectorIndexed()) return false;
1199 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1200 }
1201
1202 bool isVecListTwoQHWordIndexed() const {
1203 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001204 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1205 }
1206
1207 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001208 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001209 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1210 }
1211
Jim Grosbach3a678af2012-01-23 21:53:26 +00001212 bool isVecListThreeDByteIndexed() const {
1213 if (!isSingleSpacedVectorIndexed()) return false;
1214 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1215 }
1216
1217 bool isVecListThreeDHWordIndexed() const {
1218 if (!isSingleSpacedVectorIndexed()) return false;
1219 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1220 }
1221
1222 bool isVecListThreeQWordIndexed() const {
1223 if (!isDoubleSpacedVectorIndexed()) return false;
1224 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1225 }
1226
1227 bool isVecListThreeQHWordIndexed() const {
1228 if (!isDoubleSpacedVectorIndexed()) return false;
1229 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1230 }
1231
1232 bool isVecListThreeDWordIndexed() const {
1233 if (!isSingleSpacedVectorIndexed()) return false;
1234 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1235 }
1236
Jim Grosbache983a132012-01-24 18:37:25 +00001237 bool isVecListFourDByteIndexed() const {
1238 if (!isSingleSpacedVectorIndexed()) return false;
1239 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1240 }
1241
1242 bool isVecListFourDHWordIndexed() const {
1243 if (!isSingleSpacedVectorIndexed()) return false;
1244 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1245 }
1246
1247 bool isVecListFourQWordIndexed() const {
1248 if (!isDoubleSpacedVectorIndexed()) return false;
1249 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1250 }
1251
1252 bool isVecListFourQHWordIndexed() const {
1253 if (!isDoubleSpacedVectorIndexed()) return false;
1254 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1255 }
1256
1257 bool isVecListFourDWordIndexed() const {
1258 if (!isSingleSpacedVectorIndexed()) return false;
1259 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1260 }
1261
Jim Grosbach460a9052011-10-07 23:56:00 +00001262 bool isVectorIndex8() const {
1263 if (Kind != k_VectorIndex) return false;
1264 return VectorIndex.Val < 8;
1265 }
1266 bool isVectorIndex16() const {
1267 if (Kind != k_VectorIndex) return false;
1268 return VectorIndex.Val < 4;
1269 }
1270 bool isVectorIndex32() const {
1271 if (Kind != k_VectorIndex) return false;
1272 return VectorIndex.Val < 2;
1273 }
1274
Jim Grosbach0e387b22011-10-17 22:26:03 +00001275 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001276 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001277 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1278 // Must be a constant.
1279 if (!CE) return false;
1280 int64_t Value = CE->getValue();
1281 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1282 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001283 return Value >= 0 && Value < 256;
1284 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001285
Jim Grosbachea461102011-10-17 23:09:09 +00001286 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001287 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001288 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1289 // Must be a constant.
1290 if (!CE) return false;
1291 int64_t Value = CE->getValue();
1292 // i16 value in the range [0,255] or [0x0100, 0xff00]
1293 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1294 }
1295
Jim Grosbach6248a542011-10-18 00:22:00 +00001296 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001297 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001298 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1299 // Must be a constant.
1300 if (!CE) return false;
1301 int64_t Value = CE->getValue();
1302 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1303 return (Value >= 0 && Value < 256) ||
1304 (Value >= 0x0100 && Value <= 0xff00) ||
1305 (Value >= 0x010000 && Value <= 0xff0000) ||
1306 (Value >= 0x01000000 && Value <= 0xff000000);
1307 }
1308
1309 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001310 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001311 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1312 // Must be a constant.
1313 if (!CE) return false;
1314 int64_t Value = CE->getValue();
1315 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1316 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1317 return (Value >= 0 && Value < 256) ||
1318 (Value >= 0x0100 && Value <= 0xff00) ||
1319 (Value >= 0x010000 && Value <= 0xff0000) ||
1320 (Value >= 0x01000000 && Value <= 0xff000000) ||
1321 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1322 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1323 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001324 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001325 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 // Must be a constant.
1328 if (!CE) return false;
1329 int64_t Value = ~CE->getValue();
1330 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1331 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1332 return (Value >= 0 && Value < 256) ||
1333 (Value >= 0x0100 && Value <= 0xff00) ||
1334 (Value >= 0x010000 && Value <= 0xff0000) ||
1335 (Value >= 0x01000000 && Value <= 0xff000000) ||
1336 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1337 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1338 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001339
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001340 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001341 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001342 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1343 // Must be a constant.
1344 if (!CE) return false;
1345 uint64_t Value = CE->getValue();
1346 // i64 value with each byte being either 0 or 0xff.
1347 for (unsigned i = 0; i < 8; ++i)
1348 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1349 return true;
1350 }
1351
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001352 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001353 // Add as immediates when possible. Null MCExpr = 0.
1354 if (Expr == 0)
1355 Inst.addOperand(MCOperand::CreateImm(0));
1356 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001357 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1358 else
1359 Inst.addOperand(MCOperand::CreateExpr(Expr));
1360 }
1361
Daniel Dunbar8462b302010-08-11 06:36:53 +00001362 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001363 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001364 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001365 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1366 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001367 }
1368
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001369 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1370 assert(N == 1 && "Invalid number of operands!");
1371 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1372 }
1373
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001374 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1375 assert(N == 1 && "Invalid number of operands!");
1376 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1377 }
1378
1379 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1380 assert(N == 1 && "Invalid number of operands!");
1381 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1382 }
1383
Jim Grosbach89df9962011-08-26 21:43:41 +00001384 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1385 assert(N == 1 && "Invalid number of operands!");
1386 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1387 }
1388
1389 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1390 assert(N == 1 && "Invalid number of operands!");
1391 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1392 }
1393
Jim Grosbachd67641b2010-12-06 18:21:12 +00001394 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1395 assert(N == 1 && "Invalid number of operands!");
1396 Inst.addOperand(MCOperand::CreateReg(getReg()));
1397 }
1398
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001399 void addRegOperands(MCInst &Inst, unsigned N) const {
1400 assert(N == 1 && "Invalid number of operands!");
1401 Inst.addOperand(MCOperand::CreateReg(getReg()));
1402 }
1403
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001404 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001405 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001406 assert(isRegShiftedReg() &&
1407 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001408 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1409 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001410 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001411 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001412 }
1413
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001414 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001415 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001416 assert(isRegShiftedImm() &&
1417 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001418 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Owen Anderson92a20222011-07-21 18:54:16 +00001419 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001420 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, RegShiftedImm.ShiftImm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001421 }
1422
Jim Grosbach580f4a92011-07-25 22:20:28 +00001423 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001424 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001425 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1426 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001427 }
1428
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001429 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001430 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001431 const SmallVectorImpl<unsigned> &RegList = getRegList();
1432 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001433 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1434 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001435 }
1436
Bill Wendling0f630752010-11-17 04:32:08 +00001437 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1438 addRegListOperands(Inst, N);
1439 }
1440
1441 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1442 addRegListOperands(Inst, N);
1443 }
1444
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001445 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1446 assert(N == 1 && "Invalid number of operands!");
1447 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1448 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1449 }
1450
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001451 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1452 assert(N == 1 && "Invalid number of operands!");
1453 // Munge the lsb/width into a bitfield mask.
1454 unsigned lsb = Bitfield.LSB;
1455 unsigned width = Bitfield.Width;
1456 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1457 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1458 (32 - (lsb + width)));
1459 Inst.addOperand(MCOperand::CreateImm(Mask));
1460 }
1461
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001462 void addImmOperands(MCInst &Inst, unsigned N) const {
1463 assert(N == 1 && "Invalid number of operands!");
1464 addExpr(Inst, getImm());
1465 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001466
Jim Grosbach4050bc42011-12-22 22:19:05 +00001467 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1468 assert(N == 1 && "Invalid number of operands!");
1469 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1470 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1471 }
1472
1473 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1474 assert(N == 1 && "Invalid number of operands!");
1475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1476 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1477 }
1478
Jim Grosbach9d390362011-10-03 23:38:36 +00001479 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1480 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001481 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1482 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1483 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001484 }
1485
Jim Grosbacha77295d2011-09-08 22:07:06 +00001486 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1487 assert(N == 1 && "Invalid number of operands!");
1488 // FIXME: We really want to scale the value here, but the LDRD/STRD
1489 // instruction don't encode operands that way yet.
1490 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1491 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1492 }
1493
Jim Grosbach72f39f82011-08-24 21:22:15 +00001494 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1495 assert(N == 1 && "Invalid number of operands!");
1496 // The immediate is scaled by four in the encoding and is stored
1497 // in the MCInst as such. Lop off the low two bits here.
1498 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1499 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1500 }
1501
1502 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 // The immediate is scaled by four in the encoding and is stored
1505 // in the MCInst as such. Lop off the low two bits here.
1506 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1507 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1508 }
1509
Jim Grosbachf4943352011-07-25 23:09:14 +00001510 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1511 assert(N == 1 && "Invalid number of operands!");
1512 // The constant encodes as the immediate-1, and we store in the instruction
1513 // the bits as encoded, so subtract off one here.
1514 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1515 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1516 }
1517
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001518 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1519 assert(N == 1 && "Invalid number of operands!");
1520 // The constant encodes as the immediate-1, and we store in the instruction
1521 // the bits as encoded, so subtract off one here.
1522 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1523 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1524 }
1525
Jim Grosbach70939ee2011-08-17 21:51:27 +00001526 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1527 assert(N == 1 && "Invalid number of operands!");
1528 // The constant encodes as the immediate, except for 32, which encodes as
1529 // zero.
1530 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1531 unsigned Imm = CE->getValue();
1532 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1533 }
1534
Jim Grosbachf6c05252011-07-21 17:23:04 +00001535 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1536 assert(N == 1 && "Invalid number of operands!");
1537 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1538 // the instruction as well.
1539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1540 int Val = CE->getValue();
1541 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1542 }
1543
Jim Grosbach89a63372011-10-28 22:36:30 +00001544 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1545 assert(N == 1 && "Invalid number of operands!");
1546 // The operand is actually a t2_so_imm, but we have its bitwise
1547 // negation in the assembly source, so twiddle it here.
1548 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1549 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1550 }
1551
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001552 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1553 assert(N == 1 && "Invalid number of operands!");
1554 // The operand is actually a t2_so_imm, but we have its
1555 // negation in the assembly source, so twiddle it here.
1556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1557 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1558 }
1559
Jim Grosbache70ec842011-10-28 22:50:54 +00001560 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1561 assert(N == 1 && "Invalid number of operands!");
1562 // The operand is actually a so_imm, but we have its bitwise
1563 // negation in the assembly source, so twiddle it here.
1564 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1565 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1566 }
1567
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001568 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1569 assert(N == 1 && "Invalid number of operands!");
1570 // The operand is actually a so_imm, but we have its
1571 // negation in the assembly source, so twiddle it here.
1572 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1573 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1574 }
1575
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001576 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1577 assert(N == 1 && "Invalid number of operands!");
1578 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1579 }
1580
Jim Grosbach7ce05792011-08-03 23:50:40 +00001581 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1582 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001583 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001584 }
1585
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001586 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1587 assert(N == 1 && "Invalid number of operands!");
1588 int32_t Imm = Memory.OffsetImm->getValue();
1589 // FIXME: Handle #-0
1590 if (Imm == INT32_MIN) Imm = 0;
1591 Inst.addOperand(MCOperand::CreateImm(Imm));
1592 }
1593
Jim Grosbach57dcb852011-10-11 17:29:55 +00001594 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1595 assert(N == 2 && "Invalid number of operands!");
1596 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1597 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1598 }
1599
Jim Grosbach7ce05792011-08-03 23:50:40 +00001600 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1601 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001602 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1603 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001604 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1605 // Special case for #-0
1606 if (Val == INT32_MIN) Val = 0;
1607 if (Val < 0) Val = -Val;
1608 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1609 } else {
1610 // For register offset, we encode the shift type and negation flag
1611 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001612 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1613 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001614 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001615 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1616 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001617 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001618 }
1619
Jim Grosbach039c2e12011-08-04 23:01:30 +00001620 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1621 assert(N == 2 && "Invalid number of operands!");
1622 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1623 assert(CE && "non-constant AM2OffsetImm operand!");
1624 int32_t Val = CE->getValue();
1625 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1626 // Special case for #-0
1627 if (Val == INT32_MIN) Val = 0;
1628 if (Val < 0) Val = -Val;
1629 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1630 Inst.addOperand(MCOperand::CreateReg(0));
1631 Inst.addOperand(MCOperand::CreateImm(Val));
1632 }
1633
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001634 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1635 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001636 // If we have an immediate that's not a constant, treat it as a label
1637 // reference needing a fixup. If it is a constant, it's something else
1638 // and we reject it.
1639 if (isImm()) {
1640 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1641 Inst.addOperand(MCOperand::CreateReg(0));
1642 Inst.addOperand(MCOperand::CreateImm(0));
1643 return;
1644 }
1645
Jim Grosbache53c87b2011-10-11 15:59:20 +00001646 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1647 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001648 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1649 // Special case for #-0
1650 if (Val == INT32_MIN) Val = 0;
1651 if (Val < 0) Val = -Val;
1652 Val = ARM_AM::getAM3Opc(AddSub, Val);
1653 } else {
1654 // For register offset, we encode the shift type and negation flag
1655 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001656 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001657 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001658 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1659 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001660 Inst.addOperand(MCOperand::CreateImm(Val));
1661 }
1662
1663 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1664 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001665 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001666 int32_t Val =
1667 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1668 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1669 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001670 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001671 }
1672
1673 // Constant offset.
1674 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1675 int32_t Val = CE->getValue();
1676 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1677 // Special case for #-0
1678 if (Val == INT32_MIN) Val = 0;
1679 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001680 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001681 Inst.addOperand(MCOperand::CreateReg(0));
1682 Inst.addOperand(MCOperand::CreateImm(Val));
1683 }
1684
Jim Grosbach7ce05792011-08-03 23:50:40 +00001685 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1686 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001687 // If we have an immediate that's not a constant, treat it as a label
1688 // reference needing a fixup. If it is a constant, it's something else
1689 // and we reject it.
1690 if (isImm()) {
1691 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1692 Inst.addOperand(MCOperand::CreateImm(0));
1693 return;
1694 }
1695
Jim Grosbach7ce05792011-08-03 23:50:40 +00001696 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001697 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001698 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1699 // Special case for #-0
1700 if (Val == INT32_MIN) Val = 0;
1701 if (Val < 0) Val = -Val;
1702 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001703 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001704 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001705 }
1706
Jim Grosbacha77295d2011-09-08 22:07:06 +00001707 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001709 // If we have an immediate that's not a constant, treat it as a label
1710 // reference needing a fixup. If it is a constant, it's something else
1711 // and we reject it.
1712 if (isImm()) {
1713 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1714 Inst.addOperand(MCOperand::CreateImm(0));
1715 return;
1716 }
1717
Jim Grosbache53c87b2011-10-11 15:59:20 +00001718 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1719 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001720 Inst.addOperand(MCOperand::CreateImm(Val));
1721 }
1722
Jim Grosbachb6aed502011-09-09 18:37:27 +00001723 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1724 assert(N == 2 && "Invalid number of operands!");
1725 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001726 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1727 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001728 Inst.addOperand(MCOperand::CreateImm(Val));
1729 }
1730
Jim Grosbach7ce05792011-08-03 23:50:40 +00001731 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1732 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001733 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1734 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001735 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001736 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001737
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001738 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1739 addMemImm8OffsetOperands(Inst, N);
1740 }
1741
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001742 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001743 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001744 }
1745
1746 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 2 && "Invalid number of operands!");
1748 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001749 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001750 addExpr(Inst, getImm());
1751 Inst.addOperand(MCOperand::CreateImm(0));
1752 return;
1753 }
1754
1755 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001756 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1757 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001758 Inst.addOperand(MCOperand::CreateImm(Val));
1759 }
1760
Jim Grosbach7ce05792011-08-03 23:50:40 +00001761 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1762 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001763 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001764 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001765 addExpr(Inst, getImm());
1766 Inst.addOperand(MCOperand::CreateImm(0));
1767 return;
1768 }
1769
1770 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001771 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1772 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001773 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001774 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001775
Jim Grosbach7f739be2011-09-19 22:21:13 +00001776 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1777 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001778 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1779 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001780 }
1781
1782 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001784 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1785 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001786 }
1787
Jim Grosbach7ce05792011-08-03 23:50:40 +00001788 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1789 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001790 unsigned Val =
1791 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1792 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001793 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1794 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001795 Inst.addOperand(MCOperand::CreateImm(Val));
1796 }
1797
Jim Grosbachab899c12011-09-07 23:10:15 +00001798 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1799 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001800 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1801 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1802 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001803 }
1804
Jim Grosbach7ce05792011-08-03 23:50:40 +00001805 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1806 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001807 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1808 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001809 }
1810
Jim Grosbach60f91a32011-08-19 17:55:24 +00001811 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1812 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001813 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1814 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001815 Inst.addOperand(MCOperand::CreateImm(Val));
1816 }
1817
Jim Grosbach38466302011-08-19 18:55:51 +00001818 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1819 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001820 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1821 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001822 Inst.addOperand(MCOperand::CreateImm(Val));
1823 }
1824
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001825 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1826 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001827 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1828 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001829 Inst.addOperand(MCOperand::CreateImm(Val));
1830 }
1831
Jim Grosbachecd85892011-08-19 18:13:48 +00001832 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1833 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001834 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1835 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001836 Inst.addOperand(MCOperand::CreateImm(Val));
1837 }
1838
Jim Grosbach7ce05792011-08-03 23:50:40 +00001839 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1840 assert(N == 1 && "Invalid number of operands!");
1841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1842 assert(CE && "non-constant post-idx-imm8 operand!");
1843 int Imm = CE->getValue();
1844 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001845 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001846 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1847 Inst.addOperand(MCOperand::CreateImm(Imm));
1848 }
1849
Jim Grosbach2bd01182011-10-11 21:55:36 +00001850 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1853 assert(CE && "non-constant post-idx-imm8s4 operand!");
1854 int Imm = CE->getValue();
1855 bool isAdd = Imm >= 0;
1856 if (Imm == INT32_MIN) Imm = 0;
1857 // Immediate is scaled by 4.
1858 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1859 Inst.addOperand(MCOperand::CreateImm(Imm));
1860 }
1861
Jim Grosbach7ce05792011-08-03 23:50:40 +00001862 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1863 assert(N == 2 && "Invalid number of operands!");
1864 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001865 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1866 }
1867
1868 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 2 && "Invalid number of operands!");
1870 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1871 // The sign, shift type, and shift amount are encoded in a single operand
1872 // using the AM2 encoding helpers.
1873 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1874 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1875 PostIdxReg.ShiftTy);
1876 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001877 }
1878
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001879 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1880 assert(N == 1 && "Invalid number of operands!");
1881 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1882 }
1883
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001884 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 1 && "Invalid number of operands!");
1886 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1887 }
1888
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001889 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001890 assert(N == 1 && "Invalid number of operands!");
1891 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1892 }
1893
Jim Grosbach7636bf62011-12-02 00:35:16 +00001894 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
1896 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1897 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1898 }
1899
Jim Grosbach460a9052011-10-07 23:56:00 +00001900 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
1902 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1903 }
1904
1905 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1906 assert(N == 1 && "Invalid number of operands!");
1907 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1908 }
1909
1910 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1911 assert(N == 1 && "Invalid number of operands!");
1912 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1913 }
1914
Jim Grosbach0e387b22011-10-17 22:26:03 +00001915 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1916 assert(N == 1 && "Invalid number of operands!");
1917 // The immediate encodes the type of constant as well as the value.
1918 // Mask in that this is an i8 splat.
1919 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1920 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
1921 }
1922
Jim Grosbachea461102011-10-17 23:09:09 +00001923 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
1924 assert(N == 1 && "Invalid number of operands!");
1925 // The immediate encodes the type of constant as well as the value.
1926 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1927 unsigned Value = CE->getValue();
1928 if (Value >= 256)
1929 Value = (Value >> 8) | 0xa00;
1930 else
1931 Value |= 0x800;
1932 Inst.addOperand(MCOperand::CreateImm(Value));
1933 }
1934
Jim Grosbach6248a542011-10-18 00:22:00 +00001935 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
1936 assert(N == 1 && "Invalid number of operands!");
1937 // The immediate encodes the type of constant as well as the value.
1938 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1939 unsigned Value = CE->getValue();
1940 if (Value >= 256 && Value <= 0xff00)
1941 Value = (Value >> 8) | 0x200;
1942 else if (Value > 0xffff && Value <= 0xff0000)
1943 Value = (Value >> 16) | 0x400;
1944 else if (Value > 0xffffff)
1945 Value = (Value >> 24) | 0x600;
1946 Inst.addOperand(MCOperand::CreateImm(Value));
1947 }
1948
1949 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
1950 assert(N == 1 && "Invalid number of operands!");
1951 // The immediate encodes the type of constant as well as the value.
1952 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1953 unsigned Value = CE->getValue();
1954 if (Value >= 256 && Value <= 0xffff)
1955 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1956 else if (Value > 0xffff && Value <= 0xffffff)
1957 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1958 else if (Value > 0xffffff)
1959 Value = (Value >> 24) | 0x600;
1960 Inst.addOperand(MCOperand::CreateImm(Value));
1961 }
1962
Jim Grosbach9b087852011-12-19 23:51:07 +00001963 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
1964 assert(N == 1 && "Invalid number of operands!");
1965 // The immediate encodes the type of constant as well as the value.
1966 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1967 unsigned Value = ~CE->getValue();
1968 if (Value >= 256 && Value <= 0xffff)
1969 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
1970 else if (Value > 0xffff && Value <= 0xffffff)
1971 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
1972 else if (Value > 0xffffff)
1973 Value = (Value >> 24) | 0x600;
1974 Inst.addOperand(MCOperand::CreateImm(Value));
1975 }
1976
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001977 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 1 && "Invalid number of operands!");
1979 // The immediate encodes the type of constant as well as the value.
1980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1981 uint64_t Value = CE->getValue();
1982 unsigned Imm = 0;
1983 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
1984 Imm |= (Value & 1) << i;
1985 }
1986 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
1987 }
1988
Jim Grosbachb7f689b2011-07-13 15:34:57 +00001989 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00001990
Jim Grosbach89df9962011-08-26 21:43:41 +00001991 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001992 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00001993 Op->ITMask.Mask = Mask;
1994 Op->StartLoc = S;
1995 Op->EndLoc = S;
1996 return Op;
1997 }
1998
Chris Lattner3a697562010-10-28 17:20:03 +00001999 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002000 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002001 Op->CC.Val = CC;
2002 Op->StartLoc = S;
2003 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002004 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002005 }
2006
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002007 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002008 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002009 Op->Cop.Val = CopVal;
2010 Op->StartLoc = S;
2011 Op->EndLoc = S;
2012 return Op;
2013 }
2014
2015 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002016 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002017 Op->Cop.Val = CopVal;
2018 Op->StartLoc = S;
2019 Op->EndLoc = S;
2020 return Op;
2021 }
2022
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002023 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2024 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2025 Op->Cop.Val = Val;
2026 Op->StartLoc = S;
2027 Op->EndLoc = E;
2028 return Op;
2029 }
2030
Jim Grosbachd67641b2010-12-06 18:21:12 +00002031 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002032 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002033 Op->Reg.RegNum = RegNum;
2034 Op->StartLoc = S;
2035 Op->EndLoc = S;
2036 return Op;
2037 }
2038
Chris Lattner3a697562010-10-28 17:20:03 +00002039 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002040 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002041 Op->Tok.Data = Str.data();
2042 Op->Tok.Length = Str.size();
2043 Op->StartLoc = S;
2044 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002045 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002046 }
2047
Bill Wendling50d0f582010-11-18 23:43:05 +00002048 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002049 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002050 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002051 Op->StartLoc = S;
2052 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002053 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002054 }
2055
Jim Grosbache8606dc2011-07-13 17:50:29 +00002056 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2057 unsigned SrcReg,
2058 unsigned ShiftReg,
2059 unsigned ShiftImm,
2060 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002061 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002062 Op->RegShiftedReg.ShiftTy = ShTy;
2063 Op->RegShiftedReg.SrcReg = SrcReg;
2064 Op->RegShiftedReg.ShiftReg = ShiftReg;
2065 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002066 Op->StartLoc = S;
2067 Op->EndLoc = E;
2068 return Op;
2069 }
2070
Owen Anderson92a20222011-07-21 18:54:16 +00002071 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2072 unsigned SrcReg,
2073 unsigned ShiftImm,
2074 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002075 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002076 Op->RegShiftedImm.ShiftTy = ShTy;
2077 Op->RegShiftedImm.SrcReg = SrcReg;
2078 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002079 Op->StartLoc = S;
2080 Op->EndLoc = E;
2081 return Op;
2082 }
2083
Jim Grosbach580f4a92011-07-25 22:20:28 +00002084 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002085 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002086 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002087 Op->ShifterImm.isASR = isASR;
2088 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002089 Op->StartLoc = S;
2090 Op->EndLoc = E;
2091 return Op;
2092 }
2093
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002094 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002095 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002096 Op->RotImm.Imm = Imm;
2097 Op->StartLoc = S;
2098 Op->EndLoc = E;
2099 return Op;
2100 }
2101
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002102 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2103 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002104 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002105 Op->Bitfield.LSB = LSB;
2106 Op->Bitfield.Width = Width;
2107 Op->StartLoc = S;
2108 Op->EndLoc = E;
2109 return Op;
2110 }
2111
Bill Wendling7729e062010-11-09 22:44:22 +00002112 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002113 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002114 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002115 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002116
Jim Grosbachd300b942011-09-13 22:56:44 +00002117 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002118 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002119 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002120 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002121 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002122
2123 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002124 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002125 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002126 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002127 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002128 Op->StartLoc = StartLoc;
2129 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002130 return Op;
2131 }
2132
Jim Grosbach862019c2011-10-18 23:02:30 +00002133 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002134 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002135 ARMOperand *Op = new ARMOperand(k_VectorList);
2136 Op->VectorList.RegNum = RegNum;
2137 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002138 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002139 Op->StartLoc = S;
2140 Op->EndLoc = E;
2141 return Op;
2142 }
2143
Jim Grosbach98b05a52011-11-30 01:09:44 +00002144 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002145 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002146 SMLoc S, SMLoc E) {
2147 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2148 Op->VectorList.RegNum = RegNum;
2149 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002150 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002151 Op->StartLoc = S;
2152 Op->EndLoc = E;
2153 return Op;
2154 }
2155
Jim Grosbach7636bf62011-12-02 00:35:16 +00002156 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002157 unsigned Index,
2158 bool isDoubleSpaced,
2159 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002160 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2161 Op->VectorList.RegNum = RegNum;
2162 Op->VectorList.Count = Count;
2163 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002164 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002165 Op->StartLoc = S;
2166 Op->EndLoc = E;
2167 return Op;
2168 }
2169
Jim Grosbach460a9052011-10-07 23:56:00 +00002170 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2171 MCContext &Ctx) {
2172 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2173 Op->VectorIndex.Val = Idx;
2174 Op->StartLoc = S;
2175 Op->EndLoc = E;
2176 return Op;
2177 }
2178
Chris Lattner3a697562010-10-28 17:20:03 +00002179 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002180 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002181 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002182 Op->StartLoc = S;
2183 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002184 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002185 }
2186
Jim Grosbach7ce05792011-08-03 23:50:40 +00002187 static ARMOperand *CreateMem(unsigned BaseRegNum,
2188 const MCConstantExpr *OffsetImm,
2189 unsigned OffsetRegNum,
2190 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002191 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002192 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002193 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002194 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002195 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002196 Op->Memory.BaseRegNum = BaseRegNum;
2197 Op->Memory.OffsetImm = OffsetImm;
2198 Op->Memory.OffsetRegNum = OffsetRegNum;
2199 Op->Memory.ShiftType = ShiftType;
2200 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002201 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002202 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002203 Op->StartLoc = S;
2204 Op->EndLoc = E;
2205 return Op;
2206 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002207
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002208 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2209 ARM_AM::ShiftOpc ShiftTy,
2210 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002211 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002212 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002213 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002214 Op->PostIdxReg.isAdd = isAdd;
2215 Op->PostIdxReg.ShiftTy = ShiftTy;
2216 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002217 Op->StartLoc = S;
2218 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002219 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002220 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002221
2222 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002223 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002224 Op->MBOpt.Val = Opt;
2225 Op->StartLoc = S;
2226 Op->EndLoc = S;
2227 return Op;
2228 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002229
2230 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002231 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002232 Op->IFlags.Val = IFlags;
2233 Op->StartLoc = S;
2234 Op->EndLoc = S;
2235 return Op;
2236 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002237
2238 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002239 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002240 Op->MMask.Val = MMask;
2241 Op->StartLoc = S;
2242 Op->EndLoc = S;
2243 return Op;
2244 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002245};
2246
2247} // end anonymous namespace.
2248
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002249void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002250 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002251 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002252 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002253 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002254 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002255 OS << "<ccout " << getReg() << ">";
2256 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002257 case k_ITCondMask: {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002258 static const char *MaskStr[] = {
2259 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2260 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2261 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002262 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2263 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2264 break;
2265 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002266 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002267 OS << "<coprocessor number: " << getCoproc() << ">";
2268 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002269 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002270 OS << "<coprocessor register: " << getCoproc() << ">";
2271 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002272 case k_CoprocOption:
2273 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2274 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002275 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002276 OS << "<mask: " << getMSRMask() << ">";
2277 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002278 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002279 getImm()->print(OS);
2280 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002281 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002282 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2283 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002284 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002285 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002286 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002287 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002288 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002289 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002290 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2291 << PostIdxReg.RegNum;
2292 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2293 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2294 << PostIdxReg.ShiftImm;
2295 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002296 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002297 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002298 OS << "<ARM_PROC::";
2299 unsigned IFlags = getProcIFlags();
2300 for (int i=2; i >= 0; --i)
2301 if (IFlags & (1 << i))
2302 OS << ARM_PROC::IFlagsToString(1 << i);
2303 OS << ">";
2304 break;
2305 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002306 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002307 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002308 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002309 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002310 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2311 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002312 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002313 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002314 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002315 << RegShiftedReg.SrcReg << " "
2316 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2317 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002318 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002319 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002320 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002321 << RegShiftedImm.SrcReg << " "
2322 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2323 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002324 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002325 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002326 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2327 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002328 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002329 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2330 << ", width: " << Bitfield.Width << ">";
2331 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002332 case k_RegisterList:
2333 case k_DPRRegisterList:
2334 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002335 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002336
Bill Wendling5fa22a12010-11-09 23:28:44 +00002337 const SmallVectorImpl<unsigned> &RegList = getRegList();
2338 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002339 I = RegList.begin(), E = RegList.end(); I != E; ) {
2340 OS << *I;
2341 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002342 }
2343
2344 OS << ">";
2345 break;
2346 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002347 case k_VectorList:
2348 OS << "<vector_list " << VectorList.Count << " * "
2349 << VectorList.RegNum << ">";
2350 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002351 case k_VectorListAllLanes:
2352 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2353 << VectorList.RegNum << ">";
2354 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002355 case k_VectorListIndexed:
2356 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2357 << VectorList.Count << " * " << VectorList.RegNum << ">";
2358 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002359 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002360 OS << "'" << getToken() << "'";
2361 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002362 case k_VectorIndex:
2363 OS << "<vectorindex " << getVectorIndex() << ">";
2364 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002365 }
2366}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002367
2368/// @name Auto-generated Match Functions
2369/// {
2370
2371static unsigned MatchRegisterName(StringRef Name);
2372
2373/// }
2374
Bob Wilson69df7232011-02-03 21:46:10 +00002375bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2376 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002377 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002378 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002379 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002380
2381 return (RegNo == (unsigned)-1);
2382}
2383
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002384/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002385/// and if it is a register name the token is eaten and the register number is
2386/// returned. Otherwise return -1.
2387///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002388int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002389 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002390 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002391
Benjamin Kramer59085362011-11-06 20:37:06 +00002392 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002393 unsigned RegNum = MatchRegisterName(lowerCase);
2394 if (!RegNum) {
2395 RegNum = StringSwitch<unsigned>(lowerCase)
2396 .Case("r13", ARM::SP)
2397 .Case("r14", ARM::LR)
2398 .Case("r15", ARM::PC)
2399 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002400 // Additional register name aliases for 'gas' compatibility.
2401 .Case("a1", ARM::R0)
2402 .Case("a2", ARM::R1)
2403 .Case("a3", ARM::R2)
2404 .Case("a4", ARM::R3)
2405 .Case("v1", ARM::R4)
2406 .Case("v2", ARM::R5)
2407 .Case("v3", ARM::R6)
2408 .Case("v4", ARM::R7)
2409 .Case("v5", ARM::R8)
2410 .Case("v6", ARM::R9)
2411 .Case("v7", ARM::R10)
2412 .Case("v8", ARM::R11)
2413 .Case("sb", ARM::R9)
2414 .Case("sl", ARM::R10)
2415 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002416 .Default(0);
2417 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002418 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002419 // Check for aliases registered via .req. Canonicalize to lower case.
2420 // That's more consistent since register names are case insensitive, and
2421 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2422 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002423 // If no match, return failure.
2424 if (Entry == RegisterReqs.end())
2425 return -1;
2426 Parser.Lex(); // Eat identifier token.
2427 return Entry->getValue();
2428 }
Bob Wilson69df7232011-02-03 21:46:10 +00002429
Chris Lattnere5658fa2010-10-30 04:09:10 +00002430 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002431
Chris Lattnere5658fa2010-10-30 04:09:10 +00002432 return RegNum;
2433}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002434
Jim Grosbach19906722011-07-13 18:49:30 +00002435// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2436// If a recoverable error occurs, return 1. If an irrecoverable error
2437// occurs, return -1. An irrecoverable error is one where tokens have been
2438// consumed in the process of trying to parse the shifter (i.e., when it is
2439// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002440int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002441 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2442 SMLoc S = Parser.getTok().getLoc();
2443 const AsmToken &Tok = Parser.getTok();
2444 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2445
Benjamin Kramer59085362011-11-06 20:37:06 +00002446 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002447 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002448 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002449 .Case("lsl", ARM_AM::lsl)
2450 .Case("lsr", ARM_AM::lsr)
2451 .Case("asr", ARM_AM::asr)
2452 .Case("ror", ARM_AM::ror)
2453 .Case("rrx", ARM_AM::rrx)
2454 .Default(ARM_AM::no_shift);
2455
2456 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002457 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002458
Jim Grosbache8606dc2011-07-13 17:50:29 +00002459 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002460
Jim Grosbache8606dc2011-07-13 17:50:29 +00002461 // The source register for the shift has already been added to the
2462 // operand list, so we need to pop it off and combine it into the shifted
2463 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002464 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002465 if (!PrevOp->isReg())
2466 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2467 int SrcReg = PrevOp->getReg();
2468 int64_t Imm = 0;
2469 int ShiftReg = 0;
2470 if (ShiftTy == ARM_AM::rrx) {
2471 // RRX Doesn't have an explicit shift amount. The encoder expects
2472 // the shift register to be the same as the source register. Seems odd,
2473 // but OK.
2474 ShiftReg = SrcReg;
2475 } else {
2476 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002477 if (Parser.getTok().is(AsmToken::Hash) ||
2478 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002479 Parser.Lex(); // Eat hash.
2480 SMLoc ImmLoc = Parser.getTok().getLoc();
2481 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002482 if (getParser().ParseExpression(ShiftExpr)) {
2483 Error(ImmLoc, "invalid immediate shift value");
2484 return -1;
2485 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002486 // The expression must be evaluatable as an immediate.
2487 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002488 if (!CE) {
2489 Error(ImmLoc, "invalid immediate shift value");
2490 return -1;
2491 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002492 // Range check the immediate.
2493 // lsl, ror: 0 <= imm <= 31
2494 // lsr, asr: 0 <= imm <= 32
2495 Imm = CE->getValue();
2496 if (Imm < 0 ||
2497 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2498 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002499 Error(ImmLoc, "immediate shift value out of range");
2500 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002501 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002502 // shift by zero is a nop. Always send it through as lsl.
2503 // ('as' compatibility)
2504 if (Imm == 0)
2505 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002506 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002507 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002508 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002509 if (ShiftReg == -1) {
2510 Error (L, "expected immediate or register in shift operand");
2511 return -1;
2512 }
2513 } else {
2514 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002515 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002516 return -1;
2517 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002518 }
2519
Owen Anderson92a20222011-07-21 18:54:16 +00002520 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2521 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002522 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002523 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002524 else
2525 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2526 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002527
Jim Grosbach19906722011-07-13 18:49:30 +00002528 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002529}
2530
2531
Bill Wendling50d0f582010-11-18 23:43:05 +00002532/// Try to parse a register name. The token must be an Identifier when called.
2533/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2534/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002535///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002536/// TODO this is likely to change to allow different register types and or to
2537/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002538bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002539tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002540 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002541 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002542 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002543 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002544
Bill Wendling50d0f582010-11-18 23:43:05 +00002545 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002546
Chris Lattnere5658fa2010-10-30 04:09:10 +00002547 const AsmToken &ExclaimTok = Parser.getTok();
2548 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002549 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2550 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002551 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002552 return false;
2553 }
2554
2555 // Also check for an index operand. This is only legal for vector registers,
2556 // but that'll get caught OK in operand matching, so we don't need to
2557 // explicitly filter everything else out here.
2558 if (Parser.getTok().is(AsmToken::LBrac)) {
2559 SMLoc SIdx = Parser.getTok().getLoc();
2560 Parser.Lex(); // Eat left bracket token.
2561
2562 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002563 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002564 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002565 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002566 if (!MCE)
2567 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002568
2569 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002570 if (Parser.getTok().isNot(AsmToken::RBrac))
2571 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002572
2573 Parser.Lex(); // Eat right bracket token.
2574
2575 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2576 SIdx, E,
2577 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002578 }
2579
Bill Wendling50d0f582010-11-18 23:43:05 +00002580 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002581}
2582
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002583/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2584/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2585/// "c5", ...
2586static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002587 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2588 // but efficient.
2589 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002590 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002591 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002592 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002593 return -1;
2594 switch (Name[1]) {
2595 default: return -1;
2596 case '0': return 0;
2597 case '1': return 1;
2598 case '2': return 2;
2599 case '3': return 3;
2600 case '4': return 4;
2601 case '5': return 5;
2602 case '6': return 6;
2603 case '7': return 7;
2604 case '8': return 8;
2605 case '9': return 9;
2606 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002607 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002608 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002609 return -1;
2610 switch (Name[2]) {
2611 default: return -1;
2612 case '0': return 10;
2613 case '1': return 11;
2614 case '2': return 12;
2615 case '3': return 13;
2616 case '4': return 14;
2617 case '5': return 15;
2618 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002619 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002620}
2621
Jim Grosbach89df9962011-08-26 21:43:41 +00002622/// parseITCondCode - Try to parse a condition code for an IT instruction.
2623ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2624parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2625 SMLoc S = Parser.getTok().getLoc();
2626 const AsmToken &Tok = Parser.getTok();
2627 if (!Tok.is(AsmToken::Identifier))
2628 return MatchOperand_NoMatch;
2629 unsigned CC = StringSwitch<unsigned>(Tok.getString())
2630 .Case("eq", ARMCC::EQ)
2631 .Case("ne", ARMCC::NE)
2632 .Case("hs", ARMCC::HS)
2633 .Case("cs", ARMCC::HS)
2634 .Case("lo", ARMCC::LO)
2635 .Case("cc", ARMCC::LO)
2636 .Case("mi", ARMCC::MI)
2637 .Case("pl", ARMCC::PL)
2638 .Case("vs", ARMCC::VS)
2639 .Case("vc", ARMCC::VC)
2640 .Case("hi", ARMCC::HI)
2641 .Case("ls", ARMCC::LS)
2642 .Case("ge", ARMCC::GE)
2643 .Case("lt", ARMCC::LT)
2644 .Case("gt", ARMCC::GT)
2645 .Case("le", ARMCC::LE)
2646 .Case("al", ARMCC::AL)
2647 .Default(~0U);
2648 if (CC == ~0U)
2649 return MatchOperand_NoMatch;
2650 Parser.Lex(); // Eat the token.
2651
2652 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2653
2654 return MatchOperand_Success;
2655}
2656
Jim Grosbach43904292011-07-25 20:14:50 +00002657/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002658/// token must be an Identifier when called, and if it is a coprocessor
2659/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002660ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002661parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002662 SMLoc S = Parser.getTok().getLoc();
2663 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002664 if (Tok.isNot(AsmToken::Identifier))
2665 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002666
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002667 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002668 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002669 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002670
2671 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002672 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002673 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002674}
2675
Jim Grosbach43904292011-07-25 20:14:50 +00002676/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002677/// token must be an Identifier when called, and if it is a coprocessor
2678/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002679ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002680parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002681 SMLoc S = Parser.getTok().getLoc();
2682 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002683 if (Tok.isNot(AsmToken::Identifier))
2684 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002685
2686 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2687 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002688 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002689
2690 Parser.Lex(); // Eat identifier token.
2691 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002692 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002693}
2694
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002695/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2696/// coproc_option : '{' imm0_255 '}'
2697ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2698parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2699 SMLoc S = Parser.getTok().getLoc();
2700
2701 // If this isn't a '{', this isn't a coprocessor immediate operand.
2702 if (Parser.getTok().isNot(AsmToken::LCurly))
2703 return MatchOperand_NoMatch;
2704 Parser.Lex(); // Eat the '{'
2705
2706 const MCExpr *Expr;
2707 SMLoc Loc = Parser.getTok().getLoc();
2708 if (getParser().ParseExpression(Expr)) {
2709 Error(Loc, "illegal expression");
2710 return MatchOperand_ParseFail;
2711 }
2712 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2713 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2714 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2715 return MatchOperand_ParseFail;
2716 }
2717 int Val = CE->getValue();
2718
2719 // Check for and consume the closing '}'
2720 if (Parser.getTok().isNot(AsmToken::RCurly))
2721 return MatchOperand_ParseFail;
2722 SMLoc E = Parser.getTok().getLoc();
2723 Parser.Lex(); // Eat the '}'
2724
2725 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2726 return MatchOperand_Success;
2727}
2728
Jim Grosbachd0588e22011-09-14 18:08:35 +00002729// For register list parsing, we need to map from raw GPR register numbering
2730// to the enumeration values. The enumeration values aren't sorted by
2731// register number due to our using "sp", "lr" and "pc" as canonical names.
2732static unsigned getNextRegister(unsigned Reg) {
2733 // If this is a GPR, we need to do it manually, otherwise we can rely
2734 // on the sort ordering of the enumeration since the other reg-classes
2735 // are sane.
2736 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2737 return Reg + 1;
2738 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002739 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002740 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2741 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2742 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2743 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2744 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2745 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2746 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2747 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2748 }
2749}
2750
Jim Grosbachce485e72011-11-11 21:27:40 +00002751// Return the low-subreg of a given Q register.
2752static unsigned getDRegFromQReg(unsigned QReg) {
2753 switch (QReg) {
2754 default: llvm_unreachable("expected a Q register!");
2755 case ARM::Q0: return ARM::D0;
2756 case ARM::Q1: return ARM::D2;
2757 case ARM::Q2: return ARM::D4;
2758 case ARM::Q3: return ARM::D6;
2759 case ARM::Q4: return ARM::D8;
2760 case ARM::Q5: return ARM::D10;
2761 case ARM::Q6: return ARM::D12;
2762 case ARM::Q7: return ARM::D14;
2763 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002764 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002765 case ARM::Q10: return ARM::D20;
2766 case ARM::Q11: return ARM::D22;
2767 case ARM::Q12: return ARM::D24;
2768 case ARM::Q13: return ARM::D26;
2769 case ARM::Q14: return ARM::D28;
2770 case ARM::Q15: return ARM::D30;
2771 }
2772}
2773
Jim Grosbachd0588e22011-09-14 18:08:35 +00002774/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002775bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002776parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002777 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002778 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002779 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002780 Parser.Lex(); // Eat '{' token.
2781 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002782
Jim Grosbachd0588e22011-09-14 18:08:35 +00002783 // Check the first register in the list to see what register class
2784 // this is a list of.
2785 int Reg = tryParseRegister();
2786 if (Reg == -1)
2787 return Error(RegLoc, "register expected");
2788
Jim Grosbachce485e72011-11-11 21:27:40 +00002789 // The reglist instructions have at most 16 registers, so reserve
2790 // space for that many.
2791 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2792
2793 // Allow Q regs and just interpret them as the two D sub-registers.
2794 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2795 Reg = getDRegFromQReg(Reg);
2796 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2797 ++Reg;
2798 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002799 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002800 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2801 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2802 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2803 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2804 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2805 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2806 else
2807 return Error(RegLoc, "invalid register in register list");
2808
Jim Grosbachce485e72011-11-11 21:27:40 +00002809 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002810 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002811
Jim Grosbachd0588e22011-09-14 18:08:35 +00002812 // This starts immediately after the first register token in the list,
2813 // so we can see either a comma or a minus (range separator) as a legal
2814 // next token.
2815 while (Parser.getTok().is(AsmToken::Comma) ||
2816 Parser.getTok().is(AsmToken::Minus)) {
2817 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002818 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002819 SMLoc EndLoc = Parser.getTok().getLoc();
2820 int EndReg = tryParseRegister();
2821 if (EndReg == -1)
2822 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002823 // Allow Q regs and just interpret them as the two D sub-registers.
2824 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2825 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002826 // If the register is the same as the start reg, there's nothing
2827 // more to do.
2828 if (Reg == EndReg)
2829 continue;
2830 // The register must be in the same register class as the first.
2831 if (!RC->contains(EndReg))
2832 return Error(EndLoc, "invalid register in register list");
2833 // Ranges must go from low to high.
2834 if (getARMRegisterNumbering(Reg) > getARMRegisterNumbering(EndReg))
2835 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002836
Jim Grosbachd0588e22011-09-14 18:08:35 +00002837 // Add all the registers in the range to the register list.
2838 while (Reg != EndReg) {
2839 Reg = getNextRegister(Reg);
2840 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2841 }
2842 continue;
2843 }
2844 Parser.Lex(); // Eat the comma.
2845 RegLoc = Parser.getTok().getLoc();
2846 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002847 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002848 Reg = tryParseRegister();
2849 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002850 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002851 // Allow Q regs and just interpret them as the two D sub-registers.
2852 bool isQReg = false;
2853 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2854 Reg = getDRegFromQReg(Reg);
2855 isQReg = true;
2856 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002857 // The register must be in the same register class as the first.
2858 if (!RC->contains(Reg))
2859 return Error(RegLoc, "invalid register in register list");
2860 // List must be monotonically increasing.
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002861 if (getARMRegisterNumbering(Reg) < getARMRegisterNumbering(OldReg))
Jim Grosbachd0588e22011-09-14 18:08:35 +00002862 return Error(RegLoc, "register list not in ascending order");
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,
2984 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
2985
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002986 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002987 break;
2988 case AllLanes:
2989 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002990 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
2991 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00002992 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002993 case IndexedLane:
2994 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002995 LaneIndex,
2996 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00002997 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002998 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00002999 return MatchOperand_Success;
3000 }
3001 Error(S, "vector register expected");
3002 return MatchOperand_ParseFail;
3003 }
3004
3005 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003006 return MatchOperand_NoMatch;
3007
Jim Grosbach862019c2011-10-18 23:02:30 +00003008 Parser.Lex(); // Eat '{' token.
3009 SMLoc RegLoc = Parser.getTok().getLoc();
3010
3011 int Reg = tryParseRegister();
3012 if (Reg == -1) {
3013 Error(RegLoc, "register expected");
3014 return MatchOperand_ParseFail;
3015 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003016 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003017 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003018 unsigned FirstReg = Reg;
3019 // The list is of D registers, but we also allow Q regs and just interpret
3020 // them as the two D sub-registers.
3021 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3022 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003023 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3024 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003025 ++Reg;
3026 ++Count;
3027 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003028 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003029 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003030
Jim Grosbache43862b2011-11-15 23:19:15 +00003031 while (Parser.getTok().is(AsmToken::Comma) ||
3032 Parser.getTok().is(AsmToken::Minus)) {
3033 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003034 if (!Spacing)
3035 Spacing = 1; // Register range implies a single spaced list.
3036 else if (Spacing == 2) {
3037 Error(Parser.getTok().getLoc(),
3038 "sequential registers in double spaced list");
3039 return MatchOperand_ParseFail;
3040 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003041 Parser.Lex(); // Eat the minus.
3042 SMLoc EndLoc = Parser.getTok().getLoc();
3043 int EndReg = tryParseRegister();
3044 if (EndReg == -1) {
3045 Error(EndLoc, "register expected");
3046 return MatchOperand_ParseFail;
3047 }
3048 // Allow Q regs and just interpret them as the two D sub-registers.
3049 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3050 EndReg = getDRegFromQReg(EndReg) + 1;
3051 // If the register is the same as the start reg, there's nothing
3052 // more to do.
3053 if (Reg == EndReg)
3054 continue;
3055 // The register must be in the same register class as the first.
3056 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3057 Error(EndLoc, "invalid register in register list");
3058 return MatchOperand_ParseFail;
3059 }
3060 // Ranges must go from low to high.
3061 if (Reg > EndReg) {
3062 Error(EndLoc, "bad range in register list");
3063 return MatchOperand_ParseFail;
3064 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003065 // Parse the lane specifier if present.
3066 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003067 unsigned NextLaneIndex;
3068 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003069 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003070 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003071 Error(EndLoc, "mismatched lane index in register list");
3072 return MatchOperand_ParseFail;
3073 }
3074 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003075
3076 // Add all the registers in the range to the register list.
3077 Count += EndReg - Reg;
3078 Reg = EndReg;
3079 continue;
3080 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003081 Parser.Lex(); // Eat the comma.
3082 RegLoc = Parser.getTok().getLoc();
3083 int OldReg = Reg;
3084 Reg = tryParseRegister();
3085 if (Reg == -1) {
3086 Error(RegLoc, "register expected");
3087 return MatchOperand_ParseFail;
3088 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003089 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003090 // It's OK to use the enumeration values directly here rather, as the
3091 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003092 //
3093 // The list is of D registers, but we also allow Q regs and just interpret
3094 // them as the two D sub-registers.
3095 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003096 if (!Spacing)
3097 Spacing = 1; // Register range implies a single spaced list.
3098 else if (Spacing == 2) {
3099 Error(RegLoc,
3100 "invalid register in double-spaced list (must be 'D' register')");
3101 return MatchOperand_ParseFail;
3102 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003103 Reg = getDRegFromQReg(Reg);
3104 if (Reg != OldReg + 1) {
3105 Error(RegLoc, "non-contiguous register range");
3106 return MatchOperand_ParseFail;
3107 }
3108 ++Reg;
3109 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003110 // Parse the lane specifier if present.
3111 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003112 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003113 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003114 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003115 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003116 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003117 Error(EndLoc, "mismatched lane index in register list");
3118 return MatchOperand_ParseFail;
3119 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003120 continue;
3121 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003122 // Normal D register.
3123 // Figure out the register spacing (single or double) of the list if
3124 // we don't know it already.
3125 if (!Spacing)
3126 Spacing = 1 + (Reg == OldReg + 2);
3127
3128 // Just check that it's contiguous and keep going.
3129 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003130 Error(RegLoc, "non-contiguous register range");
3131 return MatchOperand_ParseFail;
3132 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003133 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003134 // Parse the lane specifier if present.
3135 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003136 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003137 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003138 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003139 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003140 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003141 Error(EndLoc, "mismatched lane index in register list");
3142 return MatchOperand_ParseFail;
3143 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003144 }
3145
3146 SMLoc E = Parser.getTok().getLoc();
3147 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3148 Error(E, "'}' expected");
3149 return MatchOperand_ParseFail;
3150 }
3151 Parser.Lex(); // Eat '}' token.
3152
Jim Grosbach98b05a52011-11-30 01:09:44 +00003153 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003154 case NoLanes:
Jim Grosbachc3384c92012-03-05 21:43:40 +00003155 // Non-lane two-register operands have been converted to the
3156 // composite register classes.
3157 if (Count == 2) {
3158 const MCRegisterClass *RC = (Spacing == 1) ?
3159 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3160 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3161 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3162 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003163
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003164 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3165 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003166 break;
3167 case AllLanes:
3168 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003169 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003170 S, E));
3171 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003172 case IndexedLane:
3173 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003174 LaneIndex,
3175 (Spacing == 2),
3176 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003177 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003178 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003179 return MatchOperand_Success;
3180}
3181
Jim Grosbach43904292011-07-25 20:14:50 +00003182/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003183ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003184parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003185 SMLoc S = Parser.getTok().getLoc();
3186 const AsmToken &Tok = Parser.getTok();
3187 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3188 StringRef OptStr = Tok.getString();
3189
3190 unsigned Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()))
3191 .Case("sy", ARM_MB::SY)
3192 .Case("st", ARM_MB::ST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003193 .Case("sh", ARM_MB::ISH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003194 .Case("ish", ARM_MB::ISH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003195 .Case("shst", ARM_MB::ISHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003196 .Case("ishst", ARM_MB::ISHST)
3197 .Case("nsh", ARM_MB::NSH)
Jim Grosbach032434d2011-07-13 23:40:38 +00003198 .Case("un", ARM_MB::NSH)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003199 .Case("nshst", ARM_MB::NSHST)
Jim Grosbach032434d2011-07-13 23:40:38 +00003200 .Case("unst", ARM_MB::NSHST)
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003201 .Case("osh", ARM_MB::OSH)
3202 .Case("oshst", ARM_MB::OSHST)
3203 .Default(~0U);
3204
3205 if (Opt == ~0U)
Jim Grosbachf922c472011-02-12 01:34:40 +00003206 return MatchOperand_NoMatch;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003207
3208 Parser.Lex(); // Eat identifier token.
3209 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003210 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003211}
3212
Jim Grosbach43904292011-07-25 20:14:50 +00003213/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003214ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003215parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003216 SMLoc S = Parser.getTok().getLoc();
3217 const AsmToken &Tok = Parser.getTok();
3218 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3219 StringRef IFlagsStr = Tok.getString();
3220
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003221 // An iflags string of "none" is interpreted to mean that none of the AIF
3222 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003223 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003224 if (IFlagsStr != "none") {
3225 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3226 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3227 .Case("a", ARM_PROC::A)
3228 .Case("i", ARM_PROC::I)
3229 .Case("f", ARM_PROC::F)
3230 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003231
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003232 // If some specific iflag is already set, it means that some letter is
3233 // present more than once, this is not acceptable.
3234 if (Flag == ~0U || (IFlags & Flag))
3235 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003236
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003237 IFlags |= Flag;
3238 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003239 }
3240
3241 Parser.Lex(); // Eat identifier token.
3242 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3243 return MatchOperand_Success;
3244}
3245
Jim Grosbach43904292011-07-25 20:14:50 +00003246/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003247ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003248parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003249 SMLoc S = Parser.getTok().getLoc();
3250 const AsmToken &Tok = Parser.getTok();
3251 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3252 StringRef Mask = Tok.getString();
3253
James Molloyacad68d2011-09-28 14:21:38 +00003254 if (isMClass()) {
3255 // See ARMv6-M 10.1.1
3256 unsigned FlagsVal = StringSwitch<unsigned>(Mask)
3257 .Case("apsr", 0)
3258 .Case("iapsr", 1)
3259 .Case("eapsr", 2)
3260 .Case("xpsr", 3)
3261 .Case("ipsr", 5)
3262 .Case("epsr", 6)
3263 .Case("iepsr", 7)
3264 .Case("msp", 8)
3265 .Case("psp", 9)
3266 .Case("primask", 16)
3267 .Case("basepri", 17)
3268 .Case("basepri_max", 18)
3269 .Case("faultmask", 19)
3270 .Case("control", 20)
3271 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003272
James Molloyacad68d2011-09-28 14:21:38 +00003273 if (FlagsVal == ~0U)
3274 return MatchOperand_NoMatch;
3275
3276 if (!hasV7Ops() && FlagsVal >= 17 && FlagsVal <= 19)
3277 // basepri, basepri_max and faultmask only valid for V7m.
3278 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003279
James Molloyacad68d2011-09-28 14:21:38 +00003280 Parser.Lex(); // Eat identifier token.
3281 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3282 return MatchOperand_Success;
3283 }
3284
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003285 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3286 size_t Start = 0, Next = Mask.find('_');
3287 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003288 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003289 if (Next != StringRef::npos)
3290 Flags = Mask.slice(Next+1, Mask.size());
3291
3292 // FlagsVal contains the complete mask:
3293 // 3-0: Mask
3294 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3295 unsigned FlagsVal = 0;
3296
3297 if (SpecReg == "apsr") {
3298 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003299 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003300 .Case("g", 0x4) // same as CPSR_s
3301 .Case("nzcvqg", 0xc) // same as CPSR_fs
3302 .Default(~0U);
3303
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003304 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003305 if (!Flags.empty())
3306 return MatchOperand_NoMatch;
3307 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003308 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003309 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003310 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003311 if (Flags == "all") // cpsr_all is an alias for cpsr_fc
3312 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003313 for (int i = 0, e = Flags.size(); i != e; ++i) {
3314 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3315 .Case("c", 1)
3316 .Case("x", 2)
3317 .Case("s", 4)
3318 .Case("f", 8)
3319 .Default(~0U);
3320
3321 // If some specific flag is already set, it means that some letter is
3322 // present more than once, this is not acceptable.
3323 if (FlagsVal == ~0U || (FlagsVal & Flag))
3324 return MatchOperand_NoMatch;
3325 FlagsVal |= Flag;
3326 }
3327 } else // No match for special register.
3328 return MatchOperand_NoMatch;
3329
Owen Anderson7784f1d2011-10-21 18:43:28 +00003330 // Special register without flags is NOT equivalent to "fc" flags.
3331 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3332 // two lines would enable gas compatibility at the expense of breaking
3333 // round-tripping.
3334 //
3335 // if (!FlagsVal)
3336 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003337
3338 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3339 if (SpecReg == "spsr")
3340 FlagsVal |= 16;
3341
3342 Parser.Lex(); // Eat identifier token.
3343 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3344 return MatchOperand_Success;
3345}
3346
Jim Grosbachf6c05252011-07-21 17:23:04 +00003347ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3348parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3349 int Low, int High) {
3350 const AsmToken &Tok = Parser.getTok();
3351 if (Tok.isNot(AsmToken::Identifier)) {
3352 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3353 return MatchOperand_ParseFail;
3354 }
3355 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003356 std::string LowerOp = Op.lower();
3357 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003358 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3359 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3360 return MatchOperand_ParseFail;
3361 }
3362 Parser.Lex(); // Eat shift type token.
3363
3364 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003365 if (Parser.getTok().isNot(AsmToken::Hash) &&
3366 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003367 Error(Parser.getTok().getLoc(), "'#' expected");
3368 return MatchOperand_ParseFail;
3369 }
3370 Parser.Lex(); // Eat hash token.
3371
3372 const MCExpr *ShiftAmount;
3373 SMLoc Loc = Parser.getTok().getLoc();
3374 if (getParser().ParseExpression(ShiftAmount)) {
3375 Error(Loc, "illegal expression");
3376 return MatchOperand_ParseFail;
3377 }
3378 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3379 if (!CE) {
3380 Error(Loc, "constant expression expected");
3381 return MatchOperand_ParseFail;
3382 }
3383 int Val = CE->getValue();
3384 if (Val < Low || Val > High) {
3385 Error(Loc, "immediate value out of range");
3386 return MatchOperand_ParseFail;
3387 }
3388
3389 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3390
3391 return MatchOperand_Success;
3392}
3393
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003394ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3395parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3396 const AsmToken &Tok = Parser.getTok();
3397 SMLoc S = Tok.getLoc();
3398 if (Tok.isNot(AsmToken::Identifier)) {
3399 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3400 return MatchOperand_ParseFail;
3401 }
3402 int Val = StringSwitch<int>(Tok.getString())
3403 .Case("be", 1)
3404 .Case("le", 0)
3405 .Default(-1);
3406 Parser.Lex(); // Eat the token.
3407
3408 if (Val == -1) {
3409 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3410 return MatchOperand_ParseFail;
3411 }
3412 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3413 getContext()),
3414 S, Parser.getTok().getLoc()));
3415 return MatchOperand_Success;
3416}
3417
Jim Grosbach580f4a92011-07-25 22:20:28 +00003418/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3419/// instructions. Legal values are:
3420/// lsl #n 'n' in [0,31]
3421/// asr #n 'n' in [1,32]
3422/// n == 32 encoded as n == 0.
3423ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3424parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3425 const AsmToken &Tok = Parser.getTok();
3426 SMLoc S = Tok.getLoc();
3427 if (Tok.isNot(AsmToken::Identifier)) {
3428 Error(S, "shift operator 'asr' or 'lsl' expected");
3429 return MatchOperand_ParseFail;
3430 }
3431 StringRef ShiftName = Tok.getString();
3432 bool isASR;
3433 if (ShiftName == "lsl" || ShiftName == "LSL")
3434 isASR = false;
3435 else if (ShiftName == "asr" || ShiftName == "ASR")
3436 isASR = true;
3437 else {
3438 Error(S, "shift operator 'asr' or 'lsl' expected");
3439 return MatchOperand_ParseFail;
3440 }
3441 Parser.Lex(); // Eat the operator.
3442
3443 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003444 if (Parser.getTok().isNot(AsmToken::Hash) &&
3445 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003446 Error(Parser.getTok().getLoc(), "'#' expected");
3447 return MatchOperand_ParseFail;
3448 }
3449 Parser.Lex(); // Eat hash token.
3450
3451 const MCExpr *ShiftAmount;
3452 SMLoc E = Parser.getTok().getLoc();
3453 if (getParser().ParseExpression(ShiftAmount)) {
3454 Error(E, "malformed shift expression");
3455 return MatchOperand_ParseFail;
3456 }
3457 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3458 if (!CE) {
3459 Error(E, "shift amount must be an immediate");
3460 return MatchOperand_ParseFail;
3461 }
3462
3463 int64_t Val = CE->getValue();
3464 if (isASR) {
3465 // Shift amount must be in [1,32]
3466 if (Val < 1 || Val > 32) {
3467 Error(E, "'asr' shift amount must be in range [1,32]");
3468 return MatchOperand_ParseFail;
3469 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003470 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3471 if (isThumb() && Val == 32) {
3472 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3473 return MatchOperand_ParseFail;
3474 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003475 if (Val == 32) Val = 0;
3476 } else {
3477 // Shift amount must be in [1,32]
3478 if (Val < 0 || Val > 31) {
3479 Error(E, "'lsr' shift amount must be in range [0,31]");
3480 return MatchOperand_ParseFail;
3481 }
3482 }
3483
3484 E = Parser.getTok().getLoc();
3485 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3486
3487 return MatchOperand_Success;
3488}
3489
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003490/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3491/// of instructions. Legal values are:
3492/// ror #n 'n' in {0, 8, 16, 24}
3493ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3494parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3495 const AsmToken &Tok = Parser.getTok();
3496 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003497 if (Tok.isNot(AsmToken::Identifier))
3498 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003499 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003500 if (ShiftName != "ror" && ShiftName != "ROR")
3501 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003502 Parser.Lex(); // Eat the operator.
3503
3504 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003505 if (Parser.getTok().isNot(AsmToken::Hash) &&
3506 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003507 Error(Parser.getTok().getLoc(), "'#' expected");
3508 return MatchOperand_ParseFail;
3509 }
3510 Parser.Lex(); // Eat hash token.
3511
3512 const MCExpr *ShiftAmount;
3513 SMLoc E = Parser.getTok().getLoc();
3514 if (getParser().ParseExpression(ShiftAmount)) {
3515 Error(E, "malformed rotate expression");
3516 return MatchOperand_ParseFail;
3517 }
3518 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3519 if (!CE) {
3520 Error(E, "rotate amount must be an immediate");
3521 return MatchOperand_ParseFail;
3522 }
3523
3524 int64_t Val = CE->getValue();
3525 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3526 // normally, zero is represented in asm by omitting the rotate operand
3527 // entirely.
3528 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3529 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3530 return MatchOperand_ParseFail;
3531 }
3532
3533 E = Parser.getTok().getLoc();
3534 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3535
3536 return MatchOperand_Success;
3537}
3538
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003539ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3540parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3541 SMLoc S = Parser.getTok().getLoc();
3542 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003543 if (Parser.getTok().isNot(AsmToken::Hash) &&
3544 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003545 Error(Parser.getTok().getLoc(), "'#' expected");
3546 return MatchOperand_ParseFail;
3547 }
3548 Parser.Lex(); // Eat hash token.
3549
3550 const MCExpr *LSBExpr;
3551 SMLoc E = Parser.getTok().getLoc();
3552 if (getParser().ParseExpression(LSBExpr)) {
3553 Error(E, "malformed immediate expression");
3554 return MatchOperand_ParseFail;
3555 }
3556 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3557 if (!CE) {
3558 Error(E, "'lsb' operand must be an immediate");
3559 return MatchOperand_ParseFail;
3560 }
3561
3562 int64_t LSB = CE->getValue();
3563 // The LSB must be in the range [0,31]
3564 if (LSB < 0 || LSB > 31) {
3565 Error(E, "'lsb' operand must be in the range [0,31]");
3566 return MatchOperand_ParseFail;
3567 }
3568 E = Parser.getTok().getLoc();
3569
3570 // Expect another immediate operand.
3571 if (Parser.getTok().isNot(AsmToken::Comma)) {
3572 Error(Parser.getTok().getLoc(), "too few operands");
3573 return MatchOperand_ParseFail;
3574 }
3575 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003576 if (Parser.getTok().isNot(AsmToken::Hash) &&
3577 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003578 Error(Parser.getTok().getLoc(), "'#' expected");
3579 return MatchOperand_ParseFail;
3580 }
3581 Parser.Lex(); // Eat hash token.
3582
3583 const MCExpr *WidthExpr;
3584 if (getParser().ParseExpression(WidthExpr)) {
3585 Error(E, "malformed immediate expression");
3586 return MatchOperand_ParseFail;
3587 }
3588 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3589 if (!CE) {
3590 Error(E, "'width' operand must be an immediate");
3591 return MatchOperand_ParseFail;
3592 }
3593
3594 int64_t Width = CE->getValue();
3595 // The LSB must be in the range [1,32-lsb]
3596 if (Width < 1 || Width > 32 - LSB) {
3597 Error(E, "'width' operand must be in the range [1,32-lsb]");
3598 return MatchOperand_ParseFail;
3599 }
3600 E = Parser.getTok().getLoc();
3601
3602 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3603
3604 return MatchOperand_Success;
3605}
3606
Jim Grosbach7ce05792011-08-03 23:50:40 +00003607ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3608parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3609 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003610 // postidx_reg := '+' register {, shift}
3611 // | '-' register {, shift}
3612 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003613
3614 // This method must return MatchOperand_NoMatch without consuming any tokens
3615 // in the case where there is no match, as other alternatives take other
3616 // parse methods.
3617 AsmToken Tok = Parser.getTok();
3618 SMLoc S = Tok.getLoc();
3619 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003620 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003621 int Reg = -1;
3622 if (Tok.is(AsmToken::Plus)) {
3623 Parser.Lex(); // Eat the '+' token.
3624 haveEaten = true;
3625 } else if (Tok.is(AsmToken::Minus)) {
3626 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003627 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003628 haveEaten = true;
3629 }
3630 if (Parser.getTok().is(AsmToken::Identifier))
3631 Reg = tryParseRegister();
3632 if (Reg == -1) {
3633 if (!haveEaten)
3634 return MatchOperand_NoMatch;
3635 Error(Parser.getTok().getLoc(), "register expected");
3636 return MatchOperand_ParseFail;
3637 }
3638 SMLoc E = Parser.getTok().getLoc();
3639
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003640 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3641 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003642 if (Parser.getTok().is(AsmToken::Comma)) {
3643 Parser.Lex(); // Eat the ','.
3644 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3645 return MatchOperand_ParseFail;
3646 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003647
3648 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3649 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003650
3651 return MatchOperand_Success;
3652}
3653
Jim Grosbach251bf252011-08-10 21:56:18 +00003654ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3655parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3656 // Check for a post-index addressing register operand. Specifically:
3657 // am3offset := '+' register
3658 // | '-' register
3659 // | register
3660 // | # imm
3661 // | # + imm
3662 // | # - imm
3663
3664 // This method must return MatchOperand_NoMatch without consuming any tokens
3665 // in the case where there is no match, as other alternatives take other
3666 // parse methods.
3667 AsmToken Tok = Parser.getTok();
3668 SMLoc S = Tok.getLoc();
3669
3670 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003671 if (Parser.getTok().is(AsmToken::Hash) ||
3672 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003673 Parser.Lex(); // Eat the '#'.
3674 // Explicitly look for a '-', as we need to encode negative zero
3675 // differently.
3676 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3677 const MCExpr *Offset;
3678 if (getParser().ParseExpression(Offset))
3679 return MatchOperand_ParseFail;
3680 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3681 if (!CE) {
3682 Error(S, "constant expression expected");
3683 return MatchOperand_ParseFail;
3684 }
3685 SMLoc E = Tok.getLoc();
3686 // Negative zero is encoded as the flag value INT32_MIN.
3687 int32_t Val = CE->getValue();
3688 if (isNegative && Val == 0)
3689 Val = INT32_MIN;
3690
3691 Operands.push_back(
3692 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3693
3694 return MatchOperand_Success;
3695 }
3696
3697
3698 bool haveEaten = false;
3699 bool isAdd = true;
3700 int Reg = -1;
3701 if (Tok.is(AsmToken::Plus)) {
3702 Parser.Lex(); // Eat the '+' token.
3703 haveEaten = true;
3704 } else if (Tok.is(AsmToken::Minus)) {
3705 Parser.Lex(); // Eat the '-' token.
3706 isAdd = false;
3707 haveEaten = true;
3708 }
3709 if (Parser.getTok().is(AsmToken::Identifier))
3710 Reg = tryParseRegister();
3711 if (Reg == -1) {
3712 if (!haveEaten)
3713 return MatchOperand_NoMatch;
3714 Error(Parser.getTok().getLoc(), "register expected");
3715 return MatchOperand_ParseFail;
3716 }
3717 SMLoc E = Parser.getTok().getLoc();
3718
3719 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3720 0, S, E));
3721
3722 return MatchOperand_Success;
3723}
3724
Jim Grosbacha77295d2011-09-08 22:07:06 +00003725/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3726/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3727/// when they refer multiple MIOperands inside a single one.
3728bool ARMAsmParser::
3729cvtT2LdrdPre(MCInst &Inst, unsigned Opcode,
3730 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3731 // Rt, Rt2
3732 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3733 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3734 // Create a writeback register dummy placeholder.
3735 Inst.addOperand(MCOperand::CreateReg(0));
3736 // addr
3737 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3738 // pred
3739 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3740 return true;
3741}
3742
3743/// cvtT2StrdPre - Convert parsed operands to MCInst.
3744/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3745/// when they refer multiple MIOperands inside a single one.
3746bool ARMAsmParser::
3747cvtT2StrdPre(MCInst &Inst, unsigned Opcode,
3748 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3749 // Create a writeback register dummy placeholder.
3750 Inst.addOperand(MCOperand::CreateReg(0));
3751 // Rt, Rt2
3752 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3753 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3754 // addr
3755 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3756 // pred
3757 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3758 return true;
3759}
3760
Jim Grosbacheeec0252011-09-08 00:39:19 +00003761/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3762/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3763/// when they refer multiple MIOperands inside a single one.
3764bool ARMAsmParser::
3765cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3766 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3767 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3768
3769 // Create a writeback register dummy placeholder.
3770 Inst.addOperand(MCOperand::CreateImm(0));
3771
3772 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3773 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3774 return true;
3775}
3776
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003777/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3778/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3779/// when they refer multiple MIOperands inside a single one.
3780bool ARMAsmParser::
3781cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst, unsigned Opcode,
3782 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3783 // Create a writeback register dummy placeholder.
3784 Inst.addOperand(MCOperand::CreateImm(0));
3785 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3786 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3787 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3788 return true;
3789}
3790
Jim Grosbach1355cf12011-07-26 17:10:22 +00003791/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003792/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3793/// when they refer multiple MIOperands inside a single one.
3794bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003795cvtLdWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003796 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3797 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3798
3799 // Create a writeback register dummy placeholder.
3800 Inst.addOperand(MCOperand::CreateImm(0));
3801
Jim Grosbach7ce05792011-08-03 23:50:40 +00003802 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003803 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3804 return true;
3805}
3806
Owen Anderson9ab0f252011-08-26 20:43:14 +00003807/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3808/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3809/// when they refer multiple MIOperands inside a single one.
3810bool ARMAsmParser::
3811cvtLdWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3812 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3813 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3814
3815 // Create a writeback register dummy placeholder.
3816 Inst.addOperand(MCOperand::CreateImm(0));
3817
3818 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3819 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3820 return true;
3821}
3822
3823
Jim Grosbach548340c2011-08-11 19:22:40 +00003824/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3825/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3826/// when they refer multiple MIOperands inside a single one.
3827bool ARMAsmParser::
3828cvtStWriteBackRegAddrModeImm12(MCInst &Inst, unsigned Opcode,
3829 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3830 // Create a writeback register dummy placeholder.
3831 Inst.addOperand(MCOperand::CreateImm(0));
3832 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3833 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3834 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3835 return true;
3836}
3837
Jim Grosbach1355cf12011-07-26 17:10:22 +00003838/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003839/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3840/// when they refer multiple MIOperands inside a single one.
3841bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00003842cvtStWriteBackRegAddrMode2(MCInst &Inst, unsigned Opcode,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003843 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3844 // Create a writeback register dummy placeholder.
3845 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00003846 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3847 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
3848 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003849 return true;
3850}
3851
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00003852/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3853/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3854/// when they refer multiple MIOperands inside a single one.
3855bool ARMAsmParser::
3856cvtStWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3857 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3858 // Create a writeback register dummy placeholder.
3859 Inst.addOperand(MCOperand::CreateImm(0));
3860 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3861 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3862 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3863 return true;
3864}
3865
Jim Grosbach7ce05792011-08-03 23:50:40 +00003866/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
3867/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3868/// when they refer multiple MIOperands inside a single one.
3869bool ARMAsmParser::
3870cvtLdExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3871 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3872 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003873 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003874 // Create a writeback register dummy placeholder.
3875 Inst.addOperand(MCOperand::CreateImm(0));
3876 // addr
3877 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3878 // offset
3879 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3880 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003881 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3882 return true;
3883}
3884
Jim Grosbach7ce05792011-08-03 23:50:40 +00003885/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003886/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3887/// when they refer multiple MIOperands inside a single one.
3888bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003889cvtLdExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3890 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3891 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00003892 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003893 // Create a writeback register dummy placeholder.
3894 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003895 // addr
3896 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3897 // offset
3898 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3899 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003900 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3901 return true;
3902}
3903
Jim Grosbach7ce05792011-08-03 23:50:40 +00003904/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003905/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3906/// when they refer multiple MIOperands inside a single one.
3907bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00003908cvtStExtTWriteBackImm(MCInst &Inst, unsigned Opcode,
3909 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003910 // Create a writeback register dummy placeholder.
3911 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003912 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003913 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00003914 // addr
3915 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3916 // offset
3917 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
3918 // pred
3919 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3920 return true;
3921}
3922
3923/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
3924/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3925/// when they refer multiple MIOperands inside a single one.
3926bool ARMAsmParser::
3927cvtStExtTWriteBackReg(MCInst &Inst, unsigned Opcode,
3928 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3929 // Create a writeback register dummy placeholder.
3930 Inst.addOperand(MCOperand::CreateImm(0));
3931 // Rt
3932 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3933 // addr
3934 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
3935 // offset
3936 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
3937 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00003938 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3939 return true;
3940}
3941
Jim Grosbach2fd2b872011-08-10 20:29:19 +00003942/// cvtLdrdPre - Convert parsed operands to MCInst.
3943/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3944/// when they refer multiple MIOperands inside a single one.
3945bool ARMAsmParser::
3946cvtLdrdPre(MCInst &Inst, unsigned Opcode,
3947 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3948 // Rt, Rt2
3949 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3950 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3951 // Create a writeback register dummy placeholder.
3952 Inst.addOperand(MCOperand::CreateImm(0));
3953 // addr
3954 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3955 // pred
3956 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3957 return true;
3958}
3959
Jim Grosbach14605d12011-08-11 20:28:23 +00003960/// cvtStrdPre - Convert parsed operands to MCInst.
3961/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3962/// when they refer multiple MIOperands inside a single one.
3963bool ARMAsmParser::
3964cvtStrdPre(MCInst &Inst, unsigned Opcode,
3965 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3966 // Create a writeback register dummy placeholder.
3967 Inst.addOperand(MCOperand::CreateImm(0));
3968 // Rt, Rt2
3969 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3970 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3971 // addr
3972 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
3973 // pred
3974 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3975 return true;
3976}
3977
Jim Grosbach623a4542011-08-10 22:42:16 +00003978/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
3979/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3980/// when they refer multiple MIOperands inside a single one.
3981bool ARMAsmParser::
3982cvtLdWriteBackRegAddrMode3(MCInst &Inst, unsigned Opcode,
3983 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3984 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3985 // Create a writeback register dummy placeholder.
3986 Inst.addOperand(MCOperand::CreateImm(0));
3987 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
3988 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
3989 return true;
3990}
3991
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00003992/// cvtThumbMultiple- Convert parsed operands to MCInst.
3993/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3994/// when they refer multiple MIOperands inside a single one.
3995bool ARMAsmParser::
3996cvtThumbMultiply(MCInst &Inst, unsigned Opcode,
3997 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3998 // The second source operand must be the same register as the destination
3999 // operand.
4000 if (Operands.size() == 6 &&
Jim Grosbach7a010692011-08-19 22:30:46 +00004001 (((ARMOperand*)Operands[3])->getReg() !=
4002 ((ARMOperand*)Operands[5])->getReg()) &&
4003 (((ARMOperand*)Operands[3])->getReg() !=
4004 ((ARMOperand*)Operands[4])->getReg())) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004005 Error(Operands[3]->getStartLoc(),
Jim Grosbach7a010692011-08-19 22:30:46 +00004006 "destination register must match source register");
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004007 return false;
4008 }
4009 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4010 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004011 // If we have a three-operand form, make sure to set Rn to be the operand
4012 // that isn't the same as Rd.
4013 unsigned RegOp = 4;
4014 if (Operands.size() == 6 &&
4015 ((ARMOperand*)Operands[4])->getReg() ==
4016 ((ARMOperand*)Operands[3])->getReg())
4017 RegOp = 5;
4018 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4019 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004020 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
4021
4022 return true;
4023}
Jim Grosbach623a4542011-08-10 22:42:16 +00004024
Jim Grosbach12431322011-10-24 22:16:58 +00004025bool ARMAsmParser::
4026cvtVLDwbFixed(MCInst &Inst, unsigned Opcode,
4027 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4028 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004029 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004030 // Create a writeback register dummy placeholder.
4031 Inst.addOperand(MCOperand::CreateImm(0));
4032 // Vn
4033 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4034 // pred
4035 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4036 return true;
4037}
4038
4039bool ARMAsmParser::
4040cvtVLDwbRegister(MCInst &Inst, unsigned Opcode,
4041 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4042 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004043 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004044 // Create a writeback register dummy placeholder.
4045 Inst.addOperand(MCOperand::CreateImm(0));
4046 // Vn
4047 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4048 // Vm
4049 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4050 // pred
4051 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4052 return true;
4053}
4054
Jim Grosbach4334e032011-10-31 21:50:31 +00004055bool ARMAsmParser::
4056cvtVSTwbFixed(MCInst &Inst, unsigned Opcode,
4057 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4058 // Create a writeback register dummy placeholder.
4059 Inst.addOperand(MCOperand::CreateImm(0));
4060 // Vn
4061 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4062 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004063 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004064 // pred
4065 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4066 return true;
4067}
4068
4069bool ARMAsmParser::
4070cvtVSTwbRegister(MCInst &Inst, unsigned Opcode,
4071 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4072 // Create a writeback register dummy placeholder.
4073 Inst.addOperand(MCOperand::CreateImm(0));
4074 // Vn
4075 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4076 // Vm
4077 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4078 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004079 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004080 // pred
4081 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
4082 return true;
4083}
4084
Bill Wendlinge7176102010-11-06 22:36:58 +00004085/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004086/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004087bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004088parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004089 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004090 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004091 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004092 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004093 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004094
Sean Callanan18b83232010-01-19 21:44:56 +00004095 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004096 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004097 if (BaseRegNum == -1)
4098 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004099
Daniel Dunbar05710932011-01-18 05:34:17 +00004100 // The next token must either be a comma or a closing bracket.
4101 const AsmToken &Tok = Parser.getTok();
4102 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004103 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004104
Jim Grosbach7ce05792011-08-03 23:50:40 +00004105 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004106 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004107 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004108
Jim Grosbach7ce05792011-08-03 23:50:40 +00004109 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004110 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004111
Jim Grosbachfb12f352011-09-19 18:42:21 +00004112 // If there's a pre-indexing writeback marker, '!', just add it as a token
4113 // operand. It's rather odd, but syntactically valid.
4114 if (Parser.getTok().is(AsmToken::Exclaim)) {
4115 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4116 Parser.Lex(); // Eat the '!'.
4117 }
4118
Jim Grosbach7ce05792011-08-03 23:50:40 +00004119 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004120 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004121
Jim Grosbach7ce05792011-08-03 23:50:40 +00004122 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4123 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004124
Jim Grosbach57dcb852011-10-11 17:29:55 +00004125 // If we have a ':', it's an alignment specifier.
4126 if (Parser.getTok().is(AsmToken::Colon)) {
4127 Parser.Lex(); // Eat the ':'.
4128 E = Parser.getTok().getLoc();
4129
4130 const MCExpr *Expr;
4131 if (getParser().ParseExpression(Expr))
4132 return true;
4133
4134 // The expression has to be a constant. Memory references with relocations
4135 // don't come through here, as they use the <label> forms of the relevant
4136 // instructions.
4137 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4138 if (!CE)
4139 return Error (E, "constant expression expected");
4140
4141 unsigned Align = 0;
4142 switch (CE->getValue()) {
4143 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004144 return Error(E,
4145 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4146 case 16: Align = 2; break;
4147 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004148 case 64: Align = 8; break;
4149 case 128: Align = 16; break;
4150 case 256: Align = 32; break;
4151 }
4152
4153 // Now we should have the closing ']'
4154 E = Parser.getTok().getLoc();
4155 if (Parser.getTok().isNot(AsmToken::RBrac))
4156 return Error(E, "']' expected");
4157 Parser.Lex(); // Eat right bracket token.
4158
4159 // Don't worry about range checking the value here. That's handled by
4160 // the is*() predicates.
4161 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4162 ARM_AM::no_shift, 0, Align,
4163 false, S, E));
4164
4165 // If there's a pre-indexing writeback marker, '!', just add it as a token
4166 // operand.
4167 if (Parser.getTok().is(AsmToken::Exclaim)) {
4168 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4169 Parser.Lex(); // Eat the '!'.
4170 }
4171
4172 return false;
4173 }
4174
4175 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004176 // offset. Be friendly and also accept a plain integer (without a leading
4177 // hash) for gas compatibility.
4178 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004179 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004180 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004181 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004182 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004183 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004184
Owen Anderson0da10cf2011-08-29 19:36:44 +00004185 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004186 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004187 if (getParser().ParseExpression(Offset))
4188 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004189
4190 // The expression has to be a constant. Memory references with relocations
4191 // don't come through here, as they use the <label> forms of the relevant
4192 // instructions.
4193 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4194 if (!CE)
4195 return Error (E, "constant expression expected");
4196
Owen Anderson0da10cf2011-08-29 19:36:44 +00004197 // If the constant was #-0, represent it as INT32_MIN.
4198 int32_t Val = CE->getValue();
4199 if (isNegative && Val == 0)
4200 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4201
Jim Grosbach7ce05792011-08-03 23:50:40 +00004202 // Now we should have the closing ']'
4203 E = Parser.getTok().getLoc();
4204 if (Parser.getTok().isNot(AsmToken::RBrac))
4205 return Error(E, "']' expected");
4206 Parser.Lex(); // Eat right bracket token.
4207
4208 // Don't worry about range checking the value here. That's handled by
4209 // the is*() predicates.
4210 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004211 ARM_AM::no_shift, 0, 0,
4212 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004213
4214 // If there's a pre-indexing writeback marker, '!', just add it as a token
4215 // operand.
4216 if (Parser.getTok().is(AsmToken::Exclaim)) {
4217 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4218 Parser.Lex(); // Eat the '!'.
4219 }
4220
4221 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004222 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004223
4224 // The register offset is optionally preceded by a '+' or '-'
4225 bool isNegative = false;
4226 if (Parser.getTok().is(AsmToken::Minus)) {
4227 isNegative = true;
4228 Parser.Lex(); // Eat the '-'.
4229 } else if (Parser.getTok().is(AsmToken::Plus)) {
4230 // Nothing to do.
4231 Parser.Lex(); // Eat the '+'.
4232 }
4233
4234 E = Parser.getTok().getLoc();
4235 int OffsetRegNum = tryParseRegister();
4236 if (OffsetRegNum == -1)
4237 return Error(E, "register expected");
4238
4239 // If there's a shift operator, handle it.
4240 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004241 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004242 if (Parser.getTok().is(AsmToken::Comma)) {
4243 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004244 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004245 return true;
4246 }
4247
4248 // Now we should have the closing ']'
4249 E = Parser.getTok().getLoc();
4250 if (Parser.getTok().isNot(AsmToken::RBrac))
4251 return Error(E, "']' expected");
4252 Parser.Lex(); // Eat right bracket token.
4253
4254 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004255 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004256 S, E));
4257
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004258 // If there's a pre-indexing writeback marker, '!', just add it as a token
4259 // operand.
4260 if (Parser.getTok().is(AsmToken::Exclaim)) {
4261 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4262 Parser.Lex(); // Eat the '!'.
4263 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004264
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004265 return false;
4266}
4267
Jim Grosbach7ce05792011-08-03 23:50:40 +00004268/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004269/// ( lsl | lsr | asr | ror ) , # shift_amount
4270/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004271/// return true if it parses a shift otherwise it returns false.
4272bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4273 unsigned &Amount) {
4274 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004275 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004276 if (Tok.isNot(AsmToken::Identifier))
4277 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004278 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004279 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4280 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004281 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004282 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004283 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004284 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004285 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004286 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004287 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004288 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004289 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004290 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004291 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004292 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004293
Jim Grosbach7ce05792011-08-03 23:50:40 +00004294 // rrx stands alone.
4295 Amount = 0;
4296 if (St != ARM_AM::rrx) {
4297 Loc = Parser.getTok().getLoc();
4298 // A '#' and a shift amount.
4299 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004300 if (HashTok.isNot(AsmToken::Hash) &&
4301 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004302 return Error(HashTok.getLoc(), "'#' expected");
4303 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004304
Jim Grosbach7ce05792011-08-03 23:50:40 +00004305 const MCExpr *Expr;
4306 if (getParser().ParseExpression(Expr))
4307 return true;
4308 // Range check the immediate.
4309 // lsl, ror: 0 <= imm <= 31
4310 // lsr, asr: 0 <= imm <= 32
4311 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4312 if (!CE)
4313 return Error(Loc, "shift amount must be an immediate");
4314 int64_t Imm = CE->getValue();
4315 if (Imm < 0 ||
4316 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4317 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4318 return Error(Loc, "immediate shift value out of range");
4319 Amount = Imm;
4320 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004321
4322 return false;
4323}
4324
Jim Grosbach9d390362011-10-03 23:38:36 +00004325/// parseFPImm - A floating point immediate expression operand.
4326ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4327parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004328 // Anything that can accept a floating point constant as an operand
4329 // needs to go through here, as the regular ParseExpression is
4330 // integer only.
4331 //
4332 // This routine still creates a generic Immediate operand, containing
4333 // a bitcast of the 64-bit floating point value. The various operands
4334 // that accept floats can check whether the value is valid for them
4335 // via the standard is*() predicates.
4336
Jim Grosbach9d390362011-10-03 23:38:36 +00004337 SMLoc S = Parser.getTok().getLoc();
4338
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004339 if (Parser.getTok().isNot(AsmToken::Hash) &&
4340 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004341 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004342
4343 // Disambiguate the VMOV forms that can accept an FP immediate.
4344 // vmov.f32 <sreg>, #imm
4345 // vmov.f64 <dreg>, #imm
4346 // vmov.f32 <dreg>, #imm @ vector f32x2
4347 // vmov.f32 <qreg>, #imm @ vector f32x4
4348 //
4349 // There are also the NEON VMOV instructions which expect an
4350 // integer constant. Make sure we don't try to parse an FPImm
4351 // for these:
4352 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4353 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4354 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4355 TyOp->getToken() != ".f64"))
4356 return MatchOperand_NoMatch;
4357
Jim Grosbach9d390362011-10-03 23:38:36 +00004358 Parser.Lex(); // Eat the '#'.
4359
4360 // Handle negation, as that still comes through as a separate token.
4361 bool isNegative = false;
4362 if (Parser.getTok().is(AsmToken::Minus)) {
4363 isNegative = true;
4364 Parser.Lex();
4365 }
4366 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004367 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004368 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004369 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004370 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4371 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004372 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004373 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004374 Operands.push_back(ARMOperand::CreateImm(
4375 MCConstantExpr::Create(IntVal, getContext()),
4376 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004377 return MatchOperand_Success;
4378 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004379 // Also handle plain integers. Instructions which allow floating point
4380 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004381 if (Tok.is(AsmToken::Integer)) {
4382 int64_t Val = Tok.getIntVal();
4383 Parser.Lex(); // Eat the token.
4384 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004385 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004386 return MatchOperand_ParseFail;
4387 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004388 double RealVal = ARM_AM::getFPImmFloat(Val);
4389 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4390 Operands.push_back(ARMOperand::CreateImm(
4391 MCConstantExpr::Create(Val, getContext()), S,
4392 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004393 return MatchOperand_Success;
4394 }
4395
Jim Grosbachae69f702012-01-19 02:47:30 +00004396 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004397 return MatchOperand_ParseFail;
4398}
Jim Grosbach51222d12012-01-20 18:09:51 +00004399
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004400/// Parse a arm instruction operand. For now this parses the operand regardless
4401/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004402bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004403 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004404 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004405
4406 // Check if the current operand has a custom associated parser, if so, try to
4407 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004408 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4409 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004410 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004411 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4412 // there was a match, but an error occurred, in which case, just return that
4413 // the operand parsing failed.
4414 if (ResTy == MatchOperand_ParseFail)
4415 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004416
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004417 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004418 default:
4419 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004420 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004421 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004422 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004423 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004424 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004425 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004426 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004427 else if (Res == -1) // irrecoverable error
4428 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004429 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004430 if (Mnemonic == "vmrs" && Parser.getTok().getString() == "apsr_nzcv") {
4431 S = Parser.getTok().getLoc();
4432 Parser.Lex();
4433 Operands.push_back(ARMOperand::CreateToken("apsr_nzcv", S));
4434 return false;
4435 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004436
4437 // Fall though for the Identifier case that is not a register or a
4438 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004439 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004440 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004441 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004442 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004443 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004444 // This was not a register so parse other operands that start with an
4445 // identifier (like labels) as expressions and create them as immediates.
4446 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004447 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004448 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004449 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004450 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004451 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4452 return false;
4453 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004454 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004455 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004456 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004457 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004458 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004459 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004460 // #42 -> immediate.
4461 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +00004462 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004463 Parser.Lex();
Owen Anderson63553c72011-08-29 17:17:09 +00004464 bool isNegative = Parser.getTok().is(AsmToken::Minus);
Kevin Enderby515d5092009-10-15 20:48:48 +00004465 const MCExpr *ImmVal;
4466 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004467 return true;
Owen Anderson63553c72011-08-29 17:17:09 +00004468 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbached6a0c52011-11-01 22:37:37 +00004469 if (CE) {
4470 int32_t Val = CE->getValue();
4471 if (isNegative && Val == 0)
4472 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
Owen Anderson63553c72011-08-29 17:17:09 +00004473 }
Sean Callanan76264762010-04-02 22:27:05 +00004474 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004475 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4476 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004477 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004478 case AsmToken::Colon: {
4479 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004480 // FIXME: Check it's an expression prefix,
4481 // e.g. (FOO - :lower16:BAR) isn't legal.
4482 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004483 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004484 return true;
4485
Evan Cheng75972122011-01-13 07:58:56 +00004486 const MCExpr *SubExprVal;
4487 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004488 return true;
4489
Evan Cheng75972122011-01-13 07:58:56 +00004490 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
4491 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004492 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004493 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004494 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004495 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004496 }
4497}
4498
Jim Grosbach1355cf12011-07-26 17:10:22 +00004499// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004500// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004501bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004502 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004503
4504 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004505 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004506 Parser.Lex(); // Eat ':'
4507
4508 if (getLexer().isNot(AsmToken::Identifier)) {
4509 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4510 return true;
4511 }
4512
4513 StringRef IDVal = Parser.getTok().getIdentifier();
4514 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004515 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004516 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004517 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004518 } else {
4519 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4520 return true;
4521 }
4522 Parser.Lex();
4523
4524 if (getLexer().isNot(AsmToken::Colon)) {
4525 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4526 return true;
4527 }
4528 Parser.Lex(); // Eat the last ':'
4529 return false;
4530}
4531
Daniel Dunbar352e1482011-01-11 15:59:50 +00004532/// \brief Given a mnemonic, split out possible predication code and carry
4533/// setting letters to form a canonical mnemonic and flags.
4534//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004535// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004536// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004537StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004538 unsigned &PredicationCode,
4539 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004540 unsigned &ProcessorIMod,
4541 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004542 PredicationCode = ARMCC::AL;
4543 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004544 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004545
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004546 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004547 //
4548 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004549 if ((Mnemonic == "movs" && isThumb()) ||
4550 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4551 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4552 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4553 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4554 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4555 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004556 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4557 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004558 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004559
Jim Grosbach3f00e312011-07-11 17:09:57 +00004560 // First, split out any predication code. Ignore mnemonics we know aren't
4561 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004562 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004563 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004564 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004565 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004566 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4567 .Case("eq", ARMCC::EQ)
4568 .Case("ne", ARMCC::NE)
4569 .Case("hs", ARMCC::HS)
4570 .Case("cs", ARMCC::HS)
4571 .Case("lo", ARMCC::LO)
4572 .Case("cc", ARMCC::LO)
4573 .Case("mi", ARMCC::MI)
4574 .Case("pl", ARMCC::PL)
4575 .Case("vs", ARMCC::VS)
4576 .Case("vc", ARMCC::VC)
4577 .Case("hi", ARMCC::HI)
4578 .Case("ls", ARMCC::LS)
4579 .Case("ge", ARMCC::GE)
4580 .Case("lt", ARMCC::LT)
4581 .Case("gt", ARMCC::GT)
4582 .Case("le", ARMCC::LE)
4583 .Case("al", ARMCC::AL)
4584 .Default(~0U);
4585 if (CC != ~0U) {
4586 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4587 PredicationCode = CC;
4588 }
Bill Wendling52925b62010-10-29 23:50:21 +00004589 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004590
Daniel Dunbar352e1482011-01-11 15:59:50 +00004591 // Next, determine if we have a carry setting bit. We explicitly ignore all
4592 // the instructions we know end in 's'.
4593 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004594 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004595 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4596 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4597 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004598 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004599 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004600 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach1aa149f2011-12-22 19:20:45 +00004601 Mnemonic == "fmuls" || Mnemonic == "fcmps" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004602 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004603 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4604 CarrySetting = true;
4605 }
4606
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004607 // The "cps" instruction can have a interrupt mode operand which is glued into
4608 // the mnemonic. Check if this is the case, split it and parse the imod op
4609 if (Mnemonic.startswith("cps")) {
4610 // Split out any imod code.
4611 unsigned IMod =
4612 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4613 .Case("ie", ARM_PROC::IE)
4614 .Case("id", ARM_PROC::ID)
4615 .Default(~0U);
4616 if (IMod != ~0U) {
4617 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4618 ProcessorIMod = IMod;
4619 }
4620 }
4621
Jim Grosbach89df9962011-08-26 21:43:41 +00004622 // The "it" instruction has the condition mask on the end of the mnemonic.
4623 if (Mnemonic.startswith("it")) {
4624 ITMask = Mnemonic.slice(2, Mnemonic.size());
4625 Mnemonic = Mnemonic.slice(0, 2);
4626 }
4627
Daniel Dunbar352e1482011-01-11 15:59:50 +00004628 return Mnemonic;
4629}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004630
4631/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4632/// inclusion of carry set or predication code operands.
4633//
4634// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004635void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004636getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004637 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004638 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4639 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004640 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004641 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004642 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004643 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004644 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004645 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004646 Mnemonic == "mla" || Mnemonic == "smlal" ||
4647 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004648 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004649 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004650 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004651
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004652 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4653 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4654 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4655 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004656 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4657 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004658 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004659 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4660 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4661 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004662 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4663 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004664 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004665 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004666 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004667 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004668
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004669 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004670 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004671 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004672 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004673 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004674}
4675
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004676bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4677 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004678 // FIXME: This is all horribly hacky. We really need a better way to deal
4679 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004680
4681 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4682 // another does not. Specifically, the MOVW instruction does not. So we
4683 // special case it here and remove the defaulted (non-setting) cc_out
4684 // operand if that's the instruction we're trying to match.
4685 //
4686 // We do this as post-processing of the explicit operands rather than just
4687 // conditionally adding the cc_out in the first place because we need
4688 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004689 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004690 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4691 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4692 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4693 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004694
4695 // Register-register 'add' for thumb does not have a cc_out operand
4696 // when there are only two register operands.
4697 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4698 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4699 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4700 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4701 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004702 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004703 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4704 // have to check the immediate range here since Thumb2 has a variant
4705 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004706 if (((isThumb() && Mnemonic == "add") ||
4707 (isThumbTwo() && Mnemonic == "sub")) &&
4708 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004709 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4710 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4711 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004712 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4713 (static_cast<ARMOperand*>(Operands[5])->isReg() ||
4714 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004715 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004716 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4717 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004718 // selecting via the generic "add" mnemonic, so to know that we
4719 // should remove the cc_out operand, we have to explicitly check that
4720 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004721 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4722 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004723 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4724 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4725 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4726 // Nest conditions rather than one big 'if' statement for readability.
4727 //
4728 // If either register is a high reg, it's either one of the SP
4729 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004730 // check against T3. If the second register is the PC, this is an
4731 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004732 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4733 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004734 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004735 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4736 return false;
4737 // If both registers are low, we're in an IT block, and the immediate is
4738 // in range, we should use encoding T1 instead, which has a cc_out.
4739 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004740 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004741 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4742 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4743 return false;
4744
4745 // Otherwise, we use encoding T4, which does not have a cc_out
4746 // operand.
4747 return true;
4748 }
4749
Jim Grosbach64944f42011-09-14 21:00:40 +00004750 // The thumb2 multiply instruction doesn't have a CCOut register, so
4751 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4752 // use the 16-bit encoding or not.
4753 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4754 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4755 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4756 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4757 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4758 // If the registers aren't low regs, the destination reg isn't the
4759 // same as one of the source regs, or the cc_out operand is zero
4760 // outside of an IT block, we have to use the 32-bit encoding, so
4761 // remove the cc_out operand.
4762 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4763 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004764 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004765 !inITBlock() ||
4766 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4767 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4768 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4769 static_cast<ARMOperand*>(Operands[4])->getReg())))
4770 return true;
4771
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004772 // Also check the 'mul' syntax variant that doesn't specify an explicit
4773 // destination register.
4774 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4775 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4776 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4777 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4778 // If the registers aren't low regs or the cc_out operand is zero
4779 // outside of an IT block, we have to use the 32-bit encoding, so
4780 // remove the cc_out operand.
4781 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4782 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4783 !inITBlock()))
4784 return true;
4785
Jim Grosbach64944f42011-09-14 21:00:40 +00004786
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004787
Jim Grosbachf69c8042011-08-24 21:42:27 +00004788 // Register-register 'add/sub' for thumb does not have a cc_out operand
4789 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4790 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4791 // right, this will result in better diagnostics (which operand is off)
4792 // anyway.
4793 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4794 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004795 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4796 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
4797 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4798 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004799
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004800 return false;
4801}
4802
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004803static bool isDataTypeToken(StringRef Tok) {
4804 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4805 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4806 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4807 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4808 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4809 Tok == ".f" || Tok == ".d";
4810}
4811
4812// FIXME: This bit should probably be handled via an explicit match class
4813// in the .td files that matches the suffix instead of having it be
4814// a literal string token the way it is now.
4815static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4816 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4817}
4818
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004819static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004820/// Parse an arm instruction mnemonic followed by its operands.
4821bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4822 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004823 // Apply mnemonic aliases before doing anything else, as the destination
4824 // mnemnonic may include suffices and we want to handle them normally.
4825 // The generic tblgen'erated code does this later, at the start of
4826 // MatchInstructionImpl(), but that's too late for aliases that include
4827 // any sort of suffix.
4828 unsigned AvailableFeatures = getAvailableFeatures();
4829 applyMnemonicAliases(Name, AvailableFeatures);
4830
Jim Grosbacha39cda72011-12-14 02:16:11 +00004831 // First check for the ARM-specific .req directive.
4832 if (Parser.getTok().is(AsmToken::Identifier) &&
4833 Parser.getTok().getIdentifier() == ".req") {
4834 parseDirectiveReq(Name, NameLoc);
4835 // We always return 'error' for this, as we're done with this
4836 // statement and don't need to match the 'instruction."
4837 return true;
4838 }
4839
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004840 // Create the leading tokens for the mnemonic, split by '.' characters.
4841 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004842 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004843
Daniel Dunbar352e1482011-01-11 15:59:50 +00004844 // Split out the predication code and carry setting flag from the mnemonic.
4845 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004846 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004847 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004848 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004849 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004850 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004851
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004852 // In Thumb1, only the branch (B) instruction can be predicated.
4853 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4854 Parser.EatToEndOfStatement();
4855 return Error(NameLoc, "conditional execution not supported in Thumb1");
4856 }
4857
Jim Grosbachffa32252011-07-19 19:13:28 +00004858 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4859
Jim Grosbach89df9962011-08-26 21:43:41 +00004860 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4861 // is the mask as it will be for the IT encoding if the conditional
4862 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
4863 // where the conditional bit0 is zero, the instruction post-processing
4864 // will adjust the mask accordingly.
4865 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004866 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
4867 if (ITMask.size() > 3) {
4868 Parser.EatToEndOfStatement();
4869 return Error(Loc, "too many conditions on IT instruction");
4870 }
Jim Grosbach89df9962011-08-26 21:43:41 +00004871 unsigned Mask = 8;
4872 for (unsigned i = ITMask.size(); i != 0; --i) {
4873 char pos = ITMask[i - 1];
4874 if (pos != 't' && pos != 'e') {
4875 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004876 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00004877 }
4878 Mask >>= 1;
4879 if (ITMask[i - 1] == 't')
4880 Mask |= 8;
4881 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004882 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00004883 }
4884
Jim Grosbachffa32252011-07-19 19:13:28 +00004885 // FIXME: This is all a pretty gross hack. We should automatically handle
4886 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00004887
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004888 // Next, add the CCOut and ConditionCode operands, if needed.
4889 //
4890 // For mnemonics which can ever incorporate a carry setting bit or predication
4891 // code, our matching model involves us always generating CCOut and
4892 // ConditionCode operands to match the mnemonic "as written" and then we let
4893 // the matcher deal with finding the right instruction or generating an
4894 // appropriate error.
4895 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004896 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004897
Jim Grosbach33c16a22011-07-14 22:04:21 +00004898 // If we had a carry-set on an instruction that can't do that, issue an
4899 // error.
4900 if (!CanAcceptCarrySet && CarrySetting) {
4901 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00004902 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00004903 "' can not set flags, but 's' suffix specified");
4904 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00004905 // If we had a predication code on an instruction that can't do that, issue an
4906 // error.
4907 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
4908 Parser.EatToEndOfStatement();
4909 return Error(NameLoc, "instruction '" + Mnemonic +
4910 "' is not predicable, but condition code specified");
4911 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00004912
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004913 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004914 if (CanAcceptCarrySet) {
4915 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004916 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004917 Loc));
4918 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004919
4920 // Add the predication code operand, if necessary.
4921 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004922 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
4923 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004924 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00004925 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004926 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004927
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004928 // Add the processor imod operand, if necessary.
4929 if (ProcessorIMod) {
4930 Operands.push_back(ARMOperand::CreateImm(
4931 MCConstantExpr::Create(ProcessorIMod, getContext()),
4932 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004933 }
4934
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004935 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00004936 while (Next != StringRef::npos) {
4937 Start = Next;
4938 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004939 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004940
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004941 // Some NEON instructions have an optional datatype suffix that is
4942 // completely ignored. Check for that.
4943 if (isDataTypeToken(ExtraToken) &&
4944 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
4945 continue;
4946
Jim Grosbach81d2e392011-09-07 16:06:04 +00004947 if (ExtraToken != ".n") {
4948 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
4949 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
4950 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00004951 }
4952
4953 // Read the remaining operands.
4954 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004955 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004956 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004957 Parser.EatToEndOfStatement();
4958 return true;
4959 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004960
4961 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00004962 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004963
4964 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004965 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00004966 Parser.EatToEndOfStatement();
4967 return true;
4968 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004969 }
4970 }
Jim Grosbach16c74252010-10-29 14:46:02 +00004971
Chris Lattnercbf8a982010-09-11 16:18:25 +00004972 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00004973 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00004974 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00004975 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00004976 }
Bill Wendling146018f2010-11-06 21:42:12 +00004977
Chris Lattner34e53142010-09-08 05:10:46 +00004978 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00004979
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004980 // Some instructions, mostly Thumb, have forms for the same mnemonic that
4981 // do and don't have a cc_out optional-def operand. With some spot-checks
4982 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004983 // parse and adjust accordingly before actually matching. We shouldn't ever
4984 // try to remove a cc_out operand that was explicitly set on the the
4985 // mnemonic, of course (CarrySetting == true). Reason number #317 the
4986 // table driven matcher doesn't fit well with the ARM instruction set.
4987 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00004988 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
4989 Operands.erase(Operands.begin() + 1);
4990 delete Op;
4991 }
4992
Jim Grosbachcf121c32011-07-28 21:57:55 +00004993 // ARM mode 'blx' need special handling, as the register operand version
4994 // is predicable, but the label operand version is not. So, we can't rely
4995 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00004996 // a k_CondCode operand in the list. If we're trying to match the label
4997 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00004998 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
4999 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5000 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5001 Operands.erase(Operands.begin() + 1);
5002 delete Op;
5003 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005004
5005 // The vector-compare-to-zero instructions have a literal token "#0" at
5006 // the end that comes to here as an immediate operand. Convert it to a
5007 // token to play nicely with the matcher.
5008 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5009 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5010 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5011 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5012 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5013 if (CE && CE->getValue() == 0) {
5014 Operands.erase(Operands.begin() + 5);
5015 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5016 delete Op;
5017 }
5018 }
Jim Grosbach68259142011-10-03 22:30:24 +00005019 // VCMP{E} does the same thing, but with a different operand count.
5020 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5021 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5022 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5024 if (CE && CE->getValue() == 0) {
5025 Operands.erase(Operands.begin() + 4);
5026 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5027 delete Op;
5028 }
5029 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005030 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005031 // end. Convert it to a token here. Take care not to convert those
5032 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005033 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005034 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5035 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005036 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5037 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005039 if (CE && CE->getValue() == 0 &&
5040 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005041 // The cc_out operand matches the IT block.
5042 ((inITBlock() != CarrySetting) &&
5043 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005044 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005045 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005046 Operands.erase(Operands.begin() + 5);
5047 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5048 delete Op;
5049 }
5050 }
5051
Chris Lattner98986712010-01-14 22:21:20 +00005052 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005053}
5054
Jim Grosbach189610f2011-07-26 18:25:39 +00005055// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005056
5057// return 'true' if register list contains non-low GPR registers,
5058// 'false' otherwise. If Reg is in the register list or is HiReg, set
5059// 'containsReg' to true.
5060static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5061 unsigned HiReg, bool &containsReg) {
5062 containsReg = false;
5063 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5064 unsigned OpReg = Inst.getOperand(i).getReg();
5065 if (OpReg == Reg)
5066 containsReg = true;
5067 // Anything other than a low register isn't legal here.
5068 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5069 return true;
5070 }
5071 return false;
5072}
5073
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005074// Check if the specified regisgter is in the register list of the inst,
5075// starting at the indicated operand number.
5076static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5077 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5078 unsigned OpReg = Inst.getOperand(i).getReg();
5079 if (OpReg == Reg)
5080 return true;
5081 }
5082 return false;
5083}
5084
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005085// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5086// the ARMInsts array) instead. Getting that here requires awkward
5087// API changes, though. Better way?
5088namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005089extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005090}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005091static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005092 return ARMInsts[Opcode];
5093}
5094
Jim Grosbach189610f2011-07-26 18:25:39 +00005095// FIXME: We would really like to be able to tablegen'erate this.
5096bool ARMAsmParser::
5097validateInstruction(MCInst &Inst,
5098 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005099 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005100 SMLoc Loc = Operands[0]->getStartLoc();
5101 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005102 // NOTE: BKPT instruction has the interesting property of being
5103 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005104 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005105 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5106 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005107 unsigned bit = 1;
5108 if (ITState.FirstCond)
5109 ITState.FirstCond = false;
5110 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005111 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005112 // The instruction must be predicable.
5113 if (!MCID.isPredicable())
5114 return Error(Loc, "instructions in IT block must be predicable");
5115 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5116 unsigned ITCond = bit ? ITState.Cond :
5117 ARMCC::getOppositeCondition(ITState.Cond);
5118 if (Cond != ITCond) {
5119 // Find the condition code Operand to get its SMLoc information.
5120 SMLoc CondLoc;
5121 for (unsigned i = 1; i < Operands.size(); ++i)
5122 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5123 CondLoc = Operands[i]->getStartLoc();
5124 return Error(CondLoc, "incorrect condition in IT block; got '" +
5125 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5126 "', but expected '" +
5127 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5128 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005129 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005130 } else if (isThumbTwo() && MCID.isPredicable() &&
5131 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005132 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5133 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005134 return Error(Loc, "predicated instructions must be in IT block");
5135
Jim Grosbach189610f2011-07-26 18:25:39 +00005136 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005137 case ARM::LDRD:
5138 case ARM::LDRD_PRE:
5139 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005140 case ARM::LDREXD: {
5141 // Rt2 must be Rt + 1.
5142 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5143 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5144 if (Rt2 != Rt + 1)
5145 return Error(Operands[3]->getStartLoc(),
5146 "destination operands must be sequential");
5147 return false;
5148 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005149 case ARM::STRD: {
5150 // Rt2 must be Rt + 1.
5151 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(0).getReg());
5152 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5153 if (Rt2 != Rt + 1)
5154 return Error(Operands[3]->getStartLoc(),
5155 "source operands must be sequential");
5156 return false;
5157 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005158 case ARM::STRD_PRE:
5159 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005160 case ARM::STREXD: {
5161 // Rt2 must be Rt + 1.
5162 unsigned Rt = getARMRegisterNumbering(Inst.getOperand(1).getReg());
5163 unsigned Rt2 = getARMRegisterNumbering(Inst.getOperand(2).getReg());
5164 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005165 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005166 "source operands must be sequential");
5167 return false;
5168 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005169 case ARM::SBFX:
5170 case ARM::UBFX: {
5171 // width must be in range [1, 32-lsb]
5172 unsigned lsb = Inst.getOperand(2).getImm();
5173 unsigned widthm1 = Inst.getOperand(3).getImm();
5174 if (widthm1 >= 32 - lsb)
5175 return Error(Operands[5]->getStartLoc(),
5176 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005177 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005178 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005179 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005180 // If we're parsing Thumb2, the .w variant is available and handles
5181 // most cases that are normally illegal for a Thumb1 LDM
5182 // instruction. We'll make the transformation in processInstruction()
5183 // if necessary.
5184 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005185 // Thumb LDM instructions are writeback iff the base register is not
5186 // in the register list.
5187 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005188 bool hasWritebackToken =
5189 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5190 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005191 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005192 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005193 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5194 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005195 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005196 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005197 return Error(Operands[2]->getStartLoc(),
5198 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005199 // If we should not have writeback, there must not be a '!'. This is
5200 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005201 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005202 return Error(Operands[3]->getStartLoc(),
5203 "writeback operator '!' not allowed when base register "
5204 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005205
5206 break;
5207 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005208 case ARM::t2LDMIA_UPD: {
5209 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5210 return Error(Operands[4]->getStartLoc(),
5211 "writeback operator '!' not allowed when base register "
5212 "in register list");
5213 break;
5214 }
Jim Grosbach54026372011-11-10 23:17:11 +00005215 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5216 // so only issue a diagnostic for thumb1. The instructions will be
5217 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005218 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005219 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005220 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5221 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005222 return Error(Operands[2]->getStartLoc(),
5223 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005224 break;
5225 }
5226 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005227 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005228 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5229 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005230 return Error(Operands[2]->getStartLoc(),
5231 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005232 break;
5233 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005234 case ARM::tSTMIA_UPD: {
5235 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005236 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005237 return Error(Operands[4]->getStartLoc(),
5238 "registers must be in range r0-r7");
5239 break;
5240 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005241 }
5242
5243 return false;
5244}
5245
Jim Grosbachd7433e22012-01-23 23:45:44 +00005246static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005247 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005248 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005249 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005250 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5251 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5252 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5253 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5254 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5255 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5256 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5257 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5258 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005259
5260 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005261 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5262 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5263 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5264 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5265 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005266
Jim Grosbach7945ead2012-01-24 00:43:12 +00005267 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5268 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5269 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5270 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5271 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005272
Jim Grosbach7945ead2012-01-24 00:43:12 +00005273 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5274 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5275 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5276 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5277 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005278
Jim Grosbach4adb1822012-01-24 00:07:41 +00005279 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005280 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5281 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5282 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5283 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5284 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5285 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5286 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5287 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5288 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5289 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5290 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5291 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5292 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5293 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5294 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005295
Jim Grosbachd7433e22012-01-23 23:45:44 +00005296 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005297 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5298 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5299 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5300 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5301 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5302 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5303 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5304 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5305 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5306 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5307 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5308 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5309 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5310 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5311 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5312 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5313 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5314 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005315
Jim Grosbach88a54de2012-01-24 18:53:13 +00005316 // VST4LN
5317 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5318 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5319 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5320 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5321 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5322 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5323 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5324 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5325 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5326 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5327 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5328 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5329 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5330 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5331 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5332
Jim Grosbach539aab72012-01-24 00:58:13 +00005333 // VST4
5334 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5335 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5336 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5337 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5338 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5339 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5340 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5341 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5342 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5343 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5344 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5345 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5346 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5347 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5348 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5349 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5350 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5351 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005352 }
5353}
5354
Jim Grosbachd7433e22012-01-23 23:45:44 +00005355static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005356 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005357 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005358 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005359 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5360 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5361 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5362 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5363 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5364 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5365 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5366 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5367 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005368
5369 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005370 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5371 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5372 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5373 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5374 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5375 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5376 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5377 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5378 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5379 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5380 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5381 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5382 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5383 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5384 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005385
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005386 // VLD3DUP
5387 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5388 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5389 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5390 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5391 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5392 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5393 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5394 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5395 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5396 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5397 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5398 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5399 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5400 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5401 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5402 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5403 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5404 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5405
Jim Grosbach3a678af2012-01-23 21:53:26 +00005406 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005407 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5408 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5409 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5410 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5411 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5412 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5413 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5414 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5415 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5416 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5417 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5418 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5419 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5420 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5421 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005422
5423 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005424 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5425 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5426 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5427 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5428 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5429 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5430 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5431 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5432 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5433 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5434 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5435 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5436 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5437 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5438 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5439 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5440 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5441 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005442
Jim Grosbache983a132012-01-24 18:37:25 +00005443 // VLD4LN
5444 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5445 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5446 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5447 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5448 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5449 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5450 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5451 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5452 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5453 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5454 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5455 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5456 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5457 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5458 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5459
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005460 // VLD4DUP
5461 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5462 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5463 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5464 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5465 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5466 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5467 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5468 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5469 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5470 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5471 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5472 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5473 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5474 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5475 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5476 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5477 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5478 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5479
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005480 // VLD4
5481 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5482 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5483 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5484 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5485 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5486 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5487 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5488 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5489 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5490 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5491 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5492 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5493 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5494 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5495 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5496 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5497 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5498 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005499 }
5500}
5501
Jim Grosbach83ec8772011-11-10 23:42:14 +00005502bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005503processInstruction(MCInst &Inst,
5504 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5505 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005506 // Aliases for alternate PC+imm syntax of LDR instructions.
5507 case ARM::t2LDRpcrel:
5508 Inst.setOpcode(ARM::t2LDRpci);
5509 return true;
5510 case ARM::t2LDRBpcrel:
5511 Inst.setOpcode(ARM::t2LDRBpci);
5512 return true;
5513 case ARM::t2LDRHpcrel:
5514 Inst.setOpcode(ARM::t2LDRHpci);
5515 return true;
5516 case ARM::t2LDRSBpcrel:
5517 Inst.setOpcode(ARM::t2LDRSBpci);
5518 return true;
5519 case ARM::t2LDRSHpcrel:
5520 Inst.setOpcode(ARM::t2LDRSHpci);
5521 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005522 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005523 case ARM::VST1LNdWB_register_Asm_8:
5524 case ARM::VST1LNdWB_register_Asm_16:
5525 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005526 MCInst TmpInst;
5527 // Shuffle the operands around so the lane index operand is in the
5528 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005529 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005530 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005531 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5532 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5533 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5534 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5535 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5536 TmpInst.addOperand(Inst.getOperand(1)); // lane
5537 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5538 TmpInst.addOperand(Inst.getOperand(6));
5539 Inst = TmpInst;
5540 return true;
5541 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005542
Jim Grosbach8b31f952012-01-23 19:39:08 +00005543 case ARM::VST2LNdWB_register_Asm_8:
5544 case ARM::VST2LNdWB_register_Asm_16:
5545 case ARM::VST2LNdWB_register_Asm_32:
5546 case ARM::VST2LNqWB_register_Asm_16:
5547 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005548 MCInst TmpInst;
5549 // Shuffle the operands around so the lane index operand is in the
5550 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005551 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005552 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005553 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5554 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5555 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5556 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5557 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005558 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5559 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005560 TmpInst.addOperand(Inst.getOperand(1)); // lane
5561 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5562 TmpInst.addOperand(Inst.getOperand(6));
5563 Inst = TmpInst;
5564 return true;
5565 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005566
5567 case ARM::VST3LNdWB_register_Asm_8:
5568 case ARM::VST3LNdWB_register_Asm_16:
5569 case ARM::VST3LNdWB_register_Asm_32:
5570 case ARM::VST3LNqWB_register_Asm_16:
5571 case ARM::VST3LNqWB_register_Asm_32: {
5572 MCInst TmpInst;
5573 // Shuffle the operands around so the lane index operand is in the
5574 // right place.
5575 unsigned Spacing;
5576 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5577 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5578 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5579 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5580 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5581 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5582 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5583 Spacing));
5584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5585 Spacing * 2));
5586 TmpInst.addOperand(Inst.getOperand(1)); // lane
5587 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5588 TmpInst.addOperand(Inst.getOperand(6));
5589 Inst = TmpInst;
5590 return true;
5591 }
5592
Jim Grosbach88a54de2012-01-24 18:53:13 +00005593 case ARM::VST4LNdWB_register_Asm_8:
5594 case ARM::VST4LNdWB_register_Asm_16:
5595 case ARM::VST4LNdWB_register_Asm_32:
5596 case ARM::VST4LNqWB_register_Asm_16:
5597 case ARM::VST4LNqWB_register_Asm_32: {
5598 MCInst TmpInst;
5599 // Shuffle the operands around so the lane index operand is in the
5600 // right place.
5601 unsigned Spacing;
5602 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5603 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5604 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5605 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5606 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5607 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5608 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5609 Spacing));
5610 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5611 Spacing * 2));
5612 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5613 Spacing * 3));
5614 TmpInst.addOperand(Inst.getOperand(1)); // lane
5615 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5616 TmpInst.addOperand(Inst.getOperand(6));
5617 Inst = TmpInst;
5618 return true;
5619 }
5620
Jim Grosbach8b31f952012-01-23 19:39:08 +00005621 case ARM::VST1LNdWB_fixed_Asm_8:
5622 case ARM::VST1LNdWB_fixed_Asm_16:
5623 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005624 MCInst TmpInst;
5625 // Shuffle the operands around so the lane index operand is in the
5626 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005627 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005628 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005629 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5630 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5631 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5632 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5633 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5634 TmpInst.addOperand(Inst.getOperand(1)); // lane
5635 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5636 TmpInst.addOperand(Inst.getOperand(5));
5637 Inst = TmpInst;
5638 return true;
5639 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005640
Jim Grosbach8b31f952012-01-23 19:39:08 +00005641 case ARM::VST2LNdWB_fixed_Asm_8:
5642 case ARM::VST2LNdWB_fixed_Asm_16:
5643 case ARM::VST2LNdWB_fixed_Asm_32:
5644 case ARM::VST2LNqWB_fixed_Asm_16:
5645 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005646 MCInst TmpInst;
5647 // Shuffle the operands around so the lane index operand is in the
5648 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005649 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005650 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005651 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5652 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5653 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5654 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5655 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005656 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5657 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005658 TmpInst.addOperand(Inst.getOperand(1)); // lane
5659 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5660 TmpInst.addOperand(Inst.getOperand(5));
5661 Inst = TmpInst;
5662 return true;
5663 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005664
5665 case ARM::VST3LNdWB_fixed_Asm_8:
5666 case ARM::VST3LNdWB_fixed_Asm_16:
5667 case ARM::VST3LNdWB_fixed_Asm_32:
5668 case ARM::VST3LNqWB_fixed_Asm_16:
5669 case ARM::VST3LNqWB_fixed_Asm_32: {
5670 MCInst TmpInst;
5671 // Shuffle the operands around so the lane index operand is in the
5672 // right place.
5673 unsigned Spacing;
5674 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5675 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5676 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5677 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5678 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5679 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5680 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5681 Spacing));
5682 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5683 Spacing * 2));
5684 TmpInst.addOperand(Inst.getOperand(1)); // lane
5685 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5686 TmpInst.addOperand(Inst.getOperand(5));
5687 Inst = TmpInst;
5688 return true;
5689 }
5690
Jim Grosbach88a54de2012-01-24 18:53:13 +00005691 case ARM::VST4LNdWB_fixed_Asm_8:
5692 case ARM::VST4LNdWB_fixed_Asm_16:
5693 case ARM::VST4LNdWB_fixed_Asm_32:
5694 case ARM::VST4LNqWB_fixed_Asm_16:
5695 case ARM::VST4LNqWB_fixed_Asm_32: {
5696 MCInst TmpInst;
5697 // Shuffle the operands around so the lane index operand is in the
5698 // right place.
5699 unsigned Spacing;
5700 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5701 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5702 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5703 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5704 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5705 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5706 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5707 Spacing));
5708 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5709 Spacing * 2));
5710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5711 Spacing * 3));
5712 TmpInst.addOperand(Inst.getOperand(1)); // lane
5713 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5714 TmpInst.addOperand(Inst.getOperand(5));
5715 Inst = TmpInst;
5716 return true;
5717 }
5718
Jim Grosbach8b31f952012-01-23 19:39:08 +00005719 case ARM::VST1LNdAsm_8:
5720 case ARM::VST1LNdAsm_16:
5721 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005722 MCInst TmpInst;
5723 // Shuffle the operands around so the lane index operand is in the
5724 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005725 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005726 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5730 TmpInst.addOperand(Inst.getOperand(1)); // lane
5731 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5732 TmpInst.addOperand(Inst.getOperand(5));
5733 Inst = TmpInst;
5734 return true;
5735 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005736
Jim Grosbach8b31f952012-01-23 19:39:08 +00005737 case ARM::VST2LNdAsm_8:
5738 case ARM::VST2LNdAsm_16:
5739 case ARM::VST2LNdAsm_32:
5740 case ARM::VST2LNqAsm_16:
5741 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005742 MCInst TmpInst;
5743 // Shuffle the operands around so the lane index operand is in the
5744 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005745 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005746 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005747 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5748 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5749 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5751 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005752 TmpInst.addOperand(Inst.getOperand(1)); // lane
5753 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5754 TmpInst.addOperand(Inst.getOperand(5));
5755 Inst = TmpInst;
5756 return true;
5757 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005758
5759 case ARM::VST3LNdAsm_8:
5760 case ARM::VST3LNdAsm_16:
5761 case ARM::VST3LNdAsm_32:
5762 case ARM::VST3LNqAsm_16:
5763 case ARM::VST3LNqAsm_32: {
5764 MCInst TmpInst;
5765 // Shuffle the operands around so the lane index operand is in the
5766 // right place.
5767 unsigned Spacing;
5768 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5769 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5770 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5773 Spacing));
5774 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5775 Spacing * 2));
5776 TmpInst.addOperand(Inst.getOperand(1)); // lane
5777 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5778 TmpInst.addOperand(Inst.getOperand(5));
5779 Inst = TmpInst;
5780 return true;
5781 }
5782
Jim Grosbach88a54de2012-01-24 18:53:13 +00005783 case ARM::VST4LNdAsm_8:
5784 case ARM::VST4LNdAsm_16:
5785 case ARM::VST4LNdAsm_32:
5786 case ARM::VST4LNqAsm_16:
5787 case ARM::VST4LNqAsm_32: {
5788 MCInst TmpInst;
5789 // Shuffle the operands around so the lane index operand is in the
5790 // right place.
5791 unsigned Spacing;
5792 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5793 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5794 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5795 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5796 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5797 Spacing));
5798 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5799 Spacing * 2));
5800 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5801 Spacing * 3));
5802 TmpInst.addOperand(Inst.getOperand(1)); // lane
5803 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5804 TmpInst.addOperand(Inst.getOperand(5));
5805 Inst = TmpInst;
5806 return true;
5807 }
5808
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005809 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005810 case ARM::VLD1LNdWB_register_Asm_8:
5811 case ARM::VLD1LNdWB_register_Asm_16:
5812 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005813 MCInst TmpInst;
5814 // Shuffle the operands around so the lane index operand is in the
5815 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005816 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005817 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005818 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5819 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5820 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5821 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5822 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5823 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5824 TmpInst.addOperand(Inst.getOperand(1)); // lane
5825 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5826 TmpInst.addOperand(Inst.getOperand(6));
5827 Inst = TmpInst;
5828 return true;
5829 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005830
Jim Grosbach8b31f952012-01-23 19:39:08 +00005831 case ARM::VLD2LNdWB_register_Asm_8:
5832 case ARM::VLD2LNdWB_register_Asm_16:
5833 case ARM::VLD2LNdWB_register_Asm_32:
5834 case ARM::VLD2LNqWB_register_Asm_16:
5835 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005836 MCInst TmpInst;
5837 // Shuffle the operands around so the lane index operand is in the
5838 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005839 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005840 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005841 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005842 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5843 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005844 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5845 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5846 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5847 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5848 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5850 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005851 TmpInst.addOperand(Inst.getOperand(1)); // lane
5852 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5853 TmpInst.addOperand(Inst.getOperand(6));
5854 Inst = TmpInst;
5855 return true;
5856 }
5857
Jim Grosbach3a678af2012-01-23 21:53:26 +00005858 case ARM::VLD3LNdWB_register_Asm_8:
5859 case ARM::VLD3LNdWB_register_Asm_16:
5860 case ARM::VLD3LNdWB_register_Asm_32:
5861 case ARM::VLD3LNqWB_register_Asm_16:
5862 case ARM::VLD3LNqWB_register_Asm_32: {
5863 MCInst TmpInst;
5864 // Shuffle the operands around so the lane index operand is in the
5865 // right place.
5866 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005867 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005868 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5869 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5870 Spacing));
5871 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005872 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005873 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5874 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5875 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5876 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5877 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5878 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5879 Spacing));
5880 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005881 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005882 TmpInst.addOperand(Inst.getOperand(1)); // lane
5883 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5884 TmpInst.addOperand(Inst.getOperand(6));
5885 Inst = TmpInst;
5886 return true;
5887 }
5888
Jim Grosbache983a132012-01-24 18:37:25 +00005889 case ARM::VLD4LNdWB_register_Asm_8:
5890 case ARM::VLD4LNdWB_register_Asm_16:
5891 case ARM::VLD4LNdWB_register_Asm_32:
5892 case ARM::VLD4LNqWB_register_Asm_16:
5893 case ARM::VLD4LNqWB_register_Asm_32: {
5894 MCInst TmpInst;
5895 // Shuffle the operands around so the lane index operand is in the
5896 // right place.
5897 unsigned Spacing;
5898 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
5899 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5900 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5901 Spacing));
5902 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5903 Spacing * 2));
5904 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5905 Spacing * 3));
5906 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5907 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5908 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5909 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5910 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== 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(1)); // lane
5918 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5919 TmpInst.addOperand(Inst.getOperand(6));
5920 Inst = TmpInst;
5921 return true;
5922 }
5923
Jim Grosbach8b31f952012-01-23 19:39:08 +00005924 case ARM::VLD1LNdWB_fixed_Asm_8:
5925 case ARM::VLD1LNdWB_fixed_Asm_16:
5926 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005927 MCInst TmpInst;
5928 // Shuffle the operands around so the lane index operand is in the
5929 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005930 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005931 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005932 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5933 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5934 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5935 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5936 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5937 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5938 TmpInst.addOperand(Inst.getOperand(1)); // lane
5939 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5940 TmpInst.addOperand(Inst.getOperand(5));
5941 Inst = TmpInst;
5942 return true;
5943 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005944
Jim Grosbach8b31f952012-01-23 19:39:08 +00005945 case ARM::VLD2LNdWB_fixed_Asm_8:
5946 case ARM::VLD2LNdWB_fixed_Asm_16:
5947 case ARM::VLD2LNdWB_fixed_Asm_32:
5948 case ARM::VLD2LNqWB_fixed_Asm_16:
5949 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005950 MCInst TmpInst;
5951 // Shuffle the operands around so the lane index operand is in the
5952 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005953 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005954 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005955 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005956 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5957 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005958 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5959 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5960 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5961 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5962 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5964 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005965 TmpInst.addOperand(Inst.getOperand(1)); // lane
5966 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5967 TmpInst.addOperand(Inst.getOperand(5));
5968 Inst = TmpInst;
5969 return true;
5970 }
5971
Jim Grosbach3a678af2012-01-23 21:53:26 +00005972 case ARM::VLD3LNdWB_fixed_Asm_8:
5973 case ARM::VLD3LNdWB_fixed_Asm_16:
5974 case ARM::VLD3LNdWB_fixed_Asm_32:
5975 case ARM::VLD3LNqWB_fixed_Asm_16:
5976 case ARM::VLD3LNqWB_fixed_Asm_32: {
5977 MCInst TmpInst;
5978 // Shuffle the operands around so the lane index operand is in the
5979 // right place.
5980 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005981 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005982 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5983 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5984 Spacing));
5985 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005986 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005987 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5988 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5989 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5990 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5991 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5992 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5993 Spacing));
5994 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00005995 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00005996 TmpInst.addOperand(Inst.getOperand(1)); // lane
5997 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5998 TmpInst.addOperand(Inst.getOperand(5));
5999 Inst = TmpInst;
6000 return true;
6001 }
6002
Jim Grosbache983a132012-01-24 18:37:25 +00006003 case ARM::VLD4LNdWB_fixed_Asm_8:
6004 case ARM::VLD4LNdWB_fixed_Asm_16:
6005 case ARM::VLD4LNdWB_fixed_Asm_32:
6006 case ARM::VLD4LNqWB_fixed_Asm_16:
6007 case ARM::VLD4LNqWB_fixed_Asm_32: {
6008 MCInst TmpInst;
6009 // Shuffle the operands around so the lane index operand is in the
6010 // right place.
6011 unsigned Spacing;
6012 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6015 Spacing));
6016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing * 2));
6018 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6019 Spacing * 3));
6020 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6021 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6022 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6023 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6024 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== 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(1)); // lane
6032 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6033 TmpInst.addOperand(Inst.getOperand(5));
6034 Inst = TmpInst;
6035 return true;
6036 }
6037
Jim Grosbach8b31f952012-01-23 19:39:08 +00006038 case ARM::VLD1LNdAsm_8:
6039 case ARM::VLD1LNdAsm_16:
6040 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006041 MCInst TmpInst;
6042 // Shuffle the operands around so the lane index operand is in the
6043 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006044 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006045 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006046 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6049 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6050 TmpInst.addOperand(Inst.getOperand(1)); // lane
6051 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6052 TmpInst.addOperand(Inst.getOperand(5));
6053 Inst = TmpInst;
6054 return true;
6055 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006056
Jim Grosbach8b31f952012-01-23 19:39:08 +00006057 case ARM::VLD2LNdAsm_8:
6058 case ARM::VLD2LNdAsm_16:
6059 case ARM::VLD2LNdAsm_32:
6060 case ARM::VLD2LNqAsm_16:
6061 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006062 MCInst TmpInst;
6063 // Shuffle the operands around so the lane index operand is in the
6064 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006065 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006066 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006067 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006068 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6069 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006070 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6071 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6072 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006075 TmpInst.addOperand(Inst.getOperand(1)); // lane
6076 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6077 TmpInst.addOperand(Inst.getOperand(5));
6078 Inst = TmpInst;
6079 return true;
6080 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006081
6082 case ARM::VLD3LNdAsm_8:
6083 case ARM::VLD3LNdAsm_16:
6084 case ARM::VLD3LNdAsm_32:
6085 case ARM::VLD3LNqAsm_16:
6086 case ARM::VLD3LNqAsm_32: {
6087 MCInst TmpInst;
6088 // Shuffle the operands around so the lane index operand is in the
6089 // right place.
6090 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006091 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006092 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6093 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6094 Spacing));
6095 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006096 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006097 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6098 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6099 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6100 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6101 Spacing));
6102 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006103 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006104 TmpInst.addOperand(Inst.getOperand(1)); // lane
6105 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6106 TmpInst.addOperand(Inst.getOperand(5));
6107 Inst = TmpInst;
6108 return true;
6109 }
6110
Jim Grosbache983a132012-01-24 18:37:25 +00006111 case ARM::VLD4LNdAsm_8:
6112 case ARM::VLD4LNdAsm_16:
6113 case ARM::VLD4LNdAsm_32:
6114 case ARM::VLD4LNqAsm_16:
6115 case ARM::VLD4LNqAsm_32: {
6116 MCInst TmpInst;
6117 // Shuffle the operands around so the lane index operand is in the
6118 // right place.
6119 unsigned Spacing;
6120 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6121 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6122 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6123 Spacing));
6124 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6125 Spacing * 2));
6126 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6127 Spacing * 3));
6128 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6129 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6130 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6131 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6132 Spacing));
6133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6134 Spacing * 2));
6135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6136 Spacing * 3));
6137 TmpInst.addOperand(Inst.getOperand(1)); // lane
6138 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6139 TmpInst.addOperand(Inst.getOperand(5));
6140 Inst = TmpInst;
6141 return true;
6142 }
6143
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006144 // VLD3DUP single 3-element structure to all lanes instructions.
6145 case ARM::VLD3DUPdAsm_8:
6146 case ARM::VLD3DUPdAsm_16:
6147 case ARM::VLD3DUPdAsm_32:
6148 case ARM::VLD3DUPqAsm_8:
6149 case ARM::VLD3DUPqAsm_16:
6150 case ARM::VLD3DUPqAsm_32: {
6151 MCInst TmpInst;
6152 unsigned Spacing;
6153 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6154 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6155 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6156 Spacing));
6157 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6158 Spacing * 2));
6159 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6160 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6161 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6162 TmpInst.addOperand(Inst.getOperand(4));
6163 Inst = TmpInst;
6164 return true;
6165 }
6166
6167 case ARM::VLD3DUPdWB_fixed_Asm_8:
6168 case ARM::VLD3DUPdWB_fixed_Asm_16:
6169 case ARM::VLD3DUPdWB_fixed_Asm_32:
6170 case ARM::VLD3DUPqWB_fixed_Asm_8:
6171 case ARM::VLD3DUPqWB_fixed_Asm_16:
6172 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6173 MCInst TmpInst;
6174 unsigned Spacing;
6175 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6176 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6178 Spacing));
6179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6180 Spacing * 2));
6181 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6182 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6183 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6184 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6185 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6186 TmpInst.addOperand(Inst.getOperand(4));
6187 Inst = TmpInst;
6188 return true;
6189 }
6190
6191 case ARM::VLD3DUPdWB_register_Asm_8:
6192 case ARM::VLD3DUPdWB_register_Asm_16:
6193 case ARM::VLD3DUPdWB_register_Asm_32:
6194 case ARM::VLD3DUPqWB_register_Asm_8:
6195 case ARM::VLD3DUPqWB_register_Asm_16:
6196 case ARM::VLD3DUPqWB_register_Asm_32: {
6197 MCInst TmpInst;
6198 unsigned Spacing;
6199 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6200 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6201 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6202 Spacing));
6203 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6204 Spacing * 2));
6205 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6206 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6207 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6208 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6209 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6210 TmpInst.addOperand(Inst.getOperand(5));
6211 Inst = TmpInst;
6212 return true;
6213 }
6214
Jim Grosbachc387fc62012-01-23 23:20:46 +00006215 // VLD3 multiple 3-element structure instructions.
6216 case ARM::VLD3dAsm_8:
6217 case ARM::VLD3dAsm_16:
6218 case ARM::VLD3dAsm_32:
6219 case ARM::VLD3qAsm_8:
6220 case ARM::VLD3qAsm_16:
6221 case ARM::VLD3qAsm_32: {
6222 MCInst TmpInst;
6223 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006224 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006225 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6226 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6227 Spacing));
6228 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6229 Spacing * 2));
6230 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6231 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6232 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6233 TmpInst.addOperand(Inst.getOperand(4));
6234 Inst = TmpInst;
6235 return true;
6236 }
6237
6238 case ARM::VLD3dWB_fixed_Asm_8:
6239 case ARM::VLD3dWB_fixed_Asm_16:
6240 case ARM::VLD3dWB_fixed_Asm_32:
6241 case ARM::VLD3qWB_fixed_Asm_8:
6242 case ARM::VLD3qWB_fixed_Asm_16:
6243 case ARM::VLD3qWB_fixed_Asm_32: {
6244 MCInst TmpInst;
6245 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006246 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006247 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6248 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6249 Spacing));
6250 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6251 Spacing * 2));
6252 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6253 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6254 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6255 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6256 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6257 TmpInst.addOperand(Inst.getOperand(4));
6258 Inst = TmpInst;
6259 return true;
6260 }
6261
6262 case ARM::VLD3dWB_register_Asm_8:
6263 case ARM::VLD3dWB_register_Asm_16:
6264 case ARM::VLD3dWB_register_Asm_32:
6265 case ARM::VLD3qWB_register_Asm_8:
6266 case ARM::VLD3qWB_register_Asm_16:
6267 case ARM::VLD3qWB_register_Asm_32: {
6268 MCInst TmpInst;
6269 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006270 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006271 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6272 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6273 Spacing));
6274 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6275 Spacing * 2));
6276 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6277 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6278 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6279 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6280 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6281 TmpInst.addOperand(Inst.getOperand(5));
6282 Inst = TmpInst;
6283 return true;
6284 }
6285
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006286 // VLD4DUP single 3-element structure to all lanes instructions.
6287 case ARM::VLD4DUPdAsm_8:
6288 case ARM::VLD4DUPdAsm_16:
6289 case ARM::VLD4DUPdAsm_32:
6290 case ARM::VLD4DUPqAsm_8:
6291 case ARM::VLD4DUPqAsm_16:
6292 case ARM::VLD4DUPqAsm_32: {
6293 MCInst TmpInst;
6294 unsigned Spacing;
6295 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6296 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6298 Spacing));
6299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 Spacing * 2));
6301 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6302 Spacing * 3));
6303 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6304 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6305 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6306 TmpInst.addOperand(Inst.getOperand(4));
6307 Inst = TmpInst;
6308 return true;
6309 }
6310
6311 case ARM::VLD4DUPdWB_fixed_Asm_8:
6312 case ARM::VLD4DUPdWB_fixed_Asm_16:
6313 case ARM::VLD4DUPdWB_fixed_Asm_32:
6314 case ARM::VLD4DUPqWB_fixed_Asm_8:
6315 case ARM::VLD4DUPqWB_fixed_Asm_16:
6316 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6317 MCInst TmpInst;
6318 unsigned Spacing;
6319 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6320 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6321 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6322 Spacing));
6323 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6324 Spacing * 2));
6325 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6326 Spacing * 3));
6327 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6328 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6329 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6330 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6331 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6332 TmpInst.addOperand(Inst.getOperand(4));
6333 Inst = TmpInst;
6334 return true;
6335 }
6336
6337 case ARM::VLD4DUPdWB_register_Asm_8:
6338 case ARM::VLD4DUPdWB_register_Asm_16:
6339 case ARM::VLD4DUPdWB_register_Asm_32:
6340 case ARM::VLD4DUPqWB_register_Asm_8:
6341 case ARM::VLD4DUPqWB_register_Asm_16:
6342 case ARM::VLD4DUPqWB_register_Asm_32: {
6343 MCInst TmpInst;
6344 unsigned Spacing;
6345 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6346 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6347 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6348 Spacing));
6349 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6350 Spacing * 2));
6351 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6352 Spacing * 3));
6353 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6354 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6355 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6356 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6357 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6358 TmpInst.addOperand(Inst.getOperand(5));
6359 Inst = TmpInst;
6360 return true;
6361 }
6362
6363 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006364 case ARM::VLD4dAsm_8:
6365 case ARM::VLD4dAsm_16:
6366 case ARM::VLD4dAsm_32:
6367 case ARM::VLD4qAsm_8:
6368 case ARM::VLD4qAsm_16:
6369 case ARM::VLD4qAsm_32: {
6370 MCInst TmpInst;
6371 unsigned Spacing;
6372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 Spacing));
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 Spacing * 2));
6378 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6379 Spacing * 3));
6380 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6381 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6382 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(4));
6384 Inst = TmpInst;
6385 return true;
6386 }
6387
6388 case ARM::VLD4dWB_fixed_Asm_8:
6389 case ARM::VLD4dWB_fixed_Asm_16:
6390 case ARM::VLD4dWB_fixed_Asm_32:
6391 case ARM::VLD4qWB_fixed_Asm_8:
6392 case ARM::VLD4qWB_fixed_Asm_16:
6393 case ARM::VLD4qWB_fixed_Asm_32: {
6394 MCInst TmpInst;
6395 unsigned Spacing;
6396 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6397 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6399 Spacing));
6400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6401 Spacing * 2));
6402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6403 Spacing * 3));
6404 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6405 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6406 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6407 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6408 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6409 TmpInst.addOperand(Inst.getOperand(4));
6410 Inst = TmpInst;
6411 return true;
6412 }
6413
6414 case ARM::VLD4dWB_register_Asm_8:
6415 case ARM::VLD4dWB_register_Asm_16:
6416 case ARM::VLD4dWB_register_Asm_32:
6417 case ARM::VLD4qWB_register_Asm_8:
6418 case ARM::VLD4qWB_register_Asm_16:
6419 case ARM::VLD4qWB_register_Asm_32: {
6420 MCInst TmpInst;
6421 unsigned Spacing;
6422 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6423 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6425 Spacing));
6426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6427 Spacing * 2));
6428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6429 Spacing * 3));
6430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6431 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6432 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6433 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6434 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6435 TmpInst.addOperand(Inst.getOperand(5));
6436 Inst = TmpInst;
6437 return true;
6438 }
6439
Jim Grosbachd7433e22012-01-23 23:45:44 +00006440 // VST3 multiple 3-element structure instructions.
6441 case ARM::VST3dAsm_8:
6442 case ARM::VST3dAsm_16:
6443 case ARM::VST3dAsm_32:
6444 case ARM::VST3qAsm_8:
6445 case ARM::VST3qAsm_16:
6446 case ARM::VST3qAsm_32: {
6447 MCInst TmpInst;
6448 unsigned Spacing;
6449 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6452 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6453 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6454 Spacing));
6455 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6456 Spacing * 2));
6457 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6458 TmpInst.addOperand(Inst.getOperand(4));
6459 Inst = TmpInst;
6460 return true;
6461 }
6462
6463 case ARM::VST3dWB_fixed_Asm_8:
6464 case ARM::VST3dWB_fixed_Asm_16:
6465 case ARM::VST3dWB_fixed_Asm_32:
6466 case ARM::VST3qWB_fixed_Asm_8:
6467 case ARM::VST3qWB_fixed_Asm_16:
6468 case ARM::VST3qWB_fixed_Asm_32: {
6469 MCInst TmpInst;
6470 unsigned Spacing;
6471 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6472 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6473 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6474 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6475 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6476 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6477 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6478 Spacing));
6479 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6480 Spacing * 2));
6481 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6482 TmpInst.addOperand(Inst.getOperand(4));
6483 Inst = TmpInst;
6484 return true;
6485 }
6486
6487 case ARM::VST3dWB_register_Asm_8:
6488 case ARM::VST3dWB_register_Asm_16:
6489 case ARM::VST3dWB_register_Asm_32:
6490 case ARM::VST3qWB_register_Asm_8:
6491 case ARM::VST3qWB_register_Asm_16:
6492 case ARM::VST3qWB_register_Asm_32: {
6493 MCInst TmpInst;
6494 unsigned Spacing;
6495 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6496 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6497 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6498 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6499 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6500 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6501 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6502 Spacing));
6503 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6504 Spacing * 2));
6505 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6506 TmpInst.addOperand(Inst.getOperand(5));
6507 Inst = TmpInst;
6508 return true;
6509 }
6510
Jim Grosbach539aab72012-01-24 00:58:13 +00006511 // VST4 multiple 3-element structure instructions.
6512 case ARM::VST4dAsm_8:
6513 case ARM::VST4dAsm_16:
6514 case ARM::VST4dAsm_32:
6515 case ARM::VST4qAsm_8:
6516 case ARM::VST4qAsm_16:
6517 case ARM::VST4qAsm_32: {
6518 MCInst TmpInst;
6519 unsigned Spacing;
6520 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6522 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6523 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing));
6526 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6527 Spacing * 2));
6528 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6529 Spacing * 3));
6530 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(4));
6532 Inst = TmpInst;
6533 return true;
6534 }
6535
6536 case ARM::VST4dWB_fixed_Asm_8:
6537 case ARM::VST4dWB_fixed_Asm_16:
6538 case ARM::VST4dWB_fixed_Asm_32:
6539 case ARM::VST4qWB_fixed_Asm_8:
6540 case ARM::VST4qWB_fixed_Asm_16:
6541 case ARM::VST4qWB_fixed_Asm_32: {
6542 MCInst TmpInst;
6543 unsigned Spacing;
6544 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6545 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6546 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6547 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6548 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6549 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6550 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6551 Spacing));
6552 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6553 Spacing * 2));
6554 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6555 Spacing * 3));
6556 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6557 TmpInst.addOperand(Inst.getOperand(4));
6558 Inst = TmpInst;
6559 return true;
6560 }
6561
6562 case ARM::VST4dWB_register_Asm_8:
6563 case ARM::VST4dWB_register_Asm_16:
6564 case ARM::VST4dWB_register_Asm_32:
6565 case ARM::VST4qWB_register_Asm_8:
6566 case ARM::VST4qWB_register_Asm_16:
6567 case ARM::VST4qWB_register_Asm_32: {
6568 MCInst TmpInst;
6569 unsigned Spacing;
6570 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6571 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6572 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6573 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6574 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6575 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6576 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6577 Spacing));
6578 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6579 Spacing * 2));
6580 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6581 Spacing * 3));
6582 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6583 TmpInst.addOperand(Inst.getOperand(5));
6584 Inst = TmpInst;
6585 return true;
6586 }
6587
Jim Grosbach863d2af2011-12-13 22:45:11 +00006588 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006589 case ARM::t2MOVsr:
6590 case ARM::t2MOVSsr: {
6591 // Which instruction to expand to depends on the CCOut operand and
6592 // whether we're in an IT block if the register operands are low
6593 // registers.
6594 bool isNarrow = false;
6595 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6596 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6597 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6598 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6599 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6600 isNarrow = true;
6601 MCInst TmpInst;
6602 unsigned newOpc;
6603 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6604 default: llvm_unreachable("unexpected opcode!");
6605 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6606 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6607 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6608 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6609 }
6610 TmpInst.setOpcode(newOpc);
6611 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6612 if (isNarrow)
6613 TmpInst.addOperand(MCOperand::CreateReg(
6614 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6615 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6616 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6617 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6618 TmpInst.addOperand(Inst.getOperand(5));
6619 if (!isNarrow)
6620 TmpInst.addOperand(MCOperand::CreateReg(
6621 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6622 Inst = TmpInst;
6623 return true;
6624 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006625 case ARM::t2MOVsi:
6626 case ARM::t2MOVSsi: {
6627 // Which instruction to expand to depends on the CCOut operand and
6628 // whether we're in an IT block if the register operands are low
6629 // registers.
6630 bool isNarrow = false;
6631 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6632 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6633 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6634 isNarrow = true;
6635 MCInst TmpInst;
6636 unsigned newOpc;
6637 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6638 default: llvm_unreachable("unexpected opcode!");
6639 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6640 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6641 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6642 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006643 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006644 }
6645 unsigned Ammount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6646 if (Ammount == 32) Ammount = 0;
6647 TmpInst.setOpcode(newOpc);
6648 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6649 if (isNarrow)
6650 TmpInst.addOperand(MCOperand::CreateReg(
6651 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6652 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006653 if (newOpc != ARM::t2RRX)
6654 TmpInst.addOperand(MCOperand::CreateImm(Ammount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006655 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6656 TmpInst.addOperand(Inst.getOperand(4));
6657 if (!isNarrow)
6658 TmpInst.addOperand(MCOperand::CreateReg(
6659 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6660 Inst = TmpInst;
6661 return true;
6662 }
6663 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006664 case ARM::ASRr:
6665 case ARM::LSRr:
6666 case ARM::LSLr:
6667 case ARM::RORr: {
6668 ARM_AM::ShiftOpc ShiftTy;
6669 switch(Inst.getOpcode()) {
6670 default: llvm_unreachable("unexpected opcode!");
6671 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6672 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6673 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6674 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6675 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006676 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6677 MCInst TmpInst;
6678 TmpInst.setOpcode(ARM::MOVsr);
6679 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6680 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6681 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6682 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6683 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6684 TmpInst.addOperand(Inst.getOperand(4));
6685 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6686 Inst = TmpInst;
6687 return true;
6688 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006689 case ARM::ASRi:
6690 case ARM::LSRi:
6691 case ARM::LSLi:
6692 case ARM::RORi: {
6693 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006694 switch(Inst.getOpcode()) {
6695 default: llvm_unreachable("unexpected opcode!");
6696 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6697 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6698 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6699 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6700 }
6701 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006702 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006703 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
6704 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006705 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006706 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006707 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6708 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006709 if (Opc == ARM::MOVsi)
6710 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006711 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6712 TmpInst.addOperand(Inst.getOperand(4));
6713 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6714 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006715 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006716 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006717 case ARM::RRXi: {
6718 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6719 MCInst TmpInst;
6720 TmpInst.setOpcode(ARM::MOVsi);
6721 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6722 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6723 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6724 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6725 TmpInst.addOperand(Inst.getOperand(3));
6726 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6727 Inst = TmpInst;
6728 return true;
6729 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006730 case ARM::t2LDMIA_UPD: {
6731 // If this is a load of a single register, then we should use
6732 // a post-indexed LDR instruction instead, per the ARM ARM.
6733 if (Inst.getNumOperands() != 5)
6734 return false;
6735 MCInst TmpInst;
6736 TmpInst.setOpcode(ARM::t2LDR_POST);
6737 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6738 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6739 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6740 TmpInst.addOperand(MCOperand::CreateImm(4));
6741 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6742 TmpInst.addOperand(Inst.getOperand(3));
6743 Inst = TmpInst;
6744 return true;
6745 }
6746 case ARM::t2STMDB_UPD: {
6747 // If this is a store of a single register, then we should use
6748 // a pre-indexed STR instruction instead, per the ARM ARM.
6749 if (Inst.getNumOperands() != 5)
6750 return false;
6751 MCInst TmpInst;
6752 TmpInst.setOpcode(ARM::t2STR_PRE);
6753 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6754 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6755 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6756 TmpInst.addOperand(MCOperand::CreateImm(-4));
6757 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6758 TmpInst.addOperand(Inst.getOperand(3));
6759 Inst = TmpInst;
6760 return true;
6761 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006762 case ARM::LDMIA_UPD:
6763 // If this is a load of a single register via a 'pop', then we should use
6764 // a post-indexed LDR instruction instead, per the ARM ARM.
6765 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6766 Inst.getNumOperands() == 5) {
6767 MCInst TmpInst;
6768 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6769 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6770 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6771 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6772 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6773 TmpInst.addOperand(MCOperand::CreateImm(4));
6774 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6775 TmpInst.addOperand(Inst.getOperand(3));
6776 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006777 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006778 }
6779 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006780 case ARM::STMDB_UPD:
6781 // If this is a store of a single register via a 'push', then we should use
6782 // a pre-indexed STR instruction instead, per the ARM ARM.
6783 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6784 Inst.getNumOperands() == 5) {
6785 MCInst TmpInst;
6786 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6787 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6788 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6789 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6790 TmpInst.addOperand(MCOperand::CreateImm(-4));
6791 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6792 TmpInst.addOperand(Inst.getOperand(3));
6793 Inst = TmpInst;
6794 }
6795 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006796 case ARM::t2ADDri12:
6797 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6798 // mnemonic was used (not "addw"), encoding T3 is preferred.
6799 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
6800 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6801 break;
6802 Inst.setOpcode(ARM::t2ADDri);
6803 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6804 break;
6805 case ARM::t2SUBri12:
6806 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
6807 // mnemonic was used (not "subw"), encoding T3 is preferred.
6808 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
6809 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
6810 break;
6811 Inst.setOpcode(ARM::t2SUBri);
6812 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
6813 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006814 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00006815 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6816 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6817 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6818 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006819 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006820 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006821 return true;
6822 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00006823 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00006824 case ARM::tSUBi8:
6825 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
6826 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
6827 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
6828 // to encoding T1 if <Rd> is omitted."
Jim Grosbach83ec8772011-11-10 23:42:14 +00006829 if (Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00006830 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006831 return true;
6832 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00006833 break;
Jim Grosbach927b9df2011-12-05 22:16:39 +00006834 case ARM::t2ADDrr: {
6835 // If the destination and first source operand are the same, and
6836 // there's no setting of the flags, use encoding T2 instead of T3.
6837 // Note that this is only for ADD, not SUB. This mirrors the system
6838 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
6839 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
6840 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00006841 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6842 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00006843 break;
6844 MCInst TmpInst;
6845 TmpInst.setOpcode(ARM::tADDhirr);
6846 TmpInst.addOperand(Inst.getOperand(0));
6847 TmpInst.addOperand(Inst.getOperand(0));
6848 TmpInst.addOperand(Inst.getOperand(2));
6849 TmpInst.addOperand(Inst.getOperand(3));
6850 TmpInst.addOperand(Inst.getOperand(4));
6851 Inst = TmpInst;
6852 return true;
6853 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006854 case ARM::tB:
6855 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006856 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006857 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006858 return true;
6859 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006860 break;
6861 case ARM::t2B:
6862 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006863 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006864 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006865 return true;
6866 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00006867 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00006868 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00006869 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006870 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00006871 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006872 return true;
6873 }
Jim Grosbachc0755102011-08-31 21:17:31 +00006874 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00006875 case ARM::tBcc:
6876 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00006877 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00006878 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006879 return true;
6880 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00006881 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006882 case ARM::tLDMIA: {
6883 // If the register list contains any high registers, or if the writeback
6884 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
6885 // instead if we're in Thumb2. Otherwise, this should have generated
6886 // an error in validateInstruction().
6887 unsigned Rn = Inst.getOperand(0).getReg();
6888 bool hasWritebackToken =
6889 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
6890 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
6891 bool listContainsBase;
6892 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
6893 (!listContainsBase && !hasWritebackToken) ||
6894 (listContainsBase && hasWritebackToken)) {
6895 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6896 assert (isThumbTwo());
6897 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
6898 // If we're switching to the updating version, we need to insert
6899 // the writeback tied operand.
6900 if (hasWritebackToken)
6901 Inst.insert(Inst.begin(),
6902 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006903 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00006904 }
6905 break;
6906 }
Jim Grosbach8213c962011-09-16 20:50:13 +00006907 case ARM::tSTMIA_UPD: {
6908 // If the register list contains any high registers, we need to use
6909 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6910 // should have generated an error in validateInstruction().
6911 unsigned Rn = Inst.getOperand(0).getReg();
6912 bool listContainsBase;
6913 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
6914 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
6915 assert (isThumbTwo());
6916 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00006917 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00006918 }
6919 break;
6920 }
Jim Grosbach54026372011-11-10 23:17:11 +00006921 case ARM::tPOP: {
6922 bool listContainsBase;
6923 // If the register list contains any high registers, we need to use
6924 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
6925 // should have generated an error in validateInstruction().
6926 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00006927 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00006928 assert (isThumbTwo());
6929 Inst.setOpcode(ARM::t2LDMIA_UPD);
6930 // Add the base register and writeback operands.
6931 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
6932 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00006933 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00006934 }
6935 case ARM::tPUSH: {
6936 bool listContainsBase;
6937 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, 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::t2STMDB_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 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006946 case ARM::t2MOVi: {
6947 // If we can use the 16-bit encoding and the user didn't explicitly
6948 // request the 32-bit variant, transform it here.
6949 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6950 Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00006951 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
6952 Inst.getOperand(4).getReg() == ARM::CPSR) ||
6953 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006954 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6955 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6956 // The operands aren't in the same order for tMOVi8...
6957 MCInst TmpInst;
6958 TmpInst.setOpcode(ARM::tMOVi8);
6959 TmpInst.addOperand(Inst.getOperand(0));
6960 TmpInst.addOperand(Inst.getOperand(4));
6961 TmpInst.addOperand(Inst.getOperand(1));
6962 TmpInst.addOperand(Inst.getOperand(2));
6963 TmpInst.addOperand(Inst.getOperand(3));
6964 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006965 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006966 }
6967 break;
6968 }
6969 case ARM::t2MOVr: {
6970 // If we can use the 16-bit encoding and the user didn't explicitly
6971 // request the 32-bit variant, transform it here.
6972 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6973 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6974 Inst.getOperand(2).getImm() == ARMCC::AL &&
6975 Inst.getOperand(4).getReg() == ARM::CPSR &&
6976 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
6977 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
6978 // The operands aren't the same for tMOV[S]r... (no cc_out)
6979 MCInst TmpInst;
6980 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
6981 TmpInst.addOperand(Inst.getOperand(0));
6982 TmpInst.addOperand(Inst.getOperand(1));
6983 TmpInst.addOperand(Inst.getOperand(2));
6984 TmpInst.addOperand(Inst.getOperand(3));
6985 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006986 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00006987 }
6988 break;
6989 }
Jim Grosbach326efe52011-09-19 20:29:33 +00006990 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00006991 case ARM::t2SXTB:
6992 case ARM::t2UXTH:
6993 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00006994 // If we can use the 16-bit encoding and the user didn't explicitly
6995 // request the 32-bit variant, transform it here.
6996 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6997 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6998 Inst.getOperand(2).getImm() == 0 &&
6999 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7000 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007001 unsigned NewOpc;
7002 switch (Inst.getOpcode()) {
7003 default: llvm_unreachable("Illegal opcode!");
7004 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7005 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7006 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7007 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7008 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007009 // The operands aren't the same for thumb1 (no rotate operand).
7010 MCInst TmpInst;
7011 TmpInst.setOpcode(NewOpc);
7012 TmpInst.addOperand(Inst.getOperand(0));
7013 TmpInst.addOperand(Inst.getOperand(1));
7014 TmpInst.addOperand(Inst.getOperand(3));
7015 TmpInst.addOperand(Inst.getOperand(4));
7016 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007017 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007018 }
7019 break;
7020 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007021 case ARM::MOVsi: {
7022 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
7023 if (SOpc == ARM_AM::rrx) return false;
7024 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7025 // Shifting by zero is accepted as a vanilla 'MOVr'
7026 MCInst TmpInst;
7027 TmpInst.setOpcode(ARM::MOVr);
7028 TmpInst.addOperand(Inst.getOperand(0));
7029 TmpInst.addOperand(Inst.getOperand(1));
7030 TmpInst.addOperand(Inst.getOperand(3));
7031 TmpInst.addOperand(Inst.getOperand(4));
7032 TmpInst.addOperand(Inst.getOperand(5));
7033 Inst = TmpInst;
7034 return true;
7035 }
7036 return false;
7037 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007038 case ARM::ANDrsi:
7039 case ARM::ORRrsi:
7040 case ARM::EORrsi:
7041 case ARM::BICrsi:
7042 case ARM::SUBrsi:
7043 case ARM::ADDrsi: {
7044 unsigned newOpc;
7045 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7046 if (SOpc == ARM_AM::rrx) return false;
7047 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007048 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007049 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7050 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7051 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7052 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7053 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7054 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7055 }
7056 // If the shift is by zero, use the non-shifted instruction definition.
7057 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0) {
7058 MCInst TmpInst;
7059 TmpInst.setOpcode(newOpc);
7060 TmpInst.addOperand(Inst.getOperand(0));
7061 TmpInst.addOperand(Inst.getOperand(1));
7062 TmpInst.addOperand(Inst.getOperand(2));
7063 TmpInst.addOperand(Inst.getOperand(4));
7064 TmpInst.addOperand(Inst.getOperand(5));
7065 TmpInst.addOperand(Inst.getOperand(6));
7066 Inst = TmpInst;
7067 return true;
7068 }
7069 return false;
7070 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007071 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007072 case ARM::t2IT: {
7073 // The mask bits for all but the first condition are represented as
7074 // the low bit of the condition code value implies 't'. We currently
7075 // always have 1 implies 't', so XOR toggle the bits if the low bit
7076 // of the condition code is zero. The encoding also expects the low
7077 // bit of the condition to be encoded as bit 4 of the mask operand,
7078 // so mask that in if needed
7079 MCOperand &MO = Inst.getOperand(1);
7080 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007081 unsigned OrigMask = Mask;
7082 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007083 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007084 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7085 for (unsigned i = 3; i != TZ; --i)
7086 Mask ^= 1 << i;
7087 } else
7088 Mask |= 0x10;
7089 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007090
7091 // Set up the IT block state according to the IT instruction we just
7092 // matched.
7093 assert(!inITBlock() && "nested IT blocks?!");
7094 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7095 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7096 ITState.CurPosition = 0;
7097 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007098 break;
7099 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007100 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007101 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007102}
7103
Jim Grosbach47a0d522011-08-16 20:45:50 +00007104unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7105 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7106 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007107 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007108 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007109 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7110 assert(MCID.hasOptionalDef() &&
7111 "optionally flag setting instruction missing optional def operand");
7112 assert(MCID.NumOperands == Inst.getNumOperands() &&
7113 "operand count mismatch!");
7114 // Find the optional-def operand (cc_out).
7115 unsigned OpNo;
7116 for (OpNo = 0;
7117 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7118 ++OpNo)
7119 ;
7120 // If we're parsing Thumb1, reject it completely.
7121 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7122 return Match_MnemonicFail;
7123 // If we're parsing Thumb2, which form is legal depends on whether we're
7124 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007125 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7126 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007127 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007128 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7129 inITBlock())
7130 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007131 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007132 // Some high-register supporting Thumb1 encodings only allow both registers
7133 // to be from r0-r7 when in Thumb2.
7134 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7135 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7136 isARMLowRegister(Inst.getOperand(2).getReg()))
7137 return Match_RequiresThumb2;
7138 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007139 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007140 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7141 isARMLowRegister(Inst.getOperand(1).getReg()))
7142 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007143 return Match_Success;
7144}
7145
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007146bool ARMAsmParser::
7147MatchAndEmitInstruction(SMLoc IDLoc,
7148 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7149 MCStreamer &Out) {
7150 MCInst Inst;
7151 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007152 unsigned MatchResult;
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007153 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007154 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007155 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007156 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007157 // Context sensitive operand constraints aren't handled by the matcher,
7158 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007159 if (validateInstruction(Inst, Operands)) {
7160 // Still progress the IT block, otherwise one wrong condition causes
7161 // nasty cascading errors.
7162 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007163 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007164 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007165
Jim Grosbachf8fce712011-08-11 17:35:48 +00007166 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007167 // encoding is selected. Loop on it while changes happen so the
7168 // individual transformations can chain off each other. E.g.,
7169 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7170 while (processInstruction(Inst, Operands))
7171 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007172
Jim Grosbacha1109882011-09-02 23:22:08 +00007173 // Only move forward at the very end so that everything in validate
7174 // and process gets a consistent answer about whether we're in an IT
7175 // block.
7176 forwardITPosition();
7177
Jim Grosbach74423e32012-01-25 19:52:01 +00007178 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7179 // doesn't actually encode.
7180 if (Inst.getOpcode() == ARM::ITasm)
7181 return false;
7182
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007183 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007184 Out.EmitInstruction(Inst);
7185 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007186 case Match_MissingFeature:
7187 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
7188 return true;
7189 case Match_InvalidOperand: {
7190 SMLoc ErrorLoc = IDLoc;
7191 if (ErrorInfo != ~0U) {
7192 if (ErrorInfo >= Operands.size())
7193 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007194
Chris Lattnere73d4f82010-10-28 21:41:58 +00007195 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7196 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7197 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007198
Chris Lattnere73d4f82010-10-28 21:41:58 +00007199 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007200 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007201 case Match_MnemonicFail:
Jim Grosbach47a0d522011-08-16 20:45:50 +00007202 return Error(IDLoc, "invalid instruction");
Daniel Dunbarb4129152011-02-04 17:12:23 +00007203 case Match_ConversionFail:
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00007204 // The converter function will have already emited a diagnostic.
7205 return true;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007206 case Match_RequiresNotITBlock:
7207 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007208 case Match_RequiresITBlock:
7209 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007210 case Match_RequiresV6:
7211 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7212 case Match_RequiresThumb2:
7213 return Error(IDLoc, "instruction variant requires Thumb2");
Chris Lattnere73d4f82010-10-28 21:41:58 +00007214 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007215
Eric Christopherc223e2b2010-10-29 09:26:59 +00007216 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007217}
7218
Jim Grosbach1355cf12011-07-26 17:10:22 +00007219/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007220bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7221 StringRef IDVal = DirectiveID.getIdentifier();
7222 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007223 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007224 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007225 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007226 else if (IDVal == ".arm")
7227 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007228 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007229 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007230 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007231 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007232 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007233 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007234 else if (IDVal == ".unreq")
7235 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007236 else if (IDVal == ".arch")
7237 return parseDirectiveArch(DirectiveID.getLoc());
7238 else if (IDVal == ".eabi_attribute")
7239 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007240 return true;
7241}
7242
Jim Grosbach1355cf12011-07-26 17:10:22 +00007243/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007244/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007245bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007246 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7247 for (;;) {
7248 const MCExpr *Value;
7249 if (getParser().ParseExpression(Value))
7250 return true;
7251
Chris Lattneraaec2052010-01-19 19:46:13 +00007252 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007253
7254 if (getLexer().is(AsmToken::EndOfStatement))
7255 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007256
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007257 // FIXME: Improve diagnostic.
7258 if (getLexer().isNot(AsmToken::Comma))
7259 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007260 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007261 }
7262 }
7263
Sean Callananb9a25b72010-01-19 20:27:46 +00007264 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007265 return false;
7266}
7267
Jim Grosbach1355cf12011-07-26 17:10:22 +00007268/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007269/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007270bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007271 if (getLexer().isNot(AsmToken::EndOfStatement))
7272 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007273 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007274
Jim Grosbach9a70df92011-12-07 18:04:19 +00007275 if (!isThumb())
7276 SwitchMode();
7277 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7278 return false;
7279}
7280
7281/// parseDirectiveARM
7282/// ::= .arm
7283bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7284 if (getLexer().isNot(AsmToken::EndOfStatement))
7285 return Error(L, "unexpected token in directive");
7286 Parser.Lex();
7287
7288 if (isThumb())
7289 SwitchMode();
7290 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007291 return false;
7292}
7293
Jim Grosbach1355cf12011-07-26 17:10:22 +00007294/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007295/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007296bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007297 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7298 bool isMachO = MAI.hasSubsectionsViaSymbols();
7299 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007300 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007301
Jim Grosbachde4d8392011-12-21 22:30:16 +00007302 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007303 // ELF doesn't
7304 if (isMachO) {
7305 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007306 if (Tok.isNot(AsmToken::EndOfStatement)) {
7307 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7308 return Error(L, "unexpected token in .thumb_func directive");
7309 Name = Tok.getIdentifier();
7310 Parser.Lex(); // Consume the identifier token.
7311 needFuncName = false;
7312 }
Rafael Espindola64695402011-05-16 16:17:21 +00007313 }
7314
Jim Grosbachde4d8392011-12-21 22:30:16 +00007315 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007316 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007317
7318 // Eat the end of statement and any blank lines that follow.
7319 while (getLexer().is(AsmToken::EndOfStatement))
7320 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007321
Rafael Espindola64695402011-05-16 16:17:21 +00007322 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007323 // We really should be checking the next symbol definition even if there's
7324 // stuff in between.
7325 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007326 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007327 }
7328
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007329 // Mark symbol as a thumb symbol.
7330 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7331 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007332 return false;
7333}
7334
Jim Grosbach1355cf12011-07-26 17:10:22 +00007335/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007336/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007337bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007338 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007339 if (Tok.isNot(AsmToken::Identifier))
7340 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007341 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007342 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007343 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007344 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007345 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007346 else
7347 return Error(L, "unrecognized syntax mode in .syntax directive");
7348
7349 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007350 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007351 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007352
7353 // TODO tell the MC streamer the mode
7354 // getParser().getStreamer().Emit???();
7355 return false;
7356}
7357
Jim Grosbach1355cf12011-07-26 17:10:22 +00007358/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007359/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007360bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007361 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007362 if (Tok.isNot(AsmToken::Integer))
7363 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007364 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007365 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007366 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007367 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007368 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007369 else
7370 return Error(L, "invalid operand to .code directive");
7371
7372 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007373 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007374 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007375
Evan Cheng32869202011-07-08 22:36:29 +00007376 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007377 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007378 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007379 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007380 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007381 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007382 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007383 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007384 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007385
Kevin Enderby515d5092009-10-15 20:48:48 +00007386 return false;
7387}
7388
Jim Grosbacha39cda72011-12-14 02:16:11 +00007389/// parseDirectiveReq
7390/// ::= name .req registername
7391bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7392 Parser.Lex(); // Eat the '.req' token.
7393 unsigned Reg;
7394 SMLoc SRegLoc, ERegLoc;
7395 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7396 Parser.EatToEndOfStatement();
7397 return Error(SRegLoc, "register name expected");
7398 }
7399
7400 // Shouldn't be anything else.
7401 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7402 Parser.EatToEndOfStatement();
7403 return Error(Parser.getTok().getLoc(),
7404 "unexpected input in .req directive.");
7405 }
7406
7407 Parser.Lex(); // Consume the EndOfStatement
7408
7409 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7410 return Error(SRegLoc, "redefinition of '" + Name +
7411 "' does not match original.");
7412
7413 return false;
7414}
7415
7416/// parseDirectiveUneq
7417/// ::= .unreq registername
7418bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7419 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7420 Parser.EatToEndOfStatement();
7421 return Error(L, "unexpected input in .unreq directive.");
7422 }
7423 RegisterReqs.erase(Parser.getTok().getIdentifier());
7424 Parser.Lex(); // Eat the identifier.
7425 return false;
7426}
7427
Jason W Kimd7c9e082011-12-20 17:38:12 +00007428/// parseDirectiveArch
7429/// ::= .arch token
7430bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7431 return true;
7432}
7433
7434/// parseDirectiveEabiAttr
7435/// ::= .eabi_attribute int, int
7436bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7437 return true;
7438}
7439
Sean Callanan90b70972010-04-07 20:29:34 +00007440extern "C" void LLVMInitializeARMAsmLexer();
7441
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007442/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007443extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007444 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7445 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007446 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007447}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007448
Chris Lattner0692ee62010-09-06 19:11:01 +00007449#define GET_REGISTER_MATCHER
7450#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007451#include "ARMGenAsmMatcher.inc"